Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 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> |
Alexander Graf | 2191d65 | 2010-04-16 00:11:32 +0200 | [diff] [blame] | 25 | #include <asm/kvm_book3s_asm.h> |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 26 | |
| 27 | struct kvmppc_slb { |
| 28 | u64 esid; |
| 29 | u64 vsid; |
| 30 | u64 orige; |
| 31 | u64 origv; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 32 | 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 Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 41 | struct kvmppc_bat { |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 42 | u64 raw; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 43 | u32 bepi; |
| 44 | u32 bepi_mask; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 45 | u32 brpn; |
| 46 | u8 wimg; |
| 47 | u8 pp; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 48 | bool vs : 1; |
| 49 | bool vp : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct kvmppc_sid_map { |
| 53 | u64 guest_vsid; |
| 54 | u64 guest_esid; |
| 55 | u64 host_vsid; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 56 | bool valid : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 57 | }; |
| 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 | |
Alexander Graf | 8b6db3b | 2010-08-15 08:04:24 +0200 | [diff] [blame^] | 63 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 64 | #define SID_CONTEXTS 1 |
| 65 | #else |
| 66 | #define SID_CONTEXTS 128 |
| 67 | #define VSID_POOL_SIZE (SID_CONTEXTS * 16) |
| 68 | #endif |
| 69 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 70 | struct kvmppc_vcpu_book3s { |
| 71 | struct kvm_vcpu vcpu; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 72 | struct kvmppc_book3s_shadow_vcpu *shadow_vcpu; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 73 | struct kvmppc_sid_map sid_map[SID_MAP_NUM]; |
| 74 | struct kvmppc_slb slb[64]; |
| 75 | struct { |
| 76 | u64 esid; |
| 77 | u64 vsid; |
| 78 | } slb_shadow[64]; |
| 79 | u8 slb_shadow_max; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 80 | struct kvmppc_bat ibat[8]; |
| 81 | struct kvmppc_bat dbat[8]; |
| 82 | u64 hid[6]; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 83 | u64 gqr[8]; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 84 | int slb_nr; |
| 85 | u64 sdr1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 86 | u64 hior; |
| 87 | u64 msr_mask; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 88 | u64 vsid_next; |
Alexander Graf | 8b6db3b | 2010-08-15 08:04:24 +0200 | [diff] [blame^] | 89 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 90 | u32 vsid_pool[VSID_POOL_SIZE]; |
| 91 | #else |
| 92 | u64 vsid_first; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 93 | u64 vsid_max; |
Alexander Graf | 8b6db3b | 2010-08-15 08:04:24 +0200 | [diff] [blame^] | 94 | #endif |
| 95 | int context_id[SID_CONTEXTS]; |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 96 | ulong prog_flags; /* flags to inject when giving a 700 trap */ |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | #define CONTEXT_HOST 0 |
| 100 | #define CONTEXT_GUEST 1 |
| 101 | #define CONTEXT_GUEST_END 2 |
| 102 | |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 103 | #define VSID_REAL 0x1fffffffffc00000ULL |
| 104 | #define VSID_BAT 0x1fffffffffb00000ULL |
| 105 | #define VSID_REAL_DR 0x2000000000000000ULL |
| 106 | #define VSID_REAL_IR 0x4000000000000000ULL |
Alexander Graf | 5a1b419 | 2010-03-24 21:48:35 +0100 | [diff] [blame] | 107 | #define VSID_PR 0x8000000000000000ULL |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 108 | |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 109 | extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, ulong ea, ulong ea_mask); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 110 | extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask); |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 111 | extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, ulong pa_start, ulong pa_end); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 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); |
Alexander Graf | fef093be | 2010-06-30 15:18:46 +0200 | [diff] [blame] | 118 | |
| 119 | extern void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte); |
| 120 | extern struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu); |
| 121 | extern void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu); |
| 122 | extern int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu); |
| 123 | extern void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte); |
| 124 | extern int kvmppc_mmu_hpte_sysinit(void); |
| 125 | extern void kvmppc_mmu_hpte_sysexit(void); |
| 126 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 127 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); |
| 128 | extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 129 | extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec); |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 130 | extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, |
| 131 | bool upper, u32 val); |
Alexander Graf | aba3bd7 | 2010-02-19 11:00:39 +0100 | [diff] [blame] | 132 | extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); |
Alexander Graf | 831317b | 2010-02-19 11:00:44 +0100 | [diff] [blame] | 133 | extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu); |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 134 | extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 135 | |
Alexander Graf | 2b05d71 | 2010-07-29 15:04:21 +0200 | [diff] [blame] | 136 | extern ulong kvmppc_trampoline_lowmem; |
| 137 | extern ulong kvmppc_trampoline_enter; |
Alexander Graf | 021ec9c | 2010-01-08 02:58:06 +0100 | [diff] [blame] | 138 | extern void kvmppc_rmcall(ulong srr0, ulong srr1); |
Alexander Graf | d5e5281 | 2010-01-15 14:49:10 +0100 | [diff] [blame] | 139 | extern void kvmppc_load_up_fpu(void); |
| 140 | extern void kvmppc_load_up_altivec(void); |
| 141 | extern void kvmppc_load_up_vsx(void); |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 142 | extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst); |
| 143 | extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 144 | |
| 145 | static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) |
| 146 | { |
| 147 | return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); |
| 148 | } |
| 149 | |
| 150 | static inline ulong dsisr(void) |
| 151 | { |
| 152 | ulong r; |
| 153 | asm ( "mfdsisr %0 " : "=r" (r) ); |
| 154 | return r; |
| 155 | } |
| 156 | |
| 157 | extern void kvm_return_point(void); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 158 | static inline struct kvmppc_book3s_shadow_vcpu *to_svcpu(struct kvm_vcpu *vcpu); |
| 159 | |
| 160 | static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) |
| 161 | { |
| 162 | if ( num < 14 ) { |
| 163 | to_svcpu(vcpu)->gpr[num] = val; |
| 164 | to_book3s(vcpu)->shadow_vcpu->gpr[num] = val; |
| 165 | } else |
| 166 | vcpu->arch.gpr[num] = val; |
| 167 | } |
| 168 | |
| 169 | static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num) |
| 170 | { |
| 171 | if ( num < 14 ) |
| 172 | return to_svcpu(vcpu)->gpr[num]; |
| 173 | else |
| 174 | return vcpu->arch.gpr[num]; |
| 175 | } |
| 176 | |
| 177 | static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val) |
| 178 | { |
| 179 | to_svcpu(vcpu)->cr = val; |
| 180 | to_book3s(vcpu)->shadow_vcpu->cr = val; |
| 181 | } |
| 182 | |
| 183 | static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu) |
| 184 | { |
| 185 | return to_svcpu(vcpu)->cr; |
| 186 | } |
| 187 | |
| 188 | static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val) |
| 189 | { |
| 190 | to_svcpu(vcpu)->xer = val; |
| 191 | to_book3s(vcpu)->shadow_vcpu->xer = val; |
| 192 | } |
| 193 | |
| 194 | static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu) |
| 195 | { |
| 196 | return to_svcpu(vcpu)->xer; |
| 197 | } |
| 198 | |
| 199 | static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val) |
| 200 | { |
| 201 | to_svcpu(vcpu)->ctr = val; |
| 202 | } |
| 203 | |
| 204 | static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu) |
| 205 | { |
| 206 | return to_svcpu(vcpu)->ctr; |
| 207 | } |
| 208 | |
| 209 | static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val) |
| 210 | { |
| 211 | to_svcpu(vcpu)->lr = val; |
| 212 | } |
| 213 | |
| 214 | static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu) |
| 215 | { |
| 216 | return to_svcpu(vcpu)->lr; |
| 217 | } |
| 218 | |
| 219 | static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val) |
| 220 | { |
| 221 | to_svcpu(vcpu)->pc = val; |
| 222 | } |
| 223 | |
| 224 | static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu) |
| 225 | { |
| 226 | return to_svcpu(vcpu)->pc; |
| 227 | } |
| 228 | |
| 229 | static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu) |
| 230 | { |
| 231 | ulong pc = kvmppc_get_pc(vcpu); |
| 232 | struct kvmppc_book3s_shadow_vcpu *svcpu = to_svcpu(vcpu); |
| 233 | |
| 234 | /* Load the instruction manually if it failed to do so in the |
| 235 | * exit path */ |
| 236 | if (svcpu->last_inst == KVM_INST_FETCH_FAILED) |
| 237 | kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false); |
| 238 | |
| 239 | return svcpu->last_inst; |
| 240 | } |
| 241 | |
| 242 | static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) |
| 243 | { |
| 244 | return to_svcpu(vcpu)->fault_dar; |
| 245 | } |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 246 | |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 247 | /* Magic register values loaded into r3 and r4 before the 'sc' assembly |
| 248 | * instruction for the OSI hypercalls */ |
| 249 | #define OSI_SC_MAGIC_R3 0x113724FA |
| 250 | #define OSI_SC_MAGIC_R4 0x77810F9B |
| 251 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 252 | #define INS_DCBZ 0x7c0007ec |
| 253 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 254 | /* Also add subarch specific defines */ |
| 255 | |
| 256 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 257 | #include <asm/kvm_book3s_32.h> |
| 258 | #else |
| 259 | #include <asm/kvm_book3s_64.h> |
| 260 | #endif |
| 261 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 262 | #endif /* __ASM_KVM_BOOK3S_H__ */ |