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 */
30 #define KVM_MAX_NUM_MEM_REGIONS 32u
35 int kvm_create_irqchip(KVMState
*s
);
38 * \brief Dump in kernel IRQCHIP contents
40 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
41 * and IOAPIC into a kvm_irqchip structure
43 * \param kvm Pointer to the current kvm_context
44 * \param chip The irq chip device to be dumped
46 int kvm_get_irqchip(KVMState
*s
, struct kvm_irqchip
*chip
);
49 * \brief Set in kernel IRQCHIP contents
51 * Write one of the in kernel irq chip devices, including PIC (master/slave)
55 * \param kvm Pointer to the current kvm_context
56 * \param chip THe irq chip device to be written
58 int kvm_set_irqchip(KVMState
*s
, struct kvm_irqchip
*chip
);
60 #if defined(__i386__) || defined(__x86_64__)
62 * \brief Get in kernel local APIC for vcpu
64 * Save the local apic state including the timer of a virtual CPU
66 * \param kvm Pointer to the current kvm_context
67 * \param vcpu Which virtual CPU should be accessed
68 * \param s Local apic state of the specific virtual CPU
70 int kvm_get_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
73 * \brief Set in kernel local APIC for vcpu
75 * Restore the local apic state including the timer of a virtual CPU
77 * \param kvm Pointer to the current kvm_context
78 * \param vcpu Which virtual CPU should be accessed
79 * \param s Local apic state of the specific virtual CPU
81 int kvm_set_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
84 * \brief Get in kernel PIT of the virtual domain
88 * \param kvm Pointer to the current kvm_context
89 * \param s PIT state of the virtual domain
91 int kvm_get_pit(KVMState
*s
, struct kvm_pit_state
*pit_state
);
94 * \brief Set in kernel PIT of the virtual domain
96 * Restore the PIT state.
97 * Timer would be retriggerred after restored.
99 * \param kvm Pointer to the current kvm_context
100 * \param s PIT state of the virtual domain
102 int kvm_set_pit(KVMState
*s
, struct kvm_pit_state
*pit_state
);
104 int kvm_reinject_control(KVMState
*s
, int pit_reinject
);
107 * \brief Set in kernel PIT state2 of the virtual domain
110 * \param kvm Pointer to the current kvm_context
111 * \param ps2 PIT state2 of the virtual domain
112 * \return 0 on success
114 int kvm_set_pit2(KVMState
*s
, struct kvm_pit_state2
*ps2
);
117 * \brief Get in kernel PIT state2 of the virtual domain
120 * \param kvm Pointer to the current kvm_context
121 * \param ps2 PIT state2 of the virtual domain
122 * \return 0 on success
124 int kvm_get_pit2(KVMState
*s
, struct kvm_pit_state2
*ps2
);
128 int kvm_enable_vapic(CPUState
*env
, uint64_t vapic
);
131 * \brief Notifies host kernel about a PCI device to be assigned to a guest
133 * Used for PCI device assignment, this function notifies the host
134 * kernel about the assigning of the physical PCI device to a guest.
136 * \param kvm Pointer to the current kvm_context
137 * \param assigned_dev Parameters, like bus, devfn number, etc
139 int kvm_assign_pci_device(KVMState
*s
,
140 struct kvm_assigned_pci_dev
*assigned_dev
);
143 * \brief Assign IRQ for an assigned device
145 * Used for PCI device assignment, this function assigns IRQ numbers for
146 * an physical device and guest IRQ handling.
148 * \param kvm Pointer to the current kvm_context
149 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
151 int kvm_assign_irq(KVMState
*s
, struct kvm_assigned_irq
*assigned_irq
);
154 * \brief Deassign IRQ for an assigned device
156 * Used for PCI device assignment, this function deassigns IRQ numbers
157 * for an assigned device.
159 * \param kvm Pointer to the current kvm_context
160 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
162 int kvm_deassign_irq(KVMState
*s
, struct kvm_assigned_irq
*assigned_irq
);
165 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
167 * Used for hot remove PCI device, this function notifies the host
168 * kernel about the deassigning of the physical PCI device from a guest.
170 * \param kvm Pointer to the current kvm_context
171 * \param assigned_dev Parameters, like bus, devfn number, etc
173 int kvm_deassign_pci_device(KVMState
*s
,
174 struct kvm_assigned_pci_dev
*assigned_dev
);
177 * \brief Clears the temporary irq routing table
179 * Clears the temporary irq routing table. Nothing is committed to the
183 int kvm_clear_gsi_routes(void);
186 * \brief Adds an irq route to the temporary irq routing table
188 * Adds an irq route to the temporary irq routing table. Nothing is
189 * committed to the running VM.
191 int kvm_add_irq_route(int gsi
, int irqchip
, int pin
);
194 * \brief Removes an irq route from the temporary irq routing table
196 * Adds an irq route to the temporary irq routing table. Nothing is
197 * committed to the running VM.
199 int kvm_del_irq_route(int gsi
, int irqchip
, int pin
);
201 struct kvm_irq_routing_entry
;
203 * \brief Adds a routing entry to the temporary irq routing table
205 * Adds a filled routing entry to the temporary irq routing table. Nothing is
206 * committed to the running VM.
208 int kvm_add_routing_entry(struct kvm_irq_routing_entry
*entry
);
211 * \brief Removes a routing from the temporary irq routing table
213 * Remove a routing to the temporary irq routing table. Nothing is
214 * committed to the running VM.
216 int kvm_del_routing_entry(struct kvm_irq_routing_entry
*entry
);
219 * \brief Updates a routing in the temporary irq routing table
221 * Update a routing in the temporary irq routing table
222 * with a new value. entry type and GSI can not be changed.
223 * Nothing is committed to the running VM.
225 int kvm_update_routing_entry(struct kvm_irq_routing_entry
*entry
,
226 struct kvm_irq_routing_entry
*newentry
);
229 int kvm_assign_set_msix_nr(KVMState
*s
, struct kvm_assigned_msix_nr
*msix_nr
);
230 int kvm_assign_set_msix_entry(KVMState
*s
,
231 struct kvm_assigned_msix_entry
*entry
);
233 #else /* !CONFIG_KVM */
235 struct kvm_pit_state
{
238 #endif /* !CONFIG_KVM */
240 void kvm_save_lapic(CPUState
*env
);
241 void kvm_load_lapic(CPUState
*env
);
243 void kvm_hpet_enable_kpit(void);
244 void kvm_hpet_disable_kpit(void);
246 void kvm_tpr_access_report(CPUState
*env
, uint64_t rip
, int is_write
);
248 int kvm_arch_init_irq_routing(void);
250 int kvm_add_ioport_region(unsigned long start
, unsigned long size
,
252 int kvm_remove_ioport_region(unsigned long start
, unsigned long size
,
255 int kvm_update_ioport_access(CPUState
*env
);
256 int kvm_arch_set_ioport_access(unsigned long start
, unsigned long size
,
259 extern int kvm_irqchip
;
261 extern int kvm_pit_reinject
;
262 extern unsigned int kvm_shadow_memory
;
264 int kvm_handle_tpr_access(CPUState
*env
);
265 void kvm_tpr_enable_vapic(CPUState
*env
);