]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
8de5ebf74775bab8e765849cba6ef4eb6f659a5a
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Dbg2 / Dbg2Parser.c
1 /** @file
2 DBG2 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 - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.
9 **/
10
11 #include <IndustryStandard/DebugPort2Table.h>
12 #include <Library/UefiLib.h>
13 #include "AcpiParser.h"
14 #include "AcpiTableParser.h"
15
16 // Local variables pointing to the table fields
17 STATIC CONST UINT32* OffsetDbgDeviceInfo;
18 STATIC CONST UINT32* NumberDbgDeviceInfo;
19 STATIC CONST UINT16* DbgDevInfoLen;
20 STATIC CONST UINT8* GasCount;
21 STATIC CONST UINT16* NameSpaceStringLength;
22 STATIC CONST UINT16* NameSpaceStringOffset;
23 STATIC CONST UINT16* OEMDataLength;
24 STATIC CONST UINT16* OEMDataOffset;
25 STATIC CONST UINT16* BaseAddrRegOffset;
26 STATIC CONST UINT16* AddrSizeOffset;
27 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
28
29 /**
30 This function Validates the NameSpace string length.
31
32 @param [in] Ptr Pointer to the start of the buffer.
33 @param [in] Context Pointer to context specific information e.g. this
34 could be a pointer to the ACPI table header.
35 **/
36 STATIC
37 VOID
38 EFIAPI
39 ValidateNameSpaceStrLen (
40 IN UINT8* Ptr,
41 IN VOID* Context
42 );
43
44 /**
45 This function parses the debug device information structure.
46
47 @param [in] Ptr Pointer to the start of the buffer.
48 @param [out] Length Pointer in which the length of the debug
49 device information is returned.
50 **/
51 STATIC
52 VOID
53 EFIAPI
54 DumpDbgDeviceInfo (
55 IN UINT8* Ptr,
56 OUT UINT32* Length
57 );
58
59 /// An ACPI_PARSER array describing the ACPI DBG2 table.
60 STATIC CONST ACPI_PARSER Dbg2Parser[] = {
61 PARSE_ACPI_HEADER (&AcpiHdrInfo),
62 {L"OffsetDbgDeviceInfo", 4, 36, L"0x%x", NULL,
63 (VOID**)&OffsetDbgDeviceInfo, NULL, NULL},
64 {L"NumberDbgDeviceInfo", 4, 40, L"%d", NULL,
65 (VOID**)&NumberDbgDeviceInfo, NULL, NULL}
66 };
67
68 /// An ACPI_PARSER array describing the debug device information.
69 STATIC CONST ACPI_PARSER DbgDevInfoParser[] = {
70 {L"Revision", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
71 {L"Length", 2, 1, L"%d", NULL, (VOID**)&DbgDevInfoLen, NULL, NULL},
72
73 {L"Generic Address Registers Count", 1, 3, L"0x%x", NULL,
74 (VOID**)&GasCount, NULL, NULL},
75 {L"NameSpace String Length", 2, 4, L"%d", NULL,
76 (VOID**)&NameSpaceStringLength, ValidateNameSpaceStrLen, NULL},
77 {L"NameSpace String Offset", 2, 6, L"0x%x", NULL,
78 (VOID**)&NameSpaceStringOffset, NULL, NULL},
79 {L"OEM Data Length", 2, 8, L"%d", NULL, (VOID**)&OEMDataLength,
80 NULL, NULL},
81 {L"OEM Data Offset", 2, 10, L"0x%x", NULL, (VOID**)&OEMDataOffset,
82 NULL, NULL},
83
84 {L"Port Type", 2, 12, L"0x%x", NULL, NULL, NULL, NULL},
85 {L"Port SubType", 2, 14, L"0x%x", NULL, NULL, NULL, NULL},
86 {L"Reserved", 2, 16, L"%x", NULL, NULL, NULL, NULL},
87
88 {L"Base Address Register Offset", 2, 18, L"0x%x", NULL,
89 (VOID**)&BaseAddrRegOffset, NULL, NULL},
90 {L"Address Size Offset", 2, 20, L"0x%x", NULL,
91 (VOID**)&AddrSizeOffset, NULL, NULL}
92 };
93
94 /**
95 This function validates the NameSpace string length.
96
97 @param [in] Ptr Pointer to the start of the buffer.
98 @param [in] Context Pointer to context specific information e.g. this
99 could be a pointer to the ACPI table header.
100 **/
101 STATIC
102 VOID
103 EFIAPI
104 ValidateNameSpaceStrLen (
105 IN UINT8* Ptr,
106 IN VOID* Context
107 )
108 {
109 UINT16 NameSpaceStrLen;
110
111 NameSpaceStrLen = *(UINT16*)Ptr;
112
113 if (NameSpaceStrLen < 2) {
114 IncrementErrorCount ();
115 Print (
116 L"\nERROR: NamespaceString Length = %d. If no Namespace device exists,\n"
117 L" then NamespaceString[] must contain a period '.'",
118 NameSpaceStrLen
119 );
120 }
121 }
122
123 /**
124 This function parses the debug device information structure.
125
126 @param [in] Ptr Pointer to the start of the buffer.
127 @param [out] Length Pointer in which the length of the debug
128 device information is returned.
129 **/
130 STATIC
131 VOID
132 EFIAPI
133 DumpDbgDeviceInfo (
134 IN UINT8* Ptr,
135 OUT UINT32* Length
136 )
137 {
138 UINT16 Index;
139 UINT8* DataPtr;
140 UINT32* AddrSize;
141
142 // Parse the debug device info to get the Length
143 ParseAcpi (
144 FALSE,
145 0,
146 "Debug Device Info",
147 Ptr,
148 3, // Length is 2 bytes starting at offset 1
149 PARSER_PARAMS (DbgDevInfoParser)
150 );
151
152 ParseAcpi (
153 TRUE,
154 2,
155 "Debug Device Info",
156 Ptr,
157 *DbgDevInfoLen,
158 PARSER_PARAMS (DbgDevInfoParser)
159 );
160
161 // GAS and Address Size
162 Index = 0;
163 DataPtr = Ptr + (*BaseAddrRegOffset);
164 AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));
165 while (Index < (*GasCount)) {
166 PrintFieldName (4, L"BaseAddressRegister");
167 DumpGasStruct (DataPtr, 4);
168 PrintFieldName (4, L"Address Size");
169 Print (L"0x%x\n", AddrSize[Index]);
170 DataPtr += GAS_LENGTH;
171 Index++;
172 }
173
174 // NameSpace String
175 Index = 0;
176 DataPtr = Ptr + (*NameSpaceStringOffset);
177 PrintFieldName (4, L"NameSpace String");
178 while (Index < (*NameSpaceStringLength)) {
179 Print (L"%c", DataPtr[Index++]);
180 }
181 Print (L"\n");
182
183 // OEM Data
184 Index = 0;
185 DataPtr = Ptr + (*OEMDataOffset);
186 PrintFieldName (4, L"OEM Data");
187 while (Index < (*OEMDataLength)) {
188 Print (L"%x ", DataPtr[Index++]);
189 if ((Index & 7) == 0) {
190 Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L"");
191 }
192 }
193 Print (L"\n");
194
195 *Length = *DbgDevInfoLen;
196 }
197
198 /**
199 This function parses the ACPI DBG2 table.
200 When trace is enabled this function parses the DBG2 table and
201 traces the ACPI table fields.
202
203 This function also performs validation of the ACPI table fields.
204
205 @param [in] Trace If TRUE, trace the ACPI fields.
206 @param [in] Ptr Pointer to the start of the buffer.
207 @param [in] AcpiTableLength Length of the ACPI table.
208 @param [in] AcpiTableRevision Revision of the ACPI table.
209 **/
210 VOID
211 EFIAPI
212 ParseAcpiDbg2 (
213 IN BOOLEAN Trace,
214 IN UINT8* Ptr,
215 IN UINT32 AcpiTableLength,
216 IN UINT8 AcpiTableRevision
217 )
218 {
219 UINT32 Offset;
220 UINT32 DbgDeviceInfoLength;
221 UINT8* DevInfoPtr;
222
223 if (!Trace) {
224 return;
225 }
226
227 Offset = ParseAcpi (
228 TRUE,
229 0,
230 "DBG2",
231 Ptr,
232 AcpiTableLength,
233 PARSER_PARAMS (Dbg2Parser)
234 );
235 DevInfoPtr = Ptr + Offset;
236
237 while (Offset < AcpiTableLength) {
238 DumpDbgDeviceInfo (
239 DevInfoPtr,
240 &DbgDeviceInfoLength
241 );
242 Offset += DbgDeviceInfoLength;
243 DevInfoPtr += DbgDeviceInfoLength;
244 }
245 }