]> git.proxmox.com Git - mirror_edk2.git/blame - DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
DynamicTablesPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / DynamicTablesPkg / Library / Acpi / Arm / AcpiGtdtLibArm / GtdtGenerator.c
CommitLineData
9c720258
SM
1/** @file\r
2 GTDT Table Generator\r
3\r
4 Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.\r
9cd9bdc6 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
9c720258
SM
6\r
7 @par Reference(s):\r
8 - ACPI 6.2 Specification - Errata A, September 2017\r
9\r
10**/\r
11\r
12#include <Library/AcpiLib.h>\r
13#include <Library/DebugLib.h>\r
14#include <Library/MemoryAllocationLib.h>\r
15#include <Protocol/AcpiTable.h>\r
16\r
17// Module specific include files.\r
18#include <AcpiTableGenerator.h>\r
19#include <ConfigurationManagerObject.h>\r
20#include <ConfigurationManagerHelper.h>\r
21#include <Library/TableHelperLib.h>\r
22#include <Protocol/ConfigurationManagerProtocol.h>\r
23\r
24/** ARM standard GTDT Generator\r
25\r
26Requirements:\r
27 The following Configuration Manager Object(s) are required by\r
28 this Generator:\r
29 - EArmObjGenericTimerInfo\r
30 - EArmObjPlatformGenericWatchdogInfo (OPTIONAL)\r
31 - EArmObjPlatformGTBlockInfo (OPTIONAL)\r
32 - EArmObjGTBlockTimerFrameInfo (OPTIONAL)\r
33*/\r
34\r
35/** This macro expands to a function that retrieves the Generic\r
36 Timer Information from the Configuration Manager.\r
37*/\r
38GET_OBJECT_LIST (\r
39 EObjNameSpaceArm,\r
40 EArmObjGenericTimerInfo,\r
41 CM_ARM_GENERIC_TIMER_INFO\r
42 );\r
43\r
44/** This macro expands to a function that retrieves the SBSA Generic\r
45 Watchdog Timer Information from the Configuration Manager.\r
46*/\r
47GET_OBJECT_LIST (\r
48 EObjNameSpaceArm,\r
49 EArmObjPlatformGenericWatchdogInfo,\r
50 CM_ARM_GENERIC_WATCHDOG_INFO\r
51 );\r
52\r
53/** This macro expands to a function that retrieves the Platform Generic\r
54 Timer Block Information from the Configuration Manager.\r
55*/\r
56GET_OBJECT_LIST (\r
57 EObjNameSpaceArm,\r
58 EArmObjPlatformGTBlockInfo,\r
59 CM_ARM_GTBLOCK_INFO\r
60 );\r
61\r
62/** This macro expands to a function that retrieves the Generic\r
63 Timer Block Timer Frame Information from the Configuration Manager.\r
64*/\r
65GET_OBJECT_LIST (\r
66 EObjNameSpaceArm,\r
67 EArmObjGTBlockTimerFrameInfo,\r
68 CM_ARM_GTBLOCK_TIMER_FRAME_INFO\r
69 );\r
70\r
71/** Add the Generic Timer Information to the GTDT table.\r
72\r
73 Also update the Platform Timer offset information if the platform\r
74 implements platform timers.\r
75\r
76 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
77 Protocol Interface.\r
78 @param [in] Gtdt Pointer to the GTDT Table.\r
79 @param [in] PlatformTimerCount Platform timer count.\r
80\r
81 @retval EFI_SUCCESS Success.\r
82 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
83 @retval EFI_NOT_FOUND The required object was not found.\r
84 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration\r
85 Manager is less than the Object size for the\r
86 requested object.\r
87**/\r
88STATIC\r
89EFI_STATUS\r
90EFIAPI\r
91AddGenericTimerInfo (\r
92 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,\r
93 IN EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt,\r
94 IN CONST UINT32 PlatformTimerCount\r
95)\r
96{\r
97 EFI_STATUS Status;\r
98 CM_ARM_GENERIC_TIMER_INFO * GenericTimerInfo;\r
99\r
100 ASSERT (CfgMgrProtocol != NULL);\r
101 ASSERT (Gtdt != NULL);\r
102\r
103 Status = GetEArmObjGenericTimerInfo (\r
104 CfgMgrProtocol,\r
105 CM_NULL_TOKEN,\r
106 &GenericTimerInfo,\r
107 NULL\r
108 );\r
109\r
110 if (EFI_ERROR (Status)) {\r
111 DEBUG ((\r
112 DEBUG_ERROR,\r
113 "ERROR: GTDT: Failed to get GenericTimerInfo. Status = %r\n",\r
114 Status\r
115 ));\r
116 return Status;\r
117 }\r
118\r
119 Gtdt->CntControlBasePhysicalAddress =\r
120 GenericTimerInfo->CounterControlBaseAddress;\r
121 Gtdt->Reserved = EFI_ACPI_RESERVED_DWORD;\r
122 Gtdt->SecurePL1TimerGSIV = GenericTimerInfo->SecurePL1TimerGSIV;\r
123 Gtdt->SecurePL1TimerFlags = GenericTimerInfo->SecurePL1TimerFlags;\r
124 Gtdt->NonSecurePL1TimerGSIV = GenericTimerInfo->NonSecurePL1TimerGSIV;\r
125 Gtdt->NonSecurePL1TimerFlags = GenericTimerInfo->NonSecurePL1TimerFlags;\r
126 Gtdt->VirtualTimerGSIV = GenericTimerInfo->VirtualTimerGSIV;\r
127 Gtdt->VirtualTimerFlags = GenericTimerInfo->VirtualTimerFlags;\r
128 Gtdt->NonSecurePL2TimerGSIV = GenericTimerInfo->NonSecurePL2TimerGSIV;\r
129 Gtdt->NonSecurePL2TimerFlags = GenericTimerInfo->NonSecurePL2TimerFlags;\r
130 Gtdt->CntReadBasePhysicalAddress =\r
131 GenericTimerInfo->CounterReadBaseAddress;\r
132 Gtdt->PlatformTimerCount = PlatformTimerCount;\r
133 Gtdt->PlatformTimerOffset = (PlatformTimerCount == 0) ? 0 :\r
134 sizeof (EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE);\r
135\r
136 return EFI_SUCCESS;\r
137}\r
138\r
139/** Add the SBSA Generic Watchdog Timers to the GTDT table.\r
140\r
141 @param [in] Gtdt Pointer to the GTDT Table.\r
142 @param [in] WatchdogOffset Offset to the watchdog information in the\r
143 GTDT Table.\r
144 @param [in] WatchdogInfoList Pointer to the watchdog information list.\r
145 @param [in] WatchdogCount Platform timer count.\r
146**/\r
147STATIC\r
148VOID\r
149AddGenericWatchdogList (\r
150 IN EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt,\r
151 IN CONST UINT32 WatchdogOffset,\r
152 IN CONST CM_ARM_GENERIC_WATCHDOG_INFO * WatchdogInfoList,\r
153 IN UINT32 WatchdogCount\r
154 )\r
155{\r
156 EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE * Watchdog;\r
157\r
158 ASSERT (Gtdt != NULL);\r
159 ASSERT (WatchdogInfoList != NULL);\r
160\r
161 Watchdog = (EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE *)\r
162 ((UINT8*)Gtdt + WatchdogOffset);\r
163\r
164 while (WatchdogCount-- != 0) {\r
165 // Add watchdog entry\r
166 DEBUG ((DEBUG_INFO, "GTDT: Watchdog = 0x%p\n", Watchdog));\r
167 Watchdog->Type = EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG;\r
168 Watchdog->Length =\r
169 sizeof (EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE);\r
170 Watchdog->Reserved = EFI_ACPI_RESERVED_BYTE;\r
171 Watchdog->RefreshFramePhysicalAddress =\r
172 WatchdogInfoList->RefreshFrameAddress;\r
173 Watchdog->WatchdogControlFramePhysicalAddress =\r
174 WatchdogInfoList->ControlFrameAddress;\r
175 Watchdog->WatchdogTimerGSIV = WatchdogInfoList->TimerGSIV;\r
176 Watchdog->WatchdogTimerFlags = WatchdogInfoList->Flags;\r
177 Watchdog++;\r
178 WatchdogInfoList++;\r
179 } // for\r
180}\r
181\r
182/** Update the GT Block Timer Frame lists in the GTDT Table.\r
183\r
184 @param [in] GtBlockFrame Pointer to the GT Block Frames\r
185 list to be updated.\r
186 @param [in] GTBlockTimerFrameList Pointer to the GT Block Frame\r
187 Information List.\r
188 @param [in] GTBlockFrameCount Number of GT Block Frames.\r
189\r
190 @retval EFI_SUCCESS Table generated successfully.\r
191 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
192**/\r
193STATIC\r
194EFI_STATUS\r
195AddGTBlockTimerFrames (\r
196 IN EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE * GtBlockFrame,\r
197 IN CONST CM_ARM_GTBLOCK_TIMER_FRAME_INFO * GTBlockTimerFrameList,\r
198 IN UINT32 GTBlockFrameCount\r
199)\r
200{\r
201 ASSERT (GtBlockFrame != NULL);\r
202 ASSERT (GTBlockTimerFrameList != NULL);\r
203\r
204 if (GTBlockFrameCount > 8) {\r
205 DEBUG ((\r
206 DEBUG_ERROR,\r
207 "ERROR: GTDT: GT Block Frame Count %d is greater than 8\n",\r
208 GTBlockFrameCount\r
209 ));\r
210 ASSERT (GTBlockFrameCount <= 8);\r
211 return EFI_INVALID_PARAMETER;\r
212 }\r
213\r
214 while (GTBlockFrameCount-- != 0) {\r
215 DEBUG ((\r
216 DEBUG_INFO,\r
217 "GTDT: GtBlockFrame = 0x%p\n",\r
218 GtBlockFrame\r
219 ));\r
220\r
221 GtBlockFrame->GTFrameNumber = GTBlockTimerFrameList->FrameNumber;\r
222 GtBlockFrame->Reserved[0] = EFI_ACPI_RESERVED_BYTE;\r
223 GtBlockFrame->Reserved[1] = EFI_ACPI_RESERVED_BYTE;\r
224 GtBlockFrame->Reserved[2] = EFI_ACPI_RESERVED_BYTE;\r
225\r
226 GtBlockFrame->CntBaseX = GTBlockTimerFrameList->PhysicalAddressCntBase;\r
227 GtBlockFrame->CntEL0BaseX =\r
228 GTBlockTimerFrameList->PhysicalAddressCntEL0Base;\r
229\r
230 GtBlockFrame->GTxPhysicalTimerGSIV =\r
231 GTBlockTimerFrameList->PhysicalTimerGSIV;\r
232 GtBlockFrame->GTxPhysicalTimerFlags =\r
233 GTBlockTimerFrameList->PhysicalTimerFlags;\r
234\r
235 GtBlockFrame->GTxVirtualTimerGSIV = GTBlockTimerFrameList->VirtualTimerGSIV;\r
236 GtBlockFrame->GTxVirtualTimerFlags =\r
237 GTBlockTimerFrameList->VirtualTimerFlags;\r
238\r
239 GtBlockFrame->GTxCommonFlags = GTBlockTimerFrameList->CommonFlags;\r
240 GtBlockFrame++;\r
241 GTBlockTimerFrameList++;\r
242 } // for\r
243 return EFI_SUCCESS;\r
244}\r
245\r
246/** Add the GT Block Timers in the GTDT Table.\r
247\r
248 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
249 Protocol Interface.\r
250 @param [in] Gtdt Pointer to the GTDT Table.\r
251 @param [in] GTBlockOffset Offset of the GT Block\r
252 information in the GTDT Table.\r
253 @param [in] GTBlockInfo Pointer to the GT Block\r
254 Information List.\r
255 @param [in] BlockTimerCount Number of GT Block Timers.\r
256\r
257 @retval EFI_SUCCESS Table generated successfully.\r
258 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
259**/\r
260STATIC\r
261EFI_STATUS\r
262AddGTBlockList (\r
263 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,\r
264 IN EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt,\r
265 IN CONST UINT32 GTBlockOffset,\r
266 IN CONST CM_ARM_GTBLOCK_INFO * GTBlockInfo,\r
267 IN UINT32 BlockTimerCount\r
268)\r
269{\r
270 EFI_STATUS Status;\r
271 EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE * GTBlock;\r
272 EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE * GtBlockFrame;\r
273 CM_ARM_GTBLOCK_TIMER_FRAME_INFO * GTBlockTimerFrameList;\r
274 UINT32 GTBlockTimerFrameCount;\r
275\r
276 ASSERT (Gtdt != NULL);\r
277 ASSERT (GTBlockInfo != NULL);\r
278\r
279 GTBlock = (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE *)((UINT8*)Gtdt +\r
280 GTBlockOffset);\r
281\r
282 while (BlockTimerCount-- != 0) {\r
283 DEBUG ((DEBUG_INFO, "GTDT: GTBlock = 0x%p\n", GTBlock));\r
284\r
285 Status = GetEArmObjGTBlockTimerFrameInfo (\r
286 CfgMgrProtocol,\r
287 GTBlockInfo->GTBlockTimerFrameToken,\r
288 &GTBlockTimerFrameList,\r
289 &GTBlockTimerFrameCount\r
290 );\r
291 if (EFI_ERROR (Status) ||\r
292 (GTBlockTimerFrameCount != GTBlockInfo->GTBlockTimerFrameCount)) {\r
293 DEBUG ((\r
294 DEBUG_ERROR,\r
295 "ERROR: GTDT: Failed to get Generic Timer Frames. Status = %r\n",\r
296 Status\r
297 ));\r
298 return Status;\r
299 }\r
300\r
301 GTBlock->Type = EFI_ACPI_6_2_GTDT_GT_BLOCK;\r
302 GTBlock->Length = sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE) +\r
303 (sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE) *\r
304 GTBlockInfo->GTBlockTimerFrameCount);\r
305\r
306 GTBlock->Reserved = EFI_ACPI_RESERVED_BYTE;\r
307 GTBlock->CntCtlBase = GTBlockInfo->GTBlockPhysicalAddress;\r
308 GTBlock->GTBlockTimerCount = GTBlockInfo->GTBlockTimerFrameCount;\r
309 GTBlock->GTBlockTimerOffset =\r
310 sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE);\r
311\r
312 GtBlockFrame = (EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE*)\r
313 ((UINT8*)GTBlock + GTBlock->GTBlockTimerOffset);\r
314\r
315 // Add GT Block Timer frames\r
316 Status = AddGTBlockTimerFrames (\r
317 GtBlockFrame,\r
318 GTBlockTimerFrameList,\r
319 GTBlockTimerFrameCount\r
320 );\r
321 if (EFI_ERROR (Status)) {\r
322 DEBUG ((\r
323 DEBUG_ERROR,\r
324 "ERROR: GTDT: Failed to add Generic Timer Frames. Status = %r\n",\r
325 Status\r
326 ));\r
327 return Status;\r
328 }\r
329\r
330 // Next GTBlock\r
331 GTBlock = (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE *)((UINT8*)GTBlock +\r
332 GTBlock->Length);\r
333 GTBlockInfo++;\r
334 }// for\r
335 return EFI_SUCCESS;\r
336}\r
337\r
338/** Construct the GTDT ACPI table.\r
339\r
340 Called by the Dynamic Table Manager, this function invokes the\r
341 Configuration Manager protocol interface to get the required hardware\r
342 information for generating the ACPI table.\r
343\r
344 If this function allocates any resources then they must be freed\r
345 in the FreeXXXXTableResources function.\r
346\r
347 @param [in] This Pointer to the table generator.\r
348 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.\r
349 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
350 Protocol Interface.\r
351 @param [out] Table Pointer to the constructed ACPI Table.\r
352\r
353 @retval EFI_SUCCESS Table generated successfully.\r
354 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
355 @retval EFI_NOT_FOUND The required object was not found.\r
356 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration\r
357 Manager is less than the Object size for the\r
358 requested object.\r
359 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
360**/\r
361STATIC\r
362EFI_STATUS\r
363EFIAPI\r
364BuildGtdtTable (\r
365 IN CONST ACPI_TABLE_GENERATOR * CONST This,\r
366 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,\r
367 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,\r
368 OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table\r
369 )\r
370{\r
371 EFI_STATUS Status;\r
372 UINT32 TableSize;\r
373 UINT32 PlatformTimerCount;\r
374 UINT32 WatchdogCount;\r
375 UINT32 BlockTimerCount;\r
376 CM_ARM_GENERIC_WATCHDOG_INFO * WatchdogInfoList;\r
377 CM_ARM_GTBLOCK_INFO * GTBlockInfo;\r
378 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE * Gtdt;\r
379 UINT32 Idx;\r
380 UINT32 GTBlockOffset;\r
381 UINT32 WatchdogOffset;\r
382\r
383 ASSERT (This != NULL);\r
384 ASSERT (AcpiTableInfo != NULL);\r
385 ASSERT (CfgMgrProtocol != NULL);\r
386 ASSERT (Table != NULL);\r
387 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r
388 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);\r
389\r
390 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||\r
391 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) {\r
392 DEBUG ((\r
393 DEBUG_ERROR,\r
394 "ERROR: GTDT: Requested table revision = %d, is not supported."\r
395 "Supported table revision: Minimum = %d, Maximum = %d\n",\r
396 AcpiTableInfo->AcpiTableRevision,\r
397 This->MinAcpiTableRevision,\r
398 This->AcpiTableRevision\r
399 ));\r
400 return EFI_INVALID_PARAMETER;\r
401 }\r
402\r
403 *Table = NULL;\r
404 Status = GetEArmObjPlatformGTBlockInfo (\r
405 CfgMgrProtocol,\r
406 CM_NULL_TOKEN,\r
407 &GTBlockInfo,\r
408 &BlockTimerCount\r
409 );\r
410 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {\r
411 DEBUG ((\r
412 DEBUG_ERROR,\r
413 "ERROR: GTDT: Failed to Get Platform GT Block Information." \\r
414 " Status = %r\n",\r
415 Status\r
416 ));\r
417 goto error_handler;\r
418 }\r
419\r
420 Status = GetEArmObjPlatformGenericWatchdogInfo (\r
421 CfgMgrProtocol,\r
422 CM_NULL_TOKEN,\r
423 &WatchdogInfoList,\r
424 &WatchdogCount\r
425 );\r
426 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {\r
427 DEBUG ((\r
428 DEBUG_ERROR,\r
429 "ERROR: GTDT: Failed to Get Platform Generic Watchdog Information." \\r
430 " Status = %r\n",\r
431 Status\r
432 ));\r
433 goto error_handler;\r
434 }\r
435\r
436 DEBUG ((\r
437 DEBUG_INFO,\r
438 "GTDT: BlockTimerCount = %d, WatchdogCount = %d\n",\r
439 BlockTimerCount,\r
440 WatchdogCount\r
441 ));\r
442\r
443 // Calculate the GTDT Table Size\r
444 PlatformTimerCount = 0;\r
445 TableSize = sizeof (EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE);\r
446 if (BlockTimerCount != 0) {\r
447 GTBlockOffset = TableSize;\r
448 PlatformTimerCount += BlockTimerCount;\r
449 TableSize += (sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE) *\r
450 BlockTimerCount);\r
451\r
452 for (Idx = 0; Idx < BlockTimerCount; Idx++) {\r
453 if (GTBlockInfo[Idx].GTBlockTimerFrameCount > 8) {\r
454 Status = EFI_INVALID_PARAMETER;\r
455 DEBUG ((\r
456 DEBUG_ERROR,\r
457 "GTDT: GTBockFrameCount cannot be more than 8." \\r
458 " GTBockFrameCount = %d, Status = %r\n",\r
459 GTBlockInfo[Idx].GTBlockTimerFrameCount,\r
460 Status\r
461 ));\r
462 goto error_handler;\r
463 }\r
464 TableSize += (sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE) *\r
465 GTBlockInfo[Idx].GTBlockTimerFrameCount);\r
466 }\r
467\r
468 DEBUG ((\r
469 DEBUG_INFO,\r
470 "GTDT: GTBockOffset = 0x%x, PLATFORM_TIMER_COUNT = %d\n",\r
471 GTBlockOffset,\r
472 PlatformTimerCount\r
473 ));\r
474 }\r
475\r
476 WatchdogOffset = 0;\r
477 if (WatchdogCount != 0) {\r
478 WatchdogOffset = TableSize;\r
479 PlatformTimerCount += WatchdogCount;\r
480 TableSize += (sizeof (EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE) *\r
481 WatchdogCount);\r
482 DEBUG ((\r
483 DEBUG_INFO,\r
484 "GTDT: WatchdogOffset = 0x%x, PLATFORM_TIMER_COUNT = %d\n",\r
485 WatchdogOffset,\r
486 PlatformTimerCount\r
487 ));\r
488 }\r
489\r
490 *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize);\r
491 if (*Table == NULL) {\r
492 Status = EFI_OUT_OF_RESOURCES;\r
493 DEBUG ((\r
494 DEBUG_ERROR,\r
495 "ERROR: GTDT: Failed to allocate memory for GTDT Table, Size = %d," \\r
496 " Status = %r\n",\r
497 TableSize,\r
498 Status\r
499 ));\r
500 goto error_handler;\r
501 }\r
502\r
503 Gtdt = (EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE*)*Table;\r
504 DEBUG ((\r
505 DEBUG_INFO,\r
506 "GTDT: Gtdt = 0x%p TableSize = 0x%x\n",\r
507 Gtdt,\r
508 TableSize\r
509 ));\r
510\r
511 Status = AddAcpiHeader (\r
512 CfgMgrProtocol,\r
513 This,\r
514 &Gtdt->Header,\r
e12bdeb1 515 AcpiTableInfo,\r
9c720258
SM
516 TableSize\r
517 );\r
518 if (EFI_ERROR (Status)) {\r
519 DEBUG ((\r
520 DEBUG_ERROR,\r
521 "ERROR: GTDT: Failed to add ACPI header. Status = %r\n",\r
522 Status\r
523 ));\r
524 goto error_handler;\r
525 }\r
526\r
527 Status = AddGenericTimerInfo (\r
528 CfgMgrProtocol,\r
529 Gtdt,\r
530 PlatformTimerCount\r
531 );\r
532 if (EFI_ERROR (Status)) {\r
533 DEBUG ((\r
534 DEBUG_ERROR,\r
535 "ERROR: GTDT: Failed to add Generic Timer Info. Status = %r\n",\r
536 Status\r
537 ));\r
538 goto error_handler;\r
539 }\r
540\r
541 if (BlockTimerCount != 0) {\r
542 Status = AddGTBlockList (\r
543 CfgMgrProtocol,\r
544 Gtdt,\r
545 GTBlockOffset,\r
546 GTBlockInfo,\r
547 BlockTimerCount\r
548 );\r
549 if (EFI_ERROR (Status)) {\r
550 DEBUG ((\r
551 DEBUG_ERROR,\r
552 "ERROR: GTDT: Failed to add GT Block timers. Status = %r\n",\r
553 Status\r
554 ));\r
555 goto error_handler;\r
556 }\r
557 }\r
558\r
559 if (WatchdogCount != 0) {\r
560 AddGenericWatchdogList (\r
561 Gtdt,\r
562 WatchdogOffset,\r
563 WatchdogInfoList,\r
564 WatchdogCount\r
565 );\r
566 }\r
567\r
568 return Status;\r
569\r
570error_handler:\r
571 if (*Table != NULL) {\r
572 FreePool (*Table);\r
573 *Table = NULL;\r
574 }\r
575 return Status;\r
576}\r
577\r
578/** Free any resources allocated for constructing the GTDT.\r
579\r
580 @param [in] This Pointer to the table generator.\r
581 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.\r
582 @param [in] CfgMgrProtocol Pointer to the Configuration Manager\r
583 Protocol Interface.\r
584 @param [in, out] Table Pointer to the ACPI Table.\r
585\r
586 @retval EFI_SUCCESS The resources were freed successfully.\r
587 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.\r
588**/\r
589STATIC\r
590EFI_STATUS\r
591FreeGtdtTableResources (\r
592 IN CONST ACPI_TABLE_GENERATOR * CONST This,\r
593 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,\r
594 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,\r
595 IN OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table\r
596)\r
597{\r
598 ASSERT (This != NULL);\r
599 ASSERT (AcpiTableInfo != NULL);\r
600 ASSERT (CfgMgrProtocol != NULL);\r
601 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);\r
602 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);\r
603\r
604 if ((Table == NULL) || (*Table == NULL)) {\r
605 DEBUG ((DEBUG_ERROR, "ERROR: GTDT: Invalid Table Pointer\n"));\r
606 ASSERT ((Table != NULL) && (*Table != NULL));\r
607 return EFI_INVALID_PARAMETER;\r
608 }\r
609\r
610 FreePool (*Table);\r
611 *Table = NULL;\r
612 return EFI_SUCCESS;\r
613}\r
614\r
615/** This macro defines the GTDT Table Generator revision.\r
616*/\r
617#define GTDT_GENERATOR_REVISION CREATE_REVISION (1, 0)\r
618\r
619/** The interface for the GTDT Table Generator.\r
620*/\r
621STATIC\r
622CONST\r
623ACPI_TABLE_GENERATOR GtdtGenerator = {\r
624 // Generator ID\r
625 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdGtdt),\r
626 // Generator Description\r
627 L"ACPI.STD.GTDT.GENERATOR",\r
628 // ACPI Table Signature\r
629 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,\r
630 // ACPI Table Revision supported by this Generator\r
631 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION,\r
632 // Minimum ACPI Table Revision supported by this Generator\r
633 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION,\r
634 // Creator ID\r
635 TABLE_GENERATOR_CREATOR_ID_ARM,\r
636 // Creator Revision\r
637 GTDT_GENERATOR_REVISION,\r
638 // Build Table function\r
639 BuildGtdtTable,\r
640 // Free Resource function\r
641 FreeGtdtTableResources,\r
642 // Extended build function not needed\r
643 NULL,\r
644 // Extended build function not implemented by the generator.\r
645 // Hence extended free resource function is not required.\r
646 NULL\r
647};\r
648\r
649/** Register the Generator with the ACPI Table Factory.\r
650\r
651 @param [in] ImageHandle The handle to the image.\r
652 @param [in] SystemTable Pointer to the System Table.\r
653\r
654 @retval EFI_SUCCESS The Generator is registered.\r
655 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
656 @retval EFI_ALREADY_STARTED The Generator for the Table ID\r
657 is already registered.\r
658**/\r
659EFI_STATUS\r
660EFIAPI\r
661AcpiGtdtLibConstructor (\r
662 IN CONST EFI_HANDLE ImageHandle,\r
663 IN EFI_SYSTEM_TABLE * CONST SystemTable\r
664 )\r
665{\r
666 EFI_STATUS Status;\r
667 Status = RegisterAcpiTableGenerator (&GtdtGenerator);\r
668 DEBUG ((DEBUG_INFO, "GTDT: Register Generator. Status = %r\n", Status));\r
669 ASSERT_EFI_ERROR (Status);\r
670 return Status;\r
671}\r
672\r
673/** Deregister the Generator from the ACPI Table Factory.\r
674\r
675 @param [in] ImageHandle The handle to the image.\r
676 @param [in] SystemTable Pointer to the System Table.\r
677\r
678 @retval EFI_SUCCESS The Generator is deregistered.\r
679 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
680 @retval EFI_NOT_FOUND The Generator is not registered.\r
681**/\r
682EFI_STATUS\r
683EFIAPI\r
684AcpiGtdtLibDestructor (\r
685 IN CONST EFI_HANDLE ImageHandle,\r
686 IN EFI_SYSTEM_TABLE * CONST SystemTable\r
687 )\r
688{\r
689 EFI_STATUS Status;\r
690 Status = DeregisterAcpiTableGenerator (&GtdtGenerator);\r
691 DEBUG ((DEBUG_INFO, "GTDT: Deregister Generator. Status = %r\n", Status));\r
692 ASSERT_EFI_ERROR (Status);\r
693 return Status;\r
694}\r