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" },
34 const size_t hw_compat_4_0_len
= G_N_ELEMENTS(hw_compat_4_0
);
36 GlobalProperty hw_compat_3_1
[] = {
37 { "pcie-root-port", "x-speed", "2_5" },
38 { "pcie-root-port", "x-width", "1" },
39 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
40 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
41 { "tpm-crb", "ppi", "false" },
42 { "tpm-tis", "ppi", "false" },
43 { "usb-kbd", "serial", "42" },
44 { "usb-mouse", "serial", "42" },
45 { "usb-tablet", "serial", "42" },
46 { "virtio-blk-device", "discard", "false" },
47 { "virtio-blk-device", "write-zeroes", "false" },
49 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
51 GlobalProperty hw_compat_3_0
[] = {};
52 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
54 GlobalProperty hw_compat_2_12
[] = {
55 { "migration", "decompress-error-check", "off" },
56 { "hda-audio", "use-timer", "false" },
57 { "cirrus-vga", "global-vmstate", "true" },
58 { "VGA", "global-vmstate", "true" },
59 { "vmware-svga", "global-vmstate", "true" },
60 { "qxl-vga", "global-vmstate", "true" },
62 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
64 GlobalProperty hw_compat_2_11
[] = {
65 { "hpet", "hpet-offset-saved", "false" },
66 { "virtio-blk-pci", "vectors", "2" },
67 { "vhost-user-blk-pci", "vectors", "2" },
68 { "e1000", "migrate_tso_props", "off" },
70 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
72 GlobalProperty hw_compat_2_10
[] = {
73 { "virtio-mouse-device", "wheel-axis", "false" },
74 { "virtio-tablet-device", "wheel-axis", "false" },
76 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
78 GlobalProperty hw_compat_2_9
[] = {
79 { "pci-bridge", "shpc", "off" },
80 { "intel-iommu", "pt", "off" },
81 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
82 { "pcie-root-port", "x-migrate-msix", "false" },
84 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
86 GlobalProperty hw_compat_2_8
[] = {
87 { "fw_cfg_mem", "x-file-slots", "0x10" },
88 { "fw_cfg_io", "x-file-slots", "0x10" },
89 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
90 { "pci-bridge", "shpc", "on" },
91 { TYPE_PCI_DEVICE
, "x-pcie-extcap-init", "off" },
92 { "virtio-pci", "x-pcie-deverr-init", "off" },
93 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
94 { "virtio-pci", "x-pcie-pm-init", "off" },
95 { "cirrus-vga", "vgamem_mb", "8" },
96 { "isa-cirrus-vga", "vgamem_mb", "8" },
98 const size_t hw_compat_2_8_len
= G_N_ELEMENTS(hw_compat_2_8
);
100 GlobalProperty hw_compat_2_7
[] = {
101 { "virtio-pci", "page-per-vq", "on" },
102 { "virtio-serial-device", "emergency-write", "off" },
103 { "ioapic", "version", "0x11" },
104 { "intel-iommu", "x-buggy-eim", "true" },
105 { "virtio-pci", "x-ignore-backend-features", "on" },
107 const size_t hw_compat_2_7_len
= G_N_ELEMENTS(hw_compat_2_7
);
109 GlobalProperty hw_compat_2_6
[] = {
110 { "virtio-mmio", "format_transport_address", "off" },
112 * don't include devices which are modern-only
113 * ie keyboard, mouse, tablet, gpu, vga & crypto
115 { "virtio-9p-pci", "disable-modern", "on" },
116 { "virtio-9p-pci", "disable-legacy", "off" },
117 { "virtio-balloon-pci", "disable-modern", "on" },
118 { "virtio-balloon-pci", "disable-legacy", "off" },
119 { "virtio-blk-pci", "disable-modern", "on" },
120 { "virtio-blk-pci", "disable-legacy", "off" },
121 { "virtio-input-host-pci", "disable-modern", "on" },
122 { "virtio-input-host-pci", "disable-legacy", "off" },
123 { "virtio-net-pci", "disable-modern", "on" },
124 { "virtio-net-pci", "disable-legacy", "off" },
125 { "virtio-rng-pci", "disable-modern", "on" },
126 { "virtio-rng-pci", "disable-legacy", "off" },
127 { "virtio-scsi-pci", "disable-modern", "on" },
128 { "virtio-scsi-pci", "disable-legacy", "off" },
129 { "virtio-serial-pci", "disable-modern", "on" },
130 { "virtio-serial-pci", "disable-legacy", "off" },
132 const size_t hw_compat_2_6_len
= G_N_ELEMENTS(hw_compat_2_6
);
134 GlobalProperty hw_compat_2_5
[] = {
135 { "isa-fdc", "fallback", "144" },
136 { "pvscsi", "x-old-pci-configuration", "on" },
137 { "pvscsi", "x-disable-pcie", "on" },
138 { "vmxnet3", "x-old-msi-offsets", "on" },
139 { "vmxnet3", "x-disable-pcie", "on" },
141 const size_t hw_compat_2_5_len
= G_N_ELEMENTS(hw_compat_2_5
);
143 GlobalProperty hw_compat_2_4
[] = {
144 { "virtio-blk-device", "scsi", "true" },
145 { "e1000", "extra_mac_registers", "off" },
146 { "virtio-pci", "x-disable-pcie", "on" },
147 { "virtio-pci", "migrate-extra", "off" },
148 { "fw_cfg_mem", "dma_enabled", "off" },
149 { "fw_cfg_io", "dma_enabled", "off" }
151 const size_t hw_compat_2_4_len
= G_N_ELEMENTS(hw_compat_2_4
);
153 GlobalProperty hw_compat_2_3
[] = {
154 { "virtio-blk-pci", "any_layout", "off" },
155 { "virtio-balloon-pci", "any_layout", "off" },
156 { "virtio-serial-pci", "any_layout", "off" },
157 { "virtio-9p-pci", "any_layout", "off" },
158 { "virtio-rng-pci", "any_layout", "off" },
159 { TYPE_PCI_DEVICE
, "x-pcie-lnksta-dllla", "off" },
160 { "migration", "send-configuration", "off" },
161 { "migration", "send-section-footer", "off" },
162 { "migration", "store-global-state", "off" },
164 const size_t hw_compat_2_3_len
= G_N_ELEMENTS(hw_compat_2_3
);
166 GlobalProperty hw_compat_2_2
[] = {};
167 const size_t hw_compat_2_2_len
= G_N_ELEMENTS(hw_compat_2_2
);
169 GlobalProperty hw_compat_2_1
[] = {
170 { "intel-hda", "old_msi_addr", "on" },
171 { "VGA", "qemu-extended-regs", "off" },
172 { "secondary-vga", "qemu-extended-regs", "off" },
173 { "virtio-scsi-pci", "any_layout", "off" },
174 { "usb-mouse", "usb_version", "1" },
175 { "usb-kbd", "usb_version", "1" },
176 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
178 const size_t hw_compat_2_1_len
= G_N_ELEMENTS(hw_compat_2_1
);
180 static char *machine_get_accel(Object
*obj
, Error
**errp
)
182 MachineState
*ms
= MACHINE(obj
);
184 return g_strdup(ms
->accel
);
187 static void machine_set_accel(Object
*obj
, const char *value
, Error
**errp
)
189 MachineState
*ms
= MACHINE(obj
);
192 ms
->accel
= g_strdup(value
);
195 static void machine_set_kernel_irqchip(Object
*obj
, Visitor
*v
,
196 const char *name
, void *opaque
,
200 MachineState
*ms
= MACHINE(obj
);
203 visit_type_OnOffSplit(v
, name
, &mode
, &err
);
205 error_propagate(errp
, err
);
209 case ON_OFF_SPLIT_ON
:
210 ms
->kernel_irqchip_allowed
= true;
211 ms
->kernel_irqchip_required
= true;
212 ms
->kernel_irqchip_split
= false;
214 case ON_OFF_SPLIT_OFF
:
215 ms
->kernel_irqchip_allowed
= false;
216 ms
->kernel_irqchip_required
= false;
217 ms
->kernel_irqchip_split
= false;
219 case ON_OFF_SPLIT_SPLIT
:
220 ms
->kernel_irqchip_allowed
= true;
221 ms
->kernel_irqchip_required
= true;
222 ms
->kernel_irqchip_split
= true;
225 /* The value was checked in visit_type_OnOffSplit() above. If
226 * we get here, then something is wrong in QEMU.
233 static void machine_get_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
234 const char *name
, void *opaque
,
237 MachineState
*ms
= MACHINE(obj
);
238 int64_t value
= ms
->kvm_shadow_mem
;
240 visit_type_int(v
, name
, &value
, errp
);
243 static void machine_set_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
244 const char *name
, void *opaque
,
247 MachineState
*ms
= MACHINE(obj
);
251 visit_type_int(v
, name
, &value
, &error
);
253 error_propagate(errp
, error
);
257 ms
->kvm_shadow_mem
= value
;
260 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
262 MachineState
*ms
= MACHINE(obj
);
264 return g_strdup(ms
->kernel_filename
);
267 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
269 MachineState
*ms
= MACHINE(obj
);
271 g_free(ms
->kernel_filename
);
272 ms
->kernel_filename
= g_strdup(value
);
275 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
277 MachineState
*ms
= MACHINE(obj
);
279 return g_strdup(ms
->initrd_filename
);
282 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
284 MachineState
*ms
= MACHINE(obj
);
286 g_free(ms
->initrd_filename
);
287 ms
->initrd_filename
= g_strdup(value
);
290 static char *machine_get_append(Object
*obj
, Error
**errp
)
292 MachineState
*ms
= MACHINE(obj
);
294 return g_strdup(ms
->kernel_cmdline
);
297 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
299 MachineState
*ms
= MACHINE(obj
);
301 g_free(ms
->kernel_cmdline
);
302 ms
->kernel_cmdline
= g_strdup(value
);
305 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
307 MachineState
*ms
= MACHINE(obj
);
309 return g_strdup(ms
->dtb
);
312 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
314 MachineState
*ms
= MACHINE(obj
);
317 ms
->dtb
= g_strdup(value
);
320 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
322 MachineState
*ms
= MACHINE(obj
);
324 return g_strdup(ms
->dumpdtb
);
327 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
329 MachineState
*ms
= MACHINE(obj
);
332 ms
->dumpdtb
= g_strdup(value
);
335 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
336 const char *name
, void *opaque
,
339 MachineState
*ms
= MACHINE(obj
);
340 int64_t value
= ms
->phandle_start
;
342 visit_type_int(v
, name
, &value
, errp
);
345 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
346 const char *name
, void *opaque
,
349 MachineState
*ms
= MACHINE(obj
);
353 visit_type_int(v
, name
, &value
, &error
);
355 error_propagate(errp
, error
);
359 ms
->phandle_start
= value
;
362 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
364 MachineState
*ms
= MACHINE(obj
);
366 return g_strdup(ms
->dt_compatible
);
369 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
371 MachineState
*ms
= MACHINE(obj
);
373 g_free(ms
->dt_compatible
);
374 ms
->dt_compatible
= g_strdup(value
);
377 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
379 MachineState
*ms
= MACHINE(obj
);
381 return ms
->dump_guest_core
;
384 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
386 MachineState
*ms
= MACHINE(obj
);
388 ms
->dump_guest_core
= value
;
391 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
393 MachineState
*ms
= MACHINE(obj
);
395 return ms
->mem_merge
;
398 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
400 MachineState
*ms
= MACHINE(obj
);
402 ms
->mem_merge
= value
;
405 static bool machine_get_usb(Object
*obj
, Error
**errp
)
407 MachineState
*ms
= MACHINE(obj
);
412 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
414 MachineState
*ms
= MACHINE(obj
);
417 ms
->usb_disabled
= !value
;
420 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
422 MachineState
*ms
= MACHINE(obj
);
424 return ms
->enable_graphics
;
427 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
429 MachineState
*ms
= MACHINE(obj
);
431 ms
->enable_graphics
= value
;
434 static bool machine_get_igd_gfx_passthru(Object
*obj
, Error
**errp
)
436 MachineState
*ms
= MACHINE(obj
);
438 return ms
->igd_gfx_passthru
;
441 static void machine_set_igd_gfx_passthru(Object
*obj
, bool value
, Error
**errp
)
443 MachineState
*ms
= MACHINE(obj
);
445 ms
->igd_gfx_passthru
= value
;
448 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
450 MachineState
*ms
= MACHINE(obj
);
452 return g_strdup(ms
->firmware
);
455 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
457 MachineState
*ms
= MACHINE(obj
);
459 g_free(ms
->firmware
);
460 ms
->firmware
= g_strdup(value
);
463 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
465 MachineState
*ms
= MACHINE(obj
);
467 ms
->suppress_vmdesc
= value
;
470 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
472 MachineState
*ms
= MACHINE(obj
);
474 return ms
->suppress_vmdesc
;
477 static void machine_set_enforce_config_section(Object
*obj
, bool value
,
480 MachineState
*ms
= MACHINE(obj
);
482 warn_report("enforce-config-section is deprecated, please use "
483 "-global migration.send-configuration=on|off instead");
485 ms
->enforce_config_section
= value
;
488 static bool machine_get_enforce_config_section(Object
*obj
, Error
**errp
)
490 MachineState
*ms
= MACHINE(obj
);
492 return ms
->enforce_config_section
;
495 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
497 MachineState
*ms
= MACHINE(obj
);
499 return g_strdup(ms
->memory_encryption
);
502 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
505 MachineState
*ms
= MACHINE(obj
);
507 g_free(ms
->memory_encryption
);
508 ms
->memory_encryption
= g_strdup(value
);
511 static bool machine_get_nvdimm(Object
*obj
, Error
**errp
)
513 MachineState
*ms
= MACHINE(obj
);
515 return ms
->nvdimms_state
->is_enabled
;
518 static void machine_set_nvdimm(Object
*obj
, bool value
, Error
**errp
)
520 MachineState
*ms
= MACHINE(obj
);
522 ms
->nvdimms_state
->is_enabled
= value
;
525 static char *machine_get_nvdimm_persistence(Object
*obj
, Error
**errp
)
527 MachineState
*ms
= MACHINE(obj
);
529 return g_strdup(ms
->nvdimms_state
->persistence_string
);
532 static void machine_set_nvdimm_persistence(Object
*obj
, const char *value
,
535 MachineState
*ms
= MACHINE(obj
);
536 NVDIMMState
*nvdimms_state
= ms
->nvdimms_state
;
538 if (strcmp(value
, "cpu") == 0) {
539 nvdimms_state
->persistence
= 3;
540 } else if (strcmp(value
, "mem-ctrl") == 0) {
541 nvdimms_state
->persistence
= 2;
543 error_setg(errp
, "-machine nvdimm-persistence=%s: unsupported option",
548 g_free(nvdimms_state
->persistence_string
);
549 nvdimms_state
->persistence_string
= g_strdup(value
);
552 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
554 strList
*item
= g_new0(strList
, 1);
556 item
->value
= g_strdup(type
);
557 item
->next
= mc
->allowed_dynamic_sysbus_devices
;
558 mc
->allowed_dynamic_sysbus_devices
= item
;
561 static void validate_sysbus_device(SysBusDevice
*sbdev
, void *opaque
)
563 MachineState
*machine
= opaque
;
564 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
565 bool allowed
= false;
568 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
571 allowed
|= !!object_dynamic_cast(OBJECT(sbdev
), wl
->value
);
575 error_report("Option '-device %s' cannot be handled by this machine",
576 object_class_get_name(object_get_class(OBJECT(sbdev
))));
581 static void machine_init_notify(Notifier
*notifier
, void *data
)
583 MachineState
*machine
= MACHINE(qdev_get_machine());
586 * Loop through all dynamically created sysbus devices and check if they are
587 * all allowed. If a device is not allowed, error out.
589 foreach_dynamic_sysbus_device(validate_sysbus_device
, machine
);
592 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
595 HotpluggableCPUList
*head
= NULL
;
596 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
598 /* force board to initialize possible_cpus if it hasn't been done yet */
599 mc
->possible_cpu_arch_ids(machine
);
601 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
603 HotpluggableCPUList
*list_item
= g_new0(typeof(*list_item
), 1);
604 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
606 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
607 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
608 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
609 sizeof(*cpu_item
->props
));
611 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
613 cpu_item
->has_qom_path
= true;
614 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
616 list_item
->value
= cpu_item
;
617 list_item
->next
= head
;
624 * machine_set_cpu_numa_node:
625 * @machine: machine object to modify
626 * @props: specifies which cpu objects to assign to
627 * numa node specified by @props.node_id
628 * @errp: if an error occurs, a pointer to an area to store the error
630 * Associate NUMA node specified by @props.node_id with cpu slots that
631 * match socket/core/thread-ids specified by @props. It's recommended to use
632 * query-hotpluggable-cpus.props values to specify affected cpu slots,
633 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
635 * However for CLI convenience it's possible to pass in subset of properties,
636 * which would affect all cpu slots that match it.
638 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
639 * -numa cpu,node-id=0,socket_id=0 \
640 * -numa cpu,node-id=1,socket_id=1
641 * will assign all child cores of socket 0 to node 0 and
642 * of socket 1 to node 1.
644 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
646 * Empty subset is disallowed and function will return with error in this case.
648 void machine_set_cpu_numa_node(MachineState
*machine
,
649 const CpuInstanceProperties
*props
, Error
**errp
)
651 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
655 if (!mc
->possible_cpu_arch_ids
) {
656 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
660 /* disabling node mapping is not supported, forbid it */
661 assert(props
->has_node_id
);
663 /* force board to initialize possible_cpus if it hasn't been done yet */
664 mc
->possible_cpu_arch_ids(machine
);
666 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
667 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
669 /* reject unsupported by board properties */
670 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
671 error_setg(errp
, "thread-id is not supported");
675 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
676 error_setg(errp
, "core-id is not supported");
680 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
681 error_setg(errp
, "socket-id is not supported");
685 /* skip slots with explicit mismatch */
686 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
690 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
694 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
698 /* reject assignment if slot is already assigned, for compatibility
699 * of legacy cpu_index mapping with SPAPR core based mapping do not
700 * error out if cpu thread and matched core have the same node-id */
701 if (slot
->props
.has_node_id
&&
702 slot
->props
.node_id
!= props
->node_id
) {
703 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
704 slot
->props
.node_id
);
708 /* assign slot to node as it's matched '-numa cpu' key */
710 slot
->props
.node_id
= props
->node_id
;
711 slot
->props
.has_node_id
= props
->has_node_id
;
715 error_setg(errp
, "no match found");
719 static void machine_class_init(ObjectClass
*oc
, void *data
)
721 MachineClass
*mc
= MACHINE_CLASS(oc
);
723 /* Default 128 MB as guest ram size */
724 mc
->default_ram_size
= 128 * MiB
;
725 mc
->rom_file_has_mr
= true;
727 /* numa node memory size aligned on 8MB by default.
728 * On Linux, each node's border has to be 8MB aligned
730 mc
->numa_mem_align_shift
= 23;
731 mc
->numa_auto_assign_ram
= numa_default_auto_assign_ram
;
733 object_class_property_add_str(oc
, "accel",
734 machine_get_accel
, machine_set_accel
, &error_abort
);
735 object_class_property_set_description(oc
, "accel",
736 "Accelerator list", &error_abort
);
738 object_class_property_add(oc
, "kernel-irqchip", "on|off|split",
739 NULL
, machine_set_kernel_irqchip
,
740 NULL
, NULL
, &error_abort
);
741 object_class_property_set_description(oc
, "kernel-irqchip",
742 "Configure KVM in-kernel irqchip", &error_abort
);
744 object_class_property_add(oc
, "kvm-shadow-mem", "int",
745 machine_get_kvm_shadow_mem
, machine_set_kvm_shadow_mem
,
746 NULL
, NULL
, &error_abort
);
747 object_class_property_set_description(oc
, "kvm-shadow-mem",
748 "KVM shadow MMU size", &error_abort
);
750 object_class_property_add_str(oc
, "kernel",
751 machine_get_kernel
, machine_set_kernel
, &error_abort
);
752 object_class_property_set_description(oc
, "kernel",
753 "Linux kernel image file", &error_abort
);
755 object_class_property_add_str(oc
, "initrd",
756 machine_get_initrd
, machine_set_initrd
, &error_abort
);
757 object_class_property_set_description(oc
, "initrd",
758 "Linux initial ramdisk file", &error_abort
);
760 object_class_property_add_str(oc
, "append",
761 machine_get_append
, machine_set_append
, &error_abort
);
762 object_class_property_set_description(oc
, "append",
763 "Linux kernel command line", &error_abort
);
765 object_class_property_add_str(oc
, "dtb",
766 machine_get_dtb
, machine_set_dtb
, &error_abort
);
767 object_class_property_set_description(oc
, "dtb",
768 "Linux kernel device tree file", &error_abort
);
770 object_class_property_add_str(oc
, "dumpdtb",
771 machine_get_dumpdtb
, machine_set_dumpdtb
, &error_abort
);
772 object_class_property_set_description(oc
, "dumpdtb",
773 "Dump current dtb to a file and quit", &error_abort
);
775 object_class_property_add(oc
, "phandle-start", "int",
776 machine_get_phandle_start
, machine_set_phandle_start
,
777 NULL
, NULL
, &error_abort
);
778 object_class_property_set_description(oc
, "phandle-start",
779 "The first phandle ID we may generate dynamically", &error_abort
);
781 object_class_property_add_str(oc
, "dt-compatible",
782 machine_get_dt_compatible
, machine_set_dt_compatible
, &error_abort
);
783 object_class_property_set_description(oc
, "dt-compatible",
784 "Overrides the \"compatible\" property of the dt root node",
787 object_class_property_add_bool(oc
, "dump-guest-core",
788 machine_get_dump_guest_core
, machine_set_dump_guest_core
, &error_abort
);
789 object_class_property_set_description(oc
, "dump-guest-core",
790 "Include guest memory in a core dump", &error_abort
);
792 object_class_property_add_bool(oc
, "mem-merge",
793 machine_get_mem_merge
, machine_set_mem_merge
, &error_abort
);
794 object_class_property_set_description(oc
, "mem-merge",
795 "Enable/disable memory merge support", &error_abort
);
797 object_class_property_add_bool(oc
, "usb",
798 machine_get_usb
, machine_set_usb
, &error_abort
);
799 object_class_property_set_description(oc
, "usb",
800 "Set on/off to enable/disable usb", &error_abort
);
802 object_class_property_add_bool(oc
, "graphics",
803 machine_get_graphics
, machine_set_graphics
, &error_abort
);
804 object_class_property_set_description(oc
, "graphics",
805 "Set on/off to enable/disable graphics emulation", &error_abort
);
807 object_class_property_add_bool(oc
, "igd-passthru",
808 machine_get_igd_gfx_passthru
, machine_set_igd_gfx_passthru
,
810 object_class_property_set_description(oc
, "igd-passthru",
811 "Set on/off to enable/disable igd passthrou", &error_abort
);
813 object_class_property_add_str(oc
, "firmware",
814 machine_get_firmware
, machine_set_firmware
,
816 object_class_property_set_description(oc
, "firmware",
817 "Firmware image", &error_abort
);
819 object_class_property_add_bool(oc
, "suppress-vmdesc",
820 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
,
822 object_class_property_set_description(oc
, "suppress-vmdesc",
823 "Set on to disable self-describing migration", &error_abort
);
825 object_class_property_add_bool(oc
, "enforce-config-section",
826 machine_get_enforce_config_section
, machine_set_enforce_config_section
,
828 object_class_property_set_description(oc
, "enforce-config-section",
829 "Set on to enforce configuration section migration", &error_abort
);
831 object_class_property_add_str(oc
, "memory-encryption",
832 machine_get_memory_encryption
, machine_set_memory_encryption
,
834 object_class_property_set_description(oc
, "memory-encryption",
835 "Set memory encryption object to use", &error_abort
);
838 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
840 if (!object_class_is_abstract(oc
)) {
841 MachineClass
*mc
= MACHINE_CLASS(oc
);
842 const char *cname
= object_class_get_name(oc
);
843 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
844 mc
->name
= g_strndup(cname
,
845 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
846 mc
->compat_props
= g_ptr_array_new();
850 static void machine_initfn(Object
*obj
)
852 MachineState
*ms
= MACHINE(obj
);
853 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
855 ms
->kernel_irqchip_allowed
= true;
856 ms
->kernel_irqchip_split
= mc
->default_kernel_irqchip_split
;
857 ms
->kvm_shadow_mem
= -1;
858 ms
->dump_guest_core
= true;
859 ms
->mem_merge
= true;
860 ms
->enable_graphics
= true;
862 if (mc
->nvdimm_supported
) {
863 Object
*obj
= OBJECT(ms
);
865 ms
->nvdimms_state
= g_new0(NVDIMMState
, 1);
866 object_property_add_bool(obj
, "nvdimm",
867 machine_get_nvdimm
, machine_set_nvdimm
,
869 object_property_set_description(obj
, "nvdimm",
870 "Set on/off to enable/disable "
871 "NVDIMM instantiation", NULL
);
873 object_property_add_str(obj
, "nvdimm-persistence",
874 machine_get_nvdimm_persistence
,
875 machine_set_nvdimm_persistence
,
877 object_property_set_description(obj
, "nvdimm-persistence",
878 "Set NVDIMM persistence"
879 "Valid values are cpu, mem-ctrl",
884 /* Register notifier when init is done for sysbus sanity checks */
885 ms
->sysbus_notifier
.notify
= machine_init_notify
;
886 qemu_add_machine_init_done_notifier(&ms
->sysbus_notifier
);
889 static void machine_finalize(Object
*obj
)
891 MachineState
*ms
= MACHINE(obj
);
894 g_free(ms
->kernel_filename
);
895 g_free(ms
->initrd_filename
);
896 g_free(ms
->kernel_cmdline
);
899 g_free(ms
->dt_compatible
);
900 g_free(ms
->firmware
);
901 g_free(ms
->device_memory
);
902 g_free(ms
->nvdimms_state
);
905 bool machine_usb(MachineState
*machine
)
910 bool machine_kernel_irqchip_allowed(MachineState
*machine
)
912 return machine
->kernel_irqchip_allowed
;
915 bool machine_kernel_irqchip_required(MachineState
*machine
)
917 return machine
->kernel_irqchip_required
;
920 bool machine_kernel_irqchip_split(MachineState
*machine
)
922 return machine
->kernel_irqchip_split
;
925 int machine_kvm_shadow_mem(MachineState
*machine
)
927 return machine
->kvm_shadow_mem
;
930 int machine_phandle_start(MachineState
*machine
)
932 return machine
->phandle_start
;
935 bool machine_dump_guest_core(MachineState
*machine
)
937 return machine
->dump_guest_core
;
940 bool machine_mem_merge(MachineState
*machine
)
942 return machine
->mem_merge
;
945 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
947 GString
*s
= g_string_new(NULL
);
948 if (cpu
->props
.has_socket_id
) {
949 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
951 if (cpu
->props
.has_core_id
) {
953 g_string_append_printf(s
, ", ");
955 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
957 if (cpu
->props
.has_thread_id
) {
959 g_string_append_printf(s
, ", ");
961 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
963 return g_string_free(s
, false);
966 static void machine_numa_finish_cpu_init(MachineState
*machine
)
969 bool default_mapping
;
970 GString
*s
= g_string_new(NULL
);
971 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
972 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
974 assert(nb_numa_nodes
);
975 for (i
= 0; i
< possible_cpus
->len
; i
++) {
976 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
980 default_mapping
= (i
== possible_cpus
->len
);
982 for (i
= 0; i
< possible_cpus
->len
; i
++) {
983 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
985 if (!cpu_slot
->props
.has_node_id
) {
986 /* fetch default mapping from board and enable it */
987 CpuInstanceProperties props
= cpu_slot
->props
;
989 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
990 if (!default_mapping
) {
991 /* record slots with not set mapping,
992 * TODO: make it hard error in future */
993 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
994 g_string_append_printf(s
, "%sCPU %d [%s]",
995 s
->len
? ", " : "", i
, cpu_str
);
998 /* non mapped cpus used to fallback to node 0 */
1002 props
.has_node_id
= true;
1003 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
1006 if (s
->len
&& !qtest_enabled()) {
1007 warn_report("CPU(s) not present in any NUMA nodes: %s",
1009 warn_report("All CPU(s) up to maxcpus should be described "
1010 "in NUMA config, ability to start up with partial NUMA "
1011 "mappings is obsoleted and will be removed in future");
1013 g_string_free(s
, true);
1016 void machine_run_board_init(MachineState
*machine
)
1018 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
1020 numa_complete_configuration(machine
);
1021 if (nb_numa_nodes
) {
1022 machine_numa_finish_cpu_init(machine
);
1025 /* If the machine supports the valid_cpu_types check and the user
1026 * specified a CPU with -cpu check here that the user CPU is supported.
1028 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
1029 ObjectClass
*class = object_class_by_name(machine
->cpu_type
);
1032 for (i
= 0; machine_class
->valid_cpu_types
[i
]; i
++) {
1033 if (object_class_dynamic_cast(class,
1034 machine_class
->valid_cpu_types
[i
])) {
1035 /* The user specificed CPU is in the valid field, we are
1042 if (!machine_class
->valid_cpu_types
[i
]) {
1043 /* The user specified CPU is not valid */
1044 error_report("Invalid CPU type: %s", machine
->cpu_type
);
1045 error_printf("The valid types are: %s",
1046 machine_class
->valid_cpu_types
[0]);
1047 for (i
= 1; machine_class
->valid_cpu_types
[i
]; i
++) {
1048 error_printf(", %s", machine_class
->valid_cpu_types
[i
]);
1056 machine_class
->init(machine
);
1059 static const TypeInfo machine_info
= {
1060 .name
= TYPE_MACHINE
,
1061 .parent
= TYPE_OBJECT
,
1063 .class_size
= sizeof(MachineClass
),
1064 .class_init
= machine_class_init
,
1065 .class_base_init
= machine_class_base_init
,
1066 .instance_size
= sizeof(MachineState
),
1067 .instance_init
= machine_initfn
,
1068 .instance_finalize
= machine_finalize
,
1071 static void machine_register_types(void)
1073 type_register_static(&machine_info
);
1076 type_init(machine_register_types
)