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
19 #include <asm/ptrace.h>
25 #define __user /* temporary, until installed via make headers_install */
28 #include <linux/kvm.h>
32 /* FIXME: share this number with kvm */
33 /* FIXME: or dynamically alloc/realloc regions */
35 #define KVM_MAX_NUM_MEM_REGIONS 1u
37 #define LIBKVM_S390_ORIGIN (0UL)
38 #elif defined(__ia64__)
39 #define KVM_MAX_NUM_MEM_REGIONS 32u
42 #define KVM_MAX_NUM_MEM_REGIONS 32u
48 int kvm_arch_run(CPUState
*env
);
50 int kvm_create_irqchip(KVMState
*s
);
53 * \brief Check if a vcpu is ready for interrupt injection
55 * This checks if vcpu interrupts are not masked by mov ss or sti.
57 * \param kvm Pointer to the current kvm_context
58 * \param vcpu Which virtual CPU should get dumped
59 * \return boolean indicating interrupt injection readiness
61 int kvm_is_ready_for_interrupt_injection(CPUState
*env
);
63 #if defined(__i386__) || defined(__x86_64__)
65 * \brief Simulate an external vectored interrupt
67 * This allows you to simulate an external vectored interrupt.
69 * \param kvm Pointer to the current kvm_context
70 * \param vcpu Which virtual CPU should get dumped
71 * \param irq Vector number
72 * \return 0 on success
74 int kvm_inject_irq(CPUState
*env
, unsigned irq
);
77 #ifdef KVM_CAP_IRQCHIP
79 * \brief Dump in kernel IRQCHIP contents
81 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
82 * and IOAPIC into a kvm_irqchip structure
84 * \param kvm Pointer to the current kvm_context
85 * \param chip The irq chip device to be dumped
87 int kvm_get_irqchip(KVMState
*s
, struct kvm_irqchip
*chip
);
90 * \brief Set in kernel IRQCHIP contents
92 * Write one of the in kernel irq chip devices, including PIC (master/slave)
96 * \param kvm Pointer to the current kvm_context
97 * \param chip THe irq chip device to be written
99 int kvm_set_irqchip(KVMState
*s
, struct kvm_irqchip
*chip
);
101 #if defined(__i386__) || defined(__x86_64__)
103 * \brief Get in kernel local APIC for vcpu
105 * Save the local apic state including the timer of a virtual CPU
107 * \param kvm Pointer to the current kvm_context
108 * \param vcpu Which virtual CPU should be accessed
109 * \param s Local apic state of the specific virtual CPU
111 int kvm_get_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
114 * \brief Set in kernel local APIC for vcpu
116 * Restore the local apic state including the timer of a virtual CPU
118 * \param kvm Pointer to the current kvm_context
119 * \param vcpu Which virtual CPU should be accessed
120 * \param s Local apic state of the specific virtual CPU
122 int kvm_set_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
127 * \brief Simulate an NMI
129 * This allows you to simulate a non-maskable interrupt.
131 * \param kvm Pointer to the current kvm_context
132 * \param vcpu Which virtual CPU should get dumped
133 * \return 0 on success
135 int kvm_inject_nmi(CPUState
*env
);
141 #if defined(__i386__) || defined(__x86_64__)
143 * \brief Get in kernel PIT of the virtual domain
145 * Save the PIT state.
147 * \param kvm Pointer to the current kvm_context
148 * \param s PIT state of the virtual domain
150 int kvm_get_pit(KVMState
*s
, struct kvm_pit_state
*pit_state
);
153 * \brief Set in kernel PIT of the virtual domain
155 * Restore the PIT state.
156 * Timer would be retriggerred after restored.
158 * \param kvm Pointer to the current kvm_context
159 * \param s PIT state of the virtual domain
161 int kvm_set_pit(KVMState
*s
, struct kvm_pit_state
*pit_state
);
163 int kvm_reinject_control(KVMState
*s
, int pit_reinject
);
165 #ifdef KVM_CAP_PIT_STATE2
167 * \brief Set in kernel PIT state2 of the virtual domain
170 * \param kvm Pointer to the current kvm_context
171 * \param ps2 PIT state2 of the virtual domain
172 * \return 0 on success
174 int kvm_set_pit2(KVMState
*s
, struct kvm_pit_state2
*ps2
);
177 * \brief Get in kernel PIT state2 of the virtual domain
180 * \param kvm Pointer to the current kvm_context
181 * \param ps2 PIT state2 of the virtual domain
182 * \return 0 on success
184 int kvm_get_pit2(KVMState
*s
, struct kvm_pit_state2
*ps2
);
192 int kvm_enable_vapic(CPUState
*env
, uint64_t vapic
);
196 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
198 * \brief Notifies host kernel about a PCI device to be assigned to a guest
200 * Used for PCI device assignment, this function notifies the host
201 * kernel about the assigning of the physical PCI device to a guest.
203 * \param kvm Pointer to the current kvm_context
204 * \param assigned_dev Parameters, like bus, devfn number, etc
206 int kvm_assign_pci_device(KVMState
*s
,
207 struct kvm_assigned_pci_dev
*assigned_dev
);
210 * \brief Assign IRQ for an assigned device
212 * Used for PCI device assignment, this function assigns IRQ numbers for
213 * an physical device and guest IRQ handling.
215 * \param kvm Pointer to the current kvm_context
216 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
218 int kvm_assign_irq(KVMState
*s
, struct kvm_assigned_irq
*assigned_irq
);
220 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
222 * \brief Deassign IRQ for an assigned device
224 * Used for PCI device assignment, this function deassigns IRQ numbers
225 * for an assigned device.
227 * \param kvm Pointer to the current kvm_context
228 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
230 int kvm_deassign_irq(KVMState
*s
, struct kvm_assigned_irq
*assigned_irq
);
234 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
236 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
238 * Used for hot remove PCI device, this function notifies the host
239 * kernel about the deassigning of the physical PCI device from a guest.
241 * \param kvm Pointer to the current kvm_context
242 * \param assigned_dev Parameters, like bus, devfn number, etc
244 int kvm_deassign_pci_device(KVMState
*s
,
245 struct kvm_assigned_pci_dev
*assigned_dev
);
249 * \brief Clears the temporary irq routing table
251 * Clears the temporary irq routing table. Nothing is committed to the
255 int kvm_clear_gsi_routes(void);
258 * \brief Adds an irq route to the temporary irq routing table
260 * Adds an irq route to the temporary irq routing table. Nothing is
261 * committed to the running VM.
263 int kvm_add_irq_route(int gsi
, int irqchip
, int pin
);
266 * \brief Removes an irq route from the temporary irq routing table
268 * Adds an irq route to the temporary irq routing table. Nothing is
269 * committed to the running VM.
271 int kvm_del_irq_route(int gsi
, int irqchip
, int pin
);
273 struct kvm_irq_routing_entry
;
275 * \brief Adds a routing entry to the temporary irq routing table
277 * Adds a filled routing entry to the temporary irq routing table. Nothing is
278 * committed to the running VM.
280 int kvm_add_routing_entry(struct kvm_irq_routing_entry
*entry
);
283 * \brief Removes a routing from the temporary irq routing table
285 * Remove a routing to the temporary irq routing table. Nothing is
286 * committed to the running VM.
288 int kvm_del_routing_entry(struct kvm_irq_routing_entry
*entry
);
291 * \brief Updates a routing in the temporary irq routing table
293 * Update a routing in the temporary irq routing table
294 * with a new value. entry type and GSI can not be changed.
295 * Nothing is committed to the running VM.
297 int kvm_update_routing_entry(struct kvm_irq_routing_entry
*entry
,
298 struct kvm_irq_routing_entry
*newentry
);
301 #ifdef KVM_CAP_DEVICE_MSIX
302 int kvm_assign_set_msix_nr(KVMState
*s
, struct kvm_assigned_msix_nr
*msix_nr
);
303 int kvm_assign_set_msix_entry(KVMState
*s
,
304 struct kvm_assigned_msix_entry
*entry
);
307 #else /* !CONFIG_KVM */
309 struct kvm_pit_state
{
312 #endif /* !CONFIG_KVM */
316 * \brief Create new KVM context
318 * This creates a new kvm_context. A KVM context is a small area of data that
319 * holds information about the KVM instance that gets created by this call.\n
320 * This should always be your first call to KVM.
322 * \param opaque Not used
323 * \return NULL on failure
327 int kvm_main_loop(void);
328 int kvm_init_ap(void);
329 void kvm_save_lapic(CPUState
*env
);
330 void kvm_load_lapic(CPUState
*env
);
332 void kvm_hpet_enable_kpit(void);
333 void kvm_hpet_disable_kpit(void);
335 void on_vcpu(CPUState
*env
, void (*func
)(void *data
), void *data
);
336 void kvm_update_interrupt_request(CPUState
*env
);
338 int kvm_arch_has_work(CPUState
*env
);
339 void kvm_arch_process_irqchip_events(CPUState
*env
);
340 int kvm_arch_try_push_interrupts(void *opaque
);
341 void kvm_arch_push_nmi(void);
342 int kvm_set_boot_cpu_id(KVMState
*s
, uint32_t id
);
344 void kvm_tpr_access_report(CPUState
*env
, uint64_t rip
, int is_write
);
346 int kvm_arch_init_irq_routing(void);
348 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
351 void kvm_ioperm(CPUState
*env
, void *data
);
352 void kvm_add_ioperm_data(struct ioperm_data
*data
);
353 void kvm_remove_ioperm_data(unsigned long start_port
, unsigned long num
);
354 void kvm_arch_do_ioperm(void *_data
);
358 #include "qemu-queue.h"
360 extern int kvm_irqchip
;
362 extern int kvm_pit_reinject
;
363 extern int kvm_nested
;
364 extern unsigned int kvm_shadow_memory
;
367 unsigned long start_port
;
370 QLIST_ENTRY(ioperm_data
) entries
;
373 int kvm_arch_halt(CPUState
*env
);
374 int handle_tpr_access(void *opaque
, CPUState
*env
, uint64_t rip
,
381 int kvm_tpr_enable_vapic(CPUState
*env
);
383 unsigned long kvm_get_thread_id(void);