From nobody Tue Jun 23 10:05:34 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 655B8C433F5 for ; Mon, 7 Mar 2022 20:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245502AbiCGUzb (ORCPT ); Mon, 7 Mar 2022 15:55:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245410AbiCGUzF (ORCPT ); Mon, 7 Mar 2022 15:55:05 -0500 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 60AF8340FC for ; Mon, 7 Mar 2022 12:53:35 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by albert.telenet-ops.be with bizsmtp id 3YtW2700F1Yj8bA06YtWdo; Mon, 07 Mar 2022 21:53:34 +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 1nRKLY-0036Qd-Sw; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLX-0034hG-ST; Mon, 07 Mar 2022 21:52:47 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 01/10] drm/fourcc: Add drm_format_info_bpp() helper Date: Mon, 7 Mar 2022 21:52:36 +0100 Message-Id: X-Mailer: git-send-email 2.25.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 a helper to retrieve the actual number of bits per pixel for a plane, taking into account the number of characters and pixels per block for tiled formats. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- v2: - Move up. --- drivers/gpu/drm/drm_fourcc.c | 19 +++++++++++++++++++ include/drm/drm_fourcc.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 07741b678798b0f1..cf48ea0b2cb70ba8 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -370,6 +370,25 @@ unsigned int drm_format_info_block_height(const struct= drm_format_info *info, } EXPORT_SYMBOL(drm_format_info_block_height); =20 +/** + * drm_format_info_bpp - number of bits per pixel + * @info: pixel format info + * @plane: plane index + * + * Returns: + * The actual number of bits per pixel, depending on the plane index. + */ +unsigned int drm_format_info_bpp(const struct drm_format_info *info, int p= lane) +{ + if (!info || plane < 0 || plane >=3D info->num_planes) + return 0; + + return info->char_per_block[plane] * 8 / + (drm_format_info_block_width(info, plane) * + drm_format_info_block_height(info, plane)); +} +EXPORT_SYMBOL(drm_format_info_bpp); + /** * drm_format_info_min_pitch - computes the minimum required pitch in bytes * @info: pixel format info diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 22aa64d07c7905e2..3800a7ad7f0cda7a 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -313,6 +313,7 @@ unsigned int drm_format_info_block_width(const struct d= rm_format_info *info, int plane); unsigned int drm_format_info_block_height(const struct drm_format_info *in= fo, int plane); +unsigned int drm_format_info_bpp(const struct drm_format_info *info, int p= lane); uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width); =20 --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 F31F0C433FE for ; Mon, 7 Mar 2022 20:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245449AbiCGUzY (ORCPT ); Mon, 7 Mar 2022 15:55:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245404AbiCGUy7 (ORCPT ); Mon, 7 Mar 2022 15:54:59 -0500 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 024E233374 for ; Mon, 7 Mar 2022 12:53:35 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by laurent.telenet-ops.be with bizsmtp id 3YtW270091Yj8bA01YtW0W; Mon, 07 Mar 2022 21:53:34 +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 1nRKLY-0036Qe-Pg; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLX-0034hM-TE; Mon, 07 Mar 2022 21:52:47 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 02/10] drm/fourcc: Add drm_format_info.is_color_indexed flag Date: Mon, 7 Mar 2022 21:52:37 +0100 Message-Id: X-Mailer: git-send-email 2.25.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 a flag to struct drm_format_info to indicate if a format is color-indexed, similar to the existing .is_yuv flag. This way generic code and drivers can just check this flag, instead of checking against a list of fourcc formats. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- v2: - New. --- drivers/gpu/drm/drm_fourcc.c | 2 +- include/drm/drm_fourcc.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index cf48ea0b2cb70ba8..6c76bd821d17e7c7 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -132,7 +132,7 @@ EXPORT_SYMBOL(drm_driver_legacy_fb_format); const struct drm_format_info *__drm_format_info(u32 format) { static const struct drm_format_info formats[] =3D { - { .format =3D DRM_FORMAT_C8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, + { .format =3D DRM_FORMAT_C8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, { .format =3D DRM_FORMAT_R8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R10, .depth =3D 10, .num_planes =3D 1, .cpp = =3D { 2, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R12, .depth =3D 12, .num_planes =3D 1, .cpp = =3D { 2, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 3800a7ad7f0cda7a..532ae78ca747e6c4 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -138,6 +138,9 @@ struct drm_format_info { =20 /** @is_yuv: Is it a YUV format? */ bool is_yuv; + + /** @is_color_indexed: Is it a color-indexed format? */ + bool is_color_indexed; }; =20 /** --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 2257CC433F5 for ; Mon, 7 Mar 2022 20:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244229AbiCGUx4 (ORCPT ); Mon, 7 Mar 2022 15:53:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237646AbiCGUxw (ORCPT ); Mon, 7 Mar 2022 15:53:52 -0500 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 0E3041CFD8 for ; Mon, 7 Mar 2022 12:52:56 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by xavier.telenet-ops.be with bizsmtp id 3Ysq2700J1Yj8bA01Ysq8m; Mon, 07 Mar 2022 21:52:54 +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 1nRKLY-0036Qf-Bk; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLX-0034hT-Tz; Mon, 07 Mar 2022 21:52:47 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 03/10] drm/client: Use actual bpp when allocating frame buffers Date: Mon, 7 Mar 2022 21:52:38 +0100 Message-Id: <8f29a983d42d9d68bd8cae2f9481d3c139f8750a.1646683502.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.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" When allocating a frame buffer, the number of bits per pixel needed is derived from the deprecated drm_format_info.cpp[] field. While this works for formats using less than 8 bits per pixel, it does lead to a large overallocation. Reduce memory consumption by using the actual number of bits per pixel instead. Signed-off-by: Geert Uytterhoeven Acked-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas --- v2: - Add Acked-by. --- drivers/gpu/drm/drm_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index ce45e380f4a2028f..c6a279e3de95591a 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -264,7 +264,7 @@ drm_client_buffer_create(struct drm_client_dev *client,= u32 width, u32 height, u =20 dumb_args.width =3D width; dumb_args.height =3D height; - dumb_args.bpp =3D info->cpp[0] * 8; + dumb_args.bpp =3D drm_format_info_bpp(info, 0); ret =3D drm_mode_create_dumb(dev, &dumb_args, client->file); if (ret) goto err_delete; @@ -372,7 +372,7 @@ static int drm_client_buffer_addfb(struct drm_client_bu= ffer *buffer, int ret; =20 info =3D drm_format_info(format); - fb_req.bpp =3D info->cpp[0] * 8; + 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; --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 E1F84C433EF for ; Mon, 7 Mar 2022 20:54:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245474AbiCGUzp (ORCPT ); Mon, 7 Mar 2022 15:55:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239402AbiCGUzD (ORCPT ); Mon, 7 Mar 2022 15:55:03 -0500 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 07A0F33E34 for ; Mon, 7 Mar 2022 12:53:35 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by laurent.telenet-ops.be with bizsmtp id 3YtW2700C1Yj8bA01YtW0X; Mon, 07 Mar 2022 21:53:34 +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 1nRKLZ-0036Qg-DF; Mon, 07 Mar 2022 21:52:49 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLX-0034ha-Uq; Mon, 07 Mar 2022 21:52:47 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 04/10] drm/framebuffer: Use actual bpp for DRM_IOCTL_MODE_GETFB Date: Mon, 7 Mar 2022 21:52:39 +0100 Message-Id: X-Mailer: git-send-email 2.25.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" When userspace queries the properties of a frame buffer, the number of bits per pixel is derived from the deprecated drm_format_info.cpp[] field, which does not take into account block sizes. Fix this by using the actual number of bits per pixel instead. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- v2: - No changes. --- drivers/gpu/drm/drm_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_frameb= uffer.c index 07f5abc875e97b96..4b9d7b01cb99c03d 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -530,7 +530,7 @@ int drm_mode_getfb(struct drm_device *dev, r->height =3D fb->height; r->width =3D fb->width; r->depth =3D fb->format->depth; - r->bpp =3D fb->format->cpp[0] * 8; + r->bpp =3D drm_format_info_bpp(fb->format, 0); r->pitch =3D fb->pitches[0]; =20 /* GET_FB() is an unprivileged ioctl so we must not return a --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 0CEDAC433EF for ; Mon, 7 Mar 2022 20:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245521AbiCGUzk (ORCPT ); Mon, 7 Mar 2022 15:55:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245484AbiCGUzE (ORCPT ); Mon, 7 Mar 2022 15:55:04 -0500 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 512EE340EF for ; Mon, 7 Mar 2022 12:53:35 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by albert.telenet-ops.be with bizsmtp id 3YtW2700D1Yj8bA06YtWdp; Mon, 07 Mar 2022 21:53:34 +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 1nRKLZ-0036Qh-1N; Mon, 07 Mar 2022 21:52:49 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLX-0034hh-Vg; Mon, 07 Mar 2022 21:52:47 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 05/10] drm/fourcc: Add DRM_FORMAT_C[124] Date: Mon, 7 Mar 2022 21:52:40 +0100 Message-Id: <8d3c0cc370b0214244b01a64c588e5e506531716.1646683502.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.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" Introduce fourcc codes for color-indexed frame buffer formats with two, four, and sixteen colors, and provide a mapping from bit per pixel and depth to fourcc codes. As the number of bits per pixel is less than eight, these rely on proper block handling for the calculation of bits per pixel and pitch. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas Reviewed-by: Pekka Paalanen --- v2: - Improve pixel descriptions, - Require depth to match bpp in drm_mode_legacy_fb_format(), - Set .is_color_indexed flag. --- drivers/gpu/drm/drm_fourcc.c | 21 +++++++++++++++++++++ include/uapi/drm/drm_fourcc.h | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 6c76bd821d17e7c7..29f4fe199c4ddcf0 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -43,6 +43,21 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_= t depth) uint32_t fmt =3D DRM_FORMAT_INVALID; =20 switch (bpp) { + case 1: + if (depth =3D=3D 1) + fmt =3D DRM_FORMAT_C1; + break; + + case 2: + if (depth =3D=3D 2) + fmt =3D DRM_FORMAT_C2; + break; + + case 4: + if (depth =3D=3D 4) + fmt =3D DRM_FORMAT_C4; + break; + case 8: if (depth =3D=3D 8) fmt =3D DRM_FORMAT_C8; @@ -132,6 +147,12 @@ EXPORT_SYMBOL(drm_driver_legacy_fb_format); const struct drm_format_info *__drm_format_info(u32 format) { static const struct drm_format_info formats[] =3D { + { .format =3D DRM_FORMAT_C1, .depth =3D 1, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 8, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, + { .format =3D DRM_FORMAT_C2, .depth =3D 2, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 4, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, + { .format =3D DRM_FORMAT_C4, .depth =3D 4, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 2, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, { .format =3D DRM_FORMAT_C8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, { .format =3D DRM_FORMAT_R8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R10, .depth =3D 10, .num_planes =3D 1, .cpp = =3D { 2, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h index fc0c1454d2757d5d..457ed39cc48f08e1 100644 --- a/include/uapi/drm/drm_fourcc.h +++ b/include/uapi/drm/drm_fourcc.h @@ -99,7 +99,10 @@ extern "C" { #define DRM_FORMAT_INVALID 0 =20 /* color index */ -#define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C */ +#define DRM_FORMAT_C1 fourcc_code('C', '1', ' ', ' ') /* [7:0] C0:C1:C2:C= 3:C4:C5:C6:C7 1:1:1:1:1:1:1:1 eight pixels/byte */ +#define DRM_FORMAT_C2 fourcc_code('C', '2', ' ', ' ') /* [7:0] C0:C1:C2:C= 3 2:2:2:2 four pixels/byte */ +#define DRM_FORMAT_C4 fourcc_code('C', '4', ' ', ' ') /* [7:0] C0:C1 4:4 = two pixels/byte */ +#define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C 8 one pi= xel/byte */ =20 /* 8 bpp Red */ #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */ --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 79737C433F5 for ; Mon, 7 Mar 2022 20:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245459AbiCGUyw (ORCPT ); Mon, 7 Mar 2022 15:54:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245389AbiCGUyT (ORCPT ); Mon, 7 Mar 2022 15:54:19 -0500 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C571286E3 for ; Mon, 7 Mar 2022 12:53:23 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by andre.telenet-ops.be with bizsmtp id 3YtK2700F1Yj8bA01YtKzF; Mon, 07 Mar 2022 21:53:23 +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 1nRKLY-0036Qi-Kw; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLY-0034ho-0P; Mon, 07 Mar 2022 21:52:48 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 06/10] drm/fb-helper: Add support for DRM_FORMAT_C[124] Date: Mon, 7 Mar 2022 21:52:41 +0100 Message-Id: X-Mailer: git-send-email 2.25.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 color-indexed frame buffer formats with two, four, and sixteen colors to the DRM framebuffer helper functions: 1. Add support for 1, 2, and 4 bits per pixel to the damage helper, 2. For color-indexed modes, the length of the color bitfields must be set to the color depth, else the logo code may pick a logo with too many colors. Drop the incorrect DAC width comment, which originates from the i915 driver. 3. Accept C[124] modes when validating or filling in struct fb_var_screeninfo, and use the correct number of bits per pixel. 4. Set the visual to FB_VISUAL_PSEUDOCOLOR for all color-indexed modes. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- v2: - Use drm_format_info_bpp() helper instead of deprecated .depth field or format-dependent calculations, - Use new .is_color_indexed field instead of checking against a list of formats. --- drivers/gpu/drm/drm_fb_helper.c | 101 ++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helpe= r.c index ed43b987d306afce..ba1c303a294d8c6f 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -376,12 +376,31 @@ static void drm_fb_helper_damage_blit_real(struct drm= _fb_helper *fb_helper, struct iosys_map *dst) { struct drm_framebuffer *fb =3D fb_helper->fb; - unsigned int cpp =3D fb->format->cpp[0]; - size_t offset =3D clip->y1 * fb->pitches[0] + clip->x1 * cpp; - void *src =3D fb_helper->fbdev->screen_buffer + offset; - size_t len =3D (clip->x2 - clip->x1) * cpp; + size_t offset =3D clip->y1 * fb->pitches[0]; + size_t len =3D clip->x2 - clip->x1; unsigned int y; + void *src; =20 + switch (drm_format_info_bpp(fb->format, 0)) { + case 1: + offset +=3D clip->x1 / 8; + len =3D DIV_ROUND_UP(len + clip->x1 % 8, 8); + break; + case 2: + offset +=3D clip->x1 / 4; + len =3D DIV_ROUND_UP(len + clip->x1 % 4, 4); + break; + case 4: + offset +=3D clip->x1 / 2; + len =3D DIV_ROUND_UP(len + clip->x1 % 2, 2); + break; + default: + offset +=3D clip->x1 * fb->format->cpp[0]; + len *=3D fb->format->cpp[0]; + break; + } + + src =3D fb_helper->fbdev->screen_buffer + offset; iosys_map_incr(dst, offset); /* go to first pixel within clip rect */ =20 for (y =3D clip->y1; y < clip->y2; y++) { @@ -1231,19 +1250,23 @@ static bool drm_fb_pixel_format_equal(const struct = fb_var_screeninfo *var_1, } =20 static void drm_fb_helper_fill_pixel_fmt(struct fb_var_screeninfo *var, - u8 depth) + const struct drm_format_info *format) { - switch (depth) { - case 8: + u8 depth =3D format->depth; + + if (format->is_color_indexed) { var->red.offset =3D 0; var->green.offset =3D 0; var->blue.offset =3D 0; - var->red.length =3D 8; /* 8bit DAC */ - var->green.length =3D 8; - var->blue.length =3D 8; + var->red.length =3D depth; + var->green.length =3D depth; + var->blue.length =3D depth; var->transp.offset =3D 0; var->transp.length =3D 0; - break; + return; + } + + switch (depth) { case 15: var->red.offset =3D 10; var->green.offset =3D 5; @@ -1298,7 +1321,9 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo = *var, { struct drm_fb_helper *fb_helper =3D info->par; struct drm_framebuffer *fb =3D fb_helper->fb; + const struct drm_format_info *format =3D fb->format; struct drm_device *dev =3D fb_helper->dev; + unsigned int bpp; =20 if (in_dbg_master()) return -EINVAL; @@ -1308,22 +1333,33 @@ int drm_fb_helper_check_var(struct fb_var_screeninf= o *var, var->pixclock =3D 0; } =20 - if ((drm_format_info_block_width(fb->format, 0) > 1) || - (drm_format_info_block_height(fb->format, 0) > 1)) - return -EINVAL; + switch (format->format) { + case DRM_FORMAT_C1: + case DRM_FORMAT_C2: + case DRM_FORMAT_C4: + /* supported format with sub-byte pixels */ + break; + + default: + if ((drm_format_info_block_width(format, 0) > 1) || + (drm_format_info_block_height(format, 0) > 1)) + return -EINVAL; + break; + } =20 /* * Changes struct fb_var_screeninfo are currently not pushed back * to KMS, hence fail if different settings are requested. */ - if (var->bits_per_pixel > fb->format->cpp[0] * 8 || + bpp =3D drm_format_info_bpp(format, 0); + if (var->bits_per_pixel > bpp || var->xres > fb->width || var->yres > fb->height || var->xres_virtual > fb->width || var->yres_virtual > fb->height) { drm_dbg_kms(dev, "fb requested width/height/bpp can't fit in current fb " "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n", var->xres, var->yres, var->bits_per_pixel, var->xres_virtual, var->yres_virtual, - fb->width, fb->height, fb->format->cpp[0] * 8); + fb->width, fb->height, bpp); return -EINVAL; } =20 @@ -1338,13 +1374,13 @@ int drm_fb_helper_check_var(struct fb_var_screeninf= o *var, !var->blue.length && !var->transp.length && !var->red.msb_right && !var->green.msb_right && !var->blue.msb_right && !var->transp.msb_right) { - drm_fb_helper_fill_pixel_fmt(var, fb->format->depth); + drm_fb_helper_fill_pixel_fmt(var, format); } =20 /* * Likewise, bits_per_pixel should be rounded up to a supported value. */ - var->bits_per_pixel =3D fb->format->cpp[0] * 8; + var->bits_per_pixel =3D bpp; =20 /* * drm fbdev emulation doesn't support changing the pixel format at all, @@ -1680,11 +1716,11 @@ 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, - uint32_t depth) + bool is_color_indexed) { info->fix.type =3D FB_TYPE_PACKED_PIXELS; - info->fix.visual =3D depth =3D=3D 8 ? FB_VISUAL_PSEUDOCOLOR : - FB_VISUAL_TRUECOLOR; + info->fix.visual =3D is_color_indexed ? FB_VISUAL_PSEUDOCOLOR + : info->fix.visual; info->fix.mmio_start =3D 0; info->fix.mmio_len =3D 0; info->fix.type_aux =3D 0; @@ -1701,19 +1737,31 @@ static void drm_fb_helper_fill_var(struct fb_info *= info, uint32_t fb_width, uint32_t fb_height) { struct drm_framebuffer *fb =3D fb_helper->fb; + const struct drm_format_info *format =3D fb->format; + + switch (format->format) { + case DRM_FORMAT_C1: + case DRM_FORMAT_C2: + case DRM_FORMAT_C4: + /* supported format with sub-byte pixels */ + break; + + default: + WARN_ON((drm_format_info_block_width(format, 0) > 1) || + (drm_format_info_block_height(format, 0) > 1)); + break; + } =20 - WARN_ON((drm_format_info_block_width(fb->format, 0) > 1) || - (drm_format_info_block_height(fb->format, 0) > 1)); info->pseudo_palette =3D fb_helper->pseudo_palette; info->var.xres_virtual =3D fb->width; info->var.yres_virtual =3D fb->height; - info->var.bits_per_pixel =3D fb->format->cpp[0] * 8; + info->var.bits_per_pixel =3D drm_format_info_bpp(format, 0); info->var.accel_flags =3D FB_ACCELF_TEXT; info->var.xoffset =3D 0; info->var.yoffset =3D 0; info->var.activate =3D FB_ACTIVATE_NOW; =20 - drm_fb_helper_fill_pixel_fmt(&info->var, fb->format->depth); + drm_fb_helper_fill_pixel_fmt(&info->var, format); =20 info->var.xres =3D fb_width; info->var.yres =3D fb_height; @@ -1738,7 +1786,8 @@ 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->depth); + drm_fb_helper_fill_fix(info, fb->pitches[0], + fb->format->is_color_indexed); drm_fb_helper_fill_var(info, fb_helper, sizes->fb_width, sizes->fb_height); =20 --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 58943C433EF for ; Mon, 7 Mar 2022 20:53:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245377AbiCGUyN (ORCPT ); Mon, 7 Mar 2022 15:54:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245385AbiCGUyJ (ORCPT ); Mon, 7 Mar 2022 15:54:09 -0500 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 408822459A for ; Mon, 7 Mar 2022 12:53:13 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by andre.telenet-ops.be with bizsmtp id 3Yt92700L1Yj8bA01Yt9xl; Mon, 07 Mar 2022 21:53:12 +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 1nRKLY-0036Qj-JD; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLY-0034hv-1V; Mon, 07 Mar 2022 21:52:48 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 RFC 07/10] drm/gem-fb-helper: Use actual bpp for size calculations Date: Mon, 7 Mar 2022 21:52:42 +0100 Message-Id: <842ab0a286ff743b625277e655d9bef505b630c1.1646683502.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.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 AFBC helpers derive the number of bits per pixel from the deprecated drm_format_info.cpp[] field, which does not take into account block sizes. Fix this by using the actual number of bits per pixel instead. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- RFC, as this code path was untested. v2: - Replace FIXME by TODO comment. --- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm= /drm_gem_framebuffer_helper.c index 746fd8c738451247..e5b8443378d2294b 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -492,6 +492,8 @@ void drm_gem_fb_end_cpu_access(struct drm_framebuffer *= fb, enum dma_data_directi } EXPORT_SYMBOL(drm_gem_fb_end_cpu_access); =20 +// TODO Drop this function and replace by drm_format_info_bpp() once all +// DRM_FORMAT_* provide proper block info in drivers/gpu/drm/drm_fourcc.c static __u32 drm_gem_afbc_get_bpp(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd) { @@ -499,11 +501,6 @@ static __u32 drm_gem_afbc_get_bpp(struct drm_device *d= ev, =20 info =3D drm_get_format_info(dev, mode_cmd); =20 - /* use whatever a driver has set */ - if (info->cpp[0]) - return info->cpp[0] * 8; - - /* guess otherwise */ switch (info->format) { case DRM_FORMAT_YUV420_8BIT: return 12; @@ -512,11 +509,8 @@ static __u32 drm_gem_afbc_get_bpp(struct drm_device *d= ev, case DRM_FORMAT_VUY101010: return 30; default: - break; + return drm_format_info_bpp(info, 0); } - - /* all attempts failed */ - return 0; } =20 static int drm_gem_afbc_min_size(struct drm_device *dev, --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 4CA5AC433EF for ; Mon, 7 Mar 2022 20:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245438AbiCGUzT (ORCPT ); Mon, 7 Mar 2022 15:55:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245465AbiCGUyy (ORCPT ); Mon, 7 Mar 2022 15:54:54 -0500 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 0211933368 for ; Mon, 7 Mar 2022 12:53:35 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by baptiste.telenet-ops.be with bizsmtp id 3YtW2700A1Yj8bA01YtWpf; Mon, 07 Mar 2022 21:53:33 +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 1nRKLY-0036Qk-NS; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLY-0034i2-2N; Mon, 07 Mar 2022 21:52:48 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 RFC 08/10] drm/fourcc: Document that single-channel "red" can be any color Date: Mon, 7 Mar 2022 21:52:43 +0100 Message-Id: <585dc03acb4016bba910e7d15fec3ef4f0aec5b0.1646683502.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.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" Traditionally, the first channel has been called the "red" channel, but the fourcc values for single-channel "red" formats can also be used for other light-on-dark displays, like grayscale. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- RFC, as I have no immediate need for these formats. v2: - New. --- include/uapi/drm/drm_fourcc.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h index 457ed39cc48f08e1..f0187cf20e4619d2 100644 --- a/include/uapi/drm/drm_fourcc.h +++ b/include/uapi/drm/drm_fourcc.h @@ -104,16 +104,16 @@ extern "C" { #define DRM_FORMAT_C4 fourcc_code('C', '4', ' ', ' ') /* [7:0] C0:C1 4:4 = two pixels/byte */ #define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C 8 one pi= xel/byte */ =20 -/* 8 bpp Red */ +/* 8 bpp Red (or generic light-on-dark) */ #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */ =20 -/* 10 bpp Red */ +/* 10 bpp Red (or generic light-on-dark) */ #define DRM_FORMAT_R10 fourcc_code('R', '1', '0', ' ') /* [15:0] x:R 6:10= little endian */ =20 -/* 12 bpp Red */ +/* 12 bpp Red (or generic light-on-dark) */ #define DRM_FORMAT_R12 fourcc_code('R', '1', '2', ' ') /* [15:0] x:R 4:12= little endian */ =20 -/* 16 bpp Red */ +/* 16 bpp Red (or generic light-on-dark) */ #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ') /* [15:0] R little= endian */ =20 /* 16 bpp RG */ --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 266D7C433F5 for ; Mon, 7 Mar 2022 20:54:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241649AbiCGUzG (ORCPT ); Mon, 7 Mar 2022 15:55:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245442AbiCGUyn (ORCPT ); Mon, 7 Mar 2022 15:54:43 -0500 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 D8E2B3151A for ; Mon, 7 Mar 2022 12:53:33 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by xavier.telenet-ops.be with bizsmtp id 3YtW2700A1Yj8bA01YtWF7; Mon, 07 Mar 2022 21:53:33 +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 1nRKLY-0036Ql-Nk; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLY-0034iA-3I; Mon, 07 Mar 2022 21:52:48 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 RFC 09/10] drm/fourcc: Add DRM_FORMAT_R[124] Date: Mon, 7 Mar 2022 21:52:44 +0100 Message-Id: <98c062f1b5c71427d5ba6c7bca706d04b1892162.1646683502.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.25.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" Introduce fourcc codes for single-channel light-on-dark frame buffer formats with two, four, and sixteen intensity levels. As the number of bits per pixel is less than eight, these rely on proper block handling for the calculation of bits per pixel and pitch. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- RFC, as I have no immediate need for these formats. v2: - Improve pixel descriptions. --- drivers/gpu/drm/drm_fourcc.c | 6 ++++++ include/uapi/drm/drm_fourcc.h | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 29f4fe199c4ddcf0..05e65e9ab0c69c6a 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -154,6 +154,12 @@ const struct drm_format_info *__drm_format_info(u32 fo= rmat) { .format =3D DRM_FORMAT_C4, .depth =3D 4, .num_planes =3D 1, .char_per_block =3D { 1, }, .block_w =3D { 2, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, { .format =3D DRM_FORMAT_C8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, + { .format =3D DRM_FORMAT_R1, .depth =3D 1, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 8, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, + { .format =3D DRM_FORMAT_R2, .depth =3D 2, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 4, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, + { .format =3D DRM_FORMAT_R4, .depth =3D 4, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 2, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R10, .depth =3D 10, .num_planes =3D 1, .cpp = =3D { 2, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R12, .depth =3D 12, .num_planes =3D 1, .cpp = =3D { 2, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h index f0187cf20e4619d2..def0a73620dc86d2 100644 --- a/include/uapi/drm/drm_fourcc.h +++ b/include/uapi/drm/drm_fourcc.h @@ -104,8 +104,17 @@ extern "C" { #define DRM_FORMAT_C4 fourcc_code('C', '4', ' ', ' ') /* [7:0] C0:C1 4:4 = two pixels/byte */ #define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C 8 one pi= xel/byte */ =20 +/* 1 bpp Red (or monochrome light-on-dark) */ +#define DRM_FORMAT_R1 fourcc_code('R', '1', ' ', ' ') /* [7:0] R0:R1:R2:R= 3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte */ + +/* 2 bpp Red (or generic light-on-dark) */ +#define DRM_FORMAT_R2 fourcc_code('R', '2', ' ', ' ') /* [7:0] R0:R1:R2:R= 3 2:2:2:2 four pixels/byte */ + +/* 4 bpp Red (or generic light-on-dark) */ +#define DRM_FORMAT_R4 fourcc_code('R', '4', ' ', ' ') /* [7:0] R0:R1 4:4 = two pixels/byte */ + /* 8 bpp Red (or generic light-on-dark) */ -#define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R */ +#define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ') /* [7:0] R 8 one pi= xel/byte */ =20 /* 10 bpp Red (or generic light-on-dark) */ #define DRM_FORMAT_R10 fourcc_code('R', '1', '0', ' ') /* [15:0] x:R 6:10= little endian */ --=20 2.25.1 From nobody Tue Jun 23 10:05:34 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 05C39C433F5 for ; Mon, 7 Mar 2022 20:54:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245407AbiCGUz1 (ORCPT ); Mon, 7 Mar 2022 15:55:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245401AbiCGUy7 (ORCPT ); Mon, 7 Mar 2022 15:54:59 -0500 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DDB0338A4 for ; Mon, 7 Mar 2022 12:53:37 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:6100:2d37:4115:c358]) by andre.telenet-ops.be with bizsmtp id 3YtW270091Yj8bA01YtW13; Mon, 07 Mar 2022 21:53:37 +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 1nRKLY-0036Qq-Na; Mon, 07 Mar 2022 21:52:48 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nRKLY-0034iG-4G; Mon, 07 Mar 2022 21:52:48 +0100 From: Geert Uytterhoeven To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Javier Martinez Canillas , Sam Ravnborg , Helge Deller Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2 RFC 10/10] drm/fourcc: Add DRM_FORMAT_D[1248] Date: Mon, 7 Mar 2022 21:52:45 +0100 Message-Id: X-Mailer: git-send-email 2.25.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" As Rn is light-on-dark, and Cn can be any colors, there are currently no fourcc codes to describe dark-on-light displays. Introduce fourcc codes for a single-channel dark-on-light frame buffer format with two, four, sixteen, or 256 darkness levels. As the number of bits per pixel may be less than eight, some of these formats rely on proper block handling for the calculation of bits per pixel and pitch. Signed-off-by: Geert Uytterhoeven Reviewed-by: Javier Martinez Canillas --- RFC, as I have no immediate need for these formats. v2: - Add rationale for adding new formats, - Improve pixel descriptions, - Add D[248] for completeness. --- drivers/gpu/drm/drm_fourcc.c | 7 +++++++ include/uapi/drm/drm_fourcc.h | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 05e65e9ab0c69c6a..e09331bb3bc73f21 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -154,6 +154,13 @@ const struct drm_format_info *__drm_format_info(u32 fo= rmat) { .format =3D DRM_FORMAT_C4, .depth =3D 4, .num_planes =3D 1, .char_per_block =3D { 1, }, .block_w =3D { 2, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, { .format =3D DRM_FORMAT_C8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1, .is_color_indexed =3D true }, + { .format =3D DRM_FORMAT_D1, .depth =3D 1, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 8, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, + { .format =3D DRM_FORMAT_D2, .depth =3D 2, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 4, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, + { .format =3D DRM_FORMAT_D4, .depth =3D 4, .num_planes =3D 1, + .char_per_block =3D { 1, }, .block_w =3D { 2, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, + { .format =3D DRM_FORMAT_D8, .depth =3D 8, .num_planes =3D 1, .cpp =3D= { 1, 0, 0 }, .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R1, .depth =3D 1, .num_planes =3D 1, .char_per_block =3D { 1, }, .block_w =3D { 8, }, .block_h =3D { 1, }, = .hsub =3D 1, .vsub =3D 1 }, { .format =3D DRM_FORMAT_R2, .depth =3D 2, .num_planes =3D 1, diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h index def0a73620dc86d2..1d8d82b1742898c0 100644 --- a/include/uapi/drm/drm_fourcc.h +++ b/include/uapi/drm/drm_fourcc.h @@ -104,6 +104,18 @@ extern "C" { #define DRM_FORMAT_C4 fourcc_code('C', '4', ' ', ' ') /* [7:0] C0:C1 4:4 = two pixels/byte */ #define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ') /* [7:0] C 8 one pi= xel/byte */ =20 +/* 1 bpp Darkness (monochrome dark-on-light) */ +#define DRM_FORMAT_D1 fourcc_code('D', '1', ' ', ' ') /* [7:0] D0:D1:D2:D= 3:D4:D5:D6:D7 1:1:1:1:1:1:1:1 eight pixels/byte */ + +/* 2 bpp Darkness (generic dark-on-light) */ +#define DRM_FORMAT_D2 fourcc_code('D', '2', ' ', ' ') /* [7:0] D0:D1:D2:D= 3 2:2:2:2 four pixels/byte */ + +/* 4 bpp Darkness (generic dark-on-light) */ +#define DRM_FORMAT_D4 fourcc_code('D', '4', ' ', ' ') /* [7:0] D0:D1 4:4 = two pixels/byte */ + +/* 8 bpp Darkness (generic dark-on-light) */ +#define DRM_FORMAT_D8 fourcc_code('D', '8', ' ', ' ') /* [7:0] D 8 one pi= xel/byte */ + /* 1 bpp Red (or monochrome light-on-dark) */ #define DRM_FORMAT_R1 fourcc_code('R', '1', ' ', ' ') /* [7:0] R0:R1:R2:R= 3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte */ =20 --=20 2.25.1