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.
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.
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.
15 * Copyright SUSE Linux Products GmbH 2009
17 * Authors: Alexander Graf <agraf@suse.de>
20 #ifndef __ASM_KVM_BOOK3S_H__
21 #define __ASM_KVM_BOOK3S_H__
23 #include <linux/types.h>
24 #include <linux/kvm_host.h>
25 #include <asm/kvm_book3s_asm.h>
36 bool large : 1; /* PTEs are 16MB */
37 bool tb : 1; /* 1TB segment */
61 struct kvmppc_sid_map {
68 #define SID_MAP_BITS 9
69 #define SID_MAP_NUM (1 << SID_MAP_BITS)
70 #define SID_MAP_MASK (SID_MAP_NUM - 1)
72 struct kvmppc_vcpu_book3s {
74 struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
75 struct kvmppc_sid_map sid_map[SID_MAP_NUM];
76 struct kvmppc_slb slb[64];
82 struct kvmppc_sr sr[16];
83 struct kvmppc_bat ibat[8];
84 struct kvmppc_bat dbat[8];
96 ulong prog_flags; /* flags to inject when giving a 700 trap */
99 #define CONTEXT_HOST 0
100 #define CONTEXT_GUEST 1
101 #define CONTEXT_GUEST_END 2
103 #define VSID_REAL 0x1fffffffffc00000ULL
104 #define VSID_BAT 0x1fffffffffb00000ULL
105 #define VSID_REAL_DR 0x2000000000000000ULL
106 #define VSID_REAL_IR 0x4000000000000000ULL
107 #define VSID_PR 0x8000000000000000ULL
109 extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask);
110 extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
111 extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end);
112 extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
113 extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
114 extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
115 extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
116 extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
117 extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
118 extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data);
119 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
120 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
121 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
122 extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
123 bool upper, u32 val);
124 extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr);
125 extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu);
127 extern u32 kvmppc_trampoline_lowmem;
128 extern u32 kvmppc_trampoline_enter;
129 extern void kvmppc_rmcall(ulong srr0, ulong srr1);
130 extern void kvmppc_load_up_fpu(void);
131 extern void kvmppc_load_up_altivec(void);
132 extern void kvmppc_load_up_vsx(void);
133 extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst);
134 extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst);
136 static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
138 return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
141 static inline ulong dsisr(void)
144 asm ( "mfdsisr %0 " : "=r" (r) );
148 extern void kvm_return_point(void);
149 static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu(struct kvm_vcpu *vcpu);
151 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
154 to_svcpu(vcpu)->gpr[num] = val;
155 to_book3s(vcpu)->shadow_vcpu->gpr[num] = val;
157 vcpu->arch.gpr[num] = val;
160 static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
163 return to_svcpu(vcpu)->gpr[num];
165 return vcpu->arch.gpr[num];
168 static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
170 to_svcpu(vcpu)->cr = val;
171 to_book3s(vcpu)->shadow_vcpu->cr = val;
174 static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
176 return to_svcpu(vcpu)->cr;
179 static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
181 to_svcpu(vcpu)->xer = val;
182 to_book3s(vcpu)->shadow_vcpu->xer = val;
185 static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
187 return to_svcpu(vcpu)->xer;
190 static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
192 to_svcpu(vcpu)->ctr = val;
195 static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
197 return to_svcpu(vcpu)->ctr;
200 static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
202 to_svcpu(vcpu)->lr = val;
205 static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
207 return to_svcpu(vcpu)->lr;
210 static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
212 to_svcpu(vcpu)->pc = val;
215 static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
217 return to_svcpu(vcpu)->pc;
220 static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)
222 ulong pc = kvmppc_get_pc(vcpu);
223 struct kvmppc_book3s_shadow_vcpu *svcpu = to_svcpu(vcpu);
225 /* Load the instruction manually if it failed to do so in the
227 if (svcpu->last_inst == KVM_INST_FETCH_FAILED)
228 kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false);
230 return svcpu->last_inst;
233 static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
235 return to_svcpu(vcpu)->fault_dar;
238 /* Magic register values loaded into r3 and r4 before the 'sc' assembly
239 * instruction for the OSI hypercalls */
240 #define OSI_SC_MAGIC_R3 0x113724FA
241 #define OSI_SC_MAGIC_R4 0x77810F9B
243 #define INS_DCBZ 0x7c0007ec
245 /* Also add subarch specific defines */
247 #ifdef CONFIG_PPC_BOOK3S_32
248 #include <asm/kvm_book3s_32.h>
250 #include <asm/kvm_book3s_64.h>
253 #endif /* __ASM_KVM_BOOK3S_H__ */