diff mbox series

[v5,4/8] drm/omap: omap_plane: subclass drm_plane_state

Message ID 20210923070701.145377-5-narmstrong@baylibre.com (mailing list archive)
State New, archived
Headers show
Series drm/omap: Add virtual-planes support | expand

Commit Message

Neil Armstrong Sept. 23, 2021, 7:06 a.m. UTC
From: Benoit Parrot <bparrot@ti.com>

In preparation to add omap plane state specific extensions we need to
subclass drm_plane_state and add the relevant helpers.

The addition of specific extension will be done separately.

Signed-off-by: Benoit Parrot <bparrot@ti.com>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
---
 drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

Comments

Tomi Valkeinen Oct. 12, 2021, 8:13 a.m. UTC | #1
On 23/09/2021 10:06, Neil Armstrong wrote:
> From: Benoit Parrot <bparrot@ti.com>
> 
> In preparation to add omap plane state specific extensions we need to
> subclass drm_plane_state and add the relevant helpers.
> 
> The addition of specific extension will be done separately.
> 
> Signed-off-by: Benoit Parrot <bparrot@ti.com>
> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
> ---
>   drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++---
>   1 file changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c
> index 0df5381cc015..bda794b4c915 100644
> --- a/drivers/gpu/drm/omapdrm/omap_plane.c
> +++ b/drivers/gpu/drm/omapdrm/omap_plane.c
> @@ -16,6 +16,13 @@
>    * plane funcs
>    */
>   
> +#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base)
> +
> +struct omap_plane_state {
> +	/* Must be first. */
> +	struct drm_plane_state base;
> +};
> +
>   #define to_omap_plane(x) container_of(x, struct omap_plane, base)
>   
>   struct omap_plane {
> @@ -207,11 +214,17 @@ void omap_plane_install_properties(struct drm_plane *plane,
>   static void omap_plane_reset(struct drm_plane *plane)
>   {
>   	struct omap_plane *omap_plane = to_omap_plane(plane);
> +	struct omap_plane_state *omap_state;
>   
> -	drm_atomic_helper_plane_reset(plane);
> -	if (!plane->state)
> +	if (plane->state)
> +		drm_atomic_helper_plane_destroy_state(plane, plane->state);
> +
> +	omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL);
> +	if (!omap_state)
>   		return;
>   
> +	__drm_atomic_helper_plane_reset(plane, &omap_state->base);
> +
>   	/*
>   	 * Set the zpos default depending on whether we are a primary or overlay
>   	 * plane.
> @@ -222,6 +235,25 @@ static void omap_plane_reset(struct drm_plane *plane)
>   	plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE;
>   }
>   
> +static struct drm_plane_state *
> +omap_plane_atomic_duplicate_state(struct drm_plane *plane)
> +{
> +	struct omap_plane_state *state;
> +	struct omap_plane_state *copy;
> +
> +	if (WARN_ON(!plane->state))
> +		return NULL;
> +
> +	state = to_omap_plane_state(plane->state);
> +	copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
> +	if (!copy)
> +		return NULL;
> +
> +	__drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
> +
> +	return &copy->base;
> +}
> +

omap_crtc.c has similar, but slightly different, functions. I think it 
would be good to use the same style in omap_plane, or, if the approach 
above is better, change omap_crtc to match the style here.

  Tomi
Neil Armstrong Oct. 12, 2021, 8:56 a.m. UTC | #2
On 12/10/2021 10:13, Tomi Valkeinen wrote:
> On 23/09/2021 10:06, Neil Armstrong wrote:
>> From: Benoit Parrot <bparrot@ti.com>
>>
>> In preparation to add omap plane state specific extensions we need to
>> subclass drm_plane_state and add the relevant helpers.
>>
>> The addition of specific extension will be done separately.
>>
>> Signed-off-by: Benoit Parrot <bparrot@ti.com>
>> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
>> ---
>>   drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++---
>>   1 file changed, 35 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c
>> index 0df5381cc015..bda794b4c915 100644
>> --- a/drivers/gpu/drm/omapdrm/omap_plane.c
>> +++ b/drivers/gpu/drm/omapdrm/omap_plane.c
>> @@ -16,6 +16,13 @@
>>    * plane funcs
>>    */
>>   +#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base)
>> +
>> +struct omap_plane_state {
>> +    /* Must be first. */
>> +    struct drm_plane_state base;
>> +};
>> +
>>   #define to_omap_plane(x) container_of(x, struct omap_plane, base)
>>     struct omap_plane {
>> @@ -207,11 +214,17 @@ void omap_plane_install_properties(struct drm_plane *plane,
>>   static void omap_plane_reset(struct drm_plane *plane)
>>   {
>>       struct omap_plane *omap_plane = to_omap_plane(plane);
>> +    struct omap_plane_state *omap_state;
>>   -    drm_atomic_helper_plane_reset(plane);
>> -    if (!plane->state)
>> +    if (plane->state)
>> +        drm_atomic_helper_plane_destroy_state(plane, plane->state);
>> +
>> +    omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL);
>> +    if (!omap_state)
>>           return;
>>   +    __drm_atomic_helper_plane_reset(plane, &omap_state->base);
>> +
>>       /*
>>        * Set the zpos default depending on whether we are a primary or overlay
>>        * plane.
>> @@ -222,6 +235,25 @@ static void omap_plane_reset(struct drm_plane *plane)
>>       plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE;
>>   }
>>   +static struct drm_plane_state *
>> +omap_plane_atomic_duplicate_state(struct drm_plane *plane)
>> +{
>> +    struct omap_plane_state *state;
>> +    struct omap_plane_state *copy;
>> +
>> +    if (WARN_ON(!plane->state))
>> +        return NULL;
>> +
>> +    state = to_omap_plane_state(plane->state);
>> +    copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
>> +    if (!copy)
>> +        return NULL;
>> +
>> +    __drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
>> +
>> +    return &copy->base;
>> +}
>> +
> 
> omap_crtc.c has similar, but slightly different, functions. I think it would be good to use the same style in omap_plane, or, if the approach above is better, change omap_crtc to match the style here.

Indeed the crtc version is better, I used the same style.

Thanks,
Neil

> 
>  Tomi
diff mbox series

Patch

diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c b/drivers/gpu/drm/omapdrm/omap_plane.c
index 0df5381cc015..bda794b4c915 100644
--- a/drivers/gpu/drm/omapdrm/omap_plane.c
+++ b/drivers/gpu/drm/omapdrm/omap_plane.c
@@ -16,6 +16,13 @@ 
  * plane funcs
  */
 
+#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base)
+
+struct omap_plane_state {
+	/* Must be first. */
+	struct drm_plane_state base;
+};
+
 #define to_omap_plane(x) container_of(x, struct omap_plane, base)
 
 struct omap_plane {
@@ -207,11 +214,17 @@  void omap_plane_install_properties(struct drm_plane *plane,
 static void omap_plane_reset(struct drm_plane *plane)
 {
 	struct omap_plane *omap_plane = to_omap_plane(plane);
+	struct omap_plane_state *omap_state;
 
-	drm_atomic_helper_plane_reset(plane);
-	if (!plane->state)
+	if (plane->state)
+		drm_atomic_helper_plane_destroy_state(plane, plane->state);
+
+	omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL);
+	if (!omap_state)
 		return;
 
+	__drm_atomic_helper_plane_reset(plane, &omap_state->base);
+
 	/*
 	 * Set the zpos default depending on whether we are a primary or overlay
 	 * plane.
@@ -222,6 +235,25 @@  static void omap_plane_reset(struct drm_plane *plane)
 	plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE;
 }
 
+static struct drm_plane_state *
+omap_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+	struct omap_plane_state *state;
+	struct omap_plane_state *copy;
+
+	if (WARN_ON(!plane->state))
+		return NULL;
+
+	state = to_omap_plane_state(plane->state);
+	copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
+	if (!copy)
+		return NULL;
+
+	__drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
+
+	return &copy->base;
+}
+
 static int omap_plane_atomic_set_property(struct drm_plane *plane,
 					  struct drm_plane_state *state,
 					  struct drm_property *property,
@@ -257,7 +289,7 @@  static const struct drm_plane_funcs omap_plane_funcs = {
 	.disable_plane = drm_atomic_helper_disable_plane,
 	.reset = omap_plane_reset,
 	.destroy = omap_plane_destroy,
-	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
+	.atomic_duplicate_state = omap_plane_atomic_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 	.atomic_set_property = omap_plane_atomic_set_property,
 	.atomic_get_property = omap_plane_atomic_get_property,