]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Pptt/PpttParser.c
ShellPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Pptt / PpttParser.c
1 /** @file
2 PPTT table parser
3
4 Copyright (c) 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Reference(s):
8 - ACPI 6.2 Specification - Errata A, September 2017
9 **/
10
11 #include <Library/PrintLib.h>
12 #include <Library/UefiLib.h>
13 #include "AcpiParser.h"
14
15 // Local variables
16 STATIC CONST UINT8* ProcessorTopologyStructureType;
17 STATIC CONST UINT8* ProcessorTopologyStructureLength;
18 STATIC CONST UINT32* NumberOfPrivateResources;
19 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
20
21 /**
22 An ACPI_PARSER array describing the ACPI PPTT Table.
23 **/
24 STATIC CONST ACPI_PARSER PpttParser[] = {
25 PARSE_ACPI_HEADER (&AcpiHdrInfo)
26 };
27
28 /**
29 This function validates the Cache Type Structure (Type 1) Line size field.
30
31 @param [in] Ptr Pointer to the start of the field data.
32 @param [in] Context Pointer to context specific information e.g. this
33 could be a pointer to the ACPI table header.
34 **/
35 STATIC
36 VOID
37 EFIAPI
38 ValidateCacheLineSize (
39 IN UINT8* Ptr,
40 IN VOID* Context
41 )
42 {
43 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
44 // Reference: ARM Architecture Reference Manual ARMv8 (D.a)
45 // Section D12.2.25: CCSIDR_EL1, Current Cache Size ID Register
46 // LineSize, bits [2:0]
47 // (Log2(Number of bytes in cache line)) - 4.
48
49 UINT16 LineSize;
50 LineSize = *(UINT16*)Ptr;
51
52 if ((LineSize < 16) || (LineSize > 2048)) {
53 IncrementErrorCount ();
54 Print (
55 L"\nERROR: The cache line size must be between 16 and 2048 bytes"
56 L" on ARM Platforms."
57 );
58 return;
59 }
60
61 if ((LineSize & (LineSize - 1)) != 0) {
62 IncrementErrorCount ();
63 Print (L"\nERROR: The cache line size is not a power of 2.");
64 }
65 #endif
66 }
67
68 /**
69 This function validates the Cache Type Structure (Type 1) Attributes field.
70
71 @param [in] Ptr Pointer to the start of the field data.
72 @param [in] Context Pointer to context specific information e.g. this
73 could be a pointer to the ACPI table header.
74 **/
75 STATIC
76 VOID
77 EFIAPI
78 ValidateCacheAttributes (
79 IN UINT8* Ptr,
80 IN VOID* Context
81 )
82 {
83 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
84 // Reference: Advanced Configuration and Power Interface (ACPI) Specification
85 // Version 6.2 Errata A, September 2017
86 // Table 5-153: Cache Type Structure
87
88 UINT8 Attributes;
89 Attributes = *(UINT8*)Ptr;
90
91 if ((Attributes & 0xE0) != 0) {
92 IncrementErrorCount ();
93 Print (
94 L"\nERROR: Attributes bits [7:5] are reserved and must be zero.",
95 Attributes
96 );
97 return;
98 }
99 #endif
100 }
101
102 /**
103 An ACPI_PARSER array describing the processor topology structure header.
104 **/
105 STATIC CONST ACPI_PARSER ProcessorTopologyStructureHeaderParser[] = {
106 {L"Type", 1, 0, NULL, NULL, (VOID**)&ProcessorTopologyStructureType,
107 NULL, NULL},
108 {L"Length", 1, 1, NULL, NULL, (VOID**)&ProcessorTopologyStructureLength,
109 NULL, NULL},
110 {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
111 };
112
113 /**
114 An ACPI_PARSER array describing the Processor Hierarchy Node Structure - Type 0.
115 **/
116 STATIC CONST ACPI_PARSER ProcessorHierarchyNodeStructureParser[] = {
117 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
118 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
119 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
120
121 {L"Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
122 {L"Parent", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
123 {L"ACPI Processor ID", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
124 {L"Number of private resources", 4, 16, L"%d", NULL,
125 (VOID**)&NumberOfPrivateResources, NULL, NULL}
126 };
127
128 /**
129 An ACPI_PARSER array describing the Cache Type Structure - Type 1.
130 **/
131 STATIC CONST ACPI_PARSER CacheTypeStructureParser[] = {
132 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
133 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
134 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
135
136 {L"Flags", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
137 {L"Next Level of Cache", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
138 {L"Size", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
139 {L"Number of sets", 4, 16, L"%d", NULL, NULL, NULL, NULL},
140 {L"Associativity", 1, 20, L"%d", NULL, NULL, NULL, NULL},
141 {L"Attributes", 1, 21, L"0x%x", NULL, NULL, ValidateCacheAttributes, NULL},
142 {L"Line size", 2, 22, L"%d", NULL, NULL, ValidateCacheLineSize, NULL}
143 };
144
145 /**
146 An ACPI_PARSER array describing the ID Type Structure - Type 2.
147 **/
148 STATIC CONST ACPI_PARSER IdStructureParser[] = {
149 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
150 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
151 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
152
153 {L"VENDOR_ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
154 {L"LEVEL_1_ID", 8, 8, L"0x%x", NULL, NULL, NULL, NULL},
155 {L"LEVEL_2_ID", 8, 16, L"0x%x", NULL, NULL, NULL, NULL},
156 {L"MAJOR_REV", 2, 24, L"0x%x", NULL, NULL, NULL, NULL},
157 {L"MINOR_REV", 2, 26, L"0x%x", NULL, NULL, NULL, NULL},
158 {L"SPIN_REV", 2, 28, L"0x%x", NULL, NULL, NULL, NULL},
159 };
160
161 /**
162 This function parses the Processor Hierarchy Node Structure (Type 0).
163
164 @param [in] Ptr Pointer to the start of the Processor Hierarchy Node
165 Structure data.
166 @param [in] Length Length of the Processor Hierarchy Node Structure.
167 **/
168 STATIC
169 VOID
170 DumpProcessorHierarchyNodeStructure (
171 IN UINT8* Ptr,
172 IN UINT8 Length
173 )
174 {
175 UINT32 Offset;
176 UINT8* PrivateResourcePtr;
177 UINT32 Index;
178 CHAR16 Buffer[OUTPUT_FIELD_COLUMN_WIDTH];
179
180 Offset = ParseAcpi (
181 TRUE,
182 2,
183 "Processor Hierarchy Node Structure",
184 Ptr,
185 Length,
186 PARSER_PARAMS (ProcessorHierarchyNodeStructureParser)
187 );
188
189 PrivateResourcePtr = Ptr + Offset;
190 Index = 0;
191 while (Index < *NumberOfPrivateResources) {
192 UnicodeSPrint (
193 Buffer,
194 sizeof (Buffer),
195 L"Private resources [%d]",
196 Index
197 );
198
199 PrintFieldName (4, Buffer);
200 Print (
201 L"0x%x\n",
202 *((UINT32*) PrivateResourcePtr)
203 );
204
205 PrivateResourcePtr += sizeof(UINT32);
206 Index++;
207 }
208 }
209
210 /**
211 This function parses the Cache Type Structure (Type 1).
212
213 @param [in] Ptr Pointer to the start of the Cache Type Structure data.
214 @param [in] Length Length of the Cache Type Structure.
215 **/
216 STATIC
217 VOID
218 DumpCacheTypeStructure (
219 IN UINT8* Ptr,
220 IN UINT8 Length
221 )
222 {
223 ParseAcpi (
224 TRUE,
225 2,
226 "Cache Type Structure",
227 Ptr,
228 Length,
229 PARSER_PARAMS (CacheTypeStructureParser)
230 );
231 }
232
233 /**
234 This function parses the ID Structure (Type 2).
235
236 @param [in] Ptr Pointer to the start of the ID Structure data.
237 @param [in] Length Length of the ID Structure.
238 **/
239 STATIC
240 VOID
241 DumpIDStructure (
242 IN UINT8* Ptr,
243 IN UINT8 Length
244 )
245 {
246 ParseAcpi (
247 TRUE,
248 2,
249 "ID Structure",
250 Ptr,
251 Length,
252 PARSER_PARAMS (IdStructureParser)
253 );
254 }
255
256 /**
257 This function parses the ACPI PPTT table.
258 When trace is enabled this function parses the PPTT table and
259 traces the ACPI table fields.
260
261 This function parses the following processor topology structures:
262 - Processor hierarchy node structure (Type 0)
263 - Cache Type Structure (Type 1)
264 - ID structure (Type 2)
265
266 This function also performs validation of the ACPI table fields.
267
268 @param [in] Trace If TRUE, trace the ACPI fields.
269 @param [in] Ptr Pointer to the start of the buffer.
270 @param [in] AcpiTableLength Length of the ACPI table.
271 @param [in] AcpiTableRevision Revision of the ACPI table.
272 **/
273 VOID
274 EFIAPI
275 ParseAcpiPptt (
276 IN BOOLEAN Trace,
277 IN UINT8* Ptr,
278 IN UINT32 AcpiTableLength,
279 IN UINT8 AcpiTableRevision
280 )
281 {
282 UINT32 Offset;
283 UINT8* ProcessorTopologyStructurePtr;
284
285 if (!Trace) {
286 return;
287 }
288
289 Offset = ParseAcpi (
290 TRUE,
291 0,
292 "PPTT",
293 Ptr,
294 AcpiTableLength,
295 PARSER_PARAMS (PpttParser)
296 );
297 ProcessorTopologyStructurePtr = Ptr + Offset;
298
299 while (Offset < AcpiTableLength) {
300 // Parse Processor Hierarchy Node Structure to obtain Type and Length.
301 ParseAcpi (
302 FALSE,
303 0,
304 NULL,
305 ProcessorTopologyStructurePtr,
306 4, // Length of the processor topology structure header is 4 bytes
307 PARSER_PARAMS (ProcessorTopologyStructureHeaderParser)
308 );
309
310 if ((Offset + (*ProcessorTopologyStructureLength)) > AcpiTableLength) {
311 IncrementErrorCount ();
312 Print (
313 L"ERROR: Invalid processor topology structure length:"
314 L" Type = %d, Length = %d\n",
315 *ProcessorTopologyStructureType,
316 *ProcessorTopologyStructureLength
317 );
318 break;
319 }
320
321 PrintFieldName (2, L"* Structure Offset *");
322 Print (L"0x%x\n", Offset);
323
324 switch (*ProcessorTopologyStructureType) {
325 case EFI_ACPI_6_2_PPTT_TYPE_PROCESSOR:
326 DumpProcessorHierarchyNodeStructure (
327 ProcessorTopologyStructurePtr,
328 *ProcessorTopologyStructureLength
329 );
330 break;
331 case EFI_ACPI_6_2_PPTT_TYPE_CACHE:
332 DumpCacheTypeStructure (
333 ProcessorTopologyStructurePtr,
334 *ProcessorTopologyStructureLength
335 );
336 break;
337 case EFI_ACPI_6_2_PPTT_TYPE_ID:
338 DumpIDStructure (
339 ProcessorTopologyStructurePtr,
340 *ProcessorTopologyStructureLength
341 );
342 break;
343 default:
344 IncrementErrorCount ();
345 Print (
346 L"ERROR: Unknown processor topology structure:"
347 L" Type = %d, Length = %d\n",
348 *ProcessorTopologyStructureType,
349 *ProcessorTopologyStructureLength
350 );
351 }
352
353 ProcessorTopologyStructurePtr += *ProcessorTopologyStructureLength;
354 Offset += *ProcessorTopologyStructureLength;
355 } // while
356 }