File: 0001-Add-in-basic-infrastructure-for-big-endian-support.patch

package info (click to toggle)
acpica-unix 20200925-1.2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 46,232 kB
  • sloc: ansic: 130,058; sh: 4,410; yacc: 4,272; makefile: 1,330; lex: 1,329
file content (392 lines) | stat: -rw-r--r-- 13,240 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
From bb45113bc9aed952a499cd1c53988dc81f597582 Mon Sep 17 00:00:00 2001
From: Al Stone <ahs3@redhat.com>
Date: Thu, 15 Oct 2020 11:53:33 -0600
Subject: [PATCH 01/40] Add in basic infrastructure for big-endian support

This adds in some basic functions -- AcpiUtReadUint32(), for example,
to read a UINT32 value in little-endian form and return it in host-native
format -- along with AcpiUtWriteUint() that writes out an integer in
host-native format as a little-endian value.

But, to do that, I'm adding the functions in a new file: utendian.c.  So,
the header files need fixing, and the makefiles need to be sure to compile
the new code.

However, this sets things up for the future, where endian-aware code can
be added as the need is uncovered.  For now, these functions cover all of
the cases I know about.

Signed-off-by: Al Stone <ahs3@redhat.com>
---
 generate/unix/acpibin/Makefile         |   1 +
 generate/unix/acpidump/Makefile        |   1 +
 generate/unix/acpiexamples/Makefile    |   1 +
 generate/unix/acpiexec/Makefile        |   1 +
 generate/unix/acpihelp/Makefile        |   1 +
 generate/unix/iasl/Makefile            |   1 +
 source/components/utilities/utendian.c | 205 +++++++++++++++++++++++++
 source/include/acutils.h               |  26 ++++
 source/include/platform/aclinux.h      |   5 +
 9 files changed, 242 insertions(+)
 create mode 100644 source/components/utilities/utendian.c

Index: acpica-unix-20200925/generate/unix/acpibin/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpibin/Makefile
+++ acpica-unix2-20200925/generate/unix/acpibin/Makefile
@@ -37,6 +37,7 @@ OBJECTS = \
 	$(OBJDIR)/utcache.o\
 	$(OBJDIR)/utdebug.o\
 	$(OBJDIR)/utdecode.o\
+	$(OBJDIR)/utendian.o\
 	$(OBJDIR)/utexcep.o\
 	$(OBJDIR)/utglobal.o\
 	$(OBJDIR)/utlock.o\
Index: acpica-unix2-20200925/generate/unix/acpidump/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpidump/Makefile
+++ acpica-unix2-20200925/generate/unix/acpidump/Makefile
@@ -36,6 +36,7 @@ OBJECTS = \
 	$(OBJDIR)/osunixdir.o\
 	$(OBJDIR)/osunixmap.o\
 	$(OBJDIR)/osunixxf.o\
+	$(OBJDIR)/utendian.o\
 	$(OBJDIR)/tbprint.o\
 	$(OBJDIR)/tbxfroot.o\
 	$(OBJDIR)/utascii.o\
Index: acpica-unix2-20200925/generate/unix/acpiexamples/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpiexamples/Makefile
+++ acpica-unix2-20200925/generate/unix/acpiexamples/Makefile
@@ -139,6 +139,7 @@ OBJECTS = \
 	$(OBJDIR)/utdebug.o\
 	$(OBJDIR)/utdecode.o\
 	$(OBJDIR)/utdelete.o\
+	$(OBJDIR)/utendian.o\
 	$(OBJDIR)/uterror.o\
 	$(OBJDIR)/uteval.o\
 	$(OBJDIR)/utexcep.o\
Index: acpica-unix2-20200925/generate/unix/acpiexec/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpiexec/Makefile
+++ acpica-unix2-20200925/generate/unix/acpiexec/Makefile
@@ -214,6 +214,7 @@ OBJECTS = \
 	$(OBJDIR)/utdebug.o\
 	$(OBJDIR)/utdecode.o\
 	$(OBJDIR)/utdelete.o\
+	$(OBJDIR)/utendian.o\
 	$(OBJDIR)/uterror.o\
 	$(OBJDIR)/uteval.o\
 	$(OBJDIR)/utexcep.o\
Index: acpica-unix2-20200925/generate/unix/acpihelp/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/acpihelp/Makefile
+++ acpica-unix2-20200925/generate/unix/acpihelp/Makefile
@@ -43,6 +43,7 @@ OBJECTS = \
 	$(OBJDIR)/getopt.o\
 	$(OBJDIR)/osunixxf.o\
 	$(OBJDIR)/utdebug.o\
+	$(OBJDIR)/utendian.o\
 	$(OBJDIR)/utexcep.o\
 	$(OBJDIR)/utglobal.o\
 	$(OBJDIR)/uthex.o\
Index: acpica-unix2-20200925/generate/unix/iasl/Makefile
===================================================================
--- acpica-unix2-20200925.orig/generate/unix/iasl/Makefile
+++ acpica-unix2-20200925/generate/unix/iasl/Makefile
@@ -225,6 +225,7 @@ OBJECTS = \
 	$(OBJDIR)/utdebug.o\
 	$(OBJDIR)/utdecode.o\
 	$(OBJDIR)/utdelete.o\
+	$(OBJDIR)/utendian.o\
 	$(OBJDIR)/uterror.o\
 	$(OBJDIR)/utexcep.o\
 	$(OBJDIR)/utglobal.o\
Index: acpica-unix2-20200925/source/components/utilities/utendian.c
===================================================================
--- /dev/null
+++ acpica-unix2-20200925/source/components/utilities/utendian.c
@@ -0,0 +1,225 @@
+/******************************************************************************
+ *
+ * Module Name: utendian -- byte swapping support for other-endianness
+ *
+ *****************************************************************************/
+
+/*****************************************************************************
+ *
+ * Copyright (c) 2020, Al Stone <ahs3@redhat.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Alternatively, you may choose to be licensed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ *****************************************************************************/
+
+#include "acpi.h"
+#include "accommon.h"
+
+#define _COMPONENT          ACPI_COMPILER
+        ACPI_MODULE_NAME    ("utendian")
+
+
+/*
+ * Endianness support functions.
+ *
+ * Ultimately, everything in ACPI tables or AML must be in little-endian
+ * format.  However, we sometimes find it necessary to run on a big-endian
+ * machine and create or read those little-endian values.  This is a small
+ * libary of functions to make that easier, and more visible.
+ *
+ */
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtReadUint16
+ *
+ * PARAMETERS:  Src		    - location containing the little-endian
+ *                                    value
+ *
+ * RETURN:      UINT16 value in host-native form
+ *
+ * DESCRIPTION: Read a UINT16 little-endian value from a given location
+ *              and return it in host-native form
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+UINT16 AcpiUtReadUint16 (void *SrcPtr)
+{
+    UINT16 Result = 0;
+    UINT8  *Dst = (UINT8 *)&Result;
+    UINT8  *Src = (UINT8 *)SrcPtr;
+
+    Dst[0] = Src[1];
+    Dst[1] = Src[0];
+
+    return Result;
+}
+#else
+UINT16 AcpiUtReadUint16 (void *SrcPtr) { return *(UINT16 *)SrcPtr; }
+#endif
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtReadUint32
+ *
+ * PARAMETERS:  Src		    - location containing the little-endian
+ *                                    value
+ *
+ * RETURN:      UINT32 value in host-native form
+ *
+ * DESCRIPTION: Read a UINT32 little-endian value from a given location
+ *              and return it in host-native form
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+UINT32 AcpiUtReadUint32 (void *SrcPtr)
+{
+    UINT32 Result = 0;
+    UINT8  *Dst = (UINT8 *)&Result;
+    UINT8  *Src = (UINT8 *)SrcPtr;
+
+    Dst[0] = Src[3];
+    Dst[1] = Src[2];
+    Dst[2] = Src[1];
+    Dst[3] = Src[0];
+
+    return Result;
+}
+#else
+UINT32 AcpiUtReadUint32 (void *SrcPtr) { return *(UINT32 *)SrcPtr; }
+#endif
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtReadUint64
+ *
+ * PARAMETERS:  Src		    - location containing the little-endian
+ *                                    value
+ *
+ * RETURN:      UINT64 value in host-native form
+ *
+ * DESCRIPTION: Read a UINT64 little-endian value from a given location
+ *              and return it in host-native form
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+UINT64 AcpiUtReadUint64 (void *SrcPtr)
+{
+    UINT64 Result = 0;
+    UINT8  *Dst = (UINT8 *)&Result;
+    UINT8  *Src = (UINT8 *)SrcPtr;
+
+    Dst[0] = Src[7];
+    Dst[1] = Src[6];
+    Dst[2] = Src[5];
+    Dst[3] = Src[4];
+    Dst[4] = Src[3];
+    Dst[5] = Src[2];
+    Dst[6] = Src[1];
+    Dst[7] = Src[0];
+
+    return Result;
+}
+#else
+UINT64 AcpiUtReadUint64 (void *SrcPtr) {
+#if defined(ACPI_MISALIGNMENT_NOT_SUPPORTED)
+    UINT64 Result = 0;
+    UINT8  *Dst = (UINT8 *)&Result;
+    UINT8  *Src = (UINT8 *)SrcPtr;
+
+    Dst[7] = Src[7];
+    Dst[6] = Src[6];
+    Dst[5] = Src[5];
+    Dst[4] = Src[4];
+    Dst[3] = Src[3];
+    Dst[2] = Src[2];
+    Dst[1] = Src[1];
+    Dst[0] = Src[0];
+
+    return Result;
+
+#else
+    return *(UINT64 *)SrcPtr;
+#endif
+}
+#endif
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiUtWriteUint
+ *
+ * PARAMETERS:  DstPtr		- where to place the retrieved value
+ *	        DstLength	- space in bytes for this int type
+ *	        SrcPtr		- where the little-endian value lives
+ *	        SrcLength	- space in bytes for this int type
+ *
+ * RETURN:      None.
+ *
+ * DESCRIPTION: Write a host-native integer value of the given size, and
+ * 	        store it in the location specified in little-endian form.
+ * 	        Given the amount of integer type casting done, this general
+ * 	        version seems the most useful (vs 32->32, 32->16, 16->32,
+ * 	        ad infinitum)
+ *
+ ******************************************************************************/
+
+#if defined(ACPI_BIG_ENDIAN)
+void AcpiUtWriteUint (void *DstPtr, int DstLength,
+	              const void *SrcPtr, const int SrcLength)
+{
+    UINT8 *Dst = (UINT8 *)DstPtr;
+    UINT8 *Src = (UINT8 *)SrcPtr;
+    int Length;
+    int ii;
+
+    Length = SrcLength >= DstLength ? DstLength : SrcLength;
+    for (ii = 0; ii < Length; ii++)
+	    Dst[ii] = Src[SrcLength - ii - 1];
+
+}
+#else
+void AcpiUtWriteUint (void *DstPtr, int DstLength,
+	              const void *SrcPtr, const int SrcLength)
+{
+    UINT8 *Dst = (UINT8 *)DstPtr;
+    UINT8 *Src = (UINT8 *)SrcPtr;
+    uint Length;
+
+    Length = SrcLength > DstLength ? DstLength : SrcLength;
+    memcpy(Dst, Src, Length);
+}
+#endif
+
Index: acpica-unix2-20200925/source/include/acutils.h
===================================================================
--- acpica-unix2-20200925.orig/source/include/acutils.h
+++ acpica-unix2-20200925/source/include/acutils.h
@@ -1161,4 +1161,30 @@ AcpiUtConvertStringToUuid (
     UINT8                   *UuidBuffer);
 #endif
 
+/*
+ * utendian -- byte-swapping for big-endian support
+ */
+#if defined(ACPI_ASL_COMPILER) || defined(ACPI_EXEC_APP) || \
+    defined(ACPI_HELP_APP)     || defined(ACPI_DUMP_APP) || \
+    defined(ACPI_EXAMPLE_APP)  || defined(ACPI_BIN_APP)
+UINT32
+AcpiUtReadUint32 (
+    void                    *SrcPtr);
+
+UINT16
+AcpiUtReadUint16 (
+    void                    *SrcPtr);
+
+UINT64
+AcpiUtReadUint64 (
+    void                    *SrcPtr);
+
+void  
+AcpiUtWriteUint (
+    void                    *DstPtr,
+    int                     DstLength,
+    const void              *SrcPtr,
+    const int               SrcLength);
+#endif
+
 #endif /* _ACUTILS_H */
Index: acpica-unix2-20200925/source/include/platform/aclinux.h
===================================================================
--- acpica-unix2-20200925.orig/source/include/platform/aclinux.h
+++ acpica-unix2-20200925/source/include/platform/aclinux.h
@@ -198,6 +198,7 @@
 
 #ifdef ACPI_USE_STANDARD_HEADERS
 #include <unistd.h>
+#include <endian.h>
 #endif
 
 /* Define/disable kernel-specific declarators */
@@ -233,6 +234,10 @@
 #define __cdecl
 #endif
 
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define ACPI_BIG_ENDIAN
+#endif
+
 #endif /* __KERNEL__ */
 
 #endif /* __ACLINUX_H__ */