]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
2ccbb7b80edc3b4c1e51a55b416bde11a145f25d
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Madt / MadtParser.c
1 /**
2 MADT 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 "AcpiParser.h"
20 #include "AcpiTableParser.h"
21
22 // Local Variables
23 STATIC CONST UINT8* MadtInterruptControllerType;
24 STATIC CONST UINT8* MadtInterruptControllerLength;
25 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
26
27 // Forward declarations
28 STATIC
29 VOID
30 EFIAPI
31 ValidateGICDSystemVectorBase (
32 IN UINT8* Ptr,
33 IN VOID* Context
34 );
35
36 /** An ACPI_PARSER array describing the GICC Interrupt
37 Controller Structure.
38 */
39 STATIC CONST ACPI_PARSER GicCParser[] = {
40 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
41 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
42 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
43
44 {L"CPU Interface Number", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
45 {L"ACPI Processor UID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
46 {L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
47 {L"Parking Protocol Version", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
48
49 {L"Performance Interrupt GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
50 {L"Parked Address", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL},
51 {L"Physical Base Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL},
52 {L"GICV", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL},
53 {L"GICH", 8, 48, L"0x%lx", NULL, NULL, NULL, NULL},
54 {L"VGIC Maintenance interrupt", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
55 {L"GICR Base Address", 8, 60, L"0x%lx", NULL, NULL, NULL, NULL},
56 {L"MPIDR", 8, 68, L"0x%lx", NULL, NULL, NULL, NULL},
57 {L"Processor Power Efficiency Class", 1, 76, L"0x%x", NULL, NULL, NULL,
58 NULL},
59 {L"Reserved", 3, 77, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
60 };
61
62 /** An ACPI_PARSER array describing the GICD Interrupt
63 Controller Structure.
64 */
65 STATIC CONST ACPI_PARSER GicDParser[] = {
66 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
67 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
68 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
69
70 {L"GIC ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
71 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
72 {L"System Vector Base", 4, 16, L"0x%x", NULL, NULL,
73 ValidateGICDSystemVectorBase, NULL},
74 {L"GIC Version", 1, 20, L"%d", NULL, NULL, NULL, NULL},
75 {L"Reserved", 3, 21, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
76 };
77
78 /** An ACPI_PARSER array describing the MSI Frame Interrupt
79 Controller Structure.
80 */
81 STATIC CONST ACPI_PARSER GicMSIFrameParser[] = {
82 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
83 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
84 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
85
86 {L"MSI Frame ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
87 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
88 {L"Flags", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
89
90 {L"SPI Count", 2, 20, L"%d", NULL, NULL, NULL, NULL},
91 {L"SPI Base", 2, 22, L"0x%x", NULL, NULL, NULL, NULL}
92 };
93
94 /** An ACPI_PARSER array describing the GICR Interrupt
95 Controller Structure.
96 */
97 STATIC CONST ACPI_PARSER GicRParser[] = {
98 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
99 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
100 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
101
102 {L"Discovery Range Base Address", 8, 4, L"0x%lx", NULL, NULL, NULL,
103 NULL},
104 {L"Discovery Range Length", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}
105 };
106
107 /** An ACPI_PARSER array describing the GIC ITS Interrupt
108 Controller Structure.
109 */
110 STATIC CONST ACPI_PARSER GicITSParser[] = {
111 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
112 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
113 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
114
115 {L"GIC ITS ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
116 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
117 {L"Reserved", 4, 16, L"0x%x", NULL, NULL, NULL, NULL}
118 };
119
120 /** An ACPI_PARSER array describing the ACPI MADT Table.
121 */
122 STATIC CONST ACPI_PARSER MadtParser[] = {
123 PARSE_ACPI_HEADER (&AcpiHdrInfo),
124 {L"Local Interrupt Controller Address", 4, 36, L"0x%x", NULL, NULL, NULL,
125 NULL},
126 {L"Flags", 4, 40, L"0x%x", NULL, NULL, NULL, NULL}
127 };
128
129 /** An ACPI_PARSER array describing the MADT Interrupt
130 Controller Structure Header Structure.
131 */
132 STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser[] = {
133 {NULL, 1, 0, NULL, NULL, (VOID**)&MadtInterruptControllerType, NULL, NULL},
134 {L"Length", 1, 1, NULL, NULL, (VOID**)&MadtInterruptControllerLength, NULL,
135 NULL},
136 {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
137 };
138
139 /** This function validates the System Vector Base in the GICD.
140
141 @param [in] Ptr Pointer to the start of the field data.
142 @param [in] Context Pointer to context specific information e.g. this
143 could be a pointer to the ACPI table header.
144 */
145 STATIC
146 VOID
147 EFIAPI
148 ValidateGICDSystemVectorBase (
149 IN UINT8* Ptr,
150 IN VOID* Context
151 )
152 {
153 if (*(UINT32*)Ptr != 0) {
154 IncrementErrorCount ();
155 Print (
156 L"\nERROR: System Vector Base must be zero."
157 );
158 }
159 }
160
161 /** This function parses the ACPI MADT table.
162 When trace is enabled this function parses the MADT table and
163 traces the ACPI table fields.
164
165 This function currently parses the following Interrupt Controller
166 Structures:
167 - GICC
168 - GICD
169 - GIC MSI Frame
170 - GICR
171 - GIC ITS
172
173 This function also performs validation of the ACPI table fields.
174
175 @param [in] Trace If TRUE, trace the ACPI fields.
176 @param [in] Ptr Pointer to the start of the buffer.
177 @param [in] AcpiTableLength Length of the ACPI table.
178 @param [in] AcpiTableRevision Revision of the ACPI table.
179 */
180 VOID
181 EFIAPI
182 ParseAcpiMadt (
183 IN BOOLEAN Trace,
184 IN UINT8* Ptr,
185 IN UINT32 AcpiTableLength,
186 IN UINT8 AcpiTableRevision
187 )
188 {
189 UINT32 Offset;
190 UINT8* InterruptContollerPtr;
191 UINT32 GICDCount = 0;
192
193 if (!Trace) {
194 return;
195 }
196
197 Offset = ParseAcpi (
198 TRUE,
199 0,
200 "MADT",
201 Ptr,
202 AcpiTableLength,
203 PARSER_PARAMS (MadtParser)
204 );
205 InterruptContollerPtr = Ptr + Offset;
206
207 while (Offset < AcpiTableLength) {
208 // Parse Interrupt Controller Structure to obtain Length.
209 ParseAcpi (
210 FALSE,
211 0,
212 NULL,
213 InterruptContollerPtr,
214 2, // Length is 1 byte at offset 1
215 PARSER_PARAMS (MadtInterruptControllerHeaderParser)
216 );
217
218 if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
219 (*MadtInterruptControllerLength < 4)) {
220 IncrementErrorCount ();
221 Print (
222 L"ERROR: Invalid Interrupt Controller Length,"
223 " Type = %d, Length = %d\n",
224 *MadtInterruptControllerType,
225 *MadtInterruptControllerLength
226 );
227 break;
228 }
229
230 switch (*MadtInterruptControllerType) {
231 case EFI_ACPI_6_2_GIC: {
232 ParseAcpi (
233 TRUE,
234 2,
235 "GICC",
236 InterruptContollerPtr,
237 *MadtInterruptControllerLength,
238 PARSER_PARAMS (GicCParser)
239 );
240 break;
241 }
242
243 case EFI_ACPI_6_2_GICD: {
244 if (++GICDCount > 1) {
245 IncrementErrorCount ();
246 Print (
247 L"ERROR: Only one GICD must be present,"
248 " GICDCount = %d\n",
249 GICDCount
250 );
251 }
252 ParseAcpi (
253 TRUE,
254 2,
255 "GICD",
256 InterruptContollerPtr,
257 *MadtInterruptControllerLength,
258 PARSER_PARAMS (GicDParser)
259 );
260 break;
261 }
262
263 case EFI_ACPI_6_2_GIC_MSI_FRAME: {
264 ParseAcpi (
265 TRUE,
266 2,
267 "GIC MSI Frame",
268 InterruptContollerPtr,
269 *MadtInterruptControllerLength,
270 PARSER_PARAMS (GicMSIFrameParser)
271 );
272 break;
273 }
274
275 case EFI_ACPI_6_2_GICR: {
276 ParseAcpi (
277 TRUE,
278 2,
279 "GICR",
280 InterruptContollerPtr,
281 *MadtInterruptControllerLength,
282 PARSER_PARAMS (GicRParser)
283 );
284 break;
285 }
286
287 case EFI_ACPI_6_2_GIC_ITS: {
288 ParseAcpi (
289 TRUE,
290 2,
291 "GIC ITS",
292 InterruptContollerPtr,
293 *MadtInterruptControllerLength,
294 PARSER_PARAMS (GicITSParser)
295 );
296 break;
297 }
298
299 default: {
300 IncrementErrorCount ();
301 Print (
302 L"ERROR: Unknown Interrupt Controller Structure,"
303 " Type = %d, Length = %d\n",
304 *MadtInterruptControllerType,
305 *MadtInterruptControllerLength
306 );
307 }
308 } // switch
309
310 InterruptContollerPtr += *MadtInterruptControllerLength;
311 Offset += *MadtInterruptControllerLength;
312 } // while
313 }