1 /* 2 * Copyright (c) 2003-2004 Fabrice Bellard 3 * Copyright (c) 2019 Red Hat, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this software and associated documentation files (the "Software"), to deal 7 * in the Software without restriction, including without limitation the rights 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 * copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * THE SOFTWARE. 22 */ 23 #include "qemu/osdep.h" 24 #include "qemu/error-report.h" 25 #include "qemu/option.h" 26 #include "qemu/cutils.h" 27 #include "qemu/units.h" 28 #include "qemu-common.h" 29 #include "qapi/error.h" 30 #include "qapi/qmp/qerror.h" 31 #include "qapi/qapi-visit-common.h" 32 #include "qapi/visitor.h" 33 #include "sysemu/qtest.h" 34 #include "sysemu/whpx.h" 35 #include "sysemu/numa.h" 36 #include "sysemu/replay.h" 37 #include "sysemu/sysemu.h" 38 #include "sysemu/cpu-timers.h" 39 #include "trace.h" 40 41 #include "hw/i386/x86.h" 42 #include "target/i386/cpu.h" 43 #include "hw/i386/topology.h" 44 #include "hw/i386/fw_cfg.h" 45 #include "hw/intc/i8259.h" 46 #include "hw/rtc/mc146818rtc.h" 47 48 #include "hw/acpi/cpu_hotplug.h" 49 #include "hw/irq.h" 50 #include "hw/nmi.h" 51 #include "hw/loader.h" 52 #include "multiboot.h" 53 #include "elf.h" 54 #include "standard-headers/asm-x86/bootparam.h" 55 #include CONFIG_DEVICES 56 #include "kvm_i386.h" 57 58 #define BIOS_FILENAME "bios.bin" 59 60 /* Physical Address of PVH entry point read from kernel ELF NOTE */ 61 static size_t pvh_start_addr; 62 63 inline void init_topo_info(X86CPUTopoInfo *topo_info, 64 const X86MachineState *x86ms) 65 { 66 MachineState *ms = MACHINE(x86ms); 67 68 topo_info->dies_per_pkg = x86ms->smp_dies; 69 topo_info->cores_per_die = ms->smp.cores; 70 topo_info->threads_per_core = ms->smp.threads; 71 } 72 73 /* 74 * Calculates initial APIC ID for a specific CPU index 75 * 76 * Currently we need to be able to calculate the APIC ID from the CPU index 77 * alone (without requiring a CPU object), as the QEMU<->Seabios interfaces have 78 * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of 79 * all CPUs up to max_cpus. 80 */ 81 uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms, 82 unsigned int cpu_index) 83 { 84 X86MachineClass *x86mc = X86_MACHINE_GET_CLASS(x86ms); 85 X86CPUTopoInfo topo_info; 86 uint32_t correct_id; 87 static bool warned; 88 89 init_topo_info(&topo_info, x86ms); 90 91 correct_id = x86_apicid_from_cpu_idx(&topo_info, cpu_index); 92 if (x86mc->compat_apic_id_mode) { 93 if (cpu_index != correct_id && !warned && !qtest_enabled()) { 94 error_report("APIC IDs set in compatibility mode, " 95 "CPU topology won't match the configuration"); 96 warned = true; 97 } 98 return cpu_index; 99 } else { 100 return correct_id; 101 } 102 } 103 104 105 void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp) 106 { 107 Object *cpu = object_new(MACHINE(x86ms)->cpu_type); 108 109 if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) { 110 goto out; 111 } 112 qdev_realize(DEVICE(cpu), NULL, errp); 113 114 out: 115 object_unref(cpu); 116 } 117 118 void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) 119 { 120 int i; 121 const CPUArchIdList *possible_cpus; 122 MachineState *ms = MACHINE(x86ms); 123 MachineClass *mc = MACHINE_GET_CLASS(x86ms); 124 125 x86_cpu_set_default_version(default_cpu_version); 126 127 /* 128 * Calculates the limit to CPU APIC ID values 129 * 130 * Limit for the APIC ID value, so that all 131 * CPU APIC IDs are < x86ms->apic_id_limit. 132 * 133 * This is used for FW_CFG_MAX_CPUS. See comments on fw_cfg_arch_create(). 134 */ 135 x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms, 136 ms->smp.max_cpus - 1) + 1; 137 possible_cpus = mc->possible_cpu_arch_ids(ms); 138 for (i = 0; i < ms->smp.cpus; i++) { 139 x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); 140 } 141 } 142 143 void x86_rtc_set_cpus_count(ISADevice *rtc, uint16_t cpus_count) 144 { 145 if (cpus_count > 0xff) { 146 /* 147 * If the number of CPUs can't be represented in 8 bits, the 148 * BIOS must use "FW_CFG_NB_CPUS". Set RTC field to 0 just 149 * to make old BIOSes fail more predictably. 150 */ 151 rtc_set_memory(rtc, 0x5f, 0); 152 } else { 153 rtc_set_memory(rtc, 0x5f, cpus_count - 1); 154 } 155 } 156 157 static int x86_apic_cmp(const void *a, const void *b) 158 { 159 CPUArchId *apic_a = (CPUArchId *)a; 160 CPUArchId *apic_b = (CPUArchId *)b; 161 162 return apic_a->arch_id - apic_b->arch_id; 163 } 164 165 /* 166 * returns pointer to CPUArchId descriptor that matches CPU's apic_id 167 * in ms->possible_cpus->cpus, if ms->possible_cpus->cpus has no 168 * entry corresponding to CPU's apic_id returns NULL. 169 */ 170 CPUArchId *x86_find_cpu_slot(MachineState *ms, uint32_t id, int *idx) 171 { 172 CPUArchId apic_id, *found_cpu; 173 174 apic_id.arch_id = id; 175 found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus, 176 ms->possible_cpus->len, sizeof(*ms->possible_cpus->cpus), 177 x86_apic_cmp); 178 if (found_cpu && idx) { 179 *idx = found_cpu - ms->possible_cpus->cpus; 180 } 181 return found_cpu; 182 } 183 184 void x86_cpu_plug(HotplugHandler *hotplug_dev, 185 DeviceState *dev, Error **errp) 186 { 187 CPUArchId *found_cpu; 188 Error *local_err = NULL; 189 X86CPU *cpu = X86_CPU(dev); 190 X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 191 192 if (x86ms->acpi_dev) { 193 hotplug_handler_plug(x86ms->acpi_dev, dev, &local_err); 194 if (local_err) { 195 goto out; 196 } 197 } 198 199 /* increment the number of CPUs */ 200 x86ms->boot_cpus++; 201 if (x86ms->rtc) { 202 x86_rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus); 203 } 204 if (x86ms->fw_cfg) { 205 fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); 206 } 207 208 found_cpu = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, NULL); 209 found_cpu->cpu = OBJECT(dev); 210 out: 211 error_propagate(errp, local_err); 212 } 213 214 void x86_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, 215 DeviceState *dev, Error **errp) 216 { 217 int idx = -1; 218 X86CPU *cpu = X86_CPU(dev); 219 X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 220 221 if (!x86ms->acpi_dev) { 222 error_setg(errp, "CPU hot unplug not supported without ACPI"); 223 return; 224 } 225 226 x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, &idx); 227 assert(idx != -1); 228 if (idx == 0) { 229 error_setg(errp, "Boot CPU is unpluggable"); 230 return; 231 } 232 233 hotplug_handler_unplug_request(x86ms->acpi_dev, dev, 234 errp); 235 } 236 237 void x86_cpu_unplug_cb(HotplugHandler *hotplug_dev, 238 DeviceState *dev, Error **errp) 239 { 240 CPUArchId *found_cpu; 241 Error *local_err = NULL; 242 X86CPU *cpu = X86_CPU(dev); 243 X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 244 245 hotplug_handler_unplug(x86ms->acpi_dev, dev, &local_err); 246 if (local_err) { 247 goto out; 248 } 249 250 found_cpu = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, NULL); 251 found_cpu->cpu = NULL; 252 qdev_unrealize(dev); 253 254 /* decrement the number of CPUs */ 255 x86ms->boot_cpus--; 256 /* Update the number of CPUs in CMOS */ 257 x86_rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus); 258 fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); 259 out: 260 error_propagate(errp, local_err); 261 } 262 263 void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, 264 DeviceState *dev, Error **errp) 265 { 266 int idx; 267 CPUState *cs; 268 CPUArchId *cpu_slot; 269 X86CPUTopoIDs topo_ids; 270 X86CPU *cpu = X86_CPU(dev); 271 CPUX86State *env = &cpu->env; 272 MachineState *ms = MACHINE(hotplug_dev); 273 X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 274 unsigned int smp_cores = ms->smp.cores; 275 unsigned int smp_threads = ms->smp.threads; 276 X86CPUTopoInfo topo_info; 277 278 if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { 279 error_setg(errp, "Invalid CPU type, expected cpu type: '%s'", 280 ms->cpu_type); 281 return; 282 } 283 284 if (x86ms->acpi_dev) { 285 Error *local_err = NULL; 286 287 hotplug_handler_pre_plug(HOTPLUG_HANDLER(x86ms->acpi_dev), dev, 288 &local_err); 289 if (local_err) { 290 error_propagate(errp, local_err); 291 return; 292 } 293 } 294 295 init_topo_info(&topo_info, x86ms); 296 297 env->nr_dies = x86ms->smp_dies; 298 299 /* 300 * If APIC ID is not set, 301 * set it based on socket/die/core/thread properties. 302 */ 303 if (cpu->apic_id == UNASSIGNED_APIC_ID) { 304 int max_socket = (ms->smp.max_cpus - 1) / 305 smp_threads / smp_cores / x86ms->smp_dies; 306 307 /* 308 * die-id was optional in QEMU 4.0 and older, so keep it optional 309 * if there's only one die per socket. 310 */ 311 if (cpu->die_id < 0 && x86ms->smp_dies == 1) { 312 cpu->die_id = 0; 313 } 314 315 if (cpu->socket_id < 0) { 316 error_setg(errp, "CPU socket-id is not set"); 317 return; 318 } else if (cpu->socket_id > max_socket) { 319 error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u", 320 cpu->socket_id, max_socket); 321 return; 322 } 323 if (cpu->die_id < 0) { 324 error_setg(errp, "CPU die-id is not set"); 325 return; 326 } else if (cpu->die_id > x86ms->smp_dies - 1) { 327 error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u", 328 cpu->die_id, x86ms->smp_dies - 1); 329 return; 330 } 331 if (cpu->core_id < 0) { 332 error_setg(errp, "CPU core-id is not set"); 333 return; 334 } else if (cpu->core_id > (smp_cores - 1)) { 335 error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u", 336 cpu->core_id, smp_cores - 1); 337 return; 338 } 339 if (cpu->thread_id < 0) { 340 error_setg(errp, "CPU thread-id is not set"); 341 return; 342 } else if (cpu->thread_id > (smp_threads - 1)) { 343 error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u", 344 cpu->thread_id, smp_threads - 1); 345 return; 346 } 347 348 topo_ids.pkg_id = cpu->socket_id; 349 topo_ids.die_id = cpu->die_id; 350 topo_ids.core_id = cpu->core_id; 351 topo_ids.smt_id = cpu->thread_id; 352 cpu->apic_id = x86_apicid_from_topo_ids(&topo_info, &topo_ids); 353 } 354 355 cpu_slot = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, &idx); 356 if (!cpu_slot) { 357 MachineState *ms = MACHINE(x86ms); 358 359 x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); 360 error_setg(errp, 361 "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with" 362 " APIC ID %" PRIu32 ", valid index range 0:%d", 363 topo_ids.pkg_id, topo_ids.die_id, topo_ids.core_id, topo_ids.smt_id, 364 cpu->apic_id, ms->possible_cpus->len - 1); 365 return; 366 } 367 368 if (cpu_slot->cpu) { 369 error_setg(errp, "CPU[%d] with APIC ID %" PRIu32 " exists", 370 idx, cpu->apic_id); 371 return; 372 } 373 374 /* if 'address' properties socket-id/core-id/thread-id are not set, set them 375 * so that machine_query_hotpluggable_cpus would show correct values 376 */ 377 /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn() 378 * once -smp refactoring is complete and there will be CPU private 379 * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */ 380 x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); 381 if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) { 382 error_setg(errp, "property socket-id: %u doesn't match set apic-id:" 383 " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, 384 topo_ids.pkg_id); 385 return; 386 } 387 cpu->socket_id = topo_ids.pkg_id; 388 389 if (cpu->die_id != -1 && cpu->die_id != topo_ids.die_id) { 390 error_setg(errp, "property die-id: %u doesn't match set apic-id:" 391 " 0x%x (die-id: %u)", cpu->die_id, cpu->apic_id, topo_ids.die_id); 392 return; 393 } 394 cpu->die_id = topo_ids.die_id; 395 396 if (cpu->core_id != -1 && cpu->core_id != topo_ids.core_id) { 397 error_setg(errp, "property core-id: %u doesn't match set apic-id:" 398 " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, 399 topo_ids.core_id); 400 return; 401 } 402 cpu->core_id = topo_ids.core_id; 403 404 if (cpu->thread_id != -1 && cpu->thread_id != topo_ids.smt_id) { 405 error_setg(errp, "property thread-id: %u doesn't match set apic-id:" 406 " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, 407 topo_ids.smt_id); 408 return; 409 } 410 cpu->thread_id = topo_ids.smt_id; 411 412 if (hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && 413 !kvm_hv_vpindex_settable()) { 414 error_setg(errp, "kernel doesn't allow setting HyperV VP_INDEX"); 415 return; 416 } 417 418 cs = CPU(cpu); 419 cs->cpu_index = idx; 420 421 numa_cpu_pre_plug(cpu_slot, dev, errp); 422 } 423 424 CpuInstanceProperties 425 x86_cpu_index_to_props(MachineState *ms, unsigned cpu_index) 426 { 427 MachineClass *mc = MACHINE_GET_CLASS(ms); 428 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms); 429 430 assert(cpu_index < possible_cpus->len); 431 return possible_cpus->cpus[cpu_index].props; 432 } 433 434 int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx) 435 { 436 X86CPUTopoIDs topo_ids; 437 X86MachineState *x86ms = X86_MACHINE(ms); 438 X86CPUTopoInfo topo_info; 439 440 init_topo_info(&topo_info, x86ms); 441 442 assert(idx < ms->possible_cpus->len); 443 x86_topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id, 444 &topo_info, &topo_ids); 445 return topo_ids.pkg_id % ms->numa_state->num_nodes; 446 } 447 448 const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) 449 { 450 X86MachineState *x86ms = X86_MACHINE(ms); 451 unsigned int max_cpus = ms->smp.max_cpus; 452 X86CPUTopoInfo topo_info; 453 int i; 454 455 if (ms->possible_cpus) { 456 /* 457 * make sure that max_cpus hasn't changed since the first use, i.e. 458 * -smp hasn't been parsed after it 459 */ 460 assert(ms->possible_cpus->len == max_cpus); 461 return ms->possible_cpus; 462 } 463 464 ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) + 465 sizeof(CPUArchId) * max_cpus); 466 ms->possible_cpus->len = max_cpus; 467 468 init_topo_info(&topo_info, x86ms); 469 470 for (i = 0; i < ms->possible_cpus->len; i++) { 471 X86CPUTopoIDs topo_ids; 472 473 ms->possible_cpus->cpus[i].type = ms->cpu_type; 474 ms->possible_cpus->cpus[i].vcpus_count = 1; 475 ms->possible_cpus->cpus[i].arch_id = 476 x86_cpu_apic_id_from_index(x86ms, i); 477 x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, 478 &topo_info, &topo_ids); 479 ms->possible_cpus->cpus[i].props.has_socket_id = true; 480 ms->possible_cpus->cpus[i].props.socket_id = topo_ids.pkg_id; 481 if (x86ms->smp_dies > 1) { 482 ms->possible_cpus->cpus[i].props.has_die_id = true; 483 ms->possible_cpus->cpus[i].props.die_id = topo_ids.die_id; 484 } 485 ms->possible_cpus->cpus[i].props.has_core_id = true; 486 ms->possible_cpus->cpus[i].props.core_id = topo_ids.core_id; 487 ms->possible_cpus->cpus[i].props.has_thread_id = true; 488 ms->possible_cpus->cpus[i].props.thread_id = topo_ids.smt_id; 489 } 490 return ms->possible_cpus; 491 } 492 493 static void x86_nmi(NMIState *n, int cpu_index, Error **errp) 494 { 495 /* cpu index isn't used */ 496 CPUState *cs; 497 498 CPU_FOREACH(cs) { 499 X86CPU *cpu = X86_CPU(cs); 500 501 if (!cpu->apic_state) { 502 cpu_interrupt(cs, CPU_INTERRUPT_NMI); 503 } else { 504 apic_deliver_nmi(cpu->apic_state); 505 } 506 } 507 } 508 509 static long get_file_size(FILE *f) 510 { 511 long where, size; 512 513 /* XXX: on Unix systems, using fstat() probably makes more sense */ 514 515 where = ftell(f); 516 fseek(f, 0, SEEK_END); 517 size = ftell(f); 518 fseek(f, where, SEEK_SET); 519 520 return size; 521 } 522 523 /* TSC handling */ 524 uint64_t cpu_get_tsc(CPUX86State *env) 525 { 526 return cpus_get_elapsed_ticks(); 527 } 528 529 /* IRQ handling */ 530 static void pic_irq_request(void *opaque, int irq, int level) 531 { 532 CPUState *cs = first_cpu; 533 X86CPU *cpu = X86_CPU(cs); 534 535 trace_x86_pic_interrupt(irq, level); 536 if (cpu->apic_state && !kvm_irqchip_in_kernel() && 537 !whpx_apic_in_platform()) { 538 CPU_FOREACH(cs) { 539 cpu = X86_CPU(cs); 540 if (apic_accept_pic_intr(cpu->apic_state)) { 541 apic_deliver_pic_intr(cpu->apic_state, level); 542 } 543 } 544 } else { 545 if (level) { 546 cpu_interrupt(cs, CPU_INTERRUPT_HARD); 547 } else { 548 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); 549 } 550 } 551 } 552 553 qemu_irq x86_allocate_cpu_irq(void) 554 { 555 return qemu_allocate_irq(pic_irq_request, NULL, 0); 556 } 557 558 int cpu_get_pic_interrupt(CPUX86State *env) 559 { 560 X86CPU *cpu = env_archcpu(env); 561 int intno; 562 563 if (!kvm_irqchip_in_kernel() && !whpx_apic_in_platform()) { 564 intno = apic_get_interrupt(cpu->apic_state); 565 if (intno >= 0) { 566 return intno; 567 } 568 /* read the irq from the PIC */ 569 if (!apic_accept_pic_intr(cpu->apic_state)) { 570 return -1; 571 } 572 } 573 574 intno = pic_read_irq(isa_pic); 575 return intno; 576 } 577 578 DeviceState *cpu_get_current_apic(void) 579 { 580 if (current_cpu) { 581 X86CPU *cpu = X86_CPU(current_cpu); 582 return cpu->apic_state; 583 } else { 584 return NULL; 585 } 586 } 587 588 void gsi_handler(void *opaque, int n, int level) 589 { 590 GSIState *s = opaque; 591 592 trace_x86_gsi_interrupt(n, level); 593 switch (n) { 594 case 0 ... ISA_NUM_IRQS - 1: 595 if (s->i8259_irq[n]) { 596 /* Under KVM, Kernel will forward to both PIC and IOAPIC */ 597 qemu_set_irq(s->i8259_irq[n], level); 598 } 599 /* fall through */ 600 case ISA_NUM_IRQS ... IOAPIC_NUM_PINS - 1: 601 qemu_set_irq(s->ioapic_irq[n], level); 602 break; 603 case IO_APIC_SECONDARY_IRQBASE 604 ... IO_APIC_SECONDARY_IRQBASE + IOAPIC_NUM_PINS - 1: 605 qemu_set_irq(s->ioapic2_irq[n - IO_APIC_SECONDARY_IRQBASE], level); 606 break; 607 } 608 } 609 610 void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) 611 { 612 DeviceState *dev; 613 SysBusDevice *d; 614 unsigned int i; 615 616 assert(parent_name); 617 if (kvm_ioapic_in_kernel()) { 618 dev = qdev_new(TYPE_KVM_IOAPIC); 619 } else { 620 dev = qdev_new(TYPE_IOAPIC); 621 } 622 object_property_add_child(object_resolve_path(parent_name, NULL), 623 "ioapic", OBJECT(dev)); 624 d = SYS_BUS_DEVICE(dev); 625 sysbus_realize_and_unref(d, &error_fatal); 626 sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); 627 628 for (i = 0; i < IOAPIC_NUM_PINS; i++) { 629 gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); 630 } 631 } 632 633 DeviceState *ioapic_init_secondary(GSIState *gsi_state) 634 { 635 DeviceState *dev; 636 SysBusDevice *d; 637 unsigned int i; 638 639 dev = qdev_new(TYPE_IOAPIC); 640 d = SYS_BUS_DEVICE(dev); 641 sysbus_realize_and_unref(d, &error_fatal); 642 sysbus_mmio_map(d, 0, IO_APIC_SECONDARY_ADDRESS); 643 644 for (i = 0; i < IOAPIC_NUM_PINS; i++) { 645 gsi_state->ioapic2_irq[i] = qdev_get_gpio_in(dev, i); 646 } 647 return dev; 648 } 649 650 struct setup_data { 651 uint64_t next; 652 uint32_t type; 653 uint32_t len; 654 uint8_t data[]; 655 } __attribute__((packed)); 656 657 658 /* 659 * The entry point into the kernel for PVH boot is different from 660 * the native entry point. The PVH entry is defined by the x86/HVM 661 * direct boot ABI and is available in an ELFNOTE in the kernel binary. 662 * 663 * This function is passed to load_elf() when it is called from 664 * load_elfboot() which then additionally checks for an ELF Note of 665 * type XEN_ELFNOTE_PHYS32_ENTRY and passes it to this function to 666 * parse the PVH entry address from the ELF Note. 667 * 668 * Due to trickery in elf_opts.h, load_elf() is actually available as 669 * load_elf32() or load_elf64() and this routine needs to be able 670 * to deal with being called as 32 or 64 bit. 671 * 672 * The address of the PVH entry point is saved to the 'pvh_start_addr' 673 * global variable. (although the entry point is 32-bit, the kernel 674 * binary can be either 32-bit or 64-bit). 675 */ 676 static uint64_t read_pvh_start_addr(void *arg1, void *arg2, bool is64) 677 { 678 size_t *elf_note_data_addr; 679 680 /* Check if ELF Note header passed in is valid */ 681 if (arg1 == NULL) { 682 return 0; 683 } 684 685 if (is64) { 686 struct elf64_note *nhdr64 = (struct elf64_note *)arg1; 687 uint64_t nhdr_size64 = sizeof(struct elf64_note); 688 uint64_t phdr_align = *(uint64_t *)arg2; 689 uint64_t nhdr_namesz = nhdr64->n_namesz; 690 691 elf_note_data_addr = 692 ((void *)nhdr64) + nhdr_size64 + 693 QEMU_ALIGN_UP(nhdr_namesz, phdr_align); 694 } else { 695 struct elf32_note *nhdr32 = (struct elf32_note *)arg1; 696 uint32_t nhdr_size32 = sizeof(struct elf32_note); 697 uint32_t phdr_align = *(uint32_t *)arg2; 698 uint32_t nhdr_namesz = nhdr32->n_namesz; 699 700 elf_note_data_addr = 701 ((void *)nhdr32) + nhdr_size32 + 702 QEMU_ALIGN_UP(nhdr_namesz, phdr_align); 703 } 704 705 pvh_start_addr = *elf_note_data_addr; 706 707 return pvh_start_addr; 708 } 709 710 static bool load_elfboot(const char *kernel_filename, 711 int kernel_file_size, 712 uint8_t *header, 713 size_t pvh_xen_start_addr, 714 FWCfgState *fw_cfg) 715 { 716 uint32_t flags = 0; 717 uint32_t mh_load_addr = 0; 718 uint32_t elf_kernel_size = 0; 719 uint64_t elf_entry; 720 uint64_t elf_low, elf_high; 721 int kernel_size; 722 723 if (ldl_p(header) != 0x464c457f) { 724 return false; /* no elfboot */ 725 } 726 727 bool elf_is64 = header[EI_CLASS] == ELFCLASS64; 728 flags = elf_is64 ? 729 ((Elf64_Ehdr *)header)->e_flags : ((Elf32_Ehdr *)header)->e_flags; 730 731 if (flags & 0x00010004) { /* LOAD_ELF_HEADER_HAS_ADDR */ 732 error_report("elfboot unsupported flags = %x", flags); 733 exit(1); 734 } 735 736 uint64_t elf_note_type = XEN_ELFNOTE_PHYS32_ENTRY; 737 kernel_size = load_elf(kernel_filename, read_pvh_start_addr, 738 NULL, &elf_note_type, &elf_entry, 739 &elf_low, &elf_high, NULL, 0, I386_ELF_MACHINE, 740 0, 0); 741 742 if (kernel_size < 0) { 743 error_report("Error while loading elf kernel"); 744 exit(1); 745 } 746 mh_load_addr = elf_low; 747 elf_kernel_size = elf_high - elf_low; 748 749 if (pvh_start_addr == 0) { 750 error_report("Error loading uncompressed kernel without PVH ELF Note"); 751 exit(1); 752 } 753 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, pvh_start_addr); 754 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr); 755 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, elf_kernel_size); 756 757 return true; 758 } 759 760 void x86_load_linux(X86MachineState *x86ms, 761 FWCfgState *fw_cfg, 762 int acpi_data_size, 763 bool pvh_enabled, 764 bool linuxboot_dma_enabled) 765 { 766 uint16_t protocol; 767 int setup_size, kernel_size, cmdline_size; 768 int dtb_size, setup_data_offset; 769 uint32_t initrd_max; 770 uint8_t header[8192], *setup, *kernel; 771 hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0; 772 FILE *f; 773 char *vmode; 774 MachineState *machine = MACHINE(x86ms); 775 struct setup_data *setup_data; 776 const char *kernel_filename = machine->kernel_filename; 777 const char *initrd_filename = machine->initrd_filename; 778 const char *dtb_filename = machine->dtb; 779 const char *kernel_cmdline = machine->kernel_cmdline; 780 781 /* Align to 16 bytes as a paranoia measure */ 782 cmdline_size = (strlen(kernel_cmdline) + 16) & ~15; 783 784 /* load the kernel header */ 785 f = fopen(kernel_filename, "rb"); 786 if (!f) { 787 fprintf(stderr, "qemu: could not open kernel file '%s': %s\n", 788 kernel_filename, strerror(errno)); 789 exit(1); 790 } 791 792 kernel_size = get_file_size(f); 793 if (!kernel_size || 794 fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != 795 MIN(ARRAY_SIZE(header), kernel_size)) { 796 fprintf(stderr, "qemu: could not load kernel '%s': %s\n", 797 kernel_filename, strerror(errno)); 798 exit(1); 799 } 800 801 /* kernel protocol version */ 802 if (ldl_p(header + 0x202) == 0x53726448) { 803 protocol = lduw_p(header + 0x206); 804 } else { 805 /* 806 * This could be a multiboot kernel. If it is, let's stop treating it 807 * like a Linux kernel. 808 * Note: some multiboot images could be in the ELF format (the same of 809 * PVH), so we try multiboot first since we check the multiboot magic 810 * header before to load it. 811 */ 812 if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename, 813 kernel_cmdline, kernel_size, header)) { 814 return; 815 } 816 /* 817 * Check if the file is an uncompressed kernel file (ELF) and load it, 818 * saving the PVH entry point used by the x86/HVM direct boot ABI. 819 * If load_elfboot() is successful, populate the fw_cfg info. 820 */ 821 if (pvh_enabled && 822 load_elfboot(kernel_filename, kernel_size, 823 header, pvh_start_addr, fw_cfg)) { 824 fclose(f); 825 826 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 827 strlen(kernel_cmdline) + 1); 828 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); 829 830 fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, sizeof(header)); 831 fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, 832 header, sizeof(header)); 833 834 /* load initrd */ 835 if (initrd_filename) { 836 GMappedFile *mapped_file; 837 gsize initrd_size; 838 gchar *initrd_data; 839 GError *gerr = NULL; 840 841 mapped_file = g_mapped_file_new(initrd_filename, false, &gerr); 842 if (!mapped_file) { 843 fprintf(stderr, "qemu: error reading initrd %s: %s\n", 844 initrd_filename, gerr->message); 845 exit(1); 846 } 847 x86ms->initrd_mapped_file = mapped_file; 848 849 initrd_data = g_mapped_file_get_contents(mapped_file); 850 initrd_size = g_mapped_file_get_length(mapped_file); 851 initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1; 852 if (initrd_size >= initrd_max) { 853 fprintf(stderr, "qemu: initrd is too large, cannot support." 854 "(max: %"PRIu32", need %"PRId64")\n", 855 initrd_max, (uint64_t)initrd_size); 856 exit(1); 857 } 858 859 initrd_addr = (initrd_max - initrd_size) & ~4095; 860 861 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); 862 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 863 fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, 864 initrd_size); 865 } 866 867 option_rom[nb_option_roms].bootindex = 0; 868 option_rom[nb_option_roms].name = "pvh.bin"; 869 nb_option_roms++; 870 871 return; 872 } 873 protocol = 0; 874 } 875 876 if (protocol < 0x200 || !(header[0x211] & 0x01)) { 877 /* Low kernel */ 878 real_addr = 0x90000; 879 cmdline_addr = 0x9a000 - cmdline_size; 880 prot_addr = 0x10000; 881 } else if (protocol < 0x202) { 882 /* High but ancient kernel */ 883 real_addr = 0x90000; 884 cmdline_addr = 0x9a000 - cmdline_size; 885 prot_addr = 0x100000; 886 } else { 887 /* High and recent kernel */ 888 real_addr = 0x10000; 889 cmdline_addr = 0x20000; 890 prot_addr = 0x100000; 891 } 892 893 /* highest address for loading the initrd */ 894 if (protocol >= 0x20c && 895 lduw_p(header + 0x236) & XLF_CAN_BE_LOADED_ABOVE_4G) { 896 /* 897 * Linux has supported initrd up to 4 GB for a very long time (2007, 898 * long before XLF_CAN_BE_LOADED_ABOVE_4G which was added in 2013), 899 * though it only sets initrd_max to 2 GB to "work around bootloader 900 * bugs". Luckily, QEMU firmware(which does something like bootloader) 901 * has supported this. 902 * 903 * It's believed that if XLF_CAN_BE_LOADED_ABOVE_4G is set, initrd can 904 * be loaded into any address. 905 * 906 * In addition, initrd_max is uint32_t simply because QEMU doesn't 907 * support the 64-bit boot protocol (specifically the ext_ramdisk_image 908 * field). 909 * 910 * Therefore here just limit initrd_max to UINT32_MAX simply as well. 911 */ 912 initrd_max = UINT32_MAX; 913 } else if (protocol >= 0x203) { 914 initrd_max = ldl_p(header + 0x22c); 915 } else { 916 initrd_max = 0x37ffffff; 917 } 918 919 if (initrd_max >= x86ms->below_4g_mem_size - acpi_data_size) { 920 initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1; 921 } 922 923 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr); 924 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1); 925 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); 926 927 if (protocol >= 0x202) { 928 stl_p(header + 0x228, cmdline_addr); 929 } else { 930 stw_p(header + 0x20, 0xA33F); 931 stw_p(header + 0x22, cmdline_addr - real_addr); 932 } 933 934 /* handle vga= parameter */ 935 vmode = strstr(kernel_cmdline, "vga="); 936 if (vmode) { 937 unsigned int video_mode; 938 const char *end; 939 int ret; 940 /* skip "vga=" */ 941 vmode += 4; 942 if (!strncmp(vmode, "normal", 6)) { 943 video_mode = 0xffff; 944 } else if (!strncmp(vmode, "ext", 3)) { 945 video_mode = 0xfffe; 946 } else if (!strncmp(vmode, "ask", 3)) { 947 video_mode = 0xfffd; 948 } else { 949 ret = qemu_strtoui(vmode, &end, 0, &video_mode); 950 if (ret != 0 || (*end && *end != ' ')) { 951 fprintf(stderr, "qemu: invalid 'vga=' kernel parameter.\n"); 952 exit(1); 953 } 954 } 955 stw_p(header + 0x1fa, video_mode); 956 } 957 958 /* loader type */ 959 /* 960 * High nybble = B reserved for QEMU; low nybble is revision number. 961 * If this code is substantially changed, you may want to consider 962 * incrementing the revision. 963 */ 964 if (protocol >= 0x200) { 965 header[0x210] = 0xB0; 966 } 967 /* heap */ 968 if (protocol >= 0x201) { 969 header[0x211] |= 0x80; /* CAN_USE_HEAP */ 970 stw_p(header + 0x224, cmdline_addr - real_addr - 0x200); 971 } 972 973 /* load initrd */ 974 if (initrd_filename) { 975 GMappedFile *mapped_file; 976 gsize initrd_size; 977 gchar *initrd_data; 978 GError *gerr = NULL; 979 980 if (protocol < 0x200) { 981 fprintf(stderr, "qemu: linux kernel too old to load a ram disk\n"); 982 exit(1); 983 } 984 985 mapped_file = g_mapped_file_new(initrd_filename, false, &gerr); 986 if (!mapped_file) { 987 fprintf(stderr, "qemu: error reading initrd %s: %s\n", 988 initrd_filename, gerr->message); 989 exit(1); 990 } 991 x86ms->initrd_mapped_file = mapped_file; 992 993 initrd_data = g_mapped_file_get_contents(mapped_file); 994 initrd_size = g_mapped_file_get_length(mapped_file); 995 if (initrd_size >= initrd_max) { 996 fprintf(stderr, "qemu: initrd is too large, cannot support." 997 "(max: %"PRIu32", need %"PRId64")\n", 998 initrd_max, (uint64_t)initrd_size); 999 exit(1); 1000 } 1001 1002 initrd_addr = (initrd_max - initrd_size) & ~4095; 1003 1004 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); 1005 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 1006 fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size); 1007 1008 stl_p(header + 0x218, initrd_addr); 1009 stl_p(header + 0x21c, initrd_size); 1010 } 1011 1012 /* load kernel and setup */ 1013 setup_size = header[0x1f1]; 1014 if (setup_size == 0) { 1015 setup_size = 4; 1016 } 1017 setup_size = (setup_size + 1) * 512; 1018 if (setup_size > kernel_size) { 1019 fprintf(stderr, "qemu: invalid kernel header\n"); 1020 exit(1); 1021 } 1022 kernel_size -= setup_size; 1023 1024 setup = g_malloc(setup_size); 1025 kernel = g_malloc(kernel_size); 1026 fseek(f, 0, SEEK_SET); 1027 if (fread(setup, 1, setup_size, f) != setup_size) { 1028 fprintf(stderr, "fread() failed\n"); 1029 exit(1); 1030 } 1031 if (fread(kernel, 1, kernel_size, f) != kernel_size) { 1032 fprintf(stderr, "fread() failed\n"); 1033 exit(1); 1034 } 1035 fclose(f); 1036 1037 /* append dtb to kernel */ 1038 if (dtb_filename) { 1039 if (protocol < 0x209) { 1040 fprintf(stderr, "qemu: Linux kernel too old to load a dtb\n"); 1041 exit(1); 1042 } 1043 1044 dtb_size = get_image_size(dtb_filename); 1045 if (dtb_size <= 0) { 1046 fprintf(stderr, "qemu: error reading dtb %s: %s\n", 1047 dtb_filename, strerror(errno)); 1048 exit(1); 1049 } 1050 1051 setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16); 1052 kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size; 1053 kernel = g_realloc(kernel, kernel_size); 1054 1055 stq_p(header + 0x250, prot_addr + setup_data_offset); 1056 1057 setup_data = (struct setup_data *)(kernel + setup_data_offset); 1058 setup_data->next = 0; 1059 setup_data->type = cpu_to_le32(SETUP_DTB); 1060 setup_data->len = cpu_to_le32(dtb_size); 1061 1062 load_image_size(dtb_filename, setup_data->data, dtb_size); 1063 } 1064 1065 memcpy(setup, header, MIN(sizeof(header), setup_size)); 1066 1067 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr); 1068 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 1069 fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size); 1070 1071 fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr); 1072 fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size); 1073 fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size); 1074 1075 option_rom[nb_option_roms].bootindex = 0; 1076 option_rom[nb_option_roms].name = "linuxboot.bin"; 1077 if (linuxboot_dma_enabled && fw_cfg_dma_enabled(fw_cfg)) { 1078 option_rom[nb_option_roms].name = "linuxboot_dma.bin"; 1079 } 1080 nb_option_roms++; 1081 } 1082 1083 void x86_bios_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw) 1084 { 1085 char *filename; 1086 MemoryRegion *bios, *isa_bios; 1087 int bios_size, isa_bios_size; 1088 int ret; 1089 1090 /* BIOS load */ 1091 if (bios_name == NULL) { 1092 bios_name = BIOS_FILENAME; 1093 } 1094 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 1095 if (filename) { 1096 bios_size = get_image_size(filename); 1097 } else { 1098 bios_size = -1; 1099 } 1100 if (bios_size <= 0 || 1101 (bios_size % 65536) != 0) { 1102 goto bios_error; 1103 } 1104 bios = g_malloc(sizeof(*bios)); 1105 memory_region_init_ram(bios, NULL, "pc.bios", bios_size, &error_fatal); 1106 if (!isapc_ram_fw) { 1107 memory_region_set_readonly(bios, true); 1108 } 1109 ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); 1110 if (ret != 0) { 1111 bios_error: 1112 fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); 1113 exit(1); 1114 } 1115 g_free(filename); 1116 1117 /* map the last 128KB of the BIOS in ISA space */ 1118 isa_bios_size = MIN(bios_size, 128 * KiB); 1119 isa_bios = g_malloc(sizeof(*isa_bios)); 1120 memory_region_init_alias(isa_bios, NULL, "isa-bios", bios, 1121 bios_size - isa_bios_size, isa_bios_size); 1122 memory_region_add_subregion_overlap(rom_memory, 1123 0x100000 - isa_bios_size, 1124 isa_bios, 1125 1); 1126 if (!isapc_ram_fw) { 1127 memory_region_set_readonly(isa_bios, true); 1128 } 1129 1130 /* map all the bios at the top of memory */ 1131 memory_region_add_subregion(rom_memory, 1132 (uint32_t)(-bios_size), 1133 bios); 1134 } 1135 1136 bool x86_machine_is_smm_enabled(const X86MachineState *x86ms) 1137 { 1138 bool smm_available = false; 1139 1140 if (x86ms->smm == ON_OFF_AUTO_OFF) { 1141 return false; 1142 } 1143 1144 if (tcg_enabled() || qtest_enabled()) { 1145 smm_available = true; 1146 } else if (kvm_enabled()) { 1147 smm_available = kvm_has_smm(); 1148 } 1149 1150 if (smm_available) { 1151 return true; 1152 } 1153 1154 if (x86ms->smm == ON_OFF_AUTO_ON) { 1155 error_report("System Management Mode not supported by this hypervisor."); 1156 exit(1); 1157 } 1158 return false; 1159 } 1160 1161 static void x86_machine_get_smm(Object *obj, Visitor *v, const char *name, 1162 void *opaque, Error **errp) 1163 { 1164 X86MachineState *x86ms = X86_MACHINE(obj); 1165 OnOffAuto smm = x86ms->smm; 1166 1167 visit_type_OnOffAuto(v, name, &smm, errp); 1168 } 1169 1170 static void x86_machine_set_smm(Object *obj, Visitor *v, const char *name, 1171 void *opaque, Error **errp) 1172 { 1173 X86MachineState *x86ms = X86_MACHINE(obj); 1174 1175 visit_type_OnOffAuto(v, name, &x86ms->smm, errp); 1176 } 1177 1178 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms) 1179 { 1180 if (x86ms->acpi == ON_OFF_AUTO_OFF) { 1181 return false; 1182 } 1183 return true; 1184 } 1185 1186 static void x86_machine_get_acpi(Object *obj, Visitor *v, const char *name, 1187 void *opaque, Error **errp) 1188 { 1189 X86MachineState *x86ms = X86_MACHINE(obj); 1190 OnOffAuto acpi = x86ms->acpi; 1191 1192 visit_type_OnOffAuto(v, name, &acpi, errp); 1193 } 1194 1195 static void x86_machine_set_acpi(Object *obj, Visitor *v, const char *name, 1196 void *opaque, Error **errp) 1197 { 1198 X86MachineState *x86ms = X86_MACHINE(obj); 1199 1200 visit_type_OnOffAuto(v, name, &x86ms->acpi, errp); 1201 } 1202 1203 static void x86_machine_initfn(Object *obj) 1204 { 1205 X86MachineState *x86ms = X86_MACHINE(obj); 1206 1207 x86ms->smm = ON_OFF_AUTO_AUTO; 1208 x86ms->acpi = ON_OFF_AUTO_AUTO; 1209 x86ms->smp_dies = 1; 1210 x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS; 1211 } 1212 1213 static void x86_machine_class_init(ObjectClass *oc, void *data) 1214 { 1215 MachineClass *mc = MACHINE_CLASS(oc); 1216 X86MachineClass *x86mc = X86_MACHINE_CLASS(oc); 1217 NMIClass *nc = NMI_CLASS(oc); 1218 1219 mc->cpu_index_to_instance_props = x86_cpu_index_to_props; 1220 mc->get_default_cpu_node_id = x86_get_default_cpu_node_id; 1221 mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids; 1222 x86mc->compat_apic_id_mode = false; 1223 x86mc->save_tsc_khz = true; 1224 nc->nmi_monitor_handler = x86_nmi; 1225 1226 object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto", 1227 x86_machine_get_smm, x86_machine_set_smm, 1228 NULL, NULL); 1229 object_class_property_set_description(oc, X86_MACHINE_SMM, 1230 "Enable SMM"); 1231 1232 object_class_property_add(oc, X86_MACHINE_ACPI, "OnOffAuto", 1233 x86_machine_get_acpi, x86_machine_set_acpi, 1234 NULL, NULL); 1235 object_class_property_set_description(oc, X86_MACHINE_ACPI, 1236 "Enable ACPI"); 1237 } 1238 1239 static const TypeInfo x86_machine_info = { 1240 .name = TYPE_X86_MACHINE, 1241 .parent = TYPE_MACHINE, 1242 .abstract = true, 1243 .instance_size = sizeof(X86MachineState), 1244 .instance_init = x86_machine_initfn, 1245 .class_size = sizeof(X86MachineClass), 1246 .class_init = x86_machine_class_init, 1247 .interfaces = (InterfaceInfo[]) { 1248 { TYPE_NMI }, 1249 { } 1250 }, 1251 }; 1252 1253 static void x86_machine_register_types(void) 1254 { 1255 type_register_static(&x86_machine_info); 1256 } 1257 1258 type_init(x86_machine_register_types) 1259