qom: Use returned bool to check for failure, Coccinelle part
[qemu/ar7.git] / hw / s390x / s390-virtio-ccw.c
blob1a171f0c9621c0bf0797aa9a3d359c86fb4a9f32
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 "cpu.h"
17 #include "hw/boards.h"
18 #include "exec/address-spaces.h"
19 #include "exec/ram_addr.h"
20 #include "hw/s390x/s390-virtio-hcall.h"
21 #include "hw/s390x/sclp.h"
22 #include "hw/s390x/s390_flic.h"
23 #include "hw/s390x/ioinst.h"
24 #include "hw/s390x/css.h"
25 #include "virtio-ccw.h"
26 #include "qemu/config-file.h"
27 #include "qemu/ctype.h"
28 #include "qemu/error-report.h"
29 #include "qemu/option.h"
30 #include "qemu/qemu-print.h"
31 #include "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"
36 #include "ipl.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"
42 #include "hw/nmi.h"
43 #include "hw/qdev-properties.h"
44 #include "hw/s390x/tod.h"
45 #include "sysemu/sysemu.h"
46 #include "hw/s390x/pv.h"
47 #include "migration/blocker.h"
49 static Error *pv_mig_blocker;
51 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
53 static MachineState *ms;
55 if (!ms) {
56 ms = MACHINE(qdev_get_machine());
57 g_assert(ms->possible_cpus);
60 /* CPU address corresponds to the core_id and the index */
61 if (cpu_addr >= ms->possible_cpus->len) {
62 return NULL;
64 return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
67 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
68 Error **errp)
70 S390CPU *cpu = S390_CPU(object_new(typename));
71 Error *err = NULL;
73 if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, &err)) {
74 goto out;
76 qdev_realize(DEVICE(cpu), NULL, &err);
78 out:
79 object_unref(OBJECT(cpu));
80 if (err) {
81 error_propagate(errp, err);
82 cpu = NULL;
84 return cpu;
87 static void s390_init_cpus(MachineState *machine)
89 MachineClass *mc = MACHINE_GET_CLASS(machine);
90 int i;
92 /* initialize possible_cpus */
93 mc->possible_cpu_arch_ids(machine);
95 for (i = 0; i < machine->smp.cpus; i++) {
96 s390x_new_cpu(machine->cpu_type, i, &error_fatal);
100 static const char *const reset_dev_types[] = {
101 TYPE_VIRTUAL_CSS_BRIDGE,
102 "s390-sclp-event-facility",
103 "s390-flic",
104 "diag288",
107 static void subsystem_reset(void)
109 DeviceState *dev;
110 int i;
112 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
113 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
114 if (dev) {
115 qdev_reset_all(dev);
120 static int virtio_ccw_hcall_notify(const uint64_t *args)
122 uint64_t subch_id = args[0];
123 uint64_t queue = args[1];
124 SubchDev *sch;
125 int cssid, ssid, schid, m;
127 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
128 return -EINVAL;
130 sch = css_find_subch(m, cssid, ssid, schid);
131 if (!sch || !css_subch_visible(sch)) {
132 return -EINVAL;
134 if (queue >= VIRTIO_QUEUE_MAX) {
135 return -EINVAL;
137 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
138 return 0;
142 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
144 uint64_t mem = args[0];
146 if (mem < ram_size) {
147 /* Early printk */
148 return 0;
150 return -EINVAL;
153 static void virtio_ccw_register_hcalls(void)
155 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
156 virtio_ccw_hcall_notify);
157 /* Tolerate early printk. */
158 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
159 virtio_ccw_hcall_early_printk);
162 static void s390_memory_init(MemoryRegion *ram)
164 MemoryRegion *sysmem = get_system_memory();
165 Error *local_err = NULL;
167 /* allocate RAM for core */
168 memory_region_add_subregion(sysmem, 0, ram);
171 * Configure the maximum page size. As no memory devices were created
172 * yet, this is the page size of initial memory only.
174 s390_set_max_pagesize(qemu_maxrampagesize(), &local_err);
175 if (local_err) {
176 error_report_err(local_err);
177 exit(EXIT_FAILURE);
179 /* Initialize storage key device */
180 s390_skeys_init();
181 /* Initialize storage attributes device */
182 s390_stattrib_init();
185 static void s390_init_ipl_dev(const char *kernel_filename,
186 const char *kernel_cmdline,
187 const char *initrd_filename, const char *firmware,
188 const char *netboot_fw, bool enforce_bios)
190 Object *new = object_new(TYPE_S390_IPL);
191 DeviceState *dev = DEVICE(new);
192 char *netboot_fw_prop;
194 if (kernel_filename) {
195 qdev_prop_set_string(dev, "kernel", kernel_filename);
197 if (initrd_filename) {
198 qdev_prop_set_string(dev, "initrd", initrd_filename);
200 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
201 qdev_prop_set_string(dev, "firmware", firmware);
202 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
203 netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
204 if (!strlen(netboot_fw_prop)) {
205 qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
207 g_free(netboot_fw_prop);
208 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
209 new);
210 object_unref(new);
211 qdev_realize(dev, NULL, &error_fatal);
214 static void s390_create_virtio_net(BusState *bus, const char *name)
216 int i;
218 for (i = 0; i < nb_nics; i++) {
219 NICInfo *nd = &nd_table[i];
220 DeviceState *dev;
222 if (!nd->model) {
223 nd->model = g_strdup("virtio");
226 qemu_check_nic_model(nd, "virtio");
228 dev = qdev_new(name);
229 qdev_set_nic_properties(dev, nd);
230 qdev_realize_and_unref(dev, bus, &error_fatal);
234 static void s390_create_sclpconsole(const char *type, Chardev *chardev)
236 DeviceState *dev;
238 dev = qdev_new(type);
239 qdev_prop_set_chr(dev, "chardev", chardev);
240 qdev_realize_and_unref(dev, sclp_get_event_facility_bus(), &error_fatal);
243 static void ccw_init(MachineState *machine)
245 int ret;
246 VirtualCssBus *css_bus;
247 DeviceState *dev;
249 s390_sclp_init();
250 /* init memory + setup max page size. Required for the CPU model */
251 s390_memory_init(machine->ram);
253 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
254 s390_init_cpus(machine);
256 s390_flic_init();
258 /* init the SIGP facility */
259 s390_init_sigp();
261 /* create AP bridge and bus(es) */
262 s390_init_ap();
264 /* get a BUS */
265 css_bus = virtual_css_bus_init();
266 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
267 machine->initrd_filename, "s390-ccw.img",
268 "s390-netboot.img", true);
270 dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE);
271 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
272 OBJECT(dev));
273 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
275 /* register hypercalls */
276 virtio_ccw_register_hcalls();
278 s390_enable_css_support(s390_cpu_addr2state(0));
280 ret = css_create_css_image(VIRTUAL_CSSID, true);
282 assert(ret == 0);
283 if (css_migration_enabled()) {
284 css_register_vmstate();
287 /* Create VirtIO network adapters */
288 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
290 /* init consoles */
291 if (serial_hd(0)) {
292 s390_create_sclpconsole("sclpconsole", serial_hd(0));
294 if (serial_hd(1)) {
295 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
298 /* init the TOD clock */
299 s390_init_tod();
302 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
303 DeviceState *dev, Error **errp)
305 MachineState *ms = MACHINE(hotplug_dev);
306 S390CPU *cpu = S390_CPU(dev);
308 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
309 ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
311 if (dev->hotplugged) {
312 raise_irq_cpu_hotplug();
316 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
318 S390CPU *cpu = S390_CPU(cs);
320 s390_ipl_prepare_cpu(cpu);
321 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
324 static void s390_machine_unprotect(S390CcwMachineState *ms)
326 s390_pv_vm_disable();
327 ms->pv = false;
328 migrate_del_blocker(pv_mig_blocker);
329 error_free_or_abort(&pv_mig_blocker);
330 ram_block_discard_disable(false);
333 static int s390_machine_protect(S390CcwMachineState *ms)
335 Error *local_err = NULL;
336 int rc;
339 * Discarding of memory in RAM blocks does not work as expected with
340 * protected VMs. Sharing and unsharing pages would be required. Disable
341 * it for now, until until we have a solution to make at least Linux
342 * guests either support it (e.g., virtio-balloon) or fail gracefully.
344 rc = ram_block_discard_disable(true);
345 if (rc) {
346 error_report("protected VMs: cannot disable RAM discard");
347 return rc;
350 error_setg(&pv_mig_blocker,
351 "protected VMs are currently not migrateable.");
352 rc = migrate_add_blocker(pv_mig_blocker, &local_err);
353 if (rc) {
354 ram_block_discard_disable(false);
355 error_report_err(local_err);
356 error_free_or_abort(&pv_mig_blocker);
357 return rc;
360 /* Create SE VM */
361 rc = s390_pv_vm_enable();
362 if (rc) {
363 ram_block_discard_disable(false);
364 migrate_del_blocker(pv_mig_blocker);
365 error_free_or_abort(&pv_mig_blocker);
366 return rc;
369 ms->pv = true;
371 /* Set SE header and unpack */
372 rc = s390_ipl_prepare_pv_header();
373 if (rc) {
374 goto out_err;
377 /* Decrypt image */
378 rc = s390_ipl_pv_unpack();
379 if (rc) {
380 goto out_err;
383 /* Verify integrity */
384 rc = s390_pv_verify();
385 if (rc) {
386 goto out_err;
388 return rc;
390 out_err:
391 s390_machine_unprotect(ms);
392 return rc;
395 static void s390_pv_prepare_reset(S390CcwMachineState *ms)
397 CPUState *cs;
399 if (!s390_is_pv()) {
400 return;
402 /* Unsharing requires all cpus to be stopped */
403 CPU_FOREACH(cs) {
404 s390_cpu_set_state(S390_CPU_STATE_STOPPED, S390_CPU(cs));
406 s390_pv_unshare();
407 s390_pv_prep_reset();
410 static void s390_machine_reset(MachineState *machine)
412 S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
413 enum s390_reset reset_type;
414 CPUState *cs, *t;
415 S390CPU *cpu;
417 /* get the reset parameters, reset them once done */
418 s390_ipl_get_reset_request(&cs, &reset_type);
420 /* all CPUs are paused and synchronized at this point */
421 s390_cmma_reset();
423 cpu = S390_CPU(cs);
425 switch (reset_type) {
426 case S390_RESET_EXTERNAL:
427 case S390_RESET_REIPL:
428 if (s390_is_pv()) {
429 s390_machine_unprotect(ms);
432 qemu_devices_reset();
433 s390_crypto_reset();
435 /* configure and start the ipl CPU only */
436 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
437 break;
438 case S390_RESET_MODIFIED_CLEAR:
440 * Susbsystem reset needs to be done before we unshare memory
441 * and lose access to VIRTIO structures in guest memory.
443 subsystem_reset();
444 s390_crypto_reset();
445 s390_pv_prepare_reset(ms);
446 CPU_FOREACH(t) {
447 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
449 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
450 break;
451 case S390_RESET_LOAD_NORMAL:
453 * Susbsystem reset needs to be done before we unshare memory
454 * and lose access to VIRTIO structures in guest memory.
456 subsystem_reset();
457 s390_pv_prepare_reset(ms);
458 CPU_FOREACH(t) {
459 if (t == cs) {
460 continue;
462 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
464 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
465 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
466 break;
467 case S390_RESET_PV: /* Subcode 10 */
468 subsystem_reset();
469 s390_crypto_reset();
471 CPU_FOREACH(t) {
472 if (t == cs) {
473 continue;
475 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
477 run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
479 if (s390_machine_protect(ms)) {
480 s390_pv_inject_reset_error(cs);
482 * Continue after the diag308 so the guest knows something
483 * went wrong.
485 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
486 return;
489 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
490 break;
491 default:
492 g_assert_not_reached();
494 s390_ipl_clear_reset_request();
497 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
498 DeviceState *dev, Error **errp)
500 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
501 s390_cpu_plug(hotplug_dev, dev, errp);
505 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
506 DeviceState *dev, Error **errp)
508 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
509 error_setg(errp, "CPU hot unplug not supported on this machine");
510 return;
514 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
515 unsigned cpu_index)
517 MachineClass *mc = MACHINE_GET_CLASS(ms);
518 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
520 assert(cpu_index < possible_cpus->len);
521 return possible_cpus->cpus[cpu_index].props;
524 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
526 int i;
527 unsigned int max_cpus = ms->smp.max_cpus;
529 if (ms->possible_cpus) {
530 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
531 return ms->possible_cpus;
534 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
535 sizeof(CPUArchId) * max_cpus);
536 ms->possible_cpus->len = max_cpus;
537 for (i = 0; i < ms->possible_cpus->len; i++) {
538 ms->possible_cpus->cpus[i].type = ms->cpu_type;
539 ms->possible_cpus->cpus[i].vcpus_count = 1;
540 ms->possible_cpus->cpus[i].arch_id = i;
541 ms->possible_cpus->cpus[i].props.has_core_id = true;
542 ms->possible_cpus->cpus[i].props.core_id = i;
545 return ms->possible_cpus;
548 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
549 DeviceState *dev)
551 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
552 return HOTPLUG_HANDLER(machine);
554 return NULL;
557 static void s390_hot_add_cpu(MachineState *machine,
558 const int64_t id, Error **errp)
560 ObjectClass *oc;
562 g_assert(machine->possible_cpus->cpus[0].cpu);
563 oc = OBJECT_CLASS(CPU_GET_CLASS(machine->possible_cpus->cpus[0].cpu));
565 s390x_new_cpu(object_class_get_name(oc), id, errp);
568 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
570 CPUState *cs = qemu_get_cpu(cpu_index);
572 s390_cpu_restart(S390_CPU(cs));
575 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
577 /* same logic as in sclp.c */
578 int increment_size = 20;
579 ram_addr_t newsz;
581 while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
582 increment_size++;
584 newsz = sz >> increment_size << increment_size;
586 if (sz != newsz) {
587 qemu_printf("Ram size %" PRIu64 "MB was fixed up to %" PRIu64
588 "MB to match machine restrictions. Consider updating "
589 "the guest definition.\n", (uint64_t) (sz / MiB),
590 (uint64_t) (newsz / MiB));
592 return newsz;
595 static void ccw_machine_class_init(ObjectClass *oc, void *data)
597 MachineClass *mc = MACHINE_CLASS(oc);
598 NMIClass *nc = NMI_CLASS(oc);
599 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
600 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
602 s390mc->ri_allowed = true;
603 s390mc->cpu_model_allowed = true;
604 s390mc->css_migration_enabled = true;
605 s390mc->hpage_1m_allowed = true;
606 mc->init = ccw_init;
607 mc->reset = s390_machine_reset;
608 mc->hot_add_cpu = s390_hot_add_cpu;
609 mc->block_default_type = IF_VIRTIO;
610 mc->no_cdrom = 1;
611 mc->no_floppy = 1;
612 mc->no_parallel = 1;
613 mc->no_sdcard = 1;
614 mc->max_cpus = S390_MAX_CPUS;
615 mc->has_hotpluggable_cpus = true;
616 assert(!mc->get_hotplug_handler);
617 mc->get_hotplug_handler = s390_get_hotplug_handler;
618 mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
619 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
620 /* it is overridden with 'host' cpu *in kvm_arch_init* */
621 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
622 hc->plug = s390_machine_device_plug;
623 hc->unplug_request = s390_machine_device_unplug_request;
624 nc->nmi_monitor_handler = s390_nmi;
625 mc->default_ram_id = "s390.ram";
628 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
630 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
632 return ms->aes_key_wrap;
635 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
636 Error **errp)
638 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
640 ms->aes_key_wrap = value;
643 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
645 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
647 return ms->dea_key_wrap;
650 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
651 Error **errp)
653 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
655 ms->dea_key_wrap = value;
658 static S390CcwMachineClass *current_mc;
661 * Get the class of the s390-ccw-virtio machine that is currently in use.
662 * Note: libvirt is using the "none" machine to probe for the features of the
663 * host CPU, so in case this is called with the "none" machine, the function
664 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
665 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
666 * below return the correct default value for the "none" machine.
668 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
669 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
670 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
671 * CPU initialization and s390_has_feat() later should be sufficient.
673 static S390CcwMachineClass *get_machine_class(void)
675 if (unlikely(!current_mc)) {
677 * No s390 ccw machine was instantiated, we are likely to
678 * be called for the 'none' machine. The properties will
679 * have their after-initialization values.
681 current_mc = S390_MACHINE_CLASS(
682 object_class_by_name(TYPE_S390_CCW_MACHINE));
684 return current_mc;
687 bool ri_allowed(void)
689 return get_machine_class()->ri_allowed;
692 bool cpu_model_allowed(void)
694 return get_machine_class()->cpu_model_allowed;
697 bool hpage_1m_allowed(void)
699 return get_machine_class()->hpage_1m_allowed;
702 static char *machine_get_loadparm(Object *obj, Error **errp)
704 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
706 return g_memdup(ms->loadparm, sizeof(ms->loadparm));
709 static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
711 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
712 int i;
714 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
715 uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
717 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
718 (c == ' ')) {
719 ms->loadparm[i] = c;
720 } else {
721 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
722 c, c);
723 return;
727 for (; i < sizeof(ms->loadparm); i++) {
728 ms->loadparm[i] = ' '; /* pad right with spaces */
731 static inline void s390_machine_initfn(Object *obj)
733 object_property_add_bool(obj, "aes-key-wrap",
734 machine_get_aes_key_wrap,
735 machine_set_aes_key_wrap);
736 object_property_set_description(obj, "aes-key-wrap",
737 "enable/disable AES key wrapping using the CPACF wrapping key");
738 object_property_set_bool(obj, "aes-key-wrap", true, NULL);
740 object_property_add_bool(obj, "dea-key-wrap",
741 machine_get_dea_key_wrap,
742 machine_set_dea_key_wrap);
743 object_property_set_description(obj, "dea-key-wrap",
744 "enable/disable DEA key wrapping using the CPACF wrapping key");
745 object_property_set_bool(obj, "dea-key-wrap", true, NULL);
746 object_property_add_str(obj, "loadparm",
747 machine_get_loadparm, machine_set_loadparm);
748 object_property_set_description(obj, "loadparm",
749 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
750 " to upper case) to pass to machine loader, boot manager,"
751 " and guest kernel");
754 static const TypeInfo ccw_machine_info = {
755 .name = TYPE_S390_CCW_MACHINE,
756 .parent = TYPE_MACHINE,
757 .abstract = true,
758 .instance_size = sizeof(S390CcwMachineState),
759 .instance_init = s390_machine_initfn,
760 .class_size = sizeof(S390CcwMachineClass),
761 .class_init = ccw_machine_class_init,
762 .interfaces = (InterfaceInfo[]) {
763 { TYPE_NMI },
764 { TYPE_HOTPLUG_HANDLER},
769 bool css_migration_enabled(void)
771 return get_machine_class()->css_migration_enabled;
774 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
775 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
776 void *data) \
778 MachineClass *mc = MACHINE_CLASS(oc); \
779 ccw_machine_##suffix##_class_options(mc); \
780 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
781 if (latest) { \
782 mc->alias = "s390-ccw-virtio"; \
783 mc->is_default = true; \
786 static void ccw_machine_##suffix##_instance_init(Object *obj) \
788 MachineState *machine = MACHINE(obj); \
789 current_mc = S390_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
790 ccw_machine_##suffix##_instance_options(machine); \
792 static const TypeInfo ccw_machine_##suffix##_info = { \
793 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
794 .parent = TYPE_S390_CCW_MACHINE, \
795 .class_init = ccw_machine_##suffix##_class_init, \
796 .instance_init = ccw_machine_##suffix##_instance_init, \
797 }; \
798 static void ccw_machine_register_##suffix(void) \
800 type_register_static(&ccw_machine_##suffix##_info); \
802 type_init(ccw_machine_register_##suffix)
804 static void ccw_machine_5_1_instance_options(MachineState *machine)
808 static void ccw_machine_5_1_class_options(MachineClass *mc)
811 DEFINE_CCW_MACHINE(5_1, "5.1", true);
813 static void ccw_machine_5_0_instance_options(MachineState *machine)
815 ccw_machine_5_1_instance_options(machine);
818 static void ccw_machine_5_0_class_options(MachineClass *mc)
820 ccw_machine_5_1_class_options(mc);
821 compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len);
823 DEFINE_CCW_MACHINE(5_0, "5.0", false);
825 static void ccw_machine_4_2_instance_options(MachineState *machine)
827 ccw_machine_5_0_instance_options(machine);
830 static void ccw_machine_4_2_class_options(MachineClass *mc)
832 ccw_machine_5_0_class_options(mc);
833 mc->fixup_ram_size = s390_fixup_ram_size;
834 compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
836 DEFINE_CCW_MACHINE(4_2, "4.2", false);
838 static void ccw_machine_4_1_instance_options(MachineState *machine)
840 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
841 ccw_machine_4_2_instance_options(machine);
842 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
845 static void ccw_machine_4_1_class_options(MachineClass *mc)
847 ccw_machine_4_2_class_options(mc);
848 compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
850 DEFINE_CCW_MACHINE(4_1, "4.1", false);
852 static void ccw_machine_4_0_instance_options(MachineState *machine)
854 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
855 ccw_machine_4_1_instance_options(machine);
856 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
859 static void ccw_machine_4_0_class_options(MachineClass *mc)
861 ccw_machine_4_1_class_options(mc);
862 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
864 DEFINE_CCW_MACHINE(4_0, "4.0", false);
866 static void ccw_machine_3_1_instance_options(MachineState *machine)
868 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
869 ccw_machine_4_0_instance_options(machine);
870 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
871 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
872 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
875 static void ccw_machine_3_1_class_options(MachineClass *mc)
877 ccw_machine_4_0_class_options(mc);
878 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
880 DEFINE_CCW_MACHINE(3_1, "3.1", false);
882 static void ccw_machine_3_0_instance_options(MachineState *machine)
884 ccw_machine_3_1_instance_options(machine);
887 static void ccw_machine_3_0_class_options(MachineClass *mc)
889 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
891 s390mc->hpage_1m_allowed = false;
892 ccw_machine_3_1_class_options(mc);
893 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
895 DEFINE_CCW_MACHINE(3_0, "3.0", false);
897 static void ccw_machine_2_12_instance_options(MachineState *machine)
899 ccw_machine_3_0_instance_options(machine);
900 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
901 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
904 static void ccw_machine_2_12_class_options(MachineClass *mc)
906 ccw_machine_3_0_class_options(mc);
907 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
909 DEFINE_CCW_MACHINE(2_12, "2.12", false);
911 static void ccw_machine_2_11_instance_options(MachineState *machine)
913 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
914 ccw_machine_2_12_instance_options(machine);
916 /* before 2.12 we emulated the very first z900 */
917 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
920 static void ccw_machine_2_11_class_options(MachineClass *mc)
922 static GlobalProperty compat[] = {
923 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
926 ccw_machine_2_12_class_options(mc);
927 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
928 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
930 DEFINE_CCW_MACHINE(2_11, "2.11", false);
932 static void ccw_machine_2_10_instance_options(MachineState *machine)
934 ccw_machine_2_11_instance_options(machine);
937 static void ccw_machine_2_10_class_options(MachineClass *mc)
939 ccw_machine_2_11_class_options(mc);
940 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
942 DEFINE_CCW_MACHINE(2_10, "2.10", false);
944 static void ccw_machine_2_9_instance_options(MachineState *machine)
946 ccw_machine_2_10_instance_options(machine);
947 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
948 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
949 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
950 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
951 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
954 static void ccw_machine_2_9_class_options(MachineClass *mc)
956 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
957 static GlobalProperty compat[] = {
958 { TYPE_S390_STATTRIB, "migration-enabled", "off", },
961 ccw_machine_2_10_class_options(mc);
962 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
963 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
964 s390mc->css_migration_enabled = false;
966 DEFINE_CCW_MACHINE(2_9, "2.9", false);
968 static void ccw_machine_2_8_instance_options(MachineState *machine)
970 ccw_machine_2_9_instance_options(machine);
973 static void ccw_machine_2_8_class_options(MachineClass *mc)
975 static GlobalProperty compat[] = {
976 { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
979 ccw_machine_2_9_class_options(mc);
980 compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
981 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
983 DEFINE_CCW_MACHINE(2_8, "2.8", false);
985 static void ccw_machine_2_7_instance_options(MachineState *machine)
987 ccw_machine_2_8_instance_options(machine);
990 static void ccw_machine_2_7_class_options(MachineClass *mc)
992 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
994 s390mc->cpu_model_allowed = false;
995 ccw_machine_2_8_class_options(mc);
996 compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
998 DEFINE_CCW_MACHINE(2_7, "2.7", false);
1000 static void ccw_machine_2_6_instance_options(MachineState *machine)
1002 ccw_machine_2_7_instance_options(machine);
1005 static void ccw_machine_2_6_class_options(MachineClass *mc)
1007 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
1008 static GlobalProperty compat[] = {
1009 { TYPE_S390_IPL, "iplbext_migration", "off", },
1010 { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
1013 s390mc->ri_allowed = false;
1014 ccw_machine_2_7_class_options(mc);
1015 compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
1016 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1018 DEFINE_CCW_MACHINE(2_6, "2.6", false);
1020 static void ccw_machine_2_5_instance_options(MachineState *machine)
1022 ccw_machine_2_6_instance_options(machine);
1025 static void ccw_machine_2_5_class_options(MachineClass *mc)
1027 ccw_machine_2_6_class_options(mc);
1028 compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
1030 DEFINE_CCW_MACHINE(2_5, "2.5", false);
1032 static void ccw_machine_2_4_instance_options(MachineState *machine)
1034 ccw_machine_2_5_instance_options(machine);
1037 static void ccw_machine_2_4_class_options(MachineClass *mc)
1039 static GlobalProperty compat[] = {
1040 { TYPE_S390_SKEYS, "migration-enabled", "off", },
1041 { "virtio-blk-ccw", "max_revision", "0", },
1042 { "virtio-balloon-ccw", "max_revision", "0", },
1043 { "virtio-serial-ccw", "max_revision", "0", },
1044 { "virtio-9p-ccw", "max_revision", "0", },
1045 { "virtio-rng-ccw", "max_revision", "0", },
1046 { "virtio-net-ccw", "max_revision", "0", },
1047 { "virtio-scsi-ccw", "max_revision", "0", },
1048 { "vhost-scsi-ccw", "max_revision", "0", },
1051 ccw_machine_2_5_class_options(mc);
1052 compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
1053 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1055 DEFINE_CCW_MACHINE(2_4, "2.4", false);
1057 static void ccw_machine_register_types(void)
1059 type_register_static(&ccw_machine_info);
1062 type_init(ccw_machine_register_types)