diff mbox

[4/4] drm/vkms: subclass CRTC state

Message ID 81bbb86ef375ec82bf589e40358191db28dfb833.1531149873.git.hamohammed.sa@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Haneen Mohammed July 9, 2018, 3:48 p.m. UTC
Subclass CRTC state struct to enable storing driver's private
state. This patch only adds the base drm_crtc_state struct and
the atomic functions that handle it.

Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com>
---
 drivers/gpu/drm/vkms/vkms_crtc.c | 55 ++++++++++++++++++++++++++++++--
 drivers/gpu/drm/vkms/vkms_drv.h  |  8 +++++
 2 files changed, 60 insertions(+), 3 deletions(-)

Comments

Daniel Vetter July 10, 2018, 8:10 a.m. UTC | #1
On Mon, Jul 09, 2018 at 06:48:36PM +0300, Haneen Mohammed wrote:
> Subclass CRTC state struct to enable storing driver's private
> state. This patch only adds the base drm_crtc_state struct and
> the atomic functions that handle it.
> 
> Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com>

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
>  drivers/gpu/drm/vkms/vkms_crtc.c | 55 ++++++++++++++++++++++++++++++--
>  drivers/gpu/drm/vkms/vkms_drv.h  |  8 +++++
>  2 files changed, 60 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
> index 84cc05506b09..56206437647d 100644
> --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> @@ -10,13 +10,62 @@
>  #include <drm/drm_atomic_helper.h>
>  #include <drm/drm_crtc_helper.h>
>  
> +static void vkms_crtc_reset(struct drm_crtc *crtc)
> +{
> +	struct vkms_crtc_state *state = NULL;
> +
> +	if (crtc->state) {
> +		state = container_of(crtc->state, struct vkms_crtc_state,
> +				     base);
> +		__drm_atomic_helper_crtc_destroy_state(crtc->state);
> +		kfree(state);
> +		crtc->state = NULL;
> +	}
> +
> +	state = kzalloc(sizeof(*state), GFP_KERNEL);

Hm, using kzalloc here is a good idea instead of kmalloc like in the
default functions. Care to write a patch for drm_atomic_helper to replace
all the kmalloc with kzalloc?

Thanks, Daniel

> +	if (!state)
> +		return;
> +
> +	crtc->state = &state->base;
> +	crtc->state->crtc = crtc;
> +}
> +
> +static struct drm_crtc_state *
> +vkms_crtc_duplicate_state(struct drm_crtc *crtc)
> +{
> +	struct vkms_crtc_state *state;
> +
> +	if (WARN_ON(!crtc->state))
> +		return NULL;
> +
> +	state = kzalloc(sizeof(*state), GFP_KERNEL);
> +	if (!state)
> +		return NULL;
> +
> +	__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
> +
> +	return &state->base;
> +}
> +
> +static void vkms_crtc_destroy_state(struct drm_crtc *crtc,
> +				    struct drm_crtc_state *state)
> +{
> +	struct vkms_crtc_state *vkms_state;
> +
> +	vkms_state = container_of(state, struct vkms_crtc_state, base);
> +
> +	__drm_atomic_helper_crtc_destroy_state(state);
> +	kfree(vkms_state);
> +}
> +
>  static const struct drm_crtc_funcs vkms_crtc_funcs = {
>  	.set_config             = drm_atomic_helper_set_config,
>  	.destroy                = drm_crtc_cleanup,
>  	.page_flip              = drm_atomic_helper_page_flip,
> -	.reset                  = drm_atomic_helper_crtc_reset,
> -	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
> -	.atomic_destroy_state   = drm_atomic_helper_crtc_destroy_state,
> +
> +	.reset                  = vkms_crtc_reset,
> +	.atomic_duplicate_state = vkms_crtc_duplicate_state,
> +	.atomic_destroy_state   = vkms_crtc_destroy_state,
>  };
>  
>  static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
> diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
> index d339a8108d85..61e367d32308 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.h
> +++ b/drivers/gpu/drm/vkms/vkms_drv.h
> @@ -19,6 +19,14 @@ static const u32 vkms_formats[] = {
>  	DRM_FORMAT_XRGB8888,
>  };
>  
> +/**
> + * vkms_crtc_state - Driver specific CRTC state
> + * @base: base CRTC state
> + */
> +struct vkms_crtc_state {
> +	struct drm_crtc_state base;
> +};
> +
>  struct vkms_output {
>  	struct drm_crtc crtc;
>  	struct drm_encoder encoder;
> -- 
> 2.17.1
>
Haneen Mohammed July 10, 2018, 3:13 p.m. UTC | #2
On Tue, Jul 10, 2018 at 10:10:46AM +0200, Daniel Vetter wrote:
> On Mon, Jul 09, 2018 at 06:48:36PM +0300, Haneen Mohammed wrote:
> > Subclass CRTC state struct to enable storing driver's private
> > state. This patch only adds the base drm_crtc_state struct and
> > the atomic functions that handle it.
> > 
> > Signed-off-by: Haneen Mohammed <hamohammed.sa@gmail.com>
> 
> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
> > ---
> >  drivers/gpu/drm/vkms/vkms_crtc.c | 55 ++++++++++++++++++++++++++++++--
> >  drivers/gpu/drm/vkms/vkms_drv.h  |  8 +++++
> >  2 files changed, 60 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
> > index 84cc05506b09..56206437647d 100644
> > --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> > +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> > @@ -10,13 +10,62 @@
> >  #include <drm/drm_atomic_helper.h>
> >  #include <drm/drm_crtc_helper.h>
> >  
> > +static void vkms_crtc_reset(struct drm_crtc *crtc)
> > +{
> > +	struct vkms_crtc_state *state = NULL;
> > +
> > +	if (crtc->state) {
> > +		state = container_of(crtc->state, struct vkms_crtc_state,
> > +				     base);
> > +		__drm_atomic_helper_crtc_destroy_state(crtc->state);
> > +		kfree(state);
> > +		crtc->state = NULL;
> > +	}
> > +
> > +	state = kzalloc(sizeof(*state), GFP_KERNEL);
> 
> Hm, using kzalloc here is a good idea instead of kmalloc like in the
> default functions. Care to write a patch for drm_atomic_helper to replace
> all the kmalloc with kzalloc?
> 

Sure, I will work on that and on your other comments. 

Thank you so much!
Haneen

> Thanks, Daniel
> 
> > +	if (!state)
> > +		return;
> > +
> > +	crtc->state = &state->base;
> > +	crtc->state->crtc = crtc;
> > +}
> > +
> > +static struct drm_crtc_state *
> > +vkms_crtc_duplicate_state(struct drm_crtc *crtc)
> > +{
> > +	struct vkms_crtc_state *state;
> > +
> > +	if (WARN_ON(!crtc->state))
> > +		return NULL;
> > +
> > +	state = kzalloc(sizeof(*state), GFP_KERNEL);
> > +	if (!state)
> > +		return NULL;
> > +
> > +	__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
> > +
> > +	return &state->base;
> > +}
> > +
> > +static void vkms_crtc_destroy_state(struct drm_crtc *crtc,
> > +				    struct drm_crtc_state *state)
> > +{
> > +	struct vkms_crtc_state *vkms_state;
> > +
> > +	vkms_state = container_of(state, struct vkms_crtc_state, base);
> > +
> > +	__drm_atomic_helper_crtc_destroy_state(state);
> > +	kfree(vkms_state);
> > +}
> > +
> >  static const struct drm_crtc_funcs vkms_crtc_funcs = {
> >  	.set_config             = drm_atomic_helper_set_config,
> >  	.destroy                = drm_crtc_cleanup,
> >  	.page_flip              = drm_atomic_helper_page_flip,
> > -	.reset                  = drm_atomic_helper_crtc_reset,
> > -	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
> > -	.atomic_destroy_state   = drm_atomic_helper_crtc_destroy_state,
> > +
> > +	.reset                  = vkms_crtc_reset,
> > +	.atomic_duplicate_state = vkms_crtc_duplicate_state,
> > +	.atomic_destroy_state   = vkms_crtc_destroy_state,
> >  };
> >  
> >  static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
> > diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
> > index d339a8108d85..61e367d32308 100644
> > --- a/drivers/gpu/drm/vkms/vkms_drv.h
> > +++ b/drivers/gpu/drm/vkms/vkms_drv.h
> > @@ -19,6 +19,14 @@ static const u32 vkms_formats[] = {
> >  	DRM_FORMAT_XRGB8888,
> >  };
> >  
> > +/**
> > + * vkms_crtc_state - Driver specific CRTC state
> > + * @base: base CRTC state
> > + */
> > +struct vkms_crtc_state {
> > +	struct drm_crtc_state base;
> > +};
> > +
> >  struct vkms_output {
> >  	struct drm_crtc crtc;
> >  	struct drm_encoder encoder;
> > -- 
> > 2.17.1
> > 
> 
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
diff mbox

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index 84cc05506b09..56206437647d 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -10,13 +10,62 @@ 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc_helper.h>
 
+static void vkms_crtc_reset(struct drm_crtc *crtc)
+{
+	struct vkms_crtc_state *state = NULL;
+
+	if (crtc->state) {
+		state = container_of(crtc->state, struct vkms_crtc_state,
+				     base);
+		__drm_atomic_helper_crtc_destroy_state(crtc->state);
+		kfree(state);
+		crtc->state = NULL;
+	}
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return;
+
+	crtc->state = &state->base;
+	crtc->state->crtc = crtc;
+}
+
+static struct drm_crtc_state *
+vkms_crtc_duplicate_state(struct drm_crtc *crtc)
+{
+	struct vkms_crtc_state *state;
+
+	if (WARN_ON(!crtc->state))
+		return NULL;
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return NULL;
+
+	__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
+
+	return &state->base;
+}
+
+static void vkms_crtc_destroy_state(struct drm_crtc *crtc,
+				    struct drm_crtc_state *state)
+{
+	struct vkms_crtc_state *vkms_state;
+
+	vkms_state = container_of(state, struct vkms_crtc_state, base);
+
+	__drm_atomic_helper_crtc_destroy_state(state);
+	kfree(vkms_state);
+}
+
 static const struct drm_crtc_funcs vkms_crtc_funcs = {
 	.set_config             = drm_atomic_helper_set_config,
 	.destroy                = drm_crtc_cleanup,
 	.page_flip              = drm_atomic_helper_page_flip,
-	.reset                  = drm_atomic_helper_crtc_reset,
-	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
-	.atomic_destroy_state   = drm_atomic_helper_crtc_destroy_state,
+
+	.reset                  = vkms_crtc_reset,
+	.atomic_duplicate_state = vkms_crtc_duplicate_state,
+	.atomic_destroy_state   = vkms_crtc_destroy_state,
 };
 
 static int vkms_crtc_atomic_check(struct drm_crtc *crtc,
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index d339a8108d85..61e367d32308 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -19,6 +19,14 @@  static const u32 vkms_formats[] = {
 	DRM_FORMAT_XRGB8888,
 };
 
+/**
+ * vkms_crtc_state - Driver specific CRTC state
+ * @base: base CRTC state
+ */
+struct vkms_crtc_state {
+	struct drm_crtc_state base;
+};
+
 struct vkms_output {
 	struct drm_crtc crtc;
 	struct drm_encoder encoder;