xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-core/busybox/busybox/0001-devmem-add-128-bit-width.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From d432049f288c9acdc4a7caa729c68ceba3c5dca1 Mon Sep 17 00:00:00 2001
2From: Aaro Koskinen <aaro.koskinen@nokia.com>
3Date: Thu, 25 Aug 2022 18:47:02 +0300
4Subject: [PATCH] devmem: add 128-bit width
5
6Add 128-bit width if the compiler provides the needed type.
7
8function                                             old     new   delta
9devmem_main                                          405     464     +59
10.rodata                                           109025  109043     +18
11------------------------------------------------------------------------------
12(add/remove: 0/0 grow/shrink: 2/0 up/down: 77/0)               Total: 77 bytes
13
14Upstream-Status: Backport [https://git.busybox.net/busybox/commit/?id=d432049f288c9acdc4a7caa729c68ceba3c5dca1]
15
16Signed-off-by: Aaro Koskinen <aaro.koskinen@nokia.com>
17Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
18Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
19Signed-off-by: Mingli Yu <mingli.yu@windriver.com>
20---
21 miscutils/devmem.c | 68 ++++++++++++++++++++++++++++++----------------
22 1 file changed, 44 insertions(+), 24 deletions(-)
23
24diff --git a/miscutils/devmem.c b/miscutils/devmem.c
25index f9f0276bc..f21621bd6 100644
26--- a/miscutils/devmem.c
27+++ b/miscutils/devmem.c
28@@ -29,7 +29,6 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
29 {
30 	void *map_base, *virt_addr;
31 	uint64_t read_result;
32-	uint64_t writeval = writeval; /* for compiler */
33 	off_t target;
34 	unsigned page_size, mapped_size, offset_in_page;
35 	int fd;
36@@ -64,9 +63,6 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
37 			width = strchrnul(bhwl, (argv[2][0] | 0x20)) - bhwl;
38 			width = sizes[width];
39 		}
40-		/* VALUE */
41-		if (argv[3])
42-			writeval = bb_strtoull(argv[3], NULL, 0);
43 	} else { /* argv[2] == NULL */
44 		/* make argv[3] to be a valid thing to fetch */
45 		argv--;
46@@ -96,28 +92,46 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
47 	virt_addr = (char*)map_base + offset_in_page;
48
49 	if (!argv[3]) {
50-		switch (width) {
51-		case 8:
52-			read_result = *(volatile uint8_t*)virt_addr;
53-			break;
54-		case 16:
55-			read_result = *(volatile uint16_t*)virt_addr;
56-			break;
57-		case 32:
58-			read_result = *(volatile uint32_t*)virt_addr;
59-			break;
60-		case 64:
61-			read_result = *(volatile uint64_t*)virt_addr;
62-			break;
63-		default:
64-			bb_simple_error_msg_and_die("bad width");
65+#ifdef __SIZEOF_INT128__
66+		if (width == 128) {
67+			unsigned __int128 rd =
68+				*(volatile unsigned __int128 *)virt_addr;
69+			printf("0x%016llX%016llX\n",
70+				(unsigned long long)(uint64_t)(rd >> 64),
71+				(unsigned long long)(uint64_t)rd
72+			);
73+		} else
74+#endif
75+		{
76+			switch (width) {
77+			case 8:
78+				read_result = *(volatile uint8_t*)virt_addr;
79+				break;
80+			case 16:
81+				read_result = *(volatile uint16_t*)virt_addr;
82+				break;
83+			case 32:
84+				read_result = *(volatile uint32_t*)virt_addr;
85+				break;
86+			case 64:
87+				read_result = *(volatile uint64_t*)virt_addr;
88+				break;
89+			default:
90+				bb_simple_error_msg_and_die("bad width");
91+			}
92+//			printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n",
93+//				target, virt_addr,
94+//				(unsigned long long)read_result);
95+			/* Zero-padded output shows the width of access just done */
96+			printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result);
97 		}
98-//		printf("Value at address 0x%"OFF_FMT"X (%p): 0x%llX\n",
99-//			target, virt_addr,
100-//			(unsigned long long)read_result);
101-		/* Zero-padded output shows the width of access just done */
102-		printf("0x%0*llX\n", (width >> 2), (unsigned long long)read_result);
103 	} else {
104+		/* parse VALUE */
105+#ifdef __SIZEOF_INT128__
106+		unsigned __int128 writeval = strtoumax(argv[3], NULL, 0);
107+#else
108+		uint64_t writeval = bb_strtoull(argv[3], NULL, 0);
109+#endif
110 		switch (width) {
111 		case 8:
112 			*(volatile uint8_t*)virt_addr = writeval;
113@@ -135,6 +149,12 @@ int devmem_main(int argc UNUSED_PARAM, char **argv)
114 			*(volatile uint64_t*)virt_addr = writeval;
115 //			read_result = *(volatile uint64_t*)virt_addr;
116 			break;
117+#ifdef __SIZEOF_INT128__
118+		case 128:
119+			*(volatile unsigned __int128 *)virt_addr = writeval;
120+//			read_result = *(volatile uint64_t*)virt_addr;
121+			break;
122+#endif
123 		default:
124 			bb_simple_error_msg_and_die("bad width");
125 		}
126--
1272.25.1
128
129