]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Gtdt/GtdtParser.c
0ab460b02c9e062ac181e42e7e77f875a40c86dc
[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 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 @par Reference(s):
14 - ACPI 6.2 Specification - Errata A, September 2017
15 **/
16
17 #include <IndustryStandard/Acpi.h>
18 #include <Library/UefiLib.h>
19 #include "AcpiParser.h"
20 #include "AcpiTableParser.h"
21
22 // Local variables
23 STATIC CONST UINT32* GtdtPlatformTimerCount;
24 STATIC CONST UINT32* GtdtPlatformTimerOffset;
25 STATIC CONST UINT8* PlatformTimerType;
26 STATIC CONST UINT16* PlatformTimerLength;
27 STATIC CONST UINT32* GtBlockTimerCount;
28 STATIC CONST UINT32* GtBlockTimerOffset;
29 STATIC CONST UINT16* GtBlockLength;
30 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
31
32 /**
33 This function validates the GT Block timer count.
34
35 @param [in] Ptr Pointer to the start of the field data.
36 @param [in] Context Pointer to context specific information e.g. this
37 could be a pointer to the ACPI table header.
38 **/
39 STATIC
40 VOID
41 EFIAPI
42 ValidateGtBlockTimerCount (
43 IN UINT8* Ptr,
44 IN VOID* Context
45 );
46
47 /**
48 An ACPI_PARSER array describing the ACPI GTDT Table.
49 **/
50 STATIC CONST ACPI_PARSER GtdtParser[] = {
51 PARSE_ACPI_HEADER (&AcpiHdrInfo),
52 {L"CntControlBase Physical Address", 8, 36, L"0x%lx", NULL, NULL,
53 NULL, NULL},
54 {L"Reserved", 4, 44, L"0x%x", NULL, NULL, NULL, NULL},
55 {L"Secure EL1 timer GSIV", 4, 48, L"0x%x", NULL, NULL, NULL, NULL},
56 {L"Secure EL1 timer FLAGS", 4, 52, L"0x%x", NULL, NULL, NULL, NULL},
57
58 {L"Non-Secure EL1 timer GSIV", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
59 {L"Non-Secure EL1 timer FLAGS", 4, 60, L"0x%x", NULL, NULL, NULL, NULL},
60
61 {L"Virtual timer GSIV", 4, 64, L"0x%x", NULL, NULL, NULL, NULL},
62 {L"Virtual timer FLAGS", 4, 68, L"0x%x", NULL, NULL, NULL, NULL},
63
64 {L"Non-Secure EL2 timer GSIV", 4, 72, L"0x%x", NULL, NULL, NULL, NULL},
65 {L"Non-Secure EL2 timer FLAGS", 4, 76, L"0x%x", NULL, NULL, NULL, NULL},
66
67 {L"CntReadBase Physical address", 8, 80, L"0x%lx", NULL, NULL, NULL, NULL},
68 {L"Platform Timer Count", 4, 88, L"%d", NULL,
69 (VOID**)&GtdtPlatformTimerCount, NULL, NULL},
70 {L"Platform Timer Offset", 4, 92, L"0x%x", NULL,
71 (VOID**)&GtdtPlatformTimerOffset, NULL, NULL}
72 };
73
74 /**
75 An ACPI_PARSER array describing the Platform timer header.
76 **/
77 STATIC CONST ACPI_PARSER GtPlatformTimerHeaderParser[] = {
78 {L"Type", 1, 0, NULL, NULL, (VOID**)&PlatformTimerType, NULL, NULL},
79 {L"Length", 2, 1, NULL, NULL, (VOID**)&PlatformTimerLength, NULL, NULL},
80 {L"Reserved", 1, 3, NULL, NULL, NULL, NULL, NULL}
81 };
82
83 /**
84 An ACPI_PARSER array describing the Platform GT Block.
85 **/
86 STATIC CONST ACPI_PARSER GtBlockParser[] = {
87 {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
88 {L"Length", 2, 1, L"%d", NULL, (VOID**)&GtBlockLength, NULL, NULL},
89 {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
90 {L"Physical address (CntCtlBase)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
91 {L"Timer Count", 4, 12, L"%d", NULL, (VOID**)&GtBlockTimerCount,
92 ValidateGtBlockTimerCount, NULL},
93 {L"Timer Offset", 4, 16, L"%d", NULL, (VOID**)&GtBlockTimerOffset, NULL,
94 NULL}
95 };
96
97 /**
98 An ACPI_PARSER array describing the GT Block timer.
99 **/
100 STATIC CONST ACPI_PARSER GtBlockTimerParser[] = {
101 {L"Frame Number", 1, 0, L"%d", NULL, NULL, NULL, NULL},
102 {L"Reserved", 3, 1, L"%x %x %x", Dump3Chars, NULL, NULL, NULL},
103 {L"Physical address (CntBaseX)", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
104 {L"Physical address (CntEL0BaseX)", 8, 12, L"0x%lx", NULL, NULL, NULL,
105 NULL},
106 {L"Physical Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
107 {L"Physical Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL},
108 {L"Virtual Timer GSIV", 4, 28, L"0x%x", NULL, NULL, NULL, NULL},
109 {L"Virtual Timer Flags", 4, 32, L"0x%x", NULL, NULL, NULL, NULL},
110 {L"Common Flags", 4, 36, L"0x%x", NULL, NULL, NULL, NULL}
111 };
112
113 /**
114 An ACPI_PARSER array describing the Platform Watchdog.
115 **/
116 STATIC CONST ACPI_PARSER SBSAGenericWatchdogParser[] = {
117 {L"Type", 1, 0, L"%d", NULL, NULL, NULL, NULL},
118 {L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL},
119 {L"Reserved", 1, 3, L"%x", NULL, NULL, NULL, NULL},
120 {L"RefreshFrame Physical address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL},
121 {L"ControlFrame Physical address", 8, 12, L"0x%lx", NULL, NULL, NULL, NULL},
122 {L"Watchdog Timer GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
123 {L"Watchdog Timer Flags", 4, 24, L"0x%x", NULL, NULL, NULL, NULL}
124 };
125
126 /**
127 This function validates the GT Block timer count.
128
129 @param [in] Ptr Pointer to the start of the field data.
130 @param [in] Context Pointer to context specific information e.g. this
131 could be a pointer to the ACPI table header.
132 **/
133 STATIC
134 VOID
135 EFIAPI
136 ValidateGtBlockTimerCount (
137 IN UINT8* Ptr,
138 IN VOID* Context
139 )
140 {
141 UINT32 BlockTimerCount;
142
143 BlockTimerCount = *(UINT32*)Ptr;
144
145 if (BlockTimerCount > 8) {
146 IncrementErrorCount ();
147 Print (
148 L"\nERROR: Timer Count = %d. Max Timer Count is 8.",
149 BlockTimerCount
150 );
151 }
152 }
153
154 /**
155 This function parses the Platform GT Block.
156
157 @param [in] Ptr Pointer to the start of the GT Block data.
158 @param [in] Length Length of the GT Block structure.
159 **/
160 STATIC
161 VOID
162 DumpGTBlock (
163 IN UINT8* Ptr,
164 IN UINT32 Length
165 )
166 {
167 UINT32 Index;
168 UINT32 Offset;
169 UINT32 GTBlockTimerLength;
170
171 Offset = ParseAcpi (
172 TRUE,
173 2,
174 "GT Block",
175 Ptr,
176 Length,
177 PARSER_PARAMS (GtBlockParser)
178 );
179 GTBlockTimerLength = (*GtBlockLength - Offset) / (*GtBlockTimerCount);
180 Length -= Offset;
181
182 if (*GtBlockTimerCount != 0) {
183 Ptr += (*GtBlockTimerOffset);
184 Index = 0;
185 while ((Index < (*GtBlockTimerCount)) && (Length >= GTBlockTimerLength)) {
186 Offset = ParseAcpi (
187 TRUE,
188 2,
189 "GT Block Timer",
190 Ptr,
191 GTBlockTimerLength,
192 PARSER_PARAMS (GtBlockTimerParser)
193 );
194 // Increment by GT Block Timer structure size
195 Ptr += Offset;
196 Length -= Offset;
197 Index++;
198 }
199
200 if (Length != 0) {
201 IncrementErrorCount ();
202 Print (
203 L"ERROR:GT Block Timer length mismatch. Unparsed %d bytes.\n",
204 Length
205 );
206 }
207 }
208 }
209
210 /**
211 This function parses the Platform Watchdog timer.
212
213 @param [in] Ptr Pointer to the start of the watchdog timer data.
214 @param [in] Length Length of the watchdog timer structure.
215 **/
216 STATIC
217 VOID
218 DumpWatchdogTimer (
219 IN UINT8* Ptr,
220 IN UINT16 Length
221 )
222 {
223 ParseAcpi (
224 TRUE,
225 2,
226 "SBSA Generic Watchdog",
227 Ptr,
228 Length,
229 PARSER_PARAMS (SBSAGenericWatchdogParser)
230 );
231 }
232
233 /**
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.
237
238 This function also parses the following platform timer structures:
239 - GT Block timer
240 - Watchdog timer
241
242 This function also performs validation of the ACPI table fields.
243
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.
248 **/
249 VOID
250 EFIAPI
251 ParseAcpiGtdt (
252 IN BOOLEAN Trace,
253 IN UINT8* Ptr,
254 IN UINT32 AcpiTableLength,
255 IN UINT8 AcpiTableRevision
256 )
257 {
258 UINT32 Index;
259 UINT8* TimerPtr;
260
261 if (!Trace) {
262 return;
263 }
264
265 ParseAcpi (
266 TRUE,
267 0,
268 "GTDT",
269 Ptr,
270 AcpiTableLength,
271 PARSER_PARAMS (GtdtParser)
272 );
273
274 if (*GtdtPlatformTimerCount != 0) {
275 TimerPtr = Ptr + (*GtdtPlatformTimerOffset);
276 Index = 0;
277 do {
278 // Parse the Platform Timer Header
279 ParseAcpi (
280 FALSE,
281 0,
282 NULL,
283 TimerPtr,
284 4, // GT Platform Timer structure header length.
285 PARSER_PARAMS (GtPlatformTimerHeaderParser)
286 );
287 switch (*PlatformTimerType) {
288 case EFI_ACPI_6_2_GTDT_GT_BLOCK:
289 DumpGTBlock (TimerPtr, *PlatformTimerLength);
290 break;
291 case EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG:
292 DumpWatchdogTimer (TimerPtr, *PlatformTimerLength);
293 break;
294 default:
295 IncrementErrorCount ();
296 Print (
297 L"ERROR: INVALID Platform Timer Type = %d\n",
298 *PlatformTimerType
299 );
300 break;
301 } // switch
302 TimerPtr += (*PlatformTimerLength);
303 Index++;
304 } while (Index < *GtdtPlatformTimerCount);
305 }
306 }