2 Functions related to the Firmware Volume Block service whose
3 implementation is specific to the runtime DXE driver build.
5 Copyright (C) 2015, Red Hat, Inc.
6 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Guid/EventGroup.h>
18 #include <Library/DebugLib.h>
19 #include <Library/DevicePathLib.h>
20 #include <Library/DxeServicesTableLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/UefiRuntimeLib.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/FirmwareVolumeBlock.h>
27 #include "FwBlockService.h"
28 #include "QemuFlash.h"
31 InstallProtocolInterfaces (
32 IN EFI_FW_VOL_BLOCK_DEVICE
*FvbDevice
37 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL
*OldFwbInterface
;
39 ASSERT (!FeaturePcdGet (PcdSmmSmramRequire
));
42 // Find a handle with a matching device path that has supports FW Block
45 Status
= gBS
->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid
,
46 &FvbDevice
->DevicePath
, &FwbHandle
);
47 if (EFI_ERROR (Status
)) {
49 // LocateDevicePath fails so install a new interface and device path
52 DEBUG ((EFI_D_INFO
, "Installing QEMU flash FVB\n"));
53 Status
= gBS
->InstallMultipleProtocolInterfaces (
55 &gEfiFirmwareVolumeBlockProtocolGuid
,
56 &FvbDevice
->FwVolBlockInstance
,
57 &gEfiDevicePathProtocolGuid
,
58 FvbDevice
->DevicePath
,
61 ASSERT_EFI_ERROR (Status
);
62 } else if (IsDevicePathEnd (FvbDevice
->DevicePath
)) {
64 // Device already exists, so reinstall the FVB protocol
66 Status
= gBS
->HandleProtocol (
68 &gEfiFirmwareVolumeBlockProtocolGuid
,
69 (VOID
**)&OldFwbInterface
71 ASSERT_EFI_ERROR (Status
);
73 DEBUG ((EFI_D_INFO
, "Reinstalling FVB for QEMU flash region\n"));
74 Status
= gBS
->ReinstallProtocolInterface (
76 &gEfiFirmwareVolumeBlockProtocolGuid
,
78 &FvbDevice
->FwVolBlockInstance
80 ASSERT_EFI_ERROR (Status
);
83 // There was a FVB protocol on an End Device Path node
93 FvbVirtualAddressChangeEvent (
101 Fixup internal data so that EFI and SAL can be call in virtual mode.
102 Call the passed in Child Notify event and convert the mFvbModuleGlobal
103 date items to there virtual address.
107 (Standard EFI notify event - EFI_EVENT_NOTIFY)
115 EFI_FW_VOL_INSTANCE
*FwhInstance
;
118 FwhInstance
= mFvbModuleGlobal
->FvInstance
;
119 EfiConvertPointer (0x0, (VOID
**) &mFvbModuleGlobal
->FvInstance
);
122 // Convert the base address of all the instances
125 while (Index
< mFvbModuleGlobal
->NumFv
) {
126 EfiConvertPointer (0x0, (VOID
**) &FwhInstance
->FvBase
);
127 FwhInstance
= (EFI_FW_VOL_INSTANCE
*)
129 (UINTN
) ((UINT8
*) FwhInstance
) +
130 FwhInstance
->VolumeHeader
.HeaderLength
+
131 (sizeof (EFI_FW_VOL_INSTANCE
) - sizeof (EFI_FIRMWARE_VOLUME_HEADER
))
136 EfiConvertPointer (0x0, (VOID
**) &mFvbModuleGlobal
);
137 QemuFlashConvertPointers ();
142 InstallVirtualAddressChangeHandler (
147 EFI_EVENT VirtualAddressChangeEvent
;
149 Status
= gBS
->CreateEventEx (
152 FvbVirtualAddressChangeEvent
,
154 &gEfiEventVirtualAddressChangeGuid
,
155 &VirtualAddressChangeEvent
157 ASSERT_EFI_ERROR (Status
);
161 MarkIoMemoryRangeForRuntimeAccess (
162 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
167 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor
;
170 // Mark flash region as runtime memory
172 Status
= gDS
->RemoveMemorySpace (
177 Status
= gDS
->AddMemorySpace (
178 EfiGcdMemoryTypeMemoryMappedIo
,
181 EFI_MEMORY_UC
| EFI_MEMORY_RUNTIME
183 ASSERT_EFI_ERROR (Status
);
185 Status
= gDS
->AllocateMemorySpace (
186 EfiGcdAllocateAddress
,
187 EfiGcdMemoryTypeMemoryMappedIo
,
194 ASSERT_EFI_ERROR (Status
);
196 Status
= gDS
->GetMemorySpaceDescriptor (BaseAddress
, &GcdDescriptor
);
197 ASSERT_EFI_ERROR (Status
);
199 Status
= gDS
->SetMemorySpaceAttributes (
202 GcdDescriptor
.Attributes
| EFI_MEMORY_RUNTIME
204 ASSERT_EFI_ERROR (Status
);