]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Xsdt/XsdtParser.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Xsdt / XsdtParser.c
1 /** @file
2 XSDT table parser
3
4 Copyright (c) 2016 - 2019, 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/UefiLib.h>
13 #include <Library/PrintLib.h>
14 #include "AcpiParser.h"
15 #include "AcpiTableParser.h"
16
17 // Local variables
18 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
19
20 /** An ACPI_PARSER array describing the ACPI XSDT table.
21 */
22 STATIC CONST ACPI_PARSER XsdtParser[] = {
23 PARSE_ACPI_HEADER (&AcpiHdrInfo)
24 };
25
26 /**
27 Get the ACPI XSDT header info.
28 **/
29 CONST ACPI_DESCRIPTION_HEADER_INFO *
30 EFIAPI
31 GetAcpiXsdtHeaderInfo (
32 VOID
33 )
34 {
35 return &AcpiHdrInfo;
36 }
37
38 /**
39 This function parses the ACPI XSDT table and optionally traces the ACPI table fields.
40
41 This function also performs validation of the XSDT table.
42
43 @param [in] Trace If TRUE, trace the ACPI fields.
44 @param [in] Ptr Pointer to the start of the buffer.
45 @param [in] AcpiTableLength Length of the ACPI table.
46 @param [in] AcpiTableRevision Revision of the ACPI table.
47 **/
48 VOID
49 EFIAPI
50 ParseAcpiXsdt (
51 IN BOOLEAN Trace,
52 IN UINT8 *Ptr,
53 IN UINT32 AcpiTableLength,
54 IN UINT8 AcpiTableRevision
55 )
56 {
57 UINT32 Offset;
58 UINT32 TableOffset;
59 UINT64 *TablePointer;
60 UINTN EntryIndex;
61 CHAR16 Buffer[32];
62
63 Offset = ParseAcpi (
64 Trace,
65 0,
66 "XSDT",
67 Ptr,
68 AcpiTableLength,
69 PARSER_PARAMS (XsdtParser)
70 );
71
72 TableOffset = Offset;
73
74 if (Trace) {
75 EntryIndex = 0;
76 TablePointer = (UINT64 *)(Ptr + TableOffset);
77 while (Offset < AcpiTableLength) {
78 CONST UINT32 *Signature;
79 CONST UINT32 *Length;
80 CONST UINT8 *Revision;
81
82 if ((UINT64 *)(UINTN)(*TablePointer) != NULL) {
83 UINT8 *SignaturePtr;
84
85 ParseAcpiHeader (
86 (UINT8 *)(UINTN)(*TablePointer),
87 &Signature,
88 &Length,
89 &Revision
90 );
91
92 SignaturePtr = (UINT8 *)Signature;
93
94 UnicodeSPrint (
95 Buffer,
96 sizeof (Buffer),
97 L"Entry[%d] - %c%c%c%c",
98 EntryIndex++,
99 SignaturePtr[0],
100 SignaturePtr[1],
101 SignaturePtr[2],
102 SignaturePtr[3]
103 );
104 } else {
105 UnicodeSPrint (
106 Buffer,
107 sizeof (Buffer),
108 L"Entry[%d]",
109 EntryIndex++
110 );
111 }
112
113 PrintFieldName (2, Buffer);
114 Print (L"0x%lx\n", *TablePointer);
115
116 // Validate the table pointers are not NULL
117 if ((UINT64 *)(UINTN)(*TablePointer) == NULL) {
118 IncrementErrorCount ();
119 Print (
120 L"ERROR: Invalid table entry at 0x%lx, table address is 0x%lx\n",
121 TablePointer,
122 *TablePointer
123 );
124 }
125
126 Offset += sizeof (UINT64);
127 TablePointer++;
128 } // while
129 }
130
131 // Process the tables
132 Offset = TableOffset;
133 TablePointer = (UINT64 *)(Ptr + TableOffset);
134 while (Offset < AcpiTableLength) {
135 if ((UINT64 *)(UINTN)(*TablePointer) != NULL) {
136 ProcessAcpiTable ((UINT8 *)(UINTN)(*TablePointer));
137 }
138
139 Offset += sizeof (UINT64);
140 TablePointer++;
141 } // while
142 }