From nobody Mon Jun 22 23:37:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 263ACC433FE for ; Tue, 15 Mar 2022 11:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347844AbiCOLIt (ORCPT ); Tue, 15 Mar 2022 07:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238350AbiCOLIf (ORCPT ); Tue, 15 Mar 2022 07:08:35 -0400 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95A7F4C438 for ; Tue, 15 Mar 2022 04:07:21 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:1dc0:e57f:6975:ecb9]) by albert.telenet-ops.be with bizsmtp id 6b7H2700E3jtd4z06b7H0s; Tue, 15 Mar 2022 12:07:19 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nU51I-004XNs-Uq; Tue, 15 Mar 2022 12:07:16 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nU51I-002dR1-9h; Tue, 15 Mar 2022 12:07:16 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Cc: Andy Shevchenko , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/5] drm/format-helper: Rename drm_fb_xrgb8888_to_mono_reversed() Date: Tue, 15 Mar 2022 12:07:03 +0100 Message-Id: <20220315110707.628166-2-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315110707.628166-1-geert@linux-m68k.org> References: <20220315110707.628166-1-geert@linux-m68k.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There is no "reversed" handling in drm_fb_xrgb8888_to_mono_reversed(): the function just converts from color to grayscale, and reduces the number of grayscale levels from 256 to 2 (i.e. brightness 0-127 is mapped to 0, 128-255 to 1). All "reversed" handling is done in the repaper driver, where this function originated. Hence make this clear by renaming drm_fb_xrgb8888_to_mono_reversed() to drm_fb_xrgb8888_to_mono(), and documenting the black/white pixel mapping. Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_re= versed()") Signed-off-by: Geert Uytterhoeven Acked-by: Javier Martinez Canillas Reviewed-by: Andy Shevchenko --- drivers/gpu/drm/drm_format_helper.c | 32 ++++++++++++++--------------- drivers/gpu/drm/solomon/ssd130x.c | 2 +- drivers/gpu/drm/tiny/repaper.c | 2 +- include/drm/drm_format_helper.h | 5 ++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_form= at_helper.c index bc0f49773868a9b0..b68aa857c6514529 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -594,8 +594,8 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int ds= t_pitch, uint32_t dst_for } EXPORT_SYMBOL(drm_fb_blit_toio); =20 -static void drm_fb_gray8_to_mono_reversed_line(u8 *dst, const u8 *src, uns= igned int pixels, - unsigned int start_offset, unsigned int end_len) +static void drm_fb_gray8_to_mono_line(u8 *dst, const u8 *src, unsigned int= pixels, + unsigned int start_offset, unsigned int end_len) { unsigned int xb, i; =20 @@ -621,8 +621,8 @@ static void drm_fb_gray8_to_mono_reversed_line(u8 *dst,= const u8 *src, unsigned } =20 /** - * drm_fb_xrgb8888_to_mono_reversed - Convert XRGB8888 to reversed monochr= ome - * @dst: reversed monochrome destination buffer + * drm_fb_xrgb8888_to_mono - Convert XRGB8888 to monochrome + * @dst: monochrome destination buffer (0=3Dblack, 1=3Dwhite) * @dst_pitch: Number of bytes between two consecutive scanlines within dst * @src: XRGB8888 source buffer * @fb: DRM framebuffer @@ -633,10 +633,10 @@ static void drm_fb_gray8_to_mono_reversed_line(u8 *ds= t, const u8 *src, unsigned * and use this function to convert to the native format. * * This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale a= nd - * then the result is converted from grayscale to reversed monohrome. + * then the result is converted from grayscale to monochrome. */ -void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, c= onst void *vaddr, - const struct drm_framebuffer *fb, const struct drm_rect *clip) +void drm_fb_xrgb8888_to_mono(void *dst, unsigned int dst_pitch, const void= *vaddr, + const struct drm_framebuffer *fb, const struct drm_rect *clip) { unsigned int linepixels =3D drm_rect_width(clip); unsigned int lines =3D clip->y2 - clip->y1; @@ -652,8 +652,8 @@ void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsign= ed int dst_pitch, const v return; =20 /* - * The reversed mono destination buffer contains 1 bit per pixel - * and destination scanlines have to be in multiple of 8 pixels. + * The mono destination buffer contains 1 bit per pixel and + * destination scanlines have to be in multiple of 8 pixels. */ if (!dst_pitch) dst_pitch =3D DIV_ROUND_UP(linepixels, 8); @@ -664,9 +664,9 @@ void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsign= ed int dst_pitch, const v * The cma memory is write-combined so reads are uncached. * Speed up by fetching one line at a time. * - * Also, format conversion from XR24 to reversed monochrome - * are done line-by-line but are converted to 8-bit grayscale - * as an intermediate step. + * Also, format conversion from XR24 to monochrome are done + * line-by-line but are converted to 8-bit grayscale as an + * intermediate step. * * Allocate a buffer to be used for both copying from the cma * memory and to store the intermediate grayscale line pixels. @@ -683,7 +683,7 @@ void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsign= ed int dst_pitch, const v * are not aligned to multiple of 8. * * Calculate if the start and end pixels are not aligned and set the - * offsets for the reversed mono line conversion function to adjust. + * offsets for the mono line conversion function to adjust. */ start_offset =3D clip->x1 % 8; end_len =3D clip->x2 % 8; @@ -692,12 +692,12 @@ void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsi= gned int dst_pitch, const v for (y =3D 0; y < lines; y++) { src32 =3D memcpy(src32, vaddr, len_src32); drm_fb_xrgb8888_to_gray8_line(gray8, src32, linepixels); - drm_fb_gray8_to_mono_reversed_line(mono, gray8, dst_pitch, - start_offset, end_len); + drm_fb_gray8_to_mono_line(mono, gray8, dst_pitch, start_offset, + end_len); vaddr +=3D fb->pitches[0]; mono +=3D dst_pitch; } =20 kfree(src32); } -EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono_reversed); +EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono); diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index d08d86ef07bcbe7f..caee851efd5726e7 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -458,7 +458,7 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer = *fb, const struct iosys_m if (!buf) return -ENOMEM; =20 - drm_fb_xrgb8888_to_mono_reversed(buf, 0, vmap, fb, rect); + drm_fb_xrgb8888_to_mono(buf, 0, vmap, fb, rect); =20 ssd130x_update_rect(ssd130x, buf, rect); =20 diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c index 37b6bb90e46e1fe8..a096fb8b83e99dc8 100644 --- a/drivers/gpu/drm/tiny/repaper.c +++ b/drivers/gpu/drm/tiny/repaper.c @@ -540,7 +540,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb) if (ret) goto out_free; =20 - drm_fb_xrgb8888_to_mono_reversed(buf, 0, cma_obj->vaddr, fb, &clip); + drm_fb_xrgb8888_to_mono(buf, 0, cma_obj->vaddr, fb, &clip); =20 drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); =20 diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helpe= r.h index 0b0937c0b2f6324e..55145eca07828321 100644 --- a/include/drm/drm_format_helper.h +++ b/include/drm/drm_format_helper.h @@ -43,8 +43,7 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_= pitch, uint32_t dst_for const void *vmap, const struct drm_framebuffer *fb, const struct drm_rect *rect); =20 -void drm_fb_xrgb8888_to_mono_reversed(void *dst, unsigned int dst_pitch, c= onst void *src, - const struct drm_framebuffer *fb, - const struct drm_rect *clip); +void drm_fb_xrgb8888_to_mono(void *dst, unsigned int dst_pitch, const void= *src, + const struct drm_framebuffer *fb, const struct drm_rect *clip); =20 #endif /* __LINUX_DRM_FORMAT_HELPER_H */ --=20 2.25.1 From nobody Mon Jun 22 23:37:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06306C433F5 for ; Tue, 15 Mar 2022 11:07:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347824AbiCOLIj (ORCPT ); Tue, 15 Mar 2022 07:08:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235343AbiCOLIe (ORCPT ); Tue, 15 Mar 2022 07:08:34 -0400 Received: from albert.telenet-ops.be (albert.telenet-ops.be [IPv6:2a02:1800:110:4::f00:1a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 864714C40F for ; Tue, 15 Mar 2022 04:07:21 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:1dc0:e57f:6975:ecb9]) by albert.telenet-ops.be with bizsmtp id 6b7H270093jtd4z06b7H0q; Tue, 15 Mar 2022 12:07:19 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nU51I-004XNt-Oc; Tue, 15 Mar 2022 12:07:16 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nU51I-002dR7-AW; Tue, 15 Mar 2022 12:07:16 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Cc: Andy Shevchenko , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/5] drm/format-helper: Fix XRGB888 to monochrome conversion Date: Tue, 15 Mar 2022 12:07:04 +0100 Message-Id: <20220315110707.628166-3-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315110707.628166-1-geert@linux-m68k.org> References: <20220315110707.628166-1-geert@linux-m68k.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The conversion functions drm_fb_xrgb8888_to_mono() and drm_fb_gray8_to_mono_line() do not behave correctly when the horizontal boundaries of the clip rectangle are not multiples of 8: a. When x1 % 8 !=3D 0, the calculated pitch is not correct, b. When x2 % 8 !=3D 0, the pixel data for the last byte is wrong. Simplify the code and fix (a) by: 1. Removing start_offset, and always storing the first pixel in the first bit of the monochrome destination buffer. Drivers that require the first pixel in a byte to be located at an x-coordinate that is a multiple of 8 can always align the clip rectangle before calling drm_fb_xrgb8888_to_mono(). Note that: - The ssd130x driver does not need the alignment, as the monochrome buffer is a temporary format, - The repaper driver always updates the full screen, so the clip rectangle is always aligned. 2. Passing the number of pixels to drm_fb_gray8_to_mono_line(), instead of the number of bytes, and the number of pixels in the last byte. Fix (b) by explicitly setting the target bit, instead of always setting bit 7 and shifting the value in each loop iteration. Remove the bogus pitch check, which operates on bytes instead of pixels, and triggers when e.g. flashing the cursor on a text console with a font that is 8 pixels wide. Drop the confusing comment about scanlines, as a pitch in bytes always contains a multiple of 8 pixels. While at it, use the drm_rect_height() helper instead of open-coding the same operation. Update the comments accordingly. Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_re= versed()") Signed-off-by: Geert Uytterhoeven Acked-by: Javier Martinez Canillas Reviewed-by: Andy Shevchenko --- I tried hard to fix this in small steps, but everything was no intertangled that this turned out to be unfeasible. Note that making these changes does not introduce regressions in the ssd130x driver, as the latter is broken for x1 !=3D 0 or y1 !=3D 0 anyway. --- drivers/gpu/drm/drm_format_helper.c | 56 ++++++++++------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_form= at_helper.c index b68aa857c6514529..0d7cae921ed1134f 100644 --- a/drivers/gpu/drm/drm_format_helper.c +++ b/drivers/gpu/drm/drm_format_helper.c @@ -594,27 +594,16 @@ int drm_fb_blit_toio(void __iomem *dst, unsigned int = dst_pitch, uint32_t dst_for } EXPORT_SYMBOL(drm_fb_blit_toio); =20 -static void drm_fb_gray8_to_mono_line(u8 *dst, const u8 *src, unsigned int= pixels, - unsigned int start_offset, unsigned int end_len) -{ - unsigned int xb, i; - - for (xb =3D 0; xb < pixels; xb++) { - unsigned int start =3D 0, end =3D 8; - u8 byte =3D 0x00; - - if (xb =3D=3D 0 && start_offset) - start =3D start_offset; =20 - if (xb =3D=3D pixels - 1 && end_len) - end =3D end_len; - - for (i =3D start; i < end; i++) { - unsigned int x =3D xb * 8 + i; +static void drm_fb_gray8_to_mono_line(u8 *dst, const u8 *src, unsigned int= pixels) +{ + while (pixels) { + unsigned int i, bits =3D min(pixels, 8U); + u8 byte =3D 0; =20 - byte >>=3D 1; - if (src[x] >> 7) - byte |=3D BIT(7); + for (i =3D 0; i < bits; i++, pixels--) { + if (*src++ & BIT(7)) + byte |=3D BIT(i); } *dst++ =3D byte; } @@ -634,16 +623,22 @@ static void drm_fb_gray8_to_mono_line(u8 *dst, const = u8 *src, unsigned int pixel * * This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale a= nd * then the result is converted from grayscale to monochrome. + * + * The first pixel (upper left corner of the clip rectangle) will be conve= rted + * and copied to the first bit (LSB) in the first byte of the monochrome + * destination buffer. + * If the caller requires that the first pixel in a byte must be located a= t an + * x-coordinate that is a multiple of 8, then the caller must take care it= self + * of supplying a suitable clip rectangle. */ void drm_fb_xrgb8888_to_mono(void *dst, unsigned int dst_pitch, const void= *vaddr, const struct drm_framebuffer *fb, const struct drm_rect *clip) { unsigned int linepixels =3D drm_rect_width(clip); - unsigned int lines =3D clip->y2 - clip->y1; + unsigned int lines =3D drm_rect_height(clip); unsigned int cpp =3D fb->format->cpp[0]; unsigned int len_src32 =3D linepixels * cpp; struct drm_device *dev =3D fb->dev; - unsigned int start_offset, end_len; unsigned int y; u8 *mono =3D dst, *gray8; u32 *src32; @@ -652,14 +647,11 @@ void drm_fb_xrgb8888_to_mono(void *dst, unsigned int = dst_pitch, const void *vadd return; =20 /* - * The mono destination buffer contains 1 bit per pixel and - * destination scanlines have to be in multiple of 8 pixels. + * The mono destination buffer contains 1 bit per pixel */ if (!dst_pitch) dst_pitch =3D DIV_ROUND_UP(linepixels, 8); =20 - drm_WARN_ONCE(dev, dst_pitch % 8 !=3D 0, "dst_pitch is not a multiple of = 8\n"); - /* * The cma memory is write-combined so reads are uncached. * Speed up by fetching one line at a time. @@ -677,23 +669,11 @@ void drm_fb_xrgb8888_to_mono(void *dst, unsigned int = dst_pitch, const void *vadd =20 gray8 =3D (u8 *)src32 + len_src32; =20 - /* - * For damage handling, it is possible that only parts of the source - * buffer is copied and this could lead to start and end pixels that - * are not aligned to multiple of 8. - * - * Calculate if the start and end pixels are not aligned and set the - * offsets for the mono line conversion function to adjust. - */ - start_offset =3D clip->x1 % 8; - end_len =3D clip->x2 % 8; - vaddr +=3D clip_offset(clip, fb->pitches[0], cpp); for (y =3D 0; y < lines; y++) { src32 =3D memcpy(src32, vaddr, len_src32); drm_fb_xrgb8888_to_gray8_line(gray8, src32, linepixels); - drm_fb_gray8_to_mono_line(mono, gray8, dst_pitch, start_offset, - end_len); + drm_fb_gray8_to_mono_line(mono, gray8, linepixels); vaddr +=3D fb->pitches[0]; mono +=3D dst_pitch; } --=20 2.25.1 From nobody Mon Jun 22 23:37:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D651C433F5 for ; Tue, 15 Mar 2022 11:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347878AbiCOLIz (ORCPT ); Tue, 15 Mar 2022 07:08:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347521AbiCOLIf (ORCPT ); Tue, 15 Mar 2022 07:08:35 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95B964C43E for ; Tue, 15 Mar 2022 04:07:21 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:1dc0:e57f:6975:ecb9]) by laurent.telenet-ops.be with bizsmtp id 6b7H2700K3jtd4z01b7H5E; Tue, 15 Mar 2022 12:07:19 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nU51I-004XNu-Us; Tue, 15 Mar 2022 12:07:16 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nU51I-002dRD-BO; Tue, 15 Mar 2022 12:07:16 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Cc: Andy Shevchenko , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/5] drm: ssd130x: Fix rectangle updates Date: Tue, 15 Mar 2022 12:07:05 +0100 Message-Id: <20220315110707.628166-4-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315110707.628166-1-geert@linux-m68k.org> References: <20220315110707.628166-1-geert@linux-m68k.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The rectangle update functions ssd130x_fb_blit_rect() and ssd130x_update_rect() do not behave correctly when x1 !=3D 0 or y1 !=3D 0, or when y1 or y2 are not aligned to display page boundaries. E.g. when used as a text console, only the first line of text is shown on the display. 1. The buffer passed by ssd130x_fb_blit_rect() points to the first byte of monochrome bitmap data, and thus has its origin at (x1, y1), while ssd130x_update_rect() assumes it is at (0, 0). Fix ssd130x_update_rect() by changing the vertical and horizontal loop ranges, and adding the offsets only when needed. 2. In ssd130x_fb_blit_rect(), align y1 and y2 to the display page boundaries before doing the color conversion, so the full page is converted and updated. Remove the correction for an unaligned y1 from ssd130x_update_rect(), and add a check to make sure y1 is aligned. Fixes: a61732e808672cfa ("drm: Add driver for Solomon SSD130x OLED displays= ") Signed-off-by: Geert Uytterhoeven Acked-by: Javier Martinez Canillas --- Note that instead of calling drm_fb_xrgb8888_to_mono() and transposing the bitmap, the image data could be converted to the transposed format directly. However, that would preclude exposing a monochrome format to userspace when a fourcc for such a monochrome format is introduced. --- drivers/gpu/drm/solomon/ssd130x.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index caee851efd5726e7..7c99af4ce9dd4e5c 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -355,11 +355,14 @@ static int ssd130x_update_rect(struct ssd130x_device = *ssd130x, u8 *buf, unsigned int width =3D drm_rect_width(rect); unsigned int height =3D drm_rect_height(rect); unsigned int line_length =3D DIV_ROUND_UP(width, 8); - unsigned int pages =3D DIV_ROUND_UP(y % 8 + height, 8); + unsigned int pages =3D DIV_ROUND_UP(height, 8); + struct drm_device *drm =3D &ssd130x->drm; u32 array_idx =3D 0; int ret, i, j, k; u8 *data_array =3D NULL; =20 + drm_WARN_ONCE(drm, y % 8 !=3D 0, "y must be aligned to screen page\n"); + data_array =3D kcalloc(width, pages, GFP_KERNEL); if (!data_array) return -ENOMEM; @@ -401,13 +404,13 @@ static int ssd130x_update_rect(struct ssd130x_device = *ssd130x, u8 *buf, if (ret < 0) goto out_free; =20 - for (i =3D y / 8; i < y / 8 + pages; i++) { + for (i =3D 0; i < pages; i++) { int m =3D 8; =20 /* Last page may be partial */ - if (8 * (i + 1) > ssd130x->height) + if (8 * (y / 8 + i + 1) > ssd130x->height) m =3D ssd130x->height % 8; - for (j =3D x; j < x + width; j++) { + for (j =3D 0; j < width; j++) { u8 data =3D 0; =20 for (k =3D 0; k < m; k++) { @@ -454,6 +457,10 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer= *fb, const struct iosys_m int ret =3D 0; u8 *buf =3D NULL; =20 + /* Align y to display page boundaries */ + rect->y1 =3D round_down(rect->y1, 8); + rect->y2 =3D min_t(unsigned int, round_up(rect->y2, 8), ssd130x->height); + buf =3D kcalloc(fb->width, fb->height, GFP_KERNEL); if (!buf) return -ENOMEM; --=20 2.25.1 From nobody Mon Jun 22 23:37:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C22BC433F5 for ; Tue, 15 Mar 2022 11:07:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347832AbiCOLIv (ORCPT ); Tue, 15 Mar 2022 07:08:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236116AbiCOLIf (ORCPT ); Tue, 15 Mar 2022 07:08:35 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 954AC4C429 for ; Tue, 15 Mar 2022 04:07:21 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:1dc0:e57f:6975:ecb9]) by laurent.telenet-ops.be with bizsmtp id 6b7H2700U3jtd4z01b7H5H; Tue, 15 Mar 2022 12:07:19 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nU51J-004XNv-1l; Tue, 15 Mar 2022 12:07:17 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nU51I-002dRK-C8; Tue, 15 Mar 2022 12:07:16 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Cc: Andy Shevchenko , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 4/5] drm: ssd130x: Reduce temporary buffer sizes Date: Tue, 15 Mar 2022 12:07:06 +0100 Message-Id: <20220315110707.628166-5-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315110707.628166-1-geert@linux-m68k.org> References: <20220315110707.628166-1-geert@linux-m68k.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" ssd130x_clear_screen() allocates a temporary buffer sized to hold one byte per pixel, while it only needs to hold one bit per pixel. ssd130x_fb_blit_rect() allocates a temporary buffer sized to hold one byte per pixel for the whole frame buffer, while it only needs to hold one bit per pixel for the part that is to be updated. Pass dst_pitch to drm_fb_xrgb8888_to_mono_reversed(), as we have already calculated it anyway. Fixes: a61732e808672cfa ("drm: Add driver for Solomon SSD130x OLED displays= ") Signed-off-by: Geert Uytterhoeven Acked-by: Javier Martinez Canillas --- drivers/gpu/drm/solomon/ssd130x.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index 7c99af4ce9dd4e5c..38b6c2c14f53644b 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -440,7 +440,8 @@ static void ssd130x_clear_screen(struct ssd130x_device = *ssd130x) .y2 =3D ssd130x->height, }; =20 - buf =3D kcalloc(ssd130x->width, ssd130x->height, GFP_KERNEL); + buf =3D kcalloc(DIV_ROUND_UP(ssd130x->width, 8), ssd130x->height, + GFP_KERNEL); if (!buf) return; =20 @@ -454,6 +455,7 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer = *fb, const struct iosys_m { struct ssd130x_device *ssd130x =3D drm_to_ssd130x(fb->dev); void *vmap =3D map->vaddr; /* TODO: Use mapping abstraction properly */ + unsigned int dst_pitch; int ret =3D 0; u8 *buf =3D NULL; =20 @@ -461,11 +463,12 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffe= r *fb, const struct iosys_m rect->y1 =3D round_down(rect->y1, 8); rect->y2 =3D min_t(unsigned int, round_up(rect->y2, 8), ssd130x->height); =20 - buf =3D kcalloc(fb->width, fb->height, GFP_KERNEL); + dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), 8); + buf =3D kcalloc(dst_pitch, drm_rect_height(rect), GFP_KERNEL); if (!buf) return -ENOMEM; =20 - drm_fb_xrgb8888_to_mono(buf, 0, vmap, fb, rect); + drm_fb_xrgb8888_to_mono(buf, dst_pitch, vmap, fb, rect); =20 ssd130x_update_rect(ssd130x, buf, rect); =20 --=20 2.25.1 From nobody Mon Jun 22 23:37:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34376C433F5 for ; Tue, 15 Mar 2022 11:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347815AbiCOLIg (ORCPT ); Tue, 15 Mar 2022 07:08:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232769AbiCOLIe (ORCPT ); Tue, 15 Mar 2022 07:08:34 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F6D4C796 for ; Tue, 15 Mar 2022 04:07:21 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:1dc0:e57f:6975:ecb9]) by laurent.telenet-ops.be with bizsmtp id 6b7H2700Q3jtd4z01b7H5F; Tue, 15 Mar 2022 12:07:19 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nU51I-004XNw-WF; Tue, 15 Mar 2022 12:07:17 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nU51I-002dRR-Cr; Tue, 15 Mar 2022 12:07:16 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= Cc: Andy Shevchenko , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 5/5] drm/repaper: Reduce temporary buffer size in repaper_fb_dirty() Date: Tue, 15 Mar 2022 12:07:07 +0100 Message-Id: <20220315110707.628166-6-geert@linux-m68k.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220315110707.628166-1-geert@linux-m68k.org> References: <20220315110707.628166-1-geert@linux-m68k.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" As the temporary buffer is no longer used to store 8-bit grayscale data, its size can be reduced to the size needed to store the monochrome bitmap data. Fixes: 24c6bedefbe71de9 ("drm/repaper: Use format helper for xrgb8888 to mo= nochrome conversion") Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- Untested due to lack of hardware. I replaced kmalloc_array() by kmalloc() to match size calculations in other locations in this driver. There is no point in handling a possible multiplication overflow only here. --- drivers/gpu/drm/tiny/repaper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tiny/repaper.c b/drivers/gpu/drm/tiny/repaper.c index a096fb8b83e99dc8..7738b87f370ad147 100644 --- a/drivers/gpu/drm/tiny/repaper.c +++ b/drivers/gpu/drm/tiny/repaper.c @@ -530,7 +530,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb) DRM_DEBUG("Flushing [FB:%d] st=3D%ums\n", fb->base.id, epd->factored_stage_time); =20 - buf =3D kmalloc_array(fb->width, fb->height, GFP_KERNEL); + buf =3D kmalloc(fb->width * fb->height / 8, GFP_KERNEL); if (!buf) { ret =3D -ENOMEM; goto out_exit; --=20 2.25.1