target-sh4: Use mul*2 for dmul*
[qemu/agraf.git] / hw / s390x / s390-virtio-ccw.c
blob65492118200ce91bf278e41cf03816a0c0899200
1 /*
2 * virtio ccw machine
4 * Copyright 2012 IBM Corp.
5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
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.
12 #include "hw/boards.h"
13 #include "exec/address-spaces.h"
14 #include "s390-virtio.h"
15 #include "sclp.h"
16 #include "ioinst.h"
17 #include "css.h"
18 #include "virtio-ccw.h"
20 static int virtio_ccw_hcall_notify(const uint64_t *args)
22 uint64_t subch_id = args[0];
23 uint64_t queue = args[1];
24 SubchDev *sch;
25 int cssid, ssid, schid, m;
27 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
28 return -EINVAL;
30 sch = css_find_subch(m, cssid, ssid, schid);
31 if (!sch || !css_subch_visible(sch)) {
32 return -EINVAL;
34 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
35 return 0;
39 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
41 uint64_t mem = args[0];
43 if (mem < ram_size) {
44 /* Early printk */
45 return 0;
47 return -EINVAL;
50 static void virtio_ccw_register_hcalls(void)
52 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
53 virtio_ccw_hcall_notify);
54 /* Tolerate early printk. */
55 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
56 virtio_ccw_hcall_early_printk);
59 static void ccw_init(QEMUMachineInitArgs *args)
61 ram_addr_t my_ram_size = args->ram_size;
62 MemoryRegion *sysmem = get_system_memory();
63 MemoryRegion *ram = g_new(MemoryRegion, 1);
64 int shift = 0;
65 uint8_t *storage_keys;
66 int ret;
67 VirtualCssBus *css_bus;
69 /* s390x ram size detection needs a 16bit multiplier + an increment. So
70 guests > 64GB can be specified in 2MB steps etc. */
71 while ((my_ram_size >> (20 + shift)) > 65535) {
72 shift++;
74 my_ram_size = my_ram_size >> (20 + shift) << (20 + shift);
76 /* lets propagate the changed ram size into the global variable. */
77 ram_size = my_ram_size;
79 /* get a BUS */
80 css_bus = virtual_css_bus_init();
81 s390_sclp_init();
82 s390_init_ipl_dev(args->kernel_filename, args->kernel_cmdline,
83 args->initrd_filename);
85 /* register hypercalls */
86 virtio_ccw_register_hcalls();
88 /* allocate RAM */
89 memory_region_init_ram(ram, "s390.ram", my_ram_size);
90 vmstate_register_ram_global(ram);
91 memory_region_add_subregion(sysmem, 0, ram);
93 /* allocate storage keys */
94 storage_keys = g_malloc0(my_ram_size / TARGET_PAGE_SIZE);
96 /* init CPUs */
97 s390_init_cpus(args->cpu_model, storage_keys);
99 if (kvm_enabled()) {
100 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
103 * Create virtual css and set it as default so that non mcss-e
104 * enabled guests only see virtio devices.
106 ret = css_create_css_image(VIRTUAL_CSSID, true);
107 assert(ret == 0);
109 /* Create VirtIO network adapters */
110 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
113 static QEMUMachine ccw_machine = {
114 .name = "s390-ccw-virtio",
115 .alias = "s390-ccw",
116 .desc = "VirtIO-ccw based S390 machine",
117 .init = ccw_init,
118 .block_default_type = IF_VIRTIO,
119 .no_cdrom = 1,
120 .no_floppy = 1,
121 .no_serial = 1,
122 .no_parallel = 1,
123 .no_sdcard = 1,
124 .use_sclp = 1,
125 .max_cpus = 255,
126 DEFAULT_MACHINE_OPTIONS,
129 static void ccw_machine_init(void)
131 qemu_register_machine(&ccw_machine);
134 machine_init(ccw_machine_init)