]>
Commit | Line | Data |
---|---|---|
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 | |
36 | Requirements:\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 | |
72 | typedef 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 | |
89 | typedef 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 | |
100 | @param [in] NumReg The number of generic address registers.\r | |
101 | @param [in] SubType The DBG Port SubType.\r | |
102 | @param [in] UartBase The UART port base address.\r | |
103 | @param [in] UartAddrLen The UART port address range length.\r | |
104 | @param [in] UartNameStr The UART port name string.\r | |
105 | **/\r | |
106 | #define DBG2_DEBUG_PORT_DDI( \\r | |
107 | NumReg, \\r | |
108 | SubType, \\r | |
109 | UartBase, \\r | |
110 | UartAddrLen, \\r | |
111 | UartNameStr \\r | |
112 | ) { \\r | |
113 | { \\r | |
114 | /* UINT8 Revision */ \\r | |
115 | EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION, \\r | |
116 | /* UINT16 Length */ \\r | |
117 | sizeof (DBG2_DEBUG_DEVICE_INFORMATION), \\r | |
118 | /* UINT8 NumberofGenericAddressRegisters */ \\r | |
119 | NumReg, \\r | |
120 | /* UINT16 NameSpaceStringLength */ \\r | |
121 | DBG2_NAMESPACESTRING_FIELD_SIZE, \\r | |
122 | /* UINT16 NameSpaceStringOffset */ \\r | |
123 | OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, NameSpaceString), \\r | |
124 | /* UINT16 OemDataLength */ \\r | |
125 | 0, \\r | |
126 | /* UINT16 OemDataOffset */ \\r | |
127 | 0, \\r | |
128 | /* UINT16 Port Type */ \\r | |
129 | EFI_ACPI_DBG2_PORT_TYPE_SERIAL, \\r | |
130 | /* UINT16 Port Subtype */ \\r | |
131 | SubType, \\r | |
132 | /* UINT8 Reserved[2] */ \\r | |
133 | {EFI_ACPI_RESERVED_BYTE, EFI_ACPI_RESERVED_BYTE}, \\r | |
134 | /* UINT16 BaseAddressRegister Offset */ \\r | |
135 | OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, BaseAddressRegister), \\r | |
136 | /* UINT16 AddressSize Offset */ \\r | |
137 | OFFSET_OF (DBG2_DEBUG_DEVICE_INFORMATION, AddressSize) \\r | |
138 | }, \\r | |
139 | /* EFI_ACPI_6_2_GENERIC_ADDRESS_STRUCTURE BaseAddressRegister */ \\r | |
140 | ARM_GAS32 (UartBase), \\r | |
141 | /* UINT32 AddressSize */ \\r | |
142 | UartAddrLen, \\r | |
143 | /* UINT8 NameSpaceString[MAX_DBG2_NAME_LEN] */ \\r | |
144 | UartNameStr \\r | |
145 | }\r | |
146 | \r | |
147 | /** The DBG2 Table template definition.\r | |
148 | \r | |
149 | Note: fields marked with "{Template}" will be set dynamically\r | |
150 | */\r | |
151 | STATIC\r | |
152 | DBG2_TABLE AcpiDbg2 = {\r | |
153 | {\r | |
154 | ACPI_HEADER (\r | |
155 | EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE,\r | |
156 | DBG2_TABLE,\r | |
157 | EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION\r | |
158 | ),\r | |
159 | OFFSET_OF (DBG2_TABLE, Dbg2DeviceInfo),\r | |
160 | DBG2_NUM_DEBUG_PORTS\r | |
161 | },\r | |
162 | {\r | |
163 | /*\r | |
164 | * Debug port 1\r | |
165 | */\r | |
166 | DBG2_DEBUG_PORT_DDI (\r | |
167 | DBG2_NUMBER_OF_GENERIC_ADDRESS_REGISTERS,\r | |
168 | 0, // {Template}: Serial Port Subtype\r | |
169 | 0, // {Template}: Serial Port Base Address\r | |
170 | PL011_UART_LENGTH,\r | |
171 | NAME_STR_PORT1\r | |
172 | )\r | |
173 | }\r | |
174 | };\r | |
175 | \r | |
176 | #pragma pack()\r | |
177 | \r | |
178 | /** This macro expands to a function that retrieves the Serial\r | |
179 | debug port information from the Configuration Manager\r | |
180 | */\r | |
181 | GET_OBJECT_LIST (\r | |
182 | EObjNameSpaceArm,\r | |
183 | EArmObjSerialDebugPortInfo,\r | |
184 | CM_ARM_SERIAL_PORT_INFO\r | |
185 | );\r | |
186 | \r | |
187 | /** Initialize the PL011 UART with the parameters obtained from\r | |
188 | the Configuration Manager.\r | |
189 | \r | |
190 | @param [in] SerialPortInfo Pointer to the Serial Port Information.\r | |
191 | \r | |
192 | @retval EFI_SUCCESS Success.\r | |
193 | @retval EFI_INVALID_PARAMETER The parameters for serial port initialization\r | |
194 | are invalid.\r | |
195 | **/\r | |
196 | STATIC\r | |
197 | EFI_STATUS\r | |
198 | SetupDebugUart (\r | |
199 | IN CONST CM_ARM_SERIAL_PORT_INFO * CONST SerialPortInfo\r | |
200 | )\r | |
201 | {\r | |
202 | EFI_STATUS Status;\r | |
203 | UINT64 BaudRate;\r | |
204 | UINT32 ReceiveFifoDepth;\r | |
205 | EFI_PARITY_TYPE Parity;\r | |
206 | UINT8 DataBits;\r | |
207 | EFI_STOP_BITS_TYPE StopBits;\r | |
208 | \r | |
209 | ASSERT (SerialPortInfo != NULL);\r | |
210 | \r | |
211 | // Initialize the Serial Debug UART\r | |
212 | DEBUG ((DEBUG_INFO, "Initializing Serial Debug UART...\n"));\r | |
213 | ReceiveFifoDepth = 0; // Use the default value for FIFO depth\r | |
214 | Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);\r | |
215 | DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);\r | |
216 | StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);\r | |
217 | \r | |
218 | BaudRate = SerialPortInfo->BaudRate;\r | |
219 | Status = PL011UartInitializePort (\r | |
220 | (UINTN)SerialPortInfo->BaseAddress,\r | |
221 | SerialPortInfo->Clock,\r | |
222 | &BaudRate,\r | |
223 | &ReceiveFifoDepth,\r | |
224 | &Parity,\r | |
225 | &DataBits,\r | |
226 | &StopBits\r | |
227 | );\r | |
228 | \r | |
229 | DEBUG ((DEBUG_INFO, "Debug UART Configuration:\n"));\r | |
230 | DEBUG ((DEBUG_INFO, "UART Base = 0x%lx\n", SerialPortInfo->BaseAddress));\r | |
231 | DEBUG ((DEBUG_INFO, "Clock = %d\n", SerialPortInfo->Clock));\r | |
232 | DEBUG ((DEBUG_INFO, "Baudrate = %ld\n", BaudRate));\r | |
233 | DEBUG ((DEBUG_INFO, "Configuring Debug UART. Status = %r\n", Status));\r | |
234 | \r | |
235 | ASSERT_EFI_ERROR (Status);\r | |
236 | return Status;\r | |
237 | }\r | |
238 | \r | |
239 | /** Construct the DBG2 ACPI table\r | |
240 | \r | |
241 | The BuildDbg2Table function is called by the Dynamic Table Manager\r | |
242 | to construct the DBG2 ACPI table.\r | |
243 | \r | |
244 | This function invokes the Configuration Manager protocol interface\r | |
245 | to get the required hardware information for generating the ACPI\r | |
246 | table.\r | |
247 | \r | |
248 | If this function allocates any resources then they must be freed\r | |
249 | in the FreeXXXXTableResources function.\r | |
250 | \r | |
251 | @param [in] This Pointer to the table generator.\r | |
252 | @param [in] AcpiTableInfo Pointer to the ACPI Table Info.\r | |
253 | @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r | |
254 | Protocol Interface.\r | |
255 | @param [out] Table Pointer to the constructed ACPI Table.\r | |
256 | \r | |
257 | @retval EFI_SUCCESS Table generated successfully.\r | |
258 | @retval EFI_INVALID_PARAMETER A parameter is invalid.\r | |
259 | @retval EFI_NOT_FOUND The required object was not found.\r | |
260 | @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration\r | |
261 | Manager is less than the Object size for the\r | |
262 | requested object.\r | |
263 | **/\r | |
264 | STATIC\r | |
265 | EFI_STATUS\r | |
266 | EFIAPI\r | |
267 | BuildDbg2Table (\r | |
268 | IN CONST ACPI_TABLE_GENERATOR * CONST This,\r | |
269 | IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,\r | |
270 | IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,\r | |
271 | OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table\r | |
272 | )\r | |
273 | {\r | |
274 | EFI_STATUS Status;\r | |
275 | CM_ARM_SERIAL_PORT_INFO * SerialPortInfo;\r | |
276 | \r | |
277 | ASSERT (This != NULL);\r | |
278 | ASSERT (AcpiTableInfo != NULL);\r | |
279 | ASSERT (CfgMgrProtocol != NULL);\r | |
280 | ASSERT (Table != NULL);\r | |
281 | ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r | |
282 | ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);\r | |
283 | \r | |
284 | if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||\r | |
285 | (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) {\r | |
286 | DEBUG ((\r | |
287 | DEBUG_ERROR,\r | |
288 | "ERROR: DBG2: Requested table revision = %d, is not supported."\r | |
289 | "Supported table revision: Minimum = %d, Maximum = %d\n",\r | |
290 | AcpiTableInfo->AcpiTableRevision,\r | |
291 | This->MinAcpiTableRevision,\r | |
292 | This->AcpiTableRevision\r | |
293 | ));\r | |
294 | return EFI_INVALID_PARAMETER;\r | |
295 | }\r | |
296 | \r | |
297 | *Table = NULL;\r | |
298 | \r | |
299 | Status = GetEArmObjSerialDebugPortInfo (\r | |
300 | CfgMgrProtocol,\r | |
301 | CM_NULL_TOKEN,\r | |
302 | &SerialPortInfo,\r | |
303 | NULL\r | |
304 | );\r | |
305 | if (EFI_ERROR (Status)) {\r | |
306 | DEBUG ((\r | |
307 | DEBUG_ERROR,\r | |
308 | "ERROR: DBG2: Failed to get serial port information. Status = %r\n",\r | |
309 | Status\r | |
310 | ));\r | |
311 | goto error_handler;\r | |
312 | }\r | |
313 | \r | |
314 | if (SerialPortInfo->BaseAddress == 0) {\r | |
315 | Status = EFI_INVALID_PARAMETER;\r | |
316 | DEBUG ((\r | |
317 | DEBUG_ERROR,\r | |
318 | "ERROR: DBG2: Uart port base address is invalid. BaseAddress = 0x%lx\n",\r | |
319 | SerialPortInfo->BaseAddress\r | |
320 | ));\r | |
321 | goto error_handler;\r | |
322 | }\r | |
323 | \r | |
324 | if ((SerialPortInfo->PortSubtype !=\r | |
325 | EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_PL011_UART) &&\r | |
326 | (SerialPortInfo->PortSubtype !=\r | |
327 | EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART_2X) &&\r | |
328 | (SerialPortInfo->PortSubtype !=\r | |
329 | EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_ARM_SBSA_GENERIC_UART) &&\r | |
330 | (SerialPortInfo->PortSubtype !=\r | |
331 | EFI_ACPI_DBG2_PORT_SUBTYPE_SERIAL_DCC)) {\r | |
332 | Status = EFI_INVALID_PARAMETER;\r | |
333 | DEBUG ((\r | |
334 | DEBUG_ERROR,\r | |
335 | "ERROR: DBG2: Uart port sybtype is invalid. PortSubtype = 0x%x\n",\r | |
336 | SerialPortInfo->PortSubtype\r | |
337 | ));\r | |
338 | goto error_handler;\r | |
339 | }\r | |
340 | \r | |
341 | Status = AddAcpiHeader (\r | |
342 | CfgMgrProtocol,\r | |
343 | This,\r | |
344 | (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2,\r | |
345 | AcpiTableInfo->AcpiTableRevision,\r | |
346 | sizeof (DBG2_TABLE)\r | |
347 | );\r | |
348 | if (EFI_ERROR (Status)) {\r | |
349 | DEBUG ((\r | |
350 | DEBUG_ERROR,\r | |
351 | "ERROR: DBG2: Failed to add ACPI header. Status = %r\n",\r | |
352 | Status\r | |
353 | ));\r | |
354 | goto error_handler;\r | |
355 | }\r | |
356 | \r | |
357 | // Update the base address\r | |
358 | AcpiDbg2.Dbg2DeviceInfo[DBG_PORT_INDEX_PORT1].BaseAddressRegister.Address =\r | |
359 | SerialPortInfo->BaseAddress;\r | |
360 | \r | |
361 | // Update the serial port subtype\r | |
362 | AcpiDbg2.Dbg2DeviceInfo[DBG_PORT_INDEX_PORT1].Dbg2Device.PortSubtype =\r | |
363 | SerialPortInfo->PortSubtype;\r | |
364 | \r | |
365 | // Initialize the serial port\r | |
366 | Status = SetupDebugUart (SerialPortInfo);\r | |
367 | if (EFI_ERROR (Status)) {\r | |
368 | DEBUG ((\r | |
369 | DEBUG_ERROR,\r | |
370 | "ERROR: DBG2: Failed to configure debug serial port. Status = %r\n",\r | |
371 | Status\r | |
372 | ));\r | |
373 | goto error_handler;\r | |
374 | }\r | |
375 | \r | |
376 | *Table = (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2;\r | |
377 | \r | |
378 | error_handler:\r | |
379 | return Status;\r | |
380 | }\r | |
381 | \r | |
382 | /** This macro defines the DBG2 Table Generator revision.\r | |
383 | */\r | |
384 | #define DBG2_GENERATOR_REVISION CREATE_REVISION (1, 0)\r | |
385 | \r | |
386 | /** The interface for the DBG2 Table Generator.\r | |
387 | */\r | |
388 | STATIC\r | |
389 | CONST\r | |
390 | ACPI_TABLE_GENERATOR Dbg2Generator = {\r | |
391 | // Generator ID\r | |
392 | CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdDbg2),\r | |
393 | // Generator Description\r | |
394 | L"ACPI.STD.DBG2.GENERATOR",\r | |
395 | // ACPI Table Signature\r | |
396 | EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE,\r | |
397 | // ACPI Table Revision supported by this Generator\r | |
398 | EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION,\r | |
399 | // Minimum supported ACPI Table Revision\r | |
400 | EFI_ACPI_DBG2_DEBUG_DEVICE_INFORMATION_STRUCT_REVISION,\r | |
401 | // Creator ID\r | |
402 | TABLE_GENERATOR_CREATOR_ID_ARM,\r | |
403 | // Creator Revision\r | |
404 | DBG2_GENERATOR_REVISION,\r | |
405 | // Build Table function\r | |
406 | BuildDbg2Table,\r | |
407 | // No additional resources are allocated by the generator.\r | |
408 | // Hence the Free Resource function is not required.\r | |
409 | NULL,\r | |
410 | // Extended build function not needed\r | |
411 | NULL,\r | |
412 | // Extended build function not implemented by the generator.\r | |
413 | // Hence extended free resource function is not required.\r | |
414 | NULL\r | |
415 | };\r | |
416 | \r | |
417 | /** Register the Generator with the ACPI Table Factory.\r | |
418 | \r | |
419 | @param [in] ImageHandle The handle to the image.\r | |
420 | @param [in] SystemTable Pointer to the System Table.\r | |
421 | \r | |
422 | @retval EFI_SUCCESS The Generator is registered.\r | |
423 | @retval EFI_INVALID_PARAMETER A parameter is invalid.\r | |
424 | @retval EFI_ALREADY_STARTED The Generator for the Table ID\r | |
425 | is already registered.\r | |
426 | **/\r | |
427 | EFI_STATUS\r | |
428 | EFIAPI\r | |
429 | AcpiDbg2LibConstructor (\r | |
430 | IN CONST EFI_HANDLE ImageHandle,\r | |
431 | IN EFI_SYSTEM_TABLE * CONST SystemTable\r | |
432 | )\r | |
433 | {\r | |
434 | EFI_STATUS Status;\r | |
435 | Status = RegisterAcpiTableGenerator (&Dbg2Generator);\r | |
436 | DEBUG ((DEBUG_INFO, "DBG2: Register Generator. Status = %r\n", Status));\r | |
437 | ASSERT_EFI_ERROR (Status);\r | |
438 | \r | |
439 | return Status;\r | |
440 | }\r | |
441 | \r | |
442 | /** Deregister the Generator from the ACPI Table Factory.\r | |
443 | \r | |
444 | @param [in] ImageHandle The handle to the image.\r | |
445 | @param [in] SystemTable Pointer to the System Table.\r | |
446 | \r | |
447 | @retval EFI_SUCCESS The Generator is deregistered.\r | |
448 | @retval EFI_INVALID_PARAMETER A parameter is invalid.\r | |
449 | @retval EFI_NOT_FOUND The Generator is not registered.\r | |
450 | **/\r | |
451 | EFI_STATUS\r | |
452 | EFIAPI\r | |
453 | AcpiDbg2LibDestructor (\r | |
454 | IN CONST EFI_HANDLE ImageHandle,\r | |
455 | IN EFI_SYSTEM_TABLE * CONST SystemTable\r | |
456 | )\r | |
457 | {\r | |
458 | EFI_STATUS Status;\r | |
459 | Status = DeregisterAcpiTableGenerator (&Dbg2Generator);\r | |
460 | DEBUG ((DEBUG_INFO, "DBG2: Deregister Generator. Status = %r\n", Status));\r | |
461 | ASSERT_EFI_ERROR (Status);\r | |
462 | return Status;\r | |
463 | }\r |