1 /* 2 * virtio ccw machine 3 * 4 * Copyright 2012 IBM Corp. 5 * Copyright (c) 2009 Alexander Graf <agraf@suse.de> 6 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> 7 * 8 * This work is licensed under the terms of the GNU GPL, version 2 or (at 9 * your option) any later version. See the COPYING file in the top-level 10 * directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qapi/error.h" 15 #include "cpu.h" 16 #include "hw/boards.h" 17 #include "exec/address-spaces.h" 18 #include "exec/ram_addr.h" 19 #include "hw/s390x/s390-virtio-hcall.h" 20 #include "hw/s390x/sclp.h" 21 #include "hw/s390x/s390_flic.h" 22 #include "hw/s390x/ioinst.h" 23 #include "hw/s390x/css.h" 24 #include "virtio-ccw.h" 25 #include "qemu/config-file.h" 26 #include "qemu/ctype.h" 27 #include "qemu/error-report.h" 28 #include "qemu/option.h" 29 #include "qemu/qemu-print.h" 30 #include "s390-pci-bus.h" 31 #include "sysemu/reset.h" 32 #include "hw/s390x/storage-keys.h" 33 #include "hw/s390x/storage-attributes.h" 34 #include "hw/s390x/event-facility.h" 35 #include "ipl.h" 36 #include "hw/s390x/s390-virtio-ccw.h" 37 #include "hw/s390x/css-bridge.h" 38 #include "hw/s390x/ap-bridge.h" 39 #include "migration/register.h" 40 #include "cpu_models.h" 41 #include "hw/nmi.h" 42 #include "hw/qdev-properties.h" 43 #include "hw/s390x/tod.h" 44 #include "sysemu/sysemu.h" 45 46 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr) 47 { 48 static MachineState *ms; 49 50 if (!ms) { 51 ms = MACHINE(qdev_get_machine()); 52 g_assert(ms->possible_cpus); 53 } 54 55 /* CPU address corresponds to the core_id and the index */ 56 if (cpu_addr >= ms->possible_cpus->len) { 57 return NULL; 58 } 59 return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu); 60 } 61 62 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, 63 Error **errp) 64 { 65 S390CPU *cpu = S390_CPU(object_new(typename)); 66 Error *err = NULL; 67 68 object_property_set_int(OBJECT(cpu), core_id, "core-id", &err); 69 if (err != NULL) { 70 goto out; 71 } 72 object_property_set_bool(OBJECT(cpu), true, "realized", &err); 73 74 out: 75 object_unref(OBJECT(cpu)); 76 if (err) { 77 error_propagate(errp, err); 78 cpu = NULL; 79 } 80 return cpu; 81 } 82 83 static void s390_init_cpus(MachineState *machine) 84 { 85 MachineClass *mc = MACHINE_GET_CLASS(machine); 86 int i; 87 88 /* initialize possible_cpus */ 89 mc->possible_cpu_arch_ids(machine); 90 91 for (i = 0; i < machine->smp.cpus; i++) { 92 s390x_new_cpu(machine->cpu_type, i, &error_fatal); 93 } 94 } 95 96 static const char *const reset_dev_types[] = { 97 TYPE_VIRTUAL_CSS_BRIDGE, 98 "s390-sclp-event-facility", 99 "s390-flic", 100 "diag288", 101 }; 102 103 static void subsystem_reset(void) 104 { 105 DeviceState *dev; 106 int i; 107 108 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) { 109 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL)); 110 if (dev) { 111 qdev_reset_all(dev); 112 } 113 } 114 } 115 116 static int virtio_ccw_hcall_notify(const uint64_t *args) 117 { 118 uint64_t subch_id = args[0]; 119 uint64_t queue = args[1]; 120 SubchDev *sch; 121 int cssid, ssid, schid, m; 122 123 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) { 124 return -EINVAL; 125 } 126 sch = css_find_subch(m, cssid, ssid, schid); 127 if (!sch || !css_subch_visible(sch)) { 128 return -EINVAL; 129 } 130 if (queue >= VIRTIO_QUEUE_MAX) { 131 return -EINVAL; 132 } 133 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue); 134 return 0; 135 136 } 137 138 static int virtio_ccw_hcall_early_printk(const uint64_t *args) 139 { 140 uint64_t mem = args[0]; 141 142 if (mem < ram_size) { 143 /* Early printk */ 144 return 0; 145 } 146 return -EINVAL; 147 } 148 149 static void virtio_ccw_register_hcalls(void) 150 { 151 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY, 152 virtio_ccw_hcall_notify); 153 /* Tolerate early printk. */ 154 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY, 155 virtio_ccw_hcall_early_printk); 156 } 157 158 static void s390_memory_init(MemoryRegion *ram) 159 { 160 MemoryRegion *sysmem = get_system_memory(); 161 Error *local_err = NULL; 162 163 /* allocate RAM for core */ 164 memory_region_add_subregion(sysmem, 0, ram); 165 166 /* 167 * Configure the maximum page size. As no memory devices were created 168 * yet, this is the page size of initial memory only. 169 */ 170 s390_set_max_pagesize(qemu_maxrampagesize(), &local_err); 171 if (local_err) { 172 error_report_err(local_err); 173 exit(EXIT_FAILURE); 174 } 175 /* Initialize storage key device */ 176 s390_skeys_init(); 177 /* Initialize storage attributes device */ 178 s390_stattrib_init(); 179 } 180 181 static void s390_init_ipl_dev(const char *kernel_filename, 182 const char *kernel_cmdline, 183 const char *initrd_filename, const char *firmware, 184 const char *netboot_fw, bool enforce_bios) 185 { 186 Object *new = object_new(TYPE_S390_IPL); 187 DeviceState *dev = DEVICE(new); 188 char *netboot_fw_prop; 189 190 if (kernel_filename) { 191 qdev_prop_set_string(dev, "kernel", kernel_filename); 192 } 193 if (initrd_filename) { 194 qdev_prop_set_string(dev, "initrd", initrd_filename); 195 } 196 qdev_prop_set_string(dev, "cmdline", kernel_cmdline); 197 qdev_prop_set_string(dev, "firmware", firmware); 198 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios); 199 netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort); 200 if (!strlen(netboot_fw_prop)) { 201 qdev_prop_set_string(dev, "netboot_fw", netboot_fw); 202 } 203 g_free(netboot_fw_prop); 204 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL, 205 new, NULL); 206 object_unref(new); 207 qdev_init_nofail(dev); 208 } 209 210 static void s390_create_virtio_net(BusState *bus, const char *name) 211 { 212 int i; 213 214 for (i = 0; i < nb_nics; i++) { 215 NICInfo *nd = &nd_table[i]; 216 DeviceState *dev; 217 218 if (!nd->model) { 219 nd->model = g_strdup("virtio"); 220 } 221 222 qemu_check_nic_model(nd, "virtio"); 223 224 dev = qdev_create(bus, name); 225 qdev_set_nic_properties(dev, nd); 226 qdev_init_nofail(dev); 227 } 228 } 229 230 static void s390_create_sclpconsole(const char *type, Chardev *chardev) 231 { 232 DeviceState *dev; 233 234 dev = qdev_create(sclp_get_event_facility_bus(), type); 235 qdev_prop_set_chr(dev, "chardev", chardev); 236 qdev_init_nofail(dev); 237 } 238 239 static void ccw_init(MachineState *machine) 240 { 241 int ret; 242 VirtualCssBus *css_bus; 243 DeviceState *dev; 244 245 s390_sclp_init(); 246 /* init memory + setup max page size. Required for the CPU model */ 247 s390_memory_init(machine->ram); 248 249 /* init CPUs (incl. CPU model) early so s390_has_feature() works */ 250 s390_init_cpus(machine); 251 252 s390_flic_init(); 253 254 /* init the SIGP facility */ 255 s390_init_sigp(); 256 257 /* create AP bridge and bus(es) */ 258 s390_init_ap(); 259 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, "s390-ccw.img", 264 "s390-netboot.img", true); 265 266 dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE); 267 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE, 268 OBJECT(dev), NULL); 269 qdev_init_nofail(dev); 270 271 /* register hypercalls */ 272 virtio_ccw_register_hcalls(); 273 274 s390_enable_css_support(s390_cpu_addr2state(0)); 275 276 ret = css_create_css_image(VIRTUAL_CSSID, true); 277 278 assert(ret == 0); 279 if (css_migration_enabled()) { 280 css_register_vmstate(); 281 } 282 283 /* Create VirtIO network adapters */ 284 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw"); 285 286 /* init consoles */ 287 if (serial_hd(0)) { 288 s390_create_sclpconsole("sclpconsole", serial_hd(0)); 289 } 290 if (serial_hd(1)) { 291 s390_create_sclpconsole("sclplmconsole", serial_hd(1)); 292 } 293 294 /* init the TOD clock */ 295 s390_init_tod(); 296 } 297 298 static void s390_cpu_plug(HotplugHandler *hotplug_dev, 299 DeviceState *dev, Error **errp) 300 { 301 MachineState *ms = MACHINE(hotplug_dev); 302 S390CPU *cpu = S390_CPU(dev); 303 304 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu); 305 ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev); 306 307 if (dev->hotplugged) { 308 raise_irq_cpu_hotplug(); 309 } 310 } 311 312 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg) 313 { 314 S390CPU *cpu = S390_CPU(cs); 315 316 s390_ipl_prepare_cpu(cpu); 317 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu); 318 } 319 320 static void s390_machine_reset(MachineState *machine) 321 { 322 enum s390_reset reset_type; 323 CPUState *cs, *t; 324 325 /* get the reset parameters, reset them once done */ 326 s390_ipl_get_reset_request(&cs, &reset_type); 327 328 /* all CPUs are paused and synchronized at this point */ 329 s390_cmma_reset(); 330 331 switch (reset_type) { 332 case S390_RESET_EXTERNAL: 333 case S390_RESET_REIPL: 334 qemu_devices_reset(); 335 s390_crypto_reset(); 336 337 /* configure and start the ipl CPU only */ 338 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL); 339 break; 340 case S390_RESET_MODIFIED_CLEAR: 341 CPU_FOREACH(t) { 342 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL); 343 } 344 subsystem_reset(); 345 s390_crypto_reset(); 346 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL); 347 break; 348 case S390_RESET_LOAD_NORMAL: 349 CPU_FOREACH(t) { 350 if (t == cs) { 351 continue; 352 } 353 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL); 354 } 355 subsystem_reset(); 356 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL); 357 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL); 358 break; 359 default: 360 g_assert_not_reached(); 361 } 362 s390_ipl_clear_reset_request(); 363 } 364 365 static void s390_machine_device_plug(HotplugHandler *hotplug_dev, 366 DeviceState *dev, Error **errp) 367 { 368 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { 369 s390_cpu_plug(hotplug_dev, dev, errp); 370 } 371 } 372 373 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev, 374 DeviceState *dev, Error **errp) 375 { 376 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { 377 error_setg(errp, "CPU hot unplug not supported on this machine"); 378 return; 379 } 380 } 381 382 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, 383 unsigned cpu_index) 384 { 385 MachineClass *mc = MACHINE_GET_CLASS(ms); 386 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms); 387 388 assert(cpu_index < possible_cpus->len); 389 return possible_cpus->cpus[cpu_index].props; 390 } 391 392 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms) 393 { 394 int i; 395 unsigned int max_cpus = ms->smp.max_cpus; 396 397 if (ms->possible_cpus) { 398 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus); 399 return ms->possible_cpus; 400 } 401 402 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) + 403 sizeof(CPUArchId) * max_cpus); 404 ms->possible_cpus->len = max_cpus; 405 for (i = 0; i < ms->possible_cpus->len; i++) { 406 ms->possible_cpus->cpus[i].type = ms->cpu_type; 407 ms->possible_cpus->cpus[i].vcpus_count = 1; 408 ms->possible_cpus->cpus[i].arch_id = i; 409 ms->possible_cpus->cpus[i].props.has_core_id = true; 410 ms->possible_cpus->cpus[i].props.core_id = i; 411 } 412 413 return ms->possible_cpus; 414 } 415 416 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, 417 DeviceState *dev) 418 { 419 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { 420 return HOTPLUG_HANDLER(machine); 421 } 422 return NULL; 423 } 424 425 static void s390_hot_add_cpu(MachineState *machine, 426 const int64_t id, Error **errp) 427 { 428 ObjectClass *oc; 429 430 g_assert(machine->possible_cpus->cpus[0].cpu); 431 oc = OBJECT_CLASS(CPU_GET_CLASS(machine->possible_cpus->cpus[0].cpu)); 432 433 s390x_new_cpu(object_class_get_name(oc), id, errp); 434 } 435 436 static void s390_nmi(NMIState *n, int cpu_index, Error **errp) 437 { 438 CPUState *cs = qemu_get_cpu(cpu_index); 439 440 s390_cpu_restart(S390_CPU(cs)); 441 } 442 443 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz) 444 { 445 /* same logic as in sclp.c */ 446 int increment_size = 20; 447 ram_addr_t newsz; 448 449 while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) { 450 increment_size++; 451 } 452 newsz = sz >> increment_size << increment_size; 453 454 if (sz != newsz) { 455 qemu_printf("Ram size %" PRIu64 "MB was fixed up to %" PRIu64 456 "MB to match machine restrictions. Consider updating " 457 "the guest definition.\n", (uint64_t) (sz / MiB), 458 (uint64_t) (newsz / MiB)); 459 } 460 return newsz; 461 } 462 463 static void ccw_machine_class_init(ObjectClass *oc, void *data) 464 { 465 MachineClass *mc = MACHINE_CLASS(oc); 466 NMIClass *nc = NMI_CLASS(oc); 467 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); 468 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc); 469 470 s390mc->ri_allowed = true; 471 s390mc->cpu_model_allowed = true; 472 s390mc->css_migration_enabled = true; 473 s390mc->hpage_1m_allowed = true; 474 mc->init = ccw_init; 475 mc->reset = s390_machine_reset; 476 mc->hot_add_cpu = s390_hot_add_cpu; 477 mc->block_default_type = IF_VIRTIO; 478 mc->no_cdrom = 1; 479 mc->no_floppy = 1; 480 mc->no_parallel = 1; 481 mc->no_sdcard = 1; 482 mc->max_cpus = S390_MAX_CPUS; 483 mc->has_hotpluggable_cpus = true; 484 assert(!mc->get_hotplug_handler); 485 mc->get_hotplug_handler = s390_get_hotplug_handler; 486 mc->cpu_index_to_instance_props = s390_cpu_index_to_props; 487 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids; 488 /* it is overridden with 'host' cpu *in kvm_arch_init* */ 489 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu"); 490 hc->plug = s390_machine_device_plug; 491 hc->unplug_request = s390_machine_device_unplug_request; 492 nc->nmi_monitor_handler = s390_nmi; 493 mc->default_ram_id = "s390.ram"; 494 } 495 496 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp) 497 { 498 S390CcwMachineState *ms = S390_CCW_MACHINE(obj); 499 500 return ms->aes_key_wrap; 501 } 502 503 static inline void machine_set_aes_key_wrap(Object *obj, bool value, 504 Error **errp) 505 { 506 S390CcwMachineState *ms = S390_CCW_MACHINE(obj); 507 508 ms->aes_key_wrap = value; 509 } 510 511 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp) 512 { 513 S390CcwMachineState *ms = S390_CCW_MACHINE(obj); 514 515 return ms->dea_key_wrap; 516 } 517 518 static inline void machine_set_dea_key_wrap(Object *obj, bool value, 519 Error **errp) 520 { 521 S390CcwMachineState *ms = S390_CCW_MACHINE(obj); 522 523 ms->dea_key_wrap = value; 524 } 525 526 static S390CcwMachineClass *current_mc; 527 528 /* 529 * Get the class of the s390-ccw-virtio machine that is currently in use. 530 * Note: libvirt is using the "none" machine to probe for the features of the 531 * host CPU, so in case this is called with the "none" machine, the function 532 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the 533 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers 534 * below return the correct default value for the "none" machine. 535 * 536 * Attention! Do *not* add additional new wrappers for CPU features (e.g. like 537 * the ri_allowed() wrapper) via this mechanism anymore. CPU features should 538 * be handled via the CPU models, i.e. checking with cpu_model_allowed() during 539 * CPU initialization and s390_has_feat() later should be sufficient. 540 */ 541 static S390CcwMachineClass *get_machine_class(void) 542 { 543 if (unlikely(!current_mc)) { 544 /* 545 * No s390 ccw machine was instantiated, we are likely to 546 * be called for the 'none' machine. The properties will 547 * have their after-initialization values. 548 */ 549 current_mc = S390_MACHINE_CLASS( 550 object_class_by_name(TYPE_S390_CCW_MACHINE)); 551 } 552 return current_mc; 553 } 554 555 bool ri_allowed(void) 556 { 557 return get_machine_class()->ri_allowed; 558 } 559 560 bool cpu_model_allowed(void) 561 { 562 return get_machine_class()->cpu_model_allowed; 563 } 564 565 bool hpage_1m_allowed(void) 566 { 567 return get_machine_class()->hpage_1m_allowed; 568 } 569 570 static char *machine_get_loadparm(Object *obj, Error **errp) 571 { 572 S390CcwMachineState *ms = S390_CCW_MACHINE(obj); 573 574 return g_memdup(ms->loadparm, sizeof(ms->loadparm)); 575 } 576 577 static void machine_set_loadparm(Object *obj, const char *val, Error **errp) 578 { 579 S390CcwMachineState *ms = S390_CCW_MACHINE(obj); 580 int i; 581 582 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) { 583 uint8_t c = qemu_toupper(val[i]); /* mimic HMC */ 584 585 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') || 586 (c == ' ')) { 587 ms->loadparm[i] = c; 588 } else { 589 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)", 590 c, c); 591 return; 592 } 593 } 594 595 for (; i < sizeof(ms->loadparm); i++) { 596 ms->loadparm[i] = ' '; /* pad right with spaces */ 597 } 598 } 599 static inline void s390_machine_initfn(Object *obj) 600 { 601 object_property_add_bool(obj, "aes-key-wrap", 602 machine_get_aes_key_wrap, 603 machine_set_aes_key_wrap, NULL); 604 object_property_set_description(obj, "aes-key-wrap", 605 "enable/disable AES key wrapping using the CPACF wrapping key", 606 NULL); 607 object_property_set_bool(obj, true, "aes-key-wrap", NULL); 608 609 object_property_add_bool(obj, "dea-key-wrap", 610 machine_get_dea_key_wrap, 611 machine_set_dea_key_wrap, NULL); 612 object_property_set_description(obj, "dea-key-wrap", 613 "enable/disable DEA key wrapping using the CPACF wrapping key", 614 NULL); 615 object_property_set_bool(obj, true, "dea-key-wrap", NULL); 616 object_property_add_str(obj, "loadparm", 617 machine_get_loadparm, machine_set_loadparm, NULL); 618 object_property_set_description(obj, "loadparm", 619 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted" 620 " to upper case) to pass to machine loader, boot manager," 621 " and guest kernel", 622 NULL); 623 } 624 625 static const TypeInfo ccw_machine_info = { 626 .name = TYPE_S390_CCW_MACHINE, 627 .parent = TYPE_MACHINE, 628 .abstract = true, 629 .instance_size = sizeof(S390CcwMachineState), 630 .instance_init = s390_machine_initfn, 631 .class_size = sizeof(S390CcwMachineClass), 632 .class_init = ccw_machine_class_init, 633 .interfaces = (InterfaceInfo[]) { 634 { TYPE_NMI }, 635 { TYPE_HOTPLUG_HANDLER}, 636 { } 637 }, 638 }; 639 640 bool css_migration_enabled(void) 641 { 642 return get_machine_class()->css_migration_enabled; 643 } 644 645 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \ 646 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \ 647 void *data) \ 648 { \ 649 MachineClass *mc = MACHINE_CLASS(oc); \ 650 ccw_machine_##suffix##_class_options(mc); \ 651 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \ 652 if (latest) { \ 653 mc->alias = "s390-ccw-virtio"; \ 654 mc->is_default = true; \ 655 } \ 656 } \ 657 static void ccw_machine_##suffix##_instance_init(Object *obj) \ 658 { \ 659 MachineState *machine = MACHINE(obj); \ 660 current_mc = S390_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \ 661 ccw_machine_##suffix##_instance_options(machine); \ 662 } \ 663 static const TypeInfo ccw_machine_##suffix##_info = { \ 664 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \ 665 .parent = TYPE_S390_CCW_MACHINE, \ 666 .class_init = ccw_machine_##suffix##_class_init, \ 667 .instance_init = ccw_machine_##suffix##_instance_init, \ 668 }; \ 669 static void ccw_machine_register_##suffix(void) \ 670 { \ 671 type_register_static(&ccw_machine_##suffix##_info); \ 672 } \ 673 type_init(ccw_machine_register_##suffix) 674 675 static void ccw_machine_5_0_instance_options(MachineState *machine) 676 { 677 } 678 679 static void ccw_machine_5_0_class_options(MachineClass *mc) 680 { 681 } 682 DEFINE_CCW_MACHINE(5_0, "5.0", true); 683 684 static void ccw_machine_4_2_instance_options(MachineState *machine) 685 { 686 ccw_machine_5_0_instance_options(machine); 687 } 688 689 static void ccw_machine_4_2_class_options(MachineClass *mc) 690 { 691 ccw_machine_5_0_class_options(mc); 692 mc->fixup_ram_size = s390_fixup_ram_size; 693 compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len); 694 } 695 DEFINE_CCW_MACHINE(4_2, "4.2", false); 696 697 static void ccw_machine_4_1_instance_options(MachineState *machine) 698 { 699 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 }; 700 ccw_machine_4_2_instance_options(machine); 701 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat); 702 } 703 704 static void ccw_machine_4_1_class_options(MachineClass *mc) 705 { 706 ccw_machine_4_2_class_options(mc); 707 compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len); 708 } 709 DEFINE_CCW_MACHINE(4_1, "4.1", false); 710 711 static void ccw_machine_4_0_instance_options(MachineState *machine) 712 { 713 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 }; 714 ccw_machine_4_1_instance_options(machine); 715 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat); 716 } 717 718 static void ccw_machine_4_0_class_options(MachineClass *mc) 719 { 720 ccw_machine_4_1_class_options(mc); 721 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len); 722 } 723 DEFINE_CCW_MACHINE(4_0, "4.0", false); 724 725 static void ccw_machine_3_1_instance_options(MachineState *machine) 726 { 727 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 }; 728 ccw_machine_4_0_instance_options(machine); 729 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH); 730 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF); 731 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat); 732 } 733 734 static void ccw_machine_3_1_class_options(MachineClass *mc) 735 { 736 ccw_machine_4_0_class_options(mc); 737 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len); 738 } 739 DEFINE_CCW_MACHINE(3_1, "3.1", false); 740 741 static void ccw_machine_3_0_instance_options(MachineState *machine) 742 { 743 ccw_machine_3_1_instance_options(machine); 744 } 745 746 static void ccw_machine_3_0_class_options(MachineClass *mc) 747 { 748 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc); 749 750 s390mc->hpage_1m_allowed = false; 751 ccw_machine_3_1_class_options(mc); 752 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len); 753 } 754 DEFINE_CCW_MACHINE(3_0, "3.0", false); 755 756 static void ccw_machine_2_12_instance_options(MachineState *machine) 757 { 758 ccw_machine_3_0_instance_options(machine); 759 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15); 760 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB); 761 } 762 763 static void ccw_machine_2_12_class_options(MachineClass *mc) 764 { 765 ccw_machine_3_0_class_options(mc); 766 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len); 767 } 768 DEFINE_CCW_MACHINE(2_12, "2.12", false); 769 770 static void ccw_machine_2_11_instance_options(MachineState *machine) 771 { 772 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 }; 773 ccw_machine_2_12_instance_options(machine); 774 775 /* before 2.12 we emulated the very first z900 */ 776 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat); 777 } 778 779 static void ccw_machine_2_11_class_options(MachineClass *mc) 780 { 781 static GlobalProperty compat[] = { 782 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", }, 783 }; 784 785 ccw_machine_2_12_class_options(mc); 786 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len); 787 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); 788 } 789 DEFINE_CCW_MACHINE(2_11, "2.11", false); 790 791 static void ccw_machine_2_10_instance_options(MachineState *machine) 792 { 793 ccw_machine_2_11_instance_options(machine); 794 } 795 796 static void ccw_machine_2_10_class_options(MachineClass *mc) 797 { 798 ccw_machine_2_11_class_options(mc); 799 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len); 800 } 801 DEFINE_CCW_MACHINE(2_10, "2.10", false); 802 803 static void ccw_machine_2_9_instance_options(MachineState *machine) 804 { 805 ccw_machine_2_10_instance_options(machine); 806 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP); 807 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2); 808 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI); 809 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION); 810 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION); 811 } 812 813 static void ccw_machine_2_9_class_options(MachineClass *mc) 814 { 815 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc); 816 static GlobalProperty compat[] = { 817 { TYPE_S390_STATTRIB, "migration-enabled", "off", }, 818 }; 819 820 ccw_machine_2_10_class_options(mc); 821 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len); 822 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); 823 s390mc->css_migration_enabled = false; 824 } 825 DEFINE_CCW_MACHINE(2_9, "2.9", false); 826 827 static void ccw_machine_2_8_instance_options(MachineState *machine) 828 { 829 ccw_machine_2_9_instance_options(machine); 830 } 831 832 static void ccw_machine_2_8_class_options(MachineClass *mc) 833 { 834 static GlobalProperty compat[] = { 835 { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", }, 836 }; 837 838 ccw_machine_2_9_class_options(mc); 839 compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len); 840 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); 841 } 842 DEFINE_CCW_MACHINE(2_8, "2.8", false); 843 844 static void ccw_machine_2_7_instance_options(MachineState *machine) 845 { 846 ccw_machine_2_8_instance_options(machine); 847 } 848 849 static void ccw_machine_2_7_class_options(MachineClass *mc) 850 { 851 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc); 852 853 s390mc->cpu_model_allowed = false; 854 ccw_machine_2_8_class_options(mc); 855 compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len); 856 } 857 DEFINE_CCW_MACHINE(2_7, "2.7", false); 858 859 static void ccw_machine_2_6_instance_options(MachineState *machine) 860 { 861 ccw_machine_2_7_instance_options(machine); 862 } 863 864 static void ccw_machine_2_6_class_options(MachineClass *mc) 865 { 866 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc); 867 static GlobalProperty compat[] = { 868 { TYPE_S390_IPL, "iplbext_migration", "off", }, 869 { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", }, 870 }; 871 872 s390mc->ri_allowed = false; 873 ccw_machine_2_7_class_options(mc); 874 compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len); 875 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); 876 } 877 DEFINE_CCW_MACHINE(2_6, "2.6", false); 878 879 static void ccw_machine_2_5_instance_options(MachineState *machine) 880 { 881 ccw_machine_2_6_instance_options(machine); 882 } 883 884 static void ccw_machine_2_5_class_options(MachineClass *mc) 885 { 886 ccw_machine_2_6_class_options(mc); 887 compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len); 888 } 889 DEFINE_CCW_MACHINE(2_5, "2.5", false); 890 891 static void ccw_machine_2_4_instance_options(MachineState *machine) 892 { 893 ccw_machine_2_5_instance_options(machine); 894 } 895 896 static void ccw_machine_2_4_class_options(MachineClass *mc) 897 { 898 static GlobalProperty compat[] = { 899 { TYPE_S390_SKEYS, "migration-enabled", "off", }, 900 { "virtio-blk-ccw", "max_revision", "0", }, 901 { "virtio-balloon-ccw", "max_revision", "0", }, 902 { "virtio-serial-ccw", "max_revision", "0", }, 903 { "virtio-9p-ccw", "max_revision", "0", }, 904 { "virtio-rng-ccw", "max_revision", "0", }, 905 { "virtio-net-ccw", "max_revision", "0", }, 906 { "virtio-scsi-ccw", "max_revision", "0", }, 907 { "vhost-scsi-ccw", "max_revision", "0", }, 908 }; 909 910 ccw_machine_2_5_class_options(mc); 911 compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len); 912 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); 913 } 914 DEFINE_CCW_MACHINE(2_4, "2.4", false); 915 916 static void ccw_machine_register_types(void) 917 { 918 type_register_static(&ccw_machine_info); 919 } 920 921 type_init(ccw_machine_register_types) 922