* [PATCH drm-misc-next v2 1/3] drm: verisilicon: make vs_format conversion function return int
2026-03-05 7:59 [PATCH drm-misc-next v2 0/3] drm: verisilicon: convert drm_format to vs_format in atomic_check Icenowy Zheng
@ 2026-03-05 7:59 ` Icenowy Zheng
2026-03-05 10:18 ` Thomas Zimmermann
2026-03-05 7:59 ` [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state Icenowy Zheng
2026-03-05 8:09 ` [PATCH drm-misc-next v2 3/3] drm: verisilicon: fill plane's vs_format in atomic_check Icenowy Zheng
2 siblings, 1 reply; 8+ messages in thread
From: Icenowy Zheng @ 2026-03-05 7:59 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Icenowy Zheng, Icenowy Zheng
This is for further proper invalid drm_format handling before committing
the plane state change.
The return value is not yet checked yet, and will be checked in
atomic_check in the future.
Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
---
Changes in v2:
- Move a bogus #include clause to the next patch.
drivers/gpu/drm/verisilicon/vs_plane.c | 6 ++++--
drivers/gpu/drm/verisilicon/vs_plane.h | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c b/drivers/gpu/drm/verisilicon/vs_plane.c
index 2f3953e588a34..fa88ed14e41d7 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_plane.c
@@ -12,7 +12,7 @@
#include "vs_plane.h"
-void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
+int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
{
switch (drm_format) {
case DRM_FORMAT_XRGB4444:
@@ -62,7 +62,7 @@ void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
vs_format->color = VSDC_COLOR_FORMAT_A2R10G10B10;
break;
default:
- pr_warn("Unexpected drm format!\n");
+ return -EINVAL;
}
switch (drm_format) {
@@ -101,6 +101,8 @@ void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
/* N/A for non-YUV formats */
vs_format->uv_swizzle = false;
+
+ return 0;
}
dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
index 41875ea3d66a5..a88cc19f2202e 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.h
+++ b/drivers/gpu/drm/verisilicon/vs_plane.h
@@ -63,7 +63,7 @@ struct vs_format {
bool uv_swizzle;
};
-void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
+int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
const struct drm_rect *src_rect);
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH drm-misc-next v2 1/3] drm: verisilicon: make vs_format conversion function return int
2026-03-05 7:59 ` [PATCH drm-misc-next v2 1/3] drm: verisilicon: make vs_format conversion function return int Icenowy Zheng
@ 2026-03-05 10:18 ` Thomas Zimmermann
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Zimmermann @ 2026-03-05 10:18 UTC (permalink / raw)
To: Icenowy Zheng, Maarten Lankhorst, Maxime Ripard, David Airlie,
Simona Vetter
Cc: dri-devel, linux-kernel, Icenowy Zheng
Hi
Am 05.03.26 um 08:59 schrieb Icenowy Zheng:
> This is for further proper invalid drm_format handling before committing
> the plane state change.
>
> The return value is not yet checked yet, and will be checked in
> atomic_check in the future.
>
> Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
> Changes in v2:
> - Move a bogus #include clause to the next patch.
>
> drivers/gpu/drm/verisilicon/vs_plane.c | 6 ++++--
> drivers/gpu/drm/verisilicon/vs_plane.h | 2 +-
> 2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c b/drivers/gpu/drm/verisilicon/vs_plane.c
> index 2f3953e588a34..fa88ed14e41d7 100644
> --- a/drivers/gpu/drm/verisilicon/vs_plane.c
> +++ b/drivers/gpu/drm/verisilicon/vs_plane.c
> @@ -12,7 +12,7 @@
>
> #include "vs_plane.h"
>
> -void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
> +int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
> {
> switch (drm_format) {
> case DRM_FORMAT_XRGB4444:
> @@ -62,7 +62,7 @@ void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
> vs_format->color = VSDC_COLOR_FORMAT_A2R10G10B10;
> break;
> default:
> - pr_warn("Unexpected drm format!\n");
> + return -EINVAL;
> }
>
> switch (drm_format) {
> @@ -101,6 +101,8 @@ void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format)
>
> /* N/A for non-YUV formats */
> vs_format->uv_swizzle = false;
> +
> + return 0;
> }
>
> dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
> diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
> index 41875ea3d66a5..a88cc19f2202e 100644
> --- a/drivers/gpu/drm/verisilicon/vs_plane.h
> +++ b/drivers/gpu/drm/verisilicon/vs_plane.h
> @@ -63,7 +63,7 @@ struct vs_format {
> bool uv_swizzle;
> };
>
> -void drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
> +int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
> dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
> const struct drm_rect *src_rect);
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state
2026-03-05 7:59 [PATCH drm-misc-next v2 0/3] drm: verisilicon: convert drm_format to vs_format in atomic_check Icenowy Zheng
2026-03-05 7:59 ` [PATCH drm-misc-next v2 1/3] drm: verisilicon: make vs_format conversion function return int Icenowy Zheng
@ 2026-03-05 7:59 ` Icenowy Zheng
2026-03-05 10:34 ` Thomas Zimmermann
2026-03-05 8:09 ` [PATCH drm-misc-next v2 3/3] drm: verisilicon: fill plane's vs_format in atomic_check Icenowy Zheng
2 siblings, 1 reply; 8+ messages in thread
From: Icenowy Zheng @ 2026-03-05 7:59 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Icenowy Zheng, Icenowy Zheng
Create a subclass of drm_plane_state to store hardware-specific state
information (e.g. hardware plane format settings) in the future.
Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
---
Changes in v2:
- Add the #include clause for atomic state helpers, which was wrongly
placed in the previous patch in v1.
- Switch to kzalloc_obj helper for allocating the state.
drivers/gpu/drm/verisilicon/vs_plane.c | 41 +++++++++++++++++++
drivers/gpu/drm/verisilicon/vs_plane.h | 14 +++++++
.../gpu/drm/verisilicon/vs_primary_plane.c | 6 +--
3 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c b/drivers/gpu/drm/verisilicon/vs_plane.c
index fa88ed14e41d7..2fd4fb2a9591c 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_plane.c
@@ -6,6 +6,7 @@
#include <linux/errno.h>
#include <linux/printk.h>
+#include <drm/drm_atomic_state_helper.h>
#include <drm/drm_fb_dma_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_gem_dma_helper.h>
@@ -124,3 +125,43 @@ dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
return dma_addr;
}
+
+struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane)
+{
+ struct vs_plane_state *vs_state;
+
+ if (WARN_ON(!plane->state))
+ return NULL;
+
+ vs_state = kmemdup(plane->state, sizeof(*vs_state), GFP_KERNEL);
+ if (!vs_state)
+ return NULL;
+
+ __drm_atomic_helper_plane_duplicate_state(plane, &vs_state->base);
+
+ return &vs_state->base;
+}
+
+void vs_plane_destroy_state(struct drm_plane *plane,
+ struct drm_plane_state *state)
+{
+ __drm_atomic_helper_plane_destroy_state(state);
+ kfree(state);
+}
+
+/* Called during init to allocate the plane's atomic state. */
+void vs_plane_reset(struct drm_plane *plane)
+{
+ struct vs_plane_state *vs_state;
+
+ if (plane->state)
+ __drm_atomic_helper_plane_destroy_state(plane->state);
+
+ kfree(plane->state);
+
+ vs_state = kzalloc_obj(*vs_state, GFP_KERNEL);
+ if (!vs_state)
+ return;
+
+ __drm_atomic_helper_plane_reset(plane, &vs_state->base);
+}
diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
index a88cc19f2202e..12848a72af576 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.h
+++ b/drivers/gpu/drm/verisilicon/vs_plane.h
@@ -63,10 +63,24 @@ struct vs_format {
bool uv_swizzle;
};
+struct vs_plane_state {
+ struct drm_plane_state base;
+};
+
+static inline struct vs_plane_state *state_to_vs_plane_state(struct drm_plane_state *state)
+{
+ return container_of(state, struct vs_plane_state, base);
+}
+
int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
const struct drm_rect *src_rect);
+struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane);
+void vs_plane_destroy_state(struct drm_plane *plane,
+ struct drm_plane_state *state);
+void vs_plane_reset(struct drm_plane *plane);
+
struct drm_plane *vs_primary_plane_init(struct drm_device *dev, struct vs_dc *dc);
#endif /* _VS_PLANE_H_ */
diff --git a/drivers/gpu/drm/verisilicon/vs_primary_plane.c b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
index e8fcb5958615c..bad0bc5e3242d 100644
--- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
@@ -145,10 +145,10 @@ static const struct drm_plane_helper_funcs vs_primary_plane_helper_funcs = {
};
static const struct drm_plane_funcs vs_primary_plane_funcs = {
- .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
- .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
+ .atomic_destroy_state = vs_plane_destroy_state,
+ .atomic_duplicate_state = vs_plane_duplicate_state,
.disable_plane = drm_atomic_helper_disable_plane,
- .reset = drm_atomic_helper_plane_reset,
+ .reset = vs_plane_reset,
.update_plane = drm_atomic_helper_update_plane,
};
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state
2026-03-05 7:59 ` [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state Icenowy Zheng
@ 2026-03-05 10:34 ` Thomas Zimmermann
2026-03-05 14:06 ` Icenowy Zheng
0 siblings, 1 reply; 8+ messages in thread
From: Thomas Zimmermann @ 2026-03-05 10:34 UTC (permalink / raw)
To: Icenowy Zheng, Maarten Lankhorst, Maxime Ripard, David Airlie,
Simona Vetter
Cc: dri-devel, linux-kernel, Icenowy Zheng
Hi
Am 05.03.26 um 08:59 schrieb Icenowy Zheng:
> Create a subclass of drm_plane_state to store hardware-specific state
> information (e.g. hardware plane format settings) in the future.
>
> Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
> ---
> Changes in v2:
> - Add the #include clause for atomic state helpers, which was wrongly
> placed in the previous patch in v1.
> - Switch to kzalloc_obj helper for allocating the state.
>
> drivers/gpu/drm/verisilicon/vs_plane.c | 41 +++++++++++++++++++
> drivers/gpu/drm/verisilicon/vs_plane.h | 14 +++++++
> .../gpu/drm/verisilicon/vs_primary_plane.c | 6 +--
> 3 files changed, 58 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c b/drivers/gpu/drm/verisilicon/vs_plane.c
> index fa88ed14e41d7..2fd4fb2a9591c 100644
> --- a/drivers/gpu/drm/verisilicon/vs_plane.c
> +++ b/drivers/gpu/drm/verisilicon/vs_plane.c
> @@ -6,6 +6,7 @@
> #include <linux/errno.h>
> #include <linux/printk.h>
>
> +#include <drm/drm_atomic_state_helper.h>
> #include <drm/drm_fb_dma_helper.h>
> #include <drm/drm_fourcc.h>
> #include <drm/drm_gem_dma_helper.h>
> @@ -124,3 +125,43 @@ dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
>
> return dma_addr;
> }
> +
> +struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane)
> +{
> + struct vs_plane_state *vs_state;
> +
> + if (WARN_ON(!plane->state))
drm_WARN_ON() here. You can use plane->dev for the first argument.
> + return NULL;
> +
> + vs_state = kmemdup(plane->state, sizeof(*vs_state), GFP_KERNEL);
Not wrong, but I'd advise against memdup() because it doesn't understand
copy-ing semantics of the data structures. And some fields should maybe
not be copied.
I'd rather use kzalloc_obj() and then ...
> + if (!vs_state)
> + return NULL;
> +
> + __drm_atomic_helper_plane_duplicate_state(plane, &vs_state->base);
... assign the fields manually after this call. That makes is clear
what's copied and sets the remaining bits to zero.
> +
> + return &vs_state->base;
> +}
> +
> +void vs_plane_destroy_state(struct drm_plane *plane,
> + struct drm_plane_state *state)
> +{
> + __drm_atomic_helper_plane_destroy_state(state);
> + kfree(state);
> +}
> +
> +/* Called during init to allocate the plane's atomic state. */
> +void vs_plane_reset(struct drm_plane *plane)
> +{
> + struct vs_plane_state *vs_state;
> +
> + if (plane->state)
> + __drm_atomic_helper_plane_destroy_state(plane->state);
> +
> + kfree(plane->state);
You can move this line into the conditional branch.
> +
> + vs_state = kzalloc_obj(*vs_state, GFP_KERNEL);
> + if (!vs_state)
> + return;
> +
> + __drm_atomic_helper_plane_reset(plane, &vs_state->base);
> +}
> diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
> index a88cc19f2202e..12848a72af576 100644
> --- a/drivers/gpu/drm/verisilicon/vs_plane.h
> +++ b/drivers/gpu/drm/verisilicon/vs_plane.h
> @@ -63,10 +63,24 @@ struct vs_format {
> bool uv_swizzle;
> };
>
> +struct vs_plane_state {
> + struct drm_plane_state base;
> +};
> +
> +static inline struct vs_plane_state *state_to_vs_plane_state(struct drm_plane_state *state)
Maybe 'plane_state_to_vs_plane_state' oj just 'to_vs_plane_state'.
Best regards
Thomas
> +{
> + return container_of(state, struct vs_plane_state, base);
> +}
> +
> int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
> dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
> const struct drm_rect *src_rect);
>
> +struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane);
> +void vs_plane_destroy_state(struct drm_plane *plane,
> + struct drm_plane_state *state);
> +void vs_plane_reset(struct drm_plane *plane);
> +
> struct drm_plane *vs_primary_plane_init(struct drm_device *dev, struct vs_dc *dc);
>
> #endif /* _VS_PLANE_H_ */
> diff --git a/drivers/gpu/drm/verisilicon/vs_primary_plane.c b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> index e8fcb5958615c..bad0bc5e3242d 100644
> --- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> +++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> @@ -145,10 +145,10 @@ static const struct drm_plane_helper_funcs vs_primary_plane_helper_funcs = {
> };
>
> static const struct drm_plane_funcs vs_primary_plane_funcs = {
> - .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
> - .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
> + .atomic_destroy_state = vs_plane_destroy_state,
> + .atomic_duplicate_state = vs_plane_duplicate_state,
> .disable_plane = drm_atomic_helper_disable_plane,
> - .reset = drm_atomic_helper_plane_reset,
> + .reset = vs_plane_reset,
> .update_plane = drm_atomic_helper_update_plane,
> };
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state
2026-03-05 10:34 ` Thomas Zimmermann
@ 2026-03-05 14:06 ` Icenowy Zheng
0 siblings, 0 replies; 8+ messages in thread
From: Icenowy Zheng @ 2026-03-05 14:06 UTC (permalink / raw)
To: Thomas Zimmermann, Maarten Lankhorst, Maxime Ripard,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel
在 2026-03-05四的 11:34 +0100,Thomas Zimmermann写道:
> Hi
>
> Am 05.03.26 um 08:59 schrieb Icenowy Zheng:
> > Create a subclass of drm_plane_state to store hardware-specific
> > state
> > information (e.g. hardware plane format settings) in the future.
> >
> > Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
> > ---
> > Changes in v2:
> > - Add the #include clause for atomic state helpers, which was
> > wrongly
> > placed in the previous patch in v1.
> > - Switch to kzalloc_obj helper for allocating the state.
> >
> > drivers/gpu/drm/verisilicon/vs_plane.c | 41
> > +++++++++++++++++++
> > drivers/gpu/drm/verisilicon/vs_plane.h | 14 +++++++
> > .../gpu/drm/verisilicon/vs_primary_plane.c | 6 +--
> > 3 files changed, 58 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c
> > b/drivers/gpu/drm/verisilicon/vs_plane.c
> > index fa88ed14e41d7..2fd4fb2a9591c 100644
> > --- a/drivers/gpu/drm/verisilicon/vs_plane.c
> > +++ b/drivers/gpu/drm/verisilicon/vs_plane.c
> > @@ -6,6 +6,7 @@
> > #include <linux/errno.h>
> > #include <linux/printk.h>
> >
> > +#include <drm/drm_atomic_state_helper.h>
> > #include <drm/drm_fb_dma_helper.h>
> > #include <drm/drm_fourcc.h>
> > #include <drm/drm_gem_dma_helper.h>
> > @@ -124,3 +125,43 @@ dma_addr_t vs_fb_get_dma_addr(struct
> > drm_framebuffer *fb,
> >
> > return dma_addr;
> > }
> > +
> > +struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane
> > *plane)
> > +{
> > + struct vs_plane_state *vs_state;
> > +
> > + if (WARN_ON(!plane->state))
>
> drm_WARN_ON() here. You can use plane->dev for the first argument.
Sounds right.
>
> > + return NULL;
> > +
> > + vs_state = kmemdup(plane->state, sizeof(*vs_state),
> > GFP_KERNEL);
>
> Not wrong, but I'd advise against memdup() because it doesn't
> understand
> copy-ing semantics of the data structures. And some fields should
> maybe
> not be copied.
>
> I'd rather use kzalloc_obj() and then ...
>
> > + if (!vs_state)
> > + return NULL;
> > +
> > + __drm_atomic_helper_plane_duplicate_state(plane,
> > &vs_state->base);
>
> ... assign the fields manually after this call. That makes is clear
> what's copied and sets the remaining bits to zero.
Okay. The AST demo you showed me in PATCH 3 seems to be quite
followable.
> > +
> > + return &vs_state->base;
> > +}
> > +
> > +void vs_plane_destroy_state(struct drm_plane *plane,
> > + struct drm_plane_state *state)
> > +{
> > + __drm_atomic_helper_plane_destroy_state(state);
> > + kfree(state);
> > +}
> > +
> > +/* Called during init to allocate the plane's atomic state. */
> > +void vs_plane_reset(struct drm_plane *plane)
> > +{
> > + struct vs_plane_state *vs_state;
> > +
> > + if (plane->state)
> > + __drm_atomic_helper_plane_destroy_state(plane-
> > >state);
> > +
> > + kfree(plane->state);
>
> You can move this line into the conditional branch.
Yes, this sounds more natural (although I followed what vc4 driver does
here).
>
> > +
> > + vs_state = kzalloc_obj(*vs_state, GFP_KERNEL);
> > + if (!vs_state)
> > + return;
> > +
> > + __drm_atomic_helper_plane_reset(plane, &vs_state->base);
> > +}
> > diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h
> > b/drivers/gpu/drm/verisilicon/vs_plane.h
> > index a88cc19f2202e..12848a72af576 100644
> > --- a/drivers/gpu/drm/verisilicon/vs_plane.h
> > +++ b/drivers/gpu/drm/verisilicon/vs_plane.h
> > @@ -63,10 +63,24 @@ struct vs_format {
> > bool uv_swizzle;
> > };
> >
> > +struct vs_plane_state {
> > + struct drm_plane_state base;
> > +};
> > +
> > +static inline struct vs_plane_state
> > *state_to_vs_plane_state(struct drm_plane_state *state)
>
> Maybe 'plane_state_to_vs_plane_state' oj just 'to_vs_plane_state'.
I will pick the latter. I think I removed `plane_` because of the
function name being too long.
Thanks,
Icenowy
>
> Best regards
> Thomas
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH drm-misc-next v2 3/3] drm: verisilicon: fill plane's vs_format in atomic_check
2026-03-05 7:59 [PATCH drm-misc-next v2 0/3] drm: verisilicon: convert drm_format to vs_format in atomic_check Icenowy Zheng
2026-03-05 7:59 ` [PATCH drm-misc-next v2 1/3] drm: verisilicon: make vs_format conversion function return int Icenowy Zheng
2026-03-05 7:59 ` [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state Icenowy Zheng
@ 2026-03-05 8:09 ` Icenowy Zheng
2026-03-05 11:36 ` Thomas Zimmermann
2 siblings, 1 reply; 8+ messages in thread
From: Icenowy Zheng @ 2026-03-05 8:09 UTC (permalink / raw)
To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, Icenowy Zheng, Icenowy Zheng
Move the conversion from drm_format to vs_format to atomic_check, which
is before the point of no return and can properly bail out.
Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
---
Changes in v2:
- Add non-NULL check for drm_plane_state->fb.
drivers/gpu/drm/verisilicon/vs_plane.h | 2 ++
.../gpu/drm/verisilicon/vs_primary_plane.c | 21 ++++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
index 12848a72af576..df4b248b52954 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.h
+++ b/drivers/gpu/drm/verisilicon/vs_plane.h
@@ -65,6 +65,8 @@ struct vs_format {
struct vs_plane_state {
struct drm_plane_state base;
+
+ struct vs_format format;
};
static inline struct vs_plane_state *state_to_vs_plane_state(struct drm_plane_state *state)
diff --git a/drivers/gpu/drm/verisilicon/vs_primary_plane.c b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
index bad0bc5e3242d..ca41c8053ae12 100644
--- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
@@ -25,12 +25,20 @@ static int vs_primary_plane_atomic_check(struct drm_plane *plane,
{
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
plane);
+ struct vs_plane_state *new_vs_plane_state = state_to_vs_plane_state(new_plane_state);
struct drm_crtc *crtc = new_plane_state->crtc;
+ struct drm_framebuffer *fb = new_plane_state->fb;
struct drm_crtc_state *crtc_state;
+ int ret;
- if (!crtc)
+ if (!crtc || !fb)
return 0;
+ ret = drm_format_to_vs_format(fb->format->format,
+ &new_vs_plane_state->format);
+ if (ret)
+ return ret;
+
crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
if (WARN_ON(!crtc_state))
return -EINVAL;
@@ -88,11 +96,11 @@ static void vs_primary_plane_atomic_update(struct drm_plane *plane,
{
struct drm_plane_state *state = drm_atomic_get_new_plane_state(atomic_state,
plane);
+ struct vs_plane_state *vs_state = state_to_vs_plane_state(state);
struct drm_framebuffer *fb = state->fb;
struct drm_crtc *crtc = state->crtc;
struct vs_dc *dc;
struct vs_crtc *vcrtc;
- struct vs_format fmt;
unsigned int output;
dma_addr_t dma_addr;
@@ -105,16 +113,15 @@ static void vs_primary_plane_atomic_update(struct drm_plane *plane,
output = vcrtc->id;
dc = vcrtc->dc;
- drm_format_to_vs_format(state->fb->format->format, &fmt);
-
regmap_update_bits(dc->regs, VSDC_FB_CONFIG(output),
VSDC_FB_CONFIG_FMT_MASK,
- VSDC_FB_CONFIG_FMT(fmt.color));
+ VSDC_FB_CONFIG_FMT(vs_state->format.color));
regmap_update_bits(dc->regs, VSDC_FB_CONFIG(output),
VSDC_FB_CONFIG_SWIZZLE_MASK,
- VSDC_FB_CONFIG_SWIZZLE(fmt.swizzle));
+ VSDC_FB_CONFIG_SWIZZLE(vs_state->format.swizzle));
regmap_assign_bits(dc->regs, VSDC_FB_CONFIG(output),
- VSDC_FB_CONFIG_UV_SWIZZLE_EN, fmt.uv_swizzle);
+ VSDC_FB_CONFIG_UV_SWIZZLE_EN,
+ vs_state->format.uv_swizzle);
dma_addr = vs_fb_get_dma_addr(fb, &state->src);
--
2.52.0
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH drm-misc-next v2 3/3] drm: verisilicon: fill plane's vs_format in atomic_check
2026-03-05 8:09 ` [PATCH drm-misc-next v2 3/3] drm: verisilicon: fill plane's vs_format in atomic_check Icenowy Zheng
@ 2026-03-05 11:36 ` Thomas Zimmermann
0 siblings, 0 replies; 8+ messages in thread
From: Thomas Zimmermann @ 2026-03-05 11:36 UTC (permalink / raw)
To: Icenowy Zheng, Maarten Lankhorst, Maxime Ripard, David Airlie,
Simona Vetter
Cc: dri-devel, linux-kernel, Icenowy Zheng
Hi
Am 05.03.26 um 09:09 schrieb Icenowy Zheng:
> Move the conversion from drm_format to vs_format to atomic_check, which
> is before the point of no return and can properly bail out.
>
> Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
> ---
> Changes in v2:
> - Add non-NULL check for drm_plane_state->fb.
>
> drivers/gpu/drm/verisilicon/vs_plane.h | 2 ++
> .../gpu/drm/verisilicon/vs_primary_plane.c | 21 ++++++++++++-------
> 2 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
> index 12848a72af576..df4b248b52954 100644
> --- a/drivers/gpu/drm/verisilicon/vs_plane.h
> +++ b/drivers/gpu/drm/verisilicon/vs_plane.h
> @@ -65,6 +65,8 @@ struct vs_format {
>
> struct vs_plane_state {
> struct drm_plane_state base;
> +
> + struct vs_format format;
In case you implement my comment about kzalloc vs kmemdup, don't forget
to assign it in the plane-duplicate helper.
> };
>
> static inline struct vs_plane_state *state_to_vs_plane_state(struct drm_plane_state *state)
> diff --git a/drivers/gpu/drm/verisilicon/vs_primary_plane.c b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> index bad0bc5e3242d..ca41c8053ae12 100644
> --- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> +++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
> @@ -25,12 +25,20 @@ static int vs_primary_plane_atomic_check(struct drm_plane *plane,
> {
> struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
> plane);
> + struct vs_plane_state *new_vs_plane_state = state_to_vs_plane_state(new_plane_state);
> struct drm_crtc *crtc = new_plane_state->crtc;
> + struct drm_framebuffer *fb = new_plane_state->fb;
> struct drm_crtc_state *crtc_state;
> + int ret;
>
> - if (!crtc)
> + if (!crtc || !fb)
> return 0;
I see that even the original code was not correct.
You have to call drm_atomic_helper_check_plane_state() in any case. If
there's no CRTC, use NULL for the CRTC state. See [1] for an example.
>
> + ret = drm_format_to_vs_format(fb->format->format,
> + &new_vs_plane_state->format);
> + if (ret)
> + return ret;
> +
That should also only happen after
drm_atomic_helper_check_plane_state(). You can again take the code
around [1] for an example.
[1]
https://elixir.bootlin.com/linux/v7.0-rc1/source/drivers/gpu/drm/ast/ast_mode.c#L504
I think it makes sense to warn once if the conversion fails. After all,
the driver should only export DRM formats that it can program to hardware.
if (drm_WARN_ON_ONCE(plane->dev, ret))
return ret;
> crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
> if (WARN_ON(!crtc_state))
> return -EINVAL;
> @@ -88,11 +96,11 @@ static void vs_primary_plane_atomic_update(struct drm_plane *plane,
> {
> struct drm_plane_state *state = drm_atomic_get_new_plane_state(atomic_state,
> plane);
> + struct vs_plane_state *vs_state = state_to_vs_plane_state(state);
> struct drm_framebuffer *fb = state->fb;
> struct drm_crtc *crtc = state->crtc;
> struct vs_dc *dc;
> struct vs_crtc *vcrtc;
> - struct vs_format fmt;
> unsigned int output;
> dma_addr_t dma_addr;
>
> @@ -105,16 +113,15 @@ static void vs_primary_plane_atomic_update(struct drm_plane *plane,
> output = vcrtc->id;
> dc = vcrtc->dc;
>
> - drm_format_to_vs_format(state->fb->format->format, &fmt);
Removing another possible failure from the atomic commit is really nice.
Best regards
Thomas
> -
> regmap_update_bits(dc->regs, VSDC_FB_CONFIG(output),
> VSDC_FB_CONFIG_FMT_MASK,
> - VSDC_FB_CONFIG_FMT(fmt.color));
> + VSDC_FB_CONFIG_FMT(vs_state->format.color));
> regmap_update_bits(dc->regs, VSDC_FB_CONFIG(output),
> VSDC_FB_CONFIG_SWIZZLE_MASK,
> - VSDC_FB_CONFIG_SWIZZLE(fmt.swizzle));
> + VSDC_FB_CONFIG_SWIZZLE(vs_state->format.swizzle));
> regmap_assign_bits(dc->regs, VSDC_FB_CONFIG(output),
> - VSDC_FB_CONFIG_UV_SWIZZLE_EN, fmt.uv_swizzle);
> + VSDC_FB_CONFIG_UV_SWIZZLE_EN,
> + vs_state->format.uv_swizzle);
>
> dma_addr = vs_fb_get_dma_addr(fb, &state->src);
>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
^ permalink raw reply [flat|nested] 8+ messages in thread