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 "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"
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
[] = {
30 "s390-sclp-event-facility",
35 void subsystem_reset(void)
40 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
41 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
48 static int virtio_ccw_hcall_notify(const uint64_t *args
)
50 uint64_t subch_id
= args
[0];
51 uint64_t queue
= args
[1];
53 int cssid
, ssid
, schid
, m
;
55 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
58 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
59 if (!sch
|| !css_subch_visible(sch
)) {
62 if (queue
>= VIRTIO_CCW_QUEUE_MAX
) {
65 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
70 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
72 uint64_t mem
= args
[0];
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 */
103 static void ccw_init(MachineState
*machine
)
106 VirtualCssBus
*css_bus
;
110 s390_memory_init(machine
->ram_size
);
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);
118 dev
= qdev_create(NULL
, TYPE_S390_PCI_HOST_BRIDGE
);
119 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
121 qdev_init_nofail(dev
);
123 /* register hypercalls */
124 virtio_ccw_register_hcalls();
127 s390_init_cpus(machine
);
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);
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
)
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
,
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
,
171 if (object_dynamic_cast(OBJECT(dev
), TYPE_CPU
)) {
172 return HOTPLUG_HANDLER(machine
);
177 static void s390_hot_add_cpu(const int64_t id
, Error
**errp
)
179 MachineState
*machine
= MACHINE(qdev_get_machine());
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
);
193 mc
->reset
= s390_machine_reset
;
194 mc
->hot_add_cpu
= s390_hot_add_cpu
;
195 mc
->block_default_type
= IF_VIRTIO
;
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
,
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
,
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",
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",
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
,
261 .instance_size
= sizeof(S390CcwMachineState
),
262 .instance_init
= s390_machine_initfn
,
263 .class_init
= ccw_machine_class_init
,
264 .interfaces
= (InterfaceInfo
[]) {
266 { TYPE_HOTPLUG_HANDLER
},
271 #define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
272 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
275 MachineClass *mc = MACHINE_CLASS(oc); \
276 ccw_machine_##suffix##_class_options(mc); \
277 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
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, \
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 \
303 #define CCW_COMPAT_2_4 \
307 .driver = TYPE_S390_SKEYS,\
308 .property = "migration-enabled",\
311 .driver = "virtio-blk-ccw",\
312 .property = "max_revision",\
315 .driver = "virtio-balloon-ccw",\
316 .property = "max_revision",\
319 .driver = "virtio-serial-ccw",\
320 .property = "max_revision",\
323 .driver = "virtio-9p-ccw",\
324 .property = "max_revision",\
327 .driver = "virtio-rng-ccw",\
328 .property = "max_revision",\
331 .driver = "virtio-net-ccw",\
332 .property = "max_revision",\
335 .driver = "virtio-scsi-ccw",\
336 .property = "max_revision",\
339 .driver = "vhost-scsi-ccw",\
340 .property = "max_revision",\
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
)