From nobody Sat Feb 7 11:31:47 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 00C33C0015E for ; Thu, 13 Jul 2023 13:17:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235108AbjGMNRo (ORCPT ); Thu, 13 Jul 2023 09:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234791AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -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 1A689271F for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by laurent.telenet-ops.be with bizsmtp id LdHN2A00P3wy6xv01dHNpY; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gqo-0L; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyV-MV; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/8] drm/ssd130x: Fix pitch calculation in ssd130x_fb_blit_rect() Date: Thu, 13 Jul 2023 15:17:09 +0200 Message-Id: <54deec2ec533e90544faa8c60a0c2518c58f3e9c.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 page height must be taken into account only for vertical coordinates and heights, not for horizontal coordinates and widths. Fixes: 179a790aaf2a0127 ("drm/ssd130x: Set the page height value in the dev= ice info data") Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- drivers/gpu/drm/solomon/ssd130x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index afb08a8aa9fcdaf2..b4c376962629580b 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -596,7 +596,7 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer = *fb, const struct iosys_m rect->y1 =3D round_down(rect->y1, page_height); rect->y2 =3D min_t(unsigned int, round_up(rect->y2, page_height), ssd130x= ->height); =20 - dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), page_height); + dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), 8); =20 ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); if (ret) --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 542A7EB64DD for ; Thu, 13 Jul 2023 13:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234858AbjGMNR4 (ORCPT ); Thu, 13 Jul 2023 09:17:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234806AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A01E270D for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by michel.telenet-ops.be with bizsmtp id LdHN2A00Z3wy6xv06dHNad; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gqq-0u; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyY-N9; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/8] drm/dumb-buffers: Fix drm_mode_create_dumb() for bpp < 8 Date: Thu, 13 Jul 2023 15:17:10 +0200 Message-Id: <5ba8ac5e465121b646a59487dc75b27017e0c769.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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" drm_mode_create_dumb() calculates the number of characters per pixel from the number of bits per pixel by rounding up, which is not correct as the actual value of cpp may be non-integer. While we do not need to care here about complex formats like YUV, bpp < 8 is a valid use case. - The overflow check for the buffer width is not correct if bpp < 8. However, it doesn't hurt, as widths larger than U32_MAX / 8 should not happen for real anyway. Add a comment to clarify. - Calculating the stride from the number of characters per pixel is not correct. Fix this by calculating it from the number of bits per pixel instead. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- Why is drm_mode_create_dumb.size __u64? The test for "args->height > U32_MAX / stride" rejects all sizes not fitting in __u32 anyway. --- drivers/gpu/drm/drm_dumb_buffers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_dumb_buffers.c b/drivers/gpu/drm/drm_dumb_= buffers.c index 70032bba1c97e787..21a04c32a5e3d785 100644 --- a/drivers/gpu/drm/drm_dumb_buffers.c +++ b/drivers/gpu/drm/drm_dumb_buffers.c @@ -71,10 +71,11 @@ int drm_mode_create_dumb(struct drm_device *dev, /* overflow checks for 32bit size calculations */ if (args->bpp > U32_MAX - 8) return -EINVAL; + /* Incorrect (especially if bpp < 8), but doesn't hurt much */ cpp =3D DIV_ROUND_UP(args->bpp, 8); if (cpp > U32_MAX / args->width) return -EINVAL; - stride =3D cpp * args->width; + stride =3D DIV_ROUND_UP(args->bpp * args->width, 8); if (args->height > U32_MAX / stride) return -EINVAL; =20 --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 1FBF1EB64DD for ; Thu, 13 Jul 2023 13:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234695AbjGMNSK (ORCPT ); Thu, 13 Jul 2023 09:18:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234827AbjGMNRc (ORCPT ); Thu, 13 Jul 2023 09:17:32 -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 1A2DC2711 for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by laurent.telenet-ops.be with bizsmtp id LdHN2A00R3wy6xv01dHNpa; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gqu-1Z; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyd-No; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH/RFC 3/8] drm/ssd130x: Bail out early if data_array is not yet available Date: Thu, 13 Jul 2023 15:17:11 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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" Calling ssd130x_buf_alloc() from ssd130x_encoder_helper_atomic_enable() is too late, causing a NULL pointer dereference: ssd130x_update_rect.isra.0+0x13c/0x340 ssd130x_primary_plane_helper_atomic_update+0x26c/0x284 drm_atomic_helper_commit_planes+0xfc/0x27c Work around that by checking if data_array is valid. Obviously this needs a better fix... Fixes: 49d7d581ceaf4cf8 ("drm/ssd130x: Don't allocate buffers on each plane= update") Signed-off-by: Geert Uytterhoeven Tested-by: Javier Martinez Canillas --- drivers/gpu/drm/solomon/ssd130x.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index b4c376962629580b..8ef5f61854fd7340 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -481,6 +481,7 @@ static int ssd130x_update_rect(struct ssd130x_device *s= sd130x, struct drm_rect * u32 array_idx =3D 0; int ret, i, j, k; =20 +if (!data_array) { pr_info("%s: data_array not yet initialized\n", __func_= _); return 0; } drm_WARN_ONCE(drm, y % 8 !=3D 0, "y must be aligned to screen page\n"); =20 /* --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 B8531EB64DD for ; Thu, 13 Jul 2023 13:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235165AbjGMNR7 (ORCPT ); Thu, 13 Jul 2023 09:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234817AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -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 19DA1270B for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by laurent.telenet-ops.be with bizsmtp id LdHN2A00U3wy6xv01dHNpb; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gqw-2D; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyh-OV; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 4/8] drm/ssd130x: Add support for DRM_FORMAT_R1 Date: Thu, 13 Jul 2023 15:17:12 +0200 Message-Id: <72746f6d9c47f09fc057ad7a4bbb3b7f423af803.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 native display format is monochrome light-on-dark (R1). Hence add support for R1, so monochrome applications can avoid the overhead of back-and-forth conversions between R1 and XR24. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- This work interfered with commit 49d7d581ceaf4cf8 ("drm/ssd130x: Don't allocate buffers on each plane update") in drm-misc/for-linux-next, which always allocates the buffer upfront, while it is no longer needed when never using XR24. Probably ssd130x->buffer should be allocated on first use. And why not allocate the buffers using devm_kcalloc()? --- drivers/gpu/drm/solomon/ssd130x.c | 57 ++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index 8ef5f61854fd7340..130e33a1ba3cba00 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -466,15 +466,14 @@ static int ssd130x_init(struct ssd130x_device *ssd130= x) SSD130X_SET_ADDRESS_MODE_HORIZONTAL); } =20 -static int ssd130x_update_rect(struct ssd130x_device *ssd130x, struct drm_= rect *rect) +static int ssd130x_update_rect(struct ssd130x_device *ssd130x, u8 *buf, + unsigned int pitch, struct drm_rect *rect) { unsigned int x =3D rect->x1; unsigned int y =3D rect->y1; - u8 *buf =3D ssd130x->buffer; u8 *data_array =3D ssd130x->data_array; 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 page_height =3D ssd130x->device_info->page_height; unsigned int pages =3D DIV_ROUND_UP(height, page_height); struct drm_device *drm =3D &ssd130x->drm; @@ -534,7 +533,7 @@ if (!data_array) { pr_info("%s: data_array not yet init= ialized\n", __func__); re u8 data =3D 0; =20 for (k =3D 0; k < m; k++) { - u8 byte =3D buf[(8 * i + k) * line_length + j / 8]; + u8 byte =3D buf[(8 * i + k) * pitch + j / 8]; u8 bit =3D (byte >> (j % 8)) & 1; =20 data |=3D bit << k; @@ -570,6 +569,8 @@ if (!data_array) { pr_info("%s: data_array not yet init= ialized\n", __func__); re =20 static void ssd130x_clear_screen(struct ssd130x_device *ssd130x) { + unsigned int pitch =3D DIV_ROUND_UP(ssd130x->width, 8); + u8 *buf =3D ssd130x->buffer; struct drm_rect fullscreen =3D { .x1 =3D 0, .x2 =3D ssd130x->width, @@ -577,7 +578,7 @@ static void ssd130x_clear_screen(struct ssd130x_device = *ssd130x) .y2 =3D ssd130x->height, }; =20 - ssd130x_update_rect(ssd130x, &fullscreen); + ssd130x_update_rect(ssd130x, buf, pitch, &fullscreen); } =20 static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct i= osys_map *vmap, @@ -588,27 +589,48 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffe= r *fb, const struct iosys_m struct iosys_map dst; unsigned int dst_pitch; int ret =3D 0; - u8 *buf =3D ssd130x->buffer; - - if (!buf) - return 0; + u8 *buf; =20 /* Align y to display page boundaries */ rect->y1 =3D round_down(rect->y1, page_height); rect->y2 =3D min_t(unsigned int, round_up(rect->y2, page_height), ssd130x= ->height); =20 - dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), 8); + switch (fb->format->format) { + case DRM_FORMAT_R1: + /* Align x to byte boundaries */ + rect->x1 =3D round_down(rect->x1, 8); + rect->x2 =3D round_up(rect->x2, 8); =20 - ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); - if (ret) - return ret; + ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); + if (ret) + return ret; =20 - iosys_map_set_vaddr(&dst, buf); - drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect); + dst_pitch =3D fb->pitches[0]; + buf =3D vmap[0].vaddr + rect->y1 * dst_pitch + rect->x1 / 8; =20 - drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + ssd130x_update_rect(ssd130x, buf, dst_pitch, rect); =20 - ssd130x_update_rect(ssd130x, rect); + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + break; + + case DRM_FORMAT_XRGB8888: + dst_pitch =3D DIV_ROUND_UP(drm_rect_width(rect), 8); + buf =3D ssd130x->buffer; + if (!buf) + return 0; + + ret =3D drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); + if (ret) + return ret; + + iosys_map_set_vaddr(&dst, buf); + drm_fb_xrgb8888_to_mono(&dst, &dst_pitch, vmap, fb, rect); + + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + + ssd130x_update_rect(ssd130x, buf, dst_pitch, rect); + break; + } =20 return ret; } @@ -797,6 +819,7 @@ static const struct drm_mode_config_funcs ssd130x_mode_= config_funcs =3D { }; =20 static const uint32_t ssd130x_formats[] =3D { + DRM_FORMAT_R1, DRM_FORMAT_XRGB8888, }; =20 --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 6BFD9C0015E for ; Thu, 13 Jul 2023 13:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235138AbjGMNRt (ORCPT ); Thu, 13 Jul 2023 09:17:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234802AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -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 1A4042713 for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by laurent.telenet-ops.be with bizsmtp id LdHN2A00V3wy6xv01dHNpc; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gr1-2r; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyl-PB; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 5/8] drm/client: Convert drm_mode_create_dumb() to drm_mode_addfb2() Date: Thu, 13 Jul 2023 15:17:13 +0200 Message-Id: <9090c1b423e0b56c8e906155fe53ff0841830a03.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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" Currently drm_client_buffer_addfb() uses the legacy drm_mode_addfb(), which uses bpp and depth to guess the wanted buffer format. However, drm_client_buffer_addfb() already knows the exact buffer format, so there is no need to convert back and forth between buffer format and bpp/depth, and the function can just call drm_mode_addfb2() directly instead. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- drivers/gpu/drm/drm_client.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index f6292ba0e6fc3783..de660a25ad7c6f06 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -374,19 +374,16 @@ static int drm_client_buffer_addfb(struct drm_client_= buffer *buffer, u32 handle) { struct drm_client_dev *client =3D buffer->client; - struct drm_mode_fb_cmd fb_req =3D { }; - const struct drm_format_info *info; + struct drm_mode_fb_cmd2 fb_req =3D { }; int ret; =20 - info =3D drm_format_info(format); - fb_req.bpp =3D drm_format_info_bpp(info, 0); - fb_req.depth =3D info->depth; fb_req.width =3D width; fb_req.height =3D height; - fb_req.handle =3D handle; - fb_req.pitch =3D buffer->pitch; + fb_req.pixel_format =3D format; + fb_req.handles[0] =3D handle; + fb_req.pitches[0] =3D buffer->pitch; =20 - ret =3D drm_mode_addfb(client->dev, &fb_req, client->file); + ret =3D drm_mode_addfb2(client->dev, &fb_req, client->file); if (ret) return ret; =20 --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 EE4D7C001DF for ; Thu, 13 Jul 2023 13:17:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234575AbjGMNRf (ORCPT ); Thu, 13 Jul 2023 09:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234748AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -0400 Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE3BA2708 for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by baptiste.telenet-ops.be with bizsmtp id LdHN2A00V3wy6xv01dHPUr; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001Gr8-3Z; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyp-Pq; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 6/8] drm/fb-helper: Pass buffer format via drm_fb_helper_surface_size Date: Thu, 13 Jul 2023 15:17:14 +0200 Message-Id: <00790d022752b672a28256db7b9393eca0801b99.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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" drm_fb_helper_single_fb_probe() first calls drm_fb_helper_find_sizes(), followed by drm_fbdev_generic_helper_fb_probe(): - The former tries to find a suitable buffer format, taking into account limitations of the whole display pipeline, - The latter just calls drm_mode_legacy_fb_format() again. Simplify this by passing the buffer format between these functions via a new buffer format member in the drm_fb_helper_surface_size structure. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- drivers/gpu/drm/drm_fb_helper.c | 1 + drivers/gpu/drm/drm_fbdev_generic.c | 9 ++++----- include/drm/drm_fb_helper.h | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helpe= r.c index 61a5d450cc20ef0a..e870b2ce7a8625e3 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1564,6 +1564,7 @@ static int __drm_fb_helper_find_sizes(struct drm_fb_h= elper *fb_helper, info =3D drm_format_info(surface_format); sizes->surface_bpp =3D drm_format_info_bpp(info, 0); sizes->surface_depth =3D info->depth; + sizes->surface_format =3D surface_format; =20 /* first up get a count of crtcs now in use and new min/maxes width/heigh= ts */ crtc_count =3D 0; diff --git a/drivers/gpu/drm/drm_fbdev_generic.c b/drivers/gpu/drm/drm_fbde= v_generic.c index 98ae703848a02fa3..953056896c1a5652 100644 --- a/drivers/gpu/drm/drm_fbdev_generic.c +++ b/drivers/gpu/drm/drm_fbdev_generic.c @@ -77,16 +77,15 @@ static int drm_fbdev_generic_helper_fb_probe(struct drm= _fb_helper *fb_helper, struct fb_info *info; size_t screen_size; void *screen_buffer; - u32 format; int ret; =20 - drm_dbg_kms(dev, "surface width(%d), height(%d) and bpp(%d)\n", + drm_info(dev, "surface width(%d), height(%d), bpp(%d) and format(%p4cc)\n= ", sizes->surface_width, sizes->surface_height, - sizes->surface_bpp); + sizes->surface_bpp, &sizes->surface_format); =20 - format =3D drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_d= epth); buffer =3D drm_client_framebuffer_create(client, sizes->surface_width, - sizes->surface_height, format); + sizes->surface_height, + sizes->surface_format); if (IS_ERR(buffer)) return PTR_ERR(buffer); =20 diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h index 4863b0f8299e89b6..430a17b530fa49e6 100644 --- a/include/drm/drm_fb_helper.h +++ b/include/drm/drm_fb_helper.h @@ -45,6 +45,7 @@ struct drm_fb_helper; * @surface_height: scanout buffer height * @surface_bpp: scanout buffer bpp * @surface_depth: scanout buffer depth + * @surface_format: scanout buffer format (optional) * * Note that the scanout surface width/height may be larger than the fbdev * width/height. In case of multiple displays, the scanout surface is siz= ed @@ -61,6 +62,7 @@ struct drm_fb_helper_surface_size { u32 surface_height; u32 surface_bpp; u32 surface_depth; + u32 surface_format; }; =20 /** --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 BD4E2C001DD for ; Thu, 13 Jul 2023 13:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234772AbjGMNRl (ORCPT ); Thu, 13 Jul 2023 09:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231761AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -0400 Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18EAC270A for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by michel.telenet-ops.be with bizsmtp id LdHN2A00d3wy6xv06dHNae; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001GrC-48; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyv-QU; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 7/8] drm/fb-helper: Add support for DRM_FORMAT_R1 Date: Thu, 13 Jul 2023 15:17:15 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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" Add support for the monochrome light-on-dark buffer format (R1) to the fb helper, so this format can be used for fbdev emulation and for the text console. This avoids the overhead of using XR24 and the associated conversions on display hardware that supports only a simple monochrome format. R1 is very similar to C1 (monochrome indexed color), and shares the same depth and bpp. As drm_mode_legacy_fb_format() returns a format based on only depth and bpp, it cannot distinguish between R1 and C1. Hence drm_fb_helper_find_format() is modified to try to fall back to R1 if C1 is not supported. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- drivers/gpu/drm/drm_fb_helper.c | 41 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helpe= r.c index e870b2ce7a8625e3..1f1bfa764b6b9f00 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1130,7 +1130,7 @@ static void drm_fb_helper_fill_pixel_fmt(struct fb_va= r_screeninfo *var, { u8 depth =3D format->depth; =20 - if (format->is_color_indexed) { + if (format->format =3D=3D DRM_FORMAT_R1 || format->is_color_indexed) { var->red.offset =3D 0; var->green.offset =3D 0; var->blue.offset =3D 0; @@ -1236,6 +1236,7 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo = *var, case DRM_FORMAT_C1: case DRM_FORMAT_C2: case DRM_FORMAT_C4: + case DRM_FORMAT_R1: /* supported format with sub-byte pixels */ break; =20 @@ -1439,12 +1440,24 @@ int drm_fb_helper_pan_display(struct fb_var_screeni= nfo *var, } EXPORT_SYMBOL(drm_fb_helper_pan_display); =20 +static bool is_supported_format(uint32_t format, const uint32_t *formats, + size_t format_count) +{ + size_t i; + + for (i =3D 0; i < format_count; ++i) { + if (formats[i] =3D=3D format) + return true; + } + + return false; +} + static uint32_t drm_fb_helper_find_format(struct drm_fb_helper *fb_helper,= const uint32_t *formats, size_t format_count, uint32_t bpp, uint32_t depth) { struct drm_device *dev =3D fb_helper->dev; uint32_t format; - size_t i; =20 /* * Do not consider YUV or other complicated formats @@ -1457,10 +1470,12 @@ static uint32_t drm_fb_helper_find_format(struct dr= m_fb_helper *fb_helper, const if (!format) goto err; =20 - for (i =3D 0; i < format_count; ++i) { - if (formats[i] =3D=3D format) - return format; - } + if (is_supported_format(format, formats, format_count)) + return format; + + if (format =3D=3D DRM_FORMAT_C1 && + is_supported_format(DRM_FORMAT_R1, formats, format_count)) + return DRM_FORMAT_R1; =20 err: /* We found nothing. */ @@ -1680,11 +1695,15 @@ static int drm_fb_helper_single_fb_probe(struct drm= _fb_helper *fb_helper) } =20 static void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, - bool is_color_indexed) + const struct drm_format_info *format) { info->fix.type =3D FB_TYPE_PACKED_PIXELS; - info->fix.visual =3D is_color_indexed ? FB_VISUAL_PSEUDOCOLOR - : FB_VISUAL_TRUECOLOR; + if (format->format =3D=3D DRM_FORMAT_R1) + info->fix.visual =3D FB_VISUAL_MONO10; + else if (format->is_color_indexed) + info->fix.visual =3D FB_VISUAL_PSEUDOCOLOR; + else + info->fix.visual =3D FB_VISUAL_TRUECOLOR; info->fix.mmio_start =3D 0; info->fix.mmio_len =3D 0; info->fix.type_aux =3D 0; @@ -1707,6 +1726,7 @@ static void drm_fb_helper_fill_var(struct fb_info *in= fo, case DRM_FORMAT_C1: case DRM_FORMAT_C2: case DRM_FORMAT_C4: + case DRM_FORMAT_R1: /* supported format with sub-byte pixels */ break; =20 @@ -1747,8 +1767,7 @@ void drm_fb_helper_fill_info(struct fb_info *info, { struct drm_framebuffer *fb =3D fb_helper->fb; =20 - drm_fb_helper_fill_fix(info, fb->pitches[0], - fb->format->is_color_indexed); + drm_fb_helper_fill_fix(info, fb->pitches[0], fb->format); drm_fb_helper_fill_var(info, fb_helper, sizes->fb_width, sizes->fb_height); =20 --=20 2.34.1 From nobody Sat Feb 7 11:31:47 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 9D45AC0015E for ; Thu, 13 Jul 2023 13:17:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235130AbjGMNRr (ORCPT ); Thu, 13 Jul 2023 09:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234786AbjGMNRb (ORCPT ); Thu, 13 Jul 2023 09:17:31 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A497271E for ; Thu, 13 Jul 2023 06:17:25 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6264:77e5:42e2:477d]) by xavier.telenet-ops.be with bizsmtp id LdHN2A00N3wy6xv01dHNtD; Thu, 13 Jul 2023 15:17:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1qJwC3-001GrG-4q; Thu, 13 Jul 2023 15:17:22 +0200 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1qJwCA-00GWyz-RB; Thu, 13 Jul 2023 15:17:22 +0200 From: Geert Uytterhoeven To: Javier Martinez Canillas , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 8/8] drm/ssd130x: Switch preferred_bpp/depth to 1 Date: Thu, 13 Jul 2023 15:17:16 +0200 Message-Id: <6b97ca629131a8c1c047947a21b2c558ece9ce87.1689252746.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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 native display format is R1. Hence change the preferred_depth and preferred_bpp to 1, to avoid the overhead of using XR24 and the associated conversions when using fbdev emulation and its text console. Signed-off-by: Geert Uytterhoeven Tested-by: Javier Martinez Canillas --- drivers/gpu/drm/solomon/ssd130x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/solomon/ssd130x.c b/drivers/gpu/drm/solomon/ss= d130x.c index 130e33a1ba3cba00..93af2e5fc816b5f0 100644 --- a/drivers/gpu/drm/solomon/ssd130x.c +++ b/drivers/gpu/drm/solomon/ssd130x.c @@ -945,7 +945,7 @@ static int ssd130x_init_modeset(struct ssd130x_device *= ssd130x) drm->mode_config.max_width =3D max_width; drm->mode_config.min_height =3D mode->vdisplay; drm->mode_config.max_height =3D max_height; - drm->mode_config.preferred_depth =3D 24; + drm->mode_config.preferred_depth =3D 1; drm->mode_config.funcs =3D &ssd130x_mode_config_funcs; =20 /* Primary plane */ @@ -1075,7 +1075,7 @@ struct ssd130x_device *ssd130x_probe(struct device *d= ev, struct regmap *regmap) if (ret) return ERR_PTR(dev_err_probe(dev, ret, "DRM device register failed\n")); =20 - drm_fbdev_generic_setup(drm, 32); + drm_fbdev_generic_setup(drm, 1); =20 return ssd130x; } --=20 2.34.1