From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.26438.1621876996964674938 for ; Mon, 24 May 2021 10:23:17 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: sayanta.pattanayak@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 99D546D; Mon, 24 May 2021 10:23:16 -0700 (PDT) Received: from usa.arm.com (a077432.blr.arm.com [10.162.4.31]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6A7EF3F73B; Mon, 24 May 2021 10:23:15 -0700 (PDT) From: "Sayanta Pattanayak" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar Subject: [edk2-platforms][PATCH V1 2/3] Platform/Sgi: add StandaloneMM usable NorFlashPlatformLib Date: Mon, 24 May 2021 22:52:59 +0530 Message-Id: <20210524172300.28754-3-sayanta.pattanayak@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210524172300.28754-1-sayanta.pattanayak@arm.com> References: <20210524172300.28754-1-sayanta.pattanayak@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add the NorFlashPlatformLib library instance that can be linked with MM_STANDALONE modules that implement a secure variable storage. The third instance of the NOR flash is used as the non-volatile storage. Signed-off-by: Sayanta Pattanayak --- Platform/ARM/SgiPkg/SgiPlatform.dec | 1= + Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.inf | 33= ++++++++ Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.c | 82= ++++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/Platform/ARM/SgiPkg/SgiPlatform.dec b/Platform/ARM/SgiPkg/Sg= iPlatform.dec index 3effd49592ea..af08ed153eae 100644 --- a/Platform/ARM/SgiPkg/SgiPlatform.dec +++ b/Platform/ARM/SgiPkg/SgiPlatform.dec @@ -54,6 +54,7 @@ =20 gArmSgiTokenSpaceGuid.PcdSmcCs0Base|0|UINT64|0x0000000C gArmSgiTokenSpaceGuid.PcdSmcCs1Base|0|UINT64|0x0000000D + gArmSgiTokenSpaceGuid.PcdSmcCs2Base|0|UINT64|0x00001000 gArmSgiTokenSpaceGuid.PcdSysPeriphBase|0x00000000|UINT64|0x0000000E gArmSgiTokenSpaceGuid.PcdSysPeriphSysRegBase|0x0|UINT64|0x0000000F =20 diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlash= Lib.inf b/Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib= .inf new file mode 100644 index 000000000000..96bbf1e42313 --- /dev/null +++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.inf @@ -0,0 +1,33 @@ +## @file +# StandaloneMM instance of NOR Flash library. +# +# Copyright (c) 2021, ARM Limited. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D NorFlashMmLib + FILE_GUID =3D 2ce22190-b933-4d1e-99ba-8bf1f076825= 5 + MODULE_TYPE =3D MM_STANDALONE + VERSION_STRING =3D 1.0 + PI_SPECIFICATION_VERSION =3D 0x00010032 + LIBRARY_CLASS =3D NorFlashPlatformLib + +[Sources.common] + StandaloneMmNorFlashLib.c + +[Packages] + ArmPlatformPkg/ArmPlatformPkg.dec + MdePkg/MdePkg.dec + Platform/ARM/SgiPkg/SgiPlatform.dec + +[LibraryClasses] + BaseLib + DebugLib + IoLib + +[FixedPcd] + gArmSgiTokenSpaceGuid.PcdSysPeriphSysRegBase + gArmSgiTokenSpaceGuid.PcdSmcCs2Base diff --git a/Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlash= Lib.c b/Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.c new file mode 100644 index 000000000000..3e5a5612c17e --- /dev/null +++ b/Platform/ARM/SgiPkg/Library/NorFlashLib/StandaloneMmNorFlashLib.c @@ -0,0 +1,82 @@ +/** @file +* NOR flash platform library to be used in StandaloneMM context +* +* This file provides platform callbacks for the NOR flash module that ex= ecutes +* in the StandaloneMM context. The third NOR flash instance of 64MB size= on the +* reference design platform is assigned to be used in the StandaloneMM c= ontext. +* +* Copyright (c) 2021, ARM Ltd. All rights reserved. +* +* SPDX-License-Identifier: BSD-2-Clause-Patent +* +**/ + +#include +#include +#include +#include +#include + +// +// 64MB NOR flash connected to CS2 is assigned to be used in StandaloneM= M +// context. +// +STATIC NOR_FLASH_DESCRIPTION mNorFlashDevices[] =3D { + { + // NOR-Flash2 assigned for secure storage. + FixedPcdGet64 (PcdSmcCs2Base), + FixedPcdGet64 (PcdSmcCs2Base), + SIZE_256KB * 256, + SIZE_256KB, + }, +}; + +/** Allow access to NOR flash + + On the reference design platforms, the access to NOR flash has to be + explicitly permitted by writing to the FLASH_RWEN bit of the SYSPH_SYS= _REG + register. + + @retval EFI_SUCCESS Initialize required to access NOR flash is compl= ete. + +**/ +EFI_STATUS +NorFlashPlatformInitialization ( + VOID + ) +{ + UINT64 SysRegFlash; + + SysRegFlash =3D FixedPcdGet64 (PcdSysPeriphSysRegBase) + SGI_SYSPH_SYS= _REG_FLASH; + MmioOr32 (SysRegFlash, SGI_SYSPH_SYS_REG_FLASH_RWEN); + return EFI_SUCCESS; +} + +/** Returns the list of available NOR flash devices + + For the StandaloneMM execution context, return the list of available N= OR + flash devices that are available for use. + + @param[in] NorFlashDevices Pointer to array of NOR flash devices. + @param[in] Count Number of elements in the NOR flash devi= ces + array. + + @retval EFI_SUCCESS Valid set of NOR flash devices is retu= rned. + @retval EFI_INVALID_PARAMETER Pointers to NOR flash devices and/or c= ount is + invalid. + +**/ +EFI_STATUS +NorFlashPlatformGetDevices ( + OUT NOR_FLASH_DESCRIPTION **NorFlashDevices, + OUT UINT32 *Count + ) +{ + if ((NorFlashDevices =3D=3D NULL) || (Count =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + + *NorFlashDevices =3D mNorFlashDevices; + *Count =3D ARRAY_SIZE (mNorFlashDevices); + return EFI_SUCCESS; +} --=20 2.17.1