]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Dbg2/Dbg2Parser.c
ShellPkg/UefiShellAcpiViewCommandLib: Fix ECC issues
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Dbg2 / Dbg2Parser.c
... / ...
CommitLineData
1/** @file\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/**\r
36 This function Validates the NameSpace string length.\r
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
41**/\r
42STATIC\r
43VOID\r
44EFIAPI\r
45ValidateNameSpaceStrLen (\r
46 IN UINT8* Ptr,\r
47 IN VOID* Context\r
48 );\r
49\r
50/**\r
51 This function parses the debug device information structure.\r
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
56**/\r
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
100/**\r
101 This function validates the NameSpace string length.\r
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
106**/\r
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;\r
116\r
117 NameSpaceStrLen = *(UINT16*)Ptr;\r
118\r
119 if (NameSpaceStrLen < 2) {\r
120 IncrementErrorCount ();\r
121 Print (\r
122 L"\nERROR: NamespaceString Length = %d. If no Namespace device exists,\n"\r
123 " then NamespaceString[] must contain a period '.'",\r
124 NameSpaceStrLen\r
125 );\r
126 }\r
127}\r
128\r
129/**\r
130 This function parses the debug device information structure.\r
131\r
132 @param [in] Ptr Pointer to the start of the buffer.\r
133 @param [out] Length Pointer in which the length of the debug\r
134 device information is returned.\r
135**/\r
136STATIC\r
137VOID\r
138EFIAPI\r
139DumpDbgDeviceInfo (\r
140 IN UINT8* Ptr,\r
141 OUT UINT32* Length\r
142 )\r
143{\r
144 UINT16 Index;\r
145 UINT8* DataPtr;\r
146 UINT32* AddrSize;\r
147\r
148 // Parse the debug device info to get the Length\r
149 ParseAcpi (\r
150 FALSE,\r
151 0,\r
152 "Debug Device Info",\r
153 Ptr,\r
154 3, // Length is 2 bytes starting at offset 1\r
155 PARSER_PARAMS (DbgDevInfoParser)\r
156 );\r
157\r
158 ParseAcpi (\r
159 TRUE,\r
160 2,\r
161 "Debug Device Info",\r
162 Ptr,\r
163 *DbgDevInfoLen,\r
164 PARSER_PARAMS (DbgDevInfoParser)\r
165 );\r
166\r
167 // GAS and Address Size\r
168 Index = 0;\r
169 DataPtr = Ptr + (*BaseAddrRegOffset);\r
170 AddrSize = (UINT32*)(Ptr + (*AddrSizeOffset));\r
171 while (Index < (*GasCount)) {\r
172 PrintFieldName (4, L"BaseAddressRegister");\r
173 DumpGasStruct (DataPtr, 4);\r
174 PrintFieldName (4, L"Address Size");\r
175 Print (L"0x%x\n", AddrSize[Index]);\r
176 DataPtr += GAS_LENGTH;\r
177 Index++;\r
178 }\r
179\r
180 // NameSpace String\r
181 Index = 0;\r
182 DataPtr = Ptr + (*NameSpaceStringOffset);\r
183 PrintFieldName (4, L"NameSpace String");\r
184 while (Index < (*NameSpaceStringLength)) {\r
185 Print (L"%c", DataPtr[Index++]);\r
186 }\r
187 Print (L"\n");\r
188\r
189 // OEM Data\r
190 Index = 0;\r
191 DataPtr = Ptr + (*OEMDataOffset);\r
192 PrintFieldName (4, L"OEM Data");\r
193 while (Index < (*OEMDataLength)) {\r
194 Print (L"%x ", DataPtr[Index++]);\r
195 if ((Index & 7) == 0) {\r
196 Print (L"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH, L"");\r
197 }\r
198 }\r
199\r
200 *Length = *DbgDevInfoLen;\r
201}\r
202\r
203/**\r
204 This function parses the ACPI DBG2 table.\r
205 When trace is enabled this function parses the DBG2 table and\r
206 traces the ACPI table fields.\r
207\r
208 This function also performs validation of the ACPI table fields.\r
209\r
210 @param [in] Trace If TRUE, trace the ACPI fields.\r
211 @param [in] Ptr Pointer to the start of the buffer.\r
212 @param [in] AcpiTableLength Length of the ACPI table.\r
213 @param [in] AcpiTableRevision Revision of the ACPI table.\r
214**/\r
215VOID\r
216EFIAPI\r
217ParseAcpiDbg2 (\r
218 IN BOOLEAN Trace,\r
219 IN UINT8* Ptr,\r
220 IN UINT32 AcpiTableLength,\r
221 IN UINT8 AcpiTableRevision\r
222 )\r
223{\r
224 UINT32 Offset;\r
225 UINT32 DbgDeviceInfoLength;\r
226 UINT8* DevInfoPtr;\r
227\r
228 if (!Trace) {\r
229 return;\r
230 }\r
231\r
232 Offset = ParseAcpi (\r
233 TRUE,\r
234 0,\r
235 "DBG2",\r
236 Ptr,\r
237 AcpiTableLength,\r
238 PARSER_PARAMS (Dbg2Parser)\r
239 );\r
240 DevInfoPtr = Ptr + Offset;\r
241\r
242 while (Offset < AcpiTableLength) {\r
243 DumpDbgDeviceInfo (\r
244 DevInfoPtr,\r
245 &DbgDeviceInfoLength\r
246 );\r
247 Offset += DbgDeviceInfoLength;\r
248 DevInfoPtr += DbgDeviceInfoLength;\r
249 }\r
250}\r