11 #include <asm/ptrace.h>
17 #define __user /* temporary, until installed via make headers_install */
20 #include <linux/kvm.h>
24 /* FIXME: share this number with kvm */
25 /* FIXME: or dynamically alloc/realloc regions */
27 #define KVM_MAX_NUM_MEM_REGIONS 1u
29 #define LIBKVM_S390_ORIGIN (0UL)
30 #elif defined(__ia64__)
31 #define KVM_MAX_NUM_MEM_REGIONS 32u
34 #define KVM_MAX_NUM_MEM_REGIONS 32u
38 /* kvm abi verison variable */
42 * \brief The KVM context
44 * The verbose KVM context
48 /// Filedescriptor to /dev/kvm
51 /// Callbacks that KVM uses to emulate various unvirtualizable functionality
52 struct kvm_callbacks
*callbacks
;
54 /// is dirty pages logging enabled for all regions or not
55 int dirty_pages_log_all
;
56 /// do not create in-kernel irqchip if set
57 int no_irqchip_creation
;
58 /// in-kernel irqchip status
59 int irqchip_in_kernel
;
60 /// ioctl to use to inject interrupts
61 int irqchip_inject_ioctl
;
62 /// do not create in-kernel pit if set
64 /// in-kernel pit status
66 /// in-kernel coalesced mmio
68 #ifdef KVM_CAP_IRQ_ROUTING
69 struct kvm_irq_routing
*irq_routes
;
70 int nr_allocated_irq_routes
;
72 void *used_gsi_bitmap
;
76 struct kvm_vcpu_context
80 struct kvm_context
*kvm
;
84 typedef struct kvm_context
*kvm_context_t
;
85 typedef struct kvm_vcpu_context
*kvm_vcpu_context_t
;
88 int kvm_alloc_kernel_memory(kvm_context_t kvm
, unsigned long memory
,
90 int kvm_alloc_userspace_memory(kvm_context_t kvm
, unsigned long memory
,
93 int kvm_arch_create(kvm_context_t kvm
, unsigned long phys_mem_bytes
,
95 int kvm_arch_run(kvm_vcpu_context_t vcpu
);
98 void kvm_show_code(kvm_vcpu_context_t vcpu
);
100 int handle_halt(kvm_vcpu_context_t vcpu
);
101 int handle_shutdown(kvm_context_t kvm
, CPUState
*env
);
102 void post_kvm_run(kvm_context_t kvm
, CPUState
*env
);
103 int pre_kvm_run(kvm_context_t kvm
, CPUState
*env
);
104 int handle_io_window(kvm_context_t kvm
);
105 int handle_debug(kvm_vcpu_context_t vcpu
, void *env
);
106 int try_push_interrupts(kvm_context_t kvm
);
108 #if defined(__x86_64__) || defined(__i386__)
109 struct kvm_msr_list
*kvm_get_msr_list(kvm_context_t
);
110 int kvm_get_msrs(kvm_vcpu_context_t
, struct kvm_msr_entry
*msrs
, int n
);
111 int kvm_set_msrs(kvm_vcpu_context_t
, struct kvm_msr_entry
*msrs
, int n
);
115 * \brief Create new KVM context
117 * This creates a new kvm_context. A KVM context is a small area of data that
118 * holds information about the KVM instance that gets created by this call.\n
119 * This should always be your first call to KVM.
121 * \param opaque Not used
122 * \return NULL on failure
124 kvm_context_t
kvm_init(void *opaque
);
127 * \brief Cleanup the KVM context
129 * Should always be called when closing down KVM.\n
130 * Exception: If kvm_init() fails, this function should not be called, as the
131 * context would be invalid
133 * \param kvm Pointer to the kvm_context that is to be freed
135 void kvm_finalize(kvm_context_t kvm
);
138 * \brief Disable the in-kernel IRQCHIP creation
140 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
141 * this should be called prior to kvm_create().
143 * \param kvm Pointer to the kvm_context
145 void kvm_disable_irqchip_creation(kvm_context_t kvm
);
148 * \brief Disable the in-kernel PIT creation
150 * In-kernel pit is enabled by default. If userspace pit is to be used,
151 * this should be called prior to kvm_create().
153 * \param kvm Pointer to the kvm_context
155 void kvm_disable_pit_creation(kvm_context_t kvm
);
158 * \brief Create new virtual machine
160 * This creates a new virtual machine, maps physical RAM to it, and creates a
161 * virtual CPU for it.\n
163 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
165 * \param kvm Pointer to the current kvm_context
166 * \param phys_mem_bytes The amount of physical ram you want the VM to have
167 * \param phys_mem This pointer will be set to point to the memory that
168 * kvm_create allocates for physical RAM
169 * \return 0 on success
171 int kvm_create(kvm_context_t kvm
,
172 unsigned long phys_mem_bytes
,
174 int kvm_create_vm(kvm_context_t kvm
);
175 int kvm_check_extension(kvm_context_t kvm
, int ext
);
176 void kvm_create_irqchip(kvm_context_t kvm
);
179 * \brief Create a new virtual cpu
181 * This creates a new virtual cpu (the first vcpu is created by kvm_create()).
182 * Should be called from a thread dedicated to the vcpu.
184 * \param kvm kvm context
185 * \param slot vcpu number (> 0)
186 * \return 0 on success, -errno on failure
188 kvm_vcpu_context_t
kvm_create_vcpu(kvm_context_t kvm
, int id
);
191 * \brief Start the VCPU
193 * This starts the VCPU and virtualization is started.\n
195 * This function will not return until any of these conditions are met:
196 * - An IO/MMIO handler does not return "0"
197 * - An exception that neither the guest OS, nor KVM can handle occurs
199 * \note This function will call the callbacks registered in kvm_init()
200 * to emulate those functions
201 * \note If you at any point want to interrupt the VCPU, kvm_run() will
202 * listen to the EINTR signal. This allows you to simulate external interrupts
203 * and asyncronous IO.
205 * \param kvm Pointer to the current kvm_context
206 * \param vcpu Which virtual CPU should be started
207 * \return 0 on success, but you really shouldn't expect this function to
208 * return except for when an error has occured, or when you have sent it
211 int kvm_run(kvm_vcpu_context_t vcpu
, void *env
);
214 * \brief Get interrupt flag from on last exit to userspace
216 * This gets the CPU interrupt flag as it was on the last exit to userspace.
218 * \param kvm Pointer to the current kvm_context
219 * \param vcpu Which virtual CPU should get dumped
220 * \return interrupt flag value (0 or 1)
222 int kvm_get_interrupt_flag(kvm_vcpu_context_t vcpu
);
225 * \brief Get the value of the APIC_BASE msr as of last exit to userspace
227 * This gets the APIC_BASE msr as it was on the last exit to userspace.
229 * \param kvm Pointer to the current kvm_context
230 * \param vcpu Which virtual CPU should get dumped
231 * \return APIC_BASE msr contents
233 uint64_t kvm_get_apic_base(kvm_vcpu_context_t vcpu
);
236 * \brief Check if a vcpu is ready for interrupt injection
238 * This checks if vcpu interrupts are not masked by mov ss or sti.
240 * \param kvm Pointer to the current kvm_context
241 * \param vcpu Which virtual CPU should get dumped
242 * \return boolean indicating interrupt injection readiness
244 int kvm_is_ready_for_interrupt_injection(kvm_vcpu_context_t vcpu
);
247 * \brief Read VCPU registers
249 * This gets the GP registers from the VCPU and outputs them
250 * into a kvm_regs structure
252 * \note This function returns a \b copy of the VCPUs registers.\n
253 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
255 * \param kvm Pointer to the current kvm_context
256 * \param vcpu Which virtual CPU should get dumped
257 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
259 * \return 0 on success
261 int kvm_get_regs(kvm_vcpu_context_t vcpu
, struct kvm_regs
*regs
);
264 * \brief Write VCPU registers
266 * This sets the GP registers on the VCPU from a kvm_regs structure
268 * \note When this function returns, the regs pointer and the data it points to
270 * \param kvm Pointer to the current kvm_context
271 * \param vcpu Which virtual CPU should get dumped
272 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
274 * \return 0 on success
276 int kvm_set_regs(kvm_vcpu_context_t vcpu
, struct kvm_regs
*regs
);
278 * \brief Read VCPU fpu registers
280 * This gets the FPU registers from the VCPU and outputs them
281 * into a kvm_fpu structure
283 * \note This function returns a \b copy of the VCPUs registers.\n
284 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
286 * \param kvm Pointer to the current kvm_context
287 * \param vcpu Which virtual CPU should get dumped
288 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
289 * fpu registers values
290 * \return 0 on success
292 int kvm_get_fpu(kvm_vcpu_context_t vcpu
, struct kvm_fpu
*fpu
);
295 * \brief Write VCPU fpu registers
297 * This sets the FPU registers on the VCPU from a kvm_fpu structure
299 * \note When this function returns, the fpu pointer and the data it points to
301 * \param kvm Pointer to the current kvm_context
302 * \param vcpu Which virtual CPU should get dumped
303 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
304 * \return 0 on success
306 int kvm_set_fpu(kvm_vcpu_context_t vcpu
, struct kvm_fpu
*fpu
);
309 * \brief Read VCPU system registers
311 * This gets the non-GP registers from the VCPU and outputs them
312 * into a kvm_sregs structure
314 * \note This function returns a \b copy of the VCPUs registers.\n
315 * If you wish to modify the VCPUs non-GP registers, you should call
318 * \param kvm Pointer to the current kvm_context
319 * \param vcpu Which virtual CPU should get dumped
320 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
322 * \return 0 on success
324 int kvm_get_sregs(kvm_vcpu_context_t vcpu
, struct kvm_sregs
*regs
);
327 * \brief Write VCPU system registers
329 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
331 * \note When this function returns, the regs pointer and the data it points to
333 * \param kvm Pointer to the current kvm_context
334 * \param vcpu Which virtual CPU should get dumped
335 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
337 * \return 0 on success
339 int kvm_set_sregs(kvm_vcpu_context_t vcpu
, struct kvm_sregs
*regs
);
341 #ifdef KVM_CAP_MP_STATE
343 * * \brief Read VCPU MP state
346 int kvm_get_mpstate(kvm_vcpu_context_t vcpu
, struct kvm_mp_state
*mp_state
);
349 * * \brief Write VCPU MP state
352 int kvm_set_mpstate(kvm_vcpu_context_t vcpu
, struct kvm_mp_state
*mp_state
);
354 * * \brief Reset VCPU MP state
357 static inline int kvm_reset_mpstate(kvm_vcpu_context_t vcpu
)
359 struct kvm_mp_state mp_state
= {.mp_state
= KVM_MP_STATE_UNINITIALIZED
};
360 return kvm_set_mpstate(vcpu
, &mp_state
);
365 * \brief Simulate an external vectored interrupt
367 * This allows you to simulate an external vectored interrupt.
369 * \param kvm Pointer to the current kvm_context
370 * \param vcpu Which virtual CPU should get dumped
371 * \param irq Vector number
372 * \return 0 on success
374 int kvm_inject_irq(kvm_vcpu_context_t vcpu
, unsigned irq
);
376 #ifdef KVM_CAP_SET_GUEST_DEBUG
377 int kvm_set_guest_debug(kvm_vcpu_context_t
, struct kvm_guest_debug
*dbg
);
380 #if defined(__i386__) || defined(__x86_64__)
382 * \brief Setup a vcpu's cpuid instruction emulation
384 * Set up a table of cpuid function to cpuid outputs.\n
386 * \param kvm Pointer to the current kvm_context
387 * \param vcpu Which virtual CPU should be initialized
388 * \param nent number of entries to be installed
389 * \param entries cpuid function entries table
390 * \return 0 on success, or -errno on error
392 int kvm_setup_cpuid(kvm_vcpu_context_t vcpu
, int nent
,
393 struct kvm_cpuid_entry
*entries
);
396 * \brief Setup a vcpu's cpuid instruction emulation
398 * Set up a table of cpuid function to cpuid outputs.
399 * This call replaces the older kvm_setup_cpuid interface by adding a few
400 * parameters to support cpuid functions that have sub-leaf values.
402 * \param kvm Pointer to the current kvm_context
403 * \param vcpu Which virtual CPU should be initialized
404 * \param nent number of entries to be installed
405 * \param entries cpuid function entries table
406 * \return 0 on success, or -errno on error
408 int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu
, int nent
,
409 struct kvm_cpuid_entry2
*entries
);
412 * \brief Setting the number of shadow pages to be allocated to the vm
414 * \param kvm pointer to kvm_context
415 * \param nrshadow_pages number of pages to be allocated
417 int kvm_set_shadow_pages(kvm_context_t kvm
, unsigned int nrshadow_pages
);
420 * \brief Getting the number of shadow pages that are allocated to the vm
422 * \param kvm pointer to kvm_context
423 * \param nrshadow_pages number of pages to be allocated
425 int kvm_get_shadow_pages(kvm_context_t kvm
, unsigned int *nrshadow_pages
);
428 * \brief Set up cr8 for next time the vcpu is executed
430 * This is a fast setter for cr8, which will be applied when the
431 * vcpu next enters guest mode.
433 * \param kvm Pointer to the current kvm_context
434 * \param vcpu Which virtual CPU should get dumped
435 * \param cr8 next cr8 value
437 void kvm_set_cr8(kvm_vcpu_context_t vcpu
, uint64_t cr8
);
440 * \brief Get cr8 for sync tpr in qemu apic emulation
442 * This is a getter for cr8, which used to sync with the tpr in qemu
445 * \param kvm Pointer to the current kvm_context
446 * \param vcpu Which virtual CPU should get dumped
448 __u64
kvm_get_cr8(kvm_vcpu_context_t vcpu
);
452 * \brief Set a vcpu's signal mask for guest mode
454 * A vcpu can have different signals blocked in guest mode and user mode.
455 * This allows guest execution to be interrupted on a signal, without requiring
456 * that the signal be delivered to a signal handler (the signal can be
457 * dequeued using sigwait(2).
459 * \param kvm Pointer to the current kvm_context
460 * \param vcpu Which virtual CPU should be initialized
461 * \param sigset signal mask for guest mode
462 * \return 0 on success, or -errno on error
464 int kvm_set_signal_mask(kvm_vcpu_context_t vcpu
, const sigset_t
*sigset
);
467 * \brief Dump VCPU registers
469 * This dumps some of the information that KVM has about a virtual CPU, namely:
472 * A much more verbose version of this is available as kvm_dump_vcpu()
474 * \param kvm Pointer to the current kvm_context
475 * \param vcpu Which virtual CPU should get dumped
476 * \return 0 on success
478 void kvm_show_regs(kvm_vcpu_context_t vcpu
);
481 void *kvm_create_phys_mem(kvm_context_t
, unsigned long phys_start
,
482 unsigned long len
, int log
, int writable
);
483 void kvm_destroy_phys_mem(kvm_context_t
, unsigned long phys_start
,
485 void kvm_unregister_memory_area(kvm_context_t
, uint64_t phys_start
,
488 int kvm_is_containing_region(kvm_context_t kvm
, unsigned long phys_start
, unsigned long size
);
489 int kvm_register_phys_mem(kvm_context_t kvm
,
490 unsigned long phys_start
, void *userspace_addr
,
491 unsigned long len
, int log
);
492 int kvm_get_dirty_pages(kvm_context_t
, unsigned long phys_addr
, void *buf
);
493 int kvm_get_dirty_pages_range(kvm_context_t kvm
, unsigned long phys_addr
,
494 unsigned long end_addr
, void*opaque
,
495 int (*cb
)(unsigned long start
, unsigned long len
,
496 void*bitmap
, void *opaque
));
497 int kvm_register_coalesced_mmio(kvm_context_t kvm
,
498 uint64_t addr
, uint32_t size
);
499 int kvm_unregister_coalesced_mmio(kvm_context_t kvm
,
500 uint64_t addr
, uint32_t size
);
503 * \brief Create a memory alias
505 * Aliases a portion of physical memory to another portion. If the guest
506 * accesses the alias region, it will behave exactly as if it accessed
509 int kvm_create_memory_alias(kvm_context_t
,
510 uint64_t phys_start
, uint64_t len
,
511 uint64_t target_phys
);
514 * \brief Destroy a memory alias
516 * Removes an alias created with kvm_create_memory_alias().
518 int kvm_destroy_memory_alias(kvm_context_t
, uint64_t phys_start
);
521 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
523 * \param kvm Pointer to the current kvm_context
524 * \param phys_addr Memory slot phys addr
525 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
527 int kvm_get_mem_map(kvm_context_t kvm
, unsigned long phys_addr
, void *bitmap
);
528 int kvm_get_mem_map_range(kvm_context_t kvm
, unsigned long phys_addr
,
529 unsigned long len
, void *buf
, void *opaque
,
530 int (*cb
)(unsigned long start
,unsigned long len
,
531 void* bitmap
, void* opaque
));
532 int kvm_set_irq_level(kvm_context_t kvm
, int irq
, int level
, int *status
);
534 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm
,
537 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm
,
541 * \brief Enable dirty-pages-logging for all memory regions
543 * \param kvm Pointer to the current kvm_context
545 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm
);
548 * \brief Disable dirty-page-logging for some memory regions
550 * Disable dirty-pages-logging for those memory regions that were
551 * created with dirty-page-logging disabled.
553 * \param kvm Pointer to the current kvm_context
555 int kvm_dirty_pages_log_reset(kvm_context_t kvm
);
558 * \brief Query whether in kernel irqchip is used
560 * \param kvm Pointer to the current kvm_context
562 int kvm_irqchip_in_kernel(kvm_context_t kvm
);
564 #ifdef KVM_CAP_IRQCHIP
566 * \brief Dump in kernel IRQCHIP contents
568 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
569 * and IOAPIC into a kvm_irqchip structure
571 * \param kvm Pointer to the current kvm_context
572 * \param chip The irq chip device to be dumped
574 int kvm_get_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
577 * \brief Set in kernel IRQCHIP contents
579 * Write one of the in kernel irq chip devices, including PIC (master/slave)
583 * \param kvm Pointer to the current kvm_context
584 * \param chip THe irq chip device to be written
586 int kvm_set_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
588 #if defined(__i386__) || defined(__x86_64__)
590 * \brief Get in kernel local APIC for vcpu
592 * Save the local apic state including the timer of a virtual CPU
594 * \param kvm Pointer to the current kvm_context
595 * \param vcpu Which virtual CPU should be accessed
596 * \param s Local apic state of the specific virtual CPU
598 int kvm_get_lapic(kvm_vcpu_context_t vcpu
, struct kvm_lapic_state
*s
);
601 * \brief Set in kernel local APIC for vcpu
603 * Restore the local apic state including the timer of a virtual CPU
605 * \param kvm Pointer to the current kvm_context
606 * \param vcpu Which virtual CPU should be accessed
607 * \param s Local apic state of the specific virtual CPU
609 int kvm_set_lapic(kvm_vcpu_context_t vcpu
, struct kvm_lapic_state
*s
);
614 * \brief Simulate an NMI
616 * This allows you to simulate a non-maskable interrupt.
618 * \param kvm Pointer to the current kvm_context
619 * \param vcpu Which virtual CPU should get dumped
620 * \return 0 on success
622 int kvm_inject_nmi(kvm_vcpu_context_t vcpu
);
627 * \brief Query wheather in kernel pit is used
629 * \param kvm Pointer to the current kvm_context
631 int kvm_pit_in_kernel(kvm_context_t kvm
);
634 * \brief Initialize coalesced MMIO
636 * Check for coalesced MMIO capability and store in context
638 * \param kvm Pointer to the current kvm_context
640 int kvm_init_coalesced_mmio(kvm_context_t kvm
);
644 #if defined(__i386__) || defined(__x86_64__)
646 * \brief Get in kernel PIT of the virtual domain
648 * Save the PIT state.
650 * \param kvm Pointer to the current kvm_context
651 * \param s PIT state of the virtual domain
653 int kvm_get_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
656 * \brief Set in kernel PIT of the virtual domain
658 * Restore the PIT state.
659 * Timer would be retriggerred after restored.
661 * \param kvm Pointer to the current kvm_context
662 * \param s PIT state of the virtual domain
664 int kvm_set_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
666 int kvm_reinject_control(kvm_context_t kvm
, int pit_reinject
);
668 #ifdef KVM_CAP_PIT_STATE2
670 * \brief Check for kvm support of kvm_pit_state2
672 * \param kvm Pointer to the current kvm_context
673 * \return 0 on success
675 int kvm_has_pit_state2(kvm_context_t kvm
);
678 * \brief Set in kernel PIT state2 of the virtual domain
681 * \param kvm Pointer to the current kvm_context
682 * \param ps2 PIT state2 of the virtual domain
683 * \return 0 on success
685 int kvm_set_pit2(kvm_context_t kvm
, struct kvm_pit_state2
*ps2
);
688 * \brief Get in kernel PIT state2 of the virtual domain
691 * \param kvm Pointer to the current kvm_context
692 * \param ps2 PIT state2 of the virtual domain
693 * \return 0 on success
695 int kvm_get_pit2(kvm_context_t kvm
, struct kvm_pit_state2
*ps2
);
704 * \brief Enable kernel tpr access reporting
706 * When tpr access reporting is enabled, the kernel will call the
707 * ->tpr_access() callback every time the guest vcpu accesses the tpr.
709 * \param kvm Pointer to the current kvm_context
710 * \param vcpu vcpu to enable tpr access reporting on
712 int kvm_enable_tpr_access_reporting(kvm_vcpu_context_t vcpu
);
715 * \brief Disable kernel tpr access reporting
717 * Undoes the effect of kvm_enable_tpr_access_reporting().
719 * \param kvm Pointer to the current kvm_context
720 * \param vcpu vcpu to disable tpr access reporting on
722 int kvm_disable_tpr_access_reporting(kvm_vcpu_context_t vcpu
);
724 int kvm_enable_vapic(kvm_vcpu_context_t vcpu
, uint64_t vapic
);
728 #if defined(__s390__)
729 int kvm_s390_initial_reset(kvm_context_t kvm
, int slot
);
730 int kvm_s390_interrupt(kvm_context_t kvm
, int slot
,
731 struct kvm_s390_interrupt
*kvmint
);
732 int kvm_s390_set_initial_psw(kvm_context_t kvm
, int slot
, psw_t psw
);
733 int kvm_s390_store_status(kvm_context_t kvm
, int slot
, unsigned long addr
);
736 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
738 * \brief Notifies host kernel about a PCI device to be assigned to a guest
740 * Used for PCI device assignment, this function notifies the host
741 * kernel about the assigning of the physical PCI device to a guest.
743 * \param kvm Pointer to the current kvm_context
744 * \param assigned_dev Parameters, like bus, devfn number, etc
746 int kvm_assign_pci_device(kvm_context_t kvm
,
747 struct kvm_assigned_pci_dev
*assigned_dev
);
750 * \brief Assign IRQ for an assigned device
752 * Used for PCI device assignment, this function assigns IRQ numbers for
753 * an physical device and guest IRQ handling.
755 * \param kvm Pointer to the current kvm_context
756 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
758 int kvm_assign_irq(kvm_context_t kvm
,
759 struct kvm_assigned_irq
*assigned_irq
);
761 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
763 * \brief Deassign IRQ for an assigned device
765 * Used for PCI device assignment, this function deassigns IRQ numbers
766 * for an assigned device.
768 * \param kvm Pointer to the current kvm_context
769 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
771 int kvm_deassign_irq(kvm_context_t kvm
,
772 struct kvm_assigned_irq
*assigned_irq
);
777 * \brief Determines whether destroying memory regions is allowed
779 * KVM before 2.6.29 had a bug when destroying memory regions.
781 * \param kvm Pointer to the current kvm_context
783 int kvm_destroy_memory_region_works(kvm_context_t kvm
);
785 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
787 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
789 * Used for hot remove PCI device, this function notifies the host
790 * kernel about the deassigning of the physical PCI device from a guest.
792 * \param kvm Pointer to the current kvm_context
793 * \param assigned_dev Parameters, like bus, devfn number, etc
795 int kvm_deassign_pci_device(kvm_context_t kvm
,
796 struct kvm_assigned_pci_dev
*assigned_dev
);
800 * \brief Checks whether the generic irq routing capability is present
802 * Checks whether kvm can reroute interrupts among the various interrupt
805 * \param kvm Pointer to the current kvm_context
807 int kvm_has_gsi_routing(kvm_context_t kvm
);
810 * \brief Determines the number of gsis that can be routed
812 * Returns the number of distinct gsis that can be routed by kvm. This is
813 * also the number of distinct routes (if a gsi has two routes, than another
814 * gsi cannot be used...)
816 * \param kvm Pointer to the current kvm_context
818 int kvm_get_gsi_count(kvm_context_t kvm
);
821 * \brief Clears the temporary irq routing table
823 * Clears the temporary irq routing table. Nothing is committed to the
826 * \param kvm Pointer to the current kvm_context
828 int kvm_clear_gsi_routes(kvm_context_t kvm
);
831 * \brief Adds an irq route to the temporary irq routing table
833 * Adds an irq route to the temporary irq routing table. Nothing is
834 * committed to the running VM.
836 * \param kvm Pointer to the current kvm_context
838 int kvm_add_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
841 * \brief Removes an irq route from the temporary irq routing table
843 * Adds an irq route to the temporary irq routing table. Nothing is
844 * committed to the running VM.
846 * \param kvm Pointer to the current kvm_context
848 int kvm_del_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
850 struct kvm_irq_routing_entry
;
852 * \brief Adds a routing entry to the temporary irq routing table
854 * Adds a filled routing entry to the temporary irq routing table. Nothing is
855 * committed to the running VM.
857 * \param kvm Pointer to the current kvm_context
859 int kvm_add_routing_entry(kvm_context_t kvm
,
860 struct kvm_irq_routing_entry
* entry
);
863 * \brief Removes a routing from the temporary irq routing table
865 * Remove a routing 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_del_routing_entry(kvm_context_t kvm
,
871 struct kvm_irq_routing_entry
* entry
);
874 * \brief Updates a routing in the temporary irq routing table
876 * Update a routing in the temporary irq routing table
877 * with a new value. entry type and GSI can not be changed.
878 * Nothing is committed to the running VM.
880 * \param kvm Pointer to the current kvm_context
882 int kvm_update_routing_entry(kvm_context_t kvm
,
883 struct kvm_irq_routing_entry
* entry
,
884 struct kvm_irq_routing_entry
* newentry
888 * \brief Commit the temporary irq routing table
890 * Commit the temporary irq routing table to the running VM.
892 * \param kvm Pointer to the current kvm_context
894 int kvm_commit_irq_routes(kvm_context_t kvm
);
897 * \brief Get unused GSI number for irq routing table
899 * Get unused GSI number for irq routing table
901 * \param kvm Pointer to the current kvm_context
903 int kvm_get_irq_route_gsi(kvm_context_t kvm
);
906 * \brief Create a file descriptor for injecting interrupts
908 * Creates an eventfd based file-descriptor that maps to a specific GSI
909 * in the guest. eventfd compliant signaling (write() from userspace, or
910 * eventfd_signal() from kernelspace) will cause the GSI to inject
911 * itself into the guest at the next available window.
913 * \param kvm Pointer to the current kvm_context
914 * \param gsi GSI to assign to this fd
915 * \param flags reserved, must be zero
917 int kvm_irqfd(kvm_context_t kvm
, int gsi
, int flags
);
919 #ifdef KVM_CAP_DEVICE_MSIX
920 int kvm_assign_set_msix_nr(kvm_context_t kvm
,
921 struct kvm_assigned_msix_nr
*msix_nr
);
922 int kvm_assign_set_msix_entry(kvm_context_t kvm
,
923 struct kvm_assigned_msix_entry
*entry
);
926 uint32_t kvm_get_supported_cpuid(kvm_context_t kvm
, uint32_t function
, int reg
);
930 struct kvm_pit_state
{ };
932 #endif /* !USE_KVM */