mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Icenowy Zheng <uwu@icenowy.me>
To: Thomas Zimmermann <tzimmermann@suse.de>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	 David Airlie <airlied@gmail.com>,
	Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH drm-misc-next v2 2/3] drm: verisilicon: subclass drm_plane_state
Date: Thu, 05 Mar 2026 22:06:21 +0800	[thread overview]
Message-ID: <b7a49810a21fbc847dff5ec620386ae2c2d1f2a0.camel@icenowy.me> (raw)
In-Reply-To: <09840bc3-ccd8-439b-bf44-b61abab672b4@suse.de>

在 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

  reply	other threads:[~2026-03-05 14:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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 10:34   ` Thomas Zimmermann
2026-03-05 14:06     ` Icenowy Zheng [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b7a49810a21fbc847dff5ec620386ae2c2d1f2a0.camel@icenowy.me \
    --to=uwu@icenowy.me \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®