Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QEMU S390x KVM implementation |
| 3 | * |
| 4 | * Copyright (c) 2009 Alexander Graf <agraf@suse.de> |
Christian Borntraeger | ccb084d | 2012-11-12 01:44:10 +0000 | [diff] [blame] | 5 | * Copyright IBM Corp. 2012 |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
Christian Borntraeger | ccb084d | 2012-11-12 01:44:10 +0000 | [diff] [blame] | 17 | * Contributions after 2012-10-29 are licensed under the terms of the |
| 18 | * GNU GPL, version 2 or (at your option) any later version. |
| 19 | * |
| 20 | * You should have received a copy of the GNU (Lesser) General Public |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 21 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/ioctl.h> |
| 26 | #include <sys/mman.h> |
| 27 | |
| 28 | #include <linux/kvm.h> |
| 29 | #include <asm/ptrace.h> |
| 30 | |
| 31 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 32 | #include "qemu/timer.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 33 | #include "sysemu/sysemu.h" |
| 34 | #include "sysemu/kvm.h" |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 35 | #include "cpu.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 36 | #include "sysemu/device_tree.h" |
Christian Borntraeger | 08eb8c8 | 2013-04-26 11:24:47 +0800 | [diff] [blame] | 37 | #include "qapi/qmp/qjson.h" |
| 38 | #include "monitor/monitor.h" |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 39 | |
| 40 | /* #define DEBUG_KVM */ |
| 41 | |
| 42 | #ifdef DEBUG_KVM |
Peter Maydell | e67137c | 2013-07-29 13:16:37 +0100 | [diff] [blame] | 43 | #define DPRINTF(fmt, ...) \ |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 44 | do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) |
| 45 | #else |
Peter Maydell | e67137c | 2013-07-29 13:16:37 +0100 | [diff] [blame] | 46 | #define DPRINTF(fmt, ...) \ |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 47 | do { } while (0) |
| 48 | #endif |
| 49 | |
| 50 | #define IPA0_DIAG 0x8300 |
| 51 | #define IPA0_SIGP 0xae00 |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 52 | #define IPA0_B2 0xb200 |
| 53 | #define IPA0_B9 0xb900 |
| 54 | #define IPA0_EB 0xeb00 |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 55 | |
| 56 | #define PRIV_SCLP_CALL 0x20 |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 57 | #define PRIV_CSCH 0x30 |
| 58 | #define PRIV_HSCH 0x31 |
| 59 | #define PRIV_MSCH 0x32 |
| 60 | #define PRIV_SSCH 0x33 |
| 61 | #define PRIV_STSCH 0x34 |
| 62 | #define PRIV_TSCH 0x35 |
| 63 | #define PRIV_TPI 0x36 |
| 64 | #define PRIV_SAL 0x37 |
| 65 | #define PRIV_RSCH 0x38 |
| 66 | #define PRIV_STCRW 0x39 |
| 67 | #define PRIV_STCPS 0x3a |
| 68 | #define PRIV_RCHP 0x3b |
| 69 | #define PRIV_SCHM 0x3c |
| 70 | #define PRIV_CHSC 0x5f |
| 71 | #define PRIV_SIGA 0x74 |
| 72 | #define PRIV_XSCH 0x76 |
| 73 | #define PRIV_SQBS 0x8a |
| 74 | #define PRIV_EQBS 0x9c |
Eugene (jno) Dvurechenski | 268846b | 2013-06-19 17:27:15 +0200 | [diff] [blame] | 75 | #define DIAG_IPL 0x308 |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 76 | #define DIAG_KVM_HYPERCALL 0x500 |
| 77 | #define DIAG_KVM_BREAKPOINT 0x501 |
| 78 | |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 79 | #define ICPT_INSTRUCTION 0x04 |
| 80 | #define ICPT_WAITPSW 0x1c |
| 81 | #define ICPT_SOFT_INTERCEPT 0x24 |
| 82 | #define ICPT_CPU_STOP 0x28 |
| 83 | #define ICPT_IO 0x40 |
| 84 | |
Jan Kiszka | 94a8d39 | 2011-01-21 21:48:17 +0100 | [diff] [blame] | 85 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { |
| 86 | KVM_CAP_LAST_INFO |
| 87 | }; |
| 88 | |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 89 | static int cap_sync_regs; |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 90 | static int cap_async_pf; |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 91 | |
Stefan Weil | 575ddeb | 2013-09-29 20:56:45 +0200 | [diff] [blame] | 92 | static void *legacy_s390_alloc(size_t size); |
Markus Armbruster | 9113803 | 2013-07-31 15:11:08 +0200 | [diff] [blame] | 93 | |
Jan Kiszka | cad1e28 | 2011-01-21 21:48:16 +0100 | [diff] [blame] | 94 | int kvm_arch_init(KVMState *s) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 95 | { |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 96 | cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS); |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 97 | cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF); |
Markus Armbruster | 9113803 | 2013-07-31 15:11:08 +0200 | [diff] [blame] | 98 | if (!kvm_check_extension(s, KVM_CAP_S390_GMAP) |
| 99 | || !kvm_check_extension(s, KVM_CAP_S390_COW)) { |
| 100 | phys_mem_set_alloc(legacy_s390_alloc); |
| 101 | } |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Eduardo Habkost | b164e48 | 2013-01-22 18:25:01 -0200 | [diff] [blame] | 105 | unsigned long kvm_arch_vcpu_id(CPUState *cpu) |
| 106 | { |
| 107 | return cpu->cpu_index; |
| 108 | } |
| 109 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 110 | int kvm_arch_init_vcpu(CPUState *cpu) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 111 | { |
Christian Borntraeger | 1c9d2a1 | 2013-02-04 22:53:25 +0000 | [diff] [blame] | 112 | /* nothing todo yet */ |
| 113 | return 0; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 116 | void kvm_arch_reset_vcpu(CPUState *cpu) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 117 | { |
Alexander Graf | 419831d | 2013-01-07 16:44:27 +0100 | [diff] [blame] | 118 | /* The initial reset call is needed here to reset in-kernel |
| 119 | * vcpu data that we can't access directly from QEMU |
| 120 | * (i.e. with older kernels which don't support sync_regs/ONE_REG). |
| 121 | * Before this ioctl cpu_synchronize_state() is called in common kvm |
| 122 | * code (kvm-all) */ |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 123 | if (kvm_vcpu_ioctl(cpu, KVM_S390_INITIAL_RESET, NULL)) { |
| 124 | perror("Can't reset vcpu\n"); |
| 125 | } |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 126 | } |
| 127 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 128 | int kvm_arch_put_registers(CPUState *cs, int level) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 129 | { |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 130 | S390CPU *cpu = S390_CPU(cs); |
| 131 | CPUS390XState *env = &cpu->env; |
Jason J. Herne | 420840e | 2013-04-25 04:25:50 +0000 | [diff] [blame] | 132 | struct kvm_one_reg reg; |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 133 | struct kvm_sregs sregs; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 134 | struct kvm_regs regs; |
| 135 | int ret; |
| 136 | int i; |
| 137 | |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 138 | /* always save the PSW and the GPRS*/ |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 139 | cs->kvm_run->psw_addr = env->psw.addr; |
| 140 | cs->kvm_run->psw_mask = env->psw.mask; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 141 | |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 142 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) { |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 143 | for (i = 0; i < 16; i++) { |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 144 | cs->kvm_run->s.regs.gprs[i] = env->regs[i]; |
| 145 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_GPRS; |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 146 | } |
| 147 | } else { |
| 148 | for (i = 0; i < 16; i++) { |
| 149 | regs.gprs[i] = env->regs[i]; |
| 150 | } |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 151 | ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, ®s); |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 152 | if (ret < 0) { |
| 153 | return ret; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* Do we need to save more than that? */ |
| 158 | if (level == KVM_PUT_RUNTIME_STATE) { |
| 159 | return 0; |
| 160 | } |
| 161 | |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 162 | reg.id = KVM_REG_S390_CPU_TIMER; |
| 163 | reg.addr = (__u64)&(env->cputm); |
| 164 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); |
| 165 | if (ret < 0) { |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | reg.id = KVM_REG_S390_CLOCK_COMP; |
| 170 | reg.addr = (__u64)&(env->ckc); |
| 171 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); |
| 172 | if (ret < 0) { |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | reg.id = KVM_REG_S390_TODPR; |
| 177 | reg.addr = (__u64)&(env->todpr); |
| 178 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); |
| 179 | if (ret < 0) { |
| 180 | return ret; |
| 181 | } |
| 182 | |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 183 | if (cap_async_pf) { |
| 184 | reg.id = KVM_REG_S390_PFTOKEN; |
| 185 | reg.addr = (__u64)&(env->pfault_token); |
| 186 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); |
| 187 | if (ret < 0) { |
| 188 | return ret; |
| 189 | } |
| 190 | |
| 191 | reg.id = KVM_REG_S390_PFCOMPARE; |
| 192 | reg.addr = (__u64)&(env->pfault_compare); |
| 193 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); |
| 194 | if (ret < 0) { |
| 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | reg.id = KVM_REG_S390_PFSELECT; |
| 199 | reg.addr = (__u64)&(env->pfault_select); |
| 200 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); |
| 201 | if (ret < 0) { |
| 202 | return ret; |
| 203 | } |
| 204 | } |
| 205 | |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 206 | if (cap_sync_regs && |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 207 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS && |
| 208 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) { |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 209 | for (i = 0; i < 16; i++) { |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 210 | cs->kvm_run->s.regs.acrs[i] = env->aregs[i]; |
| 211 | cs->kvm_run->s.regs.crs[i] = env->cregs[i]; |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 212 | } |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 213 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ACRS; |
| 214 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_CRS; |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 215 | } else { |
| 216 | for (i = 0; i < 16; i++) { |
| 217 | sregs.acrs[i] = env->aregs[i]; |
| 218 | sregs.crs[i] = env->cregs[i]; |
| 219 | } |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 220 | ret = kvm_vcpu_ioctl(cs, KVM_SET_SREGS, &sregs); |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 221 | if (ret < 0) { |
| 222 | return ret; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /* Finally the prefix */ |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 227 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) { |
| 228 | cs->kvm_run->s.regs.prefix = env->psa; |
| 229 | cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_PREFIX; |
Christian Borntraeger | 5b08b34 | 2012-10-29 02:13:21 +0000 | [diff] [blame] | 230 | } else { |
| 231 | /* prefix is only supported via sync regs */ |
| 232 | } |
| 233 | return 0; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 236 | int kvm_arch_get_registers(CPUState *cs) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 237 | { |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 238 | S390CPU *cpu = S390_CPU(cs); |
| 239 | CPUS390XState *env = &cpu->env; |
Jason J. Herne | 420840e | 2013-04-25 04:25:50 +0000 | [diff] [blame] | 240 | struct kvm_one_reg reg; |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 241 | struct kvm_sregs sregs; |
| 242 | struct kvm_regs regs; |
| 243 | int i, r; |
Jason J. Herne | 420840e | 2013-04-25 04:25:50 +0000 | [diff] [blame] | 244 | |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 245 | /* get the PSW */ |
| 246 | env->psw.addr = cs->kvm_run->psw_addr; |
| 247 | env->psw.mask = cs->kvm_run->psw_mask; |
| 248 | |
| 249 | /* the GPRS */ |
| 250 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_GPRS) { |
| 251 | for (i = 0; i < 16; i++) { |
| 252 | env->regs[i] = cs->kvm_run->s.regs.gprs[i]; |
| 253 | } |
| 254 | } else { |
| 255 | r = kvm_vcpu_ioctl(cs, KVM_GET_REGS, ®s); |
| 256 | if (r < 0) { |
| 257 | return r; |
| 258 | } |
| 259 | for (i = 0; i < 16; i++) { |
| 260 | env->regs[i] = regs.gprs[i]; |
| 261 | } |
Jason J. Herne | 420840e | 2013-04-25 04:25:50 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 264 | /* The ACRS and CRS */ |
| 265 | if (cap_sync_regs && |
| 266 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_ACRS && |
| 267 | cs->kvm_run->kvm_valid_regs & KVM_SYNC_CRS) { |
| 268 | for (i = 0; i < 16; i++) { |
| 269 | env->aregs[i] = cs->kvm_run->s.regs.acrs[i]; |
| 270 | env->cregs[i] = cs->kvm_run->s.regs.crs[i]; |
| 271 | } |
| 272 | } else { |
| 273 | r = kvm_vcpu_ioctl(cs, KVM_GET_SREGS, &sregs); |
| 274 | if (r < 0) { |
| 275 | return r; |
| 276 | } |
| 277 | for (i = 0; i < 16; i++) { |
| 278 | env->aregs[i] = sregs.acrs[i]; |
| 279 | env->cregs[i] = sregs.crs[i]; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /* The prefix */ |
| 284 | if (cap_sync_regs && cs->kvm_run->kvm_valid_regs & KVM_SYNC_PREFIX) { |
| 285 | env->psa = cs->kvm_run->s.regs.prefix; |
| 286 | } |
| 287 | |
| 288 | /* One Regs */ |
Jason J. Herne | 420840e | 2013-04-25 04:25:50 +0000 | [diff] [blame] | 289 | reg.id = KVM_REG_S390_CPU_TIMER; |
| 290 | reg.addr = (__u64)&(env->cputm); |
| 291 | r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); |
| 292 | if (r < 0) { |
| 293 | return r; |
| 294 | } |
| 295 | |
| 296 | reg.id = KVM_REG_S390_CLOCK_COMP; |
| 297 | reg.addr = (__u64)&(env->ckc); |
| 298 | r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); |
| 299 | if (r < 0) { |
| 300 | return r; |
| 301 | } |
| 302 | |
| 303 | reg.id = KVM_REG_S390_TODPR; |
| 304 | reg.addr = (__u64)&(env->todpr); |
| 305 | r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); |
| 306 | if (r < 0) { |
| 307 | return r; |
| 308 | } |
| 309 | |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 310 | if (cap_async_pf) { |
| 311 | reg.id = KVM_REG_S390_PFTOKEN; |
| 312 | reg.addr = (__u64)&(env->pfault_token); |
| 313 | r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); |
| 314 | if (r < 0) { |
| 315 | return r; |
| 316 | } |
| 317 | |
| 318 | reg.id = KVM_REG_S390_PFCOMPARE; |
| 319 | reg.addr = (__u64)&(env->pfault_compare); |
| 320 | r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); |
| 321 | if (r < 0) { |
| 322 | return r; |
| 323 | } |
| 324 | |
| 325 | reg.id = KVM_REG_S390_PFSELECT; |
| 326 | reg.addr = (__u64)&(env->pfault_select); |
| 327 | r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); |
| 328 | if (r < 0) { |
| 329 | return r; |
| 330 | } |
| 331 | } |
| 332 | |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
Christian Borntraeger | fdec991 | 2012-06-15 05:10:30 +0000 | [diff] [blame] | 336 | /* |
| 337 | * Legacy layout for s390: |
| 338 | * Older S390 KVM requires the topmost vma of the RAM to be |
| 339 | * smaller than an system defined value, which is at least 256GB. |
| 340 | * Larger systems have larger values. We put the guest between |
| 341 | * the end of data segment (system break) and this value. We |
| 342 | * use 32GB as a base to have enough room for the system break |
| 343 | * to grow. We also have to use MAP parameters that avoid |
| 344 | * read-only mapping of guest pages. |
| 345 | */ |
Stefan Weil | 575ddeb | 2013-09-29 20:56:45 +0200 | [diff] [blame] | 346 | static void *legacy_s390_alloc(size_t size) |
Christian Borntraeger | fdec991 | 2012-06-15 05:10:30 +0000 | [diff] [blame] | 347 | { |
| 348 | void *mem; |
| 349 | |
| 350 | mem = mmap((void *) 0x800000000ULL, size, |
| 351 | PROT_EXEC|PROT_READ|PROT_WRITE, |
| 352 | MAP_SHARED | MAP_ANONYMOUS | MAP_FIXED, -1, 0); |
Markus Armbruster | 3922825 | 2013-07-31 15:11:11 +0200 | [diff] [blame] | 353 | return mem == MAP_FAILED ? NULL : mem; |
Christian Borntraeger | fdec991 | 2012-06-15 05:10:30 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 356 | int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 357 | { |
| 358 | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
| 359 | |
Christian Borntraeger | 9282b73 | 2013-07-26 17:48:06 +0200 | [diff] [blame] | 360 | if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || |
| 361 | cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)diag_501, 4, 1)) { |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 362 | return -EINVAL; |
| 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 367 | int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 368 | { |
| 369 | uint8_t t[4]; |
| 370 | static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01}; |
| 371 | |
Christian Borntraeger | 9282b73 | 2013-07-26 17:48:06 +0200 | [diff] [blame] | 372 | if (cpu_memory_rw_debug(cs, bp->pc, t, 4, 0)) { |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 373 | return -EINVAL; |
| 374 | } else if (memcmp(t, diag_501, 4)) { |
| 375 | return -EINVAL; |
Christian Borntraeger | 9282b73 | 2013-07-26 17:48:06 +0200 | [diff] [blame] | 376 | } else if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) { |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 377 | return -EINVAL; |
| 378 | } |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 383 | void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 384 | { |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 387 | void kvm_arch_post_run(CPUState *cpu, struct kvm_run *run) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 388 | { |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 391 | int kvm_arch_process_async_events(CPUState *cs) |
Marcelo Tosatti | 0af691d | 2010-05-04 09:45:27 -0300 | [diff] [blame] | 392 | { |
Cornelia Huck | 225dc99 | 2013-03-15 10:57:40 +0100 | [diff] [blame] | 393 | return cs->halted; |
Marcelo Tosatti | 0af691d | 2010-05-04 09:45:27 -0300 | [diff] [blame] | 394 | } |
| 395 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 396 | void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, |
Alexander Graf | bcec36e | 2011-04-15 17:32:47 +0200 | [diff] [blame] | 397 | uint64_t parm64, int vm) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 398 | { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 399 | CPUState *cs = CPU(cpu); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 400 | struct kvm_s390_interrupt kvmint; |
| 401 | int r; |
| 402 | |
Andreas Färber | a60f24b | 2012-12-01 05:35:08 +0100 | [diff] [blame] | 403 | if (!cs->kvm_state) { |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 404 | return; |
| 405 | } |
| 406 | |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 407 | kvmint.type = type; |
| 408 | kvmint.parm = parm; |
| 409 | kvmint.parm64 = parm64; |
| 410 | |
| 411 | if (vm) { |
Andreas Färber | a60f24b | 2012-12-01 05:35:08 +0100 | [diff] [blame] | 412 | r = kvm_vm_ioctl(cs->kvm_state, KVM_S390_INTERRUPT, &kvmint); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 413 | } else { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 414 | r = kvm_vcpu_ioctl(cs, KVM_S390_INTERRUPT, &kvmint); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | if (r < 0) { |
| 418 | fprintf(stderr, "KVM failed to inject interrupt\n"); |
| 419 | exit(1); |
| 420 | } |
| 421 | } |
| 422 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 423 | void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 424 | { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 425 | kvm_s390_interrupt_internal(cpu, KVM_S390_INT_VIRTIO, config_change, |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 426 | token, 1); |
| 427 | } |
| 428 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 429 | void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 430 | { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 431 | kvm_s390_interrupt_internal(cpu, type, code, 0, 0); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 434 | static void enter_pgmcheck(S390CPU *cpu, uint16_t code) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 435 | { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 436 | kvm_s390_interrupt(cpu, KVM_S390_PROGRAM_INT, code); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 439 | static int kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run, |
Alexander Graf | bcec36e | 2011-04-15 17:32:47 +0200 | [diff] [blame] | 440 | uint16_t ipbh0) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 441 | { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 442 | CPUS390XState *env = &cpu->env; |
Thomas Huth | a0fa2cb | 2014-01-13 12:19:03 +0100 | [diff] [blame] | 443 | uint64_t sccb; |
| 444 | uint32_t code; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 445 | int r = 0; |
| 446 | |
Andreas Färber | cb446ec | 2013-05-01 14:24:52 +0200 | [diff] [blame] | 447 | cpu_synchronize_state(CPU(cpu)); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 448 | sccb = env->regs[ipbh0 & 0xf]; |
| 449 | code = env->regs[(ipbh0 & 0xf0) >> 4]; |
| 450 | |
Thomas Huth | 6e25280 | 2014-01-13 12:55:55 +0100 | [diff] [blame^] | 451 | r = sclp_service_call(env, sccb, code); |
Christian Borntraeger | 9abf567 | 2012-07-23 21:37:04 +0000 | [diff] [blame] | 452 | if (r < 0) { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 453 | enter_pgmcheck(cpu, -r); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 454 | } |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 455 | setcc(cpu, r); |
Alexander Graf | 81f7c56 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 456 | |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 457 | return 0; |
| 458 | } |
| 459 | |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 460 | static int kvm_handle_css_inst(S390CPU *cpu, struct kvm_run *run, |
| 461 | uint8_t ipa0, uint8_t ipa1, uint8_t ipb) |
| 462 | { |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 463 | CPUS390XState *env = &cpu->env; |
| 464 | |
| 465 | if (ipa0 != 0xb2) { |
| 466 | /* Not handled for now. */ |
| 467 | return -1; |
| 468 | } |
Jason J. Herne | 3474b67 | 2013-04-25 04:25:51 +0000 | [diff] [blame] | 469 | |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 470 | cpu_synchronize_state(CPU(cpu)); |
Jason J. Herne | 3474b67 | 2013-04-25 04:25:51 +0000 | [diff] [blame] | 471 | |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 472 | switch (ipa1) { |
| 473 | case PRIV_XSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 474 | ioinst_handle_xsch(cpu, env->regs[1]); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 475 | break; |
| 476 | case PRIV_CSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 477 | ioinst_handle_csch(cpu, env->regs[1]); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 478 | break; |
| 479 | case PRIV_HSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 480 | ioinst_handle_hsch(cpu, env->regs[1]); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 481 | break; |
| 482 | case PRIV_MSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 483 | ioinst_handle_msch(cpu, env->regs[1], run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 484 | break; |
| 485 | case PRIV_SSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 486 | ioinst_handle_ssch(cpu, env->regs[1], run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 487 | break; |
| 488 | case PRIV_STCRW: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 489 | ioinst_handle_stcrw(cpu, run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 490 | break; |
| 491 | case PRIV_STSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 492 | ioinst_handle_stsch(cpu, env->regs[1], run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 493 | break; |
| 494 | case PRIV_TSCH: |
| 495 | /* We should only get tsch via KVM_EXIT_S390_TSCH. */ |
| 496 | fprintf(stderr, "Spurious tsch intercept\n"); |
| 497 | break; |
| 498 | case PRIV_CHSC: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 499 | ioinst_handle_chsc(cpu, run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 500 | break; |
| 501 | case PRIV_TPI: |
| 502 | /* This should have been handled by kvm already. */ |
| 503 | fprintf(stderr, "Spurious tpi intercept\n"); |
| 504 | break; |
| 505 | case PRIV_SCHM: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 506 | ioinst_handle_schm(cpu, env->regs[1], env->regs[2], |
| 507 | run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 508 | break; |
| 509 | case PRIV_RSCH: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 510 | ioinst_handle_rsch(cpu, env->regs[1]); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 511 | break; |
| 512 | case PRIV_RCHP: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 513 | ioinst_handle_rchp(cpu, env->regs[1]); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 514 | break; |
| 515 | case PRIV_STCPS: |
| 516 | /* We do not provide this instruction, it is suppressed. */ |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 517 | break; |
| 518 | case PRIV_SAL: |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 519 | ioinst_handle_sal(cpu, env->regs[1]); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 520 | break; |
Thomas Huth | c1e8dfb | 2013-06-24 15:17:34 +0200 | [diff] [blame] | 521 | case PRIV_SIGA: |
| 522 | /* Not provided, set CC = 3 for subchannel not operational */ |
Thomas Huth | 5d9bf1c | 2013-07-01 15:44:18 +0200 | [diff] [blame] | 523 | setcc(cpu, 3); |
Thomas Huth | c1e8dfb | 2013-06-24 15:17:34 +0200 | [diff] [blame] | 524 | break; |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 525 | default: |
Thomas Huth | c1e8dfb | 2013-06-24 15:17:34 +0200 | [diff] [blame] | 526 | return -1; |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Thomas Huth | c1e8dfb | 2013-06-24 15:17:34 +0200 | [diff] [blame] | 529 | return 0; |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static int handle_priv(S390CPU *cpu, struct kvm_run *run, |
| 533 | uint8_t ipa0, uint8_t ipa1) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 534 | { |
| 535 | int r = 0; |
| 536 | uint16_t ipbh0 = (run->s390_sieic.ipb & 0xffff0000) >> 16; |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 537 | uint8_t ipb = run->s390_sieic.ipb & 0xff; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 538 | |
Peter Maydell | e67137c | 2013-07-29 13:16:37 +0100 | [diff] [blame] | 539 | DPRINTF("KVM: PRIV: %d\n", ipa1); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 540 | switch (ipa1) { |
| 541 | case PRIV_SCLP_CALL: |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 542 | r = kvm_sclp_service_call(cpu, run, ipbh0); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 543 | break; |
| 544 | default: |
Thomas Huth | c1e8dfb | 2013-06-24 15:17:34 +0200 | [diff] [blame] | 545 | r = kvm_handle_css_inst(cpu, run, ipa0, ipa1, ipb); |
| 546 | if (r == -1) { |
| 547 | DPRINTF("KVM: unhandled PRIV: 0x%x\n", ipa1); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 548 | } |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | |
| 552 | return r; |
| 553 | } |
| 554 | |
Andreas Färber | 4fd6dd0 | 2013-06-21 17:17:00 +0200 | [diff] [blame] | 555 | static int handle_hypercall(S390CPU *cpu, struct kvm_run *run) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 556 | { |
Andreas Färber | 4fd6dd0 | 2013-06-21 17:17:00 +0200 | [diff] [blame] | 557 | CPUS390XState *env = &cpu->env; |
Thomas Huth | 77319f2 | 2014-01-14 13:32:23 +0100 | [diff] [blame] | 558 | int ret; |
Jason J. Herne | 3474b67 | 2013-04-25 04:25:51 +0000 | [diff] [blame] | 559 | |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 560 | cpu_synchronize_state(CPU(cpu)); |
Thomas Huth | 77319f2 | 2014-01-14 13:32:23 +0100 | [diff] [blame] | 561 | ret = s390_virtio_hypercall(env); |
| 562 | if (ret == -EINVAL) { |
| 563 | enter_pgmcheck(cpu, PGM_SPECIFICATION); |
| 564 | return 0; |
| 565 | } |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 566 | |
Thomas Huth | 77319f2 | 2014-01-14 13:32:23 +0100 | [diff] [blame] | 567 | return ret; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Eugene (jno) Dvurechenski | 268846b | 2013-06-19 17:27:15 +0200 | [diff] [blame] | 570 | static void kvm_handle_diag_308(S390CPU *cpu, struct kvm_run *run) |
| 571 | { |
| 572 | uint64_t r1, r3; |
| 573 | |
| 574 | cpu_synchronize_state(CPU(cpu)); |
| 575 | r1 = (run->s390_sieic.ipa & 0x00f0) >> 8; |
| 576 | r3 = run->s390_sieic.ipa & 0x000f; |
| 577 | handle_diag_308(&cpu->env, r1, r3); |
| 578 | } |
| 579 | |
Cornelia Huck | 638129f | 2013-12-17 18:27:33 +0100 | [diff] [blame] | 580 | #define DIAG_KVM_CODE_MASK 0x000000000000ffff |
| 581 | |
| 582 | static int handle_diag(S390CPU *cpu, struct kvm_run *run, uint32_t ipb) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 583 | { |
| 584 | int r = 0; |
Cornelia Huck | 638129f | 2013-12-17 18:27:33 +0100 | [diff] [blame] | 585 | uint16_t func_code; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 586 | |
Cornelia Huck | 638129f | 2013-12-17 18:27:33 +0100 | [diff] [blame] | 587 | /* |
| 588 | * For any diagnose call we support, bits 48-63 of the resulting |
| 589 | * address specify the function code; the remainder is ignored. |
| 590 | */ |
| 591 | func_code = decode_basedisp_rs(&cpu->env, ipb) & DIAG_KVM_CODE_MASK; |
| 592 | switch (func_code) { |
Eugene (jno) Dvurechenski | 268846b | 2013-06-19 17:27:15 +0200 | [diff] [blame] | 593 | case DIAG_IPL: |
| 594 | kvm_handle_diag_308(cpu, run); |
| 595 | break; |
Christian Borntraeger | 39fbc5c | 2013-08-30 11:06:56 +0200 | [diff] [blame] | 596 | case DIAG_KVM_HYPERCALL: |
| 597 | r = handle_hypercall(cpu, run); |
| 598 | break; |
| 599 | case DIAG_KVM_BREAKPOINT: |
| 600 | sleep(10); |
| 601 | break; |
| 602 | default: |
Cornelia Huck | 638129f | 2013-12-17 18:27:33 +0100 | [diff] [blame] | 603 | DPRINTF("KVM: unknown DIAG: 0x%x\n", func_code); |
Christian Borntraeger | 39fbc5c | 2013-08-30 11:06:56 +0200 | [diff] [blame] | 604 | r = -1; |
| 605 | break; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | return r; |
| 609 | } |
| 610 | |
Thomas Huth | b20a461 | 2013-12-17 14:22:07 +0100 | [diff] [blame] | 611 | static int kvm_s390_cpu_start(S390CPU *cpu) |
| 612 | { |
| 613 | s390_add_running_cpu(cpu); |
| 614 | qemu_cpu_kick(CPU(cpu)); |
| 615 | DPRINTF("DONE: KVM cpu start: %p\n", &cpu->env); |
| 616 | return 0; |
| 617 | } |
| 618 | |
Eugene (jno) Dvurechenski | 7f7f975 | 2012-12-05 15:50:07 +0100 | [diff] [blame] | 619 | int kvm_s390_cpu_restart(S390CPU *cpu) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 620 | { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 621 | kvm_s390_interrupt(cpu, KVM_S390_RESTART, 0); |
Andreas Färber | 49e1587 | 2013-01-30 12:48:25 +0000 | [diff] [blame] | 622 | s390_add_running_cpu(cpu); |
Andreas Färber | c08d742 | 2012-05-03 04:34:15 +0200 | [diff] [blame] | 623 | qemu_cpu_kick(CPU(cpu)); |
Eugene (jno) Dvurechenski | 7f7f975 | 2012-12-05 15:50:07 +0100 | [diff] [blame] | 624 | DPRINTF("DONE: KVM cpu restart: %p\n", &cpu->env); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 625 | return 0; |
| 626 | } |
| 627 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 628 | static int s390_cpu_initial_reset(S390CPU *cpu) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 629 | { |
Andreas Färber | cb446ec | 2013-05-01 14:24:52 +0200 | [diff] [blame] | 630 | CPUState *cs = CPU(cpu); |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 631 | CPUS390XState *env = &cpu->env; |
Alexander Graf | d590081 | 2010-05-14 16:14:31 +0200 | [diff] [blame] | 632 | int i; |
| 633 | |
Andreas Färber | 49e1587 | 2013-01-30 12:48:25 +0000 | [diff] [blame] | 634 | s390_del_running_cpu(cpu); |
Andreas Färber | cb446ec | 2013-05-01 14:24:52 +0200 | [diff] [blame] | 635 | if (kvm_vcpu_ioctl(cs, KVM_S390_INITIAL_RESET, NULL) < 0) { |
Alexander Graf | d590081 | 2010-05-14 16:14:31 +0200 | [diff] [blame] | 636 | perror("cannot init reset vcpu"); |
| 637 | } |
| 638 | |
| 639 | /* Manually zero out all registers */ |
Andreas Färber | cb446ec | 2013-05-01 14:24:52 +0200 | [diff] [blame] | 640 | cpu_synchronize_state(cs); |
Alexander Graf | d590081 | 2010-05-14 16:14:31 +0200 | [diff] [blame] | 641 | for (i = 0; i < 16; i++) { |
| 642 | env->regs[i] = 0; |
| 643 | } |
| 644 | |
Peter Maydell | e67137c | 2013-07-29 13:16:37 +0100 | [diff] [blame] | 645 | DPRINTF("DONE: SIGP initial reset: %p\n", env); |
Alexander Graf | d590081 | 2010-05-14 16:14:31 +0200 | [diff] [blame] | 646 | return 0; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 647 | } |
| 648 | |
Thomas Huth | b8031ad | 2013-12-17 14:22:08 +0100 | [diff] [blame] | 649 | #define SIGP_ORDER_MASK 0x000000ff |
| 650 | |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 651 | static int handle_sigp(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 652 | { |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 653 | CPUS390XState *env = &cpu->env; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 654 | uint8_t order_code; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 655 | uint16_t cpu_addr; |
Andreas Färber | 45fa769 | 2012-05-03 04:28:14 +0200 | [diff] [blame] | 656 | S390CPU *target_cpu; |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 657 | uint64_t *statusreg = &env->regs[ipa1 >> 4]; |
| 658 | int cc; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 659 | |
Andreas Färber | cb446ec | 2013-05-01 14:24:52 +0200 | [diff] [blame] | 660 | cpu_synchronize_state(CPU(cpu)); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 661 | |
| 662 | /* get order code */ |
Thomas Huth | b8031ad | 2013-12-17 14:22:08 +0100 | [diff] [blame] | 663 | order_code = decode_basedisp_rs(env, run->s390_sieic.ipb) & SIGP_ORDER_MASK; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 664 | |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 665 | cpu_addr = env->regs[ipa1 & 0x0f]; |
Andreas Färber | 45fa769 | 2012-05-03 04:28:14 +0200 | [diff] [blame] | 666 | target_cpu = s390_cpu_addr2state(cpu_addr); |
| 667 | if (target_cpu == NULL) { |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 668 | cc = 3; /* not operational */ |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 669 | goto out; |
| 670 | } |
| 671 | |
| 672 | switch (order_code) { |
Thomas Huth | b20a461 | 2013-12-17 14:22:07 +0100 | [diff] [blame] | 673 | case SIGP_START: |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 674 | cc = kvm_s390_cpu_start(target_cpu); |
Thomas Huth | b20a461 | 2013-12-17 14:22:07 +0100 | [diff] [blame] | 675 | break; |
Thomas Huth | 0b9972a | 2013-12-17 14:22:06 +0100 | [diff] [blame] | 676 | case SIGP_RESTART: |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 677 | cc = kvm_s390_cpu_restart(target_cpu); |
Thomas Huth | 0b9972a | 2013-12-17 14:22:06 +0100 | [diff] [blame] | 678 | break; |
| 679 | case SIGP_SET_ARCH: |
Thomas Huth | 0788082 | 2014-01-22 17:02:46 +0100 | [diff] [blame] | 680 | *statusreg &= 0xffffffff00000000UL; |
| 681 | *statusreg |= SIGP_STAT_INVALID_PARAMETER; |
| 682 | cc = 1; /* status stored */ |
| 683 | break; |
Thomas Huth | 0b9972a | 2013-12-17 14:22:06 +0100 | [diff] [blame] | 684 | case SIGP_INITIAL_CPU_RESET: |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 685 | cc = s390_cpu_initial_reset(target_cpu); |
Thomas Huth | 0b9972a | 2013-12-17 14:22:06 +0100 | [diff] [blame] | 686 | break; |
| 687 | default: |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 688 | DPRINTF("KVM: unknown SIGP: 0x%x\n", order_code); |
| 689 | *statusreg &= 0xffffffff00000000UL; |
| 690 | *statusreg |= SIGP_STAT_INVALID_ORDER; |
| 691 | cc = 1; /* status stored */ |
Thomas Huth | 0b9972a | 2013-12-17 14:22:06 +0100 | [diff] [blame] | 692 | break; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | out: |
Thomas Huth | 3796f0e | 2013-12-17 14:22:09 +0100 | [diff] [blame] | 696 | setcc(cpu, cc); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
Thomas Huth | d2ee774 | 2013-07-02 14:45:16 +0200 | [diff] [blame] | 700 | static void handle_instruction(S390CPU *cpu, struct kvm_run *run) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 701 | { |
| 702 | unsigned int ipa0 = (run->s390_sieic.ipa & 0xff00); |
| 703 | uint8_t ipa1 = run->s390_sieic.ipa & 0x00ff; |
Alexander Graf | d7963c4 | 2009-12-17 13:56:47 +0100 | [diff] [blame] | 704 | int r = -1; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 705 | |
Peter Maydell | e67137c | 2013-07-29 13:16:37 +0100 | [diff] [blame] | 706 | DPRINTF("handle_instruction 0x%x 0x%x\n", |
| 707 | run->s390_sieic.ipa, run->s390_sieic.ipb); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 708 | switch (ipa0) { |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 709 | case IPA0_B2: |
| 710 | case IPA0_B9: |
| 711 | case IPA0_EB: |
| 712 | r = handle_priv(cpu, run, ipa0 >> 8, ipa1); |
| 713 | break; |
| 714 | case IPA0_DIAG: |
Cornelia Huck | 638129f | 2013-12-17 18:27:33 +0100 | [diff] [blame] | 715 | r = handle_diag(cpu, run, run->s390_sieic.ipb); |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 716 | break; |
| 717 | case IPA0_SIGP: |
| 718 | r = handle_sigp(cpu, run, ipa1); |
| 719 | break; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | if (r < 0) { |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 723 | enter_pgmcheck(cpu, 0x0001); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 724 | } |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 725 | } |
| 726 | |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 727 | static bool is_special_wait_psw(CPUState *cs) |
Christian Borntraeger | eca3ed0 | 2012-04-22 23:52:25 +0000 | [diff] [blame] | 728 | { |
| 729 | /* signal quiesce */ |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 730 | return cs->kvm_run->psw_addr == 0xfffUL; |
Christian Borntraeger | eca3ed0 | 2012-04-22 23:52:25 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 733 | static int handle_intercept(S390CPU *cpu) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 734 | { |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 735 | CPUState *cs = CPU(cpu); |
| 736 | struct kvm_run *run = cs->kvm_run; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 737 | int icpt_code = run->s390_sieic.icptcode; |
| 738 | int r = 0; |
| 739 | |
Peter Maydell | e67137c | 2013-07-29 13:16:37 +0100 | [diff] [blame] | 740 | DPRINTF("intercept: 0x%x (at 0x%lx)\n", icpt_code, |
Andreas Färber | f7575c96 | 2012-12-01 06:18:14 +0100 | [diff] [blame] | 741 | (long)cs->kvm_run->psw_addr); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 742 | switch (icpt_code) { |
| 743 | case ICPT_INSTRUCTION: |
Thomas Huth | d2ee774 | 2013-07-02 14:45:16 +0200 | [diff] [blame] | 744 | handle_instruction(cpu, run); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 745 | break; |
| 746 | case ICPT_WAITPSW: |
Christian Borntraeger | 08eb8c8 | 2013-04-26 11:24:47 +0800 | [diff] [blame] | 747 | /* disabled wait, since enabled wait is handled in kernel */ |
| 748 | if (s390_del_running_cpu(cpu) == 0) { |
| 749 | if (is_special_wait_psw(cs)) { |
| 750 | qemu_system_shutdown_request(); |
| 751 | } else { |
| 752 | QObject *data; |
| 753 | |
| 754 | data = qobject_from_jsonf("{ 'action': %s }", "pause"); |
| 755 | monitor_protocol_event(QEVENT_GUEST_PANICKED, data); |
| 756 | qobject_decref(data); |
| 757 | vm_stop(RUN_STATE_GUEST_PANICKED); |
| 758 | } |
Christian Borntraeger | eca3ed0 | 2012-04-22 23:52:25 +0000 | [diff] [blame] | 759 | } |
| 760 | r = EXCP_HALTED; |
| 761 | break; |
Christian Borntraeger | 854e42f | 2011-10-04 05:20:59 +0000 | [diff] [blame] | 762 | case ICPT_CPU_STOP: |
Andreas Färber | 49e1587 | 2013-01-30 12:48:25 +0000 | [diff] [blame] | 763 | if (s390_del_running_cpu(cpu) == 0) { |
Christian Borntraeger | 854e42f | 2011-10-04 05:20:59 +0000 | [diff] [blame] | 764 | qemu_system_shutdown_request(); |
| 765 | } |
| 766 | r = EXCP_HALTED; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 767 | break; |
| 768 | case ICPT_SOFT_INTERCEPT: |
| 769 | fprintf(stderr, "KVM unimplemented icpt SOFT\n"); |
| 770 | exit(1); |
| 771 | break; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 772 | case ICPT_IO: |
| 773 | fprintf(stderr, "KVM unimplemented icpt IO\n"); |
| 774 | exit(1); |
| 775 | break; |
| 776 | default: |
| 777 | fprintf(stderr, "Unknown intercept code: %d\n", icpt_code); |
| 778 | exit(1); |
| 779 | break; |
| 780 | } |
| 781 | |
| 782 | return r; |
| 783 | } |
| 784 | |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 785 | static int handle_tsch(S390CPU *cpu) |
| 786 | { |
| 787 | CPUS390XState *env = &cpu->env; |
| 788 | CPUState *cs = CPU(cpu); |
| 789 | struct kvm_run *run = cs->kvm_run; |
| 790 | int ret; |
| 791 | |
Dominik Dingel | 44c68de | 2013-10-01 16:28:23 +0200 | [diff] [blame] | 792 | cpu_synchronize_state(cs); |
Jason J. Herne | 3474b67 | 2013-04-25 04:25:51 +0000 | [diff] [blame] | 793 | |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 794 | ret = ioinst_handle_tsch(env, env->regs[1], run->s390_tsch.ipb); |
| 795 | if (ret >= 0) { |
| 796 | /* Success; set condition code. */ |
| 797 | setcc(cpu, ret); |
| 798 | ret = 0; |
| 799 | } else if (ret < -1) { |
| 800 | /* |
| 801 | * Failure. |
| 802 | * If an I/O interrupt had been dequeued, we have to reinject it. |
| 803 | */ |
| 804 | if (run->s390_tsch.dequeued) { |
| 805 | uint16_t subchannel_id = run->s390_tsch.subchannel_id; |
| 806 | uint16_t subchannel_nr = run->s390_tsch.subchannel_nr; |
| 807 | uint32_t io_int_parm = run->s390_tsch.io_int_parm; |
| 808 | uint32_t io_int_word = run->s390_tsch.io_int_word; |
| 809 | uint32_t type = ((subchannel_id & 0xff00) << 24) | |
| 810 | ((subchannel_id & 0x00060) << 22) | (subchannel_nr << 16); |
| 811 | |
| 812 | kvm_s390_interrupt_internal(cpu, type, |
| 813 | ((uint32_t)subchannel_id << 16) |
| 814 | | subchannel_nr, |
| 815 | ((uint64_t)io_int_parm << 32) |
| 816 | | io_int_word, 1); |
| 817 | } |
| 818 | ret = 0; |
| 819 | } |
| 820 | return ret; |
| 821 | } |
| 822 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 823 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 824 | { |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 825 | S390CPU *cpu = S390_CPU(cs); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 826 | int ret = 0; |
| 827 | |
| 828 | switch (run->exit_reason) { |
| 829 | case KVM_EXIT_S390_SIEIC: |
Andreas Färber | 1bc2265 | 2012-10-31 06:06:49 +0100 | [diff] [blame] | 830 | ret = handle_intercept(cpu); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 831 | break; |
| 832 | case KVM_EXIT_S390_RESET: |
Jens Freimann | add142e | 2012-04-22 23:52:23 +0000 | [diff] [blame] | 833 | qemu_system_reset_request(); |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 834 | break; |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 835 | case KVM_EXIT_S390_TSCH: |
| 836 | ret = handle_tsch(cpu); |
| 837 | break; |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 838 | default: |
| 839 | fprintf(stderr, "Unknown KVM exit: %d\n", run->exit_reason); |
| 840 | break; |
| 841 | } |
| 842 | |
Jan Kiszka | bb4ea39 | 2011-03-15 12:26:28 +0100 | [diff] [blame] | 843 | if (ret == 0) { |
| 844 | ret = EXCP_INTERRUPT; |
Jan Kiszka | bb4ea39 | 2011-03-15 12:26:28 +0100 | [diff] [blame] | 845 | } |
Alexander Graf | 0e60a69 | 2009-12-05 12:44:24 +0100 | [diff] [blame] | 846 | return ret; |
| 847 | } |
Gleb Natapov | 4513d92 | 2010-05-10 11:21:34 +0300 | [diff] [blame] | 848 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 849 | bool kvm_arch_stop_on_emulation_error(CPUState *cpu) |
Gleb Natapov | 4513d92 | 2010-05-10 11:21:34 +0300 | [diff] [blame] | 850 | { |
| 851 | return true; |
| 852 | } |
Jan Kiszka | a1b87fe | 2011-02-01 22:15:51 +0100 | [diff] [blame] | 853 | |
Andreas Färber | 20d695a | 2012-10-31 06:57:49 +0100 | [diff] [blame] | 854 | int kvm_arch_on_sigbus_vcpu(CPUState *cpu, int code, void *addr) |
Jan Kiszka | a1b87fe | 2011-02-01 22:15:51 +0100 | [diff] [blame] | 855 | { |
| 856 | return 1; |
| 857 | } |
| 858 | |
| 859 | int kvm_arch_on_sigbus(int code, void *addr) |
| 860 | { |
| 861 | return 1; |
| 862 | } |
Cornelia Huck | 09b9987 | 2013-01-24 02:28:07 +0000 | [diff] [blame] | 863 | |
| 864 | void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, |
| 865 | uint16_t subchannel_nr, uint32_t io_int_parm, |
| 866 | uint32_t io_int_word) |
| 867 | { |
| 868 | uint32_t type; |
| 869 | |
| 870 | type = ((subchannel_id & 0xff00) << 24) | |
| 871 | ((subchannel_id & 0x00060) << 22) | (subchannel_nr << 16); |
| 872 | kvm_s390_interrupt_internal(cpu, type, |
| 873 | ((uint32_t)subchannel_id << 16) | subchannel_nr, |
| 874 | ((uint64_t)io_int_parm << 32) | io_int_word, 1); |
| 875 | } |
| 876 | |
| 877 | void kvm_s390_crw_mchk(S390CPU *cpu) |
| 878 | { |
| 879 | kvm_s390_interrupt_internal(cpu, KVM_S390_MCHK, 1 << 28, |
| 880 | 0x00400f1d40330000, 1); |
| 881 | } |
| 882 | |
| 883 | void kvm_s390_enable_css_support(S390CPU *cpu) |
| 884 | { |
| 885 | struct kvm_enable_cap cap = {}; |
| 886 | int r; |
| 887 | |
| 888 | /* Activate host kernel channel subsystem support. */ |
| 889 | cap.cap = KVM_CAP_S390_CSS_SUPPORT; |
| 890 | r = kvm_vcpu_ioctl(CPU(cpu), KVM_ENABLE_CAP, &cap); |
| 891 | assert(r == 0); |
| 892 | } |
Alexey Kardashevskiy | 48475e1 | 2013-06-12 17:26:53 +1000 | [diff] [blame] | 893 | |
| 894 | void kvm_arch_init_irq_routing(KVMState *s) |
| 895 | { |
| 896 | } |
Cornelia Huck | b4436a0 | 2013-02-15 10:18:43 +0100 | [diff] [blame] | 897 | |
Cornelia Huck | cc3ac9c | 2013-06-28 09:28:06 +0200 | [diff] [blame] | 898 | int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, |
| 899 | int vq, bool assign) |
Cornelia Huck | b4436a0 | 2013-02-15 10:18:43 +0100 | [diff] [blame] | 900 | { |
| 901 | struct kvm_ioeventfd kick = { |
| 902 | .flags = KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY | |
| 903 | KVM_IOEVENTFD_FLAG_DATAMATCH, |
Cornelia Huck | cc3ac9c | 2013-06-28 09:28:06 +0200 | [diff] [blame] | 904 | .fd = event_notifier_get_fd(notifier), |
Cornelia Huck | b4436a0 | 2013-02-15 10:18:43 +0100 | [diff] [blame] | 905 | .datamatch = vq, |
| 906 | .addr = sch, |
| 907 | .len = 8, |
| 908 | }; |
| 909 | if (!kvm_check_extension(kvm_state, KVM_CAP_IOEVENTFD)) { |
| 910 | return -ENOSYS; |
| 911 | } |
| 912 | if (!assign) { |
| 913 | kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN; |
| 914 | } |
| 915 | return kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick); |
| 916 | } |