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 "hw/boards.h" 15 #include "qapi/error.h" 16 #include "qapi-visit.h" 17 #include "qapi/visitor.h" 18 #include "hw/sysbus.h" 19 #include "sysemu/sysemu.h" 20 #include "sysemu/numa.h" 21 #include "qemu/error-report.h" 22 #include "qemu/cutils.h" 23 #include "sysemu/numa.h" 24 25 static char *machine_get_accel(Object *obj, Error **errp) 26 { 27 MachineState *ms = MACHINE(obj); 28 29 return g_strdup(ms->accel); 30 } 31 32 static void machine_set_accel(Object *obj, const char *value, Error **errp) 33 { 34 MachineState *ms = MACHINE(obj); 35 36 g_free(ms->accel); 37 ms->accel = g_strdup(value); 38 } 39 40 static void machine_set_kernel_irqchip(Object *obj, Visitor *v, 41 const char *name, void *opaque, 42 Error **errp) 43 { 44 Error *err = NULL; 45 MachineState *ms = MACHINE(obj); 46 OnOffSplit mode; 47 48 visit_type_OnOffSplit(v, name, &mode, &err); 49 if (err) { 50 error_propagate(errp, err); 51 return; 52 } else { 53 switch (mode) { 54 case ON_OFF_SPLIT_ON: 55 ms->kernel_irqchip_allowed = true; 56 ms->kernel_irqchip_required = true; 57 ms->kernel_irqchip_split = false; 58 break; 59 case ON_OFF_SPLIT_OFF: 60 ms->kernel_irqchip_allowed = false; 61 ms->kernel_irqchip_required = false; 62 ms->kernel_irqchip_split = false; 63 break; 64 case ON_OFF_SPLIT_SPLIT: 65 ms->kernel_irqchip_allowed = true; 66 ms->kernel_irqchip_required = true; 67 ms->kernel_irqchip_split = true; 68 break; 69 default: 70 /* The value was checked in visit_type_OnOffSplit() above. If 71 * we get here, then something is wrong in QEMU. 72 */ 73 abort(); 74 } 75 } 76 } 77 78 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, 79 const char *name, void *opaque, 80 Error **errp) 81 { 82 MachineState *ms = MACHINE(obj); 83 int64_t value = ms->kvm_shadow_mem; 84 85 visit_type_int(v, name, &value, errp); 86 } 87 88 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, 89 const char *name, void *opaque, 90 Error **errp) 91 { 92 MachineState *ms = MACHINE(obj); 93 Error *error = NULL; 94 int64_t value; 95 96 visit_type_int(v, name, &value, &error); 97 if (error) { 98 error_propagate(errp, error); 99 return; 100 } 101 102 ms->kvm_shadow_mem = value; 103 } 104 105 static char *machine_get_kernel(Object *obj, Error **errp) 106 { 107 MachineState *ms = MACHINE(obj); 108 109 return g_strdup(ms->kernel_filename); 110 } 111 112 static void machine_set_kernel(Object *obj, const char *value, Error **errp) 113 { 114 MachineState *ms = MACHINE(obj); 115 116 g_free(ms->kernel_filename); 117 ms->kernel_filename = g_strdup(value); 118 } 119 120 static char *machine_get_initrd(Object *obj, Error **errp) 121 { 122 MachineState *ms = MACHINE(obj); 123 124 return g_strdup(ms->initrd_filename); 125 } 126 127 static void machine_set_initrd(Object *obj, const char *value, Error **errp) 128 { 129 MachineState *ms = MACHINE(obj); 130 131 g_free(ms->initrd_filename); 132 ms->initrd_filename = g_strdup(value); 133 } 134 135 static char *machine_get_append(Object *obj, Error **errp) 136 { 137 MachineState *ms = MACHINE(obj); 138 139 return g_strdup(ms->kernel_cmdline); 140 } 141 142 static void machine_set_append(Object *obj, const char *value, Error **errp) 143 { 144 MachineState *ms = MACHINE(obj); 145 146 g_free(ms->kernel_cmdline); 147 ms->kernel_cmdline = g_strdup(value); 148 } 149 150 static char *machine_get_dtb(Object *obj, Error **errp) 151 { 152 MachineState *ms = MACHINE(obj); 153 154 return g_strdup(ms->dtb); 155 } 156 157 static void machine_set_dtb(Object *obj, const char *value, Error **errp) 158 { 159 MachineState *ms = MACHINE(obj); 160 161 g_free(ms->dtb); 162 ms->dtb = g_strdup(value); 163 } 164 165 static char *machine_get_dumpdtb(Object *obj, Error **errp) 166 { 167 MachineState *ms = MACHINE(obj); 168 169 return g_strdup(ms->dumpdtb); 170 } 171 172 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) 173 { 174 MachineState *ms = MACHINE(obj); 175 176 g_free(ms->dumpdtb); 177 ms->dumpdtb = g_strdup(value); 178 } 179 180 static void machine_get_phandle_start(Object *obj, Visitor *v, 181 const char *name, void *opaque, 182 Error **errp) 183 { 184 MachineState *ms = MACHINE(obj); 185 int64_t value = ms->phandle_start; 186 187 visit_type_int(v, name, &value, errp); 188 } 189 190 static void machine_set_phandle_start(Object *obj, Visitor *v, 191 const char *name, void *opaque, 192 Error **errp) 193 { 194 MachineState *ms = MACHINE(obj); 195 Error *error = NULL; 196 int64_t value; 197 198 visit_type_int(v, name, &value, &error); 199 if (error) { 200 error_propagate(errp, error); 201 return; 202 } 203 204 ms->phandle_start = value; 205 } 206 207 static char *machine_get_dt_compatible(Object *obj, Error **errp) 208 { 209 MachineState *ms = MACHINE(obj); 210 211 return g_strdup(ms->dt_compatible); 212 } 213 214 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp) 215 { 216 MachineState *ms = MACHINE(obj); 217 218 g_free(ms->dt_compatible); 219 ms->dt_compatible = g_strdup(value); 220 } 221 222 static bool machine_get_dump_guest_core(Object *obj, Error **errp) 223 { 224 MachineState *ms = MACHINE(obj); 225 226 return ms->dump_guest_core; 227 } 228 229 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) 230 { 231 MachineState *ms = MACHINE(obj); 232 233 ms->dump_guest_core = value; 234 } 235 236 static bool machine_get_mem_merge(Object *obj, Error **errp) 237 { 238 MachineState *ms = MACHINE(obj); 239 240 return ms->mem_merge; 241 } 242 243 static void machine_set_mem_merge(Object *obj, bool value, Error **errp) 244 { 245 MachineState *ms = MACHINE(obj); 246 247 ms->mem_merge = value; 248 } 249 250 static bool machine_get_usb(Object *obj, Error **errp) 251 { 252 MachineState *ms = MACHINE(obj); 253 254 return ms->usb; 255 } 256 257 static void machine_set_usb(Object *obj, bool value, Error **errp) 258 { 259 MachineState *ms = MACHINE(obj); 260 261 ms->usb = value; 262 ms->usb_disabled = !value; 263 } 264 265 static bool machine_get_graphics(Object *obj, Error **errp) 266 { 267 MachineState *ms = MACHINE(obj); 268 269 return ms->enable_graphics; 270 } 271 272 static void machine_set_graphics(Object *obj, bool value, Error **errp) 273 { 274 MachineState *ms = MACHINE(obj); 275 276 ms->enable_graphics = value; 277 } 278 279 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp) 280 { 281 MachineState *ms = MACHINE(obj); 282 283 return ms->igd_gfx_passthru; 284 } 285 286 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) 287 { 288 MachineState *ms = MACHINE(obj); 289 290 ms->igd_gfx_passthru = value; 291 } 292 293 static char *machine_get_firmware(Object *obj, Error **errp) 294 { 295 MachineState *ms = MACHINE(obj); 296 297 return g_strdup(ms->firmware); 298 } 299 300 static void machine_set_firmware(Object *obj, const char *value, Error **errp) 301 { 302 MachineState *ms = MACHINE(obj); 303 304 g_free(ms->firmware); 305 ms->firmware = g_strdup(value); 306 } 307 308 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp) 309 { 310 MachineState *ms = MACHINE(obj); 311 312 ms->suppress_vmdesc = value; 313 } 314 315 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp) 316 { 317 MachineState *ms = MACHINE(obj); 318 319 return ms->suppress_vmdesc; 320 } 321 322 static void machine_set_enforce_config_section(Object *obj, bool value, 323 Error **errp) 324 { 325 MachineState *ms = MACHINE(obj); 326 327 ms->enforce_config_section = value; 328 } 329 330 static bool machine_get_enforce_config_section(Object *obj, Error **errp) 331 { 332 MachineState *ms = MACHINE(obj); 333 334 return ms->enforce_config_section; 335 } 336 337 static void error_on_sysbus_device(SysBusDevice *sbdev, void *opaque) 338 { 339 error_report("Option '-device %s' cannot be handled by this machine", 340 object_class_get_name(object_get_class(OBJECT(sbdev)))); 341 exit(1); 342 } 343 344 static void machine_init_notify(Notifier *notifier, void *data) 345 { 346 Object *machine = qdev_get_machine(); 347 ObjectClass *oc = object_get_class(machine); 348 MachineClass *mc = MACHINE_CLASS(oc); 349 350 if (mc->has_dynamic_sysbus) { 351 /* Our machine can handle dynamic sysbus devices, we're all good */ 352 return; 353 } 354 355 /* 356 * Loop through all dynamically created devices and check whether there 357 * are sysbus devices among them. If there are, error out. 358 */ 359 foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL); 360 } 361 362 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine) 363 { 364 int i; 365 Object *cpu; 366 HotpluggableCPUList *head = NULL; 367 const char *cpu_type; 368 369 cpu = machine->possible_cpus->cpus[0].cpu; 370 assert(cpu); /* Boot cpu is always present */ 371 cpu_type = object_get_typename(cpu); 372 for (i = 0; i < machine->possible_cpus->len; i++) { 373 HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1); 374 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1); 375 376 cpu_item->type = g_strdup(cpu_type); 377 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count; 378 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props, 379 sizeof(*cpu_item->props)); 380 381 cpu = machine->possible_cpus->cpus[i].cpu; 382 if (cpu) { 383 cpu_item->has_qom_path = true; 384 cpu_item->qom_path = object_get_canonical_path(cpu); 385 } 386 list_item->value = cpu_item; 387 list_item->next = head; 388 head = list_item; 389 } 390 return head; 391 } 392 393 /** 394 * machine_set_cpu_numa_node: 395 * @machine: machine object to modify 396 * @props: specifies which cpu objects to assign to 397 * numa node specified by @props.node_id 398 * @errp: if an error occurs, a pointer to an area to store the error 399 * 400 * Associate NUMA node specified by @props.node_id with cpu slots that 401 * match socket/core/thread-ids specified by @props. It's recommended to use 402 * query-hotpluggable-cpus.props values to specify affected cpu slots, 403 * which would lead to exact 1:1 mapping of cpu slots to NUMA node. 404 * 405 * However for CLI convenience it's possible to pass in subset of properties, 406 * which would affect all cpu slots that match it. 407 * Ex for pc machine: 408 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \ 409 * -numa cpu,node-id=0,socket_id=0 \ 410 * -numa cpu,node-id=1,socket_id=1 411 * will assign all child cores of socket 0 to node 0 and 412 * of socket 1 to node 1. 413 * 414 * On attempt of reassigning (already assigned) cpu slot to another NUMA node, 415 * return error. 416 * Empty subset is disallowed and function will return with error in this case. 417 */ 418 void machine_set_cpu_numa_node(MachineState *machine, 419 const CpuInstanceProperties *props, Error **errp) 420 { 421 MachineClass *mc = MACHINE_GET_CLASS(machine); 422 bool match = false; 423 int i; 424 425 if (!mc->possible_cpu_arch_ids) { 426 error_setg(errp, "mapping of CPUs to NUMA node is not supported"); 427 return; 428 } 429 430 /* disabling node mapping is not supported, forbid it */ 431 assert(props->has_node_id); 432 433 /* force board to initialize possible_cpus if it hasn't been done yet */ 434 mc->possible_cpu_arch_ids(machine); 435 436 for (i = 0; i < machine->possible_cpus->len; i++) { 437 CPUArchId *slot = &machine->possible_cpus->cpus[i]; 438 439 /* reject unsupported by board properties */ 440 if (props->has_thread_id && !slot->props.has_thread_id) { 441 error_setg(errp, "thread-id is not supported"); 442 return; 443 } 444 445 if (props->has_core_id && !slot->props.has_core_id) { 446 error_setg(errp, "core-id is not supported"); 447 return; 448 } 449 450 if (props->has_socket_id && !slot->props.has_socket_id) { 451 error_setg(errp, "socket-id is not supported"); 452 return; 453 } 454 455 /* skip slots with explicit mismatch */ 456 if (props->has_thread_id && props->thread_id != slot->props.thread_id) { 457 continue; 458 } 459 460 if (props->has_core_id && props->core_id != slot->props.core_id) { 461 continue; 462 } 463 464 if (props->has_socket_id && props->socket_id != slot->props.socket_id) { 465 continue; 466 } 467 468 /* reject assignment if slot is already assigned, for compatibility 469 * of legacy cpu_index mapping with SPAPR core based mapping do not 470 * error out if cpu thread and matched core have the same node-id */ 471 if (slot->props.has_node_id && 472 slot->props.node_id != props->node_id) { 473 error_setg(errp, "CPU is already assigned to node-id: %" PRId64, 474 slot->props.node_id); 475 return; 476 } 477 478 /* assign slot to node as it's matched '-numa cpu' key */ 479 match = true; 480 slot->props.node_id = props->node_id; 481 slot->props.has_node_id = props->has_node_id; 482 } 483 484 if (!match) { 485 error_setg(errp, "no match found"); 486 } 487 } 488 489 static void machine_class_init(ObjectClass *oc, void *data) 490 { 491 MachineClass *mc = MACHINE_CLASS(oc); 492 493 /* Default 128 MB as guest ram size */ 494 mc->default_ram_size = 128 * M_BYTE; 495 mc->rom_file_has_mr = true; 496 497 /* numa node memory size aligned on 8MB by default. 498 * On Linux, each node's border has to be 8MB aligned 499 */ 500 mc->numa_mem_align_shift = 23; 501 mc->numa_auto_assign_ram = numa_default_auto_assign_ram; 502 503 object_class_property_add_str(oc, "accel", 504 machine_get_accel, machine_set_accel, &error_abort); 505 object_class_property_set_description(oc, "accel", 506 "Accelerator list", &error_abort); 507 508 object_class_property_add(oc, "kernel-irqchip", "OnOffSplit", 509 NULL, machine_set_kernel_irqchip, 510 NULL, NULL, &error_abort); 511 object_class_property_set_description(oc, "kernel-irqchip", 512 "Configure KVM in-kernel irqchip", &error_abort); 513 514 object_class_property_add(oc, "kvm-shadow-mem", "int", 515 machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem, 516 NULL, NULL, &error_abort); 517 object_class_property_set_description(oc, "kvm-shadow-mem", 518 "KVM shadow MMU size", &error_abort); 519 520 object_class_property_add_str(oc, "kernel", 521 machine_get_kernel, machine_set_kernel, &error_abort); 522 object_class_property_set_description(oc, "kernel", 523 "Linux kernel image file", &error_abort); 524 525 object_class_property_add_str(oc, "initrd", 526 machine_get_initrd, machine_set_initrd, &error_abort); 527 object_class_property_set_description(oc, "initrd", 528 "Linux initial ramdisk file", &error_abort); 529 530 object_class_property_add_str(oc, "append", 531 machine_get_append, machine_set_append, &error_abort); 532 object_class_property_set_description(oc, "append", 533 "Linux kernel command line", &error_abort); 534 535 object_class_property_add_str(oc, "dtb", 536 machine_get_dtb, machine_set_dtb, &error_abort); 537 object_class_property_set_description(oc, "dtb", 538 "Linux kernel device tree file", &error_abort); 539 540 object_class_property_add_str(oc, "dumpdtb", 541 machine_get_dumpdtb, machine_set_dumpdtb, &error_abort); 542 object_class_property_set_description(oc, "dumpdtb", 543 "Dump current dtb to a file and quit", &error_abort); 544 545 object_class_property_add(oc, "phandle-start", "int", 546 machine_get_phandle_start, machine_set_phandle_start, 547 NULL, NULL, &error_abort); 548 object_class_property_set_description(oc, "phandle-start", 549 "The first phandle ID we may generate dynamically", &error_abort); 550 551 object_class_property_add_str(oc, "dt-compatible", 552 machine_get_dt_compatible, machine_set_dt_compatible, &error_abort); 553 object_class_property_set_description(oc, "dt-compatible", 554 "Overrides the \"compatible\" property of the dt root node", 555 &error_abort); 556 557 object_class_property_add_bool(oc, "dump-guest-core", 558 machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort); 559 object_class_property_set_description(oc, "dump-guest-core", 560 "Include guest memory in a core dump", &error_abort); 561 562 object_class_property_add_bool(oc, "mem-merge", 563 machine_get_mem_merge, machine_set_mem_merge, &error_abort); 564 object_class_property_set_description(oc, "mem-merge", 565 "Enable/disable memory merge support", &error_abort); 566 567 object_class_property_add_bool(oc, "usb", 568 machine_get_usb, machine_set_usb, &error_abort); 569 object_class_property_set_description(oc, "usb", 570 "Set on/off to enable/disable usb", &error_abort); 571 572 object_class_property_add_bool(oc, "graphics", 573 machine_get_graphics, machine_set_graphics, &error_abort); 574 object_class_property_set_description(oc, "graphics", 575 "Set on/off to enable/disable graphics emulation", &error_abort); 576 577 object_class_property_add_bool(oc, "igd-passthru", 578 machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, 579 &error_abort); 580 object_class_property_set_description(oc, "igd-passthru", 581 "Set on/off to enable/disable igd passthrou", &error_abort); 582 583 object_class_property_add_str(oc, "firmware", 584 machine_get_firmware, machine_set_firmware, 585 &error_abort); 586 object_class_property_set_description(oc, "firmware", 587 "Firmware image", &error_abort); 588 589 object_class_property_add_bool(oc, "suppress-vmdesc", 590 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc, 591 &error_abort); 592 object_class_property_set_description(oc, "suppress-vmdesc", 593 "Set on to disable self-describing migration", &error_abort); 594 595 object_class_property_add_bool(oc, "enforce-config-section", 596 machine_get_enforce_config_section, machine_set_enforce_config_section, 597 &error_abort); 598 object_class_property_set_description(oc, "enforce-config-section", 599 "Set on to enforce configuration section migration", &error_abort); 600 } 601 602 static void machine_class_base_init(ObjectClass *oc, void *data) 603 { 604 if (!object_class_is_abstract(oc)) { 605 MachineClass *mc = MACHINE_CLASS(oc); 606 const char *cname = object_class_get_name(oc); 607 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX)); 608 mc->name = g_strndup(cname, 609 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX)); 610 } 611 } 612 613 static void machine_initfn(Object *obj) 614 { 615 MachineState *ms = MACHINE(obj); 616 617 ms->kernel_irqchip_allowed = true; 618 ms->kvm_shadow_mem = -1; 619 ms->dump_guest_core = true; 620 ms->mem_merge = true; 621 ms->enable_graphics = true; 622 623 /* Register notifier when init is done for sysbus sanity checks */ 624 ms->sysbus_notifier.notify = machine_init_notify; 625 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier); 626 } 627 628 static void machine_finalize(Object *obj) 629 { 630 MachineState *ms = MACHINE(obj); 631 632 g_free(ms->accel); 633 g_free(ms->kernel_filename); 634 g_free(ms->initrd_filename); 635 g_free(ms->kernel_cmdline); 636 g_free(ms->dtb); 637 g_free(ms->dumpdtb); 638 g_free(ms->dt_compatible); 639 g_free(ms->firmware); 640 } 641 642 bool machine_usb(MachineState *machine) 643 { 644 return machine->usb; 645 } 646 647 bool machine_kernel_irqchip_allowed(MachineState *machine) 648 { 649 return machine->kernel_irqchip_allowed; 650 } 651 652 bool machine_kernel_irqchip_required(MachineState *machine) 653 { 654 return machine->kernel_irqchip_required; 655 } 656 657 bool machine_kernel_irqchip_split(MachineState *machine) 658 { 659 return machine->kernel_irqchip_split; 660 } 661 662 int machine_kvm_shadow_mem(MachineState *machine) 663 { 664 return machine->kvm_shadow_mem; 665 } 666 667 int machine_phandle_start(MachineState *machine) 668 { 669 return machine->phandle_start; 670 } 671 672 bool machine_dump_guest_core(MachineState *machine) 673 { 674 return machine->dump_guest_core; 675 } 676 677 bool machine_mem_merge(MachineState *machine) 678 { 679 return machine->mem_merge; 680 } 681 682 static char *cpu_slot_to_string(const CPUArchId *cpu) 683 { 684 GString *s = g_string_new(NULL); 685 if (cpu->props.has_socket_id) { 686 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id); 687 } 688 if (cpu->props.has_core_id) { 689 if (s->len) { 690 g_string_append_printf(s, ", "); 691 } 692 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id); 693 } 694 if (cpu->props.has_thread_id) { 695 if (s->len) { 696 g_string_append_printf(s, ", "); 697 } 698 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id); 699 } 700 return g_string_free(s, false); 701 } 702 703 static void machine_numa_validate(MachineState *machine) 704 { 705 int i; 706 GString *s = g_string_new(NULL); 707 MachineClass *mc = MACHINE_GET_CLASS(machine); 708 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine); 709 710 assert(nb_numa_nodes); 711 for (i = 0; i < possible_cpus->len; i++) { 712 const CPUArchId *cpu_slot = &possible_cpus->cpus[i]; 713 714 /* at this point numa mappings are initilized by CLI options 715 * or with default mappings so it's sufficient to list 716 * all not yet mapped CPUs here */ 717 /* TODO: make it hard error in future */ 718 if (!cpu_slot->props.has_node_id) { 719 char *cpu_str = cpu_slot_to_string(cpu_slot); 720 g_string_append_printf(s, "%sCPU %d [%s]", s->len ? ", " : "", i, 721 cpu_str); 722 g_free(cpu_str); 723 } 724 } 725 if (s->len) { 726 error_report("warning: CPU(s) not present in any NUMA nodes: %s", 727 s->str); 728 error_report("warning: All CPU(s) up to maxcpus should be described " 729 "in NUMA config, ability to start up with partial NUMA " 730 "mappings is obsoleted and will be removed in future"); 731 } 732 g_string_free(s, true); 733 } 734 735 void machine_run_board_init(MachineState *machine) 736 { 737 MachineClass *machine_class = MACHINE_GET_CLASS(machine); 738 739 if (nb_numa_nodes) { 740 machine_numa_validate(machine); 741 } 742 machine_class->init(machine); 743 } 744 745 static void machine_class_finalize(ObjectClass *klass, void *data) 746 { 747 MachineClass *mc = MACHINE_CLASS(klass); 748 749 if (mc->compat_props) { 750 g_array_free(mc->compat_props, true); 751 } 752 g_free(mc->name); 753 } 754 755 static void register_compat_prop(const char *driver, 756 const char *property, 757 const char *value) 758 { 759 GlobalProperty *p = g_new0(GlobalProperty, 1); 760 /* Machine compat_props must never cause errors: */ 761 p->errp = &error_abort; 762 p->driver = driver; 763 p->property = property; 764 p->value = value; 765 qdev_prop_register_global(p); 766 } 767 768 static void machine_register_compat_for_subclass(ObjectClass *oc, void *opaque) 769 { 770 GlobalProperty *p = opaque; 771 register_compat_prop(object_class_get_name(oc), p->property, p->value); 772 } 773 774 void machine_register_compat_props(MachineState *machine) 775 { 776 MachineClass *mc = MACHINE_GET_CLASS(machine); 777 int i; 778 GlobalProperty *p; 779 ObjectClass *oc; 780 781 if (!mc->compat_props) { 782 return; 783 } 784 785 for (i = 0; i < mc->compat_props->len; i++) { 786 p = g_array_index(mc->compat_props, GlobalProperty *, i); 787 oc = object_class_by_name(p->driver); 788 if (oc && object_class_is_abstract(oc)) { 789 /* temporary hack to make sure we do not override 790 * globals set explicitly on -global: if an abstract class 791 * is on compat_props, register globals for all its 792 * non-abstract subtypes instead. 793 * 794 * This doesn't solve the problem for cases where 795 * a non-abstract typename mentioned on compat_props 796 * has subclasses, like spapr-pci-host-bridge. 797 */ 798 object_class_foreach(machine_register_compat_for_subclass, 799 p->driver, false, p); 800 } else { 801 register_compat_prop(p->driver, p->property, p->value); 802 } 803 } 804 } 805 806 static const TypeInfo machine_info = { 807 .name = TYPE_MACHINE, 808 .parent = TYPE_OBJECT, 809 .abstract = true, 810 .class_size = sizeof(MachineClass), 811 .class_init = machine_class_init, 812 .class_base_init = machine_class_base_init, 813 .class_finalize = machine_class_finalize, 814 .instance_size = sizeof(MachineState), 815 .instance_init = machine_initfn, 816 .instance_finalize = machine_finalize, 817 }; 818 819 static void machine_register_types(void) 820 { 821 type_register_static(&machine_info); 822 } 823 824 type_init(machine_register_types) 825