Add io memory to test device
[qemu-kvm/amd-iommu.git] / qemu-kvm.h
blobecb52c1f62e02a386d0b13641d2d0f7ccaaf7ff8
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 struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
101 int kvm_get_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n);
102 int kvm_set_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n);
103 int kvm_get_mce_cap_supported(kvm_context_t, uint64_t *mce_cap,
104 int *max_banks);
105 int kvm_setup_mce(CPUState *env, uint64_t *mcg_cap);
106 struct kvm_x86_mce;
107 int kvm_set_mce(CPUState *env, struct kvm_x86_mce *mce);
108 #endif
111 * \brief Create new KVM context
113 * This creates a new kvm_context. A KVM context is a small area of data that
114 * holds information about the KVM instance that gets created by this call.\n
115 * This should always be your first call to KVM.
117 * \param opaque Not used
118 * \return NULL on failure
120 int kvm_init(int smp_cpus);
123 * \brief Disable the in-kernel IRQCHIP creation
125 * In-kernel irqchip is enabled by default. If userspace irqchip is to be used,
126 * this should be called prior to kvm_create().
128 * \param kvm Pointer to the kvm_context
130 void kvm_disable_irqchip_creation(kvm_context_t kvm);
133 * \brief Disable the in-kernel PIT creation
135 * In-kernel pit is enabled by default. If userspace pit is to be used,
136 * this should be called prior to kvm_create().
138 * \param kvm Pointer to the kvm_context
140 void kvm_disable_pit_creation(kvm_context_t kvm);
143 * \brief Create new virtual machine
145 * This creates a new virtual machine, maps physical RAM to it, and creates a
146 * virtual CPU for it.\n
147 * \n
148 * Memory gets mapped for addresses 0->0xA0000, 0xC0000->phys_mem_bytes
150 * \param kvm Pointer to the current kvm_context
151 * \param phys_mem_bytes The amount of physical ram you want the VM to have
152 * \param phys_mem This pointer will be set to point to the memory that
153 * kvm_create allocates for physical RAM
154 * \return 0 on success
156 int kvm_create(kvm_context_t kvm, unsigned long phys_mem_bytes,
157 void **phys_mem);
158 int kvm_create_vm(kvm_context_t kvm);
159 void kvm_create_irqchip(kvm_context_t kvm);
162 * \brief Start the VCPU
164 * This starts the VCPU and virtualization is started.\n
165 * \n
166 * This function will not return until any of these conditions are met:
167 * - An IO/MMIO handler does not return "0"
168 * - An exception that neither the guest OS, nor KVM can handle occurs
170 * \note This function will call the callbacks registered in kvm_init()
171 * to emulate those functions
172 * \note If you at any point want to interrupt the VCPU, kvm_run() will
173 * listen to the EINTR signal. This allows you to simulate external interrupts
174 * and asyncronous IO.
176 * \param kvm Pointer to the current kvm_context
177 * \param vcpu Which virtual CPU should be started
178 * \return 0 on success, but you really shouldn't expect this function to
179 * return except for when an error has occured, or when you have sent it
180 * an EINTR signal.
182 int kvm_run(CPUState *env);
185 * \brief Check if a vcpu is ready for interrupt injection
187 * This checks if vcpu interrupts are not masked by mov ss or sti.
189 * \param kvm Pointer to the current kvm_context
190 * \param vcpu Which virtual CPU should get dumped
191 * \return boolean indicating interrupt injection readiness
193 int kvm_is_ready_for_interrupt_injection(CPUState *env);
196 * \brief Read VCPU registers
198 * This gets the GP registers from the VCPU and outputs them
199 * into a kvm_regs structure
201 * \note This function returns a \b copy of the VCPUs registers.\n
202 * If you wish to modify the VCPUs GP registers, you should call kvm_set_regs()
204 * \param kvm Pointer to the current kvm_context
205 * \param vcpu Which virtual CPU should get dumped
206 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
207 * registers values
208 * \return 0 on success
210 int kvm_get_regs(CPUState *env, struct kvm_regs *regs);
213 * \brief Write VCPU registers
215 * This sets the GP registers on the VCPU from a kvm_regs structure
217 * \note When this function returns, the regs pointer and the data it points to
218 * can be discarded
219 * \param kvm Pointer to the current kvm_context
220 * \param vcpu Which virtual CPU should get dumped
221 * \param regs Pointer to a kvm_regs which will be populated with the VCPUs
222 * registers values
223 * \return 0 on success
225 int kvm_set_regs(CPUState *env, struct kvm_regs *regs);
227 * \brief Read VCPU fpu registers
229 * This gets the FPU registers from the VCPU and outputs them
230 * into a kvm_fpu structure
232 * \note This function returns a \b copy of the VCPUs registers.\n
233 * If you wish to modify the VCPU FPU registers, you should call kvm_set_fpu()
235 * \param kvm Pointer to the current kvm_context
236 * \param vcpu Which virtual CPU should get dumped
237 * \param fpu Pointer to a kvm_fpu which will be populated with the VCPUs
238 * fpu registers values
239 * \return 0 on success
241 int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu);
244 * \brief Write VCPU fpu registers
246 * This sets the FPU registers on the VCPU from a kvm_fpu structure
248 * \note When this function returns, the fpu pointer and the data it points to
249 * can be discarded
250 * \param kvm Pointer to the current kvm_context
251 * \param vcpu Which virtual CPU should get dumped
252 * \param fpu Pointer to a kvm_fpu which holds the new vcpu fpu state
253 * \return 0 on success
255 int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu);
258 * \brief Read VCPU system registers
260 * This gets the non-GP registers from the VCPU and outputs them
261 * into a kvm_sregs structure
263 * \note This function returns a \b copy of the VCPUs registers.\n
264 * If you wish to modify the VCPUs non-GP registers, you should call
265 * kvm_set_sregs()
267 * \param kvm Pointer to the current kvm_context
268 * \param vcpu Which virtual CPU should get dumped
269 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
270 * registers values
271 * \return 0 on success
273 int kvm_get_sregs(CPUState *env, struct kvm_sregs *regs);
276 * \brief Write VCPU system registers
278 * This sets the non-GP registers on the VCPU from a kvm_sregs structure
280 * \note When this function returns, the regs pointer and the data it points to
281 * can be discarded
282 * \param kvm Pointer to the current kvm_context
283 * \param vcpu Which virtual CPU should get dumped
284 * \param regs Pointer to a kvm_sregs which will be populated with the VCPUs
285 * registers values
286 * \return 0 on success
288 int kvm_set_sregs(CPUState *env, struct kvm_sregs *regs);
290 #ifdef KVM_CAP_MP_STATE
292 * * \brief Read VCPU MP state
295 int kvm_get_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
298 * * \brief Write VCPU MP state
301 int kvm_set_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
303 * * \brief Reset VCPU MP state
306 static inline int kvm_reset_mpstate(CPUState *env)
308 struct kvm_mp_state mp_state = {.mp_state = KVM_MP_STATE_UNINITIALIZED
310 return kvm_set_mpstate(env, &mp_state);
312 #endif
315 * \brief Simulate an external vectored interrupt
317 * This allows you to simulate an external vectored interrupt.
319 * \param kvm Pointer to the current kvm_context
320 * \param vcpu Which virtual CPU should get dumped
321 * \param irq Vector number
322 * \return 0 on success
324 int kvm_inject_irq(CPUState *env, unsigned irq);
326 #if defined(__i386__) || defined(__x86_64__)
328 * \brief Setup a vcpu's cpuid instruction emulation
330 * Set up a table of cpuid function to cpuid outputs.\n
332 * \param kvm Pointer to the current kvm_context
333 * \param vcpu Which virtual CPU should be initialized
334 * \param nent number of entries to be installed
335 * \param entries cpuid function entries table
336 * \return 0 on success, or -errno on error
338 int kvm_setup_cpuid(CPUState *env, int nent,
339 struct kvm_cpuid_entry *entries);
342 * \brief Setup a vcpu's cpuid instruction emulation
344 * Set up a table of cpuid function to cpuid outputs.
345 * This call replaces the older kvm_setup_cpuid interface by adding a few
346 * parameters to support cpuid functions that have sub-leaf values.
348 * \param kvm Pointer to the current kvm_context
349 * \param vcpu Which virtual CPU should be initialized
350 * \param nent number of entries to be installed
351 * \param entries cpuid function entries table
352 * \return 0 on success, or -errno on error
354 int kvm_setup_cpuid2(CPUState *env, int nent,
355 struct kvm_cpuid_entry2 *entries);
358 * \brief Setting the number of shadow pages to be allocated to the vm
360 * \param kvm pointer to kvm_context
361 * \param nrshadow_pages number of pages to be allocated
363 int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
366 * \brief Getting the number of shadow pages that are allocated to the vm
368 * \param kvm pointer to kvm_context
369 * \param nrshadow_pages number of pages to be allocated
371 int kvm_get_shadow_pages(kvm_context_t kvm, unsigned int *nrshadow_pages);
373 #endif
376 * \brief Dump VCPU registers
378 * This dumps some of the information that KVM has about a virtual CPU, namely:
379 * - GP Registers
381 * A much more verbose version of this is available as kvm_dump_vcpu()
383 * \param kvm Pointer to the current kvm_context
384 * \param vcpu Which virtual CPU should get dumped
385 * \return 0 on success
387 void kvm_show_regs(CPUState *env);
390 void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start,
391 unsigned long len, int log, int writable);
392 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start,
393 unsigned long len);
394 void kvm_unregister_memory_area(kvm_context_t, uint64_t phys_start,
395 unsigned long len);
397 int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start,
398 unsigned long size);
399 int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start,
400 void *userspace_addr, unsigned long len, int log);
401 int kvm_get_dirty_pages(kvm_context_t, unsigned long phys_addr, void *buf);
402 int kvm_get_dirty_pages_range(kvm_context_t kvm, unsigned long phys_addr,
403 unsigned long end_addr, void *opaque,
404 int (*cb)(unsigned long start,
405 unsigned long len, void *bitmap,
406 void *opaque));
407 int kvm_register_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
408 uint32_t size);
409 int kvm_unregister_coalesced_mmio(kvm_context_t kvm, uint64_t addr,
410 uint32_t size);
413 * \brief Create a memory alias
415 * Aliases a portion of physical memory to another portion. If the guest
416 * accesses the alias region, it will behave exactly as if it accessed
417 * the target memory.
419 int kvm_create_memory_alias(kvm_context_t, uint64_t phys_start, uint64_t len,
420 uint64_t target_phys);
423 * \brief Destroy a memory alias
425 * Removes an alias created with kvm_create_memory_alias().
427 int kvm_destroy_memory_alias(kvm_context_t, uint64_t phys_start);
430 * \brief Get a bitmap of guest ram pages which are allocated to the guest.
432 * \param kvm Pointer to the current kvm_context
433 * \param phys_addr Memory slot phys addr
434 * \param bitmap Long aligned address of a big enough bitmap (one bit per page)
436 int kvm_get_mem_map(kvm_context_t kvm, unsigned long phys_addr, void *bitmap);
437 int kvm_get_mem_map_range(kvm_context_t kvm, unsigned long phys_addr,
438 unsigned long len, void *buf, void *opaque,
439 int (*cb)(unsigned long start,
440 unsigned long len, void *bitmap,
441 void *opaque));
442 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
444 int kvm_dirty_pages_log_enable_slot(kvm_context_t kvm, uint64_t phys_start,
445 uint64_t len);
446 int kvm_dirty_pages_log_disable_slot(kvm_context_t kvm, uint64_t phys_start,
447 uint64_t len);
449 * \brief Enable dirty-pages-logging for all memory regions
451 * \param kvm Pointer to the current kvm_context
453 int kvm_dirty_pages_log_enable_all(kvm_context_t kvm);
456 * \brief Disable dirty-page-logging for some memory regions
458 * Disable dirty-pages-logging for those memory regions that were
459 * created with dirty-page-logging disabled.
461 * \param kvm Pointer to the current kvm_context
463 int kvm_dirty_pages_log_reset(kvm_context_t kvm);
465 #ifdef KVM_CAP_IRQCHIP
467 * \brief Dump in kernel IRQCHIP contents
469 * Dump one of the in kernel irq chip devices, including PIC (master/slave)
470 * and IOAPIC into a kvm_irqchip structure
472 * \param kvm Pointer to the current kvm_context
473 * \param chip The irq chip device to be dumped
475 int kvm_get_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
478 * \brief Set in kernel IRQCHIP contents
480 * Write one of the in kernel irq chip devices, including PIC (master/slave)
481 * and IOAPIC
484 * \param kvm Pointer to the current kvm_context
485 * \param chip THe irq chip device to be written
487 int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip);
489 #if defined(__i386__) || defined(__x86_64__)
491 * \brief Get in kernel local APIC for vcpu
493 * Save the local apic state including the timer of a virtual CPU
495 * \param kvm Pointer to the current kvm_context
496 * \param vcpu Which virtual CPU should be accessed
497 * \param s Local apic state of the specific virtual CPU
499 int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
502 * \brief Set in kernel local APIC for vcpu
504 * Restore the local apic state including the timer of a virtual CPU
506 * \param kvm Pointer to the current kvm_context
507 * \param vcpu Which virtual CPU should be accessed
508 * \param s Local apic state of the specific virtual CPU
510 int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
512 #endif
515 * \brief Simulate an NMI
517 * This allows you to simulate a non-maskable interrupt.
519 * \param kvm Pointer to the current kvm_context
520 * \param vcpu Which virtual CPU should get dumped
521 * \return 0 on success
523 int kvm_inject_nmi(CPUState *env);
525 #endif
528 * \brief Simulate an x86 MCE
530 * This allows you to simulate a x86 MCE.
532 * \param cenv Which virtual CPU should get MCE injected
533 * \param bank Bank number
534 * \param status MSR_MCI_STATUS
535 * \param mcg_status MSR_MCG_STATUS
536 * \param addr MSR_MCI_ADDR
537 * \param misc MSR_MCI_MISC
538 * \param abort_on_error abort on error
540 void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t status,
541 uint64_t mcg_status, uint64_t addr, uint64_t misc,
542 int abort_on_error);
545 * \brief Initialize coalesced MMIO
547 * Check for coalesced MMIO capability and store in context
549 * \param kvm Pointer to the current kvm_context
551 int kvm_init_coalesced_mmio(kvm_context_t kvm);
553 #ifdef KVM_CAP_PIT
555 #if defined(__i386__) || defined(__x86_64__)
557 * \brief Get in kernel PIT of the virtual domain
559 * Save the PIT state.
561 * \param kvm Pointer to the current kvm_context
562 * \param s PIT state of the virtual domain
564 int kvm_get_pit(kvm_context_t kvm, struct kvm_pit_state *s);
567 * \brief Set in kernel PIT of the virtual domain
569 * Restore the PIT state.
570 * Timer would be retriggerred after restored.
572 * \param kvm Pointer to the current kvm_context
573 * \param s PIT state of the virtual domain
575 int kvm_set_pit(kvm_context_t kvm, struct kvm_pit_state *s);
577 int kvm_reinject_control(kvm_context_t kvm, int pit_reinject);
579 #ifdef KVM_CAP_PIT_STATE2
581 * \brief Check for kvm support of kvm_pit_state2
583 * \param kvm Pointer to the current kvm_context
584 * \return 0 on success
586 int kvm_has_pit_state2(kvm_context_t kvm);
589 * \brief Set in kernel PIT state2 of the virtual domain
592 * \param kvm Pointer to the current kvm_context
593 * \param ps2 PIT state2 of the virtual domain
594 * \return 0 on success
596 int kvm_set_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
599 * \brief Get in kernel PIT state2 of the virtual domain
602 * \param kvm Pointer to the current kvm_context
603 * \param ps2 PIT state2 of the virtual domain
604 * \return 0 on success
606 int kvm_get_pit2(kvm_context_t kvm, struct kvm_pit_state2 *ps2);
608 #endif
609 #endif
610 #endif
612 #ifdef KVM_CAP_VAPIC
615 * \brief Enable kernel tpr access reporting
617 * When tpr access reporting is enabled, the kernel will call the
618 * ->tpr_access() callback every time the guest vcpu accesses the tpr.
620 * \param kvm Pointer to the current kvm_context
621 * \param vcpu vcpu to enable tpr access reporting on
623 int kvm_enable_tpr_access_reporting(CPUState *env);
626 * \brief Disable kernel tpr access reporting
628 * Undoes the effect of kvm_enable_tpr_access_reporting().
630 * \param kvm Pointer to the current kvm_context
631 * \param vcpu vcpu to disable tpr access reporting on
633 int kvm_disable_tpr_access_reporting(CPUState *env);
635 int kvm_enable_vapic(CPUState *env, uint64_t vapic);
637 #endif
639 #if defined(__s390__)
640 int kvm_s390_initial_reset(kvm_context_t kvm, int slot);
641 int kvm_s390_interrupt(kvm_context_t kvm, int slot,
642 struct kvm_s390_interrupt *kvmint);
643 int kvm_s390_set_initial_psw(kvm_context_t kvm, int slot, psw_t psw);
644 int kvm_s390_store_status(kvm_context_t kvm, int slot, unsigned long addr);
645 #endif
647 #ifdef KVM_CAP_DEVICE_ASSIGNMENT
649 * \brief Notifies host kernel about a PCI device to be assigned to a guest
651 * Used for PCI device assignment, this function notifies the host
652 * kernel about the assigning of the physical PCI device to a guest.
654 * \param kvm Pointer to the current kvm_context
655 * \param assigned_dev Parameters, like bus, devfn number, etc
657 int kvm_assign_pci_device(kvm_context_t kvm,
658 struct kvm_assigned_pci_dev *assigned_dev);
661 * \brief Assign IRQ for an assigned device
663 * Used for PCI device assignment, this function assigns IRQ numbers for
664 * an physical device and guest IRQ handling.
666 * \param kvm Pointer to the current kvm_context
667 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
669 int kvm_assign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
671 #ifdef KVM_CAP_ASSIGN_DEV_IRQ
673 * \brief Deassign IRQ for an assigned device
675 * Used for PCI device assignment, this function deassigns IRQ numbers
676 * for an assigned device.
678 * \param kvm Pointer to the current kvm_context
679 * \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
681 int kvm_deassign_irq(kvm_context_t kvm, struct kvm_assigned_irq *assigned_irq);
682 #endif
683 #endif
686 * \brief Determines whether destroying memory regions is allowed
688 * KVM before 2.6.29 had a bug when destroying memory regions.
690 * \param kvm Pointer to the current kvm_context
692 int kvm_destroy_memory_region_works(kvm_context_t kvm);
694 #ifdef KVM_CAP_DEVICE_DEASSIGNMENT
696 * \brief Notifies host kernel about a PCI device to be deassigned from a guest
698 * Used for hot remove PCI device, this function notifies the host
699 * kernel about the deassigning of the physical PCI device from a guest.
701 * \param kvm Pointer to the current kvm_context
702 * \param assigned_dev Parameters, like bus, devfn number, etc
704 int kvm_deassign_pci_device(kvm_context_t kvm,
705 struct kvm_assigned_pci_dev *assigned_dev);
706 #endif
709 * \brief Checks whether the generic irq routing capability is present
711 * Checks whether kvm can reroute interrupts among the various interrupt
712 * controllers.
714 * \param kvm Pointer to the current kvm_context
716 int kvm_has_gsi_routing(kvm_context_t kvm);
719 * \brief Determines the number of gsis that can be routed
721 * Returns the number of distinct gsis that can be routed by kvm. This is
722 * also the number of distinct routes (if a gsi has two routes, than another
723 * gsi cannot be used...)
725 * \param kvm Pointer to the current kvm_context
727 int kvm_get_gsi_count(kvm_context_t kvm);
730 * \brief Clears the temporary irq routing table
732 * Clears the temporary irq routing table. Nothing is committed to the
733 * running VM.
735 * \param kvm Pointer to the current kvm_context
737 int kvm_clear_gsi_routes(kvm_context_t kvm);
740 * \brief Adds an irq route to the temporary irq routing table
742 * Adds an irq route to the temporary irq routing table. Nothing is
743 * committed to the running VM.
745 * \param kvm Pointer to the current kvm_context
747 int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
750 * \brief Removes an irq route from the temporary irq routing table
752 * Adds an irq route to the temporary irq routing table. Nothing is
753 * committed to the running VM.
755 * \param kvm Pointer to the current kvm_context
757 int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin);
759 struct kvm_irq_routing_entry;
761 * \brief Adds a routing entry to the temporary irq routing table
763 * Adds a filled routing entry to the temporary irq routing table. Nothing is
764 * committed to the running VM.
766 * \param kvm Pointer to the current kvm_context
768 int kvm_add_routing_entry(kvm_context_t kvm,
769 struct kvm_irq_routing_entry *entry);
772 * \brief Removes a routing from the temporary irq routing table
774 * Remove a routing to the temporary irq routing table. Nothing is
775 * committed to the running VM.
777 * \param kvm Pointer to the current kvm_context
779 int kvm_del_routing_entry(kvm_context_t kvm,
780 struct kvm_irq_routing_entry *entry);
783 * \brief Updates a routing in the temporary irq routing table
785 * Update a routing in the temporary irq routing table
786 * with a new value. entry type and GSI can not be changed.
787 * Nothing is committed to the running VM.
789 * \param kvm Pointer to the current kvm_context
791 int kvm_update_routing_entry(kvm_context_t kvm,
792 struct kvm_irq_routing_entry *entry,
793 struct kvm_irq_routing_entry *newentry);
796 * \brief Commit the temporary irq routing table
798 * Commit the temporary irq routing table to the running VM.
800 * \param kvm Pointer to the current kvm_context
802 int kvm_commit_irq_routes(kvm_context_t kvm);
805 * \brief Get unused GSI number for irq routing table
807 * Get unused GSI number for irq routing table
809 * \param kvm Pointer to the current kvm_context
811 int kvm_get_irq_route_gsi(kvm_context_t kvm);
814 * \brief Create a file descriptor for injecting interrupts
816 * Creates an eventfd based file-descriptor that maps to a specific GSI
817 * in the guest. eventfd compliant signaling (write() from userspace, or
818 * eventfd_signal() from kernelspace) will cause the GSI to inject
819 * itself into the guest at the next available window.
821 * \param kvm Pointer to the current kvm_context
822 * \param gsi GSI to assign to this fd
823 * \param flags reserved, must be zero
825 int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
827 #ifdef KVM_CAP_DEVICE_MSIX
828 int kvm_assign_set_msix_nr(kvm_context_t kvm,
829 struct kvm_assigned_msix_nr *msix_nr);
830 int kvm_assign_set_msix_entry(kvm_context_t kvm,
831 struct kvm_assigned_msix_entry *entry);
832 #endif
834 #else /* !CONFIG_KVM */
836 typedef struct kvm_context *kvm_context_t;
837 typedef struct kvm_vcpu_context *kvm_vcpu_context_t;
839 struct kvm_pit_state {
842 static inline int kvm_init(int smp_cpus)
844 return 0;
847 static inline void kvm_inject_x86_mce(CPUState *cenv, int bank,
848 uint64_t status, uint64_t mcg_status,
849 uint64_t addr, uint64_t misc,
850 int abort_on_error)
852 if (abort_on_error)
853 abort();
856 #endif /* !CONFIG_KVM */
859 int kvm_main_loop(void);
860 int kvm_init_ap(void);
861 int kvm_vcpu_inited(CPUState *env);
862 void kvm_load_mpstate(CPUState *env);
863 void kvm_save_mpstate(CPUState *env);
864 void kvm_apic_init(CPUState *env);
865 /* called from vcpu initialization */
866 void qemu_kvm_load_lapic(CPUState *env);
868 void kvm_hpet_enable_kpit(void);
869 void kvm_hpet_disable_kpit(void);
870 int kvm_set_irq(int irq, int level, int *status);
872 int kvm_physical_memory_set_dirty_tracking(int enable);
873 int kvm_update_dirty_pages_log(void);
875 void qemu_kvm_call_with_env(void (*func)(void *), void *data, CPUState *env);
876 void qemu_kvm_cpuid_on_env(CPUState *env);
877 void kvm_inject_interrupt(CPUState *env, int mask);
878 void kvm_update_after_sipi(CPUState *env);
879 void kvm_update_interrupt_request(CPUState *env);
880 void kvm_set_phys_mem(target_phys_addr_t start_addr, ram_addr_t size,
881 ram_addr_t phys_offset);
882 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr, unsigned long size,
883 int log, int writable);
885 void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr,
886 unsigned long size);
887 void kvm_qemu_log_memory(target_phys_addr_t start, target_phys_addr_t size,
888 int log);
889 int kvm_qemu_create_memory_alias(uint64_t phys_start, uint64_t len,
890 uint64_t target_phys);
891 int kvm_qemu_destroy_memory_alias(uint64_t phys_start);
893 int kvm_arch_qemu_create_context(void);
895 void kvm_arch_save_regs(CPUState *env);
896 void kvm_arch_load_regs(CPUState *env);
897 void kvm_arch_load_mpstate(CPUState *env);
898 void kvm_arch_save_mpstate(CPUState *env);
899 int kvm_arch_has_work(CPUState *env);
900 void kvm_arch_process_irqchip_events(CPUState *env);
901 int kvm_arch_try_push_interrupts(void *opaque);
902 void kvm_arch_push_nmi(void *opaque);
903 void kvm_arch_cpu_reset(CPUState *env);
904 int kvm_set_boot_cpu_id(uint32_t id);
906 void qemu_kvm_aio_wait_start(void);
907 void qemu_kvm_aio_wait(void);
908 void qemu_kvm_aio_wait_end(void);
910 void qemu_kvm_notify_work(void);
912 void kvm_tpr_opt_setup(void);
913 void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
914 void kvm_tpr_vcpu_start(CPUState *env);
916 int qemu_kvm_get_dirty_pages(unsigned long phys_addr, void *buf);
918 int kvm_arch_init_irq_routing(void);
920 int kvm_mmio_read(void *opaque, uint64_t addr, uint8_t * data, int len);
921 int kvm_mmio_write(void *opaque, uint64_t addr, uint8_t * data, int len);
923 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
924 struct ioperm_data;
926 void kvm_ioperm(CPUState *env, void *data);
927 void kvm_add_ioperm_data(struct ioperm_data *data);
928 void kvm_remove_ioperm_data(unsigned long start_port, unsigned long num);
929 void kvm_arch_do_ioperm(void *_data);
930 #endif
932 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
933 #define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
935 #ifdef CONFIG_KVM
936 #include "qemu-queue.h"
938 extern int kvm_irqchip;
939 extern int kvm_pit;
940 extern int kvm_pit_reinject;
941 extern int kvm_nested;
942 extern kvm_context_t kvm_context;
944 struct ioperm_data {
945 unsigned long start_port;
946 unsigned long num;
947 int turn_on;
948 QLIST_ENTRY(ioperm_data) entries;
951 void qemu_kvm_cpu_stop(CPUState *env);
952 int kvm_arch_halt(CPUState *env);
953 int handle_tpr_access(void *opaque, CPUState *env, uint64_t rip,
954 int is_write);
956 #define qemu_kvm_has_gsi_routing() kvm_has_gsi_routing(kvm_context)
957 #ifdef TARGET_I386
958 #define qemu_kvm_has_pit_state2() kvm_has_pit_state2(kvm_context)
959 #endif
960 void kvm_load_tsc(CPUState *env);
961 #else
962 #define kvm_nested 0
963 #define qemu_kvm_has_gsi_routing() (0)
964 #ifdef TARGET_I386
965 #define qemu_kvm_has_pit_state2() (0)
966 #endif
967 #define kvm_save_mpstate(env) do {} while(0)
968 #define qemu_kvm_cpu_stop(env) do {} while(0)
969 static inline void kvm_load_tsc(CPUState *env)
972 #endif
974 void kvm_mutex_unlock(void);
975 void kvm_mutex_lock(void);
977 int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
978 target_phys_addr_t end_addr);
981 static inline int kvm_sync_vcpus(void)
983 return 0;
986 static inline int kvm_set_migration_log(int enable)
988 return kvm_physical_memory_set_dirty_tracking(enable);
992 #ifdef CONFIG_KVM
994 typedef struct KVMSlot {
995 target_phys_addr_t start_addr;
996 ram_addr_t memory_size;
997 ram_addr_t phys_offset;
998 int slot;
999 int flags;
1000 } KVMSlot;
1002 typedef struct kvm_dirty_log KVMDirtyLog;
1004 struct KVMState {
1005 KVMSlot slots[32];
1006 int fd;
1007 int vmfd;
1008 int coalesced_mmio;
1009 #ifdef KVM_CAP_COALESCED_MMIO
1010 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
1011 #endif
1012 int broken_set_mem_region;
1013 int migration_log;
1014 int vcpu_events;
1015 #ifdef KVM_CAP_SET_GUEST_DEBUG
1016 QTAILQ_HEAD(, kvm_sw_breakpoint) kvm_sw_breakpoints;
1017 #endif
1018 int irqchip_in_kernel;
1019 int pit_in_kernel;
1021 struct kvm_context kvm_context;
1024 extern struct KVMState *kvm_state;
1026 int kvm_tpr_enable_vapic(CPUState *env);
1028 unsigned long kvm_get_thread_id(void);
1029 int kvm_cpu_is_stopped(CPUState *env);
1031 #endif
1033 #endif