blob: 48c760f89590da8d9f1b808fbac66c021e1db31c [file] [log] [blame]
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -05001/*
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>
Paul Mackerrasa136a8b2012-09-25 20:31:56 +000031#include <linux/bug.h>
Alexander Graf1c0006d2010-01-15 14:49:12 +010032#ifdef CONFIG_PPC_BOOK3S
33#include <asm/kvm_book3s.h>
Alexander Grafc7f38f42010-04-16 00:11:40 +020034#else
35#include <asm/kvm_booke.h>
Alexander Graf1c0006d2010-01-15 14:49:12 +010036#endif
Paul Mackerras371fefd2011-06-29 00:23:08 +000037#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
38#include <asm/paca.h>
39#endif
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050040
Madhavan Srinivasana59c1d92014-09-09 22:37:35 +053041/*
42 * KVMPPC_INST_SW_BREAKPOINT is debug Instruction
43 * for supporting software breakpoint.
44 */
45#define KVMPPC_INST_SW_BREAKPOINT 0x00dddd00
46
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050047enum emulation_result {
48 EMULATE_DONE, /* no further processing */
49 EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050050 EMULATE_FAIL, /* can't emulate this instruction */
Alexander Graf37f5bca2010-02-19 11:00:31 +010051 EMULATE_AGAIN, /* something went wrong. go again */
Bharat Bhushanc402a3f2013-04-08 00:32:13 +000052 EMULATE_EXIT_USER, /* emulation requires exit to user-space */
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050053};
54
Mihai Caraman51f04722014-07-23 19:06:21 +030055enum instruction_type {
56 INST_GENERIC,
57 INST_SC, /* system call */
58};
59
Alexander Graf7d15c06f2014-06-20 13:52:36 +020060enum xlate_instdata {
61 XLATE_INST, /* translate instruction address */
62 XLATE_DATA /* translate data address */
63};
64
65enum xlate_readwrite {
66 XLATE_READ, /* check for read permissions */
67 XLATE_WRITE /* check for write permissions */
68};
69
Paul Mackerrasdf6909e52011-06-29 00:19:50 +000070extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050071extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
Alexander Graf29eb61b2009-10-30 05:47:07 +000072extern void kvmppc_handler_highmem(void);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050073
74extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
75extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
76 unsigned int rt, unsigned int bytes,
Cédric Le Goater73601772014-01-09 11:51:16 +010077 int is_default_endian);
Alexander Graf3587d532010-02-19 11:00:30 +010078extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,
79 unsigned int rt, unsigned int bytes,
Cédric Le Goater73601772014-01-09 11:51:16 +010080 int is_default_endian);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050081extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
Cédric Le Goater73601772014-01-09 11:51:16 +010082 u64 val, unsigned int bytes,
83 int is_default_endian);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050084
Mihai Caraman51f04722014-07-23 19:06:21 +030085extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu,
86 enum instruction_type type, u32 *inst);
87
Alexander Graf35c4a732014-06-20 13:58:16 +020088extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
89 bool data);
90extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr,
91 bool data);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -050092extern int kvmppc_emulate_instruction(struct kvm_run *run,
93 struct kvm_vcpu *vcpu);
Alexander Grafd69614a2014-06-18 14:53:49 +020094extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu);
Hollis Blanchardce263d72008-05-21 18:22:51 -050095extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu);
Hollis Blanchard75f74f02008-11-05 09:36:16 -060096extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu);
Scott Wood5ce941e2011-04-27 17:24:21 -050097extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb);
Mihai Caramand02d4d12014-09-01 17:19:56 +030098extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu);
Alexander Grafaf8f38b2011-08-10 13:57:08 +020099extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu);
Bharat Bhushanf61c94b2012-08-08 20:38:19 +0000100extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu);
101extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500102
Hollis Blanchardecc09812009-01-03 16:22:59 -0600103/* Core-specific hooks */
104
Hollis Blanchard89168612008-12-02 15:51:53 -0600105extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr,
Hollis Blanchard7924bd42008-12-02 15:51:55 -0600106 unsigned int gtlb_idx);
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500107extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode);
Hollis Blanchard49dd2c42008-07-25 13:54:53 -0500108extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid);
Hollis Blanchardecc09812009-01-03 16:22:59 -0600109extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu);
Alexander Graf9cc5e952010-04-16 00:11:45 +0200110extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu);
Hollis Blanchardfa86b8d2009-01-03 16:23:03 -0600111extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
112extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr);
Hollis Blanchardbe8d1ca2009-01-03 16:23:02 -0600113extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index,
114 gva_t eaddr);
Hollis Blanchardb52a6382009-01-03 16:23:11 -0600115extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu);
116extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu);
Alexander Graf7d15c06f2014-06-20 13:52:36 +0200117extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr,
118 enum xlate_instdata xlid, enum xlate_readwrite xlrw,
119 struct kvmppc_pte *pte);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600120
Hollis Blancharddb93f572008-11-05 09:36:18 -0600121extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm,
122 unsigned int id);
123extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu);
Hollis Blanchard5cbb5102008-11-05 09:36:17 -0600124extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600125extern int kvmppc_core_check_processor_compat(void);
Hollis Blanchard5cbb5102008-11-05 09:36:17 -0600126extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
127 struct kvm_translation *tr);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600128
129extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
130extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);
131
Alexander Grafa8e4ef82012-02-16 14:07:37 +0000132extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600133extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
Alexander Graf25a8a022010-01-08 02:58:07 +0100134extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600135extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
Alexander Graf7706664d2009-12-21 20:21:24 +0100136extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu);
Hollis Blanchard9dd921c2008-11-05 09:36:14 -0600137extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
138 struct kvm_interrupt *irq);
Paul Mackerras4fe27d22013-02-14 14:00:25 +0000139extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu);
Alexander Graf8de12012014-06-18 21:56:55 +0200140extern void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, ulong dear_flags,
141 ulong esr_flags);
142extern void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu,
143 ulong dear_flags,
144 ulong esr_flags);
145extern void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu);
146extern void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu,
147 ulong esr_flags);
Alexander Graf862d31f2012-07-31 00:19:50 +0200148extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu);
Alexander Graf7c973a22012-08-13 12:50:35 +0200149extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
Hollis Blanchard75f74f02008-11-05 09:36:16 -0600150
Hollis Blancharddb93f572008-11-05 09:36:18 -0600151extern int kvmppc_booke_init(void);
152extern void kvmppc_booke_exit(void);
153
Hollis Blanchardc30f8a62008-11-24 11:37:38 -0600154extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu);
Alexander Graf2a342ed2010-07-29 14:47:48 +0200155extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu);
Scott Wooda4cd8b22011-06-14 18:34:41 -0500156extern void kvmppc_map_magic(struct kvm_vcpu *vcpu);
Hollis Blanchardc30f8a62008-11-24 11:37:38 -0600157
Paul Mackerras32fad282012-05-04 02:32:53 +0000158extern long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp);
159extern long kvmppc_alloc_reset_hpt(struct kvm *kvm, u32 *htab_orderp);
Paul Mackerrasde56a942011-06-29 00:21:34 +0000160extern void kvmppc_free_hpt(struct kvm *kvm);
161extern long kvmppc_prepare_vrma(struct kvm *kvm,
162 struct kvm_userspace_memory_region *mem);
Paul Mackerrasc77162d2011-12-12 12:31:00 +0000163extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu,
Paul Mackerrasda9d1d72011-12-12 12:31:41 +0000164 struct kvm_memory_slot *memslot, unsigned long porder);
Paul Mackerrasa8606e22011-06-29 00:22:05 +0000165extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu);
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000166
David Gibson54738c02011-06-29 00:22:41 +0000167extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
Alexey Kardashevskiy58ded422016-03-01 17:54:40 +1100168 struct kvm_create_spapr_tce_64 *args);
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +1100169extern struct kvmppc_spapr_tce_table *kvmppc_find_table(
170 struct kvm_vcpu *vcpu, unsigned long liobn);
Alexey Kardashevskiy5ee7af12016-02-15 12:55:08 +1100171extern long kvmppc_ioba_validate(struct kvmppc_spapr_tce_table *stt,
172 unsigned long ioba, unsigned long npages);
173extern long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *tt,
174 unsigned long tce);
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +1100175extern long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa,
176 unsigned long *ua, unsigned long **prmap);
177extern void kvmppc_tce_put(struct kvmppc_spapr_tce_table *tt,
178 unsigned long idx, unsigned long tce);
Benjamin Herrenschmidtf31e65e2012-03-15 21:58:34 +0000179extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
180 unsigned long ioba, unsigned long tce);
Alexey Kardashevskiyd3695aa2016-02-15 12:55:09 +1100181extern long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu,
182 unsigned long liobn, unsigned long ioba,
183 unsigned long tce_list, unsigned long npages);
184extern long kvmppc_h_stuff_tce(struct kvm_vcpu *vcpu,
185 unsigned long liobn, unsigned long ioba,
186 unsigned long tce_value, unsigned long npages);
Laurent Dufour69e9fbb22014-02-21 16:31:10 +0100187extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
188 unsigned long ioba);
Aneesh Kumar K.Vfa61a4e32013-07-02 11:15:16 +0530189extern struct page *kvm_alloc_hpt(unsigned long nr_pages);
190extern void kvm_release_hpt(struct page *page, unsigned long nr_pages);
Paul Mackerrasf9e05542011-06-29 00:19:22 +0000191extern int kvmppc_core_init_vm(struct kvm *kvm);
192extern void kvmppc_core_destroy_vm(struct kvm *kvm);
Aneesh Kumar K.V55870272013-10-07 22:18:00 +0530193extern void kvmppc_core_free_memslot(struct kvm *kvm,
194 struct kvm_memory_slot *free,
Paul Mackerrasa66b48c2012-09-11 13:27:46 +0000195 struct kvm_memory_slot *dont);
Aneesh Kumar K.V55870272013-10-07 22:18:00 +0530196extern int kvmppc_core_create_memslot(struct kvm *kvm,
197 struct kvm_memory_slot *slot,
Paul Mackerrasa66b48c2012-09-11 13:27:46 +0000198 unsigned long npages);
Paul Mackerrasf9e05542011-06-29 00:19:22 +0000199extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
Paul Mackerrasa66b48c2012-09-11 13:27:46 +0000200 struct kvm_memory_slot *memslot,
Paolo Bonzini09170a42015-05-18 13:59:39 +0200201 const struct kvm_userspace_memory_region *mem);
Paul Mackerrasf9e05542011-06-29 00:19:22 +0000202extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
Paolo Bonzini09170a42015-05-18 13:59:39 +0200203 const struct kvm_userspace_memory_region *mem,
Paolo Bonzinif36f3f22015-05-18 13:20:23 +0200204 const struct kvm_memory_slot *old,
205 const struct kvm_memory_slot *new);
Benjamin Herrenschmidt5b747162012-04-26 19:43:42 +0000206extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
207 struct kvm_ppc_smmu_info *info);
Paul Mackerrasdfe49db2012-09-11 13:28:18 +0000208extern void kvmppc_core_flush_memslot(struct kvm *kvm,
209 struct kvm_memory_slot *memslot);
Paul Mackerrasf9e05542011-06-29 00:19:22 +0000210
Scott Woodd30f6e42011-12-20 15:34:43 +0000211extern int kvmppc_bookehv_init(void);
212extern void kvmppc_bookehv_exit(void);
213
Alexander Graf03d25c52012-08-10 12:28:50 +0200214extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu);
215
Paul Mackerrasa2932922012-11-19 22:57:20 +0000216extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *);
217
Scott Wood5df554ad2013-04-12 14:08:46 +0000218int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq);
219
Michael Ellerman8e591cb2013-04-17 20:30:00 +0000220extern int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp);
221extern int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu);
222extern void kvmppc_rtas_tokens_free(struct kvm *kvm);
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000223extern int kvmppc_xics_set_xive(struct kvm *kvm, u32 irq, u32 server,
224 u32 priority);
225extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server,
226 u32 *priority);
Paul Mackerrasd19bd8622013-04-17 20:32:04 +0000227extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq);
228extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq);
Michael Ellerman8e591cb2013-04-17 20:30:00 +0000229
Bharat Bhushan2f699a52014-08-13 14:39:44 +0530230void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu);
231void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu);
232
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530233union kvmppc_one_reg {
234 u32 wval;
235 u64 dval;
236 vector128 vval;
237 u64 vsxval[2];
238 struct {
239 u64 addr;
240 u64 length;
241 } vpaval;
242};
243
244struct kvmppc_ops {
Aneesh Kumar K.Vcbbc58d2013-10-07 22:18:01 +0530245 struct module *owner;
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530246 int (*get_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
247 int (*set_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
248 int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id,
249 union kvmppc_one_reg *val);
250 int (*set_one_reg)(struct kvm_vcpu *vcpu, u64 id,
251 union kvmppc_one_reg *val);
252 void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);
253 void (*vcpu_put)(struct kvm_vcpu *vcpu);
254 void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr);
255 int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
256 struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id);
257 void (*vcpu_free)(struct kvm_vcpu *vcpu);
258 int (*check_requests)(struct kvm_vcpu *vcpu);
259 int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log);
260 void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot);
261 int (*prepare_memory_region)(struct kvm *kvm,
262 struct kvm_memory_slot *memslot,
Paolo Bonzini09170a42015-05-18 13:59:39 +0200263 const struct kvm_userspace_memory_region *mem);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530264 void (*commit_memory_region)(struct kvm *kvm,
Paolo Bonzini09170a42015-05-18 13:59:39 +0200265 const struct kvm_userspace_memory_region *mem,
Paolo Bonzinif36f3f22015-05-18 13:20:23 +0200266 const struct kvm_memory_slot *old,
267 const struct kvm_memory_slot *new);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530268 int (*unmap_hva)(struct kvm *kvm, unsigned long hva);
269 int (*unmap_hva_range)(struct kvm *kvm, unsigned long start,
270 unsigned long end);
Andres Lagar-Cavilla57128462014-09-22 14:54:42 -0700271 int (*age_hva)(struct kvm *kvm, unsigned long start, unsigned long end);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530272 int (*test_age_hva)(struct kvm *kvm, unsigned long hva);
273 void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte);
274 void (*mmu_destroy)(struct kvm_vcpu *vcpu);
275 void (*free_memslot)(struct kvm_memory_slot *free,
276 struct kvm_memory_slot *dont);
277 int (*create_memslot)(struct kvm_memory_slot *slot,
278 unsigned long npages);
279 int (*init_vm)(struct kvm *kvm);
280 void (*destroy_vm)(struct kvm *kvm);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530281 int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info);
282 int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu,
283 unsigned int inst, int *advance);
284 int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val);
285 int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val);
286 void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu);
287 long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl,
288 unsigned long arg);
Paul Mackerrasae2113a2014-06-02 11:03:00 +1000289 int (*hcall_implemented)(unsigned long hcall);
Suresh Warrier95767302016-08-19 15:35:47 +1000290 int (*irq_bypass_add_producer)(struct irq_bypass_consumer *,
291 struct irq_bypass_producer *);
292 void (*irq_bypass_del_producer)(struct irq_bypass_consumer *,
293 struct irq_bypass_producer *);
Paul Mackerrasc9270132017-01-30 21:21:41 +1100294 int (*configure_mmu)(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg);
295 int (*get_rmmu_info)(struct kvm *kvm, struct kvm_ppc_rmmu_info *info);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530296};
297
Aneesh Kumar K.Vcbbc58d2013-10-07 22:18:01 +0530298extern struct kvmppc_ops *kvmppc_hv_ops;
299extern struct kvmppc_ops *kvmppc_pr_ops;
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530300
Mihai Caraman51f04722014-07-23 19:06:21 +0300301static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu,
302 enum instruction_type type, u32 *inst)
303{
304 int ret = EMULATE_DONE;
305 u32 fetched_inst;
306
307 /* Load the instruction manually if it failed to do so in the
308 * exit path */
309 if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED)
310 ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst);
311
312 /* Write fetch_failed unswapped if the fetch failed */
313 if (ret == EMULATE_DONE)
314 fetched_inst = kvmppc_need_byteswap(vcpu) ?
315 swab32(vcpu->arch.last_inst) :
316 vcpu->arch.last_inst;
317 else
318 fetched_inst = vcpu->arch.last_inst;
319
320 *inst = fetched_inst;
321 return ret;
322}
323
Aneesh Kumar K.Va78b55d2013-10-07 22:18:02 +0530324static inline bool is_kvmppc_hv_enabled(struct kvm *kvm)
325{
326 return kvm->arch.kvm_ops == kvmppc_hv_ops;
327}
328
Michael Ellermane928e9c2015-03-20 20:39:41 +1100329extern int kvmppc_hwrng_present(void);
330
Alexander Graf0564ee82010-02-19 11:00:42 +0100331/*
332 * Cuts out inst bits with ordering according to spec.
333 * That means the leftmost bit is zero. All given bits are included.
334 */
335static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb)
336{
337 u32 r;
338 u32 mask;
339
340 BUG_ON(msb > lsb);
341
342 mask = (1 << (lsb - msb + 1)) - 1;
343 r = (inst >> (63 - lsb)) & mask;
344
345 return r;
346}
347
348/*
349 * Replaces inst bits with ordering according to spec.
350 */
351static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
352{
353 u32 r;
354 u32 mask;
355
356 BUG_ON(msb > lsb);
357
358 mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb);
359 r = (inst & ~mask) | ((value << (63 - lsb)) & mask);
360
361 return r;
362}
363
Paul Mackerrasa136a8b2012-09-25 20:31:56 +0000364#define one_reg_size(id) \
365 (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
366
367#define get_reg_val(id, reg) ({ \
368 union kvmppc_one_reg __u; \
369 switch (one_reg_size(id)) { \
370 case 4: __u.wval = (reg); break; \
371 case 8: __u.dval = (reg); break; \
372 default: BUG(); \
373 } \
374 __u; \
375})
376
377
378#define set_reg_val(id, val) ({ \
379 u64 __v; \
380 switch (one_reg_size(id)) { \
381 case 4: __v = (val).wval; break; \
382 case 8: __v = (val).dval; break; \
383 default: BUG(); \
384 } \
385 __v; \
386})
387
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530388int kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
Scott Wood5ce941e2011-04-27 17:24:21 -0500389int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
390
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530391int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
Scott Wood5ce941e2011-04-27 17:24:21 -0500392int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
393
Paul Mackerras31f34382011-12-12 12:26:50 +0000394int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
395int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
Paul Mackerrasa136a8b2012-09-25 20:31:56 +0000396int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
397int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
Paul Mackerras31f34382011-12-12 12:26:50 +0000398
Scott Wood5ce941e2011-04-27 17:24:21 -0500399void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
400
Scott Wood5df554ad2013-04-12 14:08:46 +0000401struct openpic;
Scott Wood5df554ad2013-04-12 14:08:46 +0000402
Aneesh Kumar K.V9975f5e2013-10-07 22:17:52 +0530403#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
Aneesh Kumar K.Vfa61a4e32013-07-02 11:15:16 +0530404extern void kvm_cma_reserve(void) __init;
Paul Mackerras371fefd2011-06-29 00:23:08 +0000405static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
406{
407 paca[cpu].kvm_hstate.xics_phys = addr;
408}
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +0000409
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000410static inline u32 kvmppc_get_xics_latch(void)
411{
Aneesh Kumar K.V699cc872013-10-07 22:17:56 +0530412 u32 xirr;
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000413
Aneesh Kumar K.V699cc872013-10-07 22:17:56 +0530414 xirr = get_paca()->kvm_hstate.saved_xirr;
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000415 get_paca()->kvm_hstate.saved_xirr = 0;
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000416 return xirr;
417}
418
419static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)
420{
421 paca[cpu].kvm_hstate.host_ipi = host_ipi;
422}
423
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530424static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
425{
Aneesh Kumar K.Vcbbc58d2013-10-07 22:18:01 +0530426 vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530427}
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +0000428
Michael Ellerman441c19c2014-05-23 18:15:25 +1000429extern void kvm_hv_vm_activated(void);
430extern void kvm_hv_vm_deactivated(void);
431extern bool kvm_hv_mode_active(void);
432
Paul Mackerras371fefd2011-06-29 00:23:08 +0000433#else
Aneesh Kumar K.Vfa61a4e32013-07-02 11:15:16 +0530434static inline void __init kvm_cma_reserve(void)
435{}
436
Paul Mackerras371fefd2011-06-29 00:23:08 +0000437static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
438{}
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +0000439
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000440static inline u32 kvmppc_get_xics_latch(void)
441{
442 return 0;
443}
444
445static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)
446{}
447
448static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
449{
450 kvm_vcpu_kick(vcpu);
451}
Michael Ellerman441c19c2014-05-23 18:15:25 +1000452
453static inline bool kvm_hv_mode_active(void) { return false; }
454
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000455#endif
456
457#ifdef CONFIG_KVM_XICS
458static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
459{
460 return vcpu->arch.irq_type == KVMPPC_IRQ_XICS;
461}
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000462
463static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
464 struct kvm *kvm)
465{
Suresh Warrier644abbb2016-08-19 15:35:54 +1000466 if (kvm && kvm_irq_bypass)
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000467 return kvm->arch.pimap;
468 return NULL;
469}
470
Suresh Warrier79b6c242015-12-17 14:59:06 -0600471extern void kvmppc_alloc_host_rm_ops(void);
472extern void kvmppc_free_host_rm_ops(void);
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000473extern void kvmppc_free_pimap(struct kvm *kvm);
Suresh Warrierf7af5202016-08-19 15:35:52 +1000474extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall);
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000475extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu);
476extern int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server);
477extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args);
478extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
Paul Mackerras8b786452013-04-17 20:32:26 +0000479extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
480extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
Paul Mackerras5975a2e2013-04-27 00:28:37 +0000481extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev,
482 struct kvm_vcpu *vcpu, u32 cpu);
Suresh Warrier0c2a6602015-12-17 14:59:09 -0600483extern void kvmppc_xics_ipi_action(void);
Paul Mackerras5d375192016-08-19 15:35:56 +1000484extern void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long guest_irq,
485 unsigned long host_irq);
486extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
487 unsigned long host_irq);
Paul Mackerrasf7257582016-11-18 09:02:08 +1100488extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, __be32 xirr,
489 struct kvmppc_irq_map *irq_map,
490 struct kvmppc_passthru_irqmap *pimap,
491 bool *again);
Suresh E. Warrier520fe9c2015-12-21 16:33:57 -0600492extern int h_ipi_redirect;
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000493#else
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000494static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
495 struct kvm *kvm)
496 { return NULL; }
Suresh Warrier79b6c242015-12-17 14:59:06 -0600497static inline void kvmppc_alloc_host_rm_ops(void) {};
498static inline void kvmppc_free_host_rm_ops(void) {};
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000499static inline void kvmppc_free_pimap(struct kvm *kvm) {};
Suresh Warrierf7af5202016-08-19 15:35:52 +1000500static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall)
501 { return 0; }
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000502static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
503 { return 0; }
504static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { }
505static inline int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu,
506 unsigned long server)
507 { return -EINVAL; }
508static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm,
509 struct kvm_irq_level *args)
510 { return -ENOTTY; }
511static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd)
512 { return 0; }
Paul Mackerras371fefd2011-06-29 00:23:08 +0000513#endif
514
Suresh Warrier79b6c242015-12-17 14:59:06 -0600515/*
Paul Mackerrase34af782016-12-01 14:03:46 +1100516 * Prototypes for functions called only from assembler code.
517 * Having prototypes reduces sparse errors.
518 */
519long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
520 unsigned long ioba, unsigned long tce);
521long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu,
522 unsigned long liobn, unsigned long ioba,
523 unsigned long tce_list, unsigned long npages);
524long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu,
525 unsigned long liobn, unsigned long ioba,
526 unsigned long tce_value, unsigned long npages);
527long int kvmppc_rm_h_confer(struct kvm_vcpu *vcpu, int target,
528 unsigned int yield_count);
529long kvmppc_h_random(struct kvm_vcpu *vcpu);
530void kvmhv_commence_exit(int trap);
531long kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu);
532void kvmppc_subcore_enter_guest(void);
533void kvmppc_subcore_exit_guest(void);
534long kvmppc_realmode_hmi_handler(void);
535long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags,
536 long pte_index, unsigned long pteh, unsigned long ptel);
537long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags,
538 unsigned long pte_index, unsigned long avpn);
539long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu);
540long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags,
541 unsigned long pte_index, unsigned long avpn,
542 unsigned long va);
543long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags,
544 unsigned long pte_index);
545long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags,
546 unsigned long pte_index);
547long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags,
548 unsigned long pte_index);
549long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr,
550 unsigned long slb_v, unsigned int status, bool data);
551unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu);
552int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server,
553 unsigned long mfrr);
554int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr);
555int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr);
556
557/*
Suresh Warrier79b6c242015-12-17 14:59:06 -0600558 * Host-side operations we want to set up while running in real
559 * mode in the guest operating on the xics.
560 * Currently only VCPU wakeup is supported.
561 */
562
563union kvmppc_rm_state {
564 unsigned long raw;
565 struct {
566 u32 in_host;
567 u32 rm_action;
568 };
569};
570
571struct kvmppc_host_rm_core {
572 union kvmppc_rm_state rm_state;
573 void *rm_data;
574 char pad[112];
575};
576
577struct kvmppc_host_rm_ops {
578 struct kvmppc_host_rm_core *rm_core;
579 void (*vcpu_kick)(struct kvm_vcpu *vcpu);
580};
581
582extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv;
583
Bharat Bhushan34f754b2014-07-17 17:01:40 +0530584static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu)
585{
586#ifdef CONFIG_KVM_BOOKE_HV
587 return mfspr(SPRN_GEPR);
588#elif defined(CONFIG_BOOKE)
589 return vcpu->arch.epr;
590#else
591 return 0;
592#endif
593}
594
Alexander Graf1c810632013-01-04 18:12:48 +0100595static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr)
596{
597#ifdef CONFIG_KVM_BOOKE_HV
598 mtspr(SPRN_GEPR, epr);
599#elif defined(CONFIG_BOOKE)
600 vcpu->arch.epr = epr;
601#endif
602}
603
Scott Wood5df554ad2013-04-12 14:08:46 +0000604#ifdef CONFIG_KVM_MPIC
605
606void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu);
Scott Woodeb1e4f42013-04-12 14:08:47 +0000607int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu,
608 u32 cpu);
609void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu);
Scott Wood5df554ad2013-04-12 14:08:46 +0000610
611#else
612
613static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu)
614{
615}
616
Scott Woodeb1e4f42013-04-12 14:08:47 +0000617static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev,
618 struct kvm_vcpu *vcpu, u32 cpu)
619{
620 return -EINVAL;
621}
622
623static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp,
624 struct kvm_vcpu *vcpu)
625{
626}
627
Scott Wood5df554ad2013-04-12 14:08:46 +0000628#endif /* CONFIG_KVM_MPIC */
629
Scott Wooddc83b8b2011-08-18 15:25:21 -0500630int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
631 struct kvm_config_tlb *cfg);
632int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
633 struct kvm_dirty_tlb *cfg);
634
Scott Wood043cc4d2011-12-20 15:34:20 +0000635long kvmppc_alloc_lpid(void);
636void kvmppc_claim_lpid(long lpid);
637void kvmppc_free_lpid(long lpid);
638void kvmppc_init_lpid(unsigned long nr_lpids);
639
Dan Williamsba049e92016-01-15 16:56:11 -0800640static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn)
Alexander Graf249ba1e2012-08-03 13:56:33 +0200641{
Alexander Graf249ba1e2012-08-03 13:56:33 +0200642 struct page *page;
Bharat Bhushanadccf652013-04-25 06:33:57 +0000643 /*
644 * We can only access pages that the kernel maps
645 * as memory. Bail out for unmapped ones.
646 */
647 if (!pfn_valid(pfn))
648 return;
649
650 /* Clear i-cache for new pages */
Alexander Graf249ba1e2012-08-03 13:56:33 +0200651 page = pfn_to_page(pfn);
652 if (!test_bit(PG_arch_1, &page->flags)) {
653 flush_dcache_icache_page(page);
654 set_bit(PG_arch_1, &page->flags);
655 }
656}
657
Scott Wood5f1c2482013-07-10 17:47:39 -0500658/*
Alexander Graf5deb8e72014-04-24 13:46:24 +0200659 * Shared struct helpers. The shared struct can be little or big endian,
660 * depending on the guest endianness. So expose helpers to all of them.
661 */
662static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu)
663{
664#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
665 /* Only Book3S_64 PR supports bi-endian for now */
666 return vcpu->arch.shared_big_endian;
667#elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__)
668 /* Book3s_64 HV on little endian is always little endian */
669 return false;
670#else
671 return true;
672#endif
673}
674
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530675#define SPRNG_WRAPPER_GET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530676static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
677{ \
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530678 return mfspr(bookehv_spr); \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530679} \
680
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530681#define SPRNG_WRAPPER_SET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530682static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \
683{ \
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530684 mtspr(bookehv_spr, val); \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530685} \
686
Alexander Graf5deb8e72014-04-24 13:46:24 +0200687#define SHARED_WRAPPER_GET(reg, size) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530688static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
Alexander Graf5deb8e72014-04-24 13:46:24 +0200689{ \
690 if (kvmppc_shared_big_endian(vcpu)) \
691 return be##size##_to_cpu(vcpu->arch.shared->reg); \
692 else \
693 return le##size##_to_cpu(vcpu->arch.shared->reg); \
694} \
695
696#define SHARED_WRAPPER_SET(reg, size) \
697static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \
698{ \
699 if (kvmppc_shared_big_endian(vcpu)) \
700 vcpu->arch.shared->reg = cpu_to_be##size(val); \
701 else \
702 vcpu->arch.shared->reg = cpu_to_le##size(val); \
703} \
704
705#define SHARED_WRAPPER(reg, size) \
706 SHARED_WRAPPER_GET(reg, size) \
707 SHARED_WRAPPER_SET(reg, size) \
708
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530709#define SPRNG_WRAPPER(reg, bookehv_spr) \
710 SPRNG_WRAPPER_GET(reg, bookehv_spr) \
711 SPRNG_WRAPPER_SET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530712
713#ifdef CONFIG_KVM_BOOKE_HV
714
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530715#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
716 SPRNG_WRAPPER(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530717
718#else
719
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530720#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530721 SHARED_WRAPPER(reg, size) \
722
723#endif
724
Alexander Graf5deb8e72014-04-24 13:46:24 +0200725SHARED_WRAPPER(critical, 64)
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530726SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0)
727SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1)
728SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2)
729SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3)
730SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0)
731SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1)
732SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR)
Bharat Bhushandc168542014-07-17 17:01:38 +0530733SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR)
Alexander Graf5deb8e72014-04-24 13:46:24 +0200734SHARED_WRAPPER_GET(msr, 64)
735static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val)
736{
737 if (kvmppc_shared_big_endian(vcpu))
738 vcpu->arch.shared->msr = cpu_to_be64(val);
739 else
740 vcpu->arch.shared->msr = cpu_to_le64(val);
741}
742SHARED_WRAPPER(dsisr, 32)
743SHARED_WRAPPER(int_pending, 32)
744SHARED_WRAPPER(sprg4, 64)
745SHARED_WRAPPER(sprg5, 64)
746SHARED_WRAPPER(sprg6, 64)
747SHARED_WRAPPER(sprg7, 64)
748
749static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr)
750{
751 if (kvmppc_shared_big_endian(vcpu))
752 return be32_to_cpu(vcpu->arch.shared->sr[nr]);
753 else
754 return le32_to_cpu(vcpu->arch.shared->sr[nr]);
755}
756
757static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val)
758{
759 if (kvmppc_shared_big_endian(vcpu))
760 vcpu->arch.shared->sr[nr] = cpu_to_be32(val);
761 else
762 vcpu->arch.shared->sr[nr] = cpu_to_le32(val);
763}
764
765/*
Scott Wood5f1c2482013-07-10 17:47:39 -0500766 * Please call after prepare_to_enter. This function puts the lazy ee and irq
767 * disabled tracking state back to normal mode, without actually enabling
768 * interrupts.
769 */
770static inline void kvmppc_fix_ee_before_entry(void)
Alexander Grafbd2be682012-08-13 01:04:19 +0200771{
Scott Wood5f1c2482013-07-10 17:47:39 -0500772 trace_hardirqs_on();
773
Alexander Grafbd2be682012-08-13 01:04:19 +0200774#ifdef CONFIG_PPC64
Scott Wood6c85f522014-01-09 19:18:40 -0600775 /*
776 * To avoid races, the caller must have gone directly from having
777 * interrupts fully-enabled to hard-disabled.
778 */
779 WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);
780
Alexander Grafbd2be682012-08-13 01:04:19 +0200781 /* Only need to enable IRQs by hard enabling them after this */
782 local_paca->irq_happened = 0;
783 local_paca->soft_enabled = 1;
784#endif
785}
Alexander Graf249ba1e2012-08-03 13:56:33 +0200786
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000787static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)
788{
789 ulong ea;
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000790 ulong msr_64bit = 0;
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000791
792 ea = kvmppc_get_gpr(vcpu, rb);
793 if (ra)
794 ea += kvmppc_get_gpr(vcpu, ra);
795
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000796#if defined(CONFIG_PPC_BOOK3E_64)
797 msr_64bit = MSR_CM;
798#elif defined(CONFIG_PPC_BOOK3S_64)
799 msr_64bit = MSR_SF;
800#endif
801
Alexander Graf5deb8e72014-04-24 13:46:24 +0200802 if (!(kvmppc_get_msr(vcpu) & msr_64bit))
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000803 ea = (uint32_t)ea;
804
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000805 return ea;
806}
807
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000808extern void xics_wake_cpu(int cpu);
809
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500810#endif /* __POWERPC_KVM_PPC_H__ */