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 This program and the accompanying materials are licensed and made available under
10 the terms and conditions of the BSD License that accompanies this distribution.
11 The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php.
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Library/UefiRuntimeLib.h>
22 #include "FvbService.h"
24 extern FWB_GLOBAL mFvbModuleGlobal
;
27 Call back function on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
29 Fixup internal data so that the driver is callable in EFI runtime
30 in virtual mode. Convert the mFvbModuleGlobal date items to there
33 @param Event Event whose notification function is being invoked.
34 @param Context The context of the Notification context. Not used in
35 this call back function.
40 FvbVirtualddressChangeEvent (
45 EFI_FW_VOL_INSTANCE
*FwhInstance
;
49 // Convert the base address of all the instances.
51 for (Index
= 0; Index
< mFvbModuleGlobal
.NumFv
; Index
++) {
52 FwhInstance
= GetFvbInstance (Index
);
53 EfiConvertPointer (0, (VOID
**) &FwhInstance
->FvBase
);
56 EfiConvertPointer (0, (VOID
**) &mFvbModuleGlobal
.FvInstance
);
61 The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol
62 for each FV in the system.
64 @param[in] FwhInstance The pointer to a FW volume instance structure,
65 which contains the information about one FV.
66 @param[in] InstanceNum The instance number which can be used as a ID
67 to locate this FwhInstance in other functions.
74 IN EFI_FW_VOL_INSTANCE
*FwhInstance
,
78 EFI_FW_VOL_BLOCK_DEVICE
*FvbDevice
;
79 EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
;
82 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*OldFwbInterface
;
84 FvbDevice
= (EFI_FW_VOL_BLOCK_DEVICE
*) AllocateRuntimeCopyPool (
85 sizeof (EFI_FW_VOL_BLOCK_DEVICE
),
88 ASSERT (FvbDevice
!= NULL
);
90 FvbDevice
->Instance
= InstanceNum
;
91 FwVolHeader
= &FwhInstance
->VolumeHeader
;
94 // Set up the devicepath.
96 DEBUG ((EFI_D_INFO
, "FwBlockService.c: Setting up DevicePath for 0x%lx:\n", FwhInstance
->FvBase
));
97 if (FwVolHeader
->ExtHeaderOffset
== 0) {
99 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH.
101 FvbDevice
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH
), &mFvMemmapDevicePathTemplate
);
102 ((FV_MEMMAP_DEVICE_PATH
*) FvbDevice
->DevicePath
)->MemMapDevPath
.StartingAddress
= FwhInstance
->FvBase
;
103 ((FV_MEMMAP_DEVICE_PATH
*) FvbDevice
->DevicePath
)->MemMapDevPath
.EndingAddress
= FwhInstance
->FvBase
+ FwVolHeader
->FvLength
- 1;
105 FvbDevice
->DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH
), &mFvPIWGDevicePathTemplate
);
107 &((FV_PIWG_DEVICE_PATH
*)FvbDevice
->DevicePath
)->FvDevPath
.FvName
,
108 (GUID
*)(UINTN
)(FwhInstance
->FvBase
+ FwVolHeader
->ExtHeaderOffset
)
113 // Find a handle with a matching device path that has supports FW Block protocol.
115 Status
= gBS
->LocateDevicePath (
116 &gEfiFirmwareVolumeBlockProtocolGuid
,
117 &FvbDevice
->DevicePath
,
120 if (EFI_ERROR (Status
) ) {
122 // LocateDevicePath fails so install a new interface and device path.
124 DEBUG ((EFI_D_INFO
, "FwBlockService.c: LocateDevicePath failed, install new interface 0x%lx:\n", FwhInstance
->FvBase
));
126 Status
= gBS
->InstallMultipleProtocolInterfaces (
128 &gEfiFirmwareVolumeBlockProtocolGuid
,
129 &FvbDevice
->FwVolBlockInstance
,
130 &gEfiDevicePathProtocolGuid
,
131 FvbDevice
->DevicePath
,
134 ASSERT_EFI_ERROR (Status
);
135 DEBUG ((EFI_D_INFO
, "FwBlockService.c: IMPI FirmwareVolBlockProt, DevPath 0x%lx: %r\n", FwhInstance
->FvBase
, Status
));
137 } else if (IsDevicePathEnd (FvbDevice
->DevicePath
)) {
139 // Device allready exists, so reinstall the FVB protocol.
141 DEBUG ((EFI_D_ERROR
, "FwBlockService.c: LocateDevicePath succeeded, reinstall interface 0x%lx:\n", FwhInstance
->FvBase
));
142 Status
= gBS
->HandleProtocol (
144 &gEfiFirmwareVolumeBlockProtocolGuid
,
145 (VOID
**) &OldFwbInterface
147 ASSERT_EFI_ERROR (Status
);
149 Status
= gBS
->ReinstallProtocolInterface (
151 &gEfiFirmwareVolumeBlockProtocolGuid
,
153 &FvbDevice
->FwVolBlockInstance
155 ASSERT_EFI_ERROR (Status
);
159 // There was a FVB protocol on an End Device Path node.
168 The driver entry point for Firmware Volume Block Driver.
170 The function does the necessary initialization work for
171 Firmware Volume Block Driver.
173 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
174 @param[in] SystemTable A pointer to the EFI system table.
176 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
177 It will ASSERT on errors.
183 IN EFI_HANDLE ImageHandle
,
184 IN EFI_SYSTEM_TABLE
*SystemTable
190 Status
= gBS
->CreateEventEx (
193 FvbVirtualddressChangeEvent
,
195 &gEfiEventVirtualAddressChangeGuid
,
198 ASSERT_EFI_ERROR (Status
);