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