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