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