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 "target/s390x/kvm/pv.h"
46 #include "migration/blocker.h"
47 #include "qapi/visitor.h"
48 #include "hw/s390x/cpu-topology.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
);
90 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
93 if (machine
->smp
.threads
> s390mc
->max_threads
) {
94 error_report("S390 does not support more than %d threads.",
99 /* initialize possible_cpus */
100 mc
->possible_cpu_arch_ids(machine
);
102 for (i
= 0; i
< machine
->smp
.cpus
; i
++) {
103 s390x_new_cpu(machine
->cpu_type
, i
, &error_fatal
);
107 static const char *const reset_dev_types
[] = {
108 TYPE_VIRTUAL_CSS_BRIDGE
,
109 "s390-sclp-event-facility",
112 TYPE_S390_PCI_HOST_BRIDGE
,
116 static void subsystem_reset(void)
122 * ISM firmware is sensitive to unexpected changes to the IOMMU, which can
123 * occur during reset of the vfio-pci device (unmap of entire aperture).
124 * Ensure any passthrough ISM devices are reset now, while CPUs are paused
125 * but before vfio-pci cleanup occurs.
127 s390_pci_ism_reset();
129 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
130 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
132 device_cold_reset(dev
);
135 if (s390_has_topology()) {
136 s390_topology_reset();
140 static int virtio_ccw_hcall_notify(const uint64_t *args
)
142 uint64_t subch_id
= args
[0];
143 uint64_t queue
= args
[1];
145 int cssid
, ssid
, schid
, m
;
147 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
150 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
151 if (!sch
|| !css_subch_visible(sch
)) {
154 if (queue
>= VIRTIO_QUEUE_MAX
) {
157 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
162 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
164 uint64_t mem
= args
[0];
165 MachineState
*ms
= MACHINE(qdev_get_machine());
167 if (mem
< ms
->ram_size
) {
174 static void virtio_ccw_register_hcalls(void)
176 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
177 virtio_ccw_hcall_notify
);
178 /* Tolerate early printk. */
179 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
180 virtio_ccw_hcall_early_printk
);
183 static void s390_memory_init(MemoryRegion
*ram
)
185 MemoryRegion
*sysmem
= get_system_memory();
187 /* allocate RAM for core */
188 memory_region_add_subregion(sysmem
, 0, ram
);
191 * Configure the maximum page size. As no memory devices were created
192 * yet, this is the page size of initial memory only.
194 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal
);
195 /* Initialize storage key device */
197 /* Initialize storage attributes device */
198 s390_stattrib_init();
201 static void s390_init_ipl_dev(const char *kernel_filename
,
202 const char *kernel_cmdline
,
203 const char *initrd_filename
, const char *firmware
,
204 const char *netboot_fw
, bool enforce_bios
)
206 Object
*new = object_new(TYPE_S390_IPL
);
207 DeviceState
*dev
= DEVICE(new);
208 char *netboot_fw_prop
;
210 if (kernel_filename
) {
211 qdev_prop_set_string(dev
, "kernel", kernel_filename
);
213 if (initrd_filename
) {
214 qdev_prop_set_string(dev
, "initrd", initrd_filename
);
216 qdev_prop_set_string(dev
, "cmdline", kernel_cmdline
);
217 qdev_prop_set_string(dev
, "firmware", firmware
);
218 qdev_prop_set_bit(dev
, "enforce_bios", enforce_bios
);
219 netboot_fw_prop
= object_property_get_str(new, "netboot_fw", &error_abort
);
220 if (!strlen(netboot_fw_prop
)) {
221 qdev_prop_set_string(dev
, "netboot_fw", netboot_fw
);
223 g_free(netboot_fw_prop
);
224 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL
,
227 qdev_realize(dev
, NULL
, &error_fatal
);
230 static void s390_create_virtio_net(BusState
*bus
, const char *name
)
234 while ((dev
= qemu_create_nic_device(name
, true, "virtio"))) {
235 qdev_realize_and_unref(dev
, bus
, &error_fatal
);
239 static void s390_create_sclpconsole(const char *type
, Chardev
*chardev
)
243 dev
= qdev_new(type
);
244 qdev_prop_set_chr(dev
, "chardev", chardev
);
245 qdev_realize_and_unref(dev
, sclp_get_event_facility_bus(), &error_fatal
);
248 static void ccw_init(MachineState
*machine
)
250 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
252 VirtualCssBus
*css_bus
;
256 /* init memory + setup max page size. Required for the CPU model */
257 s390_memory_init(machine
->ram
);
259 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
260 s390_init_cpus(machine
);
262 /* Need CPU model to be determined before we can set up PV */
263 s390_pv_init(machine
->cgs
, &error_fatal
);
267 /* init the SIGP facility */
270 /* create AP bridge and bus(es) */
274 css_bus
= virtual_css_bus_init();
275 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
276 machine
->initrd_filename
,
277 machine
->firmware
?: "s390-ccw.img",
278 "s390-netboot.img", true);
280 dev
= qdev_new(TYPE_S390_PCI_HOST_BRIDGE
);
281 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
283 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
285 /* register hypercalls */
286 virtio_ccw_register_hcalls();
288 s390_enable_css_support(s390_cpu_addr2state(0));
290 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
293 if (css_migration_enabled()) {
294 css_register_vmstate();
297 /* Create VirtIO network adapters */
298 s390_create_virtio_net(BUS(css_bus
), mc
->default_nic
);
302 s390_create_sclpconsole("sclpconsole", serial_hd(0));
305 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
308 /* init the TOD clock */
312 static void s390_cpu_plug(HotplugHandler
*hotplug_dev
,
313 DeviceState
*dev
, Error
**errp
)
316 MachineState
*ms
= MACHINE(hotplug_dev
);
317 S390CPU
*cpu
= S390_CPU(dev
);
319 g_assert(!ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
);
320 ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
= CPU(dev
);
322 if (s390_has_topology()) {
323 s390_topology_setup_cpu(ms
, cpu
, errp
);
329 if (dev
->hotplugged
) {
330 raise_irq_cpu_hotplug();
334 static inline void s390_do_cpu_ipl(CPUState
*cs
, run_on_cpu_data arg
)
336 S390CPU
*cpu
= S390_CPU(cs
);
338 s390_ipl_prepare_cpu(cpu
);
339 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
342 static void s390_machine_unprotect(S390CcwMachineState
*ms
)
344 if (!s390_pv_vm_try_disable_async(ms
)) {
345 s390_pv_vm_disable();
348 migrate_del_blocker(&pv_mig_blocker
);
349 ram_block_discard_disable(false);
352 static int s390_machine_protect(S390CcwMachineState
*ms
)
354 Error
*local_err
= NULL
;
358 * Discarding of memory in RAM blocks does not work as expected with
359 * protected VMs. Sharing and unsharing pages would be required. Disable
360 * it for now, until until we have a solution to make at least Linux
361 * guests either support it (e.g., virtio-balloon) or fail gracefully.
363 rc
= ram_block_discard_disable(true);
365 error_report("protected VMs: cannot disable RAM discard");
369 error_setg(&pv_mig_blocker
,
370 "protected VMs are currently not migratable.");
371 rc
= migrate_add_blocker(&pv_mig_blocker
, &local_err
);
373 ram_block_discard_disable(false);
374 error_report_err(local_err
);
379 rc
= s390_pv_vm_enable();
381 ram_block_discard_disable(false);
382 migrate_del_blocker(&pv_mig_blocker
);
388 /* Will return 0 if API is not available since it's not vital */
389 rc
= s390_pv_query_info();
394 /* Set SE header and unpack */
395 rc
= s390_ipl_prepare_pv_header(&local_err
);
401 rc
= s390_ipl_pv_unpack();
406 /* Verify integrity */
407 rc
= s390_pv_verify();
415 error_report_err(local_err
);
417 s390_machine_unprotect(ms
);
421 static void s390_pv_prepare_reset(S390CcwMachineState
*ms
)
428 /* Unsharing requires all cpus to be stopped */
430 s390_cpu_set_state(S390_CPU_STATE_STOPPED
, S390_CPU(cs
));
433 s390_pv_prep_reset();
436 static void s390_machine_reset(MachineState
*machine
, ShutdownCause reason
)
438 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
439 enum s390_reset reset_type
;
443 /* get the reset parameters, reset them once done */
444 s390_ipl_get_reset_request(&cs
, &reset_type
);
446 /* all CPUs are paused and synchronized at this point */
451 switch (reset_type
) {
452 case S390_RESET_EXTERNAL
:
453 case S390_RESET_REIPL
:
455 * Reset the subsystem which includes a AP reset. If a PV
456 * guest had APQNs attached the AP reset is a prerequisite to
457 * unprotecting since the UV checks if all APQNs are reset.
461 s390_machine_unprotect(ms
);
465 * Device reset includes CPU clear resets so this has to be
466 * done AFTER the unprotect call above.
468 qemu_devices_reset(reason
);
471 /* configure and start the ipl CPU only */
472 run_on_cpu(cs
, s390_do_cpu_ipl
, RUN_ON_CPU_NULL
);
474 case S390_RESET_MODIFIED_CLEAR
:
476 * Subsystem reset needs to be done before we unshare memory
477 * and lose access to VIRTIO structures in guest memory.
481 s390_pv_prepare_reset(ms
);
483 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
485 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
487 case S390_RESET_LOAD_NORMAL
:
489 * Subsystem reset needs to be done before we unshare memory
490 * and lose access to VIRTIO structures in guest memory.
493 s390_pv_prepare_reset(ms
);
498 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
500 run_on_cpu(cs
, s390_do_cpu_initial_reset
, RUN_ON_CPU_NULL
);
501 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
503 case S390_RESET_PV
: /* Subcode 10 */
511 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
513 run_on_cpu(cs
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
515 if (s390_machine_protect(ms
)) {
516 s390_pv_inject_reset_error(cs
);
518 * Continue after the diag308 so the guest knows something
521 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
525 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
528 g_assert_not_reached();
532 run_on_cpu(t
, s390_do_cpu_set_diag318
, RUN_ON_CPU_HOST_ULONG(0));
534 s390_ipl_clear_reset_request();
537 static void s390_machine_device_plug(HotplugHandler
*hotplug_dev
,
538 DeviceState
*dev
, Error
**errp
)
540 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
541 s390_cpu_plug(hotplug_dev
, dev
, errp
);
545 static void s390_machine_device_unplug_request(HotplugHandler
*hotplug_dev
,
546 DeviceState
*dev
, Error
**errp
)
548 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
549 error_setg(errp
, "CPU hot unplug not supported on this machine");
554 static CpuInstanceProperties
s390_cpu_index_to_props(MachineState
*ms
,
557 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
558 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
560 assert(cpu_index
< possible_cpus
->len
);
561 return possible_cpus
->cpus
[cpu_index
].props
;
564 static const CPUArchIdList
*s390_possible_cpu_arch_ids(MachineState
*ms
)
567 unsigned int max_cpus
= ms
->smp
.max_cpus
;
569 if (ms
->possible_cpus
) {
570 g_assert(ms
->possible_cpus
&& ms
->possible_cpus
->len
== max_cpus
);
571 return ms
->possible_cpus
;
574 ms
->possible_cpus
= g_malloc0(sizeof(CPUArchIdList
) +
575 sizeof(CPUArchId
) * max_cpus
);
576 ms
->possible_cpus
->len
= max_cpus
;
577 for (i
= 0; i
< ms
->possible_cpus
->len
; i
++) {
578 CpuInstanceProperties
*props
= &ms
->possible_cpus
->cpus
[i
].props
;
580 ms
->possible_cpus
->cpus
[i
].type
= ms
->cpu_type
;
581 ms
->possible_cpus
->cpus
[i
].vcpus_count
= 1;
582 ms
->possible_cpus
->cpus
[i
].arch_id
= i
;
584 props
->has_core_id
= true;
586 props
->has_socket_id
= true;
587 props
->socket_id
= s390_std_socket(i
, &ms
->smp
);
588 props
->has_book_id
= true;
589 props
->book_id
= s390_std_book(i
, &ms
->smp
);
590 props
->has_drawer_id
= true;
591 props
->drawer_id
= s390_std_drawer(i
, &ms
->smp
);
594 return ms
->possible_cpus
;
597 static HotplugHandler
*s390_get_hotplug_handler(MachineState
*machine
,
600 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
601 return HOTPLUG_HANDLER(machine
);
606 static void s390_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
608 CPUState
*cs
= qemu_get_cpu(cpu_index
);
610 s390_cpu_restart(S390_CPU(cs
));
613 static ram_addr_t
s390_fixup_ram_size(ram_addr_t sz
)
615 /* same logic as in sclp.c */
616 int increment_size
= 20;
619 while ((sz
>> increment_size
) > MAX_STORAGE_INCREMENTS
) {
622 newsz
= sz
>> increment_size
<< increment_size
;
625 qemu_printf("Ram size %" PRIu64
"MB was fixed up to %" PRIu64
626 "MB to match machine restrictions. Consider updating "
627 "the guest definition.\n", (uint64_t) (sz
/ MiB
),
628 (uint64_t) (newsz
/ MiB
));
633 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
635 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
637 return ms
->aes_key_wrap
;
640 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
643 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
645 ms
->aes_key_wrap
= value
;
648 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
650 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
652 return ms
->dea_key_wrap
;
655 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
658 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
660 ms
->dea_key_wrap
= value
;
663 static S390CcwMachineClass
*current_mc
;
666 * Get the class of the s390-ccw-virtio machine that is currently in use.
667 * Note: libvirt is using the "none" machine to probe for the features of the
668 * host CPU, so in case this is called with the "none" machine, the function
669 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
670 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
671 * below return the correct default value for the "none" machine.
673 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
674 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
675 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
676 * CPU initialization and s390_has_feat() later should be sufficient.
678 static S390CcwMachineClass
*get_machine_class(void)
680 if (unlikely(!current_mc
)) {
682 * No s390 ccw machine was instantiated, we are likely to
683 * be called for the 'none' machine. The properties will
684 * have their after-initialization values.
686 current_mc
= S390_CCW_MACHINE_CLASS(
687 object_class_by_name(TYPE_S390_CCW_MACHINE
));
692 bool ri_allowed(void)
694 return get_machine_class()->ri_allowed
;
697 bool cpu_model_allowed(void)
699 return get_machine_class()->cpu_model_allowed
;
702 bool hpage_1m_allowed(void)
704 return get_machine_class()->hpage_1m_allowed
;
707 static void machine_get_loadparm(Object
*obj
, Visitor
*v
,
708 const char *name
, void *opaque
,
711 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
712 char *str
= g_strndup((char *) ms
->loadparm
, sizeof(ms
->loadparm
));
714 visit_type_str(v
, name
, &str
, errp
);
718 static void machine_set_loadparm(Object
*obj
, Visitor
*v
,
719 const char *name
, void *opaque
,
722 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
726 if (!visit_type_str(v
, name
, &val
, errp
)) {
730 for (i
= 0; i
< sizeof(ms
->loadparm
) && val
[i
]; i
++) {
731 uint8_t c
= qemu_toupper(val
[i
]); /* mimic HMC */
733 if (('A' <= c
&& c
<= 'Z') || ('0' <= c
&& c
<= '9') || (c
== '.') ||
737 error_setg(errp
, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
743 for (; i
< sizeof(ms
->loadparm
); i
++) {
744 ms
->loadparm
[i
] = ' '; /* pad right with spaces */
748 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
750 MachineClass
*mc
= MACHINE_CLASS(oc
);
751 NMIClass
*nc
= NMI_CLASS(oc
);
752 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
753 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
755 s390mc
->ri_allowed
= true;
756 s390mc
->cpu_model_allowed
= true;
757 s390mc
->css_migration_enabled
= true;
758 s390mc
->hpage_1m_allowed
= true;
759 s390mc
->max_threads
= 1;
761 mc
->reset
= s390_machine_reset
;
762 mc
->block_default_type
= IF_VIRTIO
;
767 mc
->max_cpus
= S390_MAX_CPUS
;
768 mc
->has_hotpluggable_cpus
= true;
769 mc
->smp_props
.books_supported
= true;
770 mc
->smp_props
.drawers_supported
= true;
771 assert(!mc
->get_hotplug_handler
);
772 mc
->get_hotplug_handler
= s390_get_hotplug_handler
;
773 mc
->cpu_index_to_instance_props
= s390_cpu_index_to_props
;
774 mc
->possible_cpu_arch_ids
= s390_possible_cpu_arch_ids
;
775 /* it is overridden with 'host' cpu *in kvm_arch_init* */
776 mc
->default_cpu_type
= S390_CPU_TYPE_NAME("qemu");
777 hc
->plug
= s390_machine_device_plug
;
778 hc
->unplug_request
= s390_machine_device_unplug_request
;
779 nc
->nmi_monitor_handler
= s390_nmi
;
780 mc
->default_ram_id
= "s390.ram";
781 mc
->default_nic
= "virtio-net-ccw";
783 object_class_property_add_bool(oc
, "aes-key-wrap",
784 machine_get_aes_key_wrap
,
785 machine_set_aes_key_wrap
);
786 object_class_property_set_description(oc
, "aes-key-wrap",
787 "enable/disable AES key wrapping using the CPACF wrapping key");
789 object_class_property_add_bool(oc
, "dea-key-wrap",
790 machine_get_dea_key_wrap
,
791 machine_set_dea_key_wrap
);
792 object_class_property_set_description(oc
, "dea-key-wrap",
793 "enable/disable DEA key wrapping using the CPACF wrapping key");
795 object_class_property_add(oc
, "loadparm", "loadparm",
796 machine_get_loadparm
, machine_set_loadparm
,
798 object_class_property_set_description(oc
, "loadparm",
799 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
800 " to upper case) to pass to machine loader, boot manager,"
801 " and guest kernel");
804 static inline void s390_machine_initfn(Object
*obj
)
806 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
808 ms
->aes_key_wrap
= true;
809 ms
->dea_key_wrap
= true;
812 static const TypeInfo ccw_machine_info
= {
813 .name
= TYPE_S390_CCW_MACHINE
,
814 .parent
= TYPE_MACHINE
,
816 .instance_size
= sizeof(S390CcwMachineState
),
817 .instance_init
= s390_machine_initfn
,
818 .class_size
= sizeof(S390CcwMachineClass
),
819 .class_init
= ccw_machine_class_init
,
820 .interfaces
= (InterfaceInfo
[]) {
822 { TYPE_HOTPLUG_HANDLER
},
827 bool css_migration_enabled(void)
829 return get_machine_class()->css_migration_enabled
;
832 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
833 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
836 MachineClass *mc = MACHINE_CLASS(oc); \
837 ccw_machine_##suffix##_class_options(mc); \
838 mc->desc = "Virtual s390x machine (version " verstr ")"; \
840 mc->alias = "s390-ccw-virtio"; \
841 mc->is_default = true; \
844 static void ccw_machine_##suffix##_instance_init(Object *obj) \
846 MachineState *machine = MACHINE(obj); \
847 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
848 ccw_machine_##suffix##_instance_options(machine); \
850 static const TypeInfo ccw_machine_##suffix##_info = { \
851 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
852 .parent = TYPE_S390_CCW_MACHINE, \
853 .class_init = ccw_machine_##suffix##_class_init, \
854 .instance_init = ccw_machine_##suffix##_instance_init, \
856 static void ccw_machine_register_##suffix(void) \
858 type_register_static(&ccw_machine_##suffix##_info); \
860 type_init(ccw_machine_register_##suffix)
862 static void ccw_machine_9_0_instance_options(MachineState
*machine
)
866 static void ccw_machine_9_0_class_options(MachineClass
*mc
)
869 DEFINE_CCW_MACHINE(9_0
, "9.0", true);
871 static void ccw_machine_8_2_instance_options(MachineState
*machine
)
873 ccw_machine_9_0_instance_options(machine
);
876 static void ccw_machine_8_2_class_options(MachineClass
*mc
)
878 ccw_machine_9_0_class_options(mc
);
879 compat_props_add(mc
->compat_props
, hw_compat_8_2
, hw_compat_8_2_len
);
881 DEFINE_CCW_MACHINE(8_2
, "8.2", false);
883 static void ccw_machine_8_1_instance_options(MachineState
*machine
)
885 ccw_machine_8_2_instance_options(machine
);
888 static void ccw_machine_8_1_class_options(MachineClass
*mc
)
890 ccw_machine_8_2_class_options(mc
);
891 compat_props_add(mc
->compat_props
, hw_compat_8_1
, hw_compat_8_1_len
);
892 mc
->smp_props
.drawers_supported
= false;
893 mc
->smp_props
.books_supported
= false;
895 DEFINE_CCW_MACHINE(8_1
, "8.1", false);
897 static void ccw_machine_8_0_instance_options(MachineState
*machine
)
899 ccw_machine_8_1_instance_options(machine
);
902 static void ccw_machine_8_0_class_options(MachineClass
*mc
)
904 ccw_machine_8_1_class_options(mc
);
905 compat_props_add(mc
->compat_props
, hw_compat_8_0
, hw_compat_8_0_len
);
907 DEFINE_CCW_MACHINE(8_0
, "8.0", false);
909 static void ccw_machine_7_2_instance_options(MachineState
*machine
)
911 ccw_machine_8_0_instance_options(machine
);
914 static void ccw_machine_7_2_class_options(MachineClass
*mc
)
916 ccw_machine_8_0_class_options(mc
);
917 compat_props_add(mc
->compat_props
, hw_compat_7_2
, hw_compat_7_2_len
);
919 DEFINE_CCW_MACHINE(7_2
, "7.2", false);
921 static void ccw_machine_7_1_instance_options(MachineState
*machine
)
923 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_1
};
925 ccw_machine_7_2_instance_options(machine
);
926 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE
);
927 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
930 static void ccw_machine_7_1_class_options(MachineClass
*mc
)
932 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
933 static GlobalProperty compat
[] = {
934 { TYPE_S390_PCI_DEVICE
, "interpret", "off", },
935 { TYPE_S390_PCI_DEVICE
, "forwarding-assist", "off", },
938 ccw_machine_7_2_class_options(mc
);
939 compat_props_add(mc
->compat_props
, hw_compat_7_1
, hw_compat_7_1_len
);
940 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
941 s390mc
->max_threads
= S390_MAX_CPUS
;
943 DEFINE_CCW_MACHINE(7_1
, "7.1", false);
945 static void ccw_machine_7_0_instance_options(MachineState
*machine
)
947 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_0
};
949 ccw_machine_7_1_instance_options(machine
);
950 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
953 static void ccw_machine_7_0_class_options(MachineClass
*mc
)
955 ccw_machine_7_1_class_options(mc
);
956 compat_props_add(mc
->compat_props
, hw_compat_7_0
, hw_compat_7_0_len
);
958 DEFINE_CCW_MACHINE(7_0
, "7.0", false);
960 static void ccw_machine_6_2_instance_options(MachineState
*machine
)
962 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_2
};
964 ccw_machine_7_0_instance_options(machine
);
965 s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat
);
968 static void ccw_machine_6_2_class_options(MachineClass
*mc
)
970 ccw_machine_7_0_class_options(mc
);
971 compat_props_add(mc
->compat_props
, hw_compat_6_2
, hw_compat_6_2_len
);
973 DEFINE_CCW_MACHINE(6_2
, "6.2", false);
975 static void ccw_machine_6_1_instance_options(MachineState
*machine
)
977 ccw_machine_6_2_instance_options(machine
);
978 s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA
);
979 s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2
);
980 s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH
);
981 s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP
);
982 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI
);
985 static void ccw_machine_6_1_class_options(MachineClass
*mc
)
987 ccw_machine_6_2_class_options(mc
);
988 compat_props_add(mc
->compat_props
, hw_compat_6_1
, hw_compat_6_1_len
);
989 mc
->smp_props
.prefer_sockets
= true;
991 DEFINE_CCW_MACHINE(6_1
, "6.1", false);
993 static void ccw_machine_6_0_instance_options(MachineState
*machine
)
995 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_0
};
997 ccw_machine_6_1_instance_options(machine
);
998 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
1001 static void ccw_machine_6_0_class_options(MachineClass
*mc
)
1003 ccw_machine_6_1_class_options(mc
);
1004 compat_props_add(mc
->compat_props
, hw_compat_6_0
, hw_compat_6_0_len
);
1006 DEFINE_CCW_MACHINE(6_0
, "6.0", false);
1008 static void ccw_machine_5_2_instance_options(MachineState
*machine
)
1010 ccw_machine_6_0_instance_options(machine
);
1013 static void ccw_machine_5_2_class_options(MachineClass
*mc
)
1015 ccw_machine_6_0_class_options(mc
);
1016 compat_props_add(mc
->compat_props
, hw_compat_5_2
, hw_compat_5_2_len
);
1018 DEFINE_CCW_MACHINE(5_2
, "5.2", false);
1020 static void ccw_machine_5_1_instance_options(MachineState
*machine
)
1022 ccw_machine_5_2_instance_options(machine
);
1025 static void ccw_machine_5_1_class_options(MachineClass
*mc
)
1027 ccw_machine_5_2_class_options(mc
);
1028 compat_props_add(mc
->compat_props
, hw_compat_5_1
, hw_compat_5_1_len
);
1030 DEFINE_CCW_MACHINE(5_1
, "5.1", false);
1032 static void ccw_machine_5_0_instance_options(MachineState
*machine
)
1034 ccw_machine_5_1_instance_options(machine
);
1037 static void ccw_machine_5_0_class_options(MachineClass
*mc
)
1039 ccw_machine_5_1_class_options(mc
);
1040 compat_props_add(mc
->compat_props
, hw_compat_5_0
, hw_compat_5_0_len
);
1042 DEFINE_CCW_MACHINE(5_0
, "5.0", false);
1044 static void ccw_machine_4_2_instance_options(MachineState
*machine
)
1046 ccw_machine_5_0_instance_options(machine
);
1049 static void ccw_machine_4_2_class_options(MachineClass
*mc
)
1051 ccw_machine_5_0_class_options(mc
);
1052 mc
->fixup_ram_size
= s390_fixup_ram_size
;
1053 compat_props_add(mc
->compat_props
, hw_compat_4_2
, hw_compat_4_2_len
);
1055 DEFINE_CCW_MACHINE(4_2
, "4.2", false);
1057 static void ccw_machine_4_1_instance_options(MachineState
*machine
)
1059 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_1
};
1060 ccw_machine_4_2_instance_options(machine
);
1061 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
1064 static void ccw_machine_4_1_class_options(MachineClass
*mc
)
1066 ccw_machine_4_2_class_options(mc
);
1067 compat_props_add(mc
->compat_props
, hw_compat_4_1
, hw_compat_4_1_len
);
1069 DEFINE_CCW_MACHINE(4_1
, "4.1", false);
1071 static void ccw_machine_4_0_instance_options(MachineState
*machine
)
1073 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_0
};
1074 ccw_machine_4_1_instance_options(machine
);
1075 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
1078 static void ccw_machine_4_0_class_options(MachineClass
*mc
)
1080 ccw_machine_4_1_class_options(mc
);
1081 compat_props_add(mc
->compat_props
, hw_compat_4_0
, hw_compat_4_0_len
);
1083 DEFINE_CCW_MACHINE(4_0
, "4.0", false);
1085 static void ccw_machine_3_1_instance_options(MachineState
*machine
)
1087 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V3_1
};
1088 ccw_machine_4_0_instance_options(machine
);
1089 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH
);
1090 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF
);
1091 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
1094 static void ccw_machine_3_1_class_options(MachineClass
*mc
)
1096 ccw_machine_4_0_class_options(mc
);
1097 compat_props_add(mc
->compat_props
, hw_compat_3_1
, hw_compat_3_1_len
);
1099 DEFINE_CCW_MACHINE(3_1
, "3.1", false);
1101 static void ccw_machine_3_0_instance_options(MachineState
*machine
)
1103 ccw_machine_3_1_instance_options(machine
);
1106 static void ccw_machine_3_0_class_options(MachineClass
*mc
)
1108 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1110 s390mc
->hpage_1m_allowed
= false;
1111 ccw_machine_3_1_class_options(mc
);
1112 compat_props_add(mc
->compat_props
, hw_compat_3_0
, hw_compat_3_0_len
);
1114 DEFINE_CCW_MACHINE(3_0
, "3.0", false);
1116 static void ccw_machine_2_12_instance_options(MachineState
*machine
)
1118 ccw_machine_3_0_instance_options(machine
);
1119 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15
);
1120 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB
);
1123 static void ccw_machine_2_12_class_options(MachineClass
*mc
)
1125 ccw_machine_3_0_class_options(mc
);
1126 compat_props_add(mc
->compat_props
, hw_compat_2_12
, hw_compat_2_12_len
);
1128 DEFINE_CCW_MACHINE(2_12
, "2.12", false);
1130 static void ccw_machine_2_11_instance_options(MachineState
*machine
)
1132 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V2_11
};
1133 ccw_machine_2_12_instance_options(machine
);
1135 /* before 2.12 we emulated the very first z900 */
1136 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat
);
1139 static void ccw_machine_2_11_class_options(MachineClass
*mc
)
1141 static GlobalProperty compat
[] = {
1142 { TYPE_SCLP_EVENT_FACILITY
, "allow_all_mask_sizes", "off", },
1145 ccw_machine_2_12_class_options(mc
);
1146 compat_props_add(mc
->compat_props
, hw_compat_2_11
, hw_compat_2_11_len
);
1147 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1149 DEFINE_CCW_MACHINE(2_11
, "2.11", false);
1151 static void ccw_machine_2_10_instance_options(MachineState
*machine
)
1153 ccw_machine_2_11_instance_options(machine
);
1156 static void ccw_machine_2_10_class_options(MachineClass
*mc
)
1158 ccw_machine_2_11_class_options(mc
);
1159 compat_props_add(mc
->compat_props
, hw_compat_2_10
, hw_compat_2_10_len
);
1161 DEFINE_CCW_MACHINE(2_10
, "2.10", false);
1163 static void ccw_machine_2_9_instance_options(MachineState
*machine
)
1165 ccw_machine_2_10_instance_options(machine
);
1166 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP
);
1167 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2
);
1168 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI
);
1169 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION
);
1170 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION
);
1173 static void ccw_machine_2_9_class_options(MachineClass
*mc
)
1175 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1176 static GlobalProperty compat
[] = {
1177 { TYPE_S390_STATTRIB
, "migration-enabled", "off", },
1180 ccw_machine_2_10_class_options(mc
);
1181 compat_props_add(mc
->compat_props
, hw_compat_2_9
, hw_compat_2_9_len
);
1182 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1183 s390mc
->css_migration_enabled
= false;
1185 DEFINE_CCW_MACHINE(2_9
, "2.9", false);
1187 static void ccw_machine_2_8_instance_options(MachineState
*machine
)
1189 ccw_machine_2_9_instance_options(machine
);
1192 static void ccw_machine_2_8_class_options(MachineClass
*mc
)
1194 static GlobalProperty compat
[] = {
1195 { TYPE_S390_FLIC_COMMON
, "adapter_routes_max_batch", "64", },
1198 ccw_machine_2_9_class_options(mc
);
1199 compat_props_add(mc
->compat_props
, hw_compat_2_8
, hw_compat_2_8_len
);
1200 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1202 DEFINE_CCW_MACHINE(2_8
, "2.8", false);
1204 static void ccw_machine_2_7_instance_options(MachineState
*machine
)
1206 ccw_machine_2_8_instance_options(machine
);
1209 static void ccw_machine_2_7_class_options(MachineClass
*mc
)
1211 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1213 s390mc
->cpu_model_allowed
= false;
1214 ccw_machine_2_8_class_options(mc
);
1215 compat_props_add(mc
->compat_props
, hw_compat_2_7
, hw_compat_2_7_len
);
1217 DEFINE_CCW_MACHINE(2_7
, "2.7", false);
1219 static void ccw_machine_2_6_instance_options(MachineState
*machine
)
1221 ccw_machine_2_7_instance_options(machine
);
1224 static void ccw_machine_2_6_class_options(MachineClass
*mc
)
1226 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1227 static GlobalProperty compat
[] = {
1228 { TYPE_S390_IPL
, "iplbext_migration", "off", },
1229 { TYPE_VIRTUAL_CSS_BRIDGE
, "css_dev_path", "off", },
1232 s390mc
->ri_allowed
= false;
1233 ccw_machine_2_7_class_options(mc
);
1234 compat_props_add(mc
->compat_props
, hw_compat_2_6
, hw_compat_2_6_len
);
1235 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1237 DEFINE_CCW_MACHINE(2_6
, "2.6", false);
1239 static void ccw_machine_2_5_instance_options(MachineState
*machine
)
1241 ccw_machine_2_6_instance_options(machine
);
1244 static void ccw_machine_2_5_class_options(MachineClass
*mc
)
1246 ccw_machine_2_6_class_options(mc
);
1247 compat_props_add(mc
->compat_props
, hw_compat_2_5
, hw_compat_2_5_len
);
1249 DEFINE_CCW_MACHINE(2_5
, "2.5", false);
1251 static void ccw_machine_2_4_instance_options(MachineState
*machine
)
1253 ccw_machine_2_5_instance_options(machine
);
1256 static void ccw_machine_2_4_class_options(MachineClass
*mc
)
1258 static GlobalProperty compat
[] = {
1259 { TYPE_S390_SKEYS
, "migration-enabled", "off", },
1260 { "virtio-blk-ccw", "max_revision", "0", },
1261 { "virtio-balloon-ccw", "max_revision", "0", },
1262 { "virtio-serial-ccw", "max_revision", "0", },
1263 { "virtio-9p-ccw", "max_revision", "0", },
1264 { "virtio-rng-ccw", "max_revision", "0", },
1265 { "virtio-net-ccw", "max_revision", "0", },
1266 { "virtio-scsi-ccw", "max_revision", "0", },
1267 { "vhost-scsi-ccw", "max_revision", "0", },
1270 ccw_machine_2_5_class_options(mc
);
1271 compat_props_add(mc
->compat_props
, hw_compat_2_4
, hw_compat_2_4_len
);
1272 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1274 DEFINE_CCW_MACHINE(2_4
, "2.4", false);
1276 static void ccw_machine_register_types(void)
1278 type_register_static(&ccw_machine_info
);
1281 type_init(ccw_machine_register_types
)