AcpiPlatformDxe.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /** @file
  2. Copyright (c) 2020 - 2023, Ampere Computing LLC. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include "AcpiApei.h"
  6. #include "AcpiPlatform.h"
  7. STATIC EFI_EVENT mAcpiRegistration = NULL;
  8. /*
  9. * This GUID must match the FILE_GUID in AcpiTables.inf of each boards
  10. */
  11. STATIC CONST EFI_GUID mAcpiCommonTableFile = { 0xCEFA2AEB, 0x357E, 0x4F48, { 0x80, 0x66, 0xEA, 0x95, 0x08, 0x53, 0x05, 0x6E } } ;
  12. STATIC CONST EFI_GUID mJadeAcpiTableFile = { 0x5addbc13, 0x8634, 0x480c, { 0x9b, 0x94, 0x67, 0x1b, 0x78, 0x55, 0xcd, 0xb8 } };
  13. STATIC CONST EFI_GUID mJadeAcpiTableAc02File = { 0x5CA064B6 , 0x5AA4, 0x4E29, { 0xAB, 0xDC, 0x8B, 0xF3, 0xB3, 0x4D, 0xBF, 0x9E } };
  14. /**
  15. * Callback called when ACPI Protocol is installed
  16. */
  17. STATIC VOID
  18. AcpiNotificationEvent (
  19. IN EFI_EVENT Event,
  20. IN VOID *Context
  21. )
  22. {
  23. EFI_STATUS Status;
  24. EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
  25. Status = LocateAndInstallAcpiFromFv (&mAcpiCommonTableFile);
  26. ASSERT_EFI_ERROR (Status);
  27. if (IsAc01Processor ()) {
  28. Status = LocateAndInstallAcpiFromFv (&mJadeAcpiTableFile);
  29. } else {
  30. Status = LocateAndInstallAcpiFromFv (&mJadeAcpiTableAc02File);
  31. }
  32. ASSERT_EFI_ERROR (Status);
  33. //
  34. // Find ACPI table RSD_PTR from the system table.
  35. //
  36. Status = EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)&Rsdp);
  37. if (EFI_ERROR (Status)) {
  38. Status = EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID **)&Rsdp);
  39. }
  40. if (!EFI_ERROR (Status) &&
  41. Rsdp != NULL &&
  42. Rsdp->Revision >= EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION &&
  43. Rsdp->RsdtAddress != 0)
  44. {
  45. // ARM Platforms must set the RSDT address to NULL
  46. Rsdp->RsdtAddress = 0;
  47. }
  48. DEBUG ((DEBUG_INFO, "[%a:%d]-\n", __FUNCTION__, __LINE__));
  49. }
  50. VOID
  51. EFIAPI
  52. InstallAcpiOnReadyToBoot (
  53. IN EFI_EVENT Event,
  54. IN VOID *Context
  55. )
  56. {
  57. EFI_STATUS Status;
  58. Status = AcpiInstallMadtTable ();
  59. if (!EFI_ERROR (Status)) {
  60. DEBUG ((DEBUG_INFO, "Installed MADT table\n"));
  61. }
  62. Status = AcpiInstallPpttTable ();
  63. if (!EFI_ERROR (Status)) {
  64. DEBUG ((DEBUG_INFO, "Installed PPTT table\n"));
  65. }
  66. Status = AcpiInstallSlitTable ();
  67. if (!EFI_ERROR (Status)) {
  68. DEBUG ((DEBUG_INFO, "Installed SLIT table\n"));
  69. }
  70. Status = AcpiInstallSratTable ();
  71. if (!EFI_ERROR (Status)) {
  72. DEBUG ((DEBUG_INFO, "Installed SRAT table\n"));
  73. }
  74. Status = AcpiInstallPcctTable ();
  75. if (!EFI_ERROR (Status)) {
  76. DEBUG ((DEBUG_INFO, "Installed PCCT table\n"));
  77. }
  78. Status = AcpiInstallNfitTable ();
  79. if (!EFI_ERROR (Status)) {
  80. DEBUG ((DEBUG_INFO, "Installed NFIT table\n"));
  81. }
  82. Status = AcpiInstallIort ();
  83. if (!EFI_ERROR (Status)) {
  84. DEBUG ((DEBUG_INFO, "Installed IORT table\n"));
  85. }
  86. Status = AcpiInstallMcfg ();
  87. if (!EFI_ERROR (Status)) {
  88. DEBUG ((DEBUG_INFO, "Installed MCFG table\n"));
  89. }
  90. Status = AcpiPopulateBert ();
  91. if (!EFI_ERROR (Status)) {
  92. DEBUG ((DEBUG_INFO, "Populate BERT record\n"));
  93. }
  94. //
  95. // Close the event, so it will not be signalled again.
  96. //
  97. gBS->CloseEvent (Event);
  98. }
  99. VOID
  100. EFIAPI
  101. UpdateAcpiOnExitBootServices (
  102. IN EFI_EVENT Event,
  103. IN VOID *Context
  104. )
  105. {
  106. EFI_STATUS Status;
  107. Status = AcpiPatchDsdtTable ();
  108. if (!EFI_ERROR (Status)) {
  109. DEBUG ((DEBUG_INFO, "DSDT Table updated!\n"));
  110. }
  111. // Configure ACPI Platform Error Interfaces
  112. Status = AcpiApeiUpdate ();
  113. if (!EFI_ERROR (Status)) {
  114. DEBUG ((DEBUG_INFO, "APEI Table updated!\n"));
  115. }
  116. // Advertise shared memory regions to SMpro/PMpro and unmask interrupt
  117. Status = AcpiPcctInitializeSharedMemory ();
  118. if (!EFI_ERROR (Status)) {
  119. DEBUG ((DEBUG_INFO, "PCCT Table updated!\n"));
  120. }
  121. //
  122. // Close the event, so it will not be signalled again.
  123. //
  124. gBS->CloseEvent (Event);
  125. }
  126. EFI_STATUS
  127. EFIAPI
  128. AcpiPlatformDxeInitialize (
  129. IN EFI_HANDLE ImageHandle,
  130. IN EFI_SYSTEM_TABLE *SystemTable
  131. )
  132. {
  133. EFI_EVENT ReadyToBootEvent;
  134. EFI_EVENT ExitBootServicesEvent;
  135. EFI_STATUS Status;
  136. EfiCreateProtocolNotifyEvent (
  137. &gEfiAcpiTableProtocolGuid,
  138. TPL_CALLBACK,
  139. AcpiNotificationEvent,
  140. NULL,
  141. &mAcpiRegistration
  142. );
  143. Status = gBS->CreateEvent (
  144. EVT_SIGNAL_EXIT_BOOT_SERVICES,
  145. TPL_CALLBACK,
  146. UpdateAcpiOnExitBootServices,
  147. NULL,
  148. &ExitBootServicesEvent
  149. );
  150. ASSERT_EFI_ERROR (Status);
  151. Status = gBS->CreateEventEx (
  152. EVT_NOTIFY_SIGNAL,
  153. TPL_CALLBACK,
  154. InstallAcpiOnReadyToBoot,
  155. NULL,
  156. &gEfiEventReadyToBootGuid,
  157. &ReadyToBootEvent
  158. );
  159. ASSERT_EFI_ERROR (Status);
  160. return EFI_SUCCESS;
  161. }