4 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.
11 #include <IndustryStandard/DebugPort2Table.h>
12 #include <Library/UefiLib.h>
13 #include "AcpiParser.h"
14 #include "AcpiTableParser.h"
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
;
30 This function Validates the NameSpace string length.
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.
39 ValidateNameSpaceStrLen (
45 This function parses the debug device information structure.
47 @param [in] Ptr Pointer to the start of the buffer.
48 @param [out] Length Pointer in which the length of the debug
49 device information is returned.
59 /// An ACPI_PARSER array describing the ACPI DBG2 table.
60 STATIC CONST ACPI_PARSER Dbg2Parser
[] = {
61 PARSE_ACPI_HEADER (&AcpiHdrInfo
),
62 {L
"OffsetDbgDeviceInfo", 4, 36, L
"0x%x", NULL
,
63 (VOID
**)&OffsetDbgDeviceInfo
, NULL
, NULL
},
64 {L
"NumberDbgDeviceInfo", 4, 40, L
"%d", NULL
,
65 (VOID
**)&NumberDbgDeviceInfo
, NULL
, NULL
}
68 /// An ACPI_PARSER array describing the debug device information.
69 STATIC CONST ACPI_PARSER DbgDevInfoParser
[] = {
70 {L
"Revision", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
71 {L
"Length", 2, 1, L
"%d", NULL
, (VOID
**)&DbgDevInfoLen
, NULL
, NULL
},
73 {L
"Generic Address Registers Count", 1, 3, L
"0x%x", NULL
,
74 (VOID
**)&GasCount
, NULL
, NULL
},
75 {L
"NameSpace String Length", 2, 4, L
"%d", NULL
,
76 (VOID
**)&NameSpaceStringLength
, ValidateNameSpaceStrLen
, NULL
},
77 {L
"NameSpace String Offset", 2, 6, L
"0x%x", NULL
,
78 (VOID
**)&NameSpaceStringOffset
, NULL
, NULL
},
79 {L
"OEM Data Length", 2, 8, L
"%d", NULL
, (VOID
**)&OEMDataLength
,
81 {L
"OEM Data Offset", 2, 10, L
"0x%x", NULL
, (VOID
**)&OEMDataOffset
,
84 {L
"Port Type", 2, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
85 {L
"Port SubType", 2, 14, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
86 {L
"Reserved", 2, 16, L
"%x", NULL
, NULL
, NULL
, NULL
},
88 {L
"Base Address Register Offset", 2, 18, L
"0x%x", NULL
,
89 (VOID
**)&BaseAddrRegOffset
, NULL
, NULL
},
90 {L
"Address Size Offset", 2, 20, L
"0x%x", NULL
,
91 (VOID
**)&AddrSizeOffset
, NULL
, NULL
}
95 This function validates the NameSpace string length.
97 @param [in] Ptr Pointer to the start of the buffer.
98 @param [in] Context Pointer to context specific information e.g. this
99 could be a pointer to the ACPI table header.
104 ValidateNameSpaceStrLen (
109 UINT16 NameSpaceStrLen
;
111 NameSpaceStrLen
= *(UINT16
*)Ptr
;
113 if (NameSpaceStrLen
< 2) {
114 IncrementErrorCount ();
116 L
"\nERROR: NamespaceString Length = %d. If no Namespace device exists,\n"
117 L
" then NamespaceString[] must contain a period '.'",
124 This function parses the debug device information structure.
126 @param [in] Ptr Pointer to the start of the buffer.
127 @param [out] Length Pointer in which the length of the debug
128 device information is returned.
142 // Parse the debug device info to get the Length
148 3, // Length is 2 bytes starting at offset 1
149 PARSER_PARAMS (DbgDevInfoParser
)
158 PARSER_PARAMS (DbgDevInfoParser
)
161 // GAS and Address Size
163 DataPtr
= Ptr
+ (*BaseAddrRegOffset
);
164 AddrSize
= (UINT32
*)(Ptr
+ (*AddrSizeOffset
));
165 while (Index
< (*GasCount
)) {
166 PrintFieldName (4, L
"BaseAddressRegister");
167 DumpGasStruct (DataPtr
, 4);
168 PrintFieldName (4, L
"Address Size");
169 Print (L
"0x%x\n", AddrSize
[Index
]);
170 DataPtr
+= GAS_LENGTH
;
176 DataPtr
= Ptr
+ (*NameSpaceStringOffset
);
177 PrintFieldName (4, L
"NameSpace String");
178 while (Index
< (*NameSpaceStringLength
)) {
179 Print (L
"%c", DataPtr
[Index
++]);
185 DataPtr
= Ptr
+ (*OEMDataOffset
);
186 PrintFieldName (4, L
"OEM Data");
187 while (Index
< (*OEMDataLength
)) {
188 Print (L
"%x ", DataPtr
[Index
++]);
189 if ((Index
& 7) == 0) {
190 Print (L
"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH
, L
"");
194 *Length
= *DbgDevInfoLen
;
198 This function parses the ACPI DBG2 table.
199 When trace is enabled this function parses the DBG2 table and
200 traces the ACPI table fields.
202 This function also performs validation of the ACPI table fields.
204 @param [in] Trace If TRUE, trace the ACPI fields.
205 @param [in] Ptr Pointer to the start of the buffer.
206 @param [in] AcpiTableLength Length of the ACPI table.
207 @param [in] AcpiTableRevision Revision of the ACPI table.
214 IN UINT32 AcpiTableLength
,
215 IN UINT8 AcpiTableRevision
219 UINT32 DbgDeviceInfoLength
;
232 PARSER_PARAMS (Dbg2Parser
)
234 DevInfoPtr
= Ptr
+ Offset
;
236 while (Offset
< AcpiTableLength
) {
241 Offset
+= DbgDeviceInfoLength
;
242 DevInfoPtr
+= DbgDeviceInfoLength
;