4 * Copyright 2012 IBM Corp.
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"
16 #include "hw/s390x/s390_flic.h"
19 #include "virtio-ccw.h"
20 #include "qemu/config-file.h"
21 #include "s390-pci-bus.h"
22 #include "hw/s390x/storage-keys.h"
24 #define TYPE_S390_CCW_MACHINE "s390-ccw-machine"
26 #define S390_CCW_MACHINE(obj) \
27 OBJECT_CHECK(S390CcwMachineState, (obj), TYPE_S390_CCW_MACHINE)
29 typedef struct S390CcwMachineState {
31 MachineState parent_obj;
36 } S390CcwMachineState;
38 static const char *const reset_dev_types[] = {
40 "s390-sclp-event-facility",
45 void subsystem_reset(void)
50 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
51 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
58 static int virtio_ccw_hcall_notify(const uint64_t *args)
60 uint64_t subch_id = args[0];
61 uint64_t queue = args[1];
63 int cssid, ssid, schid, m;
65 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
68 sch = css_find_subch(m, cssid, ssid, schid);
69 if (!sch || !css_subch_visible(sch)) {
72 if (queue >= VIRTIO_CCW_QUEUE_MAX) {
75 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
80 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
82 uint64_t mem = args[0];
91 static void virtio_ccw_register_hcalls(void)
93 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
94 virtio_ccw_hcall_notify);
95 /* Tolerate early printk. */
96 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
97 virtio_ccw_hcall_early_printk);
100 void s390_memory_init(ram_addr_t mem_size)
102 MemoryRegion *sysmem = get_system_memory();
103 MemoryRegion *ram = g_new(MemoryRegion, 1);
105 /* allocate RAM for core */
106 memory_region_init_ram(ram, NULL, "s390.ram", mem_size, &error_fatal);
107 vmstate_register_ram_global(ram);
108 memory_region_add_subregion(sysmem, 0, ram);
110 /* Initialize storage key device */
114 static void ccw_init(MachineState *machine)
117 VirtualCssBus *css_bus;
121 s390_memory_init(machine->ram_size);
124 css_bus = virtual_css_bus_init();
125 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
126 machine->initrd_filename, "s390-ccw.img", true);
129 dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
130 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
132 qdev_init_nofail(dev);
134 /* register hypercalls */
135 virtio_ccw_register_hcalls();
138 s390_init_cpus(machine->cpu_model);
141 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
144 * Create virtual css and set it as default so that non mcss-e
145 * enabled guests only see virtio devices.
147 ret = css_create_css_image(VIRTUAL_CSSID, true);
150 /* Create VirtIO network adapters */
151 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
153 /* Register savevm handler for guest TOD clock */
154 register_savevm(NULL, "todclock", 0, 1,
155 gtod_save, gtod_load, kvm_state);
158 static void ccw_machine_class_init(ObjectClass *oc, void *data)
160 MachineClass *mc = MACHINE_CLASS(oc);
161 NMIClass *nc = NMI_CLASS(oc);
164 mc->block_default_type = IF_VIRTIO;
172 nc->nmi_monitor_handler = s390_nmi;
175 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
177 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
179 return ms->aes_key_wrap;
182 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
185 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
187 ms->aes_key_wrap = value;
190 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
192 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
194 return ms->dea_key_wrap;
197 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
200 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
202 ms->dea_key_wrap = value;
205 static inline void s390_machine_initfn(Object *obj)
207 object_property_add_bool(obj, "aes-key-wrap",
208 machine_get_aes_key_wrap,
209 machine_set_aes_key_wrap, NULL);
210 object_property_set_description(obj, "aes-key-wrap",
211 "enable/disable AES key wrapping using the CPACF wrapping key",
213 object_property_set_bool(obj, true, "aes-key-wrap", NULL);
215 object_property_add_bool(obj, "dea-key-wrap",
216 machine_get_dea_key_wrap,
217 machine_set_dea_key_wrap, NULL);
218 object_property_set_description(obj, "dea-key-wrap",
219 "enable/disable DEA key wrapping using the CPACF wrapping key",
221 object_property_set_bool(obj, true, "dea-key-wrap", NULL);
224 static const TypeInfo ccw_machine_info = {
225 .name = TYPE_S390_CCW_MACHINE,
226 .parent = TYPE_MACHINE,
228 .instance_size = sizeof(S390CcwMachineState),
229 .instance_init = s390_machine_initfn,
230 .class_init = ccw_machine_class_init,
231 .interfaces = (InterfaceInfo[]) {
237 #define CCW_COMPAT_2_4 \
239 .driver = TYPE_S390_SKEYS,\
240 .property = "migration-enabled",\
243 .driver = "virtio-blk-ccw",\
244 .property = "max_revision",\
247 .driver = "virtio-balloon-ccw",\
248 .property = "max_revision",\
251 .driver = "virtio-serial-ccw",\
252 .property = "max_revision",\
255 .driver = "virtio-9p-ccw",\
256 .property = "max_revision",\
259 .driver = "virtio-rng-ccw",\
260 .property = "max_revision",\
263 .driver = "virtio-net-ccw",\
264 .property = "max_revision",\
267 .driver = "virtio-scsi-ccw",\
268 .property = "max_revision",\
271 .driver = "vhost-scsi-ccw",\
272 .property = "max_revision",\
276 static void ccw_machine_2_4_class_init(ObjectClass *oc, void *data)
278 MachineClass *mc = MACHINE_CLASS(oc);
279 static GlobalProperty compat_props[] = {
281 { /* end of list */ }
284 mc->desc = "VirtIO-ccw based S390 machine v2.4";
285 mc->compat_props = compat_props;
288 static const TypeInfo ccw_machine_2_4_info = {
289 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-2.4"),
290 .parent = TYPE_S390_CCW_MACHINE,
291 .class_init = ccw_machine_2_4_class_init,
294 static void ccw_machine_2_5_class_init(ObjectClass *oc, void *data)
296 MachineClass *mc = MACHINE_CLASS(oc);
298 mc->alias = "s390-ccw-virtio";
299 mc->desc = "VirtIO-ccw based S390 machine v2.5";
303 static const TypeInfo ccw_machine_2_5_info = {
304 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-2.5"),
305 .parent = TYPE_S390_CCW_MACHINE,
306 .class_init = ccw_machine_2_5_class_init,
309 static void ccw_machine_register_types(void)
311 type_register_static(&ccw_machine_info);
312 type_register_static(&ccw_machine_2_4_info);
313 type_register_static(&ccw_machine_2_5_info);
316 type_init(ccw_machine_register_types)