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 
27 struct kvmppc_slb {
28 	u64 esid;
29 	u64 vsid;
30 	u64 orige;
31 	u64 origv;
32 	bool valid;
33 	bool Ks;
34 	bool Kp;
35 	bool nx;
36 	bool large;
37 	bool class;
38 };
39 
40 struct kvmppc_sr {
41 	u32 raw;
42 	u32 vsid;
43 	bool Ks;
44 	bool Kp;
45 	bool nx;
46 };
47 
48 struct kvmppc_bat {
49 	u64 raw;
50 	u32 bepi;
51 	u32 bepi_mask;
52 	bool vs;
53 	bool vp;
54 	u32 brpn;
55 	u8 wimg;
56 	u8 pp;
57 };
58 
59 struct kvmppc_sid_map {
60 	u64 guest_vsid;
61 	u64 guest_esid;
62 	u64 host_vsid;
63 	bool valid;
64 };
65 
66 #define SID_MAP_BITS    9
67 #define SID_MAP_NUM     (1 << SID_MAP_BITS)
68 #define SID_MAP_MASK    (SID_MAP_NUM - 1)
69 
70 struct kvmppc_vcpu_book3s {
71 	struct kvm_vcpu vcpu;
72 	struct kvmppc_sid_map sid_map[SID_MAP_NUM];
73 	struct kvmppc_slb slb[64];
74 	struct {
75 		u64 esid;
76 		u64 vsid;
77 	} slb_shadow[64];
78 	u8 slb_shadow_max;
79 	struct kvmppc_sr sr[16];
80 	struct kvmppc_bat ibat[8];
81 	struct kvmppc_bat dbat[8];
82 	u64 hid[6];
83 	int slb_nr;
84 	u64 sdr1;
85 	u64 dsisr;
86 	u64 hior;
87 	u64 msr_mask;
88 	u64 vsid_first;
89 	u64 vsid_next;
90 	u64 vsid_max;
91 	int context_id;
92 };
93 
94 #define CONTEXT_HOST		0
95 #define CONTEXT_GUEST		1
96 #define CONTEXT_GUEST_END	2
97 
98 #define VSID_REAL	0xfffffffffff00000
99 #define VSID_REAL_DR	0xffffffffffe00000
100 #define VSID_REAL_IR	0xffffffffffd00000
101 #define VSID_BAT	0xffffffffffc00000
102 #define VSID_PR		0x8000000000000000
103 
104 extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask);
105 extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask);
106 extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end);
107 extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr);
108 extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu);
109 extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu);
110 extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte);
111 extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr);
112 extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu);
113 extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data);
114 extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr, bool data);
115 extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong eaddr, int size, void *ptr);
116 extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec);
117 extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
118 			   bool upper, u32 val);
119 
120 extern u32 kvmppc_trampoline_lowmem;
121 extern u32 kvmppc_trampoline_enter;
122 
123 static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu)
124 {
125 	return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu);
126 }
127 
128 static inline ulong dsisr(void)
129 {
130 	ulong r;
131 	asm ( "mfdsisr %0 " : "=r" (r) );
132 	return r;
133 }
134 
135 extern void kvm_return_point(void);
136 
137 #define INS_DCBZ			0x7c0007ec
138 
139 #endif /* __ASM_KVM_BOOK3S_H__ */
140