]>
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 | ||
12 | #include <sys/types.h> | |
13 | ||
14 | #include "cpu.h" | |
15 | #include "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)) { | |
5d9bf1c0 TH |
48 | program_interrupt(&cpu->env, PGM_OPERAND, 2); |
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)) { | |
5d9bf1c0 TH |
81 | program_interrupt(&cpu->env, PGM_OPERAND, 2); |
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)) { | |
5d9bf1c0 TH |
105 | program_interrupt(&cpu->env, PGM_OPERAND, 2); |
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 TH |
155 | if (addr & 3) { |
156 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
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)) { |
7b18aad5 | 164 | program_interrupt(env, PGM_OPERAND, 2); |
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 | } | |
204 | if ((orb->cpa & HIGH_ORDER_BIT) != 0) { | |
205 | return 0; | |
206 | } | |
207 | return 1; | |
208 | } | |
209 | ||
5d9bf1c0 | 210 | void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 CH |
211 | { |
212 | int cssid, ssid, schid, m; | |
213 | SubchDev *sch; | |
234d9b1d | 214 | ORB orig_orb, orb; |
7b18aad5 CH |
215 | uint64_t addr; |
216 | int ret = -ENODEV; | |
217 | int cc; | |
5d9bf1c0 | 218 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 219 | uint8_t ar; |
7b18aad5 | 220 | |
6cb1e49d | 221 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb TH |
222 | if (addr & 3) { |
223 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
5d9bf1c0 | 224 | return; |
61bf0dcb | 225 | } |
6cb1e49d | 226 | if (s390_cpu_virt_mem_read(cpu, addr, ar, &orig_orb, sizeof(orb))) { |
234d9b1d | 227 | return; |
7b18aad5 | 228 | } |
234d9b1d | 229 | copy_orb_from_guest(&orb, &orig_orb); |
71ed827a TH |
230 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid) || |
231 | !ioinst_orb_valid(&orb)) { | |
7b18aad5 | 232 | program_interrupt(env, PGM_OPERAND, 2); |
234d9b1d | 233 | return; |
7b18aad5 | 234 | } |
71ed827a | 235 | trace_ioinst_sch_id("ssch", cssid, ssid, schid); |
7b18aad5 CH |
236 | sch = css_find_subch(m, cssid, ssid, schid); |
237 | if (sch && css_subch_visible(sch)) { | |
238 | ret = css_do_ssch(sch, &orb); | |
239 | } | |
240 | switch (ret) { | |
241 | case -ENODEV: | |
242 | cc = 3; | |
243 | break; | |
244 | case -EBUSY: | |
245 | cc = 2; | |
246 | break; | |
247 | case 0: | |
248 | cc = 0; | |
249 | break; | |
250 | default: | |
251 | cc = 1; | |
252 | break; | |
253 | } | |
5d9bf1c0 | 254 | setcc(cpu, cc); |
7b18aad5 CH |
255 | } |
256 | ||
5d9bf1c0 | 257 | void ioinst_handle_stcrw(S390CPU *cpu, uint32_t ipb) |
7b18aad5 | 258 | { |
7f74f0aa | 259 | CRW crw; |
7b18aad5 CH |
260 | uint64_t addr; |
261 | int cc; | |
5d9bf1c0 | 262 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 263 | uint8_t ar; |
7b18aad5 | 264 | |
6cb1e49d | 265 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb TH |
266 | if (addr & 3) { |
267 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
5d9bf1c0 | 268 | return; |
61bf0dcb | 269 | } |
7f74f0aa TH |
270 | |
271 | cc = css_do_stcrw(&crw); | |
7b18aad5 | 272 | /* 0 - crw stored, 1 - zeroes stored */ |
5d9bf1c0 | 273 | |
6cb1e49d | 274 | if (s390_cpu_virt_mem_write(cpu, addr, ar, &crw, sizeof(crw)) == 0) { |
7f74f0aa TH |
275 | setcc(cpu, cc); |
276 | } else if (cc == 0) { | |
277 | /* Write failed: requeue CRW since STCRW is a suppressing instruction */ | |
278 | css_undo_stcrw(&crw); | |
279 | } | |
7b18aad5 CH |
280 | } |
281 | ||
5d9bf1c0 | 282 | void ioinst_handle_stsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 CH |
283 | { |
284 | int cssid, ssid, schid, m; | |
285 | SubchDev *sch; | |
286 | uint64_t addr; | |
287 | int cc; | |
57b22fc7 | 288 | SCHIB schib; |
5d9bf1c0 | 289 | CPUS390XState *env = &cpu->env; |
6cb1e49d | 290 | uint8_t ar; |
7b18aad5 | 291 | |
6cb1e49d | 292 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb TH |
293 | if (addr & 3) { |
294 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
5d9bf1c0 | 295 | return; |
61bf0dcb | 296 | } |
71ed827a TH |
297 | |
298 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
57b22fc7 TH |
299 | /* |
300 | * As operand exceptions have a lower priority than access exceptions, | |
301 | * we check whether the memory area is writeable (injecting the | |
302 | * access execption if it is not) first. | |
303 | */ | |
6cb1e49d | 304 | if (!s390_cpu_virt_mem_check_write(cpu, addr, ar, sizeof(schib))) { |
57b22fc7 TH |
305 | program_interrupt(env, PGM_OPERAND, 2); |
306 | } | |
307 | return; | |
71ed827a TH |
308 | } |
309 | trace_ioinst_sch_id("stsch", cssid, ssid, schid); | |
7b18aad5 CH |
310 | sch = css_find_subch(m, cssid, ssid, schid); |
311 | if (sch) { | |
312 | if (css_subch_visible(sch)) { | |
57b22fc7 | 313 | css_do_stsch(sch, &schib); |
7b18aad5 CH |
314 | cc = 0; |
315 | } else { | |
316 | /* Indicate no more subchannels in this css/ss */ | |
317 | cc = 3; | |
318 | } | |
319 | } else { | |
38dd7cc7 | 320 | if (css_schid_final(m, cssid, ssid, schid)) { |
7b18aad5 CH |
321 | cc = 3; /* No more subchannels in this css/ss */ |
322 | } else { | |
323 | /* Store an empty schib. */ | |
57b22fc7 | 324 | memset(&schib, 0, sizeof(schib)); |
7b18aad5 CH |
325 | cc = 0; |
326 | } | |
327 | } | |
57b22fc7 | 328 | if (cc != 3) { |
6cb1e49d AY |
329 | if (s390_cpu_virt_mem_write(cpu, addr, ar, &schib, |
330 | sizeof(schib)) != 0) { | |
57b22fc7 TH |
331 | return; |
332 | } | |
333 | } else { | |
334 | /* Access exceptions have a higher priority than cc3 */ | |
6cb1e49d | 335 | if (s390_cpu_virt_mem_check_write(cpu, addr, ar, sizeof(schib)) != 0) { |
57b22fc7 TH |
336 | return; |
337 | } | |
338 | } | |
5d9bf1c0 | 339 | setcc(cpu, cc); |
7b18aad5 CH |
340 | } |
341 | ||
653b0809 | 342 | int ioinst_handle_tsch(S390CPU *cpu, uint64_t reg1, uint32_t ipb) |
7b18aad5 | 343 | { |
653b0809 | 344 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
345 | int cssid, ssid, schid, m; |
346 | SubchDev *sch; | |
b7b6348a | 347 | IRB irb; |
7b18aad5 | 348 | uint64_t addr; |
b7b6348a | 349 | int cc, irb_len; |
6cb1e49d | 350 | uint8_t ar; |
7b18aad5 CH |
351 | |
352 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
353 | program_interrupt(env, PGM_OPERAND, 2); | |
354 | return -EIO; | |
355 | } | |
356 | trace_ioinst_sch_id("tsch", cssid, ssid, schid); | |
6cb1e49d | 357 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb TH |
358 | if (addr & 3) { |
359 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
360 | return -EIO; | |
361 | } | |
b7b6348a | 362 | |
7b18aad5 CH |
363 | sch = css_find_subch(m, cssid, ssid, schid); |
364 | if (sch && css_subch_visible(sch)) { | |
b7b6348a | 365 | cc = css_do_tsch_get_irb(sch, &irb, &irb_len); |
7b18aad5 CH |
366 | } else { |
367 | cc = 3; | |
368 | } | |
b7b6348a TH |
369 | /* 0 - status pending, 1 - not status pending, 3 - not operational */ |
370 | if (cc != 3) { | |
6cb1e49d | 371 | if (s390_cpu_virt_mem_write(cpu, addr, ar, &irb, irb_len) != 0) { |
b7b6348a TH |
372 | return -EFAULT; |
373 | } | |
374 | css_do_tsch_update_subch(sch); | |
375 | } else { | |
376 | irb_len = sizeof(irb) - sizeof(irb.emw); | |
377 | /* Access exceptions have a higher priority than cc3 */ | |
6cb1e49d | 378 | if (s390_cpu_virt_mem_check_write(cpu, addr, ar, irb_len) != 0) { |
b7b6348a TH |
379 | return -EFAULT; |
380 | } | |
381 | } | |
382 | ||
653b0809 | 383 | setcc(cpu, cc); |
b7b6348a | 384 | return 0; |
7b18aad5 CH |
385 | } |
386 | ||
387 | typedef struct ChscReq { | |
388 | uint16_t len; | |
389 | uint16_t command; | |
390 | uint32_t param0; | |
391 | uint32_t param1; | |
392 | uint32_t param2; | |
393 | } QEMU_PACKED ChscReq; | |
394 | ||
395 | typedef struct ChscResp { | |
396 | uint16_t len; | |
397 | uint16_t code; | |
398 | uint32_t param; | |
399 | char data[0]; | |
400 | } QEMU_PACKED ChscResp; | |
401 | ||
402 | #define CHSC_MIN_RESP_LEN 0x0008 | |
403 | ||
404 | #define CHSC_SCPD 0x0002 | |
405 | #define CHSC_SCSC 0x0010 | |
406 | #define CHSC_SDA 0x0031 | |
8cba80c3 | 407 | #define CHSC_SEI 0x000e |
7b18aad5 CH |
408 | |
409 | #define CHSC_SCPD_0_M 0x20000000 | |
410 | #define CHSC_SCPD_0_C 0x10000000 | |
411 | #define CHSC_SCPD_0_FMT 0x0f000000 | |
412 | #define CHSC_SCPD_0_CSSID 0x00ff0000 | |
413 | #define CHSC_SCPD_0_RFMT 0x00000f00 | |
414 | #define CHSC_SCPD_0_RES 0xc000f000 | |
415 | #define CHSC_SCPD_1_RES 0xffffff00 | |
416 | #define CHSC_SCPD_01_CHPID 0x000000ff | |
417 | static void ioinst_handle_chsc_scpd(ChscReq *req, ChscResp *res) | |
418 | { | |
419 | uint16_t len = be16_to_cpu(req->len); | |
420 | uint32_t param0 = be32_to_cpu(req->param0); | |
421 | uint32_t param1 = be32_to_cpu(req->param1); | |
422 | uint16_t resp_code; | |
423 | int rfmt; | |
424 | uint16_t cssid; | |
425 | uint8_t f_chpid, l_chpid; | |
426 | int desc_size; | |
427 | int m; | |
428 | ||
429 | rfmt = (param0 & CHSC_SCPD_0_RFMT) >> 8; | |
430 | if ((rfmt == 0) || (rfmt == 1)) { | |
431 | rfmt = !!(param0 & CHSC_SCPD_0_C); | |
432 | } | |
433 | if ((len != 0x0010) || (param0 & CHSC_SCPD_0_RES) || | |
434 | (param1 & CHSC_SCPD_1_RES) || req->param2) { | |
435 | resp_code = 0x0003; | |
436 | goto out_err; | |
437 | } | |
438 | if (param0 & CHSC_SCPD_0_FMT) { | |
439 | resp_code = 0x0007; | |
440 | goto out_err; | |
441 | } | |
442 | cssid = (param0 & CHSC_SCPD_0_CSSID) >> 16; | |
443 | m = param0 & CHSC_SCPD_0_M; | |
444 | if (cssid != 0) { | |
445 | if (!m || !css_present(cssid)) { | |
446 | resp_code = 0x0008; | |
447 | goto out_err; | |
448 | } | |
449 | } | |
450 | f_chpid = param0 & CHSC_SCPD_01_CHPID; | |
451 | l_chpid = param1 & CHSC_SCPD_01_CHPID; | |
452 | if (l_chpid < f_chpid) { | |
453 | resp_code = 0x0003; | |
454 | goto out_err; | |
455 | } | |
456 | /* css_collect_chp_desc() is endian-aware */ | |
457 | desc_size = css_collect_chp_desc(m, cssid, f_chpid, l_chpid, rfmt, | |
458 | &res->data); | |
459 | res->code = cpu_to_be16(0x0001); | |
460 | res->len = cpu_to_be16(8 + desc_size); | |
461 | res->param = cpu_to_be32(rfmt); | |
462 | return; | |
463 | ||
464 | out_err: | |
465 | res->code = cpu_to_be16(resp_code); | |
466 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
467 | res->param = cpu_to_be32(rfmt); | |
468 | } | |
469 | ||
470 | #define CHSC_SCSC_0_M 0x20000000 | |
471 | #define CHSC_SCSC_0_FMT 0x000f0000 | |
472 | #define CHSC_SCSC_0_CSSID 0x0000ff00 | |
473 | #define CHSC_SCSC_0_RES 0xdff000ff | |
474 | static void ioinst_handle_chsc_scsc(ChscReq *req, ChscResp *res) | |
475 | { | |
476 | uint16_t len = be16_to_cpu(req->len); | |
477 | uint32_t param0 = be32_to_cpu(req->param0); | |
478 | uint8_t cssid; | |
479 | uint16_t resp_code; | |
480 | uint32_t general_chars[510]; | |
481 | uint32_t chsc_chars[508]; | |
482 | ||
483 | if (len != 0x0010) { | |
484 | resp_code = 0x0003; | |
485 | goto out_err; | |
486 | } | |
487 | ||
488 | if (param0 & CHSC_SCSC_0_FMT) { | |
489 | resp_code = 0x0007; | |
490 | goto out_err; | |
491 | } | |
492 | cssid = (param0 & CHSC_SCSC_0_CSSID) >> 8; | |
493 | if (cssid != 0) { | |
494 | if (!(param0 & CHSC_SCSC_0_M) || !css_present(cssid)) { | |
495 | resp_code = 0x0008; | |
496 | goto out_err; | |
497 | } | |
498 | } | |
499 | if ((param0 & CHSC_SCSC_0_RES) || req->param1 || req->param2) { | |
500 | resp_code = 0x0003; | |
501 | goto out_err; | |
502 | } | |
503 | res->code = cpu_to_be16(0x0001); | |
504 | res->len = cpu_to_be16(4080); | |
505 | res->param = 0; | |
506 | ||
507 | memset(general_chars, 0, sizeof(general_chars)); | |
508 | memset(chsc_chars, 0, sizeof(chsc_chars)); | |
509 | ||
510 | general_chars[0] = cpu_to_be32(0x03000000); | |
511 | general_chars[1] = cpu_to_be32(0x00059000); | |
512 | ||
513 | chsc_chars[0] = cpu_to_be32(0x40000000); | |
514 | chsc_chars[3] = cpu_to_be32(0x00040000); | |
515 | ||
516 | memcpy(res->data, general_chars, sizeof(general_chars)); | |
517 | memcpy(res->data + sizeof(general_chars), chsc_chars, sizeof(chsc_chars)); | |
518 | return; | |
519 | ||
520 | out_err: | |
521 | res->code = cpu_to_be16(resp_code); | |
522 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
523 | res->param = 0; | |
524 | } | |
525 | ||
526 | #define CHSC_SDA_0_FMT 0x0f000000 | |
527 | #define CHSC_SDA_0_OC 0x0000ffff | |
528 | #define CHSC_SDA_0_RES 0xf0ff0000 | |
529 | #define CHSC_SDA_OC_MCSSE 0x0 | |
530 | #define CHSC_SDA_OC_MSS 0x2 | |
531 | static void ioinst_handle_chsc_sda(ChscReq *req, ChscResp *res) | |
532 | { | |
533 | uint16_t resp_code = 0x0001; | |
534 | uint16_t len = be16_to_cpu(req->len); | |
535 | uint32_t param0 = be32_to_cpu(req->param0); | |
536 | uint16_t oc; | |
537 | int ret; | |
538 | ||
539 | if ((len != 0x0400) || (param0 & CHSC_SDA_0_RES)) { | |
540 | resp_code = 0x0003; | |
541 | goto out; | |
542 | } | |
543 | ||
544 | if (param0 & CHSC_SDA_0_FMT) { | |
545 | resp_code = 0x0007; | |
546 | goto out; | |
547 | } | |
548 | ||
549 | oc = param0 & CHSC_SDA_0_OC; | |
550 | switch (oc) { | |
551 | case CHSC_SDA_OC_MCSSE: | |
552 | ret = css_enable_mcsse(); | |
553 | if (ret == -EINVAL) { | |
554 | resp_code = 0x0101; | |
555 | goto out; | |
556 | } | |
557 | break; | |
558 | case CHSC_SDA_OC_MSS: | |
559 | ret = css_enable_mss(); | |
560 | if (ret == -EINVAL) { | |
561 | resp_code = 0x0101; | |
562 | goto out; | |
563 | } | |
564 | break; | |
565 | default: | |
566 | resp_code = 0x0003; | |
567 | goto out; | |
568 | } | |
569 | ||
570 | out: | |
571 | res->code = cpu_to_be16(resp_code); | |
572 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
573 | res->param = 0; | |
574 | } | |
575 | ||
8cba80c3 FB |
576 | static int chsc_sei_nt0_get_event(void *res) |
577 | { | |
578 | /* no events yet */ | |
579 | return 1; | |
580 | } | |
581 | ||
582 | static int chsc_sei_nt0_have_event(void) | |
583 | { | |
584 | /* no events yet */ | |
585 | return 0; | |
586 | } | |
587 | ||
588 | #define CHSC_SEI_NT0 (1ULL << 63) | |
589 | #define CHSC_SEI_NT2 (1ULL << 61) | |
590 | static void ioinst_handle_chsc_sei(ChscReq *req, ChscResp *res) | |
591 | { | |
592 | uint64_t selection_mask = ldq_p(&req->param1); | |
593 | uint8_t *res_flags = (uint8_t *)res->data; | |
594 | int have_event = 0; | |
595 | int have_more = 0; | |
596 | ||
597 | /* regarding architecture nt0 can not be masked */ | |
598 | have_event = !chsc_sei_nt0_get_event(res); | |
599 | have_more = chsc_sei_nt0_have_event(); | |
600 | ||
601 | if (selection_mask & CHSC_SEI_NT2) { | |
602 | if (!have_event) { | |
603 | have_event = !chsc_sei_nt2_get_event(res); | |
604 | } | |
605 | ||
606 | if (!have_more) { | |
607 | have_more = chsc_sei_nt2_have_event(); | |
608 | } | |
609 | } | |
610 | ||
611 | if (have_event) { | |
612 | res->code = cpu_to_be16(0x0001); | |
613 | if (have_more) { | |
614 | (*res_flags) |= 0x80; | |
615 | } else { | |
616 | (*res_flags) &= ~0x80; | |
617 | } | |
618 | } else { | |
619 | res->code = cpu_to_be16(0x0004); | |
620 | } | |
621 | } | |
622 | ||
7b18aad5 CH |
623 | static void ioinst_handle_chsc_unimplemented(ChscResp *res) |
624 | { | |
625 | res->len = cpu_to_be16(CHSC_MIN_RESP_LEN); | |
626 | res->code = cpu_to_be16(0x0004); | |
627 | res->param = 0; | |
628 | } | |
629 | ||
5d9bf1c0 | 630 | void ioinst_handle_chsc(S390CPU *cpu, uint32_t ipb) |
7b18aad5 CH |
631 | { |
632 | ChscReq *req; | |
633 | ChscResp *res; | |
634 | uint64_t addr; | |
635 | int reg; | |
636 | uint16_t len; | |
637 | uint16_t command; | |
5d9bf1c0 | 638 | CPUS390XState *env = &cpu->env; |
166f1bb7 | 639 | uint8_t buf[TARGET_PAGE_SIZE]; |
7b18aad5 CH |
640 | |
641 | trace_ioinst("chsc"); | |
642 | reg = (ipb >> 20) & 0x00f; | |
643 | addr = env->regs[reg]; | |
644 | /* Page boundary? */ | |
645 | if (addr & 0xfff) { | |
646 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
5d9bf1c0 | 647 | return; |
7b18aad5 | 648 | } |
166f1bb7 TH |
649 | /* |
650 | * Reading sizeof(ChscReq) bytes is currently enough for all of our | |
651 | * present CHSC sub-handlers ... if we ever need more, we should take | |
652 | * care of req->len here first. | |
653 | */ | |
6cb1e49d | 654 | if (s390_cpu_virt_mem_read(cpu, addr, reg, buf, sizeof(ChscReq))) { |
166f1bb7 | 655 | return; |
7b18aad5 | 656 | } |
166f1bb7 | 657 | req = (ChscReq *)buf; |
7b18aad5 CH |
658 | len = be16_to_cpu(req->len); |
659 | /* Length field valid? */ | |
660 | if ((len < 16) || (len > 4088) || (len & 7)) { | |
661 | program_interrupt(env, PGM_OPERAND, 2); | |
166f1bb7 | 662 | return; |
7b18aad5 CH |
663 | } |
664 | memset((char *)req + len, 0, TARGET_PAGE_SIZE - len); | |
665 | res = (void *)((char *)req + len); | |
666 | command = be16_to_cpu(req->command); | |
667 | trace_ioinst_chsc_cmd(command, len); | |
668 | switch (command) { | |
669 | case CHSC_SCSC: | |
670 | ioinst_handle_chsc_scsc(req, res); | |
671 | break; | |
672 | case CHSC_SCPD: | |
673 | ioinst_handle_chsc_scpd(req, res); | |
674 | break; | |
675 | case CHSC_SDA: | |
676 | ioinst_handle_chsc_sda(req, res); | |
677 | break; | |
8cba80c3 FB |
678 | case CHSC_SEI: |
679 | ioinst_handle_chsc_sei(req, res); | |
680 | break; | |
7b18aad5 CH |
681 | default: |
682 | ioinst_handle_chsc_unimplemented(res); | |
683 | break; | |
684 | } | |
685 | ||
6cb1e49d AY |
686 | if (!s390_cpu_virt_mem_write(cpu, addr + len, reg, res, |
687 | be16_to_cpu(res->len))) { | |
166f1bb7 TH |
688 | setcc(cpu, 0); /* Command execution complete */ |
689 | } | |
7b18aad5 CH |
690 | } |
691 | ||
7781a492 | 692 | int ioinst_handle_tpi(S390CPU *cpu, uint32_t ipb) |
7b18aad5 | 693 | { |
7781a492 | 694 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
695 | uint64_t addr; |
696 | int lowcore; | |
7781a492 TH |
697 | IOIntCode int_code; |
698 | hwaddr len; | |
50c8d9bf | 699 | int ret; |
6cb1e49d | 700 | uint8_t ar; |
7b18aad5 CH |
701 | |
702 | trace_ioinst("tpi"); | |
6cb1e49d | 703 | addr = decode_basedisp_s(env, ipb, &ar); |
61bf0dcb TH |
704 | if (addr & 3) { |
705 | program_interrupt(env, PGM_SPECIFICATION, 2); | |
706 | return -EIO; | |
707 | } | |
708 | ||
7b18aad5 | 709 | lowcore = addr ? 0 : 1; |
50c8d9bf | 710 | len = lowcore ? 8 /* two words */ : 12 /* three words */; |
7781a492 TH |
711 | ret = css_do_tpi(&int_code, lowcore); |
712 | if (ret == 1) { | |
6cb1e49d | 713 | s390_cpu_virt_mem_write(cpu, lowcore ? 184 : addr, ar, &int_code, len); |
7b18aad5 | 714 | } |
50c8d9bf | 715 | return ret; |
7b18aad5 CH |
716 | } |
717 | ||
718 | #define SCHM_REG1_RES(_reg) (_reg & 0x000000000ffffffc) | |
719 | #define SCHM_REG1_MBK(_reg) ((_reg & 0x00000000f0000000) >> 28) | |
720 | #define SCHM_REG1_UPD(_reg) ((_reg & 0x0000000000000002) >> 1) | |
721 | #define SCHM_REG1_DCT(_reg) (_reg & 0x0000000000000001) | |
722 | ||
5d9bf1c0 TH |
723 | void ioinst_handle_schm(S390CPU *cpu, uint64_t reg1, uint64_t reg2, |
724 | uint32_t ipb) | |
7b18aad5 CH |
725 | { |
726 | uint8_t mbk; | |
727 | int update; | |
728 | int dct; | |
5d9bf1c0 | 729 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
730 | |
731 | trace_ioinst("schm"); | |
732 | ||
733 | if (SCHM_REG1_RES(reg1)) { | |
734 | program_interrupt(env, PGM_OPERAND, 2); | |
5d9bf1c0 | 735 | return; |
7b18aad5 CH |
736 | } |
737 | ||
738 | mbk = SCHM_REG1_MBK(reg1); | |
739 | update = SCHM_REG1_UPD(reg1); | |
740 | dct = SCHM_REG1_DCT(reg1); | |
741 | ||
7ae5a7c0 | 742 | if (update && (reg2 & 0x000000000000001f)) { |
7b18aad5 | 743 | program_interrupt(env, PGM_OPERAND, 2); |
5d9bf1c0 | 744 | return; |
7b18aad5 CH |
745 | } |
746 | ||
747 | css_do_schm(mbk, update, dct, update ? reg2 : 0); | |
7b18aad5 CH |
748 | } |
749 | ||
5d9bf1c0 | 750 | void ioinst_handle_rsch(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
751 | { |
752 | int cssid, ssid, schid, m; | |
753 | SubchDev *sch; | |
754 | int ret = -ENODEV; | |
755 | int cc; | |
756 | ||
757 | if (ioinst_disassemble_sch_ident(reg1, &m, &cssid, &ssid, &schid)) { | |
5d9bf1c0 TH |
758 | program_interrupt(&cpu->env, PGM_OPERAND, 2); |
759 | return; | |
7b18aad5 CH |
760 | } |
761 | trace_ioinst_sch_id("rsch", cssid, ssid, schid); | |
762 | sch = css_find_subch(m, cssid, ssid, schid); | |
763 | if (sch && css_subch_visible(sch)) { | |
764 | ret = css_do_rsch(sch); | |
765 | } | |
766 | switch (ret) { | |
767 | case -ENODEV: | |
768 | cc = 3; | |
769 | break; | |
770 | case -EINVAL: | |
771 | cc = 2; | |
772 | break; | |
773 | case 0: | |
774 | cc = 0; | |
775 | break; | |
776 | default: | |
777 | cc = 1; | |
778 | break; | |
779 | } | |
5d9bf1c0 | 780 | setcc(cpu, cc); |
7b18aad5 CH |
781 | } |
782 | ||
783 | #define RCHP_REG1_RES(_reg) (_reg & 0x00000000ff00ff00) | |
784 | #define RCHP_REG1_CSSID(_reg) ((_reg & 0x0000000000ff0000) >> 16) | |
785 | #define RCHP_REG1_CHPID(_reg) (_reg & 0x00000000000000ff) | |
5d9bf1c0 | 786 | void ioinst_handle_rchp(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
787 | { |
788 | int cc; | |
789 | uint8_t cssid; | |
790 | uint8_t chpid; | |
791 | int ret; | |
5d9bf1c0 | 792 | CPUS390XState *env = &cpu->env; |
7b18aad5 CH |
793 | |
794 | if (RCHP_REG1_RES(reg1)) { | |
795 | program_interrupt(env, PGM_OPERAND, 2); | |
5d9bf1c0 | 796 | return; |
7b18aad5 CH |
797 | } |
798 | ||
799 | cssid = RCHP_REG1_CSSID(reg1); | |
800 | chpid = RCHP_REG1_CHPID(reg1); | |
801 | ||
802 | trace_ioinst_chp_id("rchp", cssid, chpid); | |
803 | ||
804 | ret = css_do_rchp(cssid, chpid); | |
805 | ||
806 | switch (ret) { | |
807 | case -ENODEV: | |
808 | cc = 3; | |
809 | break; | |
810 | case -EBUSY: | |
811 | cc = 2; | |
812 | break; | |
813 | case 0: | |
814 | cc = 0; | |
815 | break; | |
816 | default: | |
817 | /* Invalid channel subsystem. */ | |
818 | program_interrupt(env, PGM_OPERAND, 2); | |
5d9bf1c0 | 819 | return; |
7b18aad5 | 820 | } |
5d9bf1c0 | 821 | setcc(cpu, cc); |
7b18aad5 CH |
822 | } |
823 | ||
824 | #define SAL_REG1_INVALID(_reg) (_reg & 0x0000000080000000) | |
5d9bf1c0 | 825 | void ioinst_handle_sal(S390CPU *cpu, uint64_t reg1) |
7b18aad5 CH |
826 | { |
827 | /* We do not provide address limit checking, so let's suppress it. */ | |
828 | if (SAL_REG1_INVALID(reg1) || reg1 & 0x000000000000ffff) { | |
5d9bf1c0 | 829 | program_interrupt(&cpu->env, PGM_OPERAND, 2); |
7b18aad5 | 830 | } |
7b18aad5 | 831 | } |