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