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