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