Alexander Graf | 0123518 | 2009-10-30 05:47:13 +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 | #include <linux/types.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/kvm.h> |
| 23 | #include <linux/kvm_host.h> |
| 24 | #include <linux/highmem.h> |
| 25 | |
| 26 | #include <asm/tlbflush.h> |
| 27 | #include <asm/kvm_ppc.h> |
| 28 | #include <asm/kvm_book3s.h> |
| 29 | |
| 30 | /* #define DEBUG_MMU */ |
| 31 | /* #define DEBUG_MMU_PTE */ |
| 32 | /* #define DEBUG_MMU_PTE_IP 0xfff14c40 */ |
| 33 | |
| 34 | #ifdef DEBUG_MMU |
| 35 | #define dprintk(X...) printk(KERN_INFO X) |
| 36 | #else |
| 37 | #define dprintk(X...) do { } while(0) |
| 38 | #endif |
| 39 | |
Alexander Graf | e425a6d | 2010-02-19 11:00:36 +0100 | [diff] [blame] | 40 | #ifdef DEBUG_MMU_PTE |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 41 | #define dprintk_pte(X...) printk(KERN_INFO X) |
| 42 | #else |
| 43 | #define dprintk_pte(X...) do { } while(0) |
| 44 | #endif |
| 45 | |
| 46 | #define PTEG_FLAG_ACCESSED 0x00000100 |
| 47 | #define PTEG_FLAG_DIRTY 0x00000080 |
Alexander Graf | 07b0907 | 2010-04-16 00:11:53 +0200 | [diff] [blame] | 48 | #ifndef SID_SHIFT |
| 49 | #define SID_SHIFT 28 |
| 50 | #endif |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 51 | |
| 52 | static inline bool check_debug_ip(struct kvm_vcpu *vcpu) |
| 53 | { |
| 54 | #ifdef DEBUG_MMU_PTE_IP |
| 55 | return vcpu->arch.pc == DEBUG_MMU_PTE_IP; |
| 56 | #else |
| 57 | return true; |
| 58 | #endif |
| 59 | } |
| 60 | |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 61 | static inline u32 sr_vsid(u32 sr_raw) |
| 62 | { |
| 63 | return sr_raw & 0x0fffffff; |
| 64 | } |
| 65 | |
| 66 | static inline bool sr_valid(u32 sr_raw) |
| 67 | { |
| 68 | return (sr_raw & 0x80000000) ? false : true; |
| 69 | } |
| 70 | |
| 71 | static inline bool sr_ks(u32 sr_raw) |
| 72 | { |
| 73 | return (sr_raw & 0x40000000) ? true: false; |
| 74 | } |
| 75 | |
| 76 | static inline bool sr_kp(u32 sr_raw) |
| 77 | { |
| 78 | return (sr_raw & 0x20000000) ? true: false; |
| 79 | } |
| 80 | |
| 81 | static inline bool sr_nx(u32 sr_raw) |
| 82 | { |
| 83 | return (sr_raw & 0x10000000) ? true: false; |
| 84 | } |
| 85 | |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 86 | static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 87 | struct kvmppc_pte *pte, bool data); |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 88 | static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid, |
Alexander Graf | 4b389ca | 2010-03-24 21:48:20 +0100 | [diff] [blame] | 89 | u64 *vsid); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 90 | |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 91 | static u32 find_sr(struct kvm_vcpu *vcpu, gva_t eaddr) |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 92 | { |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 93 | return vcpu->arch.shared->sr[(eaddr >> 28) & 0xf]; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static u64 kvmppc_mmu_book3s_32_ea_to_vp(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 97 | bool data) |
| 98 | { |
Alexander Graf | 4b389ca | 2010-03-24 21:48:20 +0100 | [diff] [blame] | 99 | u64 vsid; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 100 | struct kvmppc_pte pte; |
| 101 | |
| 102 | if (!kvmppc_mmu_book3s_32_xlate_bat(vcpu, eaddr, &pte, data)) |
| 103 | return pte.vpage; |
| 104 | |
Alexander Graf | 4b389ca | 2010-03-24 21:48:20 +0100 | [diff] [blame] | 105 | kvmppc_mmu_book3s_32_esid_to_vsid(vcpu, eaddr >> SID_SHIFT, &vsid); |
| 106 | return (((u64)eaddr >> 12) & 0xffff) | (vsid << 16); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void kvmppc_mmu_book3s_32_reset_msr(struct kvm_vcpu *vcpu) |
| 110 | { |
| 111 | kvmppc_set_msr(vcpu, 0); |
| 112 | } |
| 113 | |
| 114 | static hva_t kvmppc_mmu_book3s_32_get_pteg(struct kvmppc_vcpu_book3s *vcpu_book3s, |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 115 | u32 sre, gva_t eaddr, |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 116 | bool primary) |
| 117 | { |
| 118 | u32 page, hash, pteg, htabmask; |
| 119 | hva_t r; |
| 120 | |
| 121 | page = (eaddr & 0x0FFFFFFF) >> 12; |
| 122 | htabmask = ((vcpu_book3s->sdr1 & 0x1FF) << 16) | 0xFFC0; |
| 123 | |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 124 | hash = ((sr_vsid(sre) ^ page) << 6); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 125 | if (!primary) |
| 126 | hash = ~hash; |
| 127 | hash &= htabmask; |
| 128 | |
| 129 | pteg = (vcpu_book3s->sdr1 & 0xffff0000) | hash; |
| 130 | |
| 131 | dprintk("MMU: pc=0x%lx eaddr=0x%lx sdr1=0x%llx pteg=0x%x vsid=0x%x\n", |
Alexander Graf | 5302104 | 2010-07-29 15:04:16 +0200 | [diff] [blame] | 132 | kvmppc_get_pc(&vcpu_book3s->vcpu), eaddr, vcpu_book3s->sdr1, pteg, |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 133 | sr_vsid(sre)); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 134 | |
| 135 | r = gfn_to_hva(vcpu_book3s->vcpu.kvm, pteg >> PAGE_SHIFT); |
| 136 | if (kvm_is_error_hva(r)) |
| 137 | return r; |
| 138 | return r | (pteg & ~PAGE_MASK); |
| 139 | } |
| 140 | |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 141 | static u32 kvmppc_mmu_book3s_32_get_ptem(u32 sre, gva_t eaddr, bool primary) |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 142 | { |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 143 | return ((eaddr & 0x0fffffff) >> 22) | (sr_vsid(sre) << 7) | |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 144 | (primary ? 0 : 0x40) | 0x80000000; |
| 145 | } |
| 146 | |
| 147 | static int kvmppc_mmu_book3s_32_xlate_bat(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 148 | struct kvmppc_pte *pte, bool data) |
| 149 | { |
| 150 | struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu); |
| 151 | struct kvmppc_bat *bat; |
| 152 | int i; |
| 153 | |
| 154 | for (i = 0; i < 8; i++) { |
| 155 | if (data) |
| 156 | bat = &vcpu_book3s->dbat[i]; |
| 157 | else |
| 158 | bat = &vcpu_book3s->ibat[i]; |
| 159 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 160 | if (vcpu->arch.shared->msr & MSR_PR) { |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 161 | if (!bat->vp) |
| 162 | continue; |
| 163 | } else { |
| 164 | if (!bat->vs) |
| 165 | continue; |
| 166 | } |
| 167 | |
| 168 | if (check_debug_ip(vcpu)) |
| 169 | { |
| 170 | dprintk_pte("%cBAT %02d: 0x%lx - 0x%x (0x%x)\n", |
| 171 | data ? 'd' : 'i', i, eaddr, bat->bepi, |
| 172 | bat->bepi_mask); |
| 173 | } |
| 174 | if ((eaddr & bat->bepi_mask) == bat->bepi) { |
Alexander Graf | 4b389ca | 2010-03-24 21:48:20 +0100 | [diff] [blame] | 175 | u64 vsid; |
| 176 | kvmppc_mmu_book3s_32_esid_to_vsid(vcpu, |
| 177 | eaddr >> SID_SHIFT, &vsid); |
| 178 | vsid <<= 16; |
| 179 | pte->vpage = (((u64)eaddr >> 12) & 0xffff) | vsid; |
| 180 | |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 181 | pte->raddr = bat->brpn | (eaddr & ~bat->bepi_mask); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 182 | pte->may_read = bat->pp; |
| 183 | pte->may_write = bat->pp > 1; |
| 184 | pte->may_execute = true; |
| 185 | if (!pte->may_read) { |
| 186 | printk(KERN_INFO "BAT is not readable!\n"); |
| 187 | continue; |
| 188 | } |
| 189 | if (!pte->may_write) { |
| 190 | /* let's treat r/o BATs as not-readable for now */ |
| 191 | dprintk_pte("BAT is read-only!\n"); |
| 192 | continue; |
| 193 | } |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return -ENOENT; |
| 200 | } |
| 201 | |
| 202 | static int kvmppc_mmu_book3s_32_xlate_pte(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 203 | struct kvmppc_pte *pte, bool data, |
| 204 | bool primary) |
| 205 | { |
| 206 | struct kvmppc_vcpu_book3s *vcpu_book3s = to_book3s(vcpu); |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 207 | u32 sre; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 208 | hva_t ptegp; |
| 209 | u32 pteg[16]; |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 210 | u32 ptem = 0; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 211 | int i; |
| 212 | int found = 0; |
| 213 | |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 214 | sre = find_sr(vcpu, eaddr); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 215 | |
| 216 | dprintk_pte("SR 0x%lx: vsid=0x%x, raw=0x%x\n", eaddr >> 28, |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 217 | sr_vsid(sre), sre); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 218 | |
| 219 | pte->vpage = kvmppc_mmu_book3s_32_ea_to_vp(vcpu, eaddr, data); |
| 220 | |
| 221 | ptegp = kvmppc_mmu_book3s_32_get_pteg(vcpu_book3s, sre, eaddr, primary); |
| 222 | if (kvm_is_error_hva(ptegp)) { |
| 223 | printk(KERN_INFO "KVM: Invalid PTEG!\n"); |
| 224 | goto no_page_found; |
| 225 | } |
| 226 | |
| 227 | ptem = kvmppc_mmu_book3s_32_get_ptem(sre, eaddr, primary); |
| 228 | |
| 229 | if(copy_from_user(pteg, (void __user *)ptegp, sizeof(pteg))) { |
| 230 | printk(KERN_ERR "KVM: Can't copy data from 0x%lx!\n", ptegp); |
| 231 | goto no_page_found; |
| 232 | } |
| 233 | |
| 234 | for (i=0; i<16; i+=2) { |
| 235 | if (ptem == pteg[i]) { |
| 236 | u8 pp; |
| 237 | |
| 238 | pte->raddr = (pteg[i+1] & ~(0xFFFULL)) | (eaddr & 0xFFF); |
| 239 | pp = pteg[i+1] & 3; |
| 240 | |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 241 | if ((sr_kp(sre) && (vcpu->arch.shared->msr & MSR_PR)) || |
| 242 | (sr_ks(sre) && !(vcpu->arch.shared->msr & MSR_PR))) |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 243 | pp |= 4; |
| 244 | |
| 245 | pte->may_write = false; |
| 246 | pte->may_read = false; |
| 247 | pte->may_execute = true; |
| 248 | switch (pp) { |
| 249 | case 0: |
| 250 | case 1: |
| 251 | case 2: |
| 252 | case 6: |
| 253 | pte->may_write = true; |
| 254 | case 3: |
| 255 | case 5: |
| 256 | case 7: |
| 257 | pte->may_read = true; |
| 258 | break; |
| 259 | } |
| 260 | |
| 261 | if ( !pte->may_read ) |
| 262 | continue; |
| 263 | |
| 264 | dprintk_pte("MMU: Found PTE -> %x %x - %x\n", |
| 265 | pteg[i], pteg[i+1], pp); |
| 266 | found = 1; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /* Update PTE C and A bits, so the guest's swapper knows we used the |
| 272 | page */ |
| 273 | if (found) { |
| 274 | u32 oldpte = pteg[i+1]; |
| 275 | |
| 276 | if (pte->may_read) |
| 277 | pteg[i+1] |= PTEG_FLAG_ACCESSED; |
| 278 | if (pte->may_write) |
| 279 | pteg[i+1] |= PTEG_FLAG_DIRTY; |
| 280 | else |
| 281 | dprintk_pte("KVM: Mapping read-only page!\n"); |
| 282 | |
| 283 | /* Write back into the PTEG */ |
| 284 | if (pteg[i+1] != oldpte) |
| 285 | copy_to_user((void __user *)ptegp, pteg, sizeof(pteg)); |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | no_page_found: |
| 291 | |
| 292 | if (check_debug_ip(vcpu)) { |
| 293 | dprintk_pte("KVM MMU: No PTE found (sdr1=0x%llx ptegp=0x%lx)\n", |
| 294 | to_book3s(vcpu)->sdr1, ptegp); |
| 295 | for (i=0; i<16; i+=2) { |
Alexander Graf | 5302104 | 2010-07-29 15:04:16 +0200 | [diff] [blame] | 296 | dprintk_pte(" %02d: 0x%x - 0x%x (0x%x)\n", |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 297 | i, pteg[i], pteg[i+1], ptem); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | return -ENOENT; |
| 302 | } |
| 303 | |
| 304 | static int kvmppc_mmu_book3s_32_xlate(struct kvm_vcpu *vcpu, gva_t eaddr, |
| 305 | struct kvmppc_pte *pte, bool data) |
| 306 | { |
| 307 | int r; |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 308 | ulong mp_ea = vcpu->arch.magic_page_ea; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 309 | |
| 310 | pte->eaddr = eaddr; |
Alexander Graf | e850894 | 2010-07-29 14:47:54 +0200 | [diff] [blame] | 311 | |
| 312 | /* Magic page override */ |
| 313 | if (unlikely(mp_ea) && |
| 314 | unlikely((eaddr & ~0xfffULL) == (mp_ea & ~0xfffULL)) && |
| 315 | !(vcpu->arch.shared->msr & MSR_PR)) { |
| 316 | pte->vpage = kvmppc_mmu_book3s_32_ea_to_vp(vcpu, eaddr, data); |
| 317 | pte->raddr = vcpu->arch.magic_page_pa | (pte->raddr & 0xfff); |
| 318 | pte->raddr &= KVM_PAM; |
| 319 | pte->may_execute = true; |
| 320 | pte->may_read = true; |
| 321 | pte->may_write = true; |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 326 | r = kvmppc_mmu_book3s_32_xlate_bat(vcpu, eaddr, pte, data); |
| 327 | if (r < 0) |
| 328 | r = kvmppc_mmu_book3s_32_xlate_pte(vcpu, eaddr, pte, data, true); |
| 329 | if (r < 0) |
| 330 | r = kvmppc_mmu_book3s_32_xlate_pte(vcpu, eaddr, pte, data, false); |
| 331 | |
| 332 | return r; |
| 333 | } |
| 334 | |
| 335 | |
| 336 | static u32 kvmppc_mmu_book3s_32_mfsrin(struct kvm_vcpu *vcpu, u32 srnum) |
| 337 | { |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 338 | return vcpu->arch.shared->sr[srnum]; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void kvmppc_mmu_book3s_32_mtsrin(struct kvm_vcpu *vcpu, u32 srnum, |
| 342 | ulong value) |
| 343 | { |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 344 | vcpu->arch.shared->sr[srnum] = value; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 345 | kvmppc_mmu_map_segment(vcpu, srnum << SID_SHIFT); |
| 346 | } |
| 347 | |
| 348 | static void kvmppc_mmu_book3s_32_tlbie(struct kvm_vcpu *vcpu, ulong ea, bool large) |
| 349 | { |
Alexander Graf | 4b389ca | 2010-03-24 21:48:20 +0100 | [diff] [blame] | 350 | kvmppc_mmu_pte_flush(vcpu, ea, 0x0FFFF000); |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 353 | static int kvmppc_mmu_book3s_32_esid_to_vsid(struct kvm_vcpu *vcpu, ulong esid, |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 354 | u64 *vsid) |
| 355 | { |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 356 | ulong ea = esid << SID_SHIFT; |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 357 | u32 sr; |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 358 | u64 gvsid = esid; |
| 359 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 360 | if (vcpu->arch.shared->msr & (MSR_DR|MSR_IR)) { |
Alexander Graf | df1bfa2 | 2010-08-03 02:29:27 +0200 | [diff] [blame] | 361 | sr = find_sr(vcpu, ea); |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 362 | if (sr_valid(sr)) |
| 363 | gvsid = sr_vsid(sr); |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 366 | /* In case we only have one of MSR_IR or MSR_DR set, let's put |
| 367 | that in the real-mode context (and hope RM doesn't access |
| 368 | high memory) */ |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 369 | switch (vcpu->arch.shared->msr & (MSR_DR|MSR_IR)) { |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 370 | case 0: |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 371 | *vsid = VSID_REAL | esid; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 372 | break; |
| 373 | case MSR_IR: |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 374 | *vsid = VSID_REAL_IR | gvsid; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 375 | break; |
| 376 | case MSR_DR: |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 377 | *vsid = VSID_REAL_DR | gvsid; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 378 | break; |
| 379 | case MSR_DR|MSR_IR: |
Alexander Graf | 8e86517 | 2010-08-03 01:06:11 +0200 | [diff] [blame] | 380 | if (sr_valid(sr)) |
| 381 | *vsid = sr_vsid(sr); |
Alexander Graf | 4d29bdb | 2010-06-21 15:24:55 +0200 | [diff] [blame] | 382 | else |
| 383 | *vsid = VSID_BAT | gvsid; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 384 | break; |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 385 | default: |
| 386 | BUG(); |
| 387 | } |
| 388 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 389 | if (vcpu->arch.shared->msr & MSR_PR) |
Alexander Graf | 4b389ca | 2010-03-24 21:48:20 +0100 | [diff] [blame] | 390 | *vsid |= VSID_PR; |
| 391 | |
Alexander Graf | 0123518 | 2009-10-30 05:47:13 +0000 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static bool kvmppc_mmu_book3s_32_is_dcbz32(struct kvm_vcpu *vcpu) |
| 396 | { |
| 397 | return true; |
| 398 | } |
| 399 | |
| 400 | |
| 401 | void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu) |
| 402 | { |
| 403 | struct kvmppc_mmu *mmu = &vcpu->arch.mmu; |
| 404 | |
| 405 | mmu->mtsrin = kvmppc_mmu_book3s_32_mtsrin; |
| 406 | mmu->mfsrin = kvmppc_mmu_book3s_32_mfsrin; |
| 407 | mmu->xlate = kvmppc_mmu_book3s_32_xlate; |
| 408 | mmu->reset_msr = kvmppc_mmu_book3s_32_reset_msr; |
| 409 | mmu->tlbie = kvmppc_mmu_book3s_32_tlbie; |
| 410 | mmu->esid_to_vsid = kvmppc_mmu_book3s_32_esid_to_vsid; |
| 411 | mmu->ea_to_vp = kvmppc_mmu_book3s_32_ea_to_vp; |
| 412 | mmu->is_dcbz32 = kvmppc_mmu_book3s_32_is_dcbz32; |
| 413 | |
| 414 | mmu->slbmte = NULL; |
| 415 | mmu->slbmfee = NULL; |
| 416 | mmu->slbmfev = NULL; |
| 417 | mmu->slbie = NULL; |
| 418 | mmu->slbia = NULL; |
| 419 | } |