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