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