]>
Commit | Line | Data |
---|---|---|
a6eaba4d | 1 | /** @file\r |
ee4dc24f RN |
2 | SRAT table parser\r |
3 | \r | |
4 | Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.\r | |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ee4dc24f RN |
6 | \r |
7 | @par Reference(s):\r | |
8 | - ACPI 6.2 Specification - Errata A, September 2017\r | |
9 | **/\r | |
10 | \r | |
11 | #include <IndustryStandard/Acpi.h>\r | |
12 | #include <Library/PrintLib.h>\r | |
13 | #include <Library/UefiLib.h>\r | |
14 | #include "AcpiParser.h"\r | |
15 | #include "AcpiTableParser.h"\r | |
16 | \r | |
17 | // Local Variables\r | |
18 | STATIC CONST UINT8* SratRAType;\r | |
19 | STATIC CONST UINT8* SratRALength;\r | |
20 | STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r | |
21 | \r | |
a6eaba4d DB |
22 | /**\r |
23 | This function validates the Reserved field in the SRAT table header.\r | |
ee4dc24f RN |
24 | \r |
25 | @param [in] Ptr Pointer to the start of the field data.\r | |
26 | @param [in] Context Pointer to context specific information e.g. this\r | |
27 | could be a pointer to the ACPI table header.\r | |
a6eaba4d | 28 | **/\r |
ee4dc24f RN |
29 | STATIC\r |
30 | VOID\r | |
31 | EFIAPI\r | |
32 | ValidateSratReserved (\r | |
33 | IN UINT8* Ptr,\r | |
34 | IN VOID* Context\r | |
35 | );\r | |
36 | \r | |
a6eaba4d DB |
37 | /**\r |
38 | This function traces the APIC Proximity Domain field.\r | |
ee4dc24f RN |
39 | \r |
40 | @param [in] Format Format string for tracing the data.\r | |
41 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 42 | **/\r |
ee4dc24f RN |
43 | STATIC\r |
44 | VOID\r | |
7343bc80 | 45 | EFIAPI\r |
ee4dc24f RN |
46 | DumpSratApicProximity (\r |
47 | IN CONST CHAR16* Format,\r | |
48 | IN UINT8* Ptr\r | |
49 | );\r | |
50 | \r | |
a6eaba4d DB |
51 | /**\r |
52 | An ACPI_PARSER array describing the SRAT Table.\r | |
53 | **/\r | |
ee4dc24f RN |
54 | STATIC CONST ACPI_PARSER SratParser[] = {\r |
55 | PARSE_ACPI_HEADER (&AcpiHdrInfo),\r | |
56 | {L"Reserved", 4, 36, L"0x%x", NULL, NULL, ValidateSratReserved, NULL},\r | |
57 | {L"Reserved", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL}\r | |
58 | };\r | |
59 | \r | |
a6eaba4d DB |
60 | /**\r |
61 | An ACPI_PARSER array describing the Resource Allocation structure header.\r | |
62 | **/\r | |
ee4dc24f RN |
63 | STATIC CONST ACPI_PARSER SratResourceAllocationParser[] = {\r |
64 | {L"Type", 1, 0, NULL, NULL, (VOID**)&SratRAType, NULL, NULL},\r | |
65 | {L"Length", 1, 1, NULL, NULL, (VOID**)&SratRALength, NULL, NULL}\r | |
66 | };\r | |
67 | \r | |
a6eaba4d DB |
68 | /**\r |
69 | An ACPI_PARSER array describing the GICC Affinity structure.\r | |
70 | **/\r | |
ee4dc24f RN |
71 | STATIC CONST ACPI_PARSER SratGicCAffinityParser[] = {\r |
72 | {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r | |
73 | {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r | |
74 | \r | |
75 | {L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL},\r | |
76 | {L"ACPI Processor UID", 4, 6, L"0x%x", NULL, NULL, NULL, NULL},\r | |
77 | {L"Flags", 4, 10, L"0x%x", NULL, NULL, NULL, NULL},\r | |
78 | {L"Clock Domain", 4, 14, L"0x%x", NULL, NULL, NULL, NULL}\r | |
79 | };\r | |
80 | \r | |
a6eaba4d DB |
81 | /**\r |
82 | An ACPI_PARSER array describing the GIC ITS Affinity structure.\r | |
83 | **/\r | |
ee4dc24f RN |
84 | STATIC CONST ACPI_PARSER SratGicITSAffinityParser[] = {\r |
85 | {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r | |
86 | {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r | |
87 | \r | |
88 | {L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL},\r | |
89 | {L"Reserved", 2, 6, L"0x%x", NULL, NULL, NULL, NULL},\r | |
90 | {L"ITS Id", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},\r | |
91 | };\r | |
92 | \r | |
a6eaba4d DB |
93 | /**\r |
94 | An ACPI_PARSER array describing the Memory Affinity structure.\r | |
95 | **/\r | |
ee4dc24f RN |
96 | STATIC CONST ACPI_PARSER SratMemAffinityParser[] = {\r |
97 | {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r | |
98 | {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r | |
99 | \r | |
100 | {L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL},\r | |
101 | {L"Reserved", 2, 6, L"0x%x", NULL, NULL, NULL, NULL},\r | |
102 | {L"Base Address Low", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},\r | |
103 | {L"Base Address High", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},\r | |
104 | {L"Length Low", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},\r | |
105 | {L"Length High", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},\r | |
106 | {L"Reserved", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},\r | |
107 | {L"Flags", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},\r | |
108 | {L"Reserved", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL}\r | |
109 | };\r | |
110 | \r | |
a6eaba4d DB |
111 | /**\r |
112 | An ACPI_PARSER array describing the APIC/SAPIC Affinity structure.\r | |
113 | **/\r | |
ee4dc24f RN |
114 | STATIC CONST ACPI_PARSER SratApciSapicAffinityParser[] = {\r |
115 | {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r | |
116 | {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r | |
117 | \r | |
118 | {L"Proximity Domain [7:0]", 1, 2, L"0x%x", NULL, NULL, NULL, NULL},\r | |
119 | {L"APIC ID", 1, 3, L"0x%x", NULL, NULL, NULL, NULL},\r | |
120 | {L"Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},\r | |
121 | {L"Local SAPIC EID", 1, 8, L"0x%x", NULL, NULL, NULL, NULL},\r | |
122 | {L"Proximity Domain [31:8]", 3, 9, L"0x%x", DumpSratApicProximity,\r | |
123 | NULL, NULL, NULL},\r | |
124 | {L"Clock Domain", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}\r | |
125 | };\r | |
126 | \r | |
a6eaba4d DB |
127 | /**\r |
128 | An ACPI_PARSER array describing the Processor Local x2APIC Affinity structure.\r | |
129 | **/\r | |
ee4dc24f RN |
130 | STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[] = {\r |
131 | {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r | |
132 | {L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r | |
133 | \r | |
134 | {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},\r | |
135 | {L"Proximity Domain", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},\r | |
136 | {L"X2APIC ID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},\r | |
137 | {L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},\r | |
138 | {L"Clock Domain", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},\r | |
139 | {L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL}\r | |
140 | };\r | |
141 | \r | |
142 | /** This function validates the Reserved field in the SRAT table header.\r | |
143 | \r | |
144 | @param [in] Ptr Pointer to the start of the field data.\r | |
145 | @param [in] Context Pointer to context specific information e.g. this\r | |
146 | could be a pointer to the ACPI table header.\r | |
a6eaba4d | 147 | **/\r |
ee4dc24f RN |
148 | STATIC\r |
149 | VOID\r | |
150 | EFIAPI\r | |
151 | ValidateSratReserved (\r | |
152 | IN UINT8* Ptr,\r | |
153 | IN VOID* Context\r | |
154 | )\r | |
155 | {\r | |
156 | if (*(UINT32*)Ptr != 1) {\r | |
157 | IncrementErrorCount ();\r | |
158 | Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");\r | |
159 | }\r | |
160 | }\r | |
161 | \r | |
a6eaba4d DB |
162 | /**\r |
163 | This function traces the APIC Proximity Domain field.\r | |
ee4dc24f RN |
164 | \r |
165 | @param [in] Format Format string for tracing the data.\r | |
166 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 167 | **/\r |
ee4dc24f RN |
168 | STATIC\r |
169 | VOID\r | |
7343bc80 | 170 | EFIAPI\r |
ee4dc24f RN |
171 | DumpSratApicProximity (\r |
172 | IN CONST CHAR16* Format,\r | |
173 | IN UINT8* Ptr\r | |
174 | )\r | |
175 | {\r | |
f75c7478 DB |
176 | UINT32 ProximityDomain;\r |
177 | \r | |
178 | ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);\r | |
179 | \r | |
ee4dc24f RN |
180 | Print (Format, ProximityDomain);\r |
181 | }\r | |
182 | \r | |
a6eaba4d DB |
183 | /**\r |
184 | This function parses the ACPI SRAT table.\r | |
ee4dc24f RN |
185 | When trace is enabled this function parses the SRAT table and\r |
186 | traces the ACPI table fields.\r | |
187 | \r | |
188 | This function parses the following Resource Allocation Structures:\r | |
189 | - Processor Local APIC/SAPIC Affinity Structure\r | |
190 | - Memory Affinity Structure\r | |
191 | - Processor Local x2APIC Affinity Structure\r | |
192 | - GICC Affinity Structure\r | |
193 | \r | |
194 | This function also performs validation of the ACPI table fields.\r | |
195 | \r | |
196 | @param [in] Trace If TRUE, trace the ACPI fields.\r | |
197 | @param [in] Ptr Pointer to the start of the buffer.\r | |
198 | @param [in] AcpiTableLength Length of the ACPI table.\r | |
199 | @param [in] AcpiTableRevision Revision of the ACPI table.\r | |
a6eaba4d | 200 | **/\r |
ee4dc24f RN |
201 | VOID\r |
202 | EFIAPI\r | |
203 | ParseAcpiSrat (\r | |
204 | IN BOOLEAN Trace,\r | |
205 | IN UINT8* Ptr,\r | |
206 | IN UINT32 AcpiTableLength,\r | |
207 | IN UINT8 AcpiTableRevision\r | |
208 | )\r | |
209 | {\r | |
210 | UINT32 Offset;\r | |
211 | UINT8* ResourcePtr;\r | |
f75c7478 DB |
212 | UINT32 GicCAffinityIndex;\r |
213 | UINT32 GicITSAffinityIndex;\r | |
214 | UINT32 MemoryAffinityIndex;\r | |
215 | UINT32 ApicSapicAffinityIndex;\r | |
216 | UINT32 X2ApicAffinityIndex;\r | |
ee4dc24f RN |
217 | CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi\r |
218 | \r | |
f75c7478 DB |
219 | GicCAffinityIndex = 0;\r |
220 | GicITSAffinityIndex = 0;\r | |
221 | MemoryAffinityIndex = 0;\r | |
222 | ApicSapicAffinityIndex = 0;\r | |
223 | X2ApicAffinityIndex = 0;\r | |
224 | \r | |
ee4dc24f RN |
225 | if (!Trace) {\r |
226 | return;\r | |
227 | }\r | |
228 | \r | |
229 | Offset = ParseAcpi (\r | |
230 | TRUE,\r | |
231 | 0,\r | |
232 | "SRAT",\r | |
233 | Ptr,\r | |
234 | AcpiTableLength,\r | |
235 | PARSER_PARAMS (SratParser)\r | |
236 | );\r | |
237 | ResourcePtr = Ptr + Offset;\r | |
238 | \r | |
239 | while (Offset < AcpiTableLength) {\r | |
240 | ParseAcpi (\r | |
241 | FALSE,\r | |
242 | 0,\r | |
243 | NULL,\r | |
244 | ResourcePtr,\r | |
245 | 2, // The length is 1 byte at offset 1\r | |
246 | PARSER_PARAMS (SratResourceAllocationParser)\r | |
247 | );\r | |
248 | \r | |
249 | switch (*SratRAType) {\r | |
250 | case EFI_ACPI_6_2_GICC_AFFINITY:\r | |
251 | AsciiSPrint (\r | |
252 | Buffer,\r | |
253 | sizeof (Buffer),\r | |
254 | "GICC Affinity Structure [%d]",\r | |
255 | GicCAffinityIndex++\r | |
256 | );\r | |
257 | ParseAcpi (\r | |
258 | TRUE,\r | |
259 | 2,\r | |
260 | Buffer,\r | |
261 | ResourcePtr,\r | |
262 | *SratRALength,\r | |
263 | PARSER_PARAMS (SratGicCAffinityParser)\r | |
264 | );\r | |
265 | break;\r | |
266 | \r | |
267 | case EFI_ACPI_6_2_GIC_ITS_AFFINITY:\r | |
268 | AsciiSPrint (\r | |
269 | Buffer,\r | |
270 | sizeof (Buffer),\r | |
271 | "GIC ITS Affinity Structure [%d]",\r | |
272 | GicITSAffinityIndex++\r | |
273 | );\r | |
274 | ParseAcpi (\r | |
275 | TRUE,\r | |
276 | 2,\r | |
277 | Buffer,\r | |
278 | ResourcePtr,\r | |
279 | *SratRALength,\r | |
280 | PARSER_PARAMS (SratGicITSAffinityParser)\r | |
281 | );\r | |
282 | break;\r | |
283 | \r | |
284 | case EFI_ACPI_6_2_MEMORY_AFFINITY:\r | |
285 | AsciiSPrint (\r | |
286 | Buffer,\r | |
287 | sizeof (Buffer),\r | |
288 | "Memory Affinity Structure [%d]",\r | |
289 | MemoryAffinityIndex++\r | |
290 | );\r | |
291 | ParseAcpi (\r | |
292 | TRUE,\r | |
293 | 2,\r | |
294 | Buffer,\r | |
295 | ResourcePtr,\r | |
296 | *SratRALength,\r | |
297 | PARSER_PARAMS (SratMemAffinityParser)\r | |
298 | );\r | |
299 | break;\r | |
300 | \r | |
301 | case EFI_ACPI_6_2_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY:\r | |
302 | AsciiSPrint (\r | |
303 | Buffer,\r | |
304 | sizeof (Buffer),\r | |
305 | "APIC/SAPIC Affinity Structure [%d]",\r | |
306 | ApicSapicAffinityIndex++\r | |
307 | );\r | |
308 | ParseAcpi (\r | |
309 | TRUE,\r | |
310 | 2,\r | |
311 | Buffer,\r | |
312 | ResourcePtr,\r | |
313 | *SratRALength,\r | |
314 | PARSER_PARAMS (SratApciSapicAffinityParser)\r | |
315 | );\r | |
316 | break;\r | |
317 | \r | |
318 | case EFI_ACPI_6_2_PROCESSOR_LOCAL_X2APIC_AFFINITY:\r | |
319 | AsciiSPrint (\r | |
320 | Buffer,\r | |
321 | sizeof (Buffer),\r | |
322 | "X2APIC Affinity Structure [%d]",\r | |
323 | X2ApicAffinityIndex++\r | |
324 | );\r | |
325 | ParseAcpi (\r | |
326 | TRUE,\r | |
327 | 2,\r | |
328 | Buffer,\r | |
329 | ResourcePtr,\r | |
330 | *SratRALength,\r | |
331 | PARSER_PARAMS (SratX2ApciAffinityParser)\r | |
332 | );\r | |
333 | break;\r | |
334 | \r | |
335 | default:\r | |
336 | IncrementErrorCount ();\r | |
337 | Print (L"ERROR: Unknown SRAT Affinity type = 0x%x\n", *SratRAType);\r | |
338 | break;\r | |
339 | }\r | |
340 | \r | |
341 | ResourcePtr += (*SratRALength);\r | |
342 | Offset += (*SratRALength);\r | |
343 | }\r | |
344 | }\r |