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