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"
25 #include "hw/mem/nvdimm.h"
27 GlobalProperty hw_compat_4_0
[] = {
28 { "VGA", "edid", "false" },
29 { "secondary-vga", "edid", "false" },
30 { "bochs-display", "edid", "false" },
31 { "virtio-vga", "edid", "false" },
32 { "virtio-gpu-pci", "edid", "false" },
33 { "virtio-device", "use-started", "false" },
35 const size_t hw_compat_4_0_len
= G_N_ELEMENTS(hw_compat_4_0
);
37 GlobalProperty hw_compat_3_1
[] = {
38 { "pcie-root-port", "x-speed", "2_5" },
39 { "pcie-root-port", "x-width", "1" },
40 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
41 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
42 { "tpm-crb", "ppi", "false" },
43 { "tpm-tis", "ppi", "false" },
44 { "usb-kbd", "serial", "42" },
45 { "usb-mouse", "serial", "42" },
46 { "usb-tablet", "serial", "42" },
47 { "virtio-blk-device", "discard", "false" },
48 { "virtio-blk-device", "write-zeroes", "false" },
50 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
52 GlobalProperty hw_compat_3_0
[] = {};
53 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
55 GlobalProperty hw_compat_2_12
[] = {
56 { "migration", "decompress-error-check", "off" },
57 { "hda-audio", "use-timer", "false" },
58 { "cirrus-vga", "global-vmstate", "true" },
59 { "VGA", "global-vmstate", "true" },
60 { "vmware-svga", "global-vmstate", "true" },
61 { "qxl-vga", "global-vmstate", "true" },
63 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
65 GlobalProperty hw_compat_2_11
[] = {
66 { "hpet", "hpet-offset-saved", "false" },
67 { "virtio-blk-pci", "vectors", "2" },
68 { "vhost-user-blk-pci", "vectors", "2" },
69 { "e1000", "migrate_tso_props", "off" },
71 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
73 GlobalProperty hw_compat_2_10
[] = {
74 { "virtio-mouse-device", "wheel-axis", "false" },
75 { "virtio-tablet-device", "wheel-axis", "false" },
77 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
79 GlobalProperty hw_compat_2_9
[] = {
80 { "pci-bridge", "shpc", "off" },
81 { "intel-iommu", "pt", "off" },
82 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
83 { "pcie-root-port", "x-migrate-msix", "false" },
85 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
87 GlobalProperty hw_compat_2_8
[] = {
88 { "fw_cfg_mem", "x-file-slots", "0x10" },
89 { "fw_cfg_io", "x-file-slots", "0x10" },
90 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
91 { "pci-bridge", "shpc", "on" },
92 { TYPE_PCI_DEVICE
, "x-pcie-extcap-init", "off" },
93 { "virtio-pci", "x-pcie-deverr-init", "off" },
94 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
95 { "virtio-pci", "x-pcie-pm-init", "off" },
96 { "cirrus-vga", "vgamem_mb", "8" },
97 { "isa-cirrus-vga", "vgamem_mb", "8" },
99 const size_t hw_compat_2_8_len
= G_N_ELEMENTS(hw_compat_2_8
);
101 GlobalProperty hw_compat_2_7
[] = {
102 { "virtio-pci", "page-per-vq", "on" },
103 { "virtio-serial-device", "emergency-write", "off" },
104 { "ioapic", "version", "0x11" },
105 { "intel-iommu", "x-buggy-eim", "true" },
106 { "virtio-pci", "x-ignore-backend-features", "on" },
108 const size_t hw_compat_2_7_len
= G_N_ELEMENTS(hw_compat_2_7
);
110 GlobalProperty hw_compat_2_6
[] = {
111 { "virtio-mmio", "format_transport_address", "off" },
113 * don't include devices which are modern-only
114 * ie keyboard, mouse, tablet, gpu, vga & crypto
116 { "virtio-9p-pci", "disable-modern", "on" },
117 { "virtio-9p-pci", "disable-legacy", "off" },
118 { "virtio-balloon-pci", "disable-modern", "on" },
119 { "virtio-balloon-pci", "disable-legacy", "off" },
120 { "virtio-blk-pci", "disable-modern", "on" },
121 { "virtio-blk-pci", "disable-legacy", "off" },
122 { "virtio-input-host-pci", "disable-modern", "on" },
123 { "virtio-input-host-pci", "disable-legacy", "off" },
124 { "virtio-net-pci", "disable-modern", "on" },
125 { "virtio-net-pci", "disable-legacy", "off" },
126 { "virtio-rng-pci", "disable-modern", "on" },
127 { "virtio-rng-pci", "disable-legacy", "off" },
128 { "virtio-scsi-pci", "disable-modern", "on" },
129 { "virtio-scsi-pci", "disable-legacy", "off" },
130 { "virtio-serial-pci", "disable-modern", "on" },
131 { "virtio-serial-pci", "disable-legacy", "off" },
133 const size_t hw_compat_2_6_len
= G_N_ELEMENTS(hw_compat_2_6
);
135 GlobalProperty hw_compat_2_5
[] = {
136 { "isa-fdc", "fallback", "144" },
137 { "pvscsi", "x-old-pci-configuration", "on" },
138 { "pvscsi", "x-disable-pcie", "on" },
139 { "vmxnet3", "x-old-msi-offsets", "on" },
140 { "vmxnet3", "x-disable-pcie", "on" },
142 const size_t hw_compat_2_5_len
= G_N_ELEMENTS(hw_compat_2_5
);
144 GlobalProperty hw_compat_2_4
[] = {
145 { "virtio-blk-device", "scsi", "true" },
146 { "e1000", "extra_mac_registers", "off" },
147 { "virtio-pci", "x-disable-pcie", "on" },
148 { "virtio-pci", "migrate-extra", "off" },
149 { "fw_cfg_mem", "dma_enabled", "off" },
150 { "fw_cfg_io", "dma_enabled", "off" }
152 const size_t hw_compat_2_4_len
= G_N_ELEMENTS(hw_compat_2_4
);
154 GlobalProperty hw_compat_2_3
[] = {
155 { "virtio-blk-pci", "any_layout", "off" },
156 { "virtio-balloon-pci", "any_layout", "off" },
157 { "virtio-serial-pci", "any_layout", "off" },
158 { "virtio-9p-pci", "any_layout", "off" },
159 { "virtio-rng-pci", "any_layout", "off" },
160 { TYPE_PCI_DEVICE
, "x-pcie-lnksta-dllla", "off" },
161 { "migration", "send-configuration", "off" },
162 { "migration", "send-section-footer", "off" },
163 { "migration", "store-global-state", "off" },
165 const size_t hw_compat_2_3_len
= G_N_ELEMENTS(hw_compat_2_3
);
167 GlobalProperty hw_compat_2_2
[] = {};
168 const size_t hw_compat_2_2_len
= G_N_ELEMENTS(hw_compat_2_2
);
170 GlobalProperty hw_compat_2_1
[] = {
171 { "intel-hda", "old_msi_addr", "on" },
172 { "VGA", "qemu-extended-regs", "off" },
173 { "secondary-vga", "qemu-extended-regs", "off" },
174 { "virtio-scsi-pci", "any_layout", "off" },
175 { "usb-mouse", "usb_version", "1" },
176 { "usb-kbd", "usb_version", "1" },
177 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
179 const size_t hw_compat_2_1_len
= G_N_ELEMENTS(hw_compat_2_1
);
181 static char *machine_get_accel(Object
*obj
, Error
**errp
)
183 MachineState
*ms
= MACHINE(obj
);
185 return g_strdup(ms
->accel
);
188 static void machine_set_accel(Object
*obj
, const char *value
, Error
**errp
)
190 MachineState
*ms
= MACHINE(obj
);
193 ms
->accel
= g_strdup(value
);
196 static void machine_set_kernel_irqchip(Object
*obj
, Visitor
*v
,
197 const char *name
, void *opaque
,
201 MachineState
*ms
= MACHINE(obj
);
204 visit_type_OnOffSplit(v
, name
, &mode
, &err
);
206 error_propagate(errp
, err
);
210 case ON_OFF_SPLIT_ON
:
211 ms
->kernel_irqchip_allowed
= true;
212 ms
->kernel_irqchip_required
= true;
213 ms
->kernel_irqchip_split
= false;
215 case ON_OFF_SPLIT_OFF
:
216 ms
->kernel_irqchip_allowed
= false;
217 ms
->kernel_irqchip_required
= false;
218 ms
->kernel_irqchip_split
= false;
220 case ON_OFF_SPLIT_SPLIT
:
221 ms
->kernel_irqchip_allowed
= true;
222 ms
->kernel_irqchip_required
= true;
223 ms
->kernel_irqchip_split
= true;
226 /* The value was checked in visit_type_OnOffSplit() above. If
227 * we get here, then something is wrong in QEMU.
234 static void machine_get_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
235 const char *name
, void *opaque
,
238 MachineState
*ms
= MACHINE(obj
);
239 int64_t value
= ms
->kvm_shadow_mem
;
241 visit_type_int(v
, name
, &value
, errp
);
244 static void machine_set_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
245 const char *name
, void *opaque
,
248 MachineState
*ms
= MACHINE(obj
);
252 visit_type_int(v
, name
, &value
, &error
);
254 error_propagate(errp
, error
);
258 ms
->kvm_shadow_mem
= value
;
261 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
263 MachineState
*ms
= MACHINE(obj
);
265 return g_strdup(ms
->kernel_filename
);
268 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
270 MachineState
*ms
= MACHINE(obj
);
272 g_free(ms
->kernel_filename
);
273 ms
->kernel_filename
= g_strdup(value
);
276 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
278 MachineState
*ms
= MACHINE(obj
);
280 return g_strdup(ms
->initrd_filename
);
283 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
285 MachineState
*ms
= MACHINE(obj
);
287 g_free(ms
->initrd_filename
);
288 ms
->initrd_filename
= g_strdup(value
);
291 static char *machine_get_append(Object
*obj
, Error
**errp
)
293 MachineState
*ms
= MACHINE(obj
);
295 return g_strdup(ms
->kernel_cmdline
);
298 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
300 MachineState
*ms
= MACHINE(obj
);
302 g_free(ms
->kernel_cmdline
);
303 ms
->kernel_cmdline
= g_strdup(value
);
306 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
308 MachineState
*ms
= MACHINE(obj
);
310 return g_strdup(ms
->dtb
);
313 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
315 MachineState
*ms
= MACHINE(obj
);
318 ms
->dtb
= g_strdup(value
);
321 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
323 MachineState
*ms
= MACHINE(obj
);
325 return g_strdup(ms
->dumpdtb
);
328 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
330 MachineState
*ms
= MACHINE(obj
);
333 ms
->dumpdtb
= g_strdup(value
);
336 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
337 const char *name
, void *opaque
,
340 MachineState
*ms
= MACHINE(obj
);
341 int64_t value
= ms
->phandle_start
;
343 visit_type_int(v
, name
, &value
, errp
);
346 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
347 const char *name
, void *opaque
,
350 MachineState
*ms
= MACHINE(obj
);
354 visit_type_int(v
, name
, &value
, &error
);
356 error_propagate(errp
, error
);
360 ms
->phandle_start
= value
;
363 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
365 MachineState
*ms
= MACHINE(obj
);
367 return g_strdup(ms
->dt_compatible
);
370 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
372 MachineState
*ms
= MACHINE(obj
);
374 g_free(ms
->dt_compatible
);
375 ms
->dt_compatible
= g_strdup(value
);
378 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
380 MachineState
*ms
= MACHINE(obj
);
382 return ms
->dump_guest_core
;
385 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
387 MachineState
*ms
= MACHINE(obj
);
389 ms
->dump_guest_core
= value
;
392 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
394 MachineState
*ms
= MACHINE(obj
);
396 return ms
->mem_merge
;
399 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
401 MachineState
*ms
= MACHINE(obj
);
403 ms
->mem_merge
= value
;
406 static bool machine_get_usb(Object
*obj
, Error
**errp
)
408 MachineState
*ms
= MACHINE(obj
);
413 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
415 MachineState
*ms
= MACHINE(obj
);
418 ms
->usb_disabled
= !value
;
421 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
423 MachineState
*ms
= MACHINE(obj
);
425 return ms
->enable_graphics
;
428 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
430 MachineState
*ms
= MACHINE(obj
);
432 ms
->enable_graphics
= value
;
435 static bool machine_get_igd_gfx_passthru(Object
*obj
, Error
**errp
)
437 MachineState
*ms
= MACHINE(obj
);
439 return ms
->igd_gfx_passthru
;
442 static void machine_set_igd_gfx_passthru(Object
*obj
, bool value
, Error
**errp
)
444 MachineState
*ms
= MACHINE(obj
);
446 ms
->igd_gfx_passthru
= value
;
449 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
451 MachineState
*ms
= MACHINE(obj
);
453 return g_strdup(ms
->firmware
);
456 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
458 MachineState
*ms
= MACHINE(obj
);
460 g_free(ms
->firmware
);
461 ms
->firmware
= g_strdup(value
);
464 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
466 MachineState
*ms
= MACHINE(obj
);
468 ms
->suppress_vmdesc
= value
;
471 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
473 MachineState
*ms
= MACHINE(obj
);
475 return ms
->suppress_vmdesc
;
478 static void machine_set_enforce_config_section(Object
*obj
, bool value
,
481 MachineState
*ms
= MACHINE(obj
);
483 warn_report("enforce-config-section is deprecated, please use "
484 "-global migration.send-configuration=on|off instead");
486 ms
->enforce_config_section
= value
;
489 static bool machine_get_enforce_config_section(Object
*obj
, Error
**errp
)
491 MachineState
*ms
= MACHINE(obj
);
493 return ms
->enforce_config_section
;
496 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
498 MachineState
*ms
= MACHINE(obj
);
500 return g_strdup(ms
->memory_encryption
);
503 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
506 MachineState
*ms
= MACHINE(obj
);
508 g_free(ms
->memory_encryption
);
509 ms
->memory_encryption
= g_strdup(value
);
512 static bool machine_get_nvdimm(Object
*obj
, Error
**errp
)
514 MachineState
*ms
= MACHINE(obj
);
516 return ms
->nvdimms_state
->is_enabled
;
519 static void machine_set_nvdimm(Object
*obj
, bool value
, Error
**errp
)
521 MachineState
*ms
= MACHINE(obj
);
523 ms
->nvdimms_state
->is_enabled
= value
;
526 static char *machine_get_nvdimm_persistence(Object
*obj
, Error
**errp
)
528 MachineState
*ms
= MACHINE(obj
);
530 return g_strdup(ms
->nvdimms_state
->persistence_string
);
533 static void machine_set_nvdimm_persistence(Object
*obj
, const char *value
,
536 MachineState
*ms
= MACHINE(obj
);
537 NVDIMMState
*nvdimms_state
= ms
->nvdimms_state
;
539 if (strcmp(value
, "cpu") == 0) {
540 nvdimms_state
->persistence
= 3;
541 } else if (strcmp(value
, "mem-ctrl") == 0) {
542 nvdimms_state
->persistence
= 2;
544 error_setg(errp
, "-machine nvdimm-persistence=%s: unsupported option",
549 g_free(nvdimms_state
->persistence_string
);
550 nvdimms_state
->persistence_string
= g_strdup(value
);
553 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
555 strList
*item
= g_new0(strList
, 1);
557 item
->value
= g_strdup(type
);
558 item
->next
= mc
->allowed_dynamic_sysbus_devices
;
559 mc
->allowed_dynamic_sysbus_devices
= item
;
562 static void validate_sysbus_device(SysBusDevice
*sbdev
, void *opaque
)
564 MachineState
*machine
= opaque
;
565 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
566 bool allowed
= false;
569 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
572 allowed
|= !!object_dynamic_cast(OBJECT(sbdev
), wl
->value
);
576 error_report("Option '-device %s' cannot be handled by this machine",
577 object_class_get_name(object_get_class(OBJECT(sbdev
))));
582 static void machine_init_notify(Notifier
*notifier
, void *data
)
584 MachineState
*machine
= MACHINE(qdev_get_machine());
587 * Loop through all dynamically created sysbus devices and check if they are
588 * all allowed. If a device is not allowed, error out.
590 foreach_dynamic_sysbus_device(validate_sysbus_device
, machine
);
593 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
596 HotpluggableCPUList
*head
= NULL
;
597 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
599 /* force board to initialize possible_cpus if it hasn't been done yet */
600 mc
->possible_cpu_arch_ids(machine
);
602 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
604 HotpluggableCPUList
*list_item
= g_new0(typeof(*list_item
), 1);
605 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
607 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
608 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
609 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
610 sizeof(*cpu_item
->props
));
612 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
614 cpu_item
->has_qom_path
= true;
615 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
617 list_item
->value
= cpu_item
;
618 list_item
->next
= head
;
625 * machine_set_cpu_numa_node:
626 * @machine: machine object to modify
627 * @props: specifies which cpu objects to assign to
628 * numa node specified by @props.node_id
629 * @errp: if an error occurs, a pointer to an area to store the error
631 * Associate NUMA node specified by @props.node_id with cpu slots that
632 * match socket/core/thread-ids specified by @props. It's recommended to use
633 * query-hotpluggable-cpus.props values to specify affected cpu slots,
634 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
636 * However for CLI convenience it's possible to pass in subset of properties,
637 * which would affect all cpu slots that match it.
639 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
640 * -numa cpu,node-id=0,socket_id=0 \
641 * -numa cpu,node-id=1,socket_id=1
642 * will assign all child cores of socket 0 to node 0 and
643 * of socket 1 to node 1.
645 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
647 * Empty subset is disallowed and function will return with error in this case.
649 void machine_set_cpu_numa_node(MachineState
*machine
,
650 const CpuInstanceProperties
*props
, Error
**errp
)
652 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
656 if (!mc
->possible_cpu_arch_ids
) {
657 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
661 /* disabling node mapping is not supported, forbid it */
662 assert(props
->has_node_id
);
664 /* force board to initialize possible_cpus if it hasn't been done yet */
665 mc
->possible_cpu_arch_ids(machine
);
667 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
668 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
670 /* reject unsupported by board properties */
671 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
672 error_setg(errp
, "thread-id is not supported");
676 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
677 error_setg(errp
, "core-id is not supported");
681 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
682 error_setg(errp
, "socket-id is not supported");
686 /* skip slots with explicit mismatch */
687 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
691 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
695 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
699 /* reject assignment if slot is already assigned, for compatibility
700 * of legacy cpu_index mapping with SPAPR core based mapping do not
701 * error out if cpu thread and matched core have the same node-id */
702 if (slot
->props
.has_node_id
&&
703 slot
->props
.node_id
!= props
->node_id
) {
704 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
705 slot
->props
.node_id
);
709 /* assign slot to node as it's matched '-numa cpu' key */
711 slot
->props
.node_id
= props
->node_id
;
712 slot
->props
.has_node_id
= props
->has_node_id
;
716 error_setg(errp
, "no match found");
720 static void machine_class_init(ObjectClass
*oc
, void *data
)
722 MachineClass
*mc
= MACHINE_CLASS(oc
);
724 /* Default 128 MB as guest ram size */
725 mc
->default_ram_size
= 128 * MiB
;
726 mc
->rom_file_has_mr
= true;
728 /* numa node memory size aligned on 8MB by default.
729 * On Linux, each node's border has to be 8MB aligned
731 mc
->numa_mem_align_shift
= 23;
732 mc
->numa_auto_assign_ram
= numa_default_auto_assign_ram
;
734 object_class_property_add_str(oc
, "accel",
735 machine_get_accel
, machine_set_accel
, &error_abort
);
736 object_class_property_set_description(oc
, "accel",
737 "Accelerator list", &error_abort
);
739 object_class_property_add(oc
, "kernel-irqchip", "on|off|split",
740 NULL
, machine_set_kernel_irqchip
,
741 NULL
, NULL
, &error_abort
);
742 object_class_property_set_description(oc
, "kernel-irqchip",
743 "Configure KVM in-kernel irqchip", &error_abort
);
745 object_class_property_add(oc
, "kvm-shadow-mem", "int",
746 machine_get_kvm_shadow_mem
, machine_set_kvm_shadow_mem
,
747 NULL
, NULL
, &error_abort
);
748 object_class_property_set_description(oc
, "kvm-shadow-mem",
749 "KVM shadow MMU size", &error_abort
);
751 object_class_property_add_str(oc
, "kernel",
752 machine_get_kernel
, machine_set_kernel
, &error_abort
);
753 object_class_property_set_description(oc
, "kernel",
754 "Linux kernel image file", &error_abort
);
756 object_class_property_add_str(oc
, "initrd",
757 machine_get_initrd
, machine_set_initrd
, &error_abort
);
758 object_class_property_set_description(oc
, "initrd",
759 "Linux initial ramdisk file", &error_abort
);
761 object_class_property_add_str(oc
, "append",
762 machine_get_append
, machine_set_append
, &error_abort
);
763 object_class_property_set_description(oc
, "append",
764 "Linux kernel command line", &error_abort
);
766 object_class_property_add_str(oc
, "dtb",
767 machine_get_dtb
, machine_set_dtb
, &error_abort
);
768 object_class_property_set_description(oc
, "dtb",
769 "Linux kernel device tree file", &error_abort
);
771 object_class_property_add_str(oc
, "dumpdtb",
772 machine_get_dumpdtb
, machine_set_dumpdtb
, &error_abort
);
773 object_class_property_set_description(oc
, "dumpdtb",
774 "Dump current dtb to a file and quit", &error_abort
);
776 object_class_property_add(oc
, "phandle-start", "int",
777 machine_get_phandle_start
, machine_set_phandle_start
,
778 NULL
, NULL
, &error_abort
);
779 object_class_property_set_description(oc
, "phandle-start",
780 "The first phandle ID we may generate dynamically", &error_abort
);
782 object_class_property_add_str(oc
, "dt-compatible",
783 machine_get_dt_compatible
, machine_set_dt_compatible
, &error_abort
);
784 object_class_property_set_description(oc
, "dt-compatible",
785 "Overrides the \"compatible\" property of the dt root node",
788 object_class_property_add_bool(oc
, "dump-guest-core",
789 machine_get_dump_guest_core
, machine_set_dump_guest_core
, &error_abort
);
790 object_class_property_set_description(oc
, "dump-guest-core",
791 "Include guest memory in a core dump", &error_abort
);
793 object_class_property_add_bool(oc
, "mem-merge",
794 machine_get_mem_merge
, machine_set_mem_merge
, &error_abort
);
795 object_class_property_set_description(oc
, "mem-merge",
796 "Enable/disable memory merge support", &error_abort
);
798 object_class_property_add_bool(oc
, "usb",
799 machine_get_usb
, machine_set_usb
, &error_abort
);
800 object_class_property_set_description(oc
, "usb",
801 "Set on/off to enable/disable usb", &error_abort
);
803 object_class_property_add_bool(oc
, "graphics",
804 machine_get_graphics
, machine_set_graphics
, &error_abort
);
805 object_class_property_set_description(oc
, "graphics",
806 "Set on/off to enable/disable graphics emulation", &error_abort
);
808 object_class_property_add_bool(oc
, "igd-passthru",
809 machine_get_igd_gfx_passthru
, machine_set_igd_gfx_passthru
,
811 object_class_property_set_description(oc
, "igd-passthru",
812 "Set on/off to enable/disable igd passthrou", &error_abort
);
814 object_class_property_add_str(oc
, "firmware",
815 machine_get_firmware
, machine_set_firmware
,
817 object_class_property_set_description(oc
, "firmware",
818 "Firmware image", &error_abort
);
820 object_class_property_add_bool(oc
, "suppress-vmdesc",
821 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
,
823 object_class_property_set_description(oc
, "suppress-vmdesc",
824 "Set on to disable self-describing migration", &error_abort
);
826 object_class_property_add_bool(oc
, "enforce-config-section",
827 machine_get_enforce_config_section
, machine_set_enforce_config_section
,
829 object_class_property_set_description(oc
, "enforce-config-section",
830 "Set on to enforce configuration section migration", &error_abort
);
832 object_class_property_add_str(oc
, "memory-encryption",
833 machine_get_memory_encryption
, machine_set_memory_encryption
,
835 object_class_property_set_description(oc
, "memory-encryption",
836 "Set memory encryption object to use", &error_abort
);
839 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
841 if (!object_class_is_abstract(oc
)) {
842 MachineClass
*mc
= MACHINE_CLASS(oc
);
843 const char *cname
= object_class_get_name(oc
);
844 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
845 mc
->name
= g_strndup(cname
,
846 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
847 mc
->compat_props
= g_ptr_array_new();
851 static void machine_initfn(Object
*obj
)
853 MachineState
*ms
= MACHINE(obj
);
854 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
856 ms
->kernel_irqchip_allowed
= true;
857 ms
->kernel_irqchip_split
= mc
->default_kernel_irqchip_split
;
858 ms
->kvm_shadow_mem
= -1;
859 ms
->dump_guest_core
= true;
860 ms
->mem_merge
= true;
861 ms
->enable_graphics
= true;
863 if (mc
->nvdimm_supported
) {
864 Object
*obj
= OBJECT(ms
);
866 ms
->nvdimms_state
= g_new0(NVDIMMState
, 1);
867 object_property_add_bool(obj
, "nvdimm",
868 machine_get_nvdimm
, machine_set_nvdimm
,
870 object_property_set_description(obj
, "nvdimm",
871 "Set on/off to enable/disable "
872 "NVDIMM instantiation", NULL
);
874 object_property_add_str(obj
, "nvdimm-persistence",
875 machine_get_nvdimm_persistence
,
876 machine_set_nvdimm_persistence
,
878 object_property_set_description(obj
, "nvdimm-persistence",
879 "Set NVDIMM persistence"
880 "Valid values are cpu, mem-ctrl",
885 /* Register notifier when init is done for sysbus sanity checks */
886 ms
->sysbus_notifier
.notify
= machine_init_notify
;
887 qemu_add_machine_init_done_notifier(&ms
->sysbus_notifier
);
890 static void machine_finalize(Object
*obj
)
892 MachineState
*ms
= MACHINE(obj
);
895 g_free(ms
->kernel_filename
);
896 g_free(ms
->initrd_filename
);
897 g_free(ms
->kernel_cmdline
);
900 g_free(ms
->dt_compatible
);
901 g_free(ms
->firmware
);
902 g_free(ms
->device_memory
);
903 g_free(ms
->nvdimms_state
);
906 bool machine_usb(MachineState
*machine
)
911 bool machine_kernel_irqchip_allowed(MachineState
*machine
)
913 return machine
->kernel_irqchip_allowed
;
916 bool machine_kernel_irqchip_required(MachineState
*machine
)
918 return machine
->kernel_irqchip_required
;
921 bool machine_kernel_irqchip_split(MachineState
*machine
)
923 return machine
->kernel_irqchip_split
;
926 int machine_kvm_shadow_mem(MachineState
*machine
)
928 return machine
->kvm_shadow_mem
;
931 int machine_phandle_start(MachineState
*machine
)
933 return machine
->phandle_start
;
936 bool machine_dump_guest_core(MachineState
*machine
)
938 return machine
->dump_guest_core
;
941 bool machine_mem_merge(MachineState
*machine
)
943 return machine
->mem_merge
;
946 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
948 GString
*s
= g_string_new(NULL
);
949 if (cpu
->props
.has_socket_id
) {
950 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
952 if (cpu
->props
.has_core_id
) {
954 g_string_append_printf(s
, ", ");
956 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
958 if (cpu
->props
.has_thread_id
) {
960 g_string_append_printf(s
, ", ");
962 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
964 return g_string_free(s
, false);
967 static void machine_numa_finish_cpu_init(MachineState
*machine
)
970 bool default_mapping
;
971 GString
*s
= g_string_new(NULL
);
972 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
973 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
975 assert(nb_numa_nodes
);
976 for (i
= 0; i
< possible_cpus
->len
; i
++) {
977 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
981 default_mapping
= (i
== possible_cpus
->len
);
983 for (i
= 0; i
< possible_cpus
->len
; i
++) {
984 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
986 if (!cpu_slot
->props
.has_node_id
) {
987 /* fetch default mapping from board and enable it */
988 CpuInstanceProperties props
= cpu_slot
->props
;
990 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
991 if (!default_mapping
) {
992 /* record slots with not set mapping,
993 * TODO: make it hard error in future */
994 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
995 g_string_append_printf(s
, "%sCPU %d [%s]",
996 s
->len
? ", " : "", i
, cpu_str
);
999 /* non mapped cpus used to fallback to node 0 */
1003 props
.has_node_id
= true;
1004 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
1007 if (s
->len
&& !qtest_enabled()) {
1008 warn_report("CPU(s) not present in any NUMA nodes: %s",
1010 warn_report("All CPU(s) up to maxcpus should be described "
1011 "in NUMA config, ability to start up with partial NUMA "
1012 "mappings is obsoleted and will be removed in future");
1014 g_string_free(s
, true);
1017 void machine_run_board_init(MachineState
*machine
)
1019 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
1021 numa_complete_configuration(machine
);
1022 if (nb_numa_nodes
) {
1023 machine_numa_finish_cpu_init(machine
);
1026 /* If the machine supports the valid_cpu_types check and the user
1027 * specified a CPU with -cpu check here that the user CPU is supported.
1029 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
1030 ObjectClass
*class = object_class_by_name(machine
->cpu_type
);
1033 for (i
= 0; machine_class
->valid_cpu_types
[i
]; i
++) {
1034 if (object_class_dynamic_cast(class,
1035 machine_class
->valid_cpu_types
[i
])) {
1036 /* The user specificed CPU is in the valid field, we are
1043 if (!machine_class
->valid_cpu_types
[i
]) {
1044 /* The user specified CPU is not valid */
1045 error_report("Invalid CPU type: %s", machine
->cpu_type
);
1046 error_printf("The valid types are: %s",
1047 machine_class
->valid_cpu_types
[0]);
1048 for (i
= 1; machine_class
->valid_cpu_types
[i
]; i
++) {
1049 error_printf(", %s", machine_class
->valid_cpu_types
[i
]);
1057 machine_class
->init(machine
);
1060 static const TypeInfo machine_info
= {
1061 .name
= TYPE_MACHINE
,
1062 .parent
= TYPE_OBJECT
,
1064 .class_size
= sizeof(MachineClass
),
1065 .class_init
= machine_class_init
,
1066 .class_base_init
= machine_class_base_init
,
1067 .instance_size
= sizeof(MachineState
),
1068 .instance_init
= machine_initfn
,
1069 .instance_finalize
= machine_finalize
,
1072 static void machine_register_types(void)
1074 type_register_static(&machine_info
);
1077 type_init(machine_register_types
)