SmmBoardAcpiEnableLib.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /** @file
  2. Platform Hook Library instances
  3. @copyright
  4. Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Base.h>
  8. #include <Uefi.h>
  9. #include <PiDxe.h>
  10. #include <Library/BaseLib.h>
  11. #include <Library/IoLib.h>
  12. #include <Library/BoardAcpiEnableLib.h>
  13. #include <Library/PcdLib.h>
  14. #include <Library/DebugLib.h>
  15. #include <PchAccess.h>
  16. #include <Protocol/DynamicSiLibrarySmmProtocol.h>
  17. #include <Library/SmmServicesTableLib.h>
  18. EFI_STATUS
  19. EFIAPI
  20. BoardEnableAcpi (
  21. IN BOOLEAN EnableSci
  22. )
  23. {
  24. UINT32 SmiEn;
  25. UINT16 Pm1En;
  26. UINT16 Pm1Cnt;
  27. UINT16 PchPmBase;
  28. EFI_STATUS Status;
  29. DYNAMIC_SI_LIBARY_SMM_PROTOCOL *DynamicSiLibrarySmmProtocol = NULL;
  30. Status = gSmst->SmmLocateProtocol (&gDynamicSiLibrarySmmProtocolGuid, NULL, (VOID**) &DynamicSiLibrarySmmProtocol);
  31. if (EFI_ERROR (Status)) {
  32. ASSERT_EFI_ERROR (Status);
  33. return Status;
  34. }
  35. //
  36. // Init Power Management I/O Base aka ACPI Base
  37. //
  38. PchPmBase = DynamicSiLibrarySmmProtocol->PmcGetAcpiBase ();
  39. SmiEn = IoRead32 (PchPmBase + R_ACPI_IO_SMI_EN);
  40. //
  41. // Disable SW SMI Timer and legacy USB
  42. //
  43. SmiEn &= ~(B_ACPI_IO_SMI_EN_SWSMI_TMR | B_ACPI_IO_SMI_EN_LEGACY_USB | B_ACPI_IO_SMI_EN_LEGACY_USB2);
  44. //
  45. // And enable SMI on write to B_PCH_ACPI_PM1_CNT_SLP_EN when SLP_TYP is written
  46. //
  47. SmiEn |= B_ACPI_IO_SMI_EN_ON_SLP_EN ;
  48. IoWrite32 (PchPmBase + R_ACPI_IO_SMI_EN, SmiEn);
  49. //
  50. // Disable PM sources except power button
  51. //
  52. Pm1En = B_ACPI_IO_PM1_EN_PWRBTN;
  53. IoWrite16 (PchPmBase + R_ACPI_IO_PM1_EN, Pm1En);
  54. //
  55. // Enable SCI
  56. //
  57. if (EnableSci) {
  58. Pm1Cnt = IoRead16 (PchPmBase + R_ACPI_IO_PM1_CNT);
  59. Pm1Cnt |= B_ACPI_IO_PM1_CNT_SCI_EN;
  60. IoWrite16 (PchPmBase + R_ACPI_IO_PM1_CNT, Pm1Cnt);
  61. }
  62. return EFI_SUCCESS;
  63. }
  64. EFI_STATUS
  65. EFIAPI
  66. BoardDisableAcpi (
  67. IN BOOLEAN DisableSci
  68. )
  69. {
  70. UINT16 Pm1Cnt;
  71. UINT16 PchPmBase;
  72. EFI_STATUS Status;
  73. DYNAMIC_SI_LIBARY_SMM_PROTOCOL *DynamicSiLibrarySmmProtocol = NULL;
  74. Status = gSmst->SmmLocateProtocol (&gDynamicSiLibrarySmmProtocolGuid, NULL, (VOID**) &DynamicSiLibrarySmmProtocol);
  75. if (EFI_ERROR (Status)) {
  76. ASSERT_EFI_ERROR (Status);
  77. return Status;
  78. }
  79. //
  80. // Init Power Management I/O Base aka ACPI Base
  81. //
  82. PchPmBase = DynamicSiLibrarySmmProtocol->PmcGetAcpiBase ();
  83. //
  84. // Disable SCI
  85. //
  86. if (DisableSci) {
  87. Pm1Cnt = IoRead16 (PchPmBase + R_ACPI_IO_PM1_CNT);
  88. Pm1Cnt &= ~B_ACPI_IO_PM1_CNT_SCI_EN;
  89. IoWrite16 (PchPmBase + R_ACPI_IO_PM1_CNT, Pm1Cnt);
  90. }
  91. return EFI_SUCCESS;
  92. }