4 * Copyright (C) 2014 Red Hat Inc
7 * Marcel Apfelbaum <marcel.a@redhat.com>
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.
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"
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 { "tpm-crb", "ppi", "false" },
32 { "tpm-tis", "ppi", "false" },
33 { "usb-kbd", "serial", "42" },
34 { "usb-mouse", "serial", "42" },
35 { "usb-kbd", "serial", "42" },
36 { "virtio-blk-device", "discard", "false" },
37 { "virtio-blk-device", "write-zeroes", "false" },
39 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
41 GlobalProperty hw_compat_3_0
[] = {};
42 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
44 GlobalProperty hw_compat_2_12
[] = {
45 { "migration", "decompress-error-check", "off" },
46 { "hda-audio", "use-timer", "false" },
47 { "cirrus-vga", "global-vmstate", "true" },
48 { "VGA", "global-vmstate", "true" },
49 { "vmware-svga", "global-vmstate", "true" },
50 { "qxl-vga", "global-vmstate", "true" },
52 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
54 GlobalProperty hw_compat_2_11
[] = {
55 { "hpet", "hpet-offset-saved", "false" },
56 { "virtio-blk-pci", "vectors", "2" },
57 { "vhost-user-blk-pci", "vectors", "2" },
58 { "e1000", "migrate_tso_props", "off" },
60 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
62 GlobalProperty hw_compat_2_10
[] = {
63 { "virtio-mouse-device", "wheel-axis", "false" },
64 { "virtio-tablet-device", "wheel-axis", "false" },
66 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
68 GlobalProperty hw_compat_2_9
[] = {
69 { "pci-bridge", "shpc", "off" },
70 { "intel-iommu", "pt", "off" },
71 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
72 { "pcie-root-port", "x-migrate-msix", "false" },
74 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
76 GlobalProperty hw_compat_2_8
[] = {
77 { "fw_cfg_mem", "x-file-slots", "0x10" },
78 { "fw_cfg_io", "x-file-slots", "0x10" },
79 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
80 { "pci-bridge", "shpc", "on" },
81 { TYPE_PCI_DEVICE
, "x-pcie-extcap-init", "off" },
82 { "virtio-pci", "x-pcie-deverr-init", "off" },
83 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
84 { "virtio-pci", "x-pcie-pm-init", "off" },
85 { "cirrus-vga", "vgamem_mb", "8" },
86 { "isa-cirrus-vga", "vgamem_mb", "8" },
88 const size_t hw_compat_2_8_len
= G_N_ELEMENTS(hw_compat_2_8
);
90 GlobalProperty hw_compat_2_7
[] = {
91 { "virtio-pci", "page-per-vq", "on" },
92 { "virtio-serial-device", "emergency-write", "off" },
93 { "ioapic", "version", "0x11" },
94 { "intel-iommu", "x-buggy-eim", "true" },
95 { "virtio-pci", "x-ignore-backend-features", "on" },
97 const size_t hw_compat_2_7_len
= G_N_ELEMENTS(hw_compat_2_7
);
99 GlobalProperty hw_compat_2_6
[] = {
100 { "virtio-mmio", "format_transport_address", "off" },
101 /* Optional because not all virtio-pci devices support legacy mode */
102 { "virtio-pci", "disable-modern", "on", .optional
= true },
103 { "virtio-pci", "disable-legacy", "off", .optional
= true },
105 const size_t hw_compat_2_6_len
= G_N_ELEMENTS(hw_compat_2_6
);
107 GlobalProperty hw_compat_2_5
[] = {
108 { "isa-fdc", "fallback", "144" },
109 { "pvscsi", "x-old-pci-configuration", "on" },
110 { "pvscsi", "x-disable-pcie", "on" },
111 { "vmxnet3", "x-old-msi-offsets", "on" },
112 { "vmxnet3", "x-disable-pcie", "on" },
114 const size_t hw_compat_2_5_len
= G_N_ELEMENTS(hw_compat_2_5
);
116 GlobalProperty hw_compat_2_4
[] = {
117 { "virtio-blk-device", "scsi", "true" },
118 { "e1000", "extra_mac_registers", "off" },
119 { "virtio-pci", "x-disable-pcie", "on" },
120 { "virtio-pci", "migrate-extra", "off" },
121 { "fw_cfg_mem", "dma_enabled", "off" },
122 { "fw_cfg_io", "dma_enabled", "off" }
124 const size_t hw_compat_2_4_len
= G_N_ELEMENTS(hw_compat_2_4
);
126 GlobalProperty hw_compat_2_3
[] = {
127 { "virtio-blk-pci", "any_layout", "off" },
128 { "virtio-balloon-pci", "any_layout", "off" },
129 { "virtio-serial-pci", "any_layout", "off" },
130 { "virtio-9p-pci", "any_layout", "off" },
131 { "virtio-rng-pci", "any_layout", "off" },
132 { TYPE_PCI_DEVICE
, "x-pcie-lnksta-dllla", "off" },
133 { "migration", "send-configuration", "off" },
134 { "migration", "send-section-footer", "off" },
135 { "migration", "store-global-state", "off" },
137 const size_t hw_compat_2_3_len
= G_N_ELEMENTS(hw_compat_2_3
);
139 GlobalProperty hw_compat_2_2
[] = {};
140 const size_t hw_compat_2_2_len
= G_N_ELEMENTS(hw_compat_2_2
);
142 GlobalProperty hw_compat_2_1
[] = {
143 { "intel-hda", "old_msi_addr", "on" },
144 { "VGA", "qemu-extended-regs", "off" },
145 { "secondary-vga", "qemu-extended-regs", "off" },
146 { "virtio-scsi-pci", "any_layout", "off" },
147 { "usb-mouse", "usb_version", "1" },
148 { "usb-kbd", "usb_version", "1" },
149 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
151 const size_t hw_compat_2_1_len
= G_N_ELEMENTS(hw_compat_2_1
);
153 static char *machine_get_accel(Object
*obj
, Error
**errp
)
155 MachineState
*ms
= MACHINE(obj
);
157 return g_strdup(ms
->accel
);
160 static void machine_set_accel(Object
*obj
, const char *value
, Error
**errp
)
162 MachineState
*ms
= MACHINE(obj
);
165 ms
->accel
= g_strdup(value
);
168 static void machine_set_kernel_irqchip(Object
*obj
, Visitor
*v
,
169 const char *name
, void *opaque
,
173 MachineState
*ms
= MACHINE(obj
);
176 visit_type_OnOffSplit(v
, name
, &mode
, &err
);
178 error_propagate(errp
, err
);
182 case ON_OFF_SPLIT_ON
:
183 ms
->kernel_irqchip_allowed
= true;
184 ms
->kernel_irqchip_required
= true;
185 ms
->kernel_irqchip_split
= false;
187 case ON_OFF_SPLIT_OFF
:
188 ms
->kernel_irqchip_allowed
= false;
189 ms
->kernel_irqchip_required
= false;
190 ms
->kernel_irqchip_split
= false;
192 case ON_OFF_SPLIT_SPLIT
:
193 ms
->kernel_irqchip_allowed
= true;
194 ms
->kernel_irqchip_required
= true;
195 ms
->kernel_irqchip_split
= true;
198 /* The value was checked in visit_type_OnOffSplit() above. If
199 * we get here, then something is wrong in QEMU.
206 static void machine_get_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
207 const char *name
, void *opaque
,
210 MachineState
*ms
= MACHINE(obj
);
211 int64_t value
= ms
->kvm_shadow_mem
;
213 visit_type_int(v
, name
, &value
, errp
);
216 static void machine_set_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
217 const char *name
, void *opaque
,
220 MachineState
*ms
= MACHINE(obj
);
224 visit_type_int(v
, name
, &value
, &error
);
226 error_propagate(errp
, error
);
230 ms
->kvm_shadow_mem
= value
;
233 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
235 MachineState
*ms
= MACHINE(obj
);
237 return g_strdup(ms
->kernel_filename
);
240 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
242 MachineState
*ms
= MACHINE(obj
);
244 g_free(ms
->kernel_filename
);
245 ms
->kernel_filename
= g_strdup(value
);
248 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
250 MachineState
*ms
= MACHINE(obj
);
252 return g_strdup(ms
->initrd_filename
);
255 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
257 MachineState
*ms
= MACHINE(obj
);
259 g_free(ms
->initrd_filename
);
260 ms
->initrd_filename
= g_strdup(value
);
263 static char *machine_get_append(Object
*obj
, Error
**errp
)
265 MachineState
*ms
= MACHINE(obj
);
267 return g_strdup(ms
->kernel_cmdline
);
270 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
272 MachineState
*ms
= MACHINE(obj
);
274 g_free(ms
->kernel_cmdline
);
275 ms
->kernel_cmdline
= g_strdup(value
);
278 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
280 MachineState
*ms
= MACHINE(obj
);
282 return g_strdup(ms
->dtb
);
285 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
287 MachineState
*ms
= MACHINE(obj
);
290 ms
->dtb
= g_strdup(value
);
293 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
295 MachineState
*ms
= MACHINE(obj
);
297 return g_strdup(ms
->dumpdtb
);
300 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
302 MachineState
*ms
= MACHINE(obj
);
305 ms
->dumpdtb
= g_strdup(value
);
308 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
309 const char *name
, void *opaque
,
312 MachineState
*ms
= MACHINE(obj
);
313 int64_t value
= ms
->phandle_start
;
315 visit_type_int(v
, name
, &value
, errp
);
318 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
319 const char *name
, void *opaque
,
322 MachineState
*ms
= MACHINE(obj
);
326 visit_type_int(v
, name
, &value
, &error
);
328 error_propagate(errp
, error
);
332 ms
->phandle_start
= value
;
335 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
337 MachineState
*ms
= MACHINE(obj
);
339 return g_strdup(ms
->dt_compatible
);
342 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
344 MachineState
*ms
= MACHINE(obj
);
346 g_free(ms
->dt_compatible
);
347 ms
->dt_compatible
= g_strdup(value
);
350 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
352 MachineState
*ms
= MACHINE(obj
);
354 return ms
->dump_guest_core
;
357 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
359 MachineState
*ms
= MACHINE(obj
);
361 ms
->dump_guest_core
= value
;
364 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
366 MachineState
*ms
= MACHINE(obj
);
368 return ms
->mem_merge
;
371 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
373 MachineState
*ms
= MACHINE(obj
);
375 ms
->mem_merge
= value
;
378 static bool machine_get_usb(Object
*obj
, Error
**errp
)
380 MachineState
*ms
= MACHINE(obj
);
385 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
387 MachineState
*ms
= MACHINE(obj
);
390 ms
->usb_disabled
= !value
;
393 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
395 MachineState
*ms
= MACHINE(obj
);
397 return ms
->enable_graphics
;
400 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
402 MachineState
*ms
= MACHINE(obj
);
404 ms
->enable_graphics
= value
;
407 static bool machine_get_igd_gfx_passthru(Object
*obj
, Error
**errp
)
409 MachineState
*ms
= MACHINE(obj
);
411 return ms
->igd_gfx_passthru
;
414 static void machine_set_igd_gfx_passthru(Object
*obj
, bool value
, Error
**errp
)
416 MachineState
*ms
= MACHINE(obj
);
418 ms
->igd_gfx_passthru
= value
;
421 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
423 MachineState
*ms
= MACHINE(obj
);
425 return g_strdup(ms
->firmware
);
428 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
430 MachineState
*ms
= MACHINE(obj
);
432 g_free(ms
->firmware
);
433 ms
->firmware
= g_strdup(value
);
436 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
438 MachineState
*ms
= MACHINE(obj
);
440 ms
->suppress_vmdesc
= value
;
443 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
445 MachineState
*ms
= MACHINE(obj
);
447 return ms
->suppress_vmdesc
;
450 static void machine_set_enforce_config_section(Object
*obj
, bool value
,
453 MachineState
*ms
= MACHINE(obj
);
455 warn_report("enforce-config-section is deprecated, please use "
456 "-global migration.send-configuration=on|off instead");
458 ms
->enforce_config_section
= value
;
461 static bool machine_get_enforce_config_section(Object
*obj
, Error
**errp
)
463 MachineState
*ms
= MACHINE(obj
);
465 return ms
->enforce_config_section
;
468 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
470 MachineState
*ms
= MACHINE(obj
);
472 return g_strdup(ms
->memory_encryption
);
475 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
478 MachineState
*ms
= MACHINE(obj
);
480 g_free(ms
->memory_encryption
);
481 ms
->memory_encryption
= g_strdup(value
);
484 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
486 strList
*item
= g_new0(strList
, 1);
488 item
->value
= g_strdup(type
);
489 item
->next
= mc
->allowed_dynamic_sysbus_devices
;
490 mc
->allowed_dynamic_sysbus_devices
= item
;
493 static void validate_sysbus_device(SysBusDevice
*sbdev
, void *opaque
)
495 MachineState
*machine
= opaque
;
496 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
497 bool allowed
= false;
500 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
503 allowed
|= !!object_dynamic_cast(OBJECT(sbdev
), wl
->value
);
507 error_report("Option '-device %s' cannot be handled by this machine",
508 object_class_get_name(object_get_class(OBJECT(sbdev
))));
513 static void machine_init_notify(Notifier
*notifier
, void *data
)
515 MachineState
*machine
= MACHINE(qdev_get_machine());
518 * Loop through all dynamically created sysbus devices and check if they are
519 * all allowed. If a device is not allowed, error out.
521 foreach_dynamic_sysbus_device(validate_sysbus_device
, machine
);
524 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
527 HotpluggableCPUList
*head
= NULL
;
528 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
530 /* force board to initialize possible_cpus if it hasn't been done yet */
531 mc
->possible_cpu_arch_ids(machine
);
533 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
535 HotpluggableCPUList
*list_item
= g_new0(typeof(*list_item
), 1);
536 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
538 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
539 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
540 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
541 sizeof(*cpu_item
->props
));
543 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
545 cpu_item
->has_qom_path
= true;
546 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
548 list_item
->value
= cpu_item
;
549 list_item
->next
= head
;
556 * machine_set_cpu_numa_node:
557 * @machine: machine object to modify
558 * @props: specifies which cpu objects to assign to
559 * numa node specified by @props.node_id
560 * @errp: if an error occurs, a pointer to an area to store the error
562 * Associate NUMA node specified by @props.node_id with cpu slots that
563 * match socket/core/thread-ids specified by @props. It's recommended to use
564 * query-hotpluggable-cpus.props values to specify affected cpu slots,
565 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
567 * However for CLI convenience it's possible to pass in subset of properties,
568 * which would affect all cpu slots that match it.
570 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
571 * -numa cpu,node-id=0,socket_id=0 \
572 * -numa cpu,node-id=1,socket_id=1
573 * will assign all child cores of socket 0 to node 0 and
574 * of socket 1 to node 1.
576 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
578 * Empty subset is disallowed and function will return with error in this case.
580 void machine_set_cpu_numa_node(MachineState
*machine
,
581 const CpuInstanceProperties
*props
, Error
**errp
)
583 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
587 if (!mc
->possible_cpu_arch_ids
) {
588 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
592 /* disabling node mapping is not supported, forbid it */
593 assert(props
->has_node_id
);
595 /* force board to initialize possible_cpus if it hasn't been done yet */
596 mc
->possible_cpu_arch_ids(machine
);
598 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
599 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
601 /* reject unsupported by board properties */
602 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
603 error_setg(errp
, "thread-id is not supported");
607 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
608 error_setg(errp
, "core-id is not supported");
612 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
613 error_setg(errp
, "socket-id is not supported");
617 /* skip slots with explicit mismatch */
618 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
622 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
626 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
630 /* reject assignment if slot is already assigned, for compatibility
631 * of legacy cpu_index mapping with SPAPR core based mapping do not
632 * error out if cpu thread and matched core have the same node-id */
633 if (slot
->props
.has_node_id
&&
634 slot
->props
.node_id
!= props
->node_id
) {
635 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
636 slot
->props
.node_id
);
640 /* assign slot to node as it's matched '-numa cpu' key */
642 slot
->props
.node_id
= props
->node_id
;
643 slot
->props
.has_node_id
= props
->has_node_id
;
647 error_setg(errp
, "no match found");
651 static void machine_class_init(ObjectClass
*oc
, void *data
)
653 MachineClass
*mc
= MACHINE_CLASS(oc
);
655 /* Default 128 MB as guest ram size */
656 mc
->default_ram_size
= 128 * MiB
;
657 mc
->rom_file_has_mr
= true;
659 /* numa node memory size aligned on 8MB by default.
660 * On Linux, each node's border has to be 8MB aligned
662 mc
->numa_mem_align_shift
= 23;
663 mc
->numa_auto_assign_ram
= numa_default_auto_assign_ram
;
665 object_class_property_add_str(oc
, "accel",
666 machine_get_accel
, machine_set_accel
, &error_abort
);
667 object_class_property_set_description(oc
, "accel",
668 "Accelerator list", &error_abort
);
670 object_class_property_add(oc
, "kernel-irqchip", "on|off|split",
671 NULL
, machine_set_kernel_irqchip
,
672 NULL
, NULL
, &error_abort
);
673 object_class_property_set_description(oc
, "kernel-irqchip",
674 "Configure KVM in-kernel irqchip", &error_abort
);
676 object_class_property_add(oc
, "kvm-shadow-mem", "int",
677 machine_get_kvm_shadow_mem
, machine_set_kvm_shadow_mem
,
678 NULL
, NULL
, &error_abort
);
679 object_class_property_set_description(oc
, "kvm-shadow-mem",
680 "KVM shadow MMU size", &error_abort
);
682 object_class_property_add_str(oc
, "kernel",
683 machine_get_kernel
, machine_set_kernel
, &error_abort
);
684 object_class_property_set_description(oc
, "kernel",
685 "Linux kernel image file", &error_abort
);
687 object_class_property_add_str(oc
, "initrd",
688 machine_get_initrd
, machine_set_initrd
, &error_abort
);
689 object_class_property_set_description(oc
, "initrd",
690 "Linux initial ramdisk file", &error_abort
);
692 object_class_property_add_str(oc
, "append",
693 machine_get_append
, machine_set_append
, &error_abort
);
694 object_class_property_set_description(oc
, "append",
695 "Linux kernel command line", &error_abort
);
697 object_class_property_add_str(oc
, "dtb",
698 machine_get_dtb
, machine_set_dtb
, &error_abort
);
699 object_class_property_set_description(oc
, "dtb",
700 "Linux kernel device tree file", &error_abort
);
702 object_class_property_add_str(oc
, "dumpdtb",
703 machine_get_dumpdtb
, machine_set_dumpdtb
, &error_abort
);
704 object_class_property_set_description(oc
, "dumpdtb",
705 "Dump current dtb to a file and quit", &error_abort
);
707 object_class_property_add(oc
, "phandle-start", "int",
708 machine_get_phandle_start
, machine_set_phandle_start
,
709 NULL
, NULL
, &error_abort
);
710 object_class_property_set_description(oc
, "phandle-start",
711 "The first phandle ID we may generate dynamically", &error_abort
);
713 object_class_property_add_str(oc
, "dt-compatible",
714 machine_get_dt_compatible
, machine_set_dt_compatible
, &error_abort
);
715 object_class_property_set_description(oc
, "dt-compatible",
716 "Overrides the \"compatible\" property of the dt root node",
719 object_class_property_add_bool(oc
, "dump-guest-core",
720 machine_get_dump_guest_core
, machine_set_dump_guest_core
, &error_abort
);
721 object_class_property_set_description(oc
, "dump-guest-core",
722 "Include guest memory in a core dump", &error_abort
);
724 object_class_property_add_bool(oc
, "mem-merge",
725 machine_get_mem_merge
, machine_set_mem_merge
, &error_abort
);
726 object_class_property_set_description(oc
, "mem-merge",
727 "Enable/disable memory merge support", &error_abort
);
729 object_class_property_add_bool(oc
, "usb",
730 machine_get_usb
, machine_set_usb
, &error_abort
);
731 object_class_property_set_description(oc
, "usb",
732 "Set on/off to enable/disable usb", &error_abort
);
734 object_class_property_add_bool(oc
, "graphics",
735 machine_get_graphics
, machine_set_graphics
, &error_abort
);
736 object_class_property_set_description(oc
, "graphics",
737 "Set on/off to enable/disable graphics emulation", &error_abort
);
739 object_class_property_add_bool(oc
, "igd-passthru",
740 machine_get_igd_gfx_passthru
, machine_set_igd_gfx_passthru
,
742 object_class_property_set_description(oc
, "igd-passthru",
743 "Set on/off to enable/disable igd passthrou", &error_abort
);
745 object_class_property_add_str(oc
, "firmware",
746 machine_get_firmware
, machine_set_firmware
,
748 object_class_property_set_description(oc
, "firmware",
749 "Firmware image", &error_abort
);
751 object_class_property_add_bool(oc
, "suppress-vmdesc",
752 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
,
754 object_class_property_set_description(oc
, "suppress-vmdesc",
755 "Set on to disable self-describing migration", &error_abort
);
757 object_class_property_add_bool(oc
, "enforce-config-section",
758 machine_get_enforce_config_section
, machine_set_enforce_config_section
,
760 object_class_property_set_description(oc
, "enforce-config-section",
761 "Set on to enforce configuration section migration", &error_abort
);
763 object_class_property_add_str(oc
, "memory-encryption",
764 machine_get_memory_encryption
, machine_set_memory_encryption
,
766 object_class_property_set_description(oc
, "memory-encryption",
767 "Set memory encryption object to use", &error_abort
);
770 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
772 if (!object_class_is_abstract(oc
)) {
773 MachineClass
*mc
= MACHINE_CLASS(oc
);
774 const char *cname
= object_class_get_name(oc
);
775 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
776 mc
->name
= g_strndup(cname
,
777 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
778 mc
->compat_props
= g_ptr_array_new();
782 static void machine_initfn(Object
*obj
)
784 MachineState
*ms
= MACHINE(obj
);
785 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
787 ms
->kernel_irqchip_allowed
= true;
788 ms
->kernel_irqchip_split
= mc
->default_kernel_irqchip_split
;
789 ms
->kvm_shadow_mem
= -1;
790 ms
->dump_guest_core
= true;
791 ms
->mem_merge
= true;
792 ms
->enable_graphics
= true;
794 /* Register notifier when init is done for sysbus sanity checks */
795 ms
->sysbus_notifier
.notify
= machine_init_notify
;
796 qemu_add_machine_init_done_notifier(&ms
->sysbus_notifier
);
799 static void machine_finalize(Object
*obj
)
801 MachineState
*ms
= MACHINE(obj
);
804 g_free(ms
->kernel_filename
);
805 g_free(ms
->initrd_filename
);
806 g_free(ms
->kernel_cmdline
);
809 g_free(ms
->dt_compatible
);
810 g_free(ms
->firmware
);
811 g_free(ms
->device_memory
);
814 bool machine_usb(MachineState
*machine
)
819 bool machine_kernel_irqchip_allowed(MachineState
*machine
)
821 return machine
->kernel_irqchip_allowed
;
824 bool machine_kernel_irqchip_required(MachineState
*machine
)
826 return machine
->kernel_irqchip_required
;
829 bool machine_kernel_irqchip_split(MachineState
*machine
)
831 return machine
->kernel_irqchip_split
;
834 int machine_kvm_shadow_mem(MachineState
*machine
)
836 return machine
->kvm_shadow_mem
;
839 int machine_phandle_start(MachineState
*machine
)
841 return machine
->phandle_start
;
844 bool machine_dump_guest_core(MachineState
*machine
)
846 return machine
->dump_guest_core
;
849 bool machine_mem_merge(MachineState
*machine
)
851 return machine
->mem_merge
;
854 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
856 GString
*s
= g_string_new(NULL
);
857 if (cpu
->props
.has_socket_id
) {
858 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
860 if (cpu
->props
.has_core_id
) {
862 g_string_append_printf(s
, ", ");
864 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
866 if (cpu
->props
.has_thread_id
) {
868 g_string_append_printf(s
, ", ");
870 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
872 return g_string_free(s
, false);
875 static void machine_numa_finish_cpu_init(MachineState
*machine
)
878 bool default_mapping
;
879 GString
*s
= g_string_new(NULL
);
880 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
881 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
883 assert(nb_numa_nodes
);
884 for (i
= 0; i
< possible_cpus
->len
; i
++) {
885 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
889 default_mapping
= (i
== possible_cpus
->len
);
891 for (i
= 0; i
< possible_cpus
->len
; i
++) {
892 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
894 if (!cpu_slot
->props
.has_node_id
) {
895 /* fetch default mapping from board and enable it */
896 CpuInstanceProperties props
= cpu_slot
->props
;
898 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
899 if (!default_mapping
) {
900 /* record slots with not set mapping,
901 * TODO: make it hard error in future */
902 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
903 g_string_append_printf(s
, "%sCPU %d [%s]",
904 s
->len
? ", " : "", i
, cpu_str
);
907 /* non mapped cpus used to fallback to node 0 */
911 props
.has_node_id
= true;
912 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
915 if (s
->len
&& !qtest_enabled()) {
916 warn_report("CPU(s) not present in any NUMA nodes: %s",
918 warn_report("All CPU(s) up to maxcpus should be described "
919 "in NUMA config, ability to start up with partial NUMA "
920 "mappings is obsoleted and will be removed in future");
922 g_string_free(s
, true);
925 void machine_run_board_init(MachineState
*machine
)
927 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
929 numa_complete_configuration(machine
);
931 machine_numa_finish_cpu_init(machine
);
934 /* If the machine supports the valid_cpu_types check and the user
935 * specified a CPU with -cpu check here that the user CPU is supported.
937 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
938 ObjectClass
*class = object_class_by_name(machine
->cpu_type
);
941 for (i
= 0; machine_class
->valid_cpu_types
[i
]; i
++) {
942 if (object_class_dynamic_cast(class,
943 machine_class
->valid_cpu_types
[i
])) {
944 /* The user specificed CPU is in the valid field, we are
951 if (!machine_class
->valid_cpu_types
[i
]) {
952 /* The user specified CPU is not valid */
953 error_report("Invalid CPU type: %s", machine
->cpu_type
);
954 error_printf("The valid types are: %s",
955 machine_class
->valid_cpu_types
[0]);
956 for (i
= 1; machine_class
->valid_cpu_types
[i
]; i
++) {
957 error_printf(", %s", machine_class
->valid_cpu_types
[i
]);
965 machine_class
->init(machine
);
968 static const TypeInfo machine_info
= {
969 .name
= TYPE_MACHINE
,
970 .parent
= TYPE_OBJECT
,
972 .class_size
= sizeof(MachineClass
),
973 .class_init
= machine_class_init
,
974 .class_base_init
= machine_class_base_init
,
975 .instance_size
= sizeof(MachineState
),
976 .instance_init
= machine_initfn
,
977 .instance_finalize
= machine_finalize
,
980 static void machine_register_types(void)
982 type_register_static(&machine_info
);
985 type_init(machine_register_types
)