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