2 Firmware Volume Block Driver for Lakeport Platform.
4 Firmware volume block driver for FWH or SPI device.
5 It depends on which Flash Device Library to be linked with this driver.
7 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Library/UefiRuntimeLib.h>
17 #include "FvbService.h"
19 extern FWB_GLOBAL mFvbModuleGlobal
;
22 Call back function on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
24 Fixup internal data so that the driver is callable in EFI runtime
25 in virtual mode. Convert the mFvbModuleGlobal date items to there
28 @param Event Event whose notification function is being invoked.
29 @param Context The context of the Notification context. Not used in
30 this call back function.
35 FvbVirtualddressChangeEvent (
40 EFI_FW_VOL_INSTANCE
*FwhInstance
;
44 // Convert the base address of all the instances.
46 for (Index
= 0; Index
< mFvbModuleGlobal
.NumFv
; Index
++) {
47 FwhInstance
= GetFvbInstance (Index
);
48 EfiConvertPointer (0, (VOID
**) &FwhInstance
->FvBase
);
51 EfiConvertPointer (0, (VOID
**) &mFvbModuleGlobal
.FvInstance
);
56 The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol
57 for each FV in the system.
59 @param[in] FwhInstance The pointer to a FW volume instance structure,
60 which contains the information about one FV.
61 @param[in] InstanceNum The instance number which can be used as a ID
62 to locate this FwhInstance in other functions.
69 IN EFI_FW_VOL_INSTANCE
*FwhInstance
,
73 EFI_FW_VOL_BLOCK_DEVICE
*FvbDevice
;
74 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
77 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*OldFwbInterface
;
79 FvbDevice
= (EFI_FW_VOL_BLOCK_DEVICE
*) AllocateRuntimeCopyPool (
80 sizeof (EFI_FW_VOL_BLOCK_DEVICE
),
83 ASSERT (FvbDevice
!= NULL
);
85 FvbDevice
->Instance
= InstanceNum
;
86 FwVolHeader
= &FwhInstance
->VolumeHeader
;
89 // Set up the devicepath.
91 DEBUG ((EFI_D_INFO
, "FwBlockService.c: Setting up DevicePath for 0x%lx:\n", FwhInstance
->FvBase
));
92 if (FwVolHeader
->ExtHeaderOffset
== 0) {
94 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH.
96 FvbDevice
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH
), &mFvMemmapDevicePathTemplate
);
97 ((FV_MEMMAP_DEVICE_PATH
*) FvbDevice
->DevicePath
)->MemMapDevPath
.StartingAddress
= FwhInstance
->FvBase
;
98 ((FV_MEMMAP_DEVICE_PATH
*) FvbDevice
->DevicePath
)->MemMapDevPath
.EndingAddress
= FwhInstance
->FvBase
+ FwVolHeader
->FvLength
- 1;
100 FvbDevice
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH
), &mFvPIWGDevicePathTemplate
);
102 &((FV_PIWG_DEVICE_PATH
*)FvbDevice
->DevicePath
)->FvDevPath
.FvName
,
103 (GUID
*)(UINTN
)(FwhInstance
->FvBase
+ FwVolHeader
->ExtHeaderOffset
)
108 // Find a handle with a matching device path that has supports FW Block protocol.
110 Status
= gBS
->LocateDevicePath (
111 &gEfiFirmwareVolumeBlockProtocolGuid
,
112 &FvbDevice
->DevicePath
,
115 if (EFI_ERROR (Status
) ) {
117 // LocateDevicePath fails so install a new interface and device path.
119 DEBUG ((EFI_D_INFO
, "FwBlockService.c: LocateDevicePath failed, install new interface 0x%lx:\n", FwhInstance
->FvBase
));
121 Status
= gBS
->InstallMultipleProtocolInterfaces (
123 &gEfiFirmwareVolumeBlockProtocolGuid
,
124 &FvbDevice
->FwVolBlockInstance
,
125 &gEfiDevicePathProtocolGuid
,
126 FvbDevice
->DevicePath
,
129 ASSERT_EFI_ERROR (Status
);
130 DEBUG ((EFI_D_INFO
, "FwBlockService.c: IMPI FirmwareVolBlockProt, DevPath 0x%lx: %r\n", FwhInstance
->FvBase
, Status
));
132 } else if (IsDevicePathEnd (FvbDevice
->DevicePath
)) {
134 // Device allready exists, so reinstall the FVB protocol.
136 DEBUG ((EFI_D_ERROR
, "FwBlockService.c: LocateDevicePath succeeded, reinstall interface 0x%lx:\n", FwhInstance
->FvBase
));
137 Status
= gBS
->HandleProtocol (
139 &gEfiFirmwareVolumeBlockProtocolGuid
,
140 (VOID
**) &OldFwbInterface
142 ASSERT_EFI_ERROR (Status
);
144 Status
= gBS
->ReinstallProtocolInterface (
146 &gEfiFirmwareVolumeBlockProtocolGuid
,
148 &FvbDevice
->FwVolBlockInstance
150 ASSERT_EFI_ERROR (Status
);
154 // There was a FVB protocol on an End Device Path node.
163 The driver entry point for Firmware Volume Block Driver.
165 The function does the necessary initialization work for
166 Firmware Volume Block Driver.
168 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
169 @param[in] SystemTable A pointer to the EFI system table.
171 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
172 It will ASSERT on errors.
178 IN EFI_HANDLE ImageHandle
,
179 IN EFI_SYSTEM_TABLE
*SystemTable
185 Status
= gBS
->CreateEventEx (
188 FvbVirtualddressChangeEvent
,
190 &gEfiEventVirtualAddressChangeGuid
,
193 ASSERT_EFI_ERROR (Status
);