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