From nobody Fri Nov 1 04:39:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1523025792190208.34992830346482; Fri, 6 Apr 2018 07:43:12 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id ECA412268525F; Fri, 6 Apr 2018 07:43:10 -0700 (PDT) Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by ml01.01.org (Postfix) with ESMTP id BC11622685255 for ; Fri, 6 Apr 2018 07:43:09 -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 9CA521529; Fri, 6 Apr 2018 07:43:09 -0700 (PDT) Received: from u201365.usa.Arm.com (bc-c3-3-14.eu.iaas.arm.com [10.6.43.238]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D26103F587; Fri, 6 Apr 2018 07:43:07 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=217.140.101.70; helo=foss.arm.com; envelope-from=supreeth.venkatesh@arm.com; receiver=edk2-devel@lists.01.org From: Supreeth Venkatesh To: edk2-devel@lists.01.org Date: Fri, 6 Apr 2018 15:42:11 +0100 Message-Id: <20180406144223.10931-7-supreeth.venkatesh@arm.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180406144223.10931-1-supreeth.venkatesh@arm.com> References: <20180406144223.10931-1-supreeth.venkatesh@arm.com> Subject: [edk2] [PATCH v1 06/18] StandaloneMmPkg: Add an AArch64 specific entry point library. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, jiewen.yao@intel.com, liming.gao@intel.com, michael.d.kinney@intel.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The Standalone MM environment runs in S-EL0 in AArch64 on ARM Standard Platforms and is initialised during the SEC phase. ARM Trusted firmware in EL3 is responsible for initialising the architectural context for S-EL0 and loading the Standalone MM image. The memory allocated to this image is marked as RO+X. Heap memory is marked as RW+XN. Certain actions have to be completed prior to executing the generic code in the Standalone MM Core module. These are: 1. Memory permission attributes for each section of the Standalone MM Core module need to be changed prior to accessing any RW data. 2. A Hob list has to be created with information that allows the MM environment to initialise and dispatch drivers. Furthermore, this module is responsible for handing over runtime MM events to the Standalone MM CPU driver and returning control to ARM Trusted Firmware upon event completion. Hence it needs to know the CPU driver entry point. This patch implements an entry point module that ARM Trusted Firmware jumps to in S-EL0. It then performs the above actions before calling the Standalone MM Foundation entry point and handling subsequent MM events. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Achin Gupta Signed-off-by: Supreeth Venkatesh --- .../Library/Arm/StandaloneMmCoreEntryPoint.h | 232 +++++++++++++++++ .../Include/Library/MmCoreStandaloneEntryPoint.h | 101 ++++++++ .../StandaloneMmCoreEntryPoint/Arm/CreateHobList.c | 200 +++++++++++++++ .../Arm/SetPermissions.c | 278 +++++++++++++++++= ++++ .../Arm/StandaloneMmCoreEntryPoint.c | 264 +++++++++++++++++= ++ .../StandaloneMmCoreEntryPoint.inf | 53 ++++ StandaloneMmPkg =3D> StandaloneMmPkg~HEAD | 0 7 files changed, 1128 insertions(+) create mode 100644 StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEnt= ryPoint.h create mode 100644 StandaloneMmPkg/Include/Library/MmCoreStandaloneEntryPo= int.h create mode 100644 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/= CreateHobList.c create mode 100644 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/= SetPermissions.c create mode 100644 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/= StandaloneMmCoreEntryPoint.c create mode 100644 StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Stan= daloneMmCoreEntryPoint.inf rename StandaloneMmPkg =3D> StandaloneMmPkg~HEAD (100%) diff --git a/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint= .h b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h new file mode 100644 index 0000000000..029c6c476c --- /dev/null +++ b/StandaloneMmPkg/Include/Library/Arm/StandaloneMmCoreEntryPoint.h @@ -0,0 +1,232 @@ +/** @file + Entry point to the Standalone MM Foundation when initialised during the = SEC + phase on ARM platforms + +Copyright (c) 2017, 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 +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 IMPLI= ED. + +**/ + +#ifndef __MODULE_ENTRY_POINT_H__ +#define __MODULE_ENTRY_POINT_H__ + +#include +#include + +#define CPU_INFO_FLAG_PRIMARY_CPU 0x00000001 + +typedef +EFI_STATUS +(*PI_MM_CPU_TP_FW_ENTRYPOINT) ( + IN UINTN EventId, + IN UINTN CpuNumber, + IN UINTN NsCommBufferAddr + ); + +typedef struct { + UINT8 Type; /* type of the structure */ + UINT8 Version; /* version of this structure */ + UINT16 Size; /* size of this structure in bytes */ + UINT32 Attr; /* attributes: unused bits SBZ */ +} EFI_PARAM_HEADER; + +typedef struct { + UINT64 Mpidr; + UINT32 LinearId; + UINT32 Flags; +} EFI_SECURE_PARTITION_CPU_INFO; + +typedef struct { + EFI_PARAM_HEADER Header; + UINT64 SpMemBase; + UINT64 SpMemLimit; + UINT64 SpImageBase; + UINT64 SpStackBase; + UINT64 SpHeapBase; + UINT64 SpNsCommBufBase; + UINT64 SpSharedBufBase; + UINT64 SpImageSize; + UINT64 SpPcpuStackSize; + UINT64 SpHeapSize; + UINT64 SpNsCommBufSize; + UINT64 SpPcpuSharedBufSize; + UINT32 NumSpMemRegions; + UINT32 NumCpus; + EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; +} EFI_SECURE_PARTITION_BOOT_INFO; + +typedef struct { + EFI_PARAM_HEADER h; + UINT64 SpStackBase; + UINT64 SpSharedBufBase; + UINT32 SpPcpuStackSize; + UINT32 SpPcpuSharedBufSize; + EFI_SECURE_PARTITION_CPU_INFO CpuInfo; +} EFI_SECURE_PARTITION_WARM_BOOT_INFO; + + +typedef +EFI_STATUS +(*PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT) ( + IN UINTN EventId, + IN UINTN CpuNumber, + IN UINTN NsCommBufferAddr + ); + +typedef struct { + PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *ArmTfCpuDriverEpPtr; +} ARM_TF_CPU_DRIVER_EP_DESCRIPTOR; + +typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64 Length + ); + +/** + Privileged firmware assigns RO & Executable attributes to all memory occ= upied + by the Boot Firmware Volume. This function sets the correct permissions = of + sections in the Standalone MM Core module to be able to access RO and RW= data + and make further progress in the boot process. + + @param ImageContext Pointer to PE/COFF image context + @param SectionHeaderOffset Offset of PE/COFF image section header + @param NumberOfSections Number of Sections + @param TextUpdater Function to change code permissions + @param ReadOnlyUpdater Function to change RO permissions + @param ReadWriteUpdater Function to change RW permissions + +**/ +EFI_STATUS +EFIAPI +UpdateMmFoundationPeCoffPermissions ( + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN UINT32 SectionHeaderOffset, + IN CONST UINTN NumberOfSections, + IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadWriteUpdater + ); + + +/** + Privileged firmware assigns RO & Executable attributes to all memory occ= upied + by the Boot Firmware Volume. This function locates the section informati= on of + the Standalone MM Core module to be able to change permissions of the + individual sections later in the boot process. + + @param TeData Pointer to PE/COFF image data + @param ImageContext Pointer to PE/COFF image context + @param SectionHeaderOffset Offset of PE/COFF image section header + @param NumberOfSections Number of Sections + +**/ +EFI_STATUS +EFIAPI +GetStandaloneMmCorePeCoffSections ( + IN VOID *TeData, + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN OUT UINT32 *SectionHeaderOffset; + IN OUT UINTN *NumberOfSections; + ); + + +/** + Privileged firmware assigns RO & Executable attributes to all memory occ= upied + by the Boot Firmware Volume. This function locates the Standalone MM Core + module PE/COFF image in the BFV and returns this information. + + @param BfvAddress Base Address of Boot Firmware Volume + @param TeData Pointer to address for allocating memory = for + PE/COFF image data + @param TeDataSize Pointer to size of PE/COFF image data + +**/ +EFI_STATUS +EFIAPI +LocateStandaloneMmCorePeCoffData ( + IN EFI_FIRMWARE_VOLUME_HEADER *BfvAddress, + IN OUT VOID **TeData; + IN OUT UINTN *TeDataSize; + ); + + +/** + Use the boot information passed by privileged firmware to populate a HOB= list + suitable for consumption by the MM Core and drivers. + + @param CpuDriverEntryPoint Address of MM CPU driver entrypoint + @param PayloadBootInfo Boot information passed by privileged fir= mware + +**/ +VOID * +EFIAPI +CreateHobListFromBootInfo ( + IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint, + IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo + ); + + +/** + The entry point of Standalone MM Foundation. + + @param HobStart Pointer to the beginning of the HOB List. + +**/ +VOID +EFIAPI +_ModuleEntryPoint ( + IN VOID *SharedBufAddress, + IN UINT64 SharedBufSize, + IN UINT64 cookie1, + IN UINT64 cookie2 + ); + + +/** + Autogenerated function that calls the library constructors for all of th= e module's dependent libraries. + + This function must be called by _ModuleEntryPoint(). + This function calls the set of library constructors for the set of libra= ry instances + that a module depends on. This includes library instances that a module= depends on + directly and library instances that a module depends on indirectly throu= gh other + libraries. This function is autogenerated by build tools and those build= tools are + responsible for collecting the set of library instances, determine which= ones have + constructors, and calling the library constructors in the proper order b= ased upon + each of the library instances own dependencies. + + @param ImageHandle The image handle of the DXE Core. + @param SystemTable A pointer to the EFI System Table. + +**/ +VOID +EFIAPI +ProcessLibraryConstructorList ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *MmSystemTable + ); + + +/** + Autogenerated function that calls a set of module entry points. + + This function must be called by _ModuleEntryPoint(). + This function calls the set of module entry points. + This function is autogenerated by build tools and those build tools are = responsible + for collecting the module entry points and calling them in a specified o= rder. + + @param HobStart Pointer to the beginning of the HOB List passed in fro= m the PEI Phase. + +**/ +VOID +EFIAPI +ProcessModuleEntryPointList ( + IN VOID *HobStart + ); + +#endif diff --git a/StandaloneMmPkg/Include/Library/MmCoreStandaloneEntryPoint.h b= /StandaloneMmPkg/Include/Library/MmCoreStandaloneEntryPoint.h new file mode 100644 index 0000000000..d6105d4935 --- /dev/null +++ b/StandaloneMmPkg/Include/Library/MmCoreStandaloneEntryPoint.h @@ -0,0 +1,101 @@ +/** @file + Module entry point library for DXE core. + +Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.
+Copyright (c) 2016 - 2017, 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 IMPLI= ED. + +**/ + +#ifndef __MODULE_ENTRY_POINT_H__ +#define __MODULE_ENTRY_POINT_H__ + +/// +/// Global variable that contains a pointer to the Hob List passed into th= e DXE Core entry point. +/// +extern VOID *gHobList; + + +/** + The entry point of PE/COFF Image for the DXE Core. + + This function is the entry point for the DXE Core. This function is requ= ired to call + ProcessModuleEntryPointList() and ProcessModuleEntryPointList() is never= expected to return. + The DXE Core is responsible for calling ProcessLibraryConstructorList() = as soon as the EFI + System Table and the image handle for the DXE Core itself have been esta= blished. + If ProcessModuleEntryPointList() returns, then ASSERT() and halt the sys= tem. + + @param HobStart Pointer to the beginning of the HOB List passed in fro= m the PEI Phase. + +**/ +VOID +EFIAPI +_ModuleEntryPoint ( + IN VOID *HobStart + ); + + +/** + Required by the EBC compiler and identical in functionality to _ModuleEn= tryPoint(). + + This function is required to call _ModuleEntryPoint() passing in HobStar= t. + + @param HobStart Pointer to the beginning of the HOB List passed in fro= m the PEI Phase. + +**/ +VOID +EFIAPI +EfiMain ( + IN VOID *HobStart + ); + + +/** + Autogenerated function that calls the library constructors for all of th= e module's dependent libraries. + + This function must be called by _ModuleEntryPoint(). + This function calls the set of library constructors for the set of libra= ry instances + that a module depends on. This includes library instances that a module= depends on + directly and library instances that a module depends on indirectly throu= gh other + libraries. This function is autogenerated by build tools and those build= tools are + responsible for collecting the set of library instances, determine which= ones have + constructors, and calling the library constructors in the proper order b= ased upon + each of the library instances own dependencies. + + @param ImageHandle The image handle of the DXE Core. + @param SystemTable A pointer to the EFI System Table. + +**/ +VOID +EFIAPI +ProcessLibraryConstructorList ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *MmSystemTable + ); + + +/** + Autogenerated function that calls a set of module entry points. + + This function must be called by _ModuleEntryPoint(). + This function calls the set of module entry points. + This function is auto generated by build tools and those build tools are= responsible + for collecting the module entry points and calling them in a specified o= rder. + + @param HobStart Pointer to the beginning of the HOB List passed in fro= m the PEI Phase. + +**/ +VOID +EFIAPI +ProcessModuleEntryPointList ( + IN VOID *HobStart + ); + +#endif diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateH= obList.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHob= List.c new file mode 100644 index 0000000000..f9b3faea8f --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c @@ -0,0 +1,200 @@ +/** @file + Entry point to the Standalone MM Foundation when initialized during the = SEC + phase on ARM platforms + +Copyright (c) 2017, 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 +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 IMPLI= ED. + +**/ + + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +extern EFI_HOB_HANDOFF_INFO_TABLE* +HobConstructor ( + IN VOID *EfiMemoryBegin, + IN UINTN EfiMemoryLength, + IN VOID *EfiFreeMemoryBottom, + IN VOID *EfiFreeMemoryTop + ); + +// GUID to identify HOB with whereabouts of communication buffer with Norm= al +// World +extern EFI_GUID gEfiStandaloneMmNonSecureBufferGuid; + +// GUID to identify HOB where the entry point of the CPU driver will be +// populated to allow this entry point driver to invoke it upon receipt of= an +// event +extern EFI_GUID gEfiArmTfCpuDriverEpDescriptorGuid; + +/** + Use the boot information passed by privileged firmware to populate a HOB= list + suitable for consumption by the MM Core and drivers. + + @param PayloadBootInfo Boot information passed by privileged firmware + +**/ +VOID * +CreateHobListFromBootInfo ( + IN OUT PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT *CpuDriverEntryPoint, + IN EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo +) +{ + EFI_HOB_HANDOFF_INFO_TABLE *HobStart; + EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; + UINT32 Index; + UINT32 BufferSize; + UINT32 Flags; + EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHob; + EFI_MMRAM_DESCRIPTOR *MmramRanges; + EFI_MMRAM_DESCRIPTOR *NsCommBufMmramRange; + MP_INFORMATION_HOB_DATA *MpInformationHobData; + EFI_PROCESSOR_INFORMATION *ProcInfoBuffer; + EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; + ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; + + // Create a hoblist with a PHIT and EOH + HobStart =3D HobConstructor ((VOID *) PayloadBootInfo->SpMemBase, + (UINTN) PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase, + (VOID *) PayloadBootInfo->SpHeapBase, + (VOID *) (PayloadBootInfo->SpHeapBase + PayloadBootInfo->SpHeapSize)); + + // Check that the Hoblist starts at the bottom of the Heap + ASSERT (HobStart =3D=3D (VOID *) PayloadBootInfo->SpHeapBase); + + // Build a Boot Firmware Volume HOB + BuildFvHob(PayloadBootInfo->SpImageBase, PayloadBootInfo->SpImageSize); + + // Build a resource descriptor Hob that describes the available physical + // memory range + Attributes =3D( + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_TESTED | + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE + ); + + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, + Attributes, + (UINTN) PayloadBootInfo->SpMemBase, + PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase); + + // Find the size of the GUIDed HOB with MP information + BufferSize =3D sizeof (MP_INFORMATION_HOB_DATA); + BufferSize +=3D sizeof (EFI_PROCESSOR_INFORMATION) * PayloadBootInfo->Nu= mCpus; + + // Create a Guided MP information HOB to enable the ARM TF CPU driver to + // perform per-cpu allocations. + MpInformationHobData =3D BuildGuidHob(&gMpInformationHobGuid, BufferSize= ); + + // Populate the MP information HOB with the topology information passed = by + // privileged firmware + MpInformationHobData->NumberOfProcessors =3D PayloadBootInfo->NumCpus; + MpInformationHobData->NumberOfEnabledProcessors =3D PayloadBootInfo->Num= Cpus; + ProcInfoBuffer =3D MpInformationHobData->ProcessorInfoBuffer; + CpuInfo =3D PayloadBootInfo->CpuInfo; + + for (Index =3D 0; Index < PayloadBootInfo->NumCpus; Index++) { + ProcInfoBuffer[Index].ProcessorId =3D CpuInfo[Index].Mpidr; + ProcInfoBuffer[Index].Location.Package =3D GET_CLUSTER_ID(CpuInfo[Inde= x].Mpidr); + ProcInfoBuffer[Index].Location.Core =3D GET_CORE_ID(CpuInfo[Index].= Mpidr); + ProcInfoBuffer[Index].Location.Thread =3D GET_CORE_ID(CpuInfo[Index].= Mpidr); + + Flags =3D PROCESSOR_ENABLED_BIT | PROCESSOR_HEALTH_STATUS_BIT; + if (CpuInfo[Index].Flags & CPU_INFO_FLAG_PRIMARY_CPU) { + Flags |=3D PROCESSOR_AS_BSP_BIT; + } + ProcInfoBuffer[Index].StatusFlag =3D Flags; + } + + // Create a Guided HOB to tell the ARM TF CPU driver the location and le= ngth + // of the communication buffer shared with the Normal world. + NsCommBufMmramRange =3D (EFI_MMRAM_DESCRIPTOR *) BuildGuidHob (&gEfiStan= daloneMmNonSecureBufferGuid, sizeof(EFI_MMRAM_DESCRIPTOR)); + NsCommBufMmramRange->PhysicalStart =3D PayloadBootInfo->SpNsCommBufBase; + NsCommBufMmramRange->CpuStart =3D PayloadBootInfo->SpNsCommBufBase; + NsCommBufMmramRange->PhysicalSize =3D PayloadBootInfo->SpNsCommBufSize; + NsCommBufMmramRange->RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Create a Guided HOB to enable the ARM TF CPU driver to share its entry + // point and populate it with the address of the shared buffer + CpuDriverEntryPointDesc =3D (ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *) BuildGui= dHob (&gEfiArmTfCpuDriverEpDescriptorGuid, sizeof(ARM_TF_CPU_DRIVER_EP_DESC= RIPTOR)); + + *CpuDriverEntryPoint =3D NULL; + CpuDriverEntryPointDesc->ArmTfCpuDriverEpPtr =3D CpuDriverEntryPoint; + + // Find the size of the GUIDed HOB with SRAM ranges + BufferSize =3D sizeof (EFI_MMRAM_HOB_DESCRIPTOR_BLOCK); + BufferSize +=3D PayloadBootInfo->NumSpMemRegions * + sizeof(EFI_MMRAM_DESCRIPTOR); + + // Create a GUIDed HOB with SRAM ranges + MmramRangesHob =3D BuildGuidHob (&gEfiMmPeiMmramMemoryReserveGuid, Buffe= rSize); + + // Fill up the number of MMRAM memory regions + MmramRangesHob->NumberOfMmReservedRegions =3D PayloadBootInfo->NumSpMemR= egions; + // Fill up the MMRAM ranges + MmramRanges =3D &MmramRangesHob->Descriptor[0]; + + // Base and size of memory occupied by the Standalone MM image + MmramRanges[0].PhysicalStart =3D PayloadBootInfo->SpImageBase; + MmramRanges[0].CpuStart =3D PayloadBootInfo->SpImageBase; + MmramRanges[0].PhysicalSize =3D PayloadBootInfo->SpImageSize; + MmramRanges[0].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Base and size of buffer shared with privileged Secure world software + MmramRanges[1].PhysicalStart =3D PayloadBootInfo->SpSharedBufBase; + MmramRanges[1].CpuStart =3D PayloadBootInfo->SpSharedBufBase; + MmramRanges[1].PhysicalSize =3D PayloadBootInfo->SpPcpuSharedBufSize * = PayloadBootInfo->NumCpus; + MmramRanges[1].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Base and size of buffer used for synchronous communication with Normal + // world software + MmramRanges[2].PhysicalStart =3D PayloadBootInfo->SpNsCommBufBase; + MmramRanges[2].CpuStart =3D PayloadBootInfo->SpNsCommBufBase; + MmramRanges[2].PhysicalSize =3D PayloadBootInfo->SpNsCommBufSize; + MmramRanges[2].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Base and size of memory allocated for stacks for all cpus + MmramRanges[3].PhysicalStart =3D PayloadBootInfo->SpStackBase; + MmramRanges[3].CpuStart =3D PayloadBootInfo->SpStackBase; + MmramRanges[3].PhysicalSize =3D PayloadBootInfo->SpPcpuStackSize * Payl= oadBootInfo->NumCpus; + MmramRanges[3].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Base and size of heap memory shared by all cpus + MmramRanges[4].PhysicalStart =3D (EFI_PHYSICAL_ADDRESS) HobStart; + MmramRanges[4].CpuStart =3D (EFI_PHYSICAL_ADDRESS) HobStart; + MmramRanges[4].PhysicalSize =3D HobStart->EfiFreeMemoryBottom - (EFI_PH= YSICAL_ADDRESS) HobStart; + MmramRanges[4].RegionState =3D EFI_CACHEABLE | EFI_ALLOCATED; + + // Base and size of heap memory shared by all cpus + MmramRanges[5].PhysicalStart =3D HobStart->EfiFreeMemoryBottom; + MmramRanges[5].CpuStart =3D HobStart->EfiFreeMemoryBottom; + MmramRanges[5].PhysicalSize =3D HobStart->EfiFreeMemoryTop - HobStart->= EfiFreeMemoryBottom; + MmramRanges[5].RegionState =3D EFI_CACHEABLE; + + return HobStart; +} diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPerm= issions.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPermi= ssions.c new file mode 100644 index 0000000000..e96b81cdc0 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/SetPermissions= .c @@ -0,0 +1,278 @@ +/** @file + Entry point to the Standalone MM Foundation when initialised during the = SEC + phase on ARM platforms + +Copyright (c) 2017, 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 +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 IMPLI= ED. + +**/ + + +#include + + + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include + +EFI_STATUS +EFIAPI +UpdateMmFoundationPeCoffPermissions ( + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN UINT32 SectionHeaderOffset, + IN CONST UINTN NumberOfSections, + IN REGION_PERMISSION_UPDATE_FUNC TextUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadWriteUpdater + ) +{ + EFI_IMAGE_SECTION_HEADER SectionHeader; + RETURN_STATUS Status; + EFI_PHYSICAL_ADDRESS Base; + UINTN Size; + UINTN ReadSize; + UINTN Index; + + ASSERT (ImageContext !=3D NULL); + + // + // Iterate over the sections + // + for (Index =3D 0; Index < NumberOfSections; Index++) { + // + // Read section header from file + // + Size =3D sizeof (EFI_IMAGE_SECTION_HEADER); + ReadSize =3D Size; + Status =3D ImageContext->ImageRead (ImageContext->Handle, SectionHeade= rOffset, + &Size, &SectionHeader); + if (RETURN_ERROR (Status) || (Size !=3D ReadSize)) { + DEBUG ((DEBUG_ERROR, + "%a: ImageContext->ImageRead () failed (Status =3D %r)\n", + __FUNCTION__, Status)); + return Status; + } + + DEBUG ((DEBUG_INFO, + "%a: Section %d of image at 0x%lx has 0x%x permissions\n", + __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader= .Characteristics)); + DEBUG ((DEBUG_INFO, + "%a: Section %d of image at 0x%lx has %s name\n", + __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader= .Name)); + DEBUG ((DEBUG_INFO, + "%a: Section %d of image at 0x%lx has 0x%x address\n", + __FUNCTION__, Index, ImageContext->ImageAddress, ImageContext-= >ImageAddress + SectionHeader.VirtualAddress)); + DEBUG ((DEBUG_INFO, + "%a: Section %d of image at 0x%lx has 0x%x data\n", + __FUNCTION__, Index, ImageContext->ImageAddress, SectionHeader= .PointerToRawData)); + + // + // If the section is marked as XN then remove the X attribute. Further= more, + // if it is a writeable section then mark it appropriately as well. + // + if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) =3D=3D= 0) { + Base =3D ImageContext->ImageAddress + SectionHeader.VirtualAddress; + + TextUpdater (Base, SectionHeader.Misc.VirtualSize); + + if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_MEM_WRITE) !=3D 0= ) { + ReadWriteUpdater (Base, SectionHeader.Misc.VirtualSize); + DEBUG ((DEBUG_INFO, + "%a: Mapping section %d of image at 0x%lx with RW-XN permi= ssions\n", + __FUNCTION__, Index, ImageContext->ImageAddress)); + } else { + DEBUG ((DEBUG_INFO, + "%a: Mapping section %d of image at 0x%lx with RO-XN permi= ssions\n", + __FUNCTION__, Index, ImageContext->ImageAddress)); + } + } else { + DEBUG ((DEBUG_INFO, + "%a: Ignoring section %d of image at 0x%lx with 0x%x permi= ssions\n", + __FUNCTION__, Index, ImageContext->ImageAddress, SectionHe= ader.Characteristics)); + } + SectionHeaderOffset +=3D sizeof (EFI_IMAGE_SECTION_HEADER); + } + + return RETURN_SUCCESS; +} + +EFI_STATUS +EFIAPI +LocateStandaloneMmCorePeCoffData ( + IN EFI_FIRMWARE_VOLUME_HEADER *BfvAddress, + IN OUT VOID **TeData, + IN OUT UINTN *TeDataSize + ) +{ + EFI_FFS_FILE_HEADER *FileHeader =3D NULL; + EFI_STATUS Status; + + Status =3D FfsFindNextFile ( + EFI_FV_FILETYPE_SECURITY_CORE, + BfvAddress, + &FileHeader); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM FFS file - 0x%x\n= ", + Status)); + return Status; + } + + Status =3D FfsFindSectionData (EFI_SECTION_PE32, FileHeader, TeData, TeD= ataSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Unable to locate Standalone MM Section data - = 0x%x\n", + Status)); + return Status; + } + + DEBUG ((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", *TeData)); + return Status; +} + +static +EFI_STATUS +GetPeCoffSectionInformation ( + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *TmpContext, + IN OUT UINT32 *SectionHeaderOffset, + IN OUT UINTN *NumberOfSections + ) +{ + RETURN_STATUS Status; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; + UINTN Size; + UINTN ReadSize; + + ASSERT (ImageContext !=3D NULL); + ASSERT (TmpContext !=3D NULL); + ASSERT (SectionHeaderOffset !=3D NULL); + ASSERT (NumberOfSections !=3D NULL); + + // + // We need to copy ImageContext since PeCoffLoaderGetImageInfo () + // will mangle the ImageAddress field + // + CopyMem (TmpContext, ImageContext, sizeof (*TmpContext)); + + if (TmpContext->PeCoffHeaderOffset =3D=3D 0) { + Status =3D PeCoffLoaderGetImageInfo (TmpContext); + if (RETURN_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a: PeCoffLoaderGetImageInfo () failed (Status =3D %r)\n", + __FUNCTION__, Status)); + return Status; + } + } + + if (TmpContext->IsTeImage && + TmpContext->ImageAddress =3D=3D ImageContext->ImageAddress) { + DEBUG ((DEBUG_INFO, "%a: ignoring XIP TE image at 0x%lx\n", __FUNCTION= __, + ImageContext->ImageAddress)); + return RETURN_UNSUPPORTED; + } + + if (TmpContext->SectionAlignment < EFI_PAGE_SIZE) { + // + // The sections need to be at least 4 KB aligned, since that is the + // granularity at which we can tighten permissions. + // + if (!TmpContext->IsTeImage) { + DEBUG ((DEBUG_WARN, + "%a: non-TE Image at 0x%lx has SectionAlignment < 4 KB (%lu)\n", + __FUNCTION__, ImageContext->ImageAddress, TmpContext->SectionAlign= ment)); + } + return RETURN_UNSUPPORTED; + } + + // + // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much + // data, but that should not hurt anything. Hdr.Pe32->OptionalHeader.Mag= ic + // determines if this is a PE32 or PE32+ image. The magic is in the same + // location in both images. + // + Hdr.Union =3D &HdrData; + Size =3D sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION); + ReadSize =3D Size; + Status =3D TmpContext->ImageRead (TmpContext->Handle, + TmpContext->PeCoffHeaderOffset, &Size, Hdr.Pe32); + if (RETURN_ERROR (Status) || (Size !=3D ReadSize)) { + DEBUG ((DEBUG_ERROR, + "%a: TmpContext->ImageRead () failed (Status =3D %r)\n", + __FUNCTION__, Status)); + return Status; + } + + ASSERT (Hdr.Pe32->Signature =3D=3D EFI_IMAGE_NT_SIGNATURE); + + *SectionHeaderOffset =3D TmpContext->PeCoffHeaderOffset + sizeof (UINT32= ) + + sizeof (EFI_IMAGE_FILE_HEADER); + *NumberOfSections =3D (UINTN)(Hdr.Pe32->FileHeader.NumberOfSections); + + switch (Hdr.Pe32->OptionalHeader.Magic) { + case EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC: + *SectionHeaderOffset +=3D Hdr.Pe32->FileHeader.SizeOfOptionalHeader; + break; + case EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC: + *SectionHeaderOffset +=3D Hdr.Pe32Plus->FileHeader.SizeOfOptionalHea= der; + break; + default: + ASSERT (FALSE); + } + + return RETURN_SUCCESS; +} + +EFI_STATUS +EFIAPI +GetStandaloneMmCorePeCoffSections ( + IN VOID *TeData, + IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN OUT UINT32 *SectionHeaderOffset, + IN OUT UINTN *NumberOfSections + ) +{ + EFI_STATUS Status; + PE_COFF_LOADER_IMAGE_CONTEXT TmpContext; + + // Initialize the Image Context + ZeroMem (ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT)); + ImageContext->Handle =3D TeData; + ImageContext->ImageRead =3D PeCoffLoaderImageReadFromMemory; + + DEBUG((DEBUG_INFO, "Found Standalone MM PE data - 0x%x\n", TeData)); + + Status =3D PeCoffLoaderGetImageInfo (ImageContext); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Image= information - 0x%x\n", Status)); + return Status; + } + + Status =3D GetPeCoffSectionInformation(ImageContext, &TmpContext, Sectio= nHeaderOffset, NumberOfSections); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "Unable to locate Standalone MM Core PE-COFF Secti= on information - 0x%x\n", Status)); + return Status; + } + + DEBUG((DEBUG_INFO, "Standalone MM Core PE-COFF SectionHeaderOffset - 0x%= x, NumberOfSections - %d\n", *SectionHeaderOffset, *NumberOfSections)); + + return Status; +} diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Standal= oneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/= Arm/StandaloneMmCoreEntryPoint.c new file mode 100644 index 0000000000..72e3b834d4 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCo= reEntryPoint.c @@ -0,0 +1,264 @@ +/** @file + Entry point to the Standalone MM Foundation when initialized during the = SEC + phase on ARM platforms + +Copyright (c) 2017, 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 +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 IMPLI= ED. + +**/ + + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define SPM_MAJOR_VER_MASK 0xFFFF0000 +#define SPM_MINOR_VER_MASK 0x0000FFFF +#define SPM_MAJOR_VER_SHIFT 16 + +const UINT32 SPM_MAJOR_VER =3D 0; +const UINT32 SPM_MINOR_VER =3D 1; + +const UINT8 BOOT_PAYLOAD_VERSION =3D 1; + +PI_MM_ARM_TF_CPU_DRIVER_ENTRYPOINT CpuDriverEntryPoint =3D NULL; + +/** + Retrieve a pointer to and print the boot information passed by privileged + secure firmware + + @param SharedBufAddress The pointer memory shared with privileged firmw= are + +**/ +EFI_SECURE_PARTITION_BOOT_INFO * +GetAndPrintBootinformation ( + IN VOID *SharedBufAddress +) +{ + EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; + EFI_SECURE_PARTITION_CPU_INFO *PayloadCpuInfo; + UINTN Index; + + PayloadBootInfo =3D (EFI_SECURE_PARTITION_BOOT_INFO *) SharedBufAddress; + + if (PayloadBootInfo->Header.Version !=3D BOOT_PAYLOAD_VERSION) + { + DEBUG((DEBUG_ERROR, "Boot Information Version Mismatch. Current=3D0x%x= , Expected=3D0x%x.\n", PayloadBootInfo->Header.Version, BOOT_PAYLOAD_VERSIO= N)); + return NULL; + } + DEBUG((DEBUG_INFO, "NumSpMemRegions - 0x%x\n", PayloadBootInfo->NumSpMem= Regions)); + DEBUG((DEBUG_INFO, "SpMemBase - 0x%lx\n", PayloadBootInfo->SpMemBa= se)); + DEBUG((DEBUG_INFO, "SpMemLimit - 0x%lx\n", PayloadBootInfo->SpMemLi= mit)); + DEBUG((DEBUG_INFO, "SpImageBase - 0x%lx\n", PayloadBootInfo->SpImage= Base)); + DEBUG((DEBUG_INFO, "SpStackBase - 0x%lx\n", PayloadBootInfo->SpStack= Base)); + DEBUG((DEBUG_INFO, "SpHeapBase - 0x%lx\n", PayloadBootInfo->SpHeapB= ase)); + DEBUG((DEBUG_INFO, "SpNsCommBufBase - 0x%lx\n", PayloadBootInfo->SpNsCom= mBufBase)); + DEBUG((DEBUG_INFO, "SpSharedBufBase - 0x%lx\n", PayloadBootInfo->SpShare= dBufBase)); + + DEBUG((DEBUG_INFO, "SpImageSize - 0x%x\n", PayloadBootInfo->SpImageS= ize)); + DEBUG((DEBUG_INFO, "SpPcpuStackSize - 0x%x\n", PayloadBootInfo->SpPcpuSt= ackSize)); + DEBUG((DEBUG_INFO, "SpHeapSize - 0x%x\n", PayloadBootInfo->SpHeapSi= ze)); + DEBUG((DEBUG_INFO, "SpNsCommBufSize - 0x%x\n", PayloadBootInfo->SpNsComm= BufSize)); + DEBUG((DEBUG_INFO, "SpPcpuSharedBufSize - 0x%x\n", PayloadBootInfo->SpPc= puSharedBufSize)); + + DEBUG((DEBUG_INFO, "NumCpus - 0x%x\n", PayloadBootInfo->NumCpus)= ); + DEBUG((DEBUG_INFO, "CpuInfo - 0x%p\n", PayloadBootInfo->CpuInfo)= ); + + PayloadCpuInfo =3D (EFI_SECURE_PARTITION_CPU_INFO *) PayloadBootInfo->Cp= uInfo; + + for (Index =3D 0; Index < PayloadBootInfo->NumCpus; Index++) { + DEBUG((DEBUG_INFO, "Mpidr - 0x%lx\n", PayloadCpuInfo[Index].= Mpidr)); + DEBUG((DEBUG_INFO, "LinearId - 0x%x\n", PayloadCpuInfo[Index].L= inearId)); + DEBUG((DEBUG_INFO, "Flags - 0x%x\n", PayloadCpuInfo[Index].F= lags)); + } + + return PayloadBootInfo; +} + +VOID +EFIAPI +DelegatedEventLoop ( + IN ARM_SVC_ARGS *EventCompleteSvcArgs + ) +{ + EFI_STATUS Status; + + while(TRUE) { + ArmCallSvc(EventCompleteSvcArgs); + + DEBUG ((DEBUG_INFO, "Received delegated event\n")); + DEBUG ((DEBUG_INFO, "X0 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg= 0)); + DEBUG ((DEBUG_INFO, "X1 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg= 1)); + DEBUG ((DEBUG_INFO, "X2 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg= 2)); + DEBUG ((DEBUG_INFO, "X3 : 0x%x\n", (UINT32) EventCompleteSvcArgs->Arg= 3)); + + Status =3D CpuDriverEntryPoint( + EventCompleteSvcArgs->Arg0, + EventCompleteSvcArgs->Arg2, + EventCompleteSvcArgs->Arg1); + if (EFI_ERROR(Status)) { + DEBUG((DEBUG_ERROR, "Failed delegated event 0x%x, Status 0x%x\n", + EventCompleteSvcArgs->Arg0, Status)); + } + + EventCompleteSvcArgs->Arg0 =3D ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64; + EventCompleteSvcArgs->Arg1 =3D Status; + } +} + +STATIC +EFI_STATUS +GetSpmVersion () +{ + EFI_STATUS Status; + UINT16 SpmMajorVersion; + UINT16 SpmMinorVersion; + UINT32 SpmVersion; + ARM_SVC_ARGS SpmVersionArgs; + + SpmVersionArgs.Arg0 =3D ARM_SVC_ID_SPM_VERSION_AARCH32; + + ArmCallSvc (&SpmVersionArgs); + + SpmVersion =3D SpmVersionArgs.Arg0; + + SpmMajorVersion =3D ((SpmVersion & SPM_MAJOR_VER_MASK) >> SPM_MAJOR_VER_= SHIFT); + SpmMinorVersion =3D ((SpmVersion & SPM_MINOR_VER_MASK) >> 0); + + // Different major revision values indicate possibly incompatible functi= ons. + // For two revisions, A and B, for which the major revision values are + // identical, if the minor revision value of revision B is greater than + // the minor revision value of revision A, then every function in + // revision A must work in a compatible way with revision B. + // However, it is possible for revision B to have a higher + // function count than revision A. + if ((SpmMajorVersion =3D=3D SPM_MAJOR_VER) && + (SpmMinorVersion >=3D SPM_MINOR_VER)) + { + DEBUG ((DEBUG_INFO, "SPM Version: Major=3D0x%x, Minor=3D0x%x\n", + SpmMajorVersion, SpmMinorVersion)); + Status =3D EFI_SUCCESS; + } + else + { + DEBUG ((DEBUG_INFO, "Incompatible SPM Versions.\n Current Version: Maj= or=3D0x%x, Minor=3D0x%x.\n Expected: Major=3D0x%x, Minor>=3D0x%x.\n", + SpmMajorVersion, SpmMinorVersion, SPM_MAJOR_VER, SPM_MINOR_VER= )); + Status =3D EFI_UNSUPPORTED; + } + + return Status; +} + +/** + The entry point of Standalone MM Foundation. + + @param HobStart The pointer to the beginning of the HOB List. + +**/ +VOID +EFIAPI +_ModuleEntryPoint ( + IN VOID *SharedBufAddress, + IN UINT64 SharedBufSize, + IN UINT64 cookie1, + IN UINT64 cookie2 + ) +{ + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + EFI_SECURE_PARTITION_BOOT_INFO *PayloadBootInfo; + ARM_SVC_ARGS InitMmFoundationSvcArgs =3D {0}; + EFI_STATUS Status; + UINT32 SectionHeaderOffset; + UINTN NumberOfSections; + VOID *HobStart; + VOID *TeData; + UINTN TeDataSize; + + Status =3D SerialPortInitialize (); + ASSERT_EFI_ERROR (Status); + + // Get Secure Partition Manager Version Information + Status =3D GetSpmVersion(); + if (EFI_ERROR(Status)) { + goto finish; + } + + PayloadBootInfo =3D GetAndPrintBootinformation(SharedBufAddress); + if (PayloadBootInfo =3D=3D NULL) { + Status =3D EFI_UNSUPPORTED; + goto finish; + } + + // Locate PE/COFF File information for the Standalone MM core module + Status =3D LocateStandaloneMmCorePeCoffData ( + (EFI_FIRMWARE_VOLUME_HEADER *) PayloadBootInfo->SpImageBa= se, + &TeData, + &TeDataSize); + if (EFI_ERROR(Status)) { + goto finish; + } + + // Obtain the PE/COFF Section information for the Standalone MM core mod= ule + Status =3D GetStandaloneMmCorePeCoffSections ( + TeData, + &ImageContext, + &SectionHeaderOffset, + &NumberOfSections); + if (EFI_ERROR(Status)) { + goto finish; + } + + // Update the memory access permissions of individual sections in the + // Standalone MM core module + Status =3D UpdateMmFoundationPeCoffPermissions( + &ImageContext, + SectionHeaderOffset, + NumberOfSections, + ArmSetMemoryRegionNoExec, + ArmSetMemoryRegionReadOnly, + ArmClearMemoryRegionReadOnly); + if (EFI_ERROR(Status)) { + goto finish; + } + + // + // Create Hoblist based upon boot information passed by privileged softw= are + // + HobStart =3D CreateHobListFromBootInfo(&CpuDriverEntryPoint, PayloadBoot= Info); + + // + // Call the MM Core entry point + // + ProcessModuleEntryPointList (HobStart); + + ASSERT_EFI_ERROR (CpuDriverEntryPoint); + DEBUG ((DEBUG_INFO, "Shared Cpu Driver EP 0x%lx\n", (UINT64) CpuDriverEn= tryPoint)); + +finish: + InitMmFoundationSvcArgs.Arg0 =3D ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64; + InitMmFoundationSvcArgs.Arg1 =3D Status; + DelegatedEventLoop(&InitMmFoundationSvcArgs); + ASSERT_EFI_ERROR(0); + +} diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneM= mCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/St= andaloneMmCoreEntryPoint.inf new file mode 100644 index 0000000000..9edc85d406 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEn= tryPoint.inf @@ -0,0 +1,53 @@ +## @file +# Module entry point library for DXE core. +# +# Copyright (c) 2017, ARM Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may b= e 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 IM= PLIED. +# +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D StandaloneMmCoreEntryPoint + FILE_GUID =3D C97AC593-109A-4C63-905C-675FDE2689E8 + MODULE_TYPE =3D MM_CORE_STANDALONE + VERSION_STRING =3D 1.0 + PI_SPECIFICATION_VERSION =3D 0x00010032 + LIBRARY_CLASS =3D StandaloneMmCoreEntryPoint|MM_CORE_ST= ANDALONE + +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC (EBC is for build on= ly) +# + +[Sources.AARCH64] + Arm/StandaloneMmCoreEntryPoint.c + Arm/SetPermissions.c + Arm/CreateHobList.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + StandaloneMmPkg/StandaloneMmPkg.dec + +[Packages.AARCH64] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + +[LibraryClasses] + ArmMmuLib + ArmSvcLib + BaseLib + DebugLib + +[Guids] + gMpInformationHobGuid + gEfiMmPeiMmramMemoryReserveGuid + gEfiStandaloneMmNonSecureBufferGuid + gEfiArmTfCpuDriverEpDescriptorGuid diff --git a/StandaloneMmPkg b/StandaloneMmPkg~HEAD similarity index 100% rename from StandaloneMmPkg rename to StandaloneMmPkg~HEAD --=20 2.16.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel