Merge branch 'master' of git://git.qemu.org/qemu into next
[qemu/qemu-dev-zwu.git] / qemu-kvm.h
blob845880e35ee8ff6ca301861cf501fa45f0c018ba
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 /*!
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);
53 /*!
54 * \brief Set in kernel IRQCHIP contents
56 * Write one of the in kernel irq chip devices, including PIC (master/slave)
57 * and IOAPIC
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__)
66 /*!
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);
77 /*!
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);
88 /*!
89 * \brief Get in kernel PIT of the virtual domain
91 * Save the PIT state.
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);
98 /*!
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);
131 #endif
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
185 * running VM.
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,
260 bool enable);
262 extern int kvm_irqchip;
263 extern int kvm_pit;
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);
270 #endif