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