1 From 5bd43bca1708a56d32e63da0278e04caf2865927 Mon Sep 17 00:00:00 2001
2 From: Al Stone <ahs3@redhat.com>
3 Date: Tue, 29 Jun 2021 17:38:20 -0600
4 Subject: [PATCH 41/45] Support IORT in a big-endian world
6 Signed-off-by: Al Stone <ahs3@redhat.com>
8 source/common/dmtbdump2.c | 85 ++++++++++++++++++++++----------------
9 source/compiler/dttable1.c | 40 ++++++++++--------
10 2 files changed, 72 insertions(+), 53 deletions(-)
12 Index: acpica-unix2-20220331/source/common/dmtbdump2.c
13 ===================================================================
14 --- acpica-unix2-20220331.orig/source/common/dmtbdump2.c
15 +++ acpica-unix2-20220331/source/common/dmtbdump2.c
16 @@ -77,17 +77,20 @@ AcpiDmDumpIort (
17 ACPI_IORT_RMR *IortRmr = NULL;
22 ACPI_DMTABLE_INFO *InfoTable;
25 UINT32 MappingByteLength;
27 + UINT32 MappingCount;
28 + UINT32 TableLength = AcpiUtReadUint32 (&Table->Length);
33 - Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, AcpiDmTableInfoIort);
34 + Status = AcpiDmDumpTable (TableLength, 0, Table, 0, AcpiDmTableInfoIort);
35 if (ACPI_FAILURE (Status))
38 @@ -109,18 +112,19 @@ AcpiDmDumpIort (
40 /* Dump the OptionalPadding (optional) */
42 - if (Iort->NodeOffset > Offset)
43 + NodeOffset = AcpiUtReadUint32 (&Iort->NodeOffset);
44 + if (NodeOffset > Offset)
46 - Status = AcpiDmDumpTable (Table->Length, Offset, Table,
47 - Iort->NodeOffset - Offset, AcpiDmTableInfoIortPad);
48 + Status = AcpiDmDumpTable (TableLength, Offset, Table,
49 + NodeOffset - Offset, AcpiDmTableInfoIortPad);
50 if (ACPI_FAILURE (Status))
56 - Offset = Iort->NodeOffset;
57 - while (Offset < Table->Length)
58 + Offset = AcpiUtReadUint32 (&Iort->NodeOffset);
59 + while (Offset < TableLength)
61 /* Common subtable header */
63 @@ -130,12 +134,12 @@ AcpiDmDumpIort (
67 - Status = AcpiDmDumpTable (Table->Length, Offset,
68 + Status = AcpiDmDumpTable (TableLength, Offset,
69 IortNode, Length, AcpiDmTableInfoIortHdr);
71 else if (Revision >= 3)
73 - Status = AcpiDmDumpTable (Table->Length, Offset,
74 + Status = AcpiDmDumpTable (TableLength, Offset,
75 IortNode, Length, AcpiDmTableInfoIortHdr3);
78 @@ -166,7 +170,7 @@ AcpiDmDumpIort (
79 case ACPI_IORT_NODE_PCI_ROOT_COMPLEX:
81 InfoTable = AcpiDmTableInfoIort2;
82 - Length = IortNode->Length - NodeOffset;
83 + Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
86 case ACPI_IORT_NODE_SMMU:
87 @@ -179,19 +183,19 @@ AcpiDmDumpIort (
88 case ACPI_IORT_NODE_SMMU_V3:
90 InfoTable = AcpiDmTableInfoIort4;
91 - Length = IortNode->Length - NodeOffset;
92 + Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
95 case ACPI_IORT_NODE_PMCG:
97 InfoTable = AcpiDmTableInfoIort5;
98 - Length = IortNode->Length - NodeOffset;
99 + Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
102 case ACPI_IORT_NODE_RMR:
104 InfoTable = AcpiDmTableInfoIort6;
105 - Length = IortNode->Length - NodeOffset;
106 + Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
107 IortRmr = ACPI_ADD_PTR (ACPI_IORT_RMR, IortNode, NodeOffset);
110 @@ -202,7 +206,7 @@ AcpiDmDumpIort (
112 /* Attempt to continue */
114 - if (!IortNode->Length)
115 + if (!AcpiUtReadUint16 (&IortNode->Length))
117 AcpiOsPrintf ("Invalid zero length IORT node\n");
119 @@ -213,7 +217,7 @@ AcpiDmDumpIort (
120 /* Dump the node subtable header */
123 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
124 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
125 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
127 if (ACPI_FAILURE (Status))
128 @@ -233,9 +237,10 @@ AcpiDmDumpIort (
132 - for (i = 0; i < IortItsGroup->ItsCount; i++)
133 + UINT32 ItsCount = AcpiUtReadUint32 (&IortItsGroup->ItsCount);
134 + for (i = 0; i < ItsCount; i++)
136 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
137 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
138 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
139 4, AcpiDmTableInfoIort0a);
140 if (ACPI_FAILURE (Status))
141 @@ -252,12 +257,14 @@ AcpiDmDumpIort (
143 /* Dump the Padding (optional) */
145 - if (IortNode->Length > NodeOffset)
146 + NodeLength = AcpiUtReadUint16 (&IortNode->Length);
147 + if (NodeLength > NodeOffset)
150 - IortNode->MappingCount * sizeof (ACPI_IORT_ID_MAPPING);
151 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
152 - Table, IortNode->Length - NodeOffset - MappingByteLength,
153 + AcpiUtReadUint32 (&IortNode->MappingCount) *
154 + sizeof (ACPI_IORT_ID_MAPPING);
155 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
156 + Table, NodeLength - NodeOffset - MappingByteLength,
157 AcpiDmTableInfoIort1a);
158 if (ACPI_FAILURE (Status))
160 @@ -274,9 +281,11 @@ AcpiDmDumpIort (
164 + UINT32 InterruptCount;
166 Length = 2 * sizeof (UINT64);
167 - NodeOffset = IortSmmu->GlobalInterruptOffset;
168 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
169 + NodeOffset = AcpiUtReadUint32 (&IortSmmu->GlobalInterruptOffset);
170 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
171 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
172 Length, AcpiDmTableInfoIort3a);
173 if (ACPI_FAILURE (Status))
174 @@ -284,10 +293,11 @@ AcpiDmDumpIort (
178 - NodeOffset = IortSmmu->ContextInterruptOffset;
179 - for (i = 0; i < IortSmmu->ContextInterruptCount; i++)
180 + NodeOffset = AcpiUtReadUint32 (&IortSmmu->ContextInterruptOffset);
181 + InterruptCount = AcpiUtReadUint32 (&IortSmmu->ContextInterruptCount);
182 + for (i = 0; i < InterruptCount; i++)
184 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
185 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
186 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
187 8, AcpiDmTableInfoIort3b);
188 if (ACPI_FAILURE (Status))
189 @@ -298,10 +308,11 @@ AcpiDmDumpIort (
193 - NodeOffset = IortSmmu->PmuInterruptOffset;
194 - for (i = 0; i < IortSmmu->PmuInterruptCount; i++)
195 + NodeOffset = AcpiUtReadUint32 (&IortSmmu->PmuInterruptOffset);
196 + InterruptCount = AcpiUtReadUint32 (&IortSmmu->PmuInterruptCount);
197 + for (i = 0; i < InterruptCount; i++)
199 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
200 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
201 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
202 8, AcpiDmTableInfoIort3c);
203 if (ACPI_FAILURE (Status))
204 @@ -319,12 +330,15 @@ AcpiDmDumpIort (
205 /* Validate IortRmr to avoid compiler warnings */
208 - NodeOffset = IortRmr->RmrOffset;
211 + NodeOffset = AcpiUtReadUint32 (&IortRmr->RmrOffset);
212 + RmrCount = AcpiUtReadUint32 (&IortRmr->RmrCount);
213 Length = sizeof (ACPI_IORT_RMR_DESC);
214 - for (i = 0; i < IortRmr->RmrCount; i++)
215 + for (i = 0; i < RmrCount; i++)
218 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
219 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
220 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
221 Length, AcpiDmTableInfoIort6a);
222 if (ACPI_FAILURE (Status))
223 @@ -344,12 +358,13 @@ AcpiDmDumpIort (
225 /* Dump the ID mappings */
227 - NodeOffset = IortNode->MappingOffset;
228 - for (i = 0; i < IortNode->MappingCount; i++)
229 + NodeOffset = AcpiUtReadUint32 (&IortNode->MappingOffset);
230 + MappingCount = AcpiUtReadUint32 (&IortNode->MappingCount);
231 + for (i = 0; i < MappingCount; i++)
234 Length = sizeof (ACPI_IORT_ID_MAPPING);
235 - Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
236 + Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
237 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
238 Length, AcpiDmTableInfoIortMap);
239 if (ACPI_FAILURE (Status))
240 @@ -363,7 +378,7 @@ AcpiDmDumpIort (
242 /* Point to next node subtable */
244 - Offset += IortNode->Length;
245 + Offset += AcpiUtReadUint16 (&IortNode->Length);
249 Index: acpica-unix2-20220331/source/compiler/dttable1.c
250 ===================================================================
251 --- acpica-unix2-20220331.orig/source/compiler/dttable1.c
252 +++ acpica-unix2-20220331/source/compiler/dttable1.c
253 @@ -1960,6 +1960,7 @@ DtCompileIort (
254 ACPI_IORT_ITS_GROUP *IortItsGroup;
255 ACPI_IORT_SMMU *IortSmmu;
256 ACPI_IORT_RMR *IortRmr;
257 + UINT32 IortNodeOffset;
260 UINT32 IdMappingNumber;
261 @@ -2005,7 +2006,7 @@ DtCompileIort (
262 * Optionally allows the generic data types to be used for filling
265 - Iort->NodeOffset = sizeof (ACPI_TABLE_IORT);
266 + IortNodeOffset = sizeof (ACPI_TABLE_IORT);
267 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIortPad,
269 if (ACPI_FAILURE (Status))
270 @@ -2015,7 +2016,7 @@ DtCompileIort (
273 DtInsertSubtable (ParentTable, Subtable);
274 - Iort->NodeOffset += Subtable->Length;
275 + IortNodeOffset += Subtable->Length;
279 @@ -2025,7 +2026,7 @@ DtCompileIort (
283 - Iort->NodeOffset += PaddingLength;
284 + IortNodeOffset += PaddingLength;
288 @@ -2089,7 +2090,7 @@ DtCompileIort (
292 - IortItsGroup->ItsCount = ItsNumber;
293 + IortItsGroup->ItsCount = AcpiUtReadUint32 (&ItsNumber);
296 case ACPI_IORT_NODE_NAMED_COMPONENT:
297 @@ -2123,15 +2124,18 @@ DtCompileIort (
301 - if (NodeLength > IortNode->MappingOffset)
302 + UINT32 MappingOffset;
304 + MappingOffset = IortNode->MappingOffset;
305 + if (NodeLength > MappingOffset)
307 return (AE_BAD_DATA);
310 - if (NodeLength < IortNode->MappingOffset)
311 + if (NodeLength < MappingOffset)
313 Status = DtCompilePadding (
314 - IortNode->MappingOffset - NodeLength,
315 + MappingOffset - NodeLength,
317 if (ACPI_FAILURE (Status))
319 @@ -2139,7 +2143,7 @@ DtCompileIort (
322 DtInsertSubtable (ParentTable, Subtable);
323 - NodeLength = IortNode->MappingOffset;
324 + NodeLength = MappingOffset;
328 @@ -2172,7 +2176,7 @@ DtCompileIort (
330 /* Compile global interrupt array */
332 - IortSmmu->GlobalInterruptOffset = NodeLength;
333 + IortSmmu->GlobalInterruptOffset = AcpiUtReadUint32 (&NodeLength);
334 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort3a,
336 if (ACPI_FAILURE (Status))
337 @@ -2186,7 +2190,7 @@ DtCompileIort (
338 /* Compile context interrupt array */
340 ContextIrptNumber = 0;
341 - IortSmmu->ContextInterruptOffset = NodeLength;
342 + IortSmmu->ContextInterruptOffset = AcpiUtReadUint32 (&NodeLength);
345 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort3b,
346 @@ -2206,12 +2210,12 @@ DtCompileIort (
350 - IortSmmu->ContextInterruptCount = ContextIrptNumber;
351 + IortSmmu->ContextInterruptCount = AcpiUtReadUint32 (&ContextIrptNumber);
353 /* Compile PMU interrupt array */
356 - IortSmmu->PmuInterruptOffset = NodeLength;
357 + IortSmmu->PmuInterruptOffset = AcpiUtReadUint32 (&NodeLength);
360 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort3c,
361 @@ -2231,7 +2235,7 @@ DtCompileIort (
365 - IortSmmu->PmuInterruptCount = PmuIrptNumber;
366 + IortSmmu->PmuInterruptCount = AcpiUtReadUint32 (&PmuIrptNumber);
369 case ACPI_IORT_NODE_SMMU_V3:
370 @@ -2276,7 +2280,7 @@ DtCompileIort (
371 /* Compile RMR Descriptors */
374 - IortRmr->RmrOffset = NodeLength;
375 + IortRmr->RmrOffset = AcpiUtReadUint32 (&NodeLength);
378 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort6a,
379 @@ -2296,7 +2300,7 @@ DtCompileIort (
383 - IortRmr->RmrCount = RmrCount;
384 + IortRmr->RmrCount = AcpiUtReadUint32 (&RmrCount);
388 @@ -2307,7 +2311,7 @@ DtCompileIort (
390 /* Compile Array of ID mappings */
392 - IortNode->MappingOffset = NodeLength;
393 + IortNode->MappingOffset = AcpiUtReadUint32 (&NodeLength);
397 @@ -2328,7 +2332,7 @@ DtCompileIort (
401 - IortNode->MappingCount = IdMappingNumber;
402 + IortNode->MappingCount = AcpiUtReadUint32 (&IdMappingNumber);
403 if (!IdMappingNumber)
405 IortNode->MappingOffset = 0;
406 @@ -2343,7 +2347,7 @@ DtCompileIort (
410 - Iort->NodeCount = NodeNumber;
411 + Iort->NodeCount = AcpiUtReadUint32 (&NodeNumber);