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