]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
10cf16cb831f80ec195590c5c2ba8a39bf953dab
[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 /**
183 Function to test if two Generic Timer Block Frame Info structures have the
184 same frame number.
185
186 @param [in] Frame1 Pointer to the first GT Block Frame Info
187 structure.
188 @param [in] Frame2 Pointer to the second GT Block Frame Info
189 structure.
190 @param [in] Index1 Index of Frame1 in the shared GT Block Frame
191 Information List.
192 @param [in] Index2 Index of Frame2 in the shared GT Block Frame
193 Information List.
194
195 @retval TRUE Frame1 and Frame2 have the same frame number.
196 @return FALSE Frame1 and Frame2 have different frame numbers.
197
198 **/
199 BOOLEAN
200 EFIAPI
201 IsGtFrameNumberEqual (
202 IN CONST VOID * Frame1,
203 IN CONST VOID * Frame2,
204 IN UINTN Index1,
205 IN UINTN Index2
206 )
207 {
208 UINT8 FrameNumber1;
209 UINT8 FrameNumber2;
210
211 ASSERT ((Frame1 != NULL) && (Frame2 != NULL));
212
213 FrameNumber1 = ((CM_ARM_GTBLOCK_TIMER_FRAME_INFO*)Frame1)->FrameNumber;
214 FrameNumber2 = ((CM_ARM_GTBLOCK_TIMER_FRAME_INFO*)Frame2)->FrameNumber;
215
216 if (FrameNumber1 == FrameNumber2) {
217 DEBUG ((
218 DEBUG_ERROR,
219 "ERROR: GTDT: GT Block Frame Info Structures %d and %d have the same " \
220 "frame number: 0x%x.\n",
221 Index1,
222 Index2,
223 FrameNumber1
224 ));
225 return TRUE;
226 }
227
228 return FALSE;
229 }
230
231 /** Update the GT Block Timer Frame lists in the GTDT Table.
232
233 @param [in] GtBlockFrame Pointer to the GT Block Frames
234 list to be updated.
235 @param [in] GTBlockTimerFrameList Pointer to the GT Block Frame
236 Information List.
237 @param [in] GTBlockFrameCount Number of GT Block Frames.
238
239 @retval EFI_SUCCESS Table generated successfully.
240 @retval EFI_INVALID_PARAMETER A parameter is invalid.
241 **/
242 STATIC
243 EFI_STATUS
244 AddGTBlockTimerFrames (
245 IN EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE * GtBlockFrame,
246 IN CONST CM_ARM_GTBLOCK_TIMER_FRAME_INFO * GTBlockTimerFrameList,
247 IN UINT32 GTBlockFrameCount
248 )
249 {
250 BOOLEAN IsFrameNumberDuplicated;
251
252 ASSERT (GtBlockFrame != NULL);
253 ASSERT (GTBlockTimerFrameList != NULL);
254
255 if (GTBlockFrameCount > 8) {
256 DEBUG ((
257 DEBUG_ERROR,
258 "ERROR: GTDT: GT Block Frame Count %d is greater than 8\n",
259 GTBlockFrameCount
260 ));
261 ASSERT (GTBlockFrameCount <= 8);
262 return EFI_INVALID_PARAMETER;
263 }
264
265 IsFrameNumberDuplicated = FindDuplicateValue (
266 GTBlockTimerFrameList,
267 GTBlockFrameCount,
268 sizeof (CM_ARM_GTBLOCK_TIMER_FRAME_INFO),
269 IsGtFrameNumberEqual
270 );
271 // Duplicate entry was found so timer frame numbers provided are invalid
272 if (IsFrameNumberDuplicated) {
273 return EFI_INVALID_PARAMETER;
274 }
275
276 while (GTBlockFrameCount-- != 0) {
277 DEBUG ((
278 DEBUG_INFO,
279 "GTDT: GtBlockFrame = 0x%p\n",
280 GtBlockFrame
281 ));
282
283 if (GTBlockTimerFrameList->FrameNumber >= 8) {
284 DEBUG ((
285 DEBUG_ERROR,
286 "ERROR: GTDT: Frame number %d is not in the range 0-7\n",
287 GTBlockTimerFrameList->FrameNumber
288 ));
289 return EFI_INVALID_PARAMETER;
290 }
291
292 GtBlockFrame->GTFrameNumber = GTBlockTimerFrameList->FrameNumber;
293 GtBlockFrame->Reserved[0] = EFI_ACPI_RESERVED_BYTE;
294 GtBlockFrame->Reserved[1] = EFI_ACPI_RESERVED_BYTE;
295 GtBlockFrame->Reserved[2] = EFI_ACPI_RESERVED_BYTE;
296
297 GtBlockFrame->CntBaseX = GTBlockTimerFrameList->PhysicalAddressCntBase;
298 GtBlockFrame->CntEL0BaseX =
299 GTBlockTimerFrameList->PhysicalAddressCntEL0Base;
300
301 GtBlockFrame->GTxPhysicalTimerGSIV =
302 GTBlockTimerFrameList->PhysicalTimerGSIV;
303 GtBlockFrame->GTxPhysicalTimerFlags =
304 GTBlockTimerFrameList->PhysicalTimerFlags;
305
306 GtBlockFrame->GTxVirtualTimerGSIV = GTBlockTimerFrameList->VirtualTimerGSIV;
307 GtBlockFrame->GTxVirtualTimerFlags =
308 GTBlockTimerFrameList->VirtualTimerFlags;
309
310 GtBlockFrame->GTxCommonFlags = GTBlockTimerFrameList->CommonFlags;
311 GtBlockFrame++;
312 GTBlockTimerFrameList++;
313 } // for
314 return EFI_SUCCESS;
315 }
316
317 /** Add the GT Block Timers in the GTDT Table.
318
319 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
320 Protocol Interface.
321 @param [in] Gtdt Pointer to the GTDT Table.
322 @param [in] GTBlockOffset Offset of the GT Block
323 information in the GTDT Table.
324 @param [in] GTBlockInfo Pointer to the GT Block
325 Information List.
326 @param [in] BlockTimerCount Number of GT Block Timers.
327
328 @retval EFI_SUCCESS Table generated successfully.
329 @retval EFI_INVALID_PARAMETER A parameter is invalid.
330 **/
331 STATIC
332 EFI_STATUS
333 AddGTBlockList (
334 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
335 IN EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt,
336 IN CONST UINT32 GTBlockOffset,
337 IN CONST CM_ARM_GTBLOCK_INFO * GTBlockInfo,
338 IN UINT32 BlockTimerCount
339 )
340 {
341 EFI_STATUS Status;
342 EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE * GTBlock;
343 EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE * GtBlockFrame;
344 CM_ARM_GTBLOCK_TIMER_FRAME_INFO * GTBlockTimerFrameList;
345 UINT32 GTBlockTimerFrameCount;
346
347 ASSERT (Gtdt != NULL);
348 ASSERT (GTBlockInfo != NULL);
349
350 GTBlock = (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE *)((UINT8*)Gtdt +
351 GTBlockOffset);
352
353 while (BlockTimerCount-- != 0) {
354 DEBUG ((DEBUG_INFO, "GTDT: GTBlock = 0x%p\n", GTBlock));
355
356 Status = GetEArmObjGTBlockTimerFrameInfo (
357 CfgMgrProtocol,
358 GTBlockInfo->GTBlockTimerFrameToken,
359 &GTBlockTimerFrameList,
360 &GTBlockTimerFrameCount
361 );
362 if (EFI_ERROR (Status) ||
363 (GTBlockTimerFrameCount != GTBlockInfo->GTBlockTimerFrameCount)) {
364 DEBUG ((
365 DEBUG_ERROR,
366 "ERROR: GTDT: Failed to get Generic Timer Frames. Status = %r\n",
367 Status
368 ));
369 return Status;
370 }
371
372 GTBlock->Type = EFI_ACPI_6_2_GTDT_GT_BLOCK;
373 GTBlock->Length = sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE) +
374 (sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE) *
375 GTBlockInfo->GTBlockTimerFrameCount);
376
377 GTBlock->Reserved = EFI_ACPI_RESERVED_BYTE;
378 GTBlock->CntCtlBase = GTBlockInfo->GTBlockPhysicalAddress;
379 GTBlock->GTBlockTimerCount = GTBlockInfo->GTBlockTimerFrameCount;
380 GTBlock->GTBlockTimerOffset =
381 sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE);
382
383 GtBlockFrame = (EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE*)
384 ((UINT8*)GTBlock + GTBlock->GTBlockTimerOffset);
385
386 // Add GT Block Timer frames
387 Status = AddGTBlockTimerFrames (
388 GtBlockFrame,
389 GTBlockTimerFrameList,
390 GTBlockTimerFrameCount
391 );
392 if (EFI_ERROR (Status)) {
393 DEBUG ((
394 DEBUG_ERROR,
395 "ERROR: GTDT: Failed to add Generic Timer Frames. Status = %r\n",
396 Status
397 ));
398 return Status;
399 }
400
401 // Next GTBlock
402 GTBlock = (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE *)((UINT8*)GTBlock +
403 GTBlock->Length);
404 GTBlockInfo++;
405 }// for
406 return EFI_SUCCESS;
407 }
408
409 /** Construct the GTDT ACPI table.
410
411 Called by the Dynamic Table Manager, this function invokes the
412 Configuration Manager protocol interface to get the required hardware
413 information for generating the ACPI table.
414
415 If this function allocates any resources then they must be freed
416 in the FreeXXXXTableResources function.
417
418 @param [in] This Pointer to the table generator.
419 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
420 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
421 Protocol Interface.
422 @param [out] Table Pointer to the constructed ACPI Table.
423
424 @retval EFI_SUCCESS Table generated successfully.
425 @retval EFI_INVALID_PARAMETER A parameter is invalid.
426 @retval EFI_NOT_FOUND The required object was not found.
427 @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
428 Manager is less than the Object size for the
429 requested object.
430 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
431 **/
432 STATIC
433 EFI_STATUS
434 EFIAPI
435 BuildGtdtTable (
436 IN CONST ACPI_TABLE_GENERATOR * CONST This,
437 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,
438 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
439 OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table
440 )
441 {
442 EFI_STATUS Status;
443 UINT32 TableSize;
444 UINT32 PlatformTimerCount;
445 UINT32 WatchdogCount;
446 UINT32 BlockTimerCount;
447 CM_ARM_GENERIC_WATCHDOG_INFO * WatchdogInfoList;
448 CM_ARM_GTBLOCK_INFO * GTBlockInfo;
449 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE * Gtdt;
450 UINT32 Idx;
451 UINT32 GTBlockOffset;
452 UINT32 WatchdogOffset;
453
454 ASSERT (This != NULL);
455 ASSERT (AcpiTableInfo != NULL);
456 ASSERT (CfgMgrProtocol != NULL);
457 ASSERT (Table != NULL);
458 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
459 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
460
461 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
462 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) {
463 DEBUG ((
464 DEBUG_ERROR,
465 "ERROR: GTDT: Requested table revision = %d, is not supported."
466 "Supported table revision: Minimum = %d, Maximum = %d\n",
467 AcpiTableInfo->AcpiTableRevision,
468 This->MinAcpiTableRevision,
469 This->AcpiTableRevision
470 ));
471 return EFI_INVALID_PARAMETER;
472 }
473
474 *Table = NULL;
475 Status = GetEArmObjPlatformGTBlockInfo (
476 CfgMgrProtocol,
477 CM_NULL_TOKEN,
478 &GTBlockInfo,
479 &BlockTimerCount
480 );
481 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
482 DEBUG ((
483 DEBUG_ERROR,
484 "ERROR: GTDT: Failed to Get Platform GT Block Information." \
485 " Status = %r\n",
486 Status
487 ));
488 goto error_handler;
489 }
490
491 Status = GetEArmObjPlatformGenericWatchdogInfo (
492 CfgMgrProtocol,
493 CM_NULL_TOKEN,
494 &WatchdogInfoList,
495 &WatchdogCount
496 );
497 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
498 DEBUG ((
499 DEBUG_ERROR,
500 "ERROR: GTDT: Failed to Get Platform Generic Watchdog Information." \
501 " Status = %r\n",
502 Status
503 ));
504 goto error_handler;
505 }
506
507 DEBUG ((
508 DEBUG_INFO,
509 "GTDT: BlockTimerCount = %d, WatchdogCount = %d\n",
510 BlockTimerCount,
511 WatchdogCount
512 ));
513
514 // Calculate the GTDT Table Size
515 PlatformTimerCount = 0;
516 TableSize = sizeof (EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE);
517 if (BlockTimerCount != 0) {
518 GTBlockOffset = TableSize;
519 PlatformTimerCount += BlockTimerCount;
520 TableSize += (sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_STRUCTURE) *
521 BlockTimerCount);
522
523 for (Idx = 0; Idx < BlockTimerCount; Idx++) {
524 if (GTBlockInfo[Idx].GTBlockTimerFrameCount > 8) {
525 Status = EFI_INVALID_PARAMETER;
526 DEBUG ((
527 DEBUG_ERROR,
528 "GTDT: GTBockFrameCount cannot be more than 8." \
529 " GTBockFrameCount = %d, Status = %r\n",
530 GTBlockInfo[Idx].GTBlockTimerFrameCount,
531 Status
532 ));
533 goto error_handler;
534 }
535 TableSize += (sizeof (EFI_ACPI_6_2_GTDT_GT_BLOCK_TIMER_STRUCTURE) *
536 GTBlockInfo[Idx].GTBlockTimerFrameCount);
537 }
538
539 DEBUG ((
540 DEBUG_INFO,
541 "GTDT: GTBockOffset = 0x%x, PLATFORM_TIMER_COUNT = %d\n",
542 GTBlockOffset,
543 PlatformTimerCount
544 ));
545 }
546
547 WatchdogOffset = 0;
548 if (WatchdogCount != 0) {
549 WatchdogOffset = TableSize;
550 PlatformTimerCount += WatchdogCount;
551 TableSize += (sizeof (EFI_ACPI_6_2_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE) *
552 WatchdogCount);
553 DEBUG ((
554 DEBUG_INFO,
555 "GTDT: WatchdogOffset = 0x%x, PLATFORM_TIMER_COUNT = %d\n",
556 WatchdogOffset,
557 PlatformTimerCount
558 ));
559 }
560
561 *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize);
562 if (*Table == NULL) {
563 Status = EFI_OUT_OF_RESOURCES;
564 DEBUG ((
565 DEBUG_ERROR,
566 "ERROR: GTDT: Failed to allocate memory for GTDT Table, Size = %d," \
567 " Status = %r\n",
568 TableSize,
569 Status
570 ));
571 goto error_handler;
572 }
573
574 Gtdt = (EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE*)*Table;
575 DEBUG ((
576 DEBUG_INFO,
577 "GTDT: Gtdt = 0x%p TableSize = 0x%x\n",
578 Gtdt,
579 TableSize
580 ));
581
582 Status = AddAcpiHeader (
583 CfgMgrProtocol,
584 This,
585 &Gtdt->Header,
586 AcpiTableInfo,
587 TableSize
588 );
589 if (EFI_ERROR (Status)) {
590 DEBUG ((
591 DEBUG_ERROR,
592 "ERROR: GTDT: Failed to add ACPI header. Status = %r\n",
593 Status
594 ));
595 goto error_handler;
596 }
597
598 Status = AddGenericTimerInfo (
599 CfgMgrProtocol,
600 Gtdt,
601 PlatformTimerCount
602 );
603 if (EFI_ERROR (Status)) {
604 DEBUG ((
605 DEBUG_ERROR,
606 "ERROR: GTDT: Failed to add Generic Timer Info. Status = %r\n",
607 Status
608 ));
609 goto error_handler;
610 }
611
612 if (BlockTimerCount != 0) {
613 Status = AddGTBlockList (
614 CfgMgrProtocol,
615 Gtdt,
616 GTBlockOffset,
617 GTBlockInfo,
618 BlockTimerCount
619 );
620 if (EFI_ERROR (Status)) {
621 DEBUG ((
622 DEBUG_ERROR,
623 "ERROR: GTDT: Failed to add GT Block timers. Status = %r\n",
624 Status
625 ));
626 goto error_handler;
627 }
628 }
629
630 if (WatchdogCount != 0) {
631 AddGenericWatchdogList (
632 Gtdt,
633 WatchdogOffset,
634 WatchdogInfoList,
635 WatchdogCount
636 );
637 }
638
639 return Status;
640
641 error_handler:
642 if (*Table != NULL) {
643 FreePool (*Table);
644 *Table = NULL;
645 }
646 return Status;
647 }
648
649 /** Free any resources allocated for constructing the GTDT.
650
651 @param [in] This Pointer to the table generator.
652 @param [in] AcpiTableInfo Pointer to the ACPI Table Info.
653 @param [in] CfgMgrProtocol Pointer to the Configuration Manager
654 Protocol Interface.
655 @param [in, out] Table Pointer to the ACPI Table.
656
657 @retval EFI_SUCCESS The resources were freed successfully.
658 @retval EFI_INVALID_PARAMETER The table pointer is NULL or invalid.
659 **/
660 STATIC
661 EFI_STATUS
662 FreeGtdtTableResources (
663 IN CONST ACPI_TABLE_GENERATOR * CONST This,
664 IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,
665 IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
666 IN OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table
667 )
668 {
669 ASSERT (This != NULL);
670 ASSERT (AcpiTableInfo != NULL);
671 ASSERT (CfgMgrProtocol != NULL);
672 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
673 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
674
675 if ((Table == NULL) || (*Table == NULL)) {
676 DEBUG ((DEBUG_ERROR, "ERROR: GTDT: Invalid Table Pointer\n"));
677 ASSERT ((Table != NULL) && (*Table != NULL));
678 return EFI_INVALID_PARAMETER;
679 }
680
681 FreePool (*Table);
682 *Table = NULL;
683 return EFI_SUCCESS;
684 }
685
686 /** This macro defines the GTDT Table Generator revision.
687 */
688 #define GTDT_GENERATOR_REVISION CREATE_REVISION (1, 0)
689
690 /** The interface for the GTDT Table Generator.
691 */
692 STATIC
693 CONST
694 ACPI_TABLE_GENERATOR GtdtGenerator = {
695 // Generator ID
696 CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdGtdt),
697 // Generator Description
698 L"ACPI.STD.GTDT.GENERATOR",
699 // ACPI Table Signature
700 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE,
701 // ACPI Table Revision supported by this Generator
702 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION,
703 // Minimum ACPI Table Revision supported by this Generator
704 EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_REVISION,
705 // Creator ID
706 TABLE_GENERATOR_CREATOR_ID_ARM,
707 // Creator Revision
708 GTDT_GENERATOR_REVISION,
709 // Build Table function
710 BuildGtdtTable,
711 // Free Resource function
712 FreeGtdtTableResources,
713 // Extended build function not needed
714 NULL,
715 // Extended build function not implemented by the generator.
716 // Hence extended free resource function is not required.
717 NULL
718 };
719
720 /** Register the Generator with the ACPI Table Factory.
721
722 @param [in] ImageHandle The handle to the image.
723 @param [in] SystemTable Pointer to the System Table.
724
725 @retval EFI_SUCCESS The Generator is registered.
726 @retval EFI_INVALID_PARAMETER A parameter is invalid.
727 @retval EFI_ALREADY_STARTED The Generator for the Table ID
728 is already registered.
729 **/
730 EFI_STATUS
731 EFIAPI
732 AcpiGtdtLibConstructor (
733 IN CONST EFI_HANDLE ImageHandle,
734 IN EFI_SYSTEM_TABLE * CONST SystemTable
735 )
736 {
737 EFI_STATUS Status;
738 Status = RegisterAcpiTableGenerator (&GtdtGenerator);
739 DEBUG ((DEBUG_INFO, "GTDT: Register Generator. Status = %r\n", Status));
740 ASSERT_EFI_ERROR (Status);
741 return Status;
742 }
743
744 /** Deregister the Generator from the ACPI Table Factory.
745
746 @param [in] ImageHandle The handle to the image.
747 @param [in] SystemTable Pointer to the System Table.
748
749 @retval EFI_SUCCESS The Generator is deregistered.
750 @retval EFI_INVALID_PARAMETER A parameter is invalid.
751 @retval EFI_NOT_FOUND The Generator is not registered.
752 **/
753 EFI_STATUS
754 EFIAPI
755 AcpiGtdtLibDestructor (
756 IN CONST EFI_HANDLE ImageHandle,
757 IN EFI_SYSTEM_TABLE * CONST SystemTable
758 )
759 {
760 EFI_STATUS Status;
761 Status = DeregisterAcpiTableGenerator (&GtdtGenerator);
762 DEBUG ((DEBUG_INFO, "GTDT: Deregister Generator. Status = %r\n", Status));
763 ASSERT_EFI_ERROR (Status);
764 return Status;
765 }