Merge branch 'upstream-merge' into next
[qemu-dev-zwu.git] / qemu-kvm.h
blob0f833f16e4afde688bed97ebcb4e430b19a9adb9
1 /*
2 * qemu/kvm integration
4 * Copyright (C) 2006-2008 Qumranet Technologies
6 * Licensed under the terms of the GNU GPL version 2 or higher.
7 */
8 #ifndef THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
9 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
11 #include "cpu.h"
13 #include <signal.h>
14 #include <stdlib.h>
16 #ifdef CONFIG_KVM
18 #include <stdint.h>
20 #ifndef __user
21 #define __user /* temporary, until installed via make headers_install */
22 #endif
24 #include <linux/kvm.h>
26 #include <signal.h>
28 /* FIXME: share this number with kvm */
29 /* FIXME: or dynamically alloc/realloc regions */
30 #if defined(__ia64__)
31 #define KVM_MAX_NUM_MEM_REGIONS 32u
32 #define MAX_VCPUS 256
33 #else
34 #define KVM_MAX_NUM_MEM_REGIONS 32u
35 #define MAX_VCPUS 16
36 #endif
38 #include "kvm.h"
40 int kvm_create_irqchip(KVMState *s);
42 #ifdef KVM_CAP_IRQCHIP
43 /*!
44 * \brief Dump in kernel IRQCHIP contents
46 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
47 * and IOAPIC into a kvm_irqchip structure
49 * \param kvm Pointer to the current kvm_context
50 * \param chip The irq chip device to be dumped
52 int kvm_get_irqchip(KVMState *s, struct kvm_irqchip *chip);
54 /*!
55 * \brief Set in kernel IRQCHIP contents
57 * Write one of the in kernel irq chip devices, including PIC (master/slave)
58 * and IOAPIC
61 * \param kvm Pointer to the current kvm_context
62 * \param chip THe irq chip device to be written
64 int kvm_set_irqchip(KVMState *s, struct kvm_irqchip *chip);
66 #if defined(__i386__) || defined(__x86_64__)
67 /*!
68 * \brief Get in kernel local APIC for vcpu
70 * Save the local apic state including the timer of a virtual CPU
72 * \param kvm Pointer to the current kvm_context
73 * \param vcpu Which virtual CPU should be accessed
74 * \param s Local apic state of the specific virtual CPU
76 int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
78 /*!
79 * \brief Set in kernel local APIC for vcpu
81 * Restore the local apic state including the timer of a virtual CPU
83 * \param kvm Pointer to the current kvm_context
84 * \param vcpu Which virtual CPU should be accessed
85 * \param s Local apic state of the specific virtual CPU
87 int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
89 #endif
91 #endif
93 #ifdef KVM_CAP_PIT
95 #if defined(__i386__) || defined(__x86_64__)
96 /*!
97 * \brief Get in kernel PIT of the virtual domain
99 * Save the PIT state.
101 * \param kvm Pointer to the current kvm_context
102 * \param s PIT state of the virtual domain
104 int kvm_get_pit(KVMState *s, struct kvm_pit_state *pit_state);
107 * \brief Set in kernel PIT of the virtual domain
109 * Restore the PIT state.
110 * Timer would be retriggerred after restored.
112 * \param kvm Pointer to the current kvm_context
113 * \param s PIT state of the virtual domain
115 int kvm_set_pit(KVMState *s, struct kvm_pit_state *pit_state);
117 int kvm_reinject_control(KVMState *s, int pit_reinject);
119 #ifdef KVM_CAP_PIT_STATE2
121 * \brief Set in kernel PIT state2 of the virtual domain
124 * \param kvm Pointer to the current kvm_context
125 * \param ps2 PIT state2 of the virtual domain
126 * \return 0 on success
128 int kvm_set_pit2(KVMState *s, struct kvm_pit_state2 *ps2);
131 * \brief Get in kernel PIT state2 of the virtual domain
134 * \param kvm Pointer to the current kvm_context
135 * \param ps2 PIT state2 of the virtual domain
136 * \return 0 on success
138 int kvm_get_pit2(KVMState *s, struct kvm_pit_state2 *ps2);
140 #endif
141 #endif
142 #endif
144 #ifdef KVM_CAP_VAPIC
146 int kvm_enable_vapic(CPUState *env, uint64_t vapic);
148 #endif
150 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
152 * \brief Notifies host kernel about a PCI device to be assigned to a guest
154 * Used for PCI device assignment, this function notifies the host
155 * kernel about the assigning of the physical PCI device to a guest.
157 * \param kvm Pointer to the current kvm_context
158 * \param assigned_dev Parameters, like bus, devfn number, etc
160 int kvm_assign_pci_device(KVMState *s,
161 struct kvm_assigned_pci_dev *assigned_dev);
164 * \brief Assign IRQ for an assigned device
166 * Used for PCI device assignment, this function assigns IRQ numbers for
167 * an physical device and guest IRQ handling.
169 * \param kvm Pointer to the current kvm_context
170 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
172 int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
174 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
176 * \brief Deassign IRQ for an assigned device
178 * Used for PCI device assignment, this function deassigns IRQ numbers
179 * for an assigned device.
181 * \param kvm Pointer to the current kvm_context
182 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
184 int kvm_deassign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
185 #endif
186 #endif
188 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
190 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
192 * Used for hot remove PCI device, this function notifies the host
193 * kernel about the deassigning of the physical PCI device from a guest.
195 * \param kvm Pointer to the current kvm_context
196 * \param assigned_dev Parameters, like bus, devfn number, etc
198 int kvm_deassign_pci_device(KVMState *s,
199 struct kvm_assigned_pci_dev *assigned_dev);
200 #endif
203 * \brief Clears the temporary irq routing table
205 * Clears the temporary irq routing table. Nothing is committed to the
206 * running VM.
209 int kvm_clear_gsi_routes(void);
212 * \brief Adds an irq route to the temporary irq routing table
214 * Adds an irq route to the temporary irq routing table. Nothing is
215 * committed to the running VM.
217 int kvm_add_irq_route(int gsi, int irqchip, int pin);
220 * \brief Removes an irq route from the temporary irq routing table
222 * Adds an irq route to the temporary irq routing table. Nothing is
223 * committed to the running VM.
225 int kvm_del_irq_route(int gsi, int irqchip, int pin);
227 struct kvm_irq_routing_entry;
229 * \brief Adds a routing entry to the temporary irq routing table
231 * Adds a filled routing entry to the temporary irq routing table. Nothing is
232 * committed to the running VM.
234 int kvm_add_routing_entry(struct kvm_irq_routing_entry *entry);
237 * \brief Removes a routing from the temporary irq routing table
239 * Remove a routing to the temporary irq routing table. Nothing is
240 * committed to the running VM.
242 int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry);
245 * \brief Updates a routing in the temporary irq routing table
247 * Update a routing in the temporary irq routing table
248 * with a new value. entry type and GSI can not be changed.
249 * Nothing is committed to the running VM.
251 int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,
252 struct kvm_irq_routing_entry *newentry);
255 #ifdef KVM_CAP_DEVICE_MSIX
256 int kvm_assign_set_msix_nr(KVMState *s, struct kvm_assigned_msix_nr *msix_nr);
257 int kvm_assign_set_msix_entry(KVMState *s,
258 struct kvm_assigned_msix_entry *entry);
259 #endif
261 #else /* !CONFIG_KVM */
263 struct kvm_pit_state {
266 #endif /* !CONFIG_KVM */
268 void kvm_save_lapic(CPUState *env);
269 void kvm_load_lapic(CPUState *env);
271 void kvm_hpet_enable_kpit(void);
272 void kvm_hpet_disable_kpit(void);
274 int kvm_set_boot_cpu_id(KVMState *s, uint32_t id);
276 void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
278 int kvm_arch_init_irq_routing(void);
280 int kvm_add_ioport_region(unsigned long start, unsigned long size);
281 int kvm_remove_ioport_region(unsigned long start, unsigned long size);
283 int kvm_update_ioport_access(CPUState *env);
284 int kvm_arch_set_ioport_access(unsigned long start, unsigned long size,
285 bool enable);
287 #ifdef CONFIG_KVM
288 extern int kvm_irqchip;
289 extern int kvm_pit;
290 extern int kvm_pit_reinject;
291 extern int kvm_nested;
292 extern unsigned int kvm_shadow_memory;
294 int kvm_handle_tpr_access(CPUState *env);
296 #else
297 #define kvm_nested 0
298 #endif
300 int kvm_tpr_enable_vapic(CPUState *env);
302 #endif