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 "hw/s390x/pv.h"
45 #include "migration/blocker.h"
47 static Error
*pv_mig_blocker
;
49 S390CPU
*s390_cpu_addr2state(uint16_t cpu_addr
)
51 static MachineState
*ms
;
54 ms
= MACHINE(qdev_get_machine());
55 g_assert(ms
->possible_cpus
);
58 /* CPU address corresponds to the core_id and the index */
59 if (cpu_addr
>= ms
->possible_cpus
->len
) {
62 return S390_CPU(ms
->possible_cpus
->cpus
[cpu_addr
].cpu
);
65 static S390CPU
*s390x_new_cpu(const char *typename
, uint32_t core_id
,
68 S390CPU
*cpu
= S390_CPU(object_new(typename
));
71 if (!object_property_set_int(OBJECT(cpu
), "core-id", core_id
, errp
)) {
74 if (!qdev_realize(DEVICE(cpu
), NULL
, errp
)) {
80 object_unref(OBJECT(cpu
));
84 static void s390_init_cpus(MachineState
*machine
)
86 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
89 /* initialize possible_cpus */
90 mc
->possible_cpu_arch_ids(machine
);
92 for (i
= 0; i
< machine
->smp
.cpus
; i
++) {
93 s390x_new_cpu(machine
->cpu_type
, i
, &error_fatal
);
97 static const char *const reset_dev_types
[] = {
98 TYPE_VIRTUAL_CSS_BRIDGE
,
99 "s390-sclp-event-facility",
102 TYPE_S390_PCI_HOST_BRIDGE
,
105 static void subsystem_reset(void)
110 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
111 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
118 static int virtio_ccw_hcall_notify(const uint64_t *args
)
120 uint64_t subch_id
= args
[0];
121 uint64_t queue
= args
[1];
123 int cssid
, ssid
, schid
, m
;
125 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
128 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
129 if (!sch
|| !css_subch_visible(sch
)) {
132 if (queue
>= VIRTIO_QUEUE_MAX
) {
135 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
140 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
142 uint64_t mem
= args
[0];
143 MachineState
*ms
= MACHINE(qdev_get_machine());
145 if (mem
< ms
->ram_size
) {
152 static void virtio_ccw_register_hcalls(void)
154 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
155 virtio_ccw_hcall_notify
);
156 /* Tolerate early printk. */
157 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
158 virtio_ccw_hcall_early_printk
);
161 static void s390_memory_init(MemoryRegion
*ram
)
163 MemoryRegion
*sysmem
= get_system_memory();
165 /* allocate RAM for core */
166 memory_region_add_subregion(sysmem
, 0, ram
);
169 * Configure the maximum page size. As no memory devices were created
170 * yet, this is the page size of initial memory only.
172 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal
);
173 /* Initialize storage key device */
175 /* Initialize storage attributes device */
176 s390_stattrib_init();
179 static void s390_init_ipl_dev(const char *kernel_filename
,
180 const char *kernel_cmdline
,
181 const char *initrd_filename
, const char *firmware
,
182 const char *netboot_fw
, bool enforce_bios
)
184 Object
*new = object_new(TYPE_S390_IPL
);
185 DeviceState
*dev
= DEVICE(new);
186 char *netboot_fw_prop
;
188 if (kernel_filename
) {
189 qdev_prop_set_string(dev
, "kernel", kernel_filename
);
191 if (initrd_filename
) {
192 qdev_prop_set_string(dev
, "initrd", initrd_filename
);
194 qdev_prop_set_string(dev
, "cmdline", kernel_cmdline
);
195 qdev_prop_set_string(dev
, "firmware", firmware
);
196 qdev_prop_set_bit(dev
, "enforce_bios", enforce_bios
);
197 netboot_fw_prop
= object_property_get_str(new, "netboot_fw", &error_abort
);
198 if (!strlen(netboot_fw_prop
)) {
199 qdev_prop_set_string(dev
, "netboot_fw", netboot_fw
);
201 g_free(netboot_fw_prop
);
202 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL
,
205 qdev_realize(dev
, NULL
, &error_fatal
);
208 static void s390_create_virtio_net(BusState
*bus
, const char *name
)
212 for (i
= 0; i
< nb_nics
; i
++) {
213 NICInfo
*nd
= &nd_table
[i
];
217 nd
->model
= g_strdup("virtio");
220 qemu_check_nic_model(nd
, "virtio");
222 dev
= qdev_new(name
);
223 qdev_set_nic_properties(dev
, nd
);
224 qdev_realize_and_unref(dev
, bus
, &error_fatal
);
228 static void s390_create_sclpconsole(const char *type
, Chardev
*chardev
)
232 dev
= qdev_new(type
);
233 qdev_prop_set_chr(dev
, "chardev", chardev
);
234 qdev_realize_and_unref(dev
, sclp_get_event_facility_bus(), &error_fatal
);
237 static void ccw_init(MachineState
*machine
)
240 VirtualCssBus
*css_bus
;
244 /* init memory + setup max page size. Required for the CPU model */
245 s390_memory_init(machine
->ram
);
247 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
248 s390_init_cpus(machine
);
250 /* Need CPU model to be determined before we can set up PV */
251 s390_pv_init(machine
->cgs
, &error_fatal
);
255 /* init the SIGP facility */
258 /* create AP bridge and bus(es) */
262 css_bus
= virtual_css_bus_init();
263 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
264 machine
->initrd_filename
,
265 machine
->firmware
?: "s390-ccw.img",
266 "s390-netboot.img", true);
268 dev
= qdev_new(TYPE_S390_PCI_HOST_BRIDGE
);
269 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
271 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
273 /* register hypercalls */
274 virtio_ccw_register_hcalls();
276 s390_enable_css_support(s390_cpu_addr2state(0));
278 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
281 if (css_migration_enabled()) {
282 css_register_vmstate();
285 /* Create VirtIO network adapters */
286 s390_create_virtio_net(BUS(css_bus
), "virtio-net-ccw");
290 s390_create_sclpconsole("sclpconsole", serial_hd(0));
293 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
296 /* init the TOD clock */
300 static void s390_cpu_plug(HotplugHandler
*hotplug_dev
,
301 DeviceState
*dev
, Error
**errp
)
303 MachineState
*ms
= MACHINE(hotplug_dev
);
304 S390CPU
*cpu
= S390_CPU(dev
);
306 g_assert(!ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
);
307 ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
= OBJECT(dev
);
309 if (dev
->hotplugged
) {
310 raise_irq_cpu_hotplug();
314 static inline void s390_do_cpu_ipl(CPUState
*cs
, run_on_cpu_data arg
)
316 S390CPU
*cpu
= S390_CPU(cs
);
318 s390_ipl_prepare_cpu(cpu
);
319 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
322 static void s390_machine_unprotect(S390CcwMachineState
*ms
)
324 s390_pv_vm_disable();
326 migrate_del_blocker(pv_mig_blocker
);
327 error_free_or_abort(&pv_mig_blocker
);
328 ram_block_discard_disable(false);
331 static int s390_machine_protect(S390CcwMachineState
*ms
)
333 Error
*local_err
= NULL
;
337 * Discarding of memory in RAM blocks does not work as expected with
338 * protected VMs. Sharing and unsharing pages would be required. Disable
339 * it for now, until until we have a solution to make at least Linux
340 * guests either support it (e.g., virtio-balloon) or fail gracefully.
342 rc
= ram_block_discard_disable(true);
344 error_report("protected VMs: cannot disable RAM discard");
348 error_setg(&pv_mig_blocker
,
349 "protected VMs are currently not migrateable.");
350 rc
= migrate_add_blocker(pv_mig_blocker
, &local_err
);
352 ram_block_discard_disable(false);
353 error_report_err(local_err
);
354 error_free_or_abort(&pv_mig_blocker
);
359 rc
= s390_pv_vm_enable();
361 ram_block_discard_disable(false);
362 migrate_del_blocker(pv_mig_blocker
);
363 error_free_or_abort(&pv_mig_blocker
);
369 /* Set SE header and unpack */
370 rc
= s390_ipl_prepare_pv_header();
376 rc
= s390_ipl_pv_unpack();
381 /* Verify integrity */
382 rc
= s390_pv_verify();
389 s390_machine_unprotect(ms
);
393 static void s390_pv_prepare_reset(S390CcwMachineState
*ms
)
400 /* Unsharing requires all cpus to be stopped */
402 s390_cpu_set_state(S390_CPU_STATE_STOPPED
, S390_CPU(cs
));
405 s390_pv_prep_reset();
408 static void s390_machine_reset(MachineState
*machine
)
410 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
411 enum s390_reset reset_type
;
415 /* get the reset parameters, reset them once done */
416 s390_ipl_get_reset_request(&cs
, &reset_type
);
418 /* all CPUs are paused and synchronized at this point */
423 switch (reset_type
) {
424 case S390_RESET_EXTERNAL
:
425 case S390_RESET_REIPL
:
427 s390_machine_unprotect(ms
);
430 qemu_devices_reset();
433 /* configure and start the ipl CPU only */
434 run_on_cpu(cs
, s390_do_cpu_ipl
, RUN_ON_CPU_NULL
);
436 case S390_RESET_MODIFIED_CLEAR
:
438 * Susbsystem reset needs to be done before we unshare memory
439 * and lose access to VIRTIO structures in guest memory.
443 s390_pv_prepare_reset(ms
);
445 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
447 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
449 case S390_RESET_LOAD_NORMAL
:
451 * Susbsystem reset needs to be done before we unshare memory
452 * and lose access to VIRTIO structures in guest memory.
455 s390_pv_prepare_reset(ms
);
460 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
462 run_on_cpu(cs
, s390_do_cpu_initial_reset
, RUN_ON_CPU_NULL
);
463 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
465 case S390_RESET_PV
: /* Subcode 10 */
473 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
475 run_on_cpu(cs
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
477 if (s390_machine_protect(ms
)) {
478 s390_pv_inject_reset_error(cs
);
480 * Continue after the diag308 so the guest knows something
483 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
487 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
490 g_assert_not_reached();
494 run_on_cpu(t
, s390_do_cpu_set_diag318
, RUN_ON_CPU_HOST_ULONG(0));
496 s390_ipl_clear_reset_request();
499 static void s390_machine_device_plug(HotplugHandler
*hotplug_dev
,
500 DeviceState
*dev
, Error
**errp
)
502 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
503 s390_cpu_plug(hotplug_dev
, dev
, errp
);
507 static void s390_machine_device_unplug_request(HotplugHandler
*hotplug_dev
,
508 DeviceState
*dev
, Error
**errp
)
510 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
511 error_setg(errp
, "CPU hot unplug not supported on this machine");
516 static CpuInstanceProperties
s390_cpu_index_to_props(MachineState
*ms
,
519 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
520 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
522 assert(cpu_index
< possible_cpus
->len
);
523 return possible_cpus
->cpus
[cpu_index
].props
;
526 static const CPUArchIdList
*s390_possible_cpu_arch_ids(MachineState
*ms
)
529 unsigned int max_cpus
= ms
->smp
.max_cpus
;
531 if (ms
->possible_cpus
) {
532 g_assert(ms
->possible_cpus
&& ms
->possible_cpus
->len
== max_cpus
);
533 return ms
->possible_cpus
;
536 ms
->possible_cpus
= g_malloc0(sizeof(CPUArchIdList
) +
537 sizeof(CPUArchId
) * max_cpus
);
538 ms
->possible_cpus
->len
= max_cpus
;
539 for (i
= 0; i
< ms
->possible_cpus
->len
; i
++) {
540 ms
->possible_cpus
->cpus
[i
].type
= ms
->cpu_type
;
541 ms
->possible_cpus
->cpus
[i
].vcpus_count
= 1;
542 ms
->possible_cpus
->cpus
[i
].arch_id
= i
;
543 ms
->possible_cpus
->cpus
[i
].props
.has_core_id
= true;
544 ms
->possible_cpus
->cpus
[i
].props
.core_id
= i
;
547 return ms
->possible_cpus
;
550 static HotplugHandler
*s390_get_hotplug_handler(MachineState
*machine
,
553 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
554 return HOTPLUG_HANDLER(machine
);
559 static void s390_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
561 CPUState
*cs
= qemu_get_cpu(cpu_index
);
563 s390_cpu_restart(S390_CPU(cs
));
566 static ram_addr_t
s390_fixup_ram_size(ram_addr_t sz
)
568 /* same logic as in sclp.c */
569 int increment_size
= 20;
572 while ((sz
>> increment_size
) > MAX_STORAGE_INCREMENTS
) {
575 newsz
= sz
>> increment_size
<< increment_size
;
578 qemu_printf("Ram size %" PRIu64
"MB was fixed up to %" PRIu64
579 "MB to match machine restrictions. Consider updating "
580 "the guest definition.\n", (uint64_t) (sz
/ MiB
),
581 (uint64_t) (newsz
/ MiB
));
586 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
588 MachineClass
*mc
= MACHINE_CLASS(oc
);
589 NMIClass
*nc
= NMI_CLASS(oc
);
590 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
591 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
593 s390mc
->ri_allowed
= true;
594 s390mc
->cpu_model_allowed
= true;
595 s390mc
->css_migration_enabled
= true;
596 s390mc
->hpage_1m_allowed
= true;
598 mc
->reset
= s390_machine_reset
;
599 mc
->block_default_type
= IF_VIRTIO
;
604 mc
->max_cpus
= S390_MAX_CPUS
;
605 mc
->has_hotpluggable_cpus
= true;
606 assert(!mc
->get_hotplug_handler
);
607 mc
->get_hotplug_handler
= s390_get_hotplug_handler
;
608 mc
->cpu_index_to_instance_props
= s390_cpu_index_to_props
;
609 mc
->possible_cpu_arch_ids
= s390_possible_cpu_arch_ids
;
610 /* it is overridden with 'host' cpu *in kvm_arch_init* */
611 mc
->default_cpu_type
= S390_CPU_TYPE_NAME("qemu");
612 hc
->plug
= s390_machine_device_plug
;
613 hc
->unplug_request
= s390_machine_device_unplug_request
;
614 nc
->nmi_monitor_handler
= s390_nmi
;
615 mc
->default_ram_id
= "s390.ram";
618 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
620 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
622 return ms
->aes_key_wrap
;
625 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
628 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
630 ms
->aes_key_wrap
= value
;
633 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
635 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
637 return ms
->dea_key_wrap
;
640 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
643 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
645 ms
->dea_key_wrap
= value
;
648 static S390CcwMachineClass
*current_mc
;
651 * Get the class of the s390-ccw-virtio machine that is currently in use.
652 * Note: libvirt is using the "none" machine to probe for the features of the
653 * host CPU, so in case this is called with the "none" machine, the function
654 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
655 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
656 * below return the correct default value for the "none" machine.
658 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
659 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
660 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
661 * CPU initialization and s390_has_feat() later should be sufficient.
663 static S390CcwMachineClass
*get_machine_class(void)
665 if (unlikely(!current_mc
)) {
667 * No s390 ccw machine was instantiated, we are likely to
668 * be called for the 'none' machine. The properties will
669 * have their after-initialization values.
671 current_mc
= S390_CCW_MACHINE_CLASS(
672 object_class_by_name(TYPE_S390_CCW_MACHINE
));
677 bool ri_allowed(void)
679 return get_machine_class()->ri_allowed
;
682 bool cpu_model_allowed(void)
684 return get_machine_class()->cpu_model_allowed
;
687 bool hpage_1m_allowed(void)
689 return get_machine_class()->hpage_1m_allowed
;
692 static char *machine_get_loadparm(Object
*obj
, Error
**errp
)
694 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
696 /* make a NUL-terminated string */
697 return g_strndup((char *) ms
->loadparm
, sizeof(ms
->loadparm
));
700 static void machine_set_loadparm(Object
*obj
, const char *val
, Error
**errp
)
702 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
705 for (i
= 0; i
< sizeof(ms
->loadparm
) && val
[i
]; i
++) {
706 uint8_t c
= qemu_toupper(val
[i
]); /* mimic HMC */
708 if (('A' <= c
&& c
<= 'Z') || ('0' <= c
&& c
<= '9') || (c
== '.') ||
712 error_setg(errp
, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
718 for (; i
< sizeof(ms
->loadparm
); i
++) {
719 ms
->loadparm
[i
] = ' '; /* pad right with spaces */
722 static inline void s390_machine_initfn(Object
*obj
)
724 object_property_add_bool(obj
, "aes-key-wrap",
725 machine_get_aes_key_wrap
,
726 machine_set_aes_key_wrap
);
727 object_property_set_description(obj
, "aes-key-wrap",
728 "enable/disable AES key wrapping using the CPACF wrapping key");
729 object_property_set_bool(obj
, "aes-key-wrap", true, NULL
);
731 object_property_add_bool(obj
, "dea-key-wrap",
732 machine_get_dea_key_wrap
,
733 machine_set_dea_key_wrap
);
734 object_property_set_description(obj
, "dea-key-wrap",
735 "enable/disable DEA key wrapping using the CPACF wrapping key");
736 object_property_set_bool(obj
, "dea-key-wrap", true, NULL
);
737 object_property_add_str(obj
, "loadparm",
738 machine_get_loadparm
, machine_set_loadparm
);
739 object_property_set_description(obj
, "loadparm",
740 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
741 " to upper case) to pass to machine loader, boot manager,"
742 " and guest kernel");
745 static const TypeInfo ccw_machine_info
= {
746 .name
= TYPE_S390_CCW_MACHINE
,
747 .parent
= TYPE_MACHINE
,
749 .instance_size
= sizeof(S390CcwMachineState
),
750 .instance_init
= s390_machine_initfn
,
751 .class_size
= sizeof(S390CcwMachineClass
),
752 .class_init
= ccw_machine_class_init
,
753 .interfaces
= (InterfaceInfo
[]) {
755 { TYPE_HOTPLUG_HANDLER
},
760 bool css_migration_enabled(void)
762 return get_machine_class()->css_migration_enabled
;
765 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
766 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
769 MachineClass *mc = MACHINE_CLASS(oc); \
770 ccw_machine_##suffix##_class_options(mc); \
771 mc->desc = "Virtual s390x machine (version " verstr ")"; \
773 mc->alias = "s390-ccw-virtio"; \
774 mc->is_default = true; \
777 static void ccw_machine_##suffix##_instance_init(Object *obj) \
779 MachineState *machine = MACHINE(obj); \
780 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
781 ccw_machine_##suffix##_instance_options(machine); \
783 static const TypeInfo ccw_machine_##suffix##_info = { \
784 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
785 .parent = TYPE_S390_CCW_MACHINE, \
786 .class_init = ccw_machine_##suffix##_class_init, \
787 .instance_init = ccw_machine_##suffix##_instance_init, \
789 static void ccw_machine_register_##suffix(void) \
791 type_register_static(&ccw_machine_##suffix##_info); \
793 type_init(ccw_machine_register_##suffix)
795 static void ccw_machine_7_1_instance_options(MachineState
*machine
)
799 static void ccw_machine_7_1_class_options(MachineClass
*mc
)
802 DEFINE_CCW_MACHINE(7_1
, "7.1", true);
804 static void ccw_machine_7_0_instance_options(MachineState
*machine
)
806 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_0
};
808 ccw_machine_7_1_instance_options(machine
);
809 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
812 static void ccw_machine_7_0_class_options(MachineClass
*mc
)
814 ccw_machine_7_1_class_options(mc
);
815 compat_props_add(mc
->compat_props
, hw_compat_7_0
, hw_compat_7_0_len
);
817 DEFINE_CCW_MACHINE(7_0
, "7.0", false);
819 static void ccw_machine_6_2_instance_options(MachineState
*machine
)
821 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_2
};
823 ccw_machine_7_0_instance_options(machine
);
824 s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat
);
827 static void ccw_machine_6_2_class_options(MachineClass
*mc
)
829 ccw_machine_7_0_class_options(mc
);
830 compat_props_add(mc
->compat_props
, hw_compat_6_2
, hw_compat_6_2_len
);
832 DEFINE_CCW_MACHINE(6_2
, "6.2", false);
834 static void ccw_machine_6_1_instance_options(MachineState
*machine
)
836 ccw_machine_6_2_instance_options(machine
);
837 s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA
);
838 s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2
);
839 s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH
);
840 s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP
);
841 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI
);
844 static void ccw_machine_6_1_class_options(MachineClass
*mc
)
846 ccw_machine_6_2_class_options(mc
);
847 compat_props_add(mc
->compat_props
, hw_compat_6_1
, hw_compat_6_1_len
);
848 mc
->smp_props
.prefer_sockets
= true;
850 DEFINE_CCW_MACHINE(6_1
, "6.1", false);
852 static void ccw_machine_6_0_instance_options(MachineState
*machine
)
854 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_0
};
856 ccw_machine_6_1_instance_options(machine
);
857 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
860 static void ccw_machine_6_0_class_options(MachineClass
*mc
)
862 ccw_machine_6_1_class_options(mc
);
863 compat_props_add(mc
->compat_props
, hw_compat_6_0
, hw_compat_6_0_len
);
865 DEFINE_CCW_MACHINE(6_0
, "6.0", false);
867 static void ccw_machine_5_2_instance_options(MachineState
*machine
)
869 ccw_machine_6_0_instance_options(machine
);
872 static void ccw_machine_5_2_class_options(MachineClass
*mc
)
874 ccw_machine_6_0_class_options(mc
);
875 compat_props_add(mc
->compat_props
, hw_compat_5_2
, hw_compat_5_2_len
);
877 DEFINE_CCW_MACHINE(5_2
, "5.2", false);
879 static void ccw_machine_5_1_instance_options(MachineState
*machine
)
881 ccw_machine_5_2_instance_options(machine
);
884 static void ccw_machine_5_1_class_options(MachineClass
*mc
)
886 ccw_machine_5_2_class_options(mc
);
887 compat_props_add(mc
->compat_props
, hw_compat_5_1
, hw_compat_5_1_len
);
889 DEFINE_CCW_MACHINE(5_1
, "5.1", false);
891 static void ccw_machine_5_0_instance_options(MachineState
*machine
)
893 ccw_machine_5_1_instance_options(machine
);
896 static void ccw_machine_5_0_class_options(MachineClass
*mc
)
898 ccw_machine_5_1_class_options(mc
);
899 compat_props_add(mc
->compat_props
, hw_compat_5_0
, hw_compat_5_0_len
);
901 DEFINE_CCW_MACHINE(5_0
, "5.0", false);
903 static void ccw_machine_4_2_instance_options(MachineState
*machine
)
905 ccw_machine_5_0_instance_options(machine
);
908 static void ccw_machine_4_2_class_options(MachineClass
*mc
)
910 ccw_machine_5_0_class_options(mc
);
911 mc
->fixup_ram_size
= s390_fixup_ram_size
;
912 compat_props_add(mc
->compat_props
, hw_compat_4_2
, hw_compat_4_2_len
);
914 DEFINE_CCW_MACHINE(4_2
, "4.2", false);
916 static void ccw_machine_4_1_instance_options(MachineState
*machine
)
918 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_1
};
919 ccw_machine_4_2_instance_options(machine
);
920 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
923 static void ccw_machine_4_1_class_options(MachineClass
*mc
)
925 ccw_machine_4_2_class_options(mc
);
926 compat_props_add(mc
->compat_props
, hw_compat_4_1
, hw_compat_4_1_len
);
928 DEFINE_CCW_MACHINE(4_1
, "4.1", false);
930 static void ccw_machine_4_0_instance_options(MachineState
*machine
)
932 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_0
};
933 ccw_machine_4_1_instance_options(machine
);
934 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
937 static void ccw_machine_4_0_class_options(MachineClass
*mc
)
939 ccw_machine_4_1_class_options(mc
);
940 compat_props_add(mc
->compat_props
, hw_compat_4_0
, hw_compat_4_0_len
);
942 DEFINE_CCW_MACHINE(4_0
, "4.0", false);
944 static void ccw_machine_3_1_instance_options(MachineState
*machine
)
946 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V3_1
};
947 ccw_machine_4_0_instance_options(machine
);
948 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH
);
949 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF
);
950 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
953 static void ccw_machine_3_1_class_options(MachineClass
*mc
)
955 ccw_machine_4_0_class_options(mc
);
956 compat_props_add(mc
->compat_props
, hw_compat_3_1
, hw_compat_3_1_len
);
958 DEFINE_CCW_MACHINE(3_1
, "3.1", false);
960 static void ccw_machine_3_0_instance_options(MachineState
*machine
)
962 ccw_machine_3_1_instance_options(machine
);
965 static void ccw_machine_3_0_class_options(MachineClass
*mc
)
967 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
969 s390mc
->hpage_1m_allowed
= false;
970 ccw_machine_3_1_class_options(mc
);
971 compat_props_add(mc
->compat_props
, hw_compat_3_0
, hw_compat_3_0_len
);
973 DEFINE_CCW_MACHINE(3_0
, "3.0", false);
975 static void ccw_machine_2_12_instance_options(MachineState
*machine
)
977 ccw_machine_3_0_instance_options(machine
);
978 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15
);
979 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB
);
982 static void ccw_machine_2_12_class_options(MachineClass
*mc
)
984 ccw_machine_3_0_class_options(mc
);
985 compat_props_add(mc
->compat_props
, hw_compat_2_12
, hw_compat_2_12_len
);
987 DEFINE_CCW_MACHINE(2_12
, "2.12", false);
989 static void ccw_machine_2_11_instance_options(MachineState
*machine
)
991 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V2_11
};
992 ccw_machine_2_12_instance_options(machine
);
994 /* before 2.12 we emulated the very first z900 */
995 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat
);
998 static void ccw_machine_2_11_class_options(MachineClass
*mc
)
1000 static GlobalProperty compat
[] = {
1001 { TYPE_SCLP_EVENT_FACILITY
, "allow_all_mask_sizes", "off", },
1004 ccw_machine_2_12_class_options(mc
);
1005 compat_props_add(mc
->compat_props
, hw_compat_2_11
, hw_compat_2_11_len
);
1006 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1008 DEFINE_CCW_MACHINE(2_11
, "2.11", false);
1010 static void ccw_machine_2_10_instance_options(MachineState
*machine
)
1012 ccw_machine_2_11_instance_options(machine
);
1015 static void ccw_machine_2_10_class_options(MachineClass
*mc
)
1017 ccw_machine_2_11_class_options(mc
);
1018 compat_props_add(mc
->compat_props
, hw_compat_2_10
, hw_compat_2_10_len
);
1020 DEFINE_CCW_MACHINE(2_10
, "2.10", false);
1022 static void ccw_machine_2_9_instance_options(MachineState
*machine
)
1024 ccw_machine_2_10_instance_options(machine
);
1025 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP
);
1026 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2
);
1027 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI
);
1028 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION
);
1029 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION
);
1032 static void ccw_machine_2_9_class_options(MachineClass
*mc
)
1034 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1035 static GlobalProperty compat
[] = {
1036 { TYPE_S390_STATTRIB
, "migration-enabled", "off", },
1039 ccw_machine_2_10_class_options(mc
);
1040 compat_props_add(mc
->compat_props
, hw_compat_2_9
, hw_compat_2_9_len
);
1041 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1042 s390mc
->css_migration_enabled
= false;
1044 DEFINE_CCW_MACHINE(2_9
, "2.9", false);
1046 static void ccw_machine_2_8_instance_options(MachineState
*machine
)
1048 ccw_machine_2_9_instance_options(machine
);
1051 static void ccw_machine_2_8_class_options(MachineClass
*mc
)
1053 static GlobalProperty compat
[] = {
1054 { TYPE_S390_FLIC_COMMON
, "adapter_routes_max_batch", "64", },
1057 ccw_machine_2_9_class_options(mc
);
1058 compat_props_add(mc
->compat_props
, hw_compat_2_8
, hw_compat_2_8_len
);
1059 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1061 DEFINE_CCW_MACHINE(2_8
, "2.8", false);
1063 static void ccw_machine_2_7_instance_options(MachineState
*machine
)
1065 ccw_machine_2_8_instance_options(machine
);
1068 static void ccw_machine_2_7_class_options(MachineClass
*mc
)
1070 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1072 s390mc
->cpu_model_allowed
= false;
1073 ccw_machine_2_8_class_options(mc
);
1074 compat_props_add(mc
->compat_props
, hw_compat_2_7
, hw_compat_2_7_len
);
1076 DEFINE_CCW_MACHINE(2_7
, "2.7", false);
1078 static void ccw_machine_2_6_instance_options(MachineState
*machine
)
1080 ccw_machine_2_7_instance_options(machine
);
1083 static void ccw_machine_2_6_class_options(MachineClass
*mc
)
1085 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1086 static GlobalProperty compat
[] = {
1087 { TYPE_S390_IPL
, "iplbext_migration", "off", },
1088 { TYPE_VIRTUAL_CSS_BRIDGE
, "css_dev_path", "off", },
1091 s390mc
->ri_allowed
= false;
1092 ccw_machine_2_7_class_options(mc
);
1093 compat_props_add(mc
->compat_props
, hw_compat_2_6
, hw_compat_2_6_len
);
1094 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1096 DEFINE_CCW_MACHINE(2_6
, "2.6", false);
1098 static void ccw_machine_2_5_instance_options(MachineState
*machine
)
1100 ccw_machine_2_6_instance_options(machine
);
1103 static void ccw_machine_2_5_class_options(MachineClass
*mc
)
1105 ccw_machine_2_6_class_options(mc
);
1106 compat_props_add(mc
->compat_props
, hw_compat_2_5
, hw_compat_2_5_len
);
1108 DEFINE_CCW_MACHINE(2_5
, "2.5", false);
1110 static void ccw_machine_2_4_instance_options(MachineState
*machine
)
1112 ccw_machine_2_5_instance_options(machine
);
1115 static void ccw_machine_2_4_class_options(MachineClass
*mc
)
1117 static GlobalProperty compat
[] = {
1118 { TYPE_S390_SKEYS
, "migration-enabled", "off", },
1119 { "virtio-blk-ccw", "max_revision", "0", },
1120 { "virtio-balloon-ccw", "max_revision", "0", },
1121 { "virtio-serial-ccw", "max_revision", "0", },
1122 { "virtio-9p-ccw", "max_revision", "0", },
1123 { "virtio-rng-ccw", "max_revision", "0", },
1124 { "virtio-net-ccw", "max_revision", "0", },
1125 { "virtio-scsi-ccw", "max_revision", "0", },
1126 { "vhost-scsi-ccw", "max_revision", "0", },
1129 ccw_machine_2_5_class_options(mc
);
1130 compat_props_add(mc
->compat_props
, hw_compat_2_4
, hw_compat_2_4_len
);
1131 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1133 DEFINE_CCW_MACHINE(2_4
, "2.4", false);
1135 static void ccw_machine_register_types(void)
1137 type_register_static(&ccw_machine_info
);
1140 type_init(ccw_machine_register_types
)