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; 20*e300a5eeSMichael Ellerman struct kvm_cpu_task *task; 217c0e8b0cSWill Deacon 227c0e8b0cSWill Deacon u8 is_running; 237c0e8b0cSWill Deacon u8 paused; 247c0e8b0cSWill Deacon u8 needs_nmi; 257c0e8b0cSWill Deacon 267c0e8b0cSWill Deacon struct kvm_coalesced_mmio_ring *ring; 277c0e8b0cSWill Deacon 287c0e8b0cSWill Deacon void (*generate_fdt_nodes)(void *fdt, struct kvm* kvm, 297c0e8b0cSWill Deacon u32 gic_phandle); 307c0e8b0cSWill Deacon }; 317c0e8b0cSWill Deacon 327c0e8b0cSWill Deacon struct kvm_arm_target { 337c0e8b0cSWill Deacon u32 id; 349b47146bSMarc Zyngier const char *compatible; 357c0e8b0cSWill Deacon int (*init)(struct kvm_cpu *vcpu); 367c0e8b0cSWill Deacon }; 377c0e8b0cSWill Deacon 3885bd726aSAnup Patel void kvm_cpu__set_kvm_arm_generic_target(struct kvm_arm_target *target); 3985bd726aSAnup Patel 407c0e8b0cSWill Deacon int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target); 417c0e8b0cSWill Deacon 424123ca55SMarc Zyngier static inline bool kvm_cpu__emulate_io(struct kvm_cpu *vcpu, u16 port, void *data, 437c0e8b0cSWill Deacon int direction, int size, u32 count) 447c0e8b0cSWill Deacon { 457c0e8b0cSWill Deacon return false; 467c0e8b0cSWill Deacon } 477c0e8b0cSWill Deacon 48ce6ae122SAndre Przywara static inline bool kvm_cpu__emulate_mmio(struct kvm_cpu *vcpu, u64 phys_addr, 49ce6ae122SAndre Przywara u8 *data, u32 len, u8 is_write) 50ce6ae122SAndre Przywara { 51ce6ae122SAndre Przywara if (arm_addr_in_ioport_region(phys_addr)) { 52ce6ae122SAndre Przywara int direction = is_write ? KVM_EXIT_IO_OUT : KVM_EXIT_IO_IN; 53ce6ae122SAndre Przywara u16 port = (phys_addr - KVM_IOPORT_AREA) & USHRT_MAX; 54ce6ae122SAndre Przywara 55ce6ae122SAndre Przywara return kvm__emulate_io(vcpu, port, data, direction, len, 1); 56ce6ae122SAndre Przywara } 57ce6ae122SAndre Przywara 58ce6ae122SAndre Przywara return kvm__emulate_mmio(vcpu, phys_addr, data, len, is_write); 59ce6ae122SAndre Przywara } 607c0e8b0cSWill Deacon 61d06bc640SMarc Zyngier unsigned long kvm_cpu__get_vcpu_mpidr(struct kvm_cpu *vcpu); 62d06bc640SMarc Zyngier 6361076240SWill Deacon #endif /* ARM_COMMON__KVM_CPU_ARCH_H */ 64