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
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.
14 - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.
17 #include <IndustryStandard/DebugPort2Table.h>
18 #include <Library/UefiLib.h>
19 #include "AcpiParser.h"
20 #include "AcpiTableParser.h"
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
;
36 This function Validates the NameSpace string length.
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.
45 ValidateNameSpaceStrLen (
51 This function parses the debug device information structure.
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.
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
}
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
},
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
,
87 {L
"OEM Data Offset", 2, 10, L
"0x%x", NULL
, (VOID
**)&OEMDataOffset
,
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
},
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
}
101 This function validates the NameSpace string length.
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.
110 ValidateNameSpaceStrLen (
115 UINT16 NameSpaceStrLen
;
117 NameSpaceStrLen
= *(UINT16
*)Ptr
;
119 if (NameSpaceStrLen
< 2) {
120 IncrementErrorCount ();
122 L
"\nERROR: NamespaceString Length = %d. If no Namespace device exists,\n"
123 L
" then NamespaceString[] must contain a period '.'",
130 This function parses the debug device information structure.
132 @param [in] Ptr Pointer to the start of the buffer.
133 @param [out] Length Pointer in which the length of the debug
134 device information is returned.
148 // Parse the debug device info to get the Length
154 3, // Length is 2 bytes starting at offset 1
155 PARSER_PARAMS (DbgDevInfoParser
)
164 PARSER_PARAMS (DbgDevInfoParser
)
167 // GAS and Address Size
169 DataPtr
= Ptr
+ (*BaseAddrRegOffset
);
170 AddrSize
= (UINT32
*)(Ptr
+ (*AddrSizeOffset
));
171 while (Index
< (*GasCount
)) {
172 PrintFieldName (4, L
"BaseAddressRegister");
173 DumpGasStruct (DataPtr
, 4);
174 PrintFieldName (4, L
"Address Size");
175 Print (L
"0x%x\n", AddrSize
[Index
]);
176 DataPtr
+= GAS_LENGTH
;
182 DataPtr
= Ptr
+ (*NameSpaceStringOffset
);
183 PrintFieldName (4, L
"NameSpace String");
184 while (Index
< (*NameSpaceStringLength
)) {
185 Print (L
"%c", DataPtr
[Index
++]);
191 DataPtr
= Ptr
+ (*OEMDataOffset
);
192 PrintFieldName (4, L
"OEM Data");
193 while (Index
< (*OEMDataLength
)) {
194 Print (L
"%x ", DataPtr
[Index
++]);
195 if ((Index
& 7) == 0) {
196 Print (L
"\n%-*s ", OUTPUT_FIELD_COLUMN_WIDTH
, L
"");
200 *Length
= *DbgDevInfoLen
;
204 This function parses the ACPI DBG2 table.
205 When trace is enabled this function parses the DBG2 table and
206 traces the ACPI table fields.
208 This function also performs validation of the ACPI table fields.
210 @param [in] Trace If TRUE, trace the ACPI fields.
211 @param [in] Ptr Pointer to the start of the buffer.
212 @param [in] AcpiTableLength Length of the ACPI table.
213 @param [in] AcpiTableRevision Revision of the ACPI table.
220 IN UINT32 AcpiTableLength
,
221 IN UINT8 AcpiTableRevision
225 UINT32 DbgDeviceInfoLength
;
238 PARSER_PARAMS (Dbg2Parser
)
240 DevInfoPtr
= Ptr
+ Offset
;
242 while (Offset
< AcpiTableLength
) {
247 Offset
+= DbgDeviceInfoLength
;
248 DevInfoPtr
+= DbgDeviceInfoLength
;