From patchwork Thu Feb 20 16:39:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aditya Garg X-Patchwork-Id: 13984262 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 8ACBAC021B1 for ; Thu, 20 Feb 2025 16:39:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0540110E9B6; Thu, 20 Feb 2025 16:39:42 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=live.com header.i=@live.com header.b="U+miU9ib"; dkim-atps=neutral Received: from MA0PR01CU009.outbound.protection.outlook.com (mail-southindiaazolkn19010011.outbound.protection.outlook.com [52.103.67.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7C6C910E9D9 for ; Thu, 20 Feb 2025 16:39:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YYV6x3Po6JdL+4yK0ALIlIrpDx5p86/2/hkmMz1VmNmFFir39bCNBif8iz3I6kFnm2teqMgX+M5F0sF/7qrRqACWd8phP9+olHvCX6y0lffVijTLgRpmWUNUjI/ogXnT9Xet6PqPtIEKqnJNKhlynqUKAVArChANzMD8UkEdWTk+jyNckSbOG9r2xVn0cFyBdl6MxbNz7vR7dxtLBNMjTRm76b2uG3ajLaWthCaybyqO1+lqsxkz7bJUtlhxnmQjx7am5JiQ2XDS4SQ0VTBW7lP3XWVLlNp37LWgSlh6u9I7ZrETv0cYeAx4x+8e5O6EdcLm29zzFAsuxlSV9nYB6Q== 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=xG7hGQLRiBYKlH9UOgXW4Djmx9kxWyvom7PRdyuhKzA=; b=lJ/IbMkzuEogs0ZfjJ7/X1l5FAnbDcMFiisNXXucj6uGFqpgRV+AKNrM3GAD8n05xBAG3DN5XRrN05IT1T7psnJPjwiwTW8snf1muK+KyyjvDHzegJsv4uZBTemtnIf2sShTng0/5I1pYWGIDOe4sHnQffG0HZoJKnisrmqB3dFQFNUOS7OrJBGmD8hbKogn28d2rOgZymM0wEFGZrVHns3SUgL3z98hxLBAUe/oJDROdPy2ZPf4OMDFXT+gU+kn2kuWnbpczR8eGSFOLVulhXrM0DR+BuxkebbtwZiRE7kVtRgNjoRgxUkfhtiqMvAiiUNeXAG2n8x/VCJkxJj6nw== 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=xG7hGQLRiBYKlH9UOgXW4Djmx9kxWyvom7PRdyuhKzA=; b=U+miU9ib2o947qg26/DyjN7wxAy4dE5nxUpyc+u2PDd7BbH+iBKWQaHrDG3UunQZjEgiboZZ78OISl5IrJpq1nE2T0SYmPjj82kja+aXKKrtN5nREzxuOYA1SDux7Pc550KpShoXMz+q9GIze0qZ27+ESTu3UbjwqLzPpPFi2tBYHjOU5MT3bJF1ui21vWHPzQKGcu4rIDWXQLr2Nk6ERdKBjlsVKMPO4/46tVBQk/4HL8+gO3ME9H3pbb3ppeQN33Vk1I80t9D7R34HM1sn5785g2GeNajkrZRTn5oawGk2N6hU/NAnIVTcdPvB6IQWVMCgU+wVM1Nw8HtpGdjRNg== Received: from PNZPR01MB4478.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:1d::9) by PN3PR01MB5548.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c01:7b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8466.17; Thu, 20 Feb 2025 16:39:23 +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.015; Thu, 20 Feb 2025 16:39:23 +0000 From: Aditya Garg To: "pmladek@suse.com" , "rostedt@goodmis.org" , "andriy.shevchenko@linux.intel.com" , "linux@rasmusvillemoes.dk" , "senozhatsky@chromium.org" , "corbet@lwn.net" , "maarten.lankhorst@linux.intel.com" , "mripard@kernel.org" , "tzimmermann@suse.de" , "airlied@gmail.com" , "simona@ffwll.ch" , "akpm@linux-foundation.org" , "apw@canonical.com" , "joe@perches.com" , "dwaipayanray1@gmail.com" , "lukas.bulwahn@gmail.com" , "sumit.semwal@linaro.org" , "christian.koenig@amd.com" CC: "kekrby@gmail.com" , "admin@kodeit.net" , Orlando Chamberlain , "evepolonium@gmail.com" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "linux-media@vger.kernel.org" , "linaro-mm-sig@lists.linaro.org" , Hector Martin , "linux@armlinux.org.uk" , "asahi@lists.linux.dev" , Sven Peter , Janne Grunau Subject: [PATCH v2 2/3] lib/vsprintf: Add support for generic FOURCCs by extending %p4cc Thread-Topic: [PATCH v2 2/3] lib/vsprintf: Add support for generic FOURCCs by extending %p4cc Thread-Index: AQHbg7X/aqXgA+m6ckGovV62HIljEQ== Date: Thu, 20 Feb 2025 16:39:23 +0000 Message-ID: References: <716BCB0A-785B-463A-86C2-94BD66D5D22E@live.com> In-Reply-To: <716BCB0A-785B-463A-86C2-94BD66D5D22E@live.com> 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_|PN3PR01MB5548:EE_ x-ms-office365-filtering-correlation-id: 6e605b4c-a9ea-4258-19e7-08dd51cd21e1 x-microsoft-antispam: BCL:0; ARA:14566002|8062599003|8060799006|19110799003|15080799006|461199028|7092599003|3412199025|440099028|41001999003|102099032; x-microsoft-antispam-message-info: OibTCOEwF+48tuApgDrq6NUZntelurFqA+XgLsHQeErHCUCSfvOFafIVqsufbbnS0AM+xisvkm4hMiI2Rg4VYj7d6gUpTYMFM7mS/c1UvZ0rprymUCoHavYYNerso59BUGwLV0Bu5Eb+hcJPAtro/rdd4Rd0y+SnzA2ubdDgnpk4jgFEesoMVq8akWnZNwwv/Ur3sBXlIH8NJLdR//k9Cuz/EXEWWkclCcC1li0Cr30tuvV4PIV5gdsolP6w/qQSvW2qsMPl0tlPVvlsm1MvSkwNxQ/BYIMlYeirLjQjlOJOqXnRB1cA4UlhtzdDMnfqg30D0RsBq6dIfNzQZFTqzBEgA2f2yArrl+mfrYDDCRSWkwQaUOaAGBXwzkncCbYOs5cCWifB7gJaR/AXcL4B3soqwfCjFstuSqLYLsY1h7vL77Vv0A+CCZqkkdHoYZgC9i1pLpunDmHE65coakul10TGeiPLNmqjmXyLUIC6bje/nSlihEMRmh/ZjcyDwzL99gfXWSVVL1TawcQuChOswWGPEBbSUUs9CSxFpsdZe7tGOnh4WNEP2z0DccW60AzCAM3QjBTnPSooBPgdMbz/UXBLQ6r4XfR5rJP7/nF5TQMX7GhXV6vXmYew726yxVBEXlGf6JN9PbYLD/qgkPfpSHHABZAOZtHurVSXoD2pegrUQRFAXwKzYlDZwlZrSekOqp+wCwHU2R82StMJgnZq6jtPBfP8EkK06tl1EA2e4mxN75/qVZ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QSpJvOVzV0rHjh83LnEb9vCYWOxwxX7YqxdqLdn7E6KAZ4ZmszrYeP8v7zVHfoXMfHP1o4L7vz8tXwOndArHxbR/eVvd5hHm83Zgggj4VgFucV9WgPIXKgD68NOommbvRaXI4HhF6kYVugmf95EaaaEOdymoXcINx159wJsBAiAwY8zYKXxY1HYzl64dxx3z0Unr0Qzcw91b2J4DzyXcnXQ9p5swJbI7puAijPD0DkDFvONkyKbvsl97V/AC6Wud3UCpOf4s5yV1us/5cXFTieUOOMlaf9PUPkQSaUBU0jGj7OykHO/x4aPjyk0ut4AzJfnViDWdUpxFOk2CBK2L3qrenRCNAFsSV2JCBezxGoKt5rGfHMzO7eCj+0HINWIck+stxMP6pK/S10yST92Y1fbuw6ZKvBkpuogarZfO9BAI2v8vByksU1Cw6Qeqk3WiHY6WanlUPMVEGBALZPworVlfc1gyYqmz1BnwCu4Qr4WNp7jOfg5GIgevl4QoYNm/KqzlzMu2+Twvvz8/Ub6gvZsjKXJ1Z4lpcmhPLXqdLxeYMMAtPjD28wquSUMYRalwEXBFSrOKf7qWPCFPRjvfoP/El0D12brhTdaa1ueJ/eZLL+rqbuGQdq7Xt6jq9JLHLeDVeVsXubkdwJD00nPTPp5nxfk3IXJlCfIDDPZUujpc42BXYhorRvZ 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: 6e605b4c-a9ea-4258-19e7-08dd51cd21e1 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Feb 2025 16:39:23.4448 (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: PN3PR01MB5548 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 --- v2 -> Add this patch 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..ee860327e 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[] = { + struct fourcc_struct const try_cc[] = { { 0x3231564e, "NV12 little-endian (0x3231564e)", }, { 0xb231564e, "NV12 big-endian (0xb231564e)", }, { 0x10111213, ".... little-endian (0x10111213)", }, { 0x20303159, "Y10 little-endian (0x20303159)", }, }; - unsigned int i; + struct fourcc_struct const try_ch = { + 0x41424344, "ABCD (0x41424344)", + }; + struct fourcc_struct const try_cr = { + 0x41424344, "DCBA (0x44434241)", + }; + struct fourcc_struct const try_cl = { + le32_to_cpu(0x41424344), "ABCD (0x41424344)", + }; + struct fourcc_struct const 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; }