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 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 27 | struct kvmppc_bat { |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 28 | u64 raw; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 29 | u32 bepi; |
| 30 | u32 bepi_mask; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 31 | u32 brpn; |
| 32 | u8 wimg; |
| 33 | u8 pp; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 34 | bool vs : 1; |
| 35 | bool vp : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct kvmppc_sid_map { |
| 39 | u64 guest_vsid; |
| 40 | u64 guest_esid; |
| 41 | u64 host_vsid; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 42 | bool valid : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #define SID_MAP_BITS 9 |
| 46 | #define SID_MAP_NUM (1 << SID_MAP_BITS) |
| 47 | #define SID_MAP_MASK (SID_MAP_NUM - 1) |
| 48 | |
Alexander Graf | 8b6db3b | 2010-08-15 08:04:24 +0200 | [diff] [blame] | 49 | #ifdef CONFIG_PPC_BOOK3S_64 |
| 50 | #define SID_CONTEXTS 1 |
| 51 | #else |
| 52 | #define SID_CONTEXTS 128 |
| 53 | #define VSID_POOL_SIZE (SID_CONTEXTS * 16) |
| 54 | #endif |
| 55 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 56 | struct hpte_cache { |
| 57 | struct hlist_node list_pte; |
| 58 | struct hlist_node list_pte_long; |
| 59 | struct hlist_node list_vpte; |
| 60 | struct hlist_node list_vpte_long; |
| 61 | struct rcu_head rcu_head; |
| 62 | u64 host_va; |
| 63 | u64 pfn; |
| 64 | ulong slot; |
| 65 | struct kvmppc_pte pte; |
| 66 | }; |
| 67 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 68 | struct kvmppc_vcpu_book3s { |
| 69 | struct kvm_vcpu vcpu; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 70 | struct kvmppc_book3s_shadow_vcpu *shadow_vcpu; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 71 | struct kvmppc_sid_map sid_map[SID_MAP_NUM]; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 72 | struct { |
| 73 | u64 esid; |
| 74 | u64 vsid; |
| 75 | } slb_shadow[64]; |
| 76 | u8 slb_shadow_max; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 77 | struct kvmppc_bat ibat[8]; |
| 78 | struct kvmppc_bat dbat[8]; |
| 79 | u64 hid[6]; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 80 | u64 gqr[8]; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 81 | u64 sdr1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 82 | u64 hior; |
| 83 | u64 msr_mask; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 84 | u64 vsid_next; |
Alexander Graf | 8b6db3b | 2010-08-15 08:04:24 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_PPC_BOOK3S_32 |
| 86 | u32 vsid_pool[VSID_POOL_SIZE]; |
| 87 | #else |
| 88 | u64 vsid_first; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 89 | u64 vsid_max; |
Alexander Graf | 8b6db3b | 2010-08-15 08:04:24 +0200 | [diff] [blame] | 90 | #endif |
| 91 | int context_id[SID_CONTEXTS]; |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 92 | |
Alexander Graf | 1022fc3 | 2011-09-14 21:45:23 +0200 | [diff] [blame] | 93 | bool hior_explicit; /* HIOR is set by ioctl, not PVR */ |
| 94 | |
Paul Mackerras | c4befc5 | 2011-06-29 00:17:33 +0000 | [diff] [blame] | 95 | struct hlist_head hpte_hash_pte[HPTEG_HASH_NUM_PTE]; |
| 96 | struct hlist_head hpte_hash_pte_long[HPTEG_HASH_NUM_PTE_LONG]; |
| 97 | struct hlist_head hpte_hash_vpte[HPTEG_HASH_NUM_VPTE]; |
| 98 | struct hlist_head hpte_hash_vpte_long[HPTEG_HASH_NUM_VPTE_LONG]; |
| 99 | int hpte_cache_count; |
| 100 | spinlock_t mmu_lock; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | #define CONTEXT_HOST 0 |
| 104 | #define CONTEXT_GUEST 1 |
| 105 | #define CONTEXT_GUEST_END 2 |
| 106 | |
Alexander Graf | f7bc74e | 2010-04-20 02:49:48 +0200 | [diff] [blame] | 107 | #define VSID_REAL 0x1fffffffffc00000ULL |
| 108 | #define VSID_BAT 0x1fffffffffb00000ULL |
| 109 | #define VSID_REAL_DR 0x2000000000000000ULL |
| 110 | #define VSID_REAL_IR 0x4000000000000000ULL |
Alexander Graf | 5a1b419 | 2010-03-24 21:48:35 +0100 | [diff] [blame] | 111 | #define VSID_PR 0x8000000000000000ULL |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 112 | |
Alexander Graf | af7b4d1 | 2010-04-20 02:49:46 +0200 | [diff] [blame] | 113 | 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] | 114 | 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] | 115 | 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] | 116 | extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr); |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 117 | extern void kvmppc_set_pvr(struct kvm_vcpu *vcpu, u32 pvr); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 118 | extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu); |
| 119 | extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 120 | extern void kvmppc_mmu_book3s_hv_init(struct kvm_vcpu *vcpu); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 121 | extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte); |
| 122 | extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr); |
| 123 | extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu); |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 124 | extern int kvmppc_book3s_hv_page_fault(struct kvm_run *run, |
| 125 | struct kvm_vcpu *vcpu, unsigned long addr, |
| 126 | unsigned long status); |
| 127 | extern long kvmppc_hv_find_lock_hpte(struct kvm *kvm, gva_t eaddr, |
| 128 | unsigned long slb_v, unsigned long valid); |
Alexander Graf | fef093be | 2010-06-30 15:18:46 +0200 | [diff] [blame] | 129 | |
| 130 | extern void kvmppc_mmu_hpte_cache_map(struct kvm_vcpu *vcpu, struct hpte_cache *pte); |
| 131 | extern struct hpte_cache *kvmppc_mmu_hpte_cache_next(struct kvm_vcpu *vcpu); |
| 132 | extern void kvmppc_mmu_hpte_destroy(struct kvm_vcpu *vcpu); |
| 133 | extern int kvmppc_mmu_hpte_init(struct kvm_vcpu *vcpu); |
| 134 | extern void kvmppc_mmu_invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte); |
| 135 | extern int kvmppc_mmu_hpte_sysinit(void); |
| 136 | extern void kvmppc_mmu_hpte_sysexit(void); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 137 | extern int kvmppc_mmu_hv_init(void); |
Alexander Graf | fef093be | 2010-06-30 15:18:46 +0200 | [diff] [blame] | 138 | |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 139 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); |
| 140 | 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] | 141 | extern void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 142 | extern void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags); |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 143 | extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, |
| 144 | bool upper, u32 val); |
Alexander Graf | aba3bd7 | 2010-02-19 11:00:39 +0100 | [diff] [blame] | 145 | extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); |
Alexander Graf | 831317b | 2010-02-19 11:00:44 +0100 | [diff] [blame] | 146 | 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] | 147 | extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn); |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 148 | extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev, |
| 149 | unsigned long *rmap, long pte_index, int realmode); |
| 150 | extern void kvmppc_invalidate_hpte(struct kvm *kvm, unsigned long *hptep, |
| 151 | unsigned long pte_index); |
Paul Mackerras | 5551489 | 2011-12-15 02:02:47 +0000 | [diff] [blame] | 152 | void kvmppc_clear_ref_hpte(struct kvm *kvm, unsigned long *hptep, |
| 153 | unsigned long pte_index); |
Paul Mackerras | 93e6024 | 2011-12-12 12:28:55 +0000 | [diff] [blame] | 154 | extern void *kvmppc_pin_guest_page(struct kvm *kvm, unsigned long addr, |
| 155 | unsigned long *nb_ret); |
| 156 | extern void kvmppc_unpin_guest_page(struct kvm *kvm, void *addr); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 157 | extern long kvmppc_virtmode_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, |
| 158 | long pte_index, unsigned long pteh, unsigned long ptel); |
| 159 | extern long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, |
| 160 | long pte_index, unsigned long pteh, unsigned long ptel); |
Paul Mackerras | 82ed361 | 2011-12-15 02:03:22 +0000 | [diff] [blame] | 161 | extern long kvmppc_hv_get_dirty_log(struct kvm *kvm, |
| 162 | struct kvm_memory_slot *memslot); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 163 | |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 164 | extern void kvmppc_entry_trampoline(void); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 165 | extern void kvmppc_hv_entry_trampoline(void); |
Alexander Graf | d5e5281 | 2010-01-15 14:49:10 +0100 | [diff] [blame] | 166 | extern void kvmppc_load_up_fpu(void); |
| 167 | extern void kvmppc_load_up_altivec(void); |
| 168 | extern void kvmppc_load_up_vsx(void); |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 169 | extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst); |
| 170 | extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst); |
Alexander Graf | 0254f074 | 2011-08-08 17:21:15 +0200 | [diff] [blame] | 171 | extern int kvmppc_h_pr(struct kvm_vcpu *vcpu, unsigned long cmd); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 172 | |
| 173 | static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) |
| 174 | { |
| 175 | return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); |
| 176 | } |
| 177 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 178 | extern void kvm_return_point(void); |
| 179 | |
| 180 | /* Also add subarch specific defines */ |
| 181 | |
| 182 | #ifdef CONFIG_KVM_BOOK3S_32_HANDLER |
| 183 | #include <asm/kvm_book3s_32.h> |
| 184 | #endif |
| 185 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
| 186 | #include <asm/kvm_book3s_64.h> |
| 187 | #endif |
| 188 | |
| 189 | #ifdef CONFIG_KVM_BOOK3S_PR |
| 190 | |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 191 | static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu) |
| 192 | { |
| 193 | return to_book3s(vcpu)->hior; |
| 194 | } |
| 195 | |
| 196 | static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu, |
| 197 | unsigned long pending_now, unsigned long old_pending) |
| 198 | { |
| 199 | if (pending_now) |
| 200 | vcpu->arch.shared->int_pending = 1; |
| 201 | else if (old_pending) |
| 202 | vcpu->arch.shared->int_pending = 0; |
| 203 | } |
| 204 | |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 205 | static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) |
| 206 | { |
| 207 | if ( num < 14 ) { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 208 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 209 | svcpu->gpr[num] = val; |
| 210 | svcpu_put(svcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 211 | to_book3s(vcpu)->shadow_vcpu->gpr[num] = val; |
| 212 | } else |
| 213 | vcpu->arch.gpr[num] = val; |
| 214 | } |
| 215 | |
| 216 | static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num) |
| 217 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 218 | if ( num < 14 ) { |
| 219 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 220 | ulong r = svcpu->gpr[num]; |
| 221 | svcpu_put(svcpu); |
| 222 | return r; |
| 223 | } else |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 224 | return vcpu->arch.gpr[num]; |
| 225 | } |
| 226 | |
| 227 | static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val) |
| 228 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 229 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 230 | svcpu->cr = val; |
| 231 | svcpu_put(svcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 232 | to_book3s(vcpu)->shadow_vcpu->cr = val; |
| 233 | } |
| 234 | |
| 235 | static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu) |
| 236 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 237 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 238 | u32 r; |
| 239 | r = svcpu->cr; |
| 240 | svcpu_put(svcpu); |
| 241 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val) |
| 245 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 246 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 247 | svcpu->xer = val; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 248 | to_book3s(vcpu)->shadow_vcpu->xer = val; |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 249 | svcpu_put(svcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu) |
| 253 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 254 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 255 | u32 r; |
| 256 | r = svcpu->xer; |
| 257 | svcpu_put(svcpu); |
| 258 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val) |
| 262 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 263 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 264 | svcpu->ctr = val; |
| 265 | svcpu_put(svcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu) |
| 269 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 270 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 271 | ulong r; |
| 272 | r = svcpu->ctr; |
| 273 | svcpu_put(svcpu); |
| 274 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val) |
| 278 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 279 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 280 | svcpu->lr = val; |
| 281 | svcpu_put(svcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu) |
| 285 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 286 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 287 | ulong r; |
| 288 | r = svcpu->lr; |
| 289 | svcpu_put(svcpu); |
| 290 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val) |
| 294 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 295 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 296 | svcpu->pc = val; |
| 297 | svcpu_put(svcpu); |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu) |
| 301 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 302 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 303 | ulong r; |
| 304 | r = svcpu->pc; |
| 305 | svcpu_put(svcpu); |
| 306 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu) |
| 310 | { |
| 311 | ulong pc = kvmppc_get_pc(vcpu); |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 312 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 313 | u32 r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 314 | |
| 315 | /* Load the instruction manually if it failed to do so in the |
| 316 | * exit path */ |
| 317 | if (svcpu->last_inst == KVM_INST_FETCH_FAILED) |
| 318 | kvmppc_ld(vcpu, &pc, sizeof(u32), &svcpu->last_inst, false); |
| 319 | |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 320 | r = svcpu->last_inst; |
| 321 | svcpu_put(svcpu); |
| 322 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) |
| 326 | { |
Alexander Graf | 468a12c | 2011-12-09 14:44:13 +0100 | [diff] [blame] | 327 | struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu); |
| 328 | ulong r; |
| 329 | r = svcpu->fault_dar; |
| 330 | svcpu_put(svcpu); |
| 331 | return r; |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 332 | } |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 333 | |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 334 | static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) |
| 335 | { |
| 336 | ulong crit_raw = vcpu->arch.shared->critical; |
| 337 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 338 | bool crit; |
| 339 | |
| 340 | /* Truncate crit indicators in 32 bit mode */ |
| 341 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 342 | crit_raw &= 0xffffffff; |
| 343 | crit_r1 &= 0xffffffff; |
| 344 | } |
| 345 | |
| 346 | /* Critical section when crit == r1 */ |
| 347 | crit = (crit_raw == crit_r1); |
| 348 | /* ... and we're in supervisor mode */ |
| 349 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
| 350 | |
| 351 | return crit; |
| 352 | } |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 353 | #else /* CONFIG_KVM_BOOK3S_PR */ |
| 354 | |
| 355 | static inline unsigned long kvmppc_interrupt_offset(struct kvm_vcpu *vcpu) |
| 356 | { |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static inline void kvmppc_update_int_pending(struct kvm_vcpu *vcpu, |
| 361 | unsigned long pending_now, unsigned long old_pending) |
| 362 | { |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val) |
| 366 | { |
| 367 | vcpu->arch.gpr[num] = val; |
| 368 | } |
| 369 | |
| 370 | static inline ulong kvmppc_get_gpr(struct kvm_vcpu *vcpu, int num) |
| 371 | { |
| 372 | return vcpu->arch.gpr[num]; |
| 373 | } |
| 374 | |
| 375 | static inline void kvmppc_set_cr(struct kvm_vcpu *vcpu, u32 val) |
| 376 | { |
| 377 | vcpu->arch.cr = val; |
| 378 | } |
| 379 | |
| 380 | static inline u32 kvmppc_get_cr(struct kvm_vcpu *vcpu) |
| 381 | { |
| 382 | return vcpu->arch.cr; |
| 383 | } |
| 384 | |
| 385 | static inline void kvmppc_set_xer(struct kvm_vcpu *vcpu, u32 val) |
| 386 | { |
| 387 | vcpu->arch.xer = val; |
| 388 | } |
| 389 | |
| 390 | static inline u32 kvmppc_get_xer(struct kvm_vcpu *vcpu) |
| 391 | { |
| 392 | return vcpu->arch.xer; |
| 393 | } |
| 394 | |
| 395 | static inline void kvmppc_set_ctr(struct kvm_vcpu *vcpu, ulong val) |
| 396 | { |
| 397 | vcpu->arch.ctr = val; |
| 398 | } |
| 399 | |
| 400 | static inline ulong kvmppc_get_ctr(struct kvm_vcpu *vcpu) |
| 401 | { |
| 402 | return vcpu->arch.ctr; |
| 403 | } |
| 404 | |
| 405 | static inline void kvmppc_set_lr(struct kvm_vcpu *vcpu, ulong val) |
| 406 | { |
| 407 | vcpu->arch.lr = val; |
| 408 | } |
| 409 | |
| 410 | static inline ulong kvmppc_get_lr(struct kvm_vcpu *vcpu) |
| 411 | { |
| 412 | return vcpu->arch.lr; |
| 413 | } |
| 414 | |
| 415 | static inline void kvmppc_set_pc(struct kvm_vcpu *vcpu, ulong val) |
| 416 | { |
| 417 | vcpu->arch.pc = val; |
| 418 | } |
| 419 | |
| 420 | static inline ulong kvmppc_get_pc(struct kvm_vcpu *vcpu) |
| 421 | { |
| 422 | return vcpu->arch.pc; |
| 423 | } |
| 424 | |
| 425 | static inline u32 kvmppc_get_last_inst(struct kvm_vcpu *vcpu) |
| 426 | { |
| 427 | ulong pc = kvmppc_get_pc(vcpu); |
| 428 | |
| 429 | /* Load the instruction manually if it failed to do so in the |
| 430 | * exit path */ |
| 431 | if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) |
| 432 | kvmppc_ld(vcpu, &pc, sizeof(u32), &vcpu->arch.last_inst, false); |
| 433 | |
| 434 | return vcpu->arch.last_inst; |
| 435 | } |
| 436 | |
| 437 | static inline ulong kvmppc_get_fault_dar(struct kvm_vcpu *vcpu) |
| 438 | { |
| 439 | return vcpu->arch.fault_dar; |
| 440 | } |
| 441 | |
| 442 | static inline bool kvmppc_critical_section(struct kvm_vcpu *vcpu) |
| 443 | { |
| 444 | return false; |
| 445 | } |
| 446 | #endif |
Paul Mackerras | f05ed4d | 2011-06-29 00:17:58 +0000 | [diff] [blame] | 447 | |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 448 | /* Magic register values loaded into r3 and r4 before the 'sc' assembly |
| 449 | * instruction for the OSI hypercalls */ |
| 450 | #define OSI_SC_MAGIC_R3 0x113724FA |
| 451 | #define OSI_SC_MAGIC_R4 0x77810F9B |
| 452 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 453 | #define INS_DCBZ 0x7c0007ec |
| 454 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 455 | #endif /* __ASM_KVM_BOOK3S_H__ */ |