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 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 41 | enum emulation_result { |
| 42 | EMULATE_DONE, /* no further processing */ |
| 43 | EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */ |
| 44 | EMULATE_DO_DCR, /* kvm_run filled with DCR request */ |
| 45 | EMULATE_FAIL, /* can't emulate this instruction */ |
Alexander Graf | 37f5bca | 2010-02-19 11:00:31 +0100 | [diff] [blame] | 46 | EMULATE_AGAIN, /* something went wrong. go again */ |
Bharat Bhushan | c402a3f | 2013-04-08 00:32:13 +0000 | [diff] [blame] | 47 | EMULATE_EXIT_USER, /* emulation requires exit to user-space */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 48 | }; |
| 49 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame^] | 50 | enum instruction_type { |
| 51 | INST_GENERIC, |
| 52 | INST_SC, /* system call */ |
| 53 | }; |
| 54 | |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 55 | 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] | 56 | 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] | 57 | extern void kvmppc_handler_highmem(void); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 58 | |
| 59 | extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu); |
| 60 | extern int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 61 | unsigned int rt, unsigned int bytes, |
Cédric Le Goater | 7360177 | 2014-01-09 11:51:16 +0100 | [diff] [blame] | 62 | int is_default_endian); |
Alexander Graf | 3587d53 | 2010-02-19 11:00:30 +0100 | [diff] [blame] | 63 | extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 64 | unsigned int rt, unsigned int bytes, |
Cédric Le Goater | 7360177 | 2014-01-09 11:51:16 +0100 | [diff] [blame] | 65 | int is_default_endian); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 66 | 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] | 67 | u64 val, unsigned int bytes, |
| 68 | int is_default_endian); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 69 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame^] | 70 | extern int kvmppc_load_last_inst(struct kvm_vcpu *vcpu, |
| 71 | enum instruction_type type, u32 *inst); |
| 72 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 73 | extern int kvmppc_emulate_instruction(struct kvm_run *run, |
| 74 | struct kvm_vcpu *vcpu); |
Hollis Blanchard | ce263d7 | 2008-05-21 18:22:51 -0500 | [diff] [blame] | 75 | 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] | 76 | extern void kvmppc_emulate_dec(struct kvm_vcpu *vcpu); |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 77 | extern u32 kvmppc_get_dec(struct kvm_vcpu *vcpu, u64 tb); |
Scott Wood | dfd4d47 | 2011-11-17 12:39:59 +0000 | [diff] [blame] | 78 | extern void kvmppc_decrementer_func(unsigned long data); |
Alexander Graf | af8f38b | 2011-08-10 13:57:08 +0200 | [diff] [blame] | 79 | extern int kvmppc_sanity_check(struct kvm_vcpu *vcpu); |
Bharat Bhushan | f61c94b | 2012-08-08 20:38:19 +0000 | [diff] [blame] | 80 | extern int kvmppc_subarch_vcpu_init(struct kvm_vcpu *vcpu); |
| 81 | extern void kvmppc_subarch_vcpu_uninit(struct kvm_vcpu *vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 82 | |
Hollis Blanchard | ecc0981 | 2009-01-03 16:22:59 -0600 | [diff] [blame] | 83 | /* Core-specific hooks */ |
| 84 | |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 85 | 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] | 86 | unsigned int gtlb_idx); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 87 | extern void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode); |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 88 | extern void kvmppc_mmu_switch_pid(struct kvm_vcpu *vcpu, u32 pid); |
Hollis Blanchard | ecc0981 | 2009-01-03 16:22:59 -0600 | [diff] [blame] | 89 | extern void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu); |
Alexander Graf | 9cc5e95 | 2010-04-16 00:11:45 +0200 | [diff] [blame] | 90 | extern int kvmppc_mmu_init(struct kvm_vcpu *vcpu); |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 91 | extern int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr); |
| 92 | 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] | 93 | extern gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int gtlb_index, |
| 94 | gva_t eaddr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 95 | extern void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu); |
| 96 | extern void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 97 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 98 | extern struct kvm_vcpu *kvmppc_core_vcpu_create(struct kvm *kvm, |
| 99 | unsigned int id); |
| 100 | extern void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 101 | extern int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 102 | extern int kvmppc_core_check_processor_compat(void); |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 103 | extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu, |
| 104 | struct kvm_translation *tr); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 105 | |
| 106 | extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu); |
| 107 | extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu); |
| 108 | |
Alexander Graf | a8e4ef8 | 2012-02-16 14:07:37 +0000 | [diff] [blame] | 109 | extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 110 | extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu); |
Alexander Graf | 25a8a02 | 2010-01-08 02:58:07 +0100 | [diff] [blame] | 111 | extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 112 | extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu); |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 113 | extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 114 | extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 115 | struct kvm_interrupt *irq); |
Paul Mackerras | 4fe27d2 | 2013-02-14 14:00:25 +0000 | [diff] [blame] | 116 | extern void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu); |
Alexander Graf | 862d31f | 2012-07-31 00:19:50 +0200 | [diff] [blame] | 117 | extern void kvmppc_core_flush_tlb(struct kvm_vcpu *vcpu); |
Alexander Graf | 7c973a2 | 2012-08-13 12:50:35 +0200 | [diff] [blame] | 118 | extern int kvmppc_core_check_requests(struct kvm_vcpu *vcpu); |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 119 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 120 | extern int kvmppc_booke_init(void); |
| 121 | extern void kvmppc_booke_exit(void); |
| 122 | |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame] | 123 | extern void kvmppc_core_destroy_mmu(struct kvm_vcpu *vcpu); |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 124 | extern int kvmppc_kvm_pv(struct kvm_vcpu *vcpu); |
Scott Wood | a4cd8b2 | 2011-06-14 18:34:41 -0500 | [diff] [blame] | 125 | extern void kvmppc_map_magic(struct kvm_vcpu *vcpu); |
Hollis Blanchard | c30f8a6 | 2008-11-24 11:37:38 -0600 | [diff] [blame] | 126 | |
Paul Mackerras | 32fad28 | 2012-05-04 02:32:53 +0000 | [diff] [blame] | 127 | extern long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp); |
| 128 | extern long kvmppc_alloc_reset_hpt(struct kvm *kvm, u32 *htab_orderp); |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 129 | extern void kvmppc_free_hpt(struct kvm *kvm); |
| 130 | extern long kvmppc_prepare_vrma(struct kvm *kvm, |
| 131 | struct kvm_userspace_memory_region *mem); |
Paul Mackerras | c77162d | 2011-12-12 12:31:00 +0000 | [diff] [blame] | 132 | extern void kvmppc_map_vrma(struct kvm_vcpu *vcpu, |
Paul Mackerras | da9d1d7 | 2011-12-12 12:31:41 +0000 | [diff] [blame] | 133 | struct kvm_memory_slot *memslot, unsigned long porder); |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 134 | extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 135 | |
David Gibson | 54738c0 | 2011-06-29 00:22:41 +0000 | [diff] [blame] | 136 | extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, |
| 137 | struct kvm_create_spapr_tce *args); |
Benjamin Herrenschmidt | f31e65e | 2012-03-15 21:58:34 +0000 | [diff] [blame] | 138 | extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 139 | unsigned long ioba, unsigned long tce); |
Laurent Dufour | 69e9fbb2 | 2014-02-21 16:31:10 +0100 | [diff] [blame] | 140 | extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn, |
| 141 | unsigned long ioba); |
Aneesh Kumar K.V | 6c45b81 | 2013-07-02 11:15:17 +0530 | [diff] [blame] | 142 | extern struct kvm_rma_info *kvm_alloc_rma(void); |
| 143 | extern void kvm_release_rma(struct kvm_rma_info *ri); |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 144 | extern struct page *kvm_alloc_hpt(unsigned long nr_pages); |
| 145 | extern void kvm_release_hpt(struct page *page, unsigned long nr_pages); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 146 | extern int kvmppc_core_init_vm(struct kvm *kvm); |
| 147 | extern void kvmppc_core_destroy_vm(struct kvm *kvm); |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 148 | extern void kvmppc_core_free_memslot(struct kvm *kvm, |
| 149 | struct kvm_memory_slot *free, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 150 | struct kvm_memory_slot *dont); |
Aneesh Kumar K.V | 5587027 | 2013-10-07 22:18:00 +0530 | [diff] [blame] | 151 | extern int kvmppc_core_create_memslot(struct kvm *kvm, |
| 152 | struct kvm_memory_slot *slot, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 153 | unsigned long npages); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 154 | extern int kvmppc_core_prepare_memory_region(struct kvm *kvm, |
Paul Mackerras | a66b48c | 2012-09-11 13:27:46 +0000 | [diff] [blame] | 155 | struct kvm_memory_slot *memslot, |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 156 | struct kvm_userspace_memory_region *mem); |
| 157 | extern void kvmppc_core_commit_memory_region(struct kvm *kvm, |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 158 | struct kvm_userspace_memory_region *mem, |
Takuya Yoshikawa | 8482644 | 2013-02-27 19:45:25 +0900 | [diff] [blame] | 159 | const struct kvm_memory_slot *old); |
Benjamin Herrenschmidt | 5b74716 | 2012-04-26 19:43:42 +0000 | [diff] [blame] | 160 | extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm, |
| 161 | struct kvm_ppc_smmu_info *info); |
Paul Mackerras | dfe49db | 2012-09-11 13:28:18 +0000 | [diff] [blame] | 162 | extern void kvmppc_core_flush_memslot(struct kvm *kvm, |
| 163 | struct kvm_memory_slot *memslot); |
Paul Mackerras | f9e0554 | 2011-06-29 00:19:22 +0000 | [diff] [blame] | 164 | |
Scott Wood | d30f6e4 | 2011-12-20 15:34:43 +0000 | [diff] [blame] | 165 | extern int kvmppc_bookehv_init(void); |
| 166 | extern void kvmppc_bookehv_exit(void); |
| 167 | |
Alexander Graf | 03d25c5 | 2012-08-10 12:28:50 +0200 | [diff] [blame] | 168 | extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu); |
| 169 | |
Paul Mackerras | a293292 | 2012-11-19 22:57:20 +0000 | [diff] [blame] | 170 | extern int kvm_vm_ioctl_get_htab_fd(struct kvm *kvm, struct kvm_get_htab_fd *); |
| 171 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 172 | int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq); |
| 173 | |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 174 | extern int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp); |
| 175 | extern int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu); |
| 176 | extern void kvmppc_rtas_tokens_free(struct kvm *kvm); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 177 | extern int kvmppc_xics_set_xive(struct kvm *kvm, u32 irq, u32 server, |
| 178 | u32 priority); |
| 179 | extern int kvmppc_xics_get_xive(struct kvm *kvm, u32 irq, u32 *server, |
| 180 | u32 *priority); |
Paul Mackerras | d19bd862 | 2013-04-17 20:32:04 +0000 | [diff] [blame] | 181 | extern int kvmppc_xics_int_on(struct kvm *kvm, u32 irq); |
| 182 | extern int kvmppc_xics_int_off(struct kvm *kvm, u32 irq); |
Michael Ellerman | 8e591cb | 2013-04-17 20:30:00 +0000 | [diff] [blame] | 183 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 184 | union kvmppc_one_reg { |
| 185 | u32 wval; |
| 186 | u64 dval; |
| 187 | vector128 vval; |
| 188 | u64 vsxval[2]; |
| 189 | struct { |
| 190 | u64 addr; |
| 191 | u64 length; |
| 192 | } vpaval; |
| 193 | }; |
| 194 | |
| 195 | struct kvmppc_ops { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 196 | struct module *owner; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 197 | int (*get_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 198 | int (*set_sregs)(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 199 | int (*get_one_reg)(struct kvm_vcpu *vcpu, u64 id, |
| 200 | union kvmppc_one_reg *val); |
| 201 | int (*set_one_reg)(struct kvm_vcpu *vcpu, u64 id, |
| 202 | union kvmppc_one_reg *val); |
| 203 | void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu); |
| 204 | void (*vcpu_put)(struct kvm_vcpu *vcpu); |
| 205 | void (*set_msr)(struct kvm_vcpu *vcpu, u64 msr); |
| 206 | int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu); |
| 207 | struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned int id); |
| 208 | void (*vcpu_free)(struct kvm_vcpu *vcpu); |
| 209 | int (*check_requests)(struct kvm_vcpu *vcpu); |
| 210 | int (*get_dirty_log)(struct kvm *kvm, struct kvm_dirty_log *log); |
| 211 | void (*flush_memslot)(struct kvm *kvm, struct kvm_memory_slot *memslot); |
| 212 | int (*prepare_memory_region)(struct kvm *kvm, |
| 213 | struct kvm_memory_slot *memslot, |
| 214 | struct kvm_userspace_memory_region *mem); |
| 215 | void (*commit_memory_region)(struct kvm *kvm, |
| 216 | struct kvm_userspace_memory_region *mem, |
| 217 | const struct kvm_memory_slot *old); |
| 218 | int (*unmap_hva)(struct kvm *kvm, unsigned long hva); |
| 219 | int (*unmap_hva_range)(struct kvm *kvm, unsigned long start, |
| 220 | unsigned long end); |
| 221 | int (*age_hva)(struct kvm *kvm, unsigned long hva); |
| 222 | int (*test_age_hva)(struct kvm *kvm, unsigned long hva); |
| 223 | void (*set_spte_hva)(struct kvm *kvm, unsigned long hva, pte_t pte); |
| 224 | void (*mmu_destroy)(struct kvm_vcpu *vcpu); |
| 225 | void (*free_memslot)(struct kvm_memory_slot *free, |
| 226 | struct kvm_memory_slot *dont); |
| 227 | int (*create_memslot)(struct kvm_memory_slot *slot, |
| 228 | unsigned long npages); |
| 229 | int (*init_vm)(struct kvm *kvm); |
| 230 | void (*destroy_vm)(struct kvm *kvm); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 231 | int (*get_smmu_info)(struct kvm *kvm, struct kvm_ppc_smmu_info *info); |
| 232 | int (*emulate_op)(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 233 | unsigned int inst, int *advance); |
| 234 | int (*emulate_mtspr)(struct kvm_vcpu *vcpu, int sprn, ulong spr_val); |
| 235 | int (*emulate_mfspr)(struct kvm_vcpu *vcpu, int sprn, ulong *spr_val); |
| 236 | void (*fast_vcpu_kick)(struct kvm_vcpu *vcpu); |
| 237 | long (*arch_vm_ioctl)(struct file *filp, unsigned int ioctl, |
| 238 | unsigned long arg); |
Paul Mackerras | ae2113a | 2014-06-02 11:03:00 +1000 | [diff] [blame] | 239 | int (*hcall_implemented)(unsigned long hcall); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 240 | }; |
| 241 | |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 242 | extern struct kvmppc_ops *kvmppc_hv_ops; |
| 243 | extern struct kvmppc_ops *kvmppc_pr_ops; |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 244 | |
Mihai Caraman | 51f0472 | 2014-07-23 19:06:21 +0300 | [diff] [blame^] | 245 | static inline int kvmppc_get_last_inst(struct kvm_vcpu *vcpu, |
| 246 | enum instruction_type type, u32 *inst) |
| 247 | { |
| 248 | int ret = EMULATE_DONE; |
| 249 | u32 fetched_inst; |
| 250 | |
| 251 | /* Load the instruction manually if it failed to do so in the |
| 252 | * exit path */ |
| 253 | if (vcpu->arch.last_inst == KVM_INST_FETCH_FAILED) |
| 254 | ret = kvmppc_load_last_inst(vcpu, type, &vcpu->arch.last_inst); |
| 255 | |
| 256 | /* Write fetch_failed unswapped if the fetch failed */ |
| 257 | if (ret == EMULATE_DONE) |
| 258 | fetched_inst = kvmppc_need_byteswap(vcpu) ? |
| 259 | swab32(vcpu->arch.last_inst) : |
| 260 | vcpu->arch.last_inst; |
| 261 | else |
| 262 | fetched_inst = vcpu->arch.last_inst; |
| 263 | |
| 264 | *inst = fetched_inst; |
| 265 | return ret; |
| 266 | } |
| 267 | |
Aneesh Kumar K.V | a78b55d | 2013-10-07 22:18:02 +0530 | [diff] [blame] | 268 | static inline bool is_kvmppc_hv_enabled(struct kvm *kvm) |
| 269 | { |
| 270 | return kvm->arch.kvm_ops == kvmppc_hv_ops; |
| 271 | } |
| 272 | |
Alexander Graf | 0564ee8 | 2010-02-19 11:00:42 +0100 | [diff] [blame] | 273 | /* |
| 274 | * Cuts out inst bits with ordering according to spec. |
| 275 | * That means the leftmost bit is zero. All given bits are included. |
| 276 | */ |
| 277 | static inline u32 kvmppc_get_field(u64 inst, int msb, int lsb) |
| 278 | { |
| 279 | u32 r; |
| 280 | u32 mask; |
| 281 | |
| 282 | BUG_ON(msb > lsb); |
| 283 | |
| 284 | mask = (1 << (lsb - msb + 1)) - 1; |
| 285 | r = (inst >> (63 - lsb)) & mask; |
| 286 | |
| 287 | return r; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Replaces inst bits with ordering according to spec. |
| 292 | */ |
| 293 | static inline u32 kvmppc_set_field(u64 inst, int msb, int lsb, int value) |
| 294 | { |
| 295 | u32 r; |
| 296 | u32 mask; |
| 297 | |
| 298 | BUG_ON(msb > lsb); |
| 299 | |
| 300 | mask = ((1 << (lsb - msb + 1)) - 1) << (63 - lsb); |
| 301 | r = (inst & ~mask) | ((value << (63 - lsb)) & mask); |
| 302 | |
| 303 | return r; |
| 304 | } |
| 305 | |
Paul Mackerras | a136a8b | 2012-09-25 20:31:56 +0000 | [diff] [blame] | 306 | #define one_reg_size(id) \ |
| 307 | (1ul << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) |
| 308 | |
| 309 | #define get_reg_val(id, reg) ({ \ |
| 310 | union kvmppc_one_reg __u; \ |
| 311 | switch (one_reg_size(id)) { \ |
| 312 | case 4: __u.wval = (reg); break; \ |
| 313 | case 8: __u.dval = (reg); break; \ |
| 314 | default: BUG(); \ |
| 315 | } \ |
| 316 | __u; \ |
| 317 | }) |
| 318 | |
| 319 | |
| 320 | #define set_reg_val(id, val) ({ \ |
| 321 | u64 __v; \ |
| 322 | switch (one_reg_size(id)) { \ |
| 323 | case 4: __v = (val).wval; break; \ |
| 324 | case 8: __v = (val).dval; break; \ |
| 325 | default: BUG(); \ |
| 326 | } \ |
| 327 | __v; \ |
| 328 | }) |
| 329 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 330 | 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] | 331 | int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 332 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 333 | 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] | 334 | int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs); |
| 335 | |
Paul Mackerras | 31f3438 | 2011-12-12 12:26:50 +0000 | [diff] [blame] | 336 | int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg); |
| 337 | 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] | 338 | int kvmppc_get_one_reg(struct kvm_vcpu *vcpu, u64 id, union kvmppc_one_reg *); |
| 339 | 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] | 340 | |
Scott Wood | 5ce941e | 2011-04-27 17:24:21 -0500 | [diff] [blame] | 341 | void kvmppc_set_pid(struct kvm_vcpu *vcpu, u32 pid); |
| 342 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 343 | struct openpic; |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 344 | |
Aneesh Kumar K.V | 9975f5e | 2013-10-07 22:17:52 +0530 | [diff] [blame] | 345 | #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 346 | extern void kvm_cma_reserve(void) __init; |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 347 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
| 348 | { |
| 349 | paca[cpu].kvm_hstate.xics_phys = addr; |
| 350 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 351 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 352 | static inline u32 kvmppc_get_xics_latch(void) |
| 353 | { |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 354 | u32 xirr; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 355 | |
Aneesh Kumar K.V | 699cc87 | 2013-10-07 22:17:56 +0530 | [diff] [blame] | 356 | xirr = get_paca()->kvm_hstate.saved_xirr; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 357 | get_paca()->kvm_hstate.saved_xirr = 0; |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 358 | return xirr; |
| 359 | } |
| 360 | |
| 361 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) |
| 362 | { |
| 363 | paca[cpu].kvm_hstate.host_ipi = host_ipi; |
| 364 | } |
| 365 | |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 366 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
| 367 | { |
Aneesh Kumar K.V | cbbc58d | 2013-10-07 22:18:01 +0530 | [diff] [blame] | 368 | vcpu->kvm->arch.kvm_ops->fast_vcpu_kick(vcpu); |
Aneesh Kumar K.V | 3a167bea | 2013-10-07 22:17:53 +0530 | [diff] [blame] | 369 | } |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 370 | |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 371 | extern void kvm_hv_vm_activated(void); |
| 372 | extern void kvm_hv_vm_deactivated(void); |
| 373 | extern bool kvm_hv_mode_active(void); |
| 374 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 375 | #else |
Aneesh Kumar K.V | fa61a4e3 | 2013-07-02 11:15:16 +0530 | [diff] [blame] | 376 | static inline void __init kvm_cma_reserve(void) |
| 377 | {} |
| 378 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 379 | static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) |
| 380 | {} |
Paul Mackerras | aa04b4c | 2011-06-29 00:25:44 +0000 | [diff] [blame] | 381 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 382 | static inline u32 kvmppc_get_xics_latch(void) |
| 383 | { |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static inline void kvmppc_set_host_ipi(int cpu, u8 host_ipi) |
| 388 | {} |
| 389 | |
| 390 | static inline void kvmppc_fast_vcpu_kick(struct kvm_vcpu *vcpu) |
| 391 | { |
| 392 | kvm_vcpu_kick(vcpu); |
| 393 | } |
Michael Ellerman | 441c19c | 2014-05-23 18:15:25 +1000 | [diff] [blame] | 394 | |
| 395 | static inline bool kvm_hv_mode_active(void) { return false; } |
| 396 | |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 397 | #endif |
| 398 | |
| 399 | #ifdef CONFIG_KVM_XICS |
| 400 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
| 401 | { |
| 402 | return vcpu->arch.irq_type == KVMPPC_IRQ_XICS; |
| 403 | } |
| 404 | extern void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu); |
| 405 | extern int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, unsigned long server); |
| 406 | extern int kvm_vm_ioctl_xics_irq(struct kvm *kvm, struct kvm_irq_level *args); |
| 407 | extern int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd); |
Paul Mackerras | 8b78645 | 2013-04-17 20:32:26 +0000 | [diff] [blame] | 408 | extern u64 kvmppc_xics_get_icp(struct kvm_vcpu *vcpu); |
| 409 | extern int kvmppc_xics_set_icp(struct kvm_vcpu *vcpu, u64 icpval); |
Paul Mackerras | 5975a2e | 2013-04-27 00:28:37 +0000 | [diff] [blame] | 410 | extern int kvmppc_xics_connect_vcpu(struct kvm_device *dev, |
| 411 | struct kvm_vcpu *vcpu, u32 cpu); |
Benjamin Herrenschmidt | bc5ad3f | 2013-04-17 20:30:26 +0000 | [diff] [blame] | 412 | #else |
| 413 | static inline int kvmppc_xics_enabled(struct kvm_vcpu *vcpu) |
| 414 | { return 0; } |
| 415 | static inline void kvmppc_xics_free_icp(struct kvm_vcpu *vcpu) { } |
| 416 | static inline int kvmppc_xics_create_icp(struct kvm_vcpu *vcpu, |
| 417 | unsigned long server) |
| 418 | { return -EINVAL; } |
| 419 | static inline int kvm_vm_ioctl_xics_irq(struct kvm *kvm, |
| 420 | struct kvm_irq_level *args) |
| 421 | { return -ENOTTY; } |
| 422 | static inline int kvmppc_xics_hcall(struct kvm_vcpu *vcpu, u32 cmd) |
| 423 | { return 0; } |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 424 | #endif |
| 425 | |
Bharat Bhushan | 34f754b | 2014-07-17 17:01:40 +0530 | [diff] [blame] | 426 | static inline unsigned long kvmppc_get_epr(struct kvm_vcpu *vcpu) |
| 427 | { |
| 428 | #ifdef CONFIG_KVM_BOOKE_HV |
| 429 | return mfspr(SPRN_GEPR); |
| 430 | #elif defined(CONFIG_BOOKE) |
| 431 | return vcpu->arch.epr; |
| 432 | #else |
| 433 | return 0; |
| 434 | #endif |
| 435 | } |
| 436 | |
Alexander Graf | 1c81063 | 2013-01-04 18:12:48 +0100 | [diff] [blame] | 437 | static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr) |
| 438 | { |
| 439 | #ifdef CONFIG_KVM_BOOKE_HV |
| 440 | mtspr(SPRN_GEPR, epr); |
| 441 | #elif defined(CONFIG_BOOKE) |
| 442 | vcpu->arch.epr = epr; |
| 443 | #endif |
| 444 | } |
| 445 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 446 | #ifdef CONFIG_KVM_MPIC |
| 447 | |
| 448 | void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu); |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 449 | int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu, |
| 450 | u32 cpu); |
| 451 | void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, struct kvm_vcpu *vcpu); |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 452 | |
| 453 | #else |
| 454 | |
| 455 | static inline void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu) |
| 456 | { |
| 457 | } |
| 458 | |
Scott Wood | eb1e4f4 | 2013-04-12 14:08:47 +0000 | [diff] [blame] | 459 | static inline int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, |
| 460 | struct kvm_vcpu *vcpu, u32 cpu) |
| 461 | { |
| 462 | return -EINVAL; |
| 463 | } |
| 464 | |
| 465 | static inline void kvmppc_mpic_disconnect_vcpu(struct openpic *opp, |
| 466 | struct kvm_vcpu *vcpu) |
| 467 | { |
| 468 | } |
| 469 | |
Scott Wood | 5df554ad | 2013-04-12 14:08:46 +0000 | [diff] [blame] | 470 | #endif /* CONFIG_KVM_MPIC */ |
| 471 | |
Scott Wood | dc83b8b | 2011-08-18 15:25:21 -0500 | [diff] [blame] | 472 | int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, |
| 473 | struct kvm_config_tlb *cfg); |
| 474 | int kvm_vcpu_ioctl_dirty_tlb(struct kvm_vcpu *vcpu, |
| 475 | struct kvm_dirty_tlb *cfg); |
| 476 | |
Scott Wood | 043cc4d | 2011-12-20 15:34:20 +0000 | [diff] [blame] | 477 | long kvmppc_alloc_lpid(void); |
| 478 | void kvmppc_claim_lpid(long lpid); |
| 479 | void kvmppc_free_lpid(long lpid); |
| 480 | void kvmppc_init_lpid(unsigned long nr_lpids); |
| 481 | |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 482 | static inline void kvmppc_mmu_flush_icache(pfn_t pfn) |
| 483 | { |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 484 | struct page *page; |
Bharat Bhushan | adccf65 | 2013-04-25 06:33:57 +0000 | [diff] [blame] | 485 | /* |
| 486 | * We can only access pages that the kernel maps |
| 487 | * as memory. Bail out for unmapped ones. |
| 488 | */ |
| 489 | if (!pfn_valid(pfn)) |
| 490 | return; |
| 491 | |
| 492 | /* Clear i-cache for new pages */ |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 493 | page = pfn_to_page(pfn); |
| 494 | if (!test_bit(PG_arch_1, &page->flags)) { |
| 495 | flush_dcache_icache_page(page); |
| 496 | set_bit(PG_arch_1, &page->flags); |
| 497 | } |
| 498 | } |
| 499 | |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 500 | /* |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 501 | * Shared struct helpers. The shared struct can be little or big endian, |
| 502 | * depending on the guest endianness. So expose helpers to all of them. |
| 503 | */ |
| 504 | static inline bool kvmppc_shared_big_endian(struct kvm_vcpu *vcpu) |
| 505 | { |
| 506 | #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_KVM_BOOK3S_PR_POSSIBLE) |
| 507 | /* Only Book3S_64 PR supports bi-endian for now */ |
| 508 | return vcpu->arch.shared_big_endian; |
| 509 | #elif defined(CONFIG_PPC_BOOK3S_64) && defined(__LITTLE_ENDIAN__) |
| 510 | /* Book3s_64 HV on little endian is always little endian */ |
| 511 | return false; |
| 512 | #else |
| 513 | return true; |
| 514 | #endif |
| 515 | } |
| 516 | |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 517 | #define SPRNG_WRAPPER_GET(reg, e500hv_spr) \ |
| 518 | static inline ulong kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
| 519 | { \ |
| 520 | return mfspr(e500hv_spr); \ |
| 521 | } \ |
| 522 | |
| 523 | #define SPRNG_WRAPPER_SET(reg, e500hv_spr) \ |
| 524 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, ulong val) \ |
| 525 | { \ |
| 526 | mtspr(e500hv_spr, val); \ |
| 527 | } \ |
| 528 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 529 | #define SHARED_WRAPPER_GET(reg, size) \ |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 530 | static inline u##size kvmppc_get_##reg(struct kvm_vcpu *vcpu) \ |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 531 | { \ |
| 532 | if (kvmppc_shared_big_endian(vcpu)) \ |
| 533 | return be##size##_to_cpu(vcpu->arch.shared->reg); \ |
| 534 | else \ |
| 535 | return le##size##_to_cpu(vcpu->arch.shared->reg); \ |
| 536 | } \ |
| 537 | |
| 538 | #define SHARED_WRAPPER_SET(reg, size) \ |
| 539 | static inline void kvmppc_set_##reg(struct kvm_vcpu *vcpu, u##size val) \ |
| 540 | { \ |
| 541 | if (kvmppc_shared_big_endian(vcpu)) \ |
| 542 | vcpu->arch.shared->reg = cpu_to_be##size(val); \ |
| 543 | else \ |
| 544 | vcpu->arch.shared->reg = cpu_to_le##size(val); \ |
| 545 | } \ |
| 546 | |
| 547 | #define SHARED_WRAPPER(reg, size) \ |
| 548 | SHARED_WRAPPER_GET(reg, size) \ |
| 549 | SHARED_WRAPPER_SET(reg, size) \ |
| 550 | |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 551 | #define SPRNG_WRAPPER(reg, e500hv_spr) \ |
| 552 | SPRNG_WRAPPER_GET(reg, e500hv_spr) \ |
| 553 | SPRNG_WRAPPER_SET(reg, e500hv_spr) \ |
| 554 | |
| 555 | #ifdef CONFIG_KVM_BOOKE_HV |
| 556 | |
| 557 | #define SHARED_SPRNG_WRAPPER(reg, size, e500hv_spr) \ |
| 558 | SPRNG_WRAPPER(reg, e500hv_spr) \ |
| 559 | |
| 560 | #else |
| 561 | |
| 562 | #define SHARED_SPRNG_WRAPPER(reg, size, e500hv_spr) \ |
| 563 | SHARED_WRAPPER(reg, size) \ |
| 564 | |
| 565 | #endif |
| 566 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 567 | SHARED_WRAPPER(critical, 64) |
Bharat Bhushan | 1dc0c5b | 2014-07-17 17:01:35 +0530 | [diff] [blame] | 568 | SHARED_SPRNG_WRAPPER(sprg0, 64, SPRN_GSPRG0) |
| 569 | SHARED_SPRNG_WRAPPER(sprg1, 64, SPRN_GSPRG1) |
| 570 | SHARED_SPRNG_WRAPPER(sprg2, 64, SPRN_GSPRG2) |
| 571 | SHARED_SPRNG_WRAPPER(sprg3, 64, SPRN_GSPRG3) |
| 572 | SHARED_SPRNG_WRAPPER(srr0, 64, SPRN_GSRR0) |
| 573 | SHARED_SPRNG_WRAPPER(srr1, 64, SPRN_GSRR1) |
| 574 | SHARED_SPRNG_WRAPPER(dar, 64, SPRN_GDEAR) |
Bharat Bhushan | dc16854 | 2014-07-17 17:01:38 +0530 | [diff] [blame] | 575 | SHARED_SPRNG_WRAPPER(esr, 64, SPRN_GESR) |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 576 | SHARED_WRAPPER_GET(msr, 64) |
| 577 | static inline void kvmppc_set_msr_fast(struct kvm_vcpu *vcpu, u64 val) |
| 578 | { |
| 579 | if (kvmppc_shared_big_endian(vcpu)) |
| 580 | vcpu->arch.shared->msr = cpu_to_be64(val); |
| 581 | else |
| 582 | vcpu->arch.shared->msr = cpu_to_le64(val); |
| 583 | } |
| 584 | SHARED_WRAPPER(dsisr, 32) |
| 585 | SHARED_WRAPPER(int_pending, 32) |
| 586 | SHARED_WRAPPER(sprg4, 64) |
| 587 | SHARED_WRAPPER(sprg5, 64) |
| 588 | SHARED_WRAPPER(sprg6, 64) |
| 589 | SHARED_WRAPPER(sprg7, 64) |
| 590 | |
| 591 | static inline u32 kvmppc_get_sr(struct kvm_vcpu *vcpu, int nr) |
| 592 | { |
| 593 | if (kvmppc_shared_big_endian(vcpu)) |
| 594 | return be32_to_cpu(vcpu->arch.shared->sr[nr]); |
| 595 | else |
| 596 | return le32_to_cpu(vcpu->arch.shared->sr[nr]); |
| 597 | } |
| 598 | |
| 599 | static inline void kvmppc_set_sr(struct kvm_vcpu *vcpu, int nr, u32 val) |
| 600 | { |
| 601 | if (kvmppc_shared_big_endian(vcpu)) |
| 602 | vcpu->arch.shared->sr[nr] = cpu_to_be32(val); |
| 603 | else |
| 604 | vcpu->arch.shared->sr[nr] = cpu_to_le32(val); |
| 605 | } |
| 606 | |
| 607 | /* |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 608 | * Please call after prepare_to_enter. This function puts the lazy ee and irq |
| 609 | * disabled tracking state back to normal mode, without actually enabling |
| 610 | * interrupts. |
| 611 | */ |
| 612 | static inline void kvmppc_fix_ee_before_entry(void) |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 613 | { |
Scott Wood | 5f1c248 | 2013-07-10 17:47:39 -0500 | [diff] [blame] | 614 | trace_hardirqs_on(); |
| 615 | |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 616 | #ifdef CONFIG_PPC64 |
Scott Wood | 6c85f52 | 2014-01-09 19:18:40 -0600 | [diff] [blame] | 617 | /* |
| 618 | * To avoid races, the caller must have gone directly from having |
| 619 | * interrupts fully-enabled to hard-disabled. |
| 620 | */ |
| 621 | WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS); |
| 622 | |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 623 | /* Only need to enable IRQs by hard enabling them after this */ |
| 624 | local_paca->irq_happened = 0; |
| 625 | local_paca->soft_enabled = 1; |
| 626 | #endif |
| 627 | } |
Alexander Graf | 249ba1e | 2012-08-03 13:56:33 +0200 | [diff] [blame] | 628 | |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 629 | static inline ulong kvmppc_get_ea_indexed(struct kvm_vcpu *vcpu, int ra, int rb) |
| 630 | { |
| 631 | ulong ea; |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 632 | ulong msr_64bit = 0; |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 633 | |
| 634 | ea = kvmppc_get_gpr(vcpu, rb); |
| 635 | if (ra) |
| 636 | ea += kvmppc_get_gpr(vcpu, ra); |
| 637 | |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 638 | #if defined(CONFIG_PPC_BOOK3E_64) |
| 639 | msr_64bit = MSR_CM; |
| 640 | #elif defined(CONFIG_PPC_BOOK3S_64) |
| 641 | msr_64bit = MSR_SF; |
| 642 | #endif |
| 643 | |
Alexander Graf | 5deb8e7 | 2014-04-24 13:46:24 +0200 | [diff] [blame] | 644 | if (!(kvmppc_get_msr(vcpu) & msr_64bit)) |
Mihai Caraman | 8823a8f | 2012-10-11 06:13:23 +0000 | [diff] [blame] | 645 | ea = (uint32_t)ea; |
| 646 | |
Mihai Caraman | 7cdd7a9 | 2012-10-11 06:13:22 +0000 | [diff] [blame] | 647 | return ea; |
| 648 | } |
| 649 | |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 650 | extern void xics_wake_cpu(int cpu); |
| 651 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 652 | #endif /* __POWERPC_KVM_PPC_H__ */ |