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"
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"
23 #include "hw/compat.h"
25 #define TYPE_S390_CCW_MACHINE "s390-ccw-machine"
27 #define S390_CCW_MACHINE(obj) \
28 OBJECT_CHECK(S390CcwMachineState, (obj), TYPE_S390_CCW_MACHINE)
30 typedef struct S390CcwMachineState
{
32 MachineState parent_obj
;
37 } S390CcwMachineState
;
39 static const char *const reset_dev_types
[] = {
41 "s390-sclp-event-facility",
46 void subsystem_reset(void)
51 for (i
= 0; i
< ARRAY_SIZE(reset_dev_types
); i
++) {
52 dev
= DEVICE(object_resolve_path_type("", reset_dev_types
[i
], NULL
));
59 static int virtio_ccw_hcall_notify(const uint64_t *args
)
61 uint64_t subch_id
= args
[0];
62 uint64_t queue
= args
[1];
64 int cssid
, ssid
, schid
, m
;
66 if (ioinst_disassemble_sch_ident(subch_id
, &m
, &cssid
, &ssid
, &schid
)) {
69 sch
= css_find_subch(m
, cssid
, ssid
, schid
);
70 if (!sch
|| !css_subch_visible(sch
)) {
73 if (queue
>= VIRTIO_CCW_QUEUE_MAX
) {
76 virtio_queue_notify(virtio_ccw_get_vdev(sch
), queue
);
81 static int virtio_ccw_hcall_early_printk(const uint64_t *args
)
83 uint64_t mem
= args
[0];
92 static void virtio_ccw_register_hcalls(void)
94 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY
,
95 virtio_ccw_hcall_notify
);
96 /* Tolerate early printk. */
97 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY
,
98 virtio_ccw_hcall_early_printk
);
101 void s390_memory_init(ram_addr_t mem_size
)
103 MemoryRegion
*sysmem
= get_system_memory();
104 MemoryRegion
*ram
= g_new(MemoryRegion
, 1);
106 /* allocate RAM for core */
107 memory_region_init_ram(ram
, NULL
, "s390.ram", mem_size
, &error_fatal
);
108 vmstate_register_ram_global(ram
);
109 memory_region_add_subregion(sysmem
, 0, ram
);
111 /* Initialize storage key device */
115 static void ccw_init(MachineState
*machine
)
118 VirtualCssBus
*css_bus
;
122 s390_memory_init(machine
->ram_size
);
125 css_bus
= virtual_css_bus_init();
126 s390_init_ipl_dev(machine
->kernel_filename
, machine
->kernel_cmdline
,
127 machine
->initrd_filename
, "s390-ccw.img", true);
130 dev
= qdev_create(NULL
, TYPE_S390_PCI_HOST_BRIDGE
);
131 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE
,
133 qdev_init_nofail(dev
);
135 /* register hypercalls */
136 virtio_ccw_register_hcalls();
139 s390_init_cpus(machine
->cpu_model
);
142 kvm_s390_enable_css_support(s390_cpu_addr2state(0));
145 * Create virtual css and set it as default so that non mcss-e
146 * enabled guests only see virtio devices.
148 ret
= css_create_css_image(VIRTUAL_CSSID
, true);
151 /* Create VirtIO network adapters */
152 s390_create_virtio_net(BUS(css_bus
), "virtio-net-ccw");
154 /* Register savevm handler for guest TOD clock */
155 register_savevm(NULL
, "todclock", 0, 1,
156 gtod_save
, gtod_load
, kvm_state
);
159 static void ccw_machine_class_init(ObjectClass
*oc
, void *data
)
161 MachineClass
*mc
= MACHINE_CLASS(oc
);
162 NMIClass
*nc
= NMI_CLASS(oc
);
165 mc
->reset
= s390_machine_reset
;
166 mc
->block_default_type
= IF_VIRTIO
;
174 nc
->nmi_monitor_handler
= s390_nmi
;
177 static inline bool machine_get_aes_key_wrap(Object
*obj
, Error
**errp
)
179 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
181 return ms
->aes_key_wrap
;
184 static inline void machine_set_aes_key_wrap(Object
*obj
, bool value
,
187 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
189 ms
->aes_key_wrap
= value
;
192 static inline bool machine_get_dea_key_wrap(Object
*obj
, Error
**errp
)
194 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
196 return ms
->dea_key_wrap
;
199 static inline void machine_set_dea_key_wrap(Object
*obj
, bool value
,
202 S390CcwMachineState
*ms
= S390_CCW_MACHINE(obj
);
204 ms
->dea_key_wrap
= value
;
207 static inline void s390_machine_initfn(Object
*obj
)
209 object_property_add_bool(obj
, "aes-key-wrap",
210 machine_get_aes_key_wrap
,
211 machine_set_aes_key_wrap
, NULL
);
212 object_property_set_description(obj
, "aes-key-wrap",
213 "enable/disable AES key wrapping using the CPACF wrapping key",
215 object_property_set_bool(obj
, true, "aes-key-wrap", NULL
);
217 object_property_add_bool(obj
, "dea-key-wrap",
218 machine_get_dea_key_wrap
,
219 machine_set_dea_key_wrap
, NULL
);
220 object_property_set_description(obj
, "dea-key-wrap",
221 "enable/disable DEA key wrapping using the CPACF wrapping key",
223 object_property_set_bool(obj
, true, "dea-key-wrap", NULL
);
226 static const TypeInfo ccw_machine_info
= {
227 .name
= TYPE_S390_CCW_MACHINE
,
228 .parent
= TYPE_MACHINE
,
230 .instance_size
= sizeof(S390CcwMachineState
),
231 .instance_init
= s390_machine_initfn
,
232 .class_init
= ccw_machine_class_init
,
233 .interfaces
= (InterfaceInfo
[]) {
239 #define CCW_COMPAT_2_4 \
242 .driver = TYPE_S390_SKEYS,\
243 .property = "migration-enabled",\
246 .driver = "virtio-blk-ccw",\
247 .property = "max_revision",\
250 .driver = "virtio-balloon-ccw",\
251 .property = "max_revision",\
254 .driver = "virtio-serial-ccw",\
255 .property = "max_revision",\
258 .driver = "virtio-9p-ccw",\
259 .property = "max_revision",\
262 .driver = "virtio-rng-ccw",\
263 .property = "max_revision",\
266 .driver = "virtio-net-ccw",\
267 .property = "max_revision",\
270 .driver = "virtio-scsi-ccw",\
271 .property = "max_revision",\
274 .driver = "vhost-scsi-ccw",\
275 .property = "max_revision",\
279 static void ccw_machine_2_4_class_init(ObjectClass
*oc
, void *data
)
281 MachineClass
*mc
= MACHINE_CLASS(oc
);
282 static GlobalProperty compat_props
[] = {
284 { /* end of list */ }
287 mc
->desc
= "VirtIO-ccw based S390 machine v2.4";
288 mc
->compat_props
= compat_props
;
291 static const TypeInfo ccw_machine_2_4_info
= {
292 .name
= MACHINE_TYPE_NAME("s390-ccw-virtio-2.4"),
293 .parent
= TYPE_S390_CCW_MACHINE
,
294 .class_init
= ccw_machine_2_4_class_init
,
297 static void ccw_machine_2_5_class_init(ObjectClass
*oc
, void *data
)
299 MachineClass
*mc
= MACHINE_CLASS(oc
);
301 mc
->alias
= "s390-ccw-virtio";
302 mc
->desc
= "VirtIO-ccw based S390 machine v2.5";
306 static const TypeInfo ccw_machine_2_5_info
= {
307 .name
= MACHINE_TYPE_NAME("s390-ccw-virtio-2.5"),
308 .parent
= TYPE_S390_CCW_MACHINE
,
309 .class_init
= ccw_machine_2_5_class_init
,
312 static void ccw_machine_register_types(void)
314 type_register_static(&ccw_machine_info
);
315 type_register_static(&ccw_machine_2_4_info
);
316 type_register_static(&ccw_machine_2_5_info
);
319 type_init(ccw_machine_register_types
)