1 From 915b8b70726fd01befdeac0c8630db528ac40552 Mon Sep 17 00:00:00 2001
2 From: Al Stone <ahs3@redhat.com>
3 Date: Fri, 25 Sep 2020 16:56:55 -0600
4 Subject: [PATCH 28/45] Support HMAT in a big-endian world
6 Signed-off-by: Al Stone <ahs3@redhat.com>
8 source/common/dmtbdump1.c | 70 ++++++++++++++++++++++----------------
9 source/compiler/dttable1.c | 24 ++++++++++---
10 2 files changed, 59 insertions(+), 35 deletions(-)
12 Index: acpica-unix2-20220331/source/common/dmtbdump1.c
13 ===================================================================
14 --- acpica-unix2-20220331.orig/source/common/dmtbdump1.c
15 +++ acpica-unix2-20220331/source/common/dmtbdump1.c
16 @@ -1680,37 +1680,45 @@ AcpiDmDumpHmat (
18 ACPI_DMTABLE_INFO *InfoTable;
20 + UINT32 TableLength = AcpiUtReadUint32 (&Table->Length);
21 + UINT16 HmatStructType;
22 + UINT32 HmatStructLength;
25 + UINT16 SMBIOSHandles;
30 - Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, AcpiDmTableInfoHmat);
31 + Status = AcpiDmDumpTable (TableLength, 0, Table, 0, AcpiDmTableInfoHmat);
32 if (ACPI_FAILURE (Status))
36 Offset = sizeof (ACPI_TABLE_HMAT);
38 - while (Offset < Table->Length)
39 + while (Offset < TableLength)
43 /* Dump HMAT structure header */
45 HmatStruct = ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, Table, Offset);
46 - if (HmatStruct->Length < sizeof (ACPI_HMAT_STRUCTURE))
47 + HmatStructLength = AcpiUtReadUint32 (&HmatStruct->Length);
48 + if (HmatStructLength < sizeof (ACPI_HMAT_STRUCTURE))
50 AcpiOsPrintf ("Invalid HMAT structure length\n");
53 - Status = AcpiDmDumpTable (Table->Length, Offset, HmatStruct,
54 - HmatStruct->Length, AcpiDmTableInfoHmatHdr);
55 + Status = AcpiDmDumpTable (TableLength, Offset, HmatStruct,
56 + HmatStructLength, AcpiDmTableInfoHmatHdr);
57 if (ACPI_FAILURE (Status))
62 - switch (HmatStruct->Type)
63 + HmatStructType = AcpiUtReadUint16 (&HmatStruct->Type);
64 + switch (HmatStructType)
66 case ACPI_HMAT_TYPE_ADDRESS_RANGE:
68 @@ -1733,7 +1741,7 @@ AcpiDmDumpHmat (
71 AcpiOsPrintf ("\n**** Unknown HMAT structure type 0x%X\n",
75 /* Attempt to continue */
77 @@ -1742,13 +1750,13 @@ AcpiDmDumpHmat (
79 /* Dump HMAT structure body */
81 - if (HmatStruct->Length < Length)
82 + if (HmatStructLength < Length)
84 AcpiOsPrintf ("Invalid HMAT structure length\n");
87 - Status = AcpiDmDumpTable (Table->Length, Offset, HmatStruct,
88 - HmatStruct->Length, InfoTable);
89 + Status = AcpiDmDumpTable (TableLength, Offset, HmatStruct,
90 + HmatStructLength, InfoTable);
91 if (ACPI_FAILURE (Status))
94 @@ -1756,7 +1764,7 @@ AcpiDmDumpHmat (
96 /* Dump HMAT structure additionals */
98 - switch (HmatStruct->Type)
99 + switch (HmatStructType)
101 case ACPI_HMAT_TYPE_LOCALITY:
103 @@ -1765,15 +1773,16 @@ AcpiDmDumpHmat (
105 /* Dump initiator proximity domains */
107 - if ((UINT32)(HmatStruct->Length - SubtableOffset) <
108 - (UINT32)(HmatLocality->NumberOfInitiatorPDs * 4))
109 + InitPDs = AcpiUtReadUint32 (&HmatLocality->NumberOfInitiatorPDs);
110 + if ((UINT32) (HmatStructLength - SubtableOffset) <
111 + (UINT32) (InitPDs * 4))
113 AcpiOsPrintf ("Invalid initiator proximity domain number\n");
116 - for (i = 0; i < HmatLocality->NumberOfInitiatorPDs; i++)
117 + for (i = 0; i < InitPDs; i++)
119 - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
120 + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
121 ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
122 4, AcpiDmTableInfoHmat1a);
123 if (ACPI_FAILURE (Status))
124 @@ -1786,15 +1795,16 @@ AcpiDmDumpHmat (
126 /* Dump target proximity domains */
128 - if ((UINT32)(HmatStruct->Length - SubtableOffset) <
129 - (UINT32)(HmatLocality->NumberOfTargetPDs * 4))
130 + TgtPDs = AcpiUtReadUint32 (&HmatLocality->NumberOfTargetPDs);
131 + if ((UINT32) (HmatStructLength - SubtableOffset) <
132 + (UINT32) (TgtPDs * 4))
134 AcpiOsPrintf ("Invalid target proximity domain number\n");
137 - for (i = 0; i < HmatLocality->NumberOfTargetPDs; i++)
138 + for (i = 0; i < TgtPDs; i++)
140 - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
141 + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
142 ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
143 4, AcpiDmTableInfoHmat1b);
144 if (ACPI_FAILURE (Status))
145 @@ -1807,18 +1817,17 @@ AcpiDmDumpHmat (
147 /* Dump latency/bandwidth entris */
149 - if ((UINT32)(HmatStruct->Length - SubtableOffset) <
150 - (UINT32)(HmatLocality->NumberOfInitiatorPDs *
151 - HmatLocality->NumberOfTargetPDs * 2))
152 + if ((UINT32) (HmatStructLength - SubtableOffset) <
153 + (UINT32) (InitPDs * TgtPDs * 2))
155 AcpiOsPrintf ("Invalid latency/bandwidth entry number\n");
158 - for (i = 0; i < HmatLocality->NumberOfInitiatorPDs; i++)
159 + for (i = 0; i < InitPDs; i++)
161 - for (j = 0; j < HmatLocality->NumberOfTargetPDs; j++)
162 + for (j = 0; j < TgtPDs; j++)
164 - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
165 + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
166 ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
167 2, AcpiDmTableInfoHmat1c);
168 if (ACPI_FAILURE(Status))
169 @@ -1838,15 +1847,16 @@ AcpiDmDumpHmat (
171 /* Dump SMBIOS handles */
173 - if ((UINT32)(HmatStruct->Length - SubtableOffset) <
174 - (UINT32)(HmatCache->NumberOfSMBIOSHandles * 2))
175 + SMBIOSHandles = AcpiUtReadUint16 (&HmatCache->NumberOfSMBIOSHandles);
176 + if ((UINT32) (HmatStructLength - SubtableOffset) <
177 + (UINT32) (SMBIOSHandles * 2))
179 AcpiOsPrintf ("Invalid SMBIOS handle number\n");
182 - for (i = 0; i < HmatCache->NumberOfSMBIOSHandles; i++)
183 + for (i = 0; i < SMBIOSHandles; i++)
185 - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
186 + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
187 ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
188 2, AcpiDmTableInfoHmat2a);
189 if (ACPI_FAILURE (Status))
190 @@ -1866,6 +1876,6 @@ AcpiDmDumpHmat (
192 /* Point to next HMAT structure subtable */
194 - Offset += (HmatStruct->Length);
195 + Offset += (HmatStructLength);
198 Index: acpica-unix2-20220331/source/compiler/dttable1.c
199 ===================================================================
200 --- acpica-unix2-20220331.orig/source/compiler/dttable1.c
201 +++ acpica-unix2-20220331/source/compiler/dttable1.c
202 @@ -1737,6 +1737,8 @@ DtCompileHmat (
205 UINT16 SMBIOSHandleNumber;
206 + UINT16 HmatStructType;
210 ParentTable = DtPeekSubtable ();
211 @@ -1767,7 +1769,8 @@ DtCompileHmat (
213 /* Compile HMAT structure body */
215 - switch (HmatStruct->Type)
216 + HmatStructType = AcpiUtReadUint16 (&HmatStruct->Type);
217 + switch (HmatStructType)
219 case ACPI_HMAT_TYPE_ADDRESS_RANGE:
221 @@ -1800,7 +1803,7 @@ DtCompileHmat (
223 /* Compile HMAT structure additionals */
225 - switch (HmatStruct->Type)
226 + switch (HmatStructType)
228 case ACPI_HMAT_TYPE_LOCALITY:
230 @@ -1826,7 +1829,7 @@ DtCompileHmat (
231 HmatStruct->Length += Subtable->Length;
234 - HmatLocality->NumberOfInitiatorPDs = IntPDNumber;
235 + HmatLocality->NumberOfInitiatorPDs = AcpiUtReadUint32 (&IntPDNumber);
237 /* Compile target proximity domain list */
239 @@ -1847,7 +1850,7 @@ DtCompileHmat (
240 HmatStruct->Length += Subtable->Length;
243 - HmatLocality->NumberOfTargetPDs = TgtPDNumber;
244 + HmatLocality->NumberOfTargetPDs = AcpiUtReadUint32 (&TgtPDNumber);
246 /* Save start of the entries for reporting errors */
248 @@ -1873,6 +1876,9 @@ DtCompileHmat (
252 + Length = AcpiUtReadUint32 (&HmatStruct->Length);
253 + HmatStruct->Length = Length;
255 /* Validate number of entries */
258 @@ -1906,11 +1912,19 @@ DtCompileHmat (
259 HmatStruct->Length += Subtable->Length;
260 SMBIOSHandleNumber++;
262 - HmatCache->NumberOfSMBIOSHandles = SMBIOSHandleNumber;
263 + HmatCache->NumberOfSMBIOSHandles =
264 + AcpiUtReadUint16 (&SMBIOSHandleNumber);
266 + Length = AcpiUtReadUint32 (&HmatStruct->Length);
267 + HmatStruct->Length = Length;
273 + Length = AcpiUtReadUint32(&HmatStruct->Length);
274 + HmatStruct->Length = Length;