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