blob: f6e49640dbe1ebd38bae9a3e1b2af30a679f6fdb [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{
Suresh Warrier644abbb2016-08-19 15:35:54 +1000464 if (kvm && kvm_irq_bypass)
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000465 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);
Suresh Warrierf7af5202016-08-19 15:35:52 +1000472extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall);
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000473extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu);
474extern int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server);
475extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args);
476extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd);
Paul Mackerras8b786452013-04-17 20:32:26 +0000477extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu);
478extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval);
Paul Mackerras5975a2e2013-04-27 00:28:37 +0000479extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev,
480 struct kvm_vcpu *vcpu, u32 cpu);
Suresh Warrier0c2a6602015-12-17 14:59:09 -0600481extern void kvmppc_xics_ipi_action(void);
Paul Mackerras5d375192016-08-19 15:35:56 +1000482extern void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long guest_irq,
483 unsigned long host_irq);
484extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq,
485 unsigned long host_irq);
Suresh Warriere3c13e52016-08-19 15:35:51 +1000486extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, u32 xirr,
487 struct kvmppc_irq_map *irq_map,
488 struct kvmppc_passthru_irqmap *pimap);
Suresh E. Warrier520fe9c2015-12-21 16:33:57 -0600489extern int h_ipi_redirect;
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000490#else
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000491static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap(
492 struct kvm *kvm)
493 { return NULL; }
Suresh Warrier79b6c242015-12-17 14:59:06 -0600494static inline void kvmppc_alloc_host_rm_ops(void) {};
495static inline void kvmppc_free_host_rm_ops(void) {};
Suresh Warrier8daaafc2016-08-19 15:35:48 +1000496static inline void kvmppc_free_pimap(struct kvm *kvm) {};
Suresh Warrierf7af5202016-08-19 15:35:52 +1000497static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall)
498 { return 0; }
Benjamin Herrenschmidtbc5ad3f2013-04-17 20:30:26 +0000499static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu)
500 { return 0; }
501static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { }
502static inline int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu,
503 unsigned long server)
504 { return -EINVAL; }
505static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm,
506 struct kvm_irq_level *args)
507 { return -ENOTTY; }
508static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd)
509 { return 0; }
Paul Mackerras371fefd2011-06-29 00:23:08 +0000510#endif
511
Suresh Warrier79b6c242015-12-17 14:59:06 -0600512/*
513 * Host-side operations we want to set up while running in real
514 * mode in the guest operating on the xics.
515 * Currently only VCPU wakeup is supported.
516 */
517
518union kvmppc_rm_state {
519 unsigned long raw;
520 struct {
521 u32 in_host;
522 u32 rm_action;
523 };
524};
525
526struct kvmppc_host_rm_core {
527 union kvmppc_rm_state rm_state;
528 void *rm_data;
529 char pad[112];
530};
531
532struct kvmppc_host_rm_ops {
533 struct kvmppc_host_rm_core *rm_core;
534 void (*vcpu_kick)(struct kvm_vcpu *vcpu);
535};
536
537extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv;
538
Bharat Bhushan34f754b2014-07-17 17:01:40 +0530539static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu)
540{
541#ifdef CONFIG_KVM_BOOKE_HV
542 return mfspr(SPRN_GEPR);
543#elif defined(CONFIG_BOOKE)
544 return vcpu->arch.epr;
545#else
546 return 0;
547#endif
548}
549
Alexander Graf1c810632013-01-04 18:12:48 +0100550static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr)
551{
552#ifdef CONFIG_KVM_BOOKE_HV
553 mtspr(SPRN_GEPR, epr);
554#elif defined(CONFIG_BOOKE)
555 vcpu->arch.epr = epr;
556#endif
557}
558
Scott Wood5df554ad2013-04-12 14:08:46 +0000559#ifdef CONFIG_KVM_MPIC
560
561void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu);
Scott Woodeb1e4f42013-04-12 14:08:47 +0000562int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu,
563 u32 cpu);
564void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu);
Scott Wood5df554ad2013-04-12 14:08:46 +0000565
566#else
567
568static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu)
569{
570}
571
Scott Woodeb1e4f42013-04-12 14:08:47 +0000572static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev,
573 struct kvm_vcpu *vcpu, u32 cpu)
574{
575 return -EINVAL;
576}
577
578static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp,
579 struct kvm_vcpu *vcpu)
580{
581}
582
Scott Wood5df554ad2013-04-12 14:08:46 +0000583#endif /* CONFIG_KVM_MPIC */
584
Scott Wooddc83b8b2011-08-18 15:25:21 -0500585int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu,
586 struct kvm_config_tlb *cfg);
587int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu,
588 struct kvm_dirty_tlb *cfg);
589
Scott Wood043cc4d2011-12-20 15:34:20 +0000590long kvmppc_alloc_lpid(void);
591void kvmppc_claim_lpid(long lpid);
592void kvmppc_free_lpid(long lpid);
593void kvmppc_init_lpid(unsigned long nr_lpids);
594
Dan Williamsba049e92016-01-15 16:56:11 -0800595static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn)
Alexander Graf249ba1e2012-08-03 13:56:33 +0200596{
Alexander Graf249ba1e2012-08-03 13:56:33 +0200597 struct page *page;
Bharat Bhushanadccf652013-04-25 06:33:57 +0000598 /*
599 * We can only access pages that the kernel maps
600 * as memory. Bail out for unmapped ones.
601 */
602 if (!pfn_valid(pfn))
603 return;
604
605 /* Clear i-cache for new pages */
Alexander Graf249ba1e2012-08-03 13:56:33 +0200606 page = pfn_to_page(pfn);
607 if (!test_bit(PG_arch_1, &page->flags)) {
608 flush_dcache_icache_page(page);
609 set_bit(PG_arch_1, &page->flags);
610 }
611}
612
Scott Wood5f1c2482013-07-10 17:47:39 -0500613/*
Alexander Graf5deb8e72014-04-24 13:46:24 +0200614 * Shared struct helpers. The shared struct can be little or big endian,
615 * depending on the guest endianness. So expose helpers to all of them.
616 */
617static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu)
618{
619#if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE)
620 /* Only Book3S_64 PR supports bi-endian for now */
621 return vcpu->arch.shared_big_endian;
622#elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__)
623 /* Book3s_64 HV on little endian is always little endian */
624 return false;
625#else
626 return true;
627#endif
628}
629
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530630#define SPRNG_WRAPPER_GET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530631static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
632{ \
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530633 return mfspr(bookehv_spr); \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530634} \
635
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530636#define SPRNG_WRAPPER_SET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530637static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \
638{ \
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530639 mtspr(bookehv_spr, val); \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530640} \
641
Alexander Graf5deb8e72014-04-24 13:46:24 +0200642#define SHARED_WRAPPER_GET(reg, size) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530643static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \
Alexander Graf5deb8e72014-04-24 13:46:24 +0200644{ \
645 if (kvmppc_shared_big_endian(vcpu)) \
646 return be##size##_to_cpu(vcpu->arch.shared->reg); \
647 else \
648 return le##size##_to_cpu(vcpu->arch.shared->reg); \
649} \
650
651#define SHARED_WRAPPER_SET(reg, size) \
652static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \
653{ \
654 if (kvmppc_shared_big_endian(vcpu)) \
655 vcpu->arch.shared->reg = cpu_to_be##size(val); \
656 else \
657 vcpu->arch.shared->reg = cpu_to_le##size(val); \
658} \
659
660#define SHARED_WRAPPER(reg, size) \
661 SHARED_WRAPPER_GET(reg, size) \
662 SHARED_WRAPPER_SET(reg, size) \
663
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530664#define SPRNG_WRAPPER(reg, bookehv_spr) \
665 SPRNG_WRAPPER_GET(reg, bookehv_spr) \
666 SPRNG_WRAPPER_SET(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530667
668#ifdef CONFIG_KVM_BOOKE_HV
669
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530670#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
671 SPRNG_WRAPPER(reg, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530672
673#else
674
Bharat Bhushan5a484c72014-07-30 15:03:56 +0530675#define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530676 SHARED_WRAPPER(reg, size) \
677
678#endif
679
Alexander Graf5deb8e72014-04-24 13:46:24 +0200680SHARED_WRAPPER(critical, 64)
Bharat Bhushan1dc0c5b2014-07-17 17:01:35 +0530681SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0)
682SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1)
683SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2)
684SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3)
685SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0)
686SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1)
687SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR)
Bharat Bhushandc168542014-07-17 17:01:38 +0530688SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR)
Alexander Graf5deb8e72014-04-24 13:46:24 +0200689SHARED_WRAPPER_GET(msr, 64)
690static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val)
691{
692 if (kvmppc_shared_big_endian(vcpu))
693 vcpu->arch.shared->msr = cpu_to_be64(val);
694 else
695 vcpu->arch.shared->msr = cpu_to_le64(val);
696}
697SHARED_WRAPPER(dsisr, 32)
698SHARED_WRAPPER(int_pending, 32)
699SHARED_WRAPPER(sprg4, 64)
700SHARED_WRAPPER(sprg5, 64)
701SHARED_WRAPPER(sprg6, 64)
702SHARED_WRAPPER(sprg7, 64)
703
704static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr)
705{
706 if (kvmppc_shared_big_endian(vcpu))
707 return be32_to_cpu(vcpu->arch.shared->sr[nr]);
708 else
709 return le32_to_cpu(vcpu->arch.shared->sr[nr]);
710}
711
712static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val)
713{
714 if (kvmppc_shared_big_endian(vcpu))
715 vcpu->arch.shared->sr[nr] = cpu_to_be32(val);
716 else
717 vcpu->arch.shared->sr[nr] = cpu_to_le32(val);
718}
719
720/*
Scott Wood5f1c2482013-07-10 17:47:39 -0500721 * Please call after prepare_to_enter. This function puts the lazy ee and irq
722 * disabled tracking state back to normal mode, without actually enabling
723 * interrupts.
724 */
725static inline void kvmppc_fix_ee_before_entry(void)
Alexander Grafbd2be682012-08-13 01:04:19 +0200726{
Scott Wood5f1c2482013-07-10 17:47:39 -0500727 trace_hardirqs_on();
728
Alexander Grafbd2be682012-08-13 01:04:19 +0200729#ifdef CONFIG_PPC64
Scott Wood6c85f522014-01-09 19:18:40 -0600730 /*
731 * To avoid races, the caller must have gone directly from having
732 * interrupts fully-enabled to hard-disabled.
733 */
734 WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);
735
Alexander Grafbd2be682012-08-13 01:04:19 +0200736 /* Only need to enable IRQs by hard enabling them after this */
737 local_paca->irq_happened = 0;
738 local_paca->soft_enabled = 1;
739#endif
740}
Alexander Graf249ba1e2012-08-03 13:56:33 +0200741
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000742static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb)
743{
744 ulong ea;
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000745 ulong msr_64bit = 0;
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000746
747 ea = kvmppc_get_gpr(vcpu, rb);
748 if (ra)
749 ea += kvmppc_get_gpr(vcpu, ra);
750
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000751#if defined(CONFIG_PPC_BOOK3E_64)
752 msr_64bit = MSR_CM;
753#elif defined(CONFIG_PPC_BOOK3S_64)
754 msr_64bit = MSR_SF;
755#endif
756
Alexander Graf5deb8e72014-04-24 13:46:24 +0200757 if (!(kvmppc_get_msr(vcpu) & msr_64bit))
Mihai Caraman8823a8f2012-10-11 06:13:23 +0000758 ea = (uint32_t)ea;
759
Mihai Caraman7cdd7a92012-10-11 06:13:22 +0000760 return ea;
761}
762
Benjamin Herrenschmidt54695c32013-04-17 20:30:50 +0000763extern void xics_wake_cpu(int cpu);
764
Hollis Blanchardbbf45ba2008-04-16 23:28:09 -0500765#endif /* __POWERPC_KVM_PPC_H__ */