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