]> git.proxmox.com Git - mirror_edk2.git/blame - DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c
DynamicTablesPkg: DGB2: Update DBG2_DEBUG_PORT_DDI
[mirror_edk2.git] / DynamicTablesPkg / Library / Acpi / Arm / AcpiDbg2LibArm / Dbg2Generator.c
CommitLineData
fdd61615
SM
1/** @file\r
2 DBG2 Table Generator\r
3\r
4 Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 @par Reference(s):\r
14 - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.\r
15\r
16**/\r
17\r
18#include <IndustryStandard/DebugPort2Table.h>\r
19#include <Library/AcpiLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/PL011UartLib.h>\r
22#include <Protocol/AcpiTable.h>\r
23#include <Protocol/SerialIo.h>\r
24\r
25// Module specific include files.\r
26#include <AcpiTableGenerator.h>\r
27#include <ConfigurationManagerObject.h>\r
28#include <ConfigurationManagerHelper.h>\r
29#include <Library/TableHelperLib.h>\r
30#include <Protocol/ConfigurationManagerProtocol.h>\r
31\r
32/** ARM standard DBG2 Table Generator\r
33\r
34 Constructs the DBG2 table for PL011 or SBSA UART peripherals.\r
35\r
36Requirements:\r
37 The following Configuration Manager Object(s) are required by\r
38 this Generator:\r
39 - EArmObjSerialDebugPortInfo\r
40*/\r
41\r
42#pragma pack(1)\r
43\r
44/** The number of debug ports represented by the Table.\r
45*/\r
46#define DBG2_NUM_DEBUG_PORTS 1\r
47\r
48/** The number of Generic Address Registers\r
49 presented in the debug device information.\r
50*/\r
51#define DBG2_NUMBER_OF_GENERIC_ADDRESS_REGISTERS 1\r
52\r
53/** The index for the debug port 1 in the Debug port information list.\r
54*/\r
55#define DBG_PORT_INDEX_PORT1 0\r
56\r
57/** A string representing the name of the debug port 1.\r
58*/\r
59#define NAME_STR_PORT1 "COM1"\r
60\r
61/** The length of the namespace string.\r
62*/\r
63#define DBG2_NAMESPACESTRING_FIELD_SIZE sizeof (NAME_STR_PORT1)\r
64\r
65/** The PL011 UART address range length.\r
66*/\r
67#define PL011_UART_LENGTH 0x1000\r
68\r
69/** A structure that provides the OS with the required information\r
70 for initializing a debugger connection.\r
71*/\r
72typedef struct {\r
73 /// The debug device information for the platform\r
74 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT Dbg2Device;\r
75\r
76 /// The base address register for the serial port\r
77 EFI_ACPI_6_2_GENERIC_ADDRESS_STRUCTURE BaseAddressRegister;\r
78\r
79 /// The address size\r
80 UINT32 AddressSize;\r
81\r
82 /// The debug port name string\r
83 UINT8 NameSpaceString[DBG2_NAMESPACESTRING_FIELD_SIZE];\r
84} DBG2_DEBUG_DEVICE_INFORMATION;\r
85\r
86/** A structure representing the information about the debug port(s)\r
87 available on the platform.\r
88*/\r
89typedef struct {\r
90 /// The DBG2 table header\r
91 EFI_ACPI_DEBUG_PORT_2_DESCRIPTION_TABLE Description;\r
92\r
93 /// Debug port information list\r
94 DBG2_DEBUG_DEVICE_INFORMATION Dbg2DeviceInfo[DBG2_NUM_DEBUG_PORTS];\r
95} DBG2_TABLE;\r
96\r
97/** A helper macro used for initializing the debug port device\r
98 information structure.\r
99\r
fdd61615
SM
100 @param [in] SubType The DBG Port SubType.\r
101 @param [in] UartBase The UART port base address.\r
102 @param [in] UartAddrLen The UART port address range length.\r
103 @param [in] UartNameStr The UART port name string.\r
104**/\r
105#define DBG2_DEBUG_PORT_DDI( \\r
fdd61615
SM
106 SubType, \\r
107 UartBase, \\r
108 UartAddrLen, \\r
109 UartNameStr \\r
110 ) { \\r
111 { \\r
112 /* UINT8 Revision */ \\r
113 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION, \\r
114 /* UINT16 Length */ \\r
115 sizeof (DBG2_DEBUG_DEVICE_INFORMATION), \\r
116 /* UINT8 NumberofGenericAddressRegisters */ \\r
1018bd4c 117 DBG2_NUMBER_OF_GENERIC_ADDRESS_REGISTERS, \\r
fdd61615
SM
118 /* UINT16 NameSpaceStringLength */ \\r
119 DBG2_NAMESPACESTRING_FIELD_SIZE, \\r
120 /* UINT16 NameSpaceStringOffset */ \\r
121 OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, NameSpaceString), \\r
122 /* UINT16 OemDataLength */ \\r
123 0, \\r
124 /* UINT16 OemDataOffset */ \\r
125 0, \\r
126 /* UINT16 Port Type */ \\r
127 EFI_ACPI_DBG2_PORT_TYPE_SERIAL, \\r
128 /* UINT16 Port Subtype */ \\r
129 SubType, \\r
130 /* UINT8 Reserved[2] */ \\r
131 {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE}, \\r
132 /* UINT16 BaseAddressRegister Offset */ \\r
133 OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, BaseAddressRegister), \\r
134 /* UINT16 AddressSize Offset */ \\r
135 OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, AddressSize) \\r
136 }, \\r
137 /* EFI_ACPI_6_2_GENERIC_ADDRESS_STRUCTURE BaseAddressRegister */ \\r
138 ARM_GAS32 (UartBase), \\r
139 /* UINT32 AddressSize */ \\r
140 UartAddrLen, \\r
141 /* UINT8 NameSpaceString[MAX_DBG2_NAME_LEN] */ \\r
142 UartNameStr \\r
143 }\r
144\r
145/** The DBG2 Table template definition.\r
146\r
147 Note: fields marked with "{Template}" will be set dynamically\r
148*/\r
149STATIC\r
150DBG2_TABLE AcpiDbg2 = {\r
151 {\r
152 ACPI_HEADER (\r
153 EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE,\r
154 DBG2_TABLE,\r
155 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION\r
156 ),\r
157 OFFSET_OF (DBG2_TABLE, Dbg2DeviceInfo),\r
158 DBG2_NUM_DEBUG_PORTS\r
159 },\r
160 {\r
161 /*\r
162 * Debug port 1\r
163 */\r
164 DBG2_DEBUG_PORT_DDI (\r
fdd61615
SM
165 0, // {Template}: Serial Port Subtype\r
166 0, // {Template}: Serial Port Base Address\r
167 PL011_UART_LENGTH,\r
168 NAME_STR_PORT1\r
169 )\r
170 }\r
171};\r
172\r
173#pragma pack()\r
174\r
175/** This macro expands to a function that retrieves the Serial\r
176 debug port information from the Configuration Manager\r
177*/\r
178GET_OBJECT_LIST (\r
179 EObjNameSpaceArm,\r
180 EArmObjSerialDebugPortInfo,\r
181 CM_ARM_SERIAL_PORT_INFO\r
182 );\r
183\r
184/** Initialize the PL011 UART with the parameters obtained from\r
185 the Configuration Manager.\r
186\r
187 @param [in] SerialPortInfo Pointer to the Serial Port Information.\r
188\r
189 @retval EFI_SUCCESS Success.\r
190 @retval EFI_INVALID_PARAMETER The parameters for serial port initialization\r
191 are invalid.\r
192**/\r
193STATIC\r
194EFI_STATUS\r
195SetupDebugUart (\r
196 IN CONST CM_ARM_SERIAL_PORT_INFO * CONST SerialPortInfo\r
197 )\r
198{\r
199 EFI_STATUS Status;\r
200 UINT64 BaudRate;\r
201 UINT32 ReceiveFifoDepth;\r
202 EFI_PARITY_TYPE Parity;\r
203 UINT8 DataBits;\r
204 EFI_STOP_BITS_TYPE StopBits;\r
205\r
206 ASSERT (SerialPortInfo != NULL);\r
207\r
208 // Initialize the Serial Debug UART\r
209 DEBUG ((DEBUG_INFO, "Initializing Serial Debug UART...\n"));\r
210 ReceiveFifoDepth = 0; // Use the default value for FIFO depth\r
211 Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);\r
212 DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);\r
213 StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);\r
214\r
215 BaudRate = SerialPortInfo->BaudRate;\r
216 Status = PL011UartInitializePort (\r
217 (UINTN)SerialPortInfo->BaseAddress,\r
218 SerialPortInfo->Clock,\r
219 &BaudRate,\r
220 &ReceiveFifoDepth,\r
221 &Parity,\r
222 &DataBits,\r
223 &StopBits\r
224 );\r
225\r
226 DEBUG ((DEBUG_INFO, "Debug UART Configuration:\n"));\r
227 DEBUG ((DEBUG_INFO, "UART Base = 0x%lx\n", SerialPortInfo->BaseAddress));\r
228 DEBUG ((DEBUG_INFO, "Clock = %d\n", SerialPortInfo->Clock));\r
229 DEBUG ((DEBUG_INFO, "Baudrate = %ld\n", BaudRate));\r
230 DEBUG ((DEBUG_INFO, "Configuring Debug UART. Status = %r\n", Status));\r
231\r
232 ASSERT_EFI_ERROR (Status);\r
233 return Status;\r
234}\r
235\r
236/** Construct the DBG2 ACPI table\r
237\r
238 The BuildDbg2Table function is called by the Dynamic Table Manager\r
239 to construct the DBG2 ACPI table.\r
240\r
241 This function invokes the Configuration Manager protocol interface\r
242 to get the required hardware information for generating the ACPI\r
243 table.\r
244\r
245 If this function allocates any resources then they must be freed\r
246 in the FreeXXXXTableResources function.\r
247\r
248 @param [in] This Pointer to the table generator.\r
249 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.\r
250 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
251 Protocol Interface.\r
252 @param [out] Table Pointer to the constructed ACPI Table.\r
253\r
254 @retval EFI_SUCCESS Table generated successfully.\r
255 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
256 @retval EFI_NOT_FOUND The required object was not found.\r
257 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration\r
258 Manager is less than the Object size for the\r
259 requested object.\r
260**/\r
261STATIC\r
262EFI_STATUS\r
263EFIAPI\r
264BuildDbg2Table (\r
265 IN CONST ACPI_TABLE_GENERATOR * CONST This,\r
266 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,\r
267 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,\r
268 OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table\r
269 )\r
270{\r
271 EFI_STATUS Status;\r
272 CM_ARM_SERIAL_PORT_INFO * SerialPortInfo;\r
273\r
274 ASSERT (This != NULL);\r
275 ASSERT (AcpiTableInfo != NULL);\r
276 ASSERT (CfgMgrProtocol != NULL);\r
277 ASSERT (Table != NULL);\r
278 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r
279 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);\r
280\r
281 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||\r
282 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) {\r
283 DEBUG ((\r
284 DEBUG_ERROR,\r
285 "ERROR: DBG2: Requested table revision = %d, is not supported."\r
286 "Supported table revision: Minimum = %d, Maximum = %d\n",\r
287 AcpiTableInfo->AcpiTableRevision,\r
288 This->MinAcpiTableRevision,\r
289 This->AcpiTableRevision\r
290 ));\r
291 return EFI_INVALID_PARAMETER;\r
292 }\r
293\r
294 *Table = NULL;\r
295\r
296 Status = GetEArmObjSerialDebugPortInfo (\r
297 CfgMgrProtocol,\r
298 CM_NULL_TOKEN,\r
299 &SerialPortInfo,\r
300 NULL\r
301 );\r
302 if (EFI_ERROR (Status)) {\r
303 DEBUG ((\r
304 DEBUG_ERROR,\r
305 "ERROR: DBG2: Failed to get serial port information. Status = %r\n",\r
306 Status\r
307 ));\r
308 goto error_handler;\r
309 }\r
310\r
311 if (SerialPortInfo->BaseAddress == 0) {\r
312 Status = EFI_INVALID_PARAMETER;\r
313 DEBUG ((\r
314 DEBUG_ERROR,\r
315 "ERROR: DBG2: Uart port base address is invalid. BaseAddress = 0x%lx\n",\r
316 SerialPortInfo->BaseAddress\r
317 ));\r
318 goto error_handler;\r
319 }\r
320\r
321 if ((SerialPortInfo->PortSubtype !=\r
322 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_PL011_UART) &&\r
323 (SerialPortInfo->PortSubtype !=\r
324 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART_2X) &&\r
325 (SerialPortInfo->PortSubtype !=\r
326 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART) &&\r
327 (SerialPortInfo->PortSubtype !=\r
328 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_DCC)) {\r
329 Status = EFI_INVALID_PARAMETER;\r
330 DEBUG ((\r
331 DEBUG_ERROR,\r
332 "ERROR: DBG2: Uart port sybtype is invalid. PortSubtype = 0x%x\n",\r
333 SerialPortInfo->PortSubtype\r
334 ));\r
335 goto error_handler;\r
336 }\r
337\r
338 Status = AddAcpiHeader (\r
339 CfgMgrProtocol,\r
340 This,\r
341 (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2,\r
e12bdeb1 342 AcpiTableInfo,\r
fdd61615
SM
343 sizeof (DBG2_TABLE)\r
344 );\r
345 if (EFI_ERROR (Status)) {\r
346 DEBUG ((\r
347 DEBUG_ERROR,\r
348 "ERROR: DBG2: Failed to add ACPI header. Status = %r\n",\r
349 Status\r
350 ));\r
351 goto error_handler;\r
352 }\r
353\r
354 // Update the base address\r
355 AcpiDbg2.Dbg2DeviceInfo[DBG_PORT_INDEX_PORT1].BaseAddressRegister.Address =\r
356 SerialPortInfo->BaseAddress;\r
357\r
358 // Update the serial port subtype\r
359 AcpiDbg2.Dbg2DeviceInfo[DBG_PORT_INDEX_PORT1].Dbg2Device.PortSubtype =\r
360 SerialPortInfo->PortSubtype;\r
361\r
362 // Initialize the serial port\r
363 Status = SetupDebugUart (SerialPortInfo);\r
364 if (EFI_ERROR (Status)) {\r
365 DEBUG ((\r
366 DEBUG_ERROR,\r
367 "ERROR: DBG2: Failed to configure debug serial port. Status = %r\n",\r
368 Status\r
369 ));\r
370 goto error_handler;\r
371 }\r
372\r
373 *Table = (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2;\r
374\r
375error_handler:\r
376 return Status;\r
377}\r
378\r
379/** This macro defines the DBG2 Table Generator revision.\r
380*/\r
381#define DBG2_GENERATOR_REVISION CREATE_REVISION (1, 0)\r
382\r
383/** The interface for the DBG2 Table Generator.\r
384*/\r
385STATIC\r
386CONST\r
387ACPI_TABLE_GENERATOR Dbg2Generator = {\r
388 // Generator ID\r
389 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdDbg2),\r
390 // Generator Description\r
391 L"ACPI.STD.DBG2.GENERATOR",\r
392 // ACPI Table Signature\r
393 EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE,\r
394 // ACPI Table Revision supported by this Generator\r
395 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION,\r
396 // Minimum supported ACPI Table Revision\r
397 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION,\r
398 // Creator ID\r
399 TABLE_GENERATOR_CREATOR_ID_ARM,\r
400 // Creator Revision\r
401 DBG2_GENERATOR_REVISION,\r
402 // Build Table function\r
403 BuildDbg2Table,\r
404 // No additional resources are allocated by the generator.\r
405 // Hence the Free Resource function is not required.\r
406 NULL,\r
407 // Extended build function not needed\r
408 NULL,\r
409 // Extended build function not implemented by the generator.\r
410 // Hence extended free resource function is not required.\r
411 NULL\r
412};\r
413\r
414/** Register the Generator with the ACPI Table Factory.\r
415\r
416 @param [in] ImageHandle The handle to the image.\r
417 @param [in] SystemTable Pointer to the System Table.\r
418\r
419 @retval EFI_SUCCESS The Generator is registered.\r
420 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
421 @retval EFI_ALREADY_STARTED The Generator for the Table ID\r
422 is already registered.\r
423**/\r
424EFI_STATUS\r
425EFIAPI\r
426AcpiDbg2LibConstructor (\r
427 IN CONST EFI_HANDLE ImageHandle,\r
428 IN EFI_SYSTEM_TABLE * CONST SystemTable\r
429 )\r
430{\r
431 EFI_STATUS Status;\r
432 Status = RegisterAcpiTableGenerator (&Dbg2Generator);\r
433 DEBUG ((DEBUG_INFO, "DBG2: Register Generator. Status = %r\n", Status));\r
434 ASSERT_EFI_ERROR (Status);\r
435\r
436 return Status;\r
437}\r
438\r
439/** Deregister the Generator from the ACPI Table Factory.\r
440\r
441 @param [in] ImageHandle The handle to the image.\r
442 @param [in] SystemTable Pointer to the System Table.\r
443\r
444 @retval EFI_SUCCESS The Generator is deregistered.\r
445 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
446 @retval EFI_NOT_FOUND The Generator is not registered.\r
447**/\r
448EFI_STATUS\r
449EFIAPI\r
450AcpiDbg2LibDestructor (\r
451 IN CONST EFI_HANDLE ImageHandle,\r
452 IN EFI_SYSTEM_TABLE * CONST SystemTable\r
453 )\r
454{\r
455 EFI_STATUS Status;\r
456 Status = DeregisterAcpiTableGenerator (&Dbg2Generator);\r
457 DEBUG ((DEBUG_INFO, "DBG2: Deregister Generator. Status = %r\n", Status));\r
458 ASSERT_EFI_ERROR (Status);\r
459 return Status;\r
460}\r