blob: be8aac24ba83f0383b4899acb748929a37ab0bbd [file] [log] [blame]
Alexander Graf4e3420252009-10-30 05:47:05 +00001/*
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>
Alexander Graf2191d652010-04-16 00:11:32 +020025#include <asm/kvm_book3s_asm.h>
Alexander Graf4e3420252009-10-30 05:47:05 +000026
27struct kvmppc_slb {
28 u64 esid;
29 u64 vsid;
30 u64 orige;
31 u64 origv;
Alexander Graf3ed9c6d2010-03-24 21:48:36 +010032 bool valid : 1;
33 bool Ks : 1;
34 bool Kp : 1;
35 bool nx : 1;
36 bool large : 1; /* PTEs are 16MB */
37 bool tb : 1; /* 1TB segment */
38 bool class : 1;
Alexander Graf4e3420252009-10-30 05:47:05 +000039};
40
Alexander Graf4e3420252009-10-30 05:47:05 +000041struct kvmppc_bat {
Alexander Grafe15a1132009-11-30 03:02:02 +000042 u64 raw;
Alexander Graf4e3420252009-10-30 05:47:05 +000043 u32 bepi;
44 u32 bepi_mask;
Alexander Graf4e3420252009-10-30 05:47:05 +000045 u32 brpn;
46 u8 wimg;
47 u8 pp;
Alexander Graf3ed9c6d2010-03-24 21:48:36 +010048 bool vs : 1;
49 bool vp : 1;
Alexander Graf4e3420252009-10-30 05:47:05 +000050};
51
52struct kvmppc_sid_map {
53 u64 guest_vsid;
54 u64 guest_esid;
55 u64 host_vsid;
Alexander Graf3ed9c6d2010-03-24 21:48:36 +010056 bool valid : 1;
Alexander Graf4e3420252009-10-30 05:47:05 +000057};
58
59#define SID_MAP_BITS 9
60#define SID_MAP_NUM (1 << SID_MAP_BITS)
61#define SID_MAP_MASK (SID_MAP_NUM - 1)
62
63struct kvmppc_vcpu_book3s {
64 struct kvm_vcpu vcpu;
Alexander Grafc7f38f42010-04-16 00:11:40 +020065 struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
Alexander Graf4e3420252009-10-30 05:47:05 +000066 struct kvmppc_sid_map sid_map[SID_MAP_NUM];
67 struct kvmppc_slb slb[64];
68 struct {
69 u64 esid;
70 u64 vsid;
71 } slb_shadow[64];
72 u8 slb_shadow_max;
Alexander Graf4e3420252009-10-30 05:47:05 +000073 struct kvmppc_bat ibat[8];
74 struct kvmppc_bat dbat[8];
75 u64 hid[6];
Alexander Grafd6d549b2010-02-19 11:00:33 +010076 u64 gqr[8];
Alexander Graf4e3420252009-10-30 05:47:05 +000077 int slb_nr;
78 u64 sdr1;
Alexander Graf4e3420252009-10-30 05:47:05 +000079 u64 hior;
80 u64 msr_mask;
81 u64 vsid_first;
82 u64 vsid_next;
83 u64 vsid_max;
84 int context_id;
Alexander Graf25a8a022010-01-08 02:58:07 +010085 ulong prog_flags; /* flags to inject when giving a 700 trap */
Alexander Graf4e3420252009-10-30 05:47:05 +000086};
87
88#define CONTEXT_HOST 0
89#define CONTEXT_GUEST 1
90#define CONTEXT_GUEST_END 2
91
Alexander Graff7bc74e2010-04-20 02:49:48 +020092#define VSID_REAL 0x1fffffffffc00000ULL
93#define VSID_BAT 0x1fffffffffb00000ULL
94#define VSID_REAL_DR 0x2000000000000000ULL
95#define VSID_REAL_IR 0x4000000000000000ULL
Alexander Graf5a1b4192010-03-24 21:48:35 +010096#define VSID_PR 0x8000000000000000ULL
Alexander Graf4e3420252009-10-30 05:47:05 +000097
Alexander Grafaf7b4d12010-04-20 02:49:46 +020098extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask);
Alexander Graf4e3420252009-10-30 05:47:05 +000099extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
Alexander Grafaf7b4d12010-04-20 02:49:46 +0200100extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end);
Alexander Graf4e3420252009-10-30 05:47:05 +0000101extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
102extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
103extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
104extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
105extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
106extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
Alexander Graffef093b2010-06-30 15:18:46 +0200107
108extern void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte);
109extern struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu);
110extern void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu);
111extern int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu);
112extern void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte);
113extern int kvmppc_mmu_hpte_sysinit(void);
114extern void kvmppc_mmu_hpte_sysexit(void);
115
Alexander Graf5467a972010-02-19 11:00:38 +0100116extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
117extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data);
Alexander Graf4e3420252009-10-30 05:47:05 +0000118extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
Alexander Grafe15a1132009-11-30 03:02:02 +0000119extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
120 bool upper, u32 val);
Alexander Grafaba3bd72010-02-19 11:00:39 +0100121extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr);
Alexander Graf831317b2010-02-19 11:00:44 +0100122extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu);
Alexander Grafe8508942010-07-29 14:47:54 +0200123extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn);
Alexander Graf4e3420252009-10-30 05:47:05 +0000124
Alexander Graf2b05d712010-07-29 15:04:21 +0200125extern ulong kvmppc_trampoline_lowmem;
126extern ulong kvmppc_trampoline_enter;
Alexander Graf021ec9c2010-01-08 02:58:06 +0100127extern void kvmppc_rmcall(ulong srr0, ulong srr1);
Alexander Grafd5e52812010-01-15 14:49:10 +0100128extern void kvmppc_load_up_fpu(void);
129extern void kvmppc_load_up_altivec(void);
130extern void kvmppc_load_up_vsx(void);
Alexander Grafca7f4202010-03-24 21:48:28 +0100131extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst);
132extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst);
Alexander Graf4e3420252009-10-30 05:47:05 +0000133
134static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
135{
136 return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
137}
138
139static inline ulong dsisr(void)
140{
141 ulong r;
142 asm ( "mfdsisr %0 " : "=r" (r) );
143 return r;
144}
145
146extern void kvm_return_point(void);
Alexander Grafc7f38f42010-04-16 00:11:40 +0200147static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu(struct kvm_vcpu *vcpu);
148
149static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
150{
151 if ( num < 14 ) {
152 to_svcpu(vcpu)->gpr[num] = val;
153 to_book3s(vcpu)->shadow_vcpu->gpr[num] = val;
154 } else
155 vcpu->arch.gpr[num] = val;
156}
157
158static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num)
159{
160 if ( num < 14 )
161 return to_svcpu(vcpu)->gpr[num];
162 else
163 return vcpu->arch.gpr[num];
164}
165
166static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val)
167{
168 to_svcpu(vcpu)->cr = val;
169 to_book3s(vcpu)->shadow_vcpu->cr = val;
170}
171
172static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu)
173{
174 return to_svcpu(vcpu)->cr;
175}
176
177static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val)
178{
179 to_svcpu(vcpu)->xer = val;
180 to_book3s(vcpu)->shadow_vcpu->xer = val;
181}
182
183static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu)
184{
185 return to_svcpu(vcpu)->xer;
186}
187
188static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val)
189{
190 to_svcpu(vcpu)->ctr = val;
191}
192
193static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu)
194{
195 return to_svcpu(vcpu)->ctr;
196}
197
198static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val)
199{
200 to_svcpu(vcpu)->lr = val;
201}
202
203static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu)
204{
205 return to_svcpu(vcpu)->lr;
206}
207
208static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val)
209{
210 to_svcpu(vcpu)->pc = val;
211}
212
213static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu)
214{
215 return to_svcpu(vcpu)->pc;
216}
217
218static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu)
219{
220 ulong pc = kvmppc_get_pc(vcpu);
221 struct kvmppc_book3s_shadow_vcpu *svcpu = to_svcpu(vcpu);
222
223 /* Load the instruction manually if it failed to do so in the
224 * exit path */
225 if (svcpu->last_inst == KVM_INST_FETCH_FAILED)
226 kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false);
227
228 return svcpu->last_inst;
229}
230
231static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu)
232{
233 return to_svcpu(vcpu)->fault_dar;
234}
Alexander Graf4e3420252009-10-30 05:47:05 +0000235
Alexander Grafad0a0482010-03-24 21:48:30 +0100236/* Magic register values loaded into r3 and r4 before the 'sc' assembly
237 * instruction for the OSI hypercalls */
238#define OSI_SC_MAGIC_R3 0x113724FA
239#define OSI_SC_MAGIC_R4 0x77810F9B
240
Alexander Graf4e3420252009-10-30 05:47:05 +0000241#define INS_DCBZ 0x7c0007ec
242
Alexander Grafc7f38f42010-04-16 00:11:40 +0200243/* Also add subarch specific defines */
244
245#ifdef CONFIG_PPC_BOOK3S_32
246#include <asm/kvm_book3s_32.h>
247#else
248#include <asm/kvm_book3s_64.h>
249#endif
250
Alexander Graf4e3420252009-10-30 05:47:05 +0000251#endif /* __ASM_KVM_BOOK3S_H__ */