KVM: Replace read accesses of vcpu->arch.cr0 by an accessor
[linux-3.10.git] / arch / x86 / kvm / kvm_cache_regs.h
1 #ifndef ASM_KVM_CACHE_REGS_H
2 #define ASM_KVM_CACHE_REGS_H
3
4 static inline unsigned long kvm_register_read(struct kvm_vcpu *vcpu,
5                                               enum kvm_reg reg)
6 {
7         if (!test_bit(reg, (unsigned long *)&vcpu->arch.regs_avail))
8                 kvm_x86_ops->cache_reg(vcpu, reg);
9
10         return vcpu->arch.regs[reg];
11 }
12
13 static inline void kvm_register_write(struct kvm_vcpu *vcpu,
14                                       enum kvm_reg reg,
15                                       unsigned long val)
16 {
17         vcpu->arch.regs[reg] = val;
18         __set_bit(reg, (unsigned long *)&vcpu->arch.regs_dirty);
19         __set_bit(reg, (unsigned long *)&vcpu->arch.regs_avail);
20 }
21
22 static inline unsigned long kvm_rip_read(struct kvm_vcpu *vcpu)
23 {
24         return kvm_register_read(vcpu, VCPU_REGS_RIP);
25 }
26
27 static inline void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val)
28 {
29         kvm_register_write(vcpu, VCPU_REGS_RIP, val);
30 }
31
32 static inline u64 kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
33 {
34         if (!test_bit(VCPU_EXREG_PDPTR,
35                       (unsigned long *)&vcpu->arch.regs_avail))
36                 kvm_x86_ops->cache_reg(vcpu, VCPU_EXREG_PDPTR);
37
38         return vcpu->arch.pdptrs[index];
39 }
40
41 static inline ulong kvm_read_cr0_bits(struct kvm_vcpu *vcpu, ulong mask)
42 {
43         return vcpu->arch.cr0 & mask;
44 }
45
46 static inline ulong kvm_read_cr0(struct kvm_vcpu *vcpu)
47 {
48         return kvm_read_cr0_bits(vcpu, ~0UL);
49 }
50
51 static inline ulong kvm_read_cr4_bits(struct kvm_vcpu *vcpu, ulong mask)
52 {
53         if (mask & vcpu->arch.cr4_guest_owned_bits)
54                 kvm_x86_ops->decache_cr4_guest_bits(vcpu);
55         return vcpu->arch.cr4 & mask;
56 }
57
58 static inline ulong kvm_read_cr4(struct kvm_vcpu *vcpu)
59 {
60         return kvm_read_cr4_bits(vcpu, ~0UL);
61 }
62
63 #endif