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 | |
| 41 | struct kvmppc_sr { |
| 42 | u32 raw; |
| 43 | u32 vsid; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 44 | bool Ks : 1; |
| 45 | bool Kp : 1; |
| 46 | bool nx : 1; |
| 47 | bool valid : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct kvmppc_bat { |
Alexander Graf | e15a113 | 2009-11-30 03:02:02 +0000 | [diff] [blame] | 51 | u64 raw; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 52 | u32 bepi; |
| 53 | u32 bepi_mask; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 54 | u32 brpn; |
| 55 | u8 wimg; |
| 56 | u8 pp; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 57 | bool vs : 1; |
| 58 | bool vp : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct kvmppc_sid_map { |
| 62 | u64 guest_vsid; |
| 63 | u64 guest_esid; |
| 64 | u64 host_vsid; |
Alexander Graf | 3ed9c6d | 2010-03-24 21:48:36 +0100 | [diff] [blame] | 65 | bool valid : 1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #define SID_MAP_BITS 9 |
| 69 | #define SID_MAP_NUM (1 << SID_MAP_BITS) |
| 70 | #define SID_MAP_MASK (SID_MAP_NUM - 1) |
| 71 | |
| 72 | struct kvmppc_vcpu_book3s { |
| 73 | struct kvm_vcpu vcpu; |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 74 | struct kvmppc_book3s_shadow_vcpu shadow_vcpu; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 75 | struct kvmppc_sid_map sid_map[SID_MAP_NUM]; |
| 76 | struct kvmppc_slb slb[64]; |
| 77 | struct { |
| 78 | u64 esid; |
| 79 | u64 vsid; |
| 80 | } slb_shadow[64]; |
| 81 | u8 slb_shadow_max; |
| 82 | struct kvmppc_sr sr[16]; |
| 83 | struct kvmppc_bat ibat[8]; |
| 84 | struct kvmppc_bat dbat[8]; |
| 85 | u64 hid[6]; |
Alexander Graf | d6d549b | 2010-02-19 11:00:33 +0100 | [diff] [blame] | 86 | u64 gqr[8]; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 87 | int slb_nr; |
Alexander Graf | c8027f1 | 2010-03-24 21:48:19 +0100 | [diff] [blame] | 88 | u32 dsisr; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 89 | u64 sdr1; |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 90 | u64 hior; |
| 91 | u64 msr_mask; |
| 92 | u64 vsid_first; |
| 93 | u64 vsid_next; |
| 94 | u64 vsid_max; |
| 95 | int context_id; |
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 | 5a1b419 | 2010-03-24 21:48:35 +0100 | [diff] [blame] | 103 | #define VSID_REAL_DR 0x7ffffffffff00000ULL |
| 104 | #define VSID_REAL_IR 0x7fffffffffe00000ULL |
| 105 | #define VSID_SPLIT_MASK 0x7fffffffffe00000ULL |
| 106 | #define VSID_REAL 0x7fffffffffc00000ULL |
| 107 | #define VSID_BAT 0x7fffffffffb00000ULL |
| 108 | #define VSID_PR 0x8000000000000000ULL |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 109 | |
| 110 | extern void kvmppc_mmu_pte_flush(struct kvm_vcpu *vcpu, u64 ea, u64 ea_mask); |
| 111 | extern void kvmppc_mmu_pte_vflush(struct kvm_vcpu *vcpu, u64 vp, u64 vp_mask); |
| 112 | extern void kvmppc_mmu_pte_pflush(struct kvm_vcpu *vcpu, u64 pa_start, u64 pa_end); |
| 113 | extern void kvmppc_set_msr(struct kvm_vcpu *vcpu, u64 new_msr); |
| 114 | extern void kvmppc_mmu_book3s_64_init(struct kvm_vcpu *vcpu); |
| 115 | extern void kvmppc_mmu_book3s_32_init(struct kvm_vcpu *vcpu); |
| 116 | extern int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte); |
| 117 | extern int kvmppc_mmu_map_segment(struct kvm_vcpu *vcpu, ulong eaddr); |
| 118 | extern void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu); |
| 119 | extern struct kvmppc_pte *kvmppc_mmu_find_pte(struct kvm_vcpu *vcpu, u64 ea, bool data); |
Alexander Graf | 5467a97 | 2010-02-19 11:00:38 +0100 | [diff] [blame] | 120 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, bool data); |
| 121 | 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] | 122 | 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] | 123 | extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat, |
| 124 | bool upper, u32 val); |
Alexander Graf | aba3bd7 | 2010-02-19 11:00:39 +0100 | [diff] [blame] | 125 | extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); |
Alexander Graf | 831317b | 2010-02-19 11:00:44 +0100 | [diff] [blame] | 126 | extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 127 | |
| 128 | extern u32 kvmppc_trampoline_lowmem; |
| 129 | extern u32 kvmppc_trampoline_enter; |
Alexander Graf | 021ec9c | 2010-01-08 02:58:06 +0100 | [diff] [blame] | 130 | extern void kvmppc_rmcall(ulong srr0, ulong srr1); |
Alexander Graf | d5e5281 | 2010-01-15 14:49:10 +0100 | [diff] [blame] | 131 | extern void kvmppc_load_up_fpu(void); |
| 132 | extern void kvmppc_load_up_altivec(void); |
| 133 | extern void kvmppc_load_up_vsx(void); |
Alexander Graf | ca7f420 | 2010-03-24 21:48:28 +0100 | [diff] [blame] | 134 | extern u32 kvmppc_alignment_dsisr(struct kvm_vcpu *vcpu, unsigned int inst); |
| 135 | extern ulong kvmppc_alignment_dar(struct kvm_vcpu *vcpu, unsigned int inst); |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 136 | |
| 137 | static inline struct kvmppc_vcpu_book3s *to_book3s(struct kvm_vcpu *vcpu) |
| 138 | { |
| 139 | return container_of(vcpu, struct kvmppc_vcpu_book3s, vcpu); |
| 140 | } |
| 141 | |
| 142 | static inline ulong dsisr(void) |
| 143 | { |
| 144 | ulong r; |
| 145 | asm ( "mfdsisr %0 " : "=r" (r) ); |
| 146 | return r; |
| 147 | } |
| 148 | |
| 149 | extern void kvm_return_point(void); |
| 150 | |
Alexander Graf | ad0a048 | 2010-03-24 21:48:30 +0100 | [diff] [blame] | 151 | /* Magic register values loaded into r3 and r4 before the 'sc' assembly |
| 152 | * instruction for the OSI hypercalls */ |
| 153 | #define OSI_SC_MAGIC_R3 0x113724FA |
| 154 | #define OSI_SC_MAGIC_R4 0x77810F9B |
| 155 | |
Alexander Graf | 4e342025 | 2009-10-30 05:47:05 +0000 | [diff] [blame] | 156 | #define INS_DCBZ 0x7c0007ec |
| 157 | |
| 158 | #endif /* __ASM_KVM_BOOK3S_H__ */ |