From patchwork Thu Jul 13 13:17:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312186 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1CFAC0015E for ; Thu, 13 Jul 2023 13:17:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 064D210E6BC; Thu, 13 Jul 2023 13:17:42 +0000 (UTC) Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F89810E6D2 for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 device info data") Signed-off-by: Geert Uytterhoeven Reviewed-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/ssd130x.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 = round_down(rect->y1, page_height); rect->y2 = min_t(unsigned int, round_up(rect->y2, page_height), ssd130x->height); - dst_pitch = DIV_ROUND_UP(drm_rect_width(rect), page_height); + dst_pitch = DIV_ROUND_UP(drm_rect_width(rect), 8); ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); if (ret) From patchwork Thu Jul 13 13:17:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312187 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52875C001E0 for ; Thu, 13 Jul 2023 13:17:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D2F610E6D6; Thu, 13 Jul 2023 13:17:49 +0000 (UTC) Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2A24A10E6D6 for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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 = DIV_ROUND_UP(args->bpp, 8); if (cpp > U32_MAX / args->width) return -EINVAL; - stride = cpp * args->width; + stride = DIV_ROUND_UP(args->bpp * args->width, 8); if (args->height > U32_MAX / stride) return -EINVAL; From patchwork Thu Jul 13 13:17:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312182 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF676EB64DD for ; Thu, 13 Jul 2023 13:17:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 39A5B10E6D4; Thu, 13 Jul 2023 13:17:29 +0000 (UTC) Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0209010E6CC for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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/ssd130x.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 *ssd130x, struct drm_rect * u32 array_idx = 0; int ret, i, j, k; +if (!data_array) { pr_info("%s: data_array not yet initialized\n", __func__); return 0; } drm_WARN_ONCE(drm, y % 8 != 0, "y must be aligned to screen page\n"); /* From patchwork Thu Jul 13 13:17:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312183 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9097AC0015E for ; Thu, 13 Jul 2023 13:17:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E6D510E6D3; Thu, 13 Jul 2023 13:17:29 +0000 (UTC) Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 10C8510E6D3 for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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/ssd130x.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 *ssd130x) SSD130X_SET_ADDRESS_MODE_HORIZONTAL); } -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 = rect->x1; unsigned int y = rect->y1; - u8 *buf = ssd130x->buffer; u8 *data_array = ssd130x->data_array; unsigned int width = drm_rect_width(rect); unsigned int height = drm_rect_height(rect); - unsigned int line_length = DIV_ROUND_UP(width, 8); unsigned int page_height = ssd130x->device_info->page_height; unsigned int pages = DIV_ROUND_UP(height, page_height); struct drm_device *drm = &ssd130x->drm; @@ -534,7 +533,7 @@ if (!data_array) { pr_info("%s: data_array not yet initialized\n", __func__); re u8 data = 0; for (k = 0; k < m; k++) { - u8 byte = buf[(8 * i + k) * line_length + j / 8]; + u8 byte = buf[(8 * i + k) * pitch + j / 8]; u8 bit = (byte >> (j % 8)) & 1; data |= bit << k; @@ -570,6 +569,8 @@ if (!data_array) { pr_info("%s: data_array not yet initialized\n", __func__); re static void ssd130x_clear_screen(struct ssd130x_device *ssd130x) { + unsigned int pitch = DIV_ROUND_UP(ssd130x->width, 8); + u8 *buf = ssd130x->buffer; struct drm_rect fullscreen = { .x1 = 0, .x2 = ssd130x->width, @@ -577,7 +578,7 @@ static void ssd130x_clear_screen(struct ssd130x_device *ssd130x) .y2 = ssd130x->height, }; - ssd130x_update_rect(ssd130x, &fullscreen); + ssd130x_update_rect(ssd130x, buf, pitch, &fullscreen); } static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_map *vmap, @@ -588,27 +589,48 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m struct iosys_map dst; unsigned int dst_pitch; int ret = 0; - u8 *buf = ssd130x->buffer; - - if (!buf) - return 0; + u8 *buf; /* Align y to display page boundaries */ rect->y1 = round_down(rect->y1, page_height); rect->y2 = min_t(unsigned int, round_up(rect->y2, page_height), ssd130x->height); - dst_pitch = DIV_ROUND_UP(drm_rect_width(rect), 8); + switch (fb->format->format) { + case DRM_FORMAT_R1: + /* Align x to byte boundaries */ + rect->x1 = round_down(rect->x1, 8); + rect->x2 = round_up(rect->x2, 8); - ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); - if (ret) - return ret; + ret = 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); + dst_pitch = fb->pitches[0]; + buf = vmap[0].vaddr + rect->y1 * dst_pitch + rect->x1 / 8; - drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + ssd130x_update_rect(ssd130x, buf, dst_pitch, rect); - ssd130x_update_rect(ssd130x, rect); + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); + break; + + case DRM_FORMAT_XRGB8888: + dst_pitch = DIV_ROUND_UP(drm_rect_width(rect), 8); + buf = ssd130x->buffer; + if (!buf) + return 0; + + ret = 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; + } return ret; } @@ -797,6 +819,7 @@ static const struct drm_mode_config_funcs ssd130x_mode_config_funcs = { }; static const uint32_t ssd130x_formats[] = { + DRM_FORMAT_R1, DRM_FORMAT_XRGB8888, }; From patchwork Thu Jul 13 13:17:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312184 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27C8DC001DD for ; Thu, 13 Jul 2023 13:17:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA92910E6D5; Thu, 13 Jul 2023 13:17:29 +0000 (UTC) Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by gabe.freedesktop.org (Postfix) with ESMTPS id 08CE110E6CD for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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 = buffer->client; - struct drm_mode_fb_cmd fb_req = { }; - const struct drm_format_info *info; + struct drm_mode_fb_cmd2 fb_req = { }; int ret; - info = drm_format_info(format); - fb_req.bpp = drm_format_info_bpp(info, 0); - fb_req.depth = info->depth; fb_req.width = width; fb_req.height = height; - fb_req.handle = handle; - fb_req.pitch = buffer->pitch; + fb_req.pixel_format = format; + fb_req.handles[0] = handle; + fb_req.pitches[0] = buffer->pitch; - ret = drm_mode_addfb(client->dev, &fb_req, client->file); + ret = drm_mode_addfb2(client->dev, &fb_req, client->file); if (ret) return ret; From patchwork Thu Jul 13 13:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312181 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9056C001DD for ; Thu, 13 Jul 2023 13:17:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F8FC10E6CD; Thu, 13 Jul 2023 13:17:28 +0000 (UTC) Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0B94410E6D1 for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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_helper.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_helper *fb_helper, info = drm_format_info(surface_format); sizes->surface_bpp = drm_format_info_bpp(info, 0); sizes->surface_depth = info->depth; + sizes->surface_format = surface_format; /* first up get a count of crtcs now in use and new min/maxes width/heights */ crtc_count = 0; diff --git a/drivers/gpu/drm/drm_fbdev_generic.c b/drivers/gpu/drm/drm_fbdev_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; - 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); - format = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth); buffer = 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); 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 sized @@ -61,6 +62,7 @@ struct drm_fb_helper_surface_size { u32 surface_height; u32 surface_bpp; u32 surface_depth; + u32 surface_format; }; /** From patchwork Thu Jul 13 13:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312185 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AC030C001E0 for ; Thu, 13 Jul 2023 13:17:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7935210E6D8; Thu, 13 Jul 2023 13:17:30 +0000 (UTC) Received: from michel.telenet-ops.be (michel.telenet-ops.be [IPv6:2a02:1800:110:4::f00:18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 30E6D10E6D7 for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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_helper.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_var_screeninfo *var, { u8 depth = format->depth; - if (format->is_color_indexed) { + if (format->format == DRM_FORMAT_R1 || format->is_color_indexed) { var->red.offset = 0; var->green.offset = 0; var->blue.offset = 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; @@ -1439,12 +1440,24 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, } EXPORT_SYMBOL(drm_fb_helper_pan_display); +static bool is_supported_format(uint32_t format, const uint32_t *formats, + size_t format_count) +{ + size_t i; + + for (i = 0; i < format_count; ++i) { + if (formats[i] == 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 = fb_helper->dev; uint32_t format; - size_t i; /* * Do not consider YUV or other complicated formats @@ -1457,10 +1470,12 @@ static uint32_t drm_fb_helper_find_format(struct drm_fb_helper *fb_helper, const if (!format) goto err; - for (i = 0; i < format_count; ++i) { - if (formats[i] == format) - return format; - } + if (is_supported_format(format, formats, format_count)) + return format; + + if (format == DRM_FORMAT_C1 && + is_supported_format(DRM_FORMAT_R1, formats, format_count)) + return DRM_FORMAT_R1; err: /* We found nothing. */ @@ -1680,11 +1695,15 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper) } 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 = FB_TYPE_PACKED_PIXELS; - info->fix.visual = is_color_indexed ? FB_VISUAL_PSEUDOCOLOR - : FB_VISUAL_TRUECOLOR; + if (format->format == DRM_FORMAT_R1) + info->fix.visual = FB_VISUAL_MONO10; + else if (format->is_color_indexed) + info->fix.visual = FB_VISUAL_PSEUDOCOLOR; + else + info->fix.visual = FB_VISUAL_TRUECOLOR; info->fix.mmio_start = 0; info->fix.mmio_len = 0; info->fix.type_aux = 0; @@ -1707,6 +1726,7 @@ static void drm_fb_helper_fill_var(struct fb_info *info, case DRM_FORMAT_C1: case DRM_FORMAT_C2: case DRM_FORMAT_C4: + case DRM_FORMAT_R1: /* supported format with sub-byte pixels */ break; @@ -1747,8 +1767,7 @@ void drm_fb_helper_fill_info(struct fb_info *info, { struct drm_framebuffer *fb = fb_helper->fb; - 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); From patchwork Thu Jul 13 13:17:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13312188 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 579C6EB64DD for ; Thu, 13 Jul 2023 13:17:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 75B3A10E6CE; Thu, 13 Jul 2023 13:17:48 +0000 (UTC) Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1340710E6D5 for ; Thu, 13 Jul 2023 13:17:26 +0000 (UTC) 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 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Reviewed-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/ssd130x.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 = max_width; drm->mode_config.min_height = mode->vdisplay; drm->mode_config.max_height = max_height; - drm->mode_config.preferred_depth = 24; + drm->mode_config.preferred_depth = 1; drm->mode_config.funcs = &ssd130x_mode_config_funcs; /* Primary plane */ @@ -1075,7 +1075,7 @@ struct ssd130x_device *ssd130x_probe(struct device *dev, struct regmap *regmap) if (ret) return ERR_PTR(dev_err_probe(dev, ret, "DRM device register failed\n")); - drm_fbdev_generic_setup(drm, 32); + drm_fbdev_generic_setup(drm, 1); return ssd130x; }