spapr_pci: Fix broken naming of PCI bus
[qemu/ar7.git] / hw / core / machine.c
blob743fef28982c13a1d0fd00845dbbc9c2dce5598c
1 /*
2 * QEMU Machine
4 * Copyright (C) 2014 Red Hat Inc
6 * Authors:
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_3_1[] = {
28 { "pcie-root-port", "x-speed", "2_5" },
29 { "pcie-root-port", "x-width", "1" },
30 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
31 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
32 { "tpm-crb", "ppi", "false" },
33 { "tpm-tis", "ppi", "false" },
34 { "usb-kbd", "serial", "42" },
35 { "usb-mouse", "serial", "42" },
36 { "usb-kbd", "serial", "42" },
37 { "virtio-blk-device", "discard", "false" },
38 { "virtio-blk-device", "write-zeroes", "false" },
40 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1);
42 GlobalProperty hw_compat_3_0[] = {};
43 const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0);
45 GlobalProperty hw_compat_2_12[] = {
46 { "migration", "decompress-error-check", "off" },
47 { "hda-audio", "use-timer", "false" },
48 { "cirrus-vga", "global-vmstate", "true" },
49 { "VGA", "global-vmstate", "true" },
50 { "vmware-svga", "global-vmstate", "true" },
51 { "qxl-vga", "global-vmstate", "true" },
53 const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12);
55 GlobalProperty hw_compat_2_11[] = {
56 { "hpet", "hpet-offset-saved", "false" },
57 { "virtio-blk-pci", "vectors", "2" },
58 { "vhost-user-blk-pci", "vectors", "2" },
59 { "e1000", "migrate_tso_props", "off" },
61 const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11);
63 GlobalProperty hw_compat_2_10[] = {
64 { "virtio-mouse-device", "wheel-axis", "false" },
65 { "virtio-tablet-device", "wheel-axis", "false" },
67 const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10);
69 GlobalProperty hw_compat_2_9[] = {
70 { "pci-bridge", "shpc", "off" },
71 { "intel-iommu", "pt", "off" },
72 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
73 { "pcie-root-port", "x-migrate-msix", "false" },
75 const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9);
77 GlobalProperty hw_compat_2_8[] = {
78 { "fw_cfg_mem", "x-file-slots", "0x10" },
79 { "fw_cfg_io", "x-file-slots", "0x10" },
80 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
81 { "pci-bridge", "shpc", "on" },
82 { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" },
83 { "virtio-pci", "x-pcie-deverr-init", "off" },
84 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
85 { "virtio-pci", "x-pcie-pm-init", "off" },
86 { "cirrus-vga", "vgamem_mb", "8" },
87 { "isa-cirrus-vga", "vgamem_mb", "8" },
89 const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8);
91 GlobalProperty hw_compat_2_7[] = {
92 { "virtio-pci", "page-per-vq", "on" },
93 { "virtio-serial-device", "emergency-write", "off" },
94 { "ioapic", "version", "0x11" },
95 { "intel-iommu", "x-buggy-eim", "true" },
96 { "virtio-pci", "x-ignore-backend-features", "on" },
98 const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
100 GlobalProperty hw_compat_2_6[] = {
101 { "virtio-mmio", "format_transport_address", "off" },
102 /* Optional because not all virtio-pci devices support legacy mode */
103 { "virtio-pci", "disable-modern", "on", .optional = true },
104 { "virtio-pci", "disable-legacy", "off", .optional = true },
106 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
108 GlobalProperty hw_compat_2_5[] = {
109 { "isa-fdc", "fallback", "144" },
110 { "pvscsi", "x-old-pci-configuration", "on" },
111 { "pvscsi", "x-disable-pcie", "on" },
112 { "vmxnet3", "x-old-msi-offsets", "on" },
113 { "vmxnet3", "x-disable-pcie", "on" },
115 const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5);
117 GlobalProperty hw_compat_2_4[] = {
118 { "virtio-blk-device", "scsi", "true" },
119 { "e1000", "extra_mac_registers", "off" },
120 { "virtio-pci", "x-disable-pcie", "on" },
121 { "virtio-pci", "migrate-extra", "off" },
122 { "fw_cfg_mem", "dma_enabled", "off" },
123 { "fw_cfg_io", "dma_enabled", "off" }
125 const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4);
127 GlobalProperty hw_compat_2_3[] = {
128 { "virtio-blk-pci", "any_layout", "off" },
129 { "virtio-balloon-pci", "any_layout", "off" },
130 { "virtio-serial-pci", "any_layout", "off" },
131 { "virtio-9p-pci", "any_layout", "off" },
132 { "virtio-rng-pci", "any_layout", "off" },
133 { TYPE_PCI_DEVICE, "x-pcie-lnksta-dllla", "off" },
134 { "migration", "send-configuration", "off" },
135 { "migration", "send-section-footer", "off" },
136 { "migration", "store-global-state", "off" },
138 const size_t hw_compat_2_3_len = G_N_ELEMENTS(hw_compat_2_3);
140 GlobalProperty hw_compat_2_2[] = {};
141 const size_t hw_compat_2_2_len = G_N_ELEMENTS(hw_compat_2_2);
143 GlobalProperty hw_compat_2_1[] = {
144 { "intel-hda", "old_msi_addr", "on" },
145 { "VGA", "qemu-extended-regs", "off" },
146 { "secondary-vga", "qemu-extended-regs", "off" },
147 { "virtio-scsi-pci", "any_layout", "off" },
148 { "usb-mouse", "usb_version", "1" },
149 { "usb-kbd", "usb_version", "1" },
150 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
152 const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1);
154 static char *machine_get_accel(Object *obj, Error **errp)
156 MachineState *ms = MACHINE(obj);
158 return g_strdup(ms->accel);
161 static void machine_set_accel(Object *obj, const char *value, Error **errp)
163 MachineState *ms = MACHINE(obj);
165 g_free(ms->accel);
166 ms->accel = g_strdup(value);
169 static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
170 const char *name, void *opaque,
171 Error **errp)
173 Error *err = NULL;
174 MachineState *ms = MACHINE(obj);
175 OnOffSplit mode;
177 visit_type_OnOffSplit(v, name, &mode, &err);
178 if (err) {
179 error_propagate(errp, err);
180 return;
181 } else {
182 switch (mode) {
183 case ON_OFF_SPLIT_ON:
184 ms->kernel_irqchip_allowed = true;
185 ms->kernel_irqchip_required = true;
186 ms->kernel_irqchip_split = false;
187 break;
188 case ON_OFF_SPLIT_OFF:
189 ms->kernel_irqchip_allowed = false;
190 ms->kernel_irqchip_required = false;
191 ms->kernel_irqchip_split = false;
192 break;
193 case ON_OFF_SPLIT_SPLIT:
194 ms->kernel_irqchip_allowed = true;
195 ms->kernel_irqchip_required = true;
196 ms->kernel_irqchip_split = true;
197 break;
198 default:
199 /* The value was checked in visit_type_OnOffSplit() above. If
200 * we get here, then something is wrong in QEMU.
202 abort();
207 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
208 const char *name, void *opaque,
209 Error **errp)
211 MachineState *ms = MACHINE(obj);
212 int64_t value = ms->kvm_shadow_mem;
214 visit_type_int(v, name, &value, errp);
217 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
218 const char *name, void *opaque,
219 Error **errp)
221 MachineState *ms = MACHINE(obj);
222 Error *error = NULL;
223 int64_t value;
225 visit_type_int(v, name, &value, &error);
226 if (error) {
227 error_propagate(errp, error);
228 return;
231 ms->kvm_shadow_mem = value;
234 static char *machine_get_kernel(Object *obj, Error **errp)
236 MachineState *ms = MACHINE(obj);
238 return g_strdup(ms->kernel_filename);
241 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
243 MachineState *ms = MACHINE(obj);
245 g_free(ms->kernel_filename);
246 ms->kernel_filename = g_strdup(value);
249 static char *machine_get_initrd(Object *obj, Error **errp)
251 MachineState *ms = MACHINE(obj);
253 return g_strdup(ms->initrd_filename);
256 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
258 MachineState *ms = MACHINE(obj);
260 g_free(ms->initrd_filename);
261 ms->initrd_filename = g_strdup(value);
264 static char *machine_get_append(Object *obj, Error **errp)
266 MachineState *ms = MACHINE(obj);
268 return g_strdup(ms->kernel_cmdline);
271 static void machine_set_append(Object *obj, const char *value, Error **errp)
273 MachineState *ms = MACHINE(obj);
275 g_free(ms->kernel_cmdline);
276 ms->kernel_cmdline = g_strdup(value);
279 static char *machine_get_dtb(Object *obj, Error **errp)
281 MachineState *ms = MACHINE(obj);
283 return g_strdup(ms->dtb);
286 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
288 MachineState *ms = MACHINE(obj);
290 g_free(ms->dtb);
291 ms->dtb = g_strdup(value);
294 static char *machine_get_dumpdtb(Object *obj, Error **errp)
296 MachineState *ms = MACHINE(obj);
298 return g_strdup(ms->dumpdtb);
301 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
303 MachineState *ms = MACHINE(obj);
305 g_free(ms->dumpdtb);
306 ms->dumpdtb = g_strdup(value);
309 static void machine_get_phandle_start(Object *obj, Visitor *v,
310 const char *name, void *opaque,
311 Error **errp)
313 MachineState *ms = MACHINE(obj);
314 int64_t value = ms->phandle_start;
316 visit_type_int(v, name, &value, errp);
319 static void machine_set_phandle_start(Object *obj, Visitor *v,
320 const char *name, void *opaque,
321 Error **errp)
323 MachineState *ms = MACHINE(obj);
324 Error *error = NULL;
325 int64_t value;
327 visit_type_int(v, name, &value, &error);
328 if (error) {
329 error_propagate(errp, error);
330 return;
333 ms->phandle_start = value;
336 static char *machine_get_dt_compatible(Object *obj, Error **errp)
338 MachineState *ms = MACHINE(obj);
340 return g_strdup(ms->dt_compatible);
343 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
345 MachineState *ms = MACHINE(obj);
347 g_free(ms->dt_compatible);
348 ms->dt_compatible = g_strdup(value);
351 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
353 MachineState *ms = MACHINE(obj);
355 return ms->dump_guest_core;
358 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
360 MachineState *ms = MACHINE(obj);
362 ms->dump_guest_core = value;
365 static bool machine_get_mem_merge(Object *obj, Error **errp)
367 MachineState *ms = MACHINE(obj);
369 return ms->mem_merge;
372 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
374 MachineState *ms = MACHINE(obj);
376 ms->mem_merge = value;
379 static bool machine_get_usb(Object *obj, Error **errp)
381 MachineState *ms = MACHINE(obj);
383 return ms->usb;
386 static void machine_set_usb(Object *obj, bool value, Error **errp)
388 MachineState *ms = MACHINE(obj);
390 ms->usb = value;
391 ms->usb_disabled = !value;
394 static bool machine_get_graphics(Object *obj, Error **errp)
396 MachineState *ms = MACHINE(obj);
398 return ms->enable_graphics;
401 static void machine_set_graphics(Object *obj, bool value, Error **errp)
403 MachineState *ms = MACHINE(obj);
405 ms->enable_graphics = value;
408 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
410 MachineState *ms = MACHINE(obj);
412 return ms->igd_gfx_passthru;
415 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
417 MachineState *ms = MACHINE(obj);
419 ms->igd_gfx_passthru = value;
422 static char *machine_get_firmware(Object *obj, Error **errp)
424 MachineState *ms = MACHINE(obj);
426 return g_strdup(ms->firmware);
429 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
431 MachineState *ms = MACHINE(obj);
433 g_free(ms->firmware);
434 ms->firmware = g_strdup(value);
437 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
439 MachineState *ms = MACHINE(obj);
441 ms->suppress_vmdesc = value;
444 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
446 MachineState *ms = MACHINE(obj);
448 return ms->suppress_vmdesc;
451 static void machine_set_enforce_config_section(Object *obj, bool value,
452 Error **errp)
454 MachineState *ms = MACHINE(obj);
456 warn_report("enforce-config-section is deprecated, please use "
457 "-global migration.send-configuration=on|off instead");
459 ms->enforce_config_section = value;
462 static bool machine_get_enforce_config_section(Object *obj, Error **errp)
464 MachineState *ms = MACHINE(obj);
466 return ms->enforce_config_section;
469 static char *machine_get_memory_encryption(Object *obj, Error **errp)
471 MachineState *ms = MACHINE(obj);
473 return g_strdup(ms->memory_encryption);
476 static void machine_set_memory_encryption(Object *obj, const char *value,
477 Error **errp)
479 MachineState *ms = MACHINE(obj);
481 g_free(ms->memory_encryption);
482 ms->memory_encryption = g_strdup(value);
485 static bool machine_get_nvdimm(Object *obj, Error **errp)
487 MachineState *ms = MACHINE(obj);
489 return ms->nvdimms_state->is_enabled;
492 static void machine_set_nvdimm(Object *obj, bool value, Error **errp)
494 MachineState *ms = MACHINE(obj);
496 ms->nvdimms_state->is_enabled = value;
499 static char *machine_get_nvdimm_persistence(Object *obj, Error **errp)
501 MachineState *ms = MACHINE(obj);
503 return g_strdup(ms->nvdimms_state->persistence_string);
506 static void machine_set_nvdimm_persistence(Object *obj, const char *value,
507 Error **errp)
509 MachineState *ms = MACHINE(obj);
510 NVDIMMState *nvdimms_state = ms->nvdimms_state;
512 if (strcmp(value, "cpu") == 0) {
513 nvdimms_state->persistence = 3;
514 } else if (strcmp(value, "mem-ctrl") == 0) {
515 nvdimms_state->persistence = 2;
516 } else {
517 error_setg(errp, "-machine nvdimm-persistence=%s: unsupported option",
518 value);
519 return;
522 g_free(nvdimms_state->persistence_string);
523 nvdimms_state->persistence_string = g_strdup(value);
526 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
528 strList *item = g_new0(strList, 1);
530 item->value = g_strdup(type);
531 item->next = mc->allowed_dynamic_sysbus_devices;
532 mc->allowed_dynamic_sysbus_devices = item;
535 static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
537 MachineState *machine = opaque;
538 MachineClass *mc = MACHINE_GET_CLASS(machine);
539 bool allowed = false;
540 strList *wl;
542 for (wl = mc->allowed_dynamic_sysbus_devices;
543 !allowed && wl;
544 wl = wl->next) {
545 allowed |= !!object_dynamic_cast(OBJECT(sbdev), wl->value);
548 if (!allowed) {
549 error_report("Option '-device %s' cannot be handled by this machine",
550 object_class_get_name(object_get_class(OBJECT(sbdev))));
551 exit(1);
555 static void machine_init_notify(Notifier *notifier, void *data)
557 MachineState *machine = MACHINE(qdev_get_machine());
560 * Loop through all dynamically created sysbus devices and check if they are
561 * all allowed. If a device is not allowed, error out.
563 foreach_dynamic_sysbus_device(validate_sysbus_device, machine);
566 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
568 int i;
569 HotpluggableCPUList *head = NULL;
570 MachineClass *mc = MACHINE_GET_CLASS(machine);
572 /* force board to initialize possible_cpus if it hasn't been done yet */
573 mc->possible_cpu_arch_ids(machine);
575 for (i = 0; i < machine->possible_cpus->len; i++) {
576 Object *cpu;
577 HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
578 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
580 cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type);
581 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
582 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
583 sizeof(*cpu_item->props));
585 cpu = machine->possible_cpus->cpus[i].cpu;
586 if (cpu) {
587 cpu_item->has_qom_path = true;
588 cpu_item->qom_path = object_get_canonical_path(cpu);
590 list_item->value = cpu_item;
591 list_item->next = head;
592 head = list_item;
594 return head;
598 * machine_set_cpu_numa_node:
599 * @machine: machine object to modify
600 * @props: specifies which cpu objects to assign to
601 * numa node specified by @props.node_id
602 * @errp: if an error occurs, a pointer to an area to store the error
604 * Associate NUMA node specified by @props.node_id with cpu slots that
605 * match socket/core/thread-ids specified by @props. It's recommended to use
606 * query-hotpluggable-cpus.props values to specify affected cpu slots,
607 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
609 * However for CLI convenience it's possible to pass in subset of properties,
610 * which would affect all cpu slots that match it.
611 * Ex for pc machine:
612 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
613 * -numa cpu,node-id=0,socket_id=0 \
614 * -numa cpu,node-id=1,socket_id=1
615 * will assign all child cores of socket 0 to node 0 and
616 * of socket 1 to node 1.
618 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
619 * return error.
620 * Empty subset is disallowed and function will return with error in this case.
622 void machine_set_cpu_numa_node(MachineState *machine,
623 const CpuInstanceProperties *props, Error **errp)
625 MachineClass *mc = MACHINE_GET_CLASS(machine);
626 bool match = false;
627 int i;
629 if (!mc->possible_cpu_arch_ids) {
630 error_setg(errp, "mapping of CPUs to NUMA node is not supported");
631 return;
634 /* disabling node mapping is not supported, forbid it */
635 assert(props->has_node_id);
637 /* force board to initialize possible_cpus if it hasn't been done yet */
638 mc->possible_cpu_arch_ids(machine);
640 for (i = 0; i < machine->possible_cpus->len; i++) {
641 CPUArchId *slot = &machine->possible_cpus->cpus[i];
643 /* reject unsupported by board properties */
644 if (props->has_thread_id && !slot->props.has_thread_id) {
645 error_setg(errp, "thread-id is not supported");
646 return;
649 if (props->has_core_id && !slot->props.has_core_id) {
650 error_setg(errp, "core-id is not supported");
651 return;
654 if (props->has_socket_id && !slot->props.has_socket_id) {
655 error_setg(errp, "socket-id is not supported");
656 return;
659 /* skip slots with explicit mismatch */
660 if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
661 continue;
664 if (props->has_core_id && props->core_id != slot->props.core_id) {
665 continue;
668 if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
669 continue;
672 /* reject assignment if slot is already assigned, for compatibility
673 * of legacy cpu_index mapping with SPAPR core based mapping do not
674 * error out if cpu thread and matched core have the same node-id */
675 if (slot->props.has_node_id &&
676 slot->props.node_id != props->node_id) {
677 error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
678 slot->props.node_id);
679 return;
682 /* assign slot to node as it's matched '-numa cpu' key */
683 match = true;
684 slot->props.node_id = props->node_id;
685 slot->props.has_node_id = props->has_node_id;
688 if (!match) {
689 error_setg(errp, "no match found");
693 static void machine_class_init(ObjectClass *oc, void *data)
695 MachineClass *mc = MACHINE_CLASS(oc);
697 /* Default 128 MB as guest ram size */
698 mc->default_ram_size = 128 * MiB;
699 mc->rom_file_has_mr = true;
701 /* numa node memory size aligned on 8MB by default.
702 * On Linux, each node's border has to be 8MB aligned
704 mc->numa_mem_align_shift = 23;
705 mc->numa_auto_assign_ram = numa_default_auto_assign_ram;
707 object_class_property_add_str(oc, "accel",
708 machine_get_accel, machine_set_accel, &error_abort);
709 object_class_property_set_description(oc, "accel",
710 "Accelerator list", &error_abort);
712 object_class_property_add(oc, "kernel-irqchip", "on|off|split",
713 NULL, machine_set_kernel_irqchip,
714 NULL, NULL, &error_abort);
715 object_class_property_set_description(oc, "kernel-irqchip",
716 "Configure KVM in-kernel irqchip", &error_abort);
718 object_class_property_add(oc, "kvm-shadow-mem", "int",
719 machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
720 NULL, NULL, &error_abort);
721 object_class_property_set_description(oc, "kvm-shadow-mem",
722 "KVM shadow MMU size", &error_abort);
724 object_class_property_add_str(oc, "kernel",
725 machine_get_kernel, machine_set_kernel, &error_abort);
726 object_class_property_set_description(oc, "kernel",
727 "Linux kernel image file", &error_abort);
729 object_class_property_add_str(oc, "initrd",
730 machine_get_initrd, machine_set_initrd, &error_abort);
731 object_class_property_set_description(oc, "initrd",
732 "Linux initial ramdisk file", &error_abort);
734 object_class_property_add_str(oc, "append",
735 machine_get_append, machine_set_append, &error_abort);
736 object_class_property_set_description(oc, "append",
737 "Linux kernel command line", &error_abort);
739 object_class_property_add_str(oc, "dtb",
740 machine_get_dtb, machine_set_dtb, &error_abort);
741 object_class_property_set_description(oc, "dtb",
742 "Linux kernel device tree file", &error_abort);
744 object_class_property_add_str(oc, "dumpdtb",
745 machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
746 object_class_property_set_description(oc, "dumpdtb",
747 "Dump current dtb to a file and quit", &error_abort);
749 object_class_property_add(oc, "phandle-start", "int",
750 machine_get_phandle_start, machine_set_phandle_start,
751 NULL, NULL, &error_abort);
752 object_class_property_set_description(oc, "phandle-start",
753 "The first phandle ID we may generate dynamically", &error_abort);
755 object_class_property_add_str(oc, "dt-compatible",
756 machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
757 object_class_property_set_description(oc, "dt-compatible",
758 "Overrides the \"compatible\" property of the dt root node",
759 &error_abort);
761 object_class_property_add_bool(oc, "dump-guest-core",
762 machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
763 object_class_property_set_description(oc, "dump-guest-core",
764 "Include guest memory in a core dump", &error_abort);
766 object_class_property_add_bool(oc, "mem-merge",
767 machine_get_mem_merge, machine_set_mem_merge, &error_abort);
768 object_class_property_set_description(oc, "mem-merge",
769 "Enable/disable memory merge support", &error_abort);
771 object_class_property_add_bool(oc, "usb",
772 machine_get_usb, machine_set_usb, &error_abort);
773 object_class_property_set_description(oc, "usb",
774 "Set on/off to enable/disable usb", &error_abort);
776 object_class_property_add_bool(oc, "graphics",
777 machine_get_graphics, machine_set_graphics, &error_abort);
778 object_class_property_set_description(oc, "graphics",
779 "Set on/off to enable/disable graphics emulation", &error_abort);
781 object_class_property_add_bool(oc, "igd-passthru",
782 machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
783 &error_abort);
784 object_class_property_set_description(oc, "igd-passthru",
785 "Set on/off to enable/disable igd passthrou", &error_abort);
787 object_class_property_add_str(oc, "firmware",
788 machine_get_firmware, machine_set_firmware,
789 &error_abort);
790 object_class_property_set_description(oc, "firmware",
791 "Firmware image", &error_abort);
793 object_class_property_add_bool(oc, "suppress-vmdesc",
794 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
795 &error_abort);
796 object_class_property_set_description(oc, "suppress-vmdesc",
797 "Set on to disable self-describing migration", &error_abort);
799 object_class_property_add_bool(oc, "enforce-config-section",
800 machine_get_enforce_config_section, machine_set_enforce_config_section,
801 &error_abort);
802 object_class_property_set_description(oc, "enforce-config-section",
803 "Set on to enforce configuration section migration", &error_abort);
805 object_class_property_add_str(oc, "memory-encryption",
806 machine_get_memory_encryption, machine_set_memory_encryption,
807 &error_abort);
808 object_class_property_set_description(oc, "memory-encryption",
809 "Set memory encryption object to use", &error_abort);
812 static void machine_class_base_init(ObjectClass *oc, void *data)
814 if (!object_class_is_abstract(oc)) {
815 MachineClass *mc = MACHINE_CLASS(oc);
816 const char *cname = object_class_get_name(oc);
817 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
818 mc->name = g_strndup(cname,
819 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
820 mc->compat_props = g_ptr_array_new();
824 static void machine_initfn(Object *obj)
826 MachineState *ms = MACHINE(obj);
827 MachineClass *mc = MACHINE_GET_CLASS(obj);
829 ms->kernel_irqchip_allowed = true;
830 ms->kernel_irqchip_split = mc->default_kernel_irqchip_split;
831 ms->kvm_shadow_mem = -1;
832 ms->dump_guest_core = true;
833 ms->mem_merge = true;
834 ms->enable_graphics = true;
836 if (mc->nvdimm_supported) {
837 Object *obj = OBJECT(ms);
839 ms->nvdimms_state = g_new0(NVDIMMState, 1);
840 object_property_add_bool(obj, "nvdimm",
841 machine_get_nvdimm, machine_set_nvdimm,
842 &error_abort);
843 object_property_set_description(obj, "nvdimm",
844 "Set on/off to enable/disable "
845 "NVDIMM instantiation", NULL);
847 object_property_add_str(obj, "nvdimm-persistence",
848 machine_get_nvdimm_persistence,
849 machine_set_nvdimm_persistence,
850 &error_abort);
851 object_property_set_description(obj, "nvdimm-persistence",
852 "Set NVDIMM persistence"
853 "Valid values are cpu, mem-ctrl",
854 NULL);
858 /* Register notifier when init is done for sysbus sanity checks */
859 ms->sysbus_notifier.notify = machine_init_notify;
860 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
863 static void machine_finalize(Object *obj)
865 MachineState *ms = MACHINE(obj);
867 g_free(ms->accel);
868 g_free(ms->kernel_filename);
869 g_free(ms->initrd_filename);
870 g_free(ms->kernel_cmdline);
871 g_free(ms->dtb);
872 g_free(ms->dumpdtb);
873 g_free(ms->dt_compatible);
874 g_free(ms->firmware);
875 g_free(ms->device_memory);
876 g_free(ms->nvdimms_state);
879 bool machine_usb(MachineState *machine)
881 return machine->usb;
884 bool machine_kernel_irqchip_allowed(MachineState *machine)
886 return machine->kernel_irqchip_allowed;
889 bool machine_kernel_irqchip_required(MachineState *machine)
891 return machine->kernel_irqchip_required;
894 bool machine_kernel_irqchip_split(MachineState *machine)
896 return machine->kernel_irqchip_split;
899 int machine_kvm_shadow_mem(MachineState *machine)
901 return machine->kvm_shadow_mem;
904 int machine_phandle_start(MachineState *machine)
906 return machine->phandle_start;
909 bool machine_dump_guest_core(MachineState *machine)
911 return machine->dump_guest_core;
914 bool machine_mem_merge(MachineState *machine)
916 return machine->mem_merge;
919 static char *cpu_slot_to_string(const CPUArchId *cpu)
921 GString *s = g_string_new(NULL);
922 if (cpu->props.has_socket_id) {
923 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
925 if (cpu->props.has_core_id) {
926 if (s->len) {
927 g_string_append_printf(s, ", ");
929 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
931 if (cpu->props.has_thread_id) {
932 if (s->len) {
933 g_string_append_printf(s, ", ");
935 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
937 return g_string_free(s, false);
940 static void machine_numa_finish_cpu_init(MachineState *machine)
942 int i;
943 bool default_mapping;
944 GString *s = g_string_new(NULL);
945 MachineClass *mc = MACHINE_GET_CLASS(machine);
946 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
948 assert(nb_numa_nodes);
949 for (i = 0; i < possible_cpus->len; i++) {
950 if (possible_cpus->cpus[i].props.has_node_id) {
951 break;
954 default_mapping = (i == possible_cpus->len);
956 for (i = 0; i < possible_cpus->len; i++) {
957 const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
959 if (!cpu_slot->props.has_node_id) {
960 /* fetch default mapping from board and enable it */
961 CpuInstanceProperties props = cpu_slot->props;
963 props.node_id = mc->get_default_cpu_node_id(machine, i);
964 if (!default_mapping) {
965 /* record slots with not set mapping,
966 * TODO: make it hard error in future */
967 char *cpu_str = cpu_slot_to_string(cpu_slot);
968 g_string_append_printf(s, "%sCPU %d [%s]",
969 s->len ? ", " : "", i, cpu_str);
970 g_free(cpu_str);
972 /* non mapped cpus used to fallback to node 0 */
973 props.node_id = 0;
976 props.has_node_id = true;
977 machine_set_cpu_numa_node(machine, &props, &error_fatal);
980 if (s->len && !qtest_enabled()) {
981 warn_report("CPU(s) not present in any NUMA nodes: %s",
982 s->str);
983 warn_report("All CPU(s) up to maxcpus should be described "
984 "in NUMA config, ability to start up with partial NUMA "
985 "mappings is obsoleted and will be removed in future");
987 g_string_free(s, true);
990 void machine_run_board_init(MachineState *machine)
992 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
994 numa_complete_configuration(machine);
995 if (nb_numa_nodes) {
996 machine_numa_finish_cpu_init(machine);
999 /* If the machine supports the valid_cpu_types check and the user
1000 * specified a CPU with -cpu check here that the user CPU is supported.
1002 if (machine_class->valid_cpu_types && machine->cpu_type) {
1003 ObjectClass *class = object_class_by_name(machine->cpu_type);
1004 int i;
1006 for (i = 0; machine_class->valid_cpu_types[i]; i++) {
1007 if (object_class_dynamic_cast(class,
1008 machine_class->valid_cpu_types[i])) {
1009 /* The user specificed CPU is in the valid field, we are
1010 * good to go.
1012 break;
1016 if (!machine_class->valid_cpu_types[i]) {
1017 /* The user specified CPU is not valid */
1018 error_report("Invalid CPU type: %s", machine->cpu_type);
1019 error_printf("The valid types are: %s",
1020 machine_class->valid_cpu_types[0]);
1021 for (i = 1; machine_class->valid_cpu_types[i]; i++) {
1022 error_printf(", %s", machine_class->valid_cpu_types[i]);
1024 error_printf("\n");
1026 exit(1);
1030 machine_class->init(machine);
1033 static const TypeInfo machine_info = {
1034 .name = TYPE_MACHINE,
1035 .parent = TYPE_OBJECT,
1036 .abstract = true,
1037 .class_size = sizeof(MachineClass),
1038 .class_init = machine_class_init,
1039 .class_base_init = machine_class_base_init,
1040 .instance_size = sizeof(MachineState),
1041 .instance_init = machine_initfn,
1042 .instance_finalize = machine_finalize,
1045 static void machine_register_types(void)
1047 type_register_static(&machine_info);
1050 type_init(machine_register_types)