1 /* 2 * QEMU Machine 3 * 4 * Copyright (C) 2014 Red Hat Inc 5 * 6 * Authors: 7 * Marcel Apfelbaum <marcel.a@redhat.com> 8 * 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. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qemu/option.h" 15 #include "qapi/qmp/qerror.h" 16 #include "sysemu/replay.h" 17 #include "qemu/units.h" 18 #include "hw/boards.h" 19 #include "hw/loader.h" 20 #include "qapi/error.h" 21 #include "qapi/qapi-visit-common.h" 22 #include "qapi/qapi-visit-machine.h" 23 #include "qapi/visitor.h" 24 #include "hw/sysbus.h" 25 #include "sysemu/cpus.h" 26 #include "sysemu/sysemu.h" 27 #include "sysemu/reset.h" 28 #include "sysemu/runstate.h" 29 #include "sysemu/numa.h" 30 #include "qemu/error-report.h" 31 #include "sysemu/qtest.h" 32 #include "hw/pci/pci.h" 33 #include "hw/mem/nvdimm.h" 34 #include "migration/global_state.h" 35 #include "migration/vmstate.h" 36 #include "exec/confidential-guest-support.h" 37 #include "hw/virtio/virtio.h" 38 #include "hw/virtio/virtio-pci.h" 39 40 GlobalProperty hw_compat_7_0[] = {}; 41 const size_t hw_compat_7_0_len = G_N_ELEMENTS(hw_compat_7_0); 42 43 GlobalProperty hw_compat_6_2[] = { 44 { "PIIX4_PM", "x-not-migrate-acpi-index", "on"}, 45 }; 46 const size_t hw_compat_6_2_len = G_N_ELEMENTS(hw_compat_6_2); 47 48 GlobalProperty hw_compat_6_1[] = { 49 { "vhost-user-vsock-device", "seqpacket", "off" }, 50 { "nvme-ns", "shared", "off" }, 51 }; 52 const size_t hw_compat_6_1_len = G_N_ELEMENTS(hw_compat_6_1); 53 54 GlobalProperty hw_compat_6_0[] = { 55 { "gpex-pcihost", "allow-unmapped-accesses", "false" }, 56 { "i8042", "extended-state", "false"}, 57 { "nvme-ns", "eui64-default", "off"}, 58 { "e1000", "init-vet", "off" }, 59 { "e1000e", "init-vet", "off" }, 60 { "vhost-vsock-device", "seqpacket", "off" }, 61 }; 62 const size_t hw_compat_6_0_len = G_N_ELEMENTS(hw_compat_6_0); 63 64 GlobalProperty hw_compat_5_2[] = { 65 { "ICH9-LPC", "smm-compat", "on"}, 66 { "PIIX4_PM", "smm-compat", "on"}, 67 { "virtio-blk-device", "report-discard-granularity", "off" }, 68 { "virtio-net-pci-base", "vectors", "3"}, 69 }; 70 const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2); 71 72 GlobalProperty hw_compat_5_1[] = { 73 { "vhost-scsi", "num_queues", "1"}, 74 { "vhost-user-blk", "num-queues", "1"}, 75 { "vhost-user-scsi", "num_queues", "1"}, 76 { "virtio-blk-device", "num-queues", "1"}, 77 { "virtio-scsi-device", "num_queues", "1"}, 78 { "nvme", "use-intel-id", "on"}, 79 { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */ 80 { "pl011", "migrate-clk", "off" }, 81 { "virtio-pci", "x-ats-page-aligned", "off"}, 82 }; 83 const size_t hw_compat_5_1_len = G_N_ELEMENTS(hw_compat_5_1); 84 85 GlobalProperty hw_compat_5_0[] = { 86 { "pci-host-bridge", "x-config-reg-migration-enabled", "off" }, 87 { "virtio-balloon-device", "page-poison", "false" }, 88 { "vmport", "x-read-set-eax", "off" }, 89 { "vmport", "x-signal-unsupported-cmd", "off" }, 90 { "vmport", "x-report-vmx-type", "off" }, 91 { "vmport", "x-cmds-v2", "off" }, 92 { "virtio-device", "x-disable-legacy-check", "true" }, 93 }; 94 const size_t hw_compat_5_0_len = G_N_ELEMENTS(hw_compat_5_0); 95 96 GlobalProperty hw_compat_4_2[] = { 97 { "virtio-blk-device", "queue-size", "128"}, 98 { "virtio-scsi-device", "virtqueue_size", "128"}, 99 { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" }, 100 { "virtio-blk-device", "seg-max-adjust", "off"}, 101 { "virtio-scsi-device", "seg_max_adjust", "off"}, 102 { "vhost-blk-device", "seg_max_adjust", "off"}, 103 { "usb-host", "suppress-remote-wake", "off" }, 104 { "usb-redir", "suppress-remote-wake", "off" }, 105 { "qxl", "revision", "4" }, 106 { "qxl-vga", "revision", "4" }, 107 { "fw_cfg", "acpi-mr-restore", "false" }, 108 { "virtio-device", "use-disabled-flag", "false" }, 109 }; 110 const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2); 111 112 GlobalProperty hw_compat_4_1[] = { 113 { "virtio-pci", "x-pcie-flr-init", "off" }, 114 }; 115 const size_t hw_compat_4_1_len = G_N_ELEMENTS(hw_compat_4_1); 116 117 GlobalProperty hw_compat_4_0[] = { 118 { "VGA", "edid", "false" }, 119 { "secondary-vga", "edid", "false" }, 120 { "bochs-display", "edid", "false" }, 121 { "virtio-vga", "edid", "false" }, 122 { "virtio-gpu-device", "edid", "false" }, 123 { "virtio-device", "use-started", "false" }, 124 { "virtio-balloon-device", "qemu-4-0-config-size", "true" }, 125 { "pl031", "migrate-tick-offset", "false" }, 126 }; 127 const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0); 128 129 GlobalProperty hw_compat_3_1[] = { 130 { "pcie-root-port", "x-speed", "2_5" }, 131 { "pcie-root-port", "x-width", "1" }, 132 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" }, 133 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" }, 134 { "tpm-crb", "ppi", "false" }, 135 { "tpm-tis", "ppi", "false" }, 136 { "usb-kbd", "serial", "42" }, 137 { "usb-mouse", "serial", "42" }, 138 { "usb-tablet", "serial", "42" }, 139 { "virtio-blk-device", "discard", "false" }, 140 { "virtio-blk-device", "write-zeroes", "false" }, 141 { "virtio-balloon-device", "qemu-4-0-config-size", "false" }, 142 { "pcie-root-port-base", "disable-acs", "true" }, /* Added in 4.1 */ 143 }; 144 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1); 145 146 GlobalProperty hw_compat_3_0[] = {}; 147 const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0); 148 149 GlobalProperty hw_compat_2_12[] = { 150 { "migration", "decompress-error-check", "off" }, 151 { "hda-audio", "use-timer", "false" }, 152 { "cirrus-vga", "global-vmstate", "true" }, 153 { "VGA", "global-vmstate", "true" }, 154 { "vmware-svga", "global-vmstate", "true" }, 155 { "qxl-vga", "global-vmstate", "true" }, 156 }; 157 const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12); 158 159 GlobalProperty hw_compat_2_11[] = { 160 { "hpet", "hpet-offset-saved", "false" }, 161 { "virtio-blk-pci", "vectors", "2" }, 162 { "vhost-user-blk-pci", "vectors", "2" }, 163 { "e1000", "migrate_tso_props", "off" }, 164 }; 165 const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11); 166 167 GlobalProperty hw_compat_2_10[] = { 168 { "virtio-mouse-device", "wheel-axis", "false" }, 169 { "virtio-tablet-device", "wheel-axis", "false" }, 170 }; 171 const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10); 172 173 GlobalProperty hw_compat_2_9[] = { 174 { "pci-bridge", "shpc", "off" }, 175 { "intel-iommu", "pt", "off" }, 176 { "virtio-net-device", "x-mtu-bypass-backend", "off" }, 177 { "pcie-root-port", "x-migrate-msix", "false" }, 178 }; 179 const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9); 180 181 GlobalProperty hw_compat_2_8[] = { 182 { "fw_cfg_mem", "x-file-slots", "0x10" }, 183 { "fw_cfg_io", "x-file-slots", "0x10" }, 184 { "pflash_cfi01", "old-multiple-chip-handling", "on" }, 185 { "pci-bridge", "shpc", "on" }, 186 { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" }, 187 { "virtio-pci", "x-pcie-deverr-init", "off" }, 188 { "virtio-pci", "x-pcie-lnkctl-init", "off" }, 189 { "virtio-pci", "x-pcie-pm-init", "off" }, 190 { "cirrus-vga", "vgamem_mb", "8" }, 191 { "isa-cirrus-vga", "vgamem_mb", "8" }, 192 }; 193 const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8); 194 195 GlobalProperty hw_compat_2_7[] = { 196 { "virtio-pci", "page-per-vq", "on" }, 197 { "virtio-serial-device", "emergency-write", "off" }, 198 { "ioapic", "version", "0x11" }, 199 { "intel-iommu", "x-buggy-eim", "true" }, 200 { "virtio-pci", "x-ignore-backend-features", "on" }, 201 }; 202 const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); 203 204 GlobalProperty hw_compat_2_6[] = { 205 { "virtio-mmio", "format_transport_address", "off" }, 206 /* Optional because not all virtio-pci devices support legacy mode */ 207 { "virtio-pci", "disable-modern", "on", .optional = true }, 208 { "virtio-pci", "disable-legacy", "off", .optional = true }, 209 }; 210 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6); 211 212 GlobalProperty hw_compat_2_5[] = { 213 { "isa-fdc", "fallback", "144" }, 214 { "pvscsi", "x-old-pci-configuration", "on" }, 215 { "pvscsi", "x-disable-pcie", "on" }, 216 { "vmxnet3", "x-old-msi-offsets", "on" }, 217 { "vmxnet3", "x-disable-pcie", "on" }, 218 }; 219 const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5); 220 221 GlobalProperty hw_compat_2_4[] = { 222 /* Optional because the 'scsi' property is Linux-only */ 223 { "virtio-blk-device", "scsi", "true", .optional = true }, 224 { "e1000", "extra_mac_registers", "off" }, 225 { "virtio-pci", "x-disable-pcie", "on" }, 226 { "virtio-pci", "migrate-extra", "off" }, 227 { "fw_cfg_mem", "dma_enabled", "off" }, 228 { "fw_cfg_io", "dma_enabled", "off" } 229 }; 230 const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4); 231 232 GlobalProperty hw_compat_2_3[] = { 233 { "virtio-blk-pci", "any_layout", "off" }, 234 { "virtio-balloon-pci", "any_layout", "off" }, 235 { "virtio-serial-pci", "any_layout", "off" }, 236 { "virtio-9p-pci", "any_layout", "off" }, 237 { "virtio-rng-pci", "any_layout", "off" }, 238 { TYPE_PCI_DEVICE, "x-pcie-lnksta-dllla", "off" }, 239 { "migration", "send-configuration", "off" }, 240 { "migration", "send-section-footer", "off" }, 241 { "migration", "store-global-state", "off" }, 242 }; 243 const size_t hw_compat_2_3_len = G_N_ELEMENTS(hw_compat_2_3); 244 245 GlobalProperty hw_compat_2_2[] = {}; 246 const size_t hw_compat_2_2_len = G_N_ELEMENTS(hw_compat_2_2); 247 248 GlobalProperty hw_compat_2_1[] = { 249 { "intel-hda", "old_msi_addr", "on" }, 250 { "VGA", "qemu-extended-regs", "off" }, 251 { "secondary-vga", "qemu-extended-regs", "off" }, 252 { "virtio-scsi-pci", "any_layout", "off" }, 253 { "usb-mouse", "usb_version", "1" }, 254 { "usb-kbd", "usb_version", "1" }, 255 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" }, 256 }; 257 const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1); 258 259 MachineState *current_machine; 260 261 static char *machine_get_kernel(Object *obj, Error **errp) 262 { 263 MachineState *ms = MACHINE(obj); 264 265 return g_strdup(ms->kernel_filename); 266 } 267 268 static void machine_set_kernel(Object *obj, const char *value, Error **errp) 269 { 270 MachineState *ms = MACHINE(obj); 271 272 g_free(ms->kernel_filename); 273 ms->kernel_filename = g_strdup(value); 274 } 275 276 static char *machine_get_initrd(Object *obj, Error **errp) 277 { 278 MachineState *ms = MACHINE(obj); 279 280 return g_strdup(ms->initrd_filename); 281 } 282 283 static void machine_set_initrd(Object *obj, const char *value, Error **errp) 284 { 285 MachineState *ms = MACHINE(obj); 286 287 g_free(ms->initrd_filename); 288 ms->initrd_filename = g_strdup(value); 289 } 290 291 static char *machine_get_append(Object *obj, Error **errp) 292 { 293 MachineState *ms = MACHINE(obj); 294 295 return g_strdup(ms->kernel_cmdline); 296 } 297 298 static void machine_set_append(Object *obj, const char *value, Error **errp) 299 { 300 MachineState *ms = MACHINE(obj); 301 302 g_free(ms->kernel_cmdline); 303 ms->kernel_cmdline = g_strdup(value); 304 } 305 306 static char *machine_get_dtb(Object *obj, Error **errp) 307 { 308 MachineState *ms = MACHINE(obj); 309 310 return g_strdup(ms->dtb); 311 } 312 313 static void machine_set_dtb(Object *obj, const char *value, Error **errp) 314 { 315 MachineState *ms = MACHINE(obj); 316 317 g_free(ms->dtb); 318 ms->dtb = g_strdup(value); 319 } 320 321 static char *machine_get_dumpdtb(Object *obj, Error **errp) 322 { 323 MachineState *ms = MACHINE(obj); 324 325 return g_strdup(ms->dumpdtb); 326 } 327 328 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) 329 { 330 MachineState *ms = MACHINE(obj); 331 332 g_free(ms->dumpdtb); 333 ms->dumpdtb = g_strdup(value); 334 } 335 336 static void machine_get_phandle_start(Object *obj, Visitor *v, 337 const char *name, void *opaque, 338 Error **errp) 339 { 340 MachineState *ms = MACHINE(obj); 341 int64_t value = ms->phandle_start; 342 343 visit_type_int(v, name, &value, errp); 344 } 345 346 static void machine_set_phandle_start(Object *obj, Visitor *v, 347 const char *name, void *opaque, 348 Error **errp) 349 { 350 MachineState *ms = MACHINE(obj); 351 int64_t value; 352 353 if (!visit_type_int(v, name, &value, errp)) { 354 return; 355 } 356 357 ms->phandle_start = value; 358 } 359 360 static char *machine_get_dt_compatible(Object *obj, Error **errp) 361 { 362 MachineState *ms = MACHINE(obj); 363 364 return g_strdup(ms->dt_compatible); 365 } 366 367 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp) 368 { 369 MachineState *ms = MACHINE(obj); 370 371 g_free(ms->dt_compatible); 372 ms->dt_compatible = g_strdup(value); 373 } 374 375 static bool machine_get_dump_guest_core(Object *obj, Error **errp) 376 { 377 MachineState *ms = MACHINE(obj); 378 379 return ms->dump_guest_core; 380 } 381 382 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) 383 { 384 MachineState *ms = MACHINE(obj); 385 386 ms->dump_guest_core = value; 387 } 388 389 static bool machine_get_mem_merge(Object *obj, Error **errp) 390 { 391 MachineState *ms = MACHINE(obj); 392 393 return ms->mem_merge; 394 } 395 396 static void machine_set_mem_merge(Object *obj, bool value, Error **errp) 397 { 398 MachineState *ms = MACHINE(obj); 399 400 ms->mem_merge = value; 401 } 402 403 static bool machine_get_usb(Object *obj, Error **errp) 404 { 405 MachineState *ms = MACHINE(obj); 406 407 return ms->usb; 408 } 409 410 static void machine_set_usb(Object *obj, bool value, Error **errp) 411 { 412 MachineState *ms = MACHINE(obj); 413 414 ms->usb = value; 415 ms->usb_disabled = !value; 416 } 417 418 static bool machine_get_graphics(Object *obj, Error **errp) 419 { 420 MachineState *ms = MACHINE(obj); 421 422 return ms->enable_graphics; 423 } 424 425 static void machine_set_graphics(Object *obj, bool value, Error **errp) 426 { 427 MachineState *ms = MACHINE(obj); 428 429 ms->enable_graphics = value; 430 } 431 432 static char *machine_get_firmware(Object *obj, Error **errp) 433 { 434 MachineState *ms = MACHINE(obj); 435 436 return g_strdup(ms->firmware); 437 } 438 439 static void machine_set_firmware(Object *obj, const char *value, Error **errp) 440 { 441 MachineState *ms = MACHINE(obj); 442 443 g_free(ms->firmware); 444 ms->firmware = g_strdup(value); 445 } 446 447 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp) 448 { 449 MachineState *ms = MACHINE(obj); 450 451 ms->suppress_vmdesc = value; 452 } 453 454 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp) 455 { 456 MachineState *ms = MACHINE(obj); 457 458 return ms->suppress_vmdesc; 459 } 460 461 static char *machine_get_memory_encryption(Object *obj, Error **errp) 462 { 463 MachineState *ms = MACHINE(obj); 464 465 if (ms->cgs) { 466 return g_strdup(object_get_canonical_path_component(OBJECT(ms->cgs))); 467 } 468 469 return NULL; 470 } 471 472 static void machine_set_memory_encryption(Object *obj, const char *value, 473 Error **errp) 474 { 475 Object *cgs = 476 object_resolve_path_component(object_get_objects_root(), value); 477 478 if (!cgs) { 479 error_setg(errp, "No such memory encryption object '%s'", value); 480 return; 481 } 482 483 object_property_set_link(obj, "confidential-guest-support", cgs, errp); 484 } 485 486 static void machine_check_confidential_guest_support(const Object *obj, 487 const char *name, 488 Object *new_target, 489 Error **errp) 490 { 491 /* 492 * So far the only constraint is that the target has the 493 * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked 494 * by the QOM core 495 */ 496 } 497 498 static bool machine_get_nvdimm(Object *obj, Error **errp) 499 { 500 MachineState *ms = MACHINE(obj); 501 502 return ms->nvdimms_state->is_enabled; 503 } 504 505 static void machine_set_nvdimm(Object *obj, bool value, Error **errp) 506 { 507 MachineState *ms = MACHINE(obj); 508 509 ms->nvdimms_state->is_enabled = value; 510 } 511 512 static bool machine_get_hmat(Object *obj, Error **errp) 513 { 514 MachineState *ms = MACHINE(obj); 515 516 return ms->numa_state->hmat_enabled; 517 } 518 519 static void machine_set_hmat(Object *obj, bool value, Error **errp) 520 { 521 MachineState *ms = MACHINE(obj); 522 523 ms->numa_state->hmat_enabled = value; 524 } 525 526 static char *machine_get_nvdimm_persistence(Object *obj, Error **errp) 527 { 528 MachineState *ms = MACHINE(obj); 529 530 return g_strdup(ms->nvdimms_state->persistence_string); 531 } 532 533 static void machine_set_nvdimm_persistence(Object *obj, const char *value, 534 Error **errp) 535 { 536 MachineState *ms = MACHINE(obj); 537 NVDIMMState *nvdimms_state = ms->nvdimms_state; 538 539 if (strcmp(value, "cpu") == 0) { 540 nvdimms_state->persistence = 3; 541 } else if (strcmp(value, "mem-ctrl") == 0) { 542 nvdimms_state->persistence = 2; 543 } else { 544 error_setg(errp, "-machine nvdimm-persistence=%s: unsupported option", 545 value); 546 return; 547 } 548 549 g_free(nvdimms_state->persistence_string); 550 nvdimms_state->persistence_string = g_strdup(value); 551 } 552 553 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type) 554 { 555 QAPI_LIST_PREPEND(mc->allowed_dynamic_sysbus_devices, g_strdup(type)); 556 } 557 558 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev) 559 { 560 Object *obj = OBJECT(dev); 561 562 if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) { 563 return false; 564 } 565 566 return device_type_is_dynamic_sysbus(mc, object_get_typename(obj)); 567 } 568 569 bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type) 570 { 571 bool allowed = false; 572 strList *wl; 573 ObjectClass *klass = object_class_by_name(type); 574 575 for (wl = mc->allowed_dynamic_sysbus_devices; 576 !allowed && wl; 577 wl = wl->next) { 578 allowed |= !!object_class_dynamic_cast(klass, wl->value); 579 } 580 581 return allowed; 582 } 583 584 static char *machine_get_memdev(Object *obj, Error **errp) 585 { 586 MachineState *ms = MACHINE(obj); 587 588 return g_strdup(ms->ram_memdev_id); 589 } 590 591 static void machine_set_memdev(Object *obj, const char *value, Error **errp) 592 { 593 MachineState *ms = MACHINE(obj); 594 595 g_free(ms->ram_memdev_id); 596 ms->ram_memdev_id = g_strdup(value); 597 } 598 599 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine) 600 { 601 int i; 602 HotpluggableCPUList *head = NULL; 603 MachineClass *mc = MACHINE_GET_CLASS(machine); 604 605 /* force board to initialize possible_cpus if it hasn't been done yet */ 606 mc->possible_cpu_arch_ids(machine); 607 608 for (i = 0; i < machine->possible_cpus->len; i++) { 609 Object *cpu; 610 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1); 611 612 cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type); 613 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count; 614 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props, 615 sizeof(*cpu_item->props)); 616 617 cpu = machine->possible_cpus->cpus[i].cpu; 618 if (cpu) { 619 cpu_item->has_qom_path = true; 620 cpu_item->qom_path = object_get_canonical_path(cpu); 621 } 622 QAPI_LIST_PREPEND(head, cpu_item); 623 } 624 return head; 625 } 626 627 /** 628 * machine_set_cpu_numa_node: 629 * @machine: machine object to modify 630 * @props: specifies which cpu objects to assign to 631 * numa node specified by @props.node_id 632 * @errp: if an error occurs, a pointer to an area to store the error 633 * 634 * Associate NUMA node specified by @props.node_id with cpu slots that 635 * match socket/core/thread-ids specified by @props. It's recommended to use 636 * query-hotpluggable-cpus.props values to specify affected cpu slots, 637 * which would lead to exact 1:1 mapping of cpu slots to NUMA node. 638 * 639 * However for CLI convenience it's possible to pass in subset of properties, 640 * which would affect all cpu slots that match it. 641 * Ex for pc machine: 642 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \ 643 * -numa cpu,node-id=0,socket_id=0 \ 644 * -numa cpu,node-id=1,socket_id=1 645 * will assign all child cores of socket 0 to node 0 and 646 * of socket 1 to node 1. 647 * 648 * On attempt of reassigning (already assigned) cpu slot to another NUMA node, 649 * return error. 650 * Empty subset is disallowed and function will return with error in this case. 651 */ 652 void machine_set_cpu_numa_node(MachineState *machine, 653 const CpuInstanceProperties *props, Error **errp) 654 { 655 MachineClass *mc = MACHINE_GET_CLASS(machine); 656 NodeInfo *numa_info = machine->numa_state->nodes; 657 bool match = false; 658 int i; 659 660 if (!mc->possible_cpu_arch_ids) { 661 error_setg(errp, "mapping of CPUs to NUMA node is not supported"); 662 return; 663 } 664 665 /* disabling node mapping is not supported, forbid it */ 666 assert(props->has_node_id); 667 668 /* force board to initialize possible_cpus if it hasn't been done yet */ 669 mc->possible_cpu_arch_ids(machine); 670 671 for (i = 0; i < machine->possible_cpus->len; i++) { 672 CPUArchId *slot = &machine->possible_cpus->cpus[i]; 673 674 /* reject unsupported by board properties */ 675 if (props->has_thread_id && !slot->props.has_thread_id) { 676 error_setg(errp, "thread-id is not supported"); 677 return; 678 } 679 680 if (props->has_core_id && !slot->props.has_core_id) { 681 error_setg(errp, "core-id is not supported"); 682 return; 683 } 684 685 if (props->has_cluster_id && !slot->props.has_cluster_id) { 686 error_setg(errp, "cluster-id is not supported"); 687 return; 688 } 689 690 if (props->has_socket_id && !slot->props.has_socket_id) { 691 error_setg(errp, "socket-id is not supported"); 692 return; 693 } 694 695 if (props->has_die_id && !slot->props.has_die_id) { 696 error_setg(errp, "die-id is not supported"); 697 return; 698 } 699 700 /* skip slots with explicit mismatch */ 701 if (props->has_thread_id && props->thread_id != slot->props.thread_id) { 702 continue; 703 } 704 705 if (props->has_core_id && props->core_id != slot->props.core_id) { 706 continue; 707 } 708 709 if (props->has_cluster_id && 710 props->cluster_id != slot->props.cluster_id) { 711 continue; 712 } 713 714 if (props->has_die_id && props->die_id != slot->props.die_id) { 715 continue; 716 } 717 718 if (props->has_socket_id && props->socket_id != slot->props.socket_id) { 719 continue; 720 } 721 722 /* reject assignment if slot is already assigned, for compatibility 723 * of legacy cpu_index mapping with SPAPR core based mapping do not 724 * error out if cpu thread and matched core have the same node-id */ 725 if (slot->props.has_node_id && 726 slot->props.node_id != props->node_id) { 727 error_setg(errp, "CPU is already assigned to node-id: %" PRId64, 728 slot->props.node_id); 729 return; 730 } 731 732 /* assign slot to node as it's matched '-numa cpu' key */ 733 match = true; 734 slot->props.node_id = props->node_id; 735 slot->props.has_node_id = props->has_node_id; 736 737 if (machine->numa_state->hmat_enabled) { 738 if ((numa_info[props->node_id].initiator < MAX_NODES) && 739 (props->node_id != numa_info[props->node_id].initiator)) { 740 error_setg(errp, "The initiator of CPU NUMA node %" PRId64 741 " should be itself (got %" PRIu16 ")", 742 props->node_id, numa_info[props->node_id].initiator); 743 return; 744 } 745 numa_info[props->node_id].has_cpu = true; 746 numa_info[props->node_id].initiator = props->node_id; 747 } 748 } 749 750 if (!match) { 751 error_setg(errp, "no match found"); 752 } 753 } 754 755 static void machine_get_smp(Object *obj, Visitor *v, const char *name, 756 void *opaque, Error **errp) 757 { 758 MachineState *ms = MACHINE(obj); 759 SMPConfiguration *config = &(SMPConfiguration){ 760 .has_cpus = true, .cpus = ms->smp.cpus, 761 .has_sockets = true, .sockets = ms->smp.sockets, 762 .has_dies = true, .dies = ms->smp.dies, 763 .has_clusters = true, .clusters = ms->smp.clusters, 764 .has_cores = true, .cores = ms->smp.cores, 765 .has_threads = true, .threads = ms->smp.threads, 766 .has_maxcpus = true, .maxcpus = ms->smp.max_cpus, 767 }; 768 769 if (!visit_type_SMPConfiguration(v, name, &config, &error_abort)) { 770 return; 771 } 772 } 773 774 static void machine_set_smp(Object *obj, Visitor *v, const char *name, 775 void *opaque, Error **errp) 776 { 777 MachineState *ms = MACHINE(obj); 778 g_autoptr(SMPConfiguration) config = NULL; 779 780 if (!visit_type_SMPConfiguration(v, name, &config, errp)) { 781 return; 782 } 783 784 machine_parse_smp_config(ms, config, errp); 785 } 786 787 static void machine_get_boot(Object *obj, Visitor *v, const char *name, 788 void *opaque, Error **errp) 789 { 790 MachineState *ms = MACHINE(obj); 791 BootConfiguration *config = &ms->boot_config; 792 visit_type_BootConfiguration(v, name, &config, &error_abort); 793 } 794 795 static void machine_free_boot_config(MachineState *ms) 796 { 797 g_free(ms->boot_config.order); 798 g_free(ms->boot_config.once); 799 g_free(ms->boot_config.splash); 800 } 801 802 static void machine_copy_boot_config(MachineState *ms, BootConfiguration *config) 803 { 804 MachineClass *machine_class = MACHINE_GET_CLASS(ms); 805 806 machine_free_boot_config(ms); 807 ms->boot_config = *config; 808 if (!config->has_order) { 809 ms->boot_config.has_order = true; 810 ms->boot_config.order = g_strdup(machine_class->default_boot_order); 811 } 812 } 813 814 static void machine_set_boot(Object *obj, Visitor *v, const char *name, 815 void *opaque, Error **errp) 816 { 817 ERRP_GUARD(); 818 MachineState *ms = MACHINE(obj); 819 BootConfiguration *config = NULL; 820 821 if (!visit_type_BootConfiguration(v, name, &config, errp)) { 822 return; 823 } 824 if (config->has_order) { 825 validate_bootdevices(config->order, errp); 826 if (*errp) { 827 goto out_free; 828 } 829 } 830 if (config->has_once) { 831 validate_bootdevices(config->once, errp); 832 if (*errp) { 833 goto out_free; 834 } 835 } 836 837 machine_copy_boot_config(ms, config); 838 /* Strings live in ms->boot_config. */ 839 free(config); 840 return; 841 842 out_free: 843 qapi_free_BootConfiguration(config); 844 } 845 846 static void machine_class_init(ObjectClass *oc, void *data) 847 { 848 MachineClass *mc = MACHINE_CLASS(oc); 849 850 /* Default 128 MB as guest ram size */ 851 mc->default_ram_size = 128 * MiB; 852 mc->rom_file_has_mr = true; 853 854 /* numa node memory size aligned on 8MB by default. 855 * On Linux, each node's border has to be 8MB aligned 856 */ 857 mc->numa_mem_align_shift = 23; 858 859 object_class_property_add_str(oc, "kernel", 860 machine_get_kernel, machine_set_kernel); 861 object_class_property_set_description(oc, "kernel", 862 "Linux kernel image file"); 863 864 object_class_property_add_str(oc, "initrd", 865 machine_get_initrd, machine_set_initrd); 866 object_class_property_set_description(oc, "initrd", 867 "Linux initial ramdisk file"); 868 869 object_class_property_add_str(oc, "append", 870 machine_get_append, machine_set_append); 871 object_class_property_set_description(oc, "append", 872 "Linux kernel command line"); 873 874 object_class_property_add_str(oc, "dtb", 875 machine_get_dtb, machine_set_dtb); 876 object_class_property_set_description(oc, "dtb", 877 "Linux kernel device tree file"); 878 879 object_class_property_add_str(oc, "dumpdtb", 880 machine_get_dumpdtb, machine_set_dumpdtb); 881 object_class_property_set_description(oc, "dumpdtb", 882 "Dump current dtb to a file and quit"); 883 884 object_class_property_add(oc, "boot", "BootConfiguration", 885 machine_get_boot, machine_set_boot, 886 NULL, NULL); 887 object_class_property_set_description(oc, "boot", 888 "Boot configuration"); 889 890 object_class_property_add(oc, "smp", "SMPConfiguration", 891 machine_get_smp, machine_set_smp, 892 NULL, NULL); 893 object_class_property_set_description(oc, "smp", 894 "CPU topology"); 895 896 object_class_property_add(oc, "phandle-start", "int", 897 machine_get_phandle_start, machine_set_phandle_start, 898 NULL, NULL); 899 object_class_property_set_description(oc, "phandle-start", 900 "The first phandle ID we may generate dynamically"); 901 902 object_class_property_add_str(oc, "dt-compatible", 903 machine_get_dt_compatible, machine_set_dt_compatible); 904 object_class_property_set_description(oc, "dt-compatible", 905 "Overrides the \"compatible\" property of the dt root node"); 906 907 object_class_property_add_bool(oc, "dump-guest-core", 908 machine_get_dump_guest_core, machine_set_dump_guest_core); 909 object_class_property_set_description(oc, "dump-guest-core", 910 "Include guest memory in a core dump"); 911 912 object_class_property_add_bool(oc, "mem-merge", 913 machine_get_mem_merge, machine_set_mem_merge); 914 object_class_property_set_description(oc, "mem-merge", 915 "Enable/disable memory merge support"); 916 917 object_class_property_add_bool(oc, "usb", 918 machine_get_usb, machine_set_usb); 919 object_class_property_set_description(oc, "usb", 920 "Set on/off to enable/disable usb"); 921 922 object_class_property_add_bool(oc, "graphics", 923 machine_get_graphics, machine_set_graphics); 924 object_class_property_set_description(oc, "graphics", 925 "Set on/off to enable/disable graphics emulation"); 926 927 object_class_property_add_str(oc, "firmware", 928 machine_get_firmware, machine_set_firmware); 929 object_class_property_set_description(oc, "firmware", 930 "Firmware image"); 931 932 object_class_property_add_bool(oc, "suppress-vmdesc", 933 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc); 934 object_class_property_set_description(oc, "suppress-vmdesc", 935 "Set on to disable self-describing migration"); 936 937 object_class_property_add_link(oc, "confidential-guest-support", 938 TYPE_CONFIDENTIAL_GUEST_SUPPORT, 939 offsetof(MachineState, cgs), 940 machine_check_confidential_guest_support, 941 OBJ_PROP_LINK_STRONG); 942 object_class_property_set_description(oc, "confidential-guest-support", 943 "Set confidential guest scheme to support"); 944 945 /* For compatibility */ 946 object_class_property_add_str(oc, "memory-encryption", 947 machine_get_memory_encryption, machine_set_memory_encryption); 948 object_class_property_set_description(oc, "memory-encryption", 949 "Set memory encryption object to use"); 950 951 object_class_property_add_str(oc, "memory-backend", 952 machine_get_memdev, machine_set_memdev); 953 object_class_property_set_description(oc, "memory-backend", 954 "Set RAM backend" 955 "Valid value is ID of hostmem based backend"); 956 } 957 958 static void machine_class_base_init(ObjectClass *oc, void *data) 959 { 960 MachineClass *mc = MACHINE_CLASS(oc); 961 mc->max_cpus = mc->max_cpus ?: 1; 962 mc->min_cpus = mc->min_cpus ?: 1; 963 mc->default_cpus = mc->default_cpus ?: 1; 964 965 if (!object_class_is_abstract(oc)) { 966 const char *cname = object_class_get_name(oc); 967 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX)); 968 mc->name = g_strndup(cname, 969 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX)); 970 mc->compat_props = g_ptr_array_new(); 971 } 972 } 973 974 static void machine_initfn(Object *obj) 975 { 976 MachineState *ms = MACHINE(obj); 977 MachineClass *mc = MACHINE_GET_CLASS(obj); 978 979 container_get(obj, "/peripheral"); 980 container_get(obj, "/peripheral-anon"); 981 982 ms->dump_guest_core = true; 983 ms->mem_merge = true; 984 ms->enable_graphics = true; 985 ms->kernel_cmdline = g_strdup(""); 986 987 if (mc->nvdimm_supported) { 988 Object *obj = OBJECT(ms); 989 990 ms->nvdimms_state = g_new0(NVDIMMState, 1); 991 object_property_add_bool(obj, "nvdimm", 992 machine_get_nvdimm, machine_set_nvdimm); 993 object_property_set_description(obj, "nvdimm", 994 "Set on/off to enable/disable " 995 "NVDIMM instantiation"); 996 997 object_property_add_str(obj, "nvdimm-persistence", 998 machine_get_nvdimm_persistence, 999 machine_set_nvdimm_persistence); 1000 object_property_set_description(obj, "nvdimm-persistence", 1001 "Set NVDIMM persistence" 1002 "Valid values are cpu, mem-ctrl"); 1003 } 1004 1005 if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) { 1006 ms->numa_state = g_new0(NumaState, 1); 1007 object_property_add_bool(obj, "hmat", 1008 machine_get_hmat, machine_set_hmat); 1009 object_property_set_description(obj, "hmat", 1010 "Set on/off to enable/disable " 1011 "ACPI Heterogeneous Memory Attribute " 1012 "Table (HMAT)"); 1013 } 1014 1015 /* default to mc->default_cpus */ 1016 ms->smp.cpus = mc->default_cpus; 1017 ms->smp.max_cpus = mc->default_cpus; 1018 ms->smp.sockets = 1; 1019 ms->smp.dies = 1; 1020 ms->smp.clusters = 1; 1021 ms->smp.cores = 1; 1022 ms->smp.threads = 1; 1023 1024 machine_copy_boot_config(ms, &(BootConfiguration){ 0 }); 1025 } 1026 1027 static void machine_finalize(Object *obj) 1028 { 1029 MachineState *ms = MACHINE(obj); 1030 1031 machine_free_boot_config(ms); 1032 g_free(ms->kernel_filename); 1033 g_free(ms->initrd_filename); 1034 g_free(ms->kernel_cmdline); 1035 g_free(ms->dtb); 1036 g_free(ms->dumpdtb); 1037 g_free(ms->dt_compatible); 1038 g_free(ms->firmware); 1039 g_free(ms->device_memory); 1040 g_free(ms->nvdimms_state); 1041 g_free(ms->numa_state); 1042 } 1043 1044 bool machine_usb(MachineState *machine) 1045 { 1046 return machine->usb; 1047 } 1048 1049 int machine_phandle_start(MachineState *machine) 1050 { 1051 return machine->phandle_start; 1052 } 1053 1054 bool machine_dump_guest_core(MachineState *machine) 1055 { 1056 return machine->dump_guest_core; 1057 } 1058 1059 bool machine_mem_merge(MachineState *machine) 1060 { 1061 return machine->mem_merge; 1062 } 1063 1064 static char *cpu_slot_to_string(const CPUArchId *cpu) 1065 { 1066 GString *s = g_string_new(NULL); 1067 if (cpu->props.has_socket_id) { 1068 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id); 1069 } 1070 if (cpu->props.has_die_id) { 1071 if (s->len) { 1072 g_string_append_printf(s, ", "); 1073 } 1074 g_string_append_printf(s, "die-id: %"PRId64, cpu->props.die_id); 1075 } 1076 if (cpu->props.has_cluster_id) { 1077 if (s->len) { 1078 g_string_append_printf(s, ", "); 1079 } 1080 g_string_append_printf(s, "cluster-id: %"PRId64, cpu->props.cluster_id); 1081 } 1082 if (cpu->props.has_core_id) { 1083 if (s->len) { 1084 g_string_append_printf(s, ", "); 1085 } 1086 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id); 1087 } 1088 if (cpu->props.has_thread_id) { 1089 if (s->len) { 1090 g_string_append_printf(s, ", "); 1091 } 1092 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id); 1093 } 1094 return g_string_free(s, false); 1095 } 1096 1097 static void numa_validate_initiator(NumaState *numa_state) 1098 { 1099 int i; 1100 NodeInfo *numa_info = numa_state->nodes; 1101 1102 for (i = 0; i < numa_state->num_nodes; i++) { 1103 if (numa_info[i].initiator == MAX_NODES) { 1104 error_report("The initiator of NUMA node %d is missing, use " 1105 "'-numa node,initiator' option to declare it", i); 1106 exit(1); 1107 } 1108 1109 if (!numa_info[numa_info[i].initiator].present) { 1110 error_report("NUMA node %" PRIu16 " is missing, use " 1111 "'-numa node' option to declare it first", 1112 numa_info[i].initiator); 1113 exit(1); 1114 } 1115 1116 if (!numa_info[numa_info[i].initiator].has_cpu) { 1117 error_report("The initiator of NUMA node %d is invalid", i); 1118 exit(1); 1119 } 1120 } 1121 } 1122 1123 static void machine_numa_finish_cpu_init(MachineState *machine) 1124 { 1125 int i; 1126 bool default_mapping; 1127 GString *s = g_string_new(NULL); 1128 MachineClass *mc = MACHINE_GET_CLASS(machine); 1129 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine); 1130 1131 assert(machine->numa_state->num_nodes); 1132 for (i = 0; i < possible_cpus->len; i++) { 1133 if (possible_cpus->cpus[i].props.has_node_id) { 1134 break; 1135 } 1136 } 1137 default_mapping = (i == possible_cpus->len); 1138 1139 for (i = 0; i < possible_cpus->len; i++) { 1140 const CPUArchId *cpu_slot = &possible_cpus->cpus[i]; 1141 1142 if (!cpu_slot->props.has_node_id) { 1143 /* fetch default mapping from board and enable it */ 1144 CpuInstanceProperties props = cpu_slot->props; 1145 1146 props.node_id = mc->get_default_cpu_node_id(machine, i); 1147 if (!default_mapping) { 1148 /* record slots with not set mapping, 1149 * TODO: make it hard error in future */ 1150 char *cpu_str = cpu_slot_to_string(cpu_slot); 1151 g_string_append_printf(s, "%sCPU %d [%s]", 1152 s->len ? ", " : "", i, cpu_str); 1153 g_free(cpu_str); 1154 1155 /* non mapped cpus used to fallback to node 0 */ 1156 props.node_id = 0; 1157 } 1158 1159 props.has_node_id = true; 1160 machine_set_cpu_numa_node(machine, &props, &error_fatal); 1161 } 1162 } 1163 1164 if (machine->numa_state->hmat_enabled) { 1165 numa_validate_initiator(machine->numa_state); 1166 } 1167 1168 if (s->len && !qtest_enabled()) { 1169 warn_report("CPU(s) not present in any NUMA nodes: %s", 1170 s->str); 1171 warn_report("All CPU(s) up to maxcpus should be described " 1172 "in NUMA config, ability to start up with partial NUMA " 1173 "mappings is obsoleted and will be removed in future"); 1174 } 1175 g_string_free(s, true); 1176 } 1177 1178 MemoryRegion *machine_consume_memdev(MachineState *machine, 1179 HostMemoryBackend *backend) 1180 { 1181 MemoryRegion *ret = host_memory_backend_get_memory(backend); 1182 1183 if (host_memory_backend_is_mapped(backend)) { 1184 error_report("memory backend %s can't be used multiple times.", 1185 object_get_canonical_path_component(OBJECT(backend))); 1186 exit(EXIT_FAILURE); 1187 } 1188 host_memory_backend_set_mapped(backend, true); 1189 vmstate_register_ram_global(ret); 1190 return ret; 1191 } 1192 1193 void machine_run_board_init(MachineState *machine) 1194 { 1195 MachineClass *machine_class = MACHINE_GET_CLASS(machine); 1196 ObjectClass *oc = object_class_by_name(machine->cpu_type); 1197 CPUClass *cc; 1198 1199 /* This checkpoint is required by replay to separate prior clock 1200 reading from the other reads, because timer polling functions query 1201 clock values from the log. */ 1202 replay_checkpoint(CHECKPOINT_INIT); 1203 1204 if (machine->ram_memdev_id) { 1205 Object *o; 1206 o = object_resolve_path_type(machine->ram_memdev_id, 1207 TYPE_MEMORY_BACKEND, NULL); 1208 machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o)); 1209 } 1210 1211 if (machine->numa_state) { 1212 numa_complete_configuration(machine); 1213 if (machine->numa_state->num_nodes) { 1214 machine_numa_finish_cpu_init(machine); 1215 } 1216 } 1217 1218 /* If the machine supports the valid_cpu_types check and the user 1219 * specified a CPU with -cpu check here that the user CPU is supported. 1220 */ 1221 if (machine_class->valid_cpu_types && machine->cpu_type) { 1222 int i; 1223 1224 for (i = 0; machine_class->valid_cpu_types[i]; i++) { 1225 if (object_class_dynamic_cast(oc, 1226 machine_class->valid_cpu_types[i])) { 1227 /* The user specificed CPU is in the valid field, we are 1228 * good to go. 1229 */ 1230 break; 1231 } 1232 } 1233 1234 if (!machine_class->valid_cpu_types[i]) { 1235 /* The user specified CPU is not valid */ 1236 error_report("Invalid CPU type: %s", machine->cpu_type); 1237 error_printf("The valid types are: %s", 1238 machine_class->valid_cpu_types[0]); 1239 for (i = 1; machine_class->valid_cpu_types[i]; i++) { 1240 error_printf(", %s", machine_class->valid_cpu_types[i]); 1241 } 1242 error_printf("\n"); 1243 1244 exit(1); 1245 } 1246 } 1247 1248 /* Check if CPU type is deprecated and warn if so */ 1249 cc = CPU_CLASS(oc); 1250 if (cc && cc->deprecation_note) { 1251 warn_report("CPU model %s is deprecated -- %s", machine->cpu_type, 1252 cc->deprecation_note); 1253 } 1254 1255 if (machine->cgs) { 1256 /* 1257 * With confidential guests, the host can't see the real 1258 * contents of RAM, so there's no point in it trying to merge 1259 * areas. 1260 */ 1261 machine_set_mem_merge(OBJECT(machine), false, &error_abort); 1262 1263 /* 1264 * Virtio devices can't count on directly accessing guest 1265 * memory, so they need iommu_platform=on to use normal DMA 1266 * mechanisms. That requires also disabling legacy virtio 1267 * support for those virtio pci devices which allow it. 1268 */ 1269 object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", 1270 "on", true); 1271 object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform", 1272 "on", false); 1273 } 1274 1275 accel_init_interfaces(ACCEL_GET_CLASS(machine->accelerator)); 1276 machine_class->init(machine); 1277 phase_advance(PHASE_MACHINE_INITIALIZED); 1278 } 1279 1280 static NotifierList machine_init_done_notifiers = 1281 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); 1282 1283 void qemu_add_machine_init_done_notifier(Notifier *notify) 1284 { 1285 notifier_list_add(&machine_init_done_notifiers, notify); 1286 if (phase_check(PHASE_MACHINE_READY)) { 1287 notify->notify(notify, NULL); 1288 } 1289 } 1290 1291 void qemu_remove_machine_init_done_notifier(Notifier *notify) 1292 { 1293 notifier_remove(notify); 1294 } 1295 1296 void qdev_machine_creation_done(void) 1297 { 1298 cpu_synchronize_all_post_init(); 1299 1300 if (current_machine->boot_config.has_once) { 1301 qemu_boot_set(current_machine->boot_config.once, &error_fatal); 1302 qemu_register_reset(restore_boot_order, g_strdup(current_machine->boot_config.order)); 1303 } 1304 1305 /* 1306 * ok, initial machine setup is done, starting from now we can 1307 * only create hotpluggable devices 1308 */ 1309 phase_advance(PHASE_MACHINE_READY); 1310 qdev_assert_realized_properly(); 1311 1312 /* TODO: once all bus devices are qdevified, this should be done 1313 * when bus is created by qdev.c */ 1314 /* 1315 * TODO: If we had a main 'reset container' that the whole system 1316 * lived in, we could reset that using the multi-phase reset 1317 * APIs. For the moment, we just reset the sysbus, which will cause 1318 * all devices hanging off it (and all their child buses, recursively) 1319 * to be reset. Note that this will *not* reset any Device objects 1320 * which are not attached to some part of the qbus tree! 1321 */ 1322 qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); 1323 1324 notifier_list_notify(&machine_init_done_notifiers, NULL); 1325 1326 if (rom_check_and_register_reset() != 0) { 1327 exit(1); 1328 } 1329 1330 replay_start(); 1331 1332 /* This checkpoint is required by replay to separate prior clock 1333 reading from the other reads, because timer polling functions query 1334 clock values from the log. */ 1335 replay_checkpoint(CHECKPOINT_RESET); 1336 qemu_system_reset(SHUTDOWN_CAUSE_NONE); 1337 register_global_state(); 1338 } 1339 1340 static const TypeInfo machine_info = { 1341 .name = TYPE_MACHINE, 1342 .parent = TYPE_OBJECT, 1343 .abstract = true, 1344 .class_size = sizeof(MachineClass), 1345 .class_init = machine_class_init, 1346 .class_base_init = machine_class_base_init, 1347 .instance_size = sizeof(MachineState), 1348 .instance_init = machine_initfn, 1349 .instance_finalize = machine_finalize, 1350 }; 1351 1352 static void machine_register_types(void) 1353 { 1354 type_register_static(&machine_info); 1355 } 1356 1357 type_init(machine_register_types) 1358