xref: /kvmtool/arm/aarch64/arm-cpu.c (revision f57ce447709232e07e996968bd2df3e5395129a3)
1 #include "kvm/fdt.h"
2 #include "kvm/kvm.h"
3 #include "kvm/kvm-cpu.h"
4 #include "kvm/util.h"
5 
6 #include "arm-common/gic.h"
7 #include "arm-common/timer.h"
8 
9 #include "asm/pmu.h"
10 
11 #include <linux/byteorder.h>
12 #include <linux/types.h>
13 
generate_fdt_nodes(void * fdt,struct kvm * kvm)14 static void generate_fdt_nodes(void *fdt, struct kvm *kvm)
15 {
16 	int timer_interrupts[4] = {13, 14, 11, 10};
17 
18 	gic__generate_fdt_nodes(fdt, kvm->cfg.arch.irqchip);
19 	timer__generate_fdt_nodes(fdt, kvm, timer_interrupts);
20 	pmu__generate_fdt_nodes(fdt, kvm);
21 }
22 
arm_cpu__vcpu_init(struct kvm_cpu * vcpu)23 static int arm_cpu__vcpu_init(struct kvm_cpu *vcpu)
24 {
25 	vcpu->generate_fdt_nodes = generate_fdt_nodes;
26 	return kvm_cpu__setup_pvtime(vcpu);
27 }
28 
29 static struct kvm_arm_target target_generic_v8 = {
30 	.id		= UINT_MAX,
31 	.compatible	= "arm,arm-v8",
32 	.init		= arm_cpu__vcpu_init,
33 };
34 
35 static struct kvm_arm_target target_aem_v8 = {
36 	.id		= KVM_ARM_TARGET_AEM_V8,
37 	.compatible	= "arm,arm-v8",
38 	.init		= arm_cpu__vcpu_init,
39 };
40 
41 static struct kvm_arm_target target_foundation_v8 = {
42 	.id		= KVM_ARM_TARGET_FOUNDATION_V8,
43 	.compatible	= "arm,arm-v8",
44 	.init		= arm_cpu__vcpu_init,
45 };
46 
47 static struct kvm_arm_target target_cortex_a57 = {
48 	.id		= KVM_ARM_TARGET_CORTEX_A57,
49 	.compatible	= "arm,cortex-a57",
50 	.init		= arm_cpu__vcpu_init,
51 };
52 
53 /*
54  * We really don't need to register a target for every
55  * new CPU. The target for Potenza CPU is only registered
56  * to enable compatibility with older host kernels.
57  */
58 static struct kvm_arm_target target_potenza = {
59 	.id		= KVM_ARM_TARGET_XGENE_POTENZA,
60 	.compatible	= "arm,arm-v8",
61 	.init		= arm_cpu__vcpu_init,
62 };
63 
arm_cpu__core_init(struct kvm * kvm)64 static int arm_cpu__core_init(struct kvm *kvm)
65 {
66 	kvm_cpu__set_kvm_arm_generic_target(&target_generic_v8);
67 
68 	return (kvm_cpu__register_kvm_arm_target(&target_aem_v8) ||
69 		kvm_cpu__register_kvm_arm_target(&target_foundation_v8) ||
70 		kvm_cpu__register_kvm_arm_target(&target_cortex_a57) ||
71 		kvm_cpu__register_kvm_arm_target(&target_potenza));
72 }
73 core_init(arm_cpu__core_init);
74