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
12 #include "hw/boards.h"
13 #include "exec/address-spaces.h"
14 #include "s390-virtio.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];
25 int cssid
, ssid
, schid
, m
;
27 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
30 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
31 if (!sch
|| !css_subch_visible(sch
)) {
34 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
39 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
41 uint64_t mem
= args
[0];
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);
65 uint8_t *storage_keys
;
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) {
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
;
80 css_bus
= virtual_css_bus_init();
82 s390_init_ipl_dev(args
->kernel_filename
, args
->kernel_cmdline
,
83 args
->initrd_filename
);
85 /* register hypercalls */
86 virtio_ccw_register_hcalls();
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
);
97 s390_init_cpus(args
->cpu_model
, storage_keys
);
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);
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",
116 .desc
= "VirtIO-ccw based S390 machine",
118 .block_default_type
= IF_VIRTIO
,
126 DEFAULT_MACHINE_OPTIONS
,
129 static void ccw_machine_init(void)
131 qemu_register_machine(&ccw_machine
);
134 machine_init(ccw_machine_init
)