]> git.proxmox.com Git - mirror_qemu.git/blame - hw/s390x/s390-virtio-ccw.c
i386: Add x-force-features option for testing
[mirror_qemu.git] / hw / s390x / s390-virtio-ccw.c
CommitLineData
a5c95808
CH
1/*
2 * virtio ccw machine
3 *
4 * Copyright 2012 IBM Corp.
6286b419 5 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
a5c95808
CH
6 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
10 * directory.
11 */
12
9615495a 13#include "qemu/osdep.h"
da34e65c 14#include "qapi/error.h"
4771d756 15#include "cpu.h"
a5c95808
CH
16#include "hw/boards.h"
17#include "exec/address-spaces.h"
9138977b 18#include "exec/ram_addr.h"
7d577546 19#include "hw/s390x/s390-virtio-hcall.h"
83c9f4ca 20#include "hw/s390x/sclp.h"
3a553fc6 21#include "hw/s390x/s390_flic.h"
bd3f16ac
PB
22#include "hw/s390x/ioinst.h"
23#include "hw/s390x/css.h"
a5c95808 24#include "virtio-ccw.h"
b6fe0124 25#include "qemu/config-file.h"
856dfd8a 26#include "qemu/ctype.h"
b5684cd8 27#include "qemu/error-report.h"
922a01a0 28#include "qemu/option.h"
8cba80c3 29#include "s390-pci-bus.h"
0f5f6691 30#include "hw/s390x/storage-keys.h"
903fd80b 31#include "hw/s390x/storage-attributes.h"
bc61c8c6 32#include "hw/s390x/event-facility.h"
04ca4b92 33#include "ipl.h"
8b8a61ad 34#include "hw/s390x/s390-virtio-ccw.h"
dd70bd0d 35#include "hw/s390x/css-bridge.h"
a51b3153 36#include "hw/s390x/ap-bridge.h"
f2a8f0a6 37#include "migration/register.h"
7223bcce 38#include "cpu_models.h"
6286b419 39#include "hw/nmi.h"
8046f374 40#include "hw/s390x/tod.h"
6286b419 41
6286b419
DH
42S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
43{
2b44178d
DH
44 static MachineState *ms;
45
46 if (!ms) {
47 ms = MACHINE(qdev_get_machine());
48 g_assert(ms->possible_cpus);
6286b419
DH
49 }
50
2b44178d
DH
51 /* CPU address corresponds to the core_id and the index */
52 if (cpu_addr >= ms->possible_cpus->len) {
53 return NULL;
54 }
55 return S390_CPU(ms->possible_cpus->cpus[cpu_addr].cpu);
6286b419
DH
56}
57
32dc6aa0
IM
58static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
59 Error **errp)
60{
61 S390CPU *cpu = S390_CPU(object_new(typename));
62 Error *err = NULL;
63
64 object_property_set_int(OBJECT(cpu), core_id, "core-id", &err);
65 if (err != NULL) {
66 goto out;
67 }
68 object_property_set_bool(OBJECT(cpu), true, "realized", &err);
69
70out:
71 object_unref(OBJECT(cpu));
72 if (err) {
73 error_propagate(errp, err);
74 cpu = NULL;
75 }
76 return cpu;
77}
78
6286b419
DH
79static void s390_init_cpus(MachineState *machine)
80{
4dc3b151 81 MachineClass *mc = MACHINE_GET_CLASS(machine);
6286b419 82 int i;
6286b419 83
4dc3b151
DH
84 /* initialize possible_cpus */
85 mc->possible_cpu_arch_ids(machine);
86
ae71ed86 87 for (i = 0; i < machine->smp.cpus; i++) {
b6805e12 88 s390x_new_cpu(machine->cpu_type, i, &error_fatal);
6286b419
DH
89 }
90}
2eb1cd07 91
09c7f58c 92static const char *const reset_dev_types[] = {
3f9e4859 93 TYPE_VIRTUAL_CSS_BRIDGE,
09c7f58c
DH
94 "s390-sclp-event-facility",
95 "s390-flic",
96 "diag288",
97};
98
a30fb811 99static void subsystem_reset(void)
4e872a3f 100{
09c7f58c
DH
101 DeviceState *dev;
102 int i;
4e872a3f 103
09c7f58c
DH
104 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
105 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
106 if (dev) {
107 qdev_reset_all(dev);
108 }
0c7322cf 109 }
4e872a3f
CB
110}
111
a5c95808
CH
112static int virtio_ccw_hcall_notify(const uint64_t *args)
113{
114 uint64_t subch_id = args[0];
115 uint64_t queue = args[1];
116 SubchDev *sch;
117 int cssid, ssid, schid, m;
118
119 if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) {
120 return -EINVAL;
121 }
122 sch = css_find_subch(m, cssid, ssid, schid);
123 if (!sch || !css_subch_visible(sch)) {
124 return -EINVAL;
125 }
b1914b82 126 if (queue >= VIRTIO_QUEUE_MAX) {
b57ed9bf
CH
127 return -EINVAL;
128 }
a5c95808
CH
129 virtio_queue_notify(virtio_ccw_get_vdev(sch), queue);
130 return 0;
131
132}
133
134static int virtio_ccw_hcall_early_printk(const uint64_t *args)
135{
136 uint64_t mem = args[0];
137
138 if (mem < ram_size) {
139 /* Early printk */
140 return 0;
141 }
142 return -EINVAL;
143}
144
145static void virtio_ccw_register_hcalls(void)
146{
147 s390_register_virtio_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY,
148 virtio_ccw_hcall_notify);
149 /* Tolerate early printk. */
150 s390_register_virtio_hypercall(KVM_S390_VIRTIO_NOTIFY,
151 virtio_ccw_hcall_early_printk);
152}
153
bb223055
CB
154/*
155 * KVM does only support memory slots up to KVM_MEM_MAX_NR_PAGES pages
156 * as the dirty bitmap must be managed by bitops that take an int as
157 * position indicator. If we have a guest beyond that we will split off
158 * new subregions. The split must happen on a segment boundary (1MB).
159 */
160#define KVM_MEM_MAX_NR_PAGES ((1ULL << 31) - 1)
161#define SEG_MSK (~0xfffffULL)
162#define KVM_SLOT_MAX_BYTES ((KVM_MEM_MAX_NR_PAGES * TARGET_PAGE_SIZE) & SEG_MSK)
6286b419 163static void s390_memory_init(ram_addr_t mem_size)
a5c95808 164{
a5c95808 165 MemoryRegion *sysmem = get_system_memory();
bb223055
CB
166 ram_addr_t chunk, offset = 0;
167 unsigned int number = 0;
9138977b 168 Error *local_err = NULL;
bb223055 169 gchar *name;
80d23275
DH
170
171 /* allocate RAM for core */
bb223055
CB
172 name = g_strdup_printf("s390.ram");
173 while (mem_size) {
174 MemoryRegion *ram = g_new(MemoryRegion, 1);
175 uint64_t size = mem_size;
176
177 /* KVM does not allow memslots >= 8 TB */
178 chunk = MIN(size, KVM_SLOT_MAX_BYTES);
179 memory_region_allocate_system_memory(ram, NULL, name, chunk);
180 memory_region_add_subregion(sysmem, offset, ram);
181 mem_size -= chunk;
182 offset += chunk;
183 g_free(name);
184 name = g_strdup_printf("s390.ram.%u", ++number);
185 }
186 g_free(name);
80d23275 187
9138977b
DH
188 /*
189 * Configure the maximum page size. As no memory devices were created
190 * yet, this is the page size of initial memory only.
191 */
905b7ee4 192 s390_set_max_pagesize(qemu_maxrampagesize(), &local_err);
9138977b
DH
193 if (local_err) {
194 error_report_err(local_err);
195 exit(EXIT_FAILURE);
196 }
80d23275
DH
197 /* Initialize storage key device */
198 s390_skeys_init();
903fd80b
CI
199 /* Initialize storage attributes device */
200 s390_stattrib_init();
80d23275
DH
201}
202
6286b419
DH
203static void s390_init_ipl_dev(const char *kernel_filename,
204 const char *kernel_cmdline,
205 const char *initrd_filename, const char *firmware,
206 const char *netboot_fw, bool enforce_bios)
207{
208 Object *new = object_new(TYPE_S390_IPL);
209 DeviceState *dev = DEVICE(new);
d9b06db8 210 char *netboot_fw_prop;
6286b419
DH
211
212 if (kernel_filename) {
213 qdev_prop_set_string(dev, "kernel", kernel_filename);
214 }
215 if (initrd_filename) {
216 qdev_prop_set_string(dev, "initrd", initrd_filename);
217 }
218 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
219 qdev_prop_set_string(dev, "firmware", firmware);
6286b419 220 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
d9b06db8
GK
221 netboot_fw_prop = object_property_get_str(new, "netboot_fw", &error_abort);
222 if (!strlen(netboot_fw_prop)) {
3c4e9baa
TH
223 qdev_prop_set_string(dev, "netboot_fw", netboot_fw);
224 }
d9b06db8 225 g_free(netboot_fw_prop);
6286b419
DH
226 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
227 new, NULL);
228 object_unref(new);
229 qdev_init_nofail(dev);
230}
231
232static void s390_create_virtio_net(BusState *bus, const char *name)
233{
234 int i;
235
236 for (i = 0; i < nb_nics; i++) {
237 NICInfo *nd = &nd_table[i];
238 DeviceState *dev;
239
240 if (!nd->model) {
241 nd->model = g_strdup("virtio");
242 }
243
244 qemu_check_nic_model(nd, "virtio");
245
246 dev = qdev_create(bus, name);
247 qdev_set_nic_properties(dev, nd);
248 qdev_init_nofail(dev);
249 }
250}
251
052888f0
TH
252static void s390_create_sclpconsole(const char *type, Chardev *chardev)
253{
254 DeviceState *dev;
255
256 dev = qdev_create(sclp_get_event_facility_bus(), type);
257 qdev_prop_set_chr(dev, "chardev", chardev);
258 qdev_init_nofail(dev);
259}
260
80d23275
DH
261static void ccw_init(MachineState *machine)
262{
a5c95808
CH
263 int ret;
264 VirtualCssBus *css_bus;
c1843e20 265 DeviceState *dev;
b6fe0124 266
1cf065fb 267 s390_sclp_init();
9138977b 268 /* init memory + setup max page size. Required for the CPU model */
80d23275 269 s390_memory_init(machine->ram_size);
a5c95808 270
d32bd032 271 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
3720d335
YMZ
272 s390_init_cpus(machine);
273
c572d3f3
FL
274 s390_flic_init();
275
74b4c74d
DH
276 /* init the SIGP facility */
277 s390_init_sigp();
278
a51b3153
TK
279 /* create AP bridge and bus(es) */
280 s390_init_ap();
281
a5c95808
CH
282 /* get a BUS */
283 css_bus = virtual_css_bus_init();
3ef96221 284 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
5f31ade0
FA
285 machine->initrd_filename, "s390-ccw.img",
286 "s390-netboot.img", true);
a5c95808 287
c1843e20
CB
288 dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE);
289 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
290 OBJECT(dev), NULL);
291 qdev_init_nofail(dev);
8cba80c3 292
a5c95808
CH
293 /* register hypercalls */
294 virtio_ccw_register_hcalls();
295
5e7164c5 296 s390_enable_css_support(s390_cpu_addr2state(0));
36699ab4
CH
297
298 ret = css_create_css_image(VIRTUAL_CSSID, true);
d69969e5 299
a5c95808 300 assert(ret == 0);
489c909f
HP
301 if (css_migration_enabled()) {
302 css_register_vmstate();
303 }
a5c95808
CH
304
305 /* Create VirtIO network adapters */
306 s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw");
3f9e59bb 307
052888f0
TH
308 /* init consoles */
309 if (serial_hd(0)) {
310 s390_create_sclpconsole("sclpconsole", serial_hd(0));
311 }
312 if (serial_hd(1)) {
313 s390_create_sclpconsole("sclplmconsole", serial_hd(1));
314 }
315
8046f374
DH
316 /* init the TOD clock */
317 s390_init_tod();
a5c95808
CH
318}
319
502edbf8
MR
320static void s390_cpu_plug(HotplugHandler *hotplug_dev,
321 DeviceState *dev, Error **errp)
322{
4dc3b151 323 MachineState *ms = MACHINE(hotplug_dev);
502edbf8 324 S390CPU *cpu = S390_CPU(dev);
4dc3b151
DH
325
326 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
327 ms->possible_cpus->cpus[cpu->env.core_id].cpu = OBJECT(dev);
c5b93430
DH
328
329 if (dev->hotplugged) {
330 raise_irq_cpu_hotplug();
331 }
502edbf8
MR
332}
333
a30fb811
DH
334static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
335{
336 S390CPU *cpu = S390_CPU(cs);
337
338 s390_ipl_prepare_cpu(cpu);
339 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
340}
341
a0628599 342static void s390_machine_reset(MachineState *machine)
6286b419 343{
a30fb811
DH
344 enum s390_reset reset_type;
345 CPUState *cs, *t;
6286b419 346
a30fb811
DH
347 /* get the reset parameters, reset them once done */
348 s390_ipl_get_reset_request(&cs, &reset_type);
349
350 /* all CPUs are paused and synchronized at this point */
6286b419 351 s390_cmma_reset();
6286b419 352
a30fb811
DH
353 switch (reset_type) {
354 case S390_RESET_EXTERNAL:
355 case S390_RESET_REIPL:
356 qemu_devices_reset();
357 s390_crypto_reset();
358
359 /* configure and start the ipl CPU only */
360 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
361 break;
362 case S390_RESET_MODIFIED_CLEAR:
363 CPU_FOREACH(t) {
364 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
365 }
366 subsystem_reset();
367 s390_crypto_reset();
368 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
369 break;
370 case S390_RESET_LOAD_NORMAL:
371 CPU_FOREACH(t) {
372 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
373 }
374 subsystem_reset();
375 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
376 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
377 break;
378 default:
379 g_assert_not_reached();
380 }
381 s390_ipl_clear_reset_request();
6286b419
DH
382}
383
502edbf8
MR
384static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
385 DeviceState *dev, Error **errp)
386{
387 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
388 s390_cpu_plug(hotplug_dev, dev, errp);
389 }
390}
391
f2f3beb0
DH
392static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
393 DeviceState *dev, Error **errp)
394{
395 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
396 error_setg(errp, "CPU hot unplug not supported on this machine");
397 return;
398 }
399}
400
81ce6aa5 401static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
4dc3b151
DH
402 unsigned cpu_index)
403{
81ce6aa5
DH
404 MachineClass *mc = MACHINE_GET_CLASS(ms);
405 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
4dc3b151 406
81ce6aa5
DH
407 assert(cpu_index < possible_cpus->len);
408 return possible_cpus->cpus[cpu_index].props;
4dc3b151
DH
409}
410
411static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
412{
413 int i;
ae71ed86 414 unsigned int max_cpus = ms->smp.max_cpus;
4dc3b151
DH
415
416 if (ms->possible_cpus) {
417 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
418 return ms->possible_cpus;
419 }
420
421 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
422 sizeof(CPUArchId) * max_cpus);
423 ms->possible_cpus->len = max_cpus;
424 for (i = 0; i < ms->possible_cpus->len; i++) {
d342eb76 425 ms->possible_cpus->cpus[i].type = ms->cpu_type;
4dc3b151
DH
426 ms->possible_cpus->cpus[i].vcpus_count = 1;
427 ms->possible_cpus->cpus[i].arch_id = i;
428 ms->possible_cpus->cpus[i].props.has_core_id = true;
429 ms->possible_cpus->cpus[i].props.core_id = i;
430 }
431
432 return ms->possible_cpus;
433}
434
502edbf8
MR
435static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
436 DeviceState *dev)
437{
438 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
439 return HOTPLUG_HANDLER(machine);
440 }
441 return NULL;
442}
443
a0628599
LX
444static void s390_hot_add_cpu(MachineState *machine,
445 const int64_t id, Error **errp)
a006b67f 446{
524d18d8
DH
447 ObjectClass *oc;
448
449 g_assert(machine->possible_cpus->cpus[0].cpu);
450 oc = OBJECT_CLASS(CPU_GET_CLASS(machine->possible_cpus->cpus[0].cpu));
a006b67f 451
524d18d8 452 s390x_new_cpu(object_class_get_name(oc), id, errp);
a006b67f
MR
453}
454
6286b419
DH
455static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
456{
457 CPUState *cs = qemu_get_cpu(cpu_index);
458
0fc60ca5 459 s390_cpu_restart(S390_CPU(cs));
6286b419
DH
460}
461
d07aa7c7
AK
462static void ccw_machine_class_init(ObjectClass *oc, void *data)
463{
464 MachineClass *mc = MACHINE_CLASS(oc);
3dd7852f 465 NMIClass *nc = NMI_CLASS(oc);
502edbf8 466 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
9700230b 467 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
d07aa7c7 468
9700230b 469 s390mc->ri_allowed = true;
e73316d5 470 s390mc->cpu_model_allowed = true;
e996583e 471 s390mc->css_migration_enabled = true;
28221f9c 472 s390mc->hpage_1m_allowed = true;
d07aa7c7 473 mc->init = ccw_init;
db3b2566 474 mc->reset = s390_machine_reset;
a006b67f 475 mc->hot_add_cpu = s390_hot_add_cpu;
d07aa7c7
AK
476 mc->block_default_type = IF_VIRTIO;
477 mc->no_cdrom = 1;
478 mc->no_floppy = 1;
d07aa7c7
AK
479 mc->no_parallel = 1;
480 mc->no_sdcard = 1;
f42dc44a 481 mc->max_cpus = S390_MAX_CPUS;
4dc3b151 482 mc->has_hotpluggable_cpus = true;
debbdc00 483 assert(!mc->get_hotplug_handler);
502edbf8 484 mc->get_hotplug_handler = s390_get_hotplug_handler;
4dc3b151
DH
485 mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
486 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
b6805e12
IM
487 /* it is overridden with 'host' cpu *in kvm_arch_init* */
488 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
502edbf8 489 hc->plug = s390_machine_device_plug;
f2f3beb0 490 hc->unplug_request = s390_machine_device_unplug_request;
3dd7852f 491 nc->nmi_monitor_handler = s390_nmi;
d07aa7c7
AK
492}
493
2eb1cd07
TK
494static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
495{
496 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
497
498 return ms->aes_key_wrap;
499}
500
501static inline void machine_set_aes_key_wrap(Object *obj, bool value,
502 Error **errp)
503{
504 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
505
506 ms->aes_key_wrap = value;
507}
508
509static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
510{
511 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
512
513 return ms->dea_key_wrap;
514}
515
516static inline void machine_set_dea_key_wrap(Object *obj, bool value,
517 Error **errp)
518{
519 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
520
521 ms->dea_key_wrap = value;
522}
523
cec8bbf7 524static S390CcwMachineClass *current_mc;
9700230b 525
cec8bbf7
HP
526static S390CcwMachineClass *get_machine_class(void)
527{
528 if (unlikely(!current_mc)) {
392529cb 529 /*
cec8bbf7
HP
530 * No s390 ccw machine was instantiated, we are likely to
531 * be called for the 'none' machine. The properties will
532 * have their after-initialization values.
533 */
534 current_mc = S390_MACHINE_CLASS(
535 object_class_by_name(TYPE_S390_CCW_MACHINE));
9700230b 536 }
cec8bbf7 537 return current_mc;
9700230b
FZ
538}
539
cec8bbf7 540bool ri_allowed(void)
e73316d5 541{
cec8bbf7
HP
542 /* for "none" machine this results in true */
543 return get_machine_class()->ri_allowed;
544}
545
546bool cpu_model_allowed(void)
547{
548 /* for "none" machine this results in true */
549 return get_machine_class()->cpu_model_allowed;
e73316d5
CB
550}
551
28221f9c
JF
552bool hpage_1m_allowed(void)
553{
554 /* for "none" machine this results in true */
555 return get_machine_class()->hpage_1m_allowed;
556}
557
7104bae9
FA
558static char *machine_get_loadparm(Object *obj, Error **errp)
559{
560 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
561
562 return g_memdup(ms->loadparm, sizeof(ms->loadparm));
563}
564
565static void machine_set_loadparm(Object *obj, const char *val, Error **errp)
566{
567 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
568 int i;
569
570 for (i = 0; i < sizeof(ms->loadparm) && val[i]; i++) {
95a5befc 571 uint8_t c = qemu_toupper(val[i]); /* mimic HMC */
7104bae9
FA
572
573 if (('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '.') ||
574 (c == ' ')) {
575 ms->loadparm[i] = c;
576 } else {
577 error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%02x)",
578 c, c);
579 return;
580 }
581 }
582
583 for (; i < sizeof(ms->loadparm); i++) {
584 ms->loadparm[i] = ' '; /* pad right with spaces */
585 }
586}
2eb1cd07
TK
587static inline void s390_machine_initfn(Object *obj)
588{
589 object_property_add_bool(obj, "aes-key-wrap",
590 machine_get_aes_key_wrap,
591 machine_set_aes_key_wrap, NULL);
592 object_property_set_description(obj, "aes-key-wrap",
593 "enable/disable AES key wrapping using the CPACF wrapping key",
594 NULL);
595 object_property_set_bool(obj, true, "aes-key-wrap", NULL);
596
597 object_property_add_bool(obj, "dea-key-wrap",
598 machine_get_dea_key_wrap,
599 machine_set_dea_key_wrap, NULL);
600 object_property_set_description(obj, "dea-key-wrap",
601 "enable/disable DEA key wrapping using the CPACF wrapping key",
602 NULL);
603 object_property_set_bool(obj, true, "dea-key-wrap", NULL);
7104bae9
FA
604 object_property_add_str(obj, "loadparm",
605 machine_get_loadparm, machine_set_loadparm, NULL);
606 object_property_set_description(obj, "loadparm",
607 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
608 " to upper case) to pass to machine loader, boot manager,"
609 " and guest kernel",
610 NULL);
2eb1cd07
TK
611}
612
d07aa7c7
AK
613static const TypeInfo ccw_machine_info = {
614 .name = TYPE_S390_CCW_MACHINE,
615 .parent = TYPE_MACHINE,
c4d3c0a2 616 .abstract = true,
2eb1cd07
TK
617 .instance_size = sizeof(S390CcwMachineState),
618 .instance_init = s390_machine_initfn,
9700230b 619 .class_size = sizeof(S390CcwMachineClass),
d07aa7c7 620 .class_init = ccw_machine_class_init,
3dd7852f
AK
621 .interfaces = (InterfaceInfo[]) {
622 { TYPE_NMI },
502edbf8 623 { TYPE_HOTPLUG_HANDLER},
3dd7852f
AK
624 { }
625 },
a5c95808
CH
626};
627
52629b3b
HP
628bool css_migration_enabled(void)
629{
630 return get_machine_class()->css_migration_enabled;
631}
632
4fca6548
JF
633#define DEFINE_CCW_MACHINE(suffix, verstr, latest) \
634 static void ccw_machine_##suffix##_class_init(ObjectClass *oc, \
635 void *data) \
636 { \
637 MachineClass *mc = MACHINE_CLASS(oc); \
638 ccw_machine_##suffix##_class_options(mc); \
639 mc->desc = "VirtIO-ccw based S390 machine v" verstr; \
640 if (latest) { \
641 mc->alias = "s390-ccw-virtio"; \
642 mc->is_default = 1; \
643 } \
644 } \
645 static void ccw_machine_##suffix##_instance_init(Object *obj) \
646 { \
647 MachineState *machine = MACHINE(obj); \
cec8bbf7 648 current_mc = S390_MACHINE_CLASS(MACHINE_GET_CLASS(machine)); \
4fca6548
JF
649 ccw_machine_##suffix##_instance_options(machine); \
650 } \
651 static const TypeInfo ccw_machine_##suffix##_info = { \
652 .name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
653 .parent = TYPE_S390_CCW_MACHINE, \
654 .class_init = ccw_machine_##suffix##_class_init, \
655 .instance_init = ccw_machine_##suffix##_instance_init, \
656 }; \
657 static void ccw_machine_register_##suffix(void) \
658 { \
659 type_register_static(&ccw_machine_##suffix##_info); \
660 } \
0e6aac87 661 type_init(ccw_machine_register_##suffix)
4fca6548 662
9bf2650b
CH
663static void ccw_machine_4_1_instance_options(MachineState *machine)
664{
665}
666
667static void ccw_machine_4_1_class_options(MachineClass *mc)
668{
669}
670DEFINE_CCW_MACHINE(4_1, "4.1", true);
671
8c7b0c73
CH
672static void ccw_machine_4_0_instance_options(MachineState *machine)
673{
08ef92d5 674 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
9bf2650b 675 ccw_machine_4_1_instance_options(machine);
08ef92d5 676 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
8c7b0c73
CH
677}
678
679static void ccw_machine_4_0_class_options(MachineClass *mc)
680{
9bf2650b
CH
681 ccw_machine_4_1_class_options(mc);
682 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
8c7b0c73 683}
9bf2650b 684DEFINE_CCW_MACHINE(4_0, "4.0", false);
8c7b0c73 685
9ca056d6
CH
686static void ccw_machine_3_1_instance_options(MachineState *machine)
687{
d646b16b 688 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
8c7b0c73 689 ccw_machine_4_0_instance_options(machine);
84176c79
CW
690 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
691 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
d646b16b 692 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
9ca056d6
CH
693}
694
695static void ccw_machine_3_1_class_options(MachineClass *mc)
696{
8c7b0c73 697 ccw_machine_4_0_class_options(mc);
abd93cc7 698 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
9ca056d6 699}
8c7b0c73 700DEFINE_CCW_MACHINE(3_1, "3.1", false);
9ca056d6 701
2c5a2eef 702static void ccw_machine_3_0_instance_options(MachineState *machine)
7a9cb3ad 703{
9ca056d6 704 ccw_machine_3_1_instance_options(machine);
7a9cb3ad
CH
705}
706
2c5a2eef 707static void ccw_machine_3_0_class_options(MachineClass *mc)
7a9cb3ad 708{
28221f9c
JF
709 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
710
711 s390mc->hpage_1m_allowed = false;
9ca056d6 712 ccw_machine_3_1_class_options(mc);
ddb3235d 713 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
7a9cb3ad 714}
9ca056d6 715DEFINE_CCW_MACHINE(3_0, "3.0", false);
7a9cb3ad 716
67ee0cef
CH
717static void ccw_machine_2_12_instance_options(MachineState *machine)
718{
2c5a2eef 719 ccw_machine_3_0_instance_options(machine);
87273151
CB
720 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
721 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
67ee0cef
CH
722}
723
724static void ccw_machine_2_12_class_options(MachineClass *mc)
725{
2c5a2eef 726 ccw_machine_3_0_class_options(mc);
0d47310b 727 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
67ee0cef 728}
7a9cb3ad 729DEFINE_CCW_MACHINE(2_12, "2.12", false);
67ee0cef 730
70d8d9a0
CH
731static void ccw_machine_2_11_instance_options(MachineState *machine)
732{
35b4df64 733 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
67ee0cef 734 ccw_machine_2_12_instance_options(machine);
35b4df64
DH
735
736 /* before 2.12 we emulated the very first z900 */
737 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
70d8d9a0
CH
738}
739
740static void ccw_machine_2_11_class_options(MachineClass *mc)
741{
88cbe073 742 static GlobalProperty compat[] = {
6c36bddf 743 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
88cbe073
MAL
744 };
745
67ee0cef 746 ccw_machine_2_12_class_options(mc);
43df70a9 747 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
88cbe073 748 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
70d8d9a0 749}
67ee0cef 750DEFINE_CCW_MACHINE(2_11, "2.11", false);
70d8d9a0 751
10890873
CH
752static void ccw_machine_2_10_instance_options(MachineState *machine)
753{
70d8d9a0 754 ccw_machine_2_11_instance_options(machine);
10890873
CH
755}
756
757static void ccw_machine_2_10_class_options(MachineClass *mc)
758{
70d8d9a0 759 ccw_machine_2_11_class_options(mc);
503224f4 760 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
10890873 761}
70d8d9a0 762DEFINE_CCW_MACHINE(2_10, "2.10", false);
10890873 763
113725a6
CH
764static void ccw_machine_2_9_instance_options(MachineState *machine)
765{
10890873 766 ccw_machine_2_10_instance_options(machine);
7223bcce
JH
767 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
768 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
3b00f702
YMZ
769 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
770 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
771 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
113725a6
CH
772}
773
774static void ccw_machine_2_9_class_options(MachineClass *mc)
775{
52629b3b 776 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
88cbe073 777 static GlobalProperty compat[] = {
6c36bddf 778 { TYPE_S390_STATTRIB, "migration-enabled", "off", },
88cbe073 779 };
52629b3b 780
10890873 781 ccw_machine_2_10_class_options(mc);
3e803152 782 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
88cbe073 783 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
52629b3b 784 s390mc->css_migration_enabled = false;
113725a6 785}
10890873 786DEFINE_CCW_MACHINE(2_9, "2.9", false);
113725a6 787
61823988
CH
788static void ccw_machine_2_8_instance_options(MachineState *machine)
789{
113725a6 790 ccw_machine_2_9_instance_options(machine);
61823988
CH
791}
792
793static void ccw_machine_2_8_class_options(MachineClass *mc)
794{
88cbe073 795 static GlobalProperty compat[] = {
6c36bddf 796 { TYPE_S390_FLIC_COMMON, "adapter_routes_max_batch", "64", },
88cbe073
MAL
797 };
798
113725a6 799 ccw_machine_2_9_class_options(mc);
edc24ccd 800 compat_props_add(mc->compat_props, hw_compat_2_8, hw_compat_2_8_len);
88cbe073 801 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
61823988 802}
113725a6 803DEFINE_CCW_MACHINE(2_8, "2.8", false);
61823988 804
946e55f3
CH
805static void ccw_machine_2_7_instance_options(MachineState *machine)
806{
61823988 807 ccw_machine_2_8_instance_options(machine);
946e55f3
CH
808}
809
810static void ccw_machine_2_7_class_options(MachineClass *mc)
811{
e73316d5
CB
812 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
813
814 s390mc->cpu_model_allowed = false;
61823988 815 ccw_machine_2_8_class_options(mc);
5a995064 816 compat_props_add(mc->compat_props, hw_compat_2_7, hw_compat_2_7_len);
946e55f3 817}
61823988 818DEFINE_CCW_MACHINE(2_7, "2.7", false);
946e55f3 819
4fca6548 820static void ccw_machine_2_6_instance_options(MachineState *machine)
c4d3c0a2 821{
946e55f3 822 ccw_machine_2_7_instance_options(machine);
c4d3c0a2
CB
823}
824
4fca6548 825static void ccw_machine_2_6_class_options(MachineClass *mc)
84b48ad6 826{
9700230b 827 S390CcwMachineClass *s390mc = S390_MACHINE_CLASS(mc);
88cbe073 828 static GlobalProperty compat[] = {
6c36bddf
EH
829 { TYPE_S390_IPL, "iplbext_migration", "off", },
830 { TYPE_VIRTUAL_CSS_BRIDGE, "css_dev_path", "off", },
88cbe073 831 };
9700230b
FZ
832
833 s390mc->ri_allowed = false;
946e55f3 834 ccw_machine_2_7_class_options(mc);
ff8f261f 835 compat_props_add(mc->compat_props, hw_compat_2_6, hw_compat_2_6_len);
88cbe073 836 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
84b48ad6 837}
946e55f3 838DEFINE_CCW_MACHINE(2_6, "2.6", false);
84b48ad6 839
4fca6548
JF
840static void ccw_machine_2_5_instance_options(MachineState *machine)
841{
946e55f3 842 ccw_machine_2_6_instance_options(machine);
4fca6548 843}
84b48ad6 844
4fca6548 845static void ccw_machine_2_5_class_options(MachineClass *mc)
b21b7598 846{
946e55f3 847 ccw_machine_2_6_class_options(mc);
fe759610 848 compat_props_add(mc->compat_props, hw_compat_2_5, hw_compat_2_5_len);
4fca6548
JF
849}
850DEFINE_CCW_MACHINE(2_5, "2.5", false);
b21b7598 851
4fca6548
JF
852static void ccw_machine_2_4_instance_options(MachineState *machine)
853{
854 ccw_machine_2_5_instance_options(machine);
b21b7598
CH
855}
856
4fca6548
JF
857static void ccw_machine_2_4_class_options(MachineClass *mc)
858{
88cbe073 859 static GlobalProperty compat[] = {
6c36bddf
EH
860 { TYPE_S390_SKEYS, "migration-enabled", "off", },
861 { "virtio-blk-ccw", "max_revision", "0", },
862 { "virtio-balloon-ccw", "max_revision", "0", },
863 { "virtio-serial-ccw", "max_revision", "0", },
864 { "virtio-9p-ccw", "max_revision", "0", },
865 { "virtio-rng-ccw", "max_revision", "0", },
866 { "virtio-net-ccw", "max_revision", "0", },
867 { "virtio-scsi-ccw", "max_revision", "0", },
868 { "vhost-scsi-ccw", "max_revision", "0", },
88cbe073
MAL
869 };
870
946e55f3 871 ccw_machine_2_5_class_options(mc);
2f99b9c2 872 compat_props_add(mc->compat_props, hw_compat_2_4, hw_compat_2_4_len);
88cbe073 873 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
4fca6548
JF
874}
875DEFINE_CCW_MACHINE(2_4, "2.4", false);
b21b7598 876
d07aa7c7 877static void ccw_machine_register_types(void)
a5c95808 878{
d07aa7c7 879 type_register_static(&ccw_machine_info);
a5c95808
CH
880}
881
d07aa7c7 882type_init(ccw_machine_register_types)