]> git.proxmox.com Git - mirror_qemu.git/blob - hw/core/machine.c
5530b71981131592f60c9eb32708074748c58528
[mirror_qemu.git] / hw / core / machine.c
1 /*
2 * QEMU Machine
3 *
4 * Copyright (C) 2014 Red Hat Inc
5 *
6 * Authors:
7 * Marcel Apfelbaum <marcel.a@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
13 #include "qemu/osdep.h"
14 #include "qemu/units.h"
15 #include "hw/boards.h"
16 #include "qapi/error.h"
17 #include "qapi/qapi-visit-common.h"
18 #include "qapi/visitor.h"
19 #include "hw/sysbus.h"
20 #include "sysemu/sysemu.h"
21 #include "sysemu/numa.h"
22 #include "qemu/error-report.h"
23 #include "sysemu/qtest.h"
24 #include "hw/pci/pci.h"
25
26 GlobalProperty hw_compat_3_1[] = {
27 { "pcie-root-port", "x-speed", "2_5" },
28 { "pcie-root-port", "x-width", "1" },
29 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
30 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
31 };
32 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1);
33
34 GlobalProperty hw_compat_3_0[] = {};
35 const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0);
36
37 GlobalProperty hw_compat_2_12[] = {
38 { "migration", "decompress-error-check", "off" },
39 { "hda-audio", "use-timer", "false" },
40 { "cirrus-vga", "global-vmstate", "true" },
41 { "VGA", "global-vmstate", "true" },
42 { "vmware-svga", "global-vmstate", "true" },
43 { "qxl-vga", "global-vmstate", "true" },
44 };
45 const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12);
46
47 GlobalProperty hw_compat_2_11[] = {
48 { "hpet", "hpet-offset-saved", "false" },
49 { "virtio-blk-pci", "vectors", "2" },
50 { "vhost-user-blk-pci", "vectors", "2" },
51 { "e1000", "migrate_tso_props", "off" },
52 };
53 const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11);
54
55 GlobalProperty hw_compat_2_10[] = {
56 { "virtio-mouse-device", "wheel-axis", "false" },
57 { "virtio-tablet-device", "wheel-axis", "false" },
58 };
59 const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10);
60
61 GlobalProperty hw_compat_2_9[] = {
62 { "pci-bridge", "shpc", "off" },
63 { "intel-iommu", "pt", "off" },
64 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
65 { "pcie-root-port", "x-migrate-msix", "false" },
66 };
67 const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9);
68
69 GlobalProperty hw_compat_2_8[] = {
70 { "fw_cfg_mem", "x-file-slots", "0x10" },
71 { "fw_cfg_io", "x-file-slots", "0x10" },
72 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
73 { "pci-bridge", "shpc", "on" },
74 { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" },
75 { "virtio-pci", "x-pcie-deverr-init", "off" },
76 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
77 { "virtio-pci", "x-pcie-pm-init", "off" },
78 { "cirrus-vga", "vgamem_mb", "8" },
79 { "isa-cirrus-vga", "vgamem_mb", "8" },
80 };
81 const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8);
82
83 GlobalProperty hw_compat_2_7[] = {
84 { "virtio-pci", "page-per-vq", "on" },
85 { "virtio-serial-device", "emergency-write", "off" },
86 { "ioapic", "version", "0x11" },
87 { "intel-iommu", "x-buggy-eim", "true" },
88 { "virtio-pci", "x-ignore-backend-features", "on" },
89 };
90 const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
91
92 GlobalProperty hw_compat_2_6[] = {
93 { "virtio-mmio", "format_transport_address", "off" },
94 { "virtio-pci", "disable-modern", "on" },
95 { "virtio-pci", "disable-legacy", "off" },
96 };
97 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
98
99 GlobalProperty hw_compat_2_5[] = {
100 { "isa-fdc", "fallback", "144" },
101 { "pvscsi", "x-old-pci-configuration", "on" },
102 { "pvscsi", "x-disable-pcie", "on" },
103 { "vmxnet3", "x-old-msi-offsets", "on" },
104 { "vmxnet3", "x-disable-pcie", "on" },
105 };
106 const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5);
107
108 GlobalProperty hw_compat_2_4[] = {
109 { "virtio-blk-device", "scsi", "true" },
110 { "e1000", "extra_mac_registers", "off" },
111 { "virtio-pci", "x-disable-pcie", "on" },
112 { "virtio-pci", "migrate-extra", "off" },
113 { "fw_cfg_mem", "dma_enabled", "off" },
114 { "fw_cfg_io", "dma_enabled", "off" }
115 };
116 const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4);
117
118 GlobalProperty hw_compat_2_3[] = {
119 { "virtio-blk-pci", "any_layout", "off" },
120 { "virtio-balloon-pci", "any_layout", "off" },
121 { "virtio-serial-pci", "any_layout", "off" },
122 { "virtio-9p-pci", "any_layout", "off" },
123 { "virtio-rng-pci", "any_layout", "off" },
124 { TYPE_PCI_DEVICE, "x-pcie-lnksta-dllla", "off" },
125 { "migration", "send-configuration", "off" },
126 { "migration", "send-section-footer", "off" },
127 { "migration", "store-global-state", "off" },
128 };
129 const size_t hw_compat_2_3_len = G_N_ELEMENTS(hw_compat_2_3);
130
131 GlobalProperty hw_compat_2_2[] = {};
132 const size_t hw_compat_2_2_len = G_N_ELEMENTS(hw_compat_2_2);
133
134 GlobalProperty hw_compat_2_1[] = {
135 { "intel-hda", "old_msi_addr", "on" },
136 { "VGA", "qemu-extended-regs", "off" },
137 { "secondary-vga", "qemu-extended-regs", "off" },
138 { "virtio-scsi-pci", "any_layout", "off" },
139 { "usb-mouse", "usb_version", "1" },
140 { "usb-kbd", "usb_version", "1" },
141 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
142 };
143 const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1);
144
145 static char *machine_get_accel(Object *obj, Error **errp)
146 {
147 MachineState *ms = MACHINE(obj);
148
149 return g_strdup(ms->accel);
150 }
151
152 static void machine_set_accel(Object *obj, const char *value, Error **errp)
153 {
154 MachineState *ms = MACHINE(obj);
155
156 g_free(ms->accel);
157 ms->accel = g_strdup(value);
158 }
159
160 static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
161 const char *name, void *opaque,
162 Error **errp)
163 {
164 Error *err = NULL;
165 MachineState *ms = MACHINE(obj);
166 OnOffSplit mode;
167
168 visit_type_OnOffSplit(v, name, &mode, &err);
169 if (err) {
170 error_propagate(errp, err);
171 return;
172 } else {
173 switch (mode) {
174 case ON_OFF_SPLIT_ON:
175 ms->kernel_irqchip_allowed = true;
176 ms->kernel_irqchip_required = true;
177 ms->kernel_irqchip_split = false;
178 break;
179 case ON_OFF_SPLIT_OFF:
180 ms->kernel_irqchip_allowed = false;
181 ms->kernel_irqchip_required = false;
182 ms->kernel_irqchip_split = false;
183 break;
184 case ON_OFF_SPLIT_SPLIT:
185 ms->kernel_irqchip_allowed = true;
186 ms->kernel_irqchip_required = true;
187 ms->kernel_irqchip_split = true;
188 break;
189 default:
190 /* The value was checked in visit_type_OnOffSplit() above. If
191 * we get here, then something is wrong in QEMU.
192 */
193 abort();
194 }
195 }
196 }
197
198 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
199 const char *name, void *opaque,
200 Error **errp)
201 {
202 MachineState *ms = MACHINE(obj);
203 int64_t value = ms->kvm_shadow_mem;
204
205 visit_type_int(v, name, &value, errp);
206 }
207
208 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
209 const char *name, void *opaque,
210 Error **errp)
211 {
212 MachineState *ms = MACHINE(obj);
213 Error *error = NULL;
214 int64_t value;
215
216 visit_type_int(v, name, &value, &error);
217 if (error) {
218 error_propagate(errp, error);
219 return;
220 }
221
222 ms->kvm_shadow_mem = value;
223 }
224
225 static char *machine_get_kernel(Object *obj, Error **errp)
226 {
227 MachineState *ms = MACHINE(obj);
228
229 return g_strdup(ms->kernel_filename);
230 }
231
232 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
233 {
234 MachineState *ms = MACHINE(obj);
235
236 g_free(ms->kernel_filename);
237 ms->kernel_filename = g_strdup(value);
238 }
239
240 static char *machine_get_initrd(Object *obj, Error **errp)
241 {
242 MachineState *ms = MACHINE(obj);
243
244 return g_strdup(ms->initrd_filename);
245 }
246
247 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
248 {
249 MachineState *ms = MACHINE(obj);
250
251 g_free(ms->initrd_filename);
252 ms->initrd_filename = g_strdup(value);
253 }
254
255 static char *machine_get_append(Object *obj, Error **errp)
256 {
257 MachineState *ms = MACHINE(obj);
258
259 return g_strdup(ms->kernel_cmdline);
260 }
261
262 static void machine_set_append(Object *obj, const char *value, Error **errp)
263 {
264 MachineState *ms = MACHINE(obj);
265
266 g_free(ms->kernel_cmdline);
267 ms->kernel_cmdline = g_strdup(value);
268 }
269
270 static char *machine_get_dtb(Object *obj, Error **errp)
271 {
272 MachineState *ms = MACHINE(obj);
273
274 return g_strdup(ms->dtb);
275 }
276
277 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
278 {
279 MachineState *ms = MACHINE(obj);
280
281 g_free(ms->dtb);
282 ms->dtb = g_strdup(value);
283 }
284
285 static char *machine_get_dumpdtb(Object *obj, Error **errp)
286 {
287 MachineState *ms = MACHINE(obj);
288
289 return g_strdup(ms->dumpdtb);
290 }
291
292 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
293 {
294 MachineState *ms = MACHINE(obj);
295
296 g_free(ms->dumpdtb);
297 ms->dumpdtb = g_strdup(value);
298 }
299
300 static void machine_get_phandle_start(Object *obj, Visitor *v,
301 const char *name, void *opaque,
302 Error **errp)
303 {
304 MachineState *ms = MACHINE(obj);
305 int64_t value = ms->phandle_start;
306
307 visit_type_int(v, name, &value, errp);
308 }
309
310 static void machine_set_phandle_start(Object *obj, Visitor *v,
311 const char *name, void *opaque,
312 Error **errp)
313 {
314 MachineState *ms = MACHINE(obj);
315 Error *error = NULL;
316 int64_t value;
317
318 visit_type_int(v, name, &value, &error);
319 if (error) {
320 error_propagate(errp, error);
321 return;
322 }
323
324 ms->phandle_start = value;
325 }
326
327 static char *machine_get_dt_compatible(Object *obj, Error **errp)
328 {
329 MachineState *ms = MACHINE(obj);
330
331 return g_strdup(ms->dt_compatible);
332 }
333
334 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
335 {
336 MachineState *ms = MACHINE(obj);
337
338 g_free(ms->dt_compatible);
339 ms->dt_compatible = g_strdup(value);
340 }
341
342 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
343 {
344 MachineState *ms = MACHINE(obj);
345
346 return ms->dump_guest_core;
347 }
348
349 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
350 {
351 MachineState *ms = MACHINE(obj);
352
353 ms->dump_guest_core = value;
354 }
355
356 static bool machine_get_mem_merge(Object *obj, Error **errp)
357 {
358 MachineState *ms = MACHINE(obj);
359
360 return ms->mem_merge;
361 }
362
363 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
364 {
365 MachineState *ms = MACHINE(obj);
366
367 ms->mem_merge = value;
368 }
369
370 static bool machine_get_usb(Object *obj, Error **errp)
371 {
372 MachineState *ms = MACHINE(obj);
373
374 return ms->usb;
375 }
376
377 static void machine_set_usb(Object *obj, bool value, Error **errp)
378 {
379 MachineState *ms = MACHINE(obj);
380
381 ms->usb = value;
382 ms->usb_disabled = !value;
383 }
384
385 static bool machine_get_graphics(Object *obj, Error **errp)
386 {
387 MachineState *ms = MACHINE(obj);
388
389 return ms->enable_graphics;
390 }
391
392 static void machine_set_graphics(Object *obj, bool value, Error **errp)
393 {
394 MachineState *ms = MACHINE(obj);
395
396 ms->enable_graphics = value;
397 }
398
399 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
400 {
401 MachineState *ms = MACHINE(obj);
402
403 return ms->igd_gfx_passthru;
404 }
405
406 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
407 {
408 MachineState *ms = MACHINE(obj);
409
410 ms->igd_gfx_passthru = value;
411 }
412
413 static char *machine_get_firmware(Object *obj, Error **errp)
414 {
415 MachineState *ms = MACHINE(obj);
416
417 return g_strdup(ms->firmware);
418 }
419
420 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
421 {
422 MachineState *ms = MACHINE(obj);
423
424 g_free(ms->firmware);
425 ms->firmware = g_strdup(value);
426 }
427
428 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
429 {
430 MachineState *ms = MACHINE(obj);
431
432 ms->suppress_vmdesc = value;
433 }
434
435 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
436 {
437 MachineState *ms = MACHINE(obj);
438
439 return ms->suppress_vmdesc;
440 }
441
442 static void machine_set_enforce_config_section(Object *obj, bool value,
443 Error **errp)
444 {
445 MachineState *ms = MACHINE(obj);
446
447 warn_report("enforce-config-section is deprecated, please use "
448 "-global migration.send-configuration=on|off instead");
449
450 ms->enforce_config_section = value;
451 }
452
453 static bool machine_get_enforce_config_section(Object *obj, Error **errp)
454 {
455 MachineState *ms = MACHINE(obj);
456
457 return ms->enforce_config_section;
458 }
459
460 static char *machine_get_memory_encryption(Object *obj, Error **errp)
461 {
462 MachineState *ms = MACHINE(obj);
463
464 return g_strdup(ms->memory_encryption);
465 }
466
467 static void machine_set_memory_encryption(Object *obj, const char *value,
468 Error **errp)
469 {
470 MachineState *ms = MACHINE(obj);
471
472 g_free(ms->memory_encryption);
473 ms->memory_encryption = g_strdup(value);
474 }
475
476 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
477 {
478 strList *item = g_new0(strList, 1);
479
480 item->value = g_strdup(type);
481 item->next = mc->allowed_dynamic_sysbus_devices;
482 mc->allowed_dynamic_sysbus_devices = item;
483 }
484
485 static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
486 {
487 MachineState *machine = opaque;
488 MachineClass *mc = MACHINE_GET_CLASS(machine);
489 bool allowed = false;
490 strList *wl;
491
492 for (wl = mc->allowed_dynamic_sysbus_devices;
493 !allowed && wl;
494 wl = wl->next) {
495 allowed |= !!object_dynamic_cast(OBJECT(sbdev), wl->value);
496 }
497
498 if (!allowed) {
499 error_report("Option '-device %s' cannot be handled by this machine",
500 object_class_get_name(object_get_class(OBJECT(sbdev))));
501 exit(1);
502 }
503 }
504
505 static void machine_init_notify(Notifier *notifier, void *data)
506 {
507 MachineState *machine = MACHINE(qdev_get_machine());
508
509 /*
510 * Loop through all dynamically created sysbus devices and check if they are
511 * all allowed. If a device is not allowed, error out.
512 */
513 foreach_dynamic_sysbus_device(validate_sysbus_device, machine);
514 }
515
516 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
517 {
518 int i;
519 HotpluggableCPUList *head = NULL;
520 MachineClass *mc = MACHINE_GET_CLASS(machine);
521
522 /* force board to initialize possible_cpus if it hasn't been done yet */
523 mc->possible_cpu_arch_ids(machine);
524
525 for (i = 0; i < machine->possible_cpus->len; i++) {
526 Object *cpu;
527 HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
528 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
529
530 cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type);
531 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
532 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
533 sizeof(*cpu_item->props));
534
535 cpu = machine->possible_cpus->cpus[i].cpu;
536 if (cpu) {
537 cpu_item->has_qom_path = true;
538 cpu_item->qom_path = object_get_canonical_path(cpu);
539 }
540 list_item->value = cpu_item;
541 list_item->next = head;
542 head = list_item;
543 }
544 return head;
545 }
546
547 /**
548 * machine_set_cpu_numa_node:
549 * @machine: machine object to modify
550 * @props: specifies which cpu objects to assign to
551 * numa node specified by @props.node_id
552 * @errp: if an error occurs, a pointer to an area to store the error
553 *
554 * Associate NUMA node specified by @props.node_id with cpu slots that
555 * match socket/core/thread-ids specified by @props. It's recommended to use
556 * query-hotpluggable-cpus.props values to specify affected cpu slots,
557 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
558 *
559 * However for CLI convenience it's possible to pass in subset of properties,
560 * which would affect all cpu slots that match it.
561 * Ex for pc machine:
562 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
563 * -numa cpu,node-id=0,socket_id=0 \
564 * -numa cpu,node-id=1,socket_id=1
565 * will assign all child cores of socket 0 to node 0 and
566 * of socket 1 to node 1.
567 *
568 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
569 * return error.
570 * Empty subset is disallowed and function will return with error in this case.
571 */
572 void machine_set_cpu_numa_node(MachineState *machine,
573 const CpuInstanceProperties *props, Error **errp)
574 {
575 MachineClass *mc = MACHINE_GET_CLASS(machine);
576 bool match = false;
577 int i;
578
579 if (!mc->possible_cpu_arch_ids) {
580 error_setg(errp, "mapping of CPUs to NUMA node is not supported");
581 return;
582 }
583
584 /* disabling node mapping is not supported, forbid it */
585 assert(props->has_node_id);
586
587 /* force board to initialize possible_cpus if it hasn't been done yet */
588 mc->possible_cpu_arch_ids(machine);
589
590 for (i = 0; i < machine->possible_cpus->len; i++) {
591 CPUArchId *slot = &machine->possible_cpus->cpus[i];
592
593 /* reject unsupported by board properties */
594 if (props->has_thread_id && !slot->props.has_thread_id) {
595 error_setg(errp, "thread-id is not supported");
596 return;
597 }
598
599 if (props->has_core_id && !slot->props.has_core_id) {
600 error_setg(errp, "core-id is not supported");
601 return;
602 }
603
604 if (props->has_socket_id && !slot->props.has_socket_id) {
605 error_setg(errp, "socket-id is not supported");
606 return;
607 }
608
609 /* skip slots with explicit mismatch */
610 if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
611 continue;
612 }
613
614 if (props->has_core_id && props->core_id != slot->props.core_id) {
615 continue;
616 }
617
618 if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
619 continue;
620 }
621
622 /* reject assignment if slot is already assigned, for compatibility
623 * of legacy cpu_index mapping with SPAPR core based mapping do not
624 * error out if cpu thread and matched core have the same node-id */
625 if (slot->props.has_node_id &&
626 slot->props.node_id != props->node_id) {
627 error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
628 slot->props.node_id);
629 return;
630 }
631
632 /* assign slot to node as it's matched '-numa cpu' key */
633 match = true;
634 slot->props.node_id = props->node_id;
635 slot->props.has_node_id = props->has_node_id;
636 }
637
638 if (!match) {
639 error_setg(errp, "no match found");
640 }
641 }
642
643 static void machine_class_init(ObjectClass *oc, void *data)
644 {
645 MachineClass *mc = MACHINE_CLASS(oc);
646
647 /* Default 128 MB as guest ram size */
648 mc->default_ram_size = 128 * MiB;
649 mc->rom_file_has_mr = true;
650
651 /* numa node memory size aligned on 8MB by default.
652 * On Linux, each node's border has to be 8MB aligned
653 */
654 mc->numa_mem_align_shift = 23;
655 mc->numa_auto_assign_ram = numa_default_auto_assign_ram;
656
657 object_class_property_add_str(oc, "accel",
658 machine_get_accel, machine_set_accel, &error_abort);
659 object_class_property_set_description(oc, "accel",
660 "Accelerator list", &error_abort);
661
662 object_class_property_add(oc, "kernel-irqchip", "on|off|split",
663 NULL, machine_set_kernel_irqchip,
664 NULL, NULL, &error_abort);
665 object_class_property_set_description(oc, "kernel-irqchip",
666 "Configure KVM in-kernel irqchip", &error_abort);
667
668 object_class_property_add(oc, "kvm-shadow-mem", "int",
669 machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
670 NULL, NULL, &error_abort);
671 object_class_property_set_description(oc, "kvm-shadow-mem",
672 "KVM shadow MMU size", &error_abort);
673
674 object_class_property_add_str(oc, "kernel",
675 machine_get_kernel, machine_set_kernel, &error_abort);
676 object_class_property_set_description(oc, "kernel",
677 "Linux kernel image file", &error_abort);
678
679 object_class_property_add_str(oc, "initrd",
680 machine_get_initrd, machine_set_initrd, &error_abort);
681 object_class_property_set_description(oc, "initrd",
682 "Linux initial ramdisk file", &error_abort);
683
684 object_class_property_add_str(oc, "append",
685 machine_get_append, machine_set_append, &error_abort);
686 object_class_property_set_description(oc, "append",
687 "Linux kernel command line", &error_abort);
688
689 object_class_property_add_str(oc, "dtb",
690 machine_get_dtb, machine_set_dtb, &error_abort);
691 object_class_property_set_description(oc, "dtb",
692 "Linux kernel device tree file", &error_abort);
693
694 object_class_property_add_str(oc, "dumpdtb",
695 machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
696 object_class_property_set_description(oc, "dumpdtb",
697 "Dump current dtb to a file and quit", &error_abort);
698
699 object_class_property_add(oc, "phandle-start", "int",
700 machine_get_phandle_start, machine_set_phandle_start,
701 NULL, NULL, &error_abort);
702 object_class_property_set_description(oc, "phandle-start",
703 "The first phandle ID we may generate dynamically", &error_abort);
704
705 object_class_property_add_str(oc, "dt-compatible",
706 machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
707 object_class_property_set_description(oc, "dt-compatible",
708 "Overrides the \"compatible\" property of the dt root node",
709 &error_abort);
710
711 object_class_property_add_bool(oc, "dump-guest-core",
712 machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
713 object_class_property_set_description(oc, "dump-guest-core",
714 "Include guest memory in a core dump", &error_abort);
715
716 object_class_property_add_bool(oc, "mem-merge",
717 machine_get_mem_merge, machine_set_mem_merge, &error_abort);
718 object_class_property_set_description(oc, "mem-merge",
719 "Enable/disable memory merge support", &error_abort);
720
721 object_class_property_add_bool(oc, "usb",
722 machine_get_usb, machine_set_usb, &error_abort);
723 object_class_property_set_description(oc, "usb",
724 "Set on/off to enable/disable usb", &error_abort);
725
726 object_class_property_add_bool(oc, "graphics",
727 machine_get_graphics, machine_set_graphics, &error_abort);
728 object_class_property_set_description(oc, "graphics",
729 "Set on/off to enable/disable graphics emulation", &error_abort);
730
731 object_class_property_add_bool(oc, "igd-passthru",
732 machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
733 &error_abort);
734 object_class_property_set_description(oc, "igd-passthru",
735 "Set on/off to enable/disable igd passthrou", &error_abort);
736
737 object_class_property_add_str(oc, "firmware",
738 machine_get_firmware, machine_set_firmware,
739 &error_abort);
740 object_class_property_set_description(oc, "firmware",
741 "Firmware image", &error_abort);
742
743 object_class_property_add_bool(oc, "suppress-vmdesc",
744 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
745 &error_abort);
746 object_class_property_set_description(oc, "suppress-vmdesc",
747 "Set on to disable self-describing migration", &error_abort);
748
749 object_class_property_add_bool(oc, "enforce-config-section",
750 machine_get_enforce_config_section, machine_set_enforce_config_section,
751 &error_abort);
752 object_class_property_set_description(oc, "enforce-config-section",
753 "Set on to enforce configuration section migration", &error_abort);
754
755 object_class_property_add_str(oc, "memory-encryption",
756 machine_get_memory_encryption, machine_set_memory_encryption,
757 &error_abort);
758 object_class_property_set_description(oc, "memory-encryption",
759 "Set memory encryption object to use", &error_abort);
760 }
761
762 static void machine_class_base_init(ObjectClass *oc, void *data)
763 {
764 if (!object_class_is_abstract(oc)) {
765 MachineClass *mc = MACHINE_CLASS(oc);
766 const char *cname = object_class_get_name(oc);
767 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
768 mc->name = g_strndup(cname,
769 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
770 mc->compat_props = g_ptr_array_new();
771 }
772 }
773
774 static void machine_initfn(Object *obj)
775 {
776 MachineState *ms = MACHINE(obj);
777 MachineClass *mc = MACHINE_GET_CLASS(obj);
778
779 ms->kernel_irqchip_allowed = true;
780 ms->kernel_irqchip_split = mc->default_kernel_irqchip_split;
781 ms->kvm_shadow_mem = -1;
782 ms->dump_guest_core = true;
783 ms->mem_merge = true;
784 ms->enable_graphics = true;
785
786 /* Register notifier when init is done for sysbus sanity checks */
787 ms->sysbus_notifier.notify = machine_init_notify;
788 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
789 }
790
791 static void machine_finalize(Object *obj)
792 {
793 MachineState *ms = MACHINE(obj);
794
795 g_free(ms->accel);
796 g_free(ms->kernel_filename);
797 g_free(ms->initrd_filename);
798 g_free(ms->kernel_cmdline);
799 g_free(ms->dtb);
800 g_free(ms->dumpdtb);
801 g_free(ms->dt_compatible);
802 g_free(ms->firmware);
803 g_free(ms->device_memory);
804 }
805
806 bool machine_usb(MachineState *machine)
807 {
808 return machine->usb;
809 }
810
811 bool machine_kernel_irqchip_allowed(MachineState *machine)
812 {
813 return machine->kernel_irqchip_allowed;
814 }
815
816 bool machine_kernel_irqchip_required(MachineState *machine)
817 {
818 return machine->kernel_irqchip_required;
819 }
820
821 bool machine_kernel_irqchip_split(MachineState *machine)
822 {
823 return machine->kernel_irqchip_split;
824 }
825
826 int machine_kvm_shadow_mem(MachineState *machine)
827 {
828 return machine->kvm_shadow_mem;
829 }
830
831 int machine_phandle_start(MachineState *machine)
832 {
833 return machine->phandle_start;
834 }
835
836 bool machine_dump_guest_core(MachineState *machine)
837 {
838 return machine->dump_guest_core;
839 }
840
841 bool machine_mem_merge(MachineState *machine)
842 {
843 return machine->mem_merge;
844 }
845
846 static char *cpu_slot_to_string(const CPUArchId *cpu)
847 {
848 GString *s = g_string_new(NULL);
849 if (cpu->props.has_socket_id) {
850 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
851 }
852 if (cpu->props.has_core_id) {
853 if (s->len) {
854 g_string_append_printf(s, ", ");
855 }
856 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
857 }
858 if (cpu->props.has_thread_id) {
859 if (s->len) {
860 g_string_append_printf(s, ", ");
861 }
862 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
863 }
864 return g_string_free(s, false);
865 }
866
867 static void machine_numa_finish_cpu_init(MachineState *machine)
868 {
869 int i;
870 bool default_mapping;
871 GString *s = g_string_new(NULL);
872 MachineClass *mc = MACHINE_GET_CLASS(machine);
873 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
874
875 assert(nb_numa_nodes);
876 for (i = 0; i < possible_cpus->len; i++) {
877 if (possible_cpus->cpus[i].props.has_node_id) {
878 break;
879 }
880 }
881 default_mapping = (i == possible_cpus->len);
882
883 for (i = 0; i < possible_cpus->len; i++) {
884 const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
885
886 if (!cpu_slot->props.has_node_id) {
887 /* fetch default mapping from board and enable it */
888 CpuInstanceProperties props = cpu_slot->props;
889
890 props.node_id = mc->get_default_cpu_node_id(machine, i);
891 if (!default_mapping) {
892 /* record slots with not set mapping,
893 * TODO: make it hard error in future */
894 char *cpu_str = cpu_slot_to_string(cpu_slot);
895 g_string_append_printf(s, "%sCPU %d [%s]",
896 s->len ? ", " : "", i, cpu_str);
897 g_free(cpu_str);
898
899 /* non mapped cpus used to fallback to node 0 */
900 props.node_id = 0;
901 }
902
903 props.has_node_id = true;
904 machine_set_cpu_numa_node(machine, &props, &error_fatal);
905 }
906 }
907 if (s->len && !qtest_enabled()) {
908 warn_report("CPU(s) not present in any NUMA nodes: %s",
909 s->str);
910 warn_report("All CPU(s) up to maxcpus should be described "
911 "in NUMA config, ability to start up with partial NUMA "
912 "mappings is obsoleted and will be removed in future");
913 }
914 g_string_free(s, true);
915 }
916
917 void machine_run_board_init(MachineState *machine)
918 {
919 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
920
921 numa_complete_configuration(machine);
922 if (nb_numa_nodes) {
923 machine_numa_finish_cpu_init(machine);
924 }
925
926 /* If the machine supports the valid_cpu_types check and the user
927 * specified a CPU with -cpu check here that the user CPU is supported.
928 */
929 if (machine_class->valid_cpu_types && machine->cpu_type) {
930 ObjectClass *class = object_class_by_name(machine->cpu_type);
931 int i;
932
933 for (i = 0; machine_class->valid_cpu_types[i]; i++) {
934 if (object_class_dynamic_cast(class,
935 machine_class->valid_cpu_types[i])) {
936 /* The user specificed CPU is in the valid field, we are
937 * good to go.
938 */
939 break;
940 }
941 }
942
943 if (!machine_class->valid_cpu_types[i]) {
944 /* The user specified CPU is not valid */
945 error_report("Invalid CPU type: %s", machine->cpu_type);
946 error_printf("The valid types are: %s",
947 machine_class->valid_cpu_types[0]);
948 for (i = 1; machine_class->valid_cpu_types[i]; i++) {
949 error_printf(", %s", machine_class->valid_cpu_types[i]);
950 }
951 error_printf("\n");
952
953 exit(1);
954 }
955 }
956
957 machine_class->init(machine);
958 }
959
960 static const TypeInfo machine_info = {
961 .name = TYPE_MACHINE,
962 .parent = TYPE_OBJECT,
963 .abstract = true,
964 .class_size = sizeof(MachineClass),
965 .class_init = machine_class_init,
966 .class_base_init = machine_class_base_init,
967 .instance_size = sizeof(MachineState),
968 .instance_init = machine_initfn,
969 .instance_finalize = machine_finalize,
970 };
971
972 static void machine_register_types(void)
973 {
974 type_register_static(&machine_info);
975 }
976
977 type_init(machine_register_types)