1 /* 2 * virtio ccw machine 3 * 4 * Copyright 2012 IBM Corp. 5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> 6 * 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 9 * directory. 10 */ 11 12 #include "hw/boards.h" 13 #include "exec/address-spaces.h" 14 #include "s390-virtio.h" 15 #include "hw/s390x/sclp.h" 16 #include "ioinst.h" 17 #include "css.h" 18 #include "virtio-ccw.h" 19 20 void io_subsystem_reset(void) 21 { 22 DeviceState *css, *sclp; 23 24 css = DEVICE(object_resolve_path_type("", "virtual-css-bridge", NULL)); 25 if (css) { 26 qdev_reset_all(css); 27 } 28 sclp = DEVICE(object_resolve_path_type("", 29 "s390-sclp-event-facility", NULL)); 30 if (sclp) { 31 qdev_reset_all(sclp); 32 } 33 } 34 35 static int virtio_ccw_hcall_notify(const uint64_t *args) 36 { 37 uint64_t subch_id = args[0]; 38 uint64_t queue = args[1]; 39 SubchDev *sch; 40 int cssid, ssid, schid, m; 41 42 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) { 43 return -EINVAL; 44 } 45 sch = css_find_subch(m, cssid, ssid, schid); 46 if (!sch || !css_subch_visible(sch)) { 47 return -EINVAL; 48 } 49 if (queue >= VIRTIO_PCI_QUEUE_MAX) { 50 return -EINVAL; 51 } 52 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue); 53 return 0; 54 55 } 56 57 static int virtio_ccw_hcall_early_printk(const uint64_t *args) 58 { 59 uint64_t mem = args[0]; 60 61 if (mem < ram_size) { 62 /* Early printk */ 63 return 0; 64 } 65 return -EINVAL; 66 } 67 68 static void virtio_ccw_register_hcalls(void) 69 { 70 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY, 71 virtio_ccw_hcall_notify); 72 /* Tolerate early printk. */ 73 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY, 74 virtio_ccw_hcall_early_printk); 75 } 76 77 static void ccw_init(QEMUMachineInitArgs *args) 78 { 79 ram_addr_t my_ram_size = args->ram_size; 80 MemoryRegion *sysmem = get_system_memory(); 81 MemoryRegion *ram = g_new(MemoryRegion, 1); 82 int shift = 0; 83 uint8_t *storage_keys; 84 int ret; 85 VirtualCssBus *css_bus; 86 87 /* s390x ram size detection needs a 16bit multiplier + an increment. So 88 guests > 64GB can be specified in 2MB steps etc. */ 89 while ((my_ram_size >> (20 + shift)) > 65535) { 90 shift++; 91 } 92 my_ram_size = my_ram_size >> (20 + shift) << (20 + shift); 93 94 /* let's propagate the changed ram size into the global variable. */ 95 ram_size = my_ram_size; 96 97 /* get a BUS */ 98 css_bus = virtual_css_bus_init(); 99 s390_sclp_init(); 100 s390_init_ipl_dev(args->kernel_filename, args->kernel_cmdline, 101 args->initrd_filename, "s390-ccw.img"); 102 103 /* register hypercalls */ 104 virtio_ccw_register_hcalls(); 105 106 /* allocate RAM */ 107 memory_region_init_ram(ram, NULL, "s390.ram", my_ram_size); 108 vmstate_register_ram_global(ram); 109 memory_region_add_subregion(sysmem, 0, ram); 110 111 /* allocate storage keys */ 112 storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE); 113 114 /* init CPUs */ 115 s390_init_cpus(args->cpu_model, storage_keys); 116 117 if (kvm_enabled()) { 118 kvm_s390_enable_css_support(s390_cpu_addr2state(0)); 119 } 120 /* 121 * Create virtual css and set it as default so that non mcss-e 122 * enabled guests only see virtio devices. 123 */ 124 ret = css_create_css_image(VIRTUAL_CSSID, true); 125 assert(ret == 0); 126 127 /* Create VirtIO network adapters */ 128 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw"); 129 } 130 131 static QEMUMachine ccw_machine = { 132 .name = "s390-ccw-virtio", 133 .alias = "s390-ccw", 134 .desc = "VirtIO-ccw based S390 machine", 135 .init = ccw_init, 136 .block_default_type = IF_VIRTIO, 137 .no_cdrom = 1, 138 .no_floppy = 1, 139 .no_serial = 1, 140 .no_parallel = 1, 141 .no_sdcard = 1, 142 .use_sclp = 1, 143 .max_cpus = 255, 144 }; 145 146 static void ccw_machine_init(void) 147 { 148 qemu_register_machine(&ccw_machine); 149 } 150 151 machine_init(ccw_machine_init) 152