]> git.proxmox.com Git - mirror_qemu.git/blame - hw/s390x/s390-virtio-ccw.c
s390x/event-facility: fix error propagation
[mirror_qemu.git] / hw / s390x / s390-virtio-ccw.c
CommitLineData
a5c95808
CH
1/*
2 * virtio ccw machine
3 *
4 * Copyright 2012 IBM Corp.
6286b419 5 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
a5c95808
CH
6 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
10 * directory.
11 */
12
9615495a 13#include "qemu/osdep.h"
da34e65c 14#include "qapi/error.h"
4771d756 15#include "cpu.h"
a5c95808
CH
16#include "hw/boards.h"
17#include "exec/address-spaces.h"
9138977b 18#include "exec/ram_addr.h"
7d577546 19#include "hw/s390x/s390-virtio-hcall.h"
83c9f4ca 20#include "hw/s390x/sclp.h"
3a553fc6 21#include "hw/s390x/s390_flic.h"
bd3f16ac
PB
22#include "hw/s390x/ioinst.h"
23#include "hw/s390x/css.h"
a5c95808 24#include "virtio-ccw.h"
b6fe0124 25#include "qemu/config-file.h"
856dfd8a 26#include "qemu/ctype.h"
b5684cd8 27#include "qemu/error-report.h"
922a01a0 28#include "qemu/option.h"
8cba80c3 29#include "s390-pci-bus.h"
71e8a915 30#include "sysemu/reset.h"
0f5f6691 31#include "hw/s390x/storage-keys.h"
903fd80b 32#include "hw/s390x/storage-attributes.h"
bc61c8c6 33#include "hw/s390x/event-facility.h"
04ca4b92 34#include "ipl.h"
8b8a61ad 35#include "hw/s390x/s390-virtio-ccw.h"
dd70bd0d 36#include "hw/s390x/css-bridge.h"
a51b3153 37#include "hw/s390x/ap-bridge.h"
f2a8f0a6 38#include "migration/register.h"
7223bcce 39#include "cpu_models.h"
6286b419 40#include "hw/nmi.h"
a27bd6c7 41#include "hw/qdev-properties.h"
8046f374 42#include "hw/s390x/tod.h"
2f780b6a 43#include "sysemu/sysemu.h"
6286b419 44
6286b419
DH
45S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
46{
2b44178d
DH
47 static MachineState *ms;
48
49 if (!ms) {
50 ms = MACHINE(qdev_get_machine());
51 g_assert(ms->possible_cpus);
6286b419
DH
52 }
53
2b44178d
DH
54 /* CPU address corresponds to the core_id and the index */
55 if (cpu_addr >= ms->possible_cpus->len) {
56 return NULL;
57 }
58 return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
6286b419
DH
59}
60
32dc6aa0
IM
61static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
62 Error **errp)
63{
64 S390CPU *cpu = S390_CPU(object_new(typename));
65 Error *err = NULL;
66
67 object_property_set_int(OBJECT(cpu), core_id, "core-id", &err);
68 if (err != NULL) {
69 goto out;
70 }
71 object_property_set_bool(OBJECT(cpu), true, "realized", &err);
72
73out:
74 object_unref(OBJECT(cpu));
75 if (err) {
76 error_propagate(errp, err);
77 cpu = NULL;
78 }
79 return cpu;
80}
81
6286b419
DH
82static void s390_init_cpus(MachineState *machine)
83{
4dc3b151 84 MachineClass *mc = MACHINE_GET_CLASS(machine);
6286b419 85 int i;
6286b419 86
4dc3b151
DH
87 /* initialize possible_cpus */
88 mc->possible_cpu_arch_ids(machine);
89
ae71ed86 90 for (i = 0; i < machine->smp.cpus; i++) {
b6805e12 91 s390x_new_cpu(machine->cpu_type, i, &error_fatal);
6286b419
DH
92 }
93}
2eb1cd07 94
09c7f58c 95static const char *const reset_dev_types[] = {
3f9e4859 96 TYPE_VIRTUAL_CSS_BRIDGE,
09c7f58c
DH
97 "s390-sclp-event-facility",
98 "s390-flic",
99 "diag288",
100};
101
a30fb811 102static void subsystem_reset(void)
4e872a3f 103{
09c7f58c
DH
104 DeviceState *dev;
105 int i;
4e872a3f 106
09c7f58c
DH
107 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
108 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
109 if (dev) {
110 qdev_reset_all(dev);
111 }
0c7322cf 112 }
4e872a3f
CB
113}
114
a5c95808
CH
115static int virtio_ccw_hcall_notify(const uint64_t *args)
116{
117 uint64_t subch_id = args[0];
118 uint64_t queue = args[1];
119 SubchDev *sch;
120 int cssid, ssid, schid, m;
121
122 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
123 return -EINVAL;
124 }
125 sch = css_find_subch(m, cssid, ssid, schid);
126 if (!sch || !css_subch_visible(sch)) {
127 return -EINVAL;
128 }
b1914b82 129 if (queue >= VIRTIO_QUEUE_MAX) {
b57ed9bf
CH
130 return -EINVAL;
131 }
a5c95808
CH
132 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
133 return 0;
134
135}
136
137static int virtio_ccw_hcall_early_printk(const uint64_t *args)
138{
139 uint64_t mem = args[0];
140
141 if (mem < ram_size) {
142 /* Early printk */
143 return 0;
144 }
145 return -EINVAL;
146}
147
148static void virtio_ccw_register_hcalls(void)
149{
150 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
151 virtio_ccw_hcall_notify);
152 /* Tolerate early printk. */
153 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
154 virtio_ccw_hcall_early_printk);
155}
156
6286b419 157static void s390_memory_init(ram_addr_t mem_size)
a5c95808 158{
a5c95808 159 MemoryRegion *sysmem = get_system_memory();
fb1fc5a8 160 MemoryRegion *ram = g_new(MemoryRegion, 1);
9138977b 161 Error *local_err = NULL;
80d23275
DH
162
163 /* allocate RAM for core */
fb1fc5a8
IM
164 memory_region_allocate_system_memory(ram, NULL, "s390.ram", mem_size);
165 memory_region_add_subregion(sysmem, 0, ram);
80d23275 166
9138977b
DH
167 /*
168 * Configure the maximum page size. As no memory devices were created
169 * yet, this is the page size of initial memory only.
170 */
905b7ee4 171 s390_set_max_pagesize(qemu_maxrampagesize(), &local_err);
9138977b
DH
172 if (local_err) {
173 error_report_err(local_err);
174 exit(EXIT_FAILURE);
175 }
80d23275
DH
176 /* Initialize storage key device */
177 s390_skeys_init();
903fd80b
CI
178 /* Initialize storage attributes device */
179 s390_stattrib_init();
80d23275
DH
180}
181
6286b419
DH
182static void s390_init_ipl_dev(const char *kernel_filename,
183 const char *kernel_cmdline,
184 const char *initrd_filename, const char *firmware,
185 const char *netboot_fw, bool enforce_bios)
186{
187 Object *new = object_new(TYPE_S390_IPL);
188 DeviceState *dev = DEVICE(new);
d9b06db8 189 char *netboot_fw_prop;
6286b419
DH
190
191 if (kernel_filename) {
192 qdev_prop_set_string(dev, "kernel", kernel_filename);
193 }
194 if (initrd_filename) {
195 qdev_prop_set_string(dev, "initrd", initrd_filename);
196 }
197 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
198 qdev_prop_set_string(dev, "firmware", firmware);
6286b419 199 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
d9b06db8
GK
200 netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
201 if (!strlen(netboot_fw_prop)) {
3c4e9baa
TH
202 qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
203 }
d9b06db8 204 g_free(netboot_fw_prop);
6286b419
DH
205 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
206 new, NULL);
207 object_unref(new);
208 qdev_init_nofail(dev);
209}
210
211static void s390_create_virtio_net(BusState *bus, const char *name)
212{
213 int i;
214
215 for (i = 0; i < nb_nics; i++) {
216 NICInfo *nd = &nd_table[i];
217 DeviceState *dev;
218
219 if (!nd->model) {
220 nd->model = g_strdup("virtio");
221 }
222
223 qemu_check_nic_model(nd, "virtio");
224
225 dev = qdev_create(bus, name);
226 qdev_set_nic_properties(dev, nd);
227 qdev_init_nofail(dev);
228 }
229}
230
052888f0
TH
231static void s390_create_sclpconsole(const char *type, Chardev *chardev)
232{
233 DeviceState *dev;
234
235 dev = qdev_create(sclp_get_event_facility_bus(), type);
236 qdev_prop_set_chr(dev, "chardev", chardev);
237 qdev_init_nofail(dev);
238}
239
80d23275
DH
240static void ccw_init(MachineState *machine)
241{
a5c95808
CH
242 int ret;
243 VirtualCssBus *css_bus;
c1843e20 244 DeviceState *dev;
b6fe0124 245
1cf065fb 246 s390_sclp_init();
9138977b 247 /* init memory + setup max page size. Required for the CPU model */
80d23275 248 s390_memory_init(machine->ram_size);
a5c95808 249
d32bd032 250 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
3720d335
YMZ
251 s390_init_cpus(machine);
252
c572d3f3
FL
253 s390_flic_init();
254
74b4c74d
DH
255 /* init the SIGP facility */
256 s390_init_sigp();
257
a51b3153
TK
258 /* create AP bridge and bus(es) */
259 s390_init_ap();
260
a5c95808
CH
261 /* get a BUS */
262 css_bus = virtual_css_bus_init();
3ef96221 263 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
5f31ade0
FA
264 machine->initrd_filename, "s390-ccw.img",
265 "s390-netboot.img", true);
a5c95808 266
c1843e20
CB
267 dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
268 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
269 OBJECT(dev), NULL);
270 qdev_init_nofail(dev);
8cba80c3 271
a5c95808
CH
272 /* register hypercalls */
273 virtio_ccw_register_hcalls();
274
5e7164c5 275 s390_enable_css_support(s390_cpu_addr2state(0));
36699ab4
CH
276
277 ret = css_create_css_image(VIRTUAL_CSSID, true);
d69969e5 278
a5c95808 279 assert(ret == 0);
489c909f
HP
280 if (css_migration_enabled()) {
281 css_register_vmstate();
282 }
a5c95808
CH
283
284 /* Create VirtIO network adapters */
285 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
3f9e59bb 286
052888f0
TH
287 /* init consoles */
288 if (serial_hd(0)) {
289 s390_create_sclpconsole("sclpconsole", serial_hd(0));
290 }
291 if (serial_hd(1)) {
292 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
293 }
294
8046f374
DH
295 /* init the TOD clock */
296 s390_init_tod();
a5c95808
CH
297}
298
502edbf8
MR
299static void s390_cpu_plug(HotplugHandler *hotplug_dev,
300 DeviceState *dev, Error **errp)
301{
4dc3b151 302 MachineState *ms = MACHINE(hotplug_dev);
502edbf8 303 S390CPU *cpu = S390_CPU(dev);
4dc3b151
DH
304
305 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
306 ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
c5b93430
DH
307
308 if (dev->hotplugged) {
309 raise_irq_cpu_hotplug();
310 }
502edbf8
MR
311}
312
a30fb811
DH
313static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
314{
315 S390CPU *cpu = S390_CPU(cs);
316
317 s390_ipl_prepare_cpu(cpu);
318 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
319}
320
a0628599 321static void s390_machine_reset(MachineState *machine)
6286b419 322{
a30fb811
DH
323 enum s390_reset reset_type;
324 CPUState *cs, *t;
6286b419 325
a30fb811
DH
326 /* get the reset parameters, reset them once done */
327 s390_ipl_get_reset_request(&cs, &reset_type);
328
329 /* all CPUs are paused and synchronized at this point */
6286b419 330 s390_cmma_reset();
6286b419 331
a30fb811
DH
332 switch (reset_type) {
333 case S390_RESET_EXTERNAL:
334 case S390_RESET_REIPL:
335 qemu_devices_reset();
336 s390_crypto_reset();
337
338 /* configure and start the ipl CPU only */
339 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
340 break;
341 case S390_RESET_MODIFIED_CLEAR:
342 CPU_FOREACH(t) {
343 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
344 }
345 subsystem_reset();
346 s390_crypto_reset();
347 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
348 break;
349 case S390_RESET_LOAD_NORMAL:
350 CPU_FOREACH(t) {
ec922733
JF
351 if (t == cs) {
352 continue;
353 }
a30fb811
DH
354 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
355 }
356 subsystem_reset();
357 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
358 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
359 break;
360 default:
361 g_assert_not_reached();
362 }
363 s390_ipl_clear_reset_request();
6286b419
DH
364}
365
502edbf8
MR
366static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
367 DeviceState *dev, Error **errp)
368{
369 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
370 s390_cpu_plug(hotplug_dev, dev, errp);
371 }
372}
373
f2f3beb0
DH
374static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
375 DeviceState *dev, Error **errp)
376{
377 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
378 error_setg(errp, "CPU hot unplug not supported on this machine");
379 return;
380 }
381}
382
81ce6aa5 383static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
4dc3b151
DH
384 unsigned cpu_index)
385{
81ce6aa5
DH
386 MachineClass *mc = MACHINE_GET_CLASS(ms);
387 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
4dc3b151 388
81ce6aa5
DH
389 assert(cpu_index < possible_cpus->len);
390 return possible_cpus->cpus[cpu_index].props;
4dc3b151
DH
391}
392
393static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
394{
395 int i;
ae71ed86 396 unsigned int max_cpus = ms->smp.max_cpus;
4dc3b151
DH
397
398 if (ms->possible_cpus) {
399 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
400 return ms->possible_cpus;
401 }
402
403 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
404 sizeof(CPUArchId) * max_cpus);
405 ms->possible_cpus->len = max_cpus;
406 for (i = 0; i < ms->possible_cpus->len; i++) {
d342eb76 407 ms->possible_cpus->cpus[i].type = ms->cpu_type;
4dc3b151
DH
408 ms->possible_cpus->cpus[i].vcpus_count = 1;
409 ms->possible_cpus->cpus[i].arch_id = i;
410 ms->possible_cpus->cpus[i].props.has_core_id = true;
411 ms->possible_cpus->cpus[i].props.core_id = i;
412 }
413
414 return ms->possible_cpus;
415}
416
502edbf8
MR
417static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
418 DeviceState *dev)
419{
420 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
421 return HOTPLUG_HANDLER(machine);
422 }
423 return NULL;
424}
425
a0628599
LX
426static void s390_hot_add_cpu(MachineState *machine,
427 const int64_t id, Error **errp)
a006b67f 428{
524d18d8
DH
429 ObjectClass *oc;
430
431 g_assert(machine->possible_cpus->cpus[0].cpu);
432 oc = OBJECT_CLASS(CPU_GET_CLASS(machine->possible_cpus->cpus[0].cpu));
a006b67f 433
524d18d8 434 s390x_new_cpu(object_class_get_name(oc), id, errp);
a006b67f
MR
435}
436
6286b419
DH
437static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
438{
439 CPUState *cs = qemu_get_cpu(cpu_index);
440
0fc60ca5 441 s390_cpu_restart(S390_CPU(cs));
6286b419
DH
442}
443
d07aa7c7
AK
444static void ccw_machine_class_init(ObjectClass *oc, void *data)
445{
446 MachineClass *mc = MACHINE_CLASS(oc);
3dd7852f 447 NMIClass *nc = NMI_CLASS(oc);
502edbf8 448 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
9700230b 449 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
d07aa7c7 450
9700230b 451 s390mc->ri_allowed = true;
e73316d5 452 s390mc->cpu_model_allowed = true;
e996583e 453 s390mc->css_migration_enabled = true;
28221f9c 454 s390mc->hpage_1m_allowed = true;
d07aa7c7 455 mc->init = ccw_init;
db3b2566 456 mc->reset = s390_machine_reset;
a006b67f 457 mc->hot_add_cpu = s390_hot_add_cpu;
d07aa7c7
AK
458 mc->block_default_type = IF_VIRTIO;
459 mc->no_cdrom = 1;
460 mc->no_floppy = 1;
d07aa7c7
AK
461 mc->no_parallel = 1;
462 mc->no_sdcard = 1;
f42dc44a 463 mc->max_cpus = S390_MAX_CPUS;
4dc3b151 464 mc->has_hotpluggable_cpus = true;
debbdc00 465 assert(!mc->get_hotplug_handler);
502edbf8 466 mc->get_hotplug_handler = s390_get_hotplug_handler;
4dc3b151
DH
467 mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
468 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
b6805e12
IM
469 /* it is overridden with 'host' cpu *in kvm_arch_init* */
470 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
502edbf8 471 hc->plug = s390_machine_device_plug;
f2f3beb0 472 hc->unplug_request = s390_machine_device_unplug_request;
3dd7852f 473 nc->nmi_monitor_handler = s390_nmi;
d07aa7c7
AK
474}
475
2eb1cd07
TK
476static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
477{
478 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
479
480 return ms->aes_key_wrap;
481}
482
483static inline void machine_set_aes_key_wrap(Object *obj, bool value,
484 Error **errp)
485{
486 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
487
488 ms->aes_key_wrap = value;
489}
490
491static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
492{
493 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
494
495 return ms->dea_key_wrap;
496}
497
498static inline void machine_set_dea_key_wrap(Object *obj, bool value,
499 Error **errp)
500{
501 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
502
503 ms->dea_key_wrap = value;
504}
505
cec8bbf7 506static S390CcwMachineClass *current_mc;
9700230b 507
cec8bbf7
HP
508static S390CcwMachineClass *get_machine_class(void)
509{
510 if (unlikely(!current_mc)) {
392529cb 511 /*
cec8bbf7
HP
512 * No s390 ccw machine was instantiated, we are likely to
513 * be called for the 'none' machine. The properties will
514 * have their after-initialization values.
515 */
516 current_mc = S390_MACHINE_CLASS(
517 object_class_by_name(TYPE_S390_CCW_MACHINE));
9700230b 518 }
cec8bbf7 519 return current_mc;
9700230b
FZ
520}
521
cec8bbf7 522bool ri_allowed(void)
e73316d5 523{
cec8bbf7
HP
524 /* for "none" machine this results in true */
525 return get_machine_class()->ri_allowed;
526}
527
528bool cpu_model_allowed(void)
529{
530 /* for "none" machine this results in true */
531 return get_machine_class()->cpu_model_allowed;
e73316d5
CB
532}
533
28221f9c
JF
534bool hpage_1m_allowed(void)
535{
536 /* for "none" machine this results in true */
537 return get_machine_class()->hpage_1m_allowed;
538}
539
7104bae9
FA
540static char *machine_get_loadparm(Object *obj, Error **errp)
541{
542 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
543
544 return g_memdup(ms->loadparm, sizeof(ms->loadparm));
545}
546
547static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
548{
549 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
550 int i;
551
552 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
95a5befc 553 uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
7104bae9
FA
554
555 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
556 (c == ' ')) {
557 ms->loadparm[i] = c;
558 } else {
559 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
560 c, c);
561 return;
562 }
563 }
564
565 for (; i < sizeof(ms->loadparm); i++) {
566 ms->loadparm[i] = ' '; /* pad right with spaces */
567 }
568}
2eb1cd07
TK
569static inline void s390_machine_initfn(Object *obj)
570{
571 object_property_add_bool(obj, "aes-key-wrap",
572 machine_get_aes_key_wrap,
573 machine_set_aes_key_wrap, NULL);
574 object_property_set_description(obj, "aes-key-wrap",
575 "enable/disable AES key wrapping using the CPACF wrapping key",
576 NULL);
577 object_property_set_bool(obj, true, "aes-key-wrap", NULL);
578
579 object_property_add_bool(obj, "dea-key-wrap",
580 machine_get_dea_key_wrap,
581 machine_set_dea_key_wrap, NULL);
582 object_property_set_description(obj, "dea-key-wrap",
583 "enable/disable DEA key wrapping using the CPACF wrapping key",
584 NULL);
585 object_property_set_bool(obj, true, "dea-key-wrap", NULL);
7104bae9
FA
586 object_property_add_str(obj, "loadparm",
587 machine_get_loadparm, machine_set_loadparm, NULL);
588 object_property_set_description(obj, "loadparm",
589 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
590 " to upper case) to pass to machine loader, boot manager,"
591 " and guest kernel",
592 NULL);
2eb1cd07
TK
593}
594
d07aa7c7
AK
595static const TypeInfo ccw_machine_info = {
596 .name = TYPE_S390_CCW_MACHINE,
597 .parent = TYPE_MACHINE,
c4d3c0a2 598 .abstract = true,
2eb1cd07
TK
599 .instance_size = sizeof(S390CcwMachineState),
600 .instance_init = s390_machine_initfn,
9700230b 601 .class_size = sizeof(S390CcwMachineClass),
d07aa7c7 602 .class_init = ccw_machine_class_init,
3dd7852f
AK
603 .interfaces = (InterfaceInfo[]) {
604 { TYPE_NMI },
502edbf8 605 { TYPE_HOTPLUG_HANDLER},
3dd7852f
AK
606 { }
607 },
a5c95808
CH
608};
609
52629b3b
HP
610bool css_migration_enabled(void)
611{
612 return get_machine_class()->css_migration_enabled;
613}
614
4fca6548
JF
615#define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
616 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
617 void *data) \
618 { \
619 MachineClass *mc = MACHINE_CLASS(oc); \
620 ccw_machine_##suffix##_class_options(mc); \
621 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
622 if (latest) { \
623 mc->alias = "s390-ccw-virtio"; \
624 mc->is_default = 1; \
625 } \
626 } \
627 static void ccw_machine_##suffix##_instance_init(Object *obj) \
628 { \
629 MachineState *machine = MACHINE(obj); \
cec8bbf7 630 current_mc = S390_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
4fca6548
JF
631 ccw_machine_##suffix##_instance_options(machine); \
632 } \
633 static const TypeInfo ccw_machine_##suffix##_info = { \
634 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
635 .parent = TYPE_S390_CCW_MACHINE, \
636 .class_init = ccw_machine_##suffix##_class_init, \
637 .instance_init = ccw_machine_##suffix##_instance_init, \
638 }; \
639 static void ccw_machine_register_##suffix(void) \
640 { \
641 type_register_static(&ccw_machine_##suffix##_info); \
642 } \
0e6aac87 643 type_init(ccw_machine_register_##suffix)
4fca6548 644
3eb74d20
CH
645static void ccw_machine_5_0_instance_options(MachineState *machine)
646{
647}
648
649static void ccw_machine_5_0_class_options(MachineClass *mc)
650{
651}
652DEFINE_CCW_MACHINE(5_0, "5.0", true);
653
9aec2e52
CH
654static void ccw_machine_4_2_instance_options(MachineState *machine)
655{
3eb74d20 656 ccw_machine_5_0_instance_options(machine);
9aec2e52
CH
657}
658
659static void ccw_machine_4_2_class_options(MachineClass *mc)
660{
3eb74d20 661 ccw_machine_5_0_class_options(mc);
5f258577 662 compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
9aec2e52 663}
3eb74d20 664DEFINE_CCW_MACHINE(4_2, "4.2", false);
9aec2e52 665
9bf2650b
CH
666static void ccw_machine_4_1_instance_options(MachineState *machine)
667{
faa40177 668 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
9aec2e52 669 ccw_machine_4_2_instance_options(machine);
faa40177 670 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
9bf2650b
CH
671}
672
673static void ccw_machine_4_1_class_options(MachineClass *mc)
674{
9aec2e52
CH
675 ccw_machine_4_2_class_options(mc);
676 compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
9bf2650b 677}
9aec2e52 678DEFINE_CCW_MACHINE(4_1, "4.1", false);
9bf2650b 679
8c7b0c73
CH
680static void ccw_machine_4_0_instance_options(MachineState *machine)
681{
08ef92d5 682 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
9bf2650b 683 ccw_machine_4_1_instance_options(machine);
08ef92d5 684 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
8c7b0c73
CH
685}
686
687static void ccw_machine_4_0_class_options(MachineClass *mc)
688{
9bf2650b
CH
689 ccw_machine_4_1_class_options(mc);
690 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
8c7b0c73 691}
9bf2650b 692DEFINE_CCW_MACHINE(4_0, "4.0", false);
8c7b0c73 693
9ca056d6
CH
694static void ccw_machine_3_1_instance_options(MachineState *machine)
695{
d646b16b 696 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
8c7b0c73 697 ccw_machine_4_0_instance_options(machine);
84176c79
CW
698 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
699 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
d646b16b 700 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
9ca056d6
CH
701}
702
703static void ccw_machine_3_1_class_options(MachineClass *mc)
704{
8c7b0c73 705 ccw_machine_4_0_class_options(mc);
abd93cc7 706 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
9ca056d6 707}
8c7b0c73 708DEFINE_CCW_MACHINE(3_1, "3.1", false);
9ca056d6 709
2c5a2eef 710static void ccw_machine_3_0_instance_options(MachineState *machine)
7a9cb3ad 711{
9ca056d6 712 ccw_machine_3_1_instance_options(machine);
7a9cb3ad
CH
713}
714
2c5a2eef 715static void ccw_machine_3_0_class_options(MachineClass *mc)
7a9cb3ad 716{
28221f9c
JF
717 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
718
719 s390mc->hpage_1m_allowed = false;
9ca056d6 720 ccw_machine_3_1_class_options(mc);
ddb3235d 721 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
7a9cb3ad 722}
9ca056d6 723DEFINE_CCW_MACHINE(3_0, "3.0", false);
7a9cb3ad 724
67ee0cef
CH
725static void ccw_machine_2_12_instance_options(MachineState *machine)
726{
2c5a2eef 727 ccw_machine_3_0_instance_options(machine);
87273151
CB
728 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
729 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
67ee0cef
CH
730}
731
732static void ccw_machine_2_12_class_options(MachineClass *mc)
733{
2c5a2eef 734 ccw_machine_3_0_class_options(mc);
0d47310b 735 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
67ee0cef 736}
7a9cb3ad 737DEFINE_CCW_MACHINE(2_12, "2.12", false);
67ee0cef 738
70d8d9a0
CH
739static void ccw_machine_2_11_instance_options(MachineState *machine)
740{
35b4df64 741 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
67ee0cef 742 ccw_machine_2_12_instance_options(machine);
35b4df64
DH
743
744 /* before 2.12 we emulated the very first z900 */
745 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
70d8d9a0
CH
746}
747
748static void ccw_machine_2_11_class_options(MachineClass *mc)
749{
88cbe073 750 static GlobalProperty compat[] = {
6c36bddf 751 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
88cbe073
MAL
752 };
753
67ee0cef 754 ccw_machine_2_12_class_options(mc);
43df70a9 755 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
88cbe073 756 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
70d8d9a0 757}
67ee0cef 758DEFINE_CCW_MACHINE(2_11, "2.11", false);
70d8d9a0 759
10890873
CH
760static void ccw_machine_2_10_instance_options(MachineState *machine)
761{
70d8d9a0 762 ccw_machine_2_11_instance_options(machine);
10890873
CH
763}
764
765static void ccw_machine_2_10_class_options(MachineClass *mc)
766{
70d8d9a0 767 ccw_machine_2_11_class_options(mc);
503224f4 768 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
10890873 769}
70d8d9a0 770DEFINE_CCW_MACHINE(2_10, "2.10", false);
10890873 771
113725a6
CH
772static void ccw_machine_2_9_instance_options(MachineState *machine)
773{
10890873 774 ccw_machine_2_10_instance_options(machine);
7223bcce
JH
775 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
776 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
3b00f702
YMZ
777 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
778 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
779 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
113725a6
CH
780}
781
782static void ccw_machine_2_9_class_options(MachineClass *mc)
783{
52629b3b 784 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
88cbe073 785 static GlobalProperty compat[] = {
6c36bddf 786 { TYPE_S390_STATTRIB, "migration-enabled", "off", },
88cbe073 787 };
52629b3b 788
10890873 789 ccw_machine_2_10_class_options(mc);
3e803152 790 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
88cbe073 791 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
52629b3b 792 s390mc->css_migration_enabled = false;
113725a6 793}
10890873 794DEFINE_CCW_MACHINE(2_9, "2.9", false);
113725a6 795
61823988
CH
796static void ccw_machine_2_8_instance_options(MachineState *machine)
797{
113725a6 798 ccw_machine_2_9_instance_options(machine);
61823988
CH
799}
800
801static void ccw_machine_2_8_class_options(MachineClass *mc)
802{
88cbe073 803 static GlobalProperty compat[] = {
6c36bddf 804 { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
88cbe073
MAL
805 };
806
113725a6 807 ccw_machine_2_9_class_options(mc);
edc24ccd 808 compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
88cbe073 809 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
61823988 810}
113725a6 811DEFINE_CCW_MACHINE(2_8, "2.8", false);
61823988 812
946e55f3
CH
813static void ccw_machine_2_7_instance_options(MachineState *machine)
814{
61823988 815 ccw_machine_2_8_instance_options(machine);
946e55f3
CH
816}
817
818static void ccw_machine_2_7_class_options(MachineClass *mc)
819{
e73316d5
CB
820 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
821
822 s390mc->cpu_model_allowed = false;
61823988 823 ccw_machine_2_8_class_options(mc);
5a995064 824 compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
946e55f3 825}
61823988 826DEFINE_CCW_MACHINE(2_7, "2.7", false);
946e55f3 827
4fca6548 828static void ccw_machine_2_6_instance_options(MachineState *machine)
c4d3c0a2 829{
946e55f3 830 ccw_machine_2_7_instance_options(machine);
c4d3c0a2
CB
831}
832
4fca6548 833static void ccw_machine_2_6_class_options(MachineClass *mc)
84b48ad6 834{
9700230b 835 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
88cbe073 836 static GlobalProperty compat[] = {
6c36bddf
EH
837 { TYPE_S390_IPL, "iplbext_migration", "off", },
838 { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
88cbe073 839 };
9700230b
FZ
840
841 s390mc->ri_allowed = false;
946e55f3 842 ccw_machine_2_7_class_options(mc);
ff8f261f 843 compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
88cbe073 844 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
84b48ad6 845}
946e55f3 846DEFINE_CCW_MACHINE(2_6, "2.6", false);
84b48ad6 847
4fca6548
JF
848static void ccw_machine_2_5_instance_options(MachineState *machine)
849{
946e55f3 850 ccw_machine_2_6_instance_options(machine);
4fca6548 851}
84b48ad6 852
4fca6548 853static void ccw_machine_2_5_class_options(MachineClass *mc)
b21b7598 854{
946e55f3 855 ccw_machine_2_6_class_options(mc);
fe759610 856 compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
4fca6548
JF
857}
858DEFINE_CCW_MACHINE(2_5, "2.5", false);
b21b7598 859
4fca6548
JF
860static void ccw_machine_2_4_instance_options(MachineState *machine)
861{
862 ccw_machine_2_5_instance_options(machine);
b21b7598
CH
863}
864
4fca6548
JF
865static void ccw_machine_2_4_class_options(MachineClass *mc)
866{
88cbe073 867 static GlobalProperty compat[] = {
6c36bddf
EH
868 { TYPE_S390_SKEYS, "migration-enabled", "off", },
869 { "virtio-blk-ccw", "max_revision", "0", },
870 { "virtio-balloon-ccw", "max_revision", "0", },
871 { "virtio-serial-ccw", "max_revision", "0", },
872 { "virtio-9p-ccw", "max_revision", "0", },
873 { "virtio-rng-ccw", "max_revision", "0", },
874 { "virtio-net-ccw", "max_revision", "0", },
875 { "virtio-scsi-ccw", "max_revision", "0", },
876 { "vhost-scsi-ccw", "max_revision", "0", },
88cbe073
MAL
877 };
878
946e55f3 879 ccw_machine_2_5_class_options(mc);
2f99b9c2 880 compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
88cbe073 881 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
4fca6548
JF
882}
883DEFINE_CCW_MACHINE(2_4, "2.4", false);
b21b7598 884
d07aa7c7 885static void ccw_machine_register_types(void)
a5c95808 886{
d07aa7c7 887 type_register_static(&ccw_machine_info);
a5c95808
CH
888}
889
d07aa7c7 890type_init(ccw_machine_register_types)