From: "Nishant Sharma" <nishant.sharma@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
Sami Mujawar <sami.mujawar@arm.com>,
Thomas Abraham <thomas.abraham@arm.com>,
Sayanta Pattanayak <sayanta.pattanayak@arm.com>,
Achin Gupta <achin.gupta@arm.com>
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 [thread overview]
Message-ID: <20230711143658.781597-3-nishant.sharma@arm.com> (raw)
In-Reply-To: <20230711143658.781597-1-nishant.sharma@arm.com>
From: Achin Gupta <achin.gupta@arm.com>
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 memory
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 permissions
using FF-A ABIs, sets the stack pointer and invokes the C entrypoint.
Signed-off-by: Achin Gupta <achin.gupta@arm.com>
Signed-off-by: Nishant Sharma <nishant.sharma@arm.com>
---
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf | 1 +
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c | 2 +-
StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/AArch64/ModuleEntryPoint.S | 68 ++++++++++++++++++++
3 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
index dc6d3d859911..10fafa43ce59 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf
@@ -25,6 +25,7 @@
Arm/StandaloneMmCoreEntryPoint.c
Arm/SetPermissions.c
Arm/CreateHobList.c
+ Arm/AArch64/ModuleEntryPoint.S
[Sources.X64]
X64/StandaloneMmCoreEntryPoint.c
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
index 5dd1d9747995..ce867fe85158 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.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/AArch64/ModuleEntryPoint.S b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/AArch64/ModuleEntryPoint.S
new file mode 100644
index 000000000000..174bc83ebd64
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/AArch64/ModuleEntryPoint.S
@@ -0,0 +1,68 @@
+//
+// Copyright (c) 2023, ARM Limited. All rights reserved.
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//
+
+#include <AsmMacroIoLibV8.h>
+
+#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 = end - begin */
+sub x30, x30, x29
+/* x28 = 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
--
2.34.1
next prev parent reply other threads:[~2023-07-11 14:37 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 14:36 [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 01/20] ArmPkg: Change PcdFfaEnable flag datatype Nishant Sharma
2023-07-12 17:21 ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 17:23 ` Chris Fernald
2023-07-11 14:36 ` Nishant Sharma [this message]
2023-07-12 17:47 ` [edk2-devel] [edk2-platforms][PATCH V1 02/20] StandaloneMmPkg: Allocate and initialise SP stack from internal memory Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 03/20] StandaloneMmPkg: Include libfdt in the StMM Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 04/20] ArmPkg: Add data structures to receive FF-A boot information Nishant Sharma
2023-07-12 17:27 ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 05/20] ArmPkg/ArmFfaSvc: Add helper macros and fids Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 06/20] ArmPkg: Add support for FFA_MEM_PERM_GET/SET ABIs Nishant Sharma
2023-07-12 17:43 ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 07/20] StandaloneMmPkg: define new data structure to stage FF-A boot information Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 08/20] StandaloneMmPkg: Add backwards compatible support to detect FF-A v1.1 Nishant Sharma
2023-07-12 20:31 ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 09/20] StandaloneMmPkg: parse SP manifest and populate new boot information Nishant Sharma
2023-07-13 15:24 ` [edk2-devel] " Girish Mahadevan
2023-07-13 16:48 ` Chris Fernald
2023-07-13 20:49 ` Achin Gupta
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 10/20] StandaloneMmPkg: Populate Hoblist for SP init from StMM " Nishant Sharma
2023-07-12 20:52 ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 11/20] StandaloneMmPkg: Skip zero sized sections while tweaking page permissions Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 12/20] StandaloneMmPkg: Add global check for FF-A abis Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 13/20] ArmPkg: Bump the StMM SP FF-A minor version to 1 Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 14/20] ArmPkg/MmCommunicationDxe: Introduce FF-A version check Nishant Sharma
2023-07-13 16:56 ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 15/20] ArmPkg/MmCommunicationDxe: Add support for obtaining FF-A partition ID Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 16/20] ArmPkg/MmCommunicationDxe: Register FF-A RX/TX buffers Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 17/20] ArmPkg/MmCommunicationDxe: Unmap FF-A RX/TX buffers during ExitBootServices Nishant Sharma
2023-07-12 20:59 ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 18/20] ArmPkg/MmCommunicationDxe: Discover the StMM SP Nishant Sharma
2023-07-12 21:10 ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 21:48 ` Girish Mahadevan
2023-07-13 17:16 ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 19/20] ArmPkg/MmCommunicationDxe: Use the FF-A transport for MM requests Nishant Sharma
2023-07-11 19:22 ` [edk2-devel] " Kun Qin
2023-07-12 14:21 ` achin.gupta
2023-07-12 17:13 ` Kun Qin
2023-07-12 21:49 ` Girish Mahadevan
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 20/20] StandaloneMmPkg: Add support for MM requests as FF-A direct messages Nishant Sharma
2023-07-12 21:13 ` [edk2-devel] [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Oliver Smith-Denny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230711143658.781597-3-nishant.sharma@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox