xref: /openbmc/qemu/hw/s390x/s390-virtio-ccw.c (revision 76bccf3c)
1 /*
2  * virtio ccw machine
3  *
4  * Copyright 2012, 2020 IBM Corp.
5  * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
6  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7  *            Janosch Frank <frankja@linux.ibm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or (at
10  * your option) any later version. See the COPYING file in the top-level
11  * directory.
12  */
13 
14 #include "qemu/osdep.h"
15 #include "qapi/error.h"
16 #include "exec/ram_addr.h"
17 #include "exec/confidential-guest-support.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/ctype.h"
26 #include "qemu/error-report.h"
27 #include "qemu/option.h"
28 #include "qemu/qemu-print.h"
29 #include "qemu/units.h"
30 #include "hw/s390x/s390-pci-bus.h"
31 #include "sysemu/reset.h"
32 #include "hw/s390x/storage-keys.h"
33 #include "hw/s390x/storage-attributes.h"
34 #include "hw/s390x/event-facility.h"
35 #include "ipl.h"
36 #include "hw/s390x/s390-virtio-ccw.h"
37 #include "hw/s390x/css-bridge.h"
38 #include "hw/s390x/ap-bridge.h"
39 #include "migration/register.h"
40 #include "cpu_models.h"
41 #include "hw/nmi.h"
42 #include "hw/qdev-properties.h"
43 #include "hw/s390x/tod.h"
44 #include "sysemu/sysemu.h"
45 #include "sysemu/cpus.h"
46 #include "target/s390x/kvm/pv.h"
47 #include "migration/blocker.h"
48 #include "qapi/visitor.h"
49 #include "hw/s390x/cpu-topology.h"
50 #include CONFIG_DEVICES
51 
52 static Error *pv_mig_blocker;
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     S390CPU *ret = NULL;
59 
60     if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) {
61         goto out;
62     }
63     if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
64         goto out;
65     }
66     ret = cpu;
67 
68 out:
69     object_unref(OBJECT(cpu));
70     return ret;
71 }
72 
73 static void s390_init_cpus(MachineState *machine)
74 {
75     MachineClass *mc = MACHINE_GET_CLASS(machine);
76     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
77     int i;
78 
79     if (machine->smp.threads > s390mc->max_threads) {
80         error_report("S390 does not support more than %d threads.",
81                      s390mc->max_threads);
82         exit(1);
83     }
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     TYPE_S390_PCI_HOST_BRIDGE,
99     TYPE_AP_BRIDGE,
100 };
101 
102 static void subsystem_reset(void)
103 {
104     DeviceState *dev;
105     int i;
106 
107     /*
108      * ISM firmware is sensitive to unexpected changes to the IOMMU, which can
109      * occur during reset of the vfio-pci device (unmap of entire aperture).
110      * Ensure any passthrough ISM devices are reset now, while CPUs are paused
111      * but before vfio-pci cleanup occurs.
112      */
113     s390_pci_ism_reset();
114 
115     for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
116         dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
117         if (dev) {
118             device_cold_reset(dev);
119         }
120     }
121     if (s390_has_topology()) {
122         s390_topology_reset();
123     }
124 }
125 
126 static int virtio_ccw_hcall_notify(const uint64_t *args)
127 {
128     uint64_t subch_id = args[0];
129     uint64_t queue = args[1];
130     SubchDev *sch;
131     int cssid, ssid, schid, m;
132 
133     if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
134         return -EINVAL;
135     }
136     sch = css_find_subch(m, cssid, ssid, schid);
137     if (!sch || !css_subch_visible(sch)) {
138         return -EINVAL;
139     }
140     if (queue >= VIRTIO_QUEUE_MAX) {
141         return -EINVAL;
142     }
143     virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
144     return 0;
145 
146 }
147 
148 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
149 {
150     uint64_t mem = args[0];
151     MachineState *ms = MACHINE(qdev_get_machine());
152 
153     if (mem < ms->ram_size) {
154         /* Early printk */
155         return 0;
156     }
157     return -EINVAL;
158 }
159 
160 static void virtio_ccw_register_hcalls(void)
161 {
162     s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
163                                    virtio_ccw_hcall_notify);
164     /* Tolerate early printk. */
165     s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
166                                    virtio_ccw_hcall_early_printk);
167 }
168 
169 static void s390_memory_init(MemoryRegion *ram)
170 {
171     MemoryRegion *sysmem = get_system_memory();
172 
173     /* allocate RAM for core */
174     memory_region_add_subregion(sysmem, 0, ram);
175 
176     /*
177      * Configure the maximum page size. As no memory devices were created
178      * yet, this is the page size of initial memory only.
179      */
180     s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal);
181     /* Initialize storage key device */
182     s390_skeys_init();
183     /* Initialize storage attributes device */
184     s390_stattrib_init();
185 }
186 
187 static void s390_init_ipl_dev(const char *kernel_filename,
188                               const char *kernel_cmdline,
189                               const char *initrd_filename, const char *firmware,
190                               const char *netboot_fw, bool enforce_bios)
191 {
192     Object *new = object_new(TYPE_S390_IPL);
193     DeviceState *dev = DEVICE(new);
194     char *netboot_fw_prop;
195 
196     if (kernel_filename) {
197         qdev_prop_set_string(dev, "kernel", kernel_filename);
198     }
199     if (initrd_filename) {
200         qdev_prop_set_string(dev, "initrd", initrd_filename);
201     }
202     qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
203     qdev_prop_set_string(dev, "firmware", firmware);
204     qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
205     netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
206     if (!strlen(netboot_fw_prop)) {
207         qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
208     }
209     g_free(netboot_fw_prop);
210     object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
211                               new);
212     object_unref(new);
213     qdev_realize(dev, NULL, &error_fatal);
214 }
215 
216 static void s390_create_virtio_net(BusState *bus, const char *name)
217 {
218     DeviceState *dev;
219 
220     while ((dev = qemu_create_nic_device(name, true, "virtio"))) {
221         qdev_realize_and_unref(dev, bus, &error_fatal);
222     }
223 }
224 
225 static void s390_create_sclpconsole(SCLPDevice *sclp,
226                                     const char *type, Chardev *chardev)
227 {
228     SCLPEventFacility *ef = sclp->event_facility;
229     BusState *ev_fac_bus = sclp_get_event_facility_bus(ef);
230     DeviceState *dev;
231 
232     dev = qdev_new(type);
233     object_property_add_child(OBJECT(ef), type, OBJECT(dev));
234     qdev_prop_set_chr(dev, "chardev", chardev);
235     qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
236 }
237 
238 static void ccw_init(MachineState *machine)
239 {
240     MachineClass *mc = MACHINE_GET_CLASS(machine);
241     S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
242     int ret;
243     VirtualCssBus *css_bus;
244     DeviceState *dev;
245 
246     ms->sclp = SCLP(object_new(TYPE_SCLP));
247     object_property_add_child(OBJECT(machine), TYPE_SCLP, OBJECT(ms->sclp));
248     qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal);
249 
250     /* init memory + setup max page size. Required for the CPU model */
251     s390_memory_init(machine->ram);
252 
253     /* init CPUs (incl. CPU model) early so s390_has_feature() works */
254     s390_init_cpus(machine);
255 
256     /* Need CPU model to be determined before we can set up PV */
257     if (machine->cgs) {
258         confidential_guest_kvm_init(machine->cgs, &error_fatal);
259     }
260 
261     s390_flic_init();
262 
263     /* init the SIGP facility */
264     s390_init_sigp();
265 
266     /* create AP bridge and bus(es) */
267     s390_init_ap();
268 
269     /* get a BUS */
270     css_bus = virtual_css_bus_init();
271     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
272                       machine->initrd_filename,
273                       machine->firmware ?: "s390-ccw.img",
274                       "s390-netboot.img", true);
275 
276     dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE);
277     object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
278                               OBJECT(dev));
279     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
280 
281     /* register hypercalls */
282     virtio_ccw_register_hcalls();
283 
284     s390_enable_css_support(s390_cpu_addr2state(0));
285 
286     ret = css_create_css_image(VIRTUAL_CSSID, true);
287     assert(ret == 0);
288 
289     css_register_vmstate();
290 
291     /* Create VirtIO network adapters */
292     s390_create_virtio_net(BUS(css_bus), mc->default_nic);
293 
294     /* init consoles */
295     if (serial_hd(0)) {
296         s390_create_sclpconsole(ms->sclp, "sclpconsole", serial_hd(0));
297     }
298     if (serial_hd(1)) {
299         s390_create_sclpconsole(ms->sclp, "sclplmconsole", serial_hd(1));
300     }
301 
302     /* init the TOD clock */
303     s390_init_tod();
304 }
305 
306 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
307                         DeviceState *dev, Error **errp)
308 {
309     ERRP_GUARD();
310     MachineState *ms = MACHINE(hotplug_dev);
311     S390CPU *cpu = S390_CPU(dev);
312 
313     g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
314     ms->possible_cpus->cpus[cpu->env.core_id].cpu = CPU(dev);
315 
316     if (s390_has_topology()) {
317         s390_topology_setup_cpu(ms, cpu, errp);
318         if (*errp) {
319             return;
320         }
321     }
322 
323     if (dev->hotplugged) {
324         raise_irq_cpu_hotplug();
325     }
326 }
327 
328 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
329 {
330     S390CPU *cpu = S390_CPU(cs);
331 
332     s390_ipl_prepare_cpu(cpu);
333     s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
334 }
335 
336 static void s390_machine_unprotect(S390CcwMachineState *ms)
337 {
338     if (!s390_pv_vm_try_disable_async(ms)) {
339         s390_pv_vm_disable();
340     }
341     ms->pv = false;
342     migrate_del_blocker(&pv_mig_blocker);
343     ram_block_discard_disable(false);
344 }
345 
346 static int s390_machine_protect(S390CcwMachineState *ms)
347 {
348     Error *local_err = NULL;
349     int rc;
350 
351    /*
352     * Discarding of memory in RAM blocks does not work as expected with
353     * protected VMs. Sharing and unsharing pages would be required. Disable
354     * it for now, until until we have a solution to make at least Linux
355     * guests either support it (e.g., virtio-balloon) or fail gracefully.
356     */
357     rc = ram_block_discard_disable(true);
358     if (rc) {
359         error_report("protected VMs: cannot disable RAM discard");
360         return rc;
361     }
362 
363     error_setg(&pv_mig_blocker,
364                "protected VMs are currently not migratable.");
365     rc = migrate_add_blocker(&pv_mig_blocker, &local_err);
366     if (rc) {
367         ram_block_discard_disable(false);
368         error_report_err(local_err);
369         return rc;
370     }
371 
372     /* Create SE VM */
373     rc = s390_pv_vm_enable();
374     if (rc) {
375         ram_block_discard_disable(false);
376         migrate_del_blocker(&pv_mig_blocker);
377         return rc;
378     }
379 
380     ms->pv = true;
381 
382     /* Will return 0 if API is not available since it's not vital */
383     rc = s390_pv_query_info();
384     if (rc) {
385         goto out_err;
386     }
387 
388     /* Set SE header and unpack */
389     rc = s390_ipl_prepare_pv_header(&local_err);
390     if (rc) {
391         goto out_err;
392     }
393 
394     /* Decrypt image */
395     rc = s390_ipl_pv_unpack();
396     if (rc) {
397         goto out_err;
398     }
399 
400     /* Verify integrity */
401     rc = s390_pv_verify();
402     if (rc) {
403         goto out_err;
404     }
405     return rc;
406 
407 out_err:
408     if (local_err) {
409         error_report_err(local_err);
410     }
411     s390_machine_unprotect(ms);
412     return rc;
413 }
414 
415 static void s390_pv_prepare_reset(S390CcwMachineState *ms)
416 {
417     CPUState *cs;
418 
419     if (!s390_is_pv()) {
420         return;
421     }
422     /* Unsharing requires all cpus to be stopped */
423     CPU_FOREACH(cs) {
424         s390_cpu_set_state(S390_CPU_STATE_STOPPED, S390_CPU(cs));
425     }
426     s390_pv_unshare();
427     s390_pv_prep_reset();
428 }
429 
430 static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
431 {
432     S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
433     enum s390_reset reset_type;
434     CPUState *cs, *t;
435     S390CPU *cpu;
436 
437     /* get the reset parameters, reset them once done */
438     s390_ipl_get_reset_request(&cs, &reset_type);
439 
440     /* all CPUs are paused and synchronized at this point */
441     s390_cmma_reset();
442 
443     cpu = S390_CPU(cs);
444 
445     switch (reset_type) {
446     case S390_RESET_EXTERNAL:
447     case S390_RESET_REIPL:
448         /*
449          * Reset the subsystem which includes a AP reset. If a PV
450          * guest had APQNs attached the AP reset is a prerequisite to
451          * unprotecting since the UV checks if all APQNs are reset.
452          */
453         subsystem_reset();
454         if (s390_is_pv()) {
455             s390_machine_unprotect(ms);
456         }
457 
458         /*
459          * Device reset includes CPU clear resets so this has to be
460          * done AFTER the unprotect call above.
461          */
462         qemu_devices_reset(reason);
463         s390_crypto_reset();
464 
465         /* configure and start the ipl CPU only */
466         run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
467         break;
468     case S390_RESET_MODIFIED_CLEAR:
469         /*
470          * Subsystem reset needs to be done before we unshare memory
471          * and lose access to VIRTIO structures in guest memory.
472          */
473         subsystem_reset();
474         s390_crypto_reset();
475         s390_pv_prepare_reset(ms);
476         CPU_FOREACH(t) {
477             run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
478         }
479         run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
480         break;
481     case S390_RESET_LOAD_NORMAL:
482         /*
483          * Subsystem reset needs to be done before we unshare memory
484          * and lose access to VIRTIO structures in guest memory.
485          */
486         subsystem_reset();
487         s390_pv_prepare_reset(ms);
488         CPU_FOREACH(t) {
489             if (t == cs) {
490                 continue;
491             }
492             run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
493         }
494         run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
495         run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
496         break;
497     case S390_RESET_PV: /* Subcode 10 */
498         subsystem_reset();
499         s390_crypto_reset();
500 
501         CPU_FOREACH(t) {
502             if (t == cs) {
503                 continue;
504             }
505             run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
506         }
507         run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
508 
509         if (s390_machine_protect(ms)) {
510             s390_pv_inject_reset_error(cs);
511             /*
512              * Continue after the diag308 so the guest knows something
513              * went wrong.
514              */
515             s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
516             return;
517         }
518 
519         run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
520         break;
521     default:
522         g_assert_not_reached();
523     }
524 
525     CPU_FOREACH(t) {
526         run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(0));
527     }
528     s390_ipl_clear_reset_request();
529 }
530 
531 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
532                                      DeviceState *dev, Error **errp)
533 {
534     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
535         s390_cpu_plug(hotplug_dev, dev, errp);
536     }
537 }
538 
539 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
540                                                DeviceState *dev, Error **errp)
541 {
542     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
543         error_setg(errp, "CPU hot unplug not supported on this machine");
544         return;
545     }
546 }
547 
548 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
549                                                      unsigned cpu_index)
550 {
551     MachineClass *mc = MACHINE_GET_CLASS(ms);
552     const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
553 
554     assert(cpu_index < possible_cpus->len);
555     return possible_cpus->cpus[cpu_index].props;
556 }
557 
558 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
559 {
560     int i;
561     unsigned int max_cpus = ms->smp.max_cpus;
562 
563     if (ms->possible_cpus) {
564         g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
565         return ms->possible_cpus;
566     }
567 
568     ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
569                                   sizeof(CPUArchId) * max_cpus);
570     ms->possible_cpus->len = max_cpus;
571     for (i = 0; i < ms->possible_cpus->len; i++) {
572         CpuInstanceProperties *props = &ms->possible_cpus->cpus[i].props;
573 
574         ms->possible_cpus->cpus[i].type = ms->cpu_type;
575         ms->possible_cpus->cpus[i].vcpus_count = 1;
576         ms->possible_cpus->cpus[i].arch_id = i;
577 
578         props->has_core_id = true;
579         props->core_id = i;
580         props->has_socket_id = true;
581         props->socket_id = s390_std_socket(i, &ms->smp);
582         props->has_book_id = true;
583         props->book_id = s390_std_book(i, &ms->smp);
584         props->has_drawer_id = true;
585         props->drawer_id = s390_std_drawer(i, &ms->smp);
586     }
587 
588     return ms->possible_cpus;
589 }
590 
591 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
592                                                 DeviceState *dev)
593 {
594     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
595         return HOTPLUG_HANDLER(machine);
596     }
597     return NULL;
598 }
599 
600 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
601 {
602     CPUState *cs = qemu_get_cpu(cpu_index);
603 
604     s390_cpu_restart(S390_CPU(cs));
605 }
606 
607 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
608 {
609     /* same logic as in sclp.c */
610     int increment_size = 20;
611     ram_addr_t newsz;
612 
613     while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
614         increment_size++;
615     }
616     newsz = sz >> increment_size << increment_size;
617 
618     if (sz != newsz) {
619         qemu_printf("Ram size %" PRIu64 "MB was fixed up to %" PRIu64
620                     "MB to match machine restrictions. Consider updating "
621                     "the guest definition.\n", (uint64_t) (sz / MiB),
622                     (uint64_t) (newsz / MiB));
623     }
624     return newsz;
625 }
626 
627 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
628 {
629     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
630 
631     return ms->aes_key_wrap;
632 }
633 
634 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
635                                             Error **errp)
636 {
637     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
638 
639     ms->aes_key_wrap = value;
640 }
641 
642 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
643 {
644     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
645 
646     return ms->dea_key_wrap;
647 }
648 
649 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
650                                             Error **errp)
651 {
652     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
653 
654     ms->dea_key_wrap = value;
655 }
656 
657 static S390CcwMachineClass *current_mc;
658 
659 /*
660  * Get the class of the s390-ccw-virtio machine that is currently in use.
661  * Note: libvirt is using the "none" machine to probe for the features of the
662  * host CPU, so in case this is called with the "none" machine, the function
663  * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
664  * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
665  * below return the correct default value for the "none" machine.
666  *
667  * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
668  * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
669  * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
670  * CPU initialization and s390_has_feat() later should be sufficient.
671  */
672 static S390CcwMachineClass *get_machine_class(void)
673 {
674     if (unlikely(!current_mc)) {
675         /*
676         * No s390 ccw machine was instantiated, we are likely to
677         * be called for the 'none' machine. The properties will
678         * have their after-initialization values.
679         */
680         current_mc = S390_CCW_MACHINE_CLASS(
681                      object_class_by_name(TYPE_S390_CCW_MACHINE));
682     }
683     return current_mc;
684 }
685 
686 bool ri_allowed(void)
687 {
688     return get_machine_class()->ri_allowed;
689 }
690 
691 bool cpu_model_allowed(void)
692 {
693     return get_machine_class()->cpu_model_allowed;
694 }
695 
696 bool hpage_1m_allowed(void)
697 {
698     return get_machine_class()->hpage_1m_allowed;
699 }
700 
701 static void machine_get_loadparm(Object *obj, Visitor *v,
702                                  const char *name, void *opaque,
703                                  Error **errp)
704 {
705     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
706     char *str = g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
707 
708     visit_type_str(v, name, &str, errp);
709     g_free(str);
710 }
711 
712 static void machine_set_loadparm(Object *obj, Visitor *v,
713                                  const char *name, void *opaque,
714                                  Error **errp)
715 {
716     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
717     char *val;
718     int i;
719 
720     if (!visit_type_str(v, name, &val, errp)) {
721         return;
722     }
723 
724     for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
725         uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
726 
727         if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
728             (c == ' ')) {
729             ms->loadparm[i] = c;
730         } else {
731             error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
732                        c, c);
733             return;
734         }
735     }
736 
737     for (; i < sizeof(ms->loadparm); i++) {
738         ms->loadparm[i] = ' '; /* pad right with spaces */
739     }
740 }
741 
742 static void ccw_machine_class_init(ObjectClass *oc, void *data)
743 {
744     MachineClass *mc = MACHINE_CLASS(oc);
745     NMIClass *nc = NMI_CLASS(oc);
746     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
747     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
748 
749     s390mc->ri_allowed = true;
750     s390mc->cpu_model_allowed = true;
751     s390mc->hpage_1m_allowed = true;
752     s390mc->max_threads = 1;
753     mc->init = ccw_init;
754     mc->reset = s390_machine_reset;
755     mc->block_default_type = IF_VIRTIO;
756     mc->no_cdrom = 1;
757     mc->no_floppy = 1;
758     mc->no_parallel = 1;
759     mc->no_sdcard = 1;
760     mc->max_cpus = S390_MAX_CPUS;
761     mc->has_hotpluggable_cpus = true;
762     mc->smp_props.books_supported = true;
763     mc->smp_props.drawers_supported = true;
764     assert(!mc->get_hotplug_handler);
765     mc->get_hotplug_handler = s390_get_hotplug_handler;
766     mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
767     mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
768     /* it is overridden with 'host' cpu *in kvm_arch_init* */
769     mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
770     hc->plug = s390_machine_device_plug;
771     hc->unplug_request = s390_machine_device_unplug_request;
772     nc->nmi_monitor_handler = s390_nmi;
773     mc->default_ram_id = "s390.ram";
774     mc->default_nic = "virtio-net-ccw";
775 
776     object_class_property_add_bool(oc, "aes-key-wrap",
777                                    machine_get_aes_key_wrap,
778                                    machine_set_aes_key_wrap);
779     object_class_property_set_description(oc, "aes-key-wrap",
780             "enable/disable AES key wrapping using the CPACF wrapping key");
781 
782     object_class_property_add_bool(oc, "dea-key-wrap",
783                                    machine_get_dea_key_wrap,
784                                    machine_set_dea_key_wrap);
785     object_class_property_set_description(oc, "dea-key-wrap",
786             "enable/disable DEA key wrapping using the CPACF wrapping key");
787 
788     object_class_property_add(oc, "loadparm", "loadparm",
789                               machine_get_loadparm, machine_set_loadparm,
790                               NULL, NULL);
791     object_class_property_set_description(oc, "loadparm",
792             "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
793             " to upper case) to pass to machine loader, boot manager,"
794             " and guest kernel");
795 }
796 
797 static inline void s390_machine_initfn(Object *obj)
798 {
799     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
800 
801     ms->aes_key_wrap = true;
802     ms->dea_key_wrap = true;
803 }
804 
805 static const TypeInfo ccw_machine_info = {
806     .name          = TYPE_S390_CCW_MACHINE,
807     .parent        = TYPE_MACHINE,
808     .abstract      = true,
809     .instance_size = sizeof(S390CcwMachineState),
810     .instance_init = s390_machine_initfn,
811     .class_size = sizeof(S390CcwMachineClass),
812     .class_init    = ccw_machine_class_init,
813     .interfaces = (InterfaceInfo[]) {
814         { TYPE_NMI },
815         { TYPE_HOTPLUG_HANDLER},
816         { }
817     },
818 };
819 
820 #define DEFINE_CCW_MACHINE(suffix, verstr, latest)                            \
821     static void ccw_machine_##suffix##_class_init(ObjectClass *oc,            \
822                                                   void *data)                 \
823     {                                                                         \
824         MachineClass *mc = MACHINE_CLASS(oc);                                 \
825         ccw_machine_##suffix##_class_options(mc);                             \
826         mc->desc = "Virtual s390x machine (version " verstr ")";              \
827         if (latest) {                                                         \
828             mc->alias = "s390-ccw-virtio";                                    \
829             mc->is_default = true;                                            \
830         }                                                                     \
831     }                                                                         \
832     static void ccw_machine_##suffix##_instance_init(Object *obj)             \
833     {                                                                         \
834         MachineState *machine = MACHINE(obj);                                 \
835         current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine));          \
836         ccw_machine_##suffix##_instance_options(machine);                     \
837     }                                                                         \
838     static const TypeInfo ccw_machine_##suffix##_info = {                     \
839         .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr),                 \
840         .parent = TYPE_S390_CCW_MACHINE,                                      \
841         .class_init = ccw_machine_##suffix##_class_init,                      \
842         .instance_init = ccw_machine_##suffix##_instance_init,                \
843     };                                                                        \
844     static void ccw_machine_register_##suffix(void)                           \
845     {                                                                         \
846         type_register_static(&ccw_machine_##suffix##_info);                   \
847     }                                                                         \
848     type_init(ccw_machine_register_##suffix)
849 
850 static void ccw_machine_9_1_instance_options(MachineState *machine)
851 {
852 }
853 
854 static void ccw_machine_9_1_class_options(MachineClass *mc)
855 {
856 }
857 DEFINE_CCW_MACHINE(9_1, "9.1", true);
858 
859 static void ccw_machine_9_0_instance_options(MachineState *machine)
860 {
861     ccw_machine_9_1_instance_options(machine);
862 }
863 
864 static void ccw_machine_9_0_class_options(MachineClass *mc)
865 {
866     ccw_machine_9_1_class_options(mc);
867     compat_props_add(mc->compat_props, hw_compat_9_0, hw_compat_9_0_len);
868 }
869 DEFINE_CCW_MACHINE(9_0, "9.0", false);
870 
871 static void ccw_machine_8_2_instance_options(MachineState *machine)
872 {
873     ccw_machine_9_0_instance_options(machine);
874 }
875 
876 static void ccw_machine_8_2_class_options(MachineClass *mc)
877 {
878     ccw_machine_9_0_class_options(mc);
879     compat_props_add(mc->compat_props, hw_compat_8_2, hw_compat_8_2_len);
880 }
881 DEFINE_CCW_MACHINE(8_2, "8.2", false);
882 
883 static void ccw_machine_8_1_instance_options(MachineState *machine)
884 {
885     ccw_machine_8_2_instance_options(machine);
886 }
887 
888 static void ccw_machine_8_1_class_options(MachineClass *mc)
889 {
890     ccw_machine_8_2_class_options(mc);
891     compat_props_add(mc->compat_props, hw_compat_8_1, hw_compat_8_1_len);
892     mc->smp_props.drawers_supported = false;
893     mc->smp_props.books_supported = false;
894 }
895 DEFINE_CCW_MACHINE(8_1, "8.1", false);
896 
897 static void ccw_machine_8_0_instance_options(MachineState *machine)
898 {
899     ccw_machine_8_1_instance_options(machine);
900 }
901 
902 static void ccw_machine_8_0_class_options(MachineClass *mc)
903 {
904     ccw_machine_8_1_class_options(mc);
905     compat_props_add(mc->compat_props, hw_compat_8_0, hw_compat_8_0_len);
906 }
907 DEFINE_CCW_MACHINE(8_0, "8.0", false);
908 
909 static void ccw_machine_7_2_instance_options(MachineState *machine)
910 {
911     ccw_machine_8_0_instance_options(machine);
912 }
913 
914 static void ccw_machine_7_2_class_options(MachineClass *mc)
915 {
916     ccw_machine_8_0_class_options(mc);
917     compat_props_add(mc->compat_props, hw_compat_7_2, hw_compat_7_2_len);
918 }
919 DEFINE_CCW_MACHINE(7_2, "7.2", false);
920 
921 static void ccw_machine_7_1_instance_options(MachineState *machine)
922 {
923     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_1 };
924 
925     ccw_machine_7_2_instance_options(machine);
926     s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE);
927     s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
928 }
929 
930 static void ccw_machine_7_1_class_options(MachineClass *mc)
931 {
932     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
933     static GlobalProperty compat[] = {
934         { TYPE_S390_PCI_DEVICE, "interpret", "off", },
935         { TYPE_S390_PCI_DEVICE, "forwarding-assist", "off", },
936     };
937 
938     ccw_machine_7_2_class_options(mc);
939     compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len);
940     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
941     s390mc->max_threads = S390_MAX_CPUS;
942 }
943 DEFINE_CCW_MACHINE(7_1, "7.1", false);
944 
945 static void ccw_machine_7_0_instance_options(MachineState *machine)
946 {
947     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_0 };
948 
949     ccw_machine_7_1_instance_options(machine);
950     s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
951 }
952 
953 static void ccw_machine_7_0_class_options(MachineClass *mc)
954 {
955     ccw_machine_7_1_class_options(mc);
956     compat_props_add(mc->compat_props, hw_compat_7_0, hw_compat_7_0_len);
957 }
958 DEFINE_CCW_MACHINE(7_0, "7.0", false);
959 
960 static void ccw_machine_6_2_instance_options(MachineState *machine)
961 {
962     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_2 };
963 
964     ccw_machine_7_0_instance_options(machine);
965     s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat);
966 }
967 
968 static void ccw_machine_6_2_class_options(MachineClass *mc)
969 {
970     ccw_machine_7_0_class_options(mc);
971     compat_props_add(mc->compat_props, hw_compat_6_2, hw_compat_6_2_len);
972 }
973 DEFINE_CCW_MACHINE(6_2, "6.2", false);
974 
975 static void ccw_machine_6_1_instance_options(MachineState *machine)
976 {
977     ccw_machine_6_2_instance_options(machine);
978     s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA);
979     s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2);
980     s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH);
981     s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP);
982     s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI);
983 }
984 
985 static void ccw_machine_6_1_class_options(MachineClass *mc)
986 {
987     ccw_machine_6_2_class_options(mc);
988     compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
989     mc->smp_props.prefer_sockets = true;
990 }
991 DEFINE_CCW_MACHINE(6_1, "6.1", false);
992 
993 static void ccw_machine_6_0_instance_options(MachineState *machine)
994 {
995     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_0 };
996 
997     ccw_machine_6_1_instance_options(machine);
998     s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
999 }
1000 
1001 static void ccw_machine_6_0_class_options(MachineClass *mc)
1002 {
1003     ccw_machine_6_1_class_options(mc);
1004     compat_props_add(mc->compat_props, hw_compat_6_0, hw_compat_6_0_len);
1005 }
1006 DEFINE_CCW_MACHINE(6_0, "6.0", false);
1007 
1008 static void ccw_machine_5_2_instance_options(MachineState *machine)
1009 {
1010     ccw_machine_6_0_instance_options(machine);
1011 }
1012 
1013 static void ccw_machine_5_2_class_options(MachineClass *mc)
1014 {
1015     ccw_machine_6_0_class_options(mc);
1016     compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len);
1017 }
1018 DEFINE_CCW_MACHINE(5_2, "5.2", false);
1019 
1020 static void ccw_machine_5_1_instance_options(MachineState *machine)
1021 {
1022     ccw_machine_5_2_instance_options(machine);
1023 }
1024 
1025 static void ccw_machine_5_1_class_options(MachineClass *mc)
1026 {
1027     ccw_machine_5_2_class_options(mc);
1028     compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len);
1029 }
1030 DEFINE_CCW_MACHINE(5_1, "5.1", false);
1031 
1032 static void ccw_machine_5_0_instance_options(MachineState *machine)
1033 {
1034     ccw_machine_5_1_instance_options(machine);
1035 }
1036 
1037 static void ccw_machine_5_0_class_options(MachineClass *mc)
1038 {
1039     ccw_machine_5_1_class_options(mc);
1040     compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len);
1041 }
1042 DEFINE_CCW_MACHINE(5_0, "5.0", false);
1043 
1044 static void ccw_machine_4_2_instance_options(MachineState *machine)
1045 {
1046     ccw_machine_5_0_instance_options(machine);
1047 }
1048 
1049 static void ccw_machine_4_2_class_options(MachineClass *mc)
1050 {
1051     ccw_machine_5_0_class_options(mc);
1052     mc->fixup_ram_size = s390_fixup_ram_size;
1053     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
1054 }
1055 DEFINE_CCW_MACHINE(4_2, "4.2", false);
1056 
1057 static void ccw_machine_4_1_instance_options(MachineState *machine)
1058 {
1059     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
1060     ccw_machine_4_2_instance_options(machine);
1061     s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
1062 }
1063 
1064 static void ccw_machine_4_1_class_options(MachineClass *mc)
1065 {
1066     ccw_machine_4_2_class_options(mc);
1067     compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
1068 }
1069 DEFINE_CCW_MACHINE(4_1, "4.1", false);
1070 
1071 static void ccw_machine_4_0_instance_options(MachineState *machine)
1072 {
1073     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
1074     ccw_machine_4_1_instance_options(machine);
1075     s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1076 }
1077 
1078 static void ccw_machine_4_0_class_options(MachineClass *mc)
1079 {
1080     ccw_machine_4_1_class_options(mc);
1081     compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
1082 }
1083 DEFINE_CCW_MACHINE(4_0, "4.0", false);
1084 
1085 static void ccw_machine_3_1_instance_options(MachineState *machine)
1086 {
1087     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
1088     ccw_machine_4_0_instance_options(machine);
1089     s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
1090     s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
1091     s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1092 }
1093 
1094 static void ccw_machine_3_1_class_options(MachineClass *mc)
1095 {
1096     ccw_machine_4_0_class_options(mc);
1097     compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
1098 }
1099 DEFINE_CCW_MACHINE(3_1, "3.1", false);
1100 
1101 static void ccw_machine_3_0_instance_options(MachineState *machine)
1102 {
1103     ccw_machine_3_1_instance_options(machine);
1104 }
1105 
1106 static void ccw_machine_3_0_class_options(MachineClass *mc)
1107 {
1108     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1109 
1110     s390mc->hpage_1m_allowed = false;
1111     ccw_machine_3_1_class_options(mc);
1112     compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
1113 }
1114 DEFINE_CCW_MACHINE(3_0, "3.0", false);
1115 
1116 static void ccw_machine_2_12_instance_options(MachineState *machine)
1117 {
1118     ccw_machine_3_0_instance_options(machine);
1119     s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
1120     s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
1121 }
1122 
1123 static void ccw_machine_2_12_class_options(MachineClass *mc)
1124 {
1125     ccw_machine_3_0_class_options(mc);
1126     compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
1127 }
1128 DEFINE_CCW_MACHINE(2_12, "2.12", false);
1129 
1130 #ifdef CONFIG_S390X_LEGACY_CPUS
1131 
1132 static void ccw_machine_2_11_instance_options(MachineState *machine)
1133 {
1134     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
1135     ccw_machine_2_12_instance_options(machine);
1136 
1137     /* before 2.12 we emulated the very first z900 */
1138     s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
1139 }
1140 
1141 static void ccw_machine_2_11_class_options(MachineClass *mc)
1142 {
1143     static GlobalProperty compat[] = {
1144         { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
1145     };
1146 
1147     ccw_machine_2_12_class_options(mc);
1148     compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
1149     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1150 }
1151 DEFINE_CCW_MACHINE(2_11, "2.11", false);
1152 
1153 static void ccw_machine_2_10_instance_options(MachineState *machine)
1154 {
1155     ccw_machine_2_11_instance_options(machine);
1156 }
1157 
1158 static void ccw_machine_2_10_class_options(MachineClass *mc)
1159 {
1160     ccw_machine_2_11_class_options(mc);
1161     compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
1162 }
1163 DEFINE_CCW_MACHINE(2_10, "2.10", false);
1164 
1165 static void ccw_machine_2_9_instance_options(MachineState *machine)
1166 {
1167     ccw_machine_2_10_instance_options(machine);
1168     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
1169     s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
1170     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
1171     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
1172     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
1173 }
1174 
1175 static void ccw_machine_2_9_class_options(MachineClass *mc)
1176 {
1177     static GlobalProperty compat[] = {
1178         { TYPE_S390_STATTRIB, "migration-enabled", "off", },
1179         { TYPE_S390_FLIC_COMMON, "migration-enabled", "off", },
1180     };
1181 
1182     ccw_machine_2_10_class_options(mc);
1183     compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
1184     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1185     css_migration_enabled = false;
1186 }
1187 DEFINE_CCW_MACHINE(2_9, "2.9", false);
1188 
1189 static void ccw_machine_2_8_instance_options(MachineState *machine)
1190 {
1191     ccw_machine_2_9_instance_options(machine);
1192 }
1193 
1194 static void ccw_machine_2_8_class_options(MachineClass *mc)
1195 {
1196     static GlobalProperty compat[] = {
1197         { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
1198     };
1199 
1200     ccw_machine_2_9_class_options(mc);
1201     compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
1202     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1203 }
1204 DEFINE_CCW_MACHINE(2_8, "2.8", false);
1205 
1206 static void ccw_machine_2_7_instance_options(MachineState *machine)
1207 {
1208     ccw_machine_2_8_instance_options(machine);
1209 }
1210 
1211 static void ccw_machine_2_7_class_options(MachineClass *mc)
1212 {
1213     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1214 
1215     s390mc->cpu_model_allowed = false;
1216     ccw_machine_2_8_class_options(mc);
1217     compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
1218 }
1219 DEFINE_CCW_MACHINE(2_7, "2.7", false);
1220 
1221 static void ccw_machine_2_6_instance_options(MachineState *machine)
1222 {
1223     ccw_machine_2_7_instance_options(machine);
1224 }
1225 
1226 static void ccw_machine_2_6_class_options(MachineClass *mc)
1227 {
1228     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1229     static GlobalProperty compat[] = {
1230         { TYPE_S390_IPL, "iplbext_migration", "off", },
1231          { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
1232     };
1233 
1234     s390mc->ri_allowed = false;
1235     ccw_machine_2_7_class_options(mc);
1236     compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
1237     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1238 }
1239 DEFINE_CCW_MACHINE(2_6, "2.6", false);
1240 
1241 static void ccw_machine_2_5_instance_options(MachineState *machine)
1242 {
1243     ccw_machine_2_6_instance_options(machine);
1244 }
1245 
1246 static void ccw_machine_2_5_class_options(MachineClass *mc)
1247 {
1248     ccw_machine_2_6_class_options(mc);
1249     compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
1250 }
1251 DEFINE_CCW_MACHINE(2_5, "2.5", false);
1252 
1253 static void ccw_machine_2_4_instance_options(MachineState *machine)
1254 {
1255     ccw_machine_2_5_instance_options(machine);
1256 }
1257 
1258 static void ccw_machine_2_4_class_options(MachineClass *mc)
1259 {
1260     static GlobalProperty compat[] = {
1261         { TYPE_S390_SKEYS, "migration-enabled", "off", },
1262         { "virtio-blk-ccw", "max_revision", "0", },
1263         { "virtio-balloon-ccw", "max_revision", "0", },
1264         { "virtio-serial-ccw", "max_revision", "0", },
1265         { "virtio-9p-ccw", "max_revision", "0", },
1266         { "virtio-rng-ccw", "max_revision", "0", },
1267         { "virtio-net-ccw", "max_revision", "0", },
1268         { "virtio-scsi-ccw", "max_revision", "0", },
1269         { "vhost-scsi-ccw", "max_revision", "0", },
1270     };
1271 
1272     ccw_machine_2_5_class_options(mc);
1273     compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
1274     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1275 }
1276 DEFINE_CCW_MACHINE(2_4, "2.4", false);
1277 
1278 #endif
1279 
1280 static void ccw_machine_register_types(void)
1281 {
1282     type_register_static(&ccw_machine_info);
1283 }
1284 
1285 type_init(ccw_machine_register_types)
1286