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