]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/FvbRuntimeDxe/FvbServiceDxe.c
Upload BSD-licensed Vlv2TbltDevicePkg and Vlv2DeviceRefCodePkg to
[mirror_edk2.git] / Vlv2TbltDevicePkg / FvbRuntimeDxe / FvbServiceDxe.c
1 /** @file
2 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) 2006 - 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 <PiDxe.h>
21 #include <Library/UefiRuntimeLib.h>
22 #include "FvbService.h"
23
24 extern FWB_GLOBAL mFvbModuleGlobal;
25
26 /**
27 Call back function on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
28
29 Fixup internal data so that the driver is callable in EFI runtime
30 in virtual mode. Convert the mFvbModuleGlobal date items to there
31 virtual address.
32
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.
36
37 **/
38 VOID
39 EFIAPI
40 FvbVirtualddressChangeEvent (
41 IN EFI_EVENT Event,
42 IN VOID *Context
43 )
44 {
45 EFI_FW_VOL_INSTANCE *FwhInstance;
46 UINTN Index;
47
48 //
49 // Convert the base address of all the instances.
50 //
51 for (Index = 0; Index < mFvbModuleGlobal.NumFv; Index++) {
52 FwhInstance = GetFvbInstance (Index);
53 EfiConvertPointer (0, (VOID **) &FwhInstance->FvBase);
54 }
55
56 EfiConvertPointer (0, (VOID **) &mFvbModuleGlobal.FvInstance);
57 }
58
59
60 /**
61 The function installs EFI_FIRMWARE_VOLUME_BLOCK protocol
62 for each FV in the system.
63
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.
68
69 @retval VOID
70
71 **/
72 VOID
73 InstallFvbProtocol (
74 IN EFI_FW_VOL_INSTANCE *FwhInstance,
75 IN UINTN InstanceNum
76 )
77 {
78 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
79 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
80 EFI_STATUS Status;
81 EFI_HANDLE FwbHandle;
82 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;
83
84 FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *) AllocateRuntimeCopyPool (
85 sizeof (EFI_FW_VOL_BLOCK_DEVICE),
86 &mFvbDeviceTemplate
87 );
88 ASSERT (FvbDevice != NULL);
89
90 FvbDevice->Instance = InstanceNum;
91 FwVolHeader = &FwhInstance->VolumeHeader;
92
93 //
94 // Set up the devicepath.
95 //
96 DEBUG ((EFI_D_INFO, "FwBlockService.c: Setting up DevicePath for 0x%lx:\n", FwhInstance->FvBase));
97 if (FwVolHeader->ExtHeaderOffset == 0) {
98 //
99 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH.
100 //
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;
104 } else {
105 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
106 CopyGuid (
107 &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,
108 (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset)
109 );
110 }
111
112 //
113 // Find a handle with a matching device path that has supports FW Block protocol.
114 //
115 Status = gBS->LocateDevicePath (
116 &gEfiFirmwareVolumeBlockProtocolGuid,
117 &FvbDevice->DevicePath,
118 &FwbHandle
119 );
120 if (EFI_ERROR (Status) ) {
121 //
122 // LocateDevicePath fails so install a new interface and device path.
123 //
124 DEBUG ((EFI_D_INFO, "FwBlockService.c: LocateDevicePath failed, install new interface 0x%lx:\n", FwhInstance->FvBase));
125 FwbHandle = NULL;
126 Status = gBS->InstallMultipleProtocolInterfaces (
127 &FwbHandle,
128 &gEfiFirmwareVolumeBlockProtocolGuid,
129 &FvbDevice->FwVolBlockInstance,
130 &gEfiDevicePathProtocolGuid,
131 FvbDevice->DevicePath,
132 NULL
133 );
134 ASSERT_EFI_ERROR (Status);
135 DEBUG ((EFI_D_INFO, "FwBlockService.c: IMPI FirmwareVolBlockProt, DevPath 0x%lx: %r\n", FwhInstance->FvBase, Status));
136
137 } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {
138 //
139 // Device allready exists, so reinstall the FVB protocol.
140 //
141 DEBUG ((EFI_D_ERROR, "FwBlockService.c: LocateDevicePath succeeded, reinstall interface 0x%lx:\n", FwhInstance->FvBase));
142 Status = gBS->HandleProtocol (
143 FwbHandle,
144 &gEfiFirmwareVolumeBlockProtocolGuid,
145 (VOID **) &OldFwbInterface
146 );
147 ASSERT_EFI_ERROR (Status);
148
149 Status = gBS->ReinstallProtocolInterface (
150 FwbHandle,
151 &gEfiFirmwareVolumeBlockProtocolGuid,
152 OldFwbInterface,
153 &FvbDevice->FwVolBlockInstance
154 );
155 ASSERT_EFI_ERROR (Status);
156
157 } else {
158 //
159 // There was a FVB protocol on an End Device Path node.
160 //
161 ASSERT (FALSE);
162 }
163
164 }
165
166
167 /**
168 The driver entry point for Firmware Volume Block Driver.
169
170 The function does the necessary initialization work for
171 Firmware Volume Block Driver.
172
173 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
174 @param[in] SystemTable A pointer to the EFI system table.
175
176 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
177 It will ASSERT on errors.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 DxeFvbInitialize (
183 IN EFI_HANDLE ImageHandle,
184 IN EFI_SYSTEM_TABLE *SystemTable
185 )
186 {
187 EFI_STATUS Status;
188 EFI_EVENT Event;
189
190 Status = gBS->CreateEventEx (
191 EVT_NOTIFY_SIGNAL,
192 TPL_NOTIFY,
193 FvbVirtualddressChangeEvent,
194 NULL,
195 &gEfiEventVirtualAddressChangeGuid,
196 &Event
197 );
198 ASSERT_EFI_ERROR (Status);
199
200 FvbInitialize ();
201
202 return EFI_SUCCESS;
203 }
204