xref: /openbmc/qemu/hw/s390x/s390-virtio-ccw.c (revision 922a01a013d2270682a188258cbccacfecf8129c)
1 /*
2  * virtio ccw machine
3  *
4  * Copyright 2012 IBM Corp.
5  * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
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 
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "cpu.h"
16 #include "hw/boards.h"
17 #include "exec/address-spaces.h"
18 #include "hw/s390x/s390-virtio-hcall.h"
19 #include "hw/s390x/sclp.h"
20 #include "hw/s390x/s390_flic.h"
21 #include "hw/s390x/ioinst.h"
22 #include "hw/s390x/css.h"
23 #include "virtio-ccw.h"
24 #include "qemu/config-file.h"
25 #include "qemu/error-report.h"
26 #include "qemu/option.h"
27 #include "s390-pci-bus.h"
28 #include "hw/s390x/storage-keys.h"
29 #include "hw/s390x/storage-attributes.h"
30 #include "hw/compat.h"
31 #include "ipl.h"
32 #include "hw/s390x/s390-virtio-ccw.h"
33 #include "hw/s390x/css-bridge.h"
34 #include "migration/register.h"
35 #include "cpu_models.h"
36 #include "hw/nmi.h"
37 
38 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
39 {
40     static MachineState *ms;
41 
42     if (!ms) {
43         ms = MACHINE(qdev_get_machine());
44         g_assert(ms->possible_cpus);
45     }
46 
47     /* CPU address corresponds to the core_id and the index */
48     if (cpu_addr >= ms->possible_cpus->len) {
49         return NULL;
50     }
51     return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
52 }
53 
54 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
55                               Error **errp)
56 {
57     S390CPU *cpu = S390_CPU(object_new(typename));
58     Error *err = NULL;
59 
60     object_property_set_int(OBJECT(cpu), core_id, "core-id", &err);
61     if (err != NULL) {
62         goto out;
63     }
64     object_property_set_bool(OBJECT(cpu), true, "realized", &err);
65 
66 out:
67     object_unref(OBJECT(cpu));
68     if (err) {
69         error_propagate(errp, err);
70         cpu = NULL;
71     }
72     return cpu;
73 }
74 
75 static void s390_init_cpus(MachineState *machine)
76 {
77     MachineClass *mc = MACHINE_GET_CLASS(machine);
78     int i;
79 
80     if (tcg_enabled() && max_cpus > 1) {
81         error_report("WARNING: SMP support on s390x is experimental!");
82     }
83 
84     /* initialize possible_cpus */
85     mc->possible_cpu_arch_ids(machine);
86 
87     for (i = 0; i < smp_cpus; i++) {
88         s390x_new_cpu(machine->cpu_type, i, &error_fatal);
89     }
90 }
91 
92 static const char *const reset_dev_types[] = {
93     TYPE_VIRTUAL_CSS_BRIDGE,
94     "s390-sclp-event-facility",
95     "s390-flic",
96     "diag288",
97 };
98 
99 void subsystem_reset(void)
100 {
101     DeviceState *dev;
102     int i;
103 
104     for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
105         dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
106         if (dev) {
107             qdev_reset_all(dev);
108         }
109     }
110 }
111 
112 static int virtio_ccw_hcall_notify(const uint64_t *args)
113 {
114     uint64_t subch_id = args[0];
115     uint64_t queue = args[1];
116     SubchDev *sch;
117     int cssid, ssid, schid, m;
118 
119     if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
120         return -EINVAL;
121     }
122     sch = css_find_subch(m, cssid, ssid, schid);
123     if (!sch || !css_subch_visible(sch)) {
124         return -EINVAL;
125     }
126     if (queue >= VIRTIO_QUEUE_MAX) {
127         return -EINVAL;
128     }
129     virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
130     return 0;
131 
132 }
133 
134 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
135 {
136     uint64_t mem = args[0];
137 
138     if (mem < ram_size) {
139         /* Early printk */
140         return 0;
141     }
142     return -EINVAL;
143 }
144 
145 static void virtio_ccw_register_hcalls(void)
146 {
147     s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
148                                    virtio_ccw_hcall_notify);
149     /* Tolerate early printk. */
150     s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
151                                    virtio_ccw_hcall_early_printk);
152 }
153 
154 /*
155  * KVM does only support memory slots up to KVM_MEM_MAX_NR_PAGES pages
156  * as the dirty bitmap must be managed by bitops that take an int as
157  * position indicator. If we have a guest beyond that we will split off
158  * new subregions. The split must happen on a segment boundary (1MB).
159  */
160 #define KVM_MEM_MAX_NR_PAGES ((1ULL << 31) - 1)
161 #define SEG_MSK (~0xfffffULL)
162 #define KVM_SLOT_MAX_BYTES ((KVM_MEM_MAX_NR_PAGES * TARGET_PAGE_SIZE) & SEG_MSK)
163 static void s390_memory_init(ram_addr_t mem_size)
164 {
165     MemoryRegion *sysmem = get_system_memory();
166     ram_addr_t chunk, offset = 0;
167     unsigned int number = 0;
168     gchar *name;
169 
170     /* allocate RAM for core */
171     name = g_strdup_printf("s390.ram");
172     while (mem_size) {
173         MemoryRegion *ram = g_new(MemoryRegion, 1);
174         uint64_t size = mem_size;
175 
176         /* KVM does not allow memslots >= 8 TB */
177         chunk = MIN(size, KVM_SLOT_MAX_BYTES);
178         memory_region_allocate_system_memory(ram, NULL, name, chunk);
179         memory_region_add_subregion(sysmem, offset, ram);
180         mem_size -= chunk;
181         offset += chunk;
182         g_free(name);
183         name = g_strdup_printf("s390.ram.%u", ++number);
184     }
185     g_free(name);
186 
187     /* Initialize storage key device */
188     s390_skeys_init();
189     /* Initialize storage attributes device */
190     s390_stattrib_init();
191 }
192 
193 #define S390_TOD_CLOCK_VALUE_MISSING    0x00
194 #define S390_TOD_CLOCK_VALUE_PRESENT    0x01
195 
196 static void gtod_save(QEMUFile *f, void *opaque)
197 {
198     uint64_t tod_low;
199     uint8_t tod_high;
200     int r;
201 
202     r = s390_get_clock(&tod_high, &tod_low);
203     if (r) {
204         warn_report("Unable to get guest clock for migration: %s",
205                     strerror(-r));
206         error_printf("Guest clock will not be migrated "
207                      "which could cause the guest to hang.");
208         qemu_put_byte(f, S390_TOD_CLOCK_VALUE_MISSING);
209         return;
210     }
211 
212     qemu_put_byte(f, S390_TOD_CLOCK_VALUE_PRESENT);
213     qemu_put_byte(f, tod_high);
214     qemu_put_be64(f, tod_low);
215 }
216 
217 static int gtod_load(QEMUFile *f, void *opaque, int version_id)
218 {
219     uint64_t tod_low;
220     uint8_t tod_high;
221     int r;
222 
223     if (qemu_get_byte(f) == S390_TOD_CLOCK_VALUE_MISSING) {
224         warn_report("Guest clock was not migrated. This could "
225                     "cause the guest to hang.");
226         return 0;
227     }
228 
229     tod_high = qemu_get_byte(f);
230     tod_low = qemu_get_be64(f);
231 
232     r = s390_set_clock(&tod_high, &tod_low);
233     if (r) {
234         error_report("Unable to set KVM guest TOD clock: %s", strerror(-r));
235     }
236 
237     return r;
238 }
239 
240 static SaveVMHandlers savevm_gtod = {
241     .save_state = gtod_save,
242     .load_state = gtod_load,
243 };
244 
245 static void s390_init_ipl_dev(const char *kernel_filename,
246                               const char *kernel_cmdline,
247                               const char *initrd_filename, const char *firmware,
248                               const char *netboot_fw, bool enforce_bios)
249 {
250     Object *new = object_new(TYPE_S390_IPL);
251     DeviceState *dev = DEVICE(new);
252 
253     if (kernel_filename) {
254         qdev_prop_set_string(dev, "kernel", kernel_filename);
255     }
256     if (initrd_filename) {
257         qdev_prop_set_string(dev, "initrd", initrd_filename);
258     }
259     qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
260     qdev_prop_set_string(dev, "firmware", firmware);
261     qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
262     qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
263     object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
264                               new, NULL);
265     object_unref(new);
266     qdev_init_nofail(dev);
267 }
268 
269 static void s390_create_virtio_net(BusState *bus, const char *name)
270 {
271     int i;
272 
273     for (i = 0; i < nb_nics; i++) {
274         NICInfo *nd = &nd_table[i];
275         DeviceState *dev;
276 
277         if (!nd->model) {
278             nd->model = g_strdup("virtio");
279         }
280 
281         qemu_check_nic_model(nd, "virtio");
282 
283         dev = qdev_create(bus, name);
284         qdev_set_nic_properties(dev, nd);
285         qdev_init_nofail(dev);
286     }
287 }
288 
289 static void ccw_init(MachineState *machine)
290 {
291     int ret;
292     VirtualCssBus *css_bus;
293     DeviceState *dev;
294 
295     s390_sclp_init();
296     s390_memory_init(machine->ram_size);
297 
298     /* init CPUs (incl. CPU model) early so s390_has_feature() works */
299     s390_init_cpus(machine);
300 
301     s390_flic_init();
302 
303     /* init the SIGP facility */
304     s390_init_sigp();
305 
306     /* get a BUS */
307     css_bus = virtual_css_bus_init();
308     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
309                       machine->initrd_filename, "s390-ccw.img",
310                       "s390-netboot.img", true);
311 
312     /*
313      * We cannot easily make the pci host bridge conditional as older QEMUs
314      * always created it. Doing so would break migration across QEMU versions.
315      */
316     dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
317     object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
318                               OBJECT(dev), NULL);
319     qdev_init_nofail(dev);
320 
321     /* register hypercalls */
322     virtio_ccw_register_hcalls();
323 
324     s390_enable_css_support(s390_cpu_addr2state(0));
325     /*
326      * Non mcss-e enabled guests only see the devices from the default
327      * css, which is determined by the value of the squash_mcss property.
328      */
329     if (css_bus->squash_mcss) {
330         ret = css_create_css_image(0, true);
331     } else {
332         ret = css_create_css_image(VIRTUAL_CSSID, true);
333     }
334     if (qemu_opt_get(qemu_get_machine_opts(), "s390-squash-mcss")) {
335         warn_report("The machine property 's390-squash-mcss' is deprecated"
336                     " (obsoleted by lifting the cssid restrictions).");
337     }
338 
339     assert(ret == 0);
340     if (css_migration_enabled()) {
341         css_register_vmstate();
342     }
343 
344     /* Create VirtIO network adapters */
345     s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
346 
347     /* Register savevm handler for guest TOD clock */
348     register_savevm_live(NULL, "todclock", 0, 1, &savevm_gtod, NULL);
349 }
350 
351 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
352                         DeviceState *dev, Error **errp)
353 {
354     MachineState *ms = MACHINE(hotplug_dev);
355     S390CPU *cpu = S390_CPU(dev);
356 
357     g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
358     ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
359 
360     if (dev->hotplugged) {
361         raise_irq_cpu_hotplug();
362     }
363 }
364 
365 static void s390_machine_reset(void)
366 {
367     S390CPU *ipl_cpu = S390_CPU(qemu_get_cpu(0));
368 
369     s390_cmma_reset();
370     qemu_devices_reset();
371     s390_crypto_reset();
372 
373     /* all cpus are stopped - configure and start the ipl cpu only */
374     s390_ipl_prepare_cpu(ipl_cpu);
375     s390_cpu_set_state(CPU_STATE_OPERATING, ipl_cpu);
376 }
377 
378 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
379                                      DeviceState *dev, Error **errp)
380 {
381     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
382         s390_cpu_plug(hotplug_dev, dev, errp);
383     }
384 }
385 
386 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
387                                                DeviceState *dev, Error **errp)
388 {
389     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
390         error_setg(errp, "CPU hot unplug not supported on this machine");
391         return;
392     }
393 }
394 
395 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *machine,
396                                                      unsigned cpu_index)
397 {
398     g_assert(machine->possible_cpus && cpu_index < machine->possible_cpus->len);
399 
400     return machine->possible_cpus->cpus[cpu_index].props;
401 }
402 
403 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
404 {
405     int i;
406 
407     if (ms->possible_cpus) {
408         g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
409         return ms->possible_cpus;
410     }
411 
412     ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
413                                   sizeof(CPUArchId) * max_cpus);
414     ms->possible_cpus->len = max_cpus;
415     for (i = 0; i < ms->possible_cpus->len; i++) {
416         ms->possible_cpus->cpus[i].type = ms->cpu_type;
417         ms->possible_cpus->cpus[i].vcpus_count = 1;
418         ms->possible_cpus->cpus[i].arch_id = i;
419         ms->possible_cpus->cpus[i].props.has_core_id = true;
420         ms->possible_cpus->cpus[i].props.core_id = i;
421     }
422 
423     return ms->possible_cpus;
424 }
425 
426 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
427                                                 DeviceState *dev)
428 {
429     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
430         return HOTPLUG_HANDLER(machine);
431     }
432     return NULL;
433 }
434 
435 static void s390_hot_add_cpu(const int64_t id, Error **errp)
436 {
437     MachineState *machine = MACHINE(qdev_get_machine());
438     ObjectClass *oc;
439 
440     g_assert(machine->possible_cpus->cpus[0].cpu);
441     oc = OBJECT_CLASS(CPU_GET_CLASS(machine->possible_cpus->cpus[0].cpu));
442 
443     s390x_new_cpu(object_class_get_name(oc), id, errp);
444 }
445 
446 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
447 {
448     CPUState *cs = qemu_get_cpu(cpu_index);
449 
450     s390_cpu_restart(S390_CPU(cs));
451 }
452 
453 static void ccw_machine_class_init(ObjectClass *oc, void *data)
454 {
455     MachineClass *mc = MACHINE_CLASS(oc);
456     NMIClass *nc = NMI_CLASS(oc);
457     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
458     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
459 
460     s390mc->ri_allowed = true;
461     s390mc->cpu_model_allowed = true;
462     s390mc->css_migration_enabled = true;
463     mc->init = ccw_init;
464     mc->reset = s390_machine_reset;
465     mc->hot_add_cpu = s390_hot_add_cpu;
466     mc->block_default_type = IF_VIRTIO;
467     mc->no_cdrom = 1;
468     mc->no_floppy = 1;
469     mc->no_serial = 1;
470     mc->no_parallel = 1;
471     mc->no_sdcard = 1;
472     mc->use_sclp = 1;
473     mc->max_cpus = S390_MAX_CPUS;
474     mc->has_hotpluggable_cpus = true;
475     mc->get_hotplug_handler = s390_get_hotplug_handler;
476     mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
477     mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
478     /* it is overridden with 'host' cpu *in kvm_arch_init* */
479     mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
480     hc->plug = s390_machine_device_plug;
481     hc->unplug_request = s390_machine_device_unplug_request;
482     nc->nmi_monitor_handler = s390_nmi;
483 }
484 
485 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
486 {
487     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
488 
489     return ms->aes_key_wrap;
490 }
491 
492 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
493                                             Error **errp)
494 {
495     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
496 
497     ms->aes_key_wrap = value;
498 }
499 
500 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
501 {
502     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
503 
504     return ms->dea_key_wrap;
505 }
506 
507 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
508                                             Error **errp)
509 {
510     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
511 
512     ms->dea_key_wrap = value;
513 }
514 
515 static S390CcwMachineClass *current_mc;
516 
517 static S390CcwMachineClass *get_machine_class(void)
518 {
519     if (unlikely(!current_mc)) {
520         /*
521         * No s390 ccw machine was instantiated, we are likely to
522         * be called for the 'none' machine. The properties will
523         * have their after-initialization values.
524         */
525         current_mc = S390_MACHINE_CLASS(
526                      object_class_by_name(TYPE_S390_CCW_MACHINE));
527     }
528     return current_mc;
529 }
530 
531 bool ri_allowed(void)
532 {
533     /* for "none" machine this results in true */
534     return get_machine_class()->ri_allowed;
535 }
536 
537 bool cpu_model_allowed(void)
538 {
539     /* for "none" machine this results in true */
540     return get_machine_class()->cpu_model_allowed;
541 }
542 
543 static char *machine_get_loadparm(Object *obj, Error **errp)
544 {
545     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
546 
547     return g_memdup(ms->loadparm, sizeof(ms->loadparm));
548 }
549 
550 static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
551 {
552     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
553     int i;
554 
555     for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
556         uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
557 
558         if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
559             (c == ' ')) {
560             ms->loadparm[i] = c;
561         } else {
562             error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
563                        c, c);
564             return;
565         }
566     }
567 
568     for (; i < sizeof(ms->loadparm); i++) {
569         ms->loadparm[i] = ' '; /* pad right with spaces */
570     }
571 }
572 static inline bool machine_get_squash_mcss(Object *obj, Error **errp)
573 {
574     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
575 
576     return ms->s390_squash_mcss;
577 }
578 
579 static inline void machine_set_squash_mcss(Object *obj, bool value,
580                                            Error **errp)
581 {
582     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
583 
584     ms->s390_squash_mcss = value;
585 }
586 
587 static inline void s390_machine_initfn(Object *obj)
588 {
589     object_property_add_bool(obj, "aes-key-wrap",
590                              machine_get_aes_key_wrap,
591                              machine_set_aes_key_wrap, NULL);
592     object_property_set_description(obj, "aes-key-wrap",
593             "enable/disable AES key wrapping using the CPACF wrapping key",
594             NULL);
595     object_property_set_bool(obj, true, "aes-key-wrap", NULL);
596 
597     object_property_add_bool(obj, "dea-key-wrap",
598                              machine_get_dea_key_wrap,
599                              machine_set_dea_key_wrap, NULL);
600     object_property_set_description(obj, "dea-key-wrap",
601             "enable/disable DEA key wrapping using the CPACF wrapping key",
602             NULL);
603     object_property_set_bool(obj, true, "dea-key-wrap", NULL);
604     object_property_add_str(obj, "loadparm",
605             machine_get_loadparm, machine_set_loadparm, NULL);
606     object_property_set_description(obj, "loadparm",
607             "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
608             " to upper case) to pass to machine loader, boot manager,"
609             " and guest kernel",
610             NULL);
611     object_property_add_bool(obj, "s390-squash-mcss",
612                              machine_get_squash_mcss,
613                              machine_set_squash_mcss, NULL);
614     object_property_set_description(obj, "s390-squash-mcss", "(deprecated) "
615             "enable/disable squashing subchannels into the default css",
616             NULL);
617     object_property_set_bool(obj, false, "s390-squash-mcss", NULL);
618 }
619 
620 static const TypeInfo ccw_machine_info = {
621     .name          = TYPE_S390_CCW_MACHINE,
622     .parent        = TYPE_MACHINE,
623     .abstract      = true,
624     .instance_size = sizeof(S390CcwMachineState),
625     .instance_init = s390_machine_initfn,
626     .class_size = sizeof(S390CcwMachineClass),
627     .class_init    = ccw_machine_class_init,
628     .interfaces = (InterfaceInfo[]) {
629         { TYPE_NMI },
630         { TYPE_HOTPLUG_HANDLER},
631         { }
632     },
633 };
634 
635 bool css_migration_enabled(void)
636 {
637     return get_machine_class()->css_migration_enabled;
638 }
639 
640 #define DEFINE_CCW_MACHINE(suffix, verstr, latest)                            \
641     static void ccw_machine_##suffix##_class_init(ObjectClass *oc,            \
642                                                   void *data)                 \
643     {                                                                         \
644         MachineClass *mc = MACHINE_CLASS(oc);                                 \
645         ccw_machine_##suffix##_class_options(mc);                             \
646         mc->desc = "VirtIO-ccw based S390 machine v" verstr;                  \
647         if (latest) {                                                         \
648             mc->alias = "s390-ccw-virtio";                                    \
649             mc->is_default = 1;                                               \
650         }                                                                     \
651     }                                                                         \
652     static void ccw_machine_##suffix##_instance_init(Object *obj)             \
653     {                                                                         \
654         MachineState *machine = MACHINE(obj);                                 \
655         current_mc = S390_MACHINE_CLASS(MACHINE_GET_CLASS(machine));          \
656         ccw_machine_##suffix##_instance_options(machine);                     \
657     }                                                                         \
658     static const TypeInfo ccw_machine_##suffix##_info = {                     \
659         .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr),                 \
660         .parent = TYPE_S390_CCW_MACHINE,                                      \
661         .class_init = ccw_machine_##suffix##_class_init,                      \
662         .instance_init = ccw_machine_##suffix##_instance_init,                \
663     };                                                                        \
664     static void ccw_machine_register_##suffix(void)                           \
665     {                                                                         \
666         type_register_static(&ccw_machine_##suffix##_info);                   \
667     }                                                                         \
668     type_init(ccw_machine_register_##suffix)
669 
670 #define CCW_COMPAT_2_11 \
671         HW_COMPAT_2_11
672 
673 #define CCW_COMPAT_2_10 \
674         HW_COMPAT_2_10
675 
676 #define CCW_COMPAT_2_9 \
677         HW_COMPAT_2_9 \
678         {\
679             .driver   = TYPE_S390_STATTRIB,\
680             .property = "migration-enabled",\
681             .value    = "off",\
682         },
683 
684 #define CCW_COMPAT_2_8 \
685         HW_COMPAT_2_8 \
686         {\
687             .driver   = TYPE_S390_FLIC_COMMON,\
688             .property = "adapter_routes_max_batch",\
689             .value    = "64",\
690         },
691 
692 #define CCW_COMPAT_2_7 \
693         HW_COMPAT_2_7
694 
695 #define CCW_COMPAT_2_6 \
696         HW_COMPAT_2_6 \
697         {\
698             .driver   = TYPE_S390_IPL,\
699             .property = "iplbext_migration",\
700             .value    = "off",\
701         }, {\
702             .driver   = TYPE_VIRTUAL_CSS_BRIDGE,\
703             .property = "css_dev_path",\
704             .value    = "off",\
705         },
706 
707 #define CCW_COMPAT_2_5 \
708         HW_COMPAT_2_5
709 
710 #define CCW_COMPAT_2_4 \
711         HW_COMPAT_2_4 \
712         {\
713             .driver   = TYPE_S390_SKEYS,\
714             .property = "migration-enabled",\
715             .value    = "off",\
716         },{\
717             .driver   = "virtio-blk-ccw",\
718             .property = "max_revision",\
719             .value    = "0",\
720         },{\
721             .driver   = "virtio-balloon-ccw",\
722             .property = "max_revision",\
723             .value    = "0",\
724         },{\
725             .driver   = "virtio-serial-ccw",\
726             .property = "max_revision",\
727             .value    = "0",\
728         },{\
729             .driver   = "virtio-9p-ccw",\
730             .property = "max_revision",\
731             .value    = "0",\
732         },{\
733             .driver   = "virtio-rng-ccw",\
734             .property = "max_revision",\
735             .value    = "0",\
736         },{\
737             .driver   = "virtio-net-ccw",\
738             .property = "max_revision",\
739             .value    = "0",\
740         },{\
741             .driver   = "virtio-scsi-ccw",\
742             .property = "max_revision",\
743             .value    = "0",\
744         },{\
745             .driver   = "vhost-scsi-ccw",\
746             .property = "max_revision",\
747             .value    = "0",\
748         },
749 
750 static void ccw_machine_2_12_instance_options(MachineState *machine)
751 {
752 }
753 
754 static void ccw_machine_2_12_class_options(MachineClass *mc)
755 {
756 }
757 DEFINE_CCW_MACHINE(2_12, "2.12", true);
758 
759 static void ccw_machine_2_11_instance_options(MachineState *machine)
760 {
761     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
762     ccw_machine_2_12_instance_options(machine);
763 
764     /* before 2.12 we emulated the very first z900 */
765     s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
766 }
767 
768 static void ccw_machine_2_11_class_options(MachineClass *mc)
769 {
770     ccw_machine_2_12_class_options(mc);
771     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_11);
772 }
773 DEFINE_CCW_MACHINE(2_11, "2.11", false);
774 
775 static void ccw_machine_2_10_instance_options(MachineState *machine)
776 {
777     ccw_machine_2_11_instance_options(machine);
778 }
779 
780 static void ccw_machine_2_10_class_options(MachineClass *mc)
781 {
782     ccw_machine_2_11_class_options(mc);
783     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_10);
784 }
785 DEFINE_CCW_MACHINE(2_10, "2.10", false);
786 
787 static void ccw_machine_2_9_instance_options(MachineState *machine)
788 {
789     ccw_machine_2_10_instance_options(machine);
790     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
791     s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
792     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
793     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
794     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
795 }
796 
797 static void ccw_machine_2_9_class_options(MachineClass *mc)
798 {
799     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
800 
801     ccw_machine_2_10_class_options(mc);
802     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_9);
803     s390mc->css_migration_enabled = false;
804 }
805 DEFINE_CCW_MACHINE(2_9, "2.9", false);
806 
807 static void ccw_machine_2_8_instance_options(MachineState *machine)
808 {
809     ccw_machine_2_9_instance_options(machine);
810 }
811 
812 static void ccw_machine_2_8_class_options(MachineClass *mc)
813 {
814     ccw_machine_2_9_class_options(mc);
815     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_8);
816 }
817 DEFINE_CCW_MACHINE(2_8, "2.8", false);
818 
819 static void ccw_machine_2_7_instance_options(MachineState *machine)
820 {
821     ccw_machine_2_8_instance_options(machine);
822 }
823 
824 static void ccw_machine_2_7_class_options(MachineClass *mc)
825 {
826     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
827 
828     s390mc->cpu_model_allowed = false;
829     ccw_machine_2_8_class_options(mc);
830     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_7);
831 }
832 DEFINE_CCW_MACHINE(2_7, "2.7", false);
833 
834 static void ccw_machine_2_6_instance_options(MachineState *machine)
835 {
836     ccw_machine_2_7_instance_options(machine);
837 }
838 
839 static void ccw_machine_2_6_class_options(MachineClass *mc)
840 {
841     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
842 
843     s390mc->ri_allowed = false;
844     ccw_machine_2_7_class_options(mc);
845     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_6);
846 }
847 DEFINE_CCW_MACHINE(2_6, "2.6", false);
848 
849 static void ccw_machine_2_5_instance_options(MachineState *machine)
850 {
851     ccw_machine_2_6_instance_options(machine);
852 }
853 
854 static void ccw_machine_2_5_class_options(MachineClass *mc)
855 {
856     ccw_machine_2_6_class_options(mc);
857     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_5);
858 }
859 DEFINE_CCW_MACHINE(2_5, "2.5", false);
860 
861 static void ccw_machine_2_4_instance_options(MachineState *machine)
862 {
863     ccw_machine_2_5_instance_options(machine);
864 }
865 
866 static void ccw_machine_2_4_class_options(MachineClass *mc)
867 {
868     ccw_machine_2_5_class_options(mc);
869     SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_4);
870 }
871 DEFINE_CCW_MACHINE(2_4, "2.4", false);
872 
873 static void ccw_machine_register_types(void)
874 {
875     type_register_static(&ccw_machine_info);
876 }
877 
878 type_init(ccw_machine_register_types)
879