From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.101.70; helo=foss.arm.com; envelope-from=jagadeesh.ujja@arm.com; receiver=edk2-devel@lists.01.org Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id 2955A2117FD47 for ; Wed, 31 Oct 2018 04:10:08 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8021180D for ; Wed, 31 Oct 2018 04:10:08 -0700 (PDT) Received: from usa.arm.com (a75556-lin.blr.arm.com [10.162.2.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B4EDF3F71D for ; Wed, 31 Oct 2018 04:10:07 -0700 (PDT) From: Jagadeesh Ujja To: edk2-devel@lists.01.org Date: Wed, 31 Oct 2018 16:39:40 +0530 Message-Id: <20181031110947.6305-3-jagadeesh.ujja@arm.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181031110947.6305-1-jagadeesh.ujja@arm.com> References: <20181031110947.6305-1-jagadeesh.ujja@arm.com> MIME-Version: 1.0 Subject: [RFC PATCH 2/9] ArmPlatformPkg/NorFlashDxe: allow reusability as a MM driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 X-List-Received-Date: Wed, 31 Oct 2018 11:10:09 -0000 Content-Transfer-Encoding: 8bit Adapt the NorFlashDxe driver to be used as a MM_STANDALONE driver to allow access to NOR flash for code executing in MM_STANDALONE mode. This allows storing of EFI variables on NOR flash which is accessible only via the MM STANDALONE mode software. Change-Id: I289f439f6710cf53dfe073e1776dd4f438dff3d4 Signed-off-by: Jagadeesh Ujja --- .../Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 5 +- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 116 ++++++++++++++++++--- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h | 15 ++- .../Drivers/NorFlashDxe/NorFlashFvbDxe.c | 26 +++-- .../Drivers/NorFlashDxe/NorFlashMmStandalone.inf | 76 ++++++++++++++ 5 files changed, 214 insertions(+), 24 deletions(-) create mode 100644 ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c index 279b77c..38363a4 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c @@ -1,6 +1,6 @@ /** @file NorFlashBlockIoDxe.c - Copyright (c) 2011-2013, ARM Ltd. All rights reserved.
+ Copyright (c) 2011-2018, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -13,8 +13,9 @@ **/ #include +#ifndef MM_STANDALONE #include - +#endif #include "NorFlashDxe.h" // diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c index 46e815b..eb8ae4e 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -1,6 +1,6 @@ /** @file NorFlashDxe.c - Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2018, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -15,12 +15,16 @@ #include #include #include -#include #include - +#ifndef MM_STANDALONE +#include +#endif #include "NorFlashDxe.h" - +#ifndef MM_STANDALONE STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent; +#else +EFI_MM_SYSTEM_TABLE *mMmst = NULL; +#endif // // Global variable declarations @@ -134,7 +138,7 @@ NorFlashCreateInstance ( if (SupportFvb) { NorFlashFvbInitialize (Instance); - +#ifndef MM_STANDALONE Status = gBS->InstallMultipleProtocolInterfaces ( &Instance->Handle, &gEfiDevicePathProtocolGuid, &Instance->DevicePath, @@ -146,7 +150,44 @@ NorFlashCreateInstance ( FreePool (Instance); return Status; } +#else + //Install DevicePath Protocol + Status = mMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiDevicePathProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->DevicePath + ); + if (EFI_ERROR(Status)) { + FreePool (Instance); + return Status; + } + //Install BlockIo Protocol + Status = mMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiBlockIoProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->BlockIoProtocol + ); + if (EFI_ERROR(Status)) { + FreePool (Instance); + return Status; + } + + //Install FirmwareVolumeBlock Protocol + Status = mMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiSmmFirmwareVolumeBlockProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->FvbProtocol + ); + if (EFI_ERROR(Status)) { + FreePool (Instance); + return Status; + } +#endif } else { +#ifndef MM_STANDALONE Status = gBS->InstallMultipleProtocolInterfaces ( &Instance->Handle, &gEfiDevicePathProtocolGuid, &Instance->DevicePath, @@ -158,6 +199,42 @@ NorFlashCreateInstance ( FreePool (Instance); return Status; } +#else + //Install DevicePath Protocol + Status = mMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiDevicePathProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->DevicePath + ); + if (EFI_ERROR(Status)) { + FreePool (Instance); + return Status; + } + //Install BlockIo Protocol + Status = mMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiBlockIoProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->BlockIoProtocol + ); + if (EFI_ERROR(Status)) { + FreePool (Instance); + return Status; + } + + //Install DiskIO Protocol + Status = mMmst->MmInstallProtocolInterface ( + &Instance->Handle, + &gEfiDiskIoProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance->DiskIoProtocol + ); + if (EFI_ERROR(Status)) { + FreePool (Instance); + return Status; + } +#endif } *NorFlashInstance = Instance; @@ -336,6 +413,7 @@ NorFlashUnlockAndEraseSingleBlock ( { EFI_STATUS Status; UINTN Index; +#ifndef MM_STANDALONE EFI_TPL OriginalTPL; if (!EfiAtRuntime ()) { @@ -346,7 +424,7 @@ NorFlashUnlockAndEraseSingleBlock ( // use of uninitialized variables OriginalTPL = TPL_HIGH_LEVEL; } - +#endif Index = 0; // The block erase might fail a first time (SW bug ?). Retry it ... do { @@ -363,11 +441,12 @@ NorFlashUnlockAndEraseSingleBlock ( DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index)); } +#ifndef MM_STANDALONE if (!EfiAtRuntime ()) { // Interruptions can resume. gBS->RestoreTPL (OriginalTPL); } - +#endif return Status; } @@ -580,7 +659,9 @@ NorFlashWriteFullBlock ( UINTN BlockAddress; UINTN BuffersInBlock; UINTN RemainingWords; +#ifndef MM_STANDALONE EFI_TPL OriginalTPL; +#endif UINTN Cnt; Status = EFI_SUCCESS; @@ -590,7 +671,7 @@ NorFlashWriteFullBlock ( // Start writing from the first address at the start of the block WordAddress = BlockAddress; - +#ifndef MM_STANDALONE if (!EfiAtRuntime ()) { // Raise TPL to TPL_HIGH to stop anyone from interrupting us. OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL); @@ -599,7 +680,7 @@ NorFlashWriteFullBlock ( // use of uninitialized variables OriginalTPL = TPL_HIGH_LEVEL; } - +#endif Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress)); @@ -657,11 +738,12 @@ NorFlashWriteFullBlock ( } EXIT: +#ifndef MM_STANDALONE if (!EfiAtRuntime ()) { // Interruptions can resume. gBS->RestoreTPL (OriginalTPL); } - +#endif if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status)); } @@ -1243,6 +1325,7 @@ NorFlashVirtualNotifyEvent ( IN VOID *Context ) { +#ifndef MM_STANDALONE UINTN Index; for (Index = 0; Index < mNorFlashDeviceCount; Index++) { @@ -1268,7 +1351,7 @@ NorFlashVirtualNotifyEvent ( EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->ShadowBuffer); } } - +#endif return; } @@ -1276,13 +1359,20 @@ EFI_STATUS EFIAPI NorFlashInitialise ( IN EFI_HANDLE ImageHandle, +#ifndef MM_STANDALONE IN EFI_SYSTEM_TABLE *SystemTable +#else + IN EFI_MM_SYSTEM_TABLE *SystemTable +#endif ) { EFI_STATUS Status; UINT32 Index; NOR_FLASH_DESCRIPTION* NorFlashDevices; BOOLEAN ContainVariableStorage; +#ifdef MM_STANDALONE + mMmst = SystemTable; +#endif Status = NorFlashPlatformInitialization (); if (EFI_ERROR(Status)) { @@ -1318,7 +1408,7 @@ NorFlashInitialise ( DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index)); } } - +#ifndef MM_STANDALONE // // Register for the virtual address change event // @@ -1331,6 +1421,6 @@ NorFlashInitialise ( &mNorFlashVirtualAddrChangeEvent ); ASSERT_EFI_ERROR (Status); - +#endif return Status; } diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h index 5c07694..2dc19ad 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h @@ -1,6 +1,6 @@ /** @file NorFlashDxe.h - Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2018, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -17,8 +17,11 @@ #include +#ifndef MM_STANDALONE #include - +#else +#include +#endif #include #include @@ -28,8 +31,16 @@ #include #include #include +#ifndef MM_STANDALONE #include #include +#else +#include +#include +#include +#include +#include +#endif #define NOR_FLASH_ERASE_RETRY 10 diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c index e62ffbb..dae0e55 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c @@ -1,6 +1,6 @@ /*++ @file NorFlashFvbDxe.c - Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+ Copyright (c) 2011 - 2018, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -12,7 +12,11 @@ --*/ +#ifndef MM_STANDALONE #include +#else +#include +#endif #include #include @@ -20,16 +24,21 @@ #include #include #include +#ifndef MM_STANDALONE #include #include - +#else +#include +#endif #include #include #include #include "NorFlashDxe.h" +#ifndef MM_STANDALONE STATIC EFI_EVENT mFvbVirtualAddrChangeEvent; +#endif STATIC UINTN mFlashNvStorageVariableBase; /// @@ -702,7 +711,9 @@ FvbVirtualNotifyEvent ( IN VOID *Context ) { +#ifndef MM_STANDALONE EfiConvertPointer (0x0, (VOID**)&mFlashNvStorageVariableBase); +#endif return; } @@ -715,11 +726,12 @@ NorFlashFvbInitialize ( EFI_STATUS Status; UINT32 FvbNumLba; EFI_BOOT_MODE BootMode; +#ifndef MM_STANDALONE UINTN RuntimeMmioRegionSize; - +#endif DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n")); ASSERT((Instance != NULL)); - +#ifndef MM_STANDALONE // // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME // @@ -741,7 +753,7 @@ NorFlashFvbInitialize ( Instance->DeviceBaseAddress, RuntimeMmioRegionSize, EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); ASSERT_EFI_ERROR (Status); - +#endif mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase); // Set the index of the first LBA for the FVB @@ -776,7 +788,7 @@ NorFlashFvbInitialize ( return Status; } } - +#ifndef MM_STANDALONE // // The driver implementing the variable read service can now be dispatched; // the varstore headers are in place. @@ -801,6 +813,6 @@ NorFlashFvbInitialize ( &mFvbVirtualAddrChangeEvent ); ASSERT_EFI_ERROR (Status); - +#endif return Status; } diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf new file mode 100644 index 0000000..abf221c --- /dev/null +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf @@ -0,0 +1,76 @@ +#/** @file +# +# Component description file for NorFlashDxe module +# +# Copyright (c) 2018, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = StandaloneMmNorFlash + FILE_GUID = 166F677B-DAC9-4AE4-AD34-2FF2504B0637 + MODULE_TYPE = MM_STANDALONE + VERSION_STRING = 1.0 + PI_SPECIFICATION_VERSION = 0x00010032 + ENTRY_POINT = NorFlashInitialise + +[Sources.common] + NorFlashDxe.c + NorFlashFvbDxe.c + NorFlashBlockIoDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + edk2-platforms/Platform/ARM/ARM.dec + StandaloneMmPkg/StandaloneMmPkg.dec + +[LibraryClasses] + StandaloneMmDriverEntryPoint + BaseMemoryLib + ArmSvcLib + ArmLib + IoLib + BaseLib + DebugLib + HobLib + MemoryAllocationLib + NorFlashPlatformLib + +[Guids] + gEfiSystemNvDataFvGuid + gEfiVariableGuid + gEfiAuthenticatedVariableGuid + gEfiEventVirtualAddressChangeGuid + gEdkiiNvVarStoreFormattedGuid ## PRODUCES ## PROTOCOL + +[Protocols] + gEfiBlockIoProtocolGuid + gEfiDevicePathProtocolGuid + gEfiSmmFirmwareVolumeBlockProtocolGuid + gEfiDiskIoProtocolGuid + +[Pcd.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + + gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked + +[Depex] + TRUE -- 1.9.1