161076240SWill Deacon #ifndef ARM_COMMON__KVM_CPU_ARCH_H 261076240SWill Deacon #define ARM_COMMON__KVM_CPU_ARCH_H 37c0e8b0cSWill Deacon 47c0e8b0cSWill Deacon #include <linux/kvm.h> 57c0e8b0cSWill Deacon #include <pthread.h> 67c0e8b0cSWill Deacon #include <stdbool.h> 77c0e8b0cSWill Deacon 87c0e8b0cSWill Deacon struct kvm; 97c0e8b0cSWill Deacon 107c0e8b0cSWill Deacon struct kvm_cpu { 117c0e8b0cSWill Deacon pthread_t thread; 127c0e8b0cSWill Deacon 137c0e8b0cSWill Deacon unsigned long cpu_id; 147c0e8b0cSWill Deacon unsigned long cpu_type; 159b47146bSMarc Zyngier const char *cpu_compatible; 167c0e8b0cSWill Deacon 177c0e8b0cSWill Deacon struct kvm *kvm; 187c0e8b0cSWill Deacon int vcpu_fd; 197c0e8b0cSWill Deacon struct kvm_run *kvm_run; 207c0e8b0cSWill Deacon 217c0e8b0cSWill Deacon u8 is_running; 227c0e8b0cSWill Deacon u8 paused; 237c0e8b0cSWill Deacon u8 needs_nmi; 247c0e8b0cSWill Deacon 257c0e8b0cSWill Deacon struct kvm_coalesced_mmio_ring *ring; 267c0e8b0cSWill Deacon 277c0e8b0cSWill Deacon void (*generate_fdt_nodes)(void *fdt, struct kvm* kvm, 287c0e8b0cSWill Deacon u32 gic_phandle); 297c0e8b0cSWill Deacon }; 307c0e8b0cSWill Deacon 317c0e8b0cSWill Deacon struct kvm_arm_target { 327c0e8b0cSWill Deacon u32 id; 339b47146bSMarc Zyngier const char *compatible; 347c0e8b0cSWill Deacon int (*init)(struct kvm_cpu *vcpu); 357c0e8b0cSWill Deacon }; 367c0e8b0cSWill Deacon 3785bd726aSAnup Patel void kvm_cpu__set_kvm_arm_generic_target(struct kvm_arm_target *target); 3885bd726aSAnup Patel 397c0e8b0cSWill Deacon int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target); 407c0e8b0cSWill Deacon 414123ca55SMarc Zyngier static inline bool kvm_cpu__emulate_io(struct kvm_cpu *vcpu, u16 port, void *data, 427c0e8b0cSWill Deacon int direction, int size, u32 count) 437c0e8b0cSWill Deacon { 447c0e8b0cSWill Deacon return false; 457c0e8b0cSWill Deacon } 467c0e8b0cSWill Deacon 47*ce6ae122SAndre Przywara static inline bool kvm_cpu__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, 48*ce6ae122SAndre Przywara u8 *data, u32 len, u8 is_write) 49*ce6ae122SAndre Przywara { 50*ce6ae122SAndre Przywara if (arm_addr_in_ioport_region(phys_addr)) { 51*ce6ae122SAndre Przywara int direction = is_write ? KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN; 52*ce6ae122SAndre Przywara u16 port = (phys_addr - KVM_IOPORT_AREA) & USHRT_MAX; 53*ce6ae122SAndre Przywara 54*ce6ae122SAndre Przywara return kvm__emulate_io(vcpu, port, data, direction, len, 1); 55*ce6ae122SAndre Przywara } 56*ce6ae122SAndre Przywara 57*ce6ae122SAndre Przywara return kvm__emulate_mmio(vcpu, phys_addr, data, len, is_write); 58*ce6ae122SAndre Przywara } 597c0e8b0cSWill Deacon 60d06bc640SMarc Zyngier unsigned long kvm_cpu__get_vcpu_mpidr(struct kvm_cpu *vcpu); 61d06bc640SMarc Zyngier 6261076240SWill Deacon #endif /* ARM_COMMON__KVM_CPU_ARCH_H */ 63