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"
16 #include "exec/ram_addr.h"
17 #include "hw/s390x/s390-virtio-hcall.h"
18 #include "hw/s390x/sclp.h"
19 #include "hw/s390x/s390_flic.h"
20 #include "hw/s390x/ioinst.h"
21 #include "hw/s390x/css.h"
22 #include "virtio-ccw.h"
23 #include "qemu/config-file.h"
24 #include "qemu/ctype.h"
25 #include "qemu/error-report.h"
26 #include "qemu/option.h"
27 #include "qemu/qemu-print.h"
28 #include "qemu/units.h"
29 #include "hw/s390x/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"
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"
41 #include "hw/qdev-properties.h"
42 #include "hw/s390x/tod.h"
43 #include "sysemu/sysemu.h"
44 #include "sysemu/cpus.h"
45 #include "hw/s390x/pv.h"
46 #include "migration/blocker.h"
47 #include "qapi/visitor.h"
49 static Error
*pv_mig_blocker
;
51 S390CPU
*s390_cpu_addr2state(uint16_t cpu_addr
)
53 static MachineState
*ms
;
56 ms
= MACHINE(qdev_get_machine());
57 g_assert(ms
->possible_cpus
);
60 /* CPU address corresponds to the core_id and the index */
61 if (cpu_addr
>= ms
->possible_cpus
->len
) {
64 return S390_CPU(ms
->possible_cpus
->cpus
[cpu_addr
].cpu
);
67 static S390CPU
*s390x_new_cpu(const char *typename
, uint32_t core_id
,
70 S390CPU
*cpu
= S390_CPU(object_new(typename
));
73 if (!object_property_set_int(OBJECT(cpu
), "core-id", core_id
, errp
)) {
76 if (!qdev_realize(DEVICE(cpu
), NULL
, errp
)) {
82 object_unref(OBJECT(cpu
));
86 static void s390_init_cpus(MachineState
*machine
)
88 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
89 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
92 if (machine
->smp
.threads
> s390mc
->max_threads
) {
93 error_report("S390 does not support more than %d threads.",
98 /* initialize possible_cpus */
99 mc
->possible_cpu_arch_ids(machine
);
101 for (i
= 0; i
< machine
->smp
.cpus
; i
++) {
102 s390x_new_cpu(machine
->cpu_type
, i
, &error_fatal
);
106 static const char *const reset_dev_types
[] = {
107 TYPE_VIRTUAL_CSS_BRIDGE
,
108 "s390-sclp-event-facility",
111 TYPE_S390_PCI_HOST_BRIDGE
,
114 static void subsystem_reset(void)
119 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
120 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
122 device_cold_reset(dev
);
127 static int virtio_ccw_hcall_notify(const uint64_t *args
)
129 uint64_t subch_id
= args
[0];
130 uint64_t queue
= args
[1];
132 int cssid
, ssid
, schid
, m
;
134 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
137 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
138 if (!sch
|| !css_subch_visible(sch
)) {
141 if (queue
>= VIRTIO_QUEUE_MAX
) {
144 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
149 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
151 uint64_t mem
= args
[0];
152 MachineState
*ms
= MACHINE(qdev_get_machine());
154 if (mem
< ms
->ram_size
) {
161 static void virtio_ccw_register_hcalls(void)
163 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
164 virtio_ccw_hcall_notify
);
165 /* Tolerate early printk. */
166 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
167 virtio_ccw_hcall_early_printk
);
170 static void s390_memory_init(MemoryRegion
*ram
)
172 MemoryRegion
*sysmem
= get_system_memory();
174 /* allocate RAM for core */
175 memory_region_add_subregion(sysmem
, 0, ram
);
178 * Configure the maximum page size. As no memory devices were created
179 * yet, this is the page size of initial memory only.
181 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal
);
182 /* Initialize storage key device */
184 /* Initialize storage attributes device */
185 s390_stattrib_init();
188 static void s390_init_ipl_dev(const char *kernel_filename
,
189 const char *kernel_cmdline
,
190 const char *initrd_filename
, const char *firmware
,
191 const char *netboot_fw
, bool enforce_bios
)
193 Object
*new = object_new(TYPE_S390_IPL
);
194 DeviceState
*dev
= DEVICE(new);
195 char *netboot_fw_prop
;
197 if (kernel_filename
) {
198 qdev_prop_set_string(dev
, "kernel", kernel_filename
);
200 if (initrd_filename
) {
201 qdev_prop_set_string(dev
, "initrd", initrd_filename
);
203 qdev_prop_set_string(dev
, "cmdline", kernel_cmdline
);
204 qdev_prop_set_string(dev
, "firmware", firmware
);
205 qdev_prop_set_bit(dev
, "enforce_bios", enforce_bios
);
206 netboot_fw_prop
= object_property_get_str(new, "netboot_fw", &error_abort
);
207 if (!strlen(netboot_fw_prop
)) {
208 qdev_prop_set_string(dev
, "netboot_fw", netboot_fw
);
210 g_free(netboot_fw_prop
);
211 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL
,
214 qdev_realize(dev
, NULL
, &error_fatal
);
217 static void s390_create_virtio_net(BusState
*bus
, const char *name
)
221 for (i
= 0; i
< nb_nics
; i
++) {
222 NICInfo
*nd
= &nd_table
[i
];
226 nd
->model
= g_strdup("virtio");
229 qemu_check_nic_model(nd
, "virtio");
231 dev
= qdev_new(name
);
232 qdev_set_nic_properties(dev
, nd
);
233 qdev_realize_and_unref(dev
, bus
, &error_fatal
);
237 static void s390_create_sclpconsole(const char *type
, Chardev
*chardev
)
241 dev
= qdev_new(type
);
242 qdev_prop_set_chr(dev
, "chardev", chardev
);
243 qdev_realize_and_unref(dev
, sclp_get_event_facility_bus(), &error_fatal
);
246 static void ccw_init(MachineState
*machine
)
249 VirtualCssBus
*css_bus
;
253 /* init memory + setup max page size. Required for the CPU model */
254 s390_memory_init(machine
->ram
);
256 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
257 s390_init_cpus(machine
);
259 /* Need CPU model to be determined before we can set up PV */
260 s390_pv_init(machine
->cgs
, &error_fatal
);
264 /* init the SIGP facility */
267 /* create AP bridge and bus(es) */
271 css_bus
= virtual_css_bus_init();
272 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
273 machine
->initrd_filename
,
274 machine
->firmware
?: "s390-ccw.img",
275 "s390-netboot.img", true);
277 dev
= qdev_new(TYPE_S390_PCI_HOST_BRIDGE
);
278 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
280 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
282 /* register hypercalls */
283 virtio_ccw_register_hcalls();
285 s390_enable_css_support(s390_cpu_addr2state(0));
287 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
290 if (css_migration_enabled()) {
291 css_register_vmstate();
294 /* Create VirtIO network adapters */
295 s390_create_virtio_net(BUS(css_bus
), "virtio-net-ccw");
299 s390_create_sclpconsole("sclpconsole", serial_hd(0));
302 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
305 /* init the TOD clock */
309 static void s390_cpu_plug(HotplugHandler
*hotplug_dev
,
310 DeviceState
*dev
, Error
**errp
)
312 MachineState
*ms
= MACHINE(hotplug_dev
);
313 S390CPU
*cpu
= S390_CPU(dev
);
315 g_assert(!ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
);
316 ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
= OBJECT(dev
);
318 if (dev
->hotplugged
) {
319 raise_irq_cpu_hotplug();
323 static inline void s390_do_cpu_ipl(CPUState
*cs
, run_on_cpu_data arg
)
325 S390CPU
*cpu
= S390_CPU(cs
);
327 s390_ipl_prepare_cpu(cpu
);
328 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
331 static void s390_machine_unprotect(S390CcwMachineState
*ms
)
333 if (!s390_pv_vm_try_disable_async()) {
334 s390_pv_vm_disable();
337 migrate_del_blocker(pv_mig_blocker
);
338 error_free_or_abort(&pv_mig_blocker
);
339 ram_block_discard_disable(false);
342 static int s390_machine_protect(S390CcwMachineState
*ms
)
344 Error
*local_err
= NULL
;
348 * Discarding of memory in RAM blocks does not work as expected with
349 * protected VMs. Sharing and unsharing pages would be required. Disable
350 * it for now, until until we have a solution to make at least Linux
351 * guests either support it (e.g., virtio-balloon) or fail gracefully.
353 rc
= ram_block_discard_disable(true);
355 error_report("protected VMs: cannot disable RAM discard");
359 error_setg(&pv_mig_blocker
,
360 "protected VMs are currently not migratable.");
361 rc
= migrate_add_blocker(pv_mig_blocker
, &local_err
);
363 ram_block_discard_disable(false);
364 error_report_err(local_err
);
365 error_free_or_abort(&pv_mig_blocker
);
370 rc
= s390_pv_vm_enable();
372 ram_block_discard_disable(false);
373 migrate_del_blocker(pv_mig_blocker
);
374 error_free_or_abort(&pv_mig_blocker
);
380 /* Will return 0 if API is not available since it's not vital */
381 rc
= s390_pv_query_info();
386 /* Set SE header and unpack */
387 rc
= s390_ipl_prepare_pv_header();
393 rc
= s390_ipl_pv_unpack();
398 /* Verify integrity */
399 rc
= s390_pv_verify();
406 s390_machine_unprotect(ms
);
410 static void s390_pv_prepare_reset(S390CcwMachineState
*ms
)
417 /* Unsharing requires all cpus to be stopped */
419 s390_cpu_set_state(S390_CPU_STATE_STOPPED
, S390_CPU(cs
));
422 s390_pv_prep_reset();
425 static void s390_machine_reset(MachineState
*machine
, ShutdownCause reason
)
427 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
428 enum s390_reset reset_type
;
432 /* get the reset parameters, reset them once done */
433 s390_ipl_get_reset_request(&cs
, &reset_type
);
435 /* all CPUs are paused and synchronized at this point */
440 switch (reset_type
) {
441 case S390_RESET_EXTERNAL
:
442 case S390_RESET_REIPL
:
444 s390_machine_unprotect(ms
);
447 qemu_devices_reset(reason
);
450 /* configure and start the ipl CPU only */
451 run_on_cpu(cs
, s390_do_cpu_ipl
, RUN_ON_CPU_NULL
);
453 case S390_RESET_MODIFIED_CLEAR
:
455 * Subsystem reset needs to be done before we unshare memory
456 * and lose access to VIRTIO structures in guest memory.
460 s390_pv_prepare_reset(ms
);
462 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
464 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
466 case S390_RESET_LOAD_NORMAL
:
468 * Subsystem reset needs to be done before we unshare memory
469 * and lose access to VIRTIO structures in guest memory.
472 s390_pv_prepare_reset(ms
);
477 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
479 run_on_cpu(cs
, s390_do_cpu_initial_reset
, RUN_ON_CPU_NULL
);
480 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
482 case S390_RESET_PV
: /* Subcode 10 */
490 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
492 run_on_cpu(cs
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
494 if (s390_machine_protect(ms
)) {
495 s390_pv_inject_reset_error(cs
);
497 * Continue after the diag308 so the guest knows something
500 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
504 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
507 g_assert_not_reached();
511 run_on_cpu(t
, s390_do_cpu_set_diag318
, RUN_ON_CPU_HOST_ULONG(0));
513 s390_ipl_clear_reset_request();
516 static void s390_machine_device_plug(HotplugHandler
*hotplug_dev
,
517 DeviceState
*dev
, Error
**errp
)
519 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
520 s390_cpu_plug(hotplug_dev
, dev
, errp
);
524 static void s390_machine_device_unplug_request(HotplugHandler
*hotplug_dev
,
525 DeviceState
*dev
, Error
**errp
)
527 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
528 error_setg(errp
, "CPU hot unplug not supported on this machine");
533 static CpuInstanceProperties
s390_cpu_index_to_props(MachineState
*ms
,
536 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
537 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
539 assert(cpu_index
< possible_cpus
->len
);
540 return possible_cpus
->cpus
[cpu_index
].props
;
543 static const CPUArchIdList
*s390_possible_cpu_arch_ids(MachineState
*ms
)
546 unsigned int max_cpus
= ms
->smp
.max_cpus
;
548 if (ms
->possible_cpus
) {
549 g_assert(ms
->possible_cpus
&& ms
->possible_cpus
->len
== max_cpus
);
550 return ms
->possible_cpus
;
553 ms
->possible_cpus
= g_malloc0(sizeof(CPUArchIdList
) +
554 sizeof(CPUArchId
) * max_cpus
);
555 ms
->possible_cpus
->len
= max_cpus
;
556 for (i
= 0; i
< ms
->possible_cpus
->len
; i
++) {
557 ms
->possible_cpus
->cpus
[i
].type
= ms
->cpu_type
;
558 ms
->possible_cpus
->cpus
[i
].vcpus_count
= 1;
559 ms
->possible_cpus
->cpus
[i
].arch_id
= i
;
560 ms
->possible_cpus
->cpus
[i
].props
.has_core_id
= true;
561 ms
->possible_cpus
->cpus
[i
].props
.core_id
= i
;
564 return ms
->possible_cpus
;
567 static HotplugHandler
*s390_get_hotplug_handler(MachineState
*machine
,
570 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
571 return HOTPLUG_HANDLER(machine
);
576 static void s390_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
578 CPUState
*cs
= qemu_get_cpu(cpu_index
);
580 s390_cpu_restart(S390_CPU(cs
));
583 static ram_addr_t
s390_fixup_ram_size(ram_addr_t sz
)
585 /* same logic as in sclp.c */
586 int increment_size
= 20;
589 while ((sz
>> increment_size
) > MAX_STORAGE_INCREMENTS
) {
592 newsz
= sz
>> increment_size
<< increment_size
;
595 qemu_printf("Ram size %" PRIu64
"MB was fixed up to %" PRIu64
596 "MB to match machine restrictions. Consider updating "
597 "the guest definition.\n", (uint64_t) (sz
/ MiB
),
598 (uint64_t) (newsz
/ MiB
));
603 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
605 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
607 return ms
->aes_key_wrap
;
610 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
613 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
615 ms
->aes_key_wrap
= value
;
618 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
620 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
622 return ms
->dea_key_wrap
;
625 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
628 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
630 ms
->dea_key_wrap
= value
;
633 static S390CcwMachineClass
*current_mc
;
636 * Get the class of the s390-ccw-virtio machine that is currently in use.
637 * Note: libvirt is using the "none" machine to probe for the features of the
638 * host CPU, so in case this is called with the "none" machine, the function
639 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
640 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
641 * below return the correct default value for the "none" machine.
643 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
644 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
645 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
646 * CPU initialization and s390_has_feat() later should be sufficient.
648 static S390CcwMachineClass
*get_machine_class(void)
650 if (unlikely(!current_mc
)) {
652 * No s390 ccw machine was instantiated, we are likely to
653 * be called for the 'none' machine. The properties will
654 * have their after-initialization values.
656 current_mc
= S390_CCW_MACHINE_CLASS(
657 object_class_by_name(TYPE_S390_CCW_MACHINE
));
662 bool ri_allowed(void)
664 return get_machine_class()->ri_allowed
;
667 bool cpu_model_allowed(void)
669 return get_machine_class()->cpu_model_allowed
;
672 bool hpage_1m_allowed(void)
674 return get_machine_class()->hpage_1m_allowed
;
677 static void machine_get_loadparm(Object
*obj
, Visitor
*v
,
678 const char *name
, void *opaque
,
681 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
682 char *str
= g_strndup((char *) ms
->loadparm
, sizeof(ms
->loadparm
));
684 visit_type_str(v
, name
, &str
, errp
);
688 static void machine_set_loadparm(Object
*obj
, Visitor
*v
,
689 const char *name
, void *opaque
,
692 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
696 if (!visit_type_str(v
, name
, &val
, errp
)) {
700 for (i
= 0; i
< sizeof(ms
->loadparm
) && val
[i
]; i
++) {
701 uint8_t c
= qemu_toupper(val
[i
]); /* mimic HMC */
703 if (('A' <= c
&& c
<= 'Z') || ('0' <= c
&& c
<= '9') || (c
== '.') ||
707 error_setg(errp
, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
713 for (; i
< sizeof(ms
->loadparm
); i
++) {
714 ms
->loadparm
[i
] = ' '; /* pad right with spaces */
718 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
720 MachineClass
*mc
= MACHINE_CLASS(oc
);
721 NMIClass
*nc
= NMI_CLASS(oc
);
722 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
723 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
725 s390mc
->ri_allowed
= true;
726 s390mc
->cpu_model_allowed
= true;
727 s390mc
->css_migration_enabled
= true;
728 s390mc
->hpage_1m_allowed
= true;
729 s390mc
->max_threads
= 1;
731 mc
->reset
= s390_machine_reset
;
732 mc
->block_default_type
= IF_VIRTIO
;
737 mc
->max_cpus
= S390_MAX_CPUS
;
738 mc
->has_hotpluggable_cpus
= true;
739 assert(!mc
->get_hotplug_handler
);
740 mc
->get_hotplug_handler
= s390_get_hotplug_handler
;
741 mc
->cpu_index_to_instance_props
= s390_cpu_index_to_props
;
742 mc
->possible_cpu_arch_ids
= s390_possible_cpu_arch_ids
;
743 /* it is overridden with 'host' cpu *in kvm_arch_init* */
744 mc
->default_cpu_type
= S390_CPU_TYPE_NAME("qemu");
745 hc
->plug
= s390_machine_device_plug
;
746 hc
->unplug_request
= s390_machine_device_unplug_request
;
747 nc
->nmi_monitor_handler
= s390_nmi
;
748 mc
->default_ram_id
= "s390.ram";
750 object_class_property_add_bool(oc
, "aes-key-wrap",
751 machine_get_aes_key_wrap
,
752 machine_set_aes_key_wrap
);
753 object_class_property_set_description(oc
, "aes-key-wrap",
754 "enable/disable AES key wrapping using the CPACF wrapping key");
756 object_class_property_add_bool(oc
, "dea-key-wrap",
757 machine_get_dea_key_wrap
,
758 machine_set_dea_key_wrap
);
759 object_class_property_set_description(oc
, "dea-key-wrap",
760 "enable/disable DEA key wrapping using the CPACF wrapping key");
762 object_class_property_add(oc
, "loadparm", "loadparm",
763 machine_get_loadparm
, machine_set_loadparm
,
765 object_class_property_set_description(oc
, "loadparm",
766 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
767 " to upper case) to pass to machine loader, boot manager,"
768 " and guest kernel");
771 static inline void s390_machine_initfn(Object
*obj
)
773 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
775 ms
->aes_key_wrap
= true;
776 ms
->dea_key_wrap
= true;
779 static const TypeInfo ccw_machine_info
= {
780 .name
= TYPE_S390_CCW_MACHINE
,
781 .parent
= TYPE_MACHINE
,
783 .instance_size
= sizeof(S390CcwMachineState
),
784 .instance_init
= s390_machine_initfn
,
785 .class_size
= sizeof(S390CcwMachineClass
),
786 .class_init
= ccw_machine_class_init
,
787 .interfaces
= (InterfaceInfo
[]) {
789 { TYPE_HOTPLUG_HANDLER
},
794 bool css_migration_enabled(void)
796 return get_machine_class()->css_migration_enabled
;
799 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
800 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
803 MachineClass *mc = MACHINE_CLASS(oc); \
804 ccw_machine_##suffix##_class_options(mc); \
805 mc->desc = "Virtual s390x machine (version " verstr ")"; \
807 mc->alias = "s390-ccw-virtio"; \
808 mc->is_default = true; \
811 static void ccw_machine_##suffix##_instance_init(Object *obj) \
813 MachineState *machine = MACHINE(obj); \
814 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
815 ccw_machine_##suffix##_instance_options(machine); \
817 static const TypeInfo ccw_machine_##suffix##_info = { \
818 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
819 .parent = TYPE_S390_CCW_MACHINE, \
820 .class_init = ccw_machine_##suffix##_class_init, \
821 .instance_init = ccw_machine_##suffix##_instance_init, \
823 static void ccw_machine_register_##suffix(void) \
825 type_register_static(&ccw_machine_##suffix##_info); \
827 type_init(ccw_machine_register_##suffix)
829 static void ccw_machine_8_0_instance_options(MachineState
*machine
)
833 static void ccw_machine_8_0_class_options(MachineClass
*mc
)
836 DEFINE_CCW_MACHINE(8_0
, "8.0", true);
838 static void ccw_machine_7_2_instance_options(MachineState
*machine
)
840 ccw_machine_8_0_instance_options(machine
);
843 static void ccw_machine_7_2_class_options(MachineClass
*mc
)
845 ccw_machine_8_0_class_options(mc
);
846 compat_props_add(mc
->compat_props
, hw_compat_7_2
, hw_compat_7_2_len
);
848 DEFINE_CCW_MACHINE(7_2
, "7.2", false);
850 static void ccw_machine_7_1_instance_options(MachineState
*machine
)
852 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_1
};
854 ccw_machine_7_2_instance_options(machine
);
855 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE
);
856 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
859 static void ccw_machine_7_1_class_options(MachineClass
*mc
)
861 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
862 static GlobalProperty compat
[] = {
863 { TYPE_S390_PCI_DEVICE
, "interpret", "off", },
864 { TYPE_S390_PCI_DEVICE
, "forwarding-assist", "off", },
867 ccw_machine_7_2_class_options(mc
);
868 compat_props_add(mc
->compat_props
, hw_compat_7_1
, hw_compat_7_1_len
);
869 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
870 s390mc
->max_threads
= S390_MAX_CPUS
;
872 DEFINE_CCW_MACHINE(7_1
, "7.1", false);
874 static void ccw_machine_7_0_instance_options(MachineState
*machine
)
876 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_0
};
878 ccw_machine_7_1_instance_options(machine
);
879 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
882 static void ccw_machine_7_0_class_options(MachineClass
*mc
)
884 ccw_machine_7_1_class_options(mc
);
885 compat_props_add(mc
->compat_props
, hw_compat_7_0
, hw_compat_7_0_len
);
887 DEFINE_CCW_MACHINE(7_0
, "7.0", false);
889 static void ccw_machine_6_2_instance_options(MachineState
*machine
)
891 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_2
};
893 ccw_machine_7_0_instance_options(machine
);
894 s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat
);
897 static void ccw_machine_6_2_class_options(MachineClass
*mc
)
899 ccw_machine_7_0_class_options(mc
);
900 compat_props_add(mc
->compat_props
, hw_compat_6_2
, hw_compat_6_2_len
);
902 DEFINE_CCW_MACHINE(6_2
, "6.2", false);
904 static void ccw_machine_6_1_instance_options(MachineState
*machine
)
906 ccw_machine_6_2_instance_options(machine
);
907 s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA
);
908 s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2
);
909 s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH
);
910 s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP
);
911 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI
);
914 static void ccw_machine_6_1_class_options(MachineClass
*mc
)
916 ccw_machine_6_2_class_options(mc
);
917 compat_props_add(mc
->compat_props
, hw_compat_6_1
, hw_compat_6_1_len
);
918 mc
->smp_props
.prefer_sockets
= true;
920 DEFINE_CCW_MACHINE(6_1
, "6.1", false);
922 static void ccw_machine_6_0_instance_options(MachineState
*machine
)
924 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_0
};
926 ccw_machine_6_1_instance_options(machine
);
927 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
930 static void ccw_machine_6_0_class_options(MachineClass
*mc
)
932 ccw_machine_6_1_class_options(mc
);
933 compat_props_add(mc
->compat_props
, hw_compat_6_0
, hw_compat_6_0_len
);
935 DEFINE_CCW_MACHINE(6_0
, "6.0", false);
937 static void ccw_machine_5_2_instance_options(MachineState
*machine
)
939 ccw_machine_6_0_instance_options(machine
);
942 static void ccw_machine_5_2_class_options(MachineClass
*mc
)
944 ccw_machine_6_0_class_options(mc
);
945 compat_props_add(mc
->compat_props
, hw_compat_5_2
, hw_compat_5_2_len
);
947 DEFINE_CCW_MACHINE(5_2
, "5.2", false);
949 static void ccw_machine_5_1_instance_options(MachineState
*machine
)
951 ccw_machine_5_2_instance_options(machine
);
954 static void ccw_machine_5_1_class_options(MachineClass
*mc
)
956 ccw_machine_5_2_class_options(mc
);
957 compat_props_add(mc
->compat_props
, hw_compat_5_1
, hw_compat_5_1_len
);
959 DEFINE_CCW_MACHINE(5_1
, "5.1", false);
961 static void ccw_machine_5_0_instance_options(MachineState
*machine
)
963 ccw_machine_5_1_instance_options(machine
);
966 static void ccw_machine_5_0_class_options(MachineClass
*mc
)
968 ccw_machine_5_1_class_options(mc
);
969 compat_props_add(mc
->compat_props
, hw_compat_5_0
, hw_compat_5_0_len
);
971 DEFINE_CCW_MACHINE(5_0
, "5.0", false);
973 static void ccw_machine_4_2_instance_options(MachineState
*machine
)
975 ccw_machine_5_0_instance_options(machine
);
978 static void ccw_machine_4_2_class_options(MachineClass
*mc
)
980 ccw_machine_5_0_class_options(mc
);
981 mc
->fixup_ram_size
= s390_fixup_ram_size
;
982 compat_props_add(mc
->compat_props
, hw_compat_4_2
, hw_compat_4_2_len
);
984 DEFINE_CCW_MACHINE(4_2
, "4.2", false);
986 static void ccw_machine_4_1_instance_options(MachineState
*machine
)
988 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_1
};
989 ccw_machine_4_2_instance_options(machine
);
990 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
993 static void ccw_machine_4_1_class_options(MachineClass
*mc
)
995 ccw_machine_4_2_class_options(mc
);
996 compat_props_add(mc
->compat_props
, hw_compat_4_1
, hw_compat_4_1_len
);
998 DEFINE_CCW_MACHINE(4_1
, "4.1", false);
1000 static void ccw_machine_4_0_instance_options(MachineState
*machine
)
1002 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_0
};
1003 ccw_machine_4_1_instance_options(machine
);
1004 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
1007 static void ccw_machine_4_0_class_options(MachineClass
*mc
)
1009 ccw_machine_4_1_class_options(mc
);
1010 compat_props_add(mc
->compat_props
, hw_compat_4_0
, hw_compat_4_0_len
);
1012 DEFINE_CCW_MACHINE(4_0
, "4.0", false);
1014 static void ccw_machine_3_1_instance_options(MachineState
*machine
)
1016 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V3_1
};
1017 ccw_machine_4_0_instance_options(machine
);
1018 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH
);
1019 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF
);
1020 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
1023 static void ccw_machine_3_1_class_options(MachineClass
*mc
)
1025 ccw_machine_4_0_class_options(mc
);
1026 compat_props_add(mc
->compat_props
, hw_compat_3_1
, hw_compat_3_1_len
);
1028 DEFINE_CCW_MACHINE(3_1
, "3.1", false);
1030 static void ccw_machine_3_0_instance_options(MachineState
*machine
)
1032 ccw_machine_3_1_instance_options(machine
);
1035 static void ccw_machine_3_0_class_options(MachineClass
*mc
)
1037 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1039 s390mc
->hpage_1m_allowed
= false;
1040 ccw_machine_3_1_class_options(mc
);
1041 compat_props_add(mc
->compat_props
, hw_compat_3_0
, hw_compat_3_0_len
);
1043 DEFINE_CCW_MACHINE(3_0
, "3.0", false);
1045 static void ccw_machine_2_12_instance_options(MachineState
*machine
)
1047 ccw_machine_3_0_instance_options(machine
);
1048 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15
);
1049 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB
);
1052 static void ccw_machine_2_12_class_options(MachineClass
*mc
)
1054 ccw_machine_3_0_class_options(mc
);
1055 compat_props_add(mc
->compat_props
, hw_compat_2_12
, hw_compat_2_12_len
);
1057 DEFINE_CCW_MACHINE(2_12
, "2.12", false);
1059 static void ccw_machine_2_11_instance_options(MachineState
*machine
)
1061 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V2_11
};
1062 ccw_machine_2_12_instance_options(machine
);
1064 /* before 2.12 we emulated the very first z900 */
1065 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat
);
1068 static void ccw_machine_2_11_class_options(MachineClass
*mc
)
1070 static GlobalProperty compat
[] = {
1071 { TYPE_SCLP_EVENT_FACILITY
, "allow_all_mask_sizes", "off", },
1074 ccw_machine_2_12_class_options(mc
);
1075 compat_props_add(mc
->compat_props
, hw_compat_2_11
, hw_compat_2_11_len
);
1076 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1078 DEFINE_CCW_MACHINE(2_11
, "2.11", false);
1080 static void ccw_machine_2_10_instance_options(MachineState
*machine
)
1082 ccw_machine_2_11_instance_options(machine
);
1085 static void ccw_machine_2_10_class_options(MachineClass
*mc
)
1087 ccw_machine_2_11_class_options(mc
);
1088 compat_props_add(mc
->compat_props
, hw_compat_2_10
, hw_compat_2_10_len
);
1090 DEFINE_CCW_MACHINE(2_10
, "2.10", false);
1092 static void ccw_machine_2_9_instance_options(MachineState
*machine
)
1094 ccw_machine_2_10_instance_options(machine
);
1095 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP
);
1096 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2
);
1097 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI
);
1098 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION
);
1099 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION
);
1102 static void ccw_machine_2_9_class_options(MachineClass
*mc
)
1104 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1105 static GlobalProperty compat
[] = {
1106 { TYPE_S390_STATTRIB
, "migration-enabled", "off", },
1109 ccw_machine_2_10_class_options(mc
);
1110 compat_props_add(mc
->compat_props
, hw_compat_2_9
, hw_compat_2_9_len
);
1111 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1112 s390mc
->css_migration_enabled
= false;
1114 DEFINE_CCW_MACHINE(2_9
, "2.9", false);
1116 static void ccw_machine_2_8_instance_options(MachineState
*machine
)
1118 ccw_machine_2_9_instance_options(machine
);
1121 static void ccw_machine_2_8_class_options(MachineClass
*mc
)
1123 static GlobalProperty compat
[] = {
1124 { TYPE_S390_FLIC_COMMON
, "adapter_routes_max_batch", "64", },
1127 ccw_machine_2_9_class_options(mc
);
1128 compat_props_add(mc
->compat_props
, hw_compat_2_8
, hw_compat_2_8_len
);
1129 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1131 DEFINE_CCW_MACHINE(2_8
, "2.8", false);
1133 static void ccw_machine_2_7_instance_options(MachineState
*machine
)
1135 ccw_machine_2_8_instance_options(machine
);
1138 static void ccw_machine_2_7_class_options(MachineClass
*mc
)
1140 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1142 s390mc
->cpu_model_allowed
= false;
1143 ccw_machine_2_8_class_options(mc
);
1144 compat_props_add(mc
->compat_props
, hw_compat_2_7
, hw_compat_2_7_len
);
1146 DEFINE_CCW_MACHINE(2_7
, "2.7", false);
1148 static void ccw_machine_2_6_instance_options(MachineState
*machine
)
1150 ccw_machine_2_7_instance_options(machine
);
1153 static void ccw_machine_2_6_class_options(MachineClass
*mc
)
1155 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1156 static GlobalProperty compat
[] = {
1157 { TYPE_S390_IPL
, "iplbext_migration", "off", },
1158 { TYPE_VIRTUAL_CSS_BRIDGE
, "css_dev_path", "off", },
1161 s390mc
->ri_allowed
= false;
1162 ccw_machine_2_7_class_options(mc
);
1163 compat_props_add(mc
->compat_props
, hw_compat_2_6
, hw_compat_2_6_len
);
1164 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1166 DEFINE_CCW_MACHINE(2_6
, "2.6", false);
1168 static void ccw_machine_2_5_instance_options(MachineState
*machine
)
1170 ccw_machine_2_6_instance_options(machine
);
1173 static void ccw_machine_2_5_class_options(MachineClass
*mc
)
1175 ccw_machine_2_6_class_options(mc
);
1176 compat_props_add(mc
->compat_props
, hw_compat_2_5
, hw_compat_2_5_len
);
1178 DEFINE_CCW_MACHINE(2_5
, "2.5", false);
1180 static void ccw_machine_2_4_instance_options(MachineState
*machine
)
1182 ccw_machine_2_5_instance_options(machine
);
1185 static void ccw_machine_2_4_class_options(MachineClass
*mc
)
1187 static GlobalProperty compat
[] = {
1188 { TYPE_S390_SKEYS
, "migration-enabled", "off", },
1189 { "virtio-blk-ccw", "max_revision", "0", },
1190 { "virtio-balloon-ccw", "max_revision", "0", },
1191 { "virtio-serial-ccw", "max_revision", "0", },
1192 { "virtio-9p-ccw", "max_revision", "0", },
1193 { "virtio-rng-ccw", "max_revision", "0", },
1194 { "virtio-net-ccw", "max_revision", "0", },
1195 { "virtio-scsi-ccw", "max_revision", "0", },
1196 { "vhost-scsi-ccw", "max_revision", "0", },
1199 ccw_machine_2_5_class_options(mc
);
1200 compat_props_add(mc
->compat_props
, hw_compat_2_4
, hw_compat_2_4_len
);
1201 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1203 DEFINE_CCW_MACHINE(2_4
, "2.4", false);
1205 static void ccw_machine_register_types(void)
1207 type_register_static(&ccw_machine_info
);
1210 type_init(ccw_machine_register_types
)