Merge commit 'c0532a76b407af4b276dc5a62d8178db59857ea6' into upstream-merge
[qemu/qemu-dev-zwu.git] / qemu-kvm.h
blobd55bc368ee242ba7ff290a90a67190eca7426717
1 /*
2 * qemu/kvm integration
4 * Copyright (C) 2006-2008 Qumranet Technologies
6 * Licensed under the terms of the GNU GPL version 2 or higher.
7 */
8 #ifndef THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
9 #define THE_ORIGINAL_AND_TRUE_QEMU_KVM_H
11 #include "cpu.h"
13 #include <signal.h>
14 #include <stdlib.h>
16 #ifdef CONFIG_KVM
18 #if defined(__s390__)
19 #include <asm/ptrace.h>
20 #endif
22 #include <stdint.h>
24 #ifndef __user
25 #define __user /* temporary, until installed via make headers_install */
26 #endif
28 #include <linux/kvm.h>
30 #include <signal.h>
32 /* FIXME: share this number with kvm */
33 /* FIXME: or dynamically alloc/realloc regions */
34 #ifdef __s390__
35 #define KVM_MAX_NUM_MEM_REGIONS 1u
36 #define MAX_VCPUS 64
37 #define LIBKVM_S390_ORIGIN (0UL)
38 #elif defined(__ia64__)
39 #define KVM_MAX_NUM_MEM_REGIONS 32u
40 #define MAX_VCPUS 256
41 #else
42 #define KVM_MAX_NUM_MEM_REGIONS 32u
43 #define MAX_VCPUS 16
44 #endif
46 /* kvm abi verison variable */
47 extern int kvm_abi;
49 /**
50 * \brief The KVM context
52 * The verbose KVM context
55 struct kvm_context {
56 void *opaque;
57 /// is dirty pages logging enabled for all regions or not
58 int dirty_pages_log_all;
59 /// do not create in-kernel irqchip if set
60 int no_irqchip_creation;
61 /// in-kernel irqchip status
62 int irqchip_in_kernel;
63 /// ioctl to use to inject interrupts
64 int irqchip_inject_ioctl;
65 /// do not create in-kernel pit if set
66 int no_pit_creation;
67 #ifdef KVM_CAP_IRQ_ROUTING
68 struct kvm_irq_routing *irq_routes;
69 int nr_allocated_irq_routes;
70 #endif
71 void *used_gsi_bitmap;
72 int max_gsi;
75 typedef struct kvm_context *kvm_context_t;
77 #include "kvm.h"
78 int kvm_alloc_kernel_memory(kvm_context_t kvm, unsigned long memory,
79 void **vm_mem);
80 int kvm_alloc_userspace_memory(kvm_context_t kvm, unsigned long memory,
81 void **vm_mem);
83 int kvm_arch_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
84 void **vm_mem);
86 int kvm_arch_run(CPUState *env);
89 void kvm_show_code(CPUState *env);
91 int handle_halt(CPUState *env);
93 int handle_shutdown(kvm_context_t kvm, CPUState *env);
94 void post_kvm_run(kvm_context_t kvm, CPUState *env);
95 int pre_kvm_run(kvm_context_t kvm, CPUState *env);
96 int handle_io_window(kvm_context_t kvm);
97 int try_push_interrupts(kvm_context_t kvm);
99 #if defined(__x86_64__) || defined(__i386__)
100 int kvm_get_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n);
101 int kvm_set_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n);
102 struct kvm_x86_mce;
103 #endif
106 * \brief Disable the in-kernel IRQCHIP creation
108 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
109 * this should be called prior to kvm_create().
111 * \param kvm Pointer to the kvm_context
113 void kvm_disable_irqchip_creation(kvm_context_t kvm);
116 * \brief Disable the in-kernel PIT creation
118 * In-kernel pit is enabled by default. If userspace pit is to be used,
119 * this should be called prior to kvm_create().
121 * \param kvm Pointer to the kvm_context
123 void kvm_disable_pit_creation(kvm_context_t kvm);
126 * \brief Create new virtual machine
128 * This creates a new virtual machine, maps physical RAM to it, and creates a
129 * virtual CPU for it.\n
130 * \n
131 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
133 * \param kvm Pointer to the current kvm_context
134 * \param phys_mem_bytes The amount of physical ram you want the VM to have
135 * \param phys_mem This pointer will be set to point to the memory that
136 * kvm_create allocates for physical RAM
137 * \return 0 on success
139 int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
140 void **phys_mem);
141 int kvm_create_vm(kvm_context_t kvm);
142 void kvm_create_irqchip(kvm_context_t kvm);
145 * \brief Start the VCPU
147 * This starts the VCPU and virtualization is started.\n
148 * \n
149 * This function will not return until any of these conditions are met:
150 * - An IO/MMIO handler does not return "0"
151 * - An exception that neither the guest OS, nor KVM can handle occurs
153 * \note This function will call the callbacks registered in kvm_init()
154 * to emulate those functions
155 * \note If you at any point want to interrupt the VCPU, kvm_run() will
156 * listen to the EINTR signal. This allows you to simulate external interrupts
157 * and asyncronous IO.
159 * \param kvm Pointer to the current kvm_context
160 * \param vcpu Which virtual CPU should be started
161 * \return 0 on success, but you really shouldn't expect this function to
162 * return except for when an error has occured, or when you have sent it
163 * an EINTR signal.
165 int kvm_run(CPUState *env);
168 * \brief Check if a vcpu is ready for interrupt injection
170 * This checks if vcpu interrupts are not masked by mov ss or sti.
172 * \param kvm Pointer to the current kvm_context
173 * \param vcpu Which virtual CPU should get dumped
174 * \return boolean indicating interrupt injection readiness
176 int kvm_is_ready_for_interrupt_injection(CPUState *env);
179 * \brief Read VCPU registers
181 * This gets the GP registers from the VCPU and outputs them
182 * into a kvm_regs structure
184 * \note This function returns a \b copy of the VCPUs registers.\n
185 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
187 * \param kvm Pointer to the current kvm_context
188 * \param vcpu Which virtual CPU should get dumped
189 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
190 * registers values
191 * \return 0 on success
193 int kvm_get_regs(CPUState *env, struct kvm_regs *regs);
196 * \brief Write VCPU registers
198 * This sets the GP registers on the VCPU from a kvm_regs structure
200 * \note When this function returns, the regs pointer and the data it points to
201 * can be discarded
202 * \param kvm Pointer to the current kvm_context
203 * \param vcpu Which virtual CPU should get dumped
204 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
205 * registers values
206 * \return 0 on success
208 int kvm_set_regs(CPUState *env, struct kvm_regs *regs);
210 * \brief Read VCPU fpu registers
212 * This gets the FPU registers from the VCPU and outputs them
213 * into a kvm_fpu structure
215 * \note This function returns a \b copy of the VCPUs registers.\n
216 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
218 * \param kvm Pointer to the current kvm_context
219 * \param vcpu Which virtual CPU should get dumped
220 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
221 * fpu registers values
222 * \return 0 on success
224 int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu);
227 * \brief Write VCPU fpu registers
229 * This sets the FPU registers on the VCPU from a kvm_fpu structure
231 * \note When this function returns, the fpu pointer and the data it points to
232 * can be discarded
233 * \param kvm Pointer to the current kvm_context
234 * \param vcpu Which virtual CPU should get dumped
235 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
236 * \return 0 on success
238 int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu);
241 * \brief Read VCPU system registers
243 * This gets the non-GP registers from the VCPU and outputs them
244 * into a kvm_sregs structure
246 * \note This function returns a \b copy of the VCPUs registers.\n
247 * If you wish to modify the VCPUs non-GP registers, you should call
248 * kvm_set_sregs()
250 * \param kvm Pointer to the current kvm_context
251 * \param vcpu Which virtual CPU should get dumped
252 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
253 * registers values
254 * \return 0 on success
256 int kvm_get_sregs(CPUState *env, struct kvm_sregs *regs);
259 * \brief Write VCPU system registers
261 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
263 * \note When this function returns, the regs pointer and the data it points to
264 * can be discarded
265 * \param kvm Pointer to the current kvm_context
266 * \param vcpu Which virtual CPU should get dumped
267 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
268 * registers values
269 * \return 0 on success
271 int kvm_set_sregs(CPUState *env, struct kvm_sregs *regs);
273 #ifdef KVM_CAP_MP_STATE
275 * * \brief Read VCPU MP state
278 int kvm_get_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
281 * * \brief Write VCPU MP state
284 int kvm_set_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
285 #endif
287 #ifdef KVM_CAP_XSAVE
289 * * \brief Read VCPU xsave state
292 int kvm_get_xsave(CPUState *env, struct kvm_xsave *xsave);
295 * * \brief Write VCPU xsave state
298 int kvm_set_xsave(CPUState *env, struct kvm_xsave *xsave);
299 #endif
301 #ifdef KVM_CAP_XCRS
303 * * \brief Read VCPU XCRs
306 int kvm_get_xcrs(CPUState *env, struct kvm_xcrs *xcrs);
309 * * \brief Write VCPU XCRs
312 int kvm_set_xcrs(CPUState *env, struct kvm_xcrs *xcrs);
313 #endif
316 * \brief Simulate an external vectored interrupt
318 * This allows you to simulate an external vectored interrupt.
320 * \param kvm Pointer to the current kvm_context
321 * \param vcpu Which virtual CPU should get dumped
322 * \param irq Vector number
323 * \return 0 on success
325 int kvm_inject_irq(CPUState *env, unsigned irq);
327 #if defined(__i386__) || defined(__x86_64__)
329 * \brief Setup a vcpu's cpuid instruction emulation
331 * Set up a table of cpuid function to cpuid outputs.\n
333 * \param kvm Pointer to the current kvm_context
334 * \param vcpu Which virtual CPU should be initialized
335 * \param nent number of entries to be installed
336 * \param entries cpuid function entries table
337 * \return 0 on success, or -errno on error
339 int kvm_setup_cpuid(CPUState *env, int nent,
340 struct kvm_cpuid_entry *entries);
343 * \brief Setup a vcpu's cpuid instruction emulation
345 * Set up a table of cpuid function to cpuid outputs.
346 * This call replaces the older kvm_setup_cpuid interface by adding a few
347 * parameters to support cpuid functions that have sub-leaf values.
349 * \param kvm Pointer to the current kvm_context
350 * \param vcpu Which virtual CPU should be initialized
351 * \param nent number of entries to be installed
352 * \param entries cpuid function entries table
353 * \return 0 on success, or -errno on error
355 int kvm_setup_cpuid2(CPUState *env, int nent,
356 struct kvm_cpuid_entry2 *entries);
359 * \brief Setting the number of shadow pages to be allocated to the vm
361 * \param kvm pointer to kvm_context
362 * \param nrshadow_pages number of pages to be allocated
364 int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
367 * \brief Getting the number of shadow pages that are allocated to the vm
369 * \param kvm pointer to kvm_context
370 * \param nrshadow_pages number of pages to be allocated
372 int kvm_get_shadow_pages(kvm_context_t kvm, unsigned int *nrshadow_pages);
374 #endif
377 * \brief Dump VCPU registers
379 * This dumps some of the information that KVM has about a virtual CPU, namely:
380 * - GP Registers
382 * A much more verbose version of this is available as kvm_dump_vcpu()
384 * \param kvm Pointer to the current kvm_context
385 * \param vcpu Which virtual CPU should get dumped
386 * \return 0 on success
388 void kvm_show_regs(CPUState *env);
391 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start,
392 unsigned long len, int log, int writable);
393 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
394 unsigned long len);
396 int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start,
397 unsigned long size);
398 int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start,
399 void *userspace_addr, unsigned long len, int log);
400 int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr,
401 unsigned long end_addr, void *opaque,
402 int (*cb)(unsigned long start,
403 unsigned long len, void *bitmap,
404 void *opaque));
405 int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
406 uint32_t size);
407 int kvm_unregister_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
408 uint32_t size);
411 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
413 * \param kvm Pointer to the current kvm_context
414 * \param phys_addr Memory slot phys addr
415 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
417 int kvm_get_mem_map(kvm_context_t kvm, unsigned long phys_addr, void *bitmap);
418 int kvm_get_mem_map_range(kvm_context_t kvm, unsigned long phys_addr,
419 unsigned long len, void *buf, void *opaque,
420 int (*cb)(unsigned long start,
421 unsigned long len, void *bitmap,
422 void *opaque));
423 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
425 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm, uint64_t phys_start,
426 uint64_t len);
427 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm, uint64_t phys_start,
428 uint64_t len);
430 * \brief Enable dirty-pages-logging for all memory regions
432 * \param kvm Pointer to the current kvm_context
434 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
437 * \brief Disable dirty-page-logging for some memory regions
439 * Disable dirty-pages-logging for those memory regions that were
440 * created with dirty-page-logging disabled.
442 * \param kvm Pointer to the current kvm_context
444 int kvm_dirty_pages_log_reset(kvm_context_t kvm);
446 #ifdef KVM_CAP_IRQCHIP
448 * \brief Dump in kernel IRQCHIP contents
450 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
451 * and IOAPIC into a kvm_irqchip structure
453 * \param kvm Pointer to the current kvm_context
454 * \param chip The irq chip device to be dumped
456 int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
459 * \brief Set in kernel IRQCHIP contents
461 * Write one of the in kernel irq chip devices, including PIC (master/slave)
462 * and IOAPIC
465 * \param kvm Pointer to the current kvm_context
466 * \param chip THe irq chip device to be written
468 int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
470 #if defined(__i386__) || defined(__x86_64__)
472 * \brief Get in kernel local APIC for vcpu
474 * Save the local apic state including the timer of a virtual CPU
476 * \param kvm Pointer to the current kvm_context
477 * \param vcpu Which virtual CPU should be accessed
478 * \param s Local apic state of the specific virtual CPU
480 int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
483 * \brief Set in kernel local APIC for vcpu
485 * Restore the local apic state including the timer of a virtual CPU
487 * \param kvm Pointer to the current kvm_context
488 * \param vcpu Which virtual CPU should be accessed
489 * \param s Local apic state of the specific virtual CPU
491 int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
493 #endif
496 * \brief Simulate an NMI
498 * This allows you to simulate a non-maskable interrupt.
500 * \param kvm Pointer to the current kvm_context
501 * \param vcpu Which virtual CPU should get dumped
502 * \return 0 on success
504 int kvm_inject_nmi(CPUState *env);
506 #endif
509 * \brief Initialize coalesced MMIO
511 * Check for coalesced MMIO capability and store in context
513 * \param kvm Pointer to the current kvm_context
515 int kvm_init_coalesced_mmio(kvm_context_t kvm);
517 #ifdef KVM_CAP_PIT
519 #if defined(__i386__) || defined(__x86_64__)
521 * \brief Get in kernel PIT of the virtual domain
523 * Save the PIT state.
525 * \param kvm Pointer to the current kvm_context
526 * \param s PIT state of the virtual domain
528 int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);
531 * \brief Set in kernel PIT of the virtual domain
533 * Restore the PIT state.
534 * Timer would be retriggerred after restored.
536 * \param kvm Pointer to the current kvm_context
537 * \param s PIT state of the virtual domain
539 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
541 int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
543 #ifdef KVM_CAP_PIT_STATE2
545 * \brief Check for kvm support of kvm_pit_state2
547 * \param kvm Pointer to the current kvm_context
548 * \return 0 on success
550 int kvm_has_pit_state2(kvm_context_t kvm);
553 * \brief Set in kernel PIT state2 of the virtual domain
556 * \param kvm Pointer to the current kvm_context
557 * \param ps2 PIT state2 of the virtual domain
558 * \return 0 on success
560 int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
563 * \brief Get in kernel PIT state2 of the virtual domain
566 * \param kvm Pointer to the current kvm_context
567 * \param ps2 PIT state2 of the virtual domain
568 * \return 0 on success
570 int kvm_get_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
572 #endif
573 #endif
574 #endif
576 #ifdef KVM_CAP_VAPIC
578 int kvm_enable_vapic(CPUState *env, uint64_t vapic);
580 #endif
582 #if defined(__s390__)
583 int kvm_s390_initial_reset(kvm_context_t kvm, int slot);
584 int kvm_s390_interrupt(kvm_context_t kvm, int slot,
585 struct kvm_s390_interrupt *kvmint);
586 int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw);
587 int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr);
588 #endif
590 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
592 * \brief Notifies host kernel about a PCI device to be assigned to a guest
594 * Used for PCI device assignment, this function notifies the host
595 * kernel about the assigning of the physical PCI device to a guest.
597 * \param kvm Pointer to the current kvm_context
598 * \param assigned_dev Parameters, like bus, devfn number, etc
600 int kvm_assign_pci_device(kvm_context_t kvm,
601 struct kvm_assigned_pci_dev *assigned_dev);
604 * \brief Assign IRQ for an assigned device
606 * Used for PCI device assignment, this function assigns IRQ numbers for
607 * an physical device and guest IRQ handling.
609 * \param kvm Pointer to the current kvm_context
610 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
612 int kvm_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
614 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
616 * \brief Deassign IRQ for an assigned device
618 * Used for PCI device assignment, this function deassigns IRQ numbers
619 * for an assigned device.
621 * \param kvm Pointer to the current kvm_context
622 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
624 int kvm_deassign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
625 #endif
626 #endif
628 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
630 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
632 * Used for hot remove PCI device, this function notifies the host
633 * kernel about the deassigning of the physical PCI device from a guest.
635 * \param kvm Pointer to the current kvm_context
636 * \param assigned_dev Parameters, like bus, devfn number, etc
638 int kvm_deassign_pci_device(kvm_context_t kvm,
639 struct kvm_assigned_pci_dev *assigned_dev);
640 #endif
643 * \brief Determines the number of gsis that can be routed
645 * Returns the number of distinct gsis that can be routed by kvm. This is
646 * also the number of distinct routes (if a gsi has two routes, than another
647 * gsi cannot be used...)
649 * \param kvm Pointer to the current kvm_context
651 int kvm_get_gsi_count(kvm_context_t kvm);
654 * \brief Clears the temporary irq routing table
656 * Clears the temporary irq routing table. Nothing is committed to the
657 * running VM.
660 int kvm_clear_gsi_routes(void);
663 * \brief Adds an irq route to the temporary irq routing table
665 * Adds an irq route to the temporary irq routing table. Nothing is
666 * committed to the running VM.
668 int kvm_add_irq_route(int gsi, int irqchip, int pin);
671 * \brief Removes an irq route from the temporary irq routing table
673 * Adds an irq route to the temporary irq routing table. Nothing is
674 * committed to the running VM.
676 int kvm_del_irq_route(int gsi, int irqchip, int pin);
678 struct kvm_irq_routing_entry;
680 * \brief Adds a routing entry to the temporary irq routing table
682 * Adds a filled routing entry to the temporary irq routing table. Nothing is
683 * committed to the running VM.
685 int kvm_add_routing_entry(struct kvm_irq_routing_entry *entry);
688 * \brief Removes a routing from the temporary irq routing table
690 * Remove a routing to the temporary irq routing table. Nothing is
691 * committed to the running VM.
693 int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry);
696 * \brief Updates a routing in the temporary irq routing table
698 * Update a routing in the temporary irq routing table
699 * with a new value. entry type and GSI can not be changed.
700 * Nothing is committed to the running VM.
702 int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,
703 struct kvm_irq_routing_entry *newentry);
707 * \brief Create a file descriptor for injecting interrupts
709 * Creates an eventfd based file-descriptor that maps to a specific GSI
710 * in the guest. eventfd compliant signaling (write() from userspace, or
711 * eventfd_signal() from kernelspace) will cause the GSI to inject
712 * itself into the guest at the next available window.
714 * \param kvm Pointer to the current kvm_context
715 * \param gsi GSI to assign to this fd
716 * \param flags reserved, must be zero
718 int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
720 #ifdef KVM_CAP_DEVICE_MSIX
721 int kvm_assign_set_msix_nr(kvm_context_t kvm,
722 struct kvm_assigned_msix_nr *msix_nr);
723 int kvm_assign_set_msix_entry(kvm_context_t kvm,
724 struct kvm_assigned_msix_entry *entry);
725 #endif
727 #else /* !CONFIG_KVM */
729 typedef struct kvm_context *kvm_context_t;
730 typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
732 struct kvm_pit_state {
735 #endif /* !CONFIG_KVM */
739 * \brief Create new KVM context
741 * This creates a new kvm_context. A KVM context is a small area of data that
742 * holds information about the KVM instance that gets created by this call.\n
743 * This should always be your first call to KVM.
745 * \param opaque Not used
746 * \return NULL on failure
748 int kvm_init(int smp_cpus);
750 int kvm_main_loop(void);
751 int kvm_init_ap(void);
752 int kvm_vcpu_inited(CPUState *env);
753 void kvm_save_lapic(CPUState *env);
754 void kvm_load_lapic(CPUState *env);
756 void kvm_hpet_enable_kpit(void);
757 void kvm_hpet_disable_kpit(void);
759 int kvm_physical_memory_set_dirty_tracking(int enable);
761 void on_vcpu(CPUState *env, void (*func)(void *data), void *data);
762 void qemu_kvm_call_with_env(void (*func)(void *), void *data, CPUState *env);
763 void qemu_kvm_cpuid_on_env(CPUState *env);
764 void kvm_inject_interrupt(CPUState *env, int mask);
765 void kvm_update_after_sipi(CPUState *env);
766 void kvm_update_interrupt_request(CPUState *env);
767 #ifndef CONFIG_USER_ONLY
768 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, unsigned long size,
769 int log, int writable);
771 void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr,
772 unsigned long size);
773 void kvm_qemu_log_memory(target_phys_addr_t start, target_phys_addr_t size,
774 int log);
775 #endif
776 int kvm_qemu_create_memory_alias(uint64_t phys_start, uint64_t len,
777 uint64_t target_phys);
778 int kvm_qemu_destroy_memory_alias(uint64_t phys_start);
780 int kvm_arch_qemu_create_context(void);
782 void kvm_arch_save_regs(CPUState *env);
783 void kvm_arch_load_regs(CPUState *env, int level);
784 int kvm_arch_has_work(CPUState *env);
785 void kvm_arch_process_irqchip_events(CPUState *env);
786 int kvm_arch_try_push_interrupts(void *opaque);
787 void kvm_arch_push_nmi(void *opaque);
788 void kvm_arch_cpu_reset(CPUState *env);
789 int kvm_set_boot_cpu_id(uint32_t id);
791 void qemu_kvm_aio_wait_start(void);
792 void qemu_kvm_aio_wait(void);
793 void qemu_kvm_aio_wait_end(void);
795 void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
797 int kvm_arch_init_irq_routing(void);
799 int kvm_mmio_read(void *opaque, uint64_t addr, uint8_t * data, int len);
800 int kvm_mmio_write(void *opaque, uint64_t addr, uint8_t * data, int len);
802 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
803 struct ioperm_data;
805 void kvm_ioperm(CPUState *env, void *data);
806 void kvm_add_ioperm_data(struct ioperm_data *data);
807 void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
808 void kvm_arch_do_ioperm(void *_data);
809 #endif
811 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
812 #define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
814 #ifdef CONFIG_KVM
815 #include "qemu-queue.h"
817 extern int kvm_irqchip;
818 extern int kvm_pit;
819 extern int kvm_pit_reinject;
820 extern int kvm_nested;
821 extern kvm_context_t kvm_context;
823 struct ioperm_data {
824 unsigned long start_port;
825 unsigned long num;
826 int turn_on;
827 QLIST_ENTRY(ioperm_data) entries;
830 void qemu_kvm_cpu_stop(CPUState *env);
831 int kvm_arch_halt(CPUState *env);
832 int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
833 int is_write);
835 #define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing()
836 #ifdef TARGET_I386
837 #define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
838 #endif
839 #else
840 #define kvm_nested 0
841 #define qemu_kvm_has_gsi_routing() (0)
842 #ifdef TARGET_I386
843 #define qemu_kvm_has_pit_state2() (0)
844 #endif
845 #define qemu_kvm_cpu_stop(env) do {} while(0)
846 #endif
848 #ifdef CONFIG_KVM
850 typedef struct KVMSlot {
851 target_phys_addr_t start_addr;
852 ram_addr_t memory_size;
853 ram_addr_t phys_offset;
854 int slot;
855 int flags;
856 } KVMSlot;
858 typedef struct kvm_dirty_log KVMDirtyLog;
860 struct KVMState {
861 KVMSlot slots[32];
862 int fd;
863 int vmfd;
864 int coalesced_mmio;
865 #ifdef KVM_CAP_COALESCED_MMIO
866 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
867 #endif
868 int broken_set_mem_region;
869 int migration_log;
870 int vcpu_events;
871 int robust_singlestep;
872 int debugregs;
873 #ifdef KVM_CAP_SET_GUEST_DEBUG
874 QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints;
875 #endif
876 int irqchip_in_kernel;
877 int pit_in_kernel;
879 struct kvm_context kvm_context;
882 extern struct KVMState *kvm_state;
884 int kvm_tpr_enable_vapic(CPUState *env);
886 unsigned long kvm_get_thread_id(void);
887 int kvm_cpu_is_stopped(CPUState *env);
889 #endif
891 #endif