From: Paul Cercueil <paul@crapouillou.net>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
"H . Nikolaus Schaller" <hns@goldelico.com>,
Paul Boddie <paul@boddie.org.uk>,
list@opendingux.net, Sam Ravnborg <sam@ravnborg.org>,
linux-mips@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/8] drm/ingenic: Simplify code by using hwdescs array
Date: Mon, 09 Aug 2021 00:22:38 +0200 [thread overview]
Message-ID: <QTKJXQ.E7AFQWHL9BRJ3@crapouillou.net> (raw)
In-Reply-To: <d6db6de0-dcc8-b0f0-439d-7a5f69ac4c62@suse.de>
Hi Thomas,
Le dim., août 8 2021 at 20:42:53 +0200, Thomas Zimmermann
<tzimmermann@suse.de> a écrit :
> Hi
>
> Am 08.08.21 um 15:45 schrieb Paul Cercueil:
>> Instead of having one 'hwdesc' variable for the plane #0 and one for
>> the
>> plane #1, use a 'hwdesc[2]' array, where the DMA hardware descriptors
>> are indexed by the plane's number.
>>
>> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>> ---
>> drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 38
>> ++++++++++++-----------
>> 1 file changed, 20 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
>> b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
>> index e42eb43d8020..bc71ba44ccf4 100644
>> --- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
>> +++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
>> @@ -49,8 +49,7 @@ struct ingenic_dma_hwdesc {
>> } __aligned(16);
>> \x7f struct ingenic_dma_hwdescs {
>> - struct ingenic_dma_hwdesc hwdesc_f0;
>> - struct ingenic_dma_hwdesc hwdesc_f1;
>> + struct ingenic_dma_hwdesc hwdesc[2];
>> struct ingenic_dma_hwdesc hwdesc_pal;
>> u16 palette[256] __aligned(16);
>> };
>> @@ -141,6 +140,13 @@ static inline struct ingenic_drm
>> *drm_nb_get_priv(struct notifier_block *nb)
>> return container_of(nb, struct ingenic_drm, clock_nb);
>> }
>> \x7f+static inline dma_addr_t dma_hwdesc_addr(const struct
>> ingenic_drm *priv, bool use_f1)
>
> Using the plane index instead of a boolean would be more aligned to
> the way this function is being used.
Alright, I can do that.
>> +{
>> + u32 offset = offsetof(struct ingenic_dma_hwdescs, hwdesc[use_f1]);
>
> use_f1 is a function parameter. Is offsetof guaranteed to be
> evaluated at runtime?
The offsetof() macro could be defined like this:
#define offsetof(type, elm) ((size_t) &((type *) 0)->elm)
So I don't see a reason why this couldn't be evaluated at runtime, yes.
It's just that the value of "offset" is not known at compilation time
(unless the compiler does some constant propagation). In practice
though, this code works fine.
>> +
>> + return priv->dma_hwdescs_phys + offset;
>> +}
>> +
>> static int ingenic_drm_update_pixclk(struct notifier_block *nb,
>> unsigned long action,
>> void *data)
>> @@ -562,6 +568,7 @@ static void
>> ingenic_drm_plane_atomic_update(struct drm_plane *plane,
>> struct ingenic_dma_hwdesc *hwdesc;
>> unsigned int width, height, cpp, offset;
>> dma_addr_t addr;
>> + bool use_f1;
>> u32 fourcc;
>> \x7f if (newstate && newstate->fb) {
>> @@ -569,16 +576,14 @@ static void
>> ingenic_drm_plane_atomic_update(struct drm_plane *plane,
>> drm_fb_cma_sync_non_coherent(&priv->drm, oldstate, newstate);
>> \x7f crtc_state = newstate->crtc->state;
>> + use_f1 = priv->soc_info->has_osd && plane != &priv->f0;
>> \x7f addr = drm_fb_cma_get_gem_addr(newstate->fb, newstate, 0);
>> width = newstate->src_w >> 16;
>> height = newstate->src_h >> 16;
>> cpp = newstate->fb->format->cpp[0];
>> \x7f- if (!priv->soc_info->has_osd || plane == &priv->f0)
>> - hwdesc = &priv->dma_hwdescs->hwdesc_f0;
>> - else
>> - hwdesc = &priv->dma_hwdescs->hwdesc_f1;
>> + hwdesc = &priv->dma_hwdescs->hwdesc[use_f1];
>
> Maybe add a helper that looks up the hwdesc field for a given plane?
Sure.
>> \x7f hwdesc->addr = addr;
>> hwdesc->cmd = JZ_LCD_CMD_EOF_IRQ | (width * height * cpp / 4);
>> @@ -591,9 +596,9 @@ static void
>> ingenic_drm_plane_atomic_update(struct drm_plane *plane,
>> if (fourcc == DRM_FORMAT_C8)
>> offset = offsetof(struct ingenic_dma_hwdescs, hwdesc_pal);
>> else
>> - offset = offsetof(struct ingenic_dma_hwdescs, hwdesc_f0);
>> + offset = offsetof(struct ingenic_dma_hwdescs, hwdesc[0]);
>> \x7f- priv->dma_hwdescs->hwdesc_f0.next = priv->dma_hwdescs_phys +
>> offset;
>> + priv->dma_hwdescs->hwdesc[0].next = priv->dma_hwdescs_phys +
>> offset;
>
> Maybe priv->dma_hwdescs_phys + offset could be computed in a more
> flexible helper than dma_hwdesc_addr().
>
>> \x7f crtc_state->color_mgmt_changed = fourcc == DRM_FORMAT_C8;
>> }
>> @@ -964,20 +969,17 @@ static int ingenic_drm_bind(struct device
>> *dev, bool has_components)
>> \x7f \x7f /* Configure DMA hwdesc for foreground0 plane */
>> - dma_hwdesc_phys_f0 = priv->dma_hwdescs_phys
>> - + offsetof(struct ingenic_dma_hwdescs, hwdesc_f0);
>> - priv->dma_hwdescs->hwdesc_f0.next = dma_hwdesc_phys_f0;
>> - priv->dma_hwdescs->hwdesc_f0.id = 0xf0;
>> + dma_hwdesc_phys_f0 = dma_hwdesc_addr(priv, 0);
>> + priv->dma_hwdescs->hwdesc[0].next = dma_hwdesc_phys_f0;
>> + priv->dma_hwdescs->hwdesc[0].id = 0xf0;
>> \x7f /* Configure DMA hwdesc for foreground1 plane */
>> - dma_hwdesc_phys_f1 = priv->dma_hwdescs_phys
>> - + offsetof(struct ingenic_dma_hwdescs, hwdesc_f1);
>> - priv->dma_hwdescs->hwdesc_f1.next = dma_hwdesc_phys_f1;
>> - priv->dma_hwdescs->hwdesc_f1.id = 0xf1;
>> + dma_hwdesc_phys_f1 = dma_hwdesc_addr(priv, 1);
>> + priv->dma_hwdescs->hwdesc[1].next = dma_hwdesc_phys_f1;
>> + priv->dma_hwdescs->hwdesc[1].id = 0xf1;
>> \x7f /* Configure DMA hwdesc for palette */
>> - priv->dma_hwdescs->hwdesc_pal.next = priv->dma_hwdescs_phys
>> - + offsetof(struct ingenic_dma_hwdescs, hwdesc_f0);
>> + priv->dma_hwdescs->hwdesc_pal.next = dma_hwdesc_phys_f0;
>> priv->dma_hwdescs->hwdesc_pal.id = 0xc0;
>> priv->dma_hwdescs->hwdesc_pal.addr = priv->dma_hwdescs_phys
>> + offsetof(struct ingenic_dma_hwdescs, palette);
>>
>
> Could the setup in these three blocks be moved into a common helper?
Yes.
Thanks for the review.
Cheers,
-Paul
next prev parent reply other threads:[~2021-08-08 22:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-08 13:45 [PATCH 0/8] gpu/drm: ingenic-drm: Various improvements Paul Cercueil
2021-08-08 13:45 ` [PATCH 1/8] drm/ingenic: Remove dead code Paul Cercueil
2021-08-08 17:58 ` Thomas Zimmermann
2021-08-08 18:27 ` Joe Perches
2021-08-08 18:33 ` Paul Cercueil
2021-08-08 13:45 ` [PATCH 2/8] drm/ingenic: Simplify code by using hwdescs array Paul Cercueil
2021-08-08 18:42 ` Thomas Zimmermann
2021-08-08 22:22 ` Paul Cercueil [this message]
2021-08-08 13:45 ` [PATCH 3/8] drm/ingenic: Use standard drm_atomic_helper_commit_tail Paul Cercueil
2021-08-08 19:50 ` Christophe JAILLET
2021-08-08 20:09 ` Paul Cercueil
2021-08-08 20:15 ` Christophe JAILLET
2021-08-10 10:20 ` Daniel Vetter
2021-08-10 10:46 ` Paul Cercueil
2021-08-08 13:45 ` [PATCH 4/8] drm/ingenic: Add support for private objects Paul Cercueil
2021-08-08 13:45 ` [PATCH 5/8] drm/ingenic: Move IPU scale settings to private state Paul Cercueil
2021-08-08 13:45 ` [PATCH 6/8] drm/ingenic: Set DMA descriptor chain register when starting CRTC Paul Cercueil
2021-08-08 13:45 ` [PATCH 7/8] drm/ingenic: Upload palette before frame Paul Cercueil
2021-08-08 13:45 ` [PATCH 8/8] drm/ingenic: Attach bridge chain to encoders Paul Cercueil
2021-08-08 18:57 ` H. Nikolaus Schaller
2021-08-08 19:04 ` Paul Cercueil
2021-08-08 19:06 ` H. Nikolaus Schaller
2021-08-08 19:12 ` H. Nikolaus Schaller
2021-08-09 11:14 ` [Letux-kernel] " H. Nikolaus Schaller
2021-08-09 16:22 ` Paul Cercueil
2021-08-09 23:17 ` Paul Boddie
2021-08-10 7:52 ` Paul Cercueil
2021-08-10 21:15 ` Paul Boddie
2021-08-10 21:54 ` Paul Cercueil
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=QTKJXQ.E7AFQWHL9BRJ3@crapouillou.net \
--to=paul@crapouillou.net \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hns@goldelico.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=list@opendingux.net \
--cc=paul@boddie.org.uk \
--cc=sam@ravnborg.org \
--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®