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.web11.1228.1689086236695707927 for ; Tue, 11 Jul 2023 07:37:16 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: nishant.sharma@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 88C68C15; Tue, 11 Jul 2023 07:37:58 -0700 (PDT) Received: from usa.arm.com (iss-desktop02.cambridge.arm.com [10.1.196.79]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6B07D3F740; Tue, 11 Jul 2023 07:37:15 -0700 (PDT) From: "Nishant Sharma" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Sami Mujawar , Thomas Abraham , Sayanta Pattanayak , Achin Gupta Subject: [edk2-platforms][PATCH V1 02/20] StandaloneMmPkg: Allocate and initialise SP stack from internal memory Date: Tue, 11 Jul 2023 15:36:40 +0100 Message-Id: <20230711143658.781597-3-nishant.sharma@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com> References: <20230711143658.781597-1-nishant.sharma@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Achin Gupta This patch removes the dependency on the SPM to allocate and initialise stack memory for the StMM SP. This is done by reserving 8K worth of memor= y in the StMM image at a page aligned address in the data section. Then, instead of jumping directly to the C entrypoint, an assembler entrypoint = is invoked. This entrypoint locates the stack memory, changes its permission= s using FF-A ABIs, sets the stack pointer and invokes the C entrypoint. Signed-off-by: Achin Gupta Signed-off-by: Nishant Sharma --- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntry= Point.inf | 1 + StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreE= ntryPoint.c | 2 +- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/AArch64/ModuleEnt= ryPoint.S | 68 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Standalon= eMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoin= t/StandaloneMmCoreEntryPoint.inf index dc6d3d859911..10fafa43ce59 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCore= EntryPoint.inf +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCore= EntryPoint.inf @@ -25,6 +25,7 @@ Arm/StandaloneMmCoreEntryPoint.c Arm/SetPermissions.c Arm/CreateHobList.c + Arm/AArch64/ModuleEntryPoint.S =20 [Sources.X64] X64/StandaloneMmCoreEntryPoint.c diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/Stand= aloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPo= int/Arm/StandaloneMmCoreEntryPoint.c index 5dd1d9747995..ce867fe85158 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMm= CoreEntryPoint.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMm= CoreEntryPoint.c @@ -316,7 +316,7 @@ InitArmSvcArgs ( **/ VOID EFIAPI -_ModuleEntryPoint ( +ModuleEntryPoint ( IN VOID *SharedBufAddress, IN UINT64 SharedBufSize, IN UINT64 cookie1, diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/AArch= 64/ModuleEntryPoint.S b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoin= t/Arm/AArch64/ModuleEntryPoint.S new file mode 100644 index 000000000000..174bc83ebd64 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/AArch64/Modu= leEntryPoint.S @@ -0,0 +1,68 @@ +// +// Copyright (c) 2023, ARM Limited. All rights reserved. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// + +#include + +#define FFA_DATA_RW 0x1 + +.align 12 +StackBase: +.space 8192 +StackEnd: + +.macro FfaMemPermSet start:req end:req perm:req +adrp x29, \start +add x29, x29, :lo12: \start + +adrp x30, \end +add x30, x30, :lo12:\end + +/* x30 =3D end - begin */ +sub x30, x30, x29 +/* x28 =3D x30 >> 12 (number of pages) */ +mov x28, #12 +lsrv x28, x30, x28 + +mov w0, #0x89 +movk w0, #0x8400, lsl #16 +mov x1, x29 +mov x2, x28 +mov w3, #\perm + +svc #0 + +mov w1, #0x61 +movk w1, #0x8400, lsl #16 +cmp w1, w0 +b.ne . +.endm + + ASM_FUNC(_ModuleEntryPoint) +MOV32 (w8, FixedPcdGet32(PcdFfaEnable)) + cbz w8, FfaNotEnabled + // Stash boot information registers from the SPMC + mov x8, x0 + mov x9, x1 + mov x10, x2 + mov x11, x3 + + // Set the correct permissions on stack memory + FfaMemPermSet StackBase StackEnd FFA_DATA_RW + + // Initialise SP + adr x0, StackEnd + mov sp, x0 + + // Restore boot information registers from the SPMC + mov x0, x8 + mov x1, x9 + mov x2, x10 + mov x3, x11 + + // Invoke the C entrypoint + FfaNotEnabled: + b ModuleEntryPoint --=20 2.34.1