include/qemu/osdep.h: Don't include qapi/error.h
[qemu/ar7.git] / hw / s390x / s390-virtio-ccw.c
blob01aeec90fe7bf0a03666ea5c878f898c877c06e4
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 "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "hw/boards.h"
15 #include "exec/address-spaces.h"
16 #include "s390-virtio.h"
17 #include "hw/s390x/sclp.h"
18 #include "hw/s390x/s390_flic.h"
19 #include "ioinst.h"
20 #include "css.h"
21 #include "virtio-ccw.h"
22 #include "qemu/config-file.h"
23 #include "s390-pci-bus.h"
24 #include "hw/s390x/storage-keys.h"
25 #include "hw/compat.h"
26 #include "hw/s390x/s390-virtio-ccw.h"
28 static const char *const reset_dev_types[] = {
29 "virtual-css-bridge",
30 "s390-sclp-event-facility",
31 "s390-flic",
32 "diag288",
35 void subsystem_reset(void)
37 DeviceState *dev;
38 int i;
40 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
41 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
42 if (dev) {
43 qdev_reset_all(dev);
48 static int virtio_ccw_hcall_notify(const uint64_t *args)
50 uint64_t subch_id = args[0];
51 uint64_t queue = args[1];
52 SubchDev *sch;
53 int cssid, ssid, schid, m;
55 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
56 return -EINVAL;
58 sch = css_find_subch(m, cssid, ssid, schid);
59 if (!sch || !css_subch_visible(sch)) {
60 return -EINVAL;
62 if (queue >= VIRTIO_CCW_QUEUE_MAX) {
63 return -EINVAL;
65 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
66 return 0;
70 static int virtio_ccw_hcall_early_printk(const uint64_t *args)
72 uint64_t mem = args[0];
74 if (mem < ram_size) {
75 /* Early printk */
76 return 0;
78 return -EINVAL;
81 static void virtio_ccw_register_hcalls(void)
83 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
84 virtio_ccw_hcall_notify);
85 /* Tolerate early printk. */
86 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
87 virtio_ccw_hcall_early_printk);
90 void s390_memory_init(ram_addr_t mem_size)
92 MemoryRegion *sysmem = get_system_memory();
93 MemoryRegion *ram = g_new(MemoryRegion, 1);
95 /* allocate RAM for core */
96 memory_region_allocate_system_memory(ram, NULL, "s390.ram", mem_size);
97 memory_region_add_subregion(sysmem, 0, ram);
99 /* Initialize storage key device */
100 s390_skeys_init();
103 static void ccw_init(MachineState *machine)
105 int ret;
106 VirtualCssBus *css_bus;
107 DeviceState *dev;
109 s390_sclp_init();
110 s390_memory_init(machine->ram_size);
112 /* get a BUS */
113 css_bus = virtual_css_bus_init();
114 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
115 machine->initrd_filename, "s390-ccw.img", true);
116 s390_flic_init();
118 dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
119 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
120 OBJECT(dev), NULL);
121 qdev_init_nofail(dev);
123 /* register hypercalls */
124 virtio_ccw_register_hcalls();
126 /* init CPUs */
127 s390_init_cpus(machine);
129 if (kvm_enabled()) {
130 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
133 * Create virtual css and set it as default so that non mcss-e
134 * enabled guests only see virtio devices.
136 ret = css_create_css_image(VIRTUAL_CSSID, true);
137 assert(ret == 0);
139 /* Create VirtIO network adapters */
140 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
142 /* Register savevm handler for guest TOD clock */
143 register_savevm(NULL, "todclock", 0, 1,
144 gtod_save, gtod_load, kvm_state);
147 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
148 DeviceState *dev, Error **errp)
150 gchar *name;
151 S390CPU *cpu = S390_CPU(dev);
152 CPUState *cs = CPU(dev);
154 name = g_strdup_printf("cpu[%i]", cpu->env.cpu_num);
155 object_property_set_link(OBJECT(hotplug_dev), OBJECT(cs), name,
156 errp);
157 g_free(name);
160 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
161 DeviceState *dev, Error **errp)
163 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
164 s390_cpu_plug(hotplug_dev, dev, errp);
168 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
169 DeviceState *dev)
171 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
172 return HOTPLUG_HANDLER(machine);
174 return NULL;
177 static void s390_hot_add_cpu(const int64_t id, Error **errp)
179 MachineState *machine = MACHINE(qdev_get_machine());
180 Error *err = NULL;
182 s390x_new_cpu(machine->cpu_model, id, &err);
183 error_propagate(errp, err);
186 static void ccw_machine_class_init(ObjectClass *oc, void *data)
188 MachineClass *mc = MACHINE_CLASS(oc);
189 NMIClass *nc = NMI_CLASS(oc);
190 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
192 mc->init = ccw_init;
193 mc->reset = s390_machine_reset;
194 mc->hot_add_cpu = s390_hot_add_cpu;
195 mc->block_default_type = IF_VIRTIO;
196 mc->no_cdrom = 1;
197 mc->no_floppy = 1;
198 mc->no_serial = 1;
199 mc->no_parallel = 1;
200 mc->no_sdcard = 1;
201 mc->use_sclp = 1;
202 mc->max_cpus = 255;
203 mc->get_hotplug_handler = s390_get_hotplug_handler;
204 hc->plug = s390_machine_device_plug;
205 nc->nmi_monitor_handler = s390_nmi;
208 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
210 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
212 return ms->aes_key_wrap;
215 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
216 Error **errp)
218 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
220 ms->aes_key_wrap = value;
223 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
225 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
227 return ms->dea_key_wrap;
230 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
231 Error **errp)
233 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
235 ms->dea_key_wrap = value;
238 static inline void s390_machine_initfn(Object *obj)
240 object_property_add_bool(obj, "aes-key-wrap",
241 machine_get_aes_key_wrap,
242 machine_set_aes_key_wrap, NULL);
243 object_property_set_description(obj, "aes-key-wrap",
244 "enable/disable AES key wrapping using the CPACF wrapping key",
245 NULL);
246 object_property_set_bool(obj, true, "aes-key-wrap", NULL);
248 object_property_add_bool(obj, "dea-key-wrap",
249 machine_get_dea_key_wrap,
250 machine_set_dea_key_wrap, NULL);
251 object_property_set_description(obj, "dea-key-wrap",
252 "enable/disable DEA key wrapping using the CPACF wrapping key",
253 NULL);
254 object_property_set_bool(obj, true, "dea-key-wrap", NULL);
257 static const TypeInfo ccw_machine_info = {
258 .name = TYPE_S390_CCW_MACHINE,
259 .parent = TYPE_MACHINE,
260 .abstract = true,
261 .instance_size = sizeof(S390CcwMachineState),
262 .instance_init = s390_machine_initfn,
263 .class_init = ccw_machine_class_init,
264 .interfaces = (InterfaceInfo[]) {
265 { TYPE_NMI },
266 { TYPE_HOTPLUG_HANDLER},
271 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
272 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
273 void *data) \
275 MachineClass *mc = MACHINE_CLASS(oc); \
276 ccw_machine_##suffix##_class_options(mc); \
277 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
278 if (latest) { \
279 mc->alias = "s390-ccw-virtio"; \
280 mc->is_default = 1; \
283 static void ccw_machine_##suffix##_instance_init(Object *obj) \
285 MachineState *machine = MACHINE(obj); \
286 ccw_machine_##suffix##_instance_options(machine); \
288 static const TypeInfo ccw_machine_##suffix##_info = { \
289 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
290 .parent = TYPE_S390_CCW_MACHINE, \
291 .class_init = ccw_machine_##suffix##_class_init, \
292 .instance_init = ccw_machine_##suffix##_instance_init, \
293 }; \
294 static void ccw_machine_register_##suffix(void) \
296 type_register_static(&ccw_machine_##suffix##_info); \
298 type_init(ccw_machine_register_##suffix)
300 #define CCW_COMPAT_2_5 \
301 HW_COMPAT_2_5
303 #define CCW_COMPAT_2_4 \
304 CCW_COMPAT_2_5 \
305 HW_COMPAT_2_4 \
307 .driver = TYPE_S390_SKEYS,\
308 .property = "migration-enabled",\
309 .value = "off",\
310 },{\
311 .driver = "virtio-blk-ccw",\
312 .property = "max_revision",\
313 .value = "0",\
314 },{\
315 .driver = "virtio-balloon-ccw",\
316 .property = "max_revision",\
317 .value = "0",\
318 },{\
319 .driver = "virtio-serial-ccw",\
320 .property = "max_revision",\
321 .value = "0",\
322 },{\
323 .driver = "virtio-9p-ccw",\
324 .property = "max_revision",\
325 .value = "0",\
326 },{\
327 .driver = "virtio-rng-ccw",\
328 .property = "max_revision",\
329 .value = "0",\
330 },{\
331 .driver = "virtio-net-ccw",\
332 .property = "max_revision",\
333 .value = "0",\
334 },{\
335 .driver = "virtio-scsi-ccw",\
336 .property = "max_revision",\
337 .value = "0",\
338 },{\
339 .driver = "vhost-scsi-ccw",\
340 .property = "max_revision",\
341 .value = "0",\
344 static void ccw_machine_2_6_instance_options(MachineState *machine)
348 static void ccw_machine_2_6_class_options(MachineClass *mc)
351 DEFINE_CCW_MACHINE(2_6, "2.6", true);
353 static void ccw_machine_2_5_instance_options(MachineState *machine)
357 static void ccw_machine_2_5_class_options(MachineClass *mc)
359 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_5);
361 DEFINE_CCW_MACHINE(2_5, "2.5", false);
363 static void ccw_machine_2_4_instance_options(MachineState *machine)
365 ccw_machine_2_5_instance_options(machine);
368 static void ccw_machine_2_4_class_options(MachineClass *mc)
370 SET_MACHINE_COMPAT(mc, CCW_COMPAT_2_4);
372 DEFINE_CCW_MACHINE(2_4, "2.4", false);
374 static void ccw_machine_register_types(void)
376 type_register_static(&ccw_machine_info);
379 type_init(ccw_machine_register_types)