4 * Copyright (C) 2006-2008 Qumranet Technologies
6 * Licensed under the terms of the GNU GPL version 2 or higher.
8 #ifndef THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
9 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
19 #include <asm/ptrace.h>
25 #define __user /* temporary, until installed via make headers_install */
28 #include <linux/kvm.h>
32 /* FIXME: share this number with kvm */
33 /* FIXME: or dynamically alloc/realloc regions */
35 #define KVM_MAX_NUM_MEM_REGIONS 1u
37 #define LIBKVM_S390_ORIGIN (0UL)
38 #elif defined(__ia64__)
39 #define KVM_MAX_NUM_MEM_REGIONS 32u
42 #define KVM_MAX_NUM_MEM_REGIONS 32u
46 /* kvm abi verison variable */
50 * \brief The KVM context
52 * The verbose KVM context
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
67 #ifdef KVM_CAP_IRQ_ROUTING
68 struct kvm_irq_routing
*irq_routes
;
69 int nr_allocated_irq_routes
;
71 void *used_gsi_bitmap
;
75 typedef struct kvm_context
*kvm_context_t
;
78 int kvm_alloc_kernel_memory(kvm_context_t kvm
, unsigned long memory
,
80 int kvm_alloc_userspace_memory(kvm_context_t kvm
, unsigned long memory
,
83 int kvm_arch_create(kvm_context_t kvm
, unsigned long phys_mem_bytes
,
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
,
104 int kvm_setup_mce(CPUState
*env
, uint64_t *mcg_cap
);
106 int kvm_set_mce(CPUState
*env
, struct kvm_x86_mce
*mce
);
110 * \brief Disable the in-kernel IRQCHIP creation
112 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
113 * this should be called prior to kvm_create().
115 * \param kvm Pointer to the kvm_context
117 void kvm_disable_irqchip_creation(kvm_context_t kvm
);
120 * \brief Disable the in-kernel PIT creation
122 * In-kernel pit is enabled by default. If userspace pit 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_pit_creation(kvm_context_t kvm
);
130 * \brief Create new virtual machine
132 * This creates a new virtual machine, maps physical RAM to it, and creates a
133 * virtual CPU for it.\n
135 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
137 * \param kvm Pointer to the current kvm_context
138 * \param phys_mem_bytes The amount of physical ram you want the VM to have
139 * \param phys_mem This pointer will be set to point to the memory that
140 * kvm_create allocates for physical RAM
141 * \return 0 on success
143 int kvm_create(kvm_context_t kvm
, unsigned long phys_mem_bytes
,
145 int kvm_create_vm(kvm_context_t kvm
);
146 void kvm_create_irqchip(kvm_context_t kvm
);
149 * \brief Start the VCPU
151 * This starts the VCPU and virtualization is started.\n
153 * This function will not return until any of these conditions are met:
154 * - An IO/MMIO handler does not return "0"
155 * - An exception that neither the guest OS, nor KVM can handle occurs
157 * \note This function will call the callbacks registered in kvm_init()
158 * to emulate those functions
159 * \note If you at any point want to interrupt the VCPU, kvm_run() will
160 * listen to the EINTR signal. This allows you to simulate external interrupts
161 * and asyncronous IO.
163 * \param kvm Pointer to the current kvm_context
164 * \param vcpu Which virtual CPU should be started
165 * \return 0 on success, but you really shouldn't expect this function to
166 * return except for when an error has occured, or when you have sent it
169 int kvm_run(CPUState
*env
);
172 * \brief Check if a vcpu is ready for interrupt injection
174 * This checks if vcpu interrupts are not masked by mov ss or sti.
176 * \param kvm Pointer to the current kvm_context
177 * \param vcpu Which virtual CPU should get dumped
178 * \return boolean indicating interrupt injection readiness
180 int kvm_is_ready_for_interrupt_injection(CPUState
*env
);
183 * \brief Read VCPU registers
185 * This gets the GP registers from the VCPU and outputs them
186 * into a kvm_regs structure
188 * \note This function returns a \b copy of the VCPUs registers.\n
189 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
191 * \param kvm Pointer to the current kvm_context
192 * \param vcpu Which virtual CPU should get dumped
193 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
195 * \return 0 on success
197 int kvm_get_regs(CPUState
*env
, struct kvm_regs
*regs
);
200 * \brief Write VCPU registers
202 * This sets the GP registers on the VCPU from a kvm_regs structure
204 * \note When this function returns, the regs pointer and the data it points to
206 * \param kvm Pointer to the current kvm_context
207 * \param vcpu Which virtual CPU should get dumped
208 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
210 * \return 0 on success
212 int kvm_set_regs(CPUState
*env
, struct kvm_regs
*regs
);
214 * \brief Read VCPU fpu registers
216 * This gets the FPU registers from the VCPU and outputs them
217 * into a kvm_fpu structure
219 * \note This function returns a \b copy of the VCPUs registers.\n
220 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
222 * \param kvm Pointer to the current kvm_context
223 * \param vcpu Which virtual CPU should get dumped
224 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
225 * fpu registers values
226 * \return 0 on success
228 int kvm_get_fpu(CPUState
*env
, struct kvm_fpu
*fpu
);
231 * \brief Write VCPU fpu registers
233 * This sets the FPU registers on the VCPU from a kvm_fpu structure
235 * \note When this function returns, the fpu pointer and the data it points to
237 * \param kvm Pointer to the current kvm_context
238 * \param vcpu Which virtual CPU should get dumped
239 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
240 * \return 0 on success
242 int kvm_set_fpu(CPUState
*env
, struct kvm_fpu
*fpu
);
245 * \brief Read VCPU system registers
247 * This gets the non-GP registers from the VCPU and outputs them
248 * into a kvm_sregs structure
250 * \note This function returns a \b copy of the VCPUs registers.\n
251 * If you wish to modify the VCPUs non-GP registers, you should call
254 * \param kvm Pointer to the current kvm_context
255 * \param vcpu Which virtual CPU should get dumped
256 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
258 * \return 0 on success
260 int kvm_get_sregs(CPUState
*env
, struct kvm_sregs
*regs
);
263 * \brief Write VCPU system registers
265 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
267 * \note When this function returns, the regs pointer and the data it points to
269 * \param kvm Pointer to the current kvm_context
270 * \param vcpu Which virtual CPU should get dumped
271 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
273 * \return 0 on success
275 int kvm_set_sregs(CPUState
*env
, struct kvm_sregs
*regs
);
277 #ifdef KVM_CAP_MP_STATE
279 * * \brief Read VCPU MP state
282 int kvm_get_mpstate(CPUState
*env
, struct kvm_mp_state
*mp_state
);
285 * * \brief Write VCPU MP state
288 int kvm_set_mpstate(CPUState
*env
, struct kvm_mp_state
*mp_state
);
293 * * \brief Read VCPU xsave state
296 int kvm_get_xsave(CPUState
*env
, struct kvm_xsave
*xsave
);
299 * * \brief Write VCPU xsave state
302 int kvm_set_xsave(CPUState
*env
, struct kvm_xsave
*xsave
);
307 * * \brief Read VCPU XCRs
310 int kvm_get_xcrs(CPUState
*env
, struct kvm_xcrs
*xcrs
);
313 * * \brief Write VCPU XCRs
316 int kvm_set_xcrs(CPUState
*env
, struct kvm_xcrs
*xcrs
);
320 * \brief Simulate an external vectored interrupt
322 * This allows you to simulate an external vectored interrupt.
324 * \param kvm Pointer to the current kvm_context
325 * \param vcpu Which virtual CPU should get dumped
326 * \param irq Vector number
327 * \return 0 on success
329 int kvm_inject_irq(CPUState
*env
, unsigned irq
);
331 #if defined(__i386__) || defined(__x86_64__)
333 * \brief Setup a vcpu's cpuid instruction emulation
335 * Set up a table of cpuid function to cpuid outputs.\n
337 * \param kvm Pointer to the current kvm_context
338 * \param vcpu Which virtual CPU should be initialized
339 * \param nent number of entries to be installed
340 * \param entries cpuid function entries table
341 * \return 0 on success, or -errno on error
343 int kvm_setup_cpuid(CPUState
*env
, int nent
,
344 struct kvm_cpuid_entry
*entries
);
347 * \brief Setup a vcpu's cpuid instruction emulation
349 * Set up a table of cpuid function to cpuid outputs.
350 * This call replaces the older kvm_setup_cpuid interface by adding a few
351 * parameters to support cpuid functions that have sub-leaf values.
353 * \param kvm Pointer to the current kvm_context
354 * \param vcpu Which virtual CPU should be initialized
355 * \param nent number of entries to be installed
356 * \param entries cpuid function entries table
357 * \return 0 on success, or -errno on error
359 int kvm_setup_cpuid2(CPUState
*env
, int nent
,
360 struct kvm_cpuid_entry2
*entries
);
363 * \brief Setting the number of shadow pages to be allocated to the vm
365 * \param kvm pointer to kvm_context
366 * \param nrshadow_pages number of pages to be allocated
368 int kvm_set_shadow_pages(kvm_context_t kvm
, unsigned int nrshadow_pages
);
371 * \brief Getting the number of shadow pages that are allocated to the vm
373 * \param kvm pointer to kvm_context
374 * \param nrshadow_pages number of pages to be allocated
376 int kvm_get_shadow_pages(kvm_context_t kvm
, unsigned int *nrshadow_pages
);
381 * \brief Dump VCPU registers
383 * This dumps some of the information that KVM has about a virtual CPU, namely:
386 * A much more verbose version of this is available as kvm_dump_vcpu()
388 * \param kvm Pointer to the current kvm_context
389 * \param vcpu Which virtual CPU should get dumped
390 * \return 0 on success
392 void kvm_show_regs(CPUState
*env
);
395 void *kvm_create_phys_mem(kvm_context_t
, unsigned long phys_start
,
396 unsigned long len
, int log
, int writable
);
397 void kvm_destroy_phys_mem(kvm_context_t
, unsigned long phys_start
,
400 int kvm_is_containing_region(kvm_context_t kvm
, unsigned long phys_start
,
402 int kvm_register_phys_mem(kvm_context_t kvm
, unsigned long phys_start
,
403 void *userspace_addr
, unsigned long len
, int log
);
404 int kvm_get_dirty_pages_range(kvm_context_t kvm
, unsigned long phys_addr
,
405 unsigned long end_addr
, void *opaque
,
406 int (*cb
)(unsigned long start
,
407 unsigned long len
, void *bitmap
,
409 int kvm_register_coalesced_mmio(kvm_context_t kvm
, uint64_t addr
,
411 int kvm_unregister_coalesced_mmio(kvm_context_t kvm
, uint64_t addr
,
415 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
417 * \param kvm Pointer to the current kvm_context
418 * \param phys_addr Memory slot phys addr
419 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
421 int kvm_get_mem_map(kvm_context_t kvm
, unsigned long phys_addr
, void *bitmap
);
422 int kvm_get_mem_map_range(kvm_context_t kvm
, unsigned long phys_addr
,
423 unsigned long len
, void *buf
, void *opaque
,
424 int (*cb
)(unsigned long start
,
425 unsigned long len
, void *bitmap
,
427 int kvm_set_irq_level(kvm_context_t kvm
, int irq
, int level
, int *status
);
429 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm
, uint64_t phys_start
,
431 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm
, uint64_t phys_start
,
434 * \brief Enable dirty-pages-logging for all memory regions
436 * \param kvm Pointer to the current kvm_context
438 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm
);
441 * \brief Disable dirty-page-logging for some memory regions
443 * Disable dirty-pages-logging for those memory regions that were
444 * created with dirty-page-logging disabled.
446 * \param kvm Pointer to the current kvm_context
448 int kvm_dirty_pages_log_reset(kvm_context_t kvm
);
450 #ifdef KVM_CAP_IRQCHIP
452 * \brief Dump in kernel IRQCHIP contents
454 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
455 * and IOAPIC into a kvm_irqchip structure
457 * \param kvm Pointer to the current kvm_context
458 * \param chip The irq chip device to be dumped
460 int kvm_get_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
463 * \brief Set in kernel IRQCHIP contents
465 * Write one of the in kernel irq chip devices, including PIC (master/slave)
469 * \param kvm Pointer to the current kvm_context
470 * \param chip THe irq chip device to be written
472 int kvm_set_irqchip(kvm_context_t kvm
, struct kvm_irqchip
*chip
);
474 #if defined(__i386__) || defined(__x86_64__)
476 * \brief Get in kernel local APIC for vcpu
478 * Save the local apic state including the timer of a virtual CPU
480 * \param kvm Pointer to the current kvm_context
481 * \param vcpu Which virtual CPU should be accessed
482 * \param s Local apic state of the specific virtual CPU
484 int kvm_get_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
487 * \brief Set in kernel local APIC for vcpu
489 * Restore the local apic state including the timer of a virtual CPU
491 * \param kvm Pointer to the current kvm_context
492 * \param vcpu Which virtual CPU should be accessed
493 * \param s Local apic state of the specific virtual CPU
495 int kvm_set_lapic(CPUState
*env
, struct kvm_lapic_state
*s
);
500 * \brief Simulate an NMI
502 * This allows you to simulate a non-maskable interrupt.
504 * \param kvm Pointer to the current kvm_context
505 * \param vcpu Which virtual CPU should get dumped
506 * \return 0 on success
508 int kvm_inject_nmi(CPUState
*env
);
513 * \brief Simulate an x86 MCE
515 * This allows you to simulate a x86 MCE.
517 * \param cenv Which virtual CPU should get MCE injected
518 * \param bank Bank number
519 * \param status MSR_MCI_STATUS
520 * \param mcg_status MSR_MCG_STATUS
521 * \param addr MSR_MCI_ADDR
522 * \param misc MSR_MCI_MISC
523 * \param abort_on_error abort on error
525 void kvm_inject_x86_mce(CPUState
*cenv
, int bank
, uint64_t status
,
526 uint64_t mcg_status
, uint64_t addr
, uint64_t misc
,
530 * \brief Initialize coalesced MMIO
532 * Check for coalesced MMIO capability and store in context
534 * \param kvm Pointer to the current kvm_context
536 int kvm_init_coalesced_mmio(kvm_context_t kvm
);
540 #if defined(__i386__) || defined(__x86_64__)
542 * \brief Get in kernel PIT of the virtual domain
544 * Save the PIT state.
546 * \param kvm Pointer to the current kvm_context
547 * \param s PIT state of the virtual domain
549 int kvm_get_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
552 * \brief Set in kernel PIT of the virtual domain
554 * Restore the PIT state.
555 * Timer would be retriggerred after restored.
557 * \param kvm Pointer to the current kvm_context
558 * \param s PIT state of the virtual domain
560 int kvm_set_pit(kvm_context_t kvm
, struct kvm_pit_state
*s
);
562 int kvm_reinject_control(kvm_context_t kvm
, int pit_reinject
);
564 #ifdef KVM_CAP_PIT_STATE2
566 * \brief Check for kvm support of kvm_pit_state2
568 * \param kvm Pointer to the current kvm_context
569 * \return 0 on success
571 int kvm_has_pit_state2(kvm_context_t kvm
);
574 * \brief Set in kernel PIT state2 of the virtual domain
577 * \param kvm Pointer to the current kvm_context
578 * \param ps2 PIT state2 of the virtual domain
579 * \return 0 on success
581 int kvm_set_pit2(kvm_context_t kvm
, struct kvm_pit_state2
*ps2
);
584 * \brief Get in kernel PIT state2 of the virtual domain
587 * \param kvm Pointer to the current kvm_context
588 * \param ps2 PIT state2 of the virtual domain
589 * \return 0 on success
591 int kvm_get_pit2(kvm_context_t kvm
, struct kvm_pit_state2
*ps2
);
599 int kvm_enable_vapic(CPUState
*env
, uint64_t vapic
);
603 #if defined(__s390__)
604 int kvm_s390_initial_reset(kvm_context_t kvm
, int slot
);
605 int kvm_s390_interrupt(kvm_context_t kvm
, int slot
,
606 struct kvm_s390_interrupt
*kvmint
);
607 int kvm_s390_set_initial_psw(kvm_context_t kvm
, int slot
, psw_t psw
);
608 int kvm_s390_store_status(kvm_context_t kvm
, int slot
, unsigned long addr
);
611 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
613 * \brief Notifies host kernel about a PCI device to be assigned to a guest
615 * Used for PCI device assignment, this function notifies the host
616 * kernel about the assigning of the physical PCI device to a guest.
618 * \param kvm Pointer to the current kvm_context
619 * \param assigned_dev Parameters, like bus, devfn number, etc
621 int kvm_assign_pci_device(kvm_context_t kvm
,
622 struct kvm_assigned_pci_dev
*assigned_dev
);
625 * \brief Assign IRQ for an assigned device
627 * Used for PCI device assignment, this function assigns IRQ numbers for
628 * an physical device and guest IRQ handling.
630 * \param kvm Pointer to the current kvm_context
631 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
633 int kvm_assign_irq(kvm_context_t kvm
, struct kvm_assigned_irq
*assigned_irq
);
635 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
637 * \brief Deassign IRQ for an assigned device
639 * Used for PCI device assignment, this function deassigns IRQ numbers
640 * for an assigned device.
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_deassign_irq(kvm_context_t kvm
, struct kvm_assigned_irq
*assigned_irq
);
649 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
651 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
653 * Used for hot remove PCI device, this function notifies the host
654 * kernel about the deassigning of the physical PCI device from a guest.
656 * \param kvm Pointer to the current kvm_context
657 * \param assigned_dev Parameters, like bus, devfn number, etc
659 int kvm_deassign_pci_device(kvm_context_t kvm
,
660 struct kvm_assigned_pci_dev
*assigned_dev
);
664 * \brief Checks whether the generic irq routing capability is present
666 * Checks whether kvm can reroute interrupts among the various interrupt
669 * \param kvm Pointer to the current kvm_context
671 int kvm_has_gsi_routing(kvm_context_t kvm
);
674 * \brief Determines the number of gsis that can be routed
676 * Returns the number of distinct gsis that can be routed by kvm. This is
677 * also the number of distinct routes (if a gsi has two routes, than another
678 * gsi cannot be used...)
680 * \param kvm Pointer to the current kvm_context
682 int kvm_get_gsi_count(kvm_context_t kvm
);
685 * \brief Clears the temporary irq routing table
687 * Clears the temporary irq routing table. Nothing is committed to the
690 * \param kvm Pointer to the current kvm_context
692 int kvm_clear_gsi_routes(kvm_context_t kvm
);
695 * \brief Adds an irq route to the temporary irq routing table
697 * Adds an irq route to the temporary irq routing table. Nothing is
698 * committed to the running VM.
700 * \param kvm Pointer to the current kvm_context
702 int kvm_add_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
705 * \brief Removes an irq route from the temporary irq routing table
707 * Adds an irq route to the temporary irq routing table. Nothing is
708 * committed to the running VM.
710 * \param kvm Pointer to the current kvm_context
712 int kvm_del_irq_route(kvm_context_t kvm
, int gsi
, int irqchip
, int pin
);
714 struct kvm_irq_routing_entry
;
716 * \brief Adds a routing entry to the temporary irq routing table
718 * Adds a filled routing entry to the temporary irq routing table. Nothing is
719 * committed to the running VM.
721 * \param kvm Pointer to the current kvm_context
723 int kvm_add_routing_entry(kvm_context_t kvm
,
724 struct kvm_irq_routing_entry
*entry
);
727 * \brief Removes a routing from the temporary irq routing table
729 * Remove a routing to the temporary irq routing table. Nothing is
730 * committed to the running VM.
732 * \param kvm Pointer to the current kvm_context
734 int kvm_del_routing_entry(kvm_context_t kvm
,
735 struct kvm_irq_routing_entry
*entry
);
738 * \brief Updates a routing in the temporary irq routing table
740 * Update a routing in the temporary irq routing table
741 * with a new value. entry type and GSI can not be changed.
742 * Nothing is committed to the running VM.
744 * \param kvm Pointer to the current kvm_context
746 int kvm_update_routing_entry(kvm_context_t kvm
,
747 struct kvm_irq_routing_entry
*entry
,
748 struct kvm_irq_routing_entry
*newentry
);
751 * \brief Commit the temporary irq routing table
753 * Commit the temporary irq routing table to the running VM.
755 * \param kvm Pointer to the current kvm_context
757 int kvm_commit_irq_routes(kvm_context_t kvm
);
760 * \brief Get unused GSI number for irq routing table
762 * Get unused GSI number for irq routing table
764 * \param kvm Pointer to the current kvm_context
766 int kvm_get_irq_route_gsi(kvm_context_t kvm
);
769 * \brief Create a file descriptor for injecting interrupts
771 * Creates an eventfd based file-descriptor that maps to a specific GSI
772 * in the guest. eventfd compliant signaling (write() from userspace, or
773 * eventfd_signal() from kernelspace) will cause the GSI to inject
774 * itself into the guest at the next available window.
776 * \param kvm Pointer to the current kvm_context
777 * \param gsi GSI to assign to this fd
778 * \param flags reserved, must be zero
780 int kvm_irqfd(kvm_context_t kvm
, int gsi
, int flags
);
782 #ifdef KVM_CAP_DEVICE_MSIX
783 int kvm_assign_set_msix_nr(kvm_context_t kvm
,
784 struct kvm_assigned_msix_nr
*msix_nr
);
785 int kvm_assign_set_msix_entry(kvm_context_t kvm
,
786 struct kvm_assigned_msix_entry
*entry
);
789 #else /* !CONFIG_KVM */
791 typedef struct kvm_context
*kvm_context_t
;
792 typedef struct kvm_vcpu_context
*kvm_vcpu_context_t
;
794 struct kvm_pit_state
{
797 static inline void kvm_inject_x86_mce(CPUState
*cenv
, int bank
,
798 uint64_t status
, uint64_t mcg_status
,
799 uint64_t addr
, uint64_t misc
,
806 #endif /* !CONFIG_KVM */
810 * \brief Create new KVM context
812 * This creates a new kvm_context. A KVM context is a small area of data that
813 * holds information about the KVM instance that gets created by this call.\n
814 * This should always be your first call to KVM.
816 * \param opaque Not used
817 * \return NULL on failure
819 int kvm_init(int smp_cpus
);
821 int kvm_main_loop(void);
822 int kvm_init_ap(void);
823 int kvm_vcpu_inited(CPUState
*env
);
824 void kvm_save_lapic(CPUState
*env
);
825 void kvm_load_lapic(CPUState
*env
);
827 void kvm_hpet_enable_kpit(void);
828 void kvm_hpet_disable_kpit(void);
829 int kvm_set_irq(int irq
, int level
, int *status
);
831 int kvm_physical_memory_set_dirty_tracking(int enable
);
833 void qemu_kvm_call_with_env(void (*func
)(void *), void *data
, CPUState
*env
);
834 void qemu_kvm_cpuid_on_env(CPUState
*env
);
835 void kvm_inject_interrupt(CPUState
*env
, int mask
);
836 void kvm_update_after_sipi(CPUState
*env
);
837 void kvm_update_interrupt_request(CPUState
*env
);
838 #ifndef CONFIG_USER_ONLY
839 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr
, unsigned long size
,
840 int log
, int writable
);
842 void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr
,
844 void kvm_qemu_log_memory(target_phys_addr_t start
, target_phys_addr_t size
,
847 int kvm_qemu_create_memory_alias(uint64_t phys_start
, uint64_t len
,
848 uint64_t target_phys
);
849 int kvm_qemu_destroy_memory_alias(uint64_t phys_start
);
851 int kvm_arch_qemu_create_context(void);
853 void kvm_arch_save_regs(CPUState
*env
);
854 void kvm_arch_load_regs(CPUState
*env
, int level
);
855 int kvm_arch_has_work(CPUState
*env
);
856 void kvm_arch_process_irqchip_events(CPUState
*env
);
857 int kvm_arch_try_push_interrupts(void *opaque
);
858 void kvm_arch_push_nmi(void *opaque
);
859 void kvm_arch_cpu_reset(CPUState
*env
);
860 int kvm_set_boot_cpu_id(uint32_t id
);
862 void qemu_kvm_aio_wait_start(void);
863 void qemu_kvm_aio_wait(void);
864 void qemu_kvm_aio_wait_end(void);
866 void qemu_kvm_notify_work(void);
868 void kvm_tpr_access_report(CPUState
*env
, uint64_t rip
, int is_write
);
870 int kvm_arch_init_irq_routing(void);
872 int kvm_mmio_read(void *opaque
, uint64_t addr
, uint8_t * data
, int len
);
873 int kvm_mmio_write(void *opaque
, uint64_t addr
, uint8_t * data
, int len
);
875 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
878 void kvm_ioperm(CPUState
*env
, void *data
);
879 void kvm_add_ioperm_data(struct ioperm_data
*data
);
880 void kvm_remove_ioperm_data(unsigned long start_port
, unsigned long num
);
881 void kvm_arch_do_ioperm(void *_data
);
884 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
885 #define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
888 #include "qemu-queue.h"
890 extern int kvm_irqchip
;
892 extern int kvm_pit_reinject
;
893 extern int kvm_nested
;
894 extern kvm_context_t kvm_context
;
897 unsigned long start_port
;
900 QLIST_ENTRY(ioperm_data
) entries
;
903 void qemu_kvm_cpu_stop(CPUState
*env
);
904 int kvm_arch_halt(CPUState
*env
);
905 int handle_tpr_access(void *opaque
, CPUState
*env
, uint64_t rip
,
908 #define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing(kvm_context)
910 #define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
914 #define qemu_kvm_has_gsi_routing() (0)
916 #define qemu_kvm_has_pit_state2() (0)
918 #define qemu_kvm_cpu_stop(env) do {} while(0)
921 void kvm_mutex_unlock(void);
922 void kvm_mutex_lock(void);
924 static inline int kvm_sync_vcpus(void)
931 typedef struct KVMSlot
{
932 target_phys_addr_t start_addr
;
933 ram_addr_t memory_size
;
934 ram_addr_t phys_offset
;
939 typedef struct kvm_dirty_log KVMDirtyLog
;
946 #ifdef KVM_CAP_COALESCED_MMIO
947 struct kvm_coalesced_mmio_ring
*coalesced_mmio_ring
;
949 int broken_set_mem_region
;
952 int robust_singlestep
;
954 #ifdef KVM_CAP_SET_GUEST_DEBUG
955 QTAILQ_HEAD(, kvm_sw_breakpoint
) kvm_sw_breakpoints
;
957 int irqchip_in_kernel
;
960 struct kvm_context kvm_context
;
963 extern struct KVMState
*kvm_state
;
965 int kvm_tpr_enable_vapic(CPUState
*env
);
967 unsigned long kvm_get_thread_id(void);
968 int kvm_cpu_is_stopped(CPUState
*env
);