4 * Copyright (C) 2006-2008 Qumranet Technologies
6 * Licensed under the terms of the GNU GPL version 2 or higher.
8 #ifndef THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
9 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
21 #define __user /* temporary, until installed via make headers_install */
24 #include <linux/kvm.h>
28 /* FIXME: share this number with kvm */
29 /* FIXME: or dynamically alloc/realloc regions */
31 #define KVM_MAX_NUM_MEM_REGIONS 32u
34 #define KVM_MAX_NUM_MEM_REGIONS 32u
40 int kvm_create_irqchip(KVMState
*s
);
43 * \brief Dump in kernel IRQCHIP contents
45 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
46 * and IOAPIC into a kvm_irqchip structure
48 * \param kvm Pointer to the current kvm_context
49 * \param chip The irq chip device to be dumped
51 int kvm_get_irqchip(KVMState
*s
, struct kvm_irqchip
*chip
);
54 * \brief Set in kernel IRQCHIP contents
56 * Write one of the in kernel irq chip devices, including PIC (master/slave)
60 * \param kvm Pointer to the current kvm_context
61 * \param chip THe irq chip device to be written
63 int kvm_set_irqchip(KVMState
*s
, struct kvm_irqchip
*chip
);
65 #if defined(__i386__) || defined(__x86_64__)
67 * \brief Get in kernel local APIC for vcpu
69 * Save the local apic state including the timer of a virtual CPU
71 * \param kvm Pointer to the current kvm_context
72 * \param vcpu Which virtual CPU should be accessed
73 * \param s Local apic state of the specific virtual CPU
75 int kvm_get_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
78 * \brief Set in kernel local APIC for vcpu
80 * Restore the local apic state including the timer of a virtual CPU
82 * \param kvm Pointer to the current kvm_context
83 * \param vcpu Which virtual CPU should be accessed
84 * \param s Local apic state of the specific virtual CPU
86 int kvm_set_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
89 * \brief Get in kernel PIT of the virtual domain
93 * \param kvm Pointer to the current kvm_context
94 * \param s PIT state of the virtual domain
96 int kvm_get_pit(KVMState
*s
, struct kvm_pit_state
*pit_state
);
99 * \brief Set in kernel PIT of the virtual domain
101 * Restore the PIT state.
102 * Timer would be retriggerred after restored.
104 * \param kvm Pointer to the current kvm_context
105 * \param s PIT state of the virtual domain
107 int kvm_set_pit(KVMState
*s
, struct kvm_pit_state
*pit_state
);
109 int kvm_reinject_control(KVMState
*s
, int pit_reinject
);
112 * \brief Set in kernel PIT state2 of the virtual domain
115 * \param kvm Pointer to the current kvm_context
116 * \param ps2 PIT state2 of the virtual domain
117 * \return 0 on success
119 int kvm_set_pit2(KVMState
*s
, struct kvm_pit_state2
*ps2
);
122 * \brief Get in kernel PIT state2 of the virtual domain
125 * \param kvm Pointer to the current kvm_context
126 * \param ps2 PIT state2 of the virtual domain
127 * \return 0 on success
129 int kvm_get_pit2(KVMState
*s
, struct kvm_pit_state2
*ps2
);
133 int kvm_enable_vapic(CPUState
*env
, uint64_t vapic
);
136 * \brief Notifies host kernel about a PCI device to be assigned to a guest
138 * Used for PCI device assignment, this function notifies the host
139 * kernel about the assigning of the physical PCI device to a guest.
141 * \param kvm Pointer to the current kvm_context
142 * \param assigned_dev Parameters, like bus, devfn number, etc
144 int kvm_assign_pci_device(KVMState
*s
,
145 struct kvm_assigned_pci_dev
*assigned_dev
);
148 * \brief Assign IRQ for an assigned device
150 * Used for PCI device assignment, this function assigns IRQ numbers for
151 * an physical device and guest IRQ handling.
153 * \param kvm Pointer to the current kvm_context
154 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
156 int kvm_assign_irq(KVMState
*s
, struct kvm_assigned_irq
*assigned_irq
);
159 * \brief Deassign IRQ for an assigned device
161 * Used for PCI device assignment, this function deassigns IRQ numbers
162 * for an assigned device.
164 * \param kvm Pointer to the current kvm_context
165 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
167 int kvm_deassign_irq(KVMState
*s
, struct kvm_assigned_irq
*assigned_irq
);
170 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
172 * Used for hot remove PCI device, this function notifies the host
173 * kernel about the deassigning of the physical PCI device from a guest.
175 * \param kvm Pointer to the current kvm_context
176 * \param assigned_dev Parameters, like bus, devfn number, etc
178 int kvm_deassign_pci_device(KVMState
*s
,
179 struct kvm_assigned_pci_dev
*assigned_dev
);
182 * \brief Clears the temporary irq routing table
184 * Clears the temporary irq routing table. Nothing is committed to the
188 int kvm_clear_gsi_routes(void);
191 * \brief Adds an irq route to the temporary irq routing table
193 * Adds an irq route to the temporary irq routing table. Nothing is
194 * committed to the running VM.
196 int kvm_add_irq_route(int gsi
, int irqchip
, int pin
);
199 * \brief Removes an irq route from the temporary irq routing table
201 * Adds an irq route to the temporary irq routing table. Nothing is
202 * committed to the running VM.
204 int kvm_del_irq_route(int gsi
, int irqchip
, int pin
);
206 struct kvm_irq_routing_entry
;
208 * \brief Adds a routing entry to the temporary irq routing table
210 * Adds a filled routing entry to the temporary irq routing table. Nothing is
211 * committed to the running VM.
213 int kvm_add_routing_entry(struct kvm_irq_routing_entry
*entry
);
216 * \brief Removes a routing from the temporary irq routing table
218 * Remove a routing to the temporary irq routing table. Nothing is
219 * committed to the running VM.
221 int kvm_del_routing_entry(struct kvm_irq_routing_entry
*entry
);
224 * \brief Updates a routing in the temporary irq routing table
226 * Update a routing in the temporary irq routing table
227 * with a new value. entry type and GSI can not be changed.
228 * Nothing is committed to the running VM.
230 int kvm_update_routing_entry(struct kvm_irq_routing_entry
*entry
,
231 struct kvm_irq_routing_entry
*newentry
);
234 int kvm_assign_set_msix_nr(KVMState
*s
, struct kvm_assigned_msix_nr
*msix_nr
);
235 int kvm_assign_set_msix_entry(KVMState
*s
,
236 struct kvm_assigned_msix_entry
*entry
);
238 #else /* !CONFIG_KVM */
240 struct kvm_pit_state
{
243 #endif /* !CONFIG_KVM */
245 void kvm_save_lapic(CPUState
*env
);
246 void kvm_load_lapic(CPUState
*env
);
248 void kvm_hpet_enable_kpit(void);
249 void kvm_hpet_disable_kpit(void);
251 void kvm_tpr_access_report(CPUState
*env
, uint64_t rip
, int is_write
);
253 int kvm_arch_init_irq_routing(void);
255 int kvm_add_ioport_region(unsigned long start
, unsigned long size
);
256 int kvm_remove_ioport_region(unsigned long start
, unsigned long size
);
258 int kvm_update_ioport_access(CPUState
*env
);
259 int kvm_arch_set_ioport_access(unsigned long start
, unsigned long size
,
262 extern int kvm_irqchip
;
264 extern int kvm_pit_reinject
;
265 extern unsigned int kvm_shadow_memory
;
267 int kvm_handle_tpr_access(CPUState
*env
);
268 int kvm_tpr_enable_vapic(CPUState
*env
);