X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=OvmfPkg%2FQemuFlashFvbServicesRuntimeDxe%2FFwBlockService.c;h=b3f428bb4284c9f4c7ea4cfe4fc3687ae8abc1e3;hp=3e7fe6808169c1ffa2291f880bef2e276e27dfcd;hb=966363d5a34839399e3d9f68d4f4efb4b1a9ec66;hpb=a05aff56554f4ff74629d13db92260d504f8cb5b diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c index 3e7fe68081..b3f428bb42 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c @@ -20,31 +20,22 @@ **/ -// -// The package level header files this module uses -// -#include - // // The protocols, PPI and GUID defintions for this module // -#include -#include #include +#include // // The Library classes this module consumes // -#include -#include #include -#include -#include -#include #include +#include +#include +#include #include #include -#include #include "FwBlockService.h" #include "QemuFlash.h" @@ -117,70 +108,11 @@ EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = { }; - -VOID -EFIAPI -FvbVirtualddressChangeEvent ( - IN EFI_EVENT Event, - IN VOID *Context - ) -/*++ - - Routine Description: - - Fixup internal data so that EFI and SAL can be call in virtual mode. - Call the passed in Child Notify event and convert the mFvbModuleGlobal - date items to there virtual address. - - mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] - Physical copy of instance - data - mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] - Virtual pointer to common - instance data. - - Arguments: - - (Standard EFI notify event - EFI_EVENT_NOTIFY) - - Returns: - - None - ---*/ -{ - EFI_FW_VOL_INSTANCE *FwhInstance; - UINTN Index; - - EfiConvertPointer (0x0, - (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]); - - // - // Convert the base address of all the instances - // - Index = 0; - FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]; - while (Index < mFvbModuleGlobal->NumFv) { - EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]); - FwhInstance = (EFI_FW_VOL_INSTANCE *) - ( - (UINTN) ((UINT8 *) FwhInstance) + - FwhInstance->VolumeHeader.HeaderLength + - (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) - ); - Index++; - } - - EfiConvertPointer (0x0, - (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]); - EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal); - QemuFlashConvertPointers (); -} - EFI_STATUS GetFvbInstance ( IN UINTN Instance, IN ESAL_FWB_GLOBAL *Global, - OUT EFI_FW_VOL_INSTANCE **FwhInstance, - IN BOOLEAN Virtual + OUT EFI_FW_VOL_INSTANCE **FwhInstance ) /*++ @@ -193,7 +125,6 @@ GetFvbInstance ( Global - Pointer to ESAL_FWB_GLOBAL that contains all instance data FwhInstance - The EFI_FW_VOL_INSTANCE fimrware instance structure - Virtual - Whether CPU is in virtual or physical mode Returns: EFI_SUCCESS - Successfully returns @@ -210,7 +141,7 @@ GetFvbInstance ( // // Find the right instance of the FVB private data // - FwhRecord = Global->FvInstance[Virtual]; + FwhRecord = Global->FvInstance; while (Instance > 0) { FwhRecord = (EFI_FW_VOL_INSTANCE *) ( @@ -229,8 +160,7 @@ EFI_STATUS FvbGetPhysicalAddress ( IN UINTN Instance, OUT EFI_PHYSICAL_ADDRESS *Address, - IN ESAL_FWB_GLOBAL *Global, - IN BOOLEAN Virtual + IN ESAL_FWB_GLOBAL *Global ) /*++ @@ -245,7 +175,6 @@ FvbGetPhysicalAddress ( address of the firmware volume. Global - Pointer to ESAL_FWB_GLOBAL that contains all instance data - Virtual - Whether CPU is in virtual or physical mode Returns: EFI_SUCCESS - Successfully returns @@ -259,9 +188,9 @@ FvbGetPhysicalAddress ( // // Find the right instance of the FVB private data // - Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual); + Status = GetFvbInstance (Instance, Global, &FwhInstance); ASSERT_EFI_ERROR (Status); - *Address = FwhInstance->FvBase[Virtual]; + *Address = FwhInstance->FvBase; return EFI_SUCCESS; } @@ -270,8 +199,7 @@ EFI_STATUS FvbGetVolumeAttributes ( IN UINTN Instance, OUT EFI_FVB_ATTRIBUTES_2 *Attributes, - IN ESAL_FWB_GLOBAL *Global, - IN BOOLEAN Virtual + IN ESAL_FWB_GLOBAL *Global ) /*++ @@ -285,7 +213,6 @@ FvbGetVolumeAttributes ( Attributes - Output buffer which contains attributes Global - Pointer to ESAL_FWB_GLOBAL that contains all instance data - Virtual - Whether CPU is in virtual or physical mode Returns: EFI_SUCCESS - Successfully returns @@ -299,7 +226,7 @@ FvbGetVolumeAttributes ( // // Find the right instance of the FVB private data // - Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual); + Status = GetFvbInstance (Instance, Global, &FwhInstance); ASSERT_EFI_ERROR (Status); *Attributes = FwhInstance->VolumeHeader.Attributes; @@ -313,8 +240,7 @@ FvbGetLbaAddress ( OUT UINTN *LbaAddress, OUT UINTN *LbaLength, OUT UINTN *NumOfBlocks, - IN ESAL_FWB_GLOBAL *Global, - IN BOOLEAN Virtual + IN ESAL_FWB_GLOBAL *Global ) /*++ @@ -333,7 +259,6 @@ FvbGetLbaAddress ( BlockSize Global - Pointer to ESAL_FWB_GLOBAL that contains all instance data - Virtual - Whether CPU is in virtual or physical mode Returns: EFI_SUCCESS - Successfully returns @@ -353,7 +278,7 @@ FvbGetLbaAddress ( // // Find the right instance of the FVB private data // - Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual); + Status = GetFvbInstance (Instance, Global, &FwhInstance); ASSERT_EFI_ERROR (Status); StartLba = 0; @@ -379,7 +304,7 @@ FvbGetLbaAddress ( if (Lba >= StartLba && Lba < NextLba) { Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength); if (LbaAddress != NULL) { - *LbaAddress = FwhInstance->FvBase[Virtual] + Offset; + *LbaAddress = FwhInstance->FvBase + Offset; } if (LbaLength != NULL) { @@ -403,8 +328,7 @@ EFI_STATUS FvbSetVolumeAttributes ( IN UINTN Instance, IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes, - IN ESAL_FWB_GLOBAL *Global, - IN BOOLEAN Virtual + IN ESAL_FWB_GLOBAL *Global ) /*++ @@ -421,7 +345,6 @@ FvbSetVolumeAttributes ( of the firmware volume Global - Pointer to ESAL_FWB_GLOBAL that contains all instance data - Virtual - Whether CPU is in virtual or physical mode Returns: EFI_SUCCESS - Successfully returns @@ -444,7 +367,7 @@ FvbSetVolumeAttributes ( // // Find the right instance of the FVB private data // - Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual); + Status = GetFvbInstance (Instance, Global, &FwhInstance); ASSERT_EFI_ERROR (Status); AttribPtr = @@ -564,7 +487,7 @@ FvbProtocolGetPhysicalAddress ( FvbDevice = FVB_DEVICE_FROM_THIS (This); return FvbGetPhysicalAddress (FvbDevice->Instance, Address, - mFvbModuleGlobal, EfiGoneVirtual ()); + mFvbModuleGlobal); } EFI_STATUS @@ -606,8 +529,7 @@ FvbProtocolGetBlockSize ( NULL, BlockSize, NumOfBlocks, - mFvbModuleGlobal, - EfiGoneVirtual () + mFvbModuleGlobal ); } @@ -636,7 +558,7 @@ FvbProtocolGetAttributes ( FvbDevice = FVB_DEVICE_FROM_THIS (This); return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, - mFvbModuleGlobal, EfiGoneVirtual ()); + mFvbModuleGlobal); } EFI_STATUS @@ -664,7 +586,7 @@ FvbProtocolSetAttributes ( FvbDevice = FVB_DEVICE_FROM_THIS (This); return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, - mFvbModuleGlobal, EfiGoneVirtual ()); + mFvbModuleGlobal); } EFI_STATUS @@ -710,7 +632,7 @@ FvbProtocolEraseBlocks ( FvbDevice = FVB_DEVICE_FROM_THIS (This); Status = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal, - &FwhInstance, EfiGoneVirtual ()); + &FwhInstance); ASSERT_EFI_ERROR (Status); NumOfBlocks = FwhInstance->NumOfBlocks; @@ -723,7 +645,7 @@ FvbProtocolEraseBlocks ( break; } - NumOfLba = VA_ARG (args, UINT32); + NumOfLba = VA_ARG (args, UINTN); // // Check input parameters @@ -743,7 +665,7 @@ FvbProtocolEraseBlocks ( break; } - NumOfLba = VA_ARG (args, UINT32); + NumOfLba = VA_ARG (args, UINTN); while (NumOfLba > 0) { Status = QemuFlashEraseBlock (StartingLba); @@ -909,12 +831,13 @@ ValidateFvHeader ( STATIC EFI_STATUS -MarkMemoryRangeForRuntimeAccess ( +MarkIoMemoryRangeForRuntimeAccess ( EFI_PHYSICAL_ADDRESS BaseAddress, UINTN Length ) { EFI_STATUS Status; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; // // Mark flash region as runtime memory @@ -925,18 +848,31 @@ MarkMemoryRangeForRuntimeAccess ( ); Status = gDS->AddMemorySpace ( - EfiGcdMemoryTypeSystemMemory, + EfiGcdMemoryTypeMemoryMappedIo, BaseAddress, Length, EFI_MEMORY_UC | EFI_MEMORY_RUNTIME ); ASSERT_EFI_ERROR (Status); - Status = gBS->AllocatePages ( - AllocateAddress, - EfiRuntimeServicesData, - EFI_SIZE_TO_PAGES (Length), - &BaseAddress + Status = gDS->AllocateMemorySpace ( + EfiGcdAllocateAddress, + EfiGcdMemoryTypeMemoryMappedIo, + 0, + Length, + &BaseAddress, + gImageHandle, + NULL + ); + ASSERT_EFI_ERROR (Status); + + Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor); + ASSERT_EFI_ERROR (Status); + + Status = gDS->SetMemorySpaceAttributes ( + BaseAddress, + Length, + GcdDescriptor.Attributes | EFI_MEMORY_RUNTIME ); ASSERT_EFI_ERROR (Status); @@ -1038,14 +974,12 @@ FvbInitialize ( EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; UINT32 BufferSize; EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry; - EFI_HANDLE FwbHandle; EFI_FW_VOL_BLOCK_DEVICE *FvbDevice; - EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface; UINT32 MaxLbaSize; EFI_PHYSICAL_ADDRESS BaseAddress; UINTN Length; UINTN NumOfBlocks; - EFI_EVENT VirtualAddressChangeEvent; + RETURN_STATUS PcdStatus; if (EFI_ERROR (QemuFlashInitialize ())) { // @@ -1090,21 +1024,10 @@ FvbInitialize ( FwVolHeader->HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER) ); + mFvbModuleGlobal->FvInstance = AllocateRuntimePool (BufferSize); + ASSERT (mFvbModuleGlobal->FvInstance != NULL); - // - // Only need to allocate once. There is only one copy of physical memory for - // the private data of each FV instance. But in virtual mode or in physical - // mode, the address of the the physical memory may be different. - // - mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] = AllocateRuntimePool ( - BufferSize); - ASSERT (mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] != NULL); - - // - // Make a virtual copy of the FvInstance pointer. - // - FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]; - mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance; + FwhInstance = mFvbModuleGlobal->FvInstance; mFvbModuleGlobal->NumFv = 0; MaxLbaSize = 0; @@ -1113,8 +1036,7 @@ FvbInitialize ( (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase); - FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress; - FwhInstance->FvBase[FVB_VIRTUAL] = (UINTN) BaseAddress; + FwhInstance->FvBase = (UINTN) BaseAddress; CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader, FwVolHeader->HeaderLength); @@ -1179,69 +1101,30 @@ FvbInitialize ( } // - // Find a handle with a matching device path that has supports FW Block - // protocol + // Module type specific hook. // - Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, - &FvbDevice->DevicePath, &FwbHandle); - if (EFI_ERROR (Status)) { - // - // LocateDevicePath fails so install a new interface and device path - // - FwbHandle = NULL; - DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n")); - Status = gBS->InstallMultipleProtocolInterfaces ( - &FwbHandle, - &gEfiFirmwareVolumeBlockProtocolGuid, - &FvbDevice->FwVolBlockInstance, - &gEfiDevicePathProtocolGuid, - FvbDevice->DevicePath, - NULL - ); - ASSERT_EFI_ERROR (Status); - } else if (IsDevicePathEnd (FvbDevice->DevicePath)) { - // - // Device already exists, so reinstall the FVB protocol - // - Status = gBS->HandleProtocol ( - FwbHandle, - &gEfiFirmwareVolumeBlockProtocolGuid, - (VOID**)&OldFwbInterface - ); - ASSERT_EFI_ERROR (Status); + InstallProtocolInterfaces (FvbDevice); - DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n")); - Status = gBS->ReinstallProtocolInterface ( - FwbHandle, - &gEfiFirmwareVolumeBlockProtocolGuid, - OldFwbInterface, - &FvbDevice->FwVolBlockInstance - ); - ASSERT_EFI_ERROR (Status); - } else { - // - // There was a FVB protocol on an End Device Path node - // - ASSERT (FALSE); - } - - MarkMemoryRangeForRuntimeAccess (BaseAddress, Length); + MarkIoMemoryRangeForRuntimeAccess (BaseAddress, Length); // // Set several PCD values to point to flash // - PcdSet64 ( + PcdStatus = PcdSet64S ( PcdFlashNvStorageVariableBase64, (UINTN) PcdGet32 (PcdOvmfFlashNvStorageVariableBase) ); - PcdSet32 ( + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus = PcdSet32S ( PcdFlashNvStorageFtwWorkingBase, PcdGet32 (PcdOvmfFlashNvStorageFtwWorkingBase) ); - PcdSet32 ( + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus = PcdSet32S ( PcdFlashNvStorageFtwSpareBase, PcdGet32 (PcdOvmfFlashNvStorageFtwSpareBase) ); + ASSERT_RETURN_ERROR (PcdStatus); FwhInstance = (EFI_FW_VOL_INSTANCE *) ( @@ -1249,17 +1132,12 @@ FvbInitialize ( (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER)) ); - VirtualAddressChangeEvent = NULL; - Status = gBS->CreateEventEx ( - EVT_NOTIFY_SIGNAL, - TPL_NOTIFY, - FvbVirtualddressChangeEvent, - NULL, - &gEfiEventVirtualAddressChangeGuid, - &VirtualAddressChangeEvent - ); - ASSERT_EFI_ERROR (Status); + // + // Module type specific hook. + // + InstallVirtualAddressChangeHandler (); - PcdSetBool (PcdOvmfFlashVariablesEnable, TRUE); + PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE); + ASSERT_RETURN_ERROR (PcdStatus); return EFI_SUCCESS; }