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 "exec/confidential-guest-support.h"
18 #include "hw/boards.h"
19 #include "hw/s390x/s390-virtio-hcall.h"
20 #include "hw/s390x/sclp.h"
21 #include "hw/s390x/s390_flic.h"
22 #include "hw/s390x/ioinst.h"
23 #include "hw/s390x/css.h"
24 #include "virtio-ccw.h"
25 #include "qemu/config-file.h"
26 #include "qemu/ctype.h"
27 #include "qemu/error-report.h"
28 #include "qemu/option.h"
29 #include "qemu/qemu-print.h"
30 #include "qemu/units.h"
31 #include "hw/s390x/s390-pci-bus.h"
32 #include "sysemu/reset.h"
33 #include "hw/s390x/storage-keys.h"
34 #include "hw/s390x/storage-attributes.h"
35 #include "hw/s390x/event-facility.h"
37 #include "hw/s390x/s390-virtio-ccw.h"
38 #include "hw/s390x/css-bridge.h"
39 #include "hw/s390x/ap-bridge.h"
40 #include "migration/register.h"
41 #include "cpu_models.h"
43 #include "hw/qdev-properties.h"
44 #include "hw/s390x/tod.h"
45 #include "sysemu/sysemu.h"
46 #include "sysemu/cpus.h"
47 #include "target/s390x/kvm/pv.h"
48 #include "migration/blocker.h"
49 #include "qapi/visitor.h"
50 #include "hw/s390x/cpu-topology.h"
51 #include CONFIG_DEVICES
53 static Error
*pv_mig_blocker
;
55 static S390CPU
*s390x_new_cpu(const char *typename
, uint32_t core_id
,
58 S390CPU
*cpu
= S390_CPU(object_new(typename
));
61 if (!object_property_set_int(OBJECT(cpu
), "core-id", core_id
, errp
)) {
64 if (!qdev_realize(DEVICE(cpu
), NULL
, errp
)) {
70 object_unref(OBJECT(cpu
));
74 static void s390_init_cpus(MachineState
*machine
)
76 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
77 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
80 if (machine
->smp
.threads
> s390mc
->max_threads
) {
81 error_report("S390 does not support more than %d threads.",
86 /* initialize possible_cpus */
87 mc
->possible_cpu_arch_ids(machine
);
89 for (i
= 0; i
< machine
->smp
.cpus
; i
++) {
90 s390x_new_cpu(machine
->cpu_type
, i
, &error_fatal
);
94 static const char *const reset_dev_types
[] = {
95 TYPE_VIRTUAL_CSS_BRIDGE
,
96 "s390-sclp-event-facility",
99 TYPE_S390_PCI_HOST_BRIDGE
,
103 static void subsystem_reset(void)
109 * ISM firmware is sensitive to unexpected changes to the IOMMU, which can
110 * occur during reset of the vfio-pci device (unmap of entire aperture).
111 * Ensure any passthrough ISM devices are reset now, while CPUs are paused
112 * but before vfio-pci cleanup occurs.
114 s390_pci_ism_reset();
116 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
117 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
119 device_cold_reset(dev
);
122 if (s390_has_topology()) {
123 s390_topology_reset();
127 static int virtio_ccw_hcall_notify(const uint64_t *args
)
129 uint64_t subch_id
= args
[0];
130 uint64_t data
= args
[1];
133 int cssid
, ssid
, schid
, m
;
134 uint16_t vq_idx
= data
;
136 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
139 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
140 if (!sch
|| !css_subch_visible(sch
)) {
144 vdev
= virtio_ccw_get_vdev(sch
);
145 if (vq_idx
>= VIRTIO_QUEUE_MAX
|| !virtio_queue_get_num(vdev
, vq_idx
)) {
149 if (virtio_vdev_has_feature(vdev
, VIRTIO_F_NOTIFICATION_DATA
)) {
150 virtio_queue_set_shadow_avail_idx(virtio_get_queue(vdev
, vq_idx
),
151 (data
>> 16) & 0xFFFF);
154 virtio_queue_notify(vdev
, vq_idx
);
158 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
160 uint64_t mem
= args
[0];
161 MachineState
*ms
= MACHINE(qdev_get_machine());
163 if (mem
< ms
->ram_size
) {
170 static void virtio_ccw_register_hcalls(void)
172 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
173 virtio_ccw_hcall_notify
);
174 /* Tolerate early printk. */
175 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
176 virtio_ccw_hcall_early_printk
);
179 static void s390_memory_init(MemoryRegion
*ram
)
181 MemoryRegion
*sysmem
= get_system_memory();
183 /* allocate RAM for core */
184 memory_region_add_subregion(sysmem
, 0, ram
);
187 * Configure the maximum page size. As no memory devices were created
188 * yet, this is the page size of initial memory only.
190 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal
);
191 /* Initialize storage key device */
193 /* Initialize storage attributes device */
194 s390_stattrib_init();
197 static void s390_init_ipl_dev(const char *kernel_filename
,
198 const char *kernel_cmdline
,
199 const char *initrd_filename
, const char *firmware
,
200 const char *netboot_fw
, bool enforce_bios
)
202 Object
*new = object_new(TYPE_S390_IPL
);
203 DeviceState
*dev
= DEVICE(new);
204 char *netboot_fw_prop
;
206 if (kernel_filename
) {
207 qdev_prop_set_string(dev
, "kernel", kernel_filename
);
209 if (initrd_filename
) {
210 qdev_prop_set_string(dev
, "initrd", initrd_filename
);
212 qdev_prop_set_string(dev
, "cmdline", kernel_cmdline
);
213 qdev_prop_set_string(dev
, "firmware", firmware
);
214 qdev_prop_set_bit(dev
, "enforce_bios", enforce_bios
);
215 netboot_fw_prop
= object_property_get_str(new, "netboot_fw", &error_abort
);
216 if (!strlen(netboot_fw_prop
)) {
217 qdev_prop_set_string(dev
, "netboot_fw", netboot_fw
);
219 g_free(netboot_fw_prop
);
220 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL
,
223 qdev_realize(dev
, NULL
, &error_fatal
);
226 static void s390_create_virtio_net(BusState
*bus
, const char *name
)
231 while ((dev
= qemu_create_nic_device(name
, true, "virtio"))) {
232 g_autofree
char *childname
= g_strdup_printf("%s[%d]", name
, cnt
++);
233 object_property_add_child(OBJECT(bus
), childname
, OBJECT(dev
));
234 qdev_realize_and_unref(dev
, bus
, &error_fatal
);
238 static void s390_create_sclpconsole(SCLPDevice
*sclp
,
239 const char *type
, Chardev
*chardev
)
241 SCLPEventFacility
*ef
= sclp
->event_facility
;
242 BusState
*ev_fac_bus
= sclp_get_event_facility_bus(ef
);
245 dev
= qdev_new(type
);
246 object_property_add_child(OBJECT(ef
), type
, OBJECT(dev
));
247 qdev_prop_set_chr(dev
, "chardev", chardev
);
248 qdev_realize_and_unref(dev
, ev_fac_bus
, &error_fatal
);
251 static void ccw_init(MachineState
*machine
)
253 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
254 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
256 VirtualCssBus
*css_bus
;
259 ms
->sclp
= SCLP(object_new(TYPE_SCLP
));
260 object_property_add_child(OBJECT(machine
), TYPE_SCLP
, OBJECT(ms
->sclp
));
261 qdev_realize_and_unref(DEVICE(ms
->sclp
), NULL
, &error_fatal
);
263 /* init memory + setup max page size. Required for the CPU model */
264 s390_memory_init(machine
->ram
);
266 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
267 s390_init_cpus(machine
);
269 /* Need CPU model to be determined before we can set up PV */
271 confidential_guest_kvm_init(machine
->cgs
, &error_fatal
);
276 /* init the SIGP facility */
279 /* create AP bridge and bus(es) */
283 css_bus
= virtual_css_bus_init();
284 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
285 machine
->initrd_filename
,
286 machine
->firmware
?: "s390-ccw.img",
287 "s390-netboot.img", true);
289 dev
= qdev_new(TYPE_S390_PCI_HOST_BRIDGE
);
290 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
292 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
294 /* register hypercalls */
295 virtio_ccw_register_hcalls();
297 s390_enable_css_support(s390_cpu_addr2state(0));
299 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
302 css_register_vmstate();
304 /* Create VirtIO network adapters */
305 s390_create_virtio_net(BUS(css_bus
), mc
->default_nic
);
309 s390_create_sclpconsole(ms
->sclp
, "sclpconsole", serial_hd(0));
312 s390_create_sclpconsole(ms
->sclp
, "sclplmconsole", serial_hd(1));
315 /* init the TOD clock */
319 static void s390_cpu_plug(HotplugHandler
*hotplug_dev
,
320 DeviceState
*dev
, Error
**errp
)
323 MachineState
*ms
= MACHINE(hotplug_dev
);
324 S390CPU
*cpu
= S390_CPU(dev
);
326 g_assert(!ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
);
327 ms
->possible_cpus
->cpus
[cpu
->env
.core_id
].cpu
= CPU(dev
);
329 if (s390_has_topology()) {
330 s390_topology_setup_cpu(ms
, cpu
, errp
);
336 if (dev
->hotplugged
) {
337 raise_irq_cpu_hotplug();
341 static inline void s390_do_cpu_ipl(CPUState
*cs
, run_on_cpu_data arg
)
343 S390CPU
*cpu
= S390_CPU(cs
);
345 s390_ipl_prepare_cpu(cpu
);
346 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
349 static void s390_machine_unprotect(S390CcwMachineState
*ms
)
351 if (!s390_pv_vm_try_disable_async(ms
)) {
352 s390_pv_vm_disable();
355 migrate_del_blocker(&pv_mig_blocker
);
356 ram_block_discard_disable(false);
359 static int s390_machine_protect(S390CcwMachineState
*ms
)
361 Error
*local_err
= NULL
;
365 * Discarding of memory in RAM blocks does not work as expected with
366 * protected VMs. Sharing and unsharing pages would be required. Disable
367 * it for now, until until we have a solution to make at least Linux
368 * guests either support it (e.g., virtio-balloon) or fail gracefully.
370 rc
= ram_block_discard_disable(true);
372 error_report("protected VMs: cannot disable RAM discard");
376 error_setg(&pv_mig_blocker
,
377 "protected VMs are currently not migratable.");
378 rc
= migrate_add_blocker(&pv_mig_blocker
, &local_err
);
380 ram_block_discard_disable(false);
381 error_report_err(local_err
);
386 rc
= s390_pv_vm_enable();
388 ram_block_discard_disable(false);
389 migrate_del_blocker(&pv_mig_blocker
);
395 /* Will return 0 if API is not available since it's not vital */
396 rc
= s390_pv_query_info();
401 /* Set SE header and unpack */
402 rc
= s390_ipl_prepare_pv_header(&local_err
);
408 rc
= s390_ipl_pv_unpack();
413 /* Verify integrity */
414 rc
= s390_pv_verify();
422 error_report_err(local_err
);
424 s390_machine_unprotect(ms
);
428 static void s390_pv_prepare_reset(S390CcwMachineState
*ms
)
435 /* Unsharing requires all cpus to be stopped */
437 s390_cpu_set_state(S390_CPU_STATE_STOPPED
, S390_CPU(cs
));
440 s390_pv_prep_reset();
443 static void s390_machine_reset(MachineState
*machine
, ResetType type
)
445 S390CcwMachineState
*ms
= S390_CCW_MACHINE(machine
);
446 enum s390_reset reset_type
;
450 /* get the reset parameters, reset them once done */
451 s390_ipl_get_reset_request(&cs
, &reset_type
);
453 /* all CPUs are paused and synchronized at this point */
458 switch (reset_type
) {
459 case S390_RESET_EXTERNAL
:
460 case S390_RESET_REIPL
:
462 * Reset the subsystem which includes a AP reset. If a PV
463 * guest had APQNs attached the AP reset is a prerequisite to
464 * unprotecting since the UV checks if all APQNs are reset.
468 s390_machine_unprotect(ms
);
472 * Device reset includes CPU clear resets so this has to be
473 * done AFTER the unprotect call above.
475 qemu_devices_reset(type
);
478 /* configure and start the ipl CPU only */
479 run_on_cpu(cs
, s390_do_cpu_ipl
, RUN_ON_CPU_NULL
);
481 case S390_RESET_MODIFIED_CLEAR
:
483 * Subsystem reset needs to be done before we unshare memory
484 * and lose access to VIRTIO structures in guest memory.
488 s390_pv_prepare_reset(ms
);
490 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
492 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
494 case S390_RESET_LOAD_NORMAL
:
496 * Subsystem reset needs to be done before we unshare memory
497 * and lose access to VIRTIO structures in guest memory.
500 s390_pv_prepare_reset(ms
);
505 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
507 run_on_cpu(cs
, s390_do_cpu_initial_reset
, RUN_ON_CPU_NULL
);
508 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
510 case S390_RESET_PV
: /* Subcode 10 */
518 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
520 run_on_cpu(cs
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
522 if (s390_machine_protect(ms
)) {
523 s390_pv_inject_reset_error(cs
);
525 * Continue after the diag308 so the guest knows something
528 s390_cpu_set_state(S390_CPU_STATE_OPERATING
, cpu
);
532 run_on_cpu(cs
, s390_do_cpu_load_normal
, RUN_ON_CPU_NULL
);
535 g_assert_not_reached();
539 run_on_cpu(t
, s390_do_cpu_set_diag318
, RUN_ON_CPU_HOST_ULONG(0));
541 s390_ipl_clear_reset_request();
544 static void s390_machine_device_plug(HotplugHandler
*hotplug_dev
,
545 DeviceState
*dev
, Error
**errp
)
547 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
548 s390_cpu_plug(hotplug_dev
, dev
, errp
);
552 static void s390_machine_device_unplug_request(HotplugHandler
*hotplug_dev
,
553 DeviceState
*dev
, Error
**errp
)
555 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
556 error_setg(errp
, "CPU hot unplug not supported on this machine");
561 static CpuInstanceProperties
s390_cpu_index_to_props(MachineState
*ms
,
564 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
565 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
567 assert(cpu_index
< possible_cpus
->len
);
568 return possible_cpus
->cpus
[cpu_index
].props
;
571 static const CPUArchIdList
*s390_possible_cpu_arch_ids(MachineState
*ms
)
574 unsigned int max_cpus
= ms
->smp
.max_cpus
;
576 if (ms
->possible_cpus
) {
577 g_assert(ms
->possible_cpus
&& ms
->possible_cpus
->len
== max_cpus
);
578 return ms
->possible_cpus
;
581 ms
->possible_cpus
= g_malloc0(sizeof(CPUArchIdList
) +
582 sizeof(CPUArchId
) * max_cpus
);
583 ms
->possible_cpus
->len
= max_cpus
;
584 for (i
= 0; i
< ms
->possible_cpus
->len
; i
++) {
585 CpuInstanceProperties
*props
= &ms
->possible_cpus
->cpus
[i
].props
;
587 ms
->possible_cpus
->cpus
[i
].type
= ms
->cpu_type
;
588 ms
->possible_cpus
->cpus
[i
].vcpus_count
= 1;
589 ms
->possible_cpus
->cpus
[i
].arch_id
= i
;
591 props
->has_core_id
= true;
593 props
->has_socket_id
= true;
594 props
->socket_id
= s390_std_socket(i
, &ms
->smp
);
595 props
->has_book_id
= true;
596 props
->book_id
= s390_std_book(i
, &ms
->smp
);
597 props
->has_drawer_id
= true;
598 props
->drawer_id
= s390_std_drawer(i
, &ms
->smp
);
601 return ms
->possible_cpus
;
604 static HotplugHandler
*s390_get_hotplug_handler(MachineState
*machine
,
607 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
608 return HOTPLUG_HANDLER(machine
);
613 static void s390_nmi(NMIState
*n
, int cpu_index
, Error
**errp
)
615 CPUState
*cs
= qemu_get_cpu(cpu_index
);
617 s390_cpu_restart(S390_CPU(cs
));
620 static ram_addr_t
s390_fixup_ram_size(ram_addr_t sz
)
622 /* same logic as in sclp.c */
623 int increment_size
= 20;
626 while ((sz
>> increment_size
) > MAX_STORAGE_INCREMENTS
) {
629 newsz
= sz
>> increment_size
<< increment_size
;
632 qemu_printf("Ram size %" PRIu64
"MB was fixed up to %" PRIu64
633 "MB to match machine restrictions. Consider updating "
634 "the guest definition.\n", (uint64_t) (sz
/ MiB
),
635 (uint64_t) (newsz
/ MiB
));
640 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
642 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
644 return ms
->aes_key_wrap
;
647 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
650 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
652 ms
->aes_key_wrap
= value
;
655 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
657 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
659 return ms
->dea_key_wrap
;
662 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
665 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
667 ms
->dea_key_wrap
= value
;
670 static S390CcwMachineClass
*current_mc
;
673 * Get the class of the s390-ccw-virtio machine that is currently in use.
674 * Note: libvirt is using the "none" machine to probe for the features of the
675 * host CPU, so in case this is called with the "none" machine, the function
676 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
677 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
678 * below return the correct default value for the "none" machine.
680 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
681 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
682 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
683 * CPU initialization and s390_has_feat() later should be sufficient.
685 static S390CcwMachineClass
*get_machine_class(void)
687 if (unlikely(!current_mc
)) {
689 * No s390 ccw machine was instantiated, we are likely to
690 * be called for the 'none' machine. The properties will
691 * have their after-initialization values.
693 current_mc
= S390_CCW_MACHINE_CLASS(
694 object_class_by_name(TYPE_S390_CCW_MACHINE
));
699 bool ri_allowed(void)
701 return get_machine_class()->ri_allowed
;
704 bool cpu_model_allowed(void)
706 return get_machine_class()->cpu_model_allowed
;
709 bool hpage_1m_allowed(void)
711 return get_machine_class()->hpage_1m_allowed
;
714 static void machine_get_loadparm(Object
*obj
, Visitor
*v
,
715 const char *name
, void *opaque
,
718 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
719 char *str
= g_strndup((char *) ms
->loadparm
, sizeof(ms
->loadparm
));
721 visit_type_str(v
, name
, &str
, errp
);
725 static void machine_set_loadparm(Object
*obj
, Visitor
*v
,
726 const char *name
, void *opaque
,
729 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
733 if (!visit_type_str(v
, name
, &val
, errp
)) {
737 for (i
= 0; i
< sizeof(ms
->loadparm
) && val
[i
]; i
++) {
738 uint8_t c
= qemu_toupper(val
[i
]); /* mimic HMC */
740 if (('A' <= c
&& c
<= 'Z') || ('0' <= c
&& c
<= '9') || (c
== '.') ||
744 error_setg(errp
, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
750 for (; i
< sizeof(ms
->loadparm
); i
++) {
751 ms
->loadparm
[i
] = ' '; /* pad right with spaces */
755 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
757 MachineClass
*mc
= MACHINE_CLASS(oc
);
758 NMIClass
*nc
= NMI_CLASS(oc
);
759 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(oc
);
760 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
762 s390mc
->ri_allowed
= true;
763 s390mc
->cpu_model_allowed
= true;
764 s390mc
->hpage_1m_allowed
= true;
765 s390mc
->max_threads
= 1;
767 mc
->reset
= s390_machine_reset
;
768 mc
->block_default_type
= IF_VIRTIO
;
773 mc
->max_cpus
= S390_MAX_CPUS
;
774 mc
->has_hotpluggable_cpus
= true;
775 mc
->smp_props
.books_supported
= true;
776 mc
->smp_props
.drawers_supported
= true;
777 assert(!mc
->get_hotplug_handler
);
778 mc
->get_hotplug_handler
= s390_get_hotplug_handler
;
779 mc
->cpu_index_to_instance_props
= s390_cpu_index_to_props
;
780 mc
->possible_cpu_arch_ids
= s390_possible_cpu_arch_ids
;
781 /* it is overridden with 'host' cpu *in kvm_arch_init* */
782 mc
->default_cpu_type
= S390_CPU_TYPE_NAME("qemu");
783 hc
->plug
= s390_machine_device_plug
;
784 hc
->unplug_request
= s390_machine_device_unplug_request
;
785 nc
->nmi_monitor_handler
= s390_nmi
;
786 mc
->default_ram_id
= "s390.ram";
787 mc
->default_nic
= "virtio-net-ccw";
789 object_class_property_add_bool(oc
, "aes-key-wrap",
790 machine_get_aes_key_wrap
,
791 machine_set_aes_key_wrap
);
792 object_class_property_set_description(oc
, "aes-key-wrap",
793 "enable/disable AES key wrapping using the CPACF wrapping key");
795 object_class_property_add_bool(oc
, "dea-key-wrap",
796 machine_get_dea_key_wrap
,
797 machine_set_dea_key_wrap
);
798 object_class_property_set_description(oc
, "dea-key-wrap",
799 "enable/disable DEA key wrapping using the CPACF wrapping key");
801 object_class_property_add(oc
, "loadparm", "loadparm",
802 machine_get_loadparm
, machine_set_loadparm
,
804 object_class_property_set_description(oc
, "loadparm",
805 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
806 " to upper case) to pass to machine loader, boot manager,"
807 " and guest kernel");
810 static inline void s390_machine_initfn(Object
*obj
)
812 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
814 ms
->aes_key_wrap
= true;
815 ms
->dea_key_wrap
= true;
818 static const TypeInfo ccw_machine_info
= {
819 .name
= TYPE_S390_CCW_MACHINE
,
820 .parent
= TYPE_MACHINE
,
822 .instance_size
= sizeof(S390CcwMachineState
),
823 .instance_init
= s390_machine_initfn
,
824 .class_size
= sizeof(S390CcwMachineClass
),
825 .class_init
= ccw_machine_class_init
,
826 .interfaces
= (InterfaceInfo
[]) {
828 { TYPE_HOTPLUG_HANDLER
},
833 #define DEFINE_CCW_MACHINE_IMPL(latest, ...) \
834 static void MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__)( \
838 MachineClass *mc = MACHINE_CLASS(oc); \
839 MACHINE_VER_SYM(class_options, ccw, __VA_ARGS__)(mc); \
840 mc->desc = "Virtual s390x machine (version " MACHINE_VER_STR(__VA_ARGS__) ")"; \
841 MACHINE_VER_DEPRECATION(__VA_ARGS__); \
843 mc->alias = "s390-ccw-virtio"; \
844 mc->is_default = true; \
847 static void MACHINE_VER_SYM(instance_init, ccw, __VA_ARGS__)(Object *obj) \
849 MachineState *machine = MACHINE(obj); \
850 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
851 MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(machine); \
853 static const TypeInfo MACHINE_VER_SYM(info, ccw, __VA_ARGS__) = \
855 .name = MACHINE_VER_TYPE_NAME("s390-ccw-virtio", __VA_ARGS__), \
856 .parent = TYPE_S390_CCW_MACHINE, \
857 .class_init = MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__), \
858 .instance_init = MACHINE_VER_SYM(instance_init, ccw, __VA_ARGS__), \
860 static void MACHINE_VER_SYM(register, ccw, __VA_ARGS__)(void) \
862 MACHINE_VER_DELETION(__VA_ARGS__); \
863 type_register_static(&MACHINE_VER_SYM(info, ccw, __VA_ARGS__)); \
865 type_init(MACHINE_VER_SYM(register, ccw, __VA_ARGS__))
867 #define DEFINE_CCW_MACHINE_AS_LATEST(major, minor) \
868 DEFINE_CCW_MACHINE_IMPL(true, major, minor)
870 #define DEFINE_CCW_MACHINE(major, minor) \
871 DEFINE_CCW_MACHINE_IMPL(false, major, minor)
874 static void ccw_machine_9_2_instance_options(MachineState
*machine
)
878 static void ccw_machine_9_2_class_options(MachineClass
*mc
)
881 DEFINE_CCW_MACHINE_AS_LATEST(9, 2);
883 static void ccw_machine_9_1_instance_options(MachineState
*machine
)
885 ccw_machine_9_2_instance_options(machine
);
888 static void ccw_machine_9_1_class_options(MachineClass
*mc
)
890 ccw_machine_9_2_class_options(mc
);
891 compat_props_add(mc
->compat_props
, hw_compat_9_1
, hw_compat_9_1_len
);
893 DEFINE_CCW_MACHINE(9, 1);
895 static void ccw_machine_9_0_instance_options(MachineState
*machine
)
897 ccw_machine_9_1_instance_options(machine
);
900 static void ccw_machine_9_0_class_options(MachineClass
*mc
)
902 static GlobalProperty compat
[] = {
903 { TYPE_QEMU_S390_FLIC
, "migrate-all-state", "off", },
906 ccw_machine_9_1_class_options(mc
);
907 compat_props_add(mc
->compat_props
, hw_compat_9_0
, hw_compat_9_0_len
);
908 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
910 DEFINE_CCW_MACHINE(9, 0);
912 static void ccw_machine_8_2_instance_options(MachineState
*machine
)
914 ccw_machine_9_0_instance_options(machine
);
917 static void ccw_machine_8_2_class_options(MachineClass
*mc
)
919 ccw_machine_9_0_class_options(mc
);
920 compat_props_add(mc
->compat_props
, hw_compat_8_2
, hw_compat_8_2_len
);
922 DEFINE_CCW_MACHINE(8, 2);
924 static void ccw_machine_8_1_instance_options(MachineState
*machine
)
926 ccw_machine_8_2_instance_options(machine
);
929 static void ccw_machine_8_1_class_options(MachineClass
*mc
)
931 ccw_machine_8_2_class_options(mc
);
932 compat_props_add(mc
->compat_props
, hw_compat_8_1
, hw_compat_8_1_len
);
933 mc
->smp_props
.drawers_supported
= false;
934 mc
->smp_props
.books_supported
= false;
936 DEFINE_CCW_MACHINE(8, 1);
938 static void ccw_machine_8_0_instance_options(MachineState
*machine
)
940 ccw_machine_8_1_instance_options(machine
);
943 static void ccw_machine_8_0_class_options(MachineClass
*mc
)
945 ccw_machine_8_1_class_options(mc
);
946 compat_props_add(mc
->compat_props
, hw_compat_8_0
, hw_compat_8_0_len
);
948 DEFINE_CCW_MACHINE(8, 0);
950 static void ccw_machine_7_2_instance_options(MachineState
*machine
)
952 ccw_machine_8_0_instance_options(machine
);
955 static void ccw_machine_7_2_class_options(MachineClass
*mc
)
957 ccw_machine_8_0_class_options(mc
);
958 compat_props_add(mc
->compat_props
, hw_compat_7_2
, hw_compat_7_2_len
);
960 DEFINE_CCW_MACHINE(7, 2);
962 static void ccw_machine_7_1_instance_options(MachineState
*machine
)
964 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_1
};
966 ccw_machine_7_2_instance_options(machine
);
967 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE
);
968 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
971 static void ccw_machine_7_1_class_options(MachineClass
*mc
)
973 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
974 static GlobalProperty compat
[] = {
975 { TYPE_S390_PCI_DEVICE
, "interpret", "off", },
976 { TYPE_S390_PCI_DEVICE
, "forwarding-assist", "off", },
979 ccw_machine_7_2_class_options(mc
);
980 compat_props_add(mc
->compat_props
, hw_compat_7_1
, hw_compat_7_1_len
);
981 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
982 s390mc
->max_threads
= S390_MAX_CPUS
;
984 DEFINE_CCW_MACHINE(7, 1);
986 static void ccw_machine_7_0_instance_options(MachineState
*machine
)
988 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V7_0
};
990 ccw_machine_7_1_instance_options(machine
);
991 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat
);
994 static void ccw_machine_7_0_class_options(MachineClass
*mc
)
996 ccw_machine_7_1_class_options(mc
);
997 compat_props_add(mc
->compat_props
, hw_compat_7_0
, hw_compat_7_0_len
);
999 DEFINE_CCW_MACHINE(7, 0);
1001 static void ccw_machine_6_2_instance_options(MachineState
*machine
)
1003 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_2
};
1005 ccw_machine_7_0_instance_options(machine
);
1006 s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat
);
1009 static void ccw_machine_6_2_class_options(MachineClass
*mc
)
1011 ccw_machine_7_0_class_options(mc
);
1012 compat_props_add(mc
->compat_props
, hw_compat_6_2
, hw_compat_6_2_len
);
1014 DEFINE_CCW_MACHINE(6, 2);
1016 static void ccw_machine_6_1_instance_options(MachineState
*machine
)
1018 ccw_machine_6_2_instance_options(machine
);
1019 s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA
);
1020 s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2
);
1021 s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH
);
1022 s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP
);
1023 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI
);
1026 static void ccw_machine_6_1_class_options(MachineClass
*mc
)
1028 ccw_machine_6_2_class_options(mc
);
1029 compat_props_add(mc
->compat_props
, hw_compat_6_1
, hw_compat_6_1_len
);
1030 mc
->smp_props
.prefer_sockets
= true;
1032 DEFINE_CCW_MACHINE(6, 1);
1034 static void ccw_machine_6_0_instance_options(MachineState
*machine
)
1036 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V6_0
};
1038 ccw_machine_6_1_instance_options(machine
);
1039 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
1042 static void ccw_machine_6_0_class_options(MachineClass
*mc
)
1044 ccw_machine_6_1_class_options(mc
);
1045 compat_props_add(mc
->compat_props
, hw_compat_6_0
, hw_compat_6_0_len
);
1047 DEFINE_CCW_MACHINE(6, 0);
1049 static void ccw_machine_5_2_instance_options(MachineState
*machine
)
1051 ccw_machine_6_0_instance_options(machine
);
1054 static void ccw_machine_5_2_class_options(MachineClass
*mc
)
1056 ccw_machine_6_0_class_options(mc
);
1057 compat_props_add(mc
->compat_props
, hw_compat_5_2
, hw_compat_5_2_len
);
1059 DEFINE_CCW_MACHINE(5, 2);
1061 static void ccw_machine_5_1_instance_options(MachineState
*machine
)
1063 ccw_machine_5_2_instance_options(machine
);
1066 static void ccw_machine_5_1_class_options(MachineClass
*mc
)
1068 ccw_machine_5_2_class_options(mc
);
1069 compat_props_add(mc
->compat_props
, hw_compat_5_1
, hw_compat_5_1_len
);
1071 DEFINE_CCW_MACHINE(5, 1);
1073 static void ccw_machine_5_0_instance_options(MachineState
*machine
)
1075 ccw_machine_5_1_instance_options(machine
);
1078 static void ccw_machine_5_0_class_options(MachineClass
*mc
)
1080 ccw_machine_5_1_class_options(mc
);
1081 compat_props_add(mc
->compat_props
, hw_compat_5_0
, hw_compat_5_0_len
);
1083 DEFINE_CCW_MACHINE(5, 0);
1085 static void ccw_machine_4_2_instance_options(MachineState
*machine
)
1087 ccw_machine_5_0_instance_options(machine
);
1090 static void ccw_machine_4_2_class_options(MachineClass
*mc
)
1092 ccw_machine_5_0_class_options(mc
);
1093 mc
->fixup_ram_size
= s390_fixup_ram_size
;
1094 compat_props_add(mc
->compat_props
, hw_compat_4_2
, hw_compat_4_2_len
);
1096 DEFINE_CCW_MACHINE(4, 2);
1098 static void ccw_machine_4_1_instance_options(MachineState
*machine
)
1100 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_1
};
1101 ccw_machine_4_2_instance_options(machine
);
1102 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat
);
1105 static void ccw_machine_4_1_class_options(MachineClass
*mc
)
1107 ccw_machine_4_2_class_options(mc
);
1108 compat_props_add(mc
->compat_props
, hw_compat_4_1
, hw_compat_4_1_len
);
1110 DEFINE_CCW_MACHINE(4, 1);
1112 static void ccw_machine_4_0_instance_options(MachineState
*machine
)
1114 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V4_0
};
1115 ccw_machine_4_1_instance_options(machine
);
1116 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
1119 static void ccw_machine_4_0_class_options(MachineClass
*mc
)
1121 ccw_machine_4_1_class_options(mc
);
1122 compat_props_add(mc
->compat_props
, hw_compat_4_0
, hw_compat_4_0_len
);
1124 DEFINE_CCW_MACHINE(4, 0);
1126 static void ccw_machine_3_1_instance_options(MachineState
*machine
)
1128 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V3_1
};
1129 ccw_machine_4_0_instance_options(machine
);
1130 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH
);
1131 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF
);
1132 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat
);
1135 static void ccw_machine_3_1_class_options(MachineClass
*mc
)
1137 ccw_machine_4_0_class_options(mc
);
1138 compat_props_add(mc
->compat_props
, hw_compat_3_1
, hw_compat_3_1_len
);
1140 DEFINE_CCW_MACHINE(3, 1);
1142 static void ccw_machine_3_0_instance_options(MachineState
*machine
)
1144 ccw_machine_3_1_instance_options(machine
);
1147 static void ccw_machine_3_0_class_options(MachineClass
*mc
)
1149 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1151 s390mc
->hpage_1m_allowed
= false;
1152 ccw_machine_3_1_class_options(mc
);
1153 compat_props_add(mc
->compat_props
, hw_compat_3_0
, hw_compat_3_0_len
);
1155 DEFINE_CCW_MACHINE(3, 0);
1157 static void ccw_machine_2_12_instance_options(MachineState
*machine
)
1159 ccw_machine_3_0_instance_options(machine
);
1160 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15
);
1161 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB
);
1164 static void ccw_machine_2_12_class_options(MachineClass
*mc
)
1166 ccw_machine_3_0_class_options(mc
);
1167 compat_props_add(mc
->compat_props
, hw_compat_2_12
, hw_compat_2_12_len
);
1169 DEFINE_CCW_MACHINE(2, 12);
1171 #ifdef CONFIG_S390X_LEGACY_CPUS
1173 static void ccw_machine_2_11_instance_options(MachineState
*machine
)
1175 static const S390FeatInit qemu_cpu_feat
= { S390_FEAT_LIST_QEMU_V2_11
};
1176 ccw_machine_2_12_instance_options(machine
);
1178 /* before 2.12 we emulated the very first z900 */
1179 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat
);
1182 static void ccw_machine_2_11_class_options(MachineClass
*mc
)
1184 static GlobalProperty compat
[] = {
1185 { TYPE_SCLP_EVENT_FACILITY
, "allow_all_mask_sizes", "off", },
1188 ccw_machine_2_12_class_options(mc
);
1189 compat_props_add(mc
->compat_props
, hw_compat_2_11
, hw_compat_2_11_len
);
1190 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1192 DEFINE_CCW_MACHINE(2, 11);
1194 static void ccw_machine_2_10_instance_options(MachineState
*machine
)
1196 ccw_machine_2_11_instance_options(machine
);
1199 static void ccw_machine_2_10_class_options(MachineClass
*mc
)
1201 ccw_machine_2_11_class_options(mc
);
1202 compat_props_add(mc
->compat_props
, hw_compat_2_10
, hw_compat_2_10_len
);
1204 DEFINE_CCW_MACHINE(2, 10);
1206 static void ccw_machine_2_9_instance_options(MachineState
*machine
)
1208 ccw_machine_2_10_instance_options(machine
);
1209 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP
);
1210 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2
);
1211 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI
);
1212 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION
);
1213 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION
);
1216 static void ccw_machine_2_9_class_options(MachineClass
*mc
)
1218 static GlobalProperty compat
[] = {
1219 { TYPE_S390_STATTRIB
, "migration-enabled", "off", },
1220 { TYPE_S390_FLIC_COMMON
, "migration-enabled", "off", },
1223 ccw_machine_2_10_class_options(mc
);
1224 compat_props_add(mc
->compat_props
, hw_compat_2_9
, hw_compat_2_9_len
);
1225 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1226 css_migration_enabled
= false;
1228 DEFINE_CCW_MACHINE(2, 9);
1230 static void ccw_machine_2_8_instance_options(MachineState
*machine
)
1232 ccw_machine_2_9_instance_options(machine
);
1235 static void ccw_machine_2_8_class_options(MachineClass
*mc
)
1237 static GlobalProperty compat
[] = {
1238 { TYPE_S390_FLIC_COMMON
, "adapter_routes_max_batch", "64", },
1241 ccw_machine_2_9_class_options(mc
);
1242 compat_props_add(mc
->compat_props
, hw_compat_2_8
, hw_compat_2_8_len
);
1243 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1245 DEFINE_CCW_MACHINE(2, 8);
1247 static void ccw_machine_2_7_instance_options(MachineState
*machine
)
1249 ccw_machine_2_8_instance_options(machine
);
1252 static void ccw_machine_2_7_class_options(MachineClass
*mc
)
1254 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1256 s390mc
->cpu_model_allowed
= false;
1257 ccw_machine_2_8_class_options(mc
);
1258 compat_props_add(mc
->compat_props
, hw_compat_2_7
, hw_compat_2_7_len
);
1260 DEFINE_CCW_MACHINE(2, 7);
1262 static void ccw_machine_2_6_instance_options(MachineState
*machine
)
1264 ccw_machine_2_7_instance_options(machine
);
1267 static void ccw_machine_2_6_class_options(MachineClass
*mc
)
1269 S390CcwMachineClass
*s390mc
= S390_CCW_MACHINE_CLASS(mc
);
1270 static GlobalProperty compat
[] = {
1271 { TYPE_S390_IPL
, "iplbext_migration", "off", },
1272 { TYPE_VIRTUAL_CSS_BRIDGE
, "css_dev_path", "off", },
1275 s390mc
->ri_allowed
= false;
1276 ccw_machine_2_7_class_options(mc
);
1277 compat_props_add(mc
->compat_props
, hw_compat_2_6
, hw_compat_2_6_len
);
1278 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1280 DEFINE_CCW_MACHINE(2, 6);
1282 static void ccw_machine_2_5_instance_options(MachineState
*machine
)
1284 ccw_machine_2_6_instance_options(machine
);
1287 static void ccw_machine_2_5_class_options(MachineClass
*mc
)
1289 ccw_machine_2_6_class_options(mc
);
1290 compat_props_add(mc
->compat_props
, hw_compat_2_5
, hw_compat_2_5_len
);
1292 DEFINE_CCW_MACHINE(2, 5);
1294 static void ccw_machine_2_4_instance_options(MachineState
*machine
)
1296 ccw_machine_2_5_instance_options(machine
);
1299 static void ccw_machine_2_4_class_options(MachineClass
*mc
)
1301 static GlobalProperty compat
[] = {
1302 { TYPE_S390_SKEYS
, "migration-enabled", "off", },
1303 { "virtio-blk-ccw", "max_revision", "0", },
1304 { "virtio-balloon-ccw", "max_revision", "0", },
1305 { "virtio-serial-ccw", "max_revision", "0", },
1306 { "virtio-9p-ccw", "max_revision", "0", },
1307 { "virtio-rng-ccw", "max_revision", "0", },
1308 { "virtio-net-ccw", "max_revision", "0", },
1309 { "virtio-scsi-ccw", "max_revision", "0", },
1310 { "vhost-scsi-ccw", "max_revision", "0", },
1313 ccw_machine_2_5_class_options(mc
);
1314 compat_props_add(mc
->compat_props
, hw_compat_2_4
, hw_compat_2_4_len
);
1315 compat_props_add(mc
->compat_props
, compat
, G_N_ELEMENTS(compat
));
1317 DEFINE_CCW_MACHINE(2, 4);
1321 static void ccw_machine_register_types(void)
1323 type_register_static(&ccw_machine_info
);
1326 type_init(ccw_machine_register_types
)