]>
Commit | Line | Data |
---|---|---|
db1c8f53 CH |
1 | /* |
2 | * I/O instructions for S/390 | |
3 | * | |
14b4e13d | 4 | * Copyright 2012, 2015 IBM Corp. |
db1c8f53 CH |
5 | * Author(s): Cornelia Huck <[email protected]> |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2 or (at | |
8 | * your option) any later version. See the COPYING file in the top-level | |
9 | * directory. | |
10 | */ | |
11 | ||
9615495a | 12 | #include "qemu/osdep.h" |
db1c8f53 CH |
13 | |
14 | #include "cpu.h" | |
bd3f16ac | 15 | #include "hw/s390x/ioinst.h" |
7b18aad5 | 16 | #include "trace.h" |
8cba80c3 | 17 | #include "hw/s390x/s390-pci-bus.h" |
db1c8f53 CH |
18 | |
19 | int ioinst_disassemble_sch_ident(uint32_t value, int *m, int *cssid, int *ssid, | |
20 | int *schid) | |
21 | { | |
22 | if (!IOINST_SCHID_ONE(value)) { | |
23 | return -EINVAL; | |
24 | } | |
25 | if (!IOINST_SCHID_M(value)) { | |
26 | if (IOINST_SCHID_CSSID(value)) { | |
27 | return -EINVAL; | |
28 | } | |
29 | *cssid = 0; | |
30 | *m = 0; | |
31 | } else { | |
32 | *cssid = IOINST_SCHID_CSSID(value); | |
33 | *m = 1; | |
34 | } | |
35 | *ssid = IOINST_SCHID_SSID(value); | |
36 | *schid = IOINST_SCHID_NR(value); | |
37 | return 0; | |
38 | } | |
7b18aad5 | 39 | |
5d9bf1c0 | 40 | void ioinst_handle_xsch(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
41 | { |
42 | int cssid, ssid, schid, m; | |
43 | SubchDev *sch; | |
44 | int ret = -ENODEV; | |
45 | int cc; | |
46 | ||
47 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
7e01376d | 48 | program_interrupt(&cpu->env, PGM_OPERAND, 4); |
5d9bf1c0 | 49 | return; |
7b18aad5 CH |
50 | } |
51 | trace_ioinst_sch_id("xsch", cssid, ssid, schid); | |
52 | sch = css_find_subch(m, cssid, ssid, schid); | |
53 | if (sch && css_subch_visible(sch)) { | |
54 | ret = css_do_xsch(sch); | |
55 | } | |
56 | switch (ret) { | |
57 | case -ENODEV: | |
58 | cc = 3; | |
59 | break; | |
60 | case -EBUSY: | |
61 | cc = 2; | |
62 | break; | |
63 | case 0: | |
64 | cc = 0; | |
65 | break; | |
66 | default: | |
67 | cc = 1; | |
68 | break; | |
69 | } | |
5d9bf1c0 | 70 | setcc(cpu, cc); |
7b18aad5 CH |
71 | } |
72 | ||
5d9bf1c0 | 73 | void ioinst_handle_csch(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
74 | { |
75 | int cssid, ssid, schid, m; | |
76 | SubchDev *sch; | |
77 | int ret = -ENODEV; | |
78 | int cc; | |
79 | ||
80 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
7e01376d | 81 | program_interrupt(&cpu->env, PGM_OPERAND, 4); |
5d9bf1c0 | 82 | return; |
7b18aad5 CH |
83 | } |
84 | trace_ioinst_sch_id("csch", cssid, ssid, schid); | |
85 | sch = css_find_subch(m, cssid, ssid, schid); | |
86 | if (sch && css_subch_visible(sch)) { | |
87 | ret = css_do_csch(sch); | |
88 | } | |
89 | if (ret == -ENODEV) { | |
90 | cc = 3; | |
91 | } else { | |
92 | cc = 0; | |
93 | } | |
5d9bf1c0 | 94 | setcc(cpu, cc); |
7b18aad5 CH |
95 | } |
96 | ||
5d9bf1c0 | 97 | void ioinst_handle_hsch(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
98 | { |
99 | int cssid, ssid, schid, m; | |
100 | SubchDev *sch; | |
101 | int ret = -ENODEV; | |
102 | int cc; | |
103 | ||
104 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
7e01376d | 105 | program_interrupt(&cpu->env, PGM_OPERAND, 4); |
5d9bf1c0 | 106 | return; |
7b18aad5 CH |
107 | } |
108 | trace_ioinst_sch_id("hsch", cssid, ssid, schid); | |
109 | sch = css_find_subch(m, cssid, ssid, schid); | |
110 | if (sch && css_subch_visible(sch)) { | |
111 | ret = css_do_hsch(sch); | |
112 | } | |
113 | switch (ret) { | |
114 | case -ENODEV: | |
115 | cc = 3; | |
116 | break; | |
117 | case -EBUSY: | |
118 | cc = 2; | |
119 | break; | |
120 | case 0: | |
121 | cc = 0; | |
122 | break; | |
123 | default: | |
124 | cc = 1; | |
125 | break; | |
126 | } | |
5d9bf1c0 | 127 | setcc(cpu, cc); |
7b18aad5 CH |
128 | } |
129 | ||
130 | static int ioinst_schib_valid(SCHIB *schib) | |
131 | { | |
d49f4ab4 AG |
132 | if ((be16_to_cpu(schib->pmcw.flags) & PMCW_FLAGS_MASK_INVALID) || |
133 | (be32_to_cpu(schib->pmcw.chars) & PMCW_CHARS_MASK_INVALID)) { | |
7b18aad5 CH |
134 | return 0; |
135 | } | |
136 | /* Disallow extended measurements for now. */ | |
d49f4ab4 | 137 | if (be32_to_cpu(schib->pmcw.chars) & PMCW_CHARS_MASK_XMWME) { |
7b18aad5 CH |
138 | return 0; |
139 | } | |
140 | return 1; | |
141 | } | |
142 | ||
5d9bf1c0 | 143 | void ioinst_handle_msch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 CH |
144 | { |
145 | int cssid, ssid, schid, m; | |
146 | SubchDev *sch; | |
14b4e13d | 147 | SCHIB schib; |
7b18aad5 CH |
148 | uint64_t addr; |
149 | int ret = -ENODEV; | |
150 | int cc; | |
5d9bf1c0 | 151 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 152 | uint8_t ar; |
7b18aad5 | 153 | |
6cb1e49d | 154 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb | 155 | if (addr & 3) { |
7e01376d | 156 | program_interrupt(env, PGM_SPECIFICATION, 4); |
5d9bf1c0 | 157 | return; |
61bf0dcb | 158 | } |
6cb1e49d | 159 | if (s390_cpu_virt_mem_read(cpu, addr, ar, &schib, sizeof(schib))) { |
14b4e13d | 160 | return; |
7b18aad5 | 161 | } |
71ed827a | 162 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid) || |
14b4e13d | 163 | !ioinst_schib_valid(&schib)) { |
7e01376d | 164 | program_interrupt(env, PGM_OPERAND, 4); |
14b4e13d | 165 | return; |
7b18aad5 | 166 | } |
71ed827a | 167 | trace_ioinst_sch_id("msch", cssid, ssid, schid); |
7b18aad5 CH |
168 | sch = css_find_subch(m, cssid, ssid, schid); |
169 | if (sch && css_subch_visible(sch)) { | |
14b4e13d | 170 | ret = css_do_msch(sch, &schib); |
7b18aad5 CH |
171 | } |
172 | switch (ret) { | |
173 | case -ENODEV: | |
174 | cc = 3; | |
175 | break; | |
176 | case -EBUSY: | |
177 | cc = 2; | |
178 | break; | |
179 | case 0: | |
180 | cc = 0; | |
181 | break; | |
182 | default: | |
183 | cc = 1; | |
184 | break; | |
185 | } | |
5d9bf1c0 | 186 | setcc(cpu, cc); |
7b18aad5 CH |
187 | } |
188 | ||
189 | static void copy_orb_from_guest(ORB *dest, const ORB *src) | |
190 | { | |
191 | dest->intparm = be32_to_cpu(src->intparm); | |
192 | dest->ctrl0 = be16_to_cpu(src->ctrl0); | |
193 | dest->lpm = src->lpm; | |
194 | dest->ctrl1 = src->ctrl1; | |
195 | dest->cpa = be32_to_cpu(src->cpa); | |
196 | } | |
197 | ||
198 | static int ioinst_orb_valid(ORB *orb) | |
199 | { | |
200 | if ((orb->ctrl0 & ORB_CTRL0_MASK_INVALID) || | |
201 | (orb->ctrl1 & ORB_CTRL1_MASK_INVALID)) { | |
202 | return 0; | |
203 | } | |
4e19b57b CH |
204 | /* We don't support MIDA. */ |
205 | if (orb->ctrl1 & ORB_CTRL1_MASK_MIDAW) { | |
206 | return 0; | |
207 | } | |
7b18aad5 CH |
208 | if ((orb->cpa & HIGH_ORDER_BIT) != 0) { |
209 | return 0; | |
210 | } | |
211 | return 1; | |
212 | } | |
213 | ||
5d9bf1c0 | 214 | void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 CH |
215 | { |
216 | int cssid, ssid, schid, m; | |
217 | SubchDev *sch; | |
234d9b1d | 218 | ORB orig_orb, orb; |
7b18aad5 CH |
219 | uint64_t addr; |
220 | int ret = -ENODEV; | |
221 | int cc; | |
5d9bf1c0 | 222 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 223 | uint8_t ar; |
7b18aad5 | 224 | |
6cb1e49d | 225 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb | 226 | if (addr & 3) { |
7e01376d | 227 | program_interrupt(env, PGM_SPECIFICATION, 4); |
5d9bf1c0 | 228 | return; |
61bf0dcb | 229 | } |
6cb1e49d | 230 | if (s390_cpu_virt_mem_read(cpu, addr, ar, &orig_orb, sizeof(orb))) { |
234d9b1d | 231 | return; |
7b18aad5 | 232 | } |
234d9b1d | 233 | copy_orb_from_guest(&orb, &orig_orb); |
71ed827a TH |
234 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid) || |
235 | !ioinst_orb_valid(&orb)) { | |
7e01376d | 236 | program_interrupt(env, PGM_OPERAND, 4); |
234d9b1d | 237 | return; |
7b18aad5 | 238 | } |
71ed827a | 239 | trace_ioinst_sch_id("ssch", cssid, ssid, schid); |
7b18aad5 CH |
240 | sch = css_find_subch(m, cssid, ssid, schid); |
241 | if (sch && css_subch_visible(sch)) { | |
242 | ret = css_do_ssch(sch, &orb); | |
243 | } | |
244 | switch (ret) { | |
245 | case -ENODEV: | |
246 | cc = 3; | |
247 | break; | |
248 | case -EBUSY: | |
249 | cc = 2; | |
250 | break; | |
bab482d7 XFR |
251 | case -EFAULT: |
252 | /* | |
253 | * TODO: | |
254 | * I'm wondering whether there is something better | |
255 | * to do for us here (like setting some device or | |
256 | * subchannel status). | |
257 | */ | |
258 | program_interrupt(env, PGM_ADDRESSING, 4); | |
259 | return; | |
7b18aad5 CH |
260 | case 0: |
261 | cc = 0; | |
262 | break; | |
263 | default: | |
264 | cc = 1; | |
265 | break; | |
266 | } | |
5d9bf1c0 | 267 | setcc(cpu, cc); |
7b18aad5 CH |
268 | } |
269 | ||
5d9bf1c0 | 270 | void ioinst_handle_stcrw(S390CPU *cpu, uint32_t ipb) |
7b18aad5 | 271 | { |
7f74f0aa | 272 | CRW crw; |
7b18aad5 CH |
273 | uint64_t addr; |
274 | int cc; | |
5d9bf1c0 | 275 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 276 | uint8_t ar; |
7b18aad5 | 277 | |
6cb1e49d | 278 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb | 279 | if (addr & 3) { |
7e01376d | 280 | program_interrupt(env, PGM_SPECIFICATION, 4); |
5d9bf1c0 | 281 | return; |
61bf0dcb | 282 | } |
7f74f0aa TH |
283 | |
284 | cc = css_do_stcrw(&crw); | |
7b18aad5 | 285 | /* 0 - crw stored, 1 - zeroes stored */ |
5d9bf1c0 | 286 | |
6cb1e49d | 287 | if (s390_cpu_virt_mem_write(cpu, addr, ar, &crw, sizeof(crw)) == 0) { |
7f74f0aa TH |
288 | setcc(cpu, cc); |
289 | } else if (cc == 0) { | |
290 | /* Write failed: requeue CRW since STCRW is a suppressing instruction */ | |
291 | css_undo_stcrw(&crw); | |
292 | } | |
7b18aad5 CH |
293 | } |
294 | ||
5d9bf1c0 | 295 | void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 CH |
296 | { |
297 | int cssid, ssid, schid, m; | |
298 | SubchDev *sch; | |
299 | uint64_t addr; | |
300 | int cc; | |
57b22fc7 | 301 | SCHIB schib; |
5d9bf1c0 | 302 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 303 | uint8_t ar; |
7b18aad5 | 304 | |
6cb1e49d | 305 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb | 306 | if (addr & 3) { |
7e01376d | 307 | program_interrupt(env, PGM_SPECIFICATION, 4); |
5d9bf1c0 | 308 | return; |
61bf0dcb | 309 | } |
71ed827a TH |
310 | |
311 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
57b22fc7 TH |
312 | /* |
313 | * As operand exceptions have a lower priority than access exceptions, | |
314 | * we check whether the memory area is writeable (injecting the | |
315 | * access execption if it is not) first. | |
316 | */ | |
6cb1e49d | 317 | if (!s390_cpu_virt_mem_check_write(cpu, addr, ar, sizeof(schib))) { |
7e01376d | 318 | program_interrupt(env, PGM_OPERAND, 4); |
57b22fc7 TH |
319 | } |
320 | return; | |
71ed827a TH |
321 | } |
322 | trace_ioinst_sch_id("stsch", cssid, ssid, schid); | |
7b18aad5 CH |
323 | sch = css_find_subch(m, cssid, ssid, schid); |
324 | if (sch) { | |
325 | if (css_subch_visible(sch)) { | |
57b22fc7 | 326 | css_do_stsch(sch, &schib); |
7b18aad5 CH |
327 | cc = 0; |
328 | } else { | |
329 | /* Indicate no more subchannels in this css/ss */ | |
330 | cc = 3; | |
331 | } | |
332 | } else { | |
38dd7cc7 | 333 | if (css_schid_final(m, cssid, ssid, schid)) { |
7b18aad5 CH |
334 | cc = 3; /* No more subchannels in this css/ss */ |
335 | } else { | |
336 | /* Store an empty schib. */ | |
57b22fc7 | 337 | memset(&schib, 0, sizeof(schib)); |
7b18aad5 CH |
338 | cc = 0; |
339 | } | |
340 | } | |
57b22fc7 | 341 | if (cc != 3) { |
6cb1e49d AY |
342 | if (s390_cpu_virt_mem_write(cpu, addr, ar, &schib, |
343 | sizeof(schib)) != 0) { | |
57b22fc7 TH |
344 | return; |
345 | } | |
346 | } else { | |
347 | /* Access exceptions have a higher priority than cc3 */ | |
6cb1e49d | 348 | if (s390_cpu_virt_mem_check_write(cpu, addr, ar, sizeof(schib)) != 0) { |
57b22fc7 TH |
349 | return; |
350 | } | |
351 | } | |
5d9bf1c0 | 352 | setcc(cpu, cc); |
7b18aad5 CH |
353 | } |
354 | ||
653b0809 | 355 | int ioinst_handle_tsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 | 356 | { |
653b0809 | 357 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
358 | int cssid, ssid, schid, m; |
359 | SubchDev *sch; | |
b7b6348a | 360 | IRB irb; |
7b18aad5 | 361 | uint64_t addr; |
b7b6348a | 362 | int cc, irb_len; |
6cb1e49d | 363 | uint8_t ar; |
7b18aad5 CH |
364 | |
365 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
7e01376d | 366 | program_interrupt(env, PGM_OPERAND, 4); |
7b18aad5 CH |
367 | return -EIO; |
368 | } | |
369 | trace_ioinst_sch_id("tsch", cssid, ssid, schid); | |
6cb1e49d | 370 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb | 371 | if (addr & 3) { |
7e01376d | 372 | program_interrupt(env, PGM_SPECIFICATION, 4); |
61bf0dcb TH |
373 | return -EIO; |
374 | } | |
b7b6348a | 375 | |
7b18aad5 CH |
376 | sch = css_find_subch(m, cssid, ssid, schid); |
377 | if (sch && css_subch_visible(sch)) { | |
b7b6348a | 378 | cc = css_do_tsch_get_irb(sch, &irb, &irb_len); |
7b18aad5 CH |
379 | } else { |
380 | cc = 3; | |
381 | } | |
b7b6348a TH |
382 | /* 0 - status pending, 1 - not status pending, 3 - not operational */ |
383 | if (cc != 3) { | |
6cb1e49d | 384 | if (s390_cpu_virt_mem_write(cpu, addr, ar, &irb, irb_len) != 0) { |
b7b6348a TH |
385 | return -EFAULT; |
386 | } | |
387 | css_do_tsch_update_subch(sch); | |
388 | } else { | |
389 | irb_len = sizeof(irb) - sizeof(irb.emw); | |
390 | /* Access exceptions have a higher priority than cc3 */ | |
6cb1e49d | 391 | if (s390_cpu_virt_mem_check_write(cpu, addr, ar, irb_len) != 0) { |
b7b6348a TH |
392 | return -EFAULT; |
393 | } | |
394 | } | |
395 | ||
653b0809 | 396 | setcc(cpu, cc); |
b7b6348a | 397 | return 0; |
7b18aad5 CH |
398 | } |
399 | ||
400 | typedef struct ChscReq { | |
401 | uint16_t len; | |
402 | uint16_t command; | |
403 | uint32_t param0; | |
404 | uint32_t param1; | |
405 | uint32_t param2; | |
406 | } QEMU_PACKED ChscReq; | |
407 | ||
408 | typedef struct ChscResp { | |
409 | uint16_t len; | |
410 | uint16_t code; | |
411 | uint32_t param; | |
412 | char data[0]; | |
413 | } QEMU_PACKED ChscResp; | |
414 | ||
415 | #define CHSC_MIN_RESP_LEN 0x0008 | |
416 | ||
417 | #define CHSC_SCPD 0x0002 | |
418 | #define CHSC_SCSC 0x0010 | |
419 | #define CHSC_SDA 0x0031 | |
8cba80c3 | 420 | #define CHSC_SEI 0x000e |
7b18aad5 CH |
421 | |
422 | #define CHSC_SCPD_0_M 0x20000000 | |
423 | #define CHSC_SCPD_0_C 0x10000000 | |
424 | #define CHSC_SCPD_0_FMT 0x0f000000 | |
425 | #define CHSC_SCPD_0_CSSID 0x00ff0000 | |
426 | #define CHSC_SCPD_0_RFMT 0x00000f00 | |
427 | #define CHSC_SCPD_0_RES 0xc000f000 | |
428 | #define CHSC_SCPD_1_RES 0xffffff00 | |
429 | #define CHSC_SCPD_01_CHPID 0x000000ff | |
430 | static void ioinst_handle_chsc_scpd(ChscReq *req, ChscResp *res) | |
431 | { | |
432 | uint16_t len = be16_to_cpu(req->len); | |
433 | uint32_t param0 = be32_to_cpu(req->param0); | |
434 | uint32_t param1 = be32_to_cpu(req->param1); | |
435 | uint16_t resp_code; | |
436 | int rfmt; | |
437 | uint16_t cssid; | |
438 | uint8_t f_chpid, l_chpid; | |
439 | int desc_size; | |
440 | int m; | |
441 | ||
442 | rfmt = (param0 & CHSC_SCPD_0_RFMT) >> 8; | |
443 | if ((rfmt == 0) || (rfmt == 1)) { | |
444 | rfmt = !!(param0 & CHSC_SCPD_0_C); | |
445 | } | |
446 | if ((len != 0x0010) || (param0 & CHSC_SCPD_0_RES) || | |
447 | (param1 & CHSC_SCPD_1_RES) || req->param2) { | |
448 | resp_code = 0x0003; | |
449 | goto out_err; | |
450 | } | |
451 | if (param0 & CHSC_SCPD_0_FMT) { | |
452 | resp_code = 0x0007; | |
453 | goto out_err; | |
454 | } | |
455 | cssid = (param0 & CHSC_SCPD_0_CSSID) >> 16; | |
456 | m = param0 & CHSC_SCPD_0_M; | |
457 | if (cssid != 0) { | |
458 | if (!m || !css_present(cssid)) { | |
459 | resp_code = 0x0008; | |
460 | goto out_err; | |
461 | } | |
462 | } | |
463 | f_chpid = param0 & CHSC_SCPD_01_CHPID; | |
464 | l_chpid = param1 & CHSC_SCPD_01_CHPID; | |
465 | if (l_chpid < f_chpid) { | |
466 | resp_code = 0x0003; | |
467 | goto out_err; | |
468 | } | |
469 | /* css_collect_chp_desc() is endian-aware */ | |
470 | desc_size = css_collect_chp_desc(m, cssid, f_chpid, l_chpid, rfmt, | |
471 | &res->data); | |
472 | res->code = cpu_to_be16(0x0001); | |
473 | res->len = cpu_to_be16(8 + desc_size); | |
474 | res->param = cpu_to_be32(rfmt); | |
475 | return; | |
476 | ||
477 | out_err: | |
478 | res->code = cpu_to_be16(resp_code); | |
479 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
480 | res->param = cpu_to_be32(rfmt); | |
481 | } | |
482 | ||
483 | #define CHSC_SCSC_0_M 0x20000000 | |
484 | #define CHSC_SCSC_0_FMT 0x000f0000 | |
485 | #define CHSC_SCSC_0_CSSID 0x0000ff00 | |
486 | #define CHSC_SCSC_0_RES 0xdff000ff | |
487 | static void ioinst_handle_chsc_scsc(ChscReq *req, ChscResp *res) | |
488 | { | |
489 | uint16_t len = be16_to_cpu(req->len); | |
490 | uint32_t param0 = be32_to_cpu(req->param0); | |
491 | uint8_t cssid; | |
492 | uint16_t resp_code; | |
493 | uint32_t general_chars[510]; | |
494 | uint32_t chsc_chars[508]; | |
495 | ||
496 | if (len != 0x0010) { | |
497 | resp_code = 0x0003; | |
498 | goto out_err; | |
499 | } | |
500 | ||
501 | if (param0 & CHSC_SCSC_0_FMT) { | |
502 | resp_code = 0x0007; | |
503 | goto out_err; | |
504 | } | |
505 | cssid = (param0 & CHSC_SCSC_0_CSSID) >> 8; | |
506 | if (cssid != 0) { | |
507 | if (!(param0 & CHSC_SCSC_0_M) || !css_present(cssid)) { | |
508 | resp_code = 0x0008; | |
509 | goto out_err; | |
510 | } | |
511 | } | |
512 | if ((param0 & CHSC_SCSC_0_RES) || req->param1 || req->param2) { | |
513 | resp_code = 0x0003; | |
514 | goto out_err; | |
515 | } | |
516 | res->code = cpu_to_be16(0x0001); | |
517 | res->len = cpu_to_be16(4080); | |
518 | res->param = 0; | |
519 | ||
520 | memset(general_chars, 0, sizeof(general_chars)); | |
521 | memset(chsc_chars, 0, sizeof(chsc_chars)); | |
522 | ||
523 | general_chars[0] = cpu_to_be32(0x03000000); | |
5759db19 | 524 | general_chars[1] = cpu_to_be32(0x00079000); |
3041e3be | 525 | general_chars[3] = cpu_to_be32(0x00080000); |
7b18aad5 CH |
526 | |
527 | chsc_chars[0] = cpu_to_be32(0x40000000); | |
528 | chsc_chars[3] = cpu_to_be32(0x00040000); | |
529 | ||
530 | memcpy(res->data, general_chars, sizeof(general_chars)); | |
531 | memcpy(res->data + sizeof(general_chars), chsc_chars, sizeof(chsc_chars)); | |
532 | return; | |
533 | ||
534 | out_err: | |
535 | res->code = cpu_to_be16(resp_code); | |
536 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
537 | res->param = 0; | |
538 | } | |
539 | ||
540 | #define CHSC_SDA_0_FMT 0x0f000000 | |
541 | #define CHSC_SDA_0_OC 0x0000ffff | |
542 | #define CHSC_SDA_0_RES 0xf0ff0000 | |
543 | #define CHSC_SDA_OC_MCSSE 0x0 | |
544 | #define CHSC_SDA_OC_MSS 0x2 | |
545 | static void ioinst_handle_chsc_sda(ChscReq *req, ChscResp *res) | |
546 | { | |
547 | uint16_t resp_code = 0x0001; | |
548 | uint16_t len = be16_to_cpu(req->len); | |
549 | uint32_t param0 = be32_to_cpu(req->param0); | |
550 | uint16_t oc; | |
551 | int ret; | |
552 | ||
553 | if ((len != 0x0400) || (param0 & CHSC_SDA_0_RES)) { | |
554 | resp_code = 0x0003; | |
555 | goto out; | |
556 | } | |
557 | ||
558 | if (param0 & CHSC_SDA_0_FMT) { | |
559 | resp_code = 0x0007; | |
560 | goto out; | |
561 | } | |
562 | ||
563 | oc = param0 & CHSC_SDA_0_OC; | |
564 | switch (oc) { | |
565 | case CHSC_SDA_OC_MCSSE: | |
566 | ret = css_enable_mcsse(); | |
567 | if (ret == -EINVAL) { | |
568 | resp_code = 0x0101; | |
569 | goto out; | |
570 | } | |
571 | break; | |
572 | case CHSC_SDA_OC_MSS: | |
573 | ret = css_enable_mss(); | |
574 | if (ret == -EINVAL) { | |
575 | resp_code = 0x0101; | |
576 | goto out; | |
577 | } | |
578 | break; | |
579 | default: | |
580 | resp_code = 0x0003; | |
581 | goto out; | |
582 | } | |
583 | ||
584 | out: | |
585 | res->code = cpu_to_be16(resp_code); | |
586 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
587 | res->param = 0; | |
588 | } | |
589 | ||
8cba80c3 FB |
590 | static int chsc_sei_nt0_get_event(void *res) |
591 | { | |
592 | /* no events yet */ | |
593 | return 1; | |
594 | } | |
595 | ||
596 | static int chsc_sei_nt0_have_event(void) | |
597 | { | |
598 | /* no events yet */ | |
599 | return 0; | |
600 | } | |
601 | ||
1c5deaec CH |
602 | static int chsc_sei_nt2_get_event(void *res) |
603 | { | |
604 | if (s390_has_feat(S390_FEAT_ZPCI)) { | |
605 | return pci_chsc_sei_nt2_get_event(res); | |
606 | } | |
607 | return 1; | |
608 | } | |
609 | ||
610 | static int chsc_sei_nt2_have_event(void) | |
611 | { | |
612 | if (s390_has_feat(S390_FEAT_ZPCI)) { | |
613 | return pci_chsc_sei_nt2_have_event(); | |
614 | } | |
615 | return 0; | |
616 | } | |
617 | ||
8cba80c3 FB |
618 | #define CHSC_SEI_NT0 (1ULL << 63) |
619 | #define CHSC_SEI_NT2 (1ULL << 61) | |
620 | static void ioinst_handle_chsc_sei(ChscReq *req, ChscResp *res) | |
621 | { | |
622 | uint64_t selection_mask = ldq_p(&req->param1); | |
623 | uint8_t *res_flags = (uint8_t *)res->data; | |
624 | int have_event = 0; | |
625 | int have_more = 0; | |
626 | ||
627 | /* regarding architecture nt0 can not be masked */ | |
628 | have_event = !chsc_sei_nt0_get_event(res); | |
629 | have_more = chsc_sei_nt0_have_event(); | |
630 | ||
631 | if (selection_mask & CHSC_SEI_NT2) { | |
632 | if (!have_event) { | |
633 | have_event = !chsc_sei_nt2_get_event(res); | |
634 | } | |
635 | ||
636 | if (!have_more) { | |
637 | have_more = chsc_sei_nt2_have_event(); | |
638 | } | |
639 | } | |
640 | ||
641 | if (have_event) { | |
642 | res->code = cpu_to_be16(0x0001); | |
643 | if (have_more) { | |
644 | (*res_flags) |= 0x80; | |
645 | } else { | |
646 | (*res_flags) &= ~0x80; | |
c81b4f89 | 647 | css_clear_sei_pending(); |
8cba80c3 FB |
648 | } |
649 | } else { | |
f70202be PM |
650 | res->code = cpu_to_be16(0x0005); |
651 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
8cba80c3 FB |
652 | } |
653 | } | |
654 | ||
7b18aad5 CH |
655 | static void ioinst_handle_chsc_unimplemented(ChscResp *res) |
656 | { | |
657 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
658 | res->code = cpu_to_be16(0x0004); | |
659 | res->param = 0; | |
660 | } | |
661 | ||
5d9bf1c0 | 662 | void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb) |
7b18aad5 CH |
663 | { |
664 | ChscReq *req; | |
665 | ChscResp *res; | |
666 | uint64_t addr; | |
667 | int reg; | |
668 | uint16_t len; | |
669 | uint16_t command; | |
5d9bf1c0 | 670 | CPUS390XState *env = &cpu->env; |
166f1bb7 | 671 | uint8_t buf[TARGET_PAGE_SIZE]; |
7b18aad5 CH |
672 | |
673 | trace_ioinst("chsc"); | |
674 | reg = (ipb >> 20) & 0x00f; | |
675 | addr = env->regs[reg]; | |
676 | /* Page boundary? */ | |
677 | if (addr & 0xfff) { | |
7e01376d | 678 | program_interrupt(env, PGM_SPECIFICATION, 4); |
5d9bf1c0 | 679 | return; |
7b18aad5 | 680 | } |
166f1bb7 TH |
681 | /* |
682 | * Reading sizeof(ChscReq) bytes is currently enough for all of our | |
683 | * present CHSC sub-handlers ... if we ever need more, we should take | |
684 | * care of req->len here first. | |
685 | */ | |
6cb1e49d | 686 | if (s390_cpu_virt_mem_read(cpu, addr, reg, buf, sizeof(ChscReq))) { |
166f1bb7 | 687 | return; |
7b18aad5 | 688 | } |
166f1bb7 | 689 | req = (ChscReq *)buf; |
7b18aad5 CH |
690 | len = be16_to_cpu(req->len); |
691 | /* Length field valid? */ | |
692 | if ((len < 16) || (len > 4088) || (len & 7)) { | |
7e01376d | 693 | program_interrupt(env, PGM_OPERAND, 4); |
166f1bb7 | 694 | return; |
7b18aad5 CH |
695 | } |
696 | memset((char *)req + len, 0, TARGET_PAGE_SIZE - len); | |
697 | res = (void *)((char *)req + len); | |
698 | command = be16_to_cpu(req->command); | |
699 | trace_ioinst_chsc_cmd(command, len); | |
700 | switch (command) { | |
701 | case CHSC_SCSC: | |
702 | ioinst_handle_chsc_scsc(req, res); | |
703 | break; | |
704 | case CHSC_SCPD: | |
705 | ioinst_handle_chsc_scpd(req, res); | |
706 | break; | |
707 | case CHSC_SDA: | |
708 | ioinst_handle_chsc_sda(req, res); | |
709 | break; | |
8cba80c3 FB |
710 | case CHSC_SEI: |
711 | ioinst_handle_chsc_sei(req, res); | |
712 | break; | |
7b18aad5 CH |
713 | default: |
714 | ioinst_handle_chsc_unimplemented(res); | |
715 | break; | |
716 | } | |
717 | ||
6cb1e49d AY |
718 | if (!s390_cpu_virt_mem_write(cpu, addr + len, reg, res, |
719 | be16_to_cpu(res->len))) { | |
166f1bb7 TH |
720 | setcc(cpu, 0); /* Command execution complete */ |
721 | } | |
7b18aad5 CH |
722 | } |
723 | ||
7781a492 | 724 | int ioinst_handle_tpi(S390CPU *cpu, uint32_t ipb) |
7b18aad5 | 725 | { |
7781a492 | 726 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
727 | uint64_t addr; |
728 | int lowcore; | |
7781a492 TH |
729 | IOIntCode int_code; |
730 | hwaddr len; | |
50c8d9bf | 731 | int ret; |
6cb1e49d | 732 | uint8_t ar; |
7b18aad5 CH |
733 | |
734 | trace_ioinst("tpi"); | |
6cb1e49d | 735 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb | 736 | if (addr & 3) { |
7e01376d | 737 | program_interrupt(env, PGM_SPECIFICATION, 4); |
61bf0dcb TH |
738 | return -EIO; |
739 | } | |
740 | ||
7b18aad5 | 741 | lowcore = addr ? 0 : 1; |
50c8d9bf | 742 | len = lowcore ? 8 /* two words */ : 12 /* three words */; |
7781a492 TH |
743 | ret = css_do_tpi(&int_code, lowcore); |
744 | if (ret == 1) { | |
6cb1e49d | 745 | s390_cpu_virt_mem_write(cpu, lowcore ? 184 : addr, ar, &int_code, len); |
7b18aad5 | 746 | } |
50c8d9bf | 747 | return ret; |
7b18aad5 CH |
748 | } |
749 | ||
750 | #define SCHM_REG1_RES(_reg) (_reg & 0x000000000ffffffc) | |
751 | #define SCHM_REG1_MBK(_reg) ((_reg & 0x00000000f0000000) >> 28) | |
752 | #define SCHM_REG1_UPD(_reg) ((_reg & 0x0000000000000002) >> 1) | |
753 | #define SCHM_REG1_DCT(_reg) (_reg & 0x0000000000000001) | |
754 | ||
5d9bf1c0 TH |
755 | void ioinst_handle_schm(S390CPU *cpu, uint64_t reg1, uint64_t reg2, |
756 | uint32_t ipb) | |
7b18aad5 CH |
757 | { |
758 | uint8_t mbk; | |
759 | int update; | |
760 | int dct; | |
5d9bf1c0 | 761 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
762 | |
763 | trace_ioinst("schm"); | |
764 | ||
765 | if (SCHM_REG1_RES(reg1)) { | |
7e01376d | 766 | program_interrupt(env, PGM_OPERAND, 4); |
5d9bf1c0 | 767 | return; |
7b18aad5 CH |
768 | } |
769 | ||
770 | mbk = SCHM_REG1_MBK(reg1); | |
771 | update = SCHM_REG1_UPD(reg1); | |
772 | dct = SCHM_REG1_DCT(reg1); | |
773 | ||
7ae5a7c0 | 774 | if (update && (reg2 & 0x000000000000001f)) { |
7e01376d | 775 | program_interrupt(env, PGM_OPERAND, 4); |
5d9bf1c0 | 776 | return; |
7b18aad5 CH |
777 | } |
778 | ||
779 | css_do_schm(mbk, update, dct, update ? reg2 : 0); | |
7b18aad5 CH |
780 | } |
781 | ||
5d9bf1c0 | 782 | void ioinst_handle_rsch(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
783 | { |
784 | int cssid, ssid, schid, m; | |
785 | SubchDev *sch; | |
786 | int ret = -ENODEV; | |
787 | int cc; | |
788 | ||
789 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
7e01376d | 790 | program_interrupt(&cpu->env, PGM_OPERAND, 4); |
5d9bf1c0 | 791 | return; |
7b18aad5 CH |
792 | } |
793 | trace_ioinst_sch_id("rsch", cssid, ssid, schid); | |
794 | sch = css_find_subch(m, cssid, ssid, schid); | |
795 | if (sch && css_subch_visible(sch)) { | |
796 | ret = css_do_rsch(sch); | |
797 | } | |
798 | switch (ret) { | |
799 | case -ENODEV: | |
800 | cc = 3; | |
801 | break; | |
802 | case -EINVAL: | |
803 | cc = 2; | |
804 | break; | |
805 | case 0: | |
806 | cc = 0; | |
807 | break; | |
808 | default: | |
809 | cc = 1; | |
810 | break; | |
811 | } | |
5d9bf1c0 | 812 | setcc(cpu, cc); |
7b18aad5 CH |
813 | } |
814 | ||
815 | #define RCHP_REG1_RES(_reg) (_reg & 0x00000000ff00ff00) | |
816 | #define RCHP_REG1_CSSID(_reg) ((_reg & 0x0000000000ff0000) >> 16) | |
817 | #define RCHP_REG1_CHPID(_reg) (_reg & 0x00000000000000ff) | |
5d9bf1c0 | 818 | void ioinst_handle_rchp(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
819 | { |
820 | int cc; | |
821 | uint8_t cssid; | |
822 | uint8_t chpid; | |
823 | int ret; | |
5d9bf1c0 | 824 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
825 | |
826 | if (RCHP_REG1_RES(reg1)) { | |
7e01376d | 827 | program_interrupt(env, PGM_OPERAND, 4); |
5d9bf1c0 | 828 | return; |
7b18aad5 CH |
829 | } |
830 | ||
831 | cssid = RCHP_REG1_CSSID(reg1); | |
832 | chpid = RCHP_REG1_CHPID(reg1); | |
833 | ||
834 | trace_ioinst_chp_id("rchp", cssid, chpid); | |
835 | ||
836 | ret = css_do_rchp(cssid, chpid); | |
837 | ||
838 | switch (ret) { | |
839 | case -ENODEV: | |
840 | cc = 3; | |
841 | break; | |
842 | case -EBUSY: | |
843 | cc = 2; | |
844 | break; | |
845 | case 0: | |
846 | cc = 0; | |
847 | break; | |
848 | default: | |
849 | /* Invalid channel subsystem. */ | |
7e01376d | 850 | program_interrupt(env, PGM_OPERAND, 4); |
5d9bf1c0 | 851 | return; |
7b18aad5 | 852 | } |
5d9bf1c0 | 853 | setcc(cpu, cc); |
7b18aad5 CH |
854 | } |
855 | ||
856 | #define SAL_REG1_INVALID(_reg) (_reg & 0x0000000080000000) | |
5d9bf1c0 | 857 | void ioinst_handle_sal(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
858 | { |
859 | /* We do not provide address limit checking, so let's suppress it. */ | |
860 | if (SAL_REG1_INVALID(reg1) || reg1 & 0x000000000000ffff) { | |
7e01376d | 861 | program_interrupt(&cpu->env, PGM_OPERAND, 4); |
7b18aad5 | 862 | } |
7b18aad5 | 863 | } |