]>
Commit | Line | Data |
---|---|---|
bbf45ba5 HB |
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 IBM Corp. 2008 | |
16 | * | |
17 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> | |
18 | */ | |
19 | ||
20 | #ifndef __POWERPC_KVM_PPC_H__ | |
21 | #define __POWERPC_KVM_PPC_H__ | |
22 | ||
23 | /* This file exists just so we can dereference kvm_vcpu, avoiding nested header | |
24 | * dependencies. */ | |
25 | ||
26 | #include <linux/mutex.h> | |
27 | #include <linux/timer.h> | |
28 | #include <linux/types.h> | |
29 | #include <linux/kvm_types.h> | |
30 | #include <linux/kvm_host.h> | |
a136a8bd | 31 | #include <linux/bug.h> |
1c0006d8 AG |
32 | #ifdef CONFIG_PPC_BOOK3S |
33 | #include <asm/kvm_book3s.h> | |
c7f38f46 AG |
34 | #else |
35 | #include <asm/kvm_booke.h> | |
1c0006d8 | 36 | #endif |
371fefd6 PM |
37 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
38 | #include <asm/paca.h> | |
39 | #endif | |
bbf45ba5 | 40 | |
a59c1d9e MS |
41 | /* |
42 | * KVMPPC_INST_SW_BREAKPOINT is debug Instruction | |
43 | * for supporting software breakpoint. | |
44 | */ | |
45 | #define KVMPPC_INST_SW_BREAKPOINT 0x00dddd00 | |
46 | ||
bbf45ba5 HB |
47 | enum emulation_result { |
48 | EMULATE_DONE, /* no further processing */ | |
49 | EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */ | |
bbf45ba5 | 50 | EMULATE_FAIL, /* can't emulate this instruction */ |
37f5bca6 | 51 | EMULATE_AGAIN, /* something went wrong. go again */ |
c402a3f4 | 52 | EMULATE_EXIT_USER, /* emulation requires exit to user-space */ |
bbf45ba5 HB |
53 | }; |
54 | ||
51f04726 MC |
55 | enum instruction_type { |
56 | INST_GENERIC, | |
57 | INST_SC, /* system call */ | |
58 | }; | |
59 | ||
7d15c06f AG |
60 | enum xlate_instdata { |
61 | XLATE_INST, /* translate instruction address */ | |
62 | XLATE_DATA /* translate data address */ | |
63 | }; | |
64 | ||
65 | enum xlate_readwrite { | |
66 | XLATE_READ, /* check for read permissions */ | |
67 | XLATE_WRITE /* check for write permissions */ | |
68 | }; | |
69 | ||
df6909e5 | 70 | extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
bbf45ba5 | 71 | extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
29eb61bc | 72 | extern void kvmppc_handler_highmem(void); |
bbf45ba5 HB |
73 | |
74 | extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu); | |
75 | extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, | |
76 | unsigned int rt, unsigned int bytes, | |
73601775 | 77 | int is_default_endian); |
3587d534 AG |
78 | extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu, |
79 | unsigned int rt, unsigned int bytes, | |
73601775 | 80 | int is_default_endian); |
6f63e81b BL |
81 | extern int kvmppc_handle_vsx_load(struct kvm_run *run, struct kvm_vcpu *vcpu, |
82 | unsigned int rt, unsigned int bytes, | |
83 | int is_default_endian, int mmio_sign_extend); | |
bbf45ba5 | 84 | extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu, |
73601775 CLG |
85 | u64 val, unsigned int bytes, |
86 | int is_default_endian); | |
6f63e81b BL |
87 | extern int kvmppc_handle_vsx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, |
88 | int rs, unsigned int bytes, | |
89 | int is_default_endian); | |
bbf45ba5 | 90 | |
51f04726 MC |
91 | extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, |
92 | enum instruction_type type, u32 *inst); | |
93 | ||
35c4a733 AG |
94 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
95 | bool data); | |
96 | extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, | |
97 | bool data); | |
bbf45ba5 HB |
98 | extern int kvmppc_emulate_instruction(struct kvm_run *run, |
99 | struct kvm_vcpu *vcpu); | |
d69614a2 | 100 | extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu); |
ce263d70 | 101 | extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu); |
75f74f0d | 102 | extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu); |
5ce941ee | 103 | extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); |
d02d4d15 | 104 | extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu); |
af8f38b3 | 105 | extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu); |
f61c94bb BB |
106 | extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu); |
107 | extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu); | |
bbf45ba5 | 108 | |
ecc0981f HB |
109 | /* Core-specific hooks */ |
110 | ||
89168618 | 111 | extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr, |
7924bd41 | 112 | unsigned int gtlb_idx); |
bbf45ba5 | 113 | extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode); |
49dd2c49 | 114 | extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid); |
ecc0981f | 115 | extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu); |
9cc5e953 | 116 | extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu); |
fa86b8dd HB |
117 | extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr); |
118 | extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr); | |
be8d1cae HB |
119 | extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index, |
120 | gva_t eaddr); | |
b52a638c HB |
121 | extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu); |
122 | extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu); | |
7d15c06f AG |
123 | extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, |
124 | enum xlate_instdata xlid, enum xlate_readwrite xlrw, | |
125 | struct kvmppc_pte *pte); | |
9dd921cf | 126 | |
db93f574 HB |
127 | extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, |
128 | unsigned int id); | |
129 | extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu); | |
5cbb5106 | 130 | extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu); |
9dd921cf | 131 | extern int kvmppc_core_check_processor_compat(void); |
5cbb5106 HB |
132 | extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, |
133 | struct kvm_translation *tr); | |
9dd921cf HB |
134 | |
135 | extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu); | |
136 | extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu); | |
137 | ||
a8e4ef84 | 138 | extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu); |
9dd921cf | 139 | extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu); |
25a8a02d | 140 | extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags); |
307d9279 PM |
141 | extern void kvmppc_core_queue_fpunavail(struct kvm_vcpu *vcpu); |
142 | extern void kvmppc_core_queue_vec_unavail(struct kvm_vcpu *vcpu); | |
143 | extern void kvmppc_core_queue_vsx_unavail(struct kvm_vcpu *vcpu); | |
9dd921cf | 144 | extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu); |
7706664d | 145 | extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu); |
9dd921cf HB |
146 | extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
147 | struct kvm_interrupt *irq); | |
4fe27d2a | 148 | extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu); |
8de12015 AG |
149 | extern void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, ulong dear_flags, |
150 | ulong esr_flags); | |
151 | extern void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, | |
152 | ulong dear_flags, | |
153 | ulong esr_flags); | |
154 | extern void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu); | |
155 | extern void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, | |
156 | ulong esr_flags); | |
862d31f7 | 157 | extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu); |
7c973a2e | 158 | extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu); |
75f74f0d | 159 | |
db93f574 HB |
160 | extern int kvmppc_booke_init(void); |
161 | extern void kvmppc_booke_exit(void); | |
162 | ||
c30f8a6c | 163 | extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu); |
2a342ed5 | 164 | extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu); |
a4cd8b23 | 165 | extern void kvmppc_map_magic(struct kvm_vcpu *vcpu); |
c30f8a6c | 166 | |
aae0777f DG |
167 | extern int kvmppc_allocate_hpt(struct kvm_hpt_info *info, u32 order); |
168 | extern void kvmppc_set_hpt(struct kvm *kvm, struct kvm_hpt_info *info); | |
f98a8bf9 | 169 | extern long kvmppc_alloc_reset_hpt(struct kvm *kvm, int order); |
aae0777f | 170 | extern void kvmppc_free_hpt(struct kvm_hpt_info *info); |
18c3640c | 171 | extern void kvmppc_rmap_reset(struct kvm *kvm); |
de56a948 PM |
172 | extern long kvmppc_prepare_vrma(struct kvm *kvm, |
173 | struct kvm_userspace_memory_region *mem); | |
c77162de | 174 | extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu, |
da9d1d7f | 175 | struct kvm_memory_slot *memslot, unsigned long porder); |
a8606e20 | 176 | extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); |
121f80ba AK |
177 | extern long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd, |
178 | struct iommu_group *grp); | |
179 | extern void kvm_spapr_tce_release_iommu_group(struct kvm *kvm, | |
180 | struct iommu_group *grp); | |
18c3640c PM |
181 | extern int kvmppc_switch_mmu_to_hpt(struct kvm *kvm); |
182 | extern int kvmppc_switch_mmu_to_radix(struct kvm *kvm); | |
ded13fc1 | 183 | extern void kvmppc_setup_partition_table(struct kvm *kvm); |
bc5ad3f3 | 184 | |
54738c09 | 185 | extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, |
58ded420 | 186 | struct kvm_create_spapr_tce_64 *args); |
d3695aa4 | 187 | extern struct kvmppc_spapr_tce_table *kvmppc_find_table( |
503bfcbe | 188 | struct kvm *kvm, unsigned long liobn); |
b1af23d8 AK |
189 | #define kvmppc_ioba_validate(stt, ioba, npages) \ |
190 | (iommu_tce_check_ioba((stt)->page_shift, (stt)->offset, \ | |
191 | (stt)->size, (ioba), (npages)) ? \ | |
192 | H_PARAMETER : H_SUCCESS) | |
5ee7af18 AK |
193 | extern long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *tt, |
194 | unsigned long tce); | |
d3695aa4 AK |
195 | extern long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa, |
196 | unsigned long *ua, unsigned long **prmap); | |
197 | extern void kvmppc_tce_put(struct kvmppc_spapr_tce_table *tt, | |
198 | unsigned long idx, unsigned long tce); | |
f31e65e1 BH |
199 | extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
200 | unsigned long ioba, unsigned long tce); | |
d3695aa4 AK |
201 | extern long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu, |
202 | unsigned long liobn, unsigned long ioba, | |
203 | unsigned long tce_list, unsigned long npages); | |
204 | extern long kvmppc_h_stuff_tce(struct kvm_vcpu *vcpu, | |
205 | unsigned long liobn, unsigned long ioba, | |
206 | unsigned long tce_value, unsigned long npages); | |
69e9fbb2 LD |
207 | extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
208 | unsigned long ioba); | |
db9a290d DG |
209 | extern struct page *kvm_alloc_hpt_cma(unsigned long nr_pages); |
210 | extern void kvm_free_hpt_cma(struct page *page, unsigned long nr_pages); | |
f9e0554d PM |
211 | extern int kvmppc_core_init_vm(struct kvm *kvm); |
212 | extern void kvmppc_core_destroy_vm(struct kvm *kvm); | |
5587027c AK |
213 | extern void kvmppc_core_free_memslot(struct kvm *kvm, |
214 | struct kvm_memory_slot *free, | |
a66b48c3 | 215 | struct kvm_memory_slot *dont); |
5587027c AK |
216 | extern int kvmppc_core_create_memslot(struct kvm *kvm, |
217 | struct kvm_memory_slot *slot, | |
a66b48c3 | 218 | unsigned long npages); |
f9e0554d | 219 | extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
a66b48c3 | 220 | struct kvm_memory_slot *memslot, |
09170a49 | 221 | const struct kvm_userspace_memory_region *mem); |
f9e0554d | 222 | extern void kvmppc_core_commit_memory_region(struct kvm *kvm, |
09170a49 | 223 | const struct kvm_userspace_memory_region *mem, |
f36f3f28 PB |
224 | const struct kvm_memory_slot *old, |
225 | const struct kvm_memory_slot *new); | |
5b74716e BH |
226 | extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, |
227 | struct kvm_ppc_smmu_info *info); | |
dfe49dbd PM |
228 | extern void kvmppc_core_flush_memslot(struct kvm *kvm, |
229 | struct kvm_memory_slot *memslot); | |
f9e0554d | 230 | |
d30f6e48 SW |
231 | extern int kvmppc_bookehv_init(void); |
232 | extern void kvmppc_bookehv_exit(void); | |
233 | ||
03d25c5b AG |
234 | extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu); |
235 | ||
a2932923 | 236 | extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *); |
5e985969 DG |
237 | extern long kvm_vm_ioctl_resize_hpt_prepare(struct kvm *kvm, |
238 | struct kvm_ppc_resize_hpt *rhpt); | |
239 | extern long kvm_vm_ioctl_resize_hpt_commit(struct kvm *kvm, | |
240 | struct kvm_ppc_resize_hpt *rhpt); | |
a2932923 | 241 | |
5df554ad SW |
242 | int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq); |
243 | ||
8e591cb7 ME |
244 | extern int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp); |
245 | extern int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu); | |
246 | extern void kvmppc_rtas_tokens_free(struct kvm *kvm); | |
5af50993 | 247 | |
bc5ad3f3 BH |
248 | extern int kvmppc_xics_set_xive(struct kvm *kvm, u32 irq, u32 server, |
249 | u32 priority); | |
250 | extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server, | |
251 | u32 *priority); | |
d19bd862 PM |
252 | extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq); |
253 | extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq); | |
8e591cb7 | 254 | |
2f699a59 BB |
255 | void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu); |
256 | void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu); | |
257 | ||
3a167bea AK |
258 | union kvmppc_one_reg { |
259 | u32 wval; | |
260 | u64 dval; | |
261 | vector128 vval; | |
262 | u64 vsxval[2]; | |
6f63e81b | 263 | u32 vsx32val[4]; |
3a167bea AK |
264 | struct { |
265 | u64 addr; | |
266 | u64 length; | |
267 | } vpaval; | |
268 | }; | |
269 | ||
270 | struct kvmppc_ops { | |
cbbc58d4 | 271 | struct module *owner; |
3a167bea AK |
272 | int (*get_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
273 | int (*set_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); | |
274 | int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id, | |
275 | union kvmppc_one_reg *val); | |
276 | int (*set_one_reg)(struct kvm_vcpu *vcpu, u64 id, | |
277 | union kvmppc_one_reg *val); | |
278 | void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu); | |
279 | void (*vcpu_put)(struct kvm_vcpu *vcpu); | |
280 | void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr); | |
281 | int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu); | |
282 | struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id); | |
283 | void (*vcpu_free)(struct kvm_vcpu *vcpu); | |
284 | int (*check_requests)(struct kvm_vcpu *vcpu); | |
285 | int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log); | |
286 | void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot); | |
287 | int (*prepare_memory_region)(struct kvm *kvm, | |
288 | struct kvm_memory_slot *memslot, | |
09170a49 | 289 | const struct kvm_userspace_memory_region *mem); |
3a167bea | 290 | void (*commit_memory_region)(struct kvm *kvm, |
09170a49 | 291 | const struct kvm_userspace_memory_region *mem, |
f36f3f28 PB |
292 | const struct kvm_memory_slot *old, |
293 | const struct kvm_memory_slot *new); | |
3a167bea AK |
294 | int (*unmap_hva)(struct kvm *kvm, unsigned long hva); |
295 | int (*unmap_hva_range)(struct kvm *kvm, unsigned long start, | |
296 | unsigned long end); | |
57128468 | 297 | int (*age_hva)(struct kvm *kvm, unsigned long start, unsigned long end); |
3a167bea AK |
298 | int (*test_age_hva)(struct kvm *kvm, unsigned long hva); |
299 | void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte); | |
300 | void (*mmu_destroy)(struct kvm_vcpu *vcpu); | |
301 | void (*free_memslot)(struct kvm_memory_slot *free, | |
302 | struct kvm_memory_slot *dont); | |
303 | int (*create_memslot)(struct kvm_memory_slot *slot, | |
304 | unsigned long npages); | |
305 | int (*init_vm)(struct kvm *kvm); | |
306 | void (*destroy_vm)(struct kvm *kvm); | |
3a167bea AK |
307 | int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info); |
308 | int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu, | |
309 | unsigned int inst, int *advance); | |
310 | int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val); | |
311 | int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val); | |
312 | void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu); | |
313 | long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl, | |
314 | unsigned long arg); | |
ae2113a4 | 315 | int (*hcall_implemented)(unsigned long hcall); |
9576730d SW |
316 | int (*irq_bypass_add_producer)(struct irq_bypass_consumer *, |
317 | struct irq_bypass_producer *); | |
318 | void (*irq_bypass_del_producer)(struct irq_bypass_consumer *, | |
319 | struct irq_bypass_producer *); | |
c9270132 PM |
320 | int (*configure_mmu)(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg); |
321 | int (*get_rmmu_info)(struct kvm *kvm, struct kvm_ppc_rmmu_info *info); | |
3c313524 PM |
322 | int (*set_smt_mode)(struct kvm *kvm, unsigned long mode, |
323 | unsigned long flags); | |
3a167bea AK |
324 | }; |
325 | ||
cbbc58d4 AK |
326 | extern struct kvmppc_ops *kvmppc_hv_ops; |
327 | extern struct kvmppc_ops *kvmppc_pr_ops; | |
3a167bea | 328 | |
51f04726 MC |
329 | static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu, |
330 | enum instruction_type type, u32 *inst) | |
331 | { | |
332 | int ret = EMULATE_DONE; | |
333 | u32 fetched_inst; | |
334 | ||
335 | /* Load the instruction manually if it failed to do so in the | |
336 | * exit path */ | |
337 | if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) | |
338 | ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst); | |
339 | ||
340 | /* Write fetch_failed unswapped if the fetch failed */ | |
341 | if (ret == EMULATE_DONE) | |
342 | fetched_inst = kvmppc_need_byteswap(vcpu) ? | |
343 | swab32(vcpu->arch.last_inst) : | |
344 | vcpu->arch.last_inst; | |
345 | else | |
346 | fetched_inst = vcpu->arch.last_inst; | |
347 | ||
348 | *inst = fetched_inst; | |
349 | return ret; | |
350 | } | |
351 | ||
a78b55d1 AK |
352 | static inline bool is_kvmppc_hv_enabled(struct kvm *kvm) |
353 | { | |
354 | return kvm->arch.kvm_ops == kvmppc_hv_ops; | |
355 | } | |
356 | ||
e928e9cb ME |
357 | extern int kvmppc_hwrng_present(void); |
358 | ||
0564ee8a AG |
359 | /* |
360 | * Cuts out inst bits with ordering according to spec. | |
361 | * That means the leftmost bit is zero. All given bits are included. | |
362 | */ | |
363 | static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb) | |
364 | { | |
365 | u32 r; | |
366 | u32 mask; | |
367 | ||
368 | BUG_ON(msb > lsb); | |
369 | ||
370 | mask = (1 << (lsb - msb + 1)) - 1; | |
371 | r = (inst >> (63 - lsb)) & mask; | |
372 | ||
373 | return r; | |
374 | } | |
375 | ||
376 | /* | |
377 | * Replaces inst bits with ordering according to spec. | |
378 | */ | |
379 | static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value) | |
380 | { | |
381 | u32 r; | |
382 | u32 mask; | |
383 | ||
384 | BUG_ON(msb > lsb); | |
385 | ||
386 | mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb); | |
387 | r = (inst & ~mask) | ((value << (63 - lsb)) & mask); | |
388 | ||
389 | return r; | |
390 | } | |
391 | ||
a136a8bd PM |
392 | #define one_reg_size(id) \ |
393 | (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) | |
394 | ||
395 | #define get_reg_val(id, reg) ({ \ | |
396 | union kvmppc_one_reg __u; \ | |
397 | switch (one_reg_size(id)) { \ | |
398 | case 4: __u.wval = (reg); break; \ | |
399 | case 8: __u.dval = (reg); break; \ | |
400 | default: BUG(); \ | |
401 | } \ | |
402 | __u; \ | |
403 | }) | |
404 | ||
405 | ||
406 | #define set_reg_val(id, val) ({ \ | |
407 | u64 __v; \ | |
408 | switch (one_reg_size(id)) { \ | |
409 | case 4: __v = (val).wval; break; \ | |
410 | case 8: __v = (val).dval; break; \ | |
411 | default: BUG(); \ | |
412 | } \ | |
413 | __v; \ | |
414 | }) | |
415 | ||
3a167bea | 416 | int kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
5ce941ee SW |
417 | int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
418 | ||
3a167bea | 419 | int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
5ce941ee SW |
420 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
421 | ||
31f3438e PM |
422 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); |
423 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); | |
a136a8bd PM |
424 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *); |
425 | int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *); | |
31f3438e | 426 | |
5ce941ee SW |
427 | void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid); |
428 | ||
5df554ad | 429 | struct openpic; |
5df554ad | 430 | |
9975f5e3 | 431 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
fa61a4e3 | 432 | extern void kvm_cma_reserve(void) __init; |
371fefd6 PM |
433 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
434 | { | |
d381d7ca | 435 | paca[cpu].kvm_hstate.xics_phys = (void __iomem *)addr; |
371fefd6 | 436 | } |
aa04b4cc | 437 | |
5af50993 BH |
438 | static inline void kvmppc_set_xive_tima(int cpu, |
439 | unsigned long phys_addr, | |
440 | void __iomem *virt_addr) | |
441 | { | |
442 | paca[cpu].kvm_hstate.xive_tima_phys = (void __iomem *)phys_addr; | |
443 | paca[cpu].kvm_hstate.xive_tima_virt = virt_addr; | |
371fefd6 | 444 | } |
aa04b4cc | 445 | |
54695c30 BH |
446 | static inline u32 kvmppc_get_xics_latch(void) |
447 | { | |
699cc876 | 448 | u32 xirr; |
54695c30 | 449 | |
699cc876 | 450 | xirr = get_paca()->kvm_hstate.saved_xirr; |
54695c30 | 451 | get_paca()->kvm_hstate.saved_xirr = 0; |
54695c30 BH |
452 | return xirr; |
453 | } | |
454 | ||
455 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) | |
456 | { | |
457 | paca[cpu].kvm_hstate.host_ipi = host_ipi; | |
458 | } | |
459 | ||
3a167bea AK |
460 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
461 | { | |
cbbc58d4 | 462 | vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu); |
3a167bea | 463 | } |
aa04b4cc | 464 | |
441c19c8 ME |
465 | extern void kvm_hv_vm_activated(void); |
466 | extern void kvm_hv_vm_deactivated(void); | |
467 | extern bool kvm_hv_mode_active(void); | |
468 | ||
371fefd6 | 469 | #else |
fa61a4e3 AK |
470 | static inline void __init kvm_cma_reserve(void) |
471 | {} | |
472 | ||
371fefd6 PM |
473 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
474 | {} | |
aa04b4cc | 475 | |
5af50993 BH |
476 | static inline void kvmppc_set_xive_tima(int cpu, |
477 | unsigned long phys_addr, | |
478 | void __iomem *virt_addr) | |
479 | {} | |
480 | ||
54695c30 BH |
481 | static inline u32 kvmppc_get_xics_latch(void) |
482 | { | |
483 | return 0; | |
484 | } | |
485 | ||
486 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) | |
487 | {} | |
488 | ||
489 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) | |
490 | { | |
491 | kvm_vcpu_kick(vcpu); | |
492 | } | |
441c19c8 ME |
493 | |
494 | static inline bool kvm_hv_mode_active(void) { return false; } | |
495 | ||
bc5ad3f3 BH |
496 | #endif |
497 | ||
498 | #ifdef CONFIG_KVM_XICS | |
499 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) | |
500 | { | |
501 | return vcpu->arch.irq_type == KVMPPC_IRQ_XICS; | |
502 | } | |
8daaafc8 SW |
503 | |
504 | static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap( | |
505 | struct kvm *kvm) | |
506 | { | |
644abbb2 | 507 | if (kvm && kvm_irq_bypass) |
8daaafc8 SW |
508 | return kvm->arch.pimap; |
509 | return NULL; | |
510 | } | |
511 | ||
79b6c247 SW |
512 | extern void kvmppc_alloc_host_rm_ops(void); |
513 | extern void kvmppc_free_host_rm_ops(void); | |
8daaafc8 | 514 | extern void kvmppc_free_pimap(struct kvm *kvm); |
f7af5209 | 515 | extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall); |
bc5ad3f3 | 516 | extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu); |
bc5ad3f3 | 517 | extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd); |
8b78645c PM |
518 | extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu); |
519 | extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval); | |
5975a2e0 PM |
520 | extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev, |
521 | struct kvm_vcpu *vcpu, u32 cpu); | |
0c2a6606 | 522 | extern void kvmppc_xics_ipi_action(void); |
5d375199 PM |
523 | extern void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long guest_irq, |
524 | unsigned long host_irq); | |
525 | extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq, | |
526 | unsigned long host_irq); | |
f725758b PM |
527 | extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, __be32 xirr, |
528 | struct kvmppc_irq_map *irq_map, | |
529 | struct kvmppc_passthru_irqmap *pimap, | |
530 | bool *again); | |
5af50993 BH |
531 | |
532 | extern int kvmppc_xics_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, | |
533 | int level, bool line_status); | |
534 | ||
520fe9c6 | 535 | extern int h_ipi_redirect; |
bc5ad3f3 | 536 | #else |
8daaafc8 SW |
537 | static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap( |
538 | struct kvm *kvm) | |
539 | { return NULL; } | |
79b6c247 SW |
540 | static inline void kvmppc_alloc_host_rm_ops(void) {}; |
541 | static inline void kvmppc_free_host_rm_ops(void) {}; | |
8daaafc8 | 542 | static inline void kvmppc_free_pimap(struct kvm *kvm) {}; |
f7af5209 SW |
543 | static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall) |
544 | { return 0; } | |
bc5ad3f3 BH |
545 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
546 | { return 0; } | |
547 | static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { } | |
bc5ad3f3 BH |
548 | static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd) |
549 | { return 0; } | |
371fefd6 PM |
550 | #endif |
551 | ||
5af50993 BH |
552 | #ifdef CONFIG_KVM_XIVE |
553 | /* | |
554 | * Below the first "xive" is the "eXternal Interrupt Virtualization Engine" | |
555 | * ie. P9 new interrupt controller, while the second "xive" is the legacy | |
556 | * "eXternal Interrupt Vector Entry" which is the configuration of an | |
557 | * interrupt on the "xics" interrupt controller on P8 and earlier. Those | |
558 | * two function consume or produce a legacy "XIVE" state from the | |
559 | * new "XIVE" interrupt controller. | |
560 | */ | |
561 | extern int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server, | |
562 | u32 priority); | |
563 | extern int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, | |
564 | u32 *priority); | |
565 | extern int kvmppc_xive_int_on(struct kvm *kvm, u32 irq); | |
566 | extern int kvmppc_xive_int_off(struct kvm *kvm, u32 irq); | |
567 | extern void kvmppc_xive_init_module(void); | |
568 | extern void kvmppc_xive_exit_module(void); | |
569 | ||
570 | extern int kvmppc_xive_connect_vcpu(struct kvm_device *dev, | |
571 | struct kvm_vcpu *vcpu, u32 cpu); | |
572 | extern void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu); | |
573 | extern int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq, | |
574 | struct irq_desc *host_desc); | |
575 | extern int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq, | |
576 | struct irq_desc *host_desc); | |
577 | extern u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu); | |
578 | extern int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval); | |
579 | ||
580 | extern int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, | |
581 | int level, bool line_status); | |
582 | #else | |
583 | static inline int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server, | |
584 | u32 priority) { return -1; } | |
585 | static inline int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, | |
586 | u32 *priority) { return -1; } | |
587 | static inline int kvmppc_xive_int_on(struct kvm *kvm, u32 irq) { return -1; } | |
588 | static inline int kvmppc_xive_int_off(struct kvm *kvm, u32 irq) { return -1; } | |
589 | static inline void kvmppc_xive_init_module(void) { } | |
590 | static inline void kvmppc_xive_exit_module(void) { } | |
591 | ||
592 | static inline int kvmppc_xive_connect_vcpu(struct kvm_device *dev, | |
593 | struct kvm_vcpu *vcpu, u32 cpu) { return -EBUSY; } | |
594 | static inline void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu) { } | |
595 | static inline int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq, | |
596 | struct irq_desc *host_desc) { return -ENODEV; } | |
597 | static inline int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq, | |
598 | struct irq_desc *host_desc) { return -ENODEV; } | |
599 | static inline u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu) { return 0; } | |
600 | static inline int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval) { return -ENOENT; } | |
601 | ||
602 | static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, | |
603 | int level, bool line_status) { return -ENODEV; } | |
604 | #endif /* CONFIG_KVM_XIVE */ | |
605 | ||
e34af784 PM |
606 | /* |
607 | * Prototypes for functions called only from assembler code. | |
608 | * Having prototypes reduces sparse errors. | |
609 | */ | |
610 | long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, | |
611 | unsigned long ioba, unsigned long tce); | |
612 | long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu, | |
613 | unsigned long liobn, unsigned long ioba, | |
614 | unsigned long tce_list, unsigned long npages); | |
615 | long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu, | |
616 | unsigned long liobn, unsigned long ioba, | |
617 | unsigned long tce_value, unsigned long npages); | |
618 | long int kvmppc_rm_h_confer(struct kvm_vcpu *vcpu, int target, | |
619 | unsigned int yield_count); | |
620 | long kvmppc_h_random(struct kvm_vcpu *vcpu); | |
621 | void kvmhv_commence_exit(int trap); | |
622 | long kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu); | |
623 | void kvmppc_subcore_enter_guest(void); | |
624 | void kvmppc_subcore_exit_guest(void); | |
625 | long kvmppc_realmode_hmi_handler(void); | |
626 | long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, | |
627 | long pte_index, unsigned long pteh, unsigned long ptel); | |
628 | long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags, | |
629 | unsigned long pte_index, unsigned long avpn); | |
630 | long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu); | |
631 | long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags, | |
632 | unsigned long pte_index, unsigned long avpn, | |
633 | unsigned long va); | |
634 | long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags, | |
635 | unsigned long pte_index); | |
636 | long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags, | |
637 | unsigned long pte_index); | |
638 | long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags, | |
639 | unsigned long pte_index); | |
640 | long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr, | |
641 | unsigned long slb_v, unsigned int status, bool data); | |
642 | unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu); | |
5af50993 BH |
643 | unsigned long kvmppc_rm_h_xirr_x(struct kvm_vcpu *vcpu); |
644 | unsigned long kvmppc_rm_h_ipoll(struct kvm_vcpu *vcpu, unsigned long server); | |
e34af784 PM |
645 | int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server, |
646 | unsigned long mfrr); | |
647 | int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr); | |
648 | int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr); | |
649 | ||
79b6c247 SW |
650 | /* |
651 | * Host-side operations we want to set up while running in real | |
652 | * mode in the guest operating on the xics. | |
653 | * Currently only VCPU wakeup is supported. | |
654 | */ | |
655 | ||
656 | union kvmppc_rm_state { | |
657 | unsigned long raw; | |
658 | struct { | |
659 | u32 in_host; | |
660 | u32 rm_action; | |
661 | }; | |
662 | }; | |
663 | ||
664 | struct kvmppc_host_rm_core { | |
665 | union kvmppc_rm_state rm_state; | |
666 | void *rm_data; | |
667 | char pad[112]; | |
668 | }; | |
669 | ||
670 | struct kvmppc_host_rm_ops { | |
671 | struct kvmppc_host_rm_core *rm_core; | |
672 | void (*vcpu_kick)(struct kvm_vcpu *vcpu); | |
673 | }; | |
674 | ||
675 | extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv; | |
676 | ||
34f754b9 BB |
677 | static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu) |
678 | { | |
679 | #ifdef CONFIG_KVM_BOOKE_HV | |
680 | return mfspr(SPRN_GEPR); | |
681 | #elif defined(CONFIG_BOOKE) | |
682 | return vcpu->arch.epr; | |
683 | #else | |
684 | return 0; | |
685 | #endif | |
686 | } | |
687 | ||
1c810636 AG |
688 | static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr) |
689 | { | |
690 | #ifdef CONFIG_KVM_BOOKE_HV | |
691 | mtspr(SPRN_GEPR, epr); | |
692 | #elif defined(CONFIG_BOOKE) | |
693 | vcpu->arch.epr = epr; | |
694 | #endif | |
695 | } | |
696 | ||
5df554ad SW |
697 | #ifdef CONFIG_KVM_MPIC |
698 | ||
699 | void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu); | |
eb1e4f43 SW |
700 | int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu, |
701 | u32 cpu); | |
702 | void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu); | |
5df554ad SW |
703 | |
704 | #else | |
705 | ||
706 | static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu) | |
707 | { | |
708 | } | |
709 | ||
eb1e4f43 SW |
710 | static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, |
711 | struct kvm_vcpu *vcpu, u32 cpu) | |
712 | { | |
713 | return -EINVAL; | |
714 | } | |
715 | ||
716 | static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, | |
717 | struct kvm_vcpu *vcpu) | |
718 | { | |
719 | } | |
720 | ||
5df554ad SW |
721 | #endif /* CONFIG_KVM_MPIC */ |
722 | ||
dc83b8bc SW |
723 | int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, |
724 | struct kvm_config_tlb *cfg); | |
725 | int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu, | |
726 | struct kvm_dirty_tlb *cfg); | |
727 | ||
043cc4d7 SW |
728 | long kvmppc_alloc_lpid(void); |
729 | void kvmppc_claim_lpid(long lpid); | |
730 | void kvmppc_free_lpid(long lpid); | |
731 | void kvmppc_init_lpid(unsigned long nr_lpids); | |
732 | ||
ba049e93 | 733 | static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn) |
249ba1ee | 734 | { |
249ba1ee | 735 | struct page *page; |
adccf65c BB |
736 | /* |
737 | * We can only access pages that the kernel maps | |
738 | * as memory. Bail out for unmapped ones. | |
739 | */ | |
740 | if (!pfn_valid(pfn)) | |
741 | return; | |
742 | ||
743 | /* Clear i-cache for new pages */ | |
249ba1ee AG |
744 | page = pfn_to_page(pfn); |
745 | if (!test_bit(PG_arch_1, &page->flags)) { | |
746 | flush_dcache_icache_page(page); | |
747 | set_bit(PG_arch_1, &page->flags); | |
748 | } | |
749 | } | |
750 | ||
5deb8e7a AG |
751 | /* |
752 | * Shared struct helpers. The shared struct can be little or big endian, | |
753 | * depending on the guest endianness. So expose helpers to all of them. | |
754 | */ | |
755 | static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu) | |
756 | { | |
757 | #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE) | |
758 | /* Only Book3S_64 PR supports bi-endian for now */ | |
759 | return vcpu->arch.shared_big_endian; | |
760 | #elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__) | |
761 | /* Book3s_64 HV on little endian is always little endian */ | |
762 | return false; | |
763 | #else | |
764 | return true; | |
765 | #endif | |
766 | } | |
767 | ||
5a484c7c | 768 | #define SPRNG_WRAPPER_GET(reg, bookehv_spr) \ |
1dc0c5b8 BB |
769 | static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
770 | { \ | |
5a484c7c | 771 | return mfspr(bookehv_spr); \ |
1dc0c5b8 BB |
772 | } \ |
773 | ||
5a484c7c | 774 | #define SPRNG_WRAPPER_SET(reg, bookehv_spr) \ |
1dc0c5b8 BB |
775 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \ |
776 | { \ | |
5a484c7c | 777 | mtspr(bookehv_spr, val); \ |
1dc0c5b8 BB |
778 | } \ |
779 | ||
5deb8e7a | 780 | #define SHARED_WRAPPER_GET(reg, size) \ |
1dc0c5b8 | 781 | static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
5deb8e7a AG |
782 | { \ |
783 | if (kvmppc_shared_big_endian(vcpu)) \ | |
784 | return be##size##_to_cpu(vcpu->arch.shared->reg); \ | |
785 | else \ | |
786 | return le##size##_to_cpu(vcpu->arch.shared->reg); \ | |
787 | } \ | |
788 | ||
789 | #define SHARED_WRAPPER_SET(reg, size) \ | |
790 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ | |
791 | { \ | |
792 | if (kvmppc_shared_big_endian(vcpu)) \ | |
793 | vcpu->arch.shared->reg = cpu_to_be##size(val); \ | |
794 | else \ | |
795 | vcpu->arch.shared->reg = cpu_to_le##size(val); \ | |
796 | } \ | |
797 | ||
798 | #define SHARED_WRAPPER(reg, size) \ | |
799 | SHARED_WRAPPER_GET(reg, size) \ | |
800 | SHARED_WRAPPER_SET(reg, size) \ | |
801 | ||
5a484c7c BB |
802 | #define SPRNG_WRAPPER(reg, bookehv_spr) \ |
803 | SPRNG_WRAPPER_GET(reg, bookehv_spr) \ | |
804 | SPRNG_WRAPPER_SET(reg, bookehv_spr) \ | |
1dc0c5b8 BB |
805 | |
806 | #ifdef CONFIG_KVM_BOOKE_HV | |
807 | ||
5a484c7c BB |
808 | #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ |
809 | SPRNG_WRAPPER(reg, bookehv_spr) \ | |
1dc0c5b8 BB |
810 | |
811 | #else | |
812 | ||
5a484c7c | 813 | #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ |
1dc0c5b8 BB |
814 | SHARED_WRAPPER(reg, size) \ |
815 | ||
816 | #endif | |
817 | ||
5deb8e7a | 818 | SHARED_WRAPPER(critical, 64) |
1dc0c5b8 BB |
819 | SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0) |
820 | SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1) | |
821 | SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2) | |
822 | SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3) | |
823 | SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0) | |
824 | SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1) | |
825 | SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR) | |
dc168549 | 826 | SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR) |
5deb8e7a AG |
827 | SHARED_WRAPPER_GET(msr, 64) |
828 | static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val) | |
829 | { | |
830 | if (kvmppc_shared_big_endian(vcpu)) | |
831 | vcpu->arch.shared->msr = cpu_to_be64(val); | |
832 | else | |
833 | vcpu->arch.shared->msr = cpu_to_le64(val); | |
834 | } | |
835 | SHARED_WRAPPER(dsisr, 32) | |
836 | SHARED_WRAPPER(int_pending, 32) | |
837 | SHARED_WRAPPER(sprg4, 64) | |
838 | SHARED_WRAPPER(sprg5, 64) | |
839 | SHARED_WRAPPER(sprg6, 64) | |
840 | SHARED_WRAPPER(sprg7, 64) | |
841 | ||
842 | static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr) | |
843 | { | |
844 | if (kvmppc_shared_big_endian(vcpu)) | |
845 | return be32_to_cpu(vcpu->arch.shared->sr[nr]); | |
846 | else | |
847 | return le32_to_cpu(vcpu->arch.shared->sr[nr]); | |
848 | } | |
849 | ||
850 | static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val) | |
851 | { | |
852 | if (kvmppc_shared_big_endian(vcpu)) | |
853 | vcpu->arch.shared->sr[nr] = cpu_to_be32(val); | |
854 | else | |
855 | vcpu->arch.shared->sr[nr] = cpu_to_le32(val); | |
856 | } | |
857 | ||
5f1c248f SW |
858 | /* |
859 | * Please call after prepare_to_enter. This function puts the lazy ee and irq | |
860 | * disabled tracking state back to normal mode, without actually enabling | |
861 | * interrupts. | |
862 | */ | |
863 | static inline void kvmppc_fix_ee_before_entry(void) | |
bd2be683 | 864 | { |
5f1c248f SW |
865 | trace_hardirqs_on(); |
866 | ||
bd2be683 | 867 | #ifdef CONFIG_PPC64 |
6c85f52b SW |
868 | /* |
869 | * To avoid races, the caller must have gone directly from having | |
870 | * interrupts fully-enabled to hard-disabled. | |
871 | */ | |
872 | WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS); | |
873 | ||
bd2be683 AG |
874 | /* Only need to enable IRQs by hard enabling them after this */ |
875 | local_paca->irq_happened = 0; | |
876 | local_paca->soft_enabled = 1; | |
877 | #endif | |
878 | } | |
249ba1ee | 879 | |
7cdd7a95 MC |
880 | static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb) |
881 | { | |
882 | ulong ea; | |
8823a8fd | 883 | ulong msr_64bit = 0; |
7cdd7a95 MC |
884 | |
885 | ea = kvmppc_get_gpr(vcpu, rb); | |
886 | if (ra) | |
887 | ea += kvmppc_get_gpr(vcpu, ra); | |
888 | ||
8823a8fd MC |
889 | #if defined(CONFIG_PPC_BOOK3E_64) |
890 | msr_64bit = MSR_CM; | |
891 | #elif defined(CONFIG_PPC_BOOK3S_64) | |
892 | msr_64bit = MSR_SF; | |
893 | #endif | |
894 | ||
5deb8e7a | 895 | if (!(kvmppc_get_msr(vcpu) & msr_64bit)) |
8823a8fd MC |
896 | ea = (uint32_t)ea; |
897 | ||
7cdd7a95 MC |
898 | return ea; |
899 | } | |
900 | ||
54695c30 BH |
901 | extern void xics_wake_cpu(int cpu); |
902 | ||
bbf45ba5 | 903 | #endif /* __POWERPC_KVM_PPC_H__ */ |