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