Merge branch 'master' of git://git.sv.gnu.org/qemu
[qemu-kvm/markmc.git] / libkvm-all.h
blob2b18c00b9e3c430ba65575a847e590459110253c
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 struct kvm_context;
23 struct kvm_vcpu_context;
25 typedef struct kvm_context *kvm_context_t;
26 typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
28 #if defined(__x86_64__) || defined(__i386__)
29 struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
30 int kvm_get_msrs(kvm_vcpu_context_t, struct kvm_msr_entry *msrs, int n);
31 int kvm_set_msrs(kvm_vcpu_context_t, struct kvm_msr_entry *msrs, int n);
32 #endif
34 /*!
35 * \brief KVM callbacks structure
37 * This structure holds pointers to various functions that KVM will call
38 * when it encounters something that cannot be virtualized, such as
39 * accessing hardware devices via MMIO or regular IO.
41 struct kvm_callbacks {
42 /// For 8bit IO reads from the guest (Usually when executing 'inb')
43 int (*inb)(void *opaque, uint16_t addr, uint8_t *data);
44 /// For 16bit IO reads from the guest (Usually when executing 'inw')
45 int (*inw)(void *opaque, uint16_t addr, uint16_t *data);
46 /// For 32bit IO reads from the guest (Usually when executing 'inl')
47 int (*inl)(void *opaque, uint16_t addr, uint32_t *data);
48 /// For 8bit IO writes from the guest (Usually when executing 'outb')
49 int (*outb)(void *opaque, uint16_t addr, uint8_t data);
50 /// For 16bit IO writes from the guest (Usually when executing 'outw')
51 int (*outw)(void *opaque, uint16_t addr, uint16_t data);
52 /// For 32bit IO writes from the guest (Usually when executing 'outl')
53 int (*outl)(void *opaque, uint16_t addr, uint32_t data);
54 /// generic memory reads to unmapped memory (For MMIO devices)
55 int (*mmio_read)(void *opaque, uint64_t addr, uint8_t *data,
56 int len);
57 /// generic memory writes to unmapped memory (For MMIO devices)
58 int (*mmio_write)(void *opaque, uint64_t addr, uint8_t *data,
59 int len);
60 #ifdef KVM_CAP_SET_GUEST_DEBUG
61 int (*debug)(void *opaque, void *env,
62 struct kvm_debug_exit_arch *arch_info);
63 #endif
64 /*!
65 * \brief Called when the VCPU issues an 'hlt' instruction.
67 * Typically, you should yeild here to prevent 100% CPU utilization
68 * on the host CPU.
70 int (*halt)(void *opaque, kvm_vcpu_context_t vcpu);
71 int (*shutdown)(void *opaque, void *env);
72 int (*io_window)(void *opaque);
73 int (*try_push_interrupts)(void *opaque);
74 #ifdef KVM_CAP_USER_NMI
75 void (*push_nmi)(void *opaque);
76 #endif
77 void (*post_kvm_run)(void *opaque, void *env);
78 int (*pre_kvm_run)(void *opaque, void *env);
79 int (*tpr_access)(void *opaque, kvm_vcpu_context_t vcpu, uint64_t rip, int is_write);
80 #if defined(__powerpc__)
81 int (*powerpc_dcr_read)(kvm_vcpu_context_t vcpu, uint32_t dcrn, uint32_t *data);
82 int (*powerpc_dcr_write)(kvm_vcpu_context_t vcpu, uint32_t dcrn, uint32_t data);
83 #endif
84 #if defined(__s390__)
85 int (*s390_handle_intercept)(kvm_context_t context, kvm_vcpu_context_t vcpu,
86 struct kvm_run *run);
87 int (*s390_handle_reset)(kvm_context_t context, kvm_vcpu_context_t vcpu,
88 struct kvm_run *run);
89 #endif
90 int (*unhandled)(kvm_context_t context, kvm_vcpu_context_t vcpu,
91 uint64_t hw_reason);
94 /*!
95 * \brief Create new KVM context
97 * This creates a new kvm_context. A KVM context is a small area of data that
98 * holds information about the KVM instance that gets created by this call.\n
99 * This should always be your first call to KVM.
101 * \param callbacks Pointer to a valid kvm_callbacks structure
102 * \param opaque Not used
103 * \return NULL on failure
105 kvm_context_t kvm_init(struct kvm_callbacks *callbacks,
106 void *opaque);
109 * \brief Cleanup the KVM context
111 * Should always be called when closing down KVM.\n
112 * Exception: If kvm_init() fails, this function should not be called, as the
113 * context would be invalid
115 * \param kvm Pointer to the kvm_context that is to be freed
117 void kvm_finalize(kvm_context_t kvm);
120 * \brief Disable the in-kernel IRQCHIP creation
122 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
123 * this should be called prior to kvm_create().
125 * \param kvm Pointer to the kvm_context
127 void kvm_disable_irqchip_creation(kvm_context_t kvm);
130 * \brief Disable the in-kernel PIT creation
132 * In-kernel pit is enabled by default. If userspace pit is to be used,
133 * this should be called prior to kvm_create().
135 * \param kvm Pointer to the kvm_context
137 void kvm_disable_pit_creation(kvm_context_t kvm);
140 * \brief Create new virtual machine
142 * This creates a new virtual machine, maps physical RAM to it, and creates a
143 * virtual CPU for it.\n
144 * \n
145 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
147 * \param kvm Pointer to the current kvm_context
148 * \param phys_mem_bytes The amount of physical ram you want the VM to have
149 * \param phys_mem This pointer will be set to point to the memory that
150 * kvm_create allocates for physical RAM
151 * \return 0 on success
153 int kvm_create(kvm_context_t kvm,
154 unsigned long phys_mem_bytes,
155 void **phys_mem);
156 int kvm_create_vm(kvm_context_t kvm);
157 int kvm_check_extension(kvm_context_t kvm, int ext);
158 void kvm_create_irqchip(kvm_context_t kvm);
161 * \brief Create a new virtual cpu
163 * This creates a new virtual cpu (the first vcpu is created by kvm_create()).
164 * Should be called from a thread dedicated to the vcpu.
166 * \param kvm kvm context
167 * \param slot vcpu number (> 0)
168 * \return 0 on success, -errno on failure
170 kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id);
173 * \brief Start the VCPU
175 * This starts the VCPU and virtualization is started.\n
176 * \n
177 * This function will not return until any of these conditions are met:
178 * - An IO/MMIO handler does not return "0"
179 * - An exception that neither the guest OS, nor KVM can handle occurs
181 * \note This function will call the callbacks registered in kvm_init()
182 * to emulate those functions
183 * \note If you at any point want to interrupt the VCPU, kvm_run() will
184 * listen to the EINTR signal. This allows you to simulate external interrupts
185 * and asyncronous IO.
187 * \param kvm Pointer to the current kvm_context
188 * \param vcpu Which virtual CPU should be started
189 * \return 0 on success, but you really shouldn't expect this function to
190 * return except for when an error has occured, or when you have sent it
191 * an EINTR signal.
193 int kvm_run(kvm_vcpu_context_t vcpu, void *env);
196 * \brief Get interrupt flag from on last exit to userspace
198 * This gets the CPU interrupt flag as it was on the last exit to userspace.
200 * \param kvm Pointer to the current kvm_context
201 * \param vcpu Which virtual CPU should get dumped
202 * \return interrupt flag value (0 or 1)
204 int kvm_get_interrupt_flag(kvm_vcpu_context_t vcpu);
207 * \brief Get the value of the APIC_BASE msr as of last exit to userspace
209 * This gets the APIC_BASE msr as it was on the last exit to userspace.
211 * \param kvm Pointer to the current kvm_context
212 * \param vcpu Which virtual CPU should get dumped
213 * \return APIC_BASE msr contents
215 uint64_t kvm_get_apic_base(kvm_vcpu_context_t vcpu);
218 * \brief Check if a vcpu is ready for interrupt injection
220 * This checks if vcpu interrupts are not masked by mov ss or sti.
222 * \param kvm Pointer to the current kvm_context
223 * \param vcpu Which virtual CPU should get dumped
224 * \return boolean indicating interrupt injection readiness
226 int kvm_is_ready_for_interrupt_injection(kvm_vcpu_context_t vcpu);
229 * \brief Read VCPU registers
231 * This gets the GP registers from the VCPU and outputs them
232 * into a kvm_regs structure
234 * \note This function returns a \b copy of the VCPUs registers.\n
235 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
237 * \param kvm Pointer to the current kvm_context
238 * \param vcpu Which virtual CPU should get dumped
239 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
240 * registers values
241 * \return 0 on success
243 int kvm_get_regs(kvm_vcpu_context_t vcpu, struct kvm_regs *regs);
246 * \brief Write VCPU registers
248 * This sets the GP registers on the VCPU from a kvm_regs structure
250 * \note When this function returns, the regs pointer and the data it points to
251 * can be discarded
252 * \param kvm Pointer to the current kvm_context
253 * \param vcpu Which virtual CPU should get dumped
254 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
255 * registers values
256 * \return 0 on success
258 int kvm_set_regs(kvm_vcpu_context_t vcpu, struct kvm_regs *regs);
260 * \brief Read VCPU fpu registers
262 * This gets the FPU registers from the VCPU and outputs them
263 * into a kvm_fpu structure
265 * \note This function returns a \b copy of the VCPUs registers.\n
266 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
268 * \param kvm Pointer to the current kvm_context
269 * \param vcpu Which virtual CPU should get dumped
270 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
271 * fpu registers values
272 * \return 0 on success
274 int kvm_get_fpu(kvm_vcpu_context_t vcpu, struct kvm_fpu *fpu);
277 * \brief Write VCPU fpu registers
279 * This sets the FPU registers on the VCPU from a kvm_fpu structure
281 * \note When this function returns, the fpu pointer and the data it points to
282 * can be discarded
283 * \param kvm Pointer to the current kvm_context
284 * \param vcpu Which virtual CPU should get dumped
285 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
286 * \return 0 on success
288 int kvm_set_fpu(kvm_vcpu_context_t vcpu, struct kvm_fpu *fpu);
291 * \brief Read VCPU system registers
293 * This gets the non-GP registers from the VCPU and outputs them
294 * into a kvm_sregs structure
296 * \note This function returns a \b copy of the VCPUs registers.\n
297 * If you wish to modify the VCPUs non-GP registers, you should call
298 * kvm_set_sregs()
300 * \param kvm Pointer to the current kvm_context
301 * \param vcpu Which virtual CPU should get dumped
302 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
303 * registers values
304 * \return 0 on success
306 int kvm_get_sregs(kvm_vcpu_context_t vcpu, struct kvm_sregs *regs);
309 * \brief Write VCPU system registers
311 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
313 * \note When this function returns, the regs pointer and the data it points to
314 * can be discarded
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_sregs which will be populated with the VCPUs
318 * registers values
319 * \return 0 on success
321 int kvm_set_sregs(kvm_vcpu_context_t vcpu, struct kvm_sregs *regs);
323 #ifdef KVM_CAP_MP_STATE
325 * * \brief Read VCPU MP state
328 int kvm_get_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state);
331 * * \brief Write VCPU MP state
334 int kvm_set_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state);
336 * * \brief Reset VCPU MP state
339 static inline int kvm_reset_mpstate(kvm_vcpu_context_t vcpu)
341 struct kvm_mp_state mp_state = {.mp_state = KVM_MP_STATE_UNINITIALIZED};
342 return kvm_set_mpstate(vcpu, &mp_state);
344 #endif
347 * \brief Simulate an external vectored interrupt
349 * This allows you to simulate an external vectored interrupt.
351 * \param kvm Pointer to the current kvm_context
352 * \param vcpu Which virtual CPU should get dumped
353 * \param irq Vector number
354 * \return 0 on success
356 int kvm_inject_irq(kvm_vcpu_context_t vcpu, unsigned irq);
358 #ifdef KVM_CAP_SET_GUEST_DEBUG
359 int kvm_set_guest_debug(kvm_vcpu_context_t, struct kvm_guest_debug *dbg);
360 #endif
362 #if defined(__i386__) || defined(__x86_64__)
364 * \brief Setup a vcpu's cpuid instruction emulation
366 * Set up a table of cpuid function to cpuid outputs.\n
368 * \param kvm Pointer to the current kvm_context
369 * \param vcpu Which virtual CPU should be initialized
370 * \param nent number of entries to be installed
371 * \param entries cpuid function entries table
372 * \return 0 on success, or -errno on error
374 int kvm_setup_cpuid(kvm_vcpu_context_t vcpu, int nent,
375 struct kvm_cpuid_entry *entries);
378 * \brief Setup a vcpu's cpuid instruction emulation
380 * Set up a table of cpuid function to cpuid outputs.
381 * This call replaces the older kvm_setup_cpuid interface by adding a few
382 * parameters to support cpuid functions that have sub-leaf values.
384 * \param kvm Pointer to the current kvm_context
385 * \param vcpu Which virtual CPU should be initialized
386 * \param nent number of entries to be installed
387 * \param entries cpuid function entries table
388 * \return 0 on success, or -errno on error
390 int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu, int nent,
391 struct kvm_cpuid_entry2 *entries);
394 * \brief Setting the number of shadow pages to be allocated to the vm
396 * \param kvm pointer to kvm_context
397 * \param nrshadow_pages number of pages to be allocated
399 int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
402 * \brief Getting the number of shadow pages that are allocated to the vm
404 * \param kvm pointer to kvm_context
405 * \param nrshadow_pages number of pages to be allocated
407 int kvm_get_shadow_pages(kvm_context_t kvm , unsigned int *nrshadow_pages);
410 * \brief Set up cr8 for next time the vcpu is executed
412 * This is a fast setter for cr8, which will be applied when the
413 * vcpu next enters guest mode.
415 * \param kvm Pointer to the current kvm_context
416 * \param vcpu Which virtual CPU should get dumped
417 * \param cr8 next cr8 value
419 void kvm_set_cr8(kvm_vcpu_context_t vcpu, uint64_t cr8);
422 * \brief Get cr8 for sync tpr in qemu apic emulation
424 * This is a getter for cr8, which used to sync with the tpr in qemu
425 * apic emualtion.
427 * \param kvm Pointer to the current kvm_context
428 * \param vcpu Which virtual CPU should get dumped
430 __u64 kvm_get_cr8(kvm_vcpu_context_t vcpu);
431 #endif
434 * \brief Set a vcpu's signal mask for guest mode
436 * A vcpu can have different signals blocked in guest mode and user mode.
437 * This allows guest execution to be interrupted on a signal, without requiring
438 * that the signal be delivered to a signal handler (the signal can be
439 * dequeued using sigwait(2).
441 * \param kvm Pointer to the current kvm_context
442 * \param vcpu Which virtual CPU should be initialized
443 * \param sigset signal mask for guest mode
444 * \return 0 on success, or -errno on error
446 int kvm_set_signal_mask(kvm_vcpu_context_t vcpu, const sigset_t *sigset);
449 * \brief Dump VCPU registers
451 * This dumps some of the information that KVM has about a virtual CPU, namely:
452 * - GP Registers
454 * A much more verbose version of this is available as kvm_dump_vcpu()
456 * \param kvm Pointer to the current kvm_context
457 * \param vcpu Which virtual CPU should get dumped
458 * \return 0 on success
460 void kvm_show_regs(kvm_vcpu_context_t vcpu);
463 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start,
464 unsigned long len, int log, int writable);
465 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
466 unsigned long len);
467 void kvm_unregister_memory_area(kvm_context_t, uint64_t phys_start,
468 unsigned long len);
470 int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start, unsigned long size);
471 int kvm_register_phys_mem(kvm_context_t kvm,
472 unsigned long phys_start, void *userspace_addr,
473 unsigned long len, int log);
474 int kvm_get_dirty_pages(kvm_context_t, unsigned long phys_addr, void *buf);
475 int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr,
476 unsigned long end_addr, void *buf, void*opaque,
477 int (*cb)(unsigned long start, unsigned long len,
478 void*bitmap, void *opaque));
479 int kvm_register_coalesced_mmio(kvm_context_t kvm,
480 uint64_t addr, uint32_t size);
481 int kvm_unregister_coalesced_mmio(kvm_context_t kvm,
482 uint64_t addr, uint32_t size);
485 * \brief Create a memory alias
487 * Aliases a portion of physical memory to another portion. If the guest
488 * accesses the alias region, it will behave exactly as if it accessed
489 * the target memory.
491 int kvm_create_memory_alias(kvm_context_t,
492 uint64_t phys_start, uint64_t len,
493 uint64_t target_phys);
496 * \brief Destroy a memory alias
498 * Removes an alias created with kvm_create_memory_alias().
500 int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_start);
503 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
505 * \param kvm Pointer to the current kvm_context
506 * \param phys_addr Memory slot phys addr
507 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
509 int kvm_get_mem_map(kvm_context_t kvm, unsigned long phys_addr, void *bitmap);
510 int kvm_get_mem_map_range(kvm_context_t kvm, unsigned long phys_addr,
511 unsigned long len, void *buf, void *opaque,
512 int (*cb)(unsigned long start,unsigned long len,
513 void* bitmap, void* opaque));
514 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
516 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm,
517 uint64_t phys_start,
518 uint64_t len);
519 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm,
520 uint64_t phys_start,
521 uint64_t len);
523 * \brief Enable dirty-pages-logging for all memory regions
525 * \param kvm Pointer to the current kvm_context
527 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
530 * \brief Disable dirty-page-logging for some memory regions
532 * Disable dirty-pages-logging for those memory regions that were
533 * created with dirty-page-logging disabled.
535 * \param kvm Pointer to the current kvm_context
537 int kvm_dirty_pages_log_reset(kvm_context_t kvm);
540 * \brief Query whether in kernel irqchip is used
542 * \param kvm Pointer to the current kvm_context
544 int kvm_irqchip_in_kernel(kvm_context_t kvm);
546 int kvm_has_sync_mmu(kvm_context_t kvm);
548 #ifdef KVM_CAP_IRQCHIP
550 * \brief Dump in kernel IRQCHIP contents
552 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
553 * and IOAPIC into a kvm_irqchip structure
555 * \param kvm Pointer to the current kvm_context
556 * \param chip The irq chip device to be dumped
558 int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
561 * \brief Set in kernel IRQCHIP contents
563 * Write one of the in kernel irq chip devices, including PIC (master/slave)
564 * and IOAPIC
567 * \param kvm Pointer to the current kvm_context
568 * \param chip THe irq chip device to be written
570 int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
572 #if defined(__i386__) || defined(__x86_64__)
574 * \brief Get in kernel local APIC for vcpu
576 * Save the local apic state including the timer of a virtual CPU
578 * \param kvm Pointer to the current kvm_context
579 * \param vcpu Which virtual CPU should be accessed
580 * \param s Local apic state of the specific virtual CPU
582 int kvm_get_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s);
585 * \brief Set in kernel local APIC for vcpu
587 * Restore the local apic state including the timer of a virtual CPU
589 * \param kvm Pointer to the current kvm_context
590 * \param vcpu Which virtual CPU should be accessed
591 * \param s Local apic state of the specific virtual CPU
593 int kvm_set_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s);
595 #endif
598 * \brief Simulate an NMI
600 * This allows you to simulate a non-maskable interrupt.
602 * \param kvm Pointer to the current kvm_context
603 * \param vcpu Which virtual CPU should get dumped
604 * \return 0 on success
606 int kvm_inject_nmi(kvm_vcpu_context_t vcpu);
608 #endif
611 * \brief Query wheather in kernel pit is used
613 * \param kvm Pointer to the current kvm_context
615 int kvm_pit_in_kernel(kvm_context_t kvm);
618 * \brief Initialize coalesced MMIO
620 * Check for coalesced MMIO capability and store in context
622 * \param kvm Pointer to the current kvm_context
624 int kvm_init_coalesced_mmio(kvm_context_t kvm);
626 #ifdef KVM_CAP_PIT
628 #if defined(__i386__) || defined(__x86_64__)
630 * \brief Get in kernel PIT of the virtual domain
632 * Save the PIT state.
634 * \param kvm Pointer to the current kvm_context
635 * \param s PIT state of the virtual domain
637 int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);
640 * \brief Set in kernel PIT of the virtual domain
642 * Restore the PIT state.
643 * Timer would be retriggerred after restored.
645 * \param kvm Pointer to the current kvm_context
646 * \param s PIT state of the virtual domain
648 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
649 #endif
651 int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
653 #endif
655 #ifdef KVM_CAP_VAPIC
658 * \brief Enable kernel tpr access reporting
660 * When tpr access reporting is enabled, the kernel will call the
661 * ->tpr_access() callback every time the guest vcpu accesses the tpr.
663 * \param kvm Pointer to the current kvm_context
664 * \param vcpu vcpu to enable tpr access reporting on
666 int kvm_enable_tpr_access_reporting(kvm_vcpu_context_t vcpu);
669 * \brief Disable kernel tpr access reporting
671 * Undoes the effect of kvm_enable_tpr_access_reporting().
673 * \param kvm Pointer to the current kvm_context
674 * \param vcpu vcpu to disable tpr access reporting on
676 int kvm_disable_tpr_access_reporting(kvm_vcpu_context_t vcpu);
678 int kvm_enable_vapic(kvm_vcpu_context_t vcpu, uint64_t vapic);
680 #endif
682 #if defined(__s390__)
683 int kvm_s390_initial_reset(kvm_context_t kvm, int slot);
684 int kvm_s390_interrupt(kvm_context_t kvm, int slot,
685 struct kvm_s390_interrupt *kvmint);
686 int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw);
687 int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr);
688 #endif
690 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
692 * \brief Notifies host kernel about a PCI device to be assigned to a guest
694 * Used for PCI device assignment, this function notifies the host
695 * kernel about the assigning of the physical PCI device to a guest.
697 * \param kvm Pointer to the current kvm_context
698 * \param assigned_dev Parameters, like bus, devfn number, etc
700 int kvm_assign_pci_device(kvm_context_t kvm,
701 struct kvm_assigned_pci_dev *assigned_dev);
704 * \brief Assign IRQ for an assigned device
706 * Used for PCI device assignment, this function assigns IRQ numbers for
707 * an physical device and guest IRQ handling.
709 * \param kvm Pointer to the current kvm_context
710 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
712 int kvm_assign_irq(kvm_context_t kvm,
713 struct kvm_assigned_irq *assigned_irq);
715 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
717 * \brief Deassign IRQ for an assigned device
719 * Used for PCI device assignment, this function deassigns IRQ numbers
720 * for an assigned device.
722 * \param kvm Pointer to the current kvm_context
723 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
725 int kvm_deassign_irq(kvm_context_t kvm,
726 struct kvm_assigned_irq *assigned_irq);
727 #endif
728 #endif
731 * \brief Determines whether destroying memory regions is allowed
733 * KVM before 2.6.29 had a bug when destroying memory regions.
735 * \param kvm Pointer to the current kvm_context
737 int kvm_destroy_memory_region_works(kvm_context_t kvm);
739 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
741 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
743 * Used for hot remove PCI device, this function notifies the host
744 * kernel about the deassigning of the physical PCI device from a guest.
746 * \param kvm Pointer to the current kvm_context
747 * \param assigned_dev Parameters, like bus, devfn number, etc
749 int kvm_deassign_pci_device(kvm_context_t kvm,
750 struct kvm_assigned_pci_dev *assigned_dev);
751 #endif
754 * \brief Checks whether the generic irq routing capability is present
756 * Checks whether kvm can reroute interrupts among the various interrupt
757 * controllers.
759 * \param kvm Pointer to the current kvm_context
761 int kvm_has_gsi_routing(kvm_context_t kvm);
764 * \brief Determines the number of gsis that can be routed
766 * Returns the number of distinct gsis that can be routed by kvm. This is
767 * also the number of distinct routes (if a gsi has two routes, than another
768 * gsi cannot be used...)
770 * \param kvm Pointer to the current kvm_context
772 int kvm_get_gsi_count(kvm_context_t kvm);
775 * \brief Clears the temporary irq routing table
777 * Clears the temporary irq routing table. Nothing is committed to the
778 * running VM.
780 * \param kvm Pointer to the current kvm_context
782 int kvm_clear_gsi_routes(kvm_context_t kvm);
785 * \brief Adds an irq route to the temporary irq routing table
787 * Adds an irq route to the temporary irq routing table. Nothing is
788 * committed to the running VM.
790 * \param kvm Pointer to the current kvm_context
792 int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
795 * \brief Removes an irq route from the temporary irq routing table
797 * Adds an irq route to the temporary irq routing table. Nothing is
798 * committed to the running VM.
800 * \param kvm Pointer to the current kvm_context
802 int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
804 struct kvm_irq_routing_entry;
806 * \brief Adds a routing entry to the temporary irq routing table
808 * Adds a filled routing entry to the temporary irq routing table. Nothing is
809 * committed to the running VM.
811 * \param kvm Pointer to the current kvm_context
813 int kvm_add_routing_entry(kvm_context_t kvm,
814 struct kvm_irq_routing_entry* entry);
817 * \brief Removes a routing from the temporary irq routing table
819 * Remove a routing to the temporary irq routing table. Nothing is
820 * committed to the running VM.
822 * \param kvm Pointer to the current kvm_context
824 int kvm_del_routing_entry(kvm_context_t kvm,
825 struct kvm_irq_routing_entry* entry);
828 * \brief Commit the temporary irq routing table
830 * Commit the temporary irq routing table to the running VM.
832 * \param kvm Pointer to the current kvm_context
834 int kvm_commit_irq_routes(kvm_context_t kvm);
837 * \brief Get unused GSI number for irq routing table
839 * Get unused GSI number for irq routing table
841 * \param kvm Pointer to the current kvm_context
843 int kvm_get_irq_route_gsi(kvm_context_t kvm);
846 * \brief Create a file descriptor for injecting interrupts
848 * Creates an eventfd based file-descriptor that maps to a specific GSI
849 * in the guest. eventfd compliant signaling (write() from userspace, or
850 * eventfd_signal() from kernelspace) will cause the GSI to inject
851 * itself into the guest at the next available window.
853 * \param kvm Pointer to the current kvm_context
854 * \param gsi GSI to assign to this fd
855 * \param flags reserved, must be zero
857 int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
859 #ifdef KVM_CAP_DEVICE_MSIX
860 int kvm_assign_set_msix_nr(kvm_context_t kvm,
861 struct kvm_assigned_msix_nr *msix_nr);
862 int kvm_assign_set_msix_entry(kvm_context_t kvm,
863 struct kvm_assigned_msix_entry *entry);
864 #endif
866 uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg);
868 #endif