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