xref: /qemu/hw/s390x/s390-virtio-ccw.c (revision e16354b7f2e70d5ece97854d00141e3df4625cf6)
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 "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 
814     s390mc->hpage_1m_allowed = true;
815     s390mc->max_threads = 1;
816     mc->reset = s390_machine_reset;
817     mc->block_default_type = IF_VIRTIO;
818     mc->no_cdrom = 1;
819     mc->no_floppy = 1;
820     mc->no_parallel = 1;
821     mc->max_cpus = S390_MAX_CPUS;
822     mc->has_hotpluggable_cpus = true;
823     mc->smp_props.books_supported = true;
824     mc->smp_props.drawers_supported = true;
825     assert(!mc->get_hotplug_handler);
826     mc->get_hotplug_handler = s390_get_hotplug_handler;
827     mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
828     mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
829     /* it is overridden with 'host' cpu *in kvm_arch_init* */
830     mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
831     hc->pre_plug = s390_machine_device_pre_plug;
832     hc->plug = s390_machine_device_plug;
833     hc->unplug_request = s390_machine_device_unplug_request;
834     hc->unplug = s390_machine_device_unplug;
835     nc->nmi_monitor_handler = s390_nmi;
836     mc->default_ram_id = "s390.ram";
837     mc->default_nic = "virtio-net-ccw";
838 
839     object_class_property_add_bool(oc, "aes-key-wrap",
840                                    machine_get_aes_key_wrap,
841                                    machine_set_aes_key_wrap);
842     object_class_property_set_description(oc, "aes-key-wrap",
843             "enable/disable AES key wrapping using the CPACF wrapping key");
844 
845     object_class_property_add_bool(oc, "dea-key-wrap",
846                                    machine_get_dea_key_wrap,
847                                    machine_set_dea_key_wrap);
848     object_class_property_set_description(oc, "dea-key-wrap",
849             "enable/disable DEA key wrapping using the CPACF wrapping key");
850 
851     object_class_property_add(oc, "loadparm", "loadparm",
852                               machine_get_loadparm, machine_set_loadparm,
853                               NULL, NULL);
854     object_class_property_set_description(oc, "loadparm",
855             "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
856             " to upper case) to pass to machine loader, boot manager,"
857             " and guest kernel");
858 }
859 
860 static inline void s390_machine_initfn(Object *obj)
861 {
862     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
863 
864     ms->aes_key_wrap = true;
865     ms->dea_key_wrap = true;
866 }
867 
868 static const TypeInfo ccw_machine_info = {
869     .name          = TYPE_S390_CCW_MACHINE,
870     .parent        = TYPE_MACHINE,
871     .abstract      = true,
872     .instance_size = sizeof(S390CcwMachineState),
873     .instance_init = s390_machine_initfn,
874     .class_size = sizeof(S390CcwMachineClass),
875     .class_init    = ccw_machine_class_init,
876     .interfaces = (InterfaceInfo[]) {
877         { TYPE_NMI },
878         { TYPE_HOTPLUG_HANDLER},
879         { }
880     },
881 };
882 
883 #define DEFINE_CCW_MACHINE_IMPL(latest, ...)                                  \
884     static void MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__)(MachineState *mach) \
885     {                                                                         \
886         current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(mach));         \
887         MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(mach);            \
888         ccw_init(mach);                                                       \
889     }                                                                         \
890     static void MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__)(                \
891         ObjectClass *oc,                                                      \
892         void *data)                                                           \
893     {                                                                         \
894         MachineClass *mc = MACHINE_CLASS(oc);                                 \
895         MACHINE_VER_SYM(class_options, ccw, __VA_ARGS__)(mc);                 \
896         mc->desc = "Virtual s390x machine (version " MACHINE_VER_STR(__VA_ARGS__) ")"; \
897         mc->init = MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__);              \
898         MACHINE_VER_DEPRECATION(__VA_ARGS__);                                 \
899         if (latest) {                                                         \
900             mc->alias = "s390-ccw-virtio";                                    \
901             mc->is_default = true;                                            \
902         }                                                                     \
903     }                                                                         \
904     static const TypeInfo MACHINE_VER_SYM(info, ccw, __VA_ARGS__) =           \
905     {                                                                         \
906         .name = MACHINE_VER_TYPE_NAME("s390-ccw-virtio", __VA_ARGS__),        \
907         .parent = TYPE_S390_CCW_MACHINE,                                      \
908         .class_init = MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__),          \
909     };                                                                        \
910     static void MACHINE_VER_SYM(register, ccw, __VA_ARGS__)(void)             \
911     {                                                                         \
912         MACHINE_VER_DELETION(__VA_ARGS__);                                    \
913         type_register_static(&MACHINE_VER_SYM(info, ccw, __VA_ARGS__));       \
914     }                                                                         \
915     type_init(MACHINE_VER_SYM(register, ccw, __VA_ARGS__))
916 
917 #define DEFINE_CCW_MACHINE_AS_LATEST(major, minor) \
918     DEFINE_CCW_MACHINE_IMPL(true, major, minor)
919 
920 #define DEFINE_CCW_MACHINE(major, minor) \
921     DEFINE_CCW_MACHINE_IMPL(false, major, minor)
922 
923 
924 static void ccw_machine_10_0_instance_options(MachineState *machine)
925 {
926 }
927 
928 static void ccw_machine_10_0_class_options(MachineClass *mc)
929 {
930 }
931 DEFINE_CCW_MACHINE_AS_LATEST(10, 0);
932 
933 static void ccw_machine_9_2_instance_options(MachineState *machine)
934 {
935     ccw_machine_10_0_instance_options(machine);
936 }
937 
938 static void ccw_machine_9_2_class_options(MachineClass *mc)
939 {
940     static GlobalProperty compat[] = {
941         { TYPE_S390_PCI_DEVICE, "relaxed-translation", "off", },
942     };
943 
944     ccw_machine_10_0_class_options(mc);
945     compat_props_add(mc->compat_props, hw_compat_9_2, hw_compat_9_2_len);
946     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
947 }
948 DEFINE_CCW_MACHINE(9, 2);
949 
950 static void ccw_machine_9_1_instance_options(MachineState *machine)
951 {
952     ccw_machine_9_2_instance_options(machine);
953 }
954 
955 static void ccw_machine_9_1_class_options(MachineClass *mc)
956 {
957     ccw_machine_9_2_class_options(mc);
958     compat_props_add(mc->compat_props, hw_compat_9_1, hw_compat_9_1_len);
959 }
960 DEFINE_CCW_MACHINE(9, 1);
961 
962 static void ccw_machine_9_0_instance_options(MachineState *machine)
963 {
964     ccw_machine_9_1_instance_options(machine);
965 }
966 
967 static void ccw_machine_9_0_class_options(MachineClass *mc)
968 {
969     static GlobalProperty compat[] = {
970         { TYPE_QEMU_S390_FLIC, "migrate-all-state", "off", },
971     };
972 
973     ccw_machine_9_1_class_options(mc);
974     compat_props_add(mc->compat_props, hw_compat_9_0, hw_compat_9_0_len);
975     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
976 }
977 DEFINE_CCW_MACHINE(9, 0);
978 
979 static void ccw_machine_8_2_instance_options(MachineState *machine)
980 {
981     ccw_machine_9_0_instance_options(machine);
982 }
983 
984 static void ccw_machine_8_2_class_options(MachineClass *mc)
985 {
986     ccw_machine_9_0_class_options(mc);
987     compat_props_add(mc->compat_props, hw_compat_8_2, hw_compat_8_2_len);
988 }
989 DEFINE_CCW_MACHINE(8, 2);
990 
991 static void ccw_machine_8_1_instance_options(MachineState *machine)
992 {
993     ccw_machine_8_2_instance_options(machine);
994 }
995 
996 static void ccw_machine_8_1_class_options(MachineClass *mc)
997 {
998     ccw_machine_8_2_class_options(mc);
999     compat_props_add(mc->compat_props, hw_compat_8_1, hw_compat_8_1_len);
1000     mc->smp_props.drawers_supported = false;
1001     mc->smp_props.books_supported = false;
1002 }
1003 DEFINE_CCW_MACHINE(8, 1);
1004 
1005 static void ccw_machine_8_0_instance_options(MachineState *machine)
1006 {
1007     ccw_machine_8_1_instance_options(machine);
1008 }
1009 
1010 static void ccw_machine_8_0_class_options(MachineClass *mc)
1011 {
1012     ccw_machine_8_1_class_options(mc);
1013     compat_props_add(mc->compat_props, hw_compat_8_0, hw_compat_8_0_len);
1014 }
1015 DEFINE_CCW_MACHINE(8, 0);
1016 
1017 static void ccw_machine_7_2_instance_options(MachineState *machine)
1018 {
1019     ccw_machine_8_0_instance_options(machine);
1020 }
1021 
1022 static void ccw_machine_7_2_class_options(MachineClass *mc)
1023 {
1024     ccw_machine_8_0_class_options(mc);
1025     compat_props_add(mc->compat_props, hw_compat_7_2, hw_compat_7_2_len);
1026 }
1027 DEFINE_CCW_MACHINE(7, 2);
1028 
1029 static void ccw_machine_7_1_instance_options(MachineState *machine)
1030 {
1031     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_1 };
1032 
1033     ccw_machine_7_2_instance_options(machine);
1034     s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE);
1035     s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
1036 }
1037 
1038 static void ccw_machine_7_1_class_options(MachineClass *mc)
1039 {
1040     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1041     static GlobalProperty compat[] = {
1042         { TYPE_S390_PCI_DEVICE, "interpret", "off", },
1043         { TYPE_S390_PCI_DEVICE, "forwarding-assist", "off", },
1044     };
1045 
1046     ccw_machine_7_2_class_options(mc);
1047     compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len);
1048     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1049     s390mc->max_threads = S390_MAX_CPUS;
1050 }
1051 DEFINE_CCW_MACHINE(7, 1);
1052 
1053 static void ccw_machine_7_0_instance_options(MachineState *machine)
1054 {
1055     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_0 };
1056 
1057     ccw_machine_7_1_instance_options(machine);
1058     s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
1059 }
1060 
1061 static void ccw_machine_7_0_class_options(MachineClass *mc)
1062 {
1063     ccw_machine_7_1_class_options(mc);
1064     compat_props_add(mc->compat_props, hw_compat_7_0, hw_compat_7_0_len);
1065 }
1066 DEFINE_CCW_MACHINE(7, 0);
1067 
1068 static void ccw_machine_6_2_instance_options(MachineState *machine)
1069 {
1070     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_2 };
1071 
1072     ccw_machine_7_0_instance_options(machine);
1073     s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat);
1074 }
1075 
1076 static void ccw_machine_6_2_class_options(MachineClass *mc)
1077 {
1078     ccw_machine_7_0_class_options(mc);
1079     compat_props_add(mc->compat_props, hw_compat_6_2, hw_compat_6_2_len);
1080 }
1081 DEFINE_CCW_MACHINE(6, 2);
1082 
1083 static void ccw_machine_6_1_instance_options(MachineState *machine)
1084 {
1085     ccw_machine_6_2_instance_options(machine);
1086     s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA);
1087     s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2);
1088     s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH);
1089     s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP);
1090     s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI);
1091 }
1092 
1093 static void ccw_machine_6_1_class_options(MachineClass *mc)
1094 {
1095     ccw_machine_6_2_class_options(mc);
1096     compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
1097     mc->smp_props.prefer_sockets = true;
1098 }
1099 DEFINE_CCW_MACHINE(6, 1);
1100 
1101 static void ccw_machine_6_0_instance_options(MachineState *machine)
1102 {
1103     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_0 };
1104 
1105     ccw_machine_6_1_instance_options(machine);
1106     s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
1107 }
1108 
1109 static void ccw_machine_6_0_class_options(MachineClass *mc)
1110 {
1111     ccw_machine_6_1_class_options(mc);
1112     compat_props_add(mc->compat_props, hw_compat_6_0, hw_compat_6_0_len);
1113 }
1114 DEFINE_CCW_MACHINE(6, 0);
1115 
1116 static void ccw_machine_5_2_instance_options(MachineState *machine)
1117 {
1118     ccw_machine_6_0_instance_options(machine);
1119 }
1120 
1121 static void ccw_machine_5_2_class_options(MachineClass *mc)
1122 {
1123     ccw_machine_6_0_class_options(mc);
1124     compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len);
1125 }
1126 DEFINE_CCW_MACHINE(5, 2);
1127 
1128 static void ccw_machine_5_1_instance_options(MachineState *machine)
1129 {
1130     ccw_machine_5_2_instance_options(machine);
1131 }
1132 
1133 static void ccw_machine_5_1_class_options(MachineClass *mc)
1134 {
1135     ccw_machine_5_2_class_options(mc);
1136     compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len);
1137 }
1138 DEFINE_CCW_MACHINE(5, 1);
1139 
1140 static void ccw_machine_5_0_instance_options(MachineState *machine)
1141 {
1142     ccw_machine_5_1_instance_options(machine);
1143 }
1144 
1145 static void ccw_machine_5_0_class_options(MachineClass *mc)
1146 {
1147     ccw_machine_5_1_class_options(mc);
1148     compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len);
1149 }
1150 DEFINE_CCW_MACHINE(5, 0);
1151 
1152 static void ccw_machine_4_2_instance_options(MachineState *machine)
1153 {
1154     ccw_machine_5_0_instance_options(machine);
1155 }
1156 
1157 static void ccw_machine_4_2_class_options(MachineClass *mc)
1158 {
1159     ccw_machine_5_0_class_options(mc);
1160     mc->fixup_ram_size = s390_fixup_ram_size;
1161     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
1162 }
1163 DEFINE_CCW_MACHINE(4, 2);
1164 
1165 static void ccw_machine_4_1_instance_options(MachineState *machine)
1166 {
1167     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
1168     ccw_machine_4_2_instance_options(machine);
1169     s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
1170 }
1171 
1172 static void ccw_machine_4_1_class_options(MachineClass *mc)
1173 {
1174     ccw_machine_4_2_class_options(mc);
1175     compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
1176 }
1177 DEFINE_CCW_MACHINE(4, 1);
1178 
1179 static void ccw_machine_4_0_instance_options(MachineState *machine)
1180 {
1181     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
1182     ccw_machine_4_1_instance_options(machine);
1183     s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1184 }
1185 
1186 static void ccw_machine_4_0_class_options(MachineClass *mc)
1187 {
1188     ccw_machine_4_1_class_options(mc);
1189     compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
1190 }
1191 DEFINE_CCW_MACHINE(4, 0);
1192 
1193 static void ccw_machine_3_1_instance_options(MachineState *machine)
1194 {
1195     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
1196     ccw_machine_4_0_instance_options(machine);
1197     s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
1198     s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
1199     s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1200 }
1201 
1202 static void ccw_machine_3_1_class_options(MachineClass *mc)
1203 {
1204     ccw_machine_4_0_class_options(mc);
1205     compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
1206 }
1207 DEFINE_CCW_MACHINE(3, 1);
1208 
1209 static void ccw_machine_3_0_instance_options(MachineState *machine)
1210 {
1211     ccw_machine_3_1_instance_options(machine);
1212 }
1213 
1214 static void ccw_machine_3_0_class_options(MachineClass *mc)
1215 {
1216     S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1217 
1218     s390mc->hpage_1m_allowed = false;
1219     ccw_machine_3_1_class_options(mc);
1220     compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
1221 }
1222 DEFINE_CCW_MACHINE(3, 0);
1223 
1224 static void ccw_machine_2_12_instance_options(MachineState *machine)
1225 {
1226     ccw_machine_3_0_instance_options(machine);
1227     s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
1228     s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
1229 }
1230 
1231 static void ccw_machine_2_12_class_options(MachineClass *mc)
1232 {
1233     ccw_machine_3_0_class_options(mc);
1234     compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
1235 }
1236 DEFINE_CCW_MACHINE(2, 12);
1237 
1238 #ifdef CONFIG_S390X_LEGACY_CPUS
1239 
1240 static void ccw_machine_2_11_instance_options(MachineState *machine)
1241 {
1242     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
1243     ccw_machine_2_12_instance_options(machine);
1244 
1245     /* before 2.12 we emulated the very first z900 */
1246     s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
1247 }
1248 
1249 static void ccw_machine_2_11_class_options(MachineClass *mc)
1250 {
1251     static GlobalProperty compat[] = {
1252         { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
1253     };
1254 
1255     ccw_machine_2_12_class_options(mc);
1256     compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
1257     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1258 }
1259 DEFINE_CCW_MACHINE(2, 11);
1260 
1261 static void ccw_machine_2_10_instance_options(MachineState *machine)
1262 {
1263     ccw_machine_2_11_instance_options(machine);
1264 }
1265 
1266 static void ccw_machine_2_10_class_options(MachineClass *mc)
1267 {
1268     ccw_machine_2_11_class_options(mc);
1269     compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
1270 }
1271 DEFINE_CCW_MACHINE(2, 10);
1272 
1273 static void ccw_machine_2_9_instance_options(MachineState *machine)
1274 {
1275     ccw_machine_2_10_instance_options(machine);
1276     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
1277     s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
1278     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
1279     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
1280     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
1281     css_migration_enabled = false;
1282 }
1283 
1284 static void ccw_machine_2_9_class_options(MachineClass *mc)
1285 {
1286     static GlobalProperty compat[] = {
1287         { TYPE_S390_STATTRIB, "migration-enabled", "off", },
1288         { TYPE_S390_FLIC_COMMON, "migration-enabled", "off", },
1289     };
1290 
1291     ccw_machine_2_10_class_options(mc);
1292     compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
1293     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1294 }
1295 DEFINE_CCW_MACHINE(2, 9);
1296 
1297 #endif
1298 
1299 static void ccw_machine_register_types(void)
1300 {
1301     type_register_static(&ccw_machine_info);
1302 }
1303 
1304 type_init(ccw_machine_register_types)
1305