1 /*
2 * virtio ccw machine
3 *
4 * Copyright 2012, 2020 IBM Corp.
5 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
6 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
7 * Janosch Frank <frankja@linux.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or (at
10 * your option) any later version. See the COPYING file in the top-level
11 * directory.
12 */
13
14 #include "qemu/osdep.h"
15 #include "qapi/error.h"
16 #include "exec/ram_addr.h"
17 #include "system/confidential-guest-support.h"
18 #include "hw/boards.h"
19 #include "hw/s390x/sclp.h"
20 #include "hw/s390x/s390_flic.h"
21 #include "virtio-ccw.h"
22 #include "qemu/config-file.h"
23 #include "qemu/ctype.h"
24 #include "qemu/error-report.h"
25 #include "qemu/option.h"
26 #include "qemu/qemu-print.h"
27 #include "qemu/units.h"
28 #include "hw/s390x/s390-pci-bus.h"
29 #include "system/reset.h"
30 #include "hw/s390x/storage-keys.h"
31 #include "hw/s390x/storage-attributes.h"
32 #include "hw/s390x/event-facility.h"
33 #include "ipl.h"
34 #include "hw/s390x/s390-virtio-ccw.h"
35 #include "hw/s390x/css-bridge.h"
36 #include "hw/s390x/ap-bridge.h"
37 #include "migration/register.h"
38 #include "cpu_models.h"
39 #include "hw/nmi.h"
40 #include "hw/qdev-properties.h"
41 #include "hw/s390x/tod.h"
42 #include "system/system.h"
43 #include "system/cpus.h"
44 #include "system/hostmem.h"
45 #include "target/s390x/kvm/pv.h"
46 #include "migration/blocker.h"
47 #include "qapi/visitor.h"
48 #include "hw/s390x/cpu-topology.h"
49 #include "kvm/kvm_s390x.h"
50 #include "hw/virtio/virtio-md-pci.h"
51 #include "hw/s390x/virtio-ccw-md.h"
52 #include "system/replay.h"
53 #include CONFIG_DEVICES
54
55 static Error *pv_mig_blocker;
56
s390x_new_cpu(const char * typename,uint32_t core_id,Error ** errp)57 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
58 Error **errp)
59 {
60 S390CPU *cpu = S390_CPU(object_new(typename));
61 S390CPU *ret = NULL;
62
63 if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) {
64 goto out;
65 }
66 if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
67 goto out;
68 }
69 ret = cpu;
70
71 out:
72 object_unref(OBJECT(cpu));
73 return ret;
74 }
75
s390_init_cpus(MachineState * machine)76 static void s390_init_cpus(MachineState *machine)
77 {
78 MachineClass *mc = MACHINE_GET_CLASS(machine);
79 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
80 int i;
81
82 if (machine->smp.threads > s390mc->max_threads) {
83 error_report("S390 does not support more than %d threads.",
84 s390mc->max_threads);
85 exit(1);
86 }
87
88 /* initialize possible_cpus */
89 mc->possible_cpu_arch_ids(machine);
90
91 for (i = 0; i < machine->smp.cpus; i++) {
92 s390x_new_cpu(machine->cpu_type, i, &error_fatal);
93 }
94 }
95
96 static const char *const reset_dev_types[] = {
97 TYPE_VIRTUAL_CSS_BRIDGE,
98 "s390-sclp-event-facility",
99 "s390-flic",
100 "diag288",
101 TYPE_S390_PCI_HOST_BRIDGE,
102 TYPE_AP_BRIDGE,
103 };
104
subsystem_reset(void)105 static void subsystem_reset(void)
106 {
107 DeviceState *dev;
108 int i;
109
110 /*
111 * ISM firmware is sensitive to unexpected changes to the IOMMU, which can
112 * occur during reset of the vfio-pci device (unmap of entire aperture).
113 * Ensure any passthrough ISM devices are reset now, while CPUs are paused
114 * but before vfio-pci cleanup occurs.
115 */
116 s390_pci_ism_reset();
117
118 for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) {
119 dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL));
120 if (dev) {
121 device_cold_reset(dev);
122 }
123 }
124 if (s390_has_topology()) {
125 s390_topology_reset();
126 }
127 }
128
s390_set_memory_limit(S390CcwMachineState * s390ms,uint64_t new_limit)129 static void s390_set_memory_limit(S390CcwMachineState *s390ms,
130 uint64_t new_limit)
131 {
132 uint64_t hw_limit = 0;
133 int ret = 0;
134
135 assert(!s390ms->memory_limit && new_limit);
136 if (kvm_enabled()) {
137 ret = kvm_s390_set_mem_limit(new_limit, &hw_limit);
138 }
139 if (ret == -E2BIG) {
140 error_report("host supports a maximum of %" PRIu64 " GB",
141 hw_limit / GiB);
142 exit(EXIT_FAILURE);
143 } else if (ret) {
144 error_report("setting the guest size failed");
145 exit(EXIT_FAILURE);
146 }
147 s390ms->memory_limit = new_limit;
148 }
149
s390_set_max_pagesize(S390CcwMachineState * s390ms,uint64_t pagesize)150 static void s390_set_max_pagesize(S390CcwMachineState *s390ms,
151 uint64_t pagesize)
152 {
153 assert(!s390ms->max_pagesize && pagesize);
154 if (kvm_enabled()) {
155 kvm_s390_set_max_pagesize(pagesize, &error_fatal);
156 }
157 s390ms->max_pagesize = pagesize;
158 }
159
s390_memory_init(MachineState * machine)160 static void s390_memory_init(MachineState *machine)
161 {
162 S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine);
163 MemoryRegion *sysmem = get_system_memory();
164 MemoryRegion *ram = machine->ram;
165 uint64_t ram_size = memory_region_size(ram);
166 uint64_t devmem_base, devmem_size;
167
168 if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) {
169 /*
170 * SCLP cannot possibly expose smaller granularity right now and KVM
171 * cannot handle smaller granularity. As we don't support NUMA, the
172 * region size directly corresponds to machine->ram_size, and the region
173 * is a single RAM memory region.
174 */
175 error_report("ram size must be multiples of 1 MiB");
176 exit(EXIT_FAILURE);
177 }
178
179 devmem_size = 0;
180 devmem_base = ram_size;
181 #ifdef CONFIG_MEM_DEVICE
182 if (machine->ram_size < machine->maxram_size) {
183
184 /*
185 * Make sure memory devices have a sane default alignment, even
186 * when weird initial memory sizes are specified.
187 */
188 devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB);
189 devmem_size = machine->maxram_size - machine->ram_size;
190 }
191 #endif
192 s390_set_memory_limit(s390ms, devmem_base + devmem_size);
193
194 /* Map the initial memory. Must happen after setting the memory limit. */
195 memory_region_add_subregion(sysmem, 0, ram);
196
197 /* Initialize address space for memory devices. */
198 #ifdef CONFIG_MEM_DEVICE
199 if (devmem_size) {
200 machine_memory_devices_init(machine, devmem_base, devmem_size);
201 }
202 #endif /* CONFIG_MEM_DEVICE */
203
204 /*
205 * Configure the maximum page size. As no memory devices were created
206 * yet, this is the page size of initial memory only.
207 */
208 s390_set_max_pagesize(s390ms, qemu_maxrampagesize());
209 /* Initialize storage key device */
210 s390_skeys_init();
211 /* Initialize storage attributes device */
212 s390_stattrib_init();
213 }
214
s390_init_ipl_dev(const char * kernel_filename,const char * kernel_cmdline,const char * initrd_filename,const char * firmware,bool enforce_bios)215 static void s390_init_ipl_dev(const char *kernel_filename,
216 const char *kernel_cmdline,
217 const char *initrd_filename, const char *firmware,
218 bool enforce_bios)
219 {
220 Object *new = object_new(TYPE_S390_IPL);
221 DeviceState *dev = DEVICE(new);
222
223 if (kernel_filename) {
224 qdev_prop_set_string(dev, "kernel", kernel_filename);
225 }
226 if (initrd_filename) {
227 qdev_prop_set_string(dev, "initrd", initrd_filename);
228 }
229 qdev_prop_set_string(dev, "cmdline", kernel_cmdline);
230 qdev_prop_set_string(dev, "firmware", firmware);
231 qdev_prop_set_bit(dev, "enforce_bios", enforce_bios);
232 object_property_add_child(qdev_get_machine(), TYPE_S390_IPL,
233 new);
234 object_unref(new);
235 qdev_realize(dev, NULL, &error_fatal);
236 }
237
s390_create_virtio_net(BusState * bus,const char * name)238 static void s390_create_virtio_net(BusState *bus, const char *name)
239 {
240 DeviceState *dev;
241 int cnt = 0;
242
243 while ((dev = qemu_create_nic_device(name, true, "virtio"))) {
244 g_autofree char *childname = g_strdup_printf("%s[%d]", name, cnt++);
245 object_property_add_child(OBJECT(bus), childname, OBJECT(dev));
246 qdev_realize_and_unref(dev, bus, &error_fatal);
247 }
248 }
249
s390_create_sclpconsole(SCLPDevice * sclp,const char * type,Chardev * chardev)250 static void s390_create_sclpconsole(SCLPDevice *sclp,
251 const char *type, Chardev *chardev)
252 {
253 SCLPEventFacility *ef = sclp->event_facility;
254 BusState *ev_fac_bus = sclp_get_event_facility_bus(ef);
255 DeviceState *dev;
256
257 dev = qdev_new(type);
258 object_property_add_child(OBJECT(ef), type, OBJECT(dev));
259 qdev_prop_set_chr(dev, "chardev", chardev);
260 qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
261 }
262
ccw_init(MachineState * machine)263 static void ccw_init(MachineState *machine)
264 {
265 MachineClass *mc = MACHINE_GET_CLASS(machine);
266 S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
267 int ret;
268 VirtualCssBus *css_bus;
269 DeviceState *dev;
270
271 ms->sclp = SCLP(object_new(TYPE_SCLP));
272 object_property_add_child(OBJECT(machine), TYPE_SCLP, OBJECT(ms->sclp));
273 qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal);
274
275 /* init memory + setup max page size. Required for the CPU model */
276 s390_memory_init(machine);
277
278 /* init CPUs (incl. CPU model) early so s390_has_feature() works */
279 s390_init_cpus(machine);
280
281 /* Need CPU model to be determined before we can set up PV */
282 if (machine->cgs) {
283 confidential_guest_kvm_init(machine->cgs, &error_fatal);
284 }
285
286 s390_flic_init();
287
288 /* init the SIGP facility */
289 s390_init_sigp();
290
291 /* create AP bridge and bus(es) */
292 s390_init_ap();
293
294 /* get a BUS */
295 css_bus = virtual_css_bus_init();
296 s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline,
297 machine->initrd_filename,
298 machine->firmware ?: "s390-ccw.img",
299 true);
300
301 dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE);
302 object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
303 OBJECT(dev));
304 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
305
306 s390_enable_css_support(s390_cpu_addr2state(0));
307
308 ret = css_create_css_image(VIRTUAL_CSSID, true);
309 assert(ret == 0);
310
311 css_register_vmstate();
312
313 /* Create VirtIO network adapters */
314 s390_create_virtio_net(BUS(css_bus), mc->default_nic);
315
316 /* init consoles */
317 if (serial_hd(0)) {
318 s390_create_sclpconsole(ms->sclp, "sclpconsole", serial_hd(0));
319 }
320 if (serial_hd(1)) {
321 s390_create_sclpconsole(ms->sclp, "sclplmconsole", serial_hd(1));
322 }
323
324 /* init the TOD clock */
325 s390_init_tod();
326 }
327
s390_cpu_plug(HotplugHandler * hotplug_dev,DeviceState * dev,Error ** errp)328 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
329 DeviceState *dev, Error **errp)
330 {
331 ERRP_GUARD();
332 MachineState *ms = MACHINE(hotplug_dev);
333 S390CPU *cpu = S390_CPU(dev);
334
335 g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu);
336 ms->possible_cpus->cpus[cpu->env.core_id].cpu = CPU(dev);
337
338 if (s390_has_topology()) {
339 s390_topology_setup_cpu(ms, cpu, errp);
340 if (*errp) {
341 return;
342 }
343 }
344
345 if (dev->hotplugged) {
346 raise_irq_cpu_hotplug();
347 }
348 }
349
s390_do_cpu_ipl(CPUState * cs,run_on_cpu_data arg)350 static inline void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg)
351 {
352 S390CPU *cpu = S390_CPU(cs);
353
354 s390_ipl_prepare_cpu(cpu);
355 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
356 }
357
s390_machine_unprotect(S390CcwMachineState * ms)358 static void s390_machine_unprotect(S390CcwMachineState *ms)
359 {
360 if (!s390_pv_vm_try_disable_async(ms)) {
361 s390_pv_vm_disable();
362 }
363 ms->pv = false;
364 migrate_del_blocker(&pv_mig_blocker);
365 ram_block_discard_disable(false);
366 }
367
s390_machine_protect(S390CcwMachineState * ms)368 static int s390_machine_protect(S390CcwMachineState *ms)
369 {
370 Error *local_err = NULL;
371 int rc;
372
373 /*
374 * Discarding of memory in RAM blocks does not work as expected with
375 * protected VMs. Sharing and unsharing pages would be required. Disable
376 * it for now, until until we have a solution to make at least Linux
377 * guests either support it (e.g., virtio-balloon) or fail gracefully.
378 */
379 rc = ram_block_discard_disable(true);
380 if (rc) {
381 error_report("protected VMs: cannot disable RAM discard");
382 return rc;
383 }
384
385 error_setg(&pv_mig_blocker,
386 "protected VMs are currently not migratable.");
387 rc = migrate_add_blocker(&pv_mig_blocker, &local_err);
388 if (rc) {
389 ram_block_discard_disable(false);
390 error_report_err(local_err);
391 return rc;
392 }
393
394 /* Create SE VM */
395 rc = s390_pv_vm_enable();
396 if (rc) {
397 ram_block_discard_disable(false);
398 migrate_del_blocker(&pv_mig_blocker);
399 return rc;
400 }
401
402 ms->pv = true;
403
404 /* Will return 0 if API is not available since it's not vital */
405 rc = s390_pv_query_info();
406 if (rc) {
407 goto out_err;
408 }
409
410 /* Set SE header and unpack */
411 rc = s390_ipl_prepare_pv_header(&local_err);
412 if (rc) {
413 goto out_err;
414 }
415
416 /* Decrypt image */
417 rc = s390_ipl_pv_unpack();
418 if (rc) {
419 goto out_err;
420 }
421
422 /* Verify integrity */
423 rc = s390_pv_verify();
424 if (rc) {
425 goto out_err;
426 }
427 return rc;
428
429 out_err:
430 if (local_err) {
431 error_report_err(local_err);
432 }
433 s390_machine_unprotect(ms);
434 return rc;
435 }
436
s390_pv_prepare_reset(S390CcwMachineState * ms)437 static void s390_pv_prepare_reset(S390CcwMachineState *ms)
438 {
439 CPUState *cs;
440
441 if (!s390_is_pv()) {
442 return;
443 }
444 /* Unsharing requires all cpus to be stopped */
445 CPU_FOREACH(cs) {
446 s390_cpu_set_state(S390_CPU_STATE_STOPPED, S390_CPU(cs));
447 }
448 s390_pv_unshare();
449 s390_pv_prep_reset();
450 }
451
s390_machine_reset(MachineState * machine,ResetType type)452 static void s390_machine_reset(MachineState *machine, ResetType type)
453 {
454 S390CcwMachineState *ms = S390_CCW_MACHINE(machine);
455 enum s390_reset reset_type;
456 CPUState *cs, *t;
457 S390CPU *cpu;
458
459 /*
460 * Temporarily drop the record/replay mutex to let rr_cpu_thread_fn()
461 * process the run_on_cpu() requests below. This is safe, because at this
462 * point one of the following is true:
463 * - All CPU threads are not running, either because the machine is being
464 * initialized, or because the guest requested a reset using diag 308.
465 * There is no risk to desync the record/replay state.
466 * - A snapshot is about to be loaded. The record/replay state consistency
467 * is not important.
468 */
469 replay_mutex_unlock();
470
471 /* get the reset parameters, reset them once done */
472 s390_ipl_get_reset_request(&cs, &reset_type);
473
474 /* all CPUs are paused and synchronized at this point */
475 s390_cmma_reset();
476
477 cpu = S390_CPU(cs);
478
479 switch (reset_type) {
480 case S390_RESET_EXTERNAL:
481 case S390_RESET_REIPL:
482 /*
483 * Reset the subsystem which includes a AP reset. If a PV
484 * guest had APQNs attached the AP reset is a prerequisite to
485 * unprotecting since the UV checks if all APQNs are reset.
486 */
487 subsystem_reset();
488 if (s390_is_pv()) {
489 s390_machine_unprotect(ms);
490 }
491
492 /*
493 * Device reset includes CPU clear resets so this has to be
494 * done AFTER the unprotect call above.
495 */
496 qemu_devices_reset(type);
497 s390_crypto_reset();
498
499 /* configure and start the ipl CPU only */
500 run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL);
501 break;
502 case S390_RESET_MODIFIED_CLEAR:
503 /*
504 * Subsystem reset needs to be done before we unshare memory
505 * and lose access to VIRTIO structures in guest memory.
506 */
507 subsystem_reset();
508 s390_crypto_reset();
509 s390_pv_prepare_reset(ms);
510 CPU_FOREACH(t) {
511 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
512 }
513 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
514 break;
515 case S390_RESET_LOAD_NORMAL:
516 /*
517 * Subsystem reset needs to be done before we unshare memory
518 * and lose access to VIRTIO structures in guest memory.
519 */
520 subsystem_reset();
521 s390_pv_prepare_reset(ms);
522 CPU_FOREACH(t) {
523 if (t == cs) {
524 continue;
525 }
526 run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL);
527 }
528 run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL);
529 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
530 break;
531 case S390_RESET_PV: /* Subcode 10 */
532 subsystem_reset();
533 s390_crypto_reset();
534
535 CPU_FOREACH(t) {
536 if (t == cs) {
537 continue;
538 }
539 run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL);
540 }
541 run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL);
542
543 if (s390_machine_protect(ms)) {
544 s390_pv_inject_reset_error(cs);
545 /*
546 * Continue after the diag308 so the guest knows something
547 * went wrong.
548 */
549 s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
550 goto out_lock;
551 }
552
553 run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL);
554 break;
555 default:
556 g_assert_not_reached();
557 }
558
559 CPU_FOREACH(t) {
560 run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(0));
561 }
562 s390_ipl_clear_reset_request();
563
564 out_lock:
565 /*
566 * Re-take the record/replay mutex, temporarily dropping the BQL in order
567 * to satisfy the ordering requirements.
568 */
569 bql_unlock();
570 replay_mutex_lock();
571 bql_lock();
572 }
573
s390_machine_device_pre_plug(HotplugHandler * hotplug_dev,DeviceState * dev,Error ** errp)574 static void s390_machine_device_pre_plug(HotplugHandler *hotplug_dev,
575 DeviceState *dev, Error **errp)
576 {
577 if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
578 virtio_ccw_md_pre_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp);
579 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
580 virtio_md_pci_pre_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp);
581 }
582 }
583
s390_machine_device_plug(HotplugHandler * hotplug_dev,DeviceState * dev,Error ** errp)584 static void s390_machine_device_plug(HotplugHandler *hotplug_dev,
585 DeviceState *dev, Error **errp)
586 {
587 S390CcwMachineState *s390ms = S390_CCW_MACHINE(hotplug_dev);
588
589 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
590 s390_cpu_plug(hotplug_dev, dev, errp);
591 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) ||
592 object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
593 /*
594 * At this point, the device is realized and set all memdevs mapped, so
595 * qemu_maxrampagesize() will pick up the page sizes of these memdevs
596 * as well. Before we plug the device and expose any RAM memory regions
597 * to the system, make sure we don't exceed the previously set max page
598 * size. While only relevant for KVM, there is not really any use case
599 * for this with TCG, so we'll unconditionally reject it.
600 */
601 if (qemu_maxrampagesize() != s390ms->max_pagesize) {
602 error_setg(errp, "Memory device uses a bigger page size than"
603 " initial memory");
604 return;
605 }
606 if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
607 virtio_ccw_md_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp);
608 } else {
609 virtio_md_pci_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp);
610 }
611 }
612 }
613
s390_machine_device_unplug_request(HotplugHandler * hotplug_dev,DeviceState * dev,Error ** errp)614 static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev,
615 DeviceState *dev, Error **errp)
616 {
617 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
618 error_setg(errp, "CPU hot unplug not supported on this machine");
619 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
620 virtio_ccw_md_unplug_request(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev),
621 errp);
622 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
623 virtio_md_pci_unplug_request(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev),
624 errp);
625 }
626 }
627
s390_machine_device_unplug(HotplugHandler * hotplug_dev,DeviceState * dev,Error ** errp)628 static void s390_machine_device_unplug(HotplugHandler *hotplug_dev,
629 DeviceState *dev, Error **errp)
630 {
631 if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) {
632 virtio_ccw_md_unplug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp);
633 } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
634 virtio_md_pci_unplug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp);
635 }
636 }
637
s390_cpu_index_to_props(MachineState * ms,unsigned cpu_index)638 static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms,
639 unsigned cpu_index)
640 {
641 MachineClass *mc = MACHINE_GET_CLASS(ms);
642 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
643
644 assert(cpu_index < possible_cpus->len);
645 return possible_cpus->cpus[cpu_index].props;
646 }
647
s390_possible_cpu_arch_ids(MachineState * ms)648 static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms)
649 {
650 int i;
651 unsigned int max_cpus = ms->smp.max_cpus;
652
653 if (ms->possible_cpus) {
654 g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus);
655 return ms->possible_cpus;
656 }
657
658 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
659 sizeof(CPUArchId) * max_cpus);
660 ms->possible_cpus->len = max_cpus;
661 for (i = 0; i < ms->possible_cpus->len; i++) {
662 CpuInstanceProperties *props = &ms->possible_cpus->cpus[i].props;
663
664 ms->possible_cpus->cpus[i].type = ms->cpu_type;
665 ms->possible_cpus->cpus[i].vcpus_count = 1;
666 ms->possible_cpus->cpus[i].arch_id = i;
667
668 props->has_core_id = true;
669 props->core_id = i;
670 props->has_socket_id = true;
671 props->socket_id = s390_std_socket(i, &ms->smp);
672 props->has_book_id = true;
673 props->book_id = s390_std_book(i, &ms->smp);
674 props->has_drawer_id = true;
675 props->drawer_id = s390_std_drawer(i, &ms->smp);
676 }
677
678 return ms->possible_cpus;
679 }
680
s390_get_hotplug_handler(MachineState * machine,DeviceState * dev)681 static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
682 DeviceState *dev)
683 {
684 if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) ||
685 object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) ||
686 object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) {
687 return HOTPLUG_HANDLER(machine);
688 }
689 return NULL;
690 }
691
s390_nmi(NMIState * n,int cpu_index,Error ** errp)692 static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
693 {
694 CPUState *cs = qemu_get_cpu(cpu_index);
695
696 s390_cpu_restart(S390_CPU(cs));
697 }
698
s390_fixup_ram_size(ram_addr_t sz)699 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
700 {
701 /* same logic as in sclp.c */
702 int increment_size = 20;
703 ram_addr_t newsz;
704
705 while ((sz >> increment_size) > MAX_STORAGE_INCREMENTS) {
706 increment_size++;
707 }
708 newsz = sz >> increment_size << increment_size;
709
710 if (sz != newsz) {
711 qemu_printf("Ram size %" PRIu64 "MB was fixed up to %" PRIu64
712 "MB to match machine restrictions. Consider updating "
713 "the guest definition.\n", (uint64_t) (sz / MiB),
714 (uint64_t) (newsz / MiB));
715 }
716 return newsz;
717 }
718
machine_get_aes_key_wrap(Object * obj,Error ** errp)719 static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp)
720 {
721 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
722
723 return ms->aes_key_wrap;
724 }
725
machine_set_aes_key_wrap(Object * obj,bool value,Error ** errp)726 static inline void machine_set_aes_key_wrap(Object *obj, bool value,
727 Error **errp)
728 {
729 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
730
731 ms->aes_key_wrap = value;
732 }
733
machine_get_dea_key_wrap(Object * obj,Error ** errp)734 static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp)
735 {
736 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
737
738 return ms->dea_key_wrap;
739 }
740
machine_set_dea_key_wrap(Object * obj,bool value,Error ** errp)741 static inline void machine_set_dea_key_wrap(Object *obj, bool value,
742 Error **errp)
743 {
744 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
745
746 ms->dea_key_wrap = value;
747 }
748
749 static S390CcwMachineClass *current_mc;
750
751 /*
752 * Get the class of the s390-ccw-virtio machine that is currently in use.
753 * Note: libvirt is using the "none" machine to probe for the features of the
754 * host CPU, so in case this is called with the "none" machine, the function
755 * returns the TYPE_S390_CCW_MACHINE base class. In this base class, all the
756 * various "*_allowed" variables are enabled, so that the *_allowed() wrappers
757 * below return the correct default value for the "none" machine.
758 *
759 * Attention! Do *not* add additional new wrappers for CPU features via this
760 * mechanism anymore. CPU features should be handled via the CPU models,
761 * i.e. checking with s390_has_feat() should be sufficient.
762 */
get_machine_class(void)763 static S390CcwMachineClass *get_machine_class(void)
764 {
765 if (unlikely(!current_mc)) {
766 /*
767 * No s390 ccw machine was instantiated, we are likely to
768 * be called for the 'none' machine. The properties will
769 * have their after-initialization values.
770 */
771 current_mc = S390_CCW_MACHINE_CLASS(
772 object_class_by_name(TYPE_S390_CCW_MACHINE));
773 }
774 return current_mc;
775 }
776
hpage_1m_allowed(void)777 bool hpage_1m_allowed(void)
778 {
779 return get_machine_class()->hpage_1m_allowed;
780 }
781
machine_get_loadparm(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)782 static void machine_get_loadparm(Object *obj, Visitor *v,
783 const char *name, void *opaque,
784 Error **errp)
785 {
786 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
787 char *str = g_strndup((char *) ms->loadparm, sizeof(ms->loadparm));
788
789 visit_type_str(v, name, &str, errp);
790 g_free(str);
791 }
792
machine_set_loadparm(Object * obj,Visitor * v,const char * name,void * opaque,Error ** errp)793 static void machine_set_loadparm(Object *obj, Visitor *v,
794 const char *name, void *opaque,
795 Error **errp)
796 {
797 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
798 char *val;
799
800 if (!visit_type_str(v, name, &val, errp)) {
801 return;
802 }
803
804 s390_ipl_fmt_loadparm(ms->loadparm, val, errp);
805 g_free(val);
806 }
807
ccw_machine_class_init(ObjectClass * oc,void * data)808 static void ccw_machine_class_init(ObjectClass *oc, void *data)
809 {
810 MachineClass *mc = MACHINE_CLASS(oc);
811 NMIClass *nc = NMI_CLASS(oc);
812 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
813 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
814
815 s390mc->hpage_1m_allowed = true;
816 s390mc->max_threads = 1;
817 mc->reset = s390_machine_reset;
818 mc->block_default_type = IF_VIRTIO;
819 mc->no_cdrom = 1;
820 mc->no_floppy = 1;
821 mc->no_parallel = 1;
822 mc->max_cpus = S390_MAX_CPUS;
823 mc->has_hotpluggable_cpus = true;
824 mc->smp_props.books_supported = true;
825 mc->smp_props.drawers_supported = true;
826 assert(!mc->get_hotplug_handler);
827 mc->get_hotplug_handler = s390_get_hotplug_handler;
828 mc->cpu_index_to_instance_props = s390_cpu_index_to_props;
829 mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids;
830 /* it is overridden with 'host' cpu *in kvm_arch_init* */
831 mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu");
832 hc->pre_plug = s390_machine_device_pre_plug;
833 hc->plug = s390_machine_device_plug;
834 hc->unplug_request = s390_machine_device_unplug_request;
835 hc->unplug = s390_machine_device_unplug;
836 nc->nmi_monitor_handler = s390_nmi;
837 mc->default_ram_id = "s390.ram";
838 mc->default_nic = "virtio-net-ccw";
839
840 object_class_property_add_bool(oc, "aes-key-wrap",
841 machine_get_aes_key_wrap,
842 machine_set_aes_key_wrap);
843 object_class_property_set_description(oc, "aes-key-wrap",
844 "enable/disable AES key wrapping using the CPACF wrapping key");
845
846 object_class_property_add_bool(oc, "dea-key-wrap",
847 machine_get_dea_key_wrap,
848 machine_set_dea_key_wrap);
849 object_class_property_set_description(oc, "dea-key-wrap",
850 "enable/disable DEA key wrapping using the CPACF wrapping key");
851
852 object_class_property_add(oc, "loadparm", "loadparm",
853 machine_get_loadparm, machine_set_loadparm,
854 NULL, NULL);
855 object_class_property_set_description(oc, "loadparm",
856 "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted"
857 " to upper case) to pass to machine loader, boot manager,"
858 " and guest kernel");
859 }
860
s390_machine_initfn(Object * obj)861 static inline void s390_machine_initfn(Object *obj)
862 {
863 S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
864
865 ms->aes_key_wrap = true;
866 ms->dea_key_wrap = true;
867 }
868
869 static const TypeInfo ccw_machine_info = {
870 .name = TYPE_S390_CCW_MACHINE,
871 .parent = TYPE_MACHINE,
872 .abstract = true,
873 .instance_size = sizeof(S390CcwMachineState),
874 .instance_init = s390_machine_initfn,
875 .class_size = sizeof(S390CcwMachineClass),
876 .class_init = ccw_machine_class_init,
877 .interfaces = (InterfaceInfo[]) {
878 { TYPE_NMI },
879 { TYPE_HOTPLUG_HANDLER},
880 { }
881 },
882 };
883
884 #define DEFINE_CCW_MACHINE_IMPL(latest, ...) \
885 static void MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__)(MachineState *mach) \
886 { \
887 current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(mach)); \
888 MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(mach); \
889 ccw_init(mach); \
890 } \
891 static void MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__)( \
892 ObjectClass *oc, \
893 void *data) \
894 { \
895 MachineClass *mc = MACHINE_CLASS(oc); \
896 MACHINE_VER_SYM(class_options, ccw, __VA_ARGS__)(mc); \
897 mc->desc = "Virtual s390x machine (version " MACHINE_VER_STR(__VA_ARGS__) ")"; \
898 mc->init = MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__); \
899 MACHINE_VER_DEPRECATION(__VA_ARGS__); \
900 if (latest) { \
901 mc->alias = "s390-ccw-virtio"; \
902 mc->is_default = true; \
903 } \
904 } \
905 static const TypeInfo MACHINE_VER_SYM(info, ccw, __VA_ARGS__) = \
906 { \
907 .name = MACHINE_VER_TYPE_NAME("s390-ccw-virtio", __VA_ARGS__), \
908 .parent = TYPE_S390_CCW_MACHINE, \
909 .class_init = MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__), \
910 }; \
911 static void MACHINE_VER_SYM(register, ccw, __VA_ARGS__)(void) \
912 { \
913 MACHINE_VER_DELETION(__VA_ARGS__); \
914 type_register_static(&MACHINE_VER_SYM(info, ccw, __VA_ARGS__)); \
915 } \
916 type_init(MACHINE_VER_SYM(register, ccw, __VA_ARGS__))
917
918 #define DEFINE_CCW_MACHINE_AS_LATEST(major, minor) \
919 DEFINE_CCW_MACHINE_IMPL(true, major, minor)
920
921 #define DEFINE_CCW_MACHINE(major, minor) \
922 DEFINE_CCW_MACHINE_IMPL(false, major, minor)
923
924
ccw_machine_10_0_instance_options(MachineState * machine)925 static void ccw_machine_10_0_instance_options(MachineState *machine)
926 {
927 }
928
ccw_machine_10_0_class_options(MachineClass * mc)929 static void ccw_machine_10_0_class_options(MachineClass *mc)
930 {
931 }
932 DEFINE_CCW_MACHINE_AS_LATEST(10, 0);
933
ccw_machine_9_2_instance_options(MachineState * machine)934 static void ccw_machine_9_2_instance_options(MachineState *machine)
935 {
936 ccw_machine_10_0_instance_options(machine);
937 }
938
ccw_machine_9_2_class_options(MachineClass * mc)939 static void ccw_machine_9_2_class_options(MachineClass *mc)
940 {
941 static GlobalProperty compat[] = {
942 { TYPE_S390_PCI_DEVICE, "relaxed-translation", "off", },
943 };
944
945 ccw_machine_10_0_class_options(mc);
946 compat_props_add(mc->compat_props, hw_compat_9_2, hw_compat_9_2_len);
947 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
948 }
949 DEFINE_CCW_MACHINE(9, 2);
950
ccw_machine_9_1_instance_options(MachineState * machine)951 static void ccw_machine_9_1_instance_options(MachineState *machine)
952 {
953 ccw_machine_9_2_instance_options(machine);
954 }
955
ccw_machine_9_1_class_options(MachineClass * mc)956 static void ccw_machine_9_1_class_options(MachineClass *mc)
957 {
958 ccw_machine_9_2_class_options(mc);
959 compat_props_add(mc->compat_props, hw_compat_9_1, hw_compat_9_1_len);
960 }
961 DEFINE_CCW_MACHINE(9, 1);
962
ccw_machine_9_0_instance_options(MachineState * machine)963 static void ccw_machine_9_0_instance_options(MachineState *machine)
964 {
965 ccw_machine_9_1_instance_options(machine);
966 }
967
ccw_machine_9_0_class_options(MachineClass * mc)968 static void ccw_machine_9_0_class_options(MachineClass *mc)
969 {
970 static GlobalProperty compat[] = {
971 { TYPE_QEMU_S390_FLIC, "migrate-all-state", "off", },
972 };
973
974 ccw_machine_9_1_class_options(mc);
975 compat_props_add(mc->compat_props, hw_compat_9_0, hw_compat_9_0_len);
976 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
977 }
978 DEFINE_CCW_MACHINE(9, 0);
979
ccw_machine_8_2_instance_options(MachineState * machine)980 static void ccw_machine_8_2_instance_options(MachineState *machine)
981 {
982 ccw_machine_9_0_instance_options(machine);
983 }
984
ccw_machine_8_2_class_options(MachineClass * mc)985 static void ccw_machine_8_2_class_options(MachineClass *mc)
986 {
987 ccw_machine_9_0_class_options(mc);
988 compat_props_add(mc->compat_props, hw_compat_8_2, hw_compat_8_2_len);
989 }
990 DEFINE_CCW_MACHINE(8, 2);
991
ccw_machine_8_1_instance_options(MachineState * machine)992 static void ccw_machine_8_1_instance_options(MachineState *machine)
993 {
994 ccw_machine_8_2_instance_options(machine);
995 }
996
ccw_machine_8_1_class_options(MachineClass * mc)997 static void ccw_machine_8_1_class_options(MachineClass *mc)
998 {
999 ccw_machine_8_2_class_options(mc);
1000 compat_props_add(mc->compat_props, hw_compat_8_1, hw_compat_8_1_len);
1001 mc->smp_props.drawers_supported = false;
1002 mc->smp_props.books_supported = false;
1003 }
1004 DEFINE_CCW_MACHINE(8, 1);
1005
ccw_machine_8_0_instance_options(MachineState * machine)1006 static void ccw_machine_8_0_instance_options(MachineState *machine)
1007 {
1008 ccw_machine_8_1_instance_options(machine);
1009 }
1010
ccw_machine_8_0_class_options(MachineClass * mc)1011 static void ccw_machine_8_0_class_options(MachineClass *mc)
1012 {
1013 ccw_machine_8_1_class_options(mc);
1014 compat_props_add(mc->compat_props, hw_compat_8_0, hw_compat_8_0_len);
1015 }
1016 DEFINE_CCW_MACHINE(8, 0);
1017
ccw_machine_7_2_instance_options(MachineState * machine)1018 static void ccw_machine_7_2_instance_options(MachineState *machine)
1019 {
1020 ccw_machine_8_0_instance_options(machine);
1021 }
1022
ccw_machine_7_2_class_options(MachineClass * mc)1023 static void ccw_machine_7_2_class_options(MachineClass *mc)
1024 {
1025 ccw_machine_8_0_class_options(mc);
1026 compat_props_add(mc->compat_props, hw_compat_7_2, hw_compat_7_2_len);
1027 }
1028 DEFINE_CCW_MACHINE(7, 2);
1029
ccw_machine_7_1_instance_options(MachineState * machine)1030 static void ccw_machine_7_1_instance_options(MachineState *machine)
1031 {
1032 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_1 };
1033
1034 ccw_machine_7_2_instance_options(machine);
1035 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE);
1036 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
1037 }
1038
ccw_machine_7_1_class_options(MachineClass * mc)1039 static void ccw_machine_7_1_class_options(MachineClass *mc)
1040 {
1041 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1042 static GlobalProperty compat[] = {
1043 { TYPE_S390_PCI_DEVICE, "interpret", "off", },
1044 { TYPE_S390_PCI_DEVICE, "forwarding-assist", "off", },
1045 };
1046
1047 ccw_machine_7_2_class_options(mc);
1048 compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len);
1049 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1050 s390mc->max_threads = S390_MAX_CPUS;
1051 }
1052 DEFINE_CCW_MACHINE(7, 1);
1053
ccw_machine_7_0_instance_options(MachineState * machine)1054 static void ccw_machine_7_0_instance_options(MachineState *machine)
1055 {
1056 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_0 };
1057
1058 ccw_machine_7_1_instance_options(machine);
1059 s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat);
1060 }
1061
ccw_machine_7_0_class_options(MachineClass * mc)1062 static void ccw_machine_7_0_class_options(MachineClass *mc)
1063 {
1064 ccw_machine_7_1_class_options(mc);
1065 compat_props_add(mc->compat_props, hw_compat_7_0, hw_compat_7_0_len);
1066 }
1067 DEFINE_CCW_MACHINE(7, 0);
1068
ccw_machine_6_2_instance_options(MachineState * machine)1069 static void ccw_machine_6_2_instance_options(MachineState *machine)
1070 {
1071 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_2 };
1072
1073 ccw_machine_7_0_instance_options(machine);
1074 s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat);
1075 }
1076
ccw_machine_6_2_class_options(MachineClass * mc)1077 static void ccw_machine_6_2_class_options(MachineClass *mc)
1078 {
1079 ccw_machine_7_0_class_options(mc);
1080 compat_props_add(mc->compat_props, hw_compat_6_2, hw_compat_6_2_len);
1081 }
1082 DEFINE_CCW_MACHINE(6, 2);
1083
ccw_machine_6_1_instance_options(MachineState * machine)1084 static void ccw_machine_6_1_instance_options(MachineState *machine)
1085 {
1086 ccw_machine_6_2_instance_options(machine);
1087 s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA);
1088 s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2);
1089 s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH);
1090 s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP);
1091 s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI);
1092 }
1093
ccw_machine_6_1_class_options(MachineClass * mc)1094 static void ccw_machine_6_1_class_options(MachineClass *mc)
1095 {
1096 ccw_machine_6_2_class_options(mc);
1097 compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len);
1098 mc->smp_props.prefer_sockets = true;
1099 }
1100 DEFINE_CCW_MACHINE(6, 1);
1101
ccw_machine_6_0_instance_options(MachineState * machine)1102 static void ccw_machine_6_0_instance_options(MachineState *machine)
1103 {
1104 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_0 };
1105
1106 ccw_machine_6_1_instance_options(machine);
1107 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
1108 }
1109
ccw_machine_6_0_class_options(MachineClass * mc)1110 static void ccw_machine_6_0_class_options(MachineClass *mc)
1111 {
1112 ccw_machine_6_1_class_options(mc);
1113 compat_props_add(mc->compat_props, hw_compat_6_0, hw_compat_6_0_len);
1114 }
1115 DEFINE_CCW_MACHINE(6, 0);
1116
ccw_machine_5_2_instance_options(MachineState * machine)1117 static void ccw_machine_5_2_instance_options(MachineState *machine)
1118 {
1119 ccw_machine_6_0_instance_options(machine);
1120 }
1121
ccw_machine_5_2_class_options(MachineClass * mc)1122 static void ccw_machine_5_2_class_options(MachineClass *mc)
1123 {
1124 ccw_machine_6_0_class_options(mc);
1125 compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len);
1126 }
1127 DEFINE_CCW_MACHINE(5, 2);
1128
ccw_machine_5_1_instance_options(MachineState * machine)1129 static void ccw_machine_5_1_instance_options(MachineState *machine)
1130 {
1131 ccw_machine_5_2_instance_options(machine);
1132 }
1133
ccw_machine_5_1_class_options(MachineClass * mc)1134 static void ccw_machine_5_1_class_options(MachineClass *mc)
1135 {
1136 ccw_machine_5_2_class_options(mc);
1137 compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len);
1138 }
1139 DEFINE_CCW_MACHINE(5, 1);
1140
ccw_machine_5_0_instance_options(MachineState * machine)1141 static void ccw_machine_5_0_instance_options(MachineState *machine)
1142 {
1143 ccw_machine_5_1_instance_options(machine);
1144 }
1145
ccw_machine_5_0_class_options(MachineClass * mc)1146 static void ccw_machine_5_0_class_options(MachineClass *mc)
1147 {
1148 ccw_machine_5_1_class_options(mc);
1149 compat_props_add(mc->compat_props, hw_compat_5_0, hw_compat_5_0_len);
1150 }
1151 DEFINE_CCW_MACHINE(5, 0);
1152
ccw_machine_4_2_instance_options(MachineState * machine)1153 static void ccw_machine_4_2_instance_options(MachineState *machine)
1154 {
1155 ccw_machine_5_0_instance_options(machine);
1156 }
1157
ccw_machine_4_2_class_options(MachineClass * mc)1158 static void ccw_machine_4_2_class_options(MachineClass *mc)
1159 {
1160 ccw_machine_5_0_class_options(mc);
1161 mc->fixup_ram_size = s390_fixup_ram_size;
1162 compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
1163 }
1164 DEFINE_CCW_MACHINE(4, 2);
1165
ccw_machine_4_1_instance_options(MachineState * machine)1166 static void ccw_machine_4_1_instance_options(MachineState *machine)
1167 {
1168 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_1 };
1169 ccw_machine_4_2_instance_options(machine);
1170 s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat);
1171 }
1172
ccw_machine_4_1_class_options(MachineClass * mc)1173 static void ccw_machine_4_1_class_options(MachineClass *mc)
1174 {
1175 ccw_machine_4_2_class_options(mc);
1176 compat_props_add(mc->compat_props, hw_compat_4_1, hw_compat_4_1_len);
1177 }
1178 DEFINE_CCW_MACHINE(4, 1);
1179
ccw_machine_4_0_instance_options(MachineState * machine)1180 static void ccw_machine_4_0_instance_options(MachineState *machine)
1181 {
1182 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V4_0 };
1183 ccw_machine_4_1_instance_options(machine);
1184 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1185 }
1186
ccw_machine_4_0_class_options(MachineClass * mc)1187 static void ccw_machine_4_0_class_options(MachineClass *mc)
1188 {
1189 ccw_machine_4_1_class_options(mc);
1190 compat_props_add(mc->compat_props, hw_compat_4_0, hw_compat_4_0_len);
1191 }
1192 DEFINE_CCW_MACHINE(4, 0);
1193
ccw_machine_3_1_instance_options(MachineState * machine)1194 static void ccw_machine_3_1_instance_options(MachineState *machine)
1195 {
1196 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V3_1 };
1197 ccw_machine_4_0_instance_options(machine);
1198 s390_cpudef_featoff_greater(14, 1, S390_FEAT_MULTIPLE_EPOCH);
1199 s390_cpudef_group_featoff_greater(14, 1, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF);
1200 s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
1201 }
1202
ccw_machine_3_1_class_options(MachineClass * mc)1203 static void ccw_machine_3_1_class_options(MachineClass *mc)
1204 {
1205 ccw_machine_4_0_class_options(mc);
1206 compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
1207 }
1208 DEFINE_CCW_MACHINE(3, 1);
1209
ccw_machine_3_0_instance_options(MachineState * machine)1210 static void ccw_machine_3_0_instance_options(MachineState *machine)
1211 {
1212 ccw_machine_3_1_instance_options(machine);
1213 }
1214
ccw_machine_3_0_class_options(MachineClass * mc)1215 static void ccw_machine_3_0_class_options(MachineClass *mc)
1216 {
1217 S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc);
1218
1219 s390mc->hpage_1m_allowed = false;
1220 ccw_machine_3_1_class_options(mc);
1221 compat_props_add(mc->compat_props, hw_compat_3_0, hw_compat_3_0_len);
1222 }
1223 DEFINE_CCW_MACHINE(3, 0);
1224
ccw_machine_2_12_instance_options(MachineState * machine)1225 static void ccw_machine_2_12_instance_options(MachineState *machine)
1226 {
1227 ccw_machine_3_0_instance_options(machine);
1228 s390_cpudef_featoff_greater(11, 1, S390_FEAT_PPA15);
1229 s390_cpudef_featoff_greater(11, 1, S390_FEAT_BPB);
1230 }
1231
ccw_machine_2_12_class_options(MachineClass * mc)1232 static void ccw_machine_2_12_class_options(MachineClass *mc)
1233 {
1234 ccw_machine_3_0_class_options(mc);
1235 compat_props_add(mc->compat_props, hw_compat_2_12, hw_compat_2_12_len);
1236 }
1237 DEFINE_CCW_MACHINE(2, 12);
1238
1239 #ifdef CONFIG_S390X_LEGACY_CPUS
1240
ccw_machine_2_11_instance_options(MachineState * machine)1241 static void ccw_machine_2_11_instance_options(MachineState *machine)
1242 {
1243 static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
1244 ccw_machine_2_12_instance_options(machine);
1245
1246 /* before 2.12 we emulated the very first z900 */
1247 s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
1248 }
1249
ccw_machine_2_11_class_options(MachineClass * mc)1250 static void ccw_machine_2_11_class_options(MachineClass *mc)
1251 {
1252 static GlobalProperty compat[] = {
1253 { TYPE_SCLP_EVENT_FACILITY, "allow_all_mask_sizes", "off", },
1254 };
1255
1256 ccw_machine_2_12_class_options(mc);
1257 compat_props_add(mc->compat_props, hw_compat_2_11, hw_compat_2_11_len);
1258 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1259 }
1260 DEFINE_CCW_MACHINE(2, 11);
1261
ccw_machine_2_10_instance_options(MachineState * machine)1262 static void ccw_machine_2_10_instance_options(MachineState *machine)
1263 {
1264 ccw_machine_2_11_instance_options(machine);
1265 }
1266
ccw_machine_2_10_class_options(MachineClass * mc)1267 static void ccw_machine_2_10_class_options(MachineClass *mc)
1268 {
1269 ccw_machine_2_11_class_options(mc);
1270 compat_props_add(mc->compat_props, hw_compat_2_10, hw_compat_2_10_len);
1271 }
1272 DEFINE_CCW_MACHINE(2, 10);
1273
ccw_machine_2_9_instance_options(MachineState * machine)1274 static void ccw_machine_2_9_instance_options(MachineState *machine)
1275 {
1276 ccw_machine_2_10_instance_options(machine);
1277 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ESOP);
1278 s390_cpudef_featoff_greater(12, 1, S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2);
1279 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ZPCI);
1280 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_INT_SUPPRESSION);
1281 s390_cpudef_featoff_greater(12, 1, S390_FEAT_ADAPTER_EVENT_NOTIFICATION);
1282 css_migration_enabled = false;
1283 }
1284
ccw_machine_2_9_class_options(MachineClass * mc)1285 static void ccw_machine_2_9_class_options(MachineClass *mc)
1286 {
1287 static GlobalProperty compat[] = {
1288 { TYPE_S390_STATTRIB, "migration-enabled", "off", },
1289 { TYPE_S390_FLIC_COMMON, "migration-enabled", "off", },
1290 };
1291
1292 ccw_machine_2_10_class_options(mc);
1293 compat_props_add(mc->compat_props, hw_compat_2_9, hw_compat_2_9_len);
1294 compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
1295 }
1296 DEFINE_CCW_MACHINE(2, 9);
1297
1298 #endif
1299
ccw_machine_register_types(void)1300 static void ccw_machine_register_types(void)
1301 {
1302 type_register_static(&ccw_machine_info);
1303 }
1304
1305 type_init(ccw_machine_register_types)
1306