The Realm Service Interface (RSI) commands use registers between
X1-X10 as parameters and between X0-X8 as return values for SMC
calls.

According to the SMCCC Section 2.6 SMC32/HVC32 argument passing
  When an SMC32/HVC32 call is made from AArch32:
   - Arguments are passed in registers R1-R7.
   - Results are returned in R0-R7.
  When an SMC32/HVC32 call is made from AArch64:
   - Arguments are passed in registers W1-W7.
   - Results are returned in W0-W7.

According to SMCCC Section 2.7 SMC64/HVC64 argument passing
  When an SMC64/HVC64 call is made from AArch64:
   - Arguments are passed in registers X1-X17.
   - Results are returned in X0-X17.

This means SMC calls can take up to 7/17 arguments and return up
to 7/17 return values.

However, for the current use-case(s):
  - SMC32/HVC32 calls made from AArch32/AArch64 require up to 7
    arguments and 4 return values.
  - SMC64/HVC64 calls made from AArch64 require up to 10 arguments
    and 9 return values.

Therefore, for SMC32/HVC32 calls made from AArch32/AArch64 there is
no update required. However, for AMC64/HVC64 calls made from AArch64,
extend the ArmCallSmc () to use registers X1-X11 as parameters and
return values for SMC call.

Cc: Ard Biesheuvel <ardb+tianoc...@kernel.org>
Cc: Leif Lindholm <quic_llind...@quicinc.com>
Signed-off-by: Sami Mujawar <sami.muja...@arm.com>
---
 ArmPkg/Include/Library/ArmSmcLib.h        | 50 ++++++++++++++++++--
 ArmPkg/Library/ArmSmcLib/AArch64/ArmSmc.S | 22 ++++++---
 2 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/ArmPkg/Include/Library/ArmSmcLib.h 
b/ArmPkg/Include/Library/ArmSmcLib.h
index 
beef0175c35ce86aac9e465f9062bf8052b08dfb..e80b74671a6424723323bab95917fb3909771759
 100644
--- a/ArmPkg/Include/Library/ArmSmcLib.h
+++ b/ArmPkg/Include/Library/ArmSmcLib.h
@@ -1,10 +1,13 @@
 /** @file
 *
 *  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
-*  Copyright (c) 2012-2014, ARM Limited. All rights reserved.
+*  Copyright (c) 2012-2023, Arm Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
+*  @par Reference(s):
+*   - SMC Calling Convention (SMCCC), ARM DEN 0028E, EAC0, 1.4
+*     (https://developer.arm.com/documentation/den0028/e/)
 **/
 
 #ifndef ARM_SMC_LIB_H_
@@ -13,6 +16,18 @@
 /**
  * The size of the SMC arguments are different between AArch64 and AArch32.
  * The native size is used for the arguments.
+ * According to the SMCCC Section 2.6 SMC32/HVC32 argument passing
+ * When an SMC32/HVC32 call is made from AArch32:
+ *  - Arguments are passed in registers R1-R7.
+ *  - Results are returned in R0-R7.
+ * When an SMC32/HVC32 call is made from AArch64:
+ *  - Arguments are passed in registers W1-W7.
+ *  - Results are returned in W0-W7.
+ *
+ * According to SMCCC Section 2.7 SMC64/HVC64 argument passing
+ * When an SMC64/HVC64 call is made from AArch64:
+ *  - Arguments are passed in registers X1-X17.
+ *  - Results are returned in X0-X17.
  */
 typedef struct {
   UINTN    Arg0;
@@ -23,13 +38,42 @@ typedef struct {
   UINTN    Arg5;
   UINTN    Arg6;
   UINTN    Arg7;
+ #ifdef MDE_CPU_AARCH64
+  UINTN    Arg8;
+  UINTN    Arg9;
+  UINTN    Arg10;
+  UINTN    Arg11;
+ #endif
 } ARM_SMC_ARGS;
 
 /**
   Trigger an SMC call
 
-  SMC calls can take up to 7 arguments and return up to 4 return values.
-  Therefore, the 4 first fields in the ARM_SMC_ARGS structure are used
+  According to the SMCCC Section 2.6 SMC32/HVC32 argument passing
+  When an SMC32/HVC32 call is made from AArch32:
+   - Arguments are passed in registers R1-R7.
+   - Results are returned in R0-R7.
+  When an SMC32/HVC32 call is made from AArch64:
+   - Arguments are passed in registers W1-W7.
+   - Results are returned in W0-W7.
+
+  According to SMCCC Section 2.7 SMC64/HVC64 argument passing
+  When an SMC64/HVC64 call is made from AArch64:
+   - Arguments are passed in registers X1-X17.
+   - Results are returned in X0-X17.
+
+  This means SMC calls can take up to 7/17 arguments and return up
+  to 7/17 return values.
+
+  However, the current use-case:
+  - For SMC32/HVC32 calls made from AArch32/AArch64 up to 7 arguments
+    and 4 return values are required. Therefore, limit the maximum
+    arguments to 7 and return values to 4.
+  - For AMC64/HVC64 calls made from AArch64 up to 11 arguments and
+    return values are required. Therefore, limit the maximum arguments
+    and return values to 11.
+
+  The fields in the ARM_SMC_ARGS structure are used
   for both input and output values.
 
 **/
diff --git a/ArmPkg/Library/ArmSmcLib/AArch64/ArmSmc.S 
b/ArmPkg/Library/ArmSmcLib/AArch64/ArmSmc.S
index 
4a8c2a8f59eab3e5b66dda2515d5bbced131af13..299d612dc5e1ebfeaf69a356b400c511905d72fe
 100644
--- a/ArmPkg/Library/ArmSmcLib/AArch64/ArmSmc.S
+++ b/ArmPkg/Library/ArmSmcLib/AArch64/ArmSmc.S
@@ -1,8 +1,11 @@
 //
-//  Copyright (c) 2012-2014, ARM Limited. All rights reserved.
+//  Copyright (c) 2012-2023, Arm Limited. All rights reserved.
 //
 //  SPDX-License-Identifier: BSD-2-Clause-Patent
 //
+//  @par Reference(s):
+//   - SMC Calling Convention (SMCCC), ARM DEN 0028E, EAC0, 1.4
+//     (https://developer.arm.com/documentation/den0028/e/)
 //
 
 #include <AsmMacroIoLibV8.h>
@@ -12,6 +15,8 @@ ASM_FUNC(ArmCallSmc)
   str   x0, [sp, #-16]!
 
   // Load the SMC arguments values into the appropriate registers
+  ldp   x10, x11, [x0, #80]
+  ldp   x8, x9, [x0, #64]
   ldp   x6, x7, [x0, #48]
   ldp   x4, x5, [x0, #32]
   ldp   x2, x3, [x0, #16]
@@ -19,14 +24,17 @@ ASM_FUNC(ArmCallSmc)
 
   smc   #0
 
-  // Pop the ARM_SMC_ARGS structure address from the stack into x9
-  ldr   x9, [sp], #16
+  // Pop the ARM_SMC_ARGS structure address from the stack into x13
+  ldr   x13, [sp], #16
 
   // Store the SMC returned values into the ARM_SMC_ARGS structure.
-  // A SMC call can return up to 4 values - we do not need to store back x4-x7.
-  stp   x2, x3, [x9, #16]
-  stp   x0, x1, [x9, #0]
+  stp   x10, x11, [x13, #80]
+  stp   x8, x9, [x13, #64]
+  stp   x6, x7, [x13, #48]
+  stp   x4, x5, [x13, #32]
+  stp   x2, x3, [x13, #16]
+  stp   x0, x1, [x13, #0]
 
-  mov   x0, x9
+  mov   x0, x13
 
   ret
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117674): https://edk2.groups.io/g/devel/message/117674
Mute This Topic: https://groups.io/mt/105483412/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to