From patchwork Fri Feb 21 11:37:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13985277 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 9B4CAC021AA for ; Fri, 21 Feb 2025 11:37:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 13DDF10EA5A; Fri, 21 Feb 2025 11:37:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="VwfgHJTm"; dkim-atps=neutral Received: from PNZPR01CU001.outbound.protection.outlook.com (mail-centralindiaazolkn19011033.outbound.protection.outlook.com [52.103.68.33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2EB5810EA5A for ; Fri, 21 Feb 2025 11:37:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=moCLWwChdTFrj0rKN1C3DPaWUuRz/FEnVtmbuhHYSjTVX2bcV9Gz6rWAqhDe2MN0I7iUQaU/mdqRA+eErx4gPqw0YRE8p1yZgKHpgQnXGWx7d6Eg7BEIf4hOnLQWkcLi50OiynONVmVRTpQRF38r96hi5dxYFFzcwQv1wjVd3XmRKo0P+Xi4E7c+VXG+eM9SWGj+P0B83OzJ3fsXQtXDCBHNvF7QZR6hjjtCbNOliA+amDVU/y0YTu50Va0Go2kuXaaa5qRSfjMuOMt1GE4tdZPIl81by02VzrtWEZdEZFU3cbCXMUozahRwk/4osA/CeWc7H41srl6knOAqga43hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TtDHMcw1b6+smQ9zjnsyzlYPYrXKiqgZ1ffHmC1S8AI=; b=Rud3LzZjY3KhdhC20wkdwZKG5OY03E9441RlJ+1/RVuIjegkkboqn8Zt7FOD/De2g8mv9nGh1oRqAA1TZ815yyB7VMUFCFtO+v2PaHyp4FVcSmw6S3eEOZ1JPom7aKVGVY2751YzOlZtVXDeKa3ZGkWRlcfCKMmAHl9v6AgmTda9SAkkpNtkvLL4pGooz1DIbgUK3vohMM4N6jhRQZfi5dt5nXV2ZR5iqMxM0WHQU14Ytjxs0fhfUmO/r3gcxl/6DtTpaegjEnOUdAU4OkSRzp8SMLOkQZ9VeCc7ME16WFswuM2aTFSlauMERXVdffdXC4SYF03yAhfgopgdUUP71g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TtDHMcw1b6+smQ9zjnsyzlYPYrXKiqgZ1ffHmC1S8AI=; b=VwfgHJTmV4OKO6BdTFH5bz6n7cwEdEeprTjJvR94N/BX2/2VzO1yw5wS3LwkZSLN9Q6zmOmoTZkk8Gp+gxuI9ghHBtcB6rD9jJ/ezUm+JjP3FM6vEkSaL8/eEU4WRuxxqdGmArUHqbbotV4T4KJ8L/r4HrjpMXbz9aqQjftTNiprpVWjkFHLUNEsmoVCHK+xbSvsm5wnxJp3tMV66TQ+0fLxh3bT2jRGMqJMrmFhYmSbUOnawDmlMOiAW3q6vuDxOOQvK8Z3bGTXFyT1VWjFMBlpTmngTYXXLsUd31IeFzP6oOO87QrsV8JKwYXGqKXHS0uTYxoXL+zrOZrPE9o2lQ== Received: from PNZPR01MB4478.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:1d::9) by MA0PR01MB10284.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a01:127::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.16; Fri, 21 Feb 2025 11:37:13 +0000 Received: from PNZPR01MB4478.INDPRD01.PROD.OUTLOOK.COM ([fe80::27a3:3d7e:30be:e1d1]) by PNZPR01MB4478.INDPRD01.PROD.OUTLOOK.COM ([fe80::27a3:3d7e:30be:e1d1%3]) with mapi id 15.20.8466.016; Fri, 21 Feb 2025 11:37:13 +0000 From: Aditya Garg To: "pmladek@suse.com" , Steven Rostedt , "andriy.shevchenko@linux.intel.com" , "linux@rasmusvillemoes.dk" , "senozhatsky@chromium.org" , Jonathan Corbet , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "tzimmermann@suse.de" , "airlied@gmail.com" , "simona@ffwll.ch" , Andrew Morton , "apw@canonical.com" , "joe@perches.com" , "dwaipayanray1@gmail.com" , "lukas.bulwahn@gmail.com" , "sumit.semwal@linaro.org" , "christian.koenig@amd.com" CC: Kerem Karabay , Aun-Ali Zaidi , Orlando Chamberlain , Atharva Tiwari , "linux-doc@vger.kernel.org" , Linux Kernel Mailing List , "dri-devel@lists.freedesktop.org" , "linux-media@vger.kernel.org" , "linaro-mm-sig@lists.linaro.org" , Hector Martin , "linux@armlinux.org.uk" , Asahi Linux Mailing List , Sven Peter , Janne Grunau Subject: [PATCH v3 2/3] lib/vsprintf: Add support for generic FOURCCs by extending %p4cc Thread-Topic: [PATCH v3 2/3] lib/vsprintf: Add support for generic FOURCCs by extending %p4cc Thread-Index: AQHbhFTzgQy2ndYjv0+1YtY5sM6hDw== Date: Fri, 21 Feb 2025 11:37:13 +0000 Message-ID: <98289BC4-D5E1-41B8-AC89-632DBD2C2789@live.com> References: In-Reply-To: Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PNZPR01MB4478:EE_|MA0PR01MB10284:EE_ x-ms-office365-filtering-correlation-id: aec76da7-c7bb-4c83-b1b3-08dd526c162e x-microsoft-antispam: BCL:0; ARA:14566002|8062599003|19110799003|15080799006|461199028|8060799006|7092599003|440099028|3412199025|41001999003|102099032; x-microsoft-antispam-message-info: ohtFrewhkxeCfr1INrJ5HqBUWr/bQwz45N3Hi3dKybqNz8zaOg+bWyGP6Fy7ojO4Q2yJ34F9npUJ/wHvlezCzUcttthL9l4vypin54dLEX3Z05NWbL37taz9ZSlobMncnr/v9cuejZR7jTer7G3WNn9oIhNfXKk8ecIO0cl2RGH2fcMdzGfjHFOKtqIkrtzXR7OKmZIszEZNoY4RL84Lbj08WKTvYAh+dPhRMAkb4v8fEZLEEvx161eeNXnJjuF3SJbLhlIlNokrAB4uLYMyC03fAB+Edp4+CKyGkSz773/JerD2MN5CC1PkjPamDwfAX80po2nrIeYeTCECIM+2QrmZcrJ30btkhCwaT8d4SxYunjJ2Pl9xDo16DcaGya6IgjnhB+p6t5V7KDk3SmuZEU9FOcfaQMLXNBNd2n5zm6YizEXB0nrHJC9kpERv7lILUIYXqdREEOn3z7011hGrBYq7TFC5hLaUhtto+IftR3kW2QFROnr9/FymfFMR7Oa5dTphLBBJihBTXc5CcFbWzjEJtc++BccDOjEFZVKCdPd0kijOciVEund+nhrUqhrjN9C00w9GDW4W5dUnYru1MPkO+asT00n90r6m4nHY5EW+2iPcOgOc2kjtirGT8HW4RoxYlAu9806qXUOccubaxunnAsQD3ad3hV3M/lRDn2diaOB48Zxo5flWafRYX8+oBn++6HtF0PAvnRBWQo1ya/VWDI7i6E5h8TYLRe1eN0+IXI6Q5YB7vAGNyvj1ycs2Zj0QHxPJwsOozGjaUFO3W/3bfxdWskxY1QRt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+WLtCZYPFgT7Q9v9IjXRBFWnM6AEv2bcMxVAQ9WBk+E5lUwU+bZvcg/RlpU9YDwVpJ3v+CW2/QPMS+IJq9QMzG88UxGJ/Wh93zVMxLik42yuNfFfHqUu0m25AUVpzzDyuIVXGPP3Lchui1NEhxGE5W7C0BFYGdV8iGkPSxD1obVUZ+esdiM/RrWUWKsEottLGv2vsROrt0NDkrhGRMbXvXi/g6kN0Uq2f0cJgBSaZ57o+mLgm/nnjF+J+bd5R4OFH0Lj8Jy2t0U8lwHGSWcbJ5JdT+QV5hhQNQTqI758YNTPyAaEfOauseLZ7l6w0EwjW9MQIkwi76L5vhYi01NcntykYlA5XnGe3hkJVAyA/I+7fwrwJfCUqrLNuYQ2HtNhtK96iPpqJ+KEViUVW3bsRLG7tTyAhmqvMJDvPCDU+WKpHByW1FK/EKq8AjNMbFLGCNGxvCcHOLKobk+TYKccV9k0KJKVGAFe8mR+a8N9ckPO6ELQt6nLgS5aTRxq3ye8yfp8+NOc4NdPvt/1QZi6Z+scd7CBU8+wnEI2AYMcRefA9hYnONw3/TYsa/6w9i8MsUVRbuaQy8XHZLSWS1Wq4e0s+M4kRoXhdViJt4c2KBs3aMtFwNIA8ttxfzp Content-ID: MIME-Version: 1.0 X-OriginatorOrg: sct-15-20-7719-20-msonline-outlook-ae5c4.templateTenant X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PNZPR01MB4478.INDPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: aec76da7-c7bb-4c83-b1b3-08dd526c162e X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Feb 2025 11:37:13.8244 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MA0PR01MB10284 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Hector Martin %p4cc is designed for DRM/V4L2 FOURCCs with their specific quirks, but it's useful to be able to print generic 4-character codes formatted as an integer. Extend it to add format specifiers for printing generic 32-bit FOURCCs with various endian semantics: %p4ch Host-endian %p4cl Little-endian %p4cb Big-endian %p4cr Reverse-endian The endianness determines how bytes are interpreted as a u32, and the FOURCC is then always printed MSByte-first (this is the opposite of V4L/DRM FOURCCs). This covers most practical cases, e.g. %p4cr would allow printing LSByte-first FOURCCs stored in host endian order (other than the hex form being in character order, not the integer value). Signed-off-by: Hector Martin Signed-off-by: Aditya Garg Acked-by: Rasmus Villemoes --- v2 -> Add this patch v3 -> Make array static Documentation/core-api/printk-formats.rst | 32 +++++++++++++++++++ lib/test_printf.c | 39 +++++++++++++++++++---- lib/vsprintf.c | 38 ++++++++++++++++++---- scripts/checkpatch.pl | 2 +- 4 files changed, 97 insertions(+), 14 deletions(-) diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst index ecccc0473..9982861fa 100644 --- a/Documentation/core-api/printk-formats.rst +++ b/Documentation/core-api/printk-formats.rst @@ -648,6 +648,38 @@ Examples:: %p4cc Y10 little-endian (0x20303159) %p4cc NV12 big-endian (0xb231564e) +Generic FourCC code +------------------- + +:: + %p4c[hrbl] gP00 (0x67503030) + +Print a generic FourCC code, as both ASCII characters and its numerical +value as hexadecimal. + +The additional ``h``, ``r``, ``b``, and ``l`` specifiers are used to specify +host, reversed, big or little endian order data respectively. Host endian +order means the data is interpreted as a 32-bit integer and the most +significant byte is printed first; that is, the character code as printed +matches the byte order stored in memory on big-endian systems, and is reversed +on little-endian systems. + +Passed by reference. + +Examples for a little-endian machine, given &(u32)0x67503030:: + + %p4ch gP00 (0x67503030) + %p4cr 00Pg (0x30305067) + %p4cb 00Pg (0x30305067) + %p4cl gP00 (0x67503030) + +Examples for a big-endian machine, given &(u32)0x67503030:: + + %p4ch gP00 (0x67503030) + %p4cr 00Pg (0x30305067) + %p4cb gP00 (0x67503030) + %p4cl 00Pg (0x30305067) + Rust ---- diff --git a/lib/test_printf.c b/lib/test_printf.c index 59dbe4f9a..4bde40822 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -776,21 +776,46 @@ static void __init fwnode_pointer(void) software_node_unregister_node_group(group); } +struct fourcc_struct { + u32 code; + const char *str; +}; + +static void __init fourcc_pointer_test(const struct fourcc_struct *fc, size_t n, + const char *fmt) +{ + size_t i; + + for (i = 0; i < n; i++) + test(fc[i].str, fmt, &fc[i].code); +} + static void __init fourcc_pointer(void) { - struct { - u32 code; - char *str; - } const try[] = { + static const struct fourcc_struct try_cc[] = { { 0x3231564e, "NV12 little-endian (0x3231564e)", }, { 0xb231564e, "NV12 big-endian (0xb231564e)", }, { 0x10111213, ".... little-endian (0x10111213)", }, { 0x20303159, "Y10 little-endian (0x20303159)", }, }; - unsigned int i; + static const struct fourcc_struct try_ch = { + 0x41424344, "ABCD (0x41424344)", + }; + struct const struct fourcc_struct try_cr = { + 0x41424344, "DCBA (0x44434241)", + }; + static const struct fourcc_struct try_cl = { + le32_to_cpu(0x41424344), "ABCD (0x41424344)", + }; + struct const struct fourcc_struct try_cb = { + be32_to_cpu(0x41424344), "ABCD (0x41424344)", + }; - for (i = 0; i < ARRAY_SIZE(try); i++) - test(try[i].str, "%p4cc", &try[i].code); + fourcc_pointer_test(try_cc, ARRAY_SIZE(try_cc), "%p4cc"); + fourcc_pointer_test(&try_ch, 1, "%p4ch"); + fourcc_pointer_test(&try_cr, 1, "%p4cr"); + fourcc_pointer_test(&try_cl, 1, "%p4cl"); + fourcc_pointer_test(&try_cb, 1, "%p4cb"); } static void __init diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 56fe96319..13733a4da 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1781,27 +1781,53 @@ char *fourcc_string(char *buf, char *end, const u32 *fourcc, char output[sizeof("0123 little-endian (0x01234567)")]; char *p = output; unsigned int i; + bool pixel_fmt = false; u32 orig, val; - if (fmt[1] != 'c' || fmt[2] != 'c') + if (fmt[1] != 'c') return error_string(buf, end, "(%p4?)", spec); if (check_pointer(&buf, end, fourcc, spec)) return buf; orig = get_unaligned(fourcc); - val = orig & ~BIT(31); + switch (fmt[2]) { + case 'h': + val = orig; + break; + case 'r': + orig = swab32(orig); + val = orig; + break; + case 'l': + orig = le32_to_cpu(orig); + val = orig; + break; + case 'b': + orig = be32_to_cpu(orig); + val = orig; + break; + case 'c': + /* Pixel formats are printed LSB-first */ + val = swab32(orig & ~BIT(31)); + pixel_fmt = true; + break; + default: + return error_string(buf, end, "(%p4?)", spec); + } for (i = 0; i < sizeof(u32); i++) { - unsigned char c = val >> (i * 8); + unsigned char c = val >> ((3 - i) * 8); /* Print non-control ASCII characters as-is, dot otherwise */ *p++ = isascii(c) && isprint(c) ? c : '.'; } - *p++ = ' '; - strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); - p += strlen(p); + if (pixel_fmt) { + *p++ = ' '; + strcpy(p, orig & BIT(31) ? "big-endian" : "little-endian"); + p += strlen(p); + } *p++ = ' '; *p++ = '('; diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7b28ad331..21516f753 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -6904,7 +6904,7 @@ sub process { ($extension eq "f" && defined $qualifier && $qualifier !~ /^w/) || ($extension eq "4" && - defined $qualifier && $qualifier !~ /^cc/)) { + defined $qualifier && $qualifier !~ /^c[chlbr]/)) { $bad_specifier = $specifier; last; }