1 /** @file 2 SMM Firmware Volume Block Driver for Lakeport Platform. 3 4 Firmware volume block driver for FWH or SPI device. 5 It depends on which Flash Device Library to be linked with this driver. 6 7 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR> 8 9 10 This program and the accompanying materials are licensed and made available under 11 12 the terms and conditions of the BSD License that accompanies this distribution. 13 14 The full text of the license may be found at 15 16 http://opensource.org/licenses/bsd-license.php. 17 18 19 20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 21 22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 23 24 25 26 27 **/ 28 29 #include <PiSmm.h> 30 #include <Library/SmmServicesTableLib.h> 31 #include "FvbSmmCommon.h" 32 #include "FvbService.h" 33 34 /** 35 The function installs EFI_SMM_FIRMWARE_VOLUME_BLOCK protocol 36 for each FV in the system. 37 InstallFvbProtocol(IN EFI_FW_VOL_INSTANCE * FwhInstance,IN UINTN InstanceNum)38 @param[in] FwhInstance The pointer to a FW volume instance structure, 39 which contains the information about one FV. 40 @param[in] InstanceNum The instance number which can be used as a ID 41 to locate this FwhInstance in other functions. 42 43 @retval VOID 44 45 **/ 46 VOID 47 InstallFvbProtocol ( 48 IN EFI_FW_VOL_INSTANCE *FwhInstance, 49 IN UINTN InstanceNum 50 ) 51 { 52 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; 53 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; 54 EFI_STATUS Status; 55 EFI_HANDLE FvbHandle; 56 57 FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *) AllocateRuntimeCopyPool ( 58 sizeof (EFI_FW_VOL_BLOCK_DEVICE), 59 &mFvbDeviceTemplate 60 ); 61 ASSERT (FvbDevice != NULL); 62 63 FvbDevice->Instance = InstanceNum; 64 FwVolHeader = &FwhInstance->VolumeHeader; 65 66 // 67 // Set up the devicepath. 68 // 69 if (FwVolHeader->ExtHeaderOffset == 0) { 70 // 71 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH. 72 // 73 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate); 74 ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = FwhInstance->FvBase; 75 ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress = FwhInstance->FvBase + FwVolHeader->FvLength - 1; 76 } else { 77 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate); 78 CopyGuid ( 79 &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName, 80 (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset) 81 ); 82 } 83 84 // 85 // Install the SMM Firmware Volume Block Protocol and Device Path Protocol. 86 // 87 FvbHandle = NULL; 88 Status = gSmst->SmmInstallProtocolInterface ( 89 &FvbHandle, 90 &gEfiSmmFirmwareVolumeBlockProtocolGuid, 91 EFI_NATIVE_INTERFACE, 92 &FvbDevice->FwVolBlockInstance 93 ); 94 ASSERT_EFI_ERROR (Status); 95 96 Status = gSmst->SmmInstallProtocolInterface ( 97 &FvbHandle, 98 &gEfiDevicePathProtocolGuid, 99 EFI_NATIVE_INTERFACE, 100 FvbDevice->DevicePath 101 ); 102 ASSERT_EFI_ERROR (Status); 103 104 // 105 // Notify the Fvb wrapper driver SMM fvb is ready. 106 // 107 FvbHandle = NULL; 108 Status = gBS->InstallProtocolInterface ( 109 &FvbHandle, 110 &gEfiSmmFirmwareVolumeBlockProtocolGuid, 111 EFI_NATIVE_INTERFACE, 112 &FvbDevice->FwVolBlockInstance 113 ); 114 } 115 116 117 /** 118 The driver entry point for SMM Firmware Volume Block Driver. 119 120 The function does the necessary initialization work 121 Firmware Volume Block Driver. 122 FvbSmmInitialize(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)123 @param[in] ImageHandle The firmware allocated handle for the UEFI image. 124 @param[in] SystemTable A pointer to the EFI system table. 125 126 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS. 127 It will ASSERT on errors. 128 129 **/ 130 EFI_STATUS 131 EFIAPI 132 FvbSmmInitialize ( 133 IN EFI_HANDLE ImageHandle, 134 IN EFI_SYSTEM_TABLE *SystemTable 135 ) 136 { 137 FvbInitialize (); 138 139 return EFI_SUCCESS; 140 } 141 142