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 Offset
= *GtBlockTimerOffset
;
195 // Parse the specified number of GT Block Timer Structures or the GT Block
196 // Structure buffer length. Whichever is minimum.
197 while ((Index
++ < *GtBlockTimerCount
) &&
199 Offset
+= ParseAcpi (
205 PARSER_PARAMS (GtBlockTimerParser
)
211 This function parses the Platform Watchdog timer.
213 @param [in] Ptr Pointer to the start of the watchdog timer data.
214 @param [in] Length Length of the watchdog timer structure.
226 "SBSA Generic Watchdog",
229 PARSER_PARAMS (SBSAGenericWatchdogParser
)
234 This function parses the ACPI GTDT table.
235 When trace is enabled this function parses the GTDT table and
236 traces the ACPI table fields.
238 This function also parses the following platform timer structures:
242 This function also performs validation of the ACPI table fields.
244 @param [in] Trace If TRUE, trace the ACPI fields.
245 @param [in] Ptr Pointer to the start of the buffer.
246 @param [in] AcpiTableLength Length of the ACPI table.
247 @param [in] AcpiTableRevision Revision of the ACPI table.
254 IN UINT32 AcpiTableLength
,
255 IN UINT8 AcpiTableRevision
272 PARSER_PARAMS (GtdtParser
)
275 TimerPtr
= Ptr
+ *GtdtPlatformTimerOffset
;
276 Offset
= *GtdtPlatformTimerOffset
;
279 // Parse the specified number of Platform Timer Structures or the GTDT
280 // buffer length. Whichever is minimum.
281 while ((Index
++ < *GtdtPlatformTimerCount
) &&
282 (Offset
< AcpiTableLength
)) {
283 // Parse the Platform Timer Header to obtain Length and Type
289 AcpiTableLength
- Offset
,
290 PARSER_PARAMS (GtPlatformTimerHeaderParser
)
293 // Make sure the Platform Timer is inside the table.
294 if ((Offset
+ *PlatformTimerLength
) > AcpiTableLength
) {
295 IncrementErrorCount ();
297 L
"ERROR: Invalid Platform Timer Structure length. " \
298 L
"PlatformTimerLength = %d. RemainingTableBufferLength = %d. " \
299 L
"GTDT parsing aborted.\n",
300 *PlatformTimerLength
,
301 AcpiTableLength
- Offset
306 switch (*PlatformTimerType
) {
307 case EFI_ACPI_6_3_GTDT_GT_BLOCK
:
308 DumpGTBlock (TimerPtr
, *PlatformTimerLength
);
310 case EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG
:
311 DumpWatchdogTimer (TimerPtr
, *PlatformTimerLength
);
314 IncrementErrorCount ();
316 L
"ERROR: Invalid Platform Timer Type = %d\n",
322 TimerPtr
+= *PlatformTimerLength
;
323 Offset
+= *PlatformTimerLength
;