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. 2007 |
| 16 | * |
| 17 | * Authors: Hollis Blanchard <hollisb@us.ibm.com> |
| 18 | * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/err.h> |
| 23 | #include <linux/kvm_host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/gfp.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/vmalloc.h> |
| 27 | #include <linux/fs.h> |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 28 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 29 | #include <asm/cputable.h> |
| 30 | #include <asm/uaccess.h> |
| 31 | #include <asm/kvm_ppc.h> |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 32 | #include "timing.h" |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 33 | #include <asm/cacheflush.h> |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 34 | |
Hollis Blanchard | 75f74f0 | 2008-11-05 09:36:16 -0600 | [diff] [blame] | 35 | #include "booke.h" |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 36 | |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 37 | unsigned long kvmppc_booke_handlers; |
| 38 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 39 | #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM |
| 40 | #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU |
| 41 | |
| 42 | struct kvm_stats_debugfs_item debugfs_entries[] = { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 43 | { "mmio", VCPU_STAT(mmio_exits) }, |
| 44 | { "dcr", VCPU_STAT(dcr_exits) }, |
| 45 | { "sig", VCPU_STAT(signal_exits) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 46 | { "itlb_r", VCPU_STAT(itlb_real_miss_exits) }, |
| 47 | { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) }, |
| 48 | { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) }, |
| 49 | { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) }, |
| 50 | { "sysc", VCPU_STAT(syscall_exits) }, |
| 51 | { "isi", VCPU_STAT(isi_exits) }, |
| 52 | { "dsi", VCPU_STAT(dsi_exits) }, |
| 53 | { "inst_emu", VCPU_STAT(emulated_inst_exits) }, |
| 54 | { "dec", VCPU_STAT(dec_exits) }, |
| 55 | { "ext_intr", VCPU_STAT(ext_intr_exits) }, |
Hollis Blanchard | 45c5eb6 | 2008-04-25 17:55:49 -0500 | [diff] [blame] | 56 | { "halt_wakeup", VCPU_STAT(halt_wakeup) }, |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 57 | { NULL } |
| 58 | }; |
| 59 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 60 | /* TODO: use vcpu_printf() */ |
| 61 | void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) |
| 62 | { |
| 63 | int i; |
| 64 | |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 65 | printk("pc: %08lx msr: %08llx\n", vcpu->arch.pc, vcpu->arch.shared->msr); |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 66 | printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 67 | printk("srr0: %08llx srr1: %08llx\n", vcpu->arch.shared->srr0, |
| 68 | vcpu->arch.shared->srr1); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 69 | |
| 70 | printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions); |
| 71 | |
| 72 | for (i = 0; i < 32; i += 4) { |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 73 | printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i, |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 74 | kvmppc_get_gpr(vcpu, i), |
| 75 | kvmppc_get_gpr(vcpu, i+1), |
| 76 | kvmppc_get_gpr(vcpu, i+2), |
| 77 | kvmppc_get_gpr(vcpu, i+3)); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 81 | static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu, |
| 82 | unsigned int priority) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 83 | { |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 84 | set_bit(priority, &vcpu->arch.pending_exceptions); |
| 85 | } |
| 86 | |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 87 | static void kvmppc_core_queue_dtlb_miss(struct kvm_vcpu *vcpu, |
| 88 | ulong dear_flags, ulong esr_flags) |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 89 | { |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 90 | vcpu->arch.queued_dear = dear_flags; |
| 91 | vcpu->arch.queued_esr = esr_flags; |
| 92 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS); |
| 93 | } |
| 94 | |
| 95 | static void kvmppc_core_queue_data_storage(struct kvm_vcpu *vcpu, |
| 96 | ulong dear_flags, ulong esr_flags) |
| 97 | { |
| 98 | vcpu->arch.queued_dear = dear_flags; |
| 99 | vcpu->arch.queued_esr = esr_flags; |
| 100 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE); |
| 101 | } |
| 102 | |
| 103 | static void kvmppc_core_queue_inst_storage(struct kvm_vcpu *vcpu, |
| 104 | ulong esr_flags) |
| 105 | { |
| 106 | vcpu->arch.queued_esr = esr_flags; |
| 107 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE); |
| 108 | } |
| 109 | |
| 110 | void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong esr_flags) |
| 111 | { |
| 112 | vcpu->arch.queued_esr = esr_flags; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 113 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu) |
| 117 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 118 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu) |
| 122 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 123 | return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 124 | } |
| 125 | |
Alexander Graf | 7706664d | 2009-12-21 20:21:24 +0100 | [diff] [blame] | 126 | void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu) |
| 127 | { |
| 128 | clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions); |
| 129 | } |
| 130 | |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 131 | void kvmppc_core_queue_external(struct kvm_vcpu *vcpu, |
| 132 | struct kvm_interrupt *irq) |
| 133 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 134 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_EXTERNAL); |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 135 | } |
| 136 | |
Alexander Graf | 4496f97 | 2010-04-07 10:03:25 +0200 | [diff] [blame] | 137 | void kvmppc_core_dequeue_external(struct kvm_vcpu *vcpu, |
| 138 | struct kvm_interrupt *irq) |
| 139 | { |
| 140 | clear_bit(BOOKE_IRQPRIO_EXTERNAL, &vcpu->arch.pending_exceptions); |
| 141 | } |
| 142 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 143 | /* Deliver the interrupt of the corresponding priority, if possible. */ |
| 144 | static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, |
| 145 | unsigned int priority) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 146 | { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 147 | int allowed = 0; |
Asias He | 6045be5 | 2010-06-19 16:52:12 +0800 | [diff] [blame] | 148 | ulong uninitialized_var(msr_mask); |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 149 | bool update_esr = false, update_dear = false; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 150 | ulong crit_raw = vcpu->arch.shared->critical; |
| 151 | ulong crit_r1 = kvmppc_get_gpr(vcpu, 1); |
| 152 | bool crit; |
| 153 | |
| 154 | /* Truncate crit indicators in 32 bit mode */ |
| 155 | if (!(vcpu->arch.shared->msr & MSR_SF)) { |
| 156 | crit_raw &= 0xffffffff; |
| 157 | crit_r1 &= 0xffffffff; |
| 158 | } |
| 159 | |
| 160 | /* Critical section when crit == r1 */ |
| 161 | crit = (crit_raw == crit_r1); |
| 162 | /* ... and we're in supervisor mode */ |
| 163 | crit = crit && !(vcpu->arch.shared->msr & MSR_PR); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 164 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 165 | switch (priority) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 166 | case BOOKE_IRQPRIO_DTLB_MISS: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 167 | case BOOKE_IRQPRIO_DATA_STORAGE: |
| 168 | update_dear = true; |
| 169 | /* fall through */ |
| 170 | case BOOKE_IRQPRIO_INST_STORAGE: |
| 171 | case BOOKE_IRQPRIO_PROGRAM: |
| 172 | update_esr = true; |
| 173 | /* fall through */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 174 | case BOOKE_IRQPRIO_ITLB_MISS: |
| 175 | case BOOKE_IRQPRIO_SYSCALL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 176 | case BOOKE_IRQPRIO_FP_UNAVAIL: |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 177 | case BOOKE_IRQPRIO_SPE_UNAVAIL: |
| 178 | case BOOKE_IRQPRIO_SPE_FP_DATA: |
| 179 | case BOOKE_IRQPRIO_SPE_FP_ROUND: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 180 | case BOOKE_IRQPRIO_AP_UNAVAIL: |
| 181 | case BOOKE_IRQPRIO_ALIGNMENT: |
| 182 | allowed = 1; |
| 183 | msr_mask = MSR_CE|MSR_ME|MSR_DE; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 184 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 185 | case BOOKE_IRQPRIO_CRITICAL: |
| 186 | case BOOKE_IRQPRIO_WATCHDOG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 187 | allowed = vcpu->arch.shared->msr & MSR_CE; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 188 | msr_mask = MSR_ME; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 189 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 190 | case BOOKE_IRQPRIO_MACHINE_CHECK: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 191 | allowed = vcpu->arch.shared->msr & MSR_ME; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 192 | msr_mask = 0; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 193 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 194 | case BOOKE_IRQPRIO_EXTERNAL: |
| 195 | case BOOKE_IRQPRIO_DECREMENTER: |
| 196 | case BOOKE_IRQPRIO_FIT: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 197 | allowed = vcpu->arch.shared->msr & MSR_EE; |
Alexander Graf | 5c6cedf | 2010-07-29 14:47:49 +0200 | [diff] [blame] | 198 | allowed = allowed && !crit; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 199 | msr_mask = MSR_CE|MSR_ME|MSR_DE; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 200 | break; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 201 | case BOOKE_IRQPRIO_DEBUG: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 202 | allowed = vcpu->arch.shared->msr & MSR_DE; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 203 | msr_mask = MSR_ME; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 204 | break; |
| 205 | } |
| 206 | |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 207 | if (allowed) { |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 208 | vcpu->arch.shared->srr0 = vcpu->arch.pc; |
| 209 | vcpu->arch.shared->srr1 = vcpu->arch.shared->msr; |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 210 | vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 211 | if (update_esr == true) |
| 212 | vcpu->arch.esr = vcpu->arch.queued_esr; |
| 213 | if (update_dear == true) |
Alexander Graf | 5e03018 | 2010-07-29 14:47:45 +0200 | [diff] [blame] | 214 | vcpu->arch.shared->dar = vcpu->arch.queued_dear; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 215 | kvmppc_set_msr(vcpu, vcpu->arch.shared->msr & msr_mask); |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 216 | |
| 217 | clear_bit(priority, &vcpu->arch.pending_exceptions); |
| 218 | } |
| 219 | |
| 220 | return allowed; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* Check pending exceptions and deliver one, if possible. */ |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 224 | void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 225 | { |
| 226 | unsigned long *pending = &vcpu->arch.pending_exceptions; |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame^] | 227 | unsigned long old_pending = vcpu->arch.pending_exceptions; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 228 | unsigned int priority; |
| 229 | |
Hollis Blanchard | 9ab8084 | 2008-11-05 09:36:22 -0600 | [diff] [blame] | 230 | priority = __ffs(*pending); |
Hollis Blanchard | bdc89f1 | 2009-01-03 16:23:12 -0600 | [diff] [blame] | 231 | while (priority <= BOOKE_IRQPRIO_MAX) { |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 232 | if (kvmppc_booke_irqprio_deliver(vcpu, priority)) |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 233 | break; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 234 | |
| 235 | priority = find_next_bit(pending, |
| 236 | BITS_PER_BYTE * sizeof(*pending), |
| 237 | priority + 1); |
| 238 | } |
Alexander Graf | 90bba35 | 2010-07-29 14:47:51 +0200 | [diff] [blame^] | 239 | |
| 240 | /* Tell the guest about our interrupt status */ |
| 241 | if (*pending) |
| 242 | vcpu->arch.shared->int_pending = 1; |
| 243 | else if (old_pending) |
| 244 | vcpu->arch.shared->int_pending = 0; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 245 | } |
| 246 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 247 | /** |
| 248 | * kvmppc_handle_exit |
| 249 | * |
| 250 | * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV) |
| 251 | */ |
| 252 | int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, |
| 253 | unsigned int exit_nr) |
| 254 | { |
| 255 | enum emulation_result er; |
| 256 | int r = RESUME_HOST; |
| 257 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 258 | /* update before a new last_exit_type is rewritten */ |
| 259 | kvmppc_update_timing_stats(vcpu); |
| 260 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 261 | local_irq_enable(); |
| 262 | |
| 263 | run->exit_reason = KVM_EXIT_UNKNOWN; |
| 264 | run->ready_for_interrupt_injection = 1; |
| 265 | |
| 266 | switch (exit_nr) { |
| 267 | case BOOKE_INTERRUPT_MACHINE_CHECK: |
| 268 | printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR)); |
| 269 | kvmppc_dump_vcpu(vcpu); |
| 270 | r = RESUME_HOST; |
| 271 | break; |
| 272 | |
| 273 | case BOOKE_INTERRUPT_EXTERNAL: |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 274 | kvmppc_account_exit(vcpu, EXT_INTR_EXITS); |
Hollis Blanchard | 1b6766c | 2008-11-05 09:36:21 -0600 | [diff] [blame] | 275 | if (need_resched()) |
| 276 | cond_resched(); |
| 277 | r = RESUME_GUEST; |
| 278 | break; |
| 279 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 280 | case BOOKE_INTERRUPT_DECREMENTER: |
| 281 | /* Since we switched IVPR back to the host's value, the host |
| 282 | * handled this interrupt the moment we enabled interrupts. |
| 283 | * Now we just offer it a chance to reschedule the guest. */ |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 284 | kvmppc_account_exit(vcpu, DEC_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 285 | if (need_resched()) |
| 286 | cond_resched(); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 287 | r = RESUME_GUEST; |
| 288 | break; |
| 289 | |
| 290 | case BOOKE_INTERRUPT_PROGRAM: |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 291 | if (vcpu->arch.shared->msr & MSR_PR) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 292 | /* Program traps generated by user-level software must be handled |
| 293 | * by the guest kernel. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 294 | kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 295 | r = RESUME_GUEST; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 296 | kvmppc_account_exit(vcpu, USR_PR_INST); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 297 | break; |
| 298 | } |
| 299 | |
| 300 | er = kvmppc_emulate_instruction(run, vcpu); |
| 301 | switch (er) { |
| 302 | case EMULATE_DONE: |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 303 | /* don't overwrite subtypes, just account kvm_stats */ |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 304 | kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 305 | /* Future optimization: only reload non-volatiles if |
| 306 | * they were actually modified by emulation. */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 307 | r = RESUME_GUEST_NV; |
| 308 | break; |
| 309 | case EMULATE_DO_DCR: |
| 310 | run->exit_reason = KVM_EXIT_DCR; |
| 311 | r = RESUME_HOST; |
| 312 | break; |
| 313 | case EMULATE_FAIL: |
| 314 | /* XXX Deliver Program interrupt to guest. */ |
Hollis Blanchard | 5cf8ca2 | 2008-11-05 09:36:19 -0600 | [diff] [blame] | 315 | printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n", |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 316 | __func__, vcpu->arch.pc, vcpu->arch.last_inst); |
| 317 | /* For debugging, encode the failing instruction and |
| 318 | * report it to userspace. */ |
| 319 | run->hw.hardware_exit_reason = ~0ULL << 32; |
| 320 | run->hw.hardware_exit_reason |= vcpu->arch.last_inst; |
| 321 | r = RESUME_HOST; |
| 322 | break; |
| 323 | default: |
| 324 | BUG(); |
| 325 | } |
| 326 | break; |
| 327 | |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 328 | case BOOKE_INTERRUPT_FP_UNAVAIL: |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 329 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 330 | kvmppc_account_exit(vcpu, FP_UNAVAIL); |
Christian Ehrhardt | de368dc | 2008-04-29 18:18:23 +0200 | [diff] [blame] | 331 | r = RESUME_GUEST; |
| 332 | break; |
| 333 | |
Hollis Blanchard | bb3a8a1 | 2009-01-03 16:23:13 -0600 | [diff] [blame] | 334 | case BOOKE_INTERRUPT_SPE_UNAVAIL: |
| 335 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_UNAVAIL); |
| 336 | r = RESUME_GUEST; |
| 337 | break; |
| 338 | |
| 339 | case BOOKE_INTERRUPT_SPE_FP_DATA: |
| 340 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA); |
| 341 | r = RESUME_GUEST; |
| 342 | break; |
| 343 | |
| 344 | case BOOKE_INTERRUPT_SPE_FP_ROUND: |
| 345 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND); |
| 346 | r = RESUME_GUEST; |
| 347 | break; |
| 348 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 349 | case BOOKE_INTERRUPT_DATA_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 350 | kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear, |
| 351 | vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 352 | kvmppc_account_exit(vcpu, DSI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 353 | r = RESUME_GUEST; |
| 354 | break; |
| 355 | |
| 356 | case BOOKE_INTERRUPT_INST_STORAGE: |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 357 | kvmppc_core_queue_inst_storage(vcpu, vcpu->arch.fault_esr); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 358 | kvmppc_account_exit(vcpu, ISI_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 359 | r = RESUME_GUEST; |
| 360 | break; |
| 361 | |
| 362 | case BOOKE_INTERRUPT_SYSCALL: |
Alexander Graf | 2a342ed | 2010-07-29 14:47:48 +0200 | [diff] [blame] | 363 | if (!(vcpu->arch.shared->msr & MSR_PR) && |
| 364 | (((u32)kvmppc_get_gpr(vcpu, 0)) == KVM_SC_MAGIC_R0)) { |
| 365 | /* KVM PV hypercalls */ |
| 366 | kvmppc_set_gpr(vcpu, 3, kvmppc_kvm_pv(vcpu)); |
| 367 | r = RESUME_GUEST; |
| 368 | } else { |
| 369 | /* Guest syscalls */ |
| 370 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL); |
| 371 | } |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 372 | kvmppc_account_exit(vcpu, SYSCALL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 373 | r = RESUME_GUEST; |
| 374 | break; |
| 375 | |
| 376 | case BOOKE_INTERRUPT_DTLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 377 | unsigned long eaddr = vcpu->arch.fault_dear; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 378 | int gtlb_index; |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 379 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 380 | gfn_t gfn; |
| 381 | |
| 382 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 383 | gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 384 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 385 | /* The guest didn't have a mapping for it. */ |
Liu Yu | daf5e27 | 2010-02-02 19:44:35 +0800 | [diff] [blame] | 386 | kvmppc_core_queue_dtlb_miss(vcpu, |
| 387 | vcpu->arch.fault_dear, |
| 388 | vcpu->arch.fault_esr); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 389 | kvmppc_mmu_dtlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 390 | kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 391 | r = RESUME_GUEST; |
| 392 | break; |
| 393 | } |
| 394 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 395 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 396 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 397 | |
| 398 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 399 | /* The guest TLB had a mapping, but the shadow TLB |
| 400 | * didn't, and it is RAM. This could be because: |
| 401 | * a) the entry is mapping the host kernel, or |
| 402 | * b) the guest used a large mapping which we're faking |
| 403 | * Either way, we need to satisfy the fault without |
| 404 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 405 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 406 | kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 407 | r = RESUME_GUEST; |
| 408 | } else { |
| 409 | /* Guest has mapped and accessed a page which is not |
| 410 | * actually RAM. */ |
Hollis Blanchard | 475e7cd | 2009-01-03 16:23:00 -0600 | [diff] [blame] | 411 | vcpu->arch.paddr_accessed = gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 412 | r = kvmppc_emulate_mmio(run, vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 413 | kvmppc_account_exit(vcpu, MMIO_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | break; |
| 417 | } |
| 418 | |
| 419 | case BOOKE_INTERRUPT_ITLB_MISS: { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 420 | unsigned long eaddr = vcpu->arch.pc; |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 421 | gpa_t gpaddr; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 422 | gfn_t gfn; |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 423 | int gtlb_index; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 424 | |
| 425 | r = RESUME_GUEST; |
| 426 | |
| 427 | /* Check the guest TLB. */ |
Hollis Blanchard | fa86b8d | 2009-01-03 16:23:03 -0600 | [diff] [blame] | 428 | gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr); |
Hollis Blanchard | 7924bd4 | 2008-12-02 15:51:55 -0600 | [diff] [blame] | 429 | if (gtlb_index < 0) { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 430 | /* The guest didn't have a mapping for it. */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 431 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS); |
Hollis Blanchard | b52a638 | 2009-01-03 16:23:11 -0600 | [diff] [blame] | 432 | kvmppc_mmu_itlb_miss(vcpu); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 433 | kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 434 | break; |
| 435 | } |
| 436 | |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 437 | kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 438 | |
Hollis Blanchard | be8d1ca | 2009-01-03 16:23:02 -0600 | [diff] [blame] | 439 | gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr); |
Hollis Blanchard | 8916861 | 2008-12-02 15:51:53 -0600 | [diff] [blame] | 440 | gfn = gpaddr >> PAGE_SHIFT; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 441 | |
| 442 | if (kvm_is_visible_gfn(vcpu->kvm, gfn)) { |
| 443 | /* The guest TLB had a mapping, but the shadow TLB |
| 444 | * didn't. This could be because: |
| 445 | * a) the entry is mapping the host kernel, or |
| 446 | * b) the guest used a large mapping which we're faking |
| 447 | * Either way, we need to satisfy the fault without |
| 448 | * invoking the guest. */ |
Hollis Blanchard | 58a9621 | 2009-01-03 16:23:01 -0600 | [diff] [blame] | 449 | kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 450 | } else { |
| 451 | /* Guest mapped and leaped at non-RAM! */ |
Hollis Blanchard | d4cf389 | 2008-11-05 09:36:23 -0600 | [diff] [blame] | 452 | kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | break; |
| 456 | } |
| 457 | |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 458 | case BOOKE_INTERRUPT_DEBUG: { |
| 459 | u32 dbsr; |
| 460 | |
| 461 | vcpu->arch.pc = mfspr(SPRN_CSRR0); |
| 462 | |
| 463 | /* clear IAC events in DBSR register */ |
| 464 | dbsr = mfspr(SPRN_DBSR); |
| 465 | dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4; |
| 466 | mtspr(SPRN_DBSR, dbsr); |
| 467 | |
| 468 | run->exit_reason = KVM_EXIT_DEBUG; |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 469 | kvmppc_account_exit(vcpu, DEBUG_EXITS); |
Hollis Blanchard | 6a0ab73 | 2008-07-25 13:54:49 -0500 | [diff] [blame] | 470 | r = RESUME_HOST; |
| 471 | break; |
| 472 | } |
| 473 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 474 | default: |
| 475 | printk(KERN_EMERG "exit_nr %d\n", exit_nr); |
| 476 | BUG(); |
| 477 | } |
| 478 | |
| 479 | local_irq_disable(); |
| 480 | |
Hollis Blanchard | 9dd921c | 2008-11-05 09:36:14 -0600 | [diff] [blame] | 481 | kvmppc_core_deliver_interrupts(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 482 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 483 | if (!(r & RESUME_HOST)) { |
| 484 | /* To avoid clobbering exit_reason, only check for signals if |
| 485 | * we aren't already exiting to userspace for some other |
| 486 | * reason. */ |
| 487 | if (signal_pending(current)) { |
| 488 | run->exit_reason = KVM_EXIT_INTR; |
| 489 | r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV); |
Hollis Blanchard | 7b70159 | 2008-12-02 15:51:58 -0600 | [diff] [blame] | 490 | kvmppc_account_exit(vcpu, SIGNAL_EXITS); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
| 494 | return r; |
| 495 | } |
| 496 | |
| 497 | /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */ |
| 498 | int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) |
| 499 | { |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 500 | vcpu->arch.pc = 0; |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 501 | vcpu->arch.shared->msr = 0; |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 502 | kvmppc_set_gpr(vcpu, 1, (16<<20) - 8); /* -8 for the callee-save LR slot */ |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 503 | |
Hollis Blanchard | 49dd2c4 | 2008-07-25 13:54:53 -0500 | [diff] [blame] | 504 | vcpu->arch.shadow_pid = 1; |
| 505 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 506 | /* Eye-catching number so we know if the guest takes an interrupt |
| 507 | * before it's programmed its own IVPR. */ |
| 508 | vcpu->arch.ivpr = 0x55550000; |
| 509 | |
Hollis Blanchard | 73e75b4 | 2008-12-02 15:51:57 -0600 | [diff] [blame] | 510 | kvmppc_init_timing_stats(vcpu); |
| 511 | |
Hollis Blanchard | 5cbb510 | 2008-11-05 09:36:17 -0600 | [diff] [blame] | 512 | return kvmppc_core_vcpu_setup(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 516 | { |
| 517 | int i; |
| 518 | |
| 519 | regs->pc = vcpu->arch.pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 520 | regs->cr = kvmppc_get_cr(vcpu); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 521 | regs->ctr = vcpu->arch.ctr; |
| 522 | regs->lr = vcpu->arch.lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 523 | regs->xer = kvmppc_get_xer(vcpu); |
Alexander Graf | 666e725 | 2010-07-29 14:47:43 +0200 | [diff] [blame] | 524 | regs->msr = vcpu->arch.shared->msr; |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 525 | regs->srr0 = vcpu->arch.shared->srr0; |
| 526 | regs->srr1 = vcpu->arch.shared->srr1; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 527 | regs->pid = vcpu->arch.pid; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 528 | regs->sprg0 = vcpu->arch.shared->sprg0; |
| 529 | regs->sprg1 = vcpu->arch.shared->sprg1; |
| 530 | regs->sprg2 = vcpu->arch.shared->sprg2; |
| 531 | regs->sprg3 = vcpu->arch.shared->sprg3; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 532 | regs->sprg5 = vcpu->arch.sprg4; |
| 533 | regs->sprg6 = vcpu->arch.sprg5; |
| 534 | regs->sprg7 = vcpu->arch.sprg6; |
| 535 | |
| 536 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 537 | regs->gpr[i] = kvmppc_get_gpr(vcpu, i); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) |
| 543 | { |
| 544 | int i; |
| 545 | |
| 546 | vcpu->arch.pc = regs->pc; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 547 | kvmppc_set_cr(vcpu, regs->cr); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 548 | vcpu->arch.ctr = regs->ctr; |
| 549 | vcpu->arch.lr = regs->lr; |
Alexander Graf | 992b5b2 | 2010-01-08 02:58:02 +0100 | [diff] [blame] | 550 | kvmppc_set_xer(vcpu, regs->xer); |
Hollis Blanchard | b8fd68a | 2008-11-05 09:36:20 -0600 | [diff] [blame] | 551 | kvmppc_set_msr(vcpu, regs->msr); |
Alexander Graf | de7906c | 2010-07-29 14:47:46 +0200 | [diff] [blame] | 552 | vcpu->arch.shared->srr0 = regs->srr0; |
| 553 | vcpu->arch.shared->srr1 = regs->srr1; |
Alexander Graf | a73a959 | 2010-07-29 14:47:47 +0200 | [diff] [blame] | 554 | vcpu->arch.shared->sprg0 = regs->sprg0; |
| 555 | vcpu->arch.shared->sprg1 = regs->sprg1; |
| 556 | vcpu->arch.shared->sprg2 = regs->sprg2; |
| 557 | vcpu->arch.shared->sprg3 = regs->sprg3; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 558 | vcpu->arch.sprg5 = regs->sprg4; |
| 559 | vcpu->arch.sprg6 = regs->sprg5; |
| 560 | vcpu->arch.sprg7 = regs->sprg6; |
| 561 | |
Alexander Graf | 8e5b26b | 2010-01-08 02:58:01 +0100 | [diff] [blame] | 562 | for (i = 0; i < ARRAY_SIZE(regs->gpr); i++) |
| 563 | kvmppc_set_gpr(vcpu, i, regs->gpr[i]); |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, |
| 569 | struct kvm_sregs *sregs) |
| 570 | { |
| 571 | return -ENOTSUPP; |
| 572 | } |
| 573 | |
| 574 | int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, |
| 575 | struct kvm_sregs *sregs) |
| 576 | { |
| 577 | return -ENOTSUPP; |
| 578 | } |
| 579 | |
| 580 | int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 581 | { |
| 582 | return -ENOTSUPP; |
| 583 | } |
| 584 | |
| 585 | int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) |
| 586 | { |
| 587 | return -ENOTSUPP; |
| 588 | } |
| 589 | |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 590 | int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, |
| 591 | struct kvm_translation *tr) |
| 592 | { |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 593 | int r; |
| 594 | |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 595 | r = kvmppc_core_vcpu_translate(vcpu, tr); |
Avi Kivity | 98001d8 | 2010-05-13 11:05:49 +0300 | [diff] [blame] | 596 | return r; |
Hollis Blanchard | bbf45ba | 2008-04-16 23:28:09 -0500 | [diff] [blame] | 597 | } |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 598 | |
Alexander Graf | 4e75575 | 2009-10-30 05:47:01 +0000 | [diff] [blame] | 599 | int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) |
| 600 | { |
| 601 | return -ENOTSUPP; |
| 602 | } |
| 603 | |
Stephen Rothwell | 2986b8c | 2009-06-02 11:46:14 +1000 | [diff] [blame] | 604 | int __init kvmppc_booke_init(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 605 | { |
| 606 | unsigned long ivor[16]; |
| 607 | unsigned long max_ivor = 0; |
| 608 | int i; |
| 609 | |
| 610 | /* We install our own exception handlers by hijacking IVPR. IVPR must |
| 611 | * be 16-bit aligned, so we need a 64KB allocation. */ |
| 612 | kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 613 | VCPU_SIZE_ORDER); |
| 614 | if (!kvmppc_booke_handlers) |
| 615 | return -ENOMEM; |
| 616 | |
| 617 | /* XXX make sure our handlers are smaller than Linux's */ |
| 618 | |
| 619 | /* Copy our interrupt handlers to match host IVORs. That way we don't |
| 620 | * have to swap the IVORs on every guest/host transition. */ |
| 621 | ivor[0] = mfspr(SPRN_IVOR0); |
| 622 | ivor[1] = mfspr(SPRN_IVOR1); |
| 623 | ivor[2] = mfspr(SPRN_IVOR2); |
| 624 | ivor[3] = mfspr(SPRN_IVOR3); |
| 625 | ivor[4] = mfspr(SPRN_IVOR4); |
| 626 | ivor[5] = mfspr(SPRN_IVOR5); |
| 627 | ivor[6] = mfspr(SPRN_IVOR6); |
| 628 | ivor[7] = mfspr(SPRN_IVOR7); |
| 629 | ivor[8] = mfspr(SPRN_IVOR8); |
| 630 | ivor[9] = mfspr(SPRN_IVOR9); |
| 631 | ivor[10] = mfspr(SPRN_IVOR10); |
| 632 | ivor[11] = mfspr(SPRN_IVOR11); |
| 633 | ivor[12] = mfspr(SPRN_IVOR12); |
| 634 | ivor[13] = mfspr(SPRN_IVOR13); |
| 635 | ivor[14] = mfspr(SPRN_IVOR14); |
| 636 | ivor[15] = mfspr(SPRN_IVOR15); |
| 637 | |
| 638 | for (i = 0; i < 16; i++) { |
| 639 | if (ivor[i] > max_ivor) |
| 640 | max_ivor = ivor[i]; |
| 641 | |
| 642 | memcpy((void *)kvmppc_booke_handlers + ivor[i], |
| 643 | kvmppc_handlers_start + i * kvmppc_handler_len, |
| 644 | kvmppc_handler_len); |
| 645 | } |
| 646 | flush_icache_range(kvmppc_booke_handlers, |
| 647 | kvmppc_booke_handlers + max_ivor + kvmppc_handler_len); |
| 648 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 649 | return 0; |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 650 | } |
| 651 | |
Hollis Blanchard | db93f57 | 2008-11-05 09:36:18 -0600 | [diff] [blame] | 652 | void __exit kvmppc_booke_exit(void) |
Hollis Blanchard | d9fbd03 | 2008-11-05 09:36:13 -0600 | [diff] [blame] | 653 | { |
| 654 | free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER); |
| 655 | kvm_exit(); |
| 656 | } |