19c17d615SPaolo Bonzini /* 29c17d615SPaolo Bonzini * QEMU KVM support 39c17d615SPaolo Bonzini * 49c17d615SPaolo Bonzini * Copyright IBM, Corp. 2008 59c17d615SPaolo Bonzini * 69c17d615SPaolo Bonzini * Authors: 79c17d615SPaolo Bonzini * Anthony Liguori <aliguori@us.ibm.com> 89c17d615SPaolo Bonzini * 99c17d615SPaolo Bonzini * This work is licensed under the terms of the GNU GPL, version 2 or later. 109c17d615SPaolo Bonzini * See the COPYING file in the top-level directory. 119c17d615SPaolo Bonzini * 129c17d615SPaolo Bonzini */ 139c17d615SPaolo Bonzini 149c17d615SPaolo Bonzini #ifndef QEMU_KVM_H 159c17d615SPaolo Bonzini #define QEMU_KVM_H 169c17d615SPaolo Bonzini 179c17d615SPaolo Bonzini #include "qemu/queue.h" 182e5b09fdSMarkus Armbruster #include "hw/core/cpu.h" 194c663752SPaolo Bonzini #include "exec/memattrs.h" 20940e43aaSClaudio Fontana #include "qemu/accel.h" 21db1015e9SEduardo Habkost #include "qom/object.h" 229c17d615SPaolo Bonzini 23cbca3722SThomas Huth #ifdef NEED_CPU_H 249c17d615SPaolo Bonzini # ifdef CONFIG_KVM 259c17d615SPaolo Bonzini # include <linux/kvm.h> 26cbca3722SThomas Huth # define CONFIG_KVM_IS_POSSIBLE 279c17d615SPaolo Bonzini # endif 28cbca3722SThomas Huth #else 29cbca3722SThomas Huth # define CONFIG_KVM_IS_POSSIBLE 30cbca3722SThomas Huth #endif 31cbca3722SThomas Huth 32cbca3722SThomas Huth #ifdef CONFIG_KVM_IS_POSSIBLE 339c17d615SPaolo Bonzini 34d5286af5Sliguang extern bool kvm_allowed; 359c17d615SPaolo Bonzini extern bool kvm_kernel_irqchip; 3632c18a2dSMatt Gingell extern bool kvm_split_irqchip; 379c17d615SPaolo Bonzini extern bool kvm_async_interrupts_allowed; 38215e79c0SAlexander Graf extern bool kvm_halt_in_kernel_allowed; 3969e03ae6SNikolay Nikolaev extern bool kvm_eventfds_allowed; 409c17d615SPaolo Bonzini extern bool kvm_irqfds_allowed; 41f41389aeSEric Auger extern bool kvm_resamplefds_allowed; 429c17d615SPaolo Bonzini extern bool kvm_msi_via_irqfd_allowed; 439c17d615SPaolo Bonzini extern bool kvm_gsi_routing_allowed; 4476fe21deSAlexey Kardashevskiy extern bool kvm_gsi_direct_mapping; 45df9c8b75SJordan Justen extern bool kvm_readonly_mem_allowed; 4650bf31b9SPavel Fedin extern bool kvm_direct_msi_allowed; 4735108223SJason Wang extern bool kvm_ioeventfd_any_length_allowed; 48767a554aSPavel Fedin extern bool kvm_msi_use_devid; 499c17d615SPaolo Bonzini 509c17d615SPaolo Bonzini #define kvm_enabled() (kvm_allowed) 519c17d615SPaolo Bonzini /** 529c17d615SPaolo Bonzini * kvm_irqchip_in_kernel: 539c17d615SPaolo Bonzini * 5431c707fbSEduardo Habkost * Returns: true if an in-kernel irqchip was created. 559c17d615SPaolo Bonzini * What this actually means is architecture and machine model 5631c707fbSEduardo Habkost * specific: on PC, for instance, it means that the LAPIC 5731c707fbSEduardo Habkost * is in kernel. This function should never be used from generic 5831c707fbSEduardo Habkost * target-independent code: use one of the following functions or 5931c707fbSEduardo Habkost * some other specific check instead. 609c17d615SPaolo Bonzini */ 619c17d615SPaolo Bonzini #define kvm_irqchip_in_kernel() (kvm_kernel_irqchip) 629c17d615SPaolo Bonzini 639c17d615SPaolo Bonzini /** 6432c18a2dSMatt Gingell * kvm_irqchip_is_split: 6532c18a2dSMatt Gingell * 6631c707fbSEduardo Habkost * Returns: true if the irqchip implementation is split between 6731c707fbSEduardo Habkost * user and kernel space. The details are architecture and 6831c707fbSEduardo Habkost * machine specific. On PC, it means that the PIC, IOAPIC, and 6931c707fbSEduardo Habkost * PIT are in user space while the LAPIC is in the kernel. 7032c18a2dSMatt Gingell */ 7132c18a2dSMatt Gingell #define kvm_irqchip_is_split() (kvm_split_irqchip) 7232c18a2dSMatt Gingell 7332c18a2dSMatt Gingell /** 749c17d615SPaolo Bonzini * kvm_async_interrupts_enabled: 759c17d615SPaolo Bonzini * 769c17d615SPaolo Bonzini * Returns: true if we can deliver interrupts to KVM 779c17d615SPaolo Bonzini * asynchronously (ie by ioctl from any thread at any time) 789c17d615SPaolo Bonzini * rather than having to do interrupt delivery synchronously 799c17d615SPaolo Bonzini * (where the vcpu must be stopped at a suitable point first). 809c17d615SPaolo Bonzini */ 819c17d615SPaolo Bonzini #define kvm_async_interrupts_enabled() (kvm_async_interrupts_allowed) 829c17d615SPaolo Bonzini 839c17d615SPaolo Bonzini /** 84215e79c0SAlexander Graf * kvm_halt_in_kernel 85215e79c0SAlexander Graf * 86215e79c0SAlexander Graf * Returns: true if halted cpus should still get a KVM_RUN ioctl to run 87215e79c0SAlexander Graf * inside of kernel space. This only works if MP state is implemented. 88215e79c0SAlexander Graf */ 89215e79c0SAlexander Graf #define kvm_halt_in_kernel() (kvm_halt_in_kernel_allowed) 90215e79c0SAlexander Graf 91215e79c0SAlexander Graf /** 9269e03ae6SNikolay Nikolaev * kvm_eventfds_enabled: 9369e03ae6SNikolay Nikolaev * 9469e03ae6SNikolay Nikolaev * Returns: true if we can use eventfds to receive notifications 9569e03ae6SNikolay Nikolaev * from a KVM CPU (ie the kernel supports eventds and we are running 9669e03ae6SNikolay Nikolaev * with a configuration where it is meaningful to use them). 9769e03ae6SNikolay Nikolaev */ 9869e03ae6SNikolay Nikolaev #define kvm_eventfds_enabled() (kvm_eventfds_allowed) 9969e03ae6SNikolay Nikolaev 10069e03ae6SNikolay Nikolaev /** 1019c17d615SPaolo Bonzini * kvm_irqfds_enabled: 1029c17d615SPaolo Bonzini * 1039c17d615SPaolo Bonzini * Returns: true if we can use irqfds to inject interrupts into 1049c17d615SPaolo Bonzini * a KVM CPU (ie the kernel supports irqfds and we are running 1059c17d615SPaolo Bonzini * with a configuration where it is meaningful to use them). 1069c17d615SPaolo Bonzini */ 1079c17d615SPaolo Bonzini #define kvm_irqfds_enabled() (kvm_irqfds_allowed) 1089c17d615SPaolo Bonzini 1099c17d615SPaolo Bonzini /** 110f41389aeSEric Auger * kvm_resamplefds_enabled: 111f41389aeSEric Auger * 112f41389aeSEric Auger * Returns: true if we can use resamplefds to inject interrupts into 113f41389aeSEric Auger * a KVM CPU (ie the kernel supports resamplefds and we are running 114f41389aeSEric Auger * with a configuration where it is meaningful to use them). 115f41389aeSEric Auger */ 116f41389aeSEric Auger #define kvm_resamplefds_enabled() (kvm_resamplefds_allowed) 117f41389aeSEric Auger 118f41389aeSEric Auger /** 1199c17d615SPaolo Bonzini * kvm_msi_via_irqfd_enabled: 1209c17d615SPaolo Bonzini * 1219c17d615SPaolo Bonzini * Returns: true if we can route a PCI MSI (Message Signaled Interrupt) 1229c17d615SPaolo Bonzini * to a KVM CPU via an irqfd. This requires that the kernel supports 1239c17d615SPaolo Bonzini * this and that we're running in a configuration that permits it. 1249c17d615SPaolo Bonzini */ 1259c17d615SPaolo Bonzini #define kvm_msi_via_irqfd_enabled() (kvm_msi_via_irqfd_allowed) 1269c17d615SPaolo Bonzini 1279c17d615SPaolo Bonzini /** 1289c17d615SPaolo Bonzini * kvm_gsi_routing_enabled: 1299c17d615SPaolo Bonzini * 1309c17d615SPaolo Bonzini * Returns: true if GSI routing is enabled (ie the kernel supports 1319c17d615SPaolo Bonzini * it and we're running in a configuration that permits it). 1329c17d615SPaolo Bonzini */ 1339c17d615SPaolo Bonzini #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed) 1349c17d615SPaolo Bonzini 135df9c8b75SJordan Justen /** 13676fe21deSAlexey Kardashevskiy * kvm_gsi_direct_mapping: 13776fe21deSAlexey Kardashevskiy * 13876fe21deSAlexey Kardashevskiy * Returns: true if GSI direct mapping is enabled. 13976fe21deSAlexey Kardashevskiy */ 14076fe21deSAlexey Kardashevskiy #define kvm_gsi_direct_mapping() (kvm_gsi_direct_mapping) 14176fe21deSAlexey Kardashevskiy 14276fe21deSAlexey Kardashevskiy /** 143df9c8b75SJordan Justen * kvm_readonly_mem_enabled: 144df9c8b75SJordan Justen * 145df9c8b75SJordan Justen * Returns: true if KVM readonly memory is enabled (ie the kernel 146df9c8b75SJordan Justen * supports it and we're running in a configuration that permits it). 147df9c8b75SJordan Justen */ 148df9c8b75SJordan Justen #define kvm_readonly_mem_enabled() (kvm_readonly_mem_allowed) 149df9c8b75SJordan Justen 15050bf31b9SPavel Fedin /** 15150bf31b9SPavel Fedin * kvm_direct_msi_enabled: 15250bf31b9SPavel Fedin * 15350bf31b9SPavel Fedin * Returns: true if KVM allows direct MSI injection. 15450bf31b9SPavel Fedin */ 15550bf31b9SPavel Fedin #define kvm_direct_msi_enabled() (kvm_direct_msi_allowed) 15650bf31b9SPavel Fedin 15735108223SJason Wang /** 15835108223SJason Wang * kvm_ioeventfd_any_length_enabled: 15935108223SJason Wang * Returns: true if KVM allows any length io eventfd. 16035108223SJason Wang */ 16135108223SJason Wang #define kvm_ioeventfd_any_length_enabled() (kvm_ioeventfd_any_length_allowed) 16235108223SJason Wang 163767a554aSPavel Fedin /** 164767a554aSPavel Fedin * kvm_msi_devid_required: 165767a554aSPavel Fedin * Returns: true if KVM requires a device id to be provided while 166767a554aSPavel Fedin * defining an MSI routing entry. 167767a554aSPavel Fedin */ 168767a554aSPavel Fedin #define kvm_msi_devid_required() (kvm_msi_use_devid) 169767a554aSPavel Fedin 1709c17d615SPaolo Bonzini #else 171cbca3722SThomas Huth 1729c17d615SPaolo Bonzini #define kvm_enabled() (0) 1739c17d615SPaolo Bonzini #define kvm_irqchip_in_kernel() (false) 17415eafc2eSPaolo Bonzini #define kvm_irqchip_is_split() (false) 1759c17d615SPaolo Bonzini #define kvm_async_interrupts_enabled() (false) 176215e79c0SAlexander Graf #define kvm_halt_in_kernel() (false) 17769e03ae6SNikolay Nikolaev #define kvm_eventfds_enabled() (false) 1789c17d615SPaolo Bonzini #define kvm_irqfds_enabled() (false) 179879904e8SEric Auger #define kvm_resamplefds_enabled() (false) 1809c17d615SPaolo Bonzini #define kvm_msi_via_irqfd_enabled() (false) 1819c17d615SPaolo Bonzini #define kvm_gsi_routing_allowed() (false) 18276fe21deSAlexey Kardashevskiy #define kvm_gsi_direct_mapping() (false) 183df9c8b75SJordan Justen #define kvm_readonly_mem_enabled() (false) 18450bf31b9SPavel Fedin #define kvm_direct_msi_enabled() (false) 18535108223SJason Wang #define kvm_ioeventfd_any_length_enabled() (false) 186767a554aSPavel Fedin #define kvm_msi_devid_required() (false) 187cbca3722SThomas Huth 188cbca3722SThomas Huth #endif /* CONFIG_KVM_IS_POSSIBLE */ 1899c17d615SPaolo Bonzini 1909c17d615SPaolo Bonzini struct kvm_run; 1919c17d615SPaolo Bonzini struct kvm_lapic_state; 1929e03a040SFrank Blaschka struct kvm_irq_routing_entry; 1939c17d615SPaolo Bonzini 1949c17d615SPaolo Bonzini typedef struct KVMCapabilityInfo { 1959c17d615SPaolo Bonzini const char *name; 1969c17d615SPaolo Bonzini int value; 1979c17d615SPaolo Bonzini } KVMCapabilityInfo; 1989c17d615SPaolo Bonzini 1999c17d615SPaolo Bonzini #define KVM_CAP_INFO(CAP) { "KVM_CAP_" stringify(CAP), KVM_CAP_##CAP } 2009c17d615SPaolo Bonzini #define KVM_CAP_LAST_INFO { NULL, 0 } 2019c17d615SPaolo Bonzini 2029c17d615SPaolo Bonzini struct KVMState; 20397e622deSEduardo Habkost 20497e622deSEduardo Habkost #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm") 2059c17d615SPaolo Bonzini typedef struct KVMState KVMState; 2068110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(KVMState, KVM_STATE, 2078110fa1dSEduardo Habkost TYPE_KVM_ACCEL) 20897e622deSEduardo Habkost 2099c17d615SPaolo Bonzini extern KVMState *kvm_state; 2103607715aSDavid Gibson typedef struct Notifier Notifier; 2119c17d615SPaolo Bonzini 2129c17d615SPaolo Bonzini /* external API */ 2139c17d615SPaolo Bonzini 214b8865591SIgor Mammedov bool kvm_has_free_slot(MachineState *ms); 21562dd4edaSGreg Kurz bool kvm_has_sync_mmu(void); 2169c17d615SPaolo Bonzini int kvm_has_vcpu_events(void); 2179c17d615SPaolo Bonzini int kvm_has_robust_singlestep(void); 2189c17d615SPaolo Bonzini int kvm_has_debugregs(void); 219ebbfef2fSLiran Alon int kvm_max_nested_state_length(void); 2209c17d615SPaolo Bonzini int kvm_has_pit_state2(void); 2219c17d615SPaolo Bonzini int kvm_has_many_ioeventfds(void); 2229c17d615SPaolo Bonzini int kvm_has_gsi_routing(void); 2239c17d615SPaolo Bonzini int kvm_has_intx_set_mask(void); 2249c17d615SPaolo Bonzini 2255d721b78SAlexander Graf /** 2265d721b78SAlexander Graf * kvm_arm_supports_user_irq 2275d721b78SAlexander Graf * 2285d721b78SAlexander Graf * Not all KVM implementations support notifications for kernel generated 2295d721b78SAlexander Graf * interrupt events to user space. This function indicates whether the current 2305d721b78SAlexander Graf * KVM implementation does support them. 2315d721b78SAlexander Graf * 2325d721b78SAlexander Graf * Returns: true if KVM supports using kernel generated IRQs from user space 2335d721b78SAlexander Graf */ 2345d721b78SAlexander Graf bool kvm_arm_supports_user_irq(void); 2355d721b78SAlexander Graf 236b20e3780SBrijesh Singh 237504134d2SAndreas Färber #ifdef NEED_CPU_H 23833c11879SPaolo Bonzini #include "cpu.h" 2399c17d615SPaolo Bonzini 240c4cfef5eSIgor Mammedov void kvm_flush_coalesced_mmio_buffer(void); 241c4cfef5eSIgor Mammedov 24262278814SAndreas Färber int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr, 2439c17d615SPaolo Bonzini target_ulong len, int type); 24462278814SAndreas Färber int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr, 2459c17d615SPaolo Bonzini target_ulong len, int type); 2461d5791f4SAndreas Färber void kvm_remove_all_breakpoints(CPUState *cpu); 24738e478ecSStefan Weil int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap); 2489c17d615SPaolo Bonzini 249290adf38SAndreas Färber int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr); 2509c17d615SPaolo Bonzini int kvm_on_sigbus(int code, void *addr); 2519c17d615SPaolo Bonzini 25288401cbcSPaolo Bonzini /* interface with exec.c */ 25388401cbcSPaolo Bonzini 25406329cceSMarcel Apfelbaum void phys_mem_set_alloc(void *(*alloc)(size_t, uint64_t *align, bool shared)); 25588401cbcSPaolo Bonzini 2569c17d615SPaolo Bonzini /* internal API */ 2579c17d615SPaolo Bonzini 2589c17d615SPaolo Bonzini int kvm_ioctl(KVMState *s, int type, ...); 2599c17d615SPaolo Bonzini 2609c17d615SPaolo Bonzini int kvm_vm_ioctl(KVMState *s, int type, ...); 2619c17d615SPaolo Bonzini 262501a7ce7SAndreas Färber int kvm_vcpu_ioctl(CPUState *cpu, int type, ...); 2639c17d615SPaolo Bonzini 2640a6a7ccaSChristoffer Dall /** 2650a6a7ccaSChristoffer Dall * kvm_device_ioctl - call an ioctl on a kvm device 2660a6a7ccaSChristoffer Dall * @fd: The KVM device file descriptor as returned from KVM_CREATE_DEVICE 2670a6a7ccaSChristoffer Dall * @type: The device-ctrl ioctl number 2680a6a7ccaSChristoffer Dall * 2690a6a7ccaSChristoffer Dall * Returns: -errno on error, nonnegative on success 2700a6a7ccaSChristoffer Dall */ 2710a6a7ccaSChristoffer Dall int kvm_device_ioctl(int fd, int type, ...); 2720a6a7ccaSChristoffer Dall 2730a6a7ccaSChristoffer Dall /** 274d0a073a1SDominik Dingel * kvm_vm_check_attr - check for existence of a specific vm attribute 275d0a073a1SDominik Dingel * @s: The KVMState pointer 276d0a073a1SDominik Dingel * @group: the group 277d0a073a1SDominik Dingel * @attr: the attribute of that group to query for 278d0a073a1SDominik Dingel * 279d0a073a1SDominik Dingel * Returns: 1 if the attribute exists 280d0a073a1SDominik Dingel * 0 if the attribute either does not exist or if the vm device 281d0a073a1SDominik Dingel * interface is unavailable 282d0a073a1SDominik Dingel */ 283d0a073a1SDominik Dingel int kvm_vm_check_attr(KVMState *s, uint32_t group, uint64_t attr); 284d0a073a1SDominik Dingel 285d0a073a1SDominik Dingel /** 2864b3cfe72SPavel Fedin * kvm_device_check_attr - check for existence of a specific device attribute 2874b3cfe72SPavel Fedin * @fd: The device file descriptor 2884b3cfe72SPavel Fedin * @group: the group 2894b3cfe72SPavel Fedin * @attr: the attribute of that group to query for 2904b3cfe72SPavel Fedin * 2914b3cfe72SPavel Fedin * Returns: 1 if the attribute exists 2924b3cfe72SPavel Fedin * 0 if the attribute either does not exist or if the vm device 2934b3cfe72SPavel Fedin * interface is unavailable 2944b3cfe72SPavel Fedin */ 2954b3cfe72SPavel Fedin int kvm_device_check_attr(int fd, uint32_t group, uint64_t attr); 2964b3cfe72SPavel Fedin 2974b3cfe72SPavel Fedin /** 29884b6ea05SGreg Kurz * kvm_device_access - set or get value of a specific device attribute 2994b3cfe72SPavel Fedin * @fd: The device file descriptor 3004b3cfe72SPavel Fedin * @group: the group 3014b3cfe72SPavel Fedin * @attr: the attribute of that group to set or get 3024b3cfe72SPavel Fedin * @val: pointer to a storage area for the value 3034b3cfe72SPavel Fedin * @write: true for set and false for get operation 304556969e9SEric Auger * @errp: error object handle 3054b3cfe72SPavel Fedin * 306556969e9SEric Auger * Returns: 0 on success 307556969e9SEric Auger * < 0 on error 308556969e9SEric Auger * Use kvm_device_check_attr() in order to check for the availability 309556969e9SEric Auger * of optional attributes. 3104b3cfe72SPavel Fedin */ 311556969e9SEric Auger int kvm_device_access(int fd, int group, uint64_t attr, 312556969e9SEric Auger void *val, bool write, Error **errp); 3134b3cfe72SPavel Fedin 3144b3cfe72SPavel Fedin /** 3150a6a7ccaSChristoffer Dall * kvm_create_device - create a KVM device for the device control API 3160a6a7ccaSChristoffer Dall * @KVMState: The KVMState pointer 3170a6a7ccaSChristoffer Dall * @type: The KVM device type (see Documentation/virtual/kvm/devices in the 3180a6a7ccaSChristoffer Dall * kernel source) 3190a6a7ccaSChristoffer Dall * @test: If true, only test if device can be created, but don't actually 3200a6a7ccaSChristoffer Dall * create the device. 3210a6a7ccaSChristoffer Dall * 3220a6a7ccaSChristoffer Dall * Returns: -errno on error, nonnegative on success: @test ? 0 : device fd; 3230a6a7ccaSChristoffer Dall */ 3240a6a7ccaSChristoffer Dall int kvm_create_device(KVMState *s, uint64_t type, bool test); 3250a6a7ccaSChristoffer Dall 32629039acfSPeter Xu /** 32729039acfSPeter Xu * kvm_device_supported - probe whether KVM supports specific device 32829039acfSPeter Xu * 32929039acfSPeter Xu * @vmfd: The fd handler for VM 33029039acfSPeter Xu * @type: type of device 33129039acfSPeter Xu * 33229039acfSPeter Xu * @return: true if supported, otherwise false. 33329039acfSPeter Xu */ 33429039acfSPeter Xu bool kvm_device_supported(int vmfd, uint64_t type); 3350a6a7ccaSChristoffer Dall 3369c17d615SPaolo Bonzini /* Arch specific hooks */ 3379c17d615SPaolo Bonzini 3389c17d615SPaolo Bonzini extern const KVMCapabilityInfo kvm_arch_required_capabilities[]; 3399c17d615SPaolo Bonzini 340501a7ce7SAndreas Färber void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run); 3414c663752SPaolo Bonzini MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run); 3429c17d615SPaolo Bonzini 343501a7ce7SAndreas Färber int kvm_arch_handle_exit(CPUState *cpu, struct kvm_run *run); 3449c17d615SPaolo Bonzini 345501a7ce7SAndreas Färber int kvm_arch_process_async_events(CPUState *cpu); 3469c17d615SPaolo Bonzini 347501a7ce7SAndreas Färber int kvm_arch_get_registers(CPUState *cpu); 3489c17d615SPaolo Bonzini 3499c17d615SPaolo Bonzini /* state subset only touched by the VCPU itself during runtime */ 3509c17d615SPaolo Bonzini #define KVM_PUT_RUNTIME_STATE 1 3519c17d615SPaolo Bonzini /* state subset modified during VCPU reset */ 3529c17d615SPaolo Bonzini #define KVM_PUT_RESET_STATE 2 3539c17d615SPaolo Bonzini /* full state set, modified during initialization or on vmload */ 3549c17d615SPaolo Bonzini #define KVM_PUT_FULL_STATE 3 3559c17d615SPaolo Bonzini 356501a7ce7SAndreas Färber int kvm_arch_put_registers(CPUState *cpu, int level); 3579c17d615SPaolo Bonzini 358b16565b3SMarcel Apfelbaum int kvm_arch_init(MachineState *ms, KVMState *s); 3599c17d615SPaolo Bonzini 360501a7ce7SAndreas Färber int kvm_arch_init_vcpu(CPUState *cpu); 361b1115c99SLiran Alon int kvm_arch_destroy_vcpu(CPUState *cpu); 3629c17d615SPaolo Bonzini 36341264b38SGreg Kurz bool kvm_vcpu_id_is_valid(int vcpu_id); 36441264b38SGreg Kurz 365b164e48eSEduardo Habkost /* Returns VCPU ID to be used on KVM_CREATE_VCPU ioctl() */ 366b164e48eSEduardo Habkost unsigned long kvm_arch_vcpu_id(CPUState *cpu); 367b164e48eSEduardo Habkost 368e24fd076SDongjiu Geng #ifdef KVM_HAVE_MCE_INJECTION 3692ae41db2SPaolo Bonzini void kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr); 3702ae41db2SPaolo Bonzini #endif 3719c17d615SPaolo Bonzini 3729c17d615SPaolo Bonzini void kvm_arch_init_irq_routing(KVMState *s); 3739c17d615SPaolo Bonzini 3749e03a040SFrank Blaschka int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, 375dc9f06caSPavel Fedin uint64_t address, uint32_t data, PCIDevice *dev); 3769e03a040SFrank Blaschka 37738d87493SPeter Xu /* Notify arch about newly added MSI routes */ 37838d87493SPeter Xu int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, 37938d87493SPeter Xu int vector, PCIDevice *dev); 38038d87493SPeter Xu /* Notify arch about released MSI routes */ 38138d87493SPeter Xu int kvm_arch_release_virq_post(int virq); 38238d87493SPeter Xu 3831850b6b7SEric Auger int kvm_arch_msi_data_to_gsi(uint32_t data); 3841850b6b7SEric Auger 3859c17d615SPaolo Bonzini int kvm_set_irq(KVMState *s, int irq, int level); 3869c17d615SPaolo Bonzini int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg); 3879c17d615SPaolo Bonzini 3889c17d615SPaolo Bonzini void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin); 3899c17d615SPaolo Bonzini 3903607715aSDavid Gibson void kvm_irqchip_add_change_notifier(Notifier *n); 3913607715aSDavid Gibson void kvm_irqchip_remove_change_notifier(Notifier *n); 3923607715aSDavid Gibson void kvm_irqchip_change_notify(void); 3933607715aSDavid Gibson 3949c17d615SPaolo Bonzini void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); 3959c17d615SPaolo Bonzini 3969c17d615SPaolo Bonzini struct kvm_guest_debug; 3979c17d615SPaolo Bonzini struct kvm_debug_exit_arch; 3989c17d615SPaolo Bonzini 3999c17d615SPaolo Bonzini struct kvm_sw_breakpoint { 4009c17d615SPaolo Bonzini target_ulong pc; 4019c17d615SPaolo Bonzini target_ulong saved_insn; 4029c17d615SPaolo Bonzini int use_count; 4039c17d615SPaolo Bonzini QTAILQ_ENTRY(kvm_sw_breakpoint) entry; 4049c17d615SPaolo Bonzini }; 4059c17d615SPaolo Bonzini 406501a7ce7SAndreas Färber struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *cpu, 4079c17d615SPaolo Bonzini target_ulong pc); 4089c17d615SPaolo Bonzini 409501a7ce7SAndreas Färber int kvm_sw_breakpoints_active(CPUState *cpu); 4109c17d615SPaolo Bonzini 41180b7cd73SAndreas Färber int kvm_arch_insert_sw_breakpoint(CPUState *cpu, 4129c17d615SPaolo Bonzini struct kvm_sw_breakpoint *bp); 41380b7cd73SAndreas Färber int kvm_arch_remove_sw_breakpoint(CPUState *cpu, 4149c17d615SPaolo Bonzini struct kvm_sw_breakpoint *bp); 4159c17d615SPaolo Bonzini int kvm_arch_insert_hw_breakpoint(target_ulong addr, 4169c17d615SPaolo Bonzini target_ulong len, int type); 4179c17d615SPaolo Bonzini int kvm_arch_remove_hw_breakpoint(target_ulong addr, 4189c17d615SPaolo Bonzini target_ulong len, int type); 4199c17d615SPaolo Bonzini void kvm_arch_remove_all_hw_breakpoints(void); 4209c17d615SPaolo Bonzini 421501a7ce7SAndreas Färber void kvm_arch_update_guest_debug(CPUState *cpu, struct kvm_guest_debug *dbg); 4229c17d615SPaolo Bonzini 423501a7ce7SAndreas Färber bool kvm_arch_stop_on_emulation_error(CPUState *cpu); 4249c17d615SPaolo Bonzini 4259c17d615SPaolo Bonzini int kvm_check_extension(KVMState *s, unsigned int extension); 4269c17d615SPaolo Bonzini 4277d0a07faSAlexander Graf int kvm_vm_check_extension(KVMState *s, unsigned int extension); 4287d0a07faSAlexander Graf 42940f1ee27SCornelia Huck #define kvm_vm_enable_cap(s, capability, cap_flags, ...) \ 43040f1ee27SCornelia Huck ({ \ 43140f1ee27SCornelia Huck struct kvm_enable_cap cap = { \ 43240f1ee27SCornelia Huck .cap = capability, \ 43340f1ee27SCornelia Huck .flags = cap_flags, \ 43440f1ee27SCornelia Huck }; \ 43540f1ee27SCornelia Huck uint64_t args_tmp[] = { __VA_ARGS__ }; \ 4361b7ac7caSGreg Kurz size_t n = MIN(ARRAY_SIZE(args_tmp), ARRAY_SIZE(cap.args)); \ 4371b7ac7caSGreg Kurz memcpy(cap.args, args_tmp, n * sizeof(cap.args[0])); \ 43840f1ee27SCornelia Huck kvm_vm_ioctl(s, KVM_ENABLE_CAP, &cap); \ 43940f1ee27SCornelia Huck }) 44040f1ee27SCornelia Huck 44140f1ee27SCornelia Huck #define kvm_vcpu_enable_cap(cpu, capability, cap_flags, ...) \ 44240f1ee27SCornelia Huck ({ \ 44340f1ee27SCornelia Huck struct kvm_enable_cap cap = { \ 44440f1ee27SCornelia Huck .cap = capability, \ 44540f1ee27SCornelia Huck .flags = cap_flags, \ 44640f1ee27SCornelia Huck }; \ 44740f1ee27SCornelia Huck uint64_t args_tmp[] = { __VA_ARGS__ }; \ 4481b7ac7caSGreg Kurz size_t n = MIN(ARRAY_SIZE(args_tmp), ARRAY_SIZE(cap.args)); \ 4491b7ac7caSGreg Kurz memcpy(cap.args, args_tmp, n * sizeof(cap.args[0])); \ 45040f1ee27SCornelia Huck kvm_vcpu_ioctl(cpu, KVM_ENABLE_CAP, &cap); \ 45140f1ee27SCornelia Huck }) 45240f1ee27SCornelia Huck 4539c17d615SPaolo Bonzini uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, 4549c17d615SPaolo Bonzini uint32_t index, int reg); 455ede146c2SPaolo Bonzini uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index); 456f57bceb6SRobert Hoo 45797577fd4SJames Hogan 458aed6efb9SJames Hogan void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len); 459aed6efb9SJames Hogan 46097577fd4SJames Hogan #if !defined(CONFIG_USER_ONLY) 46197577fd4SJames Hogan int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr, 46297577fd4SJames Hogan hwaddr *phys_addr); 46397577fd4SJames Hogan #endif 46497577fd4SJames Hogan 46597577fd4SJames Hogan #endif /* NEED_CPU_H */ 46697577fd4SJames Hogan 467dd1750d7SAndreas Färber void kvm_cpu_synchronize_state(CPUState *cpu); 4689c17d615SPaolo Bonzini 46918268b60SPaolo Bonzini void kvm_init_cpu_signals(CPUState *cpu); 47018268b60SPaolo Bonzini 471d1f6af6aSPeter Xu /** 472d1f6af6aSPeter Xu * kvm_irqchip_add_msi_route - Add MSI route for specific vector 473d1f6af6aSPeter Xu * @s: KVM state 474d1f6af6aSPeter Xu * @vector: which vector to add. This can be either MSI/MSIX 475d1f6af6aSPeter Xu * vector. The function will automatically detect whether 476d1f6af6aSPeter Xu * MSI/MSIX is enabled, and fetch corresponding MSI 477d1f6af6aSPeter Xu * message. 478d1f6af6aSPeter Xu * @dev: Owner PCI device to add the route. If @dev is specified 479d1f6af6aSPeter Xu * as @NULL, an empty MSI message will be inited. 480d1f6af6aSPeter Xu * @return: virq (>=0) when success, errno (<0) when failed. 481d1f6af6aSPeter Xu */ 482d1f6af6aSPeter Xu int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev); 483dc9f06caSPavel Fedin int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg, 484dc9f06caSPavel Fedin PCIDevice *dev); 4853f1fea0fSPeter Xu void kvm_irqchip_commit_routes(KVMState *s); 4869c17d615SPaolo Bonzini void kvm_irqchip_release_virq(KVMState *s, int virq); 4879c17d615SPaolo Bonzini 488d426d9fbSCornelia Huck int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter); 489977a8d9cSAndrey Smetanin int kvm_irqchip_add_hv_sint_route(KVMState *s, uint32_t vcpu, uint32_t sint); 490d426d9fbSCornelia Huck 4911c9b71a7SEric Auger int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n, 492ca916d37SVincenzo Maffione EventNotifier *rn, int virq); 4931c9b71a7SEric Auger int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n, 4941c9b71a7SEric Auger int virq); 495197e3524SEric Auger int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, 496197e3524SEric Auger EventNotifier *rn, qemu_irq irq); 497197e3524SEric Auger int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, 498197e3524SEric Auger qemu_irq irq); 499197e3524SEric Auger void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi); 5009c17d615SPaolo Bonzini void kvm_pc_setup_irq_routing(bool pci_enabled); 5017b774593SAlexander Graf void kvm_init_irq_routing(KVMState *s); 502d6032e06SChristoffer Dall 5034376c40dSPaolo Bonzini bool kvm_kernel_irqchip_allowed(void); 5044376c40dSPaolo Bonzini bool kvm_kernel_irqchip_required(void); 5054376c40dSPaolo Bonzini bool kvm_kernel_irqchip_split(void); 5064376c40dSPaolo Bonzini 507d6032e06SChristoffer Dall /** 508d6032e06SChristoffer Dall * kvm_arch_irqchip_create: 509d6032e06SChristoffer Dall * @KVMState: The KVMState pointer 510d6032e06SChristoffer Dall * 511d6032e06SChristoffer Dall * Allow architectures to create an in-kernel irq chip themselves. 512d6032e06SChristoffer Dall * 513d6032e06SChristoffer Dall * Returns: < 0: error 514d6032e06SChristoffer Dall * 0: irq chip was not created 515d6032e06SChristoffer Dall * > 0: irq chip was created 516d6032e06SChristoffer Dall */ 5174376c40dSPaolo Bonzini int kvm_arch_irqchip_create(KVMState *s); 518ada4135fSCornelia Huck 519ada4135fSCornelia Huck /** 520ada4135fSCornelia Huck * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl 521ada4135fSCornelia Huck * @id: The register ID 522ada4135fSCornelia Huck * @source: The pointer to the value to be set. It must point to a variable 523ada4135fSCornelia Huck * of the correct type/size for the register being accessed. 524ada4135fSCornelia Huck * 525ada4135fSCornelia Huck * Returns: 0 on success, or a negative errno on failure. 526ada4135fSCornelia Huck */ 527ada4135fSCornelia Huck int kvm_set_one_reg(CPUState *cs, uint64_t id, void *source); 528ada4135fSCornelia Huck 529ada4135fSCornelia Huck /** 530ada4135fSCornelia Huck * kvm_get_one_reg - get a register value from KVM via KVM_GET_ONE_REG ioctl 531ada4135fSCornelia Huck * @id: The register ID 532ada4135fSCornelia Huck * @target: The pointer where the value is to be stored. It must point to a 533ada4135fSCornelia Huck * variable of the correct type/size for the register being accessed. 534ada4135fSCornelia Huck * 535ada4135fSCornelia Huck * Returns: 0 on success, or a negative errno on failure. 536ada4135fSCornelia Huck */ 537ada4135fSCornelia Huck int kvm_get_one_reg(CPUState *cs, uint64_t id, void *target); 538c64abd1fSSam Bobroff struct ppc_radix_page_info *kvm_get_radix_page_info(void); 53944f2e6c1SBharata B Rao int kvm_get_max_memslots(void); 540c82d9d43SPeter Xu 541c82d9d43SPeter Xu /* Notify resamplefd for EOI of specific interrupts. */ 542c82d9d43SPeter Xu void kvm_resample_fd_notify(int gsi); 543c82d9d43SPeter Xu 544*92a5199bSTom Lendacky /** 545*92a5199bSTom Lendacky * kvm_cpu_check_are_resettable - return whether CPUs can be reset 546*92a5199bSTom Lendacky * 547*92a5199bSTom Lendacky * Returns: true: CPUs are resettable 548*92a5199bSTom Lendacky * false: CPUs are not resettable 549*92a5199bSTom Lendacky */ 550*92a5199bSTom Lendacky bool kvm_cpu_check_are_resettable(void); 551*92a5199bSTom Lendacky 552*92a5199bSTom Lendacky bool kvm_arch_cpu_check_are_resettable(void); 553*92a5199bSTom Lendacky 5549c17d615SPaolo Bonzini #endif 555