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 "hw/s390x/s390-pci-bus.h"
29 #include "sysemu/reset.h"
30 #include "hw/s390x/storage-keys.h"
31 #include "hw/s390x/storage-attributes.h"
32 #include "hw/s390x/event-facility.h"
34 #include "hw/s390x/s390-virtio-ccw.h"
35 #include "hw/s390x/css-bridge.h"
36 #include "hw/s390x/ap-bridge.h"
37 #include "migration/register.h"
38 #include "cpu_models.h"
40 #include "hw/qdev-properties.h"
41 #include "hw/s390x/tod.h"
42 #include "sysemu/sysemu.h"
43 #include "hw/s390x/pv.h"
44 #include "migration/blocker.h"
46 static Error
*pv_mig_blocker
;
48 S390CPU
*s390_cpu_addr2state(uint16_t cpu_addr
)
50 static MachineState
*ms
;
53 ms
= MACHINE(qdev_get_machine());
54 g_assert(ms
->possible_cpus
);
57 /* CPU address corresponds to the core_id and the index */
58 if (cpu_addr
>= ms
->possible_cpus
->len
) {
61 return S390_CPU(ms
->possible_cpus
->cpus
[cpu_addr
].cpu
);
64 static S390CPU
*s390x_new_cpu(const char *typename
, uint32_t core_id
,
67 S390CPU
*cpu
= S390_CPU(object_new(typename
));
70 if (!object_property_set_int(OBJECT(cpu
), "core-id", core_id
, errp
)) {
73 if (!qdev_realize(DEVICE(cpu
), NULL
, errp
)) {
79 object_unref(OBJECT(cpu
));
83 static void s390_init_cpus(MachineState
*machine
)
85 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
88 /* initialize possible_cpus */
89 mc
->possible_cpu_arch_ids(machine
);
91 for (i
= 0; i
< machine
->smp
.cpus
; i
++) {
92 s390x_new_cpu(machine
->cpu_type
, i
, &error_fatal
);
96 static const char *const reset_dev_types
[] = {
97 TYPE_VIRTUAL_CSS_BRIDGE
,
98 "s390-sclp-event-facility",
101 TYPE_S390_PCI_HOST_BRIDGE
,
104 static void subsystem_reset(void)
109 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
110 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
117 static int virtio_ccw_hcall_notify(const uint64_t *args
)
119 uint64_t subch_id
= args
[0];
120 uint64_t queue
= args
[1];
122 int cssid
, ssid
, schid
, m
;
124 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
127 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
128 if (!sch
|| !css_subch_visible(sch
)) {
131 if (queue
>= VIRTIO_QUEUE_MAX
) {
134 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
139 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
141 uint64_t mem
= args
[0];
142 MachineState
*ms
= MACHINE(qdev_get_machine());
144 if (mem
< ms
->ram_size
) {
151 static void virtio_ccw_register_hcalls(void)
153 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
154 virtio_ccw_hcall_notify
);
155 /* Tolerate early printk. */
156 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
157 virtio_ccw_hcall_early_printk
);
160 static void s390_memory_init(MemoryRegion
*ram
)
162 MemoryRegion
*sysmem
= get_system_memory();
164 /* allocate RAM for core */
165 memory_region_add_subregion(sysmem
, 0, ram
);
168 * Configure the maximum page size. As no memory devices were created
169 * yet, this is the page size of initial memory only.
171 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal
);
172 /* Initialize storage key device */
174 /* Initialize storage attributes device */
175 s390_stattrib_init();
178 static void s390_init_ipl_dev(const char *kernel_filename
,
179 const char *kernel_cmdline
,
180 const char *initrd_filename
, const char *firmware
,
181 const char *netboot_fw
, bool enforce_bios
)
183 Object
*new = object_new(TYPE_S390_IPL
);
184 DeviceState
*dev
= DEVICE(new);
185 char *netboot_fw_prop
;
187 if (kernel_filename
) {
188 qdev_prop_set_string(dev
, "kernel", kernel_filename
);
190 if (initrd_filename
) {
191 qdev_prop_set_string(dev
, "initrd", initrd_filename
);
193 qdev_prop_set_string(dev
, "cmdline", kernel_cmdline
);
194 qdev_prop_set_string(dev
, "firmware", firmware
);
195 qdev_prop_set_bit(dev
, "enforce_bios", enforce_bios
);
196 netboot_fw_prop
= object_property_get_str(new, "netboot_fw", &error_abort
);
197 if (!strlen(netboot_fw_prop
)) {
198 qdev_prop_set_string(dev
, "netboot_fw", netboot_fw
);
200 g_free(netboot_fw_prop
);
201 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL
,
204 qdev_realize(dev
, NULL
, &error_fatal
);
207 static void s390_create_virtio_net(BusState
*bus
, const char *name
)
211 for (i
= 0; i
< nb_nics
; i
++) {
212 NICInfo
*nd
= &nd_table
[i
];
216 nd
->model
= g_strdup("virtio");
219 qemu_check_nic_model(nd
, "virtio");
221 dev
= qdev_new(name
);
222 qdev_set_nic_properties(dev
, nd
);
223 qdev_realize_and_unref(dev
, bus
, &error_fatal
);
227 static void s390_create_sclpconsole(const char *type
, Chardev
*chardev
)
231 dev
= qdev_new(type
);
232 qdev_prop_set_chr(dev
, "chardev", chardev
);
233 qdev_realize_and_unref(dev
, sclp_get_event_facility_bus(), &error_fatal
);
236 static void ccw_init(MachineState
*machine
)
239 VirtualCssBus
*css_bus
;
243 /* init memory + setup max page size. Required for the CPU model */
244 s390_memory_init(machine
->ram
);
246 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
247 s390_init_cpus(machine
);
249 /* Need CPU model to be determined before we can set up PV */
250 s390_pv_init(machine
->cgs
, &error_fatal
);
254 /* init the SIGP facility */
257 /* create AP bridge and bus(es) */
261 css_bus
= virtual_css_bus_init();
262 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
263 machine
->initrd_filename
,
264 machine
->firmware
?: "s390-ccw.img",
265 "s390-netboot.img", true);
267 dev
= qdev_new(TYPE_S390_PCI_HOST_BRIDGE
);
268 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
270 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
272 /* register hypercalls */
273 virtio_ccw_register_hcalls();
275 s390_enable_css_support(s390_cpu_addr2state(0));
277 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
280 if (css_migration_enabled()) {
281 css_register_vmstate();
284 /* Create VirtIO network adapters */
285 s390_create_virtio_net(BUS(css_bus
), "virtio-net-ccw");
289 s390_create_sclpconsole("sclpconsole", serial_hd(0));
292 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
295 /* init the TOD clock */
299 static void s390_cpu_plug(HotplugHandler
*hotplug_dev
,
300 DeviceState
*dev
, Error
**errp
)
302 MachineState
*ms
= MACHINE(hotplug_dev
);
303 S390CPU
*cpu
= S390_CPU(dev
);
305 g_assert(!ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
);
306 ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
= OBJECT(dev
);
308 if (dev
->hotplugged
) {
309 raise_irq_cpu_hotplug();
313 static inline void s390_do_cpu_ipl(CPUState
*cs
, run_on_cpu_data arg
)
315 S390CPU
*cpu
= S390_CPU(cs
);
317 s390_ipl_prepare_cpu(cpu
);
318 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
321 static void s390_machine_unprotect(S390CcwMachineState
*ms
)
323 s390_pv_vm_disable();
325 migrate_del_blocker(pv_mig_blocker
);
326 error_free_or_abort(&pv_mig_blocker
);
327 ram_block_discard_disable(false);
330 static int s390_machine_protect(S390CcwMachineState
*ms
)
332 Error
*local_err
= NULL
;
336 * Discarding of memory in RAM blocks does not work as expected with
337 * protected VMs. Sharing and unsharing pages would be required. Disable
338 * it for now, until until we have a solution to make at least Linux
339 * guests either support it (e.g., virtio-balloon) or fail gracefully.
341 rc
= ram_block_discard_disable(true);
343 error_report("protected VMs: cannot disable RAM discard");
347 error_setg(&pv_mig_blocker
,
348 "protected VMs are currently not migrateable.");
349 rc
= migrate_add_blocker(pv_mig_blocker
, &local_err
);
351 ram_block_discard_disable(false);
352 error_report_err(local_err
);
353 error_free_or_abort(&pv_mig_blocker
);
358 rc
= s390_pv_vm_enable();
360 ram_block_discard_disable(false);
361 migrate_del_blocker(pv_mig_blocker
);
362 error_free_or_abort(&pv_mig_blocker
);
368 /* Set SE header and unpack */
369 rc
= s390_ipl_prepare_pv_header();
375 rc
= s390_ipl_pv_unpack();
380 /* Verify integrity */
381 rc
= s390_pv_verify();
388 s390_machine_unprotect(ms
);
392 static void s390_pv_prepare_reset(S390CcwMachineState
*ms
)
399 /* Unsharing requires all cpus to be stopped */
401 s390_cpu_set_state(S390_CPU_STATE_STOPPED
, S390_CPU(cs
));
404 s390_pv_prep_reset();
407 static void s390_machine_reset(MachineState
*machine
)
409 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
410 enum s390_reset reset_type
;
414 /* get the reset parameters, reset them once done */
415 s390_ipl_get_reset_request(&cs
, &reset_type
);
417 /* all CPUs are paused and synchronized at this point */
422 switch (reset_type
) {
423 case S390_RESET_EXTERNAL
:
424 case S390_RESET_REIPL
:
426 s390_machine_unprotect(ms
);
429 qemu_devices_reset();
432 /* configure and start the ipl CPU only */
433 run_on_cpu(cs
, s390_do_cpu_ipl
, RUN_ON_CPU_NULL
);
435 case S390_RESET_MODIFIED_CLEAR
:
437 * Susbsystem reset needs to be done before we unshare memory
438 * and lose access to VIRTIO structures in guest memory.
442 s390_pv_prepare_reset(ms
);
444 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
446 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
448 case S390_RESET_LOAD_NORMAL
:
450 * Susbsystem reset needs to be done before we unshare memory
451 * and lose access to VIRTIO structures in guest memory.
454 s390_pv_prepare_reset(ms
);
459 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
461 run_on_cpu(cs
, s390_do_cpu_initial_reset
, RUN_ON_CPU_NULL
);
462 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
464 case S390_RESET_PV
: /* Subcode 10 */
472 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
474 run_on_cpu(cs
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
476 if (s390_machine_protect(ms
)) {
477 s390_pv_inject_reset_error(cs
);
479 * Continue after the diag308 so the guest knows something
482 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
486 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
489 g_assert_not_reached();
493 run_on_cpu(t
, s390_do_cpu_set_diag318
, RUN_ON_CPU_HOST_ULONG(0));
495 s390_ipl_clear_reset_request();
498 static void s390_machine_device_plug(HotplugHandler
*hotplug_dev
,
499 DeviceState
*dev
, Error
**errp
)
501 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
502 s390_cpu_plug(hotplug_dev
, dev
, errp
);
506 static void s390_machine_device_unplug_request(HotplugHandler
*hotplug_dev
,
507 DeviceState
*dev
, Error
**errp
)
509 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
510 error_setg(errp
, "CPU hot unplug not supported on this machine");
515 static CpuInstanceProperties
s390_cpu_index_to_props(MachineState
*ms
,
518 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
519 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
521 assert(cpu_index
< possible_cpus
->len
);
522 return possible_cpus
->cpus
[cpu_index
].props
;
525 static const CPUArchIdList
*s390_possible_cpu_arch_ids(MachineState
*ms
)
528 unsigned int max_cpus
= ms
->smp
.max_cpus
;
530 if (ms
->possible_cpus
) {
531 g_assert(ms
->possible_cpus
&& ms
->possible_cpus
->len
== max_cpus
);
532 return ms
->possible_cpus
;
535 ms
->possible_cpus
= g_malloc0(sizeof(CPUArchIdList
) +
536 sizeof(CPUArchId
) * max_cpus
);
537 ms
->possible_cpus
->len
= max_cpus
;
538 for (i
= 0; i
< ms
->possible_cpus
->len
; i
++) {
539 ms
->possible_cpus
->cpus
[i
].type
= ms
->cpu_type
;
540 ms
->possible_cpus
->cpus
[i
].vcpus_count
= 1;
541 ms
->possible_cpus
->cpus
[i
].arch_id
= i
;
542 ms
->possible_cpus
->cpus
[i
].props
.has_core_id
= true;
543 ms
->possible_cpus
->cpus
[i
].props
.core_id
= i
;
546 return ms
->possible_cpus
;
549 static HotplugHandler
*s390_get_hotplug_handler(MachineState
*machine
,
552 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
553 return HOTPLUG_HANDLER(machine
);
558 static void s390_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
560 CPUState
*cs
= qemu_get_cpu(cpu_index
);
562 s390_cpu_restart(S390_CPU(cs
));
565 static ram_addr_t
s390_fixup_ram_size(ram_addr_t sz
)
567 /* same logic as in sclp.c */
568 int increment_size
= 20;
571 while ((sz
>> increment_size
) > MAX_STORAGE_INCREMENTS
) {
574 newsz
= sz
>> increment_size
<< increment_size
;
577 qemu_printf("Ram size %" PRIu64
"MB was fixed up to %" PRIu64
578 "MB to match machine restrictions. Consider updating "
579 "the guest definition.\n", (uint64_t) (sz
/ MiB
),
580 (uint64_t) (newsz
/ MiB
));
585 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
587 MachineClass
*mc
= MACHINE_CLASS(oc
);
588 NMIClass
*nc
= NMI_CLASS(oc
);
589 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
590 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
592 s390mc
->ri_allowed
= true;
593 s390mc
->cpu_model_allowed
= true;
594 s390mc
->css_migration_enabled
= true;
595 s390mc
->hpage_1m_allowed
= true;
597 mc
->reset
= s390_machine_reset
;
598 mc
->block_default_type
= IF_VIRTIO
;
603 mc
->max_cpus
= S390_MAX_CPUS
;
604 mc
->has_hotpluggable_cpus
= true;
605 assert(!mc
->get_hotplug_handler
);
606 mc
->get_hotplug_handler
= s390_get_hotplug_handler
;
607 mc
->cpu_index_to_instance_props
= s390_cpu_index_to_props
;
608 mc
->possible_cpu_arch_ids
= s390_possible_cpu_arch_ids
;
609 /* it is overridden with 'host' cpu *in kvm_arch_init* */
610 mc
->default_cpu_type
= S390_CPU_TYPE_NAME("qemu");
611 hc
->plug
= s390_machine_device_plug
;
612 hc
->unplug_request
= s390_machine_device_unplug_request
;
613 nc
->nmi_monitor_handler
= s390_nmi
;
614 mc
->default_ram_id
= "s390.ram";
617 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
619 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
621 return ms
->aes_key_wrap
;
624 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
627 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
629 ms
->aes_key_wrap
= value
;
632 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
634 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
636 return ms
->dea_key_wrap
;
639 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
642 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
644 ms
->dea_key_wrap
= value
;
647 static S390CcwMachineClass
*current_mc
;
650 * Get the class of the s390-ccw-virtio machine that is currently in use.
651 * Note: libvirt is using the "none" machine to probe for the features of the
652 * host CPU, so in case this is called with the "none" machine, the function
653 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
654 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
655 * below return the correct default value for the "none" machine.
657 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
658 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
659 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
660 * CPU initialization and s390_has_feat() later should be sufficient.
662 static S390CcwMachineClass
*get_machine_class(void)
664 if (unlikely(!current_mc
)) {
666 * No s390 ccw machine was instantiated, we are likely to
667 * be called for the 'none' machine. The properties will
668 * have their after-initialization values.
670 current_mc
= S390_CCW_MACHINE_CLASS(
671 object_class_by_name(TYPE_S390_CCW_MACHINE
));
676 bool ri_allowed(void)
678 return get_machine_class()->ri_allowed
;
681 bool cpu_model_allowed(void)
683 return get_machine_class()->cpu_model_allowed
;
686 bool hpage_1m_allowed(void)
688 return get_machine_class()->hpage_1m_allowed
;
691 static char *machine_get_loadparm(Object
*obj
, Error
**errp
)
693 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
695 /* make a NUL-terminated string */
696 return g_strndup((char *) ms
->loadparm
, sizeof(ms
->loadparm
));
699 static void machine_set_loadparm(Object
*obj
, const char *val
, Error
**errp
)
701 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
704 for (i
= 0; i
< sizeof(ms
->loadparm
) && val
[i
]; i
++) {
705 uint8_t c
= qemu_toupper(val
[i
]); /* mimic HMC */
707 if (('A' <= c
&& c
<= 'Z') || ('0' <= c
&& c
<= '9') || (c
== '.') ||
711 error_setg(errp
, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
717 for (; i
< sizeof(ms
->loadparm
); i
++) {
718 ms
->loadparm
[i
] = ' '; /* pad right with spaces */
721 static inline void s390_machine_initfn(Object
*obj
)
723 object_property_add_bool(obj
, "aes-key-wrap",
724 machine_get_aes_key_wrap
,
725 machine_set_aes_key_wrap
);
726 object_property_set_description(obj
, "aes-key-wrap",
727 "enable/disable AES key wrapping using the CPACF wrapping key");
728 object_property_set_bool(obj
, "aes-key-wrap", true, NULL
);
730 object_property_add_bool(obj
, "dea-key-wrap",
731 machine_get_dea_key_wrap
,
732 machine_set_dea_key_wrap
);
733 object_property_set_description(obj
, "dea-key-wrap",
734 "enable/disable DEA key wrapping using the CPACF wrapping key");
735 object_property_set_bool(obj
, "dea-key-wrap", true, NULL
);
736 object_property_add_str(obj
, "loadparm",
737 machine_get_loadparm
, machine_set_loadparm
);
738 object_property_set_description(obj
, "loadparm",
739 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
740 " to upper case) to pass to machine loader, boot manager,"
741 " and guest kernel");
744 static const TypeInfo ccw_machine_info
= {
745 .name
= TYPE_S390_CCW_MACHINE
,
746 .parent
= TYPE_MACHINE
,
748 .instance_size
= sizeof(S390CcwMachineState
),
749 .instance_init
= s390_machine_initfn
,
750 .class_size
= sizeof(S390CcwMachineClass
),
751 .class_init
= ccw_machine_class_init
,
752 .interfaces
= (InterfaceInfo
[]) {
754 { TYPE_HOTPLUG_HANDLER
},
759 bool css_migration_enabled(void)
761 return get_machine_class()->css_migration_enabled
;
764 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
765 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
768 MachineClass *mc = MACHINE_CLASS(oc); \
769 ccw_machine_##suffix##_class_options(mc); \
770 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
772 mc->alias = "s390-ccw-virtio"; \
773 mc->is_default = true; \
776 static void ccw_machine_##suffix##_instance_init(Object *obj) \
778 MachineState *machine = MACHINE(obj); \
779 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
780 ccw_machine_##suffix##_instance_options(machine); \
782 static const TypeInfo ccw_machine_##suffix##_info = { \
783 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
784 .parent = TYPE_S390_CCW_MACHINE, \
785 .class_init = ccw_machine_##suffix##_class_init, \
786 .instance_init = ccw_machine_##suffix##_instance_init, \
788 static void ccw_machine_register_##suffix(void) \
790 type_register_static(&ccw_machine_##suffix##_info); \
792 type_init(ccw_machine_register_##suffix)
794 static void ccw_machine_6_1_instance_options(MachineState
*machine
)
798 static void ccw_machine_6_1_class_options(MachineClass
*mc
)
801 DEFINE_CCW_MACHINE(6_1
, "6.1", true);
803 static void ccw_machine_6_0_instance_options(MachineState
*machine
)
805 ccw_machine_6_1_instance_options(machine
);
808 static void ccw_machine_6_0_class_options(MachineClass
*mc
)
810 ccw_machine_6_1_class_options(mc
);
811 compat_props_add(mc
->compat_props
, hw_compat_6_0
, hw_compat_6_0_len
);
813 DEFINE_CCW_MACHINE(6_0
, "6.0", false);
815 static void ccw_machine_5_2_instance_options(MachineState
*machine
)
817 ccw_machine_6_0_instance_options(machine
);
820 static void ccw_machine_5_2_class_options(MachineClass
*mc
)
822 ccw_machine_6_0_class_options(mc
);
823 compat_props_add(mc
->compat_props
, hw_compat_5_2
, hw_compat_5_2_len
);
825 DEFINE_CCW_MACHINE(5_2
, "5.2", false);
827 static void ccw_machine_5_1_instance_options(MachineState
*machine
)
829 ccw_machine_5_2_instance_options(machine
);
832 static void ccw_machine_5_1_class_options(MachineClass
*mc
)
834 ccw_machine_5_2_class_options(mc
);
835 compat_props_add(mc
->compat_props
, hw_compat_5_1
, hw_compat_5_1_len
);
837 DEFINE_CCW_MACHINE(5_1
, "5.1", false);
839 static void ccw_machine_5_0_instance_options(MachineState
*machine
)
841 ccw_machine_5_1_instance_options(machine
);
844 static void ccw_machine_5_0_class_options(MachineClass
*mc
)
846 ccw_machine_5_1_class_options(mc
);
847 compat_props_add(mc
->compat_props
, hw_compat_5_0
, hw_compat_5_0_len
);
849 DEFINE_CCW_MACHINE(5_0
, "5.0", false);
851 static void ccw_machine_4_2_instance_options(MachineState
*machine
)
853 ccw_machine_5_0_instance_options(machine
);
856 static void ccw_machine_4_2_class_options(MachineClass
*mc
)
858 ccw_machine_5_0_class_options(mc
);
859 mc
->fixup_ram_size
= s390_fixup_ram_size
;
860 compat_props_add(mc
->compat_props
, hw_compat_4_2
, hw_compat_4_2_len
);
862 DEFINE_CCW_MACHINE(4_2
, "4.2", false);
864 static void ccw_machine_4_1_instance_options(MachineState
*machine
)
866 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_1
};
867 ccw_machine_4_2_instance_options(machine
);
868 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
871 static void ccw_machine_4_1_class_options(MachineClass
*mc
)
873 ccw_machine_4_2_class_options(mc
);
874 compat_props_add(mc
->compat_props
, hw_compat_4_1
, hw_compat_4_1_len
);
876 DEFINE_CCW_MACHINE(4_1
, "4.1", false);
878 static void ccw_machine_4_0_instance_options(MachineState
*machine
)
880 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_0
};
881 ccw_machine_4_1_instance_options(machine
);
882 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
885 static void ccw_machine_4_0_class_options(MachineClass
*mc
)
887 ccw_machine_4_1_class_options(mc
);
888 compat_props_add(mc
->compat_props
, hw_compat_4_0
, hw_compat_4_0_len
);
890 DEFINE_CCW_MACHINE(4_0
, "4.0", false);
892 static void ccw_machine_3_1_instance_options(MachineState
*machine
)
894 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V3_1
};
895 ccw_machine_4_0_instance_options(machine
);
896 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH
);
897 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF
);
898 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
901 static void ccw_machine_3_1_class_options(MachineClass
*mc
)
903 ccw_machine_4_0_class_options(mc
);
904 compat_props_add(mc
->compat_props
, hw_compat_3_1
, hw_compat_3_1_len
);
906 DEFINE_CCW_MACHINE(3_1
, "3.1", false);
908 static void ccw_machine_3_0_instance_options(MachineState
*machine
)
910 ccw_machine_3_1_instance_options(machine
);
913 static void ccw_machine_3_0_class_options(MachineClass
*mc
)
915 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
917 s390mc
->hpage_1m_allowed
= false;
918 ccw_machine_3_1_class_options(mc
);
919 compat_props_add(mc
->compat_props
, hw_compat_3_0
, hw_compat_3_0_len
);
921 DEFINE_CCW_MACHINE(3_0
, "3.0", false);
923 static void ccw_machine_2_12_instance_options(MachineState
*machine
)
925 ccw_machine_3_0_instance_options(machine
);
926 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15
);
927 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB
);
930 static void ccw_machine_2_12_class_options(MachineClass
*mc
)
932 ccw_machine_3_0_class_options(mc
);
933 compat_props_add(mc
->compat_props
, hw_compat_2_12
, hw_compat_2_12_len
);
935 DEFINE_CCW_MACHINE(2_12
, "2.12", false);
937 static void ccw_machine_2_11_instance_options(MachineState
*machine
)
939 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V2_11
};
940 ccw_machine_2_12_instance_options(machine
);
942 /* before 2.12 we emulated the very first z900 */
943 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat
);
946 static void ccw_machine_2_11_class_options(MachineClass
*mc
)
948 static GlobalProperty compat
[] = {
949 { TYPE_SCLP_EVENT_FACILITY
, "allow_all_mask_sizes", "off", },
952 ccw_machine_2_12_class_options(mc
);
953 compat_props_add(mc
->compat_props
, hw_compat_2_11
, hw_compat_2_11_len
);
954 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
956 DEFINE_CCW_MACHINE(2_11
, "2.11", false);
958 static void ccw_machine_2_10_instance_options(MachineState
*machine
)
960 ccw_machine_2_11_instance_options(machine
);
963 static void ccw_machine_2_10_class_options(MachineClass
*mc
)
965 ccw_machine_2_11_class_options(mc
);
966 compat_props_add(mc
->compat_props
, hw_compat_2_10
, hw_compat_2_10_len
);
968 DEFINE_CCW_MACHINE(2_10
, "2.10", false);
970 static void ccw_machine_2_9_instance_options(MachineState
*machine
)
972 ccw_machine_2_10_instance_options(machine
);
973 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP
);
974 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2
);
975 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI
);
976 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION
);
977 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION
);
980 static void ccw_machine_2_9_class_options(MachineClass
*mc
)
982 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
983 static GlobalProperty compat
[] = {
984 { TYPE_S390_STATTRIB
, "migration-enabled", "off", },
987 ccw_machine_2_10_class_options(mc
);
988 compat_props_add(mc
->compat_props
, hw_compat_2_9
, hw_compat_2_9_len
);
989 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
990 s390mc
->css_migration_enabled
= false;
992 DEFINE_CCW_MACHINE(2_9
, "2.9", false);
994 static void ccw_machine_2_8_instance_options(MachineState
*machine
)
996 ccw_machine_2_9_instance_options(machine
);
999 static void ccw_machine_2_8_class_options(MachineClass
*mc
)
1001 static GlobalProperty compat
[] = {
1002 { TYPE_S390_FLIC_COMMON
, "adapter_routes_max_batch", "64", },
1005 ccw_machine_2_9_class_options(mc
);
1006 compat_props_add(mc
->compat_props
, hw_compat_2_8
, hw_compat_2_8_len
);
1007 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1009 DEFINE_CCW_MACHINE(2_8
, "2.8", false);
1011 static void ccw_machine_2_7_instance_options(MachineState
*machine
)
1013 ccw_machine_2_8_instance_options(machine
);
1016 static void ccw_machine_2_7_class_options(MachineClass
*mc
)
1018 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1020 s390mc
->cpu_model_allowed
= false;
1021 ccw_machine_2_8_class_options(mc
);
1022 compat_props_add(mc
->compat_props
, hw_compat_2_7
, hw_compat_2_7_len
);
1024 DEFINE_CCW_MACHINE(2_7
, "2.7", false);
1026 static void ccw_machine_2_6_instance_options(MachineState
*machine
)
1028 ccw_machine_2_7_instance_options(machine
);
1031 static void ccw_machine_2_6_class_options(MachineClass
*mc
)
1033 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1034 static GlobalProperty compat
[] = {
1035 { TYPE_S390_IPL
, "iplbext_migration", "off", },
1036 { TYPE_VIRTUAL_CSS_BRIDGE
, "css_dev_path", "off", },
1039 s390mc
->ri_allowed
= false;
1040 ccw_machine_2_7_class_options(mc
);
1041 compat_props_add(mc
->compat_props
, hw_compat_2_6
, hw_compat_2_6_len
);
1042 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1044 DEFINE_CCW_MACHINE(2_6
, "2.6", false);
1046 static void ccw_machine_2_5_instance_options(MachineState
*machine
)
1048 ccw_machine_2_6_instance_options(machine
);
1051 static void ccw_machine_2_5_class_options(MachineClass
*mc
)
1053 ccw_machine_2_6_class_options(mc
);
1054 compat_props_add(mc
->compat_props
, hw_compat_2_5
, hw_compat_2_5_len
);
1056 DEFINE_CCW_MACHINE(2_5
, "2.5", false);
1058 static void ccw_machine_2_4_instance_options(MachineState
*machine
)
1060 ccw_machine_2_5_instance_options(machine
);
1063 static void ccw_machine_2_4_class_options(MachineClass
*mc
)
1065 static GlobalProperty compat
[] = {
1066 { TYPE_S390_SKEYS
, "migration-enabled", "off", },
1067 { "virtio-blk-ccw", "max_revision", "0", },
1068 { "virtio-balloon-ccw", "max_revision", "0", },
1069 { "virtio-serial-ccw", "max_revision", "0", },
1070 { "virtio-9p-ccw", "max_revision", "0", },
1071 { "virtio-rng-ccw", "max_revision", "0", },
1072 { "virtio-net-ccw", "max_revision", "0", },
1073 { "virtio-scsi-ccw", "max_revision", "0", },
1074 { "vhost-scsi-ccw", "max_revision", "0", },
1077 ccw_machine_2_5_class_options(mc
);
1078 compat_props_add(mc
->compat_props
, hw_compat_2_4
, hw_compat_2_4_len
);
1079 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1081 DEFINE_CCW_MACHINE(2_4
, "2.4", false);
1083 static void ccw_machine_register_types(void)
1085 type_register_static(&ccw_machine_info
);
1088 type_init(ccw_machine_register_types
)