From: Sam Ravnborg <sam@ravnborg.org>
To: "Noralf Trønnes" <noralf@tronnes.org>
Cc: dri-devel@lists.freedesktop.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH 07/10] drm/format-helper: Add drm_fb_swab()
Date: Sun, 3 May 2020 12:29:59 +0200 [thread overview]
Message-ID: <20200503102959.GA17117@ravnborg.org> (raw)
In-Reply-To: <20200429124830.27475-8-noralf@tronnes.org>
Hi Noralf
On Wed, Apr 29, 2020 at 02:48:27PM +0200, Noralf Trønnes wrote:
> This replaces drm_fb_swab16() with drm_fb_swab() supporting 16 and 32-bit.
> Also make pixel line caching optional.
>
> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
A couple of nits, with these considered:
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
> ---
> drivers/gpu/drm/drm_format_helper.c | 61 +++++++++++++++++++----------
> drivers/gpu/drm/drm_mipi_dbi.c | 2 +-
> include/drm/drm_format_helper.h | 4 +-
> 3 files changed, 44 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> index 0897cb9aeaff..5c147c49668c 100644
> --- a/drivers/gpu/drm/drm_format_helper.c
> +++ b/drivers/gpu/drm/drm_format_helper.c
> @@ -79,39 +79,60 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
> EXPORT_SYMBOL(drm_fb_memcpy_dstclip);
>
> /**
> - * drm_fb_swab16 - Swap bytes into clip buffer
> - * @dst: RGB565 destination buffer
> - * @vaddr: RGB565 source buffer
> + * drm_fb_swab - Swap bytes into clip buffer
> + * @dst: Destination buffer
> + * @src: Source buffer
> * @fb: DRM framebuffer
> * @clip: Clip rectangle area to copy
> + * @cached: Source buffer is mapped cached (eg. not write-combined)
> + *
> + * If @cached is false a temporary buffer is used to cache one pixel line at a
> + * time to speed up slow uncached reads.
> + *
> + * This function does not apply clipping on dst, i.e. the destination
> + * is a small buffer containing the clip rect only.
> */
> -void drm_fb_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
> - struct drm_rect *clip)
> +void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
> + struct drm_rect *clip, bool cached)
> {
> - size_t len = (clip->x2 - clip->x1) * sizeof(u16);
> + u8 cpp = fb->format->cpp[0];
Use of format->cpp is deprecated, should be char_per_block according to
the comment in drm_fourcc.h
> + size_t len = drm_rect_width(clip) * cpp;
> + u16 *src16, *dst16 = dst;
> + u32 *src32, *dst32 = dst;
> unsigned int x, y;
> - u16 *src, *buf;
> + void *buf = NULL;
>
> - /*
> - * The cma memory is write-combined so reads are uncached.
> - * Speed up by fetching one line at a time.
> - */
> - buf = kmalloc(len, GFP_KERNEL);
> - if (!buf)
> + if (WARN_ON_ONCE(cpp == 1))
> return;
Or cpp != 2 && cpp != 4?
>
> + if (!cached)
> + buf = kmalloc(len, GFP_KERNEL);
> +
> + src += clip_offset(clip, fb->pitches[0], cpp);
Good that drm_rect_width() and clip_offset() are used,
replacing open-coded variants.
> +
> for (y = clip->y1; y < clip->y2; y++) {
> - src = vaddr + (y * fb->pitches[0]);
> - src += clip->x1;
> - memcpy(buf, src, len);
> - src = buf;
> - for (x = clip->x1; x < clip->x2; x++)
> - *dst++ = swab16(*src++);
> + if (buf) {
> + memcpy(buf, src, len);
> + src16 = buf;
> + src32 = buf;
> + } else {
> + src16 = src;
> + src32 = src;
> + }
> +
> + for (x = clip->x1; x < clip->x2; x++) {
> + if (cpp == 4)
> + *dst32++ = swab32(*src32++);
> + else
> + *dst16++ = swab16(*src16++);
> + }
> +
> + src += fb->pitches[0];
> }
>
> kfree(buf);
> }
> -EXPORT_SYMBOL(drm_fb_swab16);
> +EXPORT_SYMBOL(drm_fb_swab);
>
> static void drm_fb_xrgb8888_to_rgb565_line(u16 *dbuf, u32 *sbuf,
> unsigned int pixels,
> diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
> index 16bff1be4b8a..bfefbcb69287 100644
> --- a/drivers/gpu/drm/drm_mipi_dbi.c
> +++ b/drivers/gpu/drm/drm_mipi_dbi.c
> @@ -217,7 +217,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
> switch (fb->format->format) {
> case DRM_FORMAT_RGB565:
> if (swap)
> - drm_fb_swab16(dst, src, fb, clip);
> + drm_fb_swab(dst, src, fb, clip, !import_attach);
> else
> drm_fb_memcpy(dst, src, fb, clip);
> break;
> diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
> index ac220aa1a245..5f9e37032468 100644
> --- a/include/drm/drm_format_helper.h
> +++ b/include/drm/drm_format_helper.h
> @@ -14,8 +14,8 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
> void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
> struct drm_framebuffer *fb,
> struct drm_rect *clip);
> -void drm_fb_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
> - struct drm_rect *clip);
> +void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
> + struct drm_rect *clip, bool cached);
> void drm_fb_xrgb8888_to_rgb565(void *dst, void *vaddr,
> struct drm_framebuffer *fb,
> struct drm_rect *clip, bool swab);
> --
> 2.23.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
WARNING: multiple messages have this Message-ID (diff)
From: Sam Ravnborg <sam@ravnborg.org>
To: "Noralf Trønnes" <noralf@tronnes.org>
Cc: linux-usb@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 07/10] drm/format-helper: Add drm_fb_swab()
Date: Sun, 3 May 2020 12:29:59 +0200 [thread overview]
Message-ID: <20200503102959.GA17117@ravnborg.org> (raw)
In-Reply-To: <20200429124830.27475-8-noralf@tronnes.org>
Hi Noralf
On Wed, Apr 29, 2020 at 02:48:27PM +0200, Noralf Trønnes wrote:
> This replaces drm_fb_swab16() with drm_fb_swab() supporting 16 and 32-bit.
> Also make pixel line caching optional.
>
> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
A couple of nits, with these considered:
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
> ---
> drivers/gpu/drm/drm_format_helper.c | 61 +++++++++++++++++++----------
> drivers/gpu/drm/drm_mipi_dbi.c | 2 +-
> include/drm/drm_format_helper.h | 4 +-
> 3 files changed, 44 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> index 0897cb9aeaff..5c147c49668c 100644
> --- a/drivers/gpu/drm/drm_format_helper.c
> +++ b/drivers/gpu/drm/drm_format_helper.c
> @@ -79,39 +79,60 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
> EXPORT_SYMBOL(drm_fb_memcpy_dstclip);
>
> /**
> - * drm_fb_swab16 - Swap bytes into clip buffer
> - * @dst: RGB565 destination buffer
> - * @vaddr: RGB565 source buffer
> + * drm_fb_swab - Swap bytes into clip buffer
> + * @dst: Destination buffer
> + * @src: Source buffer
> * @fb: DRM framebuffer
> * @clip: Clip rectangle area to copy
> + * @cached: Source buffer is mapped cached (eg. not write-combined)
> + *
> + * If @cached is false a temporary buffer is used to cache one pixel line at a
> + * time to speed up slow uncached reads.
> + *
> + * This function does not apply clipping on dst, i.e. the destination
> + * is a small buffer containing the clip rect only.
> */
> -void drm_fb_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
> - struct drm_rect *clip)
> +void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
> + struct drm_rect *clip, bool cached)
> {
> - size_t len = (clip->x2 - clip->x1) * sizeof(u16);
> + u8 cpp = fb->format->cpp[0];
Use of format->cpp is deprecated, should be char_per_block according to
the comment in drm_fourcc.h
> + size_t len = drm_rect_width(clip) * cpp;
> + u16 *src16, *dst16 = dst;
> + u32 *src32, *dst32 = dst;
> unsigned int x, y;
> - u16 *src, *buf;
> + void *buf = NULL;
>
> - /*
> - * The cma memory is write-combined so reads are uncached.
> - * Speed up by fetching one line at a time.
> - */
> - buf = kmalloc(len, GFP_KERNEL);
> - if (!buf)
> + if (WARN_ON_ONCE(cpp == 1))
> return;
Or cpp != 2 && cpp != 4?
>
> + if (!cached)
> + buf = kmalloc(len, GFP_KERNEL);
> +
> + src += clip_offset(clip, fb->pitches[0], cpp);
Good that drm_rect_width() and clip_offset() are used,
replacing open-coded variants.
> +
> for (y = clip->y1; y < clip->y2; y++) {
> - src = vaddr + (y * fb->pitches[0]);
> - src += clip->x1;
> - memcpy(buf, src, len);
> - src = buf;
> - for (x = clip->x1; x < clip->x2; x++)
> - *dst++ = swab16(*src++);
> + if (buf) {
> + memcpy(buf, src, len);
> + src16 = buf;
> + src32 = buf;
> + } else {
> + src16 = src;
> + src32 = src;
> + }
> +
> + for (x = clip->x1; x < clip->x2; x++) {
> + if (cpp == 4)
> + *dst32++ = swab32(*src32++);
> + else
> + *dst16++ = swab16(*src16++);
> + }
> +
> + src += fb->pitches[0];
> }
>
> kfree(buf);
> }
> -EXPORT_SYMBOL(drm_fb_swab16);
> +EXPORT_SYMBOL(drm_fb_swab);
>
> static void drm_fb_xrgb8888_to_rgb565_line(u16 *dbuf, u32 *sbuf,
> unsigned int pixels,
> diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
> index 16bff1be4b8a..bfefbcb69287 100644
> --- a/drivers/gpu/drm/drm_mipi_dbi.c
> +++ b/drivers/gpu/drm/drm_mipi_dbi.c
> @@ -217,7 +217,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
> switch (fb->format->format) {
> case DRM_FORMAT_RGB565:
> if (swap)
> - drm_fb_swab16(dst, src, fb, clip);
> + drm_fb_swab(dst, src, fb, clip, !import_attach);
> else
> drm_fb_memcpy(dst, src, fb, clip);
> break;
> diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
> index ac220aa1a245..5f9e37032468 100644
> --- a/include/drm/drm_format_helper.h
> +++ b/include/drm/drm_format_helper.h
> @@ -14,8 +14,8 @@ void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
> void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
> struct drm_framebuffer *fb,
> struct drm_rect *clip);
> -void drm_fb_swab16(u16 *dst, void *vaddr, struct drm_framebuffer *fb,
> - struct drm_rect *clip);
> +void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
> + struct drm_rect *clip, bool cached);
> void drm_fb_xrgb8888_to_rgb565(void *dst, void *vaddr,
> struct drm_framebuffer *fb,
> struct drm_rect *clip, bool swab);
> --
> 2.23.0
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-05-03 10:30 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 12:48 [PATCH 00/10] Generic USB Display driver Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 01/10] backlight: Add backlight_device_get_by_name() Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-04-30 8:32 ` Lee Jones
2020-04-30 8:32 ` Lee Jones
2020-04-30 9:20 ` Noralf Trønnes
2020-04-30 9:20 ` Noralf Trønnes
2020-04-30 10:15 ` Lee Jones
2020-04-30 10:15 ` Lee Jones
2020-04-30 10:42 ` Noralf Trønnes
2020-04-30 10:42 ` Noralf Trønnes
2020-04-30 14:02 ` Daniel Vetter
2020-04-30 14:02 ` Daniel Vetter
2020-05-04 7:10 ` Lee Jones
2020-05-04 7:10 ` Lee Jones
2020-05-03 7:13 ` Sam Ravnborg
2020-05-03 7:13 ` Sam Ravnborg
2020-04-29 12:48 ` [PATCH 02/10] drm: Add backlight helper Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-04-29 14:13 ` Hans de Goede
2020-04-29 14:13 ` Hans de Goede
2020-04-29 18:40 ` Noralf Trønnes
2020-04-29 18:40 ` Noralf Trønnes
2020-04-30 15:36 ` Hans de Goede
2020-04-30 15:36 ` Hans de Goede
2020-05-04 12:06 ` Daniel Vetter
2020-05-04 12:06 ` Daniel Vetter
2020-05-04 15:54 ` Noralf Trønnes
2020-05-04 15:54 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 03/10] drm/client: Add drm_client_init_from_id() Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 04/10] drm/client: Add drm_client_framebuffer_flush() Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-05-03 7:48 ` Sam Ravnborg
2020-05-03 7:48 ` Sam Ravnborg
2020-05-03 9:54 ` Noralf Trønnes
2020-05-03 9:54 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 05/10] drm/client: Add drm_client_modeset_check() Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-05-03 8:03 ` Sam Ravnborg
2020-05-03 8:03 ` Sam Ravnborg
2020-05-03 10:02 ` Noralf Trønnes
2020-05-03 10:02 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 06/10] drm/client: Add a way to set modeset, properties and rotation Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-05-03 8:47 ` Sam Ravnborg
2020-05-03 8:47 ` Sam Ravnborg
2020-05-03 10:50 ` Noralf Trønnes
2020-05-03 10:50 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 07/10] drm/format-helper: Add drm_fb_swab() Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-05-03 10:29 ` Sam Ravnborg [this message]
2020-05-03 10:29 ` Sam Ravnborg
2020-05-03 13:38 ` Noralf Trønnes
2020-05-03 13:38 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 08/10] drm: Add Generic USB Display driver Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-05-02 17:58 ` Noralf Trønnes
2020-05-02 17:58 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 09/10] drm/gud: Add functionality for the USB gadget side Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-04-29 12:48 ` [PATCH 10/10] usb: gadget: function: Add Generic USB Display support Noralf Trønnes
2020-04-29 12:48 ` Noralf Trønnes
2020-05-01 13:22 ` [PATCH 00/10] Generic USB Display driver Noralf Trønnes
2020-05-01 13:22 ` Noralf Trønnes
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=20200503102959.GA17117@ravnborg.org \
--to=sam@ravnborg.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-usb@vger.kernel.org \
--cc=noralf@tronnes.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.