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" },
32 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
34 GlobalProperty hw_compat_3_0
[] = {};
35 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
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" },
45 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
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" },
53 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
55 GlobalProperty hw_compat_2_10
[] = {
56 { "virtio-mouse-device", "wheel-axis", "false" },
57 { "virtio-tablet-device", "wheel-axis", "false" },
59 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
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" },
67 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
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" },
81 const size_t hw_compat_2_8_len
= G_N_ELEMENTS(hw_compat_2_8
);
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" },
90 const size_t hw_compat_2_7_len
= G_N_ELEMENTS(hw_compat_2_7
);
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" },
97 const size_t hw_compat_2_6_len
= G_N_ELEMENTS(hw_compat_2_6
);
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" },
106 const size_t hw_compat_2_5_len
= G_N_ELEMENTS(hw_compat_2_5
);
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" }
116 const size_t hw_compat_2_4_len
= G_N_ELEMENTS(hw_compat_2_4
);
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" },
129 const size_t hw_compat_2_3_len
= G_N_ELEMENTS(hw_compat_2_3
);
131 GlobalProperty hw_compat_2_2
[] = {};
132 const size_t hw_compat_2_2_len
= G_N_ELEMENTS(hw_compat_2_2
);
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" },
143 const size_t hw_compat_2_1_len
= G_N_ELEMENTS(hw_compat_2_1
);
145 static char *machine_get_accel(Object
*obj
, Error
**errp
)
147 MachineState
*ms
= MACHINE(obj
);
149 return g_strdup(ms
->accel
);
152 static void machine_set_accel(Object
*obj
, const char *value
, Error
**errp
)
154 MachineState
*ms
= MACHINE(obj
);
157 ms
->accel
= g_strdup(value
);
160 static void machine_set_kernel_irqchip(Object
*obj
, Visitor
*v
,
161 const char *name
, void *opaque
,
165 MachineState
*ms
= MACHINE(obj
);
168 visit_type_OnOffSplit(v
, name
, &mode
, &err
);
170 error_propagate(errp
, err
);
174 case ON_OFF_SPLIT_ON
:
175 ms
->kernel_irqchip_allowed
= true;
176 ms
->kernel_irqchip_required
= true;
177 ms
->kernel_irqchip_split
= false;
179 case ON_OFF_SPLIT_OFF
:
180 ms
->kernel_irqchip_allowed
= false;
181 ms
->kernel_irqchip_required
= false;
182 ms
->kernel_irqchip_split
= false;
184 case ON_OFF_SPLIT_SPLIT
:
185 ms
->kernel_irqchip_allowed
= true;
186 ms
->kernel_irqchip_required
= true;
187 ms
->kernel_irqchip_split
= true;
190 /* The value was checked in visit_type_OnOffSplit() above. If
191 * we get here, then something is wrong in QEMU.
198 static void machine_get_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
199 const char *name
, void *opaque
,
202 MachineState
*ms
= MACHINE(obj
);
203 int64_t value
= ms
->kvm_shadow_mem
;
205 visit_type_int(v
, name
, &value
, errp
);
208 static void machine_set_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
209 const char *name
, void *opaque
,
212 MachineState
*ms
= MACHINE(obj
);
216 visit_type_int(v
, name
, &value
, &error
);
218 error_propagate(errp
, error
);
222 ms
->kvm_shadow_mem
= value
;
225 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
227 MachineState
*ms
= MACHINE(obj
);
229 return g_strdup(ms
->kernel_filename
);
232 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
234 MachineState
*ms
= MACHINE(obj
);
236 g_free(ms
->kernel_filename
);
237 ms
->kernel_filename
= g_strdup(value
);
240 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
242 MachineState
*ms
= MACHINE(obj
);
244 return g_strdup(ms
->initrd_filename
);
247 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
249 MachineState
*ms
= MACHINE(obj
);
251 g_free(ms
->initrd_filename
);
252 ms
->initrd_filename
= g_strdup(value
);
255 static char *machine_get_append(Object
*obj
, Error
**errp
)
257 MachineState
*ms
= MACHINE(obj
);
259 return g_strdup(ms
->kernel_cmdline
);
262 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
264 MachineState
*ms
= MACHINE(obj
);
266 g_free(ms
->kernel_cmdline
);
267 ms
->kernel_cmdline
= g_strdup(value
);
270 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
272 MachineState
*ms
= MACHINE(obj
);
274 return g_strdup(ms
->dtb
);
277 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
279 MachineState
*ms
= MACHINE(obj
);
282 ms
->dtb
= g_strdup(value
);
285 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
287 MachineState
*ms
= MACHINE(obj
);
289 return g_strdup(ms
->dumpdtb
);
292 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
294 MachineState
*ms
= MACHINE(obj
);
297 ms
->dumpdtb
= g_strdup(value
);
300 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
301 const char *name
, void *opaque
,
304 MachineState
*ms
= MACHINE(obj
);
305 int64_t value
= ms
->phandle_start
;
307 visit_type_int(v
, name
, &value
, errp
);
310 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
311 const char *name
, void *opaque
,
314 MachineState
*ms
= MACHINE(obj
);
318 visit_type_int(v
, name
, &value
, &error
);
320 error_propagate(errp
, error
);
324 ms
->phandle_start
= value
;
327 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
329 MachineState
*ms
= MACHINE(obj
);
331 return g_strdup(ms
->dt_compatible
);
334 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
336 MachineState
*ms
= MACHINE(obj
);
338 g_free(ms
->dt_compatible
);
339 ms
->dt_compatible
= g_strdup(value
);
342 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
344 MachineState
*ms
= MACHINE(obj
);
346 return ms
->dump_guest_core
;
349 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
351 MachineState
*ms
= MACHINE(obj
);
353 ms
->dump_guest_core
= value
;
356 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
358 MachineState
*ms
= MACHINE(obj
);
360 return ms
->mem_merge
;
363 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
365 MachineState
*ms
= MACHINE(obj
);
367 ms
->mem_merge
= value
;
370 static bool machine_get_usb(Object
*obj
, Error
**errp
)
372 MachineState
*ms
= MACHINE(obj
);
377 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
379 MachineState
*ms
= MACHINE(obj
);
382 ms
->usb_disabled
= !value
;
385 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
387 MachineState
*ms
= MACHINE(obj
);
389 return ms
->enable_graphics
;
392 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
394 MachineState
*ms
= MACHINE(obj
);
396 ms
->enable_graphics
= value
;
399 static bool machine_get_igd_gfx_passthru(Object
*obj
, Error
**errp
)
401 MachineState
*ms
= MACHINE(obj
);
403 return ms
->igd_gfx_passthru
;
406 static void machine_set_igd_gfx_passthru(Object
*obj
, bool value
, Error
**errp
)
408 MachineState
*ms
= MACHINE(obj
);
410 ms
->igd_gfx_passthru
= value
;
413 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
415 MachineState
*ms
= MACHINE(obj
);
417 return g_strdup(ms
->firmware
);
420 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
422 MachineState
*ms
= MACHINE(obj
);
424 g_free(ms
->firmware
);
425 ms
->firmware
= g_strdup(value
);
428 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
430 MachineState
*ms
= MACHINE(obj
);
432 ms
->suppress_vmdesc
= value
;
435 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
437 MachineState
*ms
= MACHINE(obj
);
439 return ms
->suppress_vmdesc
;
442 static void machine_set_enforce_config_section(Object
*obj
, bool value
,
445 MachineState
*ms
= MACHINE(obj
);
447 warn_report("enforce-config-section is deprecated, please use "
448 "-global migration.send-configuration=on|off instead");
450 ms
->enforce_config_section
= value
;
453 static bool machine_get_enforce_config_section(Object
*obj
, Error
**errp
)
455 MachineState
*ms
= MACHINE(obj
);
457 return ms
->enforce_config_section
;
460 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
462 MachineState
*ms
= MACHINE(obj
);
464 return g_strdup(ms
->memory_encryption
);
467 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
470 MachineState
*ms
= MACHINE(obj
);
472 g_free(ms
->memory_encryption
);
473 ms
->memory_encryption
= g_strdup(value
);
476 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
478 strList
*item
= g_new0(strList
, 1);
480 item
->value
= g_strdup(type
);
481 item
->next
= mc
->allowed_dynamic_sysbus_devices
;
482 mc
->allowed_dynamic_sysbus_devices
= item
;
485 static void validate_sysbus_device(SysBusDevice
*sbdev
, void *opaque
)
487 MachineState
*machine
= opaque
;
488 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
489 bool allowed
= false;
492 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
495 allowed
|= !!object_dynamic_cast(OBJECT(sbdev
), wl
->value
);
499 error_report("Option '-device %s' cannot be handled by this machine",
500 object_class_get_name(object_get_class(OBJECT(sbdev
))));
505 static void machine_init_notify(Notifier
*notifier
, void *data
)
507 MachineState
*machine
= MACHINE(qdev_get_machine());
510 * Loop through all dynamically created sysbus devices and check if they are
511 * all allowed. If a device is not allowed, error out.
513 foreach_dynamic_sysbus_device(validate_sysbus_device
, machine
);
516 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
519 HotpluggableCPUList
*head
= NULL
;
520 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
522 /* force board to initialize possible_cpus if it hasn't been done yet */
523 mc
->possible_cpu_arch_ids(machine
);
525 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
527 HotpluggableCPUList
*list_item
= g_new0(typeof(*list_item
), 1);
528 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
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
));
535 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
537 cpu_item
->has_qom_path
= true;
538 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
540 list_item
->value
= cpu_item
;
541 list_item
->next
= head
;
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
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.
559 * However for CLI convenience it's possible to pass in subset of properties,
560 * which would affect all cpu slots that match it.
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.
568 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
570 * Empty subset is disallowed and function will return with error in this case.
572 void machine_set_cpu_numa_node(MachineState
*machine
,
573 const CpuInstanceProperties
*props
, Error
**errp
)
575 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
579 if (!mc
->possible_cpu_arch_ids
) {
580 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
584 /* disabling node mapping is not supported, forbid it */
585 assert(props
->has_node_id
);
587 /* force board to initialize possible_cpus if it hasn't been done yet */
588 mc
->possible_cpu_arch_ids(machine
);
590 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
591 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
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");
599 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
600 error_setg(errp
, "core-id is not supported");
604 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
605 error_setg(errp
, "socket-id is not supported");
609 /* skip slots with explicit mismatch */
610 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
614 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
618 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
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
);
632 /* assign slot to node as it's matched '-numa cpu' key */
634 slot
->props
.node_id
= props
->node_id
;
635 slot
->props
.has_node_id
= props
->has_node_id
;
639 error_setg(errp
, "no match found");
643 static void machine_class_init(ObjectClass
*oc
, void *data
)
645 MachineClass
*mc
= MACHINE_CLASS(oc
);
647 /* Default 128 MB as guest ram size */
648 mc
->default_ram_size
= 128 * MiB
;
649 mc
->rom_file_has_mr
= true;
651 /* numa node memory size aligned on 8MB by default.
652 * On Linux, each node's border has to be 8MB aligned
654 mc
->numa_mem_align_shift
= 23;
655 mc
->numa_auto_assign_ram
= numa_default_auto_assign_ram
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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",
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
);
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
);
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
);
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
);
731 object_class_property_add_bool(oc
, "igd-passthru",
732 machine_get_igd_gfx_passthru
, machine_set_igd_gfx_passthru
,
734 object_class_property_set_description(oc
, "igd-passthru",
735 "Set on/off to enable/disable igd passthrou", &error_abort
);
737 object_class_property_add_str(oc
, "firmware",
738 machine_get_firmware
, machine_set_firmware
,
740 object_class_property_set_description(oc
, "firmware",
741 "Firmware image", &error_abort
);
743 object_class_property_add_bool(oc
, "suppress-vmdesc",
744 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
,
746 object_class_property_set_description(oc
, "suppress-vmdesc",
747 "Set on to disable self-describing migration", &error_abort
);
749 object_class_property_add_bool(oc
, "enforce-config-section",
750 machine_get_enforce_config_section
, machine_set_enforce_config_section
,
752 object_class_property_set_description(oc
, "enforce-config-section",
753 "Set on to enforce configuration section migration", &error_abort
);
755 object_class_property_add_str(oc
, "memory-encryption",
756 machine_get_memory_encryption
, machine_set_memory_encryption
,
758 object_class_property_set_description(oc
, "memory-encryption",
759 "Set memory encryption object to use", &error_abort
);
762 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
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();
774 static void machine_initfn(Object
*obj
)
776 MachineState
*ms
= MACHINE(obj
);
777 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
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;
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
);
791 static void machine_finalize(Object
*obj
)
793 MachineState
*ms
= MACHINE(obj
);
796 g_free(ms
->kernel_filename
);
797 g_free(ms
->initrd_filename
);
798 g_free(ms
->kernel_cmdline
);
801 g_free(ms
->dt_compatible
);
802 g_free(ms
->firmware
);
803 g_free(ms
->device_memory
);
806 bool machine_usb(MachineState
*machine
)
811 bool machine_kernel_irqchip_allowed(MachineState
*machine
)
813 return machine
->kernel_irqchip_allowed
;
816 bool machine_kernel_irqchip_required(MachineState
*machine
)
818 return machine
->kernel_irqchip_required
;
821 bool machine_kernel_irqchip_split(MachineState
*machine
)
823 return machine
->kernel_irqchip_split
;
826 int machine_kvm_shadow_mem(MachineState
*machine
)
828 return machine
->kvm_shadow_mem
;
831 int machine_phandle_start(MachineState
*machine
)
833 return machine
->phandle_start
;
836 bool machine_dump_guest_core(MachineState
*machine
)
838 return machine
->dump_guest_core
;
841 bool machine_mem_merge(MachineState
*machine
)
843 return machine
->mem_merge
;
846 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
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
);
852 if (cpu
->props
.has_core_id
) {
854 g_string_append_printf(s
, ", ");
856 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
858 if (cpu
->props
.has_thread_id
) {
860 g_string_append_printf(s
, ", ");
862 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
864 return g_string_free(s
, false);
867 static void machine_numa_finish_cpu_init(MachineState
*machine
)
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
);
875 assert(nb_numa_nodes
);
876 for (i
= 0; i
< possible_cpus
->len
; i
++) {
877 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
881 default_mapping
= (i
== possible_cpus
->len
);
883 for (i
= 0; i
< possible_cpus
->len
; i
++) {
884 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
886 if (!cpu_slot
->props
.has_node_id
) {
887 /* fetch default mapping from board and enable it */
888 CpuInstanceProperties props
= cpu_slot
->props
;
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
);
899 /* non mapped cpus used to fallback to node 0 */
903 props
.has_node_id
= true;
904 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
907 if (s
->len
&& !qtest_enabled()) {
908 warn_report("CPU(s) not present in any NUMA nodes: %s",
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");
914 g_string_free(s
, true);
917 void machine_run_board_init(MachineState
*machine
)
919 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
921 numa_complete_configuration(machine
);
923 machine_numa_finish_cpu_init(machine
);
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.
929 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
930 ObjectClass
*class = object_class_by_name(machine
->cpu_type
);
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
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
]);
957 machine_class
->init(machine
);
960 static const TypeInfo machine_info
= {
961 .name
= TYPE_MACHINE
,
962 .parent
= TYPE_OBJECT
,
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
,
972 static void machine_register_types(void)
974 type_register_static(&machine_info
);
977 type_init(machine_register_types
)