PrmSsdtInstallDxe.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /** @file
  2. This file contains a sample implementation of the Platform Runtime Mechanism (PRM)
  3. SSDT Install library.
  4. Copyright (c) Microsoft Corporation
  5. Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <IndustryStandard/Acpi.h>
  9. #include <Library/BaseLib.h>
  10. #include <Library/BaseMemoryLib.h>
  11. #include <Library/DebugLib.h>
  12. #include <Library/DxeServicesLib.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. #include <Protocol/AcpiTable.h>
  15. #define _DBGMSGID_ "[PRMSSDTINSTALL]"
  16. /**
  17. Installs the PRM SSDT.
  18. @param[in] OemId OEM ID to be used in the SSDT installation.
  19. @retval EFI_SUCCESS The PRM SSDT was installed successfully.
  20. @retval EFI_INVALID_PARAMETER The OemId pointer argument is NULL.
  21. @retval EFI_NOT_FOUND An instance of gEfiAcpiTableProtocolGuid was not found installed or
  22. the SSDT (AML RAW section) could not be found in the current FV.
  23. @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to install the PRM SSDT.
  24. **/
  25. EFI_STATUS
  26. InstallPrmSsdt (
  27. IN CONST UINT8 *OemId
  28. )
  29. {
  30. EFI_STATUS Status;
  31. UINTN SsdtSize;
  32. UINTN TableKey;
  33. EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
  34. EFI_ACPI_DESCRIPTION_HEADER *Ssdt;
  35. DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__));
  36. if (OemId == NULL) {
  37. return EFI_INVALID_PARAMETER;
  38. }
  39. Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **)&AcpiTableProtocol);
  40. if (!EFI_ERROR (Status)) {
  41. //
  42. // Discover the SSDT
  43. //
  44. Status = GetSectionFromFv (
  45. &gEfiCallerIdGuid,
  46. EFI_SECTION_RAW,
  47. 0,
  48. (VOID **)&Ssdt,
  49. &SsdtSize
  50. );
  51. ASSERT_EFI_ERROR (Status);
  52. DEBUG ((DEBUG_INFO, "%a %a: SSDT loaded...\n", _DBGMSGID_, __FUNCTION__));
  53. //
  54. // Update OEM ID in the SSDT
  55. //
  56. CopyMem (&Ssdt->OemId, OemId, sizeof (Ssdt->OemId));
  57. //
  58. // Publish the SSDT. Table is re-checksummed.
  59. //
  60. TableKey = 0;
  61. Status = AcpiTableProtocol->InstallAcpiTable (
  62. AcpiTableProtocol,
  63. Ssdt,
  64. SsdtSize,
  65. &TableKey
  66. );
  67. ASSERT_EFI_ERROR (Status);
  68. }
  69. return Status;
  70. }
  71. /**
  72. The entry point for this module.
  73. @param[in] ImageHandle The firmware allocated handle for the EFI image.
  74. @param[in] SystemTable A pointer to the EFI System Table.
  75. @retval EFI_SUCCESS The entry point is executed successfully.
  76. @retval Others An error occurred when executing this entry point.
  77. **/
  78. EFI_STATUS
  79. EFIAPI
  80. PrmSsdtInstallEntryPoint (
  81. IN EFI_HANDLE ImageHandle,
  82. IN EFI_SYSTEM_TABLE *SystemTable
  83. )
  84. {
  85. EFI_STATUS Status;
  86. Status = InstallPrmSsdt ((UINT8 *)PcdGetPtr (PcdAcpiDefaultOemId));
  87. ASSERT_EFI_ERROR (Status);
  88. return Status;
  89. }