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