From a656046171cd98600d4f6810f1d9f856aba19b6e Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 11 Mar 2021 22:16:41 +0100 Subject: [PATCH 3/4] ArmPlatformPkg/NorFlashDxe: populate FVB_ADDRESS_LIST When the SetVirtualAddressMap() handler runs, and we convert (among other things) the GetPhysicalAddress() FVB member function pointer, stash both the physical and the virtual addresses of this member function, in FVB_ADDRESS_LIST. Signed-off-by: Laszlo Ersek --- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf | 1 + ArmPlatformPkg/Drivers/NorFlashDxe/NorFlash.c | 27 ++++++++++++++++++-- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 11 ++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf index f8d4c2703143..1eba5f869c55 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.inf @@ -43,14 +43,15 @@ [LibraryClasses] [Guids] gEfiSystemNvDataFvGuid gEfiVariableGuid gEfiAuthenticatedVariableGuid gEfiEventVirtualAddressChangeGuid gEdkiiNvVarStoreFormattedGuid ## PRODUCES ## PROTOCOL + gEdkiiFvbAddressListGuid [Protocols] gEfiBlockIoProtocolGuid gEfiDevicePathProtocolGuid gEfiFirmwareVolumeBlockProtocolGuid gEfiDiskIoProtocolGuid diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlash.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlash.c index a9e23db4461b..73faca549bda 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlash.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlash.c @@ -3,23 +3,25 @@ Copyright (c) 2011 - 2020, Arm Limited. All rights reserved.
Copyright (c) 2020, Linaro, Ltd. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include #include "NorFlash.h" // // Global variable declarations // extern NOR_FLASH_INSTANCE **mNorFlashInstances; extern UINT32 mNorFlashDeviceCount; +extern FVB_ADDRESS_LIST *mFvbAddressList; UINT32 NorFlashReadStatusRegister ( IN NOR_FLASH_INSTANCE *Instance, IN UINTN SR_Address ) { @@ -939,35 +941,56 @@ NorFlashReset ( VOID EFIAPI NorFlashVirtualNotifyEvent ( IN EFI_EVENT Event, IN VOID *Context ) { - UINTN Index; + UINT64 OwnerSignature; + FVB_ADDRESS_LIST_ENTRY *Entry; + UINTN Index; + + OwnerSignature = SIGNATURE_64 ('N', 'O', 'R', 'F', 'L', 'A', 'S', 'H'); + Entry = mFvbAddressList->Entry + mFvbAddressList->Next; for (Index = 0; Index < mNorFlashDeviceCount; Index++) { + VOID *Pointer; + EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->DeviceBaseAddress); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->RegionBaseAddress); // Convert BlockIo protocol EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.Reset); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks); // Convert Fvb EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize); - EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress); + + Pointer = (VOID *)(UINTN)mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress; + Entry->OwnerSignature = OwnerSignature; + Entry->Address = (UINTN)Pointer; + ++Entry; + + EfiConvertPointer (0x0, &Pointer); + mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress = + (EFI_FVB_GET_PHYSICAL_ADDRESS)(UINTN)Pointer; + + Entry->OwnerSignature = OwnerSignature; + Entry->Address = (UINTN)Pointer; + ++Entry; + EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Read); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes); EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Write); if (mNorFlashInstances[Index]->ShadowBuffer != NULL) { EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->ShadowBuffer); } } + mFvbAddressList->Next = Entry - mFvbAddressList->Entry; return; } diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c index f412731200cf..fad0b8c39723 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -2,14 +2,15 @@ Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include #include #include #include #include #include #include @@ -21,14 +22,16 @@ STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent; // // Global variable declarations // NOR_FLASH_INSTANCE **mNorFlashInstances; UINT32 mNorFlashDeviceCount; UINTN mFlashNvStorageVariableBase; EFI_EVENT mFvbVirtualAddrChangeEvent; +FVB_ADDRESS_LIST *mFvbAddressList; + NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = { NOR_FLASH_SIGNATURE, // Signature NULL, // Handle ... NEED TO BE FILLED 0, // DeviceBaseAddress ... NEED TO BE FILLED 0, // RegionBaseAddress ... NEED TO BE FILLED @@ -318,19 +321,27 @@ NorFlashWriteFullBlock ( EFI_STATUS EFIAPI NorFlashInitialise ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { + VOID *Hob; + FVB_ADDRESS_LIST_PTR *FvbAddressListPtrHobData; EFI_STATUS Status; UINT32 Index; NOR_FLASH_DESCRIPTION* NorFlashDevices; BOOLEAN ContainVariableStorage; + Hob = GetFirstGuidHob (&gEdkiiFvbAddressListGuid); + ASSERT (Hob != NULL); + FvbAddressListPtrHobData = GET_GUID_HOB_DATA (Hob); + mFvbAddressList = (VOID*)(UINTN)*FvbAddressListPtrHobData; + ASSERT (mFvbAddressList->Signature == FVB_ADDRESS_LIST_SIGNATURE); + Status = NorFlashPlatformInitialization (); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n")); return Status; } Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount); -- 2.19.1.3.g30247aa5d201