qemu-kvm: Merge kvm_context into KVMState
[qemu-kvm.git] / qemu-kvm.h
blob7386b4637af1002d2137fe5b02549dc2102f115d
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 #if defined(__s390__)
19 #include <asm/ptrace.h>
20 #endif
22 #include <stdint.h>
24 #ifndef __user
25 #define __user /* temporary, until installed via make headers_install */
26 #endif
28 #include <linux/kvm.h>
30 #include <signal.h>
32 /* FIXME: share this number with kvm */
33 /* FIXME: or dynamically alloc/realloc regions */
34 #ifdef __s390__
35 #define KVM_MAX_NUM_MEM_REGIONS 1u
36 #define MAX_VCPUS 64
37 #define LIBKVM_S390_ORIGIN (0UL)
38 #elif defined(__ia64__)
39 #define KVM_MAX_NUM_MEM_REGIONS 32u
40 #define MAX_VCPUS 256
41 #else
42 #define KVM_MAX_NUM_MEM_REGIONS 32u
43 #define MAX_VCPUS 16
44 #endif
46 #include "kvm.h"
48 int kvm_arch_run(CPUState *env);
50 int kvm_create_irqchip(KVMState *s);
52 /*!
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__)
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);
75 #endif
77 #ifdef KVM_CAP_IRQCHIP
78 /*!
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);
89 /*!
90 * \brief Set in kernel IRQCHIP contents
92 * Write one of the in kernel irq chip devices, including PIC (master/slave)
93 * and IOAPIC
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);
124 #endif
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);
137 #endif
139 #ifdef KVM_CAP_PIT
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);
186 #endif
187 #endif
188 #endif
190 #ifdef KVM_CAP_VAPIC
192 int kvm_enable_vapic(CPUState *env, uint64_t vapic);
194 #endif
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);
231 #endif
232 #endif
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);
246 #endif
249 * \brief Clears the temporary irq routing table
251 * Clears the temporary irq routing table. Nothing is committed to the
252 * running VM.
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);
305 #endif
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
325 int kvm_init(void);
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
349 struct ioperm_data;
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);
355 #endif
357 #ifdef CONFIG_KVM
358 #include "qemu-queue.h"
360 extern int kvm_irqchip;
361 extern int kvm_pit;
362 extern int kvm_pit_reinject;
363 extern int kvm_nested;
364 extern unsigned int kvm_shadow_memory;
366 struct ioperm_data {
367 unsigned long start_port;
368 unsigned long num;
369 int turn_on;
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,
375 int is_write);
377 #else
378 #define kvm_nested 0
379 #endif
381 int kvm_tpr_enable_vapic(CPUState *env);
383 unsigned long kvm_get_thread_id(void);
385 #endif