FvbServiceSmm.c 4.3 KB

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