]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Gtdt / GtdtParser.c
1 /** @file
2 GTDT table parser
3
4 Copyright (c) 2016 - 2021, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Reference(s):
8 - ACPI 6.4 Specification - January 2021
9 **/
10
11 #include <IndustryStandard/Acpi.h>
12 #include <Library/UefiLib.h>
13 #include "AcpiParser.h"
14 #include "AcpiTableParser.h"
15 #include "AcpiViewConfig.h"
16
17 // "The number of GT Block Timers must be less than or equal to 8"
18 #define GT_BLOCK_TIMER_COUNT_MAX 8
19
20 // Local variables
21 STATIC CONST UINT32 *GtdtPlatformTimerCount;
22 STATIC CONST UINT32 *GtdtPlatformTimerOffset;
23 STATIC CONST UINT8 *PlatformTimerType;
24 STATIC CONST UINT16 *PlatformTimerLength;
25 STATIC CONST UINT32 *GtBlockTimerCount;
26 STATIC CONST UINT32 *GtBlockTimerOffset;
27 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
28
29 /**
30 This function validates the GT Block timer count.
31
32 @param [in] Ptr Pointer to the start of the field data.
33 @param [in] Context Pointer to context specific information e.g. this
34 could be a pointer to the ACPI table header.
35 **/
36 STATIC
37 VOID
38 EFIAPI
39 ValidateGtBlockTimerCount (
40 IN UINT8 *Ptr,
41 IN VOID *Context
42 )
43 {
44 UINT32 BlockTimerCount;
45
46 BlockTimerCount = *(UINT32 *)Ptr;
47
48 if (BlockTimerCount > GT_BLOCK_TIMER_COUNT_MAX) {
49 IncrementErrorCount ();
50 Print (
51 L"\nERROR: Timer Count = %d. Max Timer Count is %d.",
52 BlockTimerCount,
53 GT_BLOCK_TIMER_COUNT_MAX
54 );
55 }
56 }
57
58 /**
59 This function validates the GT Frame Number.
60
61 @param [in] Ptr Pointer to the start of the field data.
62 @param [in] Context Pointer to context specific information e.g. this
63 could be a pointer to the ACPI table header.
64 **/
65 STATIC
66 VOID
67 EFIAPI
68 ValidateGtFrameNumber (
69 IN UINT8 *Ptr,
70 IN VOID *Context
71 )
72 {
73 UINT8 FrameNumber;
74
75 FrameNumber = *(UINT8 *)Ptr;
76
77 if (FrameNumber >= GT_BLOCK_TIMER_COUNT_MAX) {
78 IncrementErrorCount ();
79 Print (
80 L"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-%d.",
81 FrameNumber,
82 GT_BLOCK_TIMER_COUNT_MAX - 1
83 );
84 }
85 }
86
87 /**
88 An ACPI_PARSER array describing the ACPI GTDT Table.
89 **/
90 STATIC CONST ACPI_PARSER GtdtParser[] = {
91 PARSE_ACPI_HEADER (&AcpiHdrInfo),
92 { L"CntControlBase Physical Address",8, 36, L"0x%lx", NULL, NULL,
93 NULL, NULL },
94 { L"Reserved", 4, 44, L"0x%x", NULL, NULL,NULL, NULL },
95 { L"Secure EL1 timer GSIV", 4, 48, L"0x%x", NULL, NULL,NULL, NULL },
96 { L"Secure EL1 timer FLAGS", 4, 52, L"0x%x", NULL, NULL,NULL, NULL },
97
98 { L"Non-Secure EL1 timer GSIV", 4, 56, L"0x%x", NULL, NULL,NULL, NULL },
99 { L"Non-Secure EL1 timer FLAGS", 4, 60, L"0x%x", NULL, NULL,NULL, NULL },
100
101 { L"Virtual timer GSIV", 4, 64, L"0x%x", NULL, NULL,NULL, NULL },
102 { L"Virtual timer FLAGS", 4, 68, L"0x%x", NULL, NULL,NULL, NULL },
103
104 { L"Non-Secure EL2 timer GSIV", 4, 72, L"0x%x", NULL, NULL,NULL, NULL },
105 { L"Non-Secure EL2 timer FLAGS", 4, 76, L"0x%x", NULL, NULL,NULL, NULL },
106
107 { L"CntReadBase Physical address", 8, 80, L"0x%lx", NULL, NULL,NULL, NULL },
108 { L"Platform Timer Count", 4, 88, L"%d", NULL,
109 (VOID **)&GtdtPlatformTimerCount, NULL, NULL },
110 { L"Platform Timer Offset", 4, 92, L"0x%x", NULL,
111 (VOID **)&GtdtPlatformTimerOffset,NULL, NULL },
112 { L"Virtual EL2 Timer GSIV", 4, 96, L"0x%x", NULL, NULL,NULL, NULL },
113 { L"Virtual EL2 Timer Flags", 4, 100, L"0x%x", NULL, NULL,NULL, NULL }
114 };
115
116 /**
117 An ACPI_PARSER array describing the Platform timer header.
118 **/
119 STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = {
120 { L"Type", 1, 0, NULL, NULL, (VOID **)&PlatformTimerType, NULL, NULL },
121 { L"Length", 2, 1, NULL, NULL, (VOID **)&PlatformTimerLength, NULL, NULL },
122 { L"Reserved", 1, 3, NULL, NULL, NULL, NULL, NULL }
123 };
124
125 /**
126 An ACPI_PARSER array describing the Platform GT Block.
127 **/
128 STATIC CONST ACPI_PARSER GtBlockParser[] = {
129 { L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL },
130 { L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL },
131 { L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL },
132 { L"Physical address (CntCtlBase)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL },
133 { L"Timer Count", 4, 12, L"%d", NULL, (VOID **)&GtBlockTimerCount,
134 ValidateGtBlockTimerCount, NULL },
135 { L"Timer Offset", 4, 16, L"%d", NULL, (VOID **)&GtBlockTimerOffset, NULL,
136 NULL }
137 };
138
139 /**
140 An ACPI_PARSER array describing the GT Block timer.
141 **/
142 STATIC CONST ACPI_PARSER GtBlockTimerParser[] = {
143 { L"Frame Number", 1, 0, L"%d", NULL, NULL, ValidateGtFrameNumber, NULL },
144 { L"Reserved", 3, 1, L"%x %x %x", Dump3Chars, NULL, NULL, NULL },
145 { L"Physical address (CntBaseX)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL },
146 { L"Physical address (CntEL0BaseX)", 8, 12, L"0x%lx", NULL, NULL, NULL,
147 NULL },
148 { L"Physical Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL },
149 { L"Physical Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL },
150 { L"Virtual Timer GSIV", 4, 28, L"0x%x", NULL, NULL, NULL, NULL },
151 { L"Virtual Timer Flags", 4, 32, L"0x%x", NULL, NULL, NULL, NULL },
152 { L"Common Flags", 4, 36, L"0x%x", NULL, NULL, NULL, NULL }
153 };
154
155 /**
156 An ACPI_PARSER array describing the Platform Watchdog.
157 **/
158 STATIC CONST ACPI_PARSER ArmGenericWatchdogParser[] = {
159 { L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL },
160 { L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL },
161 { L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL },
162 { L"RefreshFrame Physical address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL },
163 { L"ControlFrame Physical address", 8, 12, L"0x%lx", NULL, NULL, NULL, NULL },
164 { L"Watchdog Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL },
165 { L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL }
166 };
167
168 /**
169 This function parses the Platform GT Block.
170
171 @param [in] Ptr Pointer to the start of the GT Block data.
172 @param [in] Length Length of the GT Block structure.
173 **/
174 STATIC
175 VOID
176 DumpGTBlock (
177 IN UINT8 *Ptr,
178 IN UINT16 Length
179 )
180 {
181 UINT32 Index;
182 UINT32 Offset;
183
184 ParseAcpi (
185 TRUE,
186 2,
187 "GT Block",
188 Ptr,
189 Length,
190 PARSER_PARAMS (GtBlockParser)
191 );
192
193 // Check if the values used to control the parsing logic have been
194 // successfully read.
195 if ((GtBlockTimerCount == NULL) ||
196 (GtBlockTimerOffset == NULL))
197 {
198 IncrementErrorCount ();
199 Print (
200 L"ERROR: Insufficient GT Block Structure length. Length = %d.\n",
201 Length
202 );
203 return;
204 }
205
206 Offset = *GtBlockTimerOffset;
207 Index = 0;
208
209 // Parse the specified number of GT Block Timer Structures or the GT Block
210 // Structure buffer length. Whichever is minimum.
211 while ((Index++ < *GtBlockTimerCount) &&
212 (Offset < Length))
213 {
214 Offset += ParseAcpi (
215 TRUE,
216 2,
217 "GT Block Timer",
218 Ptr + Offset,
219 Length - Offset,
220 PARSER_PARAMS (GtBlockTimerParser)
221 );
222 }
223 }
224
225 /**
226 This function parses the Platform Watchdog timer.
227
228 @param [in] Ptr Pointer to the start of the watchdog timer data.
229 @param [in] Length Length of the watchdog timer structure.
230 **/
231 STATIC
232 VOID
233 DumpWatchdogTimer (
234 IN UINT8 *Ptr,
235 IN UINT16 Length
236 )
237 {
238 ParseAcpi (
239 TRUE,
240 2,
241 "Arm Generic Watchdog",
242 Ptr,
243 Length,
244 PARSER_PARAMS (ArmGenericWatchdogParser)
245 );
246 }
247
248 /**
249 This function parses the ACPI GTDT table.
250 When trace is enabled this function parses the GTDT table and
251 traces the ACPI table fields.
252
253 This function also parses the following platform timer structures:
254 - GT Block timer
255 - Watchdog timer
256
257 This function also performs validation of the ACPI table fields.
258
259 @param [in] Trace If TRUE, trace the ACPI fields.
260 @param [in] Ptr Pointer to the start of the buffer.
261 @param [in] AcpiTableLength Length of the ACPI table.
262 @param [in] AcpiTableRevision Revision of the ACPI table.
263 **/
264 VOID
265 EFIAPI
266 ParseAcpiGtdt (
267 IN BOOLEAN Trace,
268 IN UINT8 *Ptr,
269 IN UINT32 AcpiTableLength,
270 IN UINT8 AcpiTableRevision
271 )
272 {
273 UINT32 Index;
274 UINT32 Offset;
275 UINT8 *TimerPtr;
276
277 if (!Trace) {
278 return;
279 }
280
281 ParseAcpi (
282 TRUE,
283 0,
284 "GTDT",
285 Ptr,
286 AcpiTableLength,
287 PARSER_PARAMS (GtdtParser)
288 );
289
290 // Check if the values used to control the parsing logic have been
291 // successfully read.
292 if ((GtdtPlatformTimerCount == NULL) ||
293 (GtdtPlatformTimerOffset == NULL))
294 {
295 IncrementErrorCount ();
296 Print (
297 L"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
298 AcpiTableLength
299 );
300 return;
301 }
302
303 TimerPtr = Ptr + *GtdtPlatformTimerOffset;
304 Offset = *GtdtPlatformTimerOffset;
305 Index = 0;
306
307 // Parse the specified number of Platform Timer Structures or the GTDT
308 // buffer length. Whichever is minimum.
309 while ((Index++ < *GtdtPlatformTimerCount) &&
310 (Offset < AcpiTableLength))
311 {
312 // Parse the Platform Timer Header to obtain Length and Type
313 ParseAcpi (
314 FALSE,
315 0,
316 NULL,
317 TimerPtr,
318 AcpiTableLength - Offset,
319 PARSER_PARAMS (GtPlatformTimerHeaderParser)
320 );
321
322 // Check if the values used to control the parsing logic have been
323 // successfully read.
324 if ((PlatformTimerType == NULL) ||
325 (PlatformTimerLength == NULL))
326 {
327 IncrementErrorCount ();
328 Print (
329 L"ERROR: Insufficient remaining table buffer length to read the " \
330 L"Platform Timer Structure header. Length = %d.\n",
331 AcpiTableLength - Offset
332 );
333 return;
334 }
335
336 // Validate Platform Timer Structure length
337 if ((*PlatformTimerLength == 0) ||
338 ((Offset + (*PlatformTimerLength)) > AcpiTableLength))
339 {
340 IncrementErrorCount ();
341 Print (
342 L"ERROR: Invalid Platform Timer Structure length. " \
343 L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
344 *PlatformTimerLength,
345 Offset,
346 AcpiTableLength
347 );
348 return;
349 }
350
351 switch (*PlatformTimerType) {
352 case EFI_ACPI_6_4_GTDT_GT_BLOCK:
353 DumpGTBlock (TimerPtr, *PlatformTimerLength);
354 break;
355 case EFI_ACPI_6_4_GTDT_ARM_GENERIC_WATCHDOG:
356 DumpWatchdogTimer (TimerPtr, *PlatformTimerLength);
357 break;
358 default:
359 IncrementErrorCount ();
360 Print (
361 L"ERROR: Invalid Platform Timer Type = %d\n",
362 *PlatformTimerType
363 );
364 break;
365 } // switch
366
367 TimerPtr += *PlatformTimerLength;
368 Offset += *PlatformTimerLength;
369 } // while
370 }