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