]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Srat/SratParser.c
fbe943d898ad96158f51d5afffe1fe17893ae62f
[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 = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
181 Print (Format, ProximityDomain);
182 }
183
184 /**
185 This function parses the ACPI SRAT table.
186 When trace is enabled this function parses the SRAT table and
187 traces the ACPI table fields.
188
189 This function parses the following Resource Allocation Structures:
190 - Processor Local APIC/SAPIC Affinity Structure
191 - Memory Affinity Structure
192 - Processor Local x2APIC Affinity Structure
193 - GICC Affinity Structure
194
195 This function also performs validation of the ACPI table fields.
196
197 @param [in] Trace If TRUE, trace the ACPI fields.
198 @param [in] Ptr Pointer to the start of the buffer.
199 @param [in] AcpiTableLength Length of the ACPI table.
200 @param [in] AcpiTableRevision Revision of the ACPI table.
201 **/
202 VOID
203 EFIAPI
204 ParseAcpiSrat (
205 IN BOOLEAN Trace,
206 IN UINT8* Ptr,
207 IN UINT32 AcpiTableLength,
208 IN UINT8 AcpiTableRevision
209 )
210 {
211 UINT32 Offset;
212 UINT8* ResourcePtr;
213 UINT32 GicCAffinityIndex = 0;
214 UINT32 GicITSAffinityIndex = 0;
215 UINT32 MemoryAffinityIndex = 0;
216 UINT32 ApicSapicAffinityIndex = 0;
217 UINT32 X2ApicAffinityIndex = 0;
218 CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi
219
220 if (!Trace) {
221 return;
222 }
223
224 Offset = ParseAcpi (
225 TRUE,
226 0,
227 "SRAT",
228 Ptr,
229 AcpiTableLength,
230 PARSER_PARAMS (SratParser)
231 );
232 ResourcePtr = Ptr + Offset;
233
234 while (Offset < AcpiTableLength) {
235 ParseAcpi (
236 FALSE,
237 0,
238 NULL,
239 ResourcePtr,
240 2, // The length is 1 byte at offset 1
241 PARSER_PARAMS (SratResourceAllocationParser)
242 );
243
244 switch (*SratRAType) {
245 case EFI_ACPI_6_2_GICC_AFFINITY:
246 AsciiSPrint (
247 Buffer,
248 sizeof (Buffer),
249 "GICC Affinity Structure [%d]",
250 GicCAffinityIndex++
251 );
252 ParseAcpi (
253 TRUE,
254 2,
255 Buffer,
256 ResourcePtr,
257 *SratRALength,
258 PARSER_PARAMS (SratGicCAffinityParser)
259 );
260 break;
261
262 case EFI_ACPI_6_2_GIC_ITS_AFFINITY:
263 AsciiSPrint (
264 Buffer,
265 sizeof (Buffer),
266 "GIC ITS Affinity Structure [%d]",
267 GicITSAffinityIndex++
268 );
269 ParseAcpi (
270 TRUE,
271 2,
272 Buffer,
273 ResourcePtr,
274 *SratRALength,
275 PARSER_PARAMS (SratGicITSAffinityParser)
276 );
277 break;
278
279 case EFI_ACPI_6_2_MEMORY_AFFINITY:
280 AsciiSPrint (
281 Buffer,
282 sizeof (Buffer),
283 "Memory Affinity Structure [%d]",
284 MemoryAffinityIndex++
285 );
286 ParseAcpi (
287 TRUE,
288 2,
289 Buffer,
290 ResourcePtr,
291 *SratRALength,
292 PARSER_PARAMS (SratMemAffinityParser)
293 );
294 break;
295
296 case EFI_ACPI_6_2_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY:
297 AsciiSPrint (
298 Buffer,
299 sizeof (Buffer),
300 "APIC/SAPIC Affinity Structure [%d]",
301 ApicSapicAffinityIndex++
302 );
303 ParseAcpi (
304 TRUE,
305 2,
306 Buffer,
307 ResourcePtr,
308 *SratRALength,
309 PARSER_PARAMS (SratApciSapicAffinityParser)
310 );
311 break;
312
313 case EFI_ACPI_6_2_PROCESSOR_LOCAL_X2APIC_AFFINITY:
314 AsciiSPrint (
315 Buffer,
316 sizeof (Buffer),
317 "X2APIC Affinity Structure [%d]",
318 X2ApicAffinityIndex++
319 );
320 ParseAcpi (
321 TRUE,
322 2,
323 Buffer,
324 ResourcePtr,
325 *SratRALength,
326 PARSER_PARAMS (SratX2ApciAffinityParser)
327 );
328 break;
329
330 default:
331 IncrementErrorCount ();
332 Print (L"ERROR: Unknown SRAT Affinity type = 0x%x\n", *SratRAType);
333 break;
334 }
335
336 ResourcePtr += (*SratRALength);
337 Offset += (*SratRALength);
338 }
339 }