FvbServiceDxe.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /** @file
  2. 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) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include <PiDxe.h>
  9. #include <Library/UefiRuntimeLib.h>
  10. #include "FvbService.h"
  11. extern FWB_GLOBAL mFvbModuleGlobal;
  12. /**
  13. Call back function on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
  14. Fixup internal data so that the driver is callable in EFI runtime
  15. in virtual mode. Convert the mFvbModuleGlobal date items to there
  16. virtual address.
  17. @param Event Event whose notification function is being invoked.
  18. @param Context The context of the Notification context. Not used in
  19. this call back function.
  20. **/
  21. VOID
  22. EFIAPI
  23. FvbVirtualddressChangeEvent (
  24. IN EFI_EVENT Event,
  25. IN VOID *Context
  26. )
  27. {
  28. EFI_FW_VOL_INSTANCE *FwhInstance;
  29. UINTN Index;
  30. //
  31. // Convert the base address of all the instances.
  32. //
  33. for (Index = 0; Index < mFvbModuleGlobal.NumFv; Index++) {
  34. FwhInstance = GetFvbInstance (Index);
  35. EfiConvertPointer (0, (VOID **) &FwhInstance->FvBase);
  36. }
  37. EfiConvertPointer (0, (VOID **) &mFvbModuleGlobal.FvInstance);
  38. }
  39. /**
  40. The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol
  41. for each FV in the system.
  42. @param[in] FwhInstance The pointer to a FW volume instance structure,
  43. which contains the information about one FV.
  44. @param[in] InstanceNum The instance number which can be used as a ID
  45. to locate this FwhInstance in other functions.
  46. @retval VOID
  47. **/
  48. VOID
  49. InstallFvbProtocol (
  50. IN EFI_FW_VOL_INSTANCE *FwhInstance,
  51. IN UINTN InstanceNum
  52. )
  53. {
  54. EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
  55. EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
  56. EFI_STATUS Status;
  57. EFI_HANDLE FwbHandle;
  58. EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;
  59. FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *) AllocateRuntimeCopyPool (
  60. sizeof (EFI_FW_VOL_BLOCK_DEVICE),
  61. &mFvbDeviceTemplate
  62. );
  63. ASSERT (FvbDevice != NULL);
  64. FvbDevice->Instance = InstanceNum;
  65. FwVolHeader = &FwhInstance->VolumeHeader;
  66. //
  67. // Set up the devicepath.
  68. //
  69. DEBUG ((EFI_D_INFO, "FwBlockService.c: Setting up DevicePath for 0x%lx:\n", FwhInstance->FvBase));
  70. if (FwVolHeader->ExtHeaderOffset == 0) {
  71. //
  72. // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH.
  73. //
  74. FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
  75. ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = FwhInstance->FvBase;
  76. ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress = FwhInstance->FvBase + FwVolHeader->FvLength - 1;
  77. } else {
  78. FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
  79. CopyGuid (
  80. &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,
  81. (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset)
  82. );
  83. }
  84. //
  85. // Find a handle with a matching device path that has supports FW Block protocol.
  86. //
  87. Status = gBS->LocateDevicePath (
  88. &gEfiFirmwareVolumeBlockProtocolGuid,
  89. &FvbDevice->DevicePath,
  90. &FwbHandle
  91. );
  92. if (EFI_ERROR (Status) ) {
  93. //
  94. // LocateDevicePath fails so install a new interface and device path.
  95. //
  96. DEBUG ((EFI_D_INFO, "FwBlockService.c: LocateDevicePath failed, install new interface 0x%lx:\n", FwhInstance->FvBase));
  97. FwbHandle = NULL;
  98. Status = gBS->InstallMultipleProtocolInterfaces (
  99. &FwbHandle,
  100. &gEfiFirmwareVolumeBlockProtocolGuid,
  101. &FvbDevice->FwVolBlockInstance,
  102. &gEfiDevicePathProtocolGuid,
  103. FvbDevice->DevicePath,
  104. NULL
  105. );
  106. ASSERT_EFI_ERROR (Status);
  107. DEBUG ((EFI_D_INFO, "FwBlockService.c: IMPI FirmwareVolBlockProt, DevPath 0x%lx: %r\n", FwhInstance->FvBase, Status));
  108. } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {
  109. //
  110. // Device allready exists, so reinstall the FVB protocol.
  111. //
  112. DEBUG ((EFI_D_ERROR, "FwBlockService.c: LocateDevicePath succeeded, reinstall interface 0x%lx:\n", FwhInstance->FvBase));
  113. Status = gBS->HandleProtocol (
  114. FwbHandle,
  115. &gEfiFirmwareVolumeBlockProtocolGuid,
  116. (VOID **) &OldFwbInterface
  117. );
  118. ASSERT_EFI_ERROR (Status);
  119. Status = gBS->ReinstallProtocolInterface (
  120. FwbHandle,
  121. &gEfiFirmwareVolumeBlockProtocolGuid,
  122. OldFwbInterface,
  123. &FvbDevice->FwVolBlockInstance
  124. );
  125. ASSERT_EFI_ERROR (Status);
  126. } else {
  127. //
  128. // There was a FVB protocol on an End Device Path node.
  129. //
  130. ASSERT (FALSE);
  131. }
  132. }
  133. /**
  134. The driver entry point for Firmware Volume Block Driver.
  135. The function does the necessary initialization work for
  136. Firmware Volume Block Driver.
  137. @param[in] ImageHandle The firmware allocated handle for the UEFI image.
  138. @param[in] SystemTable A pointer to the EFI system table.
  139. @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
  140. It will ASSERT on errors.
  141. **/
  142. EFI_STATUS
  143. EFIAPI
  144. DxeFvbInitialize (
  145. IN EFI_HANDLE ImageHandle,
  146. IN EFI_SYSTEM_TABLE *SystemTable
  147. )
  148. {
  149. EFI_STATUS Status;
  150. EFI_EVENT Event;
  151. Status = gBS->CreateEventEx (
  152. EVT_NOTIFY_SIGNAL,
  153. TPL_NOTIFY,
  154. FvbVirtualddressChangeEvent,
  155. NULL,
  156. &gEfiEventVirtualAddressChangeGuid,
  157. &Event
  158. );
  159. ASSERT_EFI_ERROR (Status);
  160. FvbInitialize ();
  161. return EFI_SUCCESS;
  162. }