Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #define pr_fmt(fmt) "smccc: KVM: " fmt
0004 
0005 #include <linux/arm-smccc.h>
0006 #include <linux/bitmap.h>
0007 #include <linux/cache.h>
0008 #include <linux/kernel.h>
0009 #include <linux/string.h>
0010 
0011 #include <asm/hypervisor.h>
0012 
0013 static DECLARE_BITMAP(__kvm_arm_hyp_services, ARM_SMCCC_KVM_NUM_FUNCS) __ro_after_init = { };
0014 
0015 void __init kvm_init_hyp_services(void)
0016 {
0017     struct arm_smccc_res res;
0018     u32 val[4];
0019 
0020     if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC)
0021         return;
0022 
0023     arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res);
0024     if (res.a0 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 ||
0025         res.a1 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 ||
0026         res.a2 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 ||
0027         res.a3 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3)
0028         return;
0029 
0030     memset(&res, 0, sizeof(res));
0031     arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID, &res);
0032 
0033     val[0] = lower_32_bits(res.a0);
0034     val[1] = lower_32_bits(res.a1);
0035     val[2] = lower_32_bits(res.a2);
0036     val[3] = lower_32_bits(res.a3);
0037 
0038     bitmap_from_arr32(__kvm_arm_hyp_services, val, ARM_SMCCC_KVM_NUM_FUNCS);
0039 
0040     pr_info("hypervisor services detected (0x%08lx 0x%08lx 0x%08lx 0x%08lx)\n",
0041          res.a3, res.a2, res.a1, res.a0);
0042 }
0043 
0044 bool kvm_arm_hyp_service_available(u32 func_id)
0045 {
0046     if (func_id >= ARM_SMCCC_KVM_NUM_FUNCS)
0047         return false;
0048 
0049     return test_bit(func_id, __kvm_arm_hyp_services);
0050 }
0051 EXPORT_SYMBOL_GPL(kvm_arm_hyp_service_available);