target/mips: Raise exception when DINSV opcode used with DSP disabled
[qemu/ar7.git] / hw / s390x / s390-virtio-ccw.c
blobe4b18aef496b5904d4d50b85fa1599b64c1c25cf
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 "hw/s390x/s390-pci-bus.h"
29 #include "sysemu/reset.h"
30 #include "hw/s390x/storage-keys.h"
31 #include "hw/s390x/storage-attributes.h"
32 #include "hw/s390x/event-facility.h"
33 #include "ipl.h"
34 #include "hw/s390x/s390-virtio-ccw.h"
35 #include "hw/s390x/css-bridge.h"
36 #include "hw/s390x/ap-bridge.h"
37 #include "migration/register.h"
38 #include "cpu_models.h"
39 #include "hw/nmi.h"
40 #include "hw/qdev-properties.h"
41 #include "hw/s390x/tod.h"
42 #include "sysemu/sysemu.h"
43 #include "hw/s390x/pv.h"
44 #include "migration/blocker.h"
46 static Error *pv_mig_blocker;
48 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
50 static MachineState *ms;
52 if (!ms) {
53 ms = MACHINE(qdev_get_machine());
54 g_assert(ms->possible_cpus);
57 /* CPU address corresponds to the core_id and the index */
58 if (cpu_addr >= ms->possible_cpus->len) {
59 return NULL;
61 return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
64 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
65 Error **errp)
67 S390CPU *cpu = S390_CPU(object_new(typename));
68 S390CPU *ret = NULL;
70 if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) {
71 goto out;
73 if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
74 goto out;
76 ret = cpu;
78 out:
79 object_unref(OBJECT(cpu));
80 return ret;
83 static void s390_init_cpus(MachineState *machine)
85 MachineClass *mc = MACHINE_GET_CLASS(machine);
86 int i;
88 /* initialize possible_cpus */
89 mc->possible_cpu_arch_ids(machine);
91 for (i = 0; i < machine->smp.cpus; i++) {
92 s390x_new_cpu(machine->cpu_type, i, &error_fatal);
96 static const char *const reset_dev_types[] = {
97 TYPE_VIRTUAL_CSS_BRIDGE,
98 "s390-sclp-event-facility",
99 "s390-flic",
100 "diag288",
101 TYPE_S390_PCI_HOST_BRIDGE,
104 static void subsystem_reset(void)
106 DeviceState *dev;
107 int i;
109 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
110 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
111 if (dev) {
112 qdev_reset_all(dev);
117 static int virtio_ccw_hcall_notify(const uint64_t *args)
119 uint64_t subch_id = args[0];
120 uint64_t queue = args[1];
121 SubchDev *sch;
122 int cssid, ssid, schid, m;
124 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
125 return -EINVAL;
127 sch = css_find_subch(m, cssid, ssid, schid);
128 if (!sch || !css_subch_visible(sch)) {
129 return -EINVAL;
131 if (queue >= VIRTIO_QUEUE_MAX) {
132 return -EINVAL;
134 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
135 return 0;
139 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
141 uint64_t mem = args[0];
142 MachineState *ms = MACHINE(qdev_get_machine());
144 if (mem < ms->ram_size) {
145 /* Early printk */
146 return 0;
148 return -EINVAL;
151 static void virtio_ccw_register_hcalls(void)
153 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
154 virtio_ccw_hcall_notify);
155 /* Tolerate early printk. */
156 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
157 virtio_ccw_hcall_early_printk);
160 static void s390_memory_init(MemoryRegion *ram)
162 MemoryRegion *sysmem = get_system_memory();
164 /* allocate RAM for core */
165 memory_region_add_subregion(sysmem, 0, ram);
168 * Configure the maximum page size. As no memory devices were created
169 * yet, this is the page size of initial memory only.
171 s390_set_max_pagesize(qemu_maxrampagesize(), &error_fatal);
172 /* Initialize storage key device */
173 s390_skeys_init();
174 /* Initialize storage attributes device */
175 s390_stattrib_init();
178 static void s390_init_ipl_dev(const char *kernel_filename,
179 const char *kernel_cmdline,
180 const char *initrd_filename, const char *firmware,
181 const char *netboot_fw, bool enforce_bios)
183 Object *new = object_new(TYPE_S390_IPL);
184 DeviceState *dev = DEVICE(new);
185 char *netboot_fw_prop;
187 if (kernel_filename) {
188 qdev_prop_set_string(dev, "kernel", kernel_filename);
190 if (initrd_filename) {
191 qdev_prop_set_string(dev, "initrd", initrd_filename);
193 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
194 qdev_prop_set_string(dev, "firmware", firmware);
195 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
196 netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
197 if (!strlen(netboot_fw_prop)) {
198 qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
200 g_free(netboot_fw_prop);
201 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
202 new);
203 object_unref(new);
204 qdev_realize(dev, NULL, &error_fatal);
207 static void s390_create_virtio_net(BusState *bus, const char *name)
209 int i;
211 for (i = 0; i < nb_nics; i++) {
212 NICInfo *nd = &nd_table[i];
213 DeviceState *dev;
215 if (!nd->model) {
216 nd->model = g_strdup("virtio");
219 qemu_check_nic_model(nd, "virtio");
221 dev = qdev_new(name);
222 qdev_set_nic_properties(dev, nd);
223 qdev_realize_and_unref(dev, bus, &error_fatal);
227 static void s390_create_sclpconsole(const char *type, Chardev *chardev)
229 DeviceState *dev;
231 dev = qdev_new(type);
232 qdev_prop_set_chr(dev, "chardev", chardev);
233 qdev_realize_and_unref(dev, sclp_get_event_facility_bus(), &error_fatal);
236 static void ccw_init(MachineState *machine)
238 int ret;
239 VirtualCssBus *css_bus;
240 DeviceState *dev;
242 s390_sclp_init();
243 /* init memory + setup max page size. Required for the CPU model */
244 s390_memory_init(machine->ram);
246 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
247 s390_init_cpus(machine);
249 /* Need CPU model to be determined before we can set up PV */
250 s390_pv_init(machine->cgs, &error_fatal);
252 s390_flic_init();
254 /* init the SIGP facility */
255 s390_init_sigp();
257 /* create AP bridge and bus(es) */
258 s390_init_ap();
260 /* get a BUS */
261 css_bus = virtual_css_bus_init();
262 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
263 machine->initrd_filename,
264 machine->firmware ?: "s390-ccw.img",
265 "s390-netboot.img", true);
267 dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE);
268 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
269 OBJECT(dev));
270 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
272 /* register hypercalls */
273 virtio_ccw_register_hcalls();
275 s390_enable_css_support(s390_cpu_addr2state(0));
277 ret = css_create_css_image(VIRTUAL_CSSID, true);
279 assert(ret == 0);
280 if (css_migration_enabled()) {
281 css_register_vmstate();
284 /* Create VirtIO network adapters */
285 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
287 /* init consoles */
288 if (serial_hd(0)) {
289 s390_create_sclpconsole("sclpconsole", serial_hd(0));
291 if (serial_hd(1)) {
292 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
295 /* init the TOD clock */
296 s390_init_tod();
299 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
300 DeviceState *dev, Error **errp)
302 MachineState *ms = MACHINE(hotplug_dev);
303 S390CPU *cpu = S390_CPU(dev);
305 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
306 ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
308 if (dev->hotplugged) {
309 raise_irq_cpu_hotplug();
313 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
315 S390CPU *cpu = S390_CPU(cs);
317 s390_ipl_prepare_cpu(cpu);
318 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
321 static void s390_machine_unprotect(S390CcwMachineState *ms)
323 s390_pv_vm_disable();
324 ms->pv = false;
325 migrate_del_blocker(pv_mig_blocker);
326 error_free_or_abort(&pv_mig_blocker);
327 ram_block_discard_disable(false);
330 static int s390_machine_protect(S390CcwMachineState *ms)
332 Error *local_err = NULL;
333 int rc;
336 * Discarding of memory in RAM blocks does not work as expected with
337 * protected VMs. Sharing and unsharing pages would be required. Disable
338 * it for now, until until we have a solution to make at least Linux
339 * guests either support it (e.g., virtio-balloon) or fail gracefully.
341 rc = ram_block_discard_disable(true);
342 if (rc) {
343 error_report("protected VMs: cannot disable RAM discard");
344 return rc;
347 error_setg(&pv_mig_blocker,
348 "protected VMs are currently not migrateable.");
349 rc = migrate_add_blocker(pv_mig_blocker, &local_err);
350 if (rc) {
351 ram_block_discard_disable(false);
352 error_report_err(local_err);
353 error_free_or_abort(&pv_mig_blocker);
354 return rc;
357 /* Create SE VM */
358 rc = s390_pv_vm_enable();
359 if (rc) {
360 ram_block_discard_disable(false);
361 migrate_del_blocker(pv_mig_blocker);
362 error_free_or_abort(&pv_mig_blocker);
363 return rc;
366 ms->pv = true;
368 /* Set SE header and unpack */
369 rc = s390_ipl_prepare_pv_header();
370 if (rc) {
371 goto out_err;
374 /* Decrypt image */
375 rc = s390_ipl_pv_unpack();
376 if (rc) {
377 goto out_err;
380 /* Verify integrity */
381 rc = s390_pv_verify();
382 if (rc) {
383 goto out_err;
385 return rc;
387 out_err:
388 s390_machine_unprotect(ms);
389 return rc;
392 static void s390_pv_prepare_reset(S390CcwMachineState *ms)
394 CPUState *cs;
396 if (!s390_is_pv()) {
397 return;
399 /* Unsharing requires all cpus to be stopped */
400 CPU_FOREACH(cs) {
401 s390_cpu_set_state(S390_CPU_STATE_STOPPED, S390_CPU(cs));
403 s390_pv_unshare();
404 s390_pv_prep_reset();
407 static void s390_machine_reset(MachineState *machine)
409 S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
410 enum s390_reset reset_type;
411 CPUState *cs, *t;
412 S390CPU *cpu;
414 /* get the reset parameters, reset them once done */
415 s390_ipl_get_reset_request(&cs, &reset_type);
417 /* all CPUs are paused and synchronized at this point */
418 s390_cmma_reset();
420 cpu = S390_CPU(cs);
422 switch (reset_type) {
423 case S390_RESET_EXTERNAL:
424 case S390_RESET_REIPL:
425 if (s390_is_pv()) {
426 s390_machine_unprotect(ms);
429 qemu_devices_reset();
430 s390_crypto_reset();
432 /* configure and start the ipl CPU only */
433 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
434 break;
435 case S390_RESET_MODIFIED_CLEAR:
437 * Susbsystem reset needs to be done before we unshare memory
438 * and lose access to VIRTIO structures in guest memory.
440 subsystem_reset();
441 s390_crypto_reset();
442 s390_pv_prepare_reset(ms);
443 CPU_FOREACH(t) {
444 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
446 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
447 break;
448 case S390_RESET_LOAD_NORMAL:
450 * Susbsystem reset needs to be done before we unshare memory
451 * and lose access to VIRTIO structures in guest memory.
453 subsystem_reset();
454 s390_pv_prepare_reset(ms);
455 CPU_FOREACH(t) {
456 if (t == cs) {
457 continue;
459 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
461 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
462 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
463 break;
464 case S390_RESET_PV: /* Subcode 10 */
465 subsystem_reset();
466 s390_crypto_reset();
468 CPU_FOREACH(t) {
469 if (t == cs) {
470 continue;
472 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
474 run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
476 if (s390_machine_protect(ms)) {
477 s390_pv_inject_reset_error(cs);
479 * Continue after the diag308 so the guest knows something
480 * went wrong.
482 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
483 return;
486 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
487 break;
488 default:
489 g_assert_not_reached();
492 CPU_FOREACH(t) {
493 run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(0));
495 s390_ipl_clear_reset_request();
498 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
499 DeviceState *dev, Error **errp)
501 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
502 s390_cpu_plug(hotplug_dev, dev, errp);
506 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
507 DeviceState *dev, Error **errp)
509 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
510 error_setg(errp, "CPU hot unplug not supported on this machine");
511 return;
515 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
516 unsigned cpu_index)
518 MachineClass *mc = MACHINE_GET_CLASS(ms);
519 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
521 assert(cpu_index < possible_cpus->len);
522 return possible_cpus->cpus[cpu_index].props;
525 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
527 int i;
528 unsigned int max_cpus = ms->smp.max_cpus;
530 if (ms->possible_cpus) {
531 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
532 return ms->possible_cpus;
535 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
536 sizeof(CPUArchId) * max_cpus);
537 ms->possible_cpus->len = max_cpus;
538 for (i = 0; i < ms->possible_cpus->len; i++) {
539 ms->possible_cpus->cpus[i].type = ms->cpu_type;
540 ms->possible_cpus->cpus[i].vcpus_count = 1;
541 ms->possible_cpus->cpus[i].arch_id = i;
542 ms->possible_cpus->cpus[i].props.has_core_id = true;
543 ms->possible_cpus->cpus[i].props.core_id = i;
546 return ms->possible_cpus;
549 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
550 DeviceState *dev)
552 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
553 return HOTPLUG_HANDLER(machine);
555 return NULL;
558 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
560 CPUState *cs = qemu_get_cpu(cpu_index);
562 s390_cpu_restart(S390_CPU(cs));
565 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
567 /* same logic as in sclp.c */
568 int increment_size = 20;
569 ram_addr_t newsz;
571 while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
572 increment_size++;
574 newsz = sz >> increment_size << increment_size;
576 if (sz != newsz) {
577 qemu_printf("Ram size %" PRIu64 "MB was fixed up to %" PRIu64
578 "MB to match machine restrictions. Consider updating "
579 "the guest definition.\n", (uint64_t) (sz / MiB),
580 (uint64_t) (newsz / MiB));
582 return newsz;
585 static void ccw_machine_class_init(ObjectClass *oc, void *data)
587 MachineClass *mc = MACHINE_CLASS(oc);
588 NMIClass *nc = NMI_CLASS(oc);
589 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
590 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
592 s390mc->ri_allowed = true;
593 s390mc->cpu_model_allowed = true;
594 s390mc->css_migration_enabled = true;
595 s390mc->hpage_1m_allowed = true;
596 mc->init = ccw_init;
597 mc->reset = s390_machine_reset;
598 mc->block_default_type = IF_VIRTIO;
599 mc->no_cdrom = 1;
600 mc->no_floppy = 1;
601 mc->no_parallel = 1;
602 mc->no_sdcard = 1;
603 mc->max_cpus = S390_MAX_CPUS;
604 mc->has_hotpluggable_cpus = true;
605 assert(!mc->get_hotplug_handler);
606 mc->get_hotplug_handler = s390_get_hotplug_handler;
607 mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
608 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
609 /* it is overridden with 'host' cpu *in kvm_arch_init* */
610 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
611 hc->plug = s390_machine_device_plug;
612 hc->unplug_request = s390_machine_device_unplug_request;
613 nc->nmi_monitor_handler = s390_nmi;
614 mc->default_ram_id = "s390.ram";
617 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
619 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
621 return ms->aes_key_wrap;
624 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
625 Error **errp)
627 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
629 ms->aes_key_wrap = value;
632 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
634 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
636 return ms->dea_key_wrap;
639 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
640 Error **errp)
642 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
644 ms->dea_key_wrap = value;
647 static S390CcwMachineClass *current_mc;
650 * Get the class of the s390-ccw-virtio machine that is currently in use.
651 * Note: libvirt is using the "none" machine to probe for the features of the
652 * host CPU, so in case this is called with the "none" machine, the function
653 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
654 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
655 * below return the correct default value for the "none" machine.
657 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like
658 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should
659 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during
660 * CPU initialization and s390_has_feat() later should be sufficient.
662 static S390CcwMachineClass *get_machine_class(void)
664 if (unlikely(!current_mc)) {
666 * No s390 ccw machine was instantiated, we are likely to
667 * be called for the 'none' machine. The properties will
668 * have their after-initialization values.
670 current_mc = S390_CCW_MACHINE_CLASS(
671 object_class_by_name(TYPE_S390_CCW_MACHINE));
673 return current_mc;
676 bool ri_allowed(void)
678 return get_machine_class()->ri_allowed;
681 bool cpu_model_allowed(void)
683 return get_machine_class()->cpu_model_allowed;
686 bool hpage_1m_allowed(void)
688 return get_machine_class()->hpage_1m_allowed;
691 static char *machine_get_loadparm(Object *obj, Error **errp)
693 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
695 /* make a NUL-terminated string */
696 return g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
699 static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
701 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
702 int i;
704 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
705 uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
707 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
708 (c == ' ')) {
709 ms->loadparm[i] = c;
710 } else {
711 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
712 c, c);
713 return;
717 for (; i < sizeof(ms->loadparm); i++) {
718 ms->loadparm[i] = ' '; /* pad right with spaces */
721 static inline void s390_machine_initfn(Object *obj)
723 object_property_add_bool(obj, "aes-key-wrap",
724 machine_get_aes_key_wrap,
725 machine_set_aes_key_wrap);
726 object_property_set_description(obj, "aes-key-wrap",
727 "enable/disable AES key wrapping using the CPACF wrapping key");
728 object_property_set_bool(obj, "aes-key-wrap", true, NULL);
730 object_property_add_bool(obj, "dea-key-wrap",
731 machine_get_dea_key_wrap,
732 machine_set_dea_key_wrap);
733 object_property_set_description(obj, "dea-key-wrap",
734 "enable/disable DEA key wrapping using the CPACF wrapping key");
735 object_property_set_bool(obj, "dea-key-wrap", true, NULL);
736 object_property_add_str(obj, "loadparm",
737 machine_get_loadparm, machine_set_loadparm);
738 object_property_set_description(obj, "loadparm",
739 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
740 " to upper case) to pass to machine loader, boot manager,"
741 " and guest kernel");
744 static const TypeInfo ccw_machine_info = {
745 .name = TYPE_S390_CCW_MACHINE,
746 .parent = TYPE_MACHINE,
747 .abstract = true,
748 .instance_size = sizeof(S390CcwMachineState),
749 .instance_init = s390_machine_initfn,
750 .class_size = sizeof(S390CcwMachineClass),
751 .class_init = ccw_machine_class_init,
752 .interfaces = (InterfaceInfo[]) {
753 { TYPE_NMI },
754 { TYPE_HOTPLUG_HANDLER},
759 bool css_migration_enabled(void)
761 return get_machine_class()->css_migration_enabled;
764 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
765 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
766 void *data) \
768 MachineClass *mc = MACHINE_CLASS(oc); \
769 ccw_machine_##suffix##_class_options(mc); \
770 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
771 if (latest) { \
772 mc->alias = "s390-ccw-virtio"; \
773 mc->is_default = true; \
776 static void ccw_machine_##suffix##_instance_init(Object *obj) \
778 MachineState *machine = MACHINE(obj); \
779 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
780 ccw_machine_##suffix##_instance_options(machine); \
782 static const TypeInfo ccw_machine_##suffix##_info = { \
783 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
784 .parent = TYPE_S390_CCW_MACHINE, \
785 .class_init = ccw_machine_##suffix##_class_init, \
786 .instance_init = ccw_machine_##suffix##_instance_init, \
787 }; \
788 static void ccw_machine_register_##suffix(void) \
790 type_register_static(&ccw_machine_##suffix##_info); \
792 type_init(ccw_machine_register_##suffix)
794 static void ccw_machine_6_1_instance_options(MachineState *machine)
798 static void ccw_machine_6_1_class_options(MachineClass *mc)
801 DEFINE_CCW_MACHINE(6_1, "6.1", true);
803 static void ccw_machine_6_0_instance_options(MachineState *machine)
805 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_0 };
807 ccw_machine_6_1_instance_options(machine);
808 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
811 static void ccw_machine_6_0_class_options(MachineClass *mc)
813 ccw_machine_6_1_class_options(mc);
814 compat_props_add(mc->compat_props, hw_compat_6_0, hw_compat_6_0_len);
816 DEFINE_CCW_MACHINE(6_0, "6.0", false);
818 static void ccw_machine_5_2_instance_options(MachineState *machine)
820 ccw_machine_6_0_instance_options(machine);
823 static void ccw_machine_5_2_class_options(MachineClass *mc)
825 ccw_machine_6_0_class_options(mc);
826 compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len);
828 DEFINE_CCW_MACHINE(5_2, "5.2", false);
830 static void ccw_machine_5_1_instance_options(MachineState *machine)
832 ccw_machine_5_2_instance_options(machine);
835 static void ccw_machine_5_1_class_options(MachineClass *mc)
837 ccw_machine_5_2_class_options(mc);
838 compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len);
840 DEFINE_CCW_MACHINE(5_1, "5.1", false);
842 static void ccw_machine_5_0_instance_options(MachineState *machine)
844 ccw_machine_5_1_instance_options(machine);
847 static void ccw_machine_5_0_class_options(MachineClass *mc)
849 ccw_machine_5_1_class_options(mc);
850 compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len);
852 DEFINE_CCW_MACHINE(5_0, "5.0", false);
854 static void ccw_machine_4_2_instance_options(MachineState *machine)
856 ccw_machine_5_0_instance_options(machine);
859 static void ccw_machine_4_2_class_options(MachineClass *mc)
861 ccw_machine_5_0_class_options(mc);
862 mc->fixup_ram_size = s390_fixup_ram_size;
863 compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
865 DEFINE_CCW_MACHINE(4_2, "4.2", false);
867 static void ccw_machine_4_1_instance_options(MachineState *machine)
869 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
870 ccw_machine_4_2_instance_options(machine);
871 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
874 static void ccw_machine_4_1_class_options(MachineClass *mc)
876 ccw_machine_4_2_class_options(mc);
877 compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
879 DEFINE_CCW_MACHINE(4_1, "4.1", false);
881 static void ccw_machine_4_0_instance_options(MachineState *machine)
883 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
884 ccw_machine_4_1_instance_options(machine);
885 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
888 static void ccw_machine_4_0_class_options(MachineClass *mc)
890 ccw_machine_4_1_class_options(mc);
891 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
893 DEFINE_CCW_MACHINE(4_0, "4.0", false);
895 static void ccw_machine_3_1_instance_options(MachineState *machine)
897 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
898 ccw_machine_4_0_instance_options(machine);
899 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
900 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
901 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
904 static void ccw_machine_3_1_class_options(MachineClass *mc)
906 ccw_machine_4_0_class_options(mc);
907 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
909 DEFINE_CCW_MACHINE(3_1, "3.1", false);
911 static void ccw_machine_3_0_instance_options(MachineState *machine)
913 ccw_machine_3_1_instance_options(machine);
916 static void ccw_machine_3_0_class_options(MachineClass *mc)
918 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
920 s390mc->hpage_1m_allowed = false;
921 ccw_machine_3_1_class_options(mc);
922 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
924 DEFINE_CCW_MACHINE(3_0, "3.0", false);
926 static void ccw_machine_2_12_instance_options(MachineState *machine)
928 ccw_machine_3_0_instance_options(machine);
929 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
930 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
933 static void ccw_machine_2_12_class_options(MachineClass *mc)
935 ccw_machine_3_0_class_options(mc);
936 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
938 DEFINE_CCW_MACHINE(2_12, "2.12", false);
940 static void ccw_machine_2_11_instance_options(MachineState *machine)
942 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
943 ccw_machine_2_12_instance_options(machine);
945 /* before 2.12 we emulated the very first z900 */
946 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
949 static void ccw_machine_2_11_class_options(MachineClass *mc)
951 static GlobalProperty compat[] = {
952 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
955 ccw_machine_2_12_class_options(mc);
956 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
957 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
959 DEFINE_CCW_MACHINE(2_11, "2.11", false);
961 static void ccw_machine_2_10_instance_options(MachineState *machine)
963 ccw_machine_2_11_instance_options(machine);
966 static void ccw_machine_2_10_class_options(MachineClass *mc)
968 ccw_machine_2_11_class_options(mc);
969 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
971 DEFINE_CCW_MACHINE(2_10, "2.10", false);
973 static void ccw_machine_2_9_instance_options(MachineState *machine)
975 ccw_machine_2_10_instance_options(machine);
976 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
977 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
978 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
979 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
980 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
983 static void ccw_machine_2_9_class_options(MachineClass *mc)
985 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
986 static GlobalProperty compat[] = {
987 { TYPE_S390_STATTRIB, "migration-enabled", "off", },
990 ccw_machine_2_10_class_options(mc);
991 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
992 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
993 s390mc->css_migration_enabled = false;
995 DEFINE_CCW_MACHINE(2_9, "2.9", false);
997 static void ccw_machine_2_8_instance_options(MachineState *machine)
999 ccw_machine_2_9_instance_options(machine);
1002 static void ccw_machine_2_8_class_options(MachineClass *mc)
1004 static GlobalProperty compat[] = {
1005 { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
1008 ccw_machine_2_9_class_options(mc);
1009 compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
1010 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1012 DEFINE_CCW_MACHINE(2_8, "2.8", false);
1014 static void ccw_machine_2_7_instance_options(MachineState *machine)
1016 ccw_machine_2_8_instance_options(machine);
1019 static void ccw_machine_2_7_class_options(MachineClass *mc)
1021 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1023 s390mc->cpu_model_allowed = false;
1024 ccw_machine_2_8_class_options(mc);
1025 compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
1027 DEFINE_CCW_MACHINE(2_7, "2.7", false);
1029 static void ccw_machine_2_6_instance_options(MachineState *machine)
1031 ccw_machine_2_7_instance_options(machine);
1034 static void ccw_machine_2_6_class_options(MachineClass *mc)
1036 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1037 static GlobalProperty compat[] = {
1038 { TYPE_S390_IPL, "iplbext_migration", "off", },
1039 { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
1042 s390mc->ri_allowed = false;
1043 ccw_machine_2_7_class_options(mc);
1044 compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
1045 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1047 DEFINE_CCW_MACHINE(2_6, "2.6", false);
1049 static void ccw_machine_2_5_instance_options(MachineState *machine)
1051 ccw_machine_2_6_instance_options(machine);
1054 static void ccw_machine_2_5_class_options(MachineClass *mc)
1056 ccw_machine_2_6_class_options(mc);
1057 compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
1059 DEFINE_CCW_MACHINE(2_5, "2.5", false);
1061 static void ccw_machine_2_4_instance_options(MachineState *machine)
1063 ccw_machine_2_5_instance_options(machine);
1066 static void ccw_machine_2_4_class_options(MachineClass *mc)
1068 static GlobalProperty compat[] = {
1069 { TYPE_S390_SKEYS, "migration-enabled", "off", },
1070 { "virtio-blk-ccw", "max_revision", "0", },
1071 { "virtio-balloon-ccw", "max_revision", "0", },
1072 { "virtio-serial-ccw", "max_revision", "0", },
1073 { "virtio-9p-ccw", "max_revision", "0", },
1074 { "virtio-rng-ccw", "max_revision", "0", },
1075 { "virtio-net-ccw", "max_revision", "0", },
1076 { "virtio-scsi-ccw", "max_revision", "0", },
1077 { "vhost-scsi-ccw", "max_revision", "0", },
1080 ccw_machine_2_5_class_options(mc);
1081 compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
1082 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1084 DEFINE_CCW_MACHINE(2_4, "2.4", false);
1086 static void ccw_machine_register_types(void)
1088 type_register_static(&ccw_machine_info);
1091 type_init(ccw_machine_register_types)