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