xref: /kvmtool/arm/include/arm-common/kvm-cpu-arch.h (revision e300a5eef43ed25dc415b47d67cdf8d8987a9bf8)
1 #ifndef ARM_COMMON__KVM_CPU_ARCH_H
2 #define ARM_COMMON__KVM_CPU_ARCH_H
3 
4 #include <linux/kvm.h>
5 #include <pthread.h>
6 #include <stdbool.h>
7 
8 struct kvm;
9 
10 struct kvm_cpu {
11 	pthread_t	thread;
12 
13 	unsigned long	cpu_id;
14 	unsigned long	cpu_type;
15 	const char	*cpu_compatible;
16 
17 	struct kvm	*kvm;
18 	int		vcpu_fd;
19 	struct kvm_run	*kvm_run;
20 	struct kvm_cpu_task	*task;
21 
22 	u8		is_running;
23 	u8		paused;
24 	u8		needs_nmi;
25 
26 	struct kvm_coalesced_mmio_ring	*ring;
27 
28 	void		(*generate_fdt_nodes)(void *fdt, struct kvm* kvm,
29 					      u32 gic_phandle);
30 };
31 
32 struct kvm_arm_target {
33 	u32		id;
34 	const char 	*compatible;
35 	int		(*init)(struct kvm_cpu *vcpu);
36 };
37 
38 void kvm_cpu__set_kvm_arm_generic_target(struct kvm_arm_target *target);
39 
40 int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target);
41 
42 static inline bool kvm_cpu__emulate_io(struct kvm_cpu *vcpu, u16 port, void *data,
43 				       int direction, int size, u32 count)
44 {
45 	return false;
46 }
47 
48 static inline bool kvm_cpu__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr,
49 					 u8 *data, u32 len, u8 is_write)
50 {
51 	if (arm_addr_in_ioport_region(phys_addr)) {
52 		int direction = is_write ? KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN;
53 		u16 port = (phys_addr - KVM_IOPORT_AREA) & USHRT_MAX;
54 
55 		return kvm__emulate_io(vcpu, port, data, direction, len, 1);
56 	}
57 
58 	return kvm__emulate_mmio(vcpu, phys_addr, data, len, is_write);
59 }
60 
61 unsigned long kvm_cpu__get_vcpu_mpidr(struct kvm_cpu *vcpu);
62 
63 #endif /* ARM_COMMON__KVM_CPU_ARCH_H */
64