|
6 | 6 | #include <linux/bitmap.h> |
7 | 7 | #include <linux/cache.h> |
8 | 8 | #include <linux/kernel.h> |
| 9 | +#include <linux/memblock.h> |
9 | 10 | #include <linux/string.h> |
10 | 11 |
|
| 12 | +#include <uapi/linux/psci.h> |
| 13 | + |
11 | 14 | #include <asm/hypervisor.h> |
12 | 15 |
|
13 | 16 | static DECLARE_BITMAP(__kvm_arm_hyp_services, ARM_SMCCC_KVM_NUM_FUNCS) __ro_after_init = { }; |
@@ -51,3 +54,64 @@ bool kvm_arm_hyp_service_available(u32 func_id) |
51 | 54 | return test_bit(func_id, __kvm_arm_hyp_services); |
52 | 55 | } |
53 | 56 | EXPORT_SYMBOL_GPL(kvm_arm_hyp_service_available); |
| 57 | + |
| 58 | +void __init kvm_arm_target_impl_cpu_init(void) |
| 59 | +{ |
| 60 | + int i; |
| 61 | + u32 ver; |
| 62 | + u64 max_cpus; |
| 63 | + struct arm_smccc_res res; |
| 64 | + struct target_impl_cpu *target; |
| 65 | + |
| 66 | + if (!kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_DISCOVER_IMPL_VER) || |
| 67 | + !kvm_arm_hyp_service_available(ARM_SMCCC_KVM_FUNC_DISCOVER_IMPL_CPUS)) |
| 68 | + return; |
| 69 | + |
| 70 | + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_VER_FUNC_ID, |
| 71 | + 0, &res); |
| 72 | + if (res.a0 != SMCCC_RET_SUCCESS) |
| 73 | + return; |
| 74 | + |
| 75 | + /* Version info is in lower 32 bits and is in SMMCCC_VERSION format */ |
| 76 | + ver = lower_32_bits(res.a1); |
| 77 | + if (PSCI_VERSION_MAJOR(ver) != 1) { |
| 78 | + pr_warn("Unsupported target CPU implementation version v%d.%d\n", |
| 79 | + PSCI_VERSION_MAJOR(ver), PSCI_VERSION_MINOR(ver)); |
| 80 | + return; |
| 81 | + } |
| 82 | + |
| 83 | + if (!res.a2) { |
| 84 | + pr_warn("No target implementation CPUs specified\n"); |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + max_cpus = res.a2; |
| 89 | + target = memblock_alloc(sizeof(*target) * max_cpus, __alignof__(*target)); |
| 90 | + if (!target) { |
| 91 | + pr_warn("Not enough memory for struct target_impl_cpu\n"); |
| 92 | + return; |
| 93 | + } |
| 94 | + |
| 95 | + for (i = 0; i < max_cpus; i++) { |
| 96 | + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_DISCOVER_IMPL_CPUS_FUNC_ID, |
| 97 | + i, &res); |
| 98 | + if (res.a0 != SMCCC_RET_SUCCESS) { |
| 99 | + pr_warn("Discovering target implementation CPUs failed\n"); |
| 100 | + goto mem_free; |
| 101 | + } |
| 102 | + target[i].midr = res.a1; |
| 103 | + target[i].revidr = res.a2; |
| 104 | + target[i].aidr = res.a3; |
| 105 | + }; |
| 106 | + |
| 107 | + if (!cpu_errata_set_target_impl(max_cpus, target)) { |
| 108 | + pr_warn("Failed to set target implementation CPUs\n"); |
| 109 | + goto mem_free; |
| 110 | + } |
| 111 | + |
| 112 | + pr_info("Number of target implementation CPUs is %lld\n", max_cpus); |
| 113 | + return; |
| 114 | + |
| 115 | +mem_free: |
| 116 | + memblock_free(target, sizeof(*target) * max_cpus); |
| 117 | +} |
0 commit comments