FvbServiceSmm.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /** @file
  2. SMM Firmware Volume Block Driver.
  3. Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiSmm.h>
  7. #include <Library/SmmServicesTableLib.h>
  8. #include "FvbSmmCommon.h"
  9. #include "FvbService.h"
  10. /**
  11. The function installs EFI_SMM_FIRMWARE_VOLUME_BLOCK protocol
  12. for each FV in the system.
  13. @param[in] FwhInstance The pointer to a FW volume instance structure,
  14. which contains the information about one FV.
  15. @param[in] InstanceNum The instance number which can be used as a ID
  16. to locate this FwhInstance in other functions.
  17. @retval EFI_SUCESS Installed successfully.
  18. @retval Else Did not install successfully.
  19. **/
  20. EFI_STATUS
  21. InstallFvbProtocol (
  22. IN EFI_FW_VOL_INSTANCE *FwhInstance,
  23. IN UINTN InstanceNum
  24. )
  25. {
  26. EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
  27. EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
  28. EFI_STATUS Status;
  29. EFI_HANDLE FvbHandle;
  30. FV_MEMMAP_DEVICE_PATH *FvDevicePath;
  31. VOID *TempPtr;
  32. FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *)AllocateRuntimeCopyPool (
  33. sizeof (EFI_FW_VOL_BLOCK_DEVICE),
  34. &mFvbDeviceTemplate
  35. );
  36. if (FvbDevice == NULL) {
  37. return EFI_OUT_OF_RESOURCES;
  38. }
  39. FvbDevice->Instance = InstanceNum;
  40. FwVolHeader = &FwhInstance->VolumeHeader;
  41. //
  42. // Set up the devicepath
  43. //
  44. if (FwVolHeader->ExtHeaderOffset == 0) {
  45. //
  46. // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH
  47. //
  48. TempPtr = AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
  49. FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)TempPtr;
  50. if (FvbDevice->DevicePath == NULL) {
  51. ASSERT (FALSE);
  52. return EFI_OUT_OF_RESOURCES;
  53. }
  54. FvDevicePath = (FV_MEMMAP_DEVICE_PATH *)FvbDevice->DevicePath;
  55. FvDevicePath->MemMapDevPath.StartingAddress = FwhInstance->FvBase;
  56. FvDevicePath->MemMapDevPath.EndingAddress = FwhInstance->FvBase + FwVolHeader->FvLength - 1;
  57. } else {
  58. TempPtr = AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
  59. FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)TempPtr;
  60. if (FvbDevice->DevicePath == NULL) {
  61. ASSERT (FALSE);
  62. return EFI_OUT_OF_RESOURCES;
  63. }
  64. CopyGuid (
  65. &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,
  66. (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset)
  67. );
  68. }
  69. //
  70. // Install the SMM Firmware Volume Block Protocol and Device Path Protocol
  71. //
  72. FvbHandle = NULL;
  73. Status = gSmst->SmmInstallProtocolInterface (
  74. &FvbHandle,
  75. &gEfiSmmFirmwareVolumeBlockProtocolGuid,
  76. EFI_NATIVE_INTERFACE,
  77. &FvbDevice->FwVolBlockInstance
  78. );
  79. ASSERT_EFI_ERROR (Status);
  80. Status = gSmst->SmmInstallProtocolInterface (
  81. &FvbHandle,
  82. &gEfiDevicePathProtocolGuid,
  83. EFI_NATIVE_INTERFACE,
  84. FvbDevice->DevicePath
  85. );
  86. ASSERT_EFI_ERROR (Status);
  87. //
  88. // Notify the Fvb wrapper driver SMM fvb is ready
  89. //
  90. FvbHandle = NULL;
  91. Status = gBS->InstallProtocolInterface (
  92. &FvbHandle,
  93. &gEfiSmmFirmwareVolumeBlockProtocolGuid,
  94. EFI_NATIVE_INTERFACE,
  95. &FvbDevice->FwVolBlockInstance
  96. );
  97. return Status;
  98. }
  99. /**
  100. The driver entry point for SMM Firmware Volume Block Driver.
  101. The function does the necessary initialization work
  102. Firmware Volume Block Driver.
  103. @param[in] ImageHandle The firmware allocated handle for the UEFI image.
  104. @param[in] SystemTable A pointer to the EFI system table.
  105. @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
  106. It will ASSERT on errors.
  107. **/
  108. EFI_STATUS
  109. EFIAPI
  110. FvbSmmInitialize (
  111. IN EFI_HANDLE ImageHandle,
  112. IN EFI_SYSTEM_TABLE *SystemTable
  113. )
  114. {
  115. FvbInitialize ();
  116. return EFI_SUCCESS;
  117. }