TianoCore EDK2 master
Loading...
Searching...
No Matches
SratParser.c
Go to the documentation of this file.
1
12#include <Library/PrintLib.h>
13#include <Library/UefiLib.h>
14#include "AcpiParser.h"
15#include "AcpiTableParser.h"
16#include "AcpiViewConfig.h"
17
18// Local Variables
19STATIC CONST UINT8 *SratRAType;
20STATIC CONST UINT8 *SratRALength;
21STATIC CONST UINT8 *SratDeviceHandleType;
23
33VOID
34EFIAPI
36 IN UINT8 *Ptr,
37 IN UINT32 Length,
38 IN VOID *Context
39 )
40{
41 if (*(UINT32 *)Ptr != 1) {
43 Print (L"\nERROR: Reserved should be 1 for backward compatibility.\n");
44 }
45}
46
57VOID
58EFIAPI
60 IN UINT8 *Ptr,
61 IN UINT32 Length,
62 IN VOID *Context
63 )
64{
65 UINT8 DeviceHandleType;
66
67 DeviceHandleType = *Ptr;
68
69 if (DeviceHandleType > EFI_ACPI_6_3_PCI_DEVICE_HANDLE) {
71 Print (
72 L"\nERROR: Invalid Device Handle Type: %d. Must be between 0 and %d.",
73 DeviceHandleType,
74 EFI_ACPI_6_3_PCI_DEVICE_HANDLE
75 );
76 }
77}
78
87VOID
88EFIAPI
90 IN CONST CHAR16 *Format,
91 IN UINT8 *Ptr,
92 IN UINT32 Length
93 )
94{
95 CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
96
97 Print (L"\n");
98
99 /*
100 The PCI BDF Number subfields are printed in the order specified in the ACPI
101 specification. The format of the 16-bit PCI BDF Number field is as follows:
102
103 +-----+------+------+
104 |DEV | FUNC | BUS |
105 +-----+------+------+
106 |15:11| 10:8 | 7:0 |
107 +-----+------+------+
108 */
109
110 // Print PCI Bus Number (Bits 7:0 of Byte 2)
112 Buffer,
113 sizeof (Buffer),
114 L"PCI Bus Number"
115 );
116 PrintFieldName (4, Buffer);
117 Print (
118 L"0x%x\n",
119 *Ptr
120 );
121
122 Ptr++;
123
124 // Print PCI Device Number (Bits 7:3 of Byte 3)
126 Buffer,
127 sizeof (Buffer),
128 L"PCI Device Number"
129 );
130 PrintFieldName (4, Buffer);
131 Print (
132 L"0x%x\n",
133 (*Ptr & (BIT7 | BIT6 | BIT5 | BIT4 | BIT3)) >> 3
134 );
135
136 // PCI Function Number (Bits 2:0 of Byte 3)
138 Buffer,
139 sizeof (Buffer),
140 L"PCI Function Number"
141 );
142 PrintFieldName (4, Buffer);
143 Print (
144 L"0x%x\n",
145 *Ptr & (BIT2 | BIT1 | BIT0)
146 );
147}
148
153 { L"ACPI_HID", 8, 0, L"0x%lx", NULL, NULL, NULL, NULL },
154 { L"ACPI_UID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
155 { L"Reserved", 4, 12, L"0x%x", NULL, NULL, NULL, NULL }
156};
157
162 { L"PCI Segment", 2, 0, L"0x%x", NULL, NULL, NULL, NULL },
163 { L"PCI BDF Number", 2, 2, NULL, DumpSratPciBdfNumber, NULL, NULL, NULL },
164 { L"Reserved", 12, 4, L"%x %x %x %x - %x %x %x %x - %x %x %x %x", Dump12Chars,
165 NULL, NULL, NULL }
166};
167
176STATIC
177VOID
178EFIAPI
180 IN CONST CHAR16 *Format,
181 IN UINT8 *Ptr,
182 IN UINT32 Length
183 )
184{
185 if (SratDeviceHandleType == NULL) {
187 Print (L"\nERROR: Device Handle Type read incorrectly.\n");
188 return;
189 }
190
191 Print (L"\n");
192
193 if (*SratDeviceHandleType == EFI_ACPI_6_3_ACPI_DEVICE_HANDLE) {
194 ParseAcpi (
195 TRUE,
196 2,
197 NULL,
198 Ptr,
201 );
202 } else if (*SratDeviceHandleType == EFI_ACPI_6_3_PCI_DEVICE_HANDLE) {
203 ParseAcpi (
204 TRUE,
205 2,
206 NULL,
207 Ptr,
210 );
211 }
212}
213
221STATIC
222VOID
223EFIAPI
225 IN CONST CHAR16 *Format,
226 IN UINT8 *Ptr,
227 IN UINT32 Length
228 )
229{
230 UINT32 ProximityDomain;
231
232 ProximityDomain = Ptr[0] | (Ptr[1] << 8) | (Ptr[2] << 16);
233
234 Print (Format, ProximityDomain);
235}
236
241 PARSE_ACPI_HEADER (&AcpiHdrInfo),
242 { L"Reserved", 4, 36, L"0x%x", NULL, NULL, ValidateSratReserved, NULL },
243 { L"Reserved", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL }
244};
245
250 { L"Type", 1, 0, NULL, NULL, (VOID **)&SratRAType, NULL, NULL },
251 { L"Length", 1, 1, NULL, NULL, (VOID **)&SratRALength, NULL, NULL }
252};
253
258 { L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
259 { L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
260
261 { L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL },
262 { L"ACPI Processor UID", 4, 6, L"0x%x", NULL, NULL, NULL, NULL },
263 { L"Flags", 4, 10, L"0x%x", NULL, NULL, NULL, NULL },
264 { L"Clock Domain", 4, 14, L"0x%x", NULL, NULL, NULL, NULL }
265};
266
271 { L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
272 { L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
273
274 { L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL },
275 { L"Reserved", 2, 6, L"0x%x", NULL, NULL, NULL, NULL },
276 { L"ITS Id", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
277};
278
283 { L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
284 { L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
285
286 { L"Reserved", 1, 2, L"0x%x", NULL, NULL, NULL, NULL },
287 { L"Device Handle Type", 1, 3, L"%d", NULL, (VOID **)&SratDeviceHandleType,
289 { L"Proximity Domain", 4, 4, L"0x%x", NULL, NULL, NULL, NULL },
290 { L"Device Handle", 16, 8, L"%s", DumpSratDeviceHandle, NULL, NULL, NULL },
291 { L"Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL },
292 { L"Reserved", 4, 28, L"0x%x", NULL, NULL, NULL, NULL }
293};
294
299 { L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
300 { L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
301
302 { L"Proximity Domain", 4, 2, L"0x%x", NULL, NULL, NULL, NULL },
303 { L"Reserved", 2, 6, L"0x%x", NULL, NULL, NULL, NULL },
304 { L"Base Address Low", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
305 { L"Base Address High", 4, 12, L"0x%x", NULL, NULL, NULL, NULL },
306 { L"Length Low", 4, 16, L"0x%x", NULL, NULL, NULL, NULL },
307 { L"Length High", 4, 20, L"0x%x", NULL, NULL, NULL, NULL },
308 { L"Reserved", 4, 24, L"0x%x", NULL, NULL, NULL, NULL },
309 { L"Flags", 4, 28, L"0x%x", NULL, NULL, NULL, NULL },
310 { L"Reserved", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL }
311};
312
317 { L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
318 { L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
319
320 { L"Proximity Domain [7:0]", 1, 2, L"0x%x", NULL, NULL, NULL, NULL },
321 { L"APIC ID", 1, 3, L"0x%x", NULL, NULL, NULL, NULL },
322 { L"Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL },
323 { L"Local SAPIC EID", 1, 8, L"0x%x", NULL, NULL, NULL, NULL },
324 { L"Proximity Domain [31:8]", 3, 9, L"0x%x", DumpSratApicProximity,
325 NULL, NULL, NULL },
326 { L"Clock Domain", 4, 12, L"0x%x", NULL, NULL, NULL, NULL }
327};
328
333 { L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
334 { L"Length", 1, 1, L"0x%x", NULL, NULL, NULL, NULL },
335
336 { L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL },
337 { L"Proximity Domain", 4, 4, L"0x%x", NULL, NULL, NULL, NULL },
338 { L"X2APIC ID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL },
339 { L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL },
340 { L"Clock Domain", 4, 16, L"0x%x", NULL, NULL, NULL, NULL },
341 { L"Reserved", 4, 20, L"0x%x", NULL, NULL, NULL, NULL }
342};
343
362VOID
363EFIAPI
365 IN BOOLEAN Trace,
366 IN UINT8 *Ptr,
367 IN UINT32 AcpiTableLength,
368 IN UINT8 AcpiTableRevision
369 )
370{
371 UINT32 Offset;
372 UINT8 *ResourcePtr;
373 UINT32 GicCAffinityIndex;
374 UINT32 GicITSAffinityIndex;
375 UINT32 GenericInitiatorAffinityIndex;
376 UINT32 MemoryAffinityIndex;
377 UINT32 ApicSapicAffinityIndex;
378 UINT32 X2ApicAffinityIndex;
379 CHAR8 Buffer[80]; // Used for AsciiName param of ParseAcpi
380
381 GicCAffinityIndex = 0;
382 GicITSAffinityIndex = 0;
383 GenericInitiatorAffinityIndex = 0;
384 MemoryAffinityIndex = 0;
385 ApicSapicAffinityIndex = 0;
386 X2ApicAffinityIndex = 0;
387
388 if (!Trace) {
389 return;
390 }
391
392 Offset = ParseAcpi (
393 TRUE,
394 0,
395 "SRAT",
396 Ptr,
397 AcpiTableLength,
399 );
400
401 ResourcePtr = Ptr + Offset;
402
403 while (Offset < AcpiTableLength) {
404 ParseAcpi (
405 FALSE,
406 0,
407 NULL,
408 ResourcePtr,
409 AcpiTableLength - Offset,
411 );
412
413 // Check if the values used to control the parsing logic have been
414 // successfully read.
415 if ((SratRAType == NULL) ||
416 (SratRALength == NULL))
417 {
419 Print (
420 L"ERROR: Insufficient remaining table buffer length to read the " \
421 L"Static Resource Allocation structure header. Length = %d.\n",
422 AcpiTableLength - Offset
423 );
424 return;
425 }
426
427 // Validate Static Resource Allocation Structure length
428 if ((*SratRALength == 0) ||
429 ((Offset + (*SratRALength)) > AcpiTableLength))
430 {
432 Print (
433 L"ERROR: Invalid Static Resource Allocation Structure length. " \
434 L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
435 *SratRALength,
436 Offset,
437 AcpiTableLength
438 );
439 return;
440 }
441
442 switch (*SratRAType) {
443 case EFI_ACPI_6_3_GICC_AFFINITY:
445 Buffer,
446 sizeof (Buffer),
447 "GICC Affinity Structure [%d]",
448 GicCAffinityIndex++
449 );
450 ParseAcpi (
451 TRUE,
452 2,
453 Buffer,
454 ResourcePtr,
455 *SratRALength,
457 );
458 break;
459
460 case EFI_ACPI_6_3_GIC_ITS_AFFINITY:
462 Buffer,
463 sizeof (Buffer),
464 "GIC ITS Affinity Structure [%d]",
465 GicITSAffinityIndex++
466 );
467 ParseAcpi (
468 TRUE,
469 2,
470 Buffer,
471 ResourcePtr,
472 *SratRALength,
474 );
475 break;
476
477 case EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY:
479 Buffer,
480 sizeof (Buffer),
481 "Generic Initiator Affinity Structure [%d]",
482 GenericInitiatorAffinityIndex++
483 );
484 ParseAcpi (
485 TRUE,
486 2,
487 Buffer,
488 ResourcePtr,
489 *SratRALength,
491 );
492 break;
493
494 case EFI_ACPI_6_3_MEMORY_AFFINITY:
496 Buffer,
497 sizeof (Buffer),
498 "Memory Affinity Structure [%d]",
499 MemoryAffinityIndex++
500 );
501 ParseAcpi (
502 TRUE,
503 2,
504 Buffer,
505 ResourcePtr,
506 *SratRALength,
508 );
509 break;
510
511 case EFI_ACPI_6_3_PROCESSOR_LOCAL_APIC_SAPIC_AFFINITY:
513 Buffer,
514 sizeof (Buffer),
515 "APIC/SAPIC Affinity Structure [%d]",
516 ApicSapicAffinityIndex++
517 );
518 ParseAcpi (
519 TRUE,
520 2,
521 Buffer,
522 ResourcePtr,
523 *SratRALength,
525 );
526 break;
527
528 case EFI_ACPI_6_3_PROCESSOR_LOCAL_X2APIC_AFFINITY:
530 Buffer,
531 sizeof (Buffer),
532 "X2APIC Affinity Structure [%d]",
533 X2ApicAffinityIndex++
534 );
535 ParseAcpi (
536 TRUE,
537 2,
538 Buffer,
539 ResourcePtr,
540 *SratRALength,
542 );
543 break;
544
545 default:
547 Print (L"ERROR: Unknown SRAT Affinity type = 0x%x\n", *SratRAType);
548 break;
549 }
550
551 ResourcePtr += (*SratRALength);
552 Offset += (*SratRALength);
553 }
554}
VOID EFIAPI PrintFieldName(IN UINT32 Indent, IN CONST CHAR16 *FieldName)
Definition: AcpiParser.c:641
VOID EFIAPI Dump12Chars(IN CONST CHAR16 *Format OPTIONAL, IN UINT8 *Ptr, IN UINT32 Length)
Definition: AcpiParser.c:439
VOID EFIAPI IncrementErrorCount(VOID)
Definition: AcpiParser.c:83
UINT32 EFIAPI ParseAcpi(IN BOOLEAN Trace, IN UINT32 Indent, IN CONST CHAR8 *AsciiName OPTIONAL, IN UINT8 *Ptr, IN UINT32 Length, IN CONST ACPI_PARSER *Parser, IN UINT32 ParserItems)
Definition: AcpiParser.c:683
#define PARSER_PARAMS(Parser)
Definition: AcpiParser.h:494
#define PARSE_ACPI_HEADER(Info)
Definition: AcpiParser.h:501
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
STATIC CONST ACPI_PARSER SratGicCAffinityParser[]
Definition: SratParser.c:257
STATIC VOID EFIAPI DumpSratPciBdfNumber(IN CONST CHAR16 *Format, IN UINT8 *Ptr, IN UINT32 Length)
Definition: SratParser.c:89
STATIC VOID EFIAPI DumpSratDeviceHandle(IN CONST CHAR16 *Format, IN UINT8 *Ptr, IN UINT32 Length)
Definition: SratParser.c:179
STATIC CONST ACPI_PARSER SratDeviceHandlePciParser[]
Definition: SratParser.c:161
STATIC CONST ACPI_PARSER SratX2ApciAffinityParser[]
Definition: SratParser.c:332
STATIC CONST ACPI_PARSER SratDeviceHandleAcpiParser[]
Definition: SratParser.c:152
STATIC CONST ACPI_PARSER SratApciSapicAffinityParser[]
Definition: SratParser.c:316
STATIC CONST ACPI_PARSER SratGenericInitiatorAffinityParser[]
Definition: SratParser.c:282
STATIC VOID EFIAPI ValidateSratReserved(IN UINT8 *Ptr, IN UINT32 Length, IN VOID *Context)
Definition: SratParser.c:35
VOID EFIAPI ParseAcpiSrat(IN BOOLEAN Trace, IN UINT8 *Ptr, IN UINT32 AcpiTableLength, IN UINT8 AcpiTableRevision)
Definition: SratParser.c:364
STATIC VOID EFIAPI ValidateSratDeviceHandleType(IN UINT8 *Ptr, IN UINT32 Length, IN VOID *Context)
Definition: SratParser.c:59
STATIC CONST ACPI_PARSER SratParser[]
Definition: SratParser.c:240
STATIC CONST ACPI_PARSER SratGicITSAffinityParser[]
Definition: SratParser.c:270
STATIC CONST ACPI_PARSER SratResourceAllocationParser[]
Definition: SratParser.c:249
STATIC CONST ACPI_PARSER SratMemAffinityParser[]
Definition: SratParser.c:298
STATIC VOID EFIAPI DumpSratApicProximity(IN CONST CHAR16 *Format, IN UINT8 *Ptr, IN UINT32 Length)
Definition: SratParser.c:224
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113