4 Copyright (c) 2019 - 2020, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - ACPI 6.3 Specification - January 2019
9 - ARM Architecture Reference Manual ARMv8 (D.a)
12 #include <Library/PrintLib.h>
13 #include <Library/UefiLib.h>
14 #include "AcpiParser.h"
16 #include "PpttParser.h"
19 STATIC CONST UINT8
* ProcessorTopologyStructureType
;
20 STATIC CONST UINT8
* ProcessorTopologyStructureLength
;
21 STATIC CONST UINT32
* NumberOfPrivateResources
;
22 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo
;
25 This function validates the Cache Type Structure (Type 1) 'Number of sets'
28 @param [in] Ptr Pointer to the start of the field data.
29 @param [in] Context Pointer to context specific information e.g. this
30 could be a pointer to the ACPI table header.
35 ValidateCacheNumberOfSets (
41 NumberOfSets
= *(UINT32
*)Ptr
;
43 if (NumberOfSets
== 0) {
44 IncrementErrorCount ();
45 Print (L
"\nERROR: Cache number of sets must be greater than 0");
49 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
50 if (NumberOfSets
> PPTT_ARM_CCIDX_CACHE_NUMBER_OF_SETS_MAX
) {
51 IncrementErrorCount ();
53 L
"\nERROR: When ARMv8.3-CCIDX is implemented the maximum cache number of "
54 L
"sets must be less than or equal to %d",
55 PPTT_ARM_CCIDX_CACHE_NUMBER_OF_SETS_MAX
60 if (NumberOfSets
> PPTT_ARM_CACHE_NUMBER_OF_SETS_MAX
) {
61 IncrementWarningCount ();
63 L
"\nWARNING: Without ARMv8.3-CCIDX, the maximum cache number of sets "
64 L
"must be less than or equal to %d. Ignore this message if "
65 L
"ARMv8.3-CCIDX is implemented",
66 PPTT_ARM_CACHE_NUMBER_OF_SETS_MAX
75 This function validates the Cache Type Structure (Type 1) 'Associativity'
78 @param [in] Ptr Pointer to the start of the field data.
79 @param [in] Context Pointer to context specific information e.g. this
80 could be a pointer to the ACPI table header.
85 ValidateCacheAssociativity (
91 Associativity
= *(UINT8
*)Ptr
;
93 if (Associativity
== 0) {
94 IncrementErrorCount ();
95 Print (L
"\nERROR: Cache associativity must be greater than 0");
101 This function validates the Cache Type Structure (Type 1) Line size field.
103 @param [in] Ptr Pointer to the start of the field data.
104 @param [in] Context Pointer to context specific information e.g. this
105 could be a pointer to the ACPI table header.
110 ValidateCacheLineSize (
115 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
116 // Reference: ARM Architecture Reference Manual ARMv8 (D.a)
117 // Section D12.2.25: CCSIDR_EL1, Current Cache Size ID Register
118 // LineSize, bits [2:0]
119 // (Log2(Number of bytes in cache line)) - 4.
122 LineSize
= *(UINT16
*)Ptr
;
124 if ((LineSize
< PPTT_ARM_CACHE_LINE_SIZE_MIN
) ||
125 (LineSize
> PPTT_ARM_CACHE_LINE_SIZE_MAX
)) {
126 IncrementErrorCount ();
128 L
"\nERROR: The cache line size must be between %d and %d bytes"
129 L
" on ARM Platforms.",
130 PPTT_ARM_CACHE_LINE_SIZE_MIN
,
131 PPTT_ARM_CACHE_LINE_SIZE_MAX
136 if ((LineSize
& (LineSize
- 1)) != 0) {
137 IncrementErrorCount ();
138 Print (L
"\nERROR: The cache line size is not a power of 2.");
144 This function validates the Cache Type Structure (Type 1) Attributes field.
146 @param [in] Ptr Pointer to the start of the field data.
147 @param [in] Context Pointer to context specific information e.g. this
148 could be a pointer to the ACPI table header.
153 ValidateCacheAttributes (
158 // Reference: Advanced Configuration and Power Interface (ACPI) Specification
159 // Version 6.2 Errata A, September 2017
160 // Table 5-153: Cache Type Structure
162 Attributes
= *(UINT8
*)Ptr
;
164 if ((Attributes
& 0xE0) != 0) {
165 IncrementErrorCount ();
167 L
"\nERROR: Attributes bits [7:5] are reserved and must be zero.",
175 An ACPI_PARSER array describing the ACPI PPTT Table.
177 STATIC CONST ACPI_PARSER PpttParser
[] = {
178 PARSE_ACPI_HEADER (&AcpiHdrInfo
)
182 An ACPI_PARSER array describing the processor topology structure header.
184 STATIC CONST ACPI_PARSER ProcessorTopologyStructureHeaderParser
[] = {
185 {L
"Type", 1, 0, NULL
, NULL
, (VOID
**)&ProcessorTopologyStructureType
,
187 {L
"Length", 1, 1, NULL
, NULL
, (VOID
**)&ProcessorTopologyStructureLength
,
189 {L
"Reserved", 2, 2, NULL
, NULL
, NULL
, NULL
, NULL
}
193 An ACPI_PARSER array describing the Processor Hierarchy Node Structure - Type 0.
195 STATIC CONST ACPI_PARSER ProcessorHierarchyNodeStructureParser
[] = {
196 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
197 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
198 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
200 {L
"Flags", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
201 {L
"Parent", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
202 {L
"ACPI Processor ID", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
203 {L
"Number of private resources", 4, 16, L
"%d", NULL
,
204 (VOID
**)&NumberOfPrivateResources
, NULL
, NULL
}
208 An ACPI_PARSER array describing the Cache Type Structure - Type 1.
210 STATIC CONST ACPI_PARSER CacheTypeStructureParser
[] = {
211 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
212 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
213 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
215 {L
"Flags", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
216 {L
"Next Level of Cache", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
217 {L
"Size", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
218 {L
"Number of sets", 4, 16, L
"%d", NULL
, NULL
, ValidateCacheNumberOfSets
, NULL
},
219 {L
"Associativity", 1, 20, L
"%d", NULL
, NULL
, ValidateCacheAssociativity
, NULL
},
220 {L
"Attributes", 1, 21, L
"0x%x", NULL
, NULL
, ValidateCacheAttributes
, NULL
},
221 {L
"Line size", 2, 22, L
"%d", NULL
, NULL
, ValidateCacheLineSize
, NULL
}
225 An ACPI_PARSER array describing the ID Type Structure - Type 2.
227 STATIC CONST ACPI_PARSER IdStructureParser
[] = {
228 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
229 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
230 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
232 {L
"VENDOR_ID", 4, 4, NULL
, Dump4Chars
, NULL
, NULL
, NULL
},
233 {L
"LEVEL_1_ID", 8, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
234 {L
"LEVEL_2_ID", 8, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
235 {L
"MAJOR_REV", 2, 24, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
236 {L
"MINOR_REV", 2, 26, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
237 {L
"SPIN_REV", 2, 28, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
241 This function parses the Processor Hierarchy Node Structure (Type 0).
243 @param [in] Ptr Pointer to the start of the Processor Hierarchy Node
245 @param [in] Length Length of the Processor Hierarchy Node Structure.
249 DumpProcessorHierarchyNodeStructure (
256 CHAR16 Buffer
[OUTPUT_FIELD_COLUMN_WIDTH
];
261 "Processor Hierarchy Node Structure",
264 PARSER_PARAMS (ProcessorHierarchyNodeStructureParser
)
267 // Check if the values used to control the parsing logic have been
268 // successfully read.
269 if (NumberOfPrivateResources
== NULL
) {
270 IncrementErrorCount ();
272 L
"ERROR: Insufficient Processor Hierarchy Node length. Length = %d.\n",
278 // Make sure the Private Resource array lies inside this structure
279 if (Offset
+ (*NumberOfPrivateResources
* sizeof (UINT32
)) > Length
) {
280 IncrementErrorCount ();
282 L
"ERROR: Invalid Number of Private Resources. " \
283 L
"PrivateResourceCount = %d. RemainingBufferLength = %d. " \
284 L
"Parsing of this structure aborted.\n",
285 *NumberOfPrivateResources
,
293 // Parse the specified number of private resource references or the Processor
294 // Hierarchy Node length. Whichever is minimum.
295 while (Index
< *NumberOfPrivateResources
) {
299 L
"Private resources [%d]",
303 PrintFieldName (4, Buffer
);
306 *((UINT32
*)(Ptr
+ Offset
))
309 Offset
+= sizeof (UINT32
);
315 This function parses the Cache Type Structure (Type 1).
317 @param [in] Ptr Pointer to the start of the Cache Type Structure data.
318 @param [in] Length Length of the Cache Type Structure.
322 DumpCacheTypeStructure (
330 "Cache Type Structure",
333 PARSER_PARAMS (CacheTypeStructureParser
)
338 This function parses the ID Structure (Type 2).
340 @param [in] Ptr Pointer to the start of the ID Structure data.
341 @param [in] Length Length of the ID Structure.
356 PARSER_PARAMS (IdStructureParser
)
361 This function parses the ACPI PPTT table.
362 When trace is enabled this function parses the PPTT table and
363 traces the ACPI table fields.
365 This function parses the following processor topology structures:
366 - Processor hierarchy node structure (Type 0)
367 - Cache Type Structure (Type 1)
368 - ID structure (Type 2)
370 This function also performs validation of the ACPI table fields.
372 @param [in] Trace If TRUE, trace the ACPI fields.
373 @param [in] Ptr Pointer to the start of the buffer.
374 @param [in] AcpiTableLength Length of the ACPI table.
375 @param [in] AcpiTableRevision Revision of the ACPI table.
382 IN UINT32 AcpiTableLength
,
383 IN UINT8 AcpiTableRevision
387 UINT8
* ProcessorTopologyStructurePtr
;
399 PARSER_PARAMS (PpttParser
)
402 ProcessorTopologyStructurePtr
= Ptr
+ Offset
;
404 while (Offset
< AcpiTableLength
) {
405 // Parse Processor Hierarchy Node Structure to obtain Type and Length.
410 ProcessorTopologyStructurePtr
,
411 AcpiTableLength
- Offset
,
412 PARSER_PARAMS (ProcessorTopologyStructureHeaderParser
)
415 // Check if the values used to control the parsing logic have been
416 // successfully read.
417 if ((ProcessorTopologyStructureType
== NULL
) ||
418 (ProcessorTopologyStructureLength
== NULL
)) {
419 IncrementErrorCount ();
421 L
"ERROR: Insufficient remaining table buffer length to read the " \
422 L
"processor topology structure header. Length = %d.\n",
423 AcpiTableLength
- Offset
428 // Validate Processor Topology Structure length
429 if ((*ProcessorTopologyStructureLength
== 0) ||
430 ((Offset
+ (*ProcessorTopologyStructureLength
)) > AcpiTableLength
)) {
431 IncrementErrorCount ();
433 L
"ERROR: Invalid Processor Topology Structure length. " \
434 L
"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
435 *ProcessorTopologyStructureLength
,
442 PrintFieldName (2, L
"* Structure Offset *");
443 Print (L
"0x%x\n", Offset
);
445 switch (*ProcessorTopologyStructureType
) {
446 case EFI_ACPI_6_2_PPTT_TYPE_PROCESSOR
:
447 DumpProcessorHierarchyNodeStructure (
448 ProcessorTopologyStructurePtr
,
449 *ProcessorTopologyStructureLength
452 case EFI_ACPI_6_2_PPTT_TYPE_CACHE
:
453 DumpCacheTypeStructure (
454 ProcessorTopologyStructurePtr
,
455 *ProcessorTopologyStructureLength
458 case EFI_ACPI_6_2_PPTT_TYPE_ID
:
460 ProcessorTopologyStructurePtr
,
461 *ProcessorTopologyStructureLength
465 IncrementErrorCount ();
467 L
"ERROR: Unknown processor topology structure:"
468 L
" Type = %d, Length = %d\n",
469 *ProcessorTopologyStructureType
,
470 *ProcessorTopologyStructureLength
474 ProcessorTopologyStructurePtr
+= *ProcessorTopologyStructureLength
;
475 Offset
+= *ProcessorTopologyStructureLength
;