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