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