]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/FvbRuntimeDxe/FvbServiceSmm.c
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / FvbRuntimeDxe / FvbServiceSmm.c
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 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.
13
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.
16
17
18 **/
19
20 #include <PiSmm.h>
21 #include <Library/SmmServicesTableLib.h>
22 #include "FvbSmmCommon.h"
23 #include "FvbService.h"
24
25 /**
26 The function installs EFI_SMM_FIRMWARE_VOLUME_BLOCK protocol
27 for each FV in the system.
28
29 @param[in] FwhInstance The pointer to a FW volume instance structure,
30 which contains the information about one FV.
31 @param[in] InstanceNum The instance number which can be used as a ID
32 to locate this FwhInstance in other functions.
33
34 @retval VOID
35
36 **/
37 VOID
38 InstallFvbProtocol (
39 IN EFI_FW_VOL_INSTANCE *FwhInstance,
40 IN UINTN InstanceNum
41 )
42 {
43 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
44 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
45 EFI_STATUS Status;
46 EFI_HANDLE FvbHandle;
47
48 FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *) AllocateRuntimeCopyPool (
49 sizeof (EFI_FW_VOL_BLOCK_DEVICE),
50 &mFvbDeviceTemplate
51 );
52 ASSERT (FvbDevice != NULL);
53
54 FvbDevice->Instance = InstanceNum;
55 FwVolHeader = &FwhInstance->VolumeHeader;
56
57 //
58 // Set up the devicepath.
59 //
60 if (FwVolHeader->ExtHeaderOffset == 0) {
61 //
62 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH.
63 //
64 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
65 ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = FwhInstance->FvBase;
66 ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress = FwhInstance->FvBase + FwVolHeader->FvLength - 1;
67 } else {
68 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
69 CopyGuid (
70 &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,
71 (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset)
72 );
73 }
74
75 //
76 // Install the SMM Firmware Volume Block Protocol and Device Path Protocol.
77 //
78 FvbHandle = NULL;
79 Status = gSmst->SmmInstallProtocolInterface (
80 &FvbHandle,
81 &gEfiSmmFirmwareVolumeBlockProtocolGuid,
82 EFI_NATIVE_INTERFACE,
83 &FvbDevice->FwVolBlockInstance
84 );
85 ASSERT_EFI_ERROR (Status);
86
87 Status = gSmst->SmmInstallProtocolInterface (
88 &FvbHandle,
89 &gEfiDevicePathProtocolGuid,
90 EFI_NATIVE_INTERFACE,
91 FvbDevice->DevicePath
92 );
93 ASSERT_EFI_ERROR (Status);
94
95 //
96 // Notify the Fvb wrapper driver SMM fvb is ready.
97 //
98 FvbHandle = NULL;
99 Status = gBS->InstallProtocolInterface (
100 &FvbHandle,
101 &gEfiSmmFirmwareVolumeBlockProtocolGuid,
102 EFI_NATIVE_INTERFACE,
103 &FvbDevice->FwVolBlockInstance
104 );
105 }
106
107
108 /**
109 The driver entry point for SMM Firmware Volume Block Driver.
110
111 The function does the necessary initialization work
112 Firmware Volume Block Driver.
113
114 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
115 @param[in] SystemTable A pointer to the EFI system table.
116
117 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
118 It will ASSERT on errors.
119
120 **/
121 EFI_STATUS
122 EFIAPI
123 FvbSmmInitialize (
124 IN EFI_HANDLE ImageHandle,
125 IN EFI_SYSTEM_TABLE *SystemTable
126 )
127 {
128 FvbInitialize ();
129
130 return EFI_SUCCESS;
131 }
132