xref: /qemu/hw/s390x/s390-virtio-ccw.c (revision 686a0fe4)
1 /*
2  * virtio ccw machine
3  *
4  * Copyright 2012 IBM Corp.
5  * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
6  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or (at
9  * your option) any later version. See the COPYING file in the top-level
10  * directory.
11  */
12 
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "cpu.h"
16 #include "hw/boards.h"
17 #include "exec/address-spaces.h"
18 #include "exec/ram_addr.h"
19 #include "hw/s390x/s390-virtio-hcall.h"
20 #include "hw/s390x/sclp.h"
21 #include "hw/s390x/s390_flic.h"
22 #include "hw/s390x/ioinst.h"
23 #include "hw/s390x/css.h"
24 #include "virtio-ccw.h"
25 #include "qemu/config-file.h"
26 #include "qemu/ctype.h"
27 #include "qemu/error-report.h"
28 #include "qemu/option.h"
29 #include "s390-pci-bus.h"
30 #include "sysemu/reset.h"
31 #include "hw/s390x/storage-keys.h"
32 #include "hw/s390x/storage-attributes.h"
33 #include "hw/s390x/event-facility.h"
34 #include "ipl.h"
35 #include "hw/s390x/s390-virtio-ccw.h"
36 #include "hw/s390x/css-bridge.h"
37 #include "hw/s390x/ap-bridge.h"
38 #include "migration/register.h"
39 #include "cpu_models.h"
40 #include "hw/nmi.h"
41 #include "hw/qdev-properties.h"
42 #include "hw/s390x/tod.h"
43 #include "sysemu/sysemu.h"
44 
45 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
46 {
47     static MachineState *ms;
48 
49     if (!ms) {
50         ms = MACHINE(qdev_get_machine());
51         g_assert(ms->possible_cpus);
52     }
53 
54     /* CPU address corresponds to the core_id and the index */
55     if (cpu_addr >= ms->possible_cpus->len) {
56         return NULL;
57     }
58     return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
59 }
60 
61 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
62                               Error **errp)
63 {
64     S390CPU *cpu = S390_CPU(object_new(typename));
65     Error *err = NULL;
66 
67     object_property_set_int(OBJECT(cpu), core_id, "core-id", &err);
68     if (err != NULL) {
69         goto out;
70     }
71     object_property_set_bool(OBJECT(cpu), true, "realized", &err);
72 
73 out:
74     object_unref(OBJECT(cpu));
75     if (err) {
76         error_propagate(errp, err);
77         cpu = NULL;
78     }
79     return cpu;
80 }
81 
82 static void s390_init_cpus(MachineState *machine)
83 {
84     MachineClass *mc = MACHINE_GET_CLASS(machine);
85     int i;
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 };
101 
102 static void subsystem_reset(void)
103 {
104     DeviceState *dev;
105     int i;
106 
107     for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
108         dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
109         if (dev) {
110             qdev_reset_all(dev);
111         }
112     }
113 }
114 
115 static int virtio_ccw_hcall_notify(const uint64_t *args)
116 {
117     uint64_t subch_id = args[0];
118     uint64_t queue = args[1];
119     SubchDev *sch;
120     int cssid, ssid, schid, m;
121 
122     if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
123         return -EINVAL;
124     }
125     sch = css_find_subch(m, cssid, ssid, schid);
126     if (!sch || !css_subch_visible(sch)) {
127         return -EINVAL;
128     }
129     if (queue >= VIRTIO_QUEUE_MAX) {
130         return -EINVAL;
131     }
132     virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
133     return 0;
134 
135 }
136 
137 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
138 {
139     uint64_t mem = args[0];
140 
141     if (mem < ram_size) {
142         /* Early printk */
143         return 0;
144     }
145     return -EINVAL;
146 }
147 
148 static void virtio_ccw_register_hcalls(void)
149 {
150     s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
151                                    virtio_ccw_hcall_notify);
152     /* Tolerate early printk. */
153     s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
154                                    virtio_ccw_hcall_early_printk);
155 }
156 
157 static void s390_memory_init(MemoryRegion *ram)
158 {
159     MemoryRegion *sysmem = get_system_memory();
160     Error *local_err = NULL;
161 
162     /* allocate RAM for core */
163     memory_region_add_subregion(sysmem, 0, ram);
164 
165     /*
166      * Configure the maximum page size. As no memory devices were created
167      * yet, this is the page size of initial memory only.
168      */
169     s390_set_max_pagesize(qemu_maxrampagesize(), &local_err);
170     if (local_err) {
171         error_report_err(local_err);
172         exit(EXIT_FAILURE);
173     }
174     /* Initialize storage key device */
175     s390_skeys_init();
176     /* Initialize storage attributes device */
177     s390_stattrib_init();
178 }
179 
180 static void s390_init_ipl_dev(const char *kernel_filename,
181                               const char *kernel_cmdline,
182                               const char *initrd_filename, const char *firmware,
183                               const char *netboot_fw, bool enforce_bios)
184 {
185     Object *new = object_new(TYPE_S390_IPL);
186     DeviceState *dev = DEVICE(new);
187     char *netboot_fw_prop;
188 
189     if (kernel_filename) {
190         qdev_prop_set_string(dev, "kernel", kernel_filename);
191     }
192     if (initrd_filename) {
193         qdev_prop_set_string(dev, "initrd", initrd_filename);
194     }
195     qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
196     qdev_prop_set_string(dev, "firmware", firmware);
197     qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
198     netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
199     if (!strlen(netboot_fw_prop)) {
200         qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
201     }
202     g_free(netboot_fw_prop);
203     object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
204                               new, NULL);
205     object_unref(new);
206     qdev_init_nofail(dev);
207 }
208 
209 static void s390_create_virtio_net(BusState *bus, const char *name)
210 {
211     int i;
212 
213     for (i = 0; i < nb_nics; i++) {
214         NICInfo *nd = &nd_table[i];
215         DeviceState *dev;
216 
217         if (!nd->model) {
218             nd->model = g_strdup("virtio");
219         }
220 
221         qemu_check_nic_model(nd, "virtio");
222 
223         dev = qdev_create(bus, name);
224         qdev_set_nic_properties(dev, nd);
225         qdev_init_nofail(dev);
226     }
227 }
228 
229 static void s390_create_sclpconsole(const char *type, Chardev *chardev)
230 {
231     DeviceState *dev;
232 
233     dev = qdev_create(sclp_get_event_facility_bus(), type);
234     qdev_prop_set_chr(dev, "chardev", chardev);
235     qdev_init_nofail(dev);
236 }
237 
238 static void ccw_init(MachineState *machine)
239 {
240     int ret;
241     VirtualCssBus *css_bus;
242     DeviceState *dev;
243 
244     s390_sclp_init();
245     /* init memory + setup max page size. Required for the CPU model */
246     s390_memory_init(machine->ram);
247 
248     /* init CPUs (incl. CPU model) early so s390_has_feature() works */
249     s390_init_cpus(machine);
250 
251     s390_flic_init();
252 
253     /* init the SIGP facility */
254     s390_init_sigp();
255 
256     /* create AP bridge and bus(es) */
257     s390_init_ap();
258 
259     /* get a BUS */
260     css_bus = virtual_css_bus_init();
261     s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
262                       machine->initrd_filename, "s390-ccw.img",
263                       "s390-netboot.img", true);
264 
265     dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
266     object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
267                               OBJECT(dev), NULL);
268     qdev_init_nofail(dev);
269 
270     /* register hypercalls */
271     virtio_ccw_register_hcalls();
272 
273     s390_enable_css_support(s390_cpu_addr2state(0));
274 
275     ret = css_create_css_image(VIRTUAL_CSSID, true);
276 
277     assert(ret == 0);
278     if (css_migration_enabled()) {
279         css_register_vmstate();
280     }
281 
282     /* Create VirtIO network adapters */
283     s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
284 
285     /* init consoles */
286     if (serial_hd(0)) {
287         s390_create_sclpconsole("sclpconsole", serial_hd(0));
288     }
289     if (serial_hd(1)) {
290         s390_create_sclpconsole("sclplmconsole", serial_hd(1));
291     }
292 
293     /* init the TOD clock */
294     s390_init_tod();
295 }
296 
297 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
298                         DeviceState *dev, Error **errp)
299 {
300     MachineState *ms = MACHINE(hotplug_dev);
301     S390CPU *cpu = S390_CPU(dev);
302 
303     g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
304     ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
305 
306     if (dev->hotplugged) {
307         raise_irq_cpu_hotplug();
308     }
309 }
310 
311 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
312 {
313     S390CPU *cpu = S390_CPU(cs);
314 
315     s390_ipl_prepare_cpu(cpu);
316     s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
317 }
318 
319 static void s390_machine_reset(MachineState *machine)
320 {
321     enum s390_reset reset_type;
322     CPUState *cs, *t;
323 
324     /* get the reset parameters, reset them once done */
325     s390_ipl_get_reset_request(&cs, &reset_type);
326 
327     /* all CPUs are paused and synchronized at this point */
328     s390_cmma_reset();
329 
330     switch (reset_type) {
331     case S390_RESET_EXTERNAL:
332     case S390_RESET_REIPL:
333         qemu_devices_reset();
334         s390_crypto_reset();
335 
336         /* configure and start the ipl CPU only */
337         run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
338         break;
339     case S390_RESET_MODIFIED_CLEAR:
340         CPU_FOREACH(t) {
341             run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
342         }
343         subsystem_reset();
344         s390_crypto_reset();
345         run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
346         break;
347     case S390_RESET_LOAD_NORMAL:
348         CPU_FOREACH(t) {
349             if (t == cs) {
350                 continue;
351             }
352             run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
353         }
354         subsystem_reset();
355         run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
356         run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
357         break;
358     default:
359         g_assert_not_reached();
360     }
361     s390_ipl_clear_reset_request();
362 }
363 
364 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
365                                      DeviceState *dev, Error **errp)
366 {
367     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
368         s390_cpu_plug(hotplug_dev, dev, errp);
369     }
370 }
371 
372 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
373                                                DeviceState *dev, Error **errp)
374 {
375     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
376         error_setg(errp, "CPU hot unplug not supported on this machine");
377         return;
378     }
379 }
380 
381 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
382                                                      unsigned cpu_index)
383 {
384     MachineClass *mc = MACHINE_GET_CLASS(ms);
385     const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
386 
387     assert(cpu_index < possible_cpus->len);
388     return possible_cpus->cpus[cpu_index].props;
389 }
390 
391 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
392 {
393     int i;
394     unsigned int max_cpus = ms->smp.max_cpus;
395 
396     if (ms->possible_cpus) {
397         g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
398         return ms->possible_cpus;
399     }
400 
401     ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
402                                   sizeof(CPUArchId) * max_cpus);
403     ms->possible_cpus->len = max_cpus;
404     for (i = 0; i < ms->possible_cpus->len; i++) {
405         ms->possible_cpus->cpus[i].type = ms->cpu_type;
406         ms->possible_cpus->cpus[i].vcpus_count = 1;
407         ms->possible_cpus->cpus[i].arch_id = i;
408         ms->possible_cpus->cpus[i].props.has_core_id = true;
409         ms->possible_cpus->cpus[i].props.core_id = i;
410     }
411 
412     return ms->possible_cpus;
413 }
414 
415 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
416                                                 DeviceState *dev)
417 {
418     if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
419         return HOTPLUG_HANDLER(machine);
420     }
421     return NULL;
422 }
423 
424 static void s390_hot_add_cpu(MachineState *machine,
425                              const int64_t id, Error **errp)
426 {
427     ObjectClass *oc;
428 
429     g_assert(machine->possible_cpus->cpus[0].cpu);
430     oc = OBJECT_CLASS(CPU_GET_CLASS(machine->possible_cpus->cpus[0].cpu));
431 
432     s390x_new_cpu(object_class_get_name(oc), id, errp);
433 }
434 
435 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
436 {
437     CPUState *cs = qemu_get_cpu(cpu_index);
438 
439     s390_cpu_restart(S390_CPU(cs));
440 }
441 
442 static void ccw_machine_class_init(ObjectClass *oc, void *data)
443 {
444     MachineClass *mc = MACHINE_CLASS(oc);
445     NMIClass *nc = NMI_CLASS(oc);
446     HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
447     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
448 
449     s390mc->ri_allowed = true;
450     s390mc->cpu_model_allowed = true;
451     s390mc->css_migration_enabled = true;
452     s390mc->hpage_1m_allowed = true;
453     mc->init = ccw_init;
454     mc->reset = s390_machine_reset;
455     mc->hot_add_cpu = s390_hot_add_cpu;
456     mc->block_default_type = IF_VIRTIO;
457     mc->no_cdrom = 1;
458     mc->no_floppy = 1;
459     mc->no_parallel = 1;
460     mc->no_sdcard = 1;
461     mc->max_cpus = S390_MAX_CPUS;
462     mc->has_hotpluggable_cpus = true;
463     assert(!mc->get_hotplug_handler);
464     mc->get_hotplug_handler = s390_get_hotplug_handler;
465     mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
466     mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
467     /* it is overridden with 'host' cpu *in kvm_arch_init* */
468     mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
469     hc->plug = s390_machine_device_plug;
470     hc->unplug_request = s390_machine_device_unplug_request;
471     nc->nmi_monitor_handler = s390_nmi;
472     mc->default_ram_id = "s390.ram";
473 }
474 
475 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
476 {
477     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
478 
479     return ms->aes_key_wrap;
480 }
481 
482 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
483                                             Error **errp)
484 {
485     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
486 
487     ms->aes_key_wrap = value;
488 }
489 
490 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
491 {
492     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
493 
494     return ms->dea_key_wrap;
495 }
496 
497 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
498                                             Error **errp)
499 {
500     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
501 
502     ms->dea_key_wrap = value;
503 }
504 
505 static S390CcwMachineClass *current_mc;
506 
507 /*
508  * Get the class of the s390-ccw-virtio machine that is currently in use.
509  * Note: libvirt is using the "none" machine to probe for the features of the
510  * host CPU, so in case this is called with the "none" machine, the function
511  * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
512  * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
513  * below return the correct default value for the "none" machine.
514  *
515  * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
516  * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
517  * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
518  * CPU initialization and s390_has_feat() later should be sufficient.
519  */
520 static S390CcwMachineClass *get_machine_class(void)
521 {
522     if (unlikely(!current_mc)) {
523         /*
524         * No s390 ccw machine was instantiated, we are likely to
525         * be called for the 'none' machine. The properties will
526         * have their after-initialization values.
527         */
528         current_mc = S390_MACHINE_CLASS(
529                      object_class_by_name(TYPE_S390_CCW_MACHINE));
530     }
531     return current_mc;
532 }
533 
534 bool ri_allowed(void)
535 {
536     return get_machine_class()->ri_allowed;
537 }
538 
539 bool cpu_model_allowed(void)
540 {
541     return get_machine_class()->cpu_model_allowed;
542 }
543 
544 bool hpage_1m_allowed(void)
545 {
546     return get_machine_class()->hpage_1m_allowed;
547 }
548 
549 static char *machine_get_loadparm(Object *obj, Error **errp)
550 {
551     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
552 
553     return g_memdup(ms->loadparm, sizeof(ms->loadparm));
554 }
555 
556 static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
557 {
558     S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
559     int i;
560 
561     for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
562         uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
563 
564         if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
565             (c == ' ')) {
566             ms->loadparm[i] = c;
567         } else {
568             error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
569                        c, c);
570             return;
571         }
572     }
573 
574     for (; i < sizeof(ms->loadparm); i++) {
575         ms->loadparm[i] = ' '; /* pad right with spaces */
576     }
577 }
578 static inline void s390_machine_initfn(Object *obj)
579 {
580     object_property_add_bool(obj, "aes-key-wrap",
581                              machine_get_aes_key_wrap,
582                              machine_set_aes_key_wrap, NULL);
583     object_property_set_description(obj, "aes-key-wrap",
584             "enable/disable AES key wrapping using the CPACF wrapping key",
585             NULL);
586     object_property_set_bool(obj, true, "aes-key-wrap", NULL);
587 
588     object_property_add_bool(obj, "dea-key-wrap",
589                              machine_get_dea_key_wrap,
590                              machine_set_dea_key_wrap, NULL);
591     object_property_set_description(obj, "dea-key-wrap",
592             "enable/disable DEA key wrapping using the CPACF wrapping key",
593             NULL);
594     object_property_set_bool(obj, true, "dea-key-wrap", NULL);
595     object_property_add_str(obj, "loadparm",
596             machine_get_loadparm, machine_set_loadparm, NULL);
597     object_property_set_description(obj, "loadparm",
598             "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
599             " to upper case) to pass to machine loader, boot manager,"
600             " and guest kernel",
601             NULL);
602 }
603 
604 static const TypeInfo ccw_machine_info = {
605     .name          = TYPE_S390_CCW_MACHINE,
606     .parent        = TYPE_MACHINE,
607     .abstract      = true,
608     .instance_size = sizeof(S390CcwMachineState),
609     .instance_init = s390_machine_initfn,
610     .class_size = sizeof(S390CcwMachineClass),
611     .class_init    = ccw_machine_class_init,
612     .interfaces = (InterfaceInfo[]) {
613         { TYPE_NMI },
614         { TYPE_HOTPLUG_HANDLER},
615         { }
616     },
617 };
618 
619 bool css_migration_enabled(void)
620 {
621     return get_machine_class()->css_migration_enabled;
622 }
623 
624 #define DEFINE_CCW_MACHINE(suffix, verstr, latest)                            \
625     static void ccw_machine_##suffix##_class_init(ObjectClass *oc,            \
626                                                   void *data)                 \
627     {                                                                         \
628         MachineClass *mc = MACHINE_CLASS(oc);                                 \
629         ccw_machine_##suffix##_class_options(mc);                             \
630         mc->desc = "VirtIO-ccw based S390 machine v" verstr;                  \
631         if (latest) {                                                         \
632             mc->alias = "s390-ccw-virtio";                                    \
633             mc->is_default = true;                                            \
634         }                                                                     \
635     }                                                                         \
636     static void ccw_machine_##suffix##_instance_init(Object *obj)             \
637     {                                                                         \
638         MachineState *machine = MACHINE(obj);                                 \
639         current_mc = S390_MACHINE_CLASS(MACHINE_GET_CLASS(machine));          \
640         ccw_machine_##suffix##_instance_options(machine);                     \
641     }                                                                         \
642     static const TypeInfo ccw_machine_##suffix##_info = {                     \
643         .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr),                 \
644         .parent = TYPE_S390_CCW_MACHINE,                                      \
645         .class_init = ccw_machine_##suffix##_class_init,                      \
646         .instance_init = ccw_machine_##suffix##_instance_init,                \
647     };                                                                        \
648     static void ccw_machine_register_##suffix(void)                           \
649     {                                                                         \
650         type_register_static(&ccw_machine_##suffix##_info);                   \
651     }                                                                         \
652     type_init(ccw_machine_register_##suffix)
653 
654 static void ccw_machine_5_0_instance_options(MachineState *machine)
655 {
656 }
657 
658 static void ccw_machine_5_0_class_options(MachineClass *mc)
659 {
660 }
661 DEFINE_CCW_MACHINE(5_0, "5.0", true);
662 
663 static void ccw_machine_4_2_instance_options(MachineState *machine)
664 {
665     ccw_machine_5_0_instance_options(machine);
666 }
667 
668 static void ccw_machine_4_2_class_options(MachineClass *mc)
669 {
670     ccw_machine_5_0_class_options(mc);
671     compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
672 }
673 DEFINE_CCW_MACHINE(4_2, "4.2", false);
674 
675 static void ccw_machine_4_1_instance_options(MachineState *machine)
676 {
677     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
678     ccw_machine_4_2_instance_options(machine);
679     s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
680 }
681 
682 static void ccw_machine_4_1_class_options(MachineClass *mc)
683 {
684     ccw_machine_4_2_class_options(mc);
685     compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
686 }
687 DEFINE_CCW_MACHINE(4_1, "4.1", false);
688 
689 static void ccw_machine_4_0_instance_options(MachineState *machine)
690 {
691     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
692     ccw_machine_4_1_instance_options(machine);
693     s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
694 }
695 
696 static void ccw_machine_4_0_class_options(MachineClass *mc)
697 {
698     ccw_machine_4_1_class_options(mc);
699     compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
700 }
701 DEFINE_CCW_MACHINE(4_0, "4.0", false);
702 
703 static void ccw_machine_3_1_instance_options(MachineState *machine)
704 {
705     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
706     ccw_machine_4_0_instance_options(machine);
707     s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
708     s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
709     s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
710 }
711 
712 static void ccw_machine_3_1_class_options(MachineClass *mc)
713 {
714     ccw_machine_4_0_class_options(mc);
715     compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
716 }
717 DEFINE_CCW_MACHINE(3_1, "3.1", false);
718 
719 static void ccw_machine_3_0_instance_options(MachineState *machine)
720 {
721     ccw_machine_3_1_instance_options(machine);
722 }
723 
724 static void ccw_machine_3_0_class_options(MachineClass *mc)
725 {
726     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
727 
728     s390mc->hpage_1m_allowed = false;
729     ccw_machine_3_1_class_options(mc);
730     compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
731 }
732 DEFINE_CCW_MACHINE(3_0, "3.0", false);
733 
734 static void ccw_machine_2_12_instance_options(MachineState *machine)
735 {
736     ccw_machine_3_0_instance_options(machine);
737     s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
738     s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
739 }
740 
741 static void ccw_machine_2_12_class_options(MachineClass *mc)
742 {
743     ccw_machine_3_0_class_options(mc);
744     compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
745 }
746 DEFINE_CCW_MACHINE(2_12, "2.12", false);
747 
748 static void ccw_machine_2_11_instance_options(MachineState *machine)
749 {
750     static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
751     ccw_machine_2_12_instance_options(machine);
752 
753     /* before 2.12 we emulated the very first z900 */
754     s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
755 }
756 
757 static void ccw_machine_2_11_class_options(MachineClass *mc)
758 {
759     static GlobalProperty compat[] = {
760         { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
761     };
762 
763     ccw_machine_2_12_class_options(mc);
764     compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
765     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
766 }
767 DEFINE_CCW_MACHINE(2_11, "2.11", false);
768 
769 static void ccw_machine_2_10_instance_options(MachineState *machine)
770 {
771     ccw_machine_2_11_instance_options(machine);
772 }
773 
774 static void ccw_machine_2_10_class_options(MachineClass *mc)
775 {
776     ccw_machine_2_11_class_options(mc);
777     compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
778 }
779 DEFINE_CCW_MACHINE(2_10, "2.10", false);
780 
781 static void ccw_machine_2_9_instance_options(MachineState *machine)
782 {
783     ccw_machine_2_10_instance_options(machine);
784     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
785     s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
786     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
787     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
788     s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
789 }
790 
791 static void ccw_machine_2_9_class_options(MachineClass *mc)
792 {
793     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
794     static GlobalProperty compat[] = {
795         { TYPE_S390_STATTRIB, "migration-enabled", "off", },
796     };
797 
798     ccw_machine_2_10_class_options(mc);
799     compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
800     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
801     s390mc->css_migration_enabled = false;
802 }
803 DEFINE_CCW_MACHINE(2_9, "2.9", false);
804 
805 static void ccw_machine_2_8_instance_options(MachineState *machine)
806 {
807     ccw_machine_2_9_instance_options(machine);
808 }
809 
810 static void ccw_machine_2_8_class_options(MachineClass *mc)
811 {
812     static GlobalProperty compat[] = {
813         { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
814     };
815 
816     ccw_machine_2_9_class_options(mc);
817     compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
818     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
819 }
820 DEFINE_CCW_MACHINE(2_8, "2.8", false);
821 
822 static void ccw_machine_2_7_instance_options(MachineState *machine)
823 {
824     ccw_machine_2_8_instance_options(machine);
825 }
826 
827 static void ccw_machine_2_7_class_options(MachineClass *mc)
828 {
829     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
830 
831     s390mc->cpu_model_allowed = false;
832     ccw_machine_2_8_class_options(mc);
833     compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
834 }
835 DEFINE_CCW_MACHINE(2_7, "2.7", false);
836 
837 static void ccw_machine_2_6_instance_options(MachineState *machine)
838 {
839     ccw_machine_2_7_instance_options(machine);
840 }
841 
842 static void ccw_machine_2_6_class_options(MachineClass *mc)
843 {
844     S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
845     static GlobalProperty compat[] = {
846         { TYPE_S390_IPL, "iplbext_migration", "off", },
847          { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
848     };
849 
850     s390mc->ri_allowed = false;
851     ccw_machine_2_7_class_options(mc);
852     compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
853     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
854 }
855 DEFINE_CCW_MACHINE(2_6, "2.6", false);
856 
857 static void ccw_machine_2_5_instance_options(MachineState *machine)
858 {
859     ccw_machine_2_6_instance_options(machine);
860 }
861 
862 static void ccw_machine_2_5_class_options(MachineClass *mc)
863 {
864     ccw_machine_2_6_class_options(mc);
865     compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
866 }
867 DEFINE_CCW_MACHINE(2_5, "2.5", false);
868 
869 static void ccw_machine_2_4_instance_options(MachineState *machine)
870 {
871     ccw_machine_2_5_instance_options(machine);
872 }
873 
874 static void ccw_machine_2_4_class_options(MachineClass *mc)
875 {
876     static GlobalProperty compat[] = {
877         { TYPE_S390_SKEYS, "migration-enabled", "off", },
878         { "virtio-blk-ccw", "max_revision", "0", },
879         { "virtio-balloon-ccw", "max_revision", "0", },
880         { "virtio-serial-ccw", "max_revision", "0", },
881         { "virtio-9p-ccw", "max_revision", "0", },
882         { "virtio-rng-ccw", "max_revision", "0", },
883         { "virtio-net-ccw", "max_revision", "0", },
884         { "virtio-scsi-ccw", "max_revision", "0", },
885         { "vhost-scsi-ccw", "max_revision", "0", },
886     };
887 
888     ccw_machine_2_5_class_options(mc);
889     compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
890     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
891 }
892 DEFINE_CCW_MACHINE(2_4, "2.4", false);
893 
894 static void ccw_machine_register_types(void)
895 {
896     type_register_static(&ccw_machine_info);
897 }
898 
899 type_init(ccw_machine_register_types)
900