[PATCH v2 01/21] KVM: arm64: Introduce template for inline functions

From: Gavin Shan
Date: Mon Feb 08 2021 - 22:45:39 EST


The inline functions used to get the SMCCC parameters have same
layout. It means the logical functionality can be presented by
a template, to make the code simplified. Besides, this adds more
similar inline functions like smccc_get_arg{4,5,6,7,8}() to visit
more SMCCC arguments, which are required by SDEI virtualization
support.

Signed-off-by: Gavin Shan <gshan@xxxxxxxxxx>
---
include/kvm/arm_hypercalls.h | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h
index 0e2509d27910..1120eff7aa28 100644
--- a/include/kvm/arm_hypercalls.h
+++ b/include/kvm/arm_hypercalls.h
@@ -6,27 +6,21 @@

#include <asm/kvm_emulate.h>

-int kvm_hvc_call_handler(struct kvm_vcpu *vcpu);
-
-static inline u32 smccc_get_function(struct kvm_vcpu *vcpu)
-{
- return vcpu_get_reg(vcpu, 0);
+#define SMCCC_DECLARE_GET_FUNCTION(type, name, reg) \
+static inline type smccc_get_##name(struct kvm_vcpu *vcpu) \
+{ \
+ return vcpu_get_reg(vcpu, (reg)); \
}

-static inline unsigned long smccc_get_arg1(struct kvm_vcpu *vcpu)
-{
- return vcpu_get_reg(vcpu, 1);
-}
-
-static inline unsigned long smccc_get_arg2(struct kvm_vcpu *vcpu)
-{
- return vcpu_get_reg(vcpu, 2);
-}
-
-static inline unsigned long smccc_get_arg3(struct kvm_vcpu *vcpu)
-{
- return vcpu_get_reg(vcpu, 3);
-}
+SMCCC_DECLARE_GET_FUNCTION(u32, function, 0)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg1, 1)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg2, 2)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg3, 3)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg4, 4)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg5, 5)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg6, 6)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg7, 7)
+SMCCC_DECLARE_GET_FUNCTION(unsigned long, arg8, 8)

static inline void smccc_set_retval(struct kvm_vcpu *vcpu,
unsigned long a0,
@@ -40,4 +34,6 @@ static inline void smccc_set_retval(struct kvm_vcpu *vcpu,
vcpu_set_reg(vcpu, 3, a3);
}

+int kvm_hvc_call_handler(struct kvm_vcpu *vcpu);
+
#endif
--
2.23.0