linux/include/linux/arm-smccc.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2015, Linaro Limited
 */
#ifndef __LINUX_ARM_SMCCC_H
#define __LINUX_ARM_SMCCC_H

#include <linux/args.h>
#include <linux/init.h>
#include <uapi/linux/const.h>

/*
 * This file provides common defines for ARM SMC Calling Convention as
 * specified in
 * https://developer.arm.com/docs/den0028/latest
 *
 * This code is up-to-date with version DEN 0028 C
 */

#define ARM_SMCCC_STD_CALL
#define ARM_SMCCC_FAST_CALL
#define ARM_SMCCC_TYPE_SHIFT

#define ARM_SMCCC_SMC_32
#define ARM_SMCCC_SMC_64
#define ARM_SMCCC_CALL_CONV_SHIFT

#define ARM_SMCCC_OWNER_MASK
#define ARM_SMCCC_OWNER_SHIFT

#define ARM_SMCCC_FUNC_MASK

#define ARM_SMCCC_IS_FAST_CALL(smc_val)
#define ARM_SMCCC_IS_64(smc_val)
#define ARM_SMCCC_FUNC_NUM(smc_val)
#define ARM_SMCCC_OWNER_NUM(smc_val)

#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num)

#define ARM_SMCCC_OWNER_ARCH
#define ARM_SMCCC_OWNER_CPU
#define ARM_SMCCC_OWNER_SIP
#define ARM_SMCCC_OWNER_OEM
#define ARM_SMCCC_OWNER_STANDARD
#define ARM_SMCCC_OWNER_STANDARD_HYP
#define ARM_SMCCC_OWNER_VENDOR_HYP
#define ARM_SMCCC_OWNER_TRUSTED_APP
#define ARM_SMCCC_OWNER_TRUSTED_APP_END
#define ARM_SMCCC_OWNER_TRUSTED_OS
#define ARM_SMCCC_OWNER_TRUSTED_OS_END

#define ARM_SMCCC_FUNC_QUERY_CALL_UID

#define ARM_SMCCC_QUIRK_NONE
#define ARM_SMCCC_QUIRK_QCOM_A6

#define ARM_SMCCC_VERSION_1_0
#define ARM_SMCCC_VERSION_1_1
#define ARM_SMCCC_VERSION_1_2
#define ARM_SMCCC_VERSION_1_3

#define ARM_SMCCC_1_3_SVE_HINT
#define ARM_SMCCC_CALL_HINTS


#define ARM_SMCCC_VERSION_FUNC_ID

#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID

#define ARM_SMCCC_ARCH_SOC_ID

#define ARM_SMCCC_ARCH_WORKAROUND_1

#define ARM_SMCCC_ARCH_WORKAROUND_2

#define ARM_SMCCC_ARCH_WORKAROUND_3

#define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID

/* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74 */
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3

/* KVM "vendor specific" services */
#define ARM_SMCCC_KVM_FUNC_FEATURES
#define ARM_SMCCC_KVM_FUNC_PTP
#define ARM_SMCCC_KVM_FUNC_FEATURES_2
#define ARM_SMCCC_KVM_NUM_FUNCS

#define ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID

#define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED

/*
 * ptp_kvm is a feature used for time sync between vm and host.
 * ptp_kvm module in guest kernel will get service from host using
 * this hypercall ID.
 */
#define ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID

/* ptp_kvm counter type ID */
#define KVM_PTP_VIRT_COUNTER
#define KVM_PTP_PHYS_COUNTER

/* Paravirtualised time calls (defined by ARM DEN0057A) */
#define ARM_SMCCC_HV_PV_TIME_FEATURES

#define ARM_SMCCC_HV_PV_TIME_ST

/* TRNG entropy source calls (defined by ARM DEN0098) */
#define ARM_SMCCC_TRNG_VERSION

#define ARM_SMCCC_TRNG_FEATURES

#define ARM_SMCCC_TRNG_GET_UUID

#define ARM_SMCCC_TRNG_RND32

#define ARM_SMCCC_TRNG_RND64

/*
 * Return codes defined in ARM DEN 0070A
 * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C
 */
#define SMCCC_RET_SUCCESS
#define SMCCC_RET_NOT_SUPPORTED
#define SMCCC_RET_NOT_REQUIRED
#define SMCCC_RET_INVALID_PARAMETER

#ifndef __ASSEMBLY__

#include <linux/linkage.h>
#include <linux/types.h>

enum arm_smccc_conduit {};

/**
 * arm_smccc_1_1_get_conduit()
 *
 * Returns the conduit to be used for SMCCCv1.1 or later.
 *
 * When SMCCCv1.1 is not present, returns SMCCC_CONDUIT_NONE.
 */
enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void);

/**
 * arm_smccc_get_version()
 *
 * Returns the version to be used for SMCCCv1.1 or later.
 *
 * When SMCCCv1.1 or above is not present, returns SMCCCv1.0, but this
 * does not imply the presence of firmware or a valid conduit. Caller
 * handling SMCCCv1.0 must determine the conduit by other means.
 */
u32 arm_smccc_get_version(void);

void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit);

extern u64 smccc_has_sve_hint;

/**
 * arm_smccc_get_soc_id_version()
 *
 * Returns the SOC ID version.
 *
 * When ARM_SMCCC_ARCH_SOC_ID is not present, returns SMCCC_RET_NOT_SUPPORTED.
 */
s32 arm_smccc_get_soc_id_version(void);

/**
 * arm_smccc_get_soc_id_revision()
 *
 * Returns the SOC ID revision.
 *
 * When ARM_SMCCC_ARCH_SOC_ID is not present, returns SMCCC_RET_NOT_SUPPORTED.
 */
s32 arm_smccc_get_soc_id_revision(void);

/**
 * struct arm_smccc_res - Result from SMC/HVC call
 * @a0-a3 result values from registers 0 to 3
 */
struct arm_smccc_res {};

#ifdef CONFIG_ARM64
/**
 * struct arm_smccc_1_2_regs - Arguments for or Results from SMC/HVC call
 * @a0-a17 argument values from registers 0 to 17
 */
struct arm_smccc_1_2_regs {
	unsigned long a0;
	unsigned long a1;
	unsigned long a2;
	unsigned long a3;
	unsigned long a4;
	unsigned long a5;
	unsigned long a6;
	unsigned long a7;
	unsigned long a8;
	unsigned long a9;
	unsigned long a10;
	unsigned long a11;
	unsigned long a12;
	unsigned long a13;
	unsigned long a14;
	unsigned long a15;
	unsigned long a16;
	unsigned long a17;
};

/**
 * arm_smccc_1_2_hvc() - make HVC calls
 * @args: arguments passed via struct arm_smccc_1_2_regs
 * @res: result values via struct arm_smccc_1_2_regs
 *
 * This function is used to make HVC calls following SMC Calling Convention
 * v1.2 or above. The content of the supplied param are copied from the
 * structure to registers prior to the HVC instruction. The return values
 * are updated with the content from registers on return from the HVC
 * instruction.
 */
asmlinkage void arm_smccc_1_2_hvc(const struct arm_smccc_1_2_regs *args,
				  struct arm_smccc_1_2_regs *res);

/**
 * arm_smccc_1_2_smc() - make SMC calls
 * @args: arguments passed via struct arm_smccc_1_2_regs
 * @res: result values via struct arm_smccc_1_2_regs
 *
 * This function is used to make SMC calls following SMC Calling Convention
 * v1.2 or above. The content of the supplied param are copied from the
 * structure to registers prior to the SMC instruction. The return values
 * are updated with the content from registers on return from the SMC
 * instruction.
 */
asmlinkage void arm_smccc_1_2_smc(const struct arm_smccc_1_2_regs *args,
				  struct arm_smccc_1_2_regs *res);
#endif

/**
 * struct arm_smccc_quirk - Contains quirk information
 * @id: quirk identification
 * @state: quirk specific information
 * @a6: Qualcomm quirk entry for returning post-smc call contents of a6
 */
struct arm_smccc_quirk {};

/**
 * __arm_smccc_sve_check() - Set the SVE hint bit when doing SMC calls
 *
 * Sets the SMCCC hint bit to indicate if there is live state in the SVE
 * registers, this modifies x0 in place and should never be called from C
 * code.
 */
asmlinkage unsigned long __arm_smccc_sve_check(unsigned long x0);

/**
 * __arm_smccc_smc() - make SMC calls
 * @a0-a7: arguments passed in registers 0 to 7
 * @res: result values from registers 0 to 3
 * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
 *
 * This function is used to make SMC calls following SMC Calling Convention.
 * The content of the supplied param are copied to registers 0 to 7 prior
 * to the SMC instruction. The return values are updated with the content
 * from register 0 to 3 on return from the SMC instruction.  An optional
 * quirk structure provides vendor specific behavior.
 */
#ifdef CONFIG_HAVE_ARM_SMCCC
asmlinkage 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, struct arm_smccc_quirk *quirk);
#else
static inline 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, struct arm_smccc_quirk *quirk)
{}
#endif

/**
 * __arm_smccc_hvc() - make HVC calls
 * @a0-a7: arguments passed in registers 0 to 7
 * @res: result values from registers 0 to 3
 * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
 *
 * This function is used to make HVC calls following SMC Calling
 * Convention.  The content of the supplied param are copied to registers 0
 * to 7 prior to the HVC instruction. The return values are updated with
 * the content from register 0 to 3 on return from the HVC instruction.  An
 * optional quirk structure provides vendor specific behavior.
 */
asmlinkage 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, struct arm_smccc_quirk *quirk);

#define arm_smccc_smc(...)

#define arm_smccc_smc_quirk(...)

#define arm_smccc_hvc(...)

#define arm_smccc_hvc_quirk(...)

/* SMCCC v1.1 implementation madness follows */
#ifdef CONFIG_ARM64

#define SMCCC_SMC_INST
#define SMCCC_HVC_INST

#elif defined(CONFIG_ARM)
#include <asm/opcodes-sec.h>
#include <asm/opcodes-virt.h>

#define SMCCC_SMC_INST
#define SMCCC_HVC_INST

#endif

/* nVHE hypervisor doesn't have a current thread so needs separate checks */
#if defined(CONFIG_ARM64_SVE) && !defined(__KVM_NVHE_HYPERVISOR__)

#define SMCCC_SVE_CHECK
#define smccc_sve_clobbers

#else

#define SMCCC_SVE_CHECK
#define smccc_sve_clobbers

#endif

#define __constraint_read_2
#define __constraint_read_3
#define __constraint_read_4
#define __constraint_read_5
#define __constraint_read_6
#define __constraint_read_7
#define __constraint_read_8
#define __constraint_read_9

#define __declare_arg_2(a0, res)

#define __declare_arg_3(a0, a1, res)

#define __declare_arg_4(a0, a1, a2, res)

#define __declare_arg_5(a0, a1, a2, a3, res)

#define __declare_arg_6(a0, a1, a2, a3, a4, res)

#define __declare_arg_7(a0, a1, a2, a3, a4, a5, res)

#define __declare_arg_8(a0, a1, a2, a3, a4, a5, a6, res)

#define __declare_arg_9(a0, a1, a2, a3, a4, a5, a6, a7, res)

/*
 * We have an output list that is not necessarily used, and GCC feels
 * entitled to optimise the whole sequence away. "volatile" is what
 * makes it stick.
 */
#define __arm_smccc_1_1(inst, ...)

/*
 * arm_smccc_1_1_smc() - make an SMCCC v1.1 compliant SMC call
 *
 * This is a variadic macro taking one to eight source arguments, and
 * an optional return structure.
 *
 * @a0-a7: arguments passed in registers 0 to 7
 * @res: result values from registers 0 to 3
 *
 * This macro is used to make SMC calls following SMC Calling Convention v1.1.
 * The content of the supplied param are copied to registers 0 to 7 prior
 * to the SMC instruction. The return values are updated with the content
 * from register 0 to 3 on return from the SMC instruction if not NULL.
 */
#define arm_smccc_1_1_smc(...)

/*
 * arm_smccc_1_1_hvc() - make an SMCCC v1.1 compliant HVC call
 *
 * This is a variadic macro taking one to eight source arguments, and
 * an optional return structure.
 *
 * @a0-a7: arguments passed in registers 0 to 7
 * @res: result values from registers 0 to 3
 *
 * This macro is used to make HVC calls following SMC Calling Convention v1.1.
 * The content of the supplied param are copied to registers 0 to 7 prior
 * to the HVC instruction. The return values are updated with the content
 * from register 0 to 3 on return from the HVC instruction if not NULL.
 */
#define arm_smccc_1_1_hvc(...)

/*
 * Like arm_smccc_1_1* but always returns SMCCC_RET_NOT_SUPPORTED.
 * Used when the SMCCC conduit is not defined. The empty asm statement
 * avoids compiler warnings about unused variables.
 */
#define __fail_smccc_1_1(...)

/*
 * arm_smccc_1_1_invoke() - make an SMCCC v1.1 compliant call
 *
 * This is a variadic macro taking one to eight source arguments, and
 * an optional return structure.
 *
 * @a0-a7: arguments passed in registers 0 to 7
 * @res: result values from registers 0 to 3
 *
 * This macro will make either an HVC call or an SMC call depending on the
 * current SMCCC conduit. If no valid conduit is available then -1
 * (SMCCC_RET_NOT_SUPPORTED) is returned in @res.a0 (if supplied).
 *
 * The return value also provides the conduit that was used.
 */
#define arm_smccc_1_1_invoke(...)

#endif /*__ASSEMBLY__*/
#endif /*__LINUX_ARM_SMCCC_H*/