4 Copyright (c) 2016 - 2019, 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 (
44 UINT16 NameSpaceStrLen
;
46 NameSpaceStrLen
= *(UINT16
*)Ptr
;
48 if (NameSpaceStrLen
< 2) {
49 IncrementErrorCount ();
51 L
"\nERROR: NamespaceString Length = %d. If no Namespace device exists, " \
52 L
"NamespaceString[] must contain a period '.'",
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
}
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
},
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
,
80 {L
"OEM Data Offset", 2, 10, L
"0x%x", NULL
, (VOID
**)&OEMDataOffset
,
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
},
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
}
94 This function parses the debug device information structure.
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.
112 // Parse the debug device info to get the Length
118 3, // Length is 2 bytes starting at offset 1
119 PARSER_PARAMS (DbgDevInfoParser
)
128 PARSER_PARAMS (DbgDevInfoParser
)
131 // GAS and Address Size
133 DataPtr
= Ptr
+ (*BaseAddrRegOffset
);
134 AddrSize
= (UINT32
*)(Ptr
+ (*AddrSizeOffset
));
135 while (Index
< (*GasCount
)) {
136 PrintFieldName (4, L
"BaseAddressRegister");
137 DumpGasStruct (DataPtr
, 4);
138 PrintFieldName (4, L
"Address Size");
139 Print (L
"0x%x\n", AddrSize
[Index
]);
140 DataPtr
+= GAS_LENGTH
;
146 DataPtr
= Ptr
+ (*NameSpaceStringOffset
);
147 PrintFieldName (4, L
"NameSpace String");
148 while (Index
< (*NameSpaceStringLength
)) {
149 Print (L
"%c", DataPtr
[Index
++]);
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
"");
165 *Length
= *DbgDevInfoLen
;
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.
173 This function also performs validation of the ACPI table fields.
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.
185 IN UINT32 AcpiTableLength
,
186 IN UINT8 AcpiTableRevision
190 UINT32 DbgDeviceInfoLength
;
203 PARSER_PARAMS (Dbg2Parser
)
205 DevInfoPtr
= Ptr
+ Offset
;
207 while (Offset
< AcpiTableLength
) {
212 Offset
+= DbgDeviceInfoLength
;
213 DevInfoPtr
+= DbgDeviceInfoLength
;