Fold libkvm-common.h into libkvm-all.h
[qemu-kvm/fedora.git] / libkvm-all.h
blob03b98df483d6eee65523877727a29cf88ecb8bf9
1 /** \file libkvm.h
2 * libkvm API
3 */
5 #ifndef LIBKVM_H
6 #define LIBKVM_H
8 #if defined(__s390__)
9 #include <asm/ptrace.h>
10 #endif
12 #include <stdint.h>
14 #ifndef __user
15 #define __user /* temporary, until installed via make headers_install */
16 #endif
18 #include <linux/kvm.h>
20 #include <signal.h>
22 /* FIXME: share this number with kvm */
23 /* FIXME: or dynamically alloc/realloc regions */
24 #ifdef __s390__
25 #define KVM_MAX_NUM_MEM_REGIONS 1u
26 #define MAX_VCPUS 64
27 #define LIBKVM_S390_ORIGIN (0UL)
28 #elif defined(__ia64__)
29 #define KVM_MAX_NUM_MEM_REGIONS 32u
30 #define MAX_VCPUS 256
31 #else
32 #define KVM_MAX_NUM_MEM_REGIONS 32u
33 #define MAX_VCPUS 16
34 #endif
36 /* kvm abi verison variable */
37 extern int kvm_abi;
39 /**
40 * \brief The KVM context
42 * The verbose KVM context
45 struct kvm_context {
46 /// Filedescriptor to /dev/kvm
47 int fd;
48 int vm_fd;
49 /// Callbacks that KVM uses to emulate various unvirtualizable functionality
50 struct kvm_callbacks *callbacks;
51 void *opaque;
52 /// is dirty pages logging enabled for all regions or not
53 int dirty_pages_log_all;
54 /// do not create in-kernel irqchip if set
55 int no_irqchip_creation;
56 /// in-kernel irqchip status
57 int irqchip_in_kernel;
58 /// ioctl to use to inject interrupts
59 int irqchip_inject_ioctl;
60 /// do not create in-kernel pit if set
61 int no_pit_creation;
62 /// in-kernel pit status
63 int pit_in_kernel;
64 /// in-kernel coalesced mmio
65 int coalesced_mmio;
66 #ifdef KVM_CAP_IRQ_ROUTING
67 struct kvm_irq_routing *irq_routes;
68 int nr_allocated_irq_routes;
69 #endif
70 void *used_gsi_bitmap;
71 int max_gsi;
74 struct kvm_vcpu_context
76 int fd;
77 struct kvm_run *run;
78 struct kvm_context *kvm;
79 uint32_t id;
82 typedef struct kvm_context *kvm_context_t;
83 typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
85 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
86 void **vm_mem);
87 int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
88 void **vm_mem);
90 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
91 void **vm_mem);
92 int kvm_arch_run(kvm_vcpu_context_t vcpu);
95 void kvm_show_code(kvm_vcpu_context_t vcpu);
97 int handle_halt(kvm_vcpu_context_t vcpu);
98 int handle_shutdown(kvm_context_t kvm, void *env);
99 void post_kvm_run(kvm_context_t kvm, void *env);
100 int pre_kvm_run(kvm_context_t kvm, void *env);
101 int handle_io_window(kvm_context_t kvm);
102 int handle_debug(kvm_vcpu_context_t vcpu, void *env);
103 int try_push_interrupts(kvm_context_t kvm);
106 #if defined(__x86_64__) || defined(__i386__)
107 struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
108 int kvm_get_msrs(kvm_vcpu_context_t, struct kvm_msr_entry *msrs, int n);
109 int kvm_set_msrs(kvm_vcpu_context_t, struct kvm_msr_entry *msrs, int n);
110 #endif
113 * \brief KVM callbacks structure
115 * This structure holds pointers to various functions that KVM will call
116 * when it encounters something that cannot be virtualized, such as
117 * accessing hardware devices via MMIO or regular IO.
119 struct kvm_callbacks {
120 /// For 8bit IO reads from the guest (Usually when executing 'inb')
121 int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
122 /// For 16bit IO reads from the guest (Usually when executing 'inw')
123 int (*inw)(void *opaque, uint16_t addr, uint16_t *data);
124 /// For 32bit IO reads from the guest (Usually when executing 'inl')
125 int (*inl)(void *opaque, uint16_t addr, uint32_t *data);
126 /// For 8bit IO writes from the guest (Usually when executing 'outb')
127 int (*outb)(void *opaque, uint16_t addr, uint8_t data);
128 /// For 16bit IO writes from the guest (Usually when executing 'outw')
129 int (*outw)(void *opaque, uint16_t addr, uint16_t data);
130 /// For 32bit IO writes from the guest (Usually when executing 'outl')
131 int (*outl)(void *opaque, uint16_t addr, uint32_t data);
132 /// generic memory reads to unmapped memory (For MMIO devices)
133 int (*mmio_read)(void *opaque, uint64_t addr, uint8_t *data,
134 int len);
135 /// generic memory writes to unmapped memory (For MMIO devices)
136 int (*mmio_write)(void *opaque, uint64_t addr, uint8_t *data,
137 int len);
138 #ifdef KVM_CAP_SET_GUEST_DEBUG
139 int (*debug)(void *opaque, void *env,
140 struct kvm_debug_exit_arch *arch_info);
141 #endif
143 * \brief Called when the VCPU issues an 'hlt' instruction.
145 * Typically, you should yeild here to prevent 100% CPU utilization
146 * on the host CPU.
148 int (*halt)(void *opaque, kvm_vcpu_context_t vcpu);
149 int (*shutdown)(void *opaque, void *env);
150 int (*io_window)(void *opaque);
151 int (*try_push_interrupts)(void *opaque);
152 #ifdef KVM_CAP_USER_NMI
153 void (*push_nmi)(void *opaque);
154 #endif
155 void (*post_kvm_run)(void *opaque, void *env);
156 int (*pre_kvm_run)(void *opaque, void *env);
157 int (*tpr_access)(void *opaque, kvm_vcpu_context_t vcpu, uint64_t rip, int is_write);
158 #if defined(__powerpc__)
159 int (*powerpc_dcr_read)(kvm_vcpu_context_t vcpu, uint32_t dcrn, uint32_t *data);
160 int (*powerpc_dcr_write)(kvm_vcpu_context_t vcpu, uint32_t dcrn, uint32_t data);
161 #endif
162 #if defined(__s390__)
163 int (*s390_handle_intercept)(kvm_context_t context, kvm_vcpu_context_t vcpu,
164 struct kvm_run *run);
165 int (*s390_handle_reset)(kvm_context_t context, kvm_vcpu_context_t vcpu,
166 struct kvm_run *run);
167 #endif
168 int (*unhandled)(kvm_context_t context, kvm_vcpu_context_t vcpu,
169 uint64_t hw_reason);
173 * \brief Create new KVM context
175 * This creates a new kvm_context. A KVM context is a small area of data that
176 * holds information about the KVM instance that gets created by this call.\n
177 * This should always be your first call to KVM.
179 * \param callbacks Pointer to a valid kvm_callbacks structure
180 * \param opaque Not used
181 * \return NULL on failure
183 kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
184 void *opaque);
187 * \brief Cleanup the KVM context
189 * Should always be called when closing down KVM.\n
190 * Exception: If kvm_init() fails, this function should not be called, as the
191 * context would be invalid
193 * \param kvm Pointer to the kvm_context that is to be freed
195 void kvm_finalize(kvm_context_t kvm);
198 * \brief Disable the in-kernel IRQCHIP creation
200 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
201 * this should be called prior to kvm_create().
203 * \param kvm Pointer to the kvm_context
205 void kvm_disable_irqchip_creation(kvm_context_t kvm);
208 * \brief Disable the in-kernel PIT creation
210 * In-kernel pit is enabled by default. If userspace pit is to be used,
211 * this should be called prior to kvm_create().
213 * \param kvm Pointer to the kvm_context
215 void kvm_disable_pit_creation(kvm_context_t kvm);
218 * \brief Create new virtual machine
220 * This creates a new virtual machine, maps physical RAM to it, and creates a
221 * virtual CPU for it.\n
222 * \n
223 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
225 * \param kvm Pointer to the current kvm_context
226 * \param phys_mem_bytes The amount of physical ram you want the VM to have
227 * \param phys_mem This pointer will be set to point to the memory that
228 * kvm_create allocates for physical RAM
229 * \return 0 on success
231 int kvm_create(kvm_context_t kvm,
232 unsigned long phys_mem_bytes,
233 void **phys_mem);
234 int kvm_create_vm(kvm_context_t kvm);
235 int kvm_check_extension(kvm_context_t kvm, int ext);
236 void kvm_create_irqchip(kvm_context_t kvm);
239 * \brief Create a new virtual cpu
241 * This creates a new virtual cpu (the first vcpu is created by kvm_create()).
242 * Should be called from a thread dedicated to the vcpu.
244 * \param kvm kvm context
245 * \param slot vcpu number (> 0)
246 * \return 0 on success, -errno on failure
248 kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id);
251 * \brief Start the VCPU
253 * This starts the VCPU and virtualization is started.\n
254 * \n
255 * This function will not return until any of these conditions are met:
256 * - An IO/MMIO handler does not return "0"
257 * - An exception that neither the guest OS, nor KVM can handle occurs
259 * \note This function will call the callbacks registered in kvm_init()
260 * to emulate those functions
261 * \note If you at any point want to interrupt the VCPU, kvm_run() will
262 * listen to the EINTR signal. This allows you to simulate external interrupts
263 * and asyncronous IO.
265 * \param kvm Pointer to the current kvm_context
266 * \param vcpu Which virtual CPU should be started
267 * \return 0 on success, but you really shouldn't expect this function to
268 * return except for when an error has occured, or when you have sent it
269 * an EINTR signal.
271 int kvm_run(kvm_vcpu_context_t vcpu, void *env);
274 * \brief Get interrupt flag from on last exit to userspace
276 * This gets the CPU interrupt flag as it was on the last exit to userspace.
278 * \param kvm Pointer to the current kvm_context
279 * \param vcpu Which virtual CPU should get dumped
280 * \return interrupt flag value (0 or 1)
282 int kvm_get_interrupt_flag(kvm_vcpu_context_t vcpu);
285 * \brief Get the value of the APIC_BASE msr as of last exit to userspace
287 * This gets the APIC_BASE msr as it was on the last exit to userspace.
289 * \param kvm Pointer to the current kvm_context
290 * \param vcpu Which virtual CPU should get dumped
291 * \return APIC_BASE msr contents
293 uint64_t kvm_get_apic_base(kvm_vcpu_context_t vcpu);
296 * \brief Check if a vcpu is ready for interrupt injection
298 * This checks if vcpu interrupts are not masked by mov ss or sti.
300 * \param kvm Pointer to the current kvm_context
301 * \param vcpu Which virtual CPU should get dumped
302 * \return boolean indicating interrupt injection readiness
304 int kvm_is_ready_for_interrupt_injection(kvm_vcpu_context_t vcpu);
307 * \brief Read VCPU registers
309 * This gets the GP registers from the VCPU and outputs them
310 * into a kvm_regs structure
312 * \note This function returns a \b copy of the VCPUs registers.\n
313 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
315 * \param kvm Pointer to the current kvm_context
316 * \param vcpu Which virtual CPU should get dumped
317 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
318 * registers values
319 * \return 0 on success
321 int kvm_get_regs(kvm_vcpu_context_t vcpu, struct kvm_regs *regs);
324 * \brief Write VCPU registers
326 * This sets the GP registers on the VCPU from a kvm_regs structure
328 * \note When this function returns, the regs pointer and the data it points to
329 * can be discarded
330 * \param kvm Pointer to the current kvm_context
331 * \param vcpu Which virtual CPU should get dumped
332 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
333 * registers values
334 * \return 0 on success
336 int kvm_set_regs(kvm_vcpu_context_t vcpu, struct kvm_regs *regs);
338 * \brief Read VCPU fpu registers
340 * This gets the FPU registers from the VCPU and outputs them
341 * into a kvm_fpu structure
343 * \note This function returns a \b copy of the VCPUs registers.\n
344 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
346 * \param kvm Pointer to the current kvm_context
347 * \param vcpu Which virtual CPU should get dumped
348 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
349 * fpu registers values
350 * \return 0 on success
352 int kvm_get_fpu(kvm_vcpu_context_t vcpu, struct kvm_fpu *fpu);
355 * \brief Write VCPU fpu registers
357 * This sets the FPU registers on the VCPU from a kvm_fpu structure
359 * \note When this function returns, the fpu pointer and the data it points to
360 * can be discarded
361 * \param kvm Pointer to the current kvm_context
362 * \param vcpu Which virtual CPU should get dumped
363 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
364 * \return 0 on success
366 int kvm_set_fpu(kvm_vcpu_context_t vcpu, struct kvm_fpu *fpu);
369 * \brief Read VCPU system registers
371 * This gets the non-GP registers from the VCPU and outputs them
372 * into a kvm_sregs structure
374 * \note This function returns a \b copy of the VCPUs registers.\n
375 * If you wish to modify the VCPUs non-GP registers, you should call
376 * kvm_set_sregs()
378 * \param kvm Pointer to the current kvm_context
379 * \param vcpu Which virtual CPU should get dumped
380 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
381 * registers values
382 * \return 0 on success
384 int kvm_get_sregs(kvm_vcpu_context_t vcpu, struct kvm_sregs *regs);
387 * \brief Write VCPU system registers
389 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
391 * \note When this function returns, the regs pointer and the data it points to
392 * can be discarded
393 * \param kvm Pointer to the current kvm_context
394 * \param vcpu Which virtual CPU should get dumped
395 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
396 * registers values
397 * \return 0 on success
399 int kvm_set_sregs(kvm_vcpu_context_t vcpu, struct kvm_sregs *regs);
401 #ifdef KVM_CAP_MP_STATE
403 * * \brief Read VCPU MP state
406 int kvm_get_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state);
409 * * \brief Write VCPU MP state
412 int kvm_set_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state);
414 * * \brief Reset VCPU MP state
417 static inline int kvm_reset_mpstate(kvm_vcpu_context_t vcpu)
419 struct kvm_mp_state mp_state = {.mp_state = KVM_MP_STATE_UNINITIALIZED};
420 return kvm_set_mpstate(vcpu, &mp_state);
422 #endif
425 * \brief Simulate an external vectored interrupt
427 * This allows you to simulate an external vectored interrupt.
429 * \param kvm Pointer to the current kvm_context
430 * \param vcpu Which virtual CPU should get dumped
431 * \param irq Vector number
432 * \return 0 on success
434 int kvm_inject_irq(kvm_vcpu_context_t vcpu, unsigned irq);
436 #ifdef KVM_CAP_SET_GUEST_DEBUG
437 int kvm_set_guest_debug(kvm_vcpu_context_t, struct kvm_guest_debug *dbg);
438 #endif
440 #if defined(__i386__) || defined(__x86_64__)
442 * \brief Setup a vcpu's cpuid instruction emulation
444 * Set up a table of cpuid function to cpuid outputs.\n
446 * \param kvm Pointer to the current kvm_context
447 * \param vcpu Which virtual CPU should be initialized
448 * \param nent number of entries to be installed
449 * \param entries cpuid function entries table
450 * \return 0 on success, or -errno on error
452 int kvm_setup_cpuid(kvm_vcpu_context_t vcpu, int nent,
453 struct kvm_cpuid_entry *entries);
456 * \brief Setup a vcpu's cpuid instruction emulation
458 * Set up a table of cpuid function to cpuid outputs.
459 * This call replaces the older kvm_setup_cpuid interface by adding a few
460 * parameters to support cpuid functions that have sub-leaf values.
462 * \param kvm Pointer to the current kvm_context
463 * \param vcpu Which virtual CPU should be initialized
464 * \param nent number of entries to be installed
465 * \param entries cpuid function entries table
466 * \return 0 on success, or -errno on error
468 int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu, int nent,
469 struct kvm_cpuid_entry2 *entries);
472 * \brief Setting the number of shadow pages to be allocated to the vm
474 * \param kvm pointer to kvm_context
475 * \param nrshadow_pages number of pages to be allocated
477 int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
480 * \brief Getting the number of shadow pages that are allocated to the vm
482 * \param kvm pointer to kvm_context
483 * \param nrshadow_pages number of pages to be allocated
485 int kvm_get_shadow_pages(kvm_context_t kvm , unsigned int *nrshadow_pages);
488 * \brief Set up cr8 for next time the vcpu is executed
490 * This is a fast setter for cr8, which will be applied when the
491 * vcpu next enters guest mode.
493 * \param kvm Pointer to the current kvm_context
494 * \param vcpu Which virtual CPU should get dumped
495 * \param cr8 next cr8 value
497 void kvm_set_cr8(kvm_vcpu_context_t vcpu, uint64_t cr8);
500 * \brief Get cr8 for sync tpr in qemu apic emulation
502 * This is a getter for cr8, which used to sync with the tpr in qemu
503 * apic emualtion.
505 * \param kvm Pointer to the current kvm_context
506 * \param vcpu Which virtual CPU should get dumped
508 __u64 kvm_get_cr8(kvm_vcpu_context_t vcpu);
509 #endif
512 * \brief Set a vcpu's signal mask for guest mode
514 * A vcpu can have different signals blocked in guest mode and user mode.
515 * This allows guest execution to be interrupted on a signal, without requiring
516 * that the signal be delivered to a signal handler (the signal can be
517 * dequeued using sigwait(2).
519 * \param kvm Pointer to the current kvm_context
520 * \param vcpu Which virtual CPU should be initialized
521 * \param sigset signal mask for guest mode
522 * \return 0 on success, or -errno on error
524 int kvm_set_signal_mask(kvm_vcpu_context_t vcpu, const sigset_t *sigset);
527 * \brief Dump VCPU registers
529 * This dumps some of the information that KVM has about a virtual CPU, namely:
530 * - GP Registers
532 * A much more verbose version of this is available as kvm_dump_vcpu()
534 * \param kvm Pointer to the current kvm_context
535 * \param vcpu Which virtual CPU should get dumped
536 * \return 0 on success
538 void kvm_show_regs(kvm_vcpu_context_t vcpu);
541 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start,
542 unsigned long len, int log, int writable);
543 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
544 unsigned long len);
545 void kvm_unregister_memory_area(kvm_context_t, uint64_t phys_start,
546 unsigned long len);
548 int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start, unsigned long size);
549 int kvm_register_phys_mem(kvm_context_t kvm,
550 unsigned long phys_start, void *userspace_addr,
551 unsigned long len, int log);
552 int kvm_get_dirty_pages(kvm_context_t, unsigned long phys_addr, void *buf);
553 int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr,
554 unsigned long end_addr, void *buf, void*opaque,
555 int (*cb)(unsigned long start, unsigned long len,
556 void*bitmap, void *opaque));
557 int kvm_register_coalesced_mmio(kvm_context_t kvm,
558 uint64_t addr, uint32_t size);
559 int kvm_unregister_coalesced_mmio(kvm_context_t kvm,
560 uint64_t addr, uint32_t size);
563 * \brief Create a memory alias
565 * Aliases a portion of physical memory to another portion. If the guest
566 * accesses the alias region, it will behave exactly as if it accessed
567 * the target memory.
569 int kvm_create_memory_alias(kvm_context_t,
570 uint64_t phys_start, uint64_t len,
571 uint64_t target_phys);
574 * \brief Destroy a memory alias
576 * Removes an alias created with kvm_create_memory_alias().
578 int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_start);
581 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
583 * \param kvm Pointer to the current kvm_context
584 * \param phys_addr Memory slot phys addr
585 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
587 int kvm_get_mem_map(kvm_context_t kvm, unsigned long phys_addr, void *bitmap);
588 int kvm_get_mem_map_range(kvm_context_t kvm, unsigned long phys_addr,
589 unsigned long len, void *buf, void *opaque,
590 int (*cb)(unsigned long start,unsigned long len,
591 void* bitmap, void* opaque));
592 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
594 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm,
595 uint64_t phys_start,
596 uint64_t len);
597 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm,
598 uint64_t phys_start,
599 uint64_t len);
601 * \brief Enable dirty-pages-logging for all memory regions
603 * \param kvm Pointer to the current kvm_context
605 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
608 * \brief Disable dirty-page-logging for some memory regions
610 * Disable dirty-pages-logging for those memory regions that were
611 * created with dirty-page-logging disabled.
613 * \param kvm Pointer to the current kvm_context
615 int kvm_dirty_pages_log_reset(kvm_context_t kvm);
618 * \brief Query whether in kernel irqchip is used
620 * \param kvm Pointer to the current kvm_context
622 int kvm_irqchip_in_kernel(kvm_context_t kvm);
624 int kvm_has_sync_mmu(kvm_context_t kvm);
626 #ifdef KVM_CAP_IRQCHIP
628 * \brief Dump in kernel IRQCHIP contents
630 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
631 * and IOAPIC into a kvm_irqchip structure
633 * \param kvm Pointer to the current kvm_context
634 * \param chip The irq chip device to be dumped
636 int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
639 * \brief Set in kernel IRQCHIP contents
641 * Write one of the in kernel irq chip devices, including PIC (master/slave)
642 * and IOAPIC
645 * \param kvm Pointer to the current kvm_context
646 * \param chip THe irq chip device to be written
648 int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
650 #if defined(__i386__) || defined(__x86_64__)
652 * \brief Get in kernel local APIC for vcpu
654 * Save the local apic state including the timer of a virtual CPU
656 * \param kvm Pointer to the current kvm_context
657 * \param vcpu Which virtual CPU should be accessed
658 * \param s Local apic state of the specific virtual CPU
660 int kvm_get_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s);
663 * \brief Set in kernel local APIC for vcpu
665 * Restore the local apic state including the timer of a virtual CPU
667 * \param kvm Pointer to the current kvm_context
668 * \param vcpu Which virtual CPU should be accessed
669 * \param s Local apic state of the specific virtual CPU
671 int kvm_set_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s);
673 #endif
676 * \brief Simulate an NMI
678 * This allows you to simulate a non-maskable interrupt.
680 * \param kvm Pointer to the current kvm_context
681 * \param vcpu Which virtual CPU should get dumped
682 * \return 0 on success
684 int kvm_inject_nmi(kvm_vcpu_context_t vcpu);
686 #endif
689 * \brief Query wheather in kernel pit is used
691 * \param kvm Pointer to the current kvm_context
693 int kvm_pit_in_kernel(kvm_context_t kvm);
696 * \brief Initialize coalesced MMIO
698 * Check for coalesced MMIO capability and store in context
700 * \param kvm Pointer to the current kvm_context
702 int kvm_init_coalesced_mmio(kvm_context_t kvm);
704 #ifdef KVM_CAP_PIT
706 #if defined(__i386__) || defined(__x86_64__)
708 * \brief Get in kernel PIT of the virtual domain
710 * Save the PIT state.
712 * \param kvm Pointer to the current kvm_context
713 * \param s PIT state of the virtual domain
715 int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);
718 * \brief Set in kernel PIT of the virtual domain
720 * Restore the PIT state.
721 * Timer would be retriggerred after restored.
723 * \param kvm Pointer to the current kvm_context
724 * \param s PIT state of the virtual domain
726 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
727 #endif
729 int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
731 #endif
733 #ifdef KVM_CAP_VAPIC
736 * \brief Enable kernel tpr access reporting
738 * When tpr access reporting is enabled, the kernel will call the
739 * ->tpr_access() callback every time the guest vcpu accesses the tpr.
741 * \param kvm Pointer to the current kvm_context
742 * \param vcpu vcpu to enable tpr access reporting on
744 int kvm_enable_tpr_access_reporting(kvm_vcpu_context_t vcpu);
747 * \brief Disable kernel tpr access reporting
749 * Undoes the effect of kvm_enable_tpr_access_reporting().
751 * \param kvm Pointer to the current kvm_context
752 * \param vcpu vcpu to disable tpr access reporting on
754 int kvm_disable_tpr_access_reporting(kvm_vcpu_context_t vcpu);
756 int kvm_enable_vapic(kvm_vcpu_context_t vcpu, uint64_t vapic);
758 #endif
760 #if defined(__s390__)
761 int kvm_s390_initial_reset(kvm_context_t kvm, int slot);
762 int kvm_s390_interrupt(kvm_context_t kvm, int slot,
763 struct kvm_s390_interrupt *kvmint);
764 int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw);
765 int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr);
766 #endif
768 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
770 * \brief Notifies host kernel about a PCI device to be assigned to a guest
772 * Used for PCI device assignment, this function notifies the host
773 * kernel about the assigning of the physical PCI device to a guest.
775 * \param kvm Pointer to the current kvm_context
776 * \param assigned_dev Parameters, like bus, devfn number, etc
778 int kvm_assign_pci_device(kvm_context_t kvm,
779 struct kvm_assigned_pci_dev *assigned_dev);
782 * \brief Assign IRQ for an assigned device
784 * Used for PCI device assignment, this function assigns IRQ numbers for
785 * an physical device and guest IRQ handling.
787 * \param kvm Pointer to the current kvm_context
788 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
790 int kvm_assign_irq(kvm_context_t kvm,
791 struct kvm_assigned_irq *assigned_irq);
793 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
795 * \brief Deassign IRQ for an assigned device
797 * Used for PCI device assignment, this function deassigns IRQ numbers
798 * for an assigned device.
800 * \param kvm Pointer to the current kvm_context
801 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
803 int kvm_deassign_irq(kvm_context_t kvm,
804 struct kvm_assigned_irq *assigned_irq);
805 #endif
806 #endif
809 * \brief Determines whether destroying memory regions is allowed
811 * KVM before 2.6.29 had a bug when destroying memory regions.
813 * \param kvm Pointer to the current kvm_context
815 int kvm_destroy_memory_region_works(kvm_context_t kvm);
817 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
819 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
821 * Used for hot remove PCI device, this function notifies the host
822 * kernel about the deassigning of the physical PCI device from a guest.
824 * \param kvm Pointer to the current kvm_context
825 * \param assigned_dev Parameters, like bus, devfn number, etc
827 int kvm_deassign_pci_device(kvm_context_t kvm,
828 struct kvm_assigned_pci_dev *assigned_dev);
829 #endif
832 * \brief Checks whether the generic irq routing capability is present
834 * Checks whether kvm can reroute interrupts among the various interrupt
835 * controllers.
837 * \param kvm Pointer to the current kvm_context
839 int kvm_has_gsi_routing(kvm_context_t kvm);
842 * \brief Determines the number of gsis that can be routed
844 * Returns the number of distinct gsis that can be routed by kvm. This is
845 * also the number of distinct routes (if a gsi has two routes, than another
846 * gsi cannot be used...)
848 * \param kvm Pointer to the current kvm_context
850 int kvm_get_gsi_count(kvm_context_t kvm);
853 * \brief Clears the temporary irq routing table
855 * Clears the temporary irq routing table. Nothing is committed to the
856 * running VM.
858 * \param kvm Pointer to the current kvm_context
860 int kvm_clear_gsi_routes(kvm_context_t kvm);
863 * \brief Adds an irq route to the temporary irq routing table
865 * Adds an irq route to the temporary irq routing table. Nothing is
866 * committed to the running VM.
868 * \param kvm Pointer to the current kvm_context
870 int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
873 * \brief Removes an irq route from the temporary irq routing table
875 * Adds an irq route to the temporary irq routing table. Nothing is
876 * committed to the running VM.
878 * \param kvm Pointer to the current kvm_context
880 int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
882 struct kvm_irq_routing_entry;
884 * \brief Adds a routing entry to the temporary irq routing table
886 * Adds a filled routing entry to the temporary irq routing table. Nothing is
887 * committed to the running VM.
889 * \param kvm Pointer to the current kvm_context
891 int kvm_add_routing_entry(kvm_context_t kvm,
892 struct kvm_irq_routing_entry* entry);
895 * \brief Removes a routing from the temporary irq routing table
897 * Remove a routing to the temporary irq routing table. Nothing is
898 * committed to the running VM.
900 * \param kvm Pointer to the current kvm_context
902 int kvm_del_routing_entry(kvm_context_t kvm,
903 struct kvm_irq_routing_entry* entry);
906 * \brief Commit the temporary irq routing table
908 * Commit the temporary irq routing table to the running VM.
910 * \param kvm Pointer to the current kvm_context
912 int kvm_commit_irq_routes(kvm_context_t kvm);
915 * \brief Get unused GSI number for irq routing table
917 * Get unused GSI number for irq routing table
919 * \param kvm Pointer to the current kvm_context
921 int kvm_get_irq_route_gsi(kvm_context_t kvm);
924 * \brief Create a file descriptor for injecting interrupts
926 * Creates an eventfd based file-descriptor that maps to a specific GSI
927 * in the guest. eventfd compliant signaling (write() from userspace, or
928 * eventfd_signal() from kernelspace) will cause the GSI to inject
929 * itself into the guest at the next available window.
931 * \param kvm Pointer to the current kvm_context
932 * \param gsi GSI to assign to this fd
933 * \param flags reserved, must be zero
935 int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
937 #ifdef KVM_CAP_DEVICE_MSIX
938 int kvm_assign_set_msix_nr(kvm_context_t kvm,
939 struct kvm_assigned_msix_nr *msix_nr);
940 int kvm_assign_set_msix_entry(kvm_context_t kvm,
941 struct kvm_assigned_msix_entry *entry);
942 #endif
944 uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg);
946 #endif