Merge branch 'qemu-cvs'
[kvm-userspace.git] / qemu / qemu-kvm.h
blob3aef05a2d6494a836c19eef6e9e7afe3f76002ca
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>
15 int kvm_main_loop(void);
16 int kvm_qemu_init(void);
17 int kvm_qemu_create_context(void);
18 int kvm_init_ap(void);
19 void kvm_qemu_destroy(void);
20 void kvm_load_registers(CPUState *env);
21 void kvm_save_registers(CPUState *env);
22 void kvm_load_mpstate(CPUState *env);
23 void kvm_save_mpstate(CPUState *env);
24 int kvm_cpu_exec(CPUState *env);
25 int kvm_update_debugger(CPUState *env);
26 int kvm_qemu_init_env(CPUState *env);
27 int kvm_qemu_check_extension(int ext);
28 void kvm_apic_init(CPUState *env);
29 int kvm_set_irq(int irq, int level);
31 int kvm_physical_memory_set_dirty_tracking(int enable);
32 int kvm_update_dirty_pages_log(void);
33 int kvm_get_phys_ram_page_bitmap(unsigned char *bitmap);
35 void qemu_kvm_call_with_env(void (*func)(void *), void *data, CPUState *env);
36 void qemu_kvm_cpuid_on_env(CPUState *env);
37 void kvm_inject_interrupt(CPUState *env, int mask);
38 void kvm_update_after_sipi(CPUState *env);
39 void kvm_update_interrupt_request(CPUState *env);
40 void kvm_cpu_register_physical_memory(target_phys_addr_t start_addr,
41 unsigned long size,
42 unsigned long phys_offset);
43 void kvm_cpu_unregister_physical_memory(target_phys_addr_t start_addr,
44 target_phys_addr_t size,
45 unsigned long phys_offset);
46 void *kvm_cpu_create_phys_mem(target_phys_addr_t start_addr,
47 unsigned long size, int log, int writable);
49 void kvm_cpu_destroy_phys_mem(target_phys_addr_t start_addr,
50 unsigned long size);
51 void kvm_qemu_log_memory(target_phys_addr_t start, target_phys_addr_t size,
52 int log);
53 int kvm_setup_guest_memory(void *area, unsigned long size);
54 int kvm_qemu_create_memory_alias(uint64_t phys_start,
55 uint64_t len,
56 uint64_t target_phys);
57 int kvm_qemu_destroy_memory_alias(uint64_t phys_start);
59 int kvm_arch_qemu_create_context(void);
61 void kvm_arch_save_regs(CPUState *env);
62 void kvm_arch_load_regs(CPUState *env);
63 int kvm_arch_qemu_init_env(CPUState *cenv);
64 int kvm_arch_halt(void *opaque, int vcpu);
65 void kvm_arch_pre_kvm_run(void *opaque, CPUState *env);
66 void kvm_arch_post_kvm_run(void *opaque, CPUState *env);
67 int kvm_arch_has_work(CPUState *env);
68 int kvm_arch_try_push_interrupts(void *opaque);
69 void kvm_arch_push_nmi(void *opaque);
70 void kvm_arch_update_regs_for_sipi(CPUState *env);
71 void kvm_arch_cpu_reset(CPUState *env);
73 void qemu_kvm_aio_wait_start(void);
74 void qemu_kvm_aio_wait(void);
75 void qemu_kvm_aio_wait_end(void);
77 void qemu_kvm_notify_work(void);
79 void kvm_tpr_opt_setup();
80 void kvm_tpr_access_report(CPUState *env, uint64_t rip, int is_write);
81 int handle_tpr_access(void *opaque, int vcpu,
82 uint64_t rip, int is_write);
83 void kvm_tpr_vcpu_start(CPUState *env);
85 int qemu_kvm_get_dirty_pages(unsigned long phys_addr, void *buf);
86 int qemu_kvm_register_coalesced_mmio(target_phys_addr_t addr,
87 unsigned int size);
88 int qemu_kvm_unregister_coalesced_mmio(target_phys_addr_t addr,
89 unsigned int size);
91 void qemu_kvm_system_reset_request(void);
93 #ifdef USE_KVM_DEVICE_ASSIGNMENT
94 void kvm_ioperm(CPUState *env, void *data);
95 void kvm_arch_do_ioperm(void *_data);
96 #endif
98 #ifdef TARGET_PPC
99 int handle_powerpc_dcr_read(int vcpu, uint32_t dcrn, uint32_t *data);
100 int handle_powerpc_dcr_write(int vcpu,uint32_t dcrn, uint32_t data);
101 #endif
103 #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1))
104 #define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
106 #ifdef USE_KVM
107 #include "libkvm.h"
108 #include "sys-queue.h"
110 extern int kvm_allowed;
111 extern kvm_context_t kvm_context;
113 struct ioperm_data {
114 unsigned long start_port;
115 unsigned long num;
116 int turn_on;
117 LIST_ENTRY(ioperm_data) entries;
120 #define kvm_enabled() (kvm_allowed)
121 #define qemu_kvm_irqchip_in_kernel() kvm_irqchip_in_kernel(kvm_context)
122 #define qemu_kvm_pit_in_kernel() kvm_pit_in_kernel(kvm_context)
123 #define qemu_kvm_has_sync_mmu() kvm_has_sync_mmu(kvm_context)
124 void kvm_init_vcpu(CPUState *env);
125 #else
126 #define kvm_enabled() (0)
127 #define qemu_kvm_irqchip_in_kernel() (0)
128 #define qemu_kvm_pit_in_kernel() (0)
129 #define qemu_kvm_has_sync_mmu() (0)
130 #define kvm_load_registers(env) do {} while(0)
131 #define kvm_save_registers(env) do {} while(0)
132 static inline void kvm_init_vcpu(CPUState *env) { }
134 #endif
136 void kvm_mutex_unlock(void);
137 void kvm_mutex_lock(void);
139 static inline void kvm_sleep_begin(void)
141 if (kvm_enabled())
142 kvm_mutex_unlock();
145 static inline void kvm_sleep_end(void)
147 if (kvm_enabled())
148 kvm_mutex_lock();
151 static inline void kvm_set_phys_mem(target_phys_addr_t start_addr,
152 ram_addr_t size,
153 ram_addr_t phys_offset)
155 kvm_cpu_register_physical_memory(start_addr, size, phys_offset);
159 void kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_addr_t end_addr);
161 int kvm_log_start(target_phys_addr_t phys_addr, target_phys_addr_t len);
162 int kvm_log_stop(target_phys_addr_t phys_addr, target_phys_addr_t len);
164 #endif