Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 1 | #ifndef __KVM_H |
| 2 | #define __KVM_H |
| 3 | |
| 4 | /* |
| 5 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 6 | * the COPYING file in the top-level directory. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/types.h> |
Christian Borntraeger | e56a7a2 | 2007-10-18 14:39:10 +0200 | [diff] [blame] | 10 | #include <linux/hardirq.h> |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/mutex.h> |
| 13 | #include <linux/spinlock.h> |
Markus Rechberger | 06ff0d3 | 2007-05-27 10:46:52 +0300 | [diff] [blame] | 14 | #include <linux/signal.h> |
| 15 | #include <linux/sched.h> |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 16 | #include <linux/mm.h> |
Avi Kivity | 15ad714 | 2007-07-11 18:17:21 +0300 | [diff] [blame] | 17 | #include <linux/preempt.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 18 | #include <asm/signal.h> |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 19 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 20 | #include <linux/kvm.h> |
Ingo Molnar | 102d832 | 2007-02-19 14:37:47 +0200 | [diff] [blame] | 21 | #include <linux/kvm_para.h> |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 22 | |
Hollis Blanchard | d77a39d | 2007-12-03 15:30:23 -0600 | [diff] [blame] | 23 | #include "types.h" |
| 24 | |
Zhang Xiantao | d657a98 | 2007-12-14 09:41:22 +0800 | [diff] [blame] | 25 | #include "x86.h" |
| 26 | |
Avi Kivity | ef9254d | 2007-06-05 14:37:09 +0300 | [diff] [blame] | 27 | #define KVM_MAX_VCPUS 4 |
Avi Kivity | e820754 | 2007-03-30 16:54:30 +0300 | [diff] [blame] | 28 | #define KVM_ALIAS_SLOTS 4 |
Izik Eidus | 2e2c618 | 2007-08-20 18:11:00 +0300 | [diff] [blame] | 29 | #define KVM_MEMORY_SLOTS 8 |
Izik Eidus | e0d62c7 | 2007-10-24 23:57:46 +0200 | [diff] [blame] | 30 | /* memory slots that does not exposed to userspace */ |
| 31 | #define KVM_PRIVATE_MEM_SLOTS 4 |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 32 | |
Avi Kivity | 039576c | 2007-03-20 12:46:50 +0200 | [diff] [blame] | 33 | #define KVM_PIO_PAGE_OFFSET 1 |
| 34 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 35 | /* |
Avi Kivity | d9e368d | 2007-06-07 19:18:30 +0300 | [diff] [blame] | 36 | * vcpu->requests bit members |
| 37 | */ |
Avi Kivity | 3176bc3 | 2007-10-16 17:22:08 +0200 | [diff] [blame] | 38 | #define KVM_REQ_TLB_FLUSH 0 |
Avi Kivity | d9e368d | 2007-06-07 19:18:30 +0300 | [diff] [blame] | 39 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 40 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 41 | struct kvm_vcpu; |
Rusty Russell | c16f862 | 2007-07-30 21:12:19 +1000 | [diff] [blame] | 42 | extern struct kmem_cache *kvm_vcpu_cache; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 43 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 44 | struct kvm_guest_debug { |
| 45 | int enabled; |
| 46 | unsigned long bp[4]; |
| 47 | int singlestep; |
| 48 | }; |
| 49 | |
Gregory Haskins | 2eeb2e9 | 2007-05-31 14:08:53 -0400 | [diff] [blame] | 50 | /* |
| 51 | * It would be nice to use something smarter than a linear search, TBD... |
| 52 | * Thankfully we dont expect many devices to register (famous last words :), |
| 53 | * so until then it will suffice. At least its abstracted so we can change |
| 54 | * in one place. |
| 55 | */ |
| 56 | struct kvm_io_bus { |
| 57 | int dev_count; |
| 58 | #define NR_IOBUS_DEVS 6 |
| 59 | struct kvm_io_device *devs[NR_IOBUS_DEVS]; |
| 60 | }; |
| 61 | |
| 62 | void kvm_io_bus_init(struct kvm_io_bus *bus); |
| 63 | void kvm_io_bus_destroy(struct kvm_io_bus *bus); |
| 64 | struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus, gpa_t addr); |
| 65 | void kvm_io_bus_register_dev(struct kvm_io_bus *bus, |
| 66 | struct kvm_io_device *dev); |
| 67 | |
Zhang Xiantao | d657a98 | 2007-12-14 09:41:22 +0800 | [diff] [blame] | 68 | struct kvm_vcpu { |
Zhang Xiantao | d17fbbf | 2007-12-14 09:45:31 +0800 | [diff] [blame] | 69 | struct kvm *kvm; |
| 70 | struct preempt_notifier preempt_notifier; |
| 71 | int vcpu_id; |
| 72 | struct mutex mutex; |
| 73 | int cpu; |
| 74 | struct kvm_run *run; |
| 75 | int guest_mode; |
| 76 | unsigned long requests; |
| 77 | struct kvm_guest_debug guest_debug; |
| 78 | int fpu_active; |
| 79 | int guest_fpu_loaded; |
| 80 | wait_queue_head_t wq; |
| 81 | int sigset_active; |
| 82 | sigset_t sigset; |
| 83 | struct kvm_vcpu_stat stat; |
| 84 | |
| 85 | #ifdef CONFIG_HAS_IOMEM |
| 86 | int mmio_needed; |
| 87 | int mmio_read_completed; |
| 88 | int mmio_is_write; |
| 89 | int mmio_size; |
| 90 | unsigned char mmio_data[8]; |
| 91 | gpa_t mmio_phys_addr; |
| 92 | #endif |
Zhang Xiantao | d657a98 | 2007-12-14 09:41:22 +0800 | [diff] [blame] | 93 | |
| 94 | struct kvm_vcpu_arch arch; |
| 95 | }; |
| 96 | |
Avi Kivity | e820754 | 2007-03-30 16:54:30 +0300 | [diff] [blame] | 97 | struct kvm_mem_alias { |
| 98 | gfn_t base_gfn; |
| 99 | unsigned long npages; |
| 100 | gfn_t target_gfn; |
| 101 | }; |
| 102 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 103 | struct kvm_memory_slot { |
| 104 | gfn_t base_gfn; |
| 105 | unsigned long npages; |
| 106 | unsigned long flags; |
Izik Eidus | 290fc38 | 2007-09-27 14:11:22 +0200 | [diff] [blame] | 107 | unsigned long *rmap; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 108 | unsigned long *dirty_bitmap; |
Izik Eidus | 8a7ae05 | 2007-10-18 11:09:33 +0200 | [diff] [blame] | 109 | unsigned long userspace_addr; |
Izik Eidus | 80b14b5 | 2007-10-25 11:54:04 +0200 | [diff] [blame] | 110 | int user_alloc; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Avi Kivity | ba1389b | 2007-11-18 16:24:12 +0200 | [diff] [blame] | 113 | struct kvm_vm_stat { |
Avi Kivity | 4cee576 | 2007-11-18 16:37:07 +0200 | [diff] [blame] | 114 | u32 mmu_shadow_zapped; |
| 115 | u32 mmu_pte_write; |
| 116 | u32 mmu_pte_updated; |
| 117 | u32 mmu_pde_zapped; |
| 118 | u32 mmu_flooded; |
| 119 | u32 mmu_recycled; |
Avi Kivity | 0f74a24 | 2007-11-20 23:01:14 +0200 | [diff] [blame] | 120 | u32 remote_tlb_flush; |
Avi Kivity | ba1389b | 2007-11-18 16:24:12 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 123 | struct kvm { |
Shaohua Li | 11ec280 | 2007-07-23 14:51:37 +0800 | [diff] [blame] | 124 | struct mutex lock; /* protects everything except vcpus */ |
Avi Kivity | 6d4e4c4 | 2007-11-21 16:41:05 +0200 | [diff] [blame] | 125 | struct mm_struct *mm; /* userspace tied to this vm */ |
Avi Kivity | e820754 | 2007-03-30 16:54:30 +0300 | [diff] [blame] | 126 | int naliases; |
| 127 | struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS]; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 128 | int nmemslots; |
Izik Eidus | e0d62c7 | 2007-10-24 23:57:46 +0200 | [diff] [blame] | 129 | struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS + |
| 130 | KVM_PRIVATE_MEM_SLOTS]; |
Avi Kivity | cea0f0e | 2007-01-05 16:36:43 -0800 | [diff] [blame] | 131 | /* |
| 132 | * Hash table of struct kvm_mmu_page. |
| 133 | */ |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 134 | struct list_head active_mmu_pages; |
Izik Eidus | 82ce2c9 | 2007-10-02 18:52:55 +0200 | [diff] [blame] | 135 | unsigned int n_free_mmu_pages; |
| 136 | unsigned int n_requested_mmu_pages; |
| 137 | unsigned int n_alloc_mmu_pages; |
Avi Kivity | cea0f0e | 2007-01-05 16:36:43 -0800 | [diff] [blame] | 138 | struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES]; |
Rusty Russell | fb3f0f5 | 2007-07-27 17:16:56 +1000 | [diff] [blame] | 139 | struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; |
Avi Kivity | 133de90 | 2007-02-12 00:54:44 -0800 | [diff] [blame] | 140 | struct list_head vm_list; |
Avi Kivity | bccf215 | 2007-02-21 18:04:26 +0200 | [diff] [blame] | 141 | struct file *filp; |
Gregory Haskins | 2eeb2e9 | 2007-05-31 14:08:53 -0400 | [diff] [blame] | 142 | struct kvm_io_bus mmio_bus; |
Eddie Dong | 7490634 | 2007-06-19 18:05:03 +0300 | [diff] [blame] | 143 | struct kvm_io_bus pio_bus; |
Eddie Dong | 85f455f | 2007-07-06 12:20:49 +0300 | [diff] [blame] | 144 | struct kvm_pic *vpic; |
Eddie Dong | 1fd4f2a | 2007-07-18 12:03:39 +0300 | [diff] [blame] | 145 | struct kvm_ioapic *vioapic; |
He, Qing | 932f72a | 2007-09-03 17:01:36 +0300 | [diff] [blame] | 146 | int round_robin_prev_vcpu; |
Izik Eidus | cbc9402 | 2007-10-25 00:29:55 +0200 | [diff] [blame] | 147 | unsigned int tss_addr; |
Sheng Yang | f78e0e2 | 2007-10-29 09:40:42 +0800 | [diff] [blame] | 148 | struct page *apic_access_page; |
Avi Kivity | ba1389b | 2007-11-18 16:24:12 +0200 | [diff] [blame] | 149 | struct kvm_vm_stat stat; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 150 | }; |
| 151 | |
Rusty Russell | f024247 | 2007-08-01 10:48:02 +1000 | [diff] [blame] | 152 | /* The guest did something we don't support. */ |
| 153 | #define pr_unimpl(vcpu, fmt, ...) \ |
| 154 | do { \ |
| 155 | if (printk_ratelimit()) \ |
| 156 | printk(KERN_ERR "kvm: %i: cpu%i " fmt, \ |
| 157 | current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \ |
Mike Day | d77c26f | 2007-10-08 09:02:08 -0400 | [diff] [blame] | 158 | } while (0) |
Rusty Russell | f024247 | 2007-08-01 10:48:02 +1000 | [diff] [blame] | 159 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 160 | #define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt) |
| 161 | #define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt) |
| 162 | |
Rusty Russell | fb3f0f5 | 2007-07-27 17:16:56 +1000 | [diff] [blame] | 163 | int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id); |
| 164 | void kvm_vcpu_uninit(struct kvm_vcpu *vcpu); |
| 165 | |
Carsten Otte | 313a3dc | 2007-10-11 19:16:52 +0200 | [diff] [blame] | 166 | void vcpu_load(struct kvm_vcpu *vcpu); |
| 167 | void vcpu_put(struct kvm_vcpu *vcpu); |
| 168 | |
Zhang Xiantao | e9b11c1 | 2007-11-14 20:38:21 +0800 | [diff] [blame] | 169 | void decache_vcpus_on_cpu(int cpu); |
| 170 | |
Carsten Otte | 313a3dc | 2007-10-11 19:16:52 +0200 | [diff] [blame] | 171 | |
Zhang Xiantao | f8c16bb | 2007-11-14 20:40:21 +0800 | [diff] [blame] | 172 | int kvm_init(void *opaque, unsigned int vcpu_size, |
Rusty Russell | c16f862 | 2007-07-30 21:12:19 +1000 | [diff] [blame] | 173 | struct module *module); |
Zhang Xiantao | cb498ea | 2007-11-14 20:39:31 +0800 | [diff] [blame] | 174 | void kvm_exit(void); |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 175 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 176 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) |
| 177 | #define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB) |
| 178 | static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; } |
Avi Kivity | 039576c | 2007-03-20 12:46:50 +0200 | [diff] [blame] | 179 | struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva); |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 180 | |
Izik Eidus | cea7bb2 | 2007-10-17 19:17:48 +0200 | [diff] [blame] | 181 | extern struct page *bad_page; |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 182 | |
Izik Eidus | cea7bb2 | 2007-10-17 19:17:48 +0200 | [diff] [blame] | 183 | int is_error_page(struct page *page); |
Izik Eidus | f9d46eb | 2007-11-11 22:02:22 +0200 | [diff] [blame] | 184 | int kvm_is_error_hva(unsigned long addr); |
Izik Eidus | 210c7c4 | 2007-10-24 23:52:57 +0200 | [diff] [blame] | 185 | int kvm_set_memory_region(struct kvm *kvm, |
| 186 | struct kvm_userspace_memory_region *mem, |
| 187 | int user_alloc); |
Sheng Yang | f78e0e2 | 2007-10-29 09:40:42 +0800 | [diff] [blame] | 188 | int __kvm_set_memory_region(struct kvm *kvm, |
| 189 | struct kvm_userspace_memory_region *mem, |
| 190 | int user_alloc); |
Zhang Xiantao | 0de1034 | 2007-11-20 16:25:04 +0800 | [diff] [blame] | 191 | int kvm_arch_set_memory_region(struct kvm *kvm, |
| 192 | struct kvm_userspace_memory_region *mem, |
| 193 | struct kvm_memory_slot old, |
| 194 | int user_alloc); |
Izik Eidus | 290fc38 | 2007-09-27 14:11:22 +0200 | [diff] [blame] | 195 | gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn); |
Avi Kivity | 954bbbc | 2007-03-30 14:02:32 +0300 | [diff] [blame] | 196 | struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn); |
Izik Eidus | b4231d6 | 2007-11-20 11:49:33 +0200 | [diff] [blame] | 197 | void kvm_release_page_clean(struct page *page); |
| 198 | void kvm_release_page_dirty(struct page *page); |
Izik Eidus | 195aefd | 2007-10-01 22:14:18 +0200 | [diff] [blame] | 199 | int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset, |
| 200 | int len); |
| 201 | int kvm_read_guest(struct kvm *kvm, gpa_t gpa, void *data, unsigned long len); |
| 202 | int kvm_write_guest_page(struct kvm *kvm, gfn_t gfn, const void *data, |
| 203 | int offset, int len); |
| 204 | int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, |
| 205 | unsigned long len); |
| 206 | int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len); |
| 207 | int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len); |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 208 | struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn); |
Izik Eidus | e0d62c7 | 2007-10-24 23:57:46 +0200 | [diff] [blame] | 209 | int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn); |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 210 | void mark_page_dirty(struct kvm *kvm, gfn_t gfn); |
| 211 | |
Hollis Blanchard | 8776e51 | 2007-10-31 17:24:24 -0500 | [diff] [blame] | 212 | void kvm_vcpu_block(struct kvm_vcpu *vcpu); |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 213 | void kvm_resched(struct kvm_vcpu *vcpu); |
Avi Kivity | 7702fd1 | 2007-06-14 16:27:40 +0300 | [diff] [blame] | 214 | void kvm_load_guest_fpu(struct kvm_vcpu *vcpu); |
| 215 | void kvm_put_guest_fpu(struct kvm_vcpu *vcpu); |
Avi Kivity | d9e368d | 2007-06-07 19:18:30 +0300 | [diff] [blame] | 216 | void kvm_flush_remote_tlbs(struct kvm *kvm); |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 217 | |
Carsten Otte | 043405e | 2007-10-10 17:16:19 +0200 | [diff] [blame] | 218 | long kvm_arch_dev_ioctl(struct file *filp, |
| 219 | unsigned int ioctl, unsigned long arg); |
Carsten Otte | 313a3dc | 2007-10-11 19:16:52 +0200 | [diff] [blame] | 220 | long kvm_arch_vcpu_ioctl(struct file *filp, |
| 221 | unsigned int ioctl, unsigned long arg); |
| 222 | void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu); |
| 223 | void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu); |
Zhang Xiantao | 018d00d | 2007-11-15 23:07:47 +0800 | [diff] [blame] | 224 | |
| 225 | int kvm_dev_ioctl_check_extension(long ext); |
| 226 | |
Zhang Xiantao | 5bb064d | 2007-11-18 20:29:43 +0800 | [diff] [blame] | 227 | int kvm_get_dirty_log(struct kvm *kvm, |
| 228 | struct kvm_dirty_log *log, int *is_dirty); |
| 229 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, |
| 230 | struct kvm_dirty_log *log); |
| 231 | |
Carsten Otte | 1fe779f | 2007-10-29 16:08:35 +0100 | [diff] [blame] | 232 | int kvm_vm_ioctl_set_memory_region(struct kvm *kvm, |
| 233 | struct |
| 234 | kvm_userspace_memory_region *mem, |
| 235 | int user_alloc); |
| 236 | long kvm_arch_vm_ioctl(struct file *filp, |
| 237 | unsigned int ioctl, unsigned long arg); |
| 238 | void kvm_arch_destroy_vm(struct kvm *kvm); |
Carsten Otte | 313a3dc | 2007-10-11 19:16:52 +0200 | [diff] [blame] | 239 | |
Hollis Blanchard | d075206 | 2007-10-31 17:24:25 -0500 | [diff] [blame] | 240 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); |
| 241 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu); |
| 242 | |
Zhang Xiantao | 8b00679 | 2007-11-16 13:05:55 +0800 | [diff] [blame] | 243 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 244 | struct kvm_translation *tr); |
| 245 | |
Hollis Blanchard | b6c7a5d | 2007-11-01 14:16:10 -0500 | [diff] [blame] | 246 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs); |
| 247 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs); |
| 248 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 249 | struct kvm_sregs *sregs); |
| 250 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 251 | struct kvm_sregs *sregs); |
| 252 | int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu, |
| 253 | struct kvm_debug_guest *dbg); |
| 254 | int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); |
| 255 | |
Zhang Xiantao | f8c16bb | 2007-11-14 20:40:21 +0800 | [diff] [blame] | 256 | int kvm_arch_init(void *opaque); |
| 257 | void kvm_arch_exit(void); |
Carsten Otte | 043405e | 2007-10-10 17:16:19 +0200 | [diff] [blame] | 258 | |
Zhang Xiantao | e9b11c1 | 2007-11-14 20:38:21 +0800 | [diff] [blame] | 259 | int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu); |
| 260 | void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu); |
| 261 | |
| 262 | void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu); |
| 263 | void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu); |
| 264 | void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu); |
| 265 | struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id); |
Avi Kivity | 26e5215 | 2007-11-20 15:30:24 +0200 | [diff] [blame] | 266 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu); |
Hollis Blanchard | d40ccc6 | 2007-11-19 14:04:43 -0600 | [diff] [blame] | 267 | void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu); |
Zhang Xiantao | e9b11c1 | 2007-11-14 20:38:21 +0800 | [diff] [blame] | 268 | |
| 269 | int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu); |
| 270 | void kvm_arch_hardware_enable(void *garbage); |
| 271 | void kvm_arch_hardware_disable(void *garbage); |
| 272 | int kvm_arch_hardware_setup(void); |
| 273 | void kvm_arch_hardware_unsetup(void); |
| 274 | void kvm_arch_check_processor_compat(void *rtn); |
Zhang Xiantao | 1d737c8 | 2007-12-14 09:35:10 +0800 | [diff] [blame] | 275 | int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu); |
Zhang Xiantao | e9b11c1 | 2007-11-14 20:38:21 +0800 | [diff] [blame] | 276 | |
Zhang Xiantao | d19a9cd | 2007-11-18 18:43:45 +0800 | [diff] [blame] | 277 | void kvm_free_physmem(struct kvm *kvm); |
| 278 | |
| 279 | struct kvm *kvm_arch_create_vm(void); |
| 280 | void kvm_arch_destroy_vm(struct kvm *kvm); |
Zhang Xiantao | e9b11c1 | 2007-11-14 20:38:21 +0800 | [diff] [blame] | 281 | |
Zhang Xiantao | 682c59a | 2007-12-11 20:36:00 +0800 | [diff] [blame] | 282 | int kvm_cpu_get_interrupt(struct kvm_vcpu *v); |
| 283 | int kvm_cpu_has_interrupt(struct kvm_vcpu *v); |
| 284 | |
Laurent Vivier | d172fcd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 285 | static inline void kvm_guest_enter(void) |
| 286 | { |
Christian Borntraeger | e56a7a2 | 2007-10-18 14:39:10 +0200 | [diff] [blame] | 287 | account_system_vtime(current); |
Laurent Vivier | d172fcd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 288 | current->flags |= PF_VCPU; |
| 289 | } |
| 290 | |
| 291 | static inline void kvm_guest_exit(void) |
| 292 | { |
Christian Borntraeger | e56a7a2 | 2007-10-18 14:39:10 +0200 | [diff] [blame] | 293 | account_system_vtime(current); |
Laurent Vivier | d172fcd | 2007-10-15 17:00:19 +0200 | [diff] [blame] | 294 | current->flags &= ~PF_VCPU; |
| 295 | } |
| 296 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 297 | static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot) |
| 298 | { |
| 299 | return slot - kvm->memslots; |
| 300 | } |
| 301 | |
Avi Kivity | 1755fbc | 2007-11-21 14:44:45 +0200 | [diff] [blame] | 302 | static inline gpa_t gfn_to_gpa(gfn_t gfn) |
| 303 | { |
| 304 | return (gpa_t)gfn << PAGE_SHIFT; |
| 305 | } |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 306 | |
Avi Kivity | ba1389b | 2007-11-18 16:24:12 +0200 | [diff] [blame] | 307 | enum kvm_stat_kind { |
| 308 | KVM_STAT_VM, |
| 309 | KVM_STAT_VCPU, |
| 310 | }; |
| 311 | |
Hollis Blanchard | 417bc30 | 2007-10-31 17:24:23 -0500 | [diff] [blame] | 312 | struct kvm_stats_debugfs_item { |
| 313 | const char *name; |
| 314 | int offset; |
Avi Kivity | ba1389b | 2007-11-18 16:24:12 +0200 | [diff] [blame] | 315 | enum kvm_stat_kind kind; |
Hollis Blanchard | 417bc30 | 2007-10-31 17:24:23 -0500 | [diff] [blame] | 316 | struct dentry *dentry; |
| 317 | }; |
| 318 | extern struct kvm_stats_debugfs_item debugfs_entries[]; |
| 319 | |
Avi Kivity | 6aa8b73 | 2006-12-10 02:21:36 -0800 | [diff] [blame] | 320 | #endif |