| /* |
| * qemu/kvm integration |
| * |
| * Copyright (C) 2006-2008 Qumranet Technologies |
| * |
| * Licensed under the terms of the GNU GPL version 2 or higher. |
| */ |
| #ifndef THE_ORIGINAL_AND_TRUE_QEMU_KVM_H |
| #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H |
| |
| #include "cpu.h" |
| |
| #include <signal.h> |
| #include <stdlib.h> |
| |
| #ifdef CONFIG_KVM |
| |
| #include <stdint.h> |
| |
| #ifndef __user |
| #define __user /* temporary, until installed via make headers_install */ |
| #endif |
| |
| #include <linux/kvm.h> |
| |
| #include <signal.h> |
| |
| /* FIXME: share this number with kvm */ |
| /* FIXME: or dynamically alloc/realloc regions */ |
| #define KVM_MAX_NUM_MEM_REGIONS 32u |
| #define MAX_VCPUS 16 |
| |
| #include "kvm.h" |
| |
| int kvm_create_irqchip(KVMState *s); |
| |
| /*! |
| * \brief Dump in kernel IRQCHIP contents |
| * |
| * Dump one of the in kernel irq chip devices, including PIC (master/slave) |
| * and IOAPIC into a kvm_irqchip structure |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param chip The irq chip device to be dumped |
| */ |
| int kvm_get_irqchip(KVMState *s, struct kvm_irqchip *chip); |
| |
| /*! |
| * \brief Set in kernel IRQCHIP contents |
| * |
| * Write one of the in kernel irq chip devices, including PIC (master/slave) |
| * and IOAPIC |
| * |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param chip THe irq chip device to be written |
| */ |
| int kvm_set_irqchip(KVMState *s, struct kvm_irqchip *chip); |
| |
| #if defined(__i386__) || defined(__x86_64__) |
| /*! |
| * \brief Get in kernel local APIC for vcpu |
| * |
| * Save the local apic state including the timer of a virtual CPU |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param vcpu Which virtual CPU should be accessed |
| * \param s Local apic state of the specific virtual CPU |
| */ |
| int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s); |
| |
| /*! |
| * \brief Set in kernel local APIC for vcpu |
| * |
| * Restore the local apic state including the timer of a virtual CPU |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param vcpu Which virtual CPU should be accessed |
| * \param s Local apic state of the specific virtual CPU |
| */ |
| int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s); |
| |
| /*! |
| * \brief Get in kernel PIT of the virtual domain |
| * |
| * Save the PIT state. |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param s PIT state of the virtual domain |
| */ |
| int kvm_get_pit(KVMState *s, struct kvm_pit_state *pit_state); |
| |
| /*! |
| * \brief Set in kernel PIT of the virtual domain |
| * |
| * Restore the PIT state. |
| * Timer would be retriggerred after restored. |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param s PIT state of the virtual domain |
| */ |
| int kvm_set_pit(KVMState *s, struct kvm_pit_state *pit_state); |
| |
| int kvm_reinject_control(KVMState *s, int pit_reinject); |
| |
| /*! |
| * \brief Set in kernel PIT state2 of the virtual domain |
| * |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param ps2 PIT state2 of the virtual domain |
| * \return 0 on success |
| */ |
| int kvm_set_pit2(KVMState *s, struct kvm_pit_state2 *ps2); |
| |
| /*! |
| * \brief Get in kernel PIT state2 of the virtual domain |
| * |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param ps2 PIT state2 of the virtual domain |
| * \return 0 on success |
| */ |
| int kvm_get_pit2(KVMState *s, struct kvm_pit_state2 *ps2); |
| |
| #endif |
| |
| int kvm_enable_vapic(CPUState *env, uint64_t vapic); |
| |
| /*! |
| * \brief Notifies host kernel about a PCI device to be assigned to a guest |
| * |
| * Used for PCI device assignment, this function notifies the host |
| * kernel about the assigning of the physical PCI device to a guest. |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param assigned_dev Parameters, like bus, devfn number, etc |
| */ |
| int kvm_assign_pci_device(KVMState *s, |
| struct kvm_assigned_pci_dev *assigned_dev); |
| |
| /*! |
| * \brief Assign IRQ for an assigned device |
| * |
| * Used for PCI device assignment, this function assigns IRQ numbers for |
| * an physical device and guest IRQ handling. |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc |
| */ |
| int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq); |
| |
| /*! |
| * \brief Deassign IRQ for an assigned device |
| * |
| * Used for PCI device assignment, this function deassigns IRQ numbers |
| * for an assigned device. |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc |
| */ |
| int kvm_deassign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq); |
| |
| /*! |
| * \brief Notifies host kernel about a PCI device to be deassigned from a guest |
| * |
| * Used for hot remove PCI device, this function notifies the host |
| * kernel about the deassigning of the physical PCI device from a guest. |
| * |
| * \param kvm Pointer to the current kvm_context |
| * \param assigned_dev Parameters, like bus, devfn number, etc |
| */ |
| int kvm_deassign_pci_device(KVMState *s, |
| struct kvm_assigned_pci_dev *assigned_dev); |
| |
| /*! |
| * \brief Clears the temporary irq routing table |
| * |
| * Clears the temporary irq routing table. Nothing is committed to the |
| * running VM. |
| * |
| */ |
| int kvm_clear_gsi_routes(void); |
| |
| /*! |
| * \brief Adds an irq route to the temporary irq routing table |
| * |
| * Adds an irq route to the temporary irq routing table. Nothing is |
| * committed to the running VM. |
| */ |
| int kvm_add_irq_route(int gsi, int irqchip, int pin); |
| |
| /*! |
| * \brief Removes an irq route from the temporary irq routing table |
| * |
| * Adds an irq route to the temporary irq routing table. Nothing is |
| * committed to the running VM. |
| */ |
| int kvm_del_irq_route(int gsi, int irqchip, int pin); |
| |
| struct kvm_irq_routing_entry; |
| /*! |
| * \brief Adds a routing entry to the temporary irq routing table |
| * |
| * Adds a filled routing entry to the temporary irq routing table. Nothing is |
| * committed to the running VM. |
| */ |
| int kvm_add_routing_entry(struct kvm_irq_routing_entry *entry); |
| |
| /*! |
| * \brief Removes a routing from the temporary irq routing table |
| * |
| * Remove a routing to the temporary irq routing table. Nothing is |
| * committed to the running VM. |
| */ |
| int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry); |
| |
| /*! |
| * \brief Updates a routing in the temporary irq routing table |
| * |
| * Update a routing in the temporary irq routing table |
| * with a new value. entry type and GSI can not be changed. |
| * Nothing is committed to the running VM. |
| */ |
| int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry, |
| struct kvm_irq_routing_entry *newentry); |
| |
| |
| int kvm_assign_set_msix_nr(KVMState *s, struct kvm_assigned_msix_nr *msix_nr); |
| int kvm_assign_set_msix_entry(KVMState *s, |
| struct kvm_assigned_msix_entry *entry); |
| |
| #else /* !CONFIG_KVM */ |
| |
| struct kvm_pit_state { |
| }; |
| |
| #endif /* !CONFIG_KVM */ |
| |
| void kvm_save_lapic(CPUState *env); |
| void kvm_load_lapic(CPUState *env); |
| |
| void kvm_hpet_enable_kpit(void); |
| void kvm_hpet_disable_kpit(void); |
| |
| void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write); |
| |
| int kvm_arch_init_irq_routing(void); |
| |
| int kvm_add_ioport_region(unsigned long start, unsigned long size, |
| bool is_hot_plug); |
| int kvm_remove_ioport_region(unsigned long start, unsigned long size, |
| bool is_hot_unplug); |
| |
| int kvm_update_ioport_access(CPUState *env); |
| int kvm_arch_set_ioport_access(unsigned long start, unsigned long size, |
| bool enable); |
| |
| extern int kvm_irqchip; |
| extern int kvm_pit_reinject; |
| extern unsigned int kvm_shadow_memory; |
| |
| int kvm_handle_tpr_access(CPUState *env); |
| void kvm_tpr_enable_vapic(CPUState *env); |
| |
| #endif |