blob: 4ca2ba36a860cee57bcd895a7cfc7fe0aa517750 [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 *);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530294};
295
Aneesh Kumar K.Vcbbc58d2013-10-07 22:18:01 +0530296extern struct kvmppc_ops *kvmppc_hv_ops;
297extern struct kvmppc_ops *kvmppc_pr_ops;
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530298
Mihai Caraman51f04722014-07-23 19:06:21 +0300299static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu,
300 enum instruction_type type, u32 *inst)
301{
302 int ret = EMULATE_DONE;
303 u32 fetched_inst;
304
305 /* Load the instruction manually if it failed to do so in the
306 * exit path */
307 if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED)
308 ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst);
309
310 /* Write fetch_failed unswapped if the fetch failed */
311 if (ret == EMULATE_DONE)
312 fetched_inst = kvmppc_need_byteswap(vcpu) ?
313 swab32(vcpu->arch.last_inst) :
314 vcpu->arch.last_inst;
315 else
316 fetched_inst = vcpu->arch.last_inst;
317
318 *inst = fetched_inst;
319 return ret;
320}
321
Aneesh Kumar K.Va78b55d2013-10-07 22:18:02 +0530322static inline bool is_kvmppc_hv_enabled(struct kvm *kvm)
323{
324 return kvm->arch.kvm_ops == kvmppc_hv_ops;
325}
326
Michael Ellermane928e9c2015-03-20 20:39:41 +1100327extern int kvmppc_hwrng_present(void);
328
Alexander Graf0564ee82010-02-19 11:00:42 +0100329/*
330 * Cuts out inst bits with ordering according to spec.
331 * That means the leftmost bit is zero. All given bits are included.
332 */
333static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb)
334{
335 u32 r;
336 u32 mask;
337
338 BUG_ON(msb > lsb);
339
340 mask = (1 << (lsb - msb + 1)) - 1;
341 r = (inst >> (63 - lsb)) & mask;
342
343 return r;
344}
345
346/*
347 * Replaces inst bits with ordering according to spec.
348 */
349static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value)
350{
351 u32 r;
352 u32 mask;
353
354 BUG_ON(msb > lsb);
355
356 mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb);
357 r = (inst & ~mask) | ((value << (63 - lsb)) & mask);
358
359 return r;
360}
361
Paul Mackerrasa136a8b2012-09-25 20:31:56 +0000362#define one_reg_size(id) \
363 (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
364
365#define get_reg_val(id, reg) ({ \
366 union kvmppc_one_reg __u; \
367 switch (one_reg_size(id)) { \
368 case 4: __u.wval = (reg); break; \
369 case 8: __u.dval = (reg); break; \
370 default: BUG(); \
371 } \
372 __u; \
373})
374
375
376#define set_reg_val(id, val) ({ \
377 u64 __v; \
378 switch (one_reg_size(id)) { \
379 case 4: __v = (val).wval; break; \
380 case 8: __v = (val).dval; break; \
381 default: BUG(); \
382 } \
383 __v; \
384})
385
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530386int kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
Scott Wood5ce941e2011-04-27 17:24:21 -0500387int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
388
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530389int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
Scott Wood5ce941e2011-04-27 17:24:21 -0500390int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
391
Paul Mackerras31f34382011-12-12 12:26:50 +0000392int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
393int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg);
Paul Mackerrasa136a8b2012-09-25 20:31:56 +0000394int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
395int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *);
Paul Mackerras31f34382011-12-12 12:26:50 +0000396
Scott Wood5ce941e2011-04-27 17:24:21 -0500397void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid);
398
Scott Wood5df554ad2013-04-12 14:08:46 +0000399struct openpic;
Scott Wood5df554ad2013-04-12 14:08:46 +0000400
Aneesh Kumar K.V9975f5e2013-10-07 22:17:52 +0530401#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
Aneesh Kumar K.Vfa61a4e32013-07-02 11:15:16 +0530402extern void kvm_cma_reserve(void) __init;
Paul Mackerras371fefd2011-06-29 00:23:08 +0000403static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
404{
405 paca[cpu].kvm_hstate.xics_phys = addr;
406}
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +0000407
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000408static inline u32 kvmppc_get_xics_latch(void)
409{
Aneesh Kumar K.V699cc872013-10-07 22:17:56 +0530410 u32 xirr;
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000411
Aneesh Kumar K.V699cc872013-10-07 22:17:56 +0530412 xirr = get_paca()->kvm_hstate.saved_xirr;
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000413 get_paca()->kvm_hstate.saved_xirr = 0;
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000414 return xirr;
415}
416
417static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)
418{
419 paca[cpu].kvm_hstate.host_ipi = host_ipi;
420}
421
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530422static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
423{
Aneesh Kumar K.Vcbbc58d2013-10-07 22:18:01 +0530424 vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu);
Aneesh Kumar K.V3a167bea2013-10-07 22:17:53 +0530425}
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +0000426
Michael Ellerman441c19c2014-05-23 18:15:25 +1000427extern void kvm_hv_vm_activated(void);
428extern void kvm_hv_vm_deactivated(void);
429extern bool kvm_hv_mode_active(void);
430
Paul Mackerras371fefd2011-06-29 00:23:08 +0000431#else
Aneesh Kumar K.Vfa61a4e32013-07-02 11:15:16 +0530432static inline void __init kvm_cma_reserve(void)
433{}
434
Paul Mackerras371fefd2011-06-29 00:23:08 +0000435static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
436{}
Paul Mackerrasaa04b4c2011-06-29 00:25:44 +0000437
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000438static inline u32 kvmppc_get_xics_latch(void)
439{
440 return 0;
441}
442
443static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi)
444{}
445
446static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu)
447{
448 kvm_vcpu_kick(vcpu);
449}
Michael Ellerman441c19c2014-05-23 18:15:25 +1000450
451static inline bool kvm_hv_mode_active(void) { return false; }
452
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000453#endif
454
455#ifdef CONFIG_KVM_XICS
456static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
457{
458 return vcpu->arch.irq_type == KVMPPC_IRQ_XICS;
459}
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000460
461static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
462 struct kvm *kvm)
463{
464 if (kvm)
465 return kvm->arch.pimap;
466 return NULL;
467}
468
Suresh Warrier79b6c242015-12-17 14:59:06 -0600469extern void kvmppc_alloc_host_rm_ops(void);
470extern void kvmppc_free_host_rm_ops(void);
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000471extern void kvmppc_free_pimap(struct kvm *kvm);
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000472extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu);
473extern int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server);
474extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args);
475extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
Paul Mackerras8b786452013-04-17 20:32:26 +0000476extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
477extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
Paul Mackerras5975a2e2013-04-27 00:28:37 +0000478extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev,
479 struct kvm_vcpu *vcpu, u32 cpu);
Suresh Warrier0c2a6602015-12-17 14:59:09 -0600480extern void kvmppc_xics_ipi_action(void);
Suresh E. Warrier520fe9c2015-12-21 16:33:57 -0600481extern int h_ipi_redirect;
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000482#else
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000483static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
484 struct kvm *kvm)
485 { return NULL; }
Suresh Warrier79b6c242015-12-17 14:59:06 -0600486static inline void kvmppc_alloc_host_rm_ops(void) {};
487static inline void kvmppc_free_host_rm_ops(void) {};
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000488static inline void kvmppc_free_pimap(struct kvm *kvm) {};
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000489static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
490 { return 0; }
491static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { }
492static inline int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu,
493 unsigned long server)
494 { return -EINVAL; }
495static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm,
496 struct kvm_irq_level *args)
497 { return -ENOTTY; }
498static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd)
499 { return 0; }
Paul Mackerras371fefd2011-06-29 00:23:08 +0000500#endif
501
Suresh Warrier79b6c242015-12-17 14:59:06 -0600502/*
503 * Host-side operations we want to set up while running in real
504 * mode in the guest operating on the xics.
505 * Currently only VCPU wakeup is supported.
506 */
507
508union kvmppc_rm_state {
509 unsigned long raw;
510 struct {
511 u32 in_host;
512 u32 rm_action;
513 };
514};
515
516struct kvmppc_host_rm_core {
517 union kvmppc_rm_state rm_state;
518 void *rm_data;
519 char pad[112];
520};
521
522struct kvmppc_host_rm_ops {
523 struct kvmppc_host_rm_core *rm_core;
524 void (*vcpu_kick)(struct kvm_vcpu *vcpu);
525};
526
527extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv;
528
Bharat Bhushan34f754b2014-07-17 17:01:40 +0530529static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu)
530{
531#ifdef CONFIG_KVM_BOOKE_HV
532 return mfspr(SPRN_GEPR);
533#elif defined(CONFIG_BOOKE)
534 return vcpu->arch.epr;
535#else
536 return 0;
537#endif
538}
539
Alexander Graf1c810632013-01-04 18:12:48 +0100540static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr)
541{
542#ifdef CONFIG_KVM_BOOKE_HV
543 mtspr(SPRN_GEPR, epr);
544#elif defined(CONFIG_BOOKE)
545 vcpu->arch.epr = epr;
546#endif
547}
548
Scott Wood5df554ad2013-04-12 14:08:46 +0000549#ifdef CONFIG_KVM_MPIC
550
551void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu);
Scott Woodeb1e4f42013-04-12 14:08:47 +0000552int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu,
553 u32 cpu);
554void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu);
Scott Wood5df554ad2013-04-12 14:08:46 +0000555
556#else
557
558static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu)
559{
560}
561
Scott Woodeb1e4f42013-04-12 14:08:47 +0000562static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev,
563 struct kvm_vcpu *vcpu, u32 cpu)
564{
565 return -EINVAL;
566}
567
568static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp,
569 struct kvm_vcpu *vcpu)
570{
571}
572
Scott Wood5df554ad2013-04-12 14:08:46 +0000573#endif /* CONFIG_KVM_MPIC */
574
Scott Wooddc83b8b2011-08-18 15:25:21 -0500575int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
576 struct kvm_config_tlb *cfg);
577int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
578 struct kvm_dirty_tlb *cfg);
579
Scott Wood043cc4d2011-12-20 15:34:20 +0000580long kvmppc_alloc_lpid(void);
581void kvmppc_claim_lpid(long lpid);
582void kvmppc_free_lpid(long lpid);
583void kvmppc_init_lpid(unsigned long nr_lpids);
584
Dan Williamsba049e92016-01-15 16:56:11 -0800585static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn)
Alexander Graf249ba1e2012-08-03 13:56:33 +0200586{
Alexander Graf249ba1e2012-08-03 13:56:33 +0200587 struct page *page;
Bharat Bhushanadccf652013-04-25 06:33:57 +0000588 /*
589 * We can only access pages that the kernel maps
590 * as memory. Bail out for unmapped ones.
591 */
592 if (!pfn_valid(pfn))
593 return;
594
595 /* Clear i-cache for new pages */
Alexander Graf249ba1e2012-08-03 13:56:33 +0200596 page = pfn_to_page(pfn);
597 if (!test_bit(PG_arch_1, &page->flags)) {
598 flush_dcache_icache_page(page);
599 set_bit(PG_arch_1, &page->flags);
600 }
601}
602
Scott Wood5f1c2482013-07-10 17:47:39 -0500603/*
Alexander Graf5deb8e72014-04-24 13:46:24 +0200604 * Shared struct helpers. The shared struct can be little or big endian,
605 * depending on the guest endianness. So expose helpers to all of them.
606 */
607static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu)
608{
609#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
610 /* Only Book3S_64 PR supports bi-endian for now */
611 return vcpu->arch.shared_big_endian;
612#elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__)
613 /* Book3s_64 HV on little endian is always little endian */
614 return false;
615#else
616 return true;
617#endif
618}
619
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530620#define SPRNG_WRAPPER_GET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530621static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
622{ \
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530623 return mfspr(bookehv_spr); \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530624} \
625
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530626#define SPRNG_WRAPPER_SET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530627static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \
628{ \
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530629 mtspr(bookehv_spr, val); \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530630} \
631
Alexander Graf5deb8e72014-04-24 13:46:24 +0200632#define SHARED_WRAPPER_GET(reg, size) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530633static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
Alexander Graf5deb8e72014-04-24 13:46:24 +0200634{ \
635 if (kvmppc_shared_big_endian(vcpu)) \
636 return be##size##_to_cpu(vcpu->arch.shared->reg); \
637 else \
638 return le##size##_to_cpu(vcpu->arch.shared->reg); \
639} \
640
641#define SHARED_WRAPPER_SET(reg, size) \
642static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \
643{ \
644 if (kvmppc_shared_big_endian(vcpu)) \
645 vcpu->arch.shared->reg = cpu_to_be##size(val); \
646 else \
647 vcpu->arch.shared->reg = cpu_to_le##size(val); \
648} \
649
650#define SHARED_WRAPPER(reg, size) \
651 SHARED_WRAPPER_GET(reg, size) \
652 SHARED_WRAPPER_SET(reg, size) \
653
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530654#define SPRNG_WRAPPER(reg, bookehv_spr) \
655 SPRNG_WRAPPER_GET(reg, bookehv_spr) \
656 SPRNG_WRAPPER_SET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530657
658#ifdef CONFIG_KVM_BOOKE_HV
659
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530660#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
661 SPRNG_WRAPPER(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530662
663#else
664
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530665#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530666 SHARED_WRAPPER(reg, size) \
667
668#endif
669
Alexander Graf5deb8e72014-04-24 13:46:24 +0200670SHARED_WRAPPER(critical, 64)
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530671SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0)
672SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1)
673SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2)
674SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3)
675SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0)
676SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1)
677SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR)
Bharat Bhushandc168542014-07-17 17:01:38 +0530678SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR)
Alexander Graf5deb8e72014-04-24 13:46:24 +0200679SHARED_WRAPPER_GET(msr, 64)
680static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val)
681{
682 if (kvmppc_shared_big_endian(vcpu))
683 vcpu->arch.shared->msr = cpu_to_be64(val);
684 else
685 vcpu->arch.shared->msr = cpu_to_le64(val);
686}
687SHARED_WRAPPER(dsisr, 32)
688SHARED_WRAPPER(int_pending, 32)
689SHARED_WRAPPER(sprg4, 64)
690SHARED_WRAPPER(sprg5, 64)
691SHARED_WRAPPER(sprg6, 64)
692SHARED_WRAPPER(sprg7, 64)
693
694static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr)
695{
696 if (kvmppc_shared_big_endian(vcpu))
697 return be32_to_cpu(vcpu->arch.shared->sr[nr]);
698 else
699 return le32_to_cpu(vcpu->arch.shared->sr[nr]);
700}
701
702static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val)
703{
704 if (kvmppc_shared_big_endian(vcpu))
705 vcpu->arch.shared->sr[nr] = cpu_to_be32(val);
706 else
707 vcpu->arch.shared->sr[nr] = cpu_to_le32(val);
708}
709
710/*
Scott Wood5f1c2482013-07-10 17:47:39 -0500711 * Please call after prepare_to_enter. This function puts the lazy ee and irq
712 * disabled tracking state back to normal mode, without actually enabling
713 * interrupts.
714 */
715static inline void kvmppc_fix_ee_before_entry(void)
Alexander Grafbd2be682012-08-13 01:04:19 +0200716{
Scott Wood5f1c2482013-07-10 17:47:39 -0500717 trace_hardirqs_on();
718
Alexander Grafbd2be682012-08-13 01:04:19 +0200719#ifdef CONFIG_PPC64
Scott Wood6c85f522014-01-09 19:18:40 -0600720 /*
721 * To avoid races, the caller must have gone directly from having
722 * interrupts fully-enabled to hard-disabled.
723 */
724 WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);
725
Alexander Grafbd2be682012-08-13 01:04:19 +0200726 /* Only need to enable IRQs by hard enabling them after this */
727 local_paca->irq_happened = 0;
728 local_paca->soft_enabled = 1;
729#endif
730}
Alexander Graf249ba1e2012-08-03 13:56:33 +0200731
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000732static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)
733{
734 ulong ea;
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000735 ulong msr_64bit = 0;
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000736
737 ea = kvmppc_get_gpr(vcpu, rb);
738 if (ra)
739 ea += kvmppc_get_gpr(vcpu, ra);
740
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000741#if defined(CONFIG_PPC_BOOK3E_64)
742 msr_64bit = MSR_CM;
743#elif defined(CONFIG_PPC_BOOK3S_64)
744 msr_64bit = MSR_SF;
745#endif
746
Alexander Graf5deb8e72014-04-24 13:46:24 +0200747 if (!(kvmppc_get_msr(vcpu) & msr_64bit))
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000748 ea = (uint32_t)ea;
749
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000750 return ea;
751}
752
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000753extern void xics_wake_cpu(int cpu);
754
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500755#endif /* __POWERPC_KVM_PPC_H__ */