4 Copyright (c) 2019, 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 (
255 UINT8
* PrivateResourcePtr
;
257 CHAR16 Buffer
[OUTPUT_FIELD_COLUMN_WIDTH
];
262 "Processor Hierarchy Node Structure",
265 PARSER_PARAMS (ProcessorHierarchyNodeStructureParser
)
268 PrivateResourcePtr
= Ptr
+ Offset
;
270 while (Index
< *NumberOfPrivateResources
) {
274 L
"Private resources [%d]",
278 PrintFieldName (4, Buffer
);
281 *((UINT32
*) PrivateResourcePtr
)
284 PrivateResourcePtr
+= sizeof(UINT32
);
290 This function parses the Cache Type Structure (Type 1).
292 @param [in] Ptr Pointer to the start of the Cache Type Structure data.
293 @param [in] Length Length of the Cache Type Structure.
297 DumpCacheTypeStructure (
305 "Cache Type Structure",
308 PARSER_PARAMS (CacheTypeStructureParser
)
313 This function parses the ID Structure (Type 2).
315 @param [in] Ptr Pointer to the start of the ID Structure data.
316 @param [in] Length Length of the ID Structure.
331 PARSER_PARAMS (IdStructureParser
)
336 This function parses the ACPI PPTT table.
337 When trace is enabled this function parses the PPTT table and
338 traces the ACPI table fields.
340 This function parses the following processor topology structures:
341 - Processor hierarchy node structure (Type 0)
342 - Cache Type Structure (Type 1)
343 - ID structure (Type 2)
345 This function also performs validation of the ACPI table fields.
347 @param [in] Trace If TRUE, trace the ACPI fields.
348 @param [in] Ptr Pointer to the start of the buffer.
349 @param [in] AcpiTableLength Length of the ACPI table.
350 @param [in] AcpiTableRevision Revision of the ACPI table.
357 IN UINT32 AcpiTableLength
,
358 IN UINT8 AcpiTableRevision
362 UINT8
* ProcessorTopologyStructurePtr
;
374 PARSER_PARAMS (PpttParser
)
376 ProcessorTopologyStructurePtr
= Ptr
+ Offset
;
378 while (Offset
< AcpiTableLength
) {
379 // Parse Processor Hierarchy Node Structure to obtain Type and Length.
384 ProcessorTopologyStructurePtr
,
385 4, // Length of the processor topology structure header is 4 bytes
386 PARSER_PARAMS (ProcessorTopologyStructureHeaderParser
)
389 if ((Offset
+ (*ProcessorTopologyStructureLength
)) > AcpiTableLength
) {
390 IncrementErrorCount ();
392 L
"ERROR: Invalid processor topology structure length:"
393 L
" Type = %d, Length = %d\n",
394 *ProcessorTopologyStructureType
,
395 *ProcessorTopologyStructureLength
400 PrintFieldName (2, L
"* Structure Offset *");
401 Print (L
"0x%x\n", Offset
);
403 switch (*ProcessorTopologyStructureType
) {
404 case EFI_ACPI_6_2_PPTT_TYPE_PROCESSOR
:
405 DumpProcessorHierarchyNodeStructure (
406 ProcessorTopologyStructurePtr
,
407 *ProcessorTopologyStructureLength
410 case EFI_ACPI_6_2_PPTT_TYPE_CACHE
:
411 DumpCacheTypeStructure (
412 ProcessorTopologyStructurePtr
,
413 *ProcessorTopologyStructureLength
416 case EFI_ACPI_6_2_PPTT_TYPE_ID
:
418 ProcessorTopologyStructurePtr
,
419 *ProcessorTopologyStructureLength
423 IncrementErrorCount ();
425 L
"ERROR: Unknown processor topology structure:"
426 L
" Type = %d, Length = %d\n",
427 *ProcessorTopologyStructureType
,
428 *ProcessorTopologyStructureLength
432 ProcessorTopologyStructurePtr
+= *ProcessorTopologyStructureLength
;
433 Offset
+= *ProcessorTopologyStructureLength
;