Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright 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 Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 31 | #include <linux/bug.h> |
Alexander Graf | 1c0006d | 2010-01-15 14:49:12 +0100 | [diff] [blame] | 32 | #ifdef CONFIG_PPC_BOOK3S |
| 33 | #include <asm/kvm_book3s.h> |
Alexander Graf | c7f38f4 | 2010-04-16 00:11:40 +0200 | [diff] [blame] | 34 | #else |
| 35 | #include <asm/kvm_booke.h> |
Alexander Graf | 1c0006d | 2010-01-15 14:49:12 +0100 | [diff] [blame] | 36 | #endif |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_KVM_BOOK3S_64_HANDLER |
| 38 | #include <asm/paca.h> |
| 39 | #endif |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 40 | |
Madhavan Srinivasan | a59c1d9 | 2014-09-09 22:37:35 +0530 | [diff] [blame] | 41 | /* |
| 42 | * KVMPPC_INST_SW_BREAKPOINT is debug Instruction |
| 43 | * for supporting software breakpoint. |
| 44 | */ |
| 45 | #define KVMPPC_INST_SW_BREAKPOINT 0x00dddd00 |
| 46 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 47 | enum emulation_result { |
| 48 | EMULATE_DONE, /* no further processing */ |
| 49 | EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 50 | EMULATE_FAIL, /* can't emulate this instruction */ |
Alexander Graf | 37f5bca | 2010-02-19 11:00:31 +0100 | [diff] [blame] | 51 | EMULATE_AGAIN, /* something went wrong. go again */ |
Bharat Bhushan | c402a3f | 2013-04-08 00:32:13 +0000 | [diff] [blame] | 52 | EMULATE_EXIT_USER, /* emulation requires exit to user-space */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 55 | enum instruction_type { |
| 56 | INST_GENERIC, |
| 57 | INST_SC, /* system call */ |
| 58 | }; |
| 59 | |
Alexander Graf | 7d15c06f | 2014-06-20 13:52:36 +0200 | [diff] [blame] | 60 | enum xlate_instdata { |
| 61 | XLATE_INST, /* translate instruction address */ |
| 62 | XLATE_DATA /* translate data address */ |
| 63 | }; |
| 64 | |
| 65 | enum xlate_readwrite { |
| 66 | XLATE_READ, /* check for read permissions */ |
| 67 | XLATE_WRITE /* check for write permissions */ |
| 68 | }; |
| 69 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 70 | extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 71 | extern int __kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu); |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 72 | extern void kvmppc_handler_highmem(void); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 73 | |
| 74 | extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu); |
| 75 | extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 76 | unsigned int rt, unsigned int bytes, |
Cédric Le Goater | 7360177 | 2014-01-09 11:51:16 +0100 | [diff] [blame] | 77 | int is_default_endian); |
Alexander Graf | 3587d53 | 2010-02-19 11:00:30 +0100 | [diff] [blame] | 78 | extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 79 | unsigned int rt, unsigned int bytes, |
Cédric Le Goater | 7360177 | 2014-01-09 11:51:16 +0100 | [diff] [blame] | 80 | int is_default_endian); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 81 | extern int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu, |
Cédric Le Goater | 7360177 | 2014-01-09 11:51:16 +0100 | [diff] [blame] | 82 | u64 val, unsigned int bytes, |
| 83 | int is_default_endian); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 84 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 85 | extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, |
| 86 | enum instruction_type type, u32 *inst); |
| 87 | |
Alexander Graf | 35c4a73 | 2014-06-20 13:58:16 +0200 | [diff] [blame] | 88 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
| 89 | bool data); |
| 90 | extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
| 91 | bool data); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 92 | extern int kvmppc_emulate_instruction(struct kvm_run *run, |
| 93 | struct kvm_vcpu *vcpu); |
Alexander Graf | d69614a | 2014-06-18 14:53:49 +0200 | [diff] [blame] | 94 | extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu); |
Hollis Blanchard | ce263d7 | 2008-05-21 18:22:51 -0500 | [diff] [blame] | 95 | extern int kvmppc_emulate_mmio(struct kvm_run *run, struct kvm_vcpu *vcpu); |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 96 | extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 97 | extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); |
Mihai Caraman | d02d4d1 | 2014-09-01 17:19:56 +0300 | [diff] [blame] | 98 | extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu); |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 99 | extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 100 | extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu); |
| 101 | extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 102 | |
Hollis Blanchard | ecc0981 | 2009-01-03 16:22:59 -0600 | [diff] [blame] | 103 | /* Core-specific hooks */ |
| 104 | |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 105 | extern void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 gvaddr, gpa_t gpaddr, |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 106 | unsigned int gtlb_idx); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 107 | extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode); |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 108 | extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid); |
Hollis Blanchard | ecc0981 | 2009-01-03 16:22:59 -0600 | [diff] [blame] | 109 | extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu); |
Alexander Graf | 9cc5e95 | 2010-04-16 00:11:45 +0200 | [diff] [blame] | 110 | extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu); |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 111 | extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr); |
| 112 | extern int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr); |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 113 | extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index, |
| 114 | gva_t eaddr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 115 | extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu); |
| 116 | extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu); |
Alexander Graf | 7d15c06f | 2014-06-20 13:52:36 +0200 | [diff] [blame] | 117 | extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, |
| 118 | enum xlate_instdata xlid, enum xlate_readwrite xlrw, |
| 119 | struct kvmppc_pte *pte); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 120 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 121 | extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, |
| 122 | unsigned int id); |
| 123 | extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 124 | extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 125 | extern int kvmppc_core_check_processor_compat(void); |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 126 | extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, |
| 127 | struct kvm_translation *tr); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 128 | |
| 129 | extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu); |
| 130 | extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu); |
| 131 | |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 132 | extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 133 | extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu); |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 134 | extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 135 | extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu); |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 136 | extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 137 | extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 138 | struct kvm_interrupt *irq); |
Paul Mackerras | 4fe27d2 | 2013-02-14 14:00:25 +0000 | [diff] [blame] | 139 | extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu); |
Alexander Graf | 8de1201 | 2014-06-18 21:56:55 +0200 | [diff] [blame] | 140 | extern void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, ulong dear_flags, |
| 141 | ulong esr_flags); |
| 142 | extern void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 143 | ulong dear_flags, |
| 144 | ulong esr_flags); |
| 145 | extern void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu); |
| 146 | extern void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, |
| 147 | ulong esr_flags); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 148 | extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu); |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 149 | extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 150 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 151 | extern int kvmppc_booke_init(void); |
| 152 | extern void kvmppc_booke_exit(void); |
| 153 | |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame] | 154 | extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu); |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 155 | extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu); |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 156 | extern void kvmppc_map_magic(struct kvm_vcpu *vcpu); |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame] | 157 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 158 | extern long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp); |
| 159 | extern long kvmppc_alloc_reset_hpt(struct kvm *kvm, u32 *htab_orderp); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 160 | extern void kvmppc_free_hpt(struct kvm *kvm); |
| 161 | extern long kvmppc_prepare_vrma(struct kvm *kvm, |
| 162 | struct kvm_userspace_memory_region *mem); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 163 | extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu, |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 164 | struct kvm_memory_slot *memslot, unsigned long porder); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 165 | extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 166 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 167 | extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, |
Alexey Kardashevskiy | 58ded42 | 2016-03-01 17:54:40 +1100 | [diff] [blame] | 168 | struct kvm_create_spapr_tce_64 *args); |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 169 | extern struct kvmppc_spapr_tce_table *kvmppc_find_table( |
| 170 | struct kvm_vcpu *vcpu, unsigned long liobn); |
Alexey Kardashevskiy | 5ee7af1 | 2016-02-15 12:55:08 +1100 | [diff] [blame] | 171 | extern long kvmppc_ioba_validate(struct kvmppc_spapr_tce_table *stt, |
| 172 | unsigned long ioba, unsigned long npages); |
| 173 | extern long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *tt, |
| 174 | unsigned long tce); |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 175 | extern long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa, |
| 176 | unsigned long *ua, unsigned long **prmap); |
| 177 | extern void kvmppc_tce_put(struct kvmppc_spapr_tce_table *tt, |
| 178 | unsigned long idx, unsigned long tce); |
Benjamin Herrenschmidt | f31e65e | 2012-03-15 21:58:34 +0000 | [diff] [blame] | 179 | extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 180 | unsigned long ioba, unsigned long tce); |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 181 | extern 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); |
| 184 | extern 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 Dufour | 69e9fbb2 | 2014-02-21 16:31:10 +0100 | [diff] [blame] | 187 | extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 188 | unsigned long ioba); |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 189 | extern struct page *kvm_alloc_hpt(unsigned long nr_pages); |
| 190 | extern void kvm_release_hpt(struct page *page, unsigned long nr_pages); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 191 | extern int kvmppc_core_init_vm(struct kvm *kvm); |
| 192 | extern void kvmppc_core_destroy_vm(struct kvm *kvm); |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 193 | extern void kvmppc_core_free_memslot(struct kvm *kvm, |
| 194 | struct kvm_memory_slot *free, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 195 | struct kvm_memory_slot *dont); |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 196 | extern int kvmppc_core_create_memslot(struct kvm *kvm, |
| 197 | struct kvm_memory_slot *slot, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 198 | unsigned long npages); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 199 | extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 200 | struct kvm_memory_slot *memslot, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 201 | const struct kvm_userspace_memory_region *mem); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 202 | extern void kvmppc_core_commit_memory_region(struct kvm *kvm, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 203 | const struct kvm_userspace_memory_region *mem, |
Paolo Bonzini | f36f3f2 | 2015-05-18 13:20:23 +0200 | [diff] [blame] | 204 | const struct kvm_memory_slot *old, |
| 205 | const struct kvm_memory_slot *new); |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 206 | extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, |
| 207 | struct kvm_ppc_smmu_info *info); |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 208 | extern void kvmppc_core_flush_memslot(struct kvm *kvm, |
| 209 | struct kvm_memory_slot *memslot); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 210 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 211 | extern int kvmppc_bookehv_init(void); |
| 212 | extern void kvmppc_bookehv_exit(void); |
| 213 | |
Alexander Graf | 03d25c5 | 2012-08-10 12:28:50 +0200 | [diff] [blame] | 214 | extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu); |
| 215 | |
Paul Mackerras | a293292 | 2012-11-19 22:57:20 +0000 | [diff] [blame] | 216 | extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *); |
| 217 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 218 | int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq); |
| 219 | |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 220 | extern int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp); |
| 221 | extern int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu); |
| 222 | extern void kvmppc_rtas_tokens_free(struct kvm *kvm); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 223 | extern int kvmppc_xics_set_xive(struct kvm *kvm, u32 irq, u32 server, |
| 224 | u32 priority); |
| 225 | extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server, |
| 226 | u32 *priority); |
Paul Mackerras | d19bd862 | 2013-04-17 20:32:04 +0000 | [diff] [blame] | 227 | extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq); |
| 228 | extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq); |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 229 | |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 230 | void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu); |
| 231 | void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu); |
| 232 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 233 | union 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 | |
| 244 | struct kvmppc_ops { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 245 | struct module *owner; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 246 | 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 Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 263 | const struct kvm_userspace_memory_region *mem); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 264 | void (*commit_memory_region)(struct kvm *kvm, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 265 | const struct kvm_userspace_memory_region *mem, |
Paolo Bonzini | f36f3f2 | 2015-05-18 13:20:23 +0200 | [diff] [blame] | 266 | const struct kvm_memory_slot *old, |
| 267 | const struct kvm_memory_slot *new); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 268 | 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-Cavilla | 5712846 | 2014-09-22 14:54:42 -0700 | [diff] [blame] | 271 | int (*age_hva)(struct kvm *kvm, unsigned long start, unsigned long end); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 272 | 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.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 281 | 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 Mackerras | ae2113a | 2014-06-02 11:03:00 +1000 | [diff] [blame] | 289 | int (*hcall_implemented)(unsigned long hcall); |
Suresh Warrier | 9576730 | 2016-08-19 15:35:47 +1000 | [diff] [blame] | 290 | 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.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 294 | }; |
| 295 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 296 | extern struct kvmppc_ops *kvmppc_hv_ops; |
| 297 | extern struct kvmppc_ops *kvmppc_pr_ops; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 298 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 299 | static 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.V | a78b55d | 2013-10-07 22:18:02 +0530 | [diff] [blame] | 322 | static inline bool is_kvmppc_hv_enabled(struct kvm *kvm) |
| 323 | { |
| 324 | return kvm->arch.kvm_ops == kvmppc_hv_ops; |
| 325 | } |
| 326 | |
Michael Ellerman | e928e9c | 2015-03-20 20:39:41 +1100 | [diff] [blame] | 327 | extern int kvmppc_hwrng_present(void); |
| 328 | |
Alexander Graf | 0564ee8 | 2010-02-19 11:00:42 +0100 | [diff] [blame] | 329 | /* |
| 330 | * Cuts out inst bits with ordering according to spec. |
| 331 | * That means the leftmost bit is zero. All given bits are included. |
| 332 | */ |
| 333 | static 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 | */ |
| 349 | static 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 Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 362 | #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.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 386 | int kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 387 | int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 388 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 389 | int kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 390 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 391 | |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 392 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); |
| 393 | int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 394 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *); |
| 395 | int kvmppc_set_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *); |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 396 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 397 | void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid); |
| 398 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 399 | struct openpic; |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 400 | |
Aneesh Kumar K.V | 9975f5e | 2013-10-07 22:17:52 +0530 | [diff] [blame] | 401 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 402 | extern void kvm_cma_reserve(void) __init; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 403 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
| 404 | { |
| 405 | paca[cpu].kvm_hstate.xics_phys = addr; |
| 406 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 407 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 408 | static inline u32 kvmppc_get_xics_latch(void) |
| 409 | { |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 410 | u32 xirr; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 411 | |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 412 | xirr = get_paca()->kvm_hstate.saved_xirr; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 413 | get_paca()->kvm_hstate.saved_xirr = 0; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 414 | return xirr; |
| 415 | } |
| 416 | |
| 417 | static 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.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 422 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
| 423 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 424 | vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 425 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 426 | |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 427 | extern void kvm_hv_vm_activated(void); |
| 428 | extern void kvm_hv_vm_deactivated(void); |
| 429 | extern bool kvm_hv_mode_active(void); |
| 430 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 431 | #else |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 432 | static inline void __init kvm_cma_reserve(void) |
| 433 | {} |
| 434 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 435 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
| 436 | {} |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 437 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 438 | static inline u32 kvmppc_get_xics_latch(void) |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) |
| 444 | {} |
| 445 | |
| 446 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
| 447 | { |
| 448 | kvm_vcpu_kick(vcpu); |
| 449 | } |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 450 | |
| 451 | static inline bool kvm_hv_mode_active(void) { return false; } |
| 452 | |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 453 | #endif |
| 454 | |
| 455 | #ifdef CONFIG_KVM_XICS |
| 456 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
| 457 | { |
| 458 | return vcpu->arch.irq_type == KVMPPC_IRQ_XICS; |
| 459 | } |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 460 | |
| 461 | static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap( |
| 462 | struct kvm *kvm) |
| 463 | { |
Suresh Warrier | 644abbb | 2016-08-19 15:35:54 +1000 | [diff] [blame] | 464 | if (kvm && kvm_irq_bypass) |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 465 | return kvm->arch.pimap; |
| 466 | return NULL; |
| 467 | } |
| 468 | |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 469 | extern void kvmppc_alloc_host_rm_ops(void); |
| 470 | extern void kvmppc_free_host_rm_ops(void); |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 471 | extern void kvmppc_free_pimap(struct kvm *kvm); |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 472 | extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 473 | extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu); |
| 474 | extern int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server); |
| 475 | extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args); |
| 476 | extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd); |
Paul Mackerras | 8b78645 | 2013-04-17 20:32:26 +0000 | [diff] [blame] | 477 | extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu); |
| 478 | extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval); |
Paul Mackerras | 5975a2e | 2013-04-27 00:28:37 +0000 | [diff] [blame] | 479 | extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev, |
| 480 | struct kvm_vcpu *vcpu, u32 cpu); |
Suresh Warrier | 0c2a660 | 2015-12-17 14:59:09 -0600 | [diff] [blame] | 481 | extern void kvmppc_xics_ipi_action(void); |
Paul Mackerras | 5d37519 | 2016-08-19 15:35:56 +1000 | [diff] [blame^] | 482 | extern void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 483 | unsigned long host_irq); |
| 484 | extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 485 | unsigned long host_irq); |
Suresh Warrier | e3c13e5 | 2016-08-19 15:35:51 +1000 | [diff] [blame] | 486 | extern 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. Warrier | 520fe9c | 2015-12-21 16:33:57 -0600 | [diff] [blame] | 489 | extern int h_ipi_redirect; |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 490 | #else |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 491 | static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap( |
| 492 | struct kvm *kvm) |
| 493 | { return NULL; } |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 494 | static inline void kvmppc_alloc_host_rm_ops(void) {}; |
| 495 | static inline void kvmppc_free_host_rm_ops(void) {}; |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 496 | static inline void kvmppc_free_pimap(struct kvm *kvm) {}; |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 497 | static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall) |
| 498 | { return 0; } |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 499 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
| 500 | { return 0; } |
| 501 | static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { } |
| 502 | static inline int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, |
| 503 | unsigned long server) |
| 504 | { return -EINVAL; } |
| 505 | static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm, |
| 506 | struct kvm_irq_level *args) |
| 507 | { return -ENOTTY; } |
| 508 | static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd) |
| 509 | { return 0; } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 510 | #endif |
| 511 | |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 512 | /* |
| 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 | |
| 518 | union kvmppc_rm_state { |
| 519 | unsigned long raw; |
| 520 | struct { |
| 521 | u32 in_host; |
| 522 | u32 rm_action; |
| 523 | }; |
| 524 | }; |
| 525 | |
| 526 | struct kvmppc_host_rm_core { |
| 527 | union kvmppc_rm_state rm_state; |
| 528 | void *rm_data; |
| 529 | char pad[112]; |
| 530 | }; |
| 531 | |
| 532 | struct kvmppc_host_rm_ops { |
| 533 | struct kvmppc_host_rm_core *rm_core; |
| 534 | void (*vcpu_kick)(struct kvm_vcpu *vcpu); |
| 535 | }; |
| 536 | |
| 537 | extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv; |
| 538 | |
Bharat Bhushan | 34f754b | 2014-07-17 17:01:40 +0530 | [diff] [blame] | 539 | static 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 Graf | 1c81063 | 2013-01-04 18:12:48 +0100 | [diff] [blame] | 550 | static 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 Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 559 | #ifdef CONFIG_KVM_MPIC |
| 560 | |
| 561 | void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu); |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 562 | int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu, |
| 563 | u32 cpu); |
| 564 | void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu); |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 565 | |
| 566 | #else |
| 567 | |
| 568 | static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu) |
| 569 | { |
| 570 | } |
| 571 | |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 572 | static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, |
| 573 | struct kvm_vcpu *vcpu, u32 cpu) |
| 574 | { |
| 575 | return -EINVAL; |
| 576 | } |
| 577 | |
| 578 | static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, |
| 579 | struct kvm_vcpu *vcpu) |
| 580 | { |
| 581 | } |
| 582 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 583 | #endif /* CONFIG_KVM_MPIC */ |
| 584 | |
Scott Wood | dc83b8b | 2011-08-18 15:25:21 -0500 | [diff] [blame] | 585 | int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, |
| 586 | struct kvm_config_tlb *cfg); |
| 587 | int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu, |
| 588 | struct kvm_dirty_tlb *cfg); |
| 589 | |
Scott Wood | 043cc4d | 2011-12-20 15:34:20 +0000 | [diff] [blame] | 590 | long kvmppc_alloc_lpid(void); |
| 591 | void kvmppc_claim_lpid(long lpid); |
| 592 | void kvmppc_free_lpid(long lpid); |
| 593 | void kvmppc_init_lpid(unsigned long nr_lpids); |
| 594 | |
Dan Williams | ba049e9 | 2016-01-15 16:56:11 -0800 | [diff] [blame] | 595 | static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn) |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 596 | { |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 597 | struct page *page; |
Bharat Bhushan | adccf65 | 2013-04-25 06:33:57 +0000 | [diff] [blame] | 598 | /* |
| 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 Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 606 | 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 Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 613 | /* |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 614 | * 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 | */ |
| 617 | static 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 Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 630 | #define SPRNG_WRAPPER_GET(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 631 | static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
| 632 | { \ |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 633 | return mfspr(bookehv_spr); \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 634 | } \ |
| 635 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 636 | #define SPRNG_WRAPPER_SET(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 637 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \ |
| 638 | { \ |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 639 | mtspr(bookehv_spr, val); \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 640 | } \ |
| 641 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 642 | #define SHARED_WRAPPER_GET(reg, size) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 643 | static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 644 | { \ |
| 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) \ |
| 652 | static 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 Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 664 | #define SPRNG_WRAPPER(reg, bookehv_spr) \ |
| 665 | SPRNG_WRAPPER_GET(reg, bookehv_spr) \ |
| 666 | SPRNG_WRAPPER_SET(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 667 | |
| 668 | #ifdef CONFIG_KVM_BOOKE_HV |
| 669 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 670 | #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ |
| 671 | SPRNG_WRAPPER(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 672 | |
| 673 | #else |
| 674 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 675 | #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 676 | SHARED_WRAPPER(reg, size) \ |
| 677 | |
| 678 | #endif |
| 679 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 680 | SHARED_WRAPPER(critical, 64) |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 681 | SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0) |
| 682 | SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1) |
| 683 | SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2) |
| 684 | SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3) |
| 685 | SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0) |
| 686 | SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1) |
| 687 | SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR) |
Bharat Bhushan | dc16854 | 2014-07-17 17:01:38 +0530 | [diff] [blame] | 688 | SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR) |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 689 | SHARED_WRAPPER_GET(msr, 64) |
| 690 | static 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 | } |
| 697 | SHARED_WRAPPER(dsisr, 32) |
| 698 | SHARED_WRAPPER(int_pending, 32) |
| 699 | SHARED_WRAPPER(sprg4, 64) |
| 700 | SHARED_WRAPPER(sprg5, 64) |
| 701 | SHARED_WRAPPER(sprg6, 64) |
| 702 | SHARED_WRAPPER(sprg7, 64) |
| 703 | |
| 704 | static 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 | |
| 712 | static 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 Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 721 | * 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 | */ |
| 725 | static inline void kvmppc_fix_ee_before_entry(void) |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 726 | { |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 727 | trace_hardirqs_on(); |
| 728 | |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 729 | #ifdef CONFIG_PPC64 |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 730 | /* |
| 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 Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 736 | /* 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 Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 741 | |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 742 | static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb) |
| 743 | { |
| 744 | ulong ea; |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 745 | ulong msr_64bit = 0; |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 746 | |
| 747 | ea = kvmppc_get_gpr(vcpu, rb); |
| 748 | if (ra) |
| 749 | ea += kvmppc_get_gpr(vcpu, ra); |
| 750 | |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 751 | #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 Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 757 | if (!(kvmppc_get_msr(vcpu) & msr_64bit)) |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 758 | ea = (uint32_t)ea; |
| 759 | |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 760 | return ea; |
| 761 | } |
| 762 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 763 | extern void xics_wake_cpu(int cpu); |
| 764 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 765 | #endif /* __POWERPC_KVM_PPC_H__ */ |