]> git.proxmox.com Git - mirror_edk2.git/blame - DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c
DynamicTablesPkg: Fix serial port namespace path in DBG2
[mirror_edk2.git] / DynamicTablesPkg / Library / Acpi / Arm / AcpiDbg2LibArm / Dbg2Generator.c
CommitLineData
fdd61615
SM
1/** @file\r
2 DBG2 Table Generator\r
3\r
c8ea48bd 4 Copyright (c) 2017 - 2022, Arm Limited. All rights reserved.<BR>\r
313d2ec9 5\r
9cd9bdc6 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
fdd61615
SM
7\r
8 @par Reference(s):\r
9 - Microsoft Debug Port Table 2 (DBG2) Specification - December 10, 2015.\r
10\r
11**/\r
12\r
13#include <IndustryStandard/DebugPort2Table.h>\r
14#include <Library/AcpiLib.h>\r
15#include <Library/DebugLib.h>\r
313d2ec9 16#include <Library/MemoryAllocationLib.h>\r
fdd61615
SM
17#include <Library/PL011UartLib.h>\r
18#include <Protocol/AcpiTable.h>\r
19#include <Protocol/SerialIo.h>\r
20\r
21// Module specific include files.\r
22#include <AcpiTableGenerator.h>\r
23#include <ConfigurationManagerObject.h>\r
24#include <ConfigurationManagerHelper.h>\r
313d2ec9 25#include <Library/SsdtSerialPortFixupLib.h>\r
fdd61615
SM
26#include <Library/TableHelperLib.h>\r
27#include <Protocol/ConfigurationManagerProtocol.h>\r
28\r
29/** ARM standard DBG2 Table Generator\r
30\r
31 Constructs the DBG2 table for PL011 or SBSA UART peripherals.\r
32\r
33Requirements:\r
34 The following Configuration Manager Object(s) are required by\r
35 this Generator:\r
36 - EArmObjSerialDebugPortInfo\r
37*/\r
38\r
39#pragma pack(1)\r
40\r
41/** The number of debug ports represented by the Table.\r
42*/\r
731c67e1 43#define DBG2_NUM_DEBUG_PORTS 1\r
fdd61615
SM
44\r
45/** The number of Generic Address Registers\r
46 presented in the debug device information.\r
47*/\r
731c67e1 48#define DBG2_NUMBER_OF_GENERIC_ADDRESS_REGISTERS 1\r
fdd61615 49\r
313d2ec9
PG
50/** The index for the debug port 0 in the Debug port information list.\r
51*/\r
731c67e1 52#define INDEX_DBG_PORT0 0\r
313d2ec9
PG
53\r
54/** A string representing the name of the debug port 0.\r
fdd61615 55*/\r
731c67e1 56#define NAME_STR_DBG_PORT0 "COM0"\r
fdd61615 57\r
c8ea48bd
SM
58/** A string representing the full path name of the debug port 0.\r
59*/\r
60#define NAMESPACE_STR_DBG_PORT0 "\\_SB_.COM0"\r
61\r
313d2ec9 62/** An UID representing the debug port 0.\r
fdd61615 63*/\r
731c67e1 64#define UID_DBG_PORT0 0\r
fdd61615
SM
65\r
66/** The length of the namespace string.\r
67*/\r
c8ea48bd 68#define DBG2_NAMESPACESTRING_FIELD_SIZE sizeof (NAMESPACE_STR_DBG_PORT0)\r
fdd61615
SM
69\r
70/** The PL011 UART address range length.\r
71*/\r
731c67e1 72#define PL011_UART_LENGTH 0x1000\r
fdd61615
SM
73\r
74/** A structure that provides the OS with the required information\r
75 for initializing a debugger connection.\r
76*/\r
77typedef struct {\r
78 /// The debug device information for the platform\r
731c67e1 79 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT Dbg2Device;\r
fdd61615
SM
80\r
81 /// The base address register for the serial port\r
731c67e1 82 EFI_ACPI_6_2_GENERIC_ADDRESS_STRUCTURE BaseAddressRegister;\r
fdd61615
SM
83\r
84 /// The address size\r
731c67e1 85 UINT32 AddressSize;\r
fdd61615
SM
86\r
87 /// The debug port name string\r
731c67e1 88 UINT8 NameSpaceString[DBG2_NAMESPACESTRING_FIELD_SIZE];\r
fdd61615
SM
89} DBG2_DEBUG_DEVICE_INFORMATION;\r
90\r
91/** A structure representing the information about the debug port(s)\r
92 available on the platform.\r
93*/\r
94typedef struct {\r
95 /// The DBG2 table header\r
731c67e1 96 EFI_ACPI_DEBUG_PORT_2_DESCRIPTION_TABLE Description;\r
fdd61615
SM
97\r
98 /// Debug port information list\r
731c67e1 99 DBG2_DEBUG_DEVICE_INFORMATION Dbg2DeviceInfo[DBG2_NUM_DEBUG_PORTS];\r
fdd61615
SM
100} DBG2_TABLE;\r
101\r
102/** A helper macro used for initializing the debug port device\r
103 information structure.\r
104\r
fdd61615
SM
105 @param [in] SubType The DBG Port SubType.\r
106 @param [in] UartBase The UART port base address.\r
107 @param [in] UartAddrLen The UART port address range length.\r
108 @param [in] UartNameStr The UART port name string.\r
109**/\r
110#define DBG2_DEBUG_PORT_DDI( \\r
731c67e1
MK
111 SubType, \\r
112 UartBase, \\r
113 UartAddrLen, \\r
114 UartNameStr \\r
115 ) {\\r
fdd61615 116 { \\r
731c67e1 117 /* UINT8 Revision */ \\r
fdd61615 118 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION, \\r
731c67e1 119 /* UINT16 Length */ \\r
fdd61615 120 sizeof (DBG2_DEBUG_DEVICE_INFORMATION), \\r
731c67e1 121 /* UINT8 NumberofGenericAddressRegisters */ \\r
1018bd4c 122 DBG2_NUMBER_OF_GENERIC_ADDRESS_REGISTERS, \\r
731c67e1 123 /* UINT16 NameSpaceStringLength */ \\r
fdd61615 124 DBG2_NAMESPACESTRING_FIELD_SIZE, \\r
731c67e1 125 /* UINT16 NameSpaceStringOffset */ \\r
fdd61615 126 OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, NameSpaceString), \\r
731c67e1 127 /* UINT16 OemDataLength */ \\r
fdd61615 128 0, \\r
731c67e1 129 /* UINT16 OemDataOffset */ \\r
fdd61615 130 0, \\r
731c67e1 131 /* UINT16 Port Type */ \\r
fdd61615 132 EFI_ACPI_DBG2_PORT_TYPE_SERIAL, \\r
731c67e1 133 /* UINT16 Port Subtype */ \\r
fdd61615 134 SubType, \\r
731c67e1 135 /* UINT8 Reserved[2] */ \\r
fdd61615 136 {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE}, \\r
731c67e1 137 /* UINT16 BaseAddressRegister Offset */ \\r
fdd61615 138 OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, BaseAddressRegister), \\r
731c67e1 139 /* UINT16 AddressSize Offset */ \\r
fdd61615
SM
140 OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, AddressSize) \\r
141 }, \\r
731c67e1 142 /* EFI_ACPI_6_2_GENERIC_ADDRESS_STRUCTURE BaseAddressRegister */ \\r
fdd61615 143 ARM_GAS32 (UartBase), \\r
731c67e1 144 /* UINT32 AddressSize */ \\r
fdd61615 145 UartAddrLen, \\r
731c67e1 146 /* UINT8 NameSpaceString[MAX_DBG2_NAME_LEN] */ \\r
fdd61615
SM
147 UartNameStr \\r
148 }\r
149\r
150/** The DBG2 Table template definition.\r
151\r
152 Note: fields marked with "{Template}" will be set dynamically\r
153*/\r
154STATIC\r
731c67e1 155DBG2_TABLE AcpiDbg2 = {\r
fdd61615
SM
156 {\r
157 ACPI_HEADER (\r
158 EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE,\r
159 DBG2_TABLE,\r
160 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION\r
161 ),\r
162 OFFSET_OF (DBG2_TABLE, Dbg2DeviceInfo),\r
163 DBG2_NUM_DEBUG_PORTS\r
164 },\r
165 {\r
166 /*\r
167 * Debug port 1\r
168 */\r
169 DBG2_DEBUG_PORT_DDI (\r
fdd61615
SM
170 0, // {Template}: Serial Port Subtype\r
171 0, // {Template}: Serial Port Base Address\r
172 PL011_UART_LENGTH,\r
c8ea48bd 173 NAMESPACE_STR_DBG_PORT0\r
fdd61615
SM
174 )\r
175 }\r
176};\r
177\r
178#pragma pack()\r
179\r
180/** This macro expands to a function that retrieves the Serial\r
181 debug port information from the Configuration Manager\r
182*/\r
183GET_OBJECT_LIST (\r
184 EObjNameSpaceArm,\r
185 EArmObjSerialDebugPortInfo,\r
186 CM_ARM_SERIAL_PORT_INFO\r
187 );\r
188\r
7c10e8ab 189/** Initialize the PL011/SBSA UART with the parameters obtained from\r
fdd61615
SM
190 the Configuration Manager.\r
191\r
192 @param [in] SerialPortInfo Pointer to the Serial Port Information.\r
193\r
194 @retval EFI_SUCCESS Success.\r
195 @retval EFI_INVALID_PARAMETER The parameters for serial port initialization\r
196 are invalid.\r
197**/\r
198STATIC\r
199EFI_STATUS\r
200SetupDebugUart (\r
731c67e1 201 IN CONST CM_ARM_SERIAL_PORT_INFO *CONST SerialPortInfo\r
fdd61615
SM
202 )\r
203{\r
204 EFI_STATUS Status;\r
205 UINT64 BaudRate;\r
206 UINT32 ReceiveFifoDepth;\r
207 EFI_PARITY_TYPE Parity;\r
208 UINT8 DataBits;\r
209 EFI_STOP_BITS_TYPE StopBits;\r
210\r
211 ASSERT (SerialPortInfo != NULL);\r
212\r
213 // Initialize the Serial Debug UART\r
214 DEBUG ((DEBUG_INFO, "Initializing Serial Debug UART...\n"));\r
215 ReceiveFifoDepth = 0; // Use the default value for FIFO depth\r
731c67e1
MK
216 Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);\r
217 DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);\r
218 StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);\r
fdd61615
SM
219\r
220 BaudRate = SerialPortInfo->BaudRate;\r
731c67e1
MK
221 Status = PL011UartInitializePort (\r
222 (UINTN)SerialPortInfo->BaseAddress,\r
223 SerialPortInfo->Clock,\r
224 &BaudRate,\r
225 &ReceiveFifoDepth,\r
226 &Parity,\r
227 &DataBits,\r
228 &StopBits\r
229 );\r
fdd61615 230\r
fdd61615
SM
231 ASSERT_EFI_ERROR (Status);\r
232 return Status;\r
233}\r
234\r
313d2ec9
PG
235/** Free any resources allocated for constructing the tables.\r
236\r
237 @param [in] This Pointer to the ACPI table generator.\r
238 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.\r
239 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
240 Protocol Interface.\r
241 @param [in, out] Table Pointer to an array of pointers\r
242 to ACPI Table(s).\r
243 @param [in] TableCount Number of ACPI table(s).\r
244\r
245 @retval EFI_SUCCESS The resources were freed successfully.\r
246 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.\r
247**/\r
248STATIC\r
249EFI_STATUS\r
250EFIAPI\r
251FreeDbg2TableEx (\r
731c67e1
MK
252 IN CONST ACPI_TABLE_GENERATOR *CONST This,\r
253 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo,\r
254 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,\r
255 IN OUT EFI_ACPI_DESCRIPTION_HEADER ***CONST Table,\r
313d2ec9
PG
256 IN CONST UINTN TableCount\r
257 )\r
258{\r
731c67e1
MK
259 EFI_STATUS Status;\r
260 EFI_ACPI_DESCRIPTION_HEADER **TableList;\r
313d2ec9
PG
261\r
262 ASSERT (This != NULL);\r
263 ASSERT (AcpiTableInfo != NULL);\r
264 ASSERT (CfgMgrProtocol != NULL);\r
265 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r
266 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);\r
267\r
268 if ((Table == NULL) ||\r
269 (*Table == NULL) ||\r
731c67e1
MK
270 (TableCount != 2))\r
271 {\r
313d2ec9
PG
272 DEBUG ((DEBUG_ERROR, "ERROR: DBG2: Invalid Table Pointer\n"));\r
273 return EFI_INVALID_PARAMETER;\r
274 }\r
275\r
276 TableList = *Table;\r
277\r
278 if ((TableList[1] == NULL) ||\r
279 (TableList[1]->Signature !=\r
731c67e1
MK
280 EFI_ACPI_6_3_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE))\r
281 {\r
313d2ec9
PG
282 DEBUG ((DEBUG_ERROR, "ERROR: DBG2: Invalid SSDT table pointer.\n"));\r
283 return EFI_INVALID_PARAMETER;\r
284 }\r
285\r
286 // Only need to free the SSDT table at index 1. The DBG2 table is static.\r
287 Status = FreeSsdtSerialPortTable (TableList[1]);\r
288 ASSERT_EFI_ERROR (Status);\r
289\r
290 // Free the table list.\r
291 FreePool (*Table);\r
292\r
293 return Status;\r
294}\r
fdd61615 295\r
313d2ec9 296/** Construct the DBG2 ACPI table and its associated SSDT table.\r
fdd61615
SM
297\r
298 This function invokes the Configuration Manager protocol interface\r
299 to get the required hardware information for generating the ACPI\r
300 table.\r
301\r
302 If this function allocates any resources then they must be freed\r
313d2ec9
PG
303 in the FreeXXXXTableResourcesEx function.\r
304\r
305 @param [in] This Pointer to the ACPI table generator.\r
306 @param [in] AcpiTableInfo Pointer to the ACPI table information.\r
307 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
308 Protocol interface.\r
309 @param [out] Table Pointer to a list of generated ACPI table(s).\r
310 @param [out] TableCount Number of generated ACPI table(s).\r
311\r
312 @retval EFI_SUCCESS Table generated successfully.\r
313 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration\r
314 Manager is less than the Object size for\r
315 the requested object.\r
316 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
317 @retval EFI_NOT_FOUND Could not find information.\r
318 @retval EFI_OUT_OF_RESOURCES Could not allocate memory.\r
319 @retval EFI_UNSUPPORTED Unsupported configuration.\r
fdd61615
SM
320**/\r
321STATIC\r
322EFI_STATUS\r
323EFIAPI\r
313d2ec9 324BuildDbg2TableEx (\r
731c67e1
MK
325 IN CONST ACPI_TABLE_GENERATOR *This,\r
326 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo,\r
327 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol,\r
328 OUT EFI_ACPI_DESCRIPTION_HEADER ***Table,\r
329 OUT UINTN *CONST TableCount\r
fdd61615
SM
330 )\r
331{\r
731c67e1
MK
332 EFI_STATUS Status;\r
333 CM_ARM_SERIAL_PORT_INFO *SerialPortInfo;\r
334 UINT32 SerialPortCount;\r
335 EFI_ACPI_DESCRIPTION_HEADER **TableList;\r
fdd61615
SM
336\r
337 ASSERT (This != NULL);\r
338 ASSERT (AcpiTableInfo != NULL);\r
339 ASSERT (CfgMgrProtocol != NULL);\r
340 ASSERT (Table != NULL);\r
313d2ec9 341 ASSERT (TableCount != NULL);\r
fdd61615
SM
342 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r
343 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);\r
344\r
345 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||\r
731c67e1
MK
346 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision))\r
347 {\r
fdd61615
SM
348 DEBUG ((\r
349 DEBUG_ERROR,\r
350 "ERROR: DBG2: Requested table revision = %d, is not supported."\r
351 "Supported table revision: Minimum = %d, Maximum = %d\n",\r
352 AcpiTableInfo->AcpiTableRevision,\r
353 This->MinAcpiTableRevision,\r
354 This->AcpiTableRevision\r
355 ));\r
356 return EFI_INVALID_PARAMETER;\r
357 }\r
358\r
359 *Table = NULL;\r
360\r
361 Status = GetEArmObjSerialDebugPortInfo (\r
362 CfgMgrProtocol,\r
363 CM_NULL_TOKEN,\r
364 &SerialPortInfo,\r
313d2ec9 365 &SerialPortCount\r
fdd61615
SM
366 );\r
367 if (EFI_ERROR (Status)) {\r
368 DEBUG ((\r
369 DEBUG_ERROR,\r
370 "ERROR: DBG2: Failed to get serial port information. Status = %r\n",\r
371 Status\r
372 ));\r
313d2ec9 373 return Status;\r
fdd61615
SM
374 }\r
375\r
313d2ec9 376 if (SerialPortCount == 0) {\r
fdd61615
SM
377 DEBUG ((\r
378 DEBUG_ERROR,\r
313d2ec9
PG
379 "ERROR: DBG2: Serial port information not found. Status = %r\n",\r
380 EFI_NOT_FOUND\r
fdd61615 381 ));\r
313d2ec9 382 return EFI_NOT_FOUND;\r
fdd61615
SM
383 }\r
384\r
313d2ec9
PG
385 // Only use the first DBG2 port information.\r
386 Status = ValidateSerialPortInfo (SerialPortInfo, 1);\r
387 if (EFI_ERROR (Status)) {\r
fdd61615
SM
388 DEBUG ((\r
389 DEBUG_ERROR,\r
313d2ec9
PG
390 "ERROR: DBG2: Invalid serial port information. Status = %r\n",\r
391 Status\r
fdd61615 392 ));\r
313d2ec9
PG
393 return Status;\r
394 }\r
395\r
396 // Allocate a table to store pointers to the DBG2 and SSDT tables.\r
731c67e1
MK
397 TableList = (EFI_ACPI_DESCRIPTION_HEADER **)\r
398 AllocateZeroPool (sizeof (EFI_ACPI_DESCRIPTION_HEADER *) * 2);\r
313d2ec9
PG
399 if (TableList == NULL) {\r
400 Status = EFI_OUT_OF_RESOURCES;\r
401 DEBUG ((\r
402 DEBUG_ERROR,\r
403 "ERROR: DBG2: Failed to allocate memory for Table List," \\r
404 " Status = %r\n",\r
405 Status\r
406 ));\r
407 return Status;\r
fdd61615
SM
408 }\r
409\r
410 Status = AddAcpiHeader (\r
411 CfgMgrProtocol,\r
412 This,\r
731c67e1 413 (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiDbg2,\r
e12bdeb1 414 AcpiTableInfo,\r
fdd61615
SM
415 sizeof (DBG2_TABLE)\r
416 );\r
417 if (EFI_ERROR (Status)) {\r
418 DEBUG ((\r
419 DEBUG_ERROR,\r
420 "ERROR: DBG2: Failed to add ACPI header. Status = %r\n",\r
421 Status\r
422 ));\r
423 goto error_handler;\r
424 }\r
425\r
426 // Update the base address\r
313d2ec9 427 AcpiDbg2.Dbg2DeviceInfo[INDEX_DBG_PORT0].BaseAddressRegister.Address =\r
fdd61615
SM
428 SerialPortInfo->BaseAddress;\r
429\r
8c75a072
JG
430 // Set the access size\r
431 if (SerialPortInfo->AccessSize >= EFI_ACPI_6_3_QWORD) {\r
432 Status = EFI_INVALID_PARAMETER;\r
433 DEBUG ((\r
434 DEBUG_ERROR,\r
435 "ERROR: DBG2: Access size must be <= 3 (DWORD). Status = %r\n",\r
436 Status\r
437 ));\r
438 goto error_handler;\r
439 } else if (SerialPortInfo->AccessSize == EFI_ACPI_6_3_UNDEFINED) {\r
440 // 0 Undefined (legacy reasons)\r
441 // Default to DWORD access size as the access\r
442 // size field was introduced at a later date\r
443 // and some ConfigurationManager implementations\r
444 // may not be providing this field data\r
445 AcpiDbg2.Dbg2DeviceInfo[INDEX_DBG_PORT0].BaseAddressRegister.AccessSize =\r
446 EFI_ACPI_6_3_DWORD;\r
447 } else {\r
448 AcpiDbg2.Dbg2DeviceInfo[INDEX_DBG_PORT0].BaseAddressRegister.AccessSize =\r
449 SerialPortInfo->AccessSize;\r
450 }\r
451\r
fdd61615 452 // Update the serial port subtype\r
313d2ec9 453 AcpiDbg2.Dbg2DeviceInfo[INDEX_DBG_PORT0].Dbg2Device.PortSubtype =\r
fdd61615
SM
454 SerialPortInfo->PortSubtype;\r
455\r
7c10e8ab 456 if ((SerialPortInfo->PortSubtype ==\r
731c67e1 457 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_PL011_UART) ||\r
7c10e8ab 458 (SerialPortInfo->PortSubtype ==\r
731c67e1 459 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART_2X) ||\r
7c10e8ab 460 (SerialPortInfo->PortSubtype ==\r
731c67e1
MK
461 EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART))\r
462 {\r
7c10e8ab
SM
463 // Initialize the serial port\r
464 Status = SetupDebugUart (SerialPortInfo);\r
465 if (EFI_ERROR (Status)) {\r
466 DEBUG ((\r
467 DEBUG_ERROR,\r
468 "ERROR: DBG2: Failed to configure debug serial port. Status = %r\n",\r
469 Status\r
470 ));\r
471 goto error_handler;\r
472 }\r
fdd61615
SM
473 }\r
474\r
731c67e1 475 TableList[0] = (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiDbg2;\r
313d2ec9
PG
476\r
477 // Build a SSDT table describing the serial port.\r
478 Status = BuildSsdtSerialPortTable (\r
479 AcpiTableInfo,\r
480 SerialPortInfo,\r
481 NAME_STR_DBG_PORT0,\r
482 UID_DBG_PORT0,\r
483 &TableList[1]\r
484 );\r
485 if (EFI_ERROR (Status)) {\r
486 DEBUG ((\r
487 DEBUG_ERROR,\r
488 "ERROR: DBG2: Failed to build associated SSDT table. Status = %r\n",\r
489 Status\r
490 ));\r
491 goto error_handler;\r
492 }\r
493\r
494 *TableCount = 2;\r
731c67e1 495 *Table = TableList;\r
313d2ec9
PG
496\r
497 return Status;\r
fdd61615
SM
498\r
499error_handler:\r
313d2ec9
PG
500 if (TableList != NULL) {\r
501 FreePool (TableList);\r
502 }\r
503\r
fdd61615
SM
504 return Status;\r
505}\r
506\r
507/** This macro defines the DBG2 Table Generator revision.\r
508*/\r
731c67e1 509#define DBG2_GENERATOR_REVISION CREATE_REVISION (1, 0)\r
fdd61615
SM
510\r
511/** The interface for the DBG2 Table Generator.\r
512*/\r
513STATIC\r
514CONST\r
731c67e1 515ACPI_TABLE_GENERATOR Dbg2Generator = {\r
fdd61615
SM
516 // Generator ID\r
517 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdDbg2),\r
518 // Generator Description\r
519 L"ACPI.STD.DBG2.GENERATOR",\r
520 // ACPI Table Signature\r
313d2ec9 521 EFI_ACPI_6_3_DEBUG_PORT_2_TABLE_SIGNATURE,\r
fdd61615
SM
522 // ACPI Table Revision supported by this Generator\r
523 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION,\r
524 // Minimum supported ACPI Table Revision\r
525 EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION,\r
526 // Creator ID\r
527 TABLE_GENERATOR_CREATOR_ID_ARM,\r
528 // Creator Revision\r
529 DBG2_GENERATOR_REVISION,\r
313d2ec9 530 // Build table function. Use the extended version instead.\r
fdd61615 531 NULL,\r
313d2ec9 532 // Free table function. Use the extended version instead.\r
fdd61615 533 NULL,\r
313d2ec9
PG
534 // Extended Build table function.\r
535 BuildDbg2TableEx,\r
536 // Extended free function.\r
537 FreeDbg2TableEx\r
fdd61615
SM
538};\r
539\r
540/** Register the Generator with the ACPI Table Factory.\r
541\r
542 @param [in] ImageHandle The handle to the image.\r
543 @param [in] SystemTable Pointer to the System Table.\r
544\r
545 @retval EFI_SUCCESS The Generator is registered.\r
546 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
547 @retval EFI_ALREADY_STARTED The Generator for the Table ID\r
548 is already registered.\r
549**/\r
550EFI_STATUS\r
551EFIAPI\r
552AcpiDbg2LibConstructor (\r
731c67e1
MK
553 IN EFI_HANDLE ImageHandle,\r
554 IN EFI_SYSTEM_TABLE *SystemTable\r
fdd61615
SM
555 )\r
556{\r
557 EFI_STATUS Status;\r
731c67e1 558\r
fdd61615
SM
559 Status = RegisterAcpiTableGenerator (&Dbg2Generator);\r
560 DEBUG ((DEBUG_INFO, "DBG2: Register Generator. Status = %r\n", Status));\r
561 ASSERT_EFI_ERROR (Status);\r
fdd61615
SM
562 return Status;\r
563}\r
564\r
565/** Deregister the Generator from the ACPI Table Factory.\r
566\r
567 @param [in] ImageHandle The handle to the image.\r
568 @param [in] SystemTable Pointer to the System Table.\r
569\r
570 @retval EFI_SUCCESS The Generator is deregistered.\r
571 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
572 @retval EFI_NOT_FOUND The Generator is not registered.\r
573**/\r
574EFI_STATUS\r
575EFIAPI\r
576AcpiDbg2LibDestructor (\r
731c67e1
MK
577 IN EFI_HANDLE ImageHandle,\r
578 IN EFI_SYSTEM_TABLE *SystemTable\r
fdd61615
SM
579 )\r
580{\r
581 EFI_STATUS Status;\r
731c67e1 582\r
fdd61615
SM
583 Status = DeregisterAcpiTableGenerator (&Dbg2Generator);\r
584 DEBUG ((DEBUG_INFO, "DBG2: Deregister Generator. Status = %r\n", Status));\r
585 ASSERT_EFI_ERROR (Status);\r
586 return Status;\r
587}\r