This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 6d74d766c67284b56ce04bbe4601a3aee3b29092
Author: hujun5 <[email protected]>
AuthorDate: Wed Apr 22 13:46:14 2026 +0800

    arch/arm: unify SMCCC interface across arm and arm64
    
    Rename arm64-prefixed SMCCC symbols to arch-neutral arm_ prefix
    (arm64_smccc_smc -> arm_smccc_smc, ARM64_SMCCC_NUTTX_* ->
    ARM_SMCCC_NUTTX_*) and move shared SMCCC macros, types and
    function declarations from arm64/include/syscall.h and
    arm_a_r/arm_cpu_psci.h into arch/arm/include/syscall.h so that
    both architectures use a single set of definitions. Add NuttX SPD
    SMC IDs (TEE_IDLE, REE_IDLE, SEND_SECURE_SGI) for arm32 TrustZone
    and simplify optee_smc.c conduit aliases.
    
    Signed-off-by: hujun5 <[email protected]>
---
 arch/arm/include/syscall.h             | 127 ++++++++++++++++++++++++++++++++-
 arch/arm/src/armv7-a/arm_cpu_psci.h    |  51 -------------
 arch/arm64/include/syscall.h           |  32 ++++-----
 arch/arm64/src/common/arm64_cpu_psci.c |  48 ++++++-------
 arch/arm64/src/common/arm64_cpu_psci.h |   2 +-
 arch/arm64/src/common/arm64_gicv3.c    |   4 +-
 arch/arm64/src/common/arm64_idle.c     |  16 ++---
 arch/arm64/src/common/arm64_smccc.S    |   8 +--
 drivers/tee/optee_smc.c                |   6 +-
 9 files changed, 181 insertions(+), 113 deletions(-)

diff --git a/arch/arm/include/syscall.h b/arch/arm/include/syscall.h
index e75ad239400..36a766826e9 100644
--- a/arch/arm/include/syscall.h
+++ b/arch/arm/include/syscall.h
@@ -125,16 +125,113 @@
 #define SYS_signal_handler_return (7)
 #endif /* !CONFIG_BUILD_FLAT */
 
+#define ARM_SMCC_RES_A0           (0)
+#define ARM_SMCC_RES_A1           (1)
+#define ARM_SMCC_RES_A2           (2)
+#define ARM_SMCC_RES_A3           (3)
+#define ARM_SMCC_RES_A4           (4)
+#define ARM_SMCC_RES_A5           (5)
+#define ARM_SMCC_RES_A6           (6)
+#define ARM_SMCC_RES_A7           (7)
+
+#define ARM_SMCCC_STD_CALL        0UL
+#define ARM_SMCCC_FAST_CALL       1UL
+#define ARM_SMCCC_TYPE_SHIFT      31
+
+#define ARM_SMCCC_SMC_32          0
+#define ARM_SMCCC_SMC_64          1
+#define ARM_SMCCC_CALL_CONV_SHIFT 30
+
+#define ARM_SMCCC_OWNER_MASK      0x3F
+#define ARM_SMCCC_OWNER_SHIFT     24
+
+#define ARM_SMCCC_FUNC_MASK       0xFFFF
+
+#define ARM_SMCCC_IS_FAST_CALL(smc_val) \
+  ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT))
+#define ARM_SMCCC_IS_64(smc_val) \
+  ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT))
+#define ARM_SMCCC_FUNC_NUM(smc_val)  ((smc_val) & ARM_SMCCC_FUNC_MASK)
+#define ARM_SMCCC_OWNER_NUM(smc_val) \
+  (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK)
+
+#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
+  (((type) << ARM_SMCCC_TYPE_SHIFT) | \
+  ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
+  (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
+  ((func_num) & ARM_SMCCC_FUNC_MASK))
+
+#define ARM_SMCCC_OWNER_ARCH            0
+#define ARM_SMCCC_OWNER_CPU             1
+#define ARM_SMCCC_OWNER_SIP             2
+#define ARM_SMCCC_OWNER_OEM             3
+#define ARM_SMCCC_OWNER_STANDARD        4
+#define ARM_SMCCC_OWNER_TRUSTED_APP     48
+#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49
+#define ARM_SMCCC_OWNER_TRUSTED_OS      50
+#define ARM_SMCCC_OWNER_TRUSTED_OS_END  63
+
+#define ARM_SMCCC_QUIRK_NONE            0
+#define ARM_SMCCC_QUIRK_QCOM_A6         1 /* Save/restore register a6 */
+
+#define ARM_SMCCC_ARCH_FEATURES         0x80000001
+
+#define ARM_SMCCC_RET_NOT_SUPPORTED     ((unsigned long)-1)
+
+/* NuttX SPD (Secure Payload Dispatcher) SMC function IDs.
+ * Used for BL32 <-> BL31 communication in TrustZone configurations.
+ *
+ * Yielding SMCs: world-switch / long-running ops, may be preempted.
+ * Fast SMCs: short atomic ops, non-preemptible.
+ */
+
+#define ARM_SMCCC_NUTTX_SEND_SECURE_SGI \
+  ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
+                     ARM_SMCCC_OWNER_TRUSTED_OS_END, 0x0000)
+
+#define ARM_SMCCC_NUTTX_TEE_IDLE \
+  ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
+                     ARM_SMCCC_OWNER_TRUSTED_OS_END, 0x0001)
+
+#define ARM_SMCCC_NUTTX_REE_IDLE \
+  ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
+                     ARM_SMCCC_OWNER_TRUSTED_OS_END, 0x0002)
+
+#ifndef __ASSEMBLY__
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
 
+/* Result from SMC/HVC call
+ * a0-a7 result values from registers 0 to 7
+ */
+
+struct arm_smccc_res
+{
+  unsigned long a0;
+  unsigned long a1;
+  unsigned long a2;
+  unsigned long a3;
+  unsigned long a4;
+  unsigned long a5;
+  unsigned long a6;
+  unsigned long a7;
+};
+
+typedef struct arm_smccc_res arm_smccc_res_t;
+
+enum arm_smccc_conduit
+{
+  SMCCC_CONDUIT_NONE,
+  SMCCC_CONDUIT_SMC,
+  SMCCC_CONDUIT_HVC,
+};
+
 /****************************************************************************
  * Inline functions
  ****************************************************************************/
 
-#ifndef __ASSEMBLY__
-
 /* A system call returns with R1-R3 and R12 changed (dispatch_syscall() calls
  * the stub function), so the macros give these registers to the compiler
  * as outputs or as clobbered.
@@ -500,6 +597,32 @@
  * Public Function Prototypes
  ****************************************************************************/
 
+/* Make HVC calls
+ *
+ * param a0 function identifier
+ * param a1-a7 parameters registers
+ * param res results
+ */
+
+void arm_smccc_hvc(unsigned long a0, unsigned long a1,
+                   unsigned long a2, unsigned long a3,
+                   unsigned long a4, unsigned long a5,
+                   unsigned long a6, unsigned long a7,
+                   struct arm_smccc_res *res);
+
+/* Make SMC calls
+ *
+ * param a0 function identifier
+ * param a1-a7 parameters registers
+ * param res results
+ */
+
+void arm_smccc_smc(unsigned long a0, unsigned long a1,
+                   unsigned long a2, unsigned long a3,
+                   unsigned long a4, unsigned long a5,
+                   unsigned long a6, unsigned long a7,
+                   struct arm_smccc_res *res);
+
 #ifdef __cplusplus
 extern "C"
 {
diff --git a/arch/arm/src/armv7-a/arm_cpu_psci.h 
b/arch/arm/src/armv7-a/arm_cpu_psci.h
index b4515dd72de..91ba9b63843 100644
--- a/arch/arm/src/armv7-a/arm_cpu_psci.h
+++ b/arch/arm/src/armv7-a/arm_cpu_psci.h
@@ -85,31 +85,6 @@
 #define PSCI_VERSION_MINOR(ver) \
   ((ver) & PSCI_VERSION_MINOR_MASK)
 
-/* Result from SMC/HVC call
- * a0-a7 result values from registers 0 to 7
- */
-
-struct arm_smccc_res
-{
-  unsigned long a0;
-  unsigned long a1;
-  unsigned long a2;
-  unsigned long a3;
-  unsigned long a4;
-  unsigned long a5;
-  unsigned long a6;
-  unsigned long a7;
-};
-
-typedef struct arm_smccc_res arm_smccc_res_t;
-
-enum arm_smccc_conduit
-{
-  SMCCC_CONDUIT_NONE,
-  SMCCC_CONDUIT_SMC,
-  SMCCC_CONDUIT_HVC,
-};
-
 typedef unsigned long (*psci_fn)(unsigned long, unsigned long, unsigned long,
                                  unsigned long);
 
@@ -124,32 +99,6 @@ struct psci_interface
  * Public Function Prototypes
  ****************************************************************************/
 
-/* Make HVC calls
- *
- * param a0 function identifier
- * param a1-a7 parameters registers
- * param res results
- */
-
-void arm_smccc_hvc(unsigned long a0, unsigned long a1,
-                   unsigned long a2, unsigned long a3,
-                   unsigned long a4, unsigned long a5,
-                   unsigned long a6, unsigned long a7,
-                   struct arm_smccc_res *res);
-
-/* Make SMC calls
- *
- * param a0 function identifier
- * param a1-a7 parameters registers
- * param res results
- */
-
-void arm_smccc_smc(unsigned long a0, unsigned long a1,
-                   unsigned long a2, unsigned long a3,
-                   unsigned long a4, unsigned long a5,
-                   unsigned long a6, unsigned long a7,
-                   struct arm_smccc_res *res);
-
 uint32_t psci_version(void);
 int psci_cpu_off(void);
 int psci_cpu_on(unsigned long cpuid, uintptr_t entry_point);
diff --git a/arch/arm64/include/syscall.h b/arch/arm64/include/syscall.h
index d8bfd987c45..4c3e577c0c2 100644
--- a/arch/arm64/include/syscall.h
+++ b/arch/arm64/include/syscall.h
@@ -161,15 +161,15 @@
  * Fast SMCs: short atomic ops, non-preemptible.
  */
 
-#define ARM64_SMCCC_NUTTX_SEND_SECURE_SGI \
+#define ARM_SMCCC_NUTTX_SEND_SECURE_SGI \
   ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
                      ARM_SMCCC_OWNER_TRUSTED_OS_END, 0x0000)
 
-#define ARM64_SMCCC_NUTTX_TEE_IDLE \
+#define ARM_SMCCC_NUTTX_TEE_IDLE \
   ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_64, \
                      ARM_SMCCC_OWNER_TRUSTED_OS_END, 0x0001)
 
-#define ARM64_SMCCC_NUTTX_REE_IDLE \
+#define ARM_SMCCC_NUTTX_REE_IDLE \
   ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_64, \
                      ARM_SMCCC_OWNER_TRUSTED_OS_END, 0x0002)
 
@@ -183,7 +183,7 @@
  * a0-a7 result values from registers 0 to 7
  */
 
-struct arm64_smccc_res
+struct arm_smccc_res
 {
   unsigned long a0;
   unsigned long a1;
@@ -195,9 +195,9 @@ struct arm64_smccc_res
   unsigned long a7;
 };
 
-typedef struct arm64_smccc_res arm64_smccc_res_t;
+typedef struct arm_smccc_res arm_smccc_res_t;
 
-enum arm64_smccc_conduit
+enum arm_smccc_conduit
 {
   SMCCC_CONDUIT_NONE,
   SMCCC_CONDUIT_SMC,
@@ -394,11 +394,11 @@ static inline long smh_call(unsigned int nbr, void *parm)
  * param res results
  */
 
-void arm64_smccc_hvc(unsigned long a0, unsigned long a1,
-                     unsigned long a2, unsigned long a3,
-                     unsigned long a4, unsigned long a5,
-                     unsigned long a6, unsigned long a7,
-                     struct arm64_smccc_res *res);
+void arm_smccc_hvc(unsigned long a0, unsigned long a1,
+                   unsigned long a2, unsigned long a3,
+                   unsigned long a4, unsigned long a5,
+                   unsigned long a6, unsigned long a7,
+                   struct arm_smccc_res *res);
 
 /* Make SMC calls
  *
@@ -407,11 +407,11 @@ void arm64_smccc_hvc(unsigned long a0, unsigned long a1,
  * param res results
  */
 
-void arm64_smccc_smc(unsigned long a0, unsigned long a1,
-                     unsigned long a2, unsigned long a3,
-                     unsigned long a4, unsigned long a5,
-                     unsigned long a6, unsigned long a7,
-                     struct arm64_smccc_res *res);
+void arm_smccc_smc(unsigned long a0, unsigned long a1,
+                   unsigned long a2, unsigned long a3,
+                   unsigned long a4, unsigned long a5,
+                   unsigned long a6, unsigned long a7,
+                   struct arm_smccc_res *res);
 
 #ifdef __cplusplus
 extern "C"
diff --git a/arch/arm64/src/common/arm64_cpu_psci.c 
b/arch/arm64/src/common/arm64_cpu_psci.c
index db5e21a943a..5c29e675a3a 100644
--- a/arch/arm64/src/common/arm64_cpu_psci.c
+++ b/arch/arm64/src/common/arm64_cpu_psci.c
@@ -52,26 +52,26 @@ static int psci_to_dev_err(int ret)
 {
   switch (ret)
     {
-    case PSCI_RET_SUCCESS:
-      {
-        return 0;
-      }
-
-    case PSCI_RET_NOT_SUPPORTED:
-      {
-        return -ENOTSUP;
-      }
-
-    case PSCI_RET_INVALID_PARAMS:
-    case PSCI_RET_INVALID_ADDRESS:
-      {
-        return -EINVAL;
-      }
-
-    case PSCI_RET_DENIED:
-      {
-        return -EPERM;
-      }
+      case PSCI_RET_SUCCESS:
+        {
+          return 0;
+        }
+
+      case PSCI_RET_NOT_SUPPORTED:
+        {
+          return -ENOTSUP;
+        }
+
+      case PSCI_RET_INVALID_PARAMS:
+      case PSCI_RET_INVALID_ADDRESS:
+        {
+          return -EINVAL;
+        }
+
+      case PSCI_RET_DENIED:
+        {
+          return -EPERM;
+        }
     }
 
   return -EINVAL;
@@ -82,9 +82,9 @@ static unsigned long __invoke_psci_fn_hvc(unsigned long 
function_id,
                                           unsigned long arg1,
                                           unsigned long arg2)
 {
-  struct arm64_smccc_res res;
+  struct arm_smccc_res res;
 
-  arm64_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
+  arm_smccc_hvc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
   return res.a0;
 }
 
@@ -93,9 +93,9 @@ static unsigned long __invoke_psci_fn_smc(unsigned long 
function_id,
                                           unsigned long arg1,
                                           unsigned long arg2)
 {
-  struct arm64_smccc_res res;
+  struct arm_smccc_res res;
 
-  arm64_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
+  arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res);
   return res.a0;
 }
 
diff --git a/arch/arm64/src/common/arm64_cpu_psci.h 
b/arch/arm64/src/common/arm64_cpu_psci.h
index edb54edd683..0a2d430c0f9 100644
--- a/arch/arm64/src/common/arm64_cpu_psci.h
+++ b/arch/arm64/src/common/arm64_cpu_psci.h
@@ -90,7 +90,7 @@ typedef unsigned long (*psci_fn)(unsigned long, unsigned 
long, unsigned long,
 
 struct psci_interface
 {
-  enum arm64_smccc_conduit conduit;
+  enum arm_smccc_conduit conduit;
   psci_fn invoke_psci_fn;
   uint32_t version;
 };
diff --git a/arch/arm64/src/common/arm64_gicv3.c 
b/arch/arm64/src/common/arm64_gicv3.c
index eed7433787c..c8194903a2d 100644
--- a/arch/arm64/src/common/arm64_gicv3.c
+++ b/arch/arm64/src/common/arm64_gicv3.c
@@ -849,9 +849,9 @@ void up_trigger_irq(int irq, cpu_set_t cpuset)
 
       if (!(IGROUPR_SGI_SECURE_VAL & BIT(irq)))
         {
-          struct arm64_smccc_res res;
+          struct arm_smccc_res res;
 
-          arm64_smccc_smc(ARM64_SMCCC_NUTTX_SEND_SECURE_SGI,
+          arm_smccc_smc(ARM_SMCCC_NUTTX_SEND_SECURE_SGI,
                           irq, 0, 0, 0, 0, 0, 0, &res);
         }
       else
diff --git a/arch/arm64/src/common/arm64_idle.c 
b/arch/arm64/src/common/arm64_idle.c
index fd8db6fc86d..d4f314fc868 100644
--- a/arch/arm64/src/common/arm64_idle.c
+++ b/arch/arm64/src/common/arm64_idle.c
@@ -59,7 +59,7 @@ void up_idle(void)
 
   /* Secure OS idle.
    *
-   * Every entry calls ARM64_SMCCC_NUTTX_TEE_IDLE:
+   * Every entry calls ARM_SMCCC_NUTTX_TEE_IDLE:
    *   - First call: EL3 registers interrupt handlers and boots REE.
    *   - Subsequent calls: EL3 checks if REE was preempted by G1S.
    *     If so, resumes REE. Otherwise returns 0 and TEE does WFI.
@@ -68,13 +68,13 @@ void up_idle(void)
    *   1. Secure timer fires from REE -> EL3 does world switch ->
    *      TEE resumes here (after SMC/WFI) -> pending G1S IRQ
    *      fires through normal S-EL1 vector table -> threads run ->
-   *      all done -> back here -> ARM64_SMCCC_NUTTX_TEE_IDLE -> resume REE
+   *      all done -> back here -> ARM_SMCCC_NUTTX_TEE_IDLE -> resume REE
    *   2. TEE was preempted by NS interrupt -> REE idle sends
-   *      ARM64_SMCCC_NUTTX_REE_IDLE -> EL3 switches to TEE -> TEE
-   *      continues -> eventually idle -> ARM64_SMCCC_NUTTX_TEE_IDLE here
+   *      ARM_SMCCC_NUTTX_REE_IDLE -> EL3 switches to TEE -> TEE
+   *      continues -> eventually idle -> ARM_SMCCC_NUTTX_TEE_IDLE here
    */
 
-  struct arm64_smccc_res res;
+  struct arm_smccc_res res;
 
   /* TEE idle: on first call, EL3 registers interrupt handlers
    * and switches to REE. On subsequent calls, checks if REE
@@ -88,7 +88,7 @@ void up_idle(void)
 
   irqstate_t flags = irq_save();
 
-  arm64_smccc_smc(ARM64_SMCCC_NUTTX_TEE_IDLE, 0, 0, 0, 0, 0, 0, 0, &res);
+  arm_smccc_smc(ARM_SMCCC_NUTTX_TEE_IDLE, 0, 0, 0, 0, 0, 0, 0, &res);
 
   asm("dsb sy");
   asm("wfi");
@@ -103,9 +103,9 @@ void up_idle(void)
    * and TEE_IDLE will resume us later.
    */
 
-  struct arm64_smccc_res res;
+  struct arm_smccc_res res;
 
-  arm64_smccc_smc(ARM64_SMCCC_NUTTX_REE_IDLE, 0, 0, 0, 0, 0, 0, 0, &res);
+  arm_smccc_smc(ARM_SMCCC_NUTTX_REE_IDLE, 0, 0, 0, 0, 0, 0, 0, &res);
 #else
 
   /* Sleep until an interrupt occurs to save power */
diff --git a/arch/arm64/src/common/arm64_smccc.S 
b/arch/arm64/src/common/arm64_smccc.S
index 0e53bc909a0..96533de61b9 100644
--- a/arch/arm64/src/common/arm64_smccc.S
+++ b/arch/arm64/src/common/arm64_smccc.S
@@ -51,8 +51,8 @@
  * handled by Secure Monitor code running in EL3.
  */
 
-GTEXT(arm64_smccc_smc)
-SECTION_FUNC(text, arm64_smccc_smc)
+GTEXT(arm_smccc_smc)
+SECTION_FUNC(text, arm_smccc_smc)
     smc   #0
     ldr   x4, [sp]
     stp   x0, x1, [x4, #8 * ARM_SMCC_RES_A0]
@@ -65,8 +65,8 @@ SECTION_FUNC(text, arm64_smccc_smc)
  * handled by a hypervisor running in EL2.
  */
 
-GTEXT(arm64_smccc_hvc)
-SECTION_FUNC(text, arm64_smccc_hvc)
+GTEXT(arm_smccc_hvc)
+SECTION_FUNC(text, arm_smccc_hvc)
     hvc   #0
     ldr   x4, [sp]
     stp   x0, x1, [x4, #8 * ARM_SMCC_RES_A0]
diff --git a/drivers/tee/optee_smc.c b/drivers/tee/optee_smc.c
index 3321f7c2d00..7187853a77e 100644
--- a/drivers/tee/optee_smc.c
+++ b/drivers/tee/optee_smc.c
@@ -40,14 +40,10 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#if defined(CONFIG_ARCH_ARM)
+#if defined(CONFIG_ARCH_ARM) || defined(CONFIG_ARCH_ARM64)
 #  define smccc_smc                  arm_smccc_smc
 #  define smccc_hvc                  arm_smccc_hvc
 #  define smccc_res_t                arm_smccc_res_t
-#elif defined(CONFIG_ARCH_ARM64)
-#  define smccc_smc                  arm64_smccc_smc
-#  define smccc_hvc                  arm64_smccc_hvc
-#  define smccc_res_t                arm64_smccc_res_t
 #else
 #  error "CONFIG_DEV_OPTEE_SMC is only supported on arm and arm64"
 #endif

Reply via email to