Merge branch 'upstream-merge' into next
[qemu/qemu-dev-zwu.git] / qemu-kvm.h
blob3ace503f7cd00c3d7195f0c919b642f92329546e
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 /* kvm abi verison variable */
47 extern int kvm_abi;
49 /**
50 * \brief The KVM context
52 * The verbose KVM context
55 struct kvm_context {
56 void *opaque;
57 /// is dirty pages logging enabled for all regions or not
58 int dirty_pages_log_all;
59 /// do not create in-kernel irqchip if set
60 int no_irqchip_creation;
61 /// in-kernel irqchip status
62 int irqchip_in_kernel;
63 /// ioctl to use to inject interrupts
64 int irqchip_inject_ioctl;
65 /// do not create in-kernel pit if set
66 int no_pit_creation;
67 #ifdef KVM_CAP_IRQ_ROUTING
68 struct kvm_irq_routing *irq_routes;
69 int nr_allocated_irq_routes;
70 #endif
71 void *used_gsi_bitmap;
72 int max_gsi;
75 typedef struct kvm_context *kvm_context_t;
77 #include "kvm.h"
78 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
79 void **vm_mem);
80 int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
81 void **vm_mem);
83 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
84 void **vm_mem);
86 int kvm_arch_run(CPUState *env);
89 void kvm_show_code(CPUState *env);
91 int handle_halt(CPUState *env);
93 int handle_shutdown(kvm_context_t kvm, CPUState *env);
94 void post_kvm_run(kvm_context_t kvm, CPUState *env);
95 int pre_kvm_run(kvm_context_t kvm, CPUState *env);
96 int handle_io_window(kvm_context_t kvm);
97 int try_push_interrupts(kvm_context_t kvm);
99 #if defined(__x86_64__) || defined(__i386__)
100 int kvm_get_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n);
101 int kvm_set_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n);
102 int kvm_get_mce_cap_supported(kvm_context_t, uint64_t *mce_cap,
103 int *max_banks);
104 int kvm_setup_mce(CPUState *env, uint64_t *mcg_cap);
105 struct kvm_x86_mce;
106 int kvm_set_mce(CPUState *env, struct kvm_x86_mce *mce);
107 #endif
110 * \brief Create new KVM context
112 * This creates a new kvm_context. A KVM context is a small area of data that
113 * holds information about the KVM instance that gets created by this call.\n
114 * This should always be your first call to KVM.
116 * \param opaque Not used
117 * \return NULL on failure
119 int kvm_init(int smp_cpus);
122 * \brief Disable the in-kernel IRQCHIP creation
124 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
125 * this should be called prior to kvm_create().
127 * \param kvm Pointer to the kvm_context
129 void kvm_disable_irqchip_creation(kvm_context_t kvm);
132 * \brief Disable the in-kernel PIT creation
134 * In-kernel pit is enabled by default. If userspace pit is to be used,
135 * this should be called prior to kvm_create().
137 * \param kvm Pointer to the kvm_context
139 void kvm_disable_pit_creation(kvm_context_t kvm);
142 * \brief Create new virtual machine
144 * This creates a new virtual machine, maps physical RAM to it, and creates a
145 * virtual CPU for it.\n
146 * \n
147 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
149 * \param kvm Pointer to the current kvm_context
150 * \param phys_mem_bytes The amount of physical ram you want the VM to have
151 * \param phys_mem This pointer will be set to point to the memory that
152 * kvm_create allocates for physical RAM
153 * \return 0 on success
155 int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
156 void **phys_mem);
157 int kvm_create_vm(kvm_context_t kvm);
158 void kvm_create_irqchip(kvm_context_t kvm);
161 * \brief Start the VCPU
163 * This starts the VCPU and virtualization is started.\n
164 * \n
165 * This function will not return until any of these conditions are met:
166 * - An IO/MMIO handler does not return "0"
167 * - An exception that neither the guest OS, nor KVM can handle occurs
169 * \note This function will call the callbacks registered in kvm_init()
170 * to emulate those functions
171 * \note If you at any point want to interrupt the VCPU, kvm_run() will
172 * listen to the EINTR signal. This allows you to simulate external interrupts
173 * and asyncronous IO.
175 * \param kvm Pointer to the current kvm_context
176 * \param vcpu Which virtual CPU should be started
177 * \return 0 on success, but you really shouldn't expect this function to
178 * return except for when an error has occured, or when you have sent it
179 * an EINTR signal.
181 int kvm_run(CPUState *env);
184 * \brief Check if a vcpu is ready for interrupt injection
186 * This checks if vcpu interrupts are not masked by mov ss or sti.
188 * \param kvm Pointer to the current kvm_context
189 * \param vcpu Which virtual CPU should get dumped
190 * \return boolean indicating interrupt injection readiness
192 int kvm_is_ready_for_interrupt_injection(CPUState *env);
195 * \brief Read VCPU registers
197 * This gets the GP registers from the VCPU and outputs them
198 * into a kvm_regs structure
200 * \note This function returns a \b copy of the VCPUs registers.\n
201 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
203 * \param kvm Pointer to the current kvm_context
204 * \param vcpu Which virtual CPU should get dumped
205 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
206 * registers values
207 * \return 0 on success
209 int kvm_get_regs(CPUState *env, struct kvm_regs *regs);
212 * \brief Write VCPU registers
214 * This sets the GP registers on the VCPU from a kvm_regs structure
216 * \note When this function returns, the regs pointer and the data it points to
217 * can be discarded
218 * \param kvm Pointer to the current kvm_context
219 * \param vcpu Which virtual CPU should get dumped
220 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
221 * registers values
222 * \return 0 on success
224 int kvm_set_regs(CPUState *env, struct kvm_regs *regs);
226 * \brief Read VCPU fpu registers
228 * This gets the FPU registers from the VCPU and outputs them
229 * into a kvm_fpu structure
231 * \note This function returns a \b copy of the VCPUs registers.\n
232 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
234 * \param kvm Pointer to the current kvm_context
235 * \param vcpu Which virtual CPU should get dumped
236 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
237 * fpu registers values
238 * \return 0 on success
240 int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu);
243 * \brief Write VCPU fpu registers
245 * This sets the FPU registers on the VCPU from a kvm_fpu structure
247 * \note When this function returns, the fpu pointer and the data it points to
248 * can be discarded
249 * \param kvm Pointer to the current kvm_context
250 * \param vcpu Which virtual CPU should get dumped
251 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
252 * \return 0 on success
254 int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu);
257 * \brief Read VCPU system registers
259 * This gets the non-GP registers from the VCPU and outputs them
260 * into a kvm_sregs structure
262 * \note This function returns a \b copy of the VCPUs registers.\n
263 * If you wish to modify the VCPUs non-GP registers, you should call
264 * kvm_set_sregs()
266 * \param kvm Pointer to the current kvm_context
267 * \param vcpu Which virtual CPU should get dumped
268 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
269 * registers values
270 * \return 0 on success
272 int kvm_get_sregs(CPUState *env, struct kvm_sregs *regs);
275 * \brief Write VCPU system registers
277 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
279 * \note When this function returns, the regs pointer and the data it points to
280 * can be discarded
281 * \param kvm Pointer to the current kvm_context
282 * \param vcpu Which virtual CPU should get dumped
283 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
284 * registers values
285 * \return 0 on success
287 int kvm_set_sregs(CPUState *env, struct kvm_sregs *regs);
289 #ifdef KVM_CAP_MP_STATE
291 * * \brief Read VCPU MP state
294 int kvm_get_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
297 * * \brief Write VCPU MP state
300 int kvm_set_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
301 #endif
303 #ifdef KVM_CAP_XSAVE
305 * * \brief Read VCPU xsave state
308 int kvm_get_xsave(CPUState *env, struct kvm_xsave *xsave);
311 * * \brief Write VCPU xsave state
314 int kvm_set_xsave(CPUState *env, struct kvm_xsave *xsave);
315 #endif
317 #ifdef KVM_CAP_XCRS
319 * * \brief Read VCPU XCRs
322 int kvm_get_xcrs(CPUState *env, struct kvm_xcrs *xcrs);
325 * * \brief Write VCPU XCRs
328 int kvm_set_xcrs(CPUState *env, struct kvm_xcrs *xcrs);
329 #endif
332 * \brief Simulate an external vectored interrupt
334 * This allows you to simulate an external vectored interrupt.
336 * \param kvm Pointer to the current kvm_context
337 * \param vcpu Which virtual CPU should get dumped
338 * \param irq Vector number
339 * \return 0 on success
341 int kvm_inject_irq(CPUState *env, unsigned irq);
343 #if defined(__i386__) || defined(__x86_64__)
345 * \brief Setup a vcpu's cpuid instruction emulation
347 * Set up a table of cpuid function to cpuid outputs.\n
349 * \param kvm Pointer to the current kvm_context
350 * \param vcpu Which virtual CPU should be initialized
351 * \param nent number of entries to be installed
352 * \param entries cpuid function entries table
353 * \return 0 on success, or -errno on error
355 int kvm_setup_cpuid(CPUState *env, int nent,
356 struct kvm_cpuid_entry *entries);
359 * \brief Setup a vcpu's cpuid instruction emulation
361 * Set up a table of cpuid function to cpuid outputs.
362 * This call replaces the older kvm_setup_cpuid interface by adding a few
363 * parameters to support cpuid functions that have sub-leaf values.
365 * \param kvm Pointer to the current kvm_context
366 * \param vcpu Which virtual CPU should be initialized
367 * \param nent number of entries to be installed
368 * \param entries cpuid function entries table
369 * \return 0 on success, or -errno on error
371 int kvm_setup_cpuid2(CPUState *env, int nent,
372 struct kvm_cpuid_entry2 *entries);
375 * \brief Setting the number of shadow pages to be allocated to the vm
377 * \param kvm pointer to kvm_context
378 * \param nrshadow_pages number of pages to be allocated
380 int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
383 * \brief Getting the number of shadow pages that are allocated to the vm
385 * \param kvm pointer to kvm_context
386 * \param nrshadow_pages number of pages to be allocated
388 int kvm_get_shadow_pages(kvm_context_t kvm, unsigned int *nrshadow_pages);
390 #endif
393 * \brief Dump VCPU registers
395 * This dumps some of the information that KVM has about a virtual CPU, namely:
396 * - GP Registers
398 * A much more verbose version of this is available as kvm_dump_vcpu()
400 * \param kvm Pointer to the current kvm_context
401 * \param vcpu Which virtual CPU should get dumped
402 * \return 0 on success
404 void kvm_show_regs(CPUState *env);
407 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start,
408 unsigned long len, int log, int writable);
409 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
410 unsigned long len);
412 int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start,
413 unsigned long size);
414 int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start,
415 void *userspace_addr, unsigned long len, int log);
416 int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr,
417 unsigned long end_addr, void *opaque,
418 int (*cb)(unsigned long start,
419 unsigned long len, void *bitmap,
420 void *opaque));
421 int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
422 uint32_t size);
423 int kvm_unregister_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
424 uint32_t size);
427 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
429 * \param kvm Pointer to the current kvm_context
430 * \param phys_addr Memory slot phys addr
431 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
433 int kvm_get_mem_map(kvm_context_t kvm, unsigned long phys_addr, void *bitmap);
434 int kvm_get_mem_map_range(kvm_context_t kvm, unsigned long phys_addr,
435 unsigned long len, void *buf, void *opaque,
436 int (*cb)(unsigned long start,
437 unsigned long len, void *bitmap,
438 void *opaque));
439 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
441 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm, uint64_t phys_start,
442 uint64_t len);
443 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm, uint64_t phys_start,
444 uint64_t len);
446 * \brief Enable dirty-pages-logging for all memory regions
448 * \param kvm Pointer to the current kvm_context
450 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
453 * \brief Disable dirty-page-logging for some memory regions
455 * Disable dirty-pages-logging for those memory regions that were
456 * created with dirty-page-logging disabled.
458 * \param kvm Pointer to the current kvm_context
460 int kvm_dirty_pages_log_reset(kvm_context_t kvm);
462 #ifdef KVM_CAP_IRQCHIP
464 * \brief Dump in kernel IRQCHIP contents
466 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
467 * and IOAPIC into a kvm_irqchip structure
469 * \param kvm Pointer to the current kvm_context
470 * \param chip The irq chip device to be dumped
472 int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
475 * \brief Set in kernel IRQCHIP contents
477 * Write one of the in kernel irq chip devices, including PIC (master/slave)
478 * and IOAPIC
481 * \param kvm Pointer to the current kvm_context
482 * \param chip THe irq chip device to be written
484 int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
486 #if defined(__i386__) || defined(__x86_64__)
488 * \brief Get in kernel local APIC for vcpu
490 * Save the local apic state including the timer of a virtual CPU
492 * \param kvm Pointer to the current kvm_context
493 * \param vcpu Which virtual CPU should be accessed
494 * \param s Local apic state of the specific virtual CPU
496 int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
499 * \brief Set in kernel local APIC for vcpu
501 * Restore the local apic state including the timer of a virtual CPU
503 * \param kvm Pointer to the current kvm_context
504 * \param vcpu Which virtual CPU should be accessed
505 * \param s Local apic state of the specific virtual CPU
507 int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
509 #endif
512 * \brief Simulate an NMI
514 * This allows you to simulate a non-maskable interrupt.
516 * \param kvm Pointer to the current kvm_context
517 * \param vcpu Which virtual CPU should get dumped
518 * \return 0 on success
520 int kvm_inject_nmi(CPUState *env);
522 #endif
525 * \brief Simulate an x86 MCE
527 * This allows you to simulate a x86 MCE.
529 * \param cenv Which virtual CPU should get MCE injected
530 * \param bank Bank number
531 * \param status MSR_MCI_STATUS
532 * \param mcg_status MSR_MCG_STATUS
533 * \param addr MSR_MCI_ADDR
534 * \param misc MSR_MCI_MISC
535 * \param abort_on_error abort on error
537 void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
538 uint64_t mcg_status, uint64_t addr, uint64_t misc,
539 int abort_on_error);
542 * \brief Initialize coalesced MMIO
544 * Check for coalesced MMIO capability and store in context
546 * \param kvm Pointer to the current kvm_context
548 int kvm_init_coalesced_mmio(kvm_context_t kvm);
550 #ifdef KVM_CAP_PIT
552 #if defined(__i386__) || defined(__x86_64__)
554 * \brief Get in kernel PIT of the virtual domain
556 * Save the PIT state.
558 * \param kvm Pointer to the current kvm_context
559 * \param s PIT state of the virtual domain
561 int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);
564 * \brief Set in kernel PIT of the virtual domain
566 * Restore the PIT state.
567 * Timer would be retriggerred after restored.
569 * \param kvm Pointer to the current kvm_context
570 * \param s PIT state of the virtual domain
572 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
574 int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
576 #ifdef KVM_CAP_PIT_STATE2
578 * \brief Check for kvm support of kvm_pit_state2
580 * \param kvm Pointer to the current kvm_context
581 * \return 0 on success
583 int kvm_has_pit_state2(kvm_context_t kvm);
586 * \brief Set in kernel PIT state2 of the virtual domain
589 * \param kvm Pointer to the current kvm_context
590 * \param ps2 PIT state2 of the virtual domain
591 * \return 0 on success
593 int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
596 * \brief Get in kernel PIT state2 of the virtual domain
599 * \param kvm Pointer to the current kvm_context
600 * \param ps2 PIT state2 of the virtual domain
601 * \return 0 on success
603 int kvm_get_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
605 #endif
606 #endif
607 #endif
609 #ifdef KVM_CAP_VAPIC
611 int kvm_enable_vapic(CPUState *env, uint64_t vapic);
613 #endif
615 #if defined(__s390__)
616 int kvm_s390_initial_reset(kvm_context_t kvm, int slot);
617 int kvm_s390_interrupt(kvm_context_t kvm, int slot,
618 struct kvm_s390_interrupt *kvmint);
619 int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw);
620 int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr);
621 #endif
623 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
625 * \brief Notifies host kernel about a PCI device to be assigned to a guest
627 * Used for PCI device assignment, this function notifies the host
628 * kernel about the assigning of the physical PCI device to a guest.
630 * \param kvm Pointer to the current kvm_context
631 * \param assigned_dev Parameters, like bus, devfn number, etc
633 int kvm_assign_pci_device(kvm_context_t kvm,
634 struct kvm_assigned_pci_dev *assigned_dev);
637 * \brief Assign IRQ for an assigned device
639 * Used for PCI device assignment, this function assigns IRQ numbers for
640 * an physical device and guest IRQ handling.
642 * \param kvm Pointer to the current kvm_context
643 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
645 int kvm_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
647 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
649 * \brief Deassign IRQ for an assigned device
651 * Used for PCI device assignment, this function deassigns IRQ numbers
652 * for an assigned device.
654 * \param kvm Pointer to the current kvm_context
655 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
657 int kvm_deassign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
658 #endif
659 #endif
661 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
663 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
665 * Used for hot remove PCI device, this function notifies the host
666 * kernel about the deassigning of the physical PCI device from a guest.
668 * \param kvm Pointer to the current kvm_context
669 * \param assigned_dev Parameters, like bus, devfn number, etc
671 int kvm_deassign_pci_device(kvm_context_t kvm,
672 struct kvm_assigned_pci_dev *assigned_dev);
673 #endif
676 * \brief Checks whether the generic irq routing capability is present
678 * Checks whether kvm can reroute interrupts among the various interrupt
679 * controllers.
681 * \param kvm Pointer to the current kvm_context
683 int kvm_has_gsi_routing(kvm_context_t kvm);
686 * \brief Determines the number of gsis that can be routed
688 * Returns the number of distinct gsis that can be routed by kvm. This is
689 * also the number of distinct routes (if a gsi has two routes, than another
690 * gsi cannot be used...)
692 * \param kvm Pointer to the current kvm_context
694 int kvm_get_gsi_count(kvm_context_t kvm);
697 * \brief Clears the temporary irq routing table
699 * Clears the temporary irq routing table. Nothing is committed to the
700 * running VM.
702 * \param kvm Pointer to the current kvm_context
704 int kvm_clear_gsi_routes(kvm_context_t kvm);
707 * \brief Adds an irq route to the temporary irq routing table
709 * Adds an irq route to the temporary irq routing table. Nothing is
710 * committed to the running VM.
712 * \param kvm Pointer to the current kvm_context
714 int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
717 * \brief Removes an irq route from the temporary irq routing table
719 * Adds an irq route to the temporary irq routing table. Nothing is
720 * committed to the running VM.
722 * \param kvm Pointer to the current kvm_context
724 int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
726 struct kvm_irq_routing_entry;
728 * \brief Adds a routing entry to the temporary irq routing table
730 * Adds a filled routing entry to the temporary irq routing table. Nothing is
731 * committed to the running VM.
733 * \param kvm Pointer to the current kvm_context
735 int kvm_add_routing_entry(kvm_context_t kvm,
736 struct kvm_irq_routing_entry *entry);
739 * \brief Removes a routing from the temporary irq routing table
741 * Remove a routing to the temporary irq routing table. Nothing is
742 * committed to the running VM.
744 * \param kvm Pointer to the current kvm_context
746 int kvm_del_routing_entry(kvm_context_t kvm,
747 struct kvm_irq_routing_entry *entry);
750 * \brief Updates a routing in the temporary irq routing table
752 * Update a routing in the temporary irq routing table
753 * with a new value. entry type and GSI can not be changed.
754 * Nothing is committed to the running VM.
756 * \param kvm Pointer to the current kvm_context
758 int kvm_update_routing_entry(kvm_context_t kvm,
759 struct kvm_irq_routing_entry *entry,
760 struct kvm_irq_routing_entry *newentry);
763 * \brief Commit the temporary irq routing table
765 * Commit the temporary irq routing table to the running VM.
767 * \param kvm Pointer to the current kvm_context
769 int kvm_commit_irq_routes(kvm_context_t kvm);
772 * \brief Get unused GSI number for irq routing table
774 * Get unused GSI number for irq routing table
776 * \param kvm Pointer to the current kvm_context
778 int kvm_get_irq_route_gsi(kvm_context_t kvm);
781 * \brief Create a file descriptor for injecting interrupts
783 * Creates an eventfd based file-descriptor that maps to a specific GSI
784 * in the guest. eventfd compliant signaling (write() from userspace, or
785 * eventfd_signal() from kernelspace) will cause the GSI to inject
786 * itself into the guest at the next available window.
788 * \param kvm Pointer to the current kvm_context
789 * \param gsi GSI to assign to this fd
790 * \param flags reserved, must be zero
792 int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
794 #ifdef KVM_CAP_DEVICE_MSIX
795 int kvm_assign_set_msix_nr(kvm_context_t kvm,
796 struct kvm_assigned_msix_nr *msix_nr);
797 int kvm_assign_set_msix_entry(kvm_context_t kvm,
798 struct kvm_assigned_msix_entry *entry);
799 #endif
801 #else /* !CONFIG_KVM */
803 typedef struct kvm_context *kvm_context_t;
804 typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
806 struct kvm_pit_state {
809 static inline int kvm_init(int smp_cpus)
811 return 0;
814 static inline void kvm_inject_x86_mce(CPUState *cenv, int bank,
815 uint64_t status, uint64_t mcg_status,
816 uint64_t addr, uint64_t misc,
817 int abort_on_error)
819 if (abort_on_error)
820 abort();
823 #endif /* !CONFIG_KVM */
826 int kvm_main_loop(void);
827 int kvm_init_ap(void);
828 int kvm_vcpu_inited(CPUState *env);
829 void kvm_save_lapic(CPUState *env);
830 void kvm_load_lapic(CPUState *env);
832 void kvm_hpet_enable_kpit(void);
833 void kvm_hpet_disable_kpit(void);
834 int kvm_set_irq(int irq, int level, int *status);
836 int kvm_physical_memory_set_dirty_tracking(int enable);
838 void qemu_kvm_call_with_env(void (*func)(void *), void *data, CPUState *env);
839 void qemu_kvm_cpuid_on_env(CPUState *env);
840 void kvm_inject_interrupt(CPUState *env, int mask);
841 void kvm_update_after_sipi(CPUState *env);
842 void kvm_update_interrupt_request(CPUState *env);
843 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, unsigned long size,
844 int log, int writable);
846 void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr,
847 unsigned long size);
848 void kvm_qemu_log_memory(target_phys_addr_t start, target_phys_addr_t size,
849 int log);
850 int kvm_qemu_create_memory_alias(uint64_t phys_start, uint64_t len,
851 uint64_t target_phys);
852 int kvm_qemu_destroy_memory_alias(uint64_t phys_start);
854 int kvm_arch_qemu_create_context(void);
856 void kvm_arch_save_regs(CPUState *env);
857 void kvm_arch_load_regs(CPUState *env, int level);
858 int kvm_arch_has_work(CPUState *env);
859 void kvm_arch_process_irqchip_events(CPUState *env);
860 int kvm_arch_try_push_interrupts(void *opaque);
861 void kvm_arch_push_nmi(void *opaque);
862 void kvm_arch_cpu_reset(CPUState *env);
863 int kvm_set_boot_cpu_id(uint32_t id);
865 void qemu_kvm_aio_wait_start(void);
866 void qemu_kvm_aio_wait(void);
867 void qemu_kvm_aio_wait_end(void);
869 void qemu_kvm_notify_work(void);
871 void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
873 int kvm_arch_init_irq_routing(void);
875 int kvm_mmio_read(void *opaque, uint64_t addr, uint8_t * data, int len);
876 int kvm_mmio_write(void *opaque, uint64_t addr, uint8_t * data, int len);
878 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
879 struct ioperm_data;
881 void kvm_ioperm(CPUState *env, void *data);
882 void kvm_add_ioperm_data(struct ioperm_data *data);
883 void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
884 void kvm_arch_do_ioperm(void *_data);
885 #endif
887 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
888 #define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
890 #ifdef CONFIG_KVM
891 #include "qemu-queue.h"
893 extern int kvm_irqchip;
894 extern int kvm_pit;
895 extern int kvm_pit_reinject;
896 extern int kvm_nested;
897 extern kvm_context_t kvm_context;
899 struct ioperm_data {
900 unsigned long start_port;
901 unsigned long num;
902 int turn_on;
903 QLIST_ENTRY(ioperm_data) entries;
906 void qemu_kvm_cpu_stop(CPUState *env);
907 int kvm_arch_halt(CPUState *env);
908 int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
909 int is_write);
911 #define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing(kvm_context)
912 #ifdef TARGET_I386
913 #define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
914 #endif
915 #else
916 #define kvm_nested 0
917 #define qemu_kvm_has_gsi_routing() (0)
918 #ifdef TARGET_I386
919 #define qemu_kvm_has_pit_state2() (0)
920 #endif
921 #define qemu_kvm_cpu_stop(env) do {} while(0)
922 #endif
924 void kvm_mutex_unlock(void);
925 void kvm_mutex_lock(void);
927 static inline int kvm_sync_vcpus(void)
929 return 0;
932 #ifdef CONFIG_KVM
934 typedef struct KVMSlot {
935 target_phys_addr_t start_addr;
936 ram_addr_t memory_size;
937 ram_addr_t phys_offset;
938 int slot;
939 int flags;
940 } KVMSlot;
942 typedef struct kvm_dirty_log KVMDirtyLog;
944 struct KVMState {
945 KVMSlot slots[32];
946 int fd;
947 int vmfd;
948 int coalesced_mmio;
949 #ifdef KVM_CAP_COALESCED_MMIO
950 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
951 #endif
952 int broken_set_mem_region;
953 int migration_log;
954 int vcpu_events;
955 int robust_singlestep;
956 int debugregs;
957 #ifdef KVM_CAP_SET_GUEST_DEBUG
958 QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints;
959 #endif
960 int irqchip_in_kernel;
961 int pit_in_kernel;
963 struct kvm_context kvm_context;
966 extern struct KVMState *kvm_state;
968 int kvm_tpr_enable_vapic(CPUState *env);
970 unsigned long kvm_get_thread_id(void);
971 int kvm_cpu_is_stopped(CPUState *env);
973 #endif
975 #endif