4 Copyright (c) 2016 - 2021, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - ACPI 6.4 Specification - January 2021
11 #include <IndustryStandard/Acpi.h>
12 #include <Library/UefiLib.h>
13 #include "AcpiParser.h"
14 #include "AcpiTableParser.h"
15 #include "AcpiViewConfig.h"
17 // "The number of GT Block Timers must be less than or equal to 8"
18 #define GT_BLOCK_TIMER_COUNT_MAX 8
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
;
30 This function validates the GT Block timer count.
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.
39 ValidateGtBlockTimerCount (
44 UINT32 BlockTimerCount
;
46 BlockTimerCount
= *(UINT32
*)Ptr
;
48 if (BlockTimerCount
> GT_BLOCK_TIMER_COUNT_MAX
) {
49 IncrementErrorCount ();
51 L
"\nERROR: Timer Count = %d. Max Timer Count is %d.",
53 GT_BLOCK_TIMER_COUNT_MAX
59 This function validates the GT Frame Number.
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.
68 ValidateGtFrameNumber (
75 FrameNumber
= *(UINT8
*)Ptr
;
77 if (FrameNumber
>= GT_BLOCK_TIMER_COUNT_MAX
) {
78 IncrementErrorCount ();
80 L
"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-%d.",
82 GT_BLOCK_TIMER_COUNT_MAX
- 1
88 An ACPI_PARSER array describing the ACPI GTDT Table.
90 STATIC CONST ACPI_PARSER GtdtParser
[] = {
91 PARSE_ACPI_HEADER (&AcpiHdrInfo
),
92 { L
"CntControlBase Physical Address",8, 36, L
"0x%lx", 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
},
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
},
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
},
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
},
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
}
117 An ACPI_PARSER array describing the Platform timer header.
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
}
126 An ACPI_PARSER array describing the Platform GT Block.
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
,
140 An ACPI_PARSER array describing the GT Block timer.
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
,
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
}
156 An ACPI_PARSER array describing the Platform Watchdog.
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
}
169 This function parses the Platform GT Block.
171 @param [in] Ptr Pointer to the start of the GT Block data.
172 @param [in] Length Length of the GT Block structure.
190 PARSER_PARAMS (GtBlockParser
)
193 // Check if the values used to control the parsing logic have been
194 // successfully read.
195 if ((GtBlockTimerCount
== NULL
) ||
196 (GtBlockTimerOffset
== NULL
))
198 IncrementErrorCount ();
200 L
"ERROR: Insufficient GT Block Structure length. Length = %d.\n",
206 Offset
= *GtBlockTimerOffset
;
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
) &&
214 Offset
+= ParseAcpi (
220 PARSER_PARAMS (GtBlockTimerParser
)
226 This function parses the Platform Watchdog timer.
228 @param [in] Ptr Pointer to the start of the watchdog timer data.
229 @param [in] Length Length of the watchdog timer structure.
241 "Arm Generic Watchdog",
244 PARSER_PARAMS (ArmGenericWatchdogParser
)
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.
253 This function also parses the following platform timer structures:
257 This function also performs validation of the ACPI table fields.
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.
269 IN UINT32 AcpiTableLength
,
270 IN UINT8 AcpiTableRevision
287 PARSER_PARAMS (GtdtParser
)
290 // Check if the values used to control the parsing logic have been
291 // successfully read.
292 if ((GtdtPlatformTimerCount
== NULL
) ||
293 (GtdtPlatformTimerOffset
== NULL
))
295 IncrementErrorCount ();
297 L
"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
303 TimerPtr
= Ptr
+ *GtdtPlatformTimerOffset
;
304 Offset
= *GtdtPlatformTimerOffset
;
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
))
312 // Parse the Platform Timer Header to obtain Length and Type
318 AcpiTableLength
- Offset
,
319 PARSER_PARAMS (GtPlatformTimerHeaderParser
)
322 // Check if the values used to control the parsing logic have been
323 // successfully read.
324 if ((PlatformTimerType
== NULL
) ||
325 (PlatformTimerLength
== NULL
))
327 IncrementErrorCount ();
329 L
"ERROR: Insufficient remaining table buffer length to read the " \
330 L
"Platform Timer Structure header. Length = %d.\n",
331 AcpiTableLength
- Offset
336 // Validate Platform Timer Structure length
337 if ((*PlatformTimerLength
== 0) ||
338 ((Offset
+ (*PlatformTimerLength
)) > AcpiTableLength
))
340 IncrementErrorCount ();
342 L
"ERROR: Invalid Platform Timer Structure length. " \
343 L
"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
344 *PlatformTimerLength
,
351 switch (*PlatformTimerType
) {
352 case EFI_ACPI_6_4_GTDT_GT_BLOCK
:
353 DumpGTBlock (TimerPtr
, *PlatformTimerLength
);
355 case EFI_ACPI_6_4_GTDT_ARM_GENERIC_WATCHDOG
:
356 DumpWatchdogTimer (TimerPtr
, *PlatformTimerLength
);
359 IncrementErrorCount ();
361 L
"ERROR: Invalid Platform Timer Type = %d\n",
367 TimerPtr
+= *PlatformTimerLength
;
368 Offset
+= *PlatformTimerLength
;