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