1 | /** @file
|
---|
2 | ACPI table parser
|
---|
3 |
|
---|
4 | Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 | **/
|
---|
7 |
|
---|
8 | #include <Uefi.h>
|
---|
9 | #include <IndustryStandard/Acpi.h>
|
---|
10 | #include <Library/UefiLib.h>
|
---|
11 | #include "AcpiParser.h"
|
---|
12 | #include "AcpiTableParser.h"
|
---|
13 | #include "AcpiView.h"
|
---|
14 |
|
---|
15 | /**
|
---|
16 | A list of registered ACPI table parsers.
|
---|
17 | **/
|
---|
18 | STATIC ACPI_TABLE_PARSER mTableParserList[MAX_ACPI_TABLE_PARSERS];
|
---|
19 |
|
---|
20 | /**
|
---|
21 | Register the ACPI table Parser
|
---|
22 |
|
---|
23 | This function registers the ACPI table parser.
|
---|
24 |
|
---|
25 | @param [in] Signature The ACPI table signature.
|
---|
26 | @param [in] ParserProc The ACPI table parser.
|
---|
27 |
|
---|
28 | @retval EFI_SUCCESS The parser is registered.
|
---|
29 | @retval EFI_INVALID_PARAMETER A parameter is invalid.
|
---|
30 | @retval EFI_ALREADY_STARTED The parser for the Table
|
---|
31 | was already registered.
|
---|
32 | @retval EFI_OUT_OF_RESOURCES No space to register the
|
---|
33 | parser.
|
---|
34 | **/
|
---|
35 | EFI_STATUS
|
---|
36 | EFIAPI
|
---|
37 | RegisterParser (
|
---|
38 | IN UINT32 Signature,
|
---|
39 | IN PARSE_ACPI_TABLE_PROC ParserProc
|
---|
40 | )
|
---|
41 | {
|
---|
42 | UINT32 Index;
|
---|
43 |
|
---|
44 | if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
|
---|
45 | return EFI_INVALID_PARAMETER;
|
---|
46 | }
|
---|
47 |
|
---|
48 | // Search if a parser is already installed
|
---|
49 | for (Index = 0;
|
---|
50 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
|
---|
51 | Index++)
|
---|
52 | {
|
---|
53 | if (Signature == mTableParserList[Index].Signature) {
|
---|
54 | if (mTableParserList[Index].Parser != NULL) {
|
---|
55 | return EFI_ALREADY_STARTED;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | // Find the first free slot and register the parser
|
---|
61 | for (Index = 0;
|
---|
62 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
|
---|
63 | Index++)
|
---|
64 | {
|
---|
65 | if (mTableParserList[Index].Signature == ACPI_PARSER_SIGNATURE_NULL) {
|
---|
66 | mTableParserList[Index].Signature = Signature;
|
---|
67 | mTableParserList[Index].Parser = ParserProc;
|
---|
68 | return EFI_SUCCESS;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | // No free slot found
|
---|
73 | return EFI_OUT_OF_RESOURCES;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | Deregister the ACPI table Parser
|
---|
78 |
|
---|
79 | This function deregisters the ACPI table parser.
|
---|
80 |
|
---|
81 | @param [in] Signature The ACPI table signature.
|
---|
82 |
|
---|
83 | @retval EFI_SUCCESS The parser was deregistered.
|
---|
84 | @retval EFI_INVALID_PARAMETER A parameter is invalid.
|
---|
85 | @retval EFI_NOT_FOUND A registered parser was not found.
|
---|
86 | **/
|
---|
87 | EFI_STATUS
|
---|
88 | EFIAPI
|
---|
89 | DeregisterParser (
|
---|
90 | IN UINT32 Signature
|
---|
91 | )
|
---|
92 | {
|
---|
93 | UINT32 Index;
|
---|
94 |
|
---|
95 | if (Signature == ACPI_PARSER_SIGNATURE_NULL) {
|
---|
96 | return EFI_INVALID_PARAMETER;
|
---|
97 | }
|
---|
98 |
|
---|
99 | for (Index = 0;
|
---|
100 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
|
---|
101 | Index++)
|
---|
102 | {
|
---|
103 | if (Signature == mTableParserList[Index].Signature) {
|
---|
104 | mTableParserList[Index].Signature = ACPI_PARSER_SIGNATURE_NULL;
|
---|
105 | mTableParserList[Index].Parser = NULL;
|
---|
106 | return EFI_SUCCESS;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | // No matching registered parser found.
|
---|
111 | return EFI_NOT_FOUND;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | Get the ACPI table Parser
|
---|
116 |
|
---|
117 | This function returns the ACPI table parser proc from the list of
|
---|
118 | registered parsers.
|
---|
119 |
|
---|
120 | @param [in] Signature The ACPI table signature.
|
---|
121 | @param [out] ParserProc Pointer to a ACPI table parser proc.
|
---|
122 |
|
---|
123 | @retval EFI_SUCCESS The parser was returned successfully.
|
---|
124 | @retval EFI_INVALID_PARAMETER A parameter is invalid.
|
---|
125 | @retval EFI_NOT_FOUND A registered parser was not found.
|
---|
126 | **/
|
---|
127 | EFI_STATUS
|
---|
128 | EFIAPI
|
---|
129 | GetParser (
|
---|
130 | IN UINT32 Signature,
|
---|
131 | OUT PARSE_ACPI_TABLE_PROC * ParserProc
|
---|
132 | )
|
---|
133 | {
|
---|
134 | UINT32 Index;
|
---|
135 |
|
---|
136 | if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
|
---|
137 | return EFI_INVALID_PARAMETER;
|
---|
138 | }
|
---|
139 |
|
---|
140 | for (Index = 0;
|
---|
141 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
|
---|
142 | Index++)
|
---|
143 | {
|
---|
144 | if (Signature == mTableParserList[Index].Signature) {
|
---|
145 | *ParserProc = mTableParserList[Index].Parser;
|
---|
146 | return EFI_SUCCESS;
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | // No matching registered parser found.
|
---|
151 | return EFI_NOT_FOUND;
|
---|
152 | }
|
---|
153 |
|
---|
154 | /**
|
---|
155 | This function processes the ACPI tables.
|
---|
156 | This function calls ProcessTableReportOptions() to list the ACPI
|
---|
157 | tables, perform binary dump of the tables and determine if the
|
---|
158 | ACPI fields should be traced.
|
---|
159 |
|
---|
160 | This function also invokes the parser for the ACPI tables.
|
---|
161 |
|
---|
162 | This function also performs a RAW dump of the ACPI table including
|
---|
163 | the unknown/unparsed ACPI tables and validates the checksum.
|
---|
164 |
|
---|
165 | @param [in] Ptr Pointer to the start of the ACPI
|
---|
166 | table data buffer.
|
---|
167 | **/
|
---|
168 | VOID
|
---|
169 | EFIAPI
|
---|
170 | ProcessAcpiTable (
|
---|
171 | IN UINT8* Ptr
|
---|
172 | )
|
---|
173 | {
|
---|
174 | EFI_STATUS Status;
|
---|
175 | BOOLEAN Trace;
|
---|
176 | CONST UINT32* AcpiTableSignature;
|
---|
177 | CONST UINT32* AcpiTableLength;
|
---|
178 | CONST UINT8* AcpiTableRevision;
|
---|
179 | PARSE_ACPI_TABLE_PROC ParserProc;
|
---|
180 |
|
---|
181 | ParseAcpiHeader (
|
---|
182 | Ptr,
|
---|
183 | &AcpiTableSignature,
|
---|
184 | &AcpiTableLength,
|
---|
185 | &AcpiTableRevision
|
---|
186 | );
|
---|
187 |
|
---|
188 | Trace = ProcessTableReportOptions (
|
---|
189 | *AcpiTableSignature,
|
---|
190 | Ptr,
|
---|
191 | *AcpiTableLength
|
---|
192 | );
|
---|
193 |
|
---|
194 | if (Trace) {
|
---|
195 | DumpRaw (Ptr, *AcpiTableLength);
|
---|
196 | if (GetConsistencyChecking ()) {
|
---|
197 | VerifyChecksum (TRUE, Ptr, *AcpiTableLength);
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | Status = GetParser (*AcpiTableSignature, &ParserProc);
|
---|
202 | if (EFI_ERROR (Status)) {
|
---|
203 | // No registered parser found, do default handling.
|
---|
204 | if (Trace) {
|
---|
205 | DumpAcpiHeader (Ptr);
|
---|
206 | }
|
---|
207 | return;
|
---|
208 | }
|
---|
209 |
|
---|
210 | ParserProc (
|
---|
211 | Trace,
|
---|
212 | Ptr,
|
---|
213 | *AcpiTableLength,
|
---|
214 | *AcpiTableRevision
|
---|
215 | );
|
---|
216 | }
|
---|