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 | |
Simon Guo | 7092360 | 2018-05-21 13:24:21 +0800 | [diff] [blame] | 55 | enum instruction_fetch_type { |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 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); |
Bin Lu | 6f63e81 | 2017-02-21 21:12:36 +0800 | [diff] [blame] | 81 | extern int kvmppc_handle_vsx_load(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 82 | unsigned int rt, unsigned int bytes, |
| 83 | int is_default_endian, int mmio_sign_extend); |
Jose Ricardo Ziviani | 09f9849 | 2018-02-03 18:24:26 -0200 | [diff] [blame] | 84 | extern int kvmppc_handle_load128_by2x64(struct kvm_run *run, |
| 85 | struct kvm_vcpu *vcpu, unsigned int rt, int is_default_endian); |
| 86 | extern int kvmppc_handle_store128_by2x64(struct kvm_run *run, |
| 87 | struct kvm_vcpu *vcpu, unsigned int rs, int is_default_endian); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 88 | 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] | 89 | u64 val, unsigned int bytes, |
| 90 | int is_default_endian); |
Bin Lu | 6f63e81 | 2017-02-21 21:12:36 +0800 | [diff] [blame] | 91 | extern int kvmppc_handle_vsx_store(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 92 | int rs, unsigned int bytes, |
| 93 | int is_default_endian); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 94 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 95 | extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, |
Simon Guo | 7092360 | 2018-05-21 13:24:21 +0800 | [diff] [blame] | 96 | enum instruction_fetch_type type, u32 *inst); |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 97 | |
Alexander Graf | 35c4a73 | 2014-06-20 13:58:16 +0200 | [diff] [blame] | 98 | extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
| 99 | bool data); |
| 100 | extern int kvmppc_st(struct kvm_vcpu *vcpu, ulong *eaddr, int size, void *ptr, |
| 101 | bool data); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 102 | extern int kvmppc_emulate_instruction(struct kvm_run *run, |
| 103 | struct kvm_vcpu *vcpu); |
Alexander Graf | d69614a | 2014-06-18 14:53:49 +0200 | [diff] [blame] | 104 | extern int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu); |
Hollis Blanchard | ce263d7 | 2008-05-21 18:22:51 -0500 | [diff] [blame] | 105 | 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] | 106 | extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 107 | extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); |
Mihai Caraman | d02d4d1 | 2014-09-01 17:19:56 +0300 | [diff] [blame] | 108 | extern void kvmppc_decrementer_func(struct kvm_vcpu *vcpu); |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 109 | extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 110 | extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu); |
| 111 | extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 112 | |
Hollis Blanchard | ecc0981 | 2009-01-03 16:22:59 -0600 | [diff] [blame] | 113 | /* Core-specific hooks */ |
| 114 | |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 115 | 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] | 116 | unsigned int gtlb_idx); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 117 | extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode); |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 118 | extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid); |
Hollis Blanchard | ecc0981 | 2009-01-03 16:22:59 -0600 | [diff] [blame] | 119 | extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu); |
Alexander Graf | 9cc5e95 | 2010-04-16 00:11:45 +0200 | [diff] [blame] | 120 | extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu); |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 121 | extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr); |
| 122 | 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] | 123 | extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index, |
| 124 | gva_t eaddr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 125 | extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu); |
| 126 | extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu); |
Alexander Graf | 7d15c06f | 2014-06-20 13:52:36 +0200 | [diff] [blame] | 127 | extern int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, |
| 128 | enum xlate_instdata xlid, enum xlate_readwrite xlrw, |
| 129 | struct kvmppc_pte *pte); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 130 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 131 | extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, |
| 132 | unsigned int id); |
| 133 | extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 134 | extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 135 | extern int kvmppc_core_check_processor_compat(void); |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 136 | extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, |
| 137 | struct kvm_translation *tr); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 138 | |
| 139 | extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu); |
| 140 | extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu); |
| 141 | |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 142 | extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 143 | extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu); |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 144 | extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags); |
Paul Mackerras | 307d927 | 2017-03-22 21:02:08 +1100 | [diff] [blame] | 145 | extern void kvmppc_core_queue_fpunavail(struct kvm_vcpu *vcpu); |
| 146 | extern void kvmppc_core_queue_vec_unavail(struct kvm_vcpu *vcpu); |
| 147 | extern void kvmppc_core_queue_vsx_unavail(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 148 | extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu); |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 149 | extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 150 | extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 151 | struct kvm_interrupt *irq); |
Paul Mackerras | 4fe27d2 | 2013-02-14 14:00:25 +0000 | [diff] [blame] | 152 | extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu); |
Alexander Graf | 8de1201 | 2014-06-18 21:56:55 +0200 | [diff] [blame] | 153 | extern void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, ulong dear_flags, |
| 154 | ulong esr_flags); |
| 155 | extern void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 156 | ulong dear_flags, |
| 157 | ulong esr_flags); |
| 158 | extern void kvmppc_core_queue_itlb_miss(struct kvm_vcpu *vcpu); |
| 159 | extern void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, |
| 160 | ulong esr_flags); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 161 | extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu); |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 162 | extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 163 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 164 | extern int kvmppc_booke_init(void); |
| 165 | extern void kvmppc_booke_exit(void); |
| 166 | |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame] | 167 | extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu); |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 168 | extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu); |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 169 | extern void kvmppc_map_magic(struct kvm_vcpu *vcpu); |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame] | 170 | |
David Gibson | aae0777 | 2016-12-20 16:49:02 +1100 | [diff] [blame] | 171 | extern int kvmppc_allocate_hpt(struct kvm_hpt_info *info, u32 order); |
| 172 | extern void kvmppc_set_hpt(struct kvm *kvm, struct kvm_hpt_info *info); |
David Gibson | f98a8bf | 2016-12-20 16:49:03 +1100 | [diff] [blame] | 173 | extern long kvmppc_alloc_reset_hpt(struct kvm *kvm, int order); |
David Gibson | aae0777 | 2016-12-20 16:49:02 +1100 | [diff] [blame] | 174 | extern void kvmppc_free_hpt(struct kvm_hpt_info *info); |
Paul Mackerras | 18c3640 | 2017-09-13 16:00:10 +1000 | [diff] [blame] | 175 | extern void kvmppc_rmap_reset(struct kvm *kvm); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 176 | extern long kvmppc_prepare_vrma(struct kvm *kvm, |
| 177 | struct kvm_userspace_memory_region *mem); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 178 | extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu, |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 179 | struct kvm_memory_slot *memslot, unsigned long porder); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 180 | extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); |
Alexey Kardashevskiy | 121f80b | 2017-03-22 15:21:56 +1100 | [diff] [blame] | 181 | extern long kvm_spapr_tce_attach_iommu_group(struct kvm *kvm, int tablefd, |
| 182 | struct iommu_group *grp); |
| 183 | extern void kvm_spapr_tce_release_iommu_group(struct kvm *kvm, |
| 184 | struct iommu_group *grp); |
Paul Mackerras | 18c3640 | 2017-09-13 16:00:10 +1000 | [diff] [blame] | 185 | extern int kvmppc_switch_mmu_to_hpt(struct kvm *kvm); |
| 186 | extern int kvmppc_switch_mmu_to_radix(struct kvm *kvm); |
Paul Mackerras | ded13fc | 2017-11-22 14:38:53 +1100 | [diff] [blame] | 187 | extern void kvmppc_setup_partition_table(struct kvm *kvm); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 188 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 189 | extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, |
Alexey Kardashevskiy | 58ded42 | 2016-03-01 17:54:40 +1100 | [diff] [blame] | 190 | struct kvm_create_spapr_tce_64 *args); |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 191 | extern struct kvmppc_spapr_tce_table *kvmppc_find_table( |
Alexey Kardashevskiy | 503bfcb | 2017-03-22 15:21:53 +1100 | [diff] [blame] | 192 | struct kvm *kvm, unsigned long liobn); |
Alexey Kardashevskiy | b1af23d | 2017-03-22 15:21:55 +1100 | [diff] [blame] | 193 | #define kvmppc_ioba_validate(stt, ioba, npages) \ |
| 194 | (iommu_tce_check_ioba((stt)->page_shift, (stt)->offset, \ |
| 195 | (stt)->size, (ioba), (npages)) ? \ |
| 196 | H_PARAMETER : H_SUCCESS) |
Alexey Kardashevskiy | 5ee7af1 | 2016-02-15 12:55:08 +1100 | [diff] [blame] | 197 | extern long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *tt, |
| 198 | unsigned long tce); |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 199 | extern long kvmppc_gpa_to_ua(struct kvm *kvm, unsigned long gpa, |
| 200 | unsigned long *ua, unsigned long **prmap); |
| 201 | extern void kvmppc_tce_put(struct kvmppc_spapr_tce_table *tt, |
| 202 | unsigned long idx, unsigned long tce); |
Benjamin Herrenschmidt | f31e65e | 2012-03-15 21:58:34 +0000 | [diff] [blame] | 203 | extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 204 | unsigned long ioba, unsigned long tce); |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 205 | extern long kvmppc_h_put_tce_indirect(struct kvm_vcpu *vcpu, |
| 206 | unsigned long liobn, unsigned long ioba, |
| 207 | unsigned long tce_list, unsigned long npages); |
| 208 | extern long kvmppc_h_stuff_tce(struct kvm_vcpu *vcpu, |
| 209 | unsigned long liobn, unsigned long ioba, |
| 210 | unsigned long tce_value, unsigned long npages); |
Laurent Dufour | 69e9fbb2 | 2014-02-21 16:31:10 +0100 | [diff] [blame] | 211 | extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 212 | unsigned long ioba); |
David Gibson | db9a290 | 2016-12-20 16:48:59 +1100 | [diff] [blame] | 213 | extern struct page *kvm_alloc_hpt_cma(unsigned long nr_pages); |
| 214 | extern void kvm_free_hpt_cma(struct page *page, unsigned long nr_pages); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 215 | extern int kvmppc_core_init_vm(struct kvm *kvm); |
| 216 | extern void kvmppc_core_destroy_vm(struct kvm *kvm); |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 217 | extern void kvmppc_core_free_memslot(struct kvm *kvm, |
| 218 | struct kvm_memory_slot *free, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 219 | struct kvm_memory_slot *dont); |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 220 | extern int kvmppc_core_create_memslot(struct kvm *kvm, |
| 221 | struct kvm_memory_slot *slot, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 222 | unsigned long npages); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 223 | extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 224 | struct kvm_memory_slot *memslot, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 225 | const struct kvm_userspace_memory_region *mem); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 226 | extern void kvmppc_core_commit_memory_region(struct kvm *kvm, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 227 | const struct kvm_userspace_memory_region *mem, |
Paolo Bonzini | f36f3f2 | 2015-05-18 13:20:23 +0200 | [diff] [blame] | 228 | const struct kvm_memory_slot *old, |
| 229 | const struct kvm_memory_slot *new); |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 230 | extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, |
| 231 | struct kvm_ppc_smmu_info *info); |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 232 | extern void kvmppc_core_flush_memslot(struct kvm *kvm, |
| 233 | struct kvm_memory_slot *memslot); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 234 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 235 | extern int kvmppc_bookehv_init(void); |
| 236 | extern void kvmppc_bookehv_exit(void); |
| 237 | |
Alexander Graf | 03d25c5 | 2012-08-10 12:28:50 +0200 | [diff] [blame] | 238 | extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu); |
| 239 | |
Paul Mackerras | a293292 | 2012-11-19 22:57:20 +0000 | [diff] [blame] | 240 | extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *); |
David Gibson | 5e98596 | 2016-12-20 16:49:05 +1100 | [diff] [blame] | 241 | extern long kvm_vm_ioctl_resize_hpt_prepare(struct kvm *kvm, |
| 242 | struct kvm_ppc_resize_hpt *rhpt); |
| 243 | extern long kvm_vm_ioctl_resize_hpt_commit(struct kvm *kvm, |
| 244 | struct kvm_ppc_resize_hpt *rhpt); |
Paul Mackerras | a293292 | 2012-11-19 22:57:20 +0000 | [diff] [blame] | 245 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 246 | int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq); |
| 247 | |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 248 | extern int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp); |
| 249 | extern int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu); |
| 250 | extern void kvmppc_rtas_tokens_free(struct kvm *kvm); |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 251 | |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 252 | extern int kvmppc_xics_set_xive(struct kvm *kvm, u32 irq, u32 server, |
| 253 | u32 priority); |
| 254 | extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server, |
| 255 | u32 *priority); |
Paul Mackerras | d19bd862 | 2013-04-17 20:32:04 +0000 | [diff] [blame] | 256 | extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq); |
| 257 | extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq); |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 258 | |
Bharat Bhushan | 2f699a5 | 2014-08-13 14:39:44 +0530 | [diff] [blame] | 259 | void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu); |
| 260 | void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu); |
| 261 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 262 | union kvmppc_one_reg { |
| 263 | u32 wval; |
| 264 | u64 dval; |
| 265 | vector128 vval; |
| 266 | u64 vsxval[2]; |
Bin Lu | 6f63e81 | 2017-02-21 21:12:36 +0800 | [diff] [blame] | 267 | u32 vsx32val[4]; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 268 | struct { |
| 269 | u64 addr; |
| 270 | u64 length; |
| 271 | } vpaval; |
| 272 | }; |
| 273 | |
| 274 | struct kvmppc_ops { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 275 | struct module *owner; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 276 | int (*get_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 277 | int (*set_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 278 | int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id, |
| 279 | union kvmppc_one_reg *val); |
| 280 | int (*set_one_reg)(struct kvm_vcpu *vcpu, u64 id, |
| 281 | union kvmppc_one_reg *val); |
| 282 | void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu); |
| 283 | void (*vcpu_put)(struct kvm_vcpu *vcpu); |
| 284 | void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr); |
| 285 | int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu); |
| 286 | struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id); |
| 287 | void (*vcpu_free)(struct kvm_vcpu *vcpu); |
| 288 | int (*check_requests)(struct kvm_vcpu *vcpu); |
| 289 | int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log); |
| 290 | void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot); |
| 291 | int (*prepare_memory_region)(struct kvm *kvm, |
| 292 | struct kvm_memory_slot *memslot, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 293 | const struct kvm_userspace_memory_region *mem); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 294 | void (*commit_memory_region)(struct kvm *kvm, |
Paolo Bonzini | 09170a4 | 2015-05-18 13:59:39 +0200 | [diff] [blame] | 295 | const struct kvm_userspace_memory_region *mem, |
Paolo Bonzini | f36f3f2 | 2015-05-18 13:20:23 +0200 | [diff] [blame] | 296 | const struct kvm_memory_slot *old, |
| 297 | const struct kvm_memory_slot *new); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 298 | int (*unmap_hva_range)(struct kvm *kvm, unsigned long start, |
| 299 | unsigned long end); |
Andres Lagar-Cavilla | 5712846 | 2014-09-22 14:54:42 -0700 | [diff] [blame] | 300 | 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] | 301 | int (*test_age_hva)(struct kvm *kvm, unsigned long hva); |
| 302 | void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte); |
| 303 | void (*mmu_destroy)(struct kvm_vcpu *vcpu); |
| 304 | void (*free_memslot)(struct kvm_memory_slot *free, |
| 305 | struct kvm_memory_slot *dont); |
| 306 | int (*create_memslot)(struct kvm_memory_slot *slot, |
| 307 | unsigned long npages); |
| 308 | int (*init_vm)(struct kvm *kvm); |
| 309 | void (*destroy_vm)(struct kvm *kvm); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 310 | int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info); |
| 311 | int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 312 | unsigned int inst, int *advance); |
| 313 | int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val); |
| 314 | int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val); |
| 315 | void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu); |
| 316 | long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl, |
| 317 | unsigned long arg); |
Paul Mackerras | ae2113a | 2014-06-02 11:03:00 +1000 | [diff] [blame] | 318 | int (*hcall_implemented)(unsigned long hcall); |
Suresh Warrier | 9576730 | 2016-08-19 15:35:47 +1000 | [diff] [blame] | 319 | int (*irq_bypass_add_producer)(struct irq_bypass_consumer *, |
| 320 | struct irq_bypass_producer *); |
| 321 | void (*irq_bypass_del_producer)(struct irq_bypass_consumer *, |
| 322 | struct irq_bypass_producer *); |
Paul Mackerras | c927013 | 2017-01-30 21:21:41 +1100 | [diff] [blame] | 323 | int (*configure_mmu)(struct kvm *kvm, struct kvm_ppc_mmuv3_cfg *cfg); |
| 324 | int (*get_rmmu_info)(struct kvm *kvm, struct kvm_ppc_rmmu_info *info); |
Paul Mackerras | 3c31352 | 2017-02-06 13:24:41 +1100 | [diff] [blame] | 325 | int (*set_smt_mode)(struct kvm *kvm, unsigned long mode, |
| 326 | unsigned long flags); |
Simon Guo | 2e6baa4 | 2018-05-21 13:24:22 +0800 | [diff] [blame^] | 327 | void (*giveup_ext)(struct kvm_vcpu *vcpu, ulong msr); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 328 | }; |
| 329 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 330 | extern struct kvmppc_ops *kvmppc_hv_ops; |
| 331 | extern struct kvmppc_ops *kvmppc_pr_ops; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 332 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 333 | static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu, |
Simon Guo | 7092360 | 2018-05-21 13:24:21 +0800 | [diff] [blame] | 334 | enum instruction_fetch_type type, u32 *inst) |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame] | 335 | { |
| 336 | int ret = EMULATE_DONE; |
| 337 | u32 fetched_inst; |
| 338 | |
| 339 | /* Load the instruction manually if it failed to do so in the |
| 340 | * exit path */ |
| 341 | if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) |
| 342 | ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst); |
| 343 | |
| 344 | /* Write fetch_failed unswapped if the fetch failed */ |
| 345 | if (ret == EMULATE_DONE) |
| 346 | fetched_inst = kvmppc_need_byteswap(vcpu) ? |
| 347 | swab32(vcpu->arch.last_inst) : |
| 348 | vcpu->arch.last_inst; |
| 349 | else |
| 350 | fetched_inst = vcpu->arch.last_inst; |
| 351 | |
| 352 | *inst = fetched_inst; |
| 353 | return ret; |
| 354 | } |
| 355 | |
Aneesh Kumar K.V | a78b55d | 2013-10-07 22:18:02 +0530 | [diff] [blame] | 356 | static inline bool is_kvmppc_hv_enabled(struct kvm *kvm) |
| 357 | { |
| 358 | return kvm->arch.kvm_ops == kvmppc_hv_ops; |
| 359 | } |
| 360 | |
Michael Ellerman | e928e9c | 2015-03-20 20:39:41 +1100 | [diff] [blame] | 361 | extern int kvmppc_hwrng_present(void); |
| 362 | |
Alexander Graf | 0564ee8 | 2010-02-19 11:00:42 +0100 | [diff] [blame] | 363 | /* |
| 364 | * Cuts out inst bits with ordering according to spec. |
| 365 | * That means the leftmost bit is zero. All given bits are included. |
| 366 | */ |
| 367 | static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb) |
| 368 | { |
| 369 | u32 r; |
| 370 | u32 mask; |
| 371 | |
| 372 | BUG_ON(msb > lsb); |
| 373 | |
| 374 | mask = (1 << (lsb - msb + 1)) - 1; |
| 375 | r = (inst >> (63 - lsb)) & mask; |
| 376 | |
| 377 | return r; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Replaces inst bits with ordering according to spec. |
| 382 | */ |
| 383 | static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value) |
| 384 | { |
| 385 | u32 r; |
| 386 | u32 mask; |
| 387 | |
| 388 | BUG_ON(msb > lsb); |
| 389 | |
| 390 | mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb); |
| 391 | r = (inst & ~mask) | ((value << (63 - lsb)) & mask); |
| 392 | |
| 393 | return r; |
| 394 | } |
| 395 | |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 396 | #define one_reg_size(id) \ |
| 397 | (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) |
| 398 | |
| 399 | #define get_reg_val(id, reg) ({ \ |
| 400 | union kvmppc_one_reg __u; \ |
| 401 | switch (one_reg_size(id)) { \ |
| 402 | case 4: __u.wval = (reg); break; \ |
| 403 | case 8: __u.dval = (reg); break; \ |
| 404 | default: BUG(); \ |
| 405 | } \ |
| 406 | __u; \ |
| 407 | }) |
| 408 | |
| 409 | |
| 410 | #define set_reg_val(id, val) ({ \ |
| 411 | u64 __v; \ |
| 412 | switch (one_reg_size(id)) { \ |
| 413 | case 4: __v = (val).wval; break; \ |
| 414 | case 8: __v = (val).dval; break; \ |
| 415 | default: BUG(); \ |
| 416 | } \ |
| 417 | __v; \ |
| 418 | }) |
| 419 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 420 | 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] | 421 | int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 422 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 423 | 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] | 424 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 425 | |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 426 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); |
| 427 | 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] | 428 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *); |
| 429 | 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] | 430 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 431 | void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid); |
| 432 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 433 | struct openpic; |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 434 | |
Aneesh Kumar K.V | 9975f5e | 2013-10-07 22:17:52 +0530 | [diff] [blame] | 435 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 436 | extern void kvm_cma_reserve(void) __init; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 437 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
| 438 | { |
Nicholas Piggin | d2e6007 | 2018-02-14 01:08:12 +1000 | [diff] [blame] | 439 | paca_ptrs[cpu]->kvm_hstate.xics_phys = (void __iomem *)addr; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 440 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 441 | |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 442 | static inline void kvmppc_set_xive_tima(int cpu, |
| 443 | unsigned long phys_addr, |
| 444 | void __iomem *virt_addr) |
| 445 | { |
Nicholas Piggin | d2e6007 | 2018-02-14 01:08:12 +1000 | [diff] [blame] | 446 | paca_ptrs[cpu]->kvm_hstate.xive_tima_phys = (void __iomem *)phys_addr; |
| 447 | paca_ptrs[cpu]->kvm_hstate.xive_tima_virt = virt_addr; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 448 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 449 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 450 | static inline u32 kvmppc_get_xics_latch(void) |
| 451 | { |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 452 | u32 xirr; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 453 | |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 454 | xirr = get_paca()->kvm_hstate.saved_xirr; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 455 | get_paca()->kvm_hstate.saved_xirr = 0; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 456 | return xirr; |
| 457 | } |
| 458 | |
| 459 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) |
| 460 | { |
Nicholas Piggin | d2e6007 | 2018-02-14 01:08:12 +1000 | [diff] [blame] | 461 | paca_ptrs[cpu]->kvm_hstate.host_ipi = host_ipi; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 464 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
| 465 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 466 | vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 467 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 468 | |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 469 | extern void kvm_hv_vm_activated(void); |
| 470 | extern void kvm_hv_vm_deactivated(void); |
| 471 | extern bool kvm_hv_mode_active(void); |
| 472 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 473 | #else |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 474 | static inline void __init kvm_cma_reserve(void) |
| 475 | {} |
| 476 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 477 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
| 478 | {} |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 479 | |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 480 | static inline void kvmppc_set_xive_tima(int cpu, |
| 481 | unsigned long phys_addr, |
| 482 | void __iomem *virt_addr) |
| 483 | {} |
| 484 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 485 | static inline u32 kvmppc_get_xics_latch(void) |
| 486 | { |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) |
| 491 | {} |
| 492 | |
| 493 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
| 494 | { |
| 495 | kvm_vcpu_kick(vcpu); |
| 496 | } |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 497 | |
| 498 | static inline bool kvm_hv_mode_active(void) { return false; } |
| 499 | |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 500 | #endif |
| 501 | |
| 502 | #ifdef CONFIG_KVM_XICS |
| 503 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
| 504 | { |
| 505 | return vcpu->arch.irq_type == KVMPPC_IRQ_XICS; |
| 506 | } |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 507 | |
| 508 | static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap( |
| 509 | struct kvm *kvm) |
| 510 | { |
Suresh Warrier | 644abbb | 2016-08-19 15:35:54 +1000 | [diff] [blame] | 511 | if (kvm && kvm_irq_bypass) |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 512 | return kvm->arch.pimap; |
| 513 | return NULL; |
| 514 | } |
| 515 | |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 516 | extern void kvmppc_alloc_host_rm_ops(void); |
| 517 | extern void kvmppc_free_host_rm_ops(void); |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 518 | extern void kvmppc_free_pimap(struct kvm *kvm); |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 519 | extern int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 520 | extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 521 | extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd); |
Paul Mackerras | 8b78645 | 2013-04-17 20:32:26 +0000 | [diff] [blame] | 522 | extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu); |
| 523 | extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval); |
Paul Mackerras | 5975a2e | 2013-04-27 00:28:37 +0000 | [diff] [blame] | 524 | extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev, |
| 525 | struct kvm_vcpu *vcpu, u32 cpu); |
Suresh Warrier | 0c2a660 | 2015-12-17 14:59:09 -0600 | [diff] [blame] | 526 | extern void kvmppc_xics_ipi_action(void); |
Paul Mackerras | 5d37519 | 2016-08-19 15:35:56 +1000 | [diff] [blame] | 527 | extern void kvmppc_xics_set_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 528 | unsigned long host_irq); |
| 529 | extern void kvmppc_xics_clr_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 530 | unsigned long host_irq); |
Paul Mackerras | f725758 | 2016-11-18 09:02:08 +1100 | [diff] [blame] | 531 | extern long kvmppc_deliver_irq_passthru(struct kvm_vcpu *vcpu, __be32 xirr, |
| 532 | struct kvmppc_irq_map *irq_map, |
| 533 | struct kvmppc_passthru_irqmap *pimap, |
| 534 | bool *again); |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 535 | |
| 536 | extern int kvmppc_xics_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, |
| 537 | int level, bool line_status); |
| 538 | |
Suresh E. Warrier | 520fe9c | 2015-12-21 16:33:57 -0600 | [diff] [blame] | 539 | extern int h_ipi_redirect; |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 540 | #else |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 541 | static inline struct kvmppc_passthru_irqmap *kvmppc_get_passthru_irqmap( |
| 542 | struct kvm *kvm) |
| 543 | { return NULL; } |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 544 | static inline void kvmppc_alloc_host_rm_ops(void) {}; |
| 545 | static inline void kvmppc_free_host_rm_ops(void) {}; |
Suresh Warrier | 8daaafc | 2016-08-19 15:35:48 +1000 | [diff] [blame] | 546 | static inline void kvmppc_free_pimap(struct kvm *kvm) {}; |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 547 | static inline int kvmppc_xics_rm_complete(struct kvm_vcpu *vcpu, u32 hcall) |
| 548 | { return 0; } |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 549 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
| 550 | { return 0; } |
| 551 | static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { } |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 552 | static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd) |
| 553 | { return 0; } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 554 | #endif |
| 555 | |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 556 | #ifdef CONFIG_KVM_XIVE |
| 557 | /* |
| 558 | * Below the first "xive" is the "eXternal Interrupt Virtualization Engine" |
| 559 | * ie. P9 new interrupt controller, while the second "xive" is the legacy |
| 560 | * "eXternal Interrupt Vector Entry" which is the configuration of an |
| 561 | * interrupt on the "xics" interrupt controller on P8 and earlier. Those |
| 562 | * two function consume or produce a legacy "XIVE" state from the |
| 563 | * new "XIVE" interrupt controller. |
| 564 | */ |
| 565 | extern int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server, |
| 566 | u32 priority); |
| 567 | extern int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, |
| 568 | u32 *priority); |
| 569 | extern int kvmppc_xive_int_on(struct kvm *kvm, u32 irq); |
| 570 | extern int kvmppc_xive_int_off(struct kvm *kvm, u32 irq); |
| 571 | extern void kvmppc_xive_init_module(void); |
| 572 | extern void kvmppc_xive_exit_module(void); |
| 573 | |
| 574 | extern int kvmppc_xive_connect_vcpu(struct kvm_device *dev, |
| 575 | struct kvm_vcpu *vcpu, u32 cpu); |
| 576 | extern void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu); |
| 577 | extern int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 578 | struct irq_desc *host_desc); |
| 579 | extern int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 580 | struct irq_desc *host_desc); |
| 581 | extern u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu); |
| 582 | extern int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval); |
| 583 | |
| 584 | extern int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, |
| 585 | int level, bool line_status); |
| 586 | #else |
| 587 | static inline int kvmppc_xive_set_xive(struct kvm *kvm, u32 irq, u32 server, |
| 588 | u32 priority) { return -1; } |
| 589 | static inline int kvmppc_xive_get_xive(struct kvm *kvm, u32 irq, u32 *server, |
| 590 | u32 *priority) { return -1; } |
| 591 | static inline int kvmppc_xive_int_on(struct kvm *kvm, u32 irq) { return -1; } |
| 592 | static inline int kvmppc_xive_int_off(struct kvm *kvm, u32 irq) { return -1; } |
| 593 | static inline void kvmppc_xive_init_module(void) { } |
| 594 | static inline void kvmppc_xive_exit_module(void) { } |
| 595 | |
| 596 | static inline int kvmppc_xive_connect_vcpu(struct kvm_device *dev, |
| 597 | struct kvm_vcpu *vcpu, u32 cpu) { return -EBUSY; } |
| 598 | static inline void kvmppc_xive_cleanup_vcpu(struct kvm_vcpu *vcpu) { } |
| 599 | static inline int kvmppc_xive_set_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 600 | struct irq_desc *host_desc) { return -ENODEV; } |
| 601 | static inline int kvmppc_xive_clr_mapped(struct kvm *kvm, unsigned long guest_irq, |
| 602 | struct irq_desc *host_desc) { return -ENODEV; } |
| 603 | static inline u64 kvmppc_xive_get_icp(struct kvm_vcpu *vcpu) { return 0; } |
| 604 | static inline int kvmppc_xive_set_icp(struct kvm_vcpu *vcpu, u64 icpval) { return -ENOENT; } |
| 605 | |
| 606 | static inline int kvmppc_xive_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, |
| 607 | int level, bool line_status) { return -ENODEV; } |
| 608 | #endif /* CONFIG_KVM_XIVE */ |
| 609 | |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 610 | /* |
Paul Mackerras | e34af78 | 2016-12-01 14:03:46 +1100 | [diff] [blame] | 611 | * Prototypes for functions called only from assembler code. |
| 612 | * Having prototypes reduces sparse errors. |
| 613 | */ |
| 614 | long kvmppc_rm_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 615 | unsigned long ioba, unsigned long tce); |
| 616 | long kvmppc_rm_h_put_tce_indirect(struct kvm_vcpu *vcpu, |
| 617 | unsigned long liobn, unsigned long ioba, |
| 618 | unsigned long tce_list, unsigned long npages); |
| 619 | long kvmppc_rm_h_stuff_tce(struct kvm_vcpu *vcpu, |
| 620 | unsigned long liobn, unsigned long ioba, |
| 621 | unsigned long tce_value, unsigned long npages); |
| 622 | long int kvmppc_rm_h_confer(struct kvm_vcpu *vcpu, int target, |
| 623 | unsigned int yield_count); |
| 624 | long kvmppc_h_random(struct kvm_vcpu *vcpu); |
| 625 | void kvmhv_commence_exit(int trap); |
| 626 | long kvmppc_realmode_machine_check(struct kvm_vcpu *vcpu); |
| 627 | void kvmppc_subcore_enter_guest(void); |
| 628 | void kvmppc_subcore_exit_guest(void); |
| 629 | long kvmppc_realmode_hmi_handler(void); |
| 630 | long kvmppc_h_enter(struct kvm_vcpu *vcpu, unsigned long flags, |
| 631 | long pte_index, unsigned long pteh, unsigned long ptel); |
| 632 | long kvmppc_h_remove(struct kvm_vcpu *vcpu, unsigned long flags, |
| 633 | unsigned long pte_index, unsigned long avpn); |
| 634 | long kvmppc_h_bulk_remove(struct kvm_vcpu *vcpu); |
| 635 | long kvmppc_h_protect(struct kvm_vcpu *vcpu, unsigned long flags, |
| 636 | unsigned long pte_index, unsigned long avpn, |
| 637 | unsigned long va); |
| 638 | long kvmppc_h_read(struct kvm_vcpu *vcpu, unsigned long flags, |
| 639 | unsigned long pte_index); |
| 640 | long kvmppc_h_clear_ref(struct kvm_vcpu *vcpu, unsigned long flags, |
| 641 | unsigned long pte_index); |
| 642 | long kvmppc_h_clear_mod(struct kvm_vcpu *vcpu, unsigned long flags, |
| 643 | unsigned long pte_index); |
| 644 | long kvmppc_hpte_hv_fault(struct kvm_vcpu *vcpu, unsigned long addr, |
| 645 | unsigned long slb_v, unsigned int status, bool data); |
| 646 | unsigned long kvmppc_rm_h_xirr(struct kvm_vcpu *vcpu); |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 647 | unsigned long kvmppc_rm_h_xirr_x(struct kvm_vcpu *vcpu); |
| 648 | unsigned long kvmppc_rm_h_ipoll(struct kvm_vcpu *vcpu, unsigned long server); |
Paul Mackerras | e34af78 | 2016-12-01 14:03:46 +1100 | [diff] [blame] | 649 | int kvmppc_rm_h_ipi(struct kvm_vcpu *vcpu, unsigned long server, |
| 650 | unsigned long mfrr); |
| 651 | int kvmppc_rm_h_cppr(struct kvm_vcpu *vcpu, unsigned long cppr); |
| 652 | int kvmppc_rm_h_eoi(struct kvm_vcpu *vcpu, unsigned long xirr); |
| 653 | |
| 654 | /* |
Suresh Warrier | 79b6c24 | 2015-12-17 14:59:06 -0600 | [diff] [blame] | 655 | * Host-side operations we want to set up while running in real |
| 656 | * mode in the guest operating on the xics. |
| 657 | * Currently only VCPU wakeup is supported. |
| 658 | */ |
| 659 | |
| 660 | union kvmppc_rm_state { |
| 661 | unsigned long raw; |
| 662 | struct { |
| 663 | u32 in_host; |
| 664 | u32 rm_action; |
| 665 | }; |
| 666 | }; |
| 667 | |
| 668 | struct kvmppc_host_rm_core { |
| 669 | union kvmppc_rm_state rm_state; |
| 670 | void *rm_data; |
| 671 | char pad[112]; |
| 672 | }; |
| 673 | |
| 674 | struct kvmppc_host_rm_ops { |
| 675 | struct kvmppc_host_rm_core *rm_core; |
| 676 | void (*vcpu_kick)(struct kvm_vcpu *vcpu); |
| 677 | }; |
| 678 | |
| 679 | extern struct kvmppc_host_rm_ops *kvmppc_host_rm_ops_hv; |
| 680 | |
Bharat Bhushan | 34f754b | 2014-07-17 17:01:40 +0530 | [diff] [blame] | 681 | static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu) |
| 682 | { |
| 683 | #ifdef CONFIG_KVM_BOOKE_HV |
| 684 | return mfspr(SPRN_GEPR); |
| 685 | #elif defined(CONFIG_BOOKE) |
| 686 | return vcpu->arch.epr; |
| 687 | #else |
| 688 | return 0; |
| 689 | #endif |
| 690 | } |
| 691 | |
Alexander Graf | 1c81063 | 2013-01-04 18:12:48 +0100 | [diff] [blame] | 692 | static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr) |
| 693 | { |
| 694 | #ifdef CONFIG_KVM_BOOKE_HV |
| 695 | mtspr(SPRN_GEPR, epr); |
| 696 | #elif defined(CONFIG_BOOKE) |
| 697 | vcpu->arch.epr = epr; |
| 698 | #endif |
| 699 | } |
| 700 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 701 | #ifdef CONFIG_KVM_MPIC |
| 702 | |
| 703 | void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu); |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 704 | int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu, |
| 705 | u32 cpu); |
| 706 | void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu); |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 707 | |
| 708 | #else |
| 709 | |
| 710 | static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu) |
| 711 | { |
| 712 | } |
| 713 | |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 714 | static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, |
| 715 | struct kvm_vcpu *vcpu, u32 cpu) |
| 716 | { |
| 717 | return -EINVAL; |
| 718 | } |
| 719 | |
| 720 | static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, |
| 721 | struct kvm_vcpu *vcpu) |
| 722 | { |
| 723 | } |
| 724 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 725 | #endif /* CONFIG_KVM_MPIC */ |
| 726 | |
Scott Wood | dc83b8b | 2011-08-18 15:25:21 -0500 | [diff] [blame] | 727 | int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, |
| 728 | struct kvm_config_tlb *cfg); |
| 729 | int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu, |
| 730 | struct kvm_dirty_tlb *cfg); |
| 731 | |
Scott Wood | 043cc4d | 2011-12-20 15:34:20 +0000 | [diff] [blame] | 732 | long kvmppc_alloc_lpid(void); |
| 733 | void kvmppc_claim_lpid(long lpid); |
| 734 | void kvmppc_free_lpid(long lpid); |
| 735 | void kvmppc_init_lpid(unsigned long nr_lpids); |
| 736 | |
Dan Williams | ba049e9 | 2016-01-15 16:56:11 -0800 | [diff] [blame] | 737 | static inline void kvmppc_mmu_flush_icache(kvm_pfn_t pfn) |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 738 | { |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 739 | struct page *page; |
Bharat Bhushan | adccf65 | 2013-04-25 06:33:57 +0000 | [diff] [blame] | 740 | /* |
| 741 | * We can only access pages that the kernel maps |
| 742 | * as memory. Bail out for unmapped ones. |
| 743 | */ |
| 744 | if (!pfn_valid(pfn)) |
| 745 | return; |
| 746 | |
| 747 | /* Clear i-cache for new pages */ |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 748 | page = pfn_to_page(pfn); |
| 749 | if (!test_bit(PG_arch_1, &page->flags)) { |
| 750 | flush_dcache_icache_page(page); |
| 751 | set_bit(PG_arch_1, &page->flags); |
| 752 | } |
| 753 | } |
| 754 | |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 755 | /* |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 756 | * Shared struct helpers. The shared struct can be little or big endian, |
| 757 | * depending on the guest endianness. So expose helpers to all of them. |
| 758 | */ |
| 759 | static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu) |
| 760 | { |
| 761 | #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE) |
| 762 | /* Only Book3S_64 PR supports bi-endian for now */ |
| 763 | return vcpu->arch.shared_big_endian; |
| 764 | #elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__) |
| 765 | /* Book3s_64 HV on little endian is always little endian */ |
| 766 | return false; |
| 767 | #else |
| 768 | return true; |
| 769 | #endif |
| 770 | } |
| 771 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 772 | #define SPRNG_WRAPPER_GET(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 773 | static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
| 774 | { \ |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 775 | return mfspr(bookehv_spr); \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 776 | } \ |
| 777 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 778 | #define SPRNG_WRAPPER_SET(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 779 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \ |
| 780 | { \ |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 781 | mtspr(bookehv_spr, val); \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 782 | } \ |
| 783 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 784 | #define SHARED_WRAPPER_GET(reg, size) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 785 | static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 786 | { \ |
| 787 | if (kvmppc_shared_big_endian(vcpu)) \ |
| 788 | return be##size##_to_cpu(vcpu->arch.shared->reg); \ |
| 789 | else \ |
| 790 | return le##size##_to_cpu(vcpu->arch.shared->reg); \ |
| 791 | } \ |
| 792 | |
| 793 | #define SHARED_WRAPPER_SET(reg, size) \ |
| 794 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ |
| 795 | { \ |
| 796 | if (kvmppc_shared_big_endian(vcpu)) \ |
| 797 | vcpu->arch.shared->reg = cpu_to_be##size(val); \ |
| 798 | else \ |
| 799 | vcpu->arch.shared->reg = cpu_to_le##size(val); \ |
| 800 | } \ |
| 801 | |
| 802 | #define SHARED_WRAPPER(reg, size) \ |
| 803 | SHARED_WRAPPER_GET(reg, size) \ |
| 804 | SHARED_WRAPPER_SET(reg, size) \ |
| 805 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 806 | #define SPRNG_WRAPPER(reg, bookehv_spr) \ |
| 807 | SPRNG_WRAPPER_GET(reg, bookehv_spr) \ |
| 808 | SPRNG_WRAPPER_SET(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 809 | |
| 810 | #ifdef CONFIG_KVM_BOOKE_HV |
| 811 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 812 | #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ |
| 813 | SPRNG_WRAPPER(reg, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 814 | |
| 815 | #else |
| 816 | |
Bharat Bhushan | 5a484c7 | 2014-07-30 15:03:56 +0530 | [diff] [blame] | 817 | #define SHARED_SPRNG_WRAPPER(reg, size, bookehv_spr) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 818 | SHARED_WRAPPER(reg, size) \ |
| 819 | |
| 820 | #endif |
| 821 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 822 | SHARED_WRAPPER(critical, 64) |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 823 | SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0) |
| 824 | SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1) |
| 825 | SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2) |
| 826 | SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3) |
| 827 | SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0) |
| 828 | SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1) |
| 829 | SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR) |
Bharat Bhushan | dc16854 | 2014-07-17 17:01:38 +0530 | [diff] [blame] | 830 | SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR) |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 831 | SHARED_WRAPPER_GET(msr, 64) |
| 832 | static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val) |
| 833 | { |
| 834 | if (kvmppc_shared_big_endian(vcpu)) |
| 835 | vcpu->arch.shared->msr = cpu_to_be64(val); |
| 836 | else |
| 837 | vcpu->arch.shared->msr = cpu_to_le64(val); |
| 838 | } |
| 839 | SHARED_WRAPPER(dsisr, 32) |
| 840 | SHARED_WRAPPER(int_pending, 32) |
| 841 | SHARED_WRAPPER(sprg4, 64) |
| 842 | SHARED_WRAPPER(sprg5, 64) |
| 843 | SHARED_WRAPPER(sprg6, 64) |
| 844 | SHARED_WRAPPER(sprg7, 64) |
| 845 | |
| 846 | static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr) |
| 847 | { |
| 848 | if (kvmppc_shared_big_endian(vcpu)) |
| 849 | return be32_to_cpu(vcpu->arch.shared->sr[nr]); |
| 850 | else |
| 851 | return le32_to_cpu(vcpu->arch.shared->sr[nr]); |
| 852 | } |
| 853 | |
| 854 | static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val) |
| 855 | { |
| 856 | if (kvmppc_shared_big_endian(vcpu)) |
| 857 | vcpu->arch.shared->sr[nr] = cpu_to_be32(val); |
| 858 | else |
| 859 | vcpu->arch.shared->sr[nr] = cpu_to_le32(val); |
| 860 | } |
| 861 | |
| 862 | /* |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 863 | * Please call after prepare_to_enter. This function puts the lazy ee and irq |
| 864 | * disabled tracking state back to normal mode, without actually enabling |
| 865 | * interrupts. |
| 866 | */ |
| 867 | static inline void kvmppc_fix_ee_before_entry(void) |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 868 | { |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 869 | trace_hardirqs_on(); |
| 870 | |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 871 | #ifdef CONFIG_PPC64 |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 872 | /* |
| 873 | * To avoid races, the caller must have gone directly from having |
| 874 | * interrupts fully-enabled to hard-disabled. |
| 875 | */ |
| 876 | WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS); |
| 877 | |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 878 | /* Only need to enable IRQs by hard enabling them after this */ |
| 879 | local_paca->irq_happened = 0; |
Madhavan Srinivasan | 4e26bc4 | 2017-12-20 09:25:50 +0530 | [diff] [blame] | 880 | irq_soft_mask_set(IRQS_ENABLED); |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 881 | #endif |
| 882 | } |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 883 | |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 884 | static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb) |
| 885 | { |
| 886 | ulong ea; |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 887 | ulong msr_64bit = 0; |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 888 | |
| 889 | ea = kvmppc_get_gpr(vcpu, rb); |
| 890 | if (ra) |
| 891 | ea += kvmppc_get_gpr(vcpu, ra); |
| 892 | |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 893 | #if defined(CONFIG_PPC_BOOK3E_64) |
| 894 | msr_64bit = MSR_CM; |
| 895 | #elif defined(CONFIG_PPC_BOOK3S_64) |
| 896 | msr_64bit = MSR_SF; |
| 897 | #endif |
| 898 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 899 | if (!(kvmppc_get_msr(vcpu) & msr_64bit)) |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 900 | ea = (uint32_t)ea; |
| 901 | |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 902 | return ea; |
| 903 | } |
| 904 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 905 | extern void xics_wake_cpu(int cpu); |
| 906 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 907 | #endif /* __POWERPC_KVM_PPC_H__ */ |