blob: 5592456c36ad504d8aee33a52a737c37f988125b [file] [log] [blame]
Carsten Otte043405e2007-10-10 17:16:19 +02001#/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * This header defines architecture specific interfaces, x86 version
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2. See
7 * the COPYING file in the top-level directory.
8 *
9 */
10
11#ifndef KVM_X86_H
12#define KVM_X86_H
13
14#include "kvm.h"
15
Zhang Xiantao34c16ee2007-10-20 15:34:38 +080016#include <linux/types.h>
17#include <linux/mm.h>
18
19#include <linux/kvm.h>
20#include <linux/kvm_para.h>
21
22struct kvm_vcpu {
23 KVM_VCPU_COMM;
24 u64 host_tsc;
25 int interrupt_window_open;
26 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
27 DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
28 unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
29 unsigned long rip; /* needs vcpu_load_rsp_rip() */
30
31 unsigned long cr0;
32 unsigned long cr2;
33 unsigned long cr3;
34 unsigned long cr4;
35 unsigned long cr8;
36 u64 pdptrs[4]; /* pae */
37 u64 shadow_efer;
38 u64 apic_base;
39 struct kvm_lapic *apic; /* kernel irqchip context */
40#define VCPU_MP_STATE_RUNNABLE 0
41#define VCPU_MP_STATE_UNINITIALIZED 1
42#define VCPU_MP_STATE_INIT_RECEIVED 2
43#define VCPU_MP_STATE_SIPI_RECEIVED 3
44#define VCPU_MP_STATE_HALTED 4
45 int mp_state;
46 int sipi_vector;
47 u64 ia32_misc_enable_msr;
48
49 struct kvm_mmu mmu;
50
51 struct kvm_mmu_memory_cache mmu_pte_chain_cache;
52 struct kvm_mmu_memory_cache mmu_rmap_desc_cache;
53 struct kvm_mmu_memory_cache mmu_page_cache;
54 struct kvm_mmu_memory_cache mmu_page_header_cache;
55
56 gfn_t last_pt_write_gfn;
57 int last_pt_write_count;
58 u64 *last_pte_updated;
59
60
61 struct i387_fxsave_struct host_fx_image;
62 struct i387_fxsave_struct guest_fx_image;
63
64 gva_t mmio_fault_cr2;
65 struct kvm_pio_request pio;
66 void *pio_data;
67
68 struct {
69 int active;
70 u8 save_iopl;
71 struct kvm_save_segment {
72 u16 selector;
73 unsigned long base;
74 u32 limit;
75 u32 ar;
76 } tr, es, ds, fs, gs;
77 } rmode;
78 int halt_request; /* real mode on Intel only */
79
80 int cpuid_nent;
81 struct kvm_cpuid_entry cpuid_entries[KVM_MAX_CPUID_ENTRIES];
82
83 /* emulate context */
84
85 struct x86_emulate_ctxt emulate_ctxt;
86};
87
Avi Kivity30677142007-10-28 18:48:59 +020088int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code);
Zhang Xiantao34c16ee2007-10-20 15:34:38 +080089
90static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
91{
92 if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))
93 __kvm_mmu_free_some_pages(vcpu);
94}
95
96static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu)
97{
98 if (likely(vcpu->mmu.root_hpa != INVALID_PAGE))
99 return 0;
100
101 return kvm_mmu_load(vcpu);
102}
103
104static inline int is_long_mode(struct kvm_vcpu *vcpu)
105{
106#ifdef CONFIG_X86_64
107 return vcpu->shadow_efer & EFER_LME;
108#else
109 return 0;
110#endif
111}
112
113static inline int is_pae(struct kvm_vcpu *vcpu)
114{
115 return vcpu->cr4 & X86_CR4_PAE;
116}
117
118static inline int is_pse(struct kvm_vcpu *vcpu)
119{
120 return vcpu->cr4 & X86_CR4_PSE;
121}
122
123static inline int is_paging(struct kvm_vcpu *vcpu)
124{
125 return vcpu->cr0 & X86_CR0_PG;
126}
127
Carsten Ottea03490e2007-10-29 16:09:35 +0100128int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
Carsten Otte043405e2007-10-10 17:16:19 +0200129#endif