]> git.proxmox.com Git - mirror_qemu.git/blame - hw/s390x/s390-virtio-ccw.c
s390x/css: realize css_sch_build_schib
[mirror_qemu.git] / hw / s390x / s390-virtio-ccw.c
CommitLineData
a5c95808
CH
1/*
2 * virtio ccw machine
3 *
4 * Copyright 2012 IBM Corp.
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
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"
da34e65c 13#include "qapi/error.h"
4771d756
PB
14#include "qemu-common.h"
15#include "cpu.h"
a5c95808
CH
16#include "hw/boards.h"
17#include "exec/address-spaces.h"
18#include "s390-virtio.h"
83c9f4ca 19#include "hw/s390x/sclp.h"
3a553fc6 20#include "hw/s390x/s390_flic.h"
bd3f16ac
PB
21#include "hw/s390x/ioinst.h"
22#include "hw/s390x/css.h"
a5c95808 23#include "virtio-ccw.h"
b6fe0124 24#include "qemu/config-file.h"
8cba80c3 25#include "s390-pci-bus.h"
0f5f6691 26#include "hw/s390x/storage-keys.h"
54d8ec84 27#include "hw/compat.h"
04ca4b92 28#include "ipl.h"
8b8a61ad 29#include "hw/s390x/s390-virtio-ccw.h"
dd70bd0d 30#include "hw/s390x/css-bridge.h"
2eb1cd07 31
09c7f58c 32static const char *const reset_dev_types[] = {
3f9e4859 33 TYPE_VIRTUAL_CSS_BRIDGE,
09c7f58c
DH
34 "s390-sclp-event-facility",
35 "s390-flic",
36 "diag288",
37};
38
d9f090ec 39void subsystem_reset(void)
4e872a3f 40{
09c7f58c
DH
41 DeviceState *dev;
42 int i;
4e872a3f 43
09c7f58c
DH
44 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
45 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
46 if (dev) {
47 qdev_reset_all(dev);
48 }
0c7322cf 49 }
4e872a3f
CB
50}
51
a5c95808
CH
52static int virtio_ccw_hcall_notify(const uint64_t *args)
53{
54 uint64_t subch_id = args[0];
55 uint64_t queue = args[1];
56 SubchDev *sch;
57 int cssid, ssid, schid, m;
58
59 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
60 return -EINVAL;
61 }
62 sch = css_find_subch(m, cssid, ssid, schid);
63 if (!sch || !css_subch_visible(sch)) {
64 return -EINVAL;
65 }
b1914b82 66 if (queue >= VIRTIO_QUEUE_MAX) {
b57ed9bf
CH
67 return -EINVAL;
68 }
a5c95808
CH
69 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
70 return 0;
71
72}
73
74static int virtio_ccw_hcall_early_printk(const uint64_t *args)
75{
76 uint64_t mem = args[0];
77
78 if (mem < ram_size) {
79 /* Early printk */
80 return 0;
81 }
82 return -EINVAL;
83}
84
85static void virtio_ccw_register_hcalls(void)
86{
87 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
88 virtio_ccw_hcall_notify);
89 /* Tolerate early printk. */
90 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
91 virtio_ccw_hcall_early_printk);
92}
93
80d23275 94void s390_memory_init(ram_addr_t mem_size)
a5c95808 95{
a5c95808
CH
96 MemoryRegion *sysmem = get_system_memory();
97 MemoryRegion *ram = g_new(MemoryRegion, 1);
80d23275
DH
98
99 /* allocate RAM for core */
ae23a335 100 memory_region_allocate_system_memory(ram, NULL, "s390.ram", mem_size);
80d23275
DH
101 memory_region_add_subregion(sysmem, 0, ram);
102
103 /* Initialize storage key device */
104 s390_skeys_init();
105}
106
107static void ccw_init(MachineState *machine)
108{
a5c95808
CH
109 int ret;
110 VirtualCssBus *css_bus;
8cba80c3 111 DeviceState *dev;
b6fe0124 112
1cf065fb 113 s390_sclp_init();
80d23275 114 s390_memory_init(machine->ram_size);
a5c95808 115
c572d3f3
FL
116 s390_flic_init();
117
a5c95808
CH
118 /* get a BUS */
119 css_bus = virtual_css_bus_init();
3ef96221 120 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
5f31ade0
FA
121 machine->initrd_filename, "s390-ccw.img",
122 "s390-netboot.img", true);
a5c95808 123
8cba80c3
FB
124 dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
125 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
126 OBJECT(dev), NULL);
127 qdev_init_nofail(dev);
128
a5c95808
CH
129 /* register hypercalls */
130 virtio_ccw_register_hcalls();
131
a5c95808 132 /* init CPUs */
d2eae207 133 s390_init_cpus(machine);
a5c95808
CH
134
135 if (kvm_enabled()) {
136 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
137 }
138 /*
139 * Create virtual css and set it as default so that non mcss-e
140 * enabled guests only see virtio devices.
141 */
142 ret = css_create_css_image(VIRTUAL_CSSID, true);
143 assert(ret == 0);
144
145 /* Create VirtIO network adapters */
146 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
3f9e59bb
JH
147
148 /* Register savevm handler for guest TOD clock */
149 register_savevm(NULL, "todclock", 0, 1,
150 gtod_save, gtod_load, kvm_state);
a5c95808
CH
151}
152
502edbf8
MR
153static void s390_cpu_plug(HotplugHandler *hotplug_dev,
154 DeviceState *dev, Error **errp)
155{
156 gchar *name;
157 S390CPU *cpu = S390_CPU(dev);
158 CPUState *cs = CPU(dev);
159
160 name = g_strdup_printf("cpu[%i]", cpu->env.cpu_num);
161 object_property_set_link(OBJECT(hotplug_dev), OBJECT(cs), name,
162 errp);
163 g_free(name);
164}
165
166static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
167 DeviceState *dev, Error **errp)
168{
169 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
170 s390_cpu_plug(hotplug_dev, dev, errp);
171 }
172}
173
174static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
175 DeviceState *dev)
176{
177 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
178 return HOTPLUG_HANDLER(machine);
179 }
180 return NULL;
181}
182
a006b67f
MR
183static void s390_hot_add_cpu(const int64_t id, Error **errp)
184{
185 MachineState *machine = MACHINE(qdev_get_machine());
a006b67f 186
6b62d961 187 s390x_new_cpu(machine->cpu_model, id, errp);
a006b67f
MR
188}
189
d07aa7c7
AK
190static void ccw_machine_class_init(ObjectClass *oc, void *data)
191{
192 MachineClass *mc = MACHINE_CLASS(oc);
3dd7852f 193 NMIClass *nc = NMI_CLASS(oc);
502edbf8 194 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
9700230b 195 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
d07aa7c7 196
9700230b 197 s390mc->ri_allowed = true;
e73316d5 198 s390mc->cpu_model_allowed = true;
d07aa7c7 199 mc->init = ccw_init;
db3b2566 200 mc->reset = s390_machine_reset;
a006b67f 201 mc->hot_add_cpu = s390_hot_add_cpu;
d07aa7c7
AK
202 mc->block_default_type = IF_VIRTIO;
203 mc->no_cdrom = 1;
204 mc->no_floppy = 1;
205 mc->no_serial = 1;
206 mc->no_parallel = 1;
207 mc->no_sdcard = 1;
fb85b34d 208 mc->use_sclp = 1;
dcddc75e 209 mc->max_cpus = 248;
502edbf8
MR
210 mc->get_hotplug_handler = s390_get_hotplug_handler;
211 hc->plug = s390_machine_device_plug;
3dd7852f 212 nc->nmi_monitor_handler = s390_nmi;
d07aa7c7
AK
213}
214
2eb1cd07
TK
215static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
216{
217 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
218
219 return ms->aes_key_wrap;
220}
221
222static inline void machine_set_aes_key_wrap(Object *obj, bool value,
223 Error **errp)
224{
225 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
226
227 ms->aes_key_wrap = value;
228}
229
230static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
231{
232 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
233
234 return ms->dea_key_wrap;
235}
236
237static inline void machine_set_dea_key_wrap(Object *obj, bool value,
238 Error **errp)
239{
240 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
241
242 ms->dea_key_wrap = value;
243}
244
9700230b
FZ
245bool ri_allowed(void)
246{
247 if (kvm_enabled()) {
248 MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
249 if (object_class_dynamic_cast(OBJECT_CLASS(mc),
250 TYPE_S390_CCW_MACHINE)) {
251 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
252
253 return s390mc->ri_allowed;
254 }
392529cb
DH
255 /*
256 * Make sure the "none" machine can have ri, otherwise it won't * be
257 * unlocked in KVM and therefore the host CPU model might be wrong.
258 */
259 return true;
9700230b
FZ
260 }
261 return 0;
262}
263
e73316d5
CB
264bool cpu_model_allowed(void)
265{
266 MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
267 if (object_class_dynamic_cast(OBJECT_CLASS(mc),
268 TYPE_S390_CCW_MACHINE)) {
269 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
270
271 return s390mc->cpu_model_allowed;
272 }
273 /* allow CPU model qmp queries with the "none" machine */
274 return true;
275}
276
7104bae9
FA
277static char *machine_get_loadparm(Object *obj, Error **errp)
278{
279 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
280
281 return g_memdup(ms->loadparm, sizeof(ms->loadparm));
282}
283
284static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
285{
286 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
287 int i;
288
289 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
290 uint8_t c = toupper(val[i]); /* mimic HMC */
291
292 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
293 (c == ' ')) {
294 ms->loadparm[i] = c;
295 } else {
296 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
297 c, c);
298 return;
299 }
300 }
301
302 for (; i < sizeof(ms->loadparm); i++) {
303 ms->loadparm[i] = ' '; /* pad right with spaces */
304 }
305}
274250c3
XFR
306static inline bool machine_get_squash_mcss(Object *obj, Error **errp)
307{
308 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
309
310 return ms->s390_squash_mcss;
311}
312
313static inline void machine_set_squash_mcss(Object *obj, bool value,
314 Error **errp)
315{
316 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
317
318 ms->s390_squash_mcss = value;
319}
7104bae9 320
2eb1cd07
TK
321static inline void s390_machine_initfn(Object *obj)
322{
323 object_property_add_bool(obj, "aes-key-wrap",
324 machine_get_aes_key_wrap,
325 machine_set_aes_key_wrap, NULL);
326 object_property_set_description(obj, "aes-key-wrap",
327 "enable/disable AES key wrapping using the CPACF wrapping key",
328 NULL);
329 object_property_set_bool(obj, true, "aes-key-wrap", NULL);
330
331 object_property_add_bool(obj, "dea-key-wrap",
332 machine_get_dea_key_wrap,
333 machine_set_dea_key_wrap, NULL);
334 object_property_set_description(obj, "dea-key-wrap",
335 "enable/disable DEA key wrapping using the CPACF wrapping key",
336 NULL);
337 object_property_set_bool(obj, true, "dea-key-wrap", NULL);
7104bae9
FA
338 object_property_add_str(obj, "loadparm",
339 machine_get_loadparm, machine_set_loadparm, NULL);
340 object_property_set_description(obj, "loadparm",
341 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
342 " to upper case) to pass to machine loader, boot manager,"
343 " and guest kernel",
344 NULL);
274250c3
XFR
345 object_property_add_bool(obj, "s390-squash-mcss",
346 machine_get_squash_mcss,
347 machine_set_squash_mcss, NULL);
348 object_property_set_description(obj, "s390-squash-mcss",
349 "enable/disable squashing subchannels into the default css",
350 NULL);
351 object_property_set_bool(obj, false, "s390-squash-mcss", NULL);
2eb1cd07
TK
352}
353
d07aa7c7
AK
354static const TypeInfo ccw_machine_info = {
355 .name = TYPE_S390_CCW_MACHINE,
356 .parent = TYPE_MACHINE,
c4d3c0a2 357 .abstract = true,
2eb1cd07
TK
358 .instance_size = sizeof(S390CcwMachineState),
359 .instance_init = s390_machine_initfn,
9700230b 360 .class_size = sizeof(S390CcwMachineClass),
d07aa7c7 361 .class_init = ccw_machine_class_init,
3dd7852f
AK
362 .interfaces = (InterfaceInfo[]) {
363 { TYPE_NMI },
502edbf8 364 { TYPE_HOTPLUG_HANDLER},
3dd7852f
AK
365 { }
366 },
a5c95808
CH
367};
368
4fca6548
JF
369#define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
370 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
371 void *data) \
372 { \
373 MachineClass *mc = MACHINE_CLASS(oc); \
374 ccw_machine_##suffix##_class_options(mc); \
375 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
376 if (latest) { \
377 mc->alias = "s390-ccw-virtio"; \
378 mc->is_default = 1; \
379 } \
380 } \
381 static void ccw_machine_##suffix##_instance_init(Object *obj) \
382 { \
383 MachineState *machine = MACHINE(obj); \
384 ccw_machine_##suffix##_instance_options(machine); \
385 } \
386 static const TypeInfo ccw_machine_##suffix##_info = { \
387 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
388 .parent = TYPE_S390_CCW_MACHINE, \
389 .class_init = ccw_machine_##suffix##_class_init, \
390 .instance_init = ccw_machine_##suffix##_instance_init, \
391 }; \
392 static void ccw_machine_register_##suffix(void) \
393 { \
394 type_register_static(&ccw_machine_##suffix##_info); \
395 } \
0e6aac87 396 type_init(ccw_machine_register_##suffix)
4fca6548 397
10890873
CH
398#define CCW_COMPAT_2_9 \
399 HW_COMPAT_2_9
400
113725a6 401#define CCW_COMPAT_2_8 \
069097da
HP
402 HW_COMPAT_2_8 \
403 {\
404 .driver = TYPE_S390_FLIC_COMMON,\
405 .property = "adapter_routes_max_batch",\
406 .value = "64",\
407 },
113725a6 408
61823988
CH
409#define CCW_COMPAT_2_7 \
410 HW_COMPAT_2_7
411
946e55f3 412#define CCW_COMPAT_2_6 \
04ca4b92
AY
413 HW_COMPAT_2_6 \
414 {\
415 .driver = TYPE_S390_IPL,\
416 .property = "iplbext_migration",\
417 .value = "off",\
2a79eb1a
CH
418 }, {\
419 .driver = TYPE_VIRTUAL_CSS_BRIDGE,\
420 .property = "css_dev_path",\
421 .value = "off",\
04ca4b92 422 },
946e55f3 423
cf87e0a3
SL
424#define CCW_COMPAT_2_5 \
425 HW_COMPAT_2_5
426
9ef40173 427#define CCW_COMPAT_2_4 \
54d8ec84 428 HW_COMPAT_2_4 \
9ef40173
JH
429 {\
430 .driver = TYPE_S390_SKEYS,\
431 .property = "migration-enabled",\
432 .value = "off",\
542571d5
CH
433 },{\
434 .driver = "virtio-blk-ccw",\
435 .property = "max_revision",\
436 .value = "0",\
437 },{\
438 .driver = "virtio-balloon-ccw",\
439 .property = "max_revision",\
440 .value = "0",\
441 },{\
442 .driver = "virtio-serial-ccw",\
443 .property = "max_revision",\
444 .value = "0",\
445 },{\
446 .driver = "virtio-9p-ccw",\
447 .property = "max_revision",\
448 .value = "0",\
449 },{\
450 .driver = "virtio-rng-ccw",\
451 .property = "max_revision",\
452 .value = "0",\
085b0b05
CH
453 },{\
454 .driver = "virtio-net-ccw",\
455 .property = "max_revision",\
456 .value = "0",\
457 },{\
458 .driver = "virtio-scsi-ccw",\
459 .property = "max_revision",\
460 .value = "0",\
461 },{\
462 .driver = "vhost-scsi-ccw",\
463 .property = "max_revision",\
464 .value = "0",\
9ef40173
JH
465 },
466
10890873
CH
467static void ccw_machine_2_10_instance_options(MachineState *machine)
468{
469}
470
471static void ccw_machine_2_10_class_options(MachineClass *mc)
472{
473}
474DEFINE_CCW_MACHINE(2_10, "2.10", true);
475
113725a6
CH
476static void ccw_machine_2_9_instance_options(MachineState *machine)
477{
10890873 478 ccw_machine_2_10_instance_options(machine);
113725a6
CH
479}
480
481static void ccw_machine_2_9_class_options(MachineClass *mc)
482{
10890873
CH
483 ccw_machine_2_10_class_options(mc);
484 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_9);
113725a6 485}
10890873 486DEFINE_CCW_MACHINE(2_9, "2.9", false);
113725a6 487
61823988
CH
488static void ccw_machine_2_8_instance_options(MachineState *machine)
489{
113725a6 490 ccw_machine_2_9_instance_options(machine);
61823988
CH
491}
492
493static void ccw_machine_2_8_class_options(MachineClass *mc)
494{
113725a6
CH
495 ccw_machine_2_9_class_options(mc);
496 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_8);
61823988 497}
113725a6 498DEFINE_CCW_MACHINE(2_8, "2.8", false);
61823988 499
946e55f3
CH
500static void ccw_machine_2_7_instance_options(MachineState *machine)
501{
61823988 502 ccw_machine_2_8_instance_options(machine);
946e55f3
CH
503}
504
505static void ccw_machine_2_7_class_options(MachineClass *mc)
506{
e73316d5
CB
507 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
508
509 s390mc->cpu_model_allowed = false;
61823988
CH
510 ccw_machine_2_8_class_options(mc);
511 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_7);
946e55f3 512}
61823988 513DEFINE_CCW_MACHINE(2_7, "2.7", false);
946e55f3 514
4fca6548 515static void ccw_machine_2_6_instance_options(MachineState *machine)
c4d3c0a2 516{
946e55f3 517 ccw_machine_2_7_instance_options(machine);
c4d3c0a2
CB
518}
519
4fca6548 520static void ccw_machine_2_6_class_options(MachineClass *mc)
84b48ad6 521{
9700230b
FZ
522 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
523
524 s390mc->ri_allowed = false;
946e55f3
CH
525 ccw_machine_2_7_class_options(mc);
526 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_6);
84b48ad6 527}
946e55f3 528DEFINE_CCW_MACHINE(2_6, "2.6", false);
84b48ad6 529
4fca6548
JF
530static void ccw_machine_2_5_instance_options(MachineState *machine)
531{
946e55f3 532 ccw_machine_2_6_instance_options(machine);
4fca6548 533}
84b48ad6 534
4fca6548 535static void ccw_machine_2_5_class_options(MachineClass *mc)
b21b7598 536{
946e55f3 537 ccw_machine_2_6_class_options(mc);
4fca6548
JF
538 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_5);
539}
540DEFINE_CCW_MACHINE(2_5, "2.5", false);
b21b7598 541
4fca6548
JF
542static void ccw_machine_2_4_instance_options(MachineState *machine)
543{
544 ccw_machine_2_5_instance_options(machine);
b21b7598
CH
545}
546
4fca6548
JF
547static void ccw_machine_2_4_class_options(MachineClass *mc)
548{
946e55f3 549 ccw_machine_2_5_class_options(mc);
4fca6548
JF
550 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_4);
551}
552DEFINE_CCW_MACHINE(2_4, "2.4", false);
b21b7598 553
d07aa7c7 554static void ccw_machine_register_types(void)
a5c95808 555{
d07aa7c7 556 type_register_static(&ccw_machine_info);
a5c95808
CH
557}
558
d07aa7c7 559type_init(ccw_machine_register_types)