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