git: e4c3536138f4 - main - dev/psci: Create macros to simplify calling SMCCC

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 17:25:09 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=e4c3536138f4a314dc26331b0a1488faae09aaf4

commit e4c3536138f4a314dc26331b0a1488faae09aaf4
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-10-14 14:33:44 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-10-15 17:24:41 +0000

    dev/psci: Create macros to simplify calling SMCCC
    
    When calling into SMCCC functions we often only need a few arguments.
    As the current function needs all 8 possible arguments to be set the
    unused values will be zero.
    
    Create a macro to pass in the used values, followed by enough zeros,
    then the result pointer.
    
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D46986
---
 sys/dev/psci/smccc.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/sys/dev/psci/smccc.h b/sys/dev/psci/smccc.h
index 96527f037d78..dd10fb8018ae 100644
--- a/sys/dev/psci/smccc.h
+++ b/sys/dev/psci/smccc.h
@@ -91,6 +91,38 @@ int arm_smccc_smc(register_t, register_t, register_t, register_t, register_t,
 int arm_smccc_hvc(register_t, register_t, register_t, register_t, register_t,
     register_t, register_t, register_t, struct arm_smccc_res *res);
 
+#define	arm_smccc_invoke_1(func, a0, res)				\
+    func(a0,  0,  0,  0,  0,  0,  0,  0, res)
+#define	arm_smccc_invoke_2(func, a0, a1, res)				\
+    func(a0, a1,  0,  0,  0,  0,  0,  0, res)
+#define	arm_smccc_invoke_3(func, a0, a1, a2, res)			\
+    func(a0, a1, a2,  0,  0,  0,  0,  0, res)
+#define	arm_smccc_invoke_4(func, a0, a1, a2, a3, res)			\
+    func(a0, a1, a2, a3,  0,  0,  0,  0, res)
+#define	arm_smccc_invoke_5(func, a0, a1, a2, a3, a4, res)		\
+    func(a0, a1, a2, a3, a4,  0,  0,  0, res)
+#define	arm_smccc_invoke_6(func, a0, a1, a2, a3, a4, a5, res)		\
+    func(a0, a1, a2, a3, a4, a5,  0,  0, res)
+#define	arm_smccc_invoke_7(func, a0, a1, a2, a3, a4, a5, a6, res)	\
+    func(a0, a1, a2, a3, a4, a5, a6,  0, res)
+#define	arm_smccc_invoke_8(func, a0, a1, a2, a3, a4, a5, a6, a7, res)	\
+    func(a0, a1, a2, a3, a4, a5, a6, a7, res)
+
+#define	_arm_smccc_invoke_macro(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) \
+    NAME
+#define	_arm_smccc_invoke(func, a0, ...)				\
+    _arm_smccc_invoke_macro(__VA_ARGS__, arm_smccc_invoke_8,		\
+      arm_smccc_invoke_7, arm_smccc_invoke_6, arm_smccc_invoke_5,	\
+      arm_smccc_invoke_4, arm_smccc_invoke_3, arm_smccc_invoke_2,	\
+      arm_smccc_invoke_1)(func, a0, __VA_ARGS__)
+
+#define	arm_smccc_invoke_hvc(a0, ...)					\
+    _arm_smccc_invoke(arm_smccc_hvc, a0, __VA_ARGS__)
+#define	arm_smccc_invoke_smc(a0, ...)					\
+    _arm_smccc_invoke(arm_smccc_smc, a0, __VA_ARGS__)
+#define	arm_smccc_invoke(a0, ...)					\
+    _arm_smccc_invoke(psci_callfn, a0, __VA_ARGS__)
+
 struct arm_smccc_1_2_regs {
 	register_t a0;
 	register_t a1;