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