\r
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
\r
- This program and the accompanying materials are licensed and made available\r
- under the terms and conditions of the BSD License which accompanies this\r
- distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
Module Name:\r
\r
**/\r
\r
//\r
-// The package level header files this module uses\r
-//\r
-#include <PiDxe.h>\r
-\r
-//\r
-// The protocols, PPI and GUID defintions for this module\r
+// The protocols, PPI and GUID definitions for this module\r
//\r
-#include <Guid/EventGroup.h>\r
-#include <Protocol/FirmwareVolumeBlock.h>\r
#include <Protocol/DevicePath.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
\r
//\r
// The Library classes this module consumes\r
//\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
#include <Library/BaseLib.h>\r
-#include <Library/DxeServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Library/DebugLib.h>\r
#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/DevicePathLib.h>\r
\r
#include "FwBlockService.h"\r
#include "QemuFlash.h"\r
};\r
\r
\r
-\r
-VOID\r
-EFIAPI\r
-FvbVirtualddressChangeEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
- Routine Description:\r
-\r
- Fixup internal data so that EFI and SAL can be call in virtual mode.\r
- Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
- date items to there virtual address.\r
-\r
- mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] - Physical copy of instance\r
- data\r
- mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] - Virtual pointer to common\r
- instance data.\r
-\r
- Arguments:\r
-\r
- (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
-\r
- Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- EFI_FW_VOL_INSTANCE *FwhInstance;\r
- UINTN Index;\r
-\r
- EfiConvertPointer (0x0,\r
- (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]);\r
-\r
- //\r
- // Convert the base address of all the instances\r
- //\r
- Index = 0;\r
- FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
- while (Index < mFvbModuleGlobal->NumFv) {\r
- EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]);\r
- FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
- (\r
- (UINTN) ((UINT8 *) FwhInstance) +\r
- FwhInstance->VolumeHeader.HeaderLength +\r
- (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
- );\r
- Index++;\r
- }\r
-\r
- EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
- QemuFlashConvertPointers ();\r
-}\r
-\r
EFI_STATUS\r
GetFvbInstance (\r
IN UINTN Instance,\r
IN ESAL_FWB_GLOBAL *Global,\r
- OUT EFI_FW_VOL_INSTANCE **FwhInstance,\r
- IN BOOLEAN Virtual\r
+ OUT EFI_FW_VOL_INSTANCE **FwhInstance\r
)\r
/*++\r
\r
returned\r
Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
instance data\r
- FwhInstance - The EFI_FW_VOL_INSTANCE fimrware instance structure\r
- Virtual - Whether CPU is in virtual or physical mode\r
+ FwhInstance - The EFI_FW_VOL_INSTANCE firmware instance structure\r
\r
Returns:\r
EFI_SUCCESS - Successfully returns\r
//\r
// Find the right instance of the FVB private data\r
//\r
- FwhRecord = Global->FvInstance[Virtual];\r
+ FwhRecord = Global->FvInstance;\r
while (Instance > 0) {\r
FwhRecord = (EFI_FW_VOL_INSTANCE *)\r
(\r
FvbGetPhysicalAddress (\r
IN UINTN Instance,\r
OUT EFI_PHYSICAL_ADDRESS *Address,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
address of the firmware volume.\r
Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
\r
Returns:\r
EFI_SUCCESS - Successfully returns\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
- *Address = FwhInstance->FvBase[Virtual];\r
+ *Address = FwhInstance->FvBase;\r
\r
return EFI_SUCCESS;\r
}\r
FvbGetVolumeAttributes (\r
IN UINTN Instance,\r
OUT EFI_FVB_ATTRIBUTES_2 *Attributes,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
Attributes - Output buffer which contains attributes\r
Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
\r
Returns:\r
EFI_SUCCESS - Successfully returns\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
*Attributes = FwhInstance->VolumeHeader.Attributes;\r
\r
OUT UINTN *LbaAddress,\r
OUT UINTN *LbaLength,\r
OUT UINTN *NumOfBlocks,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
BlockSize\r
Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
\r
Returns:\r
EFI_SUCCESS - Successfully returns\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
\r
StartLba = 0;\r
if (Lba >= StartLba && Lba < NextLba) {\r
Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength);\r
if (LbaAddress != NULL) {\r
- *LbaAddress = FwhInstance->FvBase[Virtual] + Offset;\r
+ *LbaAddress = FwhInstance->FvBase + Offset;\r
}\r
\r
if (LbaLength != NULL) {\r
FvbSetVolumeAttributes (\r
IN UINTN Instance,\r
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes,\r
- IN ESAL_FWB_GLOBAL *Global,\r
- IN BOOLEAN Virtual\r
+ IN ESAL_FWB_GLOBAL *Global\r
)\r
/*++\r
\r
of the firmware volume\r
Global - Pointer to ESAL_FWB_GLOBAL that contains all\r
instance data\r
- Virtual - Whether CPU is in virtual or physical mode\r
\r
Returns:\r
EFI_SUCCESS - Successfully returns\r
//\r
// Find the right instance of the FVB private data\r
//\r
- Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+ Status = GetFvbInstance (Instance, Global, &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
\r
AttribPtr =\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
return FvbGetPhysicalAddress (FvbDevice->Instance, Address,\r
- mFvbModuleGlobal, EfiGoneVirtual ());\r
+ mFvbModuleGlobal);\r
}\r
\r
EFI_STATUS\r
NULL,\r
BlockSize,\r
NumOfBlocks,\r
- mFvbModuleGlobal,\r
- EfiGoneVirtual ()\r
+ mFvbModuleGlobal\r
);\r
}\r
\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes,\r
- mFvbModuleGlobal, EfiGoneVirtual ());\r
+ mFvbModuleGlobal);\r
}\r
\r
EFI_STATUS\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes,\r
- mFvbModuleGlobal, EfiGoneVirtual ());\r
+ mFvbModuleGlobal);\r
}\r
\r
EFI_STATUS\r
FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
\r
Status = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal,\r
- &FwhInstance, EfiGoneVirtual ());\r
+ &FwhInstance);\r
ASSERT_EFI_ERROR (Status);\r
\r
NumOfBlocks = FwhInstance->NumOfBlocks;\r
break;\r
}\r
\r
- NumOfLba = VA_ARG (args, UINT32);\r
+ NumOfLba = VA_ARG (args, UINTN);\r
\r
//\r
// Check input parameters\r
break;\r
}\r
\r
- NumOfLba = VA_ARG (args, UINT32);\r
+ NumOfLba = VA_ARG (args, UINTN);\r
\r
while (NumOfLba > 0) {\r
Status = QemuFlashEraseBlock (StartingLba);\r
Writes data beginning at Lba:Offset from FV. The write terminates either\r
when *NumBytes of data have been written, or when a block boundary is\r
reached. *NumBytes is updated to reflect the actual number of bytes\r
- written. The write opertion does not include erase. This routine will\r
+ written. The write operation does not include erase. This routine will\r
attempt to write only the specified bytes. If the writes do not stick,\r
it will return an error.\r
\r
Reads data beginning at Lba:Offset from FV. The Read terminates either\r
when *NumBytes of data have been read, or when a block boundary is\r
reached. *NumBytes is updated to reflect the actual number of bytes\r
- written. The write opertion does not include erase. This routine will\r
+ written. The write operation does not include erase. This routine will\r
attempt to write only the specified bytes. If the writes do not stick,\r
it will return an error.\r
\r
return EFI_SUCCESS;\r
}\r
\r
-STATIC\r
-EFI_STATUS\r
-MarkMemoryRangeForRuntimeAccess (\r
- EFI_PHYSICAL_ADDRESS BaseAddress,\r
- UINTN Length\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Mark flash region as runtime memory\r
- //\r
- Status = gDS->RemoveMemorySpace (\r
- BaseAddress,\r
- Length\r
- );\r
-\r
- Status = gDS->AddMemorySpace (\r
- EfiGcdMemoryTypeSystemMemory,\r
- BaseAddress,\r
- Length,\r
- EFI_MEMORY_UC | EFI_MEMORY_RUNTIME\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Status = gBS->AllocatePages (\r
- AllocateAddress,\r
- EfiRuntimeServicesData,\r
- EFI_SIZE_TO_PAGES (Length),\r
- &BaseAddress\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return Status;\r
-}\r
-\r
STATIC\r
EFI_STATUS\r
InitializeVariableFvHeader (\r
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
UINT32 BufferSize;\r
EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;\r
- EFI_HANDLE FwbHandle;\r
EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;\r
UINT32 MaxLbaSize;\r
EFI_PHYSICAL_ADDRESS BaseAddress;\r
UINTN Length;\r
UINTN NumOfBlocks;\r
- EFI_EVENT VirtualAddressChangeEvent;\r
+ RETURN_STATUS PcdStatus;\r
\r
if (EFI_ERROR (QemuFlashInitialize ())) {\r
//\r
FwVolHeader->HeaderLength -\r
sizeof (EFI_FIRMWARE_VOLUME_HEADER)\r
);\r
+ mFvbModuleGlobal->FvInstance = AllocateRuntimePool (BufferSize);\r
+ ASSERT (mFvbModuleGlobal->FvInstance != NULL);\r
\r
- //\r
- // Only need to allocate once. There is only one copy of physical memory for\r
- // the private data of each FV instance. But in virtual mode or in physical\r
- // mode, the address of the the physical memory may be different.\r
- //\r
- mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] = AllocateRuntimePool (\r
- BufferSize);\r
- ASSERT (mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] != NULL);\r
-\r
- //\r
- // Make a virtual copy of the FvInstance pointer.\r
- //\r
- FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
- mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance;\r
+ FwhInstance = mFvbModuleGlobal->FvInstance;\r
\r
mFvbModuleGlobal->NumFv = 0;\r
MaxLbaSize = 0;\r
(EFI_FIRMWARE_VOLUME_HEADER *) (UINTN)\r
PcdGet32 (PcdOvmfFlashNvStorageVariableBase);\r
\r
- FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;\r
- FwhInstance->FvBase[FVB_VIRTUAL] = (UINTN) BaseAddress;\r
+ FwhInstance->FvBase = (UINTN) BaseAddress;\r
\r
CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader,\r
FwVolHeader->HeaderLength);\r
}\r
\r
//\r
- // Find a handle with a matching device path that has supports FW Block\r
- // protocol\r
+ // Module type specific hook.\r
//\r
- Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid,\r
- &FvbDevice->DevicePath, &FwbHandle);\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // LocateDevicePath fails so install a new interface and device path\r
- //\r
- FwbHandle = NULL;\r
- DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &FwbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- &FvbDevice->FwVolBlockInstance,\r
- &gEfiDevicePathProtocolGuid,\r
- FvbDevice->DevicePath,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
- //\r
- // Device already exists, so reinstall the FVB protocol\r
- //\r
- Status = gBS->HandleProtocol (\r
- FwbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- (VOID**)&OldFwbInterface\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
- Status = gBS->ReinstallProtocolInterface (\r
- FwbHandle,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- OldFwbInterface,\r
- &FvbDevice->FwVolBlockInstance\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- } else {\r
- //\r
- // There was a FVB protocol on an End Device Path node\r
- //\r
- ASSERT (FALSE);\r
- }\r
+ InstallProtocolInterfaces (FvbDevice);\r
\r
- MarkMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
+ MarkIoMemoryRangeForRuntimeAccess (BaseAddress, Length);\r
\r
- //\r
- // Set several PCD values to point to flash\r
- //\r
- PcdSet64 (\r
- PcdFlashNvStorageVariableBase64,\r
- (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase)\r
- );\r
- PcdSet32 (\r
- PcdFlashNvStorageFtwWorkingBase,\r
- PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase)\r
- );\r
- PcdSet32 (\r
- PcdFlashNvStorageFtwSpareBase,\r
- PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase)\r
- );\r
+ SetPcdFlashNvStorageBaseAddresses ();\r
\r
FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
(\r
(sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
);\r
\r
- VirtualAddressChangeEvent = NULL;\r
- Status = gBS->CreateEventEx (\r
- EVT_NOTIFY_SIGNAL,\r
- TPL_NOTIFY,\r
- FvbVirtualddressChangeEvent,\r
- NULL,\r
- &gEfiEventVirtualAddressChangeGuid,\r
- &VirtualAddressChangeEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
+ //\r
+ // Module type specific hook.\r
+ //\r
+ InstallVirtualAddressChangeHandler ();\r
\r
- PcdSetBool (PcdOvmfFlashVariablesEnable, TRUE);\r
+ PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE);\r
+ ASSERT_RETURN_ERROR (PcdStatus);\r
return EFI_SUCCESS;\r
}\r