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