KVM: PPC: Call SLB patching code in interrupt safe manner
[safe/jmp/linux-2.6] / arch / powerpc / include / asm / kvm_book3s.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License, version 2, as
4  * published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14  *
15  * Copyright SUSE Linux Products GmbH 2009
16  *
17  * Authors: Alexander Graf <agraf@suse.de>
18  */
19
20 #ifndef __ASM_KVM_BOOK3S_H__
21 #define __ASM_KVM_BOOK3S_H__
22
23 #include <linux/types.h>
24 #include <linux/kvm_host.h>
25 #include <asm/kvm_ppc.h>
26 #include <asm/kvm_book3s_64_asm.h>
27
28 struct kvmppc_slb {
29         u64 esid;
30         u64 vsid;
31         u64 orige;
32         u64 origv;
33         bool valid;
34         bool Ks;
35         bool Kp;
36         bool nx;
37         bool large;
38         bool class;
39 };
40
41 struct kvmppc_sr {
42         u32 raw;
43         u32 vsid;
44         bool Ks;
45         bool Kp;
46         bool nx;
47 };
48
49 struct kvmppc_bat {
50         u64 raw;
51         u32 bepi;
52         u32 bepi_mask;
53         bool vs;
54         bool vp;
55         u32 brpn;
56         u8 wimg;
57         u8 pp;
58 };
59
60 struct kvmppc_sid_map {
61         u64 guest_vsid;
62         u64 guest_esid;
63         u64 host_vsid;
64         bool valid;
65 };
66
67 #define SID_MAP_BITS    9
68 #define SID_MAP_NUM     (1 << SID_MAP_BITS)
69 #define SID_MAP_MASK    (SID_MAP_NUM - 1)
70
71 struct kvmppc_vcpu_book3s {
72         struct kvm_vcpu vcpu;
73         struct kvmppc_book3s_shadow_vcpu shadow_vcpu;
74         struct kvmppc_sid_map sid_map[SID_MAP_NUM];
75         struct kvmppc_slb slb[64];
76         struct {
77                 u64 esid;
78                 u64 vsid;
79         } slb_shadow[64];
80         u8 slb_shadow_max;
81         struct kvmppc_sr sr[16];
82         struct kvmppc_bat ibat[8];
83         struct kvmppc_bat dbat[8];
84         u64 hid[6];
85         int slb_nr;
86         u64 sdr1;
87         u64 dsisr;
88         u64 hior;
89         u64 msr_mask;
90         u64 vsid_first;
91         u64 vsid_next;
92         u64 vsid_max;
93         int context_id;
94 };
95
96 #define CONTEXT_HOST            0
97 #define CONTEXT_GUEST           1
98 #define CONTEXT_GUEST_END       2
99
100 #define VSID_REAL       0xfffffffffff00000
101 #define VSID_REAL_DR    0xffffffffffe00000
102 #define VSID_REAL_IR    0xffffffffffd00000
103 #define VSID_BAT        0xffffffffffc00000
104 #define VSID_PR         0x8000000000000000
105
106 extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask);
107 extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
108 extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end);
109 extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
110 extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
111 extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
112 extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
113 extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
114 extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
115 extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data);
116 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, bool data);
117 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
118 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
119 extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
120                            bool upper, u32 val);
121
122 extern u32 kvmppc_trampoline_lowmem;
123 extern u32 kvmppc_trampoline_enter;
124 extern void kvmppc_rmcall(ulong srr0, ulong srr1);
125
126 static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
127 {
128         return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
129 }
130
131 static inline ulong dsisr(void)
132 {
133         ulong r;
134         asm ( "mfdsisr %0 " : "=r" (r) );
135         return r;
136 }
137
138 extern void kvm_return_point(void);
139
140 #define INS_DCBZ                        0x7c0007ec
141
142 #endif /* __ASM_KVM_BOOK3S_H__ */