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