4 Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - ACPI 6.3 Specification - January 2019
11 #include <IndustryStandard/Acpi.h>
12 #include <Library/UefiLib.h>
13 #include "AcpiParser.h"
14 #include "AcpiTableParser.h"
16 // "The number of GT Block Timers must be less than or equal to 8"
17 #define GT_BLOCK_TIMER_COUNT_MAX 8
20 STATIC CONST UINT32
* GtdtPlatformTimerCount
;
21 STATIC CONST UINT32
* GtdtPlatformTimerOffset
;
22 STATIC CONST UINT8
* PlatformTimerType
;
23 STATIC CONST UINT16
* PlatformTimerLength
;
24 STATIC CONST UINT32
* GtBlockTimerCount
;
25 STATIC CONST UINT32
* GtBlockTimerOffset
;
26 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo
;
29 This function validates the GT Block timer count.
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.
38 ValidateGtBlockTimerCount (
43 UINT32 BlockTimerCount
;
45 BlockTimerCount
= *(UINT32
*)Ptr
;
47 if (BlockTimerCount
> GT_BLOCK_TIMER_COUNT_MAX
) {
48 IncrementErrorCount ();
50 L
"\nERROR: Timer Count = %d. Max Timer Count is %d.",
52 GT_BLOCK_TIMER_COUNT_MAX
58 This function validates the GT Frame Number.
60 @param [in] Ptr Pointer to the start of the field data.
61 @param [in] Context Pointer to context specific information e.g. this
62 could be a pointer to the ACPI table header.
67 ValidateGtFrameNumber (
74 FrameNumber
= *(UINT8
*)Ptr
;
76 if (FrameNumber
>= GT_BLOCK_TIMER_COUNT_MAX
) {
77 IncrementErrorCount ();
79 L
"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-%d.",
81 GT_BLOCK_TIMER_COUNT_MAX
- 1
87 An ACPI_PARSER array describing the ACPI GTDT Table.
89 STATIC CONST ACPI_PARSER GtdtParser
[] = {
90 PARSE_ACPI_HEADER (&AcpiHdrInfo
),
91 {L
"CntControlBase Physical Address", 8, 36, L
"0x%lx", NULL
, NULL
,
93 {L
"Reserved", 4, 44, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
94 {L
"Secure EL1 timer GSIV", 4, 48, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
95 {L
"Secure EL1 timer FLAGS", 4, 52, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
97 {L
"Non-Secure EL1 timer GSIV", 4, 56, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
98 {L
"Non-Secure EL1 timer FLAGS", 4, 60, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
100 {L
"Virtual timer GSIV", 4, 64, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
101 {L
"Virtual timer FLAGS", 4, 68, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
103 {L
"Non-Secure EL2 timer GSIV", 4, 72, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
104 {L
"Non-Secure EL2 timer FLAGS", 4, 76, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
106 {L
"CntReadBase Physical address", 8, 80, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
107 {L
"Platform Timer Count", 4, 88, L
"%d", NULL
,
108 (VOID
**)&GtdtPlatformTimerCount
, NULL
, NULL
},
109 {L
"Platform Timer Offset", 4, 92, L
"0x%x", NULL
,
110 (VOID
**)&GtdtPlatformTimerOffset
, NULL
, NULL
},
111 {L
"Virtual EL2 Timer GSIV", 4, 96, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
112 {L
"Virtual EL2 Timer Flags", 4, 100, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
116 An ACPI_PARSER array describing the Platform timer header.
118 STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser
[] = {
119 {L
"Type", 1, 0, NULL
, NULL
, (VOID
**)&PlatformTimerType
, NULL
, NULL
},
120 {L
"Length", 2, 1, NULL
, NULL
, (VOID
**)&PlatformTimerLength
, NULL
, NULL
},
121 {L
"Reserved", 1, 3, NULL
, NULL
, NULL
, NULL
, NULL
}
125 An ACPI_PARSER array describing the Platform GT Block.
127 STATIC CONST ACPI_PARSER GtBlockParser
[] = {
128 {L
"Type", 1, 0, L
"%d", NULL
, NULL
, NULL
, NULL
},
129 {L
"Length", 2, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
130 {L
"Reserved", 1, 3, L
"%x", NULL
, NULL
, NULL
, NULL
},
131 {L
"Physical address (CntCtlBase)", 8, 4, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
132 {L
"Timer Count", 4, 12, L
"%d", NULL
, (VOID
**)&GtBlockTimerCount
,
133 ValidateGtBlockTimerCount
, NULL
},
134 {L
"Timer Offset", 4, 16, L
"%d", NULL
, (VOID
**)&GtBlockTimerOffset
, NULL
,
139 An ACPI_PARSER array describing the GT Block timer.
141 STATIC CONST ACPI_PARSER GtBlockTimerParser
[] = {
142 {L
"Frame Number", 1, 0, L
"%d", NULL
, NULL
, ValidateGtFrameNumber
, NULL
},
143 {L
"Reserved", 3, 1, L
"%x %x %x", Dump3Chars
, NULL
, NULL
, NULL
},
144 {L
"Physical address (CntBaseX)", 8, 4, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
145 {L
"Physical address (CntEL0BaseX)", 8, 12, L
"0x%lx", NULL
, NULL
, NULL
,
147 {L
"Physical Timer GSIV", 4, 20, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
148 {L
"Physical Timer Flags", 4, 24, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
149 {L
"Virtual Timer GSIV", 4, 28, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
150 {L
"Virtual Timer Flags", 4, 32, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
151 {L
"Common Flags", 4, 36, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
155 An ACPI_PARSER array describing the Platform Watchdog.
157 STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser
[] = {
158 {L
"Type", 1, 0, L
"%d", NULL
, NULL
, NULL
, NULL
},
159 {L
"Length", 2, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
160 {L
"Reserved", 1, 3, L
"%x", NULL
, NULL
, NULL
, NULL
},
161 {L
"RefreshFrame Physical address", 8, 4, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
162 {L
"ControlFrame Physical address", 8, 12, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
163 {L
"Watchdog Timer GSIV", 4, 20, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
164 {L
"Watchdog Timer Flags", 4, 24, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
168 This function parses the Platform GT Block.
170 @param [in] Ptr Pointer to the start of the GT Block data.
171 @param [in] Length Length of the GT Block structure.
189 PARSER_PARAMS (GtBlockParser
)
192 // Check if the values used to control the parsing logic have been
193 // successfully read.
194 if ((GtBlockTimerCount
== NULL
) ||
195 (GtBlockTimerOffset
== NULL
)) {
196 IncrementErrorCount ();
198 L
"ERROR: Insufficient GT Block Structure length. Length = %d.\n",
204 Offset
= *GtBlockTimerOffset
;
207 // Parse the specified number of GT Block Timer Structures or the GT Block
208 // Structure buffer length. Whichever is minimum.
209 while ((Index
++ < *GtBlockTimerCount
) &&
211 Offset
+= ParseAcpi (
217 PARSER_PARAMS (GtBlockTimerParser
)
223 This function parses the Platform Watchdog timer.
225 @param [in] Ptr Pointer to the start of the watchdog timer data.
226 @param [in] Length Length of the watchdog timer structure.
238 "SBSA Generic Watchdog",
241 PARSER_PARAMS (SBSAGenericWatchdogParser
)
246 This function parses the ACPI GTDT table.
247 When trace is enabled this function parses the GTDT table and
248 traces the ACPI table fields.
250 This function also parses the following platform timer structures:
254 This function also performs validation of the ACPI table fields.
256 @param [in] Trace If TRUE, trace the ACPI fields.
257 @param [in] Ptr Pointer to the start of the buffer.
258 @param [in] AcpiTableLength Length of the ACPI table.
259 @param [in] AcpiTableRevision Revision of the ACPI table.
266 IN UINT32 AcpiTableLength
,
267 IN UINT8 AcpiTableRevision
284 PARSER_PARAMS (GtdtParser
)
287 // Check if the values used to control the parsing logic have been
288 // successfully read.
289 if ((GtdtPlatformTimerCount
== NULL
) ||
290 (GtdtPlatformTimerOffset
== NULL
)) {
291 IncrementErrorCount ();
293 L
"ERROR: Insufficient table length. AcpiTableLength = %d.\n",
299 TimerPtr
= Ptr
+ *GtdtPlatformTimerOffset
;
300 Offset
= *GtdtPlatformTimerOffset
;
303 // Parse the specified number of Platform Timer Structures or the GTDT
304 // buffer length. Whichever is minimum.
305 while ((Index
++ < *GtdtPlatformTimerCount
) &&
306 (Offset
< AcpiTableLength
)) {
307 // Parse the Platform Timer Header to obtain Length and Type
313 AcpiTableLength
- Offset
,
314 PARSER_PARAMS (GtPlatformTimerHeaderParser
)
317 // Check if the values used to control the parsing logic have been
318 // successfully read.
319 if ((PlatformTimerType
== NULL
) ||
320 (PlatformTimerLength
== NULL
)) {
321 IncrementErrorCount ();
323 L
"ERROR: Insufficient remaining table buffer length to read the " \
324 L
"Platform Timer Structure header. Length = %d.\n",
325 AcpiTableLength
- Offset
330 // Make sure the Platform Timer is inside the table.
331 if ((Offset
+ *PlatformTimerLength
) > AcpiTableLength
) {
332 IncrementErrorCount ();
334 L
"ERROR: Invalid Platform Timer Structure length. " \
335 L
"PlatformTimerLength = %d. RemainingTableBufferLength = %d. " \
336 L
"GTDT parsing aborted.\n",
337 *PlatformTimerLength
,
338 AcpiTableLength
- Offset
343 switch (*PlatformTimerType
) {
344 case EFI_ACPI_6_3_GTDT_GT_BLOCK
:
345 DumpGTBlock (TimerPtr
, *PlatformTimerLength
);
347 case EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG
:
348 DumpWatchdogTimer (TimerPtr
, *PlatformTimerLength
);
351 IncrementErrorCount ();
353 L
"ERROR: Invalid Platform Timer Type = %d\n",
359 TimerPtr
+= *PlatformTimerLength
;
360 Offset
+= *PlatformTimerLength
;