4 * Copyright 2012 IBM Corp.
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
12 #include "hw/boards.h"
13 #include "exec/address-spaces.h"
14 #include "s390-virtio.h"
15 #include "hw/s390x/sclp.h"
16 #include "hw/s390x/s390_flic.h"
19 #include "virtio-ccw.h"
21 #define TYPE_S390_CCW_MACHINE "s390-ccw-machine"
23 void io_subsystem_reset(void)
25 DeviceState *css, *sclp, *flic;
27 css = DEVICE(object_resolve_path_type("", "virtual-css-bridge", NULL));
31 sclp = DEVICE(object_resolve_path_type("",
32 "s390-sclp-event-facility", NULL));
36 flic = DEVICE(object_resolve_path_type("", "s390-flic", NULL));
42 static int virtio_ccw_hcall_notify(const uint64_t *args)
44 uint64_t subch_id = args[0];
45 uint64_t queue = args[1];
47 int cssid, ssid, schid, m;
49 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
52 sch = css_find_subch(m, cssid, ssid, schid);
53 if (!sch || !css_subch_visible(sch)) {
56 if (queue >= VIRTIO_PCI_QUEUE_MAX) {
59 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
64 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
66 uint64_t mem = args[0];
75 static void virtio_ccw_register_hcalls(void)
77 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
78 virtio_ccw_hcall_notify);
79 /* Tolerate early printk. */
80 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
81 virtio_ccw_hcall_early_printk);
84 static void ccw_init(MachineState *machine)
86 ram_addr_t my_ram_size = machine->ram_size;
87 MemoryRegion *sysmem = get_system_memory();
88 MemoryRegion *ram = g_new(MemoryRegion, 1);
90 uint8_t *storage_keys;
92 VirtualCssBus *css_bus;
94 /* s390x ram size detection needs a 16bit multiplier + an increment. So
95 guests > 64GB can be specified in 2MB steps etc. */
96 while ((my_ram_size >> (20 + shift)) > 65535) {
99 my_ram_size = my_ram_size >> (20 + shift) << (20 + shift);
101 /* let's propagate the changed ram size into the global variable. */
102 ram_size = my_ram_size;
105 css_bus = virtual_css_bus_init();
107 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
108 machine->initrd_filename, "s390-ccw.img");
111 /* register hypercalls */
112 virtio_ccw_register_hcalls();
115 memory_region_init_ram(ram, NULL, "s390.ram", my_ram_size);
116 vmstate_register_ram_global(ram);
117 memory_region_add_subregion(sysmem, 0, ram);
119 /* allocate storage keys */
120 storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
123 s390_init_cpus(machine->cpu_model, storage_keys);
126 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
129 * Create virtual css and set it as default so that non mcss-e
130 * enabled guests only see virtio devices.
132 ret = css_create_css_image(VIRTUAL_CSSID, true);
135 /* Create VirtIO network adapters */
136 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
139 static void ccw_machine_class_init(ObjectClass *oc, void *data)
141 MachineClass *mc = MACHINE_CLASS(oc);
142 NMIClass *nc = NMI_CLASS(oc);
144 mc->name = "s390-ccw-virtio";
145 mc->alias = "s390-ccw";
146 mc->desc = "VirtIO-ccw based S390 machine";
148 mc->block_default_type = IF_VIRTIO;
156 nc->nmi_monitor_handler = s390_nmi;
159 static const TypeInfo ccw_machine_info = {
160 .name = TYPE_S390_CCW_MACHINE,
161 .parent = TYPE_MACHINE,
162 .class_init = ccw_machine_class_init,
163 .interfaces = (InterfaceInfo[]) {
169 static void ccw_machine_register_types(void)
171 type_register_static(&ccw_machine_info);
174 type_init(ccw_machine_register_types)