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"
15 #include "hw/s390x/sclp.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 if (queue
>= VIRTIO_PCI_QUEUE_MAX
) {
37 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
42 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
44 uint64_t mem
= args
[0];
53 static void virtio_ccw_register_hcalls(void)
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
);
62 static void ccw_init(QEMUMachineInitArgs
*args
)
64 ram_addr_t my_ram_size
= args
->ram_size
;
65 MemoryRegion
*sysmem
= get_system_memory();
66 MemoryRegion
*ram
= g_new(MemoryRegion
, 1);
68 uint8_t *storage_keys
;
70 VirtualCssBus
*css_bus
;
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) {
77 my_ram_size
= my_ram_size
>> (20 + shift
) << (20 + shift
);
79 /* let's propagate the changed ram size into the global variable. */
80 ram_size
= my_ram_size
;
83 css_bus
= virtual_css_bus_init();
85 s390_init_ipl_dev(args
->kernel_filename
, args
->kernel_cmdline
,
86 args
->initrd_filename
, "s390-ccw.img");
88 /* register hypercalls */
89 virtio_ccw_register_hcalls();
92 memory_region_init_ram(ram
, "s390.ram", my_ram_size
);
93 vmstate_register_ram_global(ram
);
94 memory_region_add_subregion(sysmem
, 0, ram
);
96 /* allocate storage keys */
97 storage_keys
= g_malloc0(my_ram_size
/ TARGET_PAGE_SIZE
);
100 s390_init_cpus(args
->cpu_model
, storage_keys
);
103 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
106 * Create virtual css and set it as default so that non mcss-e
107 * enabled guests only see virtio devices.
109 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
112 /* Create VirtIO network adapters */
113 s390_create_virtio_net(BUS(css_bus
), "virtio-net-ccw");
116 static QEMUMachine ccw_machine
= {
117 .name
= "s390-ccw-virtio",
119 .desc
= "VirtIO-ccw based S390 machine",
121 .block_default_type
= IF_VIRTIO
,
129 DEFAULT_MACHINE_OPTIONS
,
132 static void ccw_machine_init(void)
134 qemu_register_machine(&ccw_machine
);
137 machine_init(ccw_machine_init
)