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>
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
14 #include "qemu/osdep.h"
15 #include "qapi/error.h"
17 #include "hw/boards.h"
18 #include "exec/address-spaces.h"
19 #include "exec/ram_addr.h"
20 #include "hw/boards.h"
21 #include "hw/s390x/s390-virtio-hcall.h"
22 #include "hw/s390x/sclp.h"
23 #include "hw/s390x/s390_flic.h"
24 #include "hw/s390x/ioinst.h"
25 #include "hw/s390x/css.h"
26 #include "virtio-ccw.h"
27 #include "qemu/config-file.h"
28 #include "qemu/ctype.h"
29 #include "qemu/error-report.h"
30 #include "qemu/option.h"
31 #include "qemu/qemu-print.h"
32 #include "hw/s390x/s390-pci-bus.h"
33 #include "sysemu/reset.h"
34 #include "hw/s390x/storage-keys.h"
35 #include "hw/s390x/storage-attributes.h"
36 #include "hw/s390x/event-facility.h"
38 #include "hw/s390x/s390-virtio-ccw.h"
39 #include "hw/s390x/css-bridge.h"
40 #include "hw/s390x/ap-bridge.h"
41 #include "migration/register.h"
42 #include "cpu_models.h"
44 #include "hw/qdev-properties.h"
45 #include "hw/s390x/tod.h"
46 #include "sysemu/sysemu.h"
47 #include "hw/s390x/pv.h"
48 #include "migration/blocker.h"
50 static Error
*pv_mig_blocker
;
52 S390CPU
*s390_cpu_addr2state(uint16_t cpu_addr
)
54 static MachineState
*ms
;
57 ms
= MACHINE(qdev_get_machine());
58 g_assert(ms
->possible_cpus
);
61 /* CPU address corresponds to the core_id and the index */
62 if (cpu_addr
>= ms
->possible_cpus
->len
) {
65 return S390_CPU(ms
->possible_cpus
->cpus
[cpu_addr
].cpu
);
68 static S390CPU
*s390x_new_cpu(const char *typename
, uint32_t core_id
,
71 S390CPU
*cpu
= S390_CPU(object_new(typename
));
74 if (!object_property_set_int(OBJECT(cpu
), "core-id", core_id
, errp
)) {
77 if (!qdev_realize(DEVICE(cpu
), NULL
, errp
)) {
83 object_unref(OBJECT(cpu
));
87 static void s390_init_cpus(MachineState
*machine
)
89 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
92 /* initialize possible_cpus */
93 mc
->possible_cpu_arch_ids(machine
);
95 for (i
= 0; i
< machine
->smp
.cpus
; i
++) {
96 s390x_new_cpu(machine
->cpu_type
, i
, &error_fatal
);
100 static const char *const reset_dev_types
[] = {
101 TYPE_VIRTUAL_CSS_BRIDGE
,
102 "s390-sclp-event-facility",
105 TYPE_S390_PCI_HOST_BRIDGE
,
108 static void subsystem_reset(void)
113 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
114 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
121 static int virtio_ccw_hcall_notify(const uint64_t *args
)
123 uint64_t subch_id
= args
[0];
124 uint64_t queue
= args
[1];
126 int cssid
, ssid
, schid
, m
;
128 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
131 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
132 if (!sch
|| !css_subch_visible(sch
)) {
135 if (queue
>= VIRTIO_QUEUE_MAX
) {
138 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
143 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
145 uint64_t mem
= args
[0];
146 MachineState
*ms
= MACHINE(qdev_get_machine());
148 if (mem
< ms
->ram_size
) {
155 static void virtio_ccw_register_hcalls(void)
157 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
158 virtio_ccw_hcall_notify
);
159 /* Tolerate early printk. */
160 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
161 virtio_ccw_hcall_early_printk
);
164 static void s390_memory_init(MemoryRegion
*ram
)
166 MemoryRegion
*sysmem
= get_system_memory();
168 /* allocate RAM for core */
169 memory_region_add_subregion(sysmem
, 0, ram
);
172 * Configure the maximum page size. As no memory devices were created
173 * yet, this is the page size of initial memory only.
175 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal
);
176 /* Initialize storage key device */
178 /* Initialize storage attributes device */
179 s390_stattrib_init();
182 static void s390_init_ipl_dev(const char *kernel_filename
,
183 const char *kernel_cmdline
,
184 const char *initrd_filename
, const char *firmware
,
185 const char *netboot_fw
, bool enforce_bios
)
187 Object
*new = object_new(TYPE_S390_IPL
);
188 DeviceState
*dev
= DEVICE(new);
189 char *netboot_fw_prop
;
191 if (kernel_filename
) {
192 qdev_prop_set_string(dev
, "kernel", kernel_filename
);
194 if (initrd_filename
) {
195 qdev_prop_set_string(dev
, "initrd", initrd_filename
);
197 qdev_prop_set_string(dev
, "cmdline", kernel_cmdline
);
198 qdev_prop_set_string(dev
, "firmware", firmware
);
199 qdev_prop_set_bit(dev
, "enforce_bios", enforce_bios
);
200 netboot_fw_prop
= object_property_get_str(new, "netboot_fw", &error_abort
);
201 if (!strlen(netboot_fw_prop
)) {
202 qdev_prop_set_string(dev
, "netboot_fw", netboot_fw
);
204 g_free(netboot_fw_prop
);
205 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL
,
208 qdev_realize(dev
, NULL
, &error_fatal
);
211 static void s390_create_virtio_net(BusState
*bus
, const char *name
)
215 for (i
= 0; i
< nb_nics
; i
++) {
216 NICInfo
*nd
= &nd_table
[i
];
220 nd
->model
= g_strdup("virtio");
223 qemu_check_nic_model(nd
, "virtio");
225 dev
= qdev_new(name
);
226 qdev_set_nic_properties(dev
, nd
);
227 qdev_realize_and_unref(dev
, bus
, &error_fatal
);
231 static void s390_create_sclpconsole(const char *type
, Chardev
*chardev
)
235 dev
= qdev_new(type
);
236 qdev_prop_set_chr(dev
, "chardev", chardev
);
237 qdev_realize_and_unref(dev
, sclp_get_event_facility_bus(), &error_fatal
);
240 static void ccw_init(MachineState
*machine
)
243 VirtualCssBus
*css_bus
;
247 /* init memory + setup max page size. Required for the CPU model */
248 s390_memory_init(machine
->ram
);
250 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
251 s390_init_cpus(machine
);
253 /* Need CPU model to be determined before we can set up PV */
254 s390_pv_init(machine
->cgs
, &error_fatal
);
258 /* init the SIGP facility */
261 /* create AP bridge and bus(es) */
265 css_bus
= virtual_css_bus_init();
266 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
267 machine
->initrd_filename
,
268 machine
->firmware
?: "s390-ccw.img",
269 "s390-netboot.img", true);
271 dev
= qdev_new(TYPE_S390_PCI_HOST_BRIDGE
);
272 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
274 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
276 /* register hypercalls */
277 virtio_ccw_register_hcalls();
279 s390_enable_css_support(s390_cpu_addr2state(0));
281 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
284 if (css_migration_enabled()) {
285 css_register_vmstate();
288 /* Create VirtIO network adapters */
289 s390_create_virtio_net(BUS(css_bus
), "virtio-net-ccw");
293 s390_create_sclpconsole("sclpconsole", serial_hd(0));
296 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
299 /* init the TOD clock */
303 static void s390_cpu_plug(HotplugHandler
*hotplug_dev
,
304 DeviceState
*dev
, Error
**errp
)
306 MachineState
*ms
= MACHINE(hotplug_dev
);
307 S390CPU
*cpu
= S390_CPU(dev
);
309 g_assert(!ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
);
310 ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
= OBJECT(dev
);
312 if (dev
->hotplugged
) {
313 raise_irq_cpu_hotplug();
317 static inline void s390_do_cpu_ipl(CPUState
*cs
, run_on_cpu_data arg
)
319 S390CPU
*cpu
= S390_CPU(cs
);
321 s390_ipl_prepare_cpu(cpu
);
322 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
325 static void s390_machine_unprotect(S390CcwMachineState
*ms
)
327 s390_pv_vm_disable();
329 migrate_del_blocker(pv_mig_blocker
);
330 error_free_or_abort(&pv_mig_blocker
);
331 ram_block_discard_disable(false);
334 static int s390_machine_protect(S390CcwMachineState
*ms
)
336 Error
*local_err
= NULL
;
340 * Discarding of memory in RAM blocks does not work as expected with
341 * protected VMs. Sharing and unsharing pages would be required. Disable
342 * it for now, until until we have a solution to make at least Linux
343 * guests either support it (e.g., virtio-balloon) or fail gracefully.
345 rc
= ram_block_discard_disable(true);
347 error_report("protected VMs: cannot disable RAM discard");
351 error_setg(&pv_mig_blocker
,
352 "protected VMs are currently not migrateable.");
353 rc
= migrate_add_blocker(pv_mig_blocker
, &local_err
);
355 ram_block_discard_disable(false);
356 error_report_err(local_err
);
357 error_free_or_abort(&pv_mig_blocker
);
362 rc
= s390_pv_vm_enable();
364 ram_block_discard_disable(false);
365 migrate_del_blocker(pv_mig_blocker
);
366 error_free_or_abort(&pv_mig_blocker
);
372 /* Set SE header and unpack */
373 rc
= s390_ipl_prepare_pv_header();
379 rc
= s390_ipl_pv_unpack();
384 /* Verify integrity */
385 rc
= s390_pv_verify();
392 s390_machine_unprotect(ms
);
396 static void s390_pv_prepare_reset(S390CcwMachineState
*ms
)
403 /* Unsharing requires all cpus to be stopped */
405 s390_cpu_set_state(S390_CPU_STATE_STOPPED
, S390_CPU(cs
));
408 s390_pv_prep_reset();
411 static void s390_machine_reset(MachineState
*machine
)
413 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
414 enum s390_reset reset_type
;
418 /* get the reset parameters, reset them once done */
419 s390_ipl_get_reset_request(&cs
, &reset_type
);
421 /* all CPUs are paused and synchronized at this point */
426 switch (reset_type
) {
427 case S390_RESET_EXTERNAL
:
428 case S390_RESET_REIPL
:
430 s390_machine_unprotect(ms
);
433 qemu_devices_reset();
436 /* configure and start the ipl CPU only */
437 run_on_cpu(cs
, s390_do_cpu_ipl
, RUN_ON_CPU_NULL
);
439 case S390_RESET_MODIFIED_CLEAR
:
441 * Susbsystem reset needs to be done before we unshare memory
442 * and lose access to VIRTIO structures in guest memory.
446 s390_pv_prepare_reset(ms
);
448 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
450 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
452 case S390_RESET_LOAD_NORMAL
:
454 * Susbsystem reset needs to be done before we unshare memory
455 * and lose access to VIRTIO structures in guest memory.
458 s390_pv_prepare_reset(ms
);
463 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
465 run_on_cpu(cs
, s390_do_cpu_initial_reset
, RUN_ON_CPU_NULL
);
466 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
468 case S390_RESET_PV
: /* Subcode 10 */
476 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
478 run_on_cpu(cs
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
480 if (s390_machine_protect(ms
)) {
481 s390_pv_inject_reset_error(cs
);
483 * Continue after the diag308 so the guest knows something
486 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
490 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
493 g_assert_not_reached();
497 run_on_cpu(t
, s390_do_cpu_set_diag318
, RUN_ON_CPU_HOST_ULONG(0));
499 s390_ipl_clear_reset_request();
502 static void s390_machine_device_plug(HotplugHandler
*hotplug_dev
,
503 DeviceState
*dev
, Error
**errp
)
505 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
506 s390_cpu_plug(hotplug_dev
, dev
, errp
);
510 static void s390_machine_device_unplug_request(HotplugHandler
*hotplug_dev
,
511 DeviceState
*dev
, Error
**errp
)
513 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
514 error_setg(errp
, "CPU hot unplug not supported on this machine");
519 static CpuInstanceProperties
s390_cpu_index_to_props(MachineState
*ms
,
522 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
523 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
525 assert(cpu_index
< possible_cpus
->len
);
526 return possible_cpus
->cpus
[cpu_index
].props
;
529 static const CPUArchIdList
*s390_possible_cpu_arch_ids(MachineState
*ms
)
532 unsigned int max_cpus
= ms
->smp
.max_cpus
;
534 if (ms
->possible_cpus
) {
535 g_assert(ms
->possible_cpus
&& ms
->possible_cpus
->len
== max_cpus
);
536 return ms
->possible_cpus
;
539 ms
->possible_cpus
= g_malloc0(sizeof(CPUArchIdList
) +
540 sizeof(CPUArchId
) * max_cpus
);
541 ms
->possible_cpus
->len
= max_cpus
;
542 for (i
= 0; i
< ms
->possible_cpus
->len
; i
++) {
543 ms
->possible_cpus
->cpus
[i
].type
= ms
->cpu_type
;
544 ms
->possible_cpus
->cpus
[i
].vcpus_count
= 1;
545 ms
->possible_cpus
->cpus
[i
].arch_id
= i
;
546 ms
->possible_cpus
->cpus
[i
].props
.has_core_id
= true;
547 ms
->possible_cpus
->cpus
[i
].props
.core_id
= i
;
550 return ms
->possible_cpus
;
553 static HotplugHandler
*s390_get_hotplug_handler(MachineState
*machine
,
556 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
557 return HOTPLUG_HANDLER(machine
);
562 static void s390_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
564 CPUState
*cs
= qemu_get_cpu(cpu_index
);
566 s390_cpu_restart(S390_CPU(cs
));
569 static ram_addr_t
s390_fixup_ram_size(ram_addr_t sz
)
571 /* same logic as in sclp.c */
572 int increment_size
= 20;
575 while ((sz
>> increment_size
) > MAX_STORAGE_INCREMENTS
) {
578 newsz
= sz
>> increment_size
<< increment_size
;
581 qemu_printf("Ram size %" PRIu64
"MB was fixed up to %" PRIu64
582 "MB to match machine restrictions. Consider updating "
583 "the guest definition.\n", (uint64_t) (sz
/ MiB
),
584 (uint64_t) (newsz
/ MiB
));
589 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
591 MachineClass
*mc
= MACHINE_CLASS(oc
);
592 NMIClass
*nc
= NMI_CLASS(oc
);
593 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
594 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
596 s390mc
->ri_allowed
= true;
597 s390mc
->cpu_model_allowed
= true;
598 s390mc
->css_migration_enabled
= true;
599 s390mc
->hpage_1m_allowed
= true;
601 mc
->reset
= s390_machine_reset
;
602 mc
->block_default_type
= IF_VIRTIO
;
607 mc
->max_cpus
= S390_MAX_CPUS
;
608 mc
->has_hotpluggable_cpus
= true;
609 assert(!mc
->get_hotplug_handler
);
610 mc
->get_hotplug_handler
= s390_get_hotplug_handler
;
611 mc
->cpu_index_to_instance_props
= s390_cpu_index_to_props
;
612 mc
->possible_cpu_arch_ids
= s390_possible_cpu_arch_ids
;
613 /* it is overridden with 'host' cpu *in kvm_arch_init* */
614 mc
->default_cpu_type
= S390_CPU_TYPE_NAME("qemu");
615 hc
->plug
= s390_machine_device_plug
;
616 hc
->unplug_request
= s390_machine_device_unplug_request
;
617 nc
->nmi_monitor_handler
= s390_nmi
;
618 mc
->default_ram_id
= "s390.ram";
621 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
623 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
625 return ms
->aes_key_wrap
;
628 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
631 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
633 ms
->aes_key_wrap
= value
;
636 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
638 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
640 return ms
->dea_key_wrap
;
643 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
646 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
648 ms
->dea_key_wrap
= value
;
651 static S390CcwMachineClass
*current_mc
;
654 * Get the class of the s390-ccw-virtio machine that is currently in use.
655 * Note: libvirt is using the "none" machine to probe for the features of the
656 * host CPU, so in case this is called with the "none" machine, the function
657 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
658 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
659 * below return the correct default value for the "none" machine.
661 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
662 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
663 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
664 * CPU initialization and s390_has_feat() later should be sufficient.
666 static S390CcwMachineClass
*get_machine_class(void)
668 if (unlikely(!current_mc
)) {
670 * No s390 ccw machine was instantiated, we are likely to
671 * be called for the 'none' machine. The properties will
672 * have their after-initialization values.
674 current_mc
= S390_CCW_MACHINE_CLASS(
675 object_class_by_name(TYPE_S390_CCW_MACHINE
));
680 bool ri_allowed(void)
682 return get_machine_class()->ri_allowed
;
685 bool cpu_model_allowed(void)
687 return get_machine_class()->cpu_model_allowed
;
690 bool hpage_1m_allowed(void)
692 return get_machine_class()->hpage_1m_allowed
;
695 static char *machine_get_loadparm(Object
*obj
, Error
**errp
)
697 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
699 /* make a NUL-terminated string */
700 return g_strndup((char *) ms
->loadparm
, sizeof(ms
->loadparm
));
703 static void machine_set_loadparm(Object
*obj
, const char *val
, Error
**errp
)
705 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
708 for (i
= 0; i
< sizeof(ms
->loadparm
) && val
[i
]; i
++) {
709 uint8_t c
= qemu_toupper(val
[i
]); /* mimic HMC */
711 if (('A' <= c
&& c
<= 'Z') || ('0' <= c
&& c
<= '9') || (c
== '.') ||
715 error_setg(errp
, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
721 for (; i
< sizeof(ms
->loadparm
); i
++) {
722 ms
->loadparm
[i
] = ' '; /* pad right with spaces */
725 static inline void s390_machine_initfn(Object
*obj
)
727 object_property_add_bool(obj
, "aes-key-wrap",
728 machine_get_aes_key_wrap
,
729 machine_set_aes_key_wrap
);
730 object_property_set_description(obj
, "aes-key-wrap",
731 "enable/disable AES key wrapping using the CPACF wrapping key");
732 object_property_set_bool(obj
, "aes-key-wrap", true, NULL
);
734 object_property_add_bool(obj
, "dea-key-wrap",
735 machine_get_dea_key_wrap
,
736 machine_set_dea_key_wrap
);
737 object_property_set_description(obj
, "dea-key-wrap",
738 "enable/disable DEA key wrapping using the CPACF wrapping key");
739 object_property_set_bool(obj
, "dea-key-wrap", true, NULL
);
740 object_property_add_str(obj
, "loadparm",
741 machine_get_loadparm
, machine_set_loadparm
);
742 object_property_set_description(obj
, "loadparm",
743 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
744 " to upper case) to pass to machine loader, boot manager,"
745 " and guest kernel");
748 static const TypeInfo ccw_machine_info
= {
749 .name
= TYPE_S390_CCW_MACHINE
,
750 .parent
= TYPE_MACHINE
,
752 .instance_size
= sizeof(S390CcwMachineState
),
753 .instance_init
= s390_machine_initfn
,
754 .class_size
= sizeof(S390CcwMachineClass
),
755 .class_init
= ccw_machine_class_init
,
756 .interfaces
= (InterfaceInfo
[]) {
758 { TYPE_HOTPLUG_HANDLER
},
763 bool css_migration_enabled(void)
765 return get_machine_class()->css_migration_enabled
;
768 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
769 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
772 MachineClass *mc = MACHINE_CLASS(oc); \
773 ccw_machine_##suffix##_class_options(mc); \
774 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
776 mc->alias = "s390-ccw-virtio"; \
777 mc->is_default = true; \
780 static void ccw_machine_##suffix##_instance_init(Object *obj) \
782 MachineState *machine = MACHINE(obj); \
783 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
784 ccw_machine_##suffix##_instance_options(machine); \
786 static const TypeInfo ccw_machine_##suffix##_info = { \
787 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
788 .parent = TYPE_S390_CCW_MACHINE, \
789 .class_init = ccw_machine_##suffix##_class_init, \
790 .instance_init = ccw_machine_##suffix##_instance_init, \
792 static void ccw_machine_register_##suffix(void) \
794 type_register_static(&ccw_machine_##suffix##_info); \
796 type_init(ccw_machine_register_##suffix)
798 static void ccw_machine_6_0_instance_options(MachineState
*machine
)
802 static void ccw_machine_6_0_class_options(MachineClass
*mc
)
805 DEFINE_CCW_MACHINE(6_0
, "6.0", true);
807 static void ccw_machine_5_2_instance_options(MachineState
*machine
)
809 ccw_machine_6_0_instance_options(machine
);
812 static void ccw_machine_5_2_class_options(MachineClass
*mc
)
814 ccw_machine_6_0_class_options(mc
);
815 compat_props_add(mc
->compat_props
, hw_compat_5_2
, hw_compat_5_2_len
);
817 DEFINE_CCW_MACHINE(5_2
, "5.2", false);
819 static void ccw_machine_5_1_instance_options(MachineState
*machine
)
821 ccw_machine_5_2_instance_options(machine
);
824 static void ccw_machine_5_1_class_options(MachineClass
*mc
)
826 ccw_machine_5_2_class_options(mc
);
827 compat_props_add(mc
->compat_props
, hw_compat_5_1
, hw_compat_5_1_len
);
829 DEFINE_CCW_MACHINE(5_1
, "5.1", false);
831 static void ccw_machine_5_0_instance_options(MachineState
*machine
)
833 ccw_machine_5_1_instance_options(machine
);
836 static void ccw_machine_5_0_class_options(MachineClass
*mc
)
838 ccw_machine_5_1_class_options(mc
);
839 compat_props_add(mc
->compat_props
, hw_compat_5_0
, hw_compat_5_0_len
);
841 DEFINE_CCW_MACHINE(5_0
, "5.0", false);
843 static void ccw_machine_4_2_instance_options(MachineState
*machine
)
845 ccw_machine_5_0_instance_options(machine
);
848 static void ccw_machine_4_2_class_options(MachineClass
*mc
)
850 ccw_machine_5_0_class_options(mc
);
851 mc
->fixup_ram_size
= s390_fixup_ram_size
;
852 compat_props_add(mc
->compat_props
, hw_compat_4_2
, hw_compat_4_2_len
);
854 DEFINE_CCW_MACHINE(4_2
, "4.2", false);
856 static void ccw_machine_4_1_instance_options(MachineState
*machine
)
858 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_1
};
859 ccw_machine_4_2_instance_options(machine
);
860 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
863 static void ccw_machine_4_1_class_options(MachineClass
*mc
)
865 ccw_machine_4_2_class_options(mc
);
866 compat_props_add(mc
->compat_props
, hw_compat_4_1
, hw_compat_4_1_len
);
868 DEFINE_CCW_MACHINE(4_1
, "4.1", false);
870 static void ccw_machine_4_0_instance_options(MachineState
*machine
)
872 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_0
};
873 ccw_machine_4_1_instance_options(machine
);
874 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
877 static void ccw_machine_4_0_class_options(MachineClass
*mc
)
879 ccw_machine_4_1_class_options(mc
);
880 compat_props_add(mc
->compat_props
, hw_compat_4_0
, hw_compat_4_0_len
);
882 DEFINE_CCW_MACHINE(4_0
, "4.0", false);
884 static void ccw_machine_3_1_instance_options(MachineState
*machine
)
886 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V3_1
};
887 ccw_machine_4_0_instance_options(machine
);
888 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH
);
889 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF
);
890 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
893 static void ccw_machine_3_1_class_options(MachineClass
*mc
)
895 ccw_machine_4_0_class_options(mc
);
896 compat_props_add(mc
->compat_props
, hw_compat_3_1
, hw_compat_3_1_len
);
898 DEFINE_CCW_MACHINE(3_1
, "3.1", false);
900 static void ccw_machine_3_0_instance_options(MachineState
*machine
)
902 ccw_machine_3_1_instance_options(machine
);
905 static void ccw_machine_3_0_class_options(MachineClass
*mc
)
907 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
909 s390mc
->hpage_1m_allowed
= false;
910 ccw_machine_3_1_class_options(mc
);
911 compat_props_add(mc
->compat_props
, hw_compat_3_0
, hw_compat_3_0_len
);
913 DEFINE_CCW_MACHINE(3_0
, "3.0", false);
915 static void ccw_machine_2_12_instance_options(MachineState
*machine
)
917 ccw_machine_3_0_instance_options(machine
);
918 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15
);
919 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB
);
922 static void ccw_machine_2_12_class_options(MachineClass
*mc
)
924 ccw_machine_3_0_class_options(mc
);
925 compat_props_add(mc
->compat_props
, hw_compat_2_12
, hw_compat_2_12_len
);
927 DEFINE_CCW_MACHINE(2_12
, "2.12", false);
929 static void ccw_machine_2_11_instance_options(MachineState
*machine
)
931 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V2_11
};
932 ccw_machine_2_12_instance_options(machine
);
934 /* before 2.12 we emulated the very first z900 */
935 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat
);
938 static void ccw_machine_2_11_class_options(MachineClass
*mc
)
940 static GlobalProperty compat
[] = {
941 { TYPE_SCLP_EVENT_FACILITY
, "allow_all_mask_sizes", "off", },
944 ccw_machine_2_12_class_options(mc
);
945 compat_props_add(mc
->compat_props
, hw_compat_2_11
, hw_compat_2_11_len
);
946 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
948 DEFINE_CCW_MACHINE(2_11
, "2.11", false);
950 static void ccw_machine_2_10_instance_options(MachineState
*machine
)
952 ccw_machine_2_11_instance_options(machine
);
955 static void ccw_machine_2_10_class_options(MachineClass
*mc
)
957 ccw_machine_2_11_class_options(mc
);
958 compat_props_add(mc
->compat_props
, hw_compat_2_10
, hw_compat_2_10_len
);
960 DEFINE_CCW_MACHINE(2_10
, "2.10", false);
962 static void ccw_machine_2_9_instance_options(MachineState
*machine
)
964 ccw_machine_2_10_instance_options(machine
);
965 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP
);
966 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2
);
967 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI
);
968 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION
);
969 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION
);
972 static void ccw_machine_2_9_class_options(MachineClass
*mc
)
974 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
975 static GlobalProperty compat
[] = {
976 { TYPE_S390_STATTRIB
, "migration-enabled", "off", },
979 ccw_machine_2_10_class_options(mc
);
980 compat_props_add(mc
->compat_props
, hw_compat_2_9
, hw_compat_2_9_len
);
981 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
982 s390mc
->css_migration_enabled
= false;
984 DEFINE_CCW_MACHINE(2_9
, "2.9", false);
986 static void ccw_machine_2_8_instance_options(MachineState
*machine
)
988 ccw_machine_2_9_instance_options(machine
);
991 static void ccw_machine_2_8_class_options(MachineClass
*mc
)
993 static GlobalProperty compat
[] = {
994 { TYPE_S390_FLIC_COMMON
, "adapter_routes_max_batch", "64", },
997 ccw_machine_2_9_class_options(mc
);
998 compat_props_add(mc
->compat_props
, hw_compat_2_8
, hw_compat_2_8_len
);
999 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1001 DEFINE_CCW_MACHINE(2_8
, "2.8", false);
1003 static void ccw_machine_2_7_instance_options(MachineState
*machine
)
1005 ccw_machine_2_8_instance_options(machine
);
1008 static void ccw_machine_2_7_class_options(MachineClass
*mc
)
1010 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1012 s390mc
->cpu_model_allowed
= false;
1013 ccw_machine_2_8_class_options(mc
);
1014 compat_props_add(mc
->compat_props
, hw_compat_2_7
, hw_compat_2_7_len
);
1016 DEFINE_CCW_MACHINE(2_7
, "2.7", false);
1018 static void ccw_machine_2_6_instance_options(MachineState
*machine
)
1020 ccw_machine_2_7_instance_options(machine
);
1023 static void ccw_machine_2_6_class_options(MachineClass
*mc
)
1025 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1026 static GlobalProperty compat
[] = {
1027 { TYPE_S390_IPL
, "iplbext_migration", "off", },
1028 { TYPE_VIRTUAL_CSS_BRIDGE
, "css_dev_path", "off", },
1031 s390mc
->ri_allowed
= false;
1032 ccw_machine_2_7_class_options(mc
);
1033 compat_props_add(mc
->compat_props
, hw_compat_2_6
, hw_compat_2_6_len
);
1034 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1036 DEFINE_CCW_MACHINE(2_6
, "2.6", false);
1038 static void ccw_machine_2_5_instance_options(MachineState
*machine
)
1040 ccw_machine_2_6_instance_options(machine
);
1043 static void ccw_machine_2_5_class_options(MachineClass
*mc
)
1045 ccw_machine_2_6_class_options(mc
);
1046 compat_props_add(mc
->compat_props
, hw_compat_2_5
, hw_compat_2_5_len
);
1048 DEFINE_CCW_MACHINE(2_5
, "2.5", false);
1050 static void ccw_machine_2_4_instance_options(MachineState
*machine
)
1052 ccw_machine_2_5_instance_options(machine
);
1055 static void ccw_machine_2_4_class_options(MachineClass
*mc
)
1057 static GlobalProperty compat
[] = {
1058 { TYPE_S390_SKEYS
, "migration-enabled", "off", },
1059 { "virtio-blk-ccw", "max_revision", "0", },
1060 { "virtio-balloon-ccw", "max_revision", "0", },
1061 { "virtio-serial-ccw", "max_revision", "0", },
1062 { "virtio-9p-ccw", "max_revision", "0", },
1063 { "virtio-rng-ccw", "max_revision", "0", },
1064 { "virtio-net-ccw", "max_revision", "0", },
1065 { "virtio-scsi-ccw", "max_revision", "0", },
1066 { "vhost-scsi-ccw", "max_revision", "0", },
1069 ccw_machine_2_5_class_options(mc
);
1070 compat_props_add(mc
->compat_props
, hw_compat_2_4
, hw_compat_2_4_len
);
1071 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1073 DEFINE_CCW_MACHINE(2_4
, "2.4", false);
1075 static void ccw_machine_register_types(void)
1077 type_register_static(&ccw_machine_info
);
1080 type_init(ccw_machine_register_types
)