pcihp: acpi: ignore coldplugged bridges when composing hotpluggable slots
[qemu.git] / hw / s390x / s390-virtio-ccw.c
blobf22f61b8b6ac8467ee264176088d1f90c1890b4f
1 /*
2 * virtio ccw machine
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
11 * directory.
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"
34 #include "ipl.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"
40 #include "hw/nmi.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"
46 #include "qapi/visitor.h"
48 static Error *pv_mig_blocker;
50 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
52 static MachineState *ms;
54 if (!ms) {
55 ms = MACHINE(qdev_get_machine());
56 g_assert(ms->possible_cpus);
59 /* CPU address corresponds to the core_id and the index */
60 if (cpu_addr >= ms->possible_cpus->len) {
61 return NULL;
63 return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
66 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
67 Error **errp)
69 S390CPU *cpu = S390_CPU(object_new(typename));
70 S390CPU *ret = NULL;
72 if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) {
73 goto out;
75 if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
76 goto out;
78 ret = cpu;
80 out:
81 object_unref(OBJECT(cpu));
82 return ret;
85 static void s390_init_cpus(MachineState *machine)
87 MachineClass *mc = MACHINE_GET_CLASS(machine);
88 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
89 int i;
91 if (machine->smp.threads > s390mc->max_threads) {
92 error_report("S390 does not support more than %d threads.",
93 s390mc->max_threads);
94 exit(1);
97 /* initialize possible_cpus */
98 mc->possible_cpu_arch_ids(machine);
100 for (i = 0; i < machine->smp.cpus; i++) {
101 s390x_new_cpu(machine->cpu_type, i, &error_fatal);
105 static const char *const reset_dev_types[] = {
106 TYPE_VIRTUAL_CSS_BRIDGE,
107 "s390-sclp-event-facility",
108 "s390-flic",
109 "diag288",
110 TYPE_S390_PCI_HOST_BRIDGE,
113 static void subsystem_reset(void)
115 DeviceState *dev;
116 int i;
118 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
119 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
120 if (dev) {
121 device_cold_reset(dev);
126 static int virtio_ccw_hcall_notify(const uint64_t *args)
128 uint64_t subch_id = args[0];
129 uint64_t queue = args[1];
130 SubchDev *sch;
131 int cssid, ssid, schid, m;
133 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
134 return -EINVAL;
136 sch = css_find_subch(m, cssid, ssid, schid);
137 if (!sch || !css_subch_visible(sch)) {
138 return -EINVAL;
140 if (queue >= VIRTIO_QUEUE_MAX) {
141 return -EINVAL;
143 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
144 return 0;
148 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
150 uint64_t mem = args[0];
151 MachineState *ms = MACHINE(qdev_get_machine());
153 if (mem < ms->ram_size) {
154 /* Early printk */
155 return 0;
157 return -EINVAL;
160 static void virtio_ccw_register_hcalls(void)
162 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
163 virtio_ccw_hcall_notify);
164 /* Tolerate early printk. */
165 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
166 virtio_ccw_hcall_early_printk);
169 static void s390_memory_init(MemoryRegion *ram)
171 MemoryRegion *sysmem = get_system_memory();
173 /* allocate RAM for core */
174 memory_region_add_subregion(sysmem, 0, ram);
177 * Configure the maximum page size. As no memory devices were created
178 * yet, this is the page size of initial memory only.
180 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal);
181 /* Initialize storage key device */
182 s390_skeys_init();
183 /* Initialize storage attributes device */
184 s390_stattrib_init();
187 static void s390_init_ipl_dev(const char *kernel_filename,
188 const char *kernel_cmdline,
189 const char *initrd_filename, const char *firmware,
190 const char *netboot_fw, bool enforce_bios)
192 Object *new = object_new(TYPE_S390_IPL);
193 DeviceState *dev = DEVICE(new);
194 char *netboot_fw_prop;
196 if (kernel_filename) {
197 qdev_prop_set_string(dev, "kernel", kernel_filename);
199 if (initrd_filename) {
200 qdev_prop_set_string(dev, "initrd", initrd_filename);
202 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
203 qdev_prop_set_string(dev, "firmware", firmware);
204 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
205 netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
206 if (!strlen(netboot_fw_prop)) {
207 qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
209 g_free(netboot_fw_prop);
210 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
211 new);
212 object_unref(new);
213 qdev_realize(dev, NULL, &error_fatal);
216 static void s390_create_virtio_net(BusState *bus, const char *name)
218 int i;
220 for (i = 0; i < nb_nics; i++) {
221 NICInfo *nd = &nd_table[i];
222 DeviceState *dev;
224 if (!nd->model) {
225 nd->model = g_strdup("virtio");
228 qemu_check_nic_model(nd, "virtio");
230 dev = qdev_new(name);
231 qdev_set_nic_properties(dev, nd);
232 qdev_realize_and_unref(dev, bus, &error_fatal);
236 static void s390_create_sclpconsole(const char *type, Chardev *chardev)
238 DeviceState *dev;
240 dev = qdev_new(type);
241 qdev_prop_set_chr(dev, "chardev", chardev);
242 qdev_realize_and_unref(dev, sclp_get_event_facility_bus(), &error_fatal);
245 static void ccw_init(MachineState *machine)
247 int ret;
248 VirtualCssBus *css_bus;
249 DeviceState *dev;
251 s390_sclp_init();
252 /* init memory + setup max page size. Required for the CPU model */
253 s390_memory_init(machine->ram);
255 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
256 s390_init_cpus(machine);
258 /* Need CPU model to be determined before we can set up PV */
259 s390_pv_init(machine->cgs, &error_fatal);
261 s390_flic_init();
263 /* init the SIGP facility */
264 s390_init_sigp();
266 /* create AP bridge and bus(es) */
267 s390_init_ap();
269 /* get a BUS */
270 css_bus = virtual_css_bus_init();
271 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
272 machine->initrd_filename,
273 machine->firmware ?: "s390-ccw.img",
274 "s390-netboot.img", true);
276 dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE);
277 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
278 OBJECT(dev));
279 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
281 /* register hypercalls */
282 virtio_ccw_register_hcalls();
284 s390_enable_css_support(s390_cpu_addr2state(0));
286 ret = css_create_css_image(VIRTUAL_CSSID, true);
288 assert(ret == 0);
289 if (css_migration_enabled()) {
290 css_register_vmstate();
293 /* Create VirtIO network adapters */
294 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
296 /* init consoles */
297 if (serial_hd(0)) {
298 s390_create_sclpconsole("sclpconsole", serial_hd(0));
300 if (serial_hd(1)) {
301 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
304 /* init the TOD clock */
305 s390_init_tod();
308 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
309 DeviceState *dev, Error **errp)
311 MachineState *ms = MACHINE(hotplug_dev);
312 S390CPU *cpu = S390_CPU(dev);
314 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
315 ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
317 if (dev->hotplugged) {
318 raise_irq_cpu_hotplug();
322 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
324 S390CPU *cpu = S390_CPU(cs);
326 s390_ipl_prepare_cpu(cpu);
327 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
330 static void s390_machine_unprotect(S390CcwMachineState *ms)
332 s390_pv_vm_disable();
333 ms->pv = false;
334 migrate_del_blocker(pv_mig_blocker);
335 error_free_or_abort(&pv_mig_blocker);
336 ram_block_discard_disable(false);
339 static int s390_machine_protect(S390CcwMachineState *ms)
341 Error *local_err = NULL;
342 int rc;
345 * Discarding of memory in RAM blocks does not work as expected with
346 * protected VMs. Sharing and unsharing pages would be required. Disable
347 * it for now, until until we have a solution to make at least Linux
348 * guests either support it (e.g., virtio-balloon) or fail gracefully.
350 rc = ram_block_discard_disable(true);
351 if (rc) {
352 error_report("protected VMs: cannot disable RAM discard");
353 return rc;
356 error_setg(&pv_mig_blocker,
357 "protected VMs are currently not migratable.");
358 rc = migrate_add_blocker(pv_mig_blocker, &local_err);
359 if (rc) {
360 ram_block_discard_disable(false);
361 error_report_err(local_err);
362 error_free_or_abort(&pv_mig_blocker);
363 return rc;
366 /* Create SE VM */
367 rc = s390_pv_vm_enable();
368 if (rc) {
369 ram_block_discard_disable(false);
370 migrate_del_blocker(pv_mig_blocker);
371 error_free_or_abort(&pv_mig_blocker);
372 return rc;
375 ms->pv = true;
377 /* Will return 0 if API is not available since it's not vital */
378 rc = s390_pv_query_info();
379 if (rc) {
380 goto out_err;
383 /* Set SE header and unpack */
384 rc = s390_ipl_prepare_pv_header();
385 if (rc) {
386 goto out_err;
389 /* Decrypt image */
390 rc = s390_ipl_pv_unpack();
391 if (rc) {
392 goto out_err;
395 /* Verify integrity */
396 rc = s390_pv_verify();
397 if (rc) {
398 goto out_err;
400 return rc;
402 out_err:
403 s390_machine_unprotect(ms);
404 return rc;
407 static void s390_pv_prepare_reset(S390CcwMachineState *ms)
409 CPUState *cs;
411 if (!s390_is_pv()) {
412 return;
414 /* Unsharing requires all cpus to be stopped */
415 CPU_FOREACH(cs) {
416 s390_cpu_set_state(S390_CPU_STATE_STOPPED, S390_CPU(cs));
418 s390_pv_unshare();
419 s390_pv_prep_reset();
422 static void s390_machine_reset(MachineState *machine, ShutdownCause reason)
424 S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
425 enum s390_reset reset_type;
426 CPUState *cs, *t;
427 S390CPU *cpu;
429 /* get the reset parameters, reset them once done */
430 s390_ipl_get_reset_request(&cs, &reset_type);
432 /* all CPUs are paused and synchronized at this point */
433 s390_cmma_reset();
435 cpu = S390_CPU(cs);
437 switch (reset_type) {
438 case S390_RESET_EXTERNAL:
439 case S390_RESET_REIPL:
440 if (s390_is_pv()) {
441 s390_machine_unprotect(ms);
444 qemu_devices_reset(reason);
445 s390_crypto_reset();
447 /* configure and start the ipl CPU only */
448 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
449 break;
450 case S390_RESET_MODIFIED_CLEAR:
452 * Subsystem reset needs to be done before we unshare memory
453 * and lose access to VIRTIO structures in guest memory.
455 subsystem_reset();
456 s390_crypto_reset();
457 s390_pv_prepare_reset(ms);
458 CPU_FOREACH(t) {
459 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
461 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
462 break;
463 case S390_RESET_LOAD_NORMAL:
465 * Subsystem reset needs to be done before we unshare memory
466 * and lose access to VIRTIO structures in guest memory.
468 subsystem_reset();
469 s390_pv_prepare_reset(ms);
470 CPU_FOREACH(t) {
471 if (t == cs) {
472 continue;
474 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
476 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
477 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
478 break;
479 case S390_RESET_PV: /* Subcode 10 */
480 subsystem_reset();
481 s390_crypto_reset();
483 CPU_FOREACH(t) {
484 if (t == cs) {
485 continue;
487 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
489 run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
491 if (s390_machine_protect(ms)) {
492 s390_pv_inject_reset_error(cs);
494 * Continue after the diag308 so the guest knows something
495 * went wrong.
497 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
498 return;
501 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
502 break;
503 default:
504 g_assert_not_reached();
507 CPU_FOREACH(t) {
508 run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(0));
510 s390_ipl_clear_reset_request();
513 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
514 DeviceState *dev, Error **errp)
516 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
517 s390_cpu_plug(hotplug_dev, dev, errp);
521 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
522 DeviceState *dev, Error **errp)
524 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
525 error_setg(errp, "CPU hot unplug not supported on this machine");
526 return;
530 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
531 unsigned cpu_index)
533 MachineClass *mc = MACHINE_GET_CLASS(ms);
534 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
536 assert(cpu_index < possible_cpus->len);
537 return possible_cpus->cpus[cpu_index].props;
540 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
542 int i;
543 unsigned int max_cpus = ms->smp.max_cpus;
545 if (ms->possible_cpus) {
546 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
547 return ms->possible_cpus;
550 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
551 sizeof(CPUArchId) * max_cpus);
552 ms->possible_cpus->len = max_cpus;
553 for (i = 0; i < ms->possible_cpus->len; i++) {
554 ms->possible_cpus->cpus[i].type = ms->cpu_type;
555 ms->possible_cpus->cpus[i].vcpus_count = 1;
556 ms->possible_cpus->cpus[i].arch_id = i;
557 ms->possible_cpus->cpus[i].props.has_core_id = true;
558 ms->possible_cpus->cpus[i].props.core_id = i;
561 return ms->possible_cpus;
564 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
565 DeviceState *dev)
567 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
568 return HOTPLUG_HANDLER(machine);
570 return NULL;
573 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
575 CPUState *cs = qemu_get_cpu(cpu_index);
577 s390_cpu_restart(S390_CPU(cs));
580 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
582 /* same logic as in sclp.c */
583 int increment_size = 20;
584 ram_addr_t newsz;
586 while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
587 increment_size++;
589 newsz = sz >> increment_size << increment_size;
591 if (sz != newsz) {
592 qemu_printf("Ram size %" PRIu64 "MB was fixed up to %" PRIu64
593 "MB to match machine restrictions. Consider updating "
594 "the guest definition.\n", (uint64_t) (sz / MiB),
595 (uint64_t) (newsz / MiB));
597 return newsz;
600 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
602 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
604 return ms->aes_key_wrap;
607 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
608 Error **errp)
610 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
612 ms->aes_key_wrap = value;
615 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
617 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
619 return ms->dea_key_wrap;
622 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
623 Error **errp)
625 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
627 ms->dea_key_wrap = value;
630 static S390CcwMachineClass *current_mc;
633 * Get the class of the s390-ccw-virtio machine that is currently in use.
634 * Note: libvirt is using the "none" machine to probe for the features of the
635 * host CPU, so in case this is called with the "none" machine, the function
636 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
637 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
638 * below return the correct default value for the "none" machine.
640 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
641 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
642 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
643 * CPU initialization and s390_has_feat() later should be sufficient.
645 static S390CcwMachineClass *get_machine_class(void)
647 if (unlikely(!current_mc)) {
649 * No s390 ccw machine was instantiated, we are likely to
650 * be called for the 'none' machine. The properties will
651 * have their after-initialization values.
653 current_mc = S390_CCW_MACHINE_CLASS(
654 object_class_by_name(TYPE_S390_CCW_MACHINE));
656 return current_mc;
659 bool ri_allowed(void)
661 return get_machine_class()->ri_allowed;
664 bool cpu_model_allowed(void)
666 return get_machine_class()->cpu_model_allowed;
669 bool hpage_1m_allowed(void)
671 return get_machine_class()->hpage_1m_allowed;
674 static void machine_get_loadparm(Object *obj, Visitor *v,
675 const char *name, void *opaque,
676 Error **errp)
678 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
679 char *str = g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
681 visit_type_str(v, name, &str, errp);
682 g_free(str);
685 static void machine_set_loadparm(Object *obj, Visitor *v,
686 const char *name, void *opaque,
687 Error **errp)
689 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
690 char *val;
691 int i;
693 if (!visit_type_str(v, name, &val, errp)) {
694 return;
697 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
698 uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
700 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
701 (c == ' ')) {
702 ms->loadparm[i] = c;
703 } else {
704 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
705 c, c);
706 return;
710 for (; i < sizeof(ms->loadparm); i++) {
711 ms->loadparm[i] = ' '; /* pad right with spaces */
715 static void ccw_machine_class_init(ObjectClass *oc, void *data)
717 MachineClass *mc = MACHINE_CLASS(oc);
718 NMIClass *nc = NMI_CLASS(oc);
719 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
720 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
722 s390mc->ri_allowed = true;
723 s390mc->cpu_model_allowed = true;
724 s390mc->css_migration_enabled = true;
725 s390mc->hpage_1m_allowed = true;
726 s390mc->max_threads = 1;
727 mc->init = ccw_init;
728 mc->reset = s390_machine_reset;
729 mc->block_default_type = IF_VIRTIO;
730 mc->no_cdrom = 1;
731 mc->no_floppy = 1;
732 mc->no_parallel = 1;
733 mc->no_sdcard = 1;
734 mc->max_cpus = S390_MAX_CPUS;
735 mc->has_hotpluggable_cpus = true;
736 assert(!mc->get_hotplug_handler);
737 mc->get_hotplug_handler = s390_get_hotplug_handler;
738 mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
739 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
740 /* it is overridden with 'host' cpu *in kvm_arch_init* */
741 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
742 hc->plug = s390_machine_device_plug;
743 hc->unplug_request = s390_machine_device_unplug_request;
744 nc->nmi_monitor_handler = s390_nmi;
745 mc->default_ram_id = "s390.ram";
747 object_class_property_add_bool(oc, "aes-key-wrap",
748 machine_get_aes_key_wrap,
749 machine_set_aes_key_wrap);
750 object_class_property_set_description(oc, "aes-key-wrap",
751 "enable/disable AES key wrapping using the CPACF wrapping key");
753 object_class_property_add_bool(oc, "dea-key-wrap",
754 machine_get_dea_key_wrap,
755 machine_set_dea_key_wrap);
756 object_class_property_set_description(oc, "dea-key-wrap",
757 "enable/disable DEA key wrapping using the CPACF wrapping key");
759 object_class_property_add(oc, "loadparm", "loadparm",
760 machine_get_loadparm, machine_set_loadparm,
761 NULL, NULL);
762 object_class_property_set_description(oc, "loadparm",
763 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
764 " to upper case) to pass to machine loader, boot manager,"
765 " and guest kernel");
768 static inline void s390_machine_initfn(Object *obj)
770 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
772 ms->aes_key_wrap = true;
773 ms->dea_key_wrap = true;
776 static const TypeInfo ccw_machine_info = {
777 .name = TYPE_S390_CCW_MACHINE,
778 .parent = TYPE_MACHINE,
779 .abstract = true,
780 .instance_size = sizeof(S390CcwMachineState),
781 .instance_init = s390_machine_initfn,
782 .class_size = sizeof(S390CcwMachineClass),
783 .class_init = ccw_machine_class_init,
784 .interfaces = (InterfaceInfo[]) {
785 { TYPE_NMI },
786 { TYPE_HOTPLUG_HANDLER},
791 bool css_migration_enabled(void)
793 return get_machine_class()->css_migration_enabled;
796 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
797 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
798 void *data) \
800 MachineClass *mc = MACHINE_CLASS(oc); \
801 ccw_machine_##suffix##_class_options(mc); \
802 mc->desc = "Virtual s390x machine (version " verstr ")"; \
803 if (latest) { \
804 mc->alias = "s390-ccw-virtio"; \
805 mc->is_default = true; \
808 static void ccw_machine_##suffix##_instance_init(Object *obj) \
810 MachineState *machine = MACHINE(obj); \
811 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
812 ccw_machine_##suffix##_instance_options(machine); \
814 static const TypeInfo ccw_machine_##suffix##_info = { \
815 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
816 .parent = TYPE_S390_CCW_MACHINE, \
817 .class_init = ccw_machine_##suffix##_class_init, \
818 .instance_init = ccw_machine_##suffix##_instance_init, \
819 }; \
820 static void ccw_machine_register_##suffix(void) \
822 type_register_static(&ccw_machine_##suffix##_info); \
824 type_init(ccw_machine_register_##suffix)
826 static void ccw_machine_8_0_instance_options(MachineState *machine)
830 static void ccw_machine_8_0_class_options(MachineClass *mc)
833 DEFINE_CCW_MACHINE(8_0, "8.0", true);
835 static void ccw_machine_7_2_instance_options(MachineState *machine)
837 ccw_machine_8_0_instance_options(machine);
840 static void ccw_machine_7_2_class_options(MachineClass *mc)
842 ccw_machine_8_0_class_options(mc);
843 compat_props_add(mc->compat_props, hw_compat_7_2, hw_compat_7_2_len);
845 DEFINE_CCW_MACHINE(7_2, "7.2", false);
847 static void ccw_machine_7_1_instance_options(MachineState *machine)
849 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_1 };
851 ccw_machine_7_2_instance_options(machine);
852 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE);
853 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
856 static void ccw_machine_7_1_class_options(MachineClass *mc)
858 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
859 static GlobalProperty compat[] = {
860 { TYPE_S390_PCI_DEVICE, "interpret", "off", },
861 { TYPE_S390_PCI_DEVICE, "forwarding-assist", "off", },
864 ccw_machine_7_2_class_options(mc);
865 compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len);
866 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
867 s390mc->max_threads = S390_MAX_CPUS;
869 DEFINE_CCW_MACHINE(7_1, "7.1", false);
871 static void ccw_machine_7_0_instance_options(MachineState *machine)
873 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_0 };
875 ccw_machine_7_1_instance_options(machine);
876 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
879 static void ccw_machine_7_0_class_options(MachineClass *mc)
881 ccw_machine_7_1_class_options(mc);
882 compat_props_add(mc->compat_props, hw_compat_7_0, hw_compat_7_0_len);
884 DEFINE_CCW_MACHINE(7_0, "7.0", false);
886 static void ccw_machine_6_2_instance_options(MachineState *machine)
888 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_2 };
890 ccw_machine_7_0_instance_options(machine);
891 s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat);
894 static void ccw_machine_6_2_class_options(MachineClass *mc)
896 ccw_machine_7_0_class_options(mc);
897 compat_props_add(mc->compat_props, hw_compat_6_2, hw_compat_6_2_len);
899 DEFINE_CCW_MACHINE(6_2, "6.2", false);
901 static void ccw_machine_6_1_instance_options(MachineState *machine)
903 ccw_machine_6_2_instance_options(machine);
904 s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA);
905 s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2);
906 s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH);
907 s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP);
908 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI);
911 static void ccw_machine_6_1_class_options(MachineClass *mc)
913 ccw_machine_6_2_class_options(mc);
914 compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
915 mc->smp_props.prefer_sockets = true;
917 DEFINE_CCW_MACHINE(6_1, "6.1", false);
919 static void ccw_machine_6_0_instance_options(MachineState *machine)
921 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_0 };
923 ccw_machine_6_1_instance_options(machine);
924 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
927 static void ccw_machine_6_0_class_options(MachineClass *mc)
929 ccw_machine_6_1_class_options(mc);
930 compat_props_add(mc->compat_props, hw_compat_6_0, hw_compat_6_0_len);
932 DEFINE_CCW_MACHINE(6_0, "6.0", false);
934 static void ccw_machine_5_2_instance_options(MachineState *machine)
936 ccw_machine_6_0_instance_options(machine);
939 static void ccw_machine_5_2_class_options(MachineClass *mc)
941 ccw_machine_6_0_class_options(mc);
942 compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len);
944 DEFINE_CCW_MACHINE(5_2, "5.2", false);
946 static void ccw_machine_5_1_instance_options(MachineState *machine)
948 ccw_machine_5_2_instance_options(machine);
951 static void ccw_machine_5_1_class_options(MachineClass *mc)
953 ccw_machine_5_2_class_options(mc);
954 compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len);
956 DEFINE_CCW_MACHINE(5_1, "5.1", false);
958 static void ccw_machine_5_0_instance_options(MachineState *machine)
960 ccw_machine_5_1_instance_options(machine);
963 static void ccw_machine_5_0_class_options(MachineClass *mc)
965 ccw_machine_5_1_class_options(mc);
966 compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len);
968 DEFINE_CCW_MACHINE(5_0, "5.0", false);
970 static void ccw_machine_4_2_instance_options(MachineState *machine)
972 ccw_machine_5_0_instance_options(machine);
975 static void ccw_machine_4_2_class_options(MachineClass *mc)
977 ccw_machine_5_0_class_options(mc);
978 mc->fixup_ram_size = s390_fixup_ram_size;
979 compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
981 DEFINE_CCW_MACHINE(4_2, "4.2", false);
983 static void ccw_machine_4_1_instance_options(MachineState *machine)
985 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
986 ccw_machine_4_2_instance_options(machine);
987 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
990 static void ccw_machine_4_1_class_options(MachineClass *mc)
992 ccw_machine_4_2_class_options(mc);
993 compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
995 DEFINE_CCW_MACHINE(4_1, "4.1", false);
997 static void ccw_machine_4_0_instance_options(MachineState *machine)
999 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
1000 ccw_machine_4_1_instance_options(machine);
1001 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1004 static void ccw_machine_4_0_class_options(MachineClass *mc)
1006 ccw_machine_4_1_class_options(mc);
1007 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
1009 DEFINE_CCW_MACHINE(4_0, "4.0", false);
1011 static void ccw_machine_3_1_instance_options(MachineState *machine)
1013 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
1014 ccw_machine_4_0_instance_options(machine);
1015 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
1016 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
1017 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1020 static void ccw_machine_3_1_class_options(MachineClass *mc)
1022 ccw_machine_4_0_class_options(mc);
1023 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
1025 DEFINE_CCW_MACHINE(3_1, "3.1", false);
1027 static void ccw_machine_3_0_instance_options(MachineState *machine)
1029 ccw_machine_3_1_instance_options(machine);
1032 static void ccw_machine_3_0_class_options(MachineClass *mc)
1034 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1036 s390mc->hpage_1m_allowed = false;
1037 ccw_machine_3_1_class_options(mc);
1038 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
1040 DEFINE_CCW_MACHINE(3_0, "3.0", false);
1042 static void ccw_machine_2_12_instance_options(MachineState *machine)
1044 ccw_machine_3_0_instance_options(machine);
1045 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
1046 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
1049 static void ccw_machine_2_12_class_options(MachineClass *mc)
1051 ccw_machine_3_0_class_options(mc);
1052 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
1054 DEFINE_CCW_MACHINE(2_12, "2.12", false);
1056 static void ccw_machine_2_11_instance_options(MachineState *machine)
1058 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
1059 ccw_machine_2_12_instance_options(machine);
1061 /* before 2.12 we emulated the very first z900 */
1062 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
1065 static void ccw_machine_2_11_class_options(MachineClass *mc)
1067 static GlobalProperty compat[] = {
1068 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
1071 ccw_machine_2_12_class_options(mc);
1072 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
1073 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1075 DEFINE_CCW_MACHINE(2_11, "2.11", false);
1077 static void ccw_machine_2_10_instance_options(MachineState *machine)
1079 ccw_machine_2_11_instance_options(machine);
1082 static void ccw_machine_2_10_class_options(MachineClass *mc)
1084 ccw_machine_2_11_class_options(mc);
1085 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
1087 DEFINE_CCW_MACHINE(2_10, "2.10", false);
1089 static void ccw_machine_2_9_instance_options(MachineState *machine)
1091 ccw_machine_2_10_instance_options(machine);
1092 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
1093 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
1094 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
1095 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
1096 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
1099 static void ccw_machine_2_9_class_options(MachineClass *mc)
1101 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1102 static GlobalProperty compat[] = {
1103 { TYPE_S390_STATTRIB, "migration-enabled", "off", },
1106 ccw_machine_2_10_class_options(mc);
1107 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
1108 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1109 s390mc->css_migration_enabled = false;
1111 DEFINE_CCW_MACHINE(2_9, "2.9", false);
1113 static void ccw_machine_2_8_instance_options(MachineState *machine)
1115 ccw_machine_2_9_instance_options(machine);
1118 static void ccw_machine_2_8_class_options(MachineClass *mc)
1120 static GlobalProperty compat[] = {
1121 { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
1124 ccw_machine_2_9_class_options(mc);
1125 compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
1126 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1128 DEFINE_CCW_MACHINE(2_8, "2.8", false);
1130 static void ccw_machine_2_7_instance_options(MachineState *machine)
1132 ccw_machine_2_8_instance_options(machine);
1135 static void ccw_machine_2_7_class_options(MachineClass *mc)
1137 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1139 s390mc->cpu_model_allowed = false;
1140 ccw_machine_2_8_class_options(mc);
1141 compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
1143 DEFINE_CCW_MACHINE(2_7, "2.7", false);
1145 static void ccw_machine_2_6_instance_options(MachineState *machine)
1147 ccw_machine_2_7_instance_options(machine);
1150 static void ccw_machine_2_6_class_options(MachineClass *mc)
1152 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1153 static GlobalProperty compat[] = {
1154 { TYPE_S390_IPL, "iplbext_migration", "off", },
1155 { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
1158 s390mc->ri_allowed = false;
1159 ccw_machine_2_7_class_options(mc);
1160 compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
1161 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1163 DEFINE_CCW_MACHINE(2_6, "2.6", false);
1165 static void ccw_machine_2_5_instance_options(MachineState *machine)
1167 ccw_machine_2_6_instance_options(machine);
1170 static void ccw_machine_2_5_class_options(MachineClass *mc)
1172 ccw_machine_2_6_class_options(mc);
1173 compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
1175 DEFINE_CCW_MACHINE(2_5, "2.5", false);
1177 static void ccw_machine_2_4_instance_options(MachineState *machine)
1179 ccw_machine_2_5_instance_options(machine);
1182 static void ccw_machine_2_4_class_options(MachineClass *mc)
1184 static GlobalProperty compat[] = {
1185 { TYPE_S390_SKEYS, "migration-enabled", "off", },
1186 { "virtio-blk-ccw", "max_revision", "0", },
1187 { "virtio-balloon-ccw", "max_revision", "0", },
1188 { "virtio-serial-ccw", "max_revision", "0", },
1189 { "virtio-9p-ccw", "max_revision", "0", },
1190 { "virtio-rng-ccw", "max_revision", "0", },
1191 { "virtio-net-ccw", "max_revision", "0", },
1192 { "virtio-scsi-ccw", "max_revision", "0", },
1193 { "vhost-scsi-ccw", "max_revision", "0", },
1196 ccw_machine_2_5_class_options(mc);
1197 compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
1198 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1200 DEFINE_CCW_MACHINE(2_4, "2.4", false);
1202 static void ccw_machine_register_types(void)
1204 type_register_static(&ccw_machine_info);
1207 type_init(ccw_machine_register_types)