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