]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
1b7e56486c8fb98a8fe063ae5fa25d86500a58a9
[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.2 Specification - Errata A, September 2017
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 };
82
83 /**
84 An ACPI_PARSER array describing the Platform timer header.
85 **/
86 STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = {
87 {L"Type", 1, 0, NULL, NULL, (VOID**)&PlatformTimerType, NULL, NULL},
88 {L"Length", 2, 1, NULL, NULL, (VOID**)&PlatformTimerLength, NULL, NULL},
89 {L"Reserved", 1, 3, NULL, NULL, NULL, NULL, NULL}
90 };
91
92 /**
93 An ACPI_PARSER array describing the Platform GT Block.
94 **/
95 STATIC CONST ACPI_PARSER GtBlockParser[] = {
96 {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
97 {L"Length", 2, 1, L"%d", NULL, (VOID**)&GtBlockLength, NULL, NULL},
98 {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
99 {L"Physical address (CntCtlBase)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
100 {L"Timer Count", 4, 12, L"%d", NULL, (VOID**)&GtBlockTimerCount,
101 ValidateGtBlockTimerCount, NULL},
102 {L"Timer Offset", 4, 16, L"%d", NULL, (VOID**)&GtBlockTimerOffset, NULL,
103 NULL}
104 };
105
106 /**
107 An ACPI_PARSER array describing the GT Block timer.
108 **/
109 STATIC CONST ACPI_PARSER GtBlockTimerParser[] = {
110 {L"Frame Number", 1, 0, L"%d", NULL, NULL, ValidateGtFrameNumber, NULL},
111 {L"Reserved", 3, 1, L"%x %x %x", Dump3Chars, NULL, NULL, NULL},
112 {L"Physical address (CntBaseX)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
113 {L"Physical address (CntEL0BaseX)", 8, 12, L"0x%lx", NULL, NULL, NULL,
114 NULL},
115 {L"Physical Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
116 {L"Physical Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
117 {L"Virtual Timer GSIV", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
118 {L"Virtual Timer Flags", 4, 32, L"0x%x", NULL, NULL, NULL, NULL},
119 {L"Common Flags", 4, 36, L"0x%x", NULL, NULL, NULL, NULL}
120 };
121
122 /**
123 An ACPI_PARSER array describing the Platform Watchdog.
124 **/
125 STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = {
126 {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
127 {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},
128 {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
129 {L"RefreshFrame Physical address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
130 {L"ControlFrame Physical address", 8, 12, L"0x%lx", NULL, NULL, NULL, NULL},
131 {L"Watchdog Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
132 {L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL}
133 };
134
135 /**
136 This function validates the GT Block timer count.
137
138 @param [in] Ptr Pointer to the start of the field data.
139 @param [in] Context Pointer to context specific information e.g. this
140 could be a pointer to the ACPI table header.
141 **/
142 STATIC
143 VOID
144 EFIAPI
145 ValidateGtBlockTimerCount (
146 IN UINT8* Ptr,
147 IN VOID* Context
148 )
149 {
150 UINT32 BlockTimerCount;
151
152 BlockTimerCount = *(UINT32*)Ptr;
153
154 if (BlockTimerCount > 8) {
155 IncrementErrorCount ();
156 Print (
157 L"\nERROR: Timer Count = %d. Max Timer Count is 8.",
158 BlockTimerCount
159 );
160 }
161 }
162
163 /**
164 This function validates the GT Frame Number.
165
166 @param [in] Ptr Pointer to the start of the field data.
167 @param [in] Context Pointer to context specific information e.g. this
168 could be a pointer to the ACPI table header.
169 **/
170 STATIC
171 VOID
172 EFIAPI
173 ValidateGtFrameNumber (
174 IN UINT8* Ptr,
175 IN VOID* Context
176 )
177 {
178 UINT8 FrameNumber;
179
180 FrameNumber = *(UINT8*)Ptr;
181
182 if (FrameNumber > 7) {
183 IncrementErrorCount ();
184 Print (
185 L"\nERROR: GT Frame Number = %d. GT Frame Number must be in range 0-7.",
186 FrameNumber
187 );
188 }
189 }
190
191 /**
192 This function parses the Platform GT Block.
193
194 @param [in] Ptr Pointer to the start of the GT Block data.
195 @param [in] Length Length of the GT Block structure.
196 **/
197 STATIC
198 VOID
199 DumpGTBlock (
200 IN UINT8* Ptr,
201 IN UINT32 Length
202 )
203 {
204 UINT32 Index;
205 UINT32 Offset;
206 UINT32 GTBlockTimerLength;
207
208 Offset = ParseAcpi (
209 TRUE,
210 2,
211 "GT Block",
212 Ptr,
213 Length,
214 PARSER_PARAMS (GtBlockParser)
215 );
216 GTBlockTimerLength = (*GtBlockLength - Offset) / (*GtBlockTimerCount);
217 Length -= Offset;
218
219 if (*GtBlockTimerCount != 0) {
220 Ptr += (*GtBlockTimerOffset);
221 Index = 0;
222 while ((Index < (*GtBlockTimerCount)) && (Length >= GTBlockTimerLength)) {
223 Offset = ParseAcpi (
224 TRUE,
225 2,
226 "GT Block Timer",
227 Ptr,
228 GTBlockTimerLength,
229 PARSER_PARAMS (GtBlockTimerParser)
230 );
231 // Increment by GT Block Timer structure size
232 Ptr += Offset;
233 Length -= Offset;
234 Index++;
235 }
236
237 if (Length != 0) {
238 IncrementErrorCount ();
239 Print (
240 L"ERROR:GT Block Timer length mismatch. Unparsed %d bytes.\n",
241 Length
242 );
243 }
244 }
245 }
246
247 /**
248 This function parses the Platform Watchdog timer.
249
250 @param [in] Ptr Pointer to the start of the watchdog timer data.
251 @param [in] Length Length of the watchdog timer structure.
252 **/
253 STATIC
254 VOID
255 DumpWatchdogTimer (
256 IN UINT8* Ptr,
257 IN UINT16 Length
258 )
259 {
260 ParseAcpi (
261 TRUE,
262 2,
263 "SBSA Generic Watchdog",
264 Ptr,
265 Length,
266 PARSER_PARAMS (SBSAGenericWatchdogParser)
267 );
268 }
269
270 /**
271 This function parses the ACPI GTDT table.
272 When trace is enabled this function parses the GTDT table and
273 traces the ACPI table fields.
274
275 This function also parses the following platform timer structures:
276 - GT Block timer
277 - Watchdog timer
278
279 This function also performs validation of the ACPI table fields.
280
281 @param [in] Trace If TRUE, trace the ACPI fields.
282 @param [in] Ptr Pointer to the start of the buffer.
283 @param [in] AcpiTableLength Length of the ACPI table.
284 @param [in] AcpiTableRevision Revision of the ACPI table.
285 **/
286 VOID
287 EFIAPI
288 ParseAcpiGtdt (
289 IN BOOLEAN Trace,
290 IN UINT8* Ptr,
291 IN UINT32 AcpiTableLength,
292 IN UINT8 AcpiTableRevision
293 )
294 {
295 UINT32 Index;
296 UINT8* TimerPtr;
297
298 if (!Trace) {
299 return;
300 }
301
302 ParseAcpi (
303 TRUE,
304 0,
305 "GTDT",
306 Ptr,
307 AcpiTableLength,
308 PARSER_PARAMS (GtdtParser)
309 );
310
311 if (*GtdtPlatformTimerCount != 0) {
312 TimerPtr = Ptr + (*GtdtPlatformTimerOffset);
313 Index = 0;
314 do {
315 // Parse the Platform Timer Header
316 ParseAcpi (
317 FALSE,
318 0,
319 NULL,
320 TimerPtr,
321 4, // GT Platform Timer structure header length.
322 PARSER_PARAMS (GtPlatformTimerHeaderParser)
323 );
324 switch (*PlatformTimerType) {
325 case EFI_ACPI_6_2_GTDT_GT_BLOCK:
326 DumpGTBlock (TimerPtr, *PlatformTimerLength);
327 break;
328 case EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG:
329 DumpWatchdogTimer (TimerPtr, *PlatformTimerLength);
330 break;
331 default:
332 IncrementErrorCount ();
333 Print (
334 L"ERROR: INVALID Platform Timer Type = %d\n",
335 *PlatformTimerType
336 );
337 break;
338 } // switch
339 TimerPtr += (*PlatformTimerLength);
340 Index++;
341 } while (Index < *GtdtPlatformTimerCount);
342 }
343 }