TianoCore EDK2 master
Loading...
Searching...
No Matches
Dbg2Parser.c
Go to the documentation of this file.
1
12#include <Library/UefiLib.h>
13#include "AcpiParser.h"
14#include "AcpiTableParser.h"
15
16// Local variables pointing to the table fields
17STATIC CONST UINT32 *OffsetDbgDeviceInfo;
18STATIC CONST UINT32 *NumberDbgDeviceInfo;
19STATIC CONST UINT16 *DbgDevInfoLen;
20STATIC CONST UINT8 *GasCount;
21STATIC CONST UINT16 *NameSpaceStringLength;
22STATIC CONST UINT16 *NameSpaceStringOffset;
23STATIC CONST UINT16 *OEMDataLength;
24STATIC CONST UINT16 *OEMDataOffset;
25STATIC CONST UINT16 *BaseAddrRegOffset;
26STATIC CONST UINT16 *AddrSizeOffset;
28
38VOID
39EFIAPI
41 IN UINT8 *Ptr,
42 IN UINT32 Length,
43 IN VOID *Context
44 )
45{
46 UINT16 NameSpaceStrLen;
47
48 NameSpaceStrLen = *(UINT16 *)Ptr;
49
50 if (NameSpaceStrLen < 2) {
52 Print (
53 L"\nERROR: NamespaceString Length = %d. If no Namespace device exists, " \
54 L"NamespaceString[] must contain a period '.'",
55 NameSpaceStrLen
56 );
57 }
58}
59
62 PARSE_ACPI_HEADER (&AcpiHdrInfo),
63 { L"OffsetDbgDeviceInfo", 4, 36, L"0x%x", NULL,
64 (VOID **)&OffsetDbgDeviceInfo, NULL, NULL },
65 { L"NumberDbgDeviceInfo", 4, 40, L"%d", NULL,
66 (VOID **)&NumberDbgDeviceInfo, NULL, NULL }
67};
68
72 { L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
73 { L"Length", 2, 1, L"%d", NULL, (VOID **)&DbgDevInfoLen, NULL, NULL }
74};
75
78 { L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL },
79 { L"Length", 2, 1, L"%d", NULL, NULL, NULL, NULL },
80
81 { L"Generic Address Registers Count", 1, 3, L"0x%x", NULL,
82 (VOID **)&GasCount, NULL, NULL },
83 { L"NameSpace String Length", 2, 4, L"%d", NULL,
84 (VOID **)&NameSpaceStringLength, ValidateNameSpaceStrLen, NULL },
85 { L"NameSpace String Offset", 2, 6, L"0x%x", NULL,
86 (VOID **)&NameSpaceStringOffset, NULL, NULL },
87 { L"OEM Data Length", 2, 8, L"%d", NULL, (VOID **)&OEMDataLength,
88 NULL, NULL },
89 { L"OEM Data Offset", 2, 10, L"0x%x", NULL, (VOID **)&OEMDataOffset,
90 NULL, NULL },
91
92 { L"Port Type", 2, 12, L"0x%x", NULL, NULL, NULL, NULL },
93 { L"Port SubType", 2, 14, L"0x%x", NULL, NULL, NULL, NULL },
94 { L"Reserved", 2, 16, L"%x", NULL, NULL, NULL, NULL },
95
96 { L"Base Address Register Offset", 2, 18, L"0x%x", NULL,
97 (VOID **)&BaseAddrRegOffset, NULL, NULL },
98 { L"Address Size Offset", 2, 20, L"0x%x", NULL,
99 (VOID **)&AddrSizeOffset, NULL, NULL }
100};
101
108STATIC
109VOID
110EFIAPI
112 IN UINT8 *Ptr,
113 IN UINT16 Length
114 )
115{
116 UINT16 Index;
117 UINT16 Offset;
118
119 ParseAcpi (
120 TRUE,
121 2,
122 "Debug Device Info",
123 Ptr,
124 Length,
126 );
127
128 // Check if the values used to control the parsing logic have been
129 // successfully read.
130 if ((GasCount == NULL) ||
131 (NameSpaceStringLength == NULL) ||
132 (NameSpaceStringOffset == NULL) ||
133 (OEMDataLength == NULL) ||
134 (OEMDataOffset == NULL) ||
135 (BaseAddrRegOffset == NULL) ||
136 (AddrSizeOffset == NULL))
137 {
139 Print (
140 L"ERROR: Insufficient Debug Device Information Structure length. " \
141 L"Length = %d.\n",
142 Length
143 );
144 return;
145 }
146
147 // GAS
148 Index = 0;
149 Offset = *BaseAddrRegOffset;
150 while ((Index++ < *GasCount) &&
151 (Offset < Length))
152 {
153 PrintFieldName (4, L"BaseAddressRegister");
154 Offset += (UINT16)DumpGasStruct (
155 Ptr + Offset,
156 4,
157 Length - Offset
158 );
159 }
160
161 // Make sure the array of address sizes corresponding to each GAS fit in the
162 // Debug Device Information structure
163 if ((*AddrSizeOffset + (*GasCount * sizeof (UINT32))) > Length) {
165 Print (
166 L"ERROR: Invalid GAS count. GasCount = %d. RemainingBufferLength = %d. " \
167 L"Parsing of the Debug Device Information structure aborted.\n",
168 *GasCount,
169 Length - *AddrSizeOffset
170 );
171 return;
172 }
173
174 // Address Size
175 Index = 0;
176 Offset = *AddrSizeOffset;
177 while ((Index++ < *GasCount) &&
178 (Offset < Length))
179 {
180 PrintFieldName (4, L"Address Size");
181 Print (L"0x%x\n", *((UINT32 *)(Ptr + Offset)));
182 Offset += sizeof (UINT32);
183 }
184
185 // NameSpace String
186 Index = 0;
187 Offset = *NameSpaceStringOffset;
188 PrintFieldName (4, L"NameSpace String");
189 while ((Index++ < *NameSpaceStringLength) &&
190 (Offset < Length))
191 {
192 Print (L"%c", *(Ptr + Offset));
193 Offset++;
194 }
195
196 Print (L"\n");
197
198 // OEM Data
199 if (*OEMDataOffset != 0) {
200 Index = 0;
201 Offset = *OEMDataOffset;
202 PrintFieldName (4, L"OEM Data");
203 while ((Index++ < *OEMDataLength) &&
204 (Offset < Length))
205 {
206 Print (L"%x ", *(Ptr + Offset));
207 if ((Index & 7) == 0) {
208 Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L"");
209 }
210
211 Offset++;
212 }
213
214 Print (L"\n");
215 }
216}
217
230VOID
231EFIAPI
233 IN BOOLEAN Trace,
234 IN UINT8 *Ptr,
235 IN UINT32 AcpiTableLength,
236 IN UINT8 AcpiTableRevision
237 )
238{
239 UINT32 Offset;
240 UINT32 Index;
241
242 if (!Trace) {
243 return;
244 }
245
246 Offset = ParseAcpi (
247 TRUE,
248 0,
249 "DBG2",
250 Ptr,
251 AcpiTableLength,
253 );
254
255 // Check if the values used to control the parsing logic have been
256 // successfully read.
257 if ((OffsetDbgDeviceInfo == NULL) ||
258 (NumberDbgDeviceInfo == NULL))
259 {
261 Print (
262 L"ERROR: Insufficient table length. AcpiTableLength = %d\n",
263 AcpiTableLength
264 );
265 return;
266 }
267
268 Offset = *OffsetDbgDeviceInfo;
269 Index = 0;
270
271 while (Index++ < *NumberDbgDeviceInfo) {
272 // Parse the Debug Device Information Structure header to obtain Length
273 ParseAcpi (
274 FALSE,
275 0,
276 NULL,
277 Ptr + Offset,
278 AcpiTableLength - Offset,
280 );
281
282 // Check if the values used to control the parsing logic have been
283 // successfully read.
284 if (DbgDevInfoLen == NULL) {
286 Print (
287 L"ERROR: Insufficient remaining table buffer length to read the " \
288 L"Debug Device Information structure's 'Length' field. " \
289 L"RemainingTableBufferLength = %d.\n",
290 AcpiTableLength - Offset
291 );
292 return;
293 }
294
295 // Validate Debug Device Information Structure length
296 if ((*DbgDevInfoLen == 0) ||
297 ((Offset + (*DbgDevInfoLen)) > AcpiTableLength))
298 {
300 Print (
301 L"ERROR: Invalid Debug Device Information Structure length. " \
302 L"Length = %d. Offset = %d. AcpiTableLength = %d.\n",
303 *DbgDevInfoLen,
304 Offset,
305 AcpiTableLength
306 );
307 return;
308 }
309
310 DumpDbgDeviceInfo (Ptr + Offset, (*DbgDevInfoLen));
311 Offset += (*DbgDevInfoLen);
312 }
313}
UINT32 EFIAPI DumpGasStruct(IN UINT8 *Ptr, IN UINT32 Indent, IN UINT32 Length)
Definition: AcpiParser.c:841
VOID EFIAPI PrintFieldName(IN UINT32 Indent, IN CONST CHAR16 *FieldName)
Definition: AcpiParser.c:641
VOID EFIAPI IncrementErrorCount(VOID)
Definition: AcpiParser.c:83
UINT32 EFIAPI ParseAcpi(IN BOOLEAN Trace, IN UINT32 Indent, IN CONST CHAR8 *AsciiName OPTIONAL, IN UINT8 *Ptr, IN UINT32 Length, IN CONST ACPI_PARSER *Parser, IN UINT32 ParserItems)
Definition: AcpiParser.c:683
#define PARSER_PARAMS(Parser)
Definition: AcpiParser.h:494
#define PARSE_ACPI_HEADER(Info)
Definition: AcpiParser.h:501
STATIC CONST ACPI_PARSER Dbg2Parser[]
An ACPI_PARSER array describing the ACPI DBG2 table.
Definition: Dbg2Parser.c:61
STATIC VOID EFIAPI DumpDbgDeviceInfo(IN UINT8 *Ptr, IN UINT16 Length)
Definition: Dbg2Parser.c:111
STATIC CONST ACPI_PARSER DbgDevInfoParser[]
An ACPI_PARSER array describing the debug device information.
Definition: Dbg2Parser.c:77
VOID EFIAPI ParseAcpiDbg2(IN BOOLEAN Trace, IN UINT8 *Ptr, IN UINT32 AcpiTableLength, IN UINT8 AcpiTableRevision)
Definition: Dbg2Parser.c:232
STATIC VOID EFIAPI ValidateNameSpaceStrLen(IN UINT8 *Ptr, IN UINT32 Length, IN VOID *Context)
Definition: Dbg2Parser.c:40
STATIC CONST ACPI_PARSER DbgDevInfoHeaderParser[]
Definition: Dbg2Parser.c:71
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113