1b061f059SPaolo Bonzini /* 2b061f059SPaolo Bonzini * Copyright (c) 2003-2004 Fabrice Bellard 3b061f059SPaolo Bonzini * Copyright (c) 2019, 2024 Red Hat, Inc. 4b061f059SPaolo Bonzini * 5b061f059SPaolo Bonzini * Permission is hereby granted, free of charge, to any person obtaining a copy 6b061f059SPaolo Bonzini * of this software and associated documentation files (the "Software"), to deal 7b061f059SPaolo Bonzini * in the Software without restriction, including without limitation the rights 8b061f059SPaolo Bonzini * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9b061f059SPaolo Bonzini * copies of the Software, and to permit persons to whom the Software is 10b061f059SPaolo Bonzini * furnished to do so, subject to the following conditions: 11b061f059SPaolo Bonzini * 12b061f059SPaolo Bonzini * The above copyright notice and this permission notice shall be included in 13b061f059SPaolo Bonzini * all copies or substantial portions of the Software. 14b061f059SPaolo Bonzini * 15b061f059SPaolo Bonzini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b061f059SPaolo Bonzini * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b061f059SPaolo Bonzini * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18b061f059SPaolo Bonzini * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19b061f059SPaolo Bonzini * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20b061f059SPaolo Bonzini * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21b061f059SPaolo Bonzini * THE SOFTWARE. 22b061f059SPaolo Bonzini */ 23b061f059SPaolo Bonzini #include "qemu/osdep.h" 24b061f059SPaolo Bonzini #include "qemu/error-report.h" 25b061f059SPaolo Bonzini #include "qemu/cutils.h" 26b061f059SPaolo Bonzini #include "qemu/units.h" 27b061f059SPaolo Bonzini #include "qemu/datadir.h" 28b061f059SPaolo Bonzini #include "qapi/error.h" 29b061f059SPaolo Bonzini #include "sysemu/numa.h" 30b061f059SPaolo Bonzini #include "sysemu/sysemu.h" 31b061f059SPaolo Bonzini #include "sysemu/xen.h" 32b061f059SPaolo Bonzini #include "trace.h" 33b061f059SPaolo Bonzini 34b061f059SPaolo Bonzini #include "hw/i386/x86.h" 35b061f059SPaolo Bonzini #include "target/i386/cpu.h" 36b061f059SPaolo Bonzini #include "hw/rtc/mc146818rtc.h" 37b061f059SPaolo Bonzini #include "target/i386/sev.h" 38b061f059SPaolo Bonzini 39b061f059SPaolo Bonzini #include "hw/acpi/cpu_hotplug.h" 40b061f059SPaolo Bonzini #include "hw/irq.h" 41b061f059SPaolo Bonzini #include "hw/loader.h" 42b061f059SPaolo Bonzini #include "multiboot.h" 43b061f059SPaolo Bonzini #include "elf.h" 44b061f059SPaolo Bonzini #include "standard-headers/asm-x86/bootparam.h" 45b061f059SPaolo Bonzini #include CONFIG_DEVICES 46b061f059SPaolo Bonzini #include "kvm/kvm_i386.h" 47b061f059SPaolo Bonzini 48b061f059SPaolo Bonzini #ifdef CONFIG_XEN_EMU 49b061f059SPaolo Bonzini #include "hw/xen/xen.h" 50b061f059SPaolo Bonzini #include "hw/i386/kvm/xen_evtchn.h" 51b061f059SPaolo Bonzini #endif 52b061f059SPaolo Bonzini 53b061f059SPaolo Bonzini /* Physical Address of PVH entry point read from kernel ELF NOTE */ 54b061f059SPaolo Bonzini static size_t pvh_start_addr; 55b061f059SPaolo Bonzini 56b061f059SPaolo Bonzini static void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp) 57b061f059SPaolo Bonzini { 58b061f059SPaolo Bonzini Object *cpu = object_new(MACHINE(x86ms)->cpu_type); 59b061f059SPaolo Bonzini 60b061f059SPaolo Bonzini if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) { 61b061f059SPaolo Bonzini goto out; 62b061f059SPaolo Bonzini } 63b061f059SPaolo Bonzini qdev_realize(DEVICE(cpu), NULL, errp); 64b061f059SPaolo Bonzini 65b061f059SPaolo Bonzini out: 66b061f059SPaolo Bonzini object_unref(cpu); 67b061f059SPaolo Bonzini } 68b061f059SPaolo Bonzini 69b061f059SPaolo Bonzini void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) 70b061f059SPaolo Bonzini { 71b061f059SPaolo Bonzini int i; 72b061f059SPaolo Bonzini const CPUArchIdList *possible_cpus; 73b061f059SPaolo Bonzini MachineState *ms = MACHINE(x86ms); 74b061f059SPaolo Bonzini MachineClass *mc = MACHINE_GET_CLASS(x86ms); 75b061f059SPaolo Bonzini 76b061f059SPaolo Bonzini x86_cpu_set_default_version(default_cpu_version); 77b061f059SPaolo Bonzini 78b061f059SPaolo Bonzini /* 79b061f059SPaolo Bonzini * Calculates the limit to CPU APIC ID values 80b061f059SPaolo Bonzini * 81b061f059SPaolo Bonzini * Limit for the APIC ID value, so that all 82b061f059SPaolo Bonzini * CPU APIC IDs are < x86ms->apic_id_limit. 83b061f059SPaolo Bonzini * 84b061f059SPaolo Bonzini * This is used for FW_CFG_MAX_CPUS. See comments on fw_cfg_arch_create(). 85b061f059SPaolo Bonzini */ 86b061f059SPaolo Bonzini x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms, 87b061f059SPaolo Bonzini ms->smp.max_cpus - 1) + 1; 88b061f059SPaolo Bonzini 89b061f059SPaolo Bonzini /* 90b061f059SPaolo Bonzini * Can we support APIC ID 255 or higher? With KVM, that requires 91b061f059SPaolo Bonzini * both in-kernel lapic and X2APIC userspace API. 92b061f059SPaolo Bonzini * 93b061f059SPaolo Bonzini * kvm_enabled() must go first to ensure that kvm_* references are 94b061f059SPaolo Bonzini * not emitted for the linker to consume (kvm_enabled() is 95b061f059SPaolo Bonzini * a literal `0` in configurations where kvm_* aren't defined) 96b061f059SPaolo Bonzini */ 97b061f059SPaolo Bonzini if (kvm_enabled() && x86ms->apic_id_limit > 255 && 98b061f059SPaolo Bonzini kvm_irqchip_in_kernel() && !kvm_enable_x2apic()) { 99b061f059SPaolo Bonzini error_report("current -smp configuration requires kernel " 100b061f059SPaolo Bonzini "irqchip and X2APIC API support."); 101b061f059SPaolo Bonzini exit(EXIT_FAILURE); 102b061f059SPaolo Bonzini } 103b061f059SPaolo Bonzini 104b061f059SPaolo Bonzini if (kvm_enabled()) { 105b061f059SPaolo Bonzini kvm_set_max_apic_id(x86ms->apic_id_limit); 106b061f059SPaolo Bonzini } 107b061f059SPaolo Bonzini 108b061f059SPaolo Bonzini if (!kvm_irqchip_in_kernel()) { 109b061f059SPaolo Bonzini apic_set_max_apic_id(x86ms->apic_id_limit); 110b061f059SPaolo Bonzini } 111b061f059SPaolo Bonzini 112b061f059SPaolo Bonzini possible_cpus = mc->possible_cpu_arch_ids(ms); 113b061f059SPaolo Bonzini for (i = 0; i < ms->smp.cpus; i++) { 114b061f059SPaolo Bonzini x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); 115b061f059SPaolo Bonzini } 116b061f059SPaolo Bonzini } 117b061f059SPaolo Bonzini 118b061f059SPaolo Bonzini void x86_rtc_set_cpus_count(ISADevice *s, uint16_t cpus_count) 119b061f059SPaolo Bonzini { 120b061f059SPaolo Bonzini MC146818RtcState *rtc = MC146818_RTC(s); 121b061f059SPaolo Bonzini 122b061f059SPaolo Bonzini if (cpus_count > 0xff) { 123b061f059SPaolo Bonzini /* 124b061f059SPaolo Bonzini * If the number of CPUs can't be represented in 8 bits, the 125b061f059SPaolo Bonzini * BIOS must use "FW_CFG_NB_CPUS". Set RTC field to 0 just 126b061f059SPaolo Bonzini * to make old BIOSes fail more predictably. 127b061f059SPaolo Bonzini */ 128b061f059SPaolo Bonzini mc146818rtc_set_cmos_data(rtc, 0x5f, 0); 129b061f059SPaolo Bonzini } else { 130b061f059SPaolo Bonzini mc146818rtc_set_cmos_data(rtc, 0x5f, cpus_count - 1); 131b061f059SPaolo Bonzini } 132b061f059SPaolo Bonzini } 133b061f059SPaolo Bonzini 134b061f059SPaolo Bonzini static int x86_apic_cmp(const void *a, const void *b) 135b061f059SPaolo Bonzini { 136b061f059SPaolo Bonzini CPUArchId *apic_a = (CPUArchId *)a; 137b061f059SPaolo Bonzini CPUArchId *apic_b = (CPUArchId *)b; 138b061f059SPaolo Bonzini 139b061f059SPaolo Bonzini return apic_a->arch_id - apic_b->arch_id; 140b061f059SPaolo Bonzini } 141b061f059SPaolo Bonzini 142b061f059SPaolo Bonzini /* 143b061f059SPaolo Bonzini * returns pointer to CPUArchId descriptor that matches CPU's apic_id 144b061f059SPaolo Bonzini * in ms->possible_cpus->cpus, if ms->possible_cpus->cpus has no 145b061f059SPaolo Bonzini * entry corresponding to CPU's apic_id returns NULL. 146b061f059SPaolo Bonzini */ 147b061f059SPaolo Bonzini static CPUArchId *x86_find_cpu_slot(MachineState *ms, uint32_t id, int *idx) 148b061f059SPaolo Bonzini { 149b061f059SPaolo Bonzini CPUArchId apic_id, *found_cpu; 150b061f059SPaolo Bonzini 151b061f059SPaolo Bonzini apic_id.arch_id = id; 152b061f059SPaolo Bonzini found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus, 153b061f059SPaolo Bonzini ms->possible_cpus->len, sizeof(*ms->possible_cpus->cpus), 154b061f059SPaolo Bonzini x86_apic_cmp); 155b061f059SPaolo Bonzini if (found_cpu && idx) { 156b061f059SPaolo Bonzini *idx = found_cpu - ms->possible_cpus->cpus; 157b061f059SPaolo Bonzini } 158b061f059SPaolo Bonzini return found_cpu; 159b061f059SPaolo Bonzini } 160b061f059SPaolo Bonzini 161b061f059SPaolo Bonzini void x86_cpu_plug(HotplugHandler *hotplug_dev, 162b061f059SPaolo Bonzini DeviceState *dev, Error **errp) 163b061f059SPaolo Bonzini { 164b061f059SPaolo Bonzini CPUArchId *found_cpu; 165b061f059SPaolo Bonzini Error *local_err = NULL; 166b061f059SPaolo Bonzini X86CPU *cpu = X86_CPU(dev); 167b061f059SPaolo Bonzini X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 168b061f059SPaolo Bonzini 169b061f059SPaolo Bonzini if (x86ms->acpi_dev) { 170b061f059SPaolo Bonzini hotplug_handler_plug(x86ms->acpi_dev, dev, &local_err); 171b061f059SPaolo Bonzini if (local_err) { 172b061f059SPaolo Bonzini goto out; 173b061f059SPaolo Bonzini } 174b061f059SPaolo Bonzini } 175b061f059SPaolo Bonzini 176b061f059SPaolo Bonzini /* increment the number of CPUs */ 177b061f059SPaolo Bonzini x86ms->boot_cpus++; 178b061f059SPaolo Bonzini if (x86ms->rtc) { 179b061f059SPaolo Bonzini x86_rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus); 180b061f059SPaolo Bonzini } 181b061f059SPaolo Bonzini if (x86ms->fw_cfg) { 182b061f059SPaolo Bonzini fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); 183b061f059SPaolo Bonzini } 184b061f059SPaolo Bonzini 185b061f059SPaolo Bonzini found_cpu = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, NULL); 186b061f059SPaolo Bonzini found_cpu->cpu = CPU(dev); 187b061f059SPaolo Bonzini out: 188b061f059SPaolo Bonzini error_propagate(errp, local_err); 189b061f059SPaolo Bonzini } 190b061f059SPaolo Bonzini 191b061f059SPaolo Bonzini void x86_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, 192b061f059SPaolo Bonzini DeviceState *dev, Error **errp) 193b061f059SPaolo Bonzini { 194b061f059SPaolo Bonzini int idx = -1; 195b061f059SPaolo Bonzini X86CPU *cpu = X86_CPU(dev); 196b061f059SPaolo Bonzini X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 197b061f059SPaolo Bonzini 198b061f059SPaolo Bonzini if (!x86ms->acpi_dev) { 199b061f059SPaolo Bonzini error_setg(errp, "CPU hot unplug not supported without ACPI"); 200b061f059SPaolo Bonzini return; 201b061f059SPaolo Bonzini } 202b061f059SPaolo Bonzini 203b061f059SPaolo Bonzini x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, &idx); 204b061f059SPaolo Bonzini assert(idx != -1); 205b061f059SPaolo Bonzini if (idx == 0) { 206b061f059SPaolo Bonzini error_setg(errp, "Boot CPU is unpluggable"); 207b061f059SPaolo Bonzini return; 208b061f059SPaolo Bonzini } 209b061f059SPaolo Bonzini 210b061f059SPaolo Bonzini hotplug_handler_unplug_request(x86ms->acpi_dev, dev, 211b061f059SPaolo Bonzini errp); 212b061f059SPaolo Bonzini } 213b061f059SPaolo Bonzini 214b061f059SPaolo Bonzini void x86_cpu_unplug_cb(HotplugHandler *hotplug_dev, 215b061f059SPaolo Bonzini DeviceState *dev, Error **errp) 216b061f059SPaolo Bonzini { 217b061f059SPaolo Bonzini CPUArchId *found_cpu; 218b061f059SPaolo Bonzini Error *local_err = NULL; 219b061f059SPaolo Bonzini X86CPU *cpu = X86_CPU(dev); 220b061f059SPaolo Bonzini X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 221b061f059SPaolo Bonzini 222b061f059SPaolo Bonzini hotplug_handler_unplug(x86ms->acpi_dev, dev, &local_err); 223b061f059SPaolo Bonzini if (local_err) { 224b061f059SPaolo Bonzini goto out; 225b061f059SPaolo Bonzini } 226b061f059SPaolo Bonzini 227b061f059SPaolo Bonzini found_cpu = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, NULL); 228b061f059SPaolo Bonzini found_cpu->cpu = NULL; 229b061f059SPaolo Bonzini qdev_unrealize(dev); 230b061f059SPaolo Bonzini 231b061f059SPaolo Bonzini /* decrement the number of CPUs */ 232b061f059SPaolo Bonzini x86ms->boot_cpus--; 233b061f059SPaolo Bonzini /* Update the number of CPUs in CMOS */ 234b061f059SPaolo Bonzini x86_rtc_set_cpus_count(x86ms->rtc, x86ms->boot_cpus); 235b061f059SPaolo Bonzini fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); 236b061f059SPaolo Bonzini out: 237b061f059SPaolo Bonzini error_propagate(errp, local_err); 238b061f059SPaolo Bonzini } 239b061f059SPaolo Bonzini 240b061f059SPaolo Bonzini void x86_cpu_pre_plug(HotplugHandler *hotplug_dev, 241b061f059SPaolo Bonzini DeviceState *dev, Error **errp) 242b061f059SPaolo Bonzini { 243b061f059SPaolo Bonzini int idx; 244b061f059SPaolo Bonzini CPUState *cs; 245b061f059SPaolo Bonzini CPUArchId *cpu_slot; 246b061f059SPaolo Bonzini X86CPUTopoIDs topo_ids; 247b061f059SPaolo Bonzini X86CPU *cpu = X86_CPU(dev); 248b061f059SPaolo Bonzini CPUX86State *env = &cpu->env; 249b061f059SPaolo Bonzini MachineState *ms = MACHINE(hotplug_dev); 250b061f059SPaolo Bonzini X86MachineState *x86ms = X86_MACHINE(hotplug_dev); 251b061f059SPaolo Bonzini unsigned int smp_cores = ms->smp.cores; 252b061f059SPaolo Bonzini unsigned int smp_threads = ms->smp.threads; 253b061f059SPaolo Bonzini X86CPUTopoInfo topo_info; 254b061f059SPaolo Bonzini 255b061f059SPaolo Bonzini if (!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) { 256b061f059SPaolo Bonzini error_setg(errp, "Invalid CPU type, expected cpu type: '%s'", 257b061f059SPaolo Bonzini ms->cpu_type); 258b061f059SPaolo Bonzini return; 259b061f059SPaolo Bonzini } 260b061f059SPaolo Bonzini 261b061f059SPaolo Bonzini if (x86ms->acpi_dev) { 262b061f059SPaolo Bonzini Error *local_err = NULL; 263b061f059SPaolo Bonzini 264b061f059SPaolo Bonzini hotplug_handler_pre_plug(HOTPLUG_HANDLER(x86ms->acpi_dev), dev, 265b061f059SPaolo Bonzini &local_err); 266b061f059SPaolo Bonzini if (local_err) { 267b061f059SPaolo Bonzini error_propagate(errp, local_err); 268b061f059SPaolo Bonzini return; 269b061f059SPaolo Bonzini } 270b061f059SPaolo Bonzini } 271b061f059SPaolo Bonzini 272b061f059SPaolo Bonzini init_topo_info(&topo_info, x86ms); 273b061f059SPaolo Bonzini 27481c392abSZhao Liu if (ms->smp.modules > 1) { 27581c392abSZhao Liu env->nr_modules = ms->smp.modules; 2765304873aSZhao Liu set_bit(CPU_TOPO_LEVEL_MODULE, env->avail_cpu_topo); 27781c392abSZhao Liu } 27881c392abSZhao Liu 2796ddeb0ecSZhao Liu if (ms->smp.dies > 1) { 280b061f059SPaolo Bonzini env->nr_dies = ms->smp.dies; 2816ddeb0ecSZhao Liu set_bit(CPU_TOPO_LEVEL_DIE, env->avail_cpu_topo); 2826ddeb0ecSZhao Liu } 283b061f059SPaolo Bonzini 284b061f059SPaolo Bonzini /* 285b061f059SPaolo Bonzini * If APIC ID is not set, 286*b17a26bcSZhao Liu * set it based on socket/die/module/core/thread properties. 287b061f059SPaolo Bonzini */ 288b061f059SPaolo Bonzini if (cpu->apic_id == UNASSIGNED_APIC_ID) { 289b061f059SPaolo Bonzini /* 290b061f059SPaolo Bonzini * die-id was optional in QEMU 4.0 and older, so keep it optional 291b061f059SPaolo Bonzini * if there's only one die per socket. 292b061f059SPaolo Bonzini */ 293b061f059SPaolo Bonzini if (cpu->die_id < 0 && ms->smp.dies == 1) { 294b061f059SPaolo Bonzini cpu->die_id = 0; 295b061f059SPaolo Bonzini } 296b061f059SPaolo Bonzini 297b061f059SPaolo Bonzini if (cpu->socket_id < 0) { 298b061f059SPaolo Bonzini error_setg(errp, "CPU socket-id is not set"); 299b061f059SPaolo Bonzini return; 300*b17a26bcSZhao Liu } else if (cpu->socket_id > ms->smp.sockets - 1) { 301b061f059SPaolo Bonzini error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u", 302*b17a26bcSZhao Liu cpu->socket_id, ms->smp.sockets - 1); 303b061f059SPaolo Bonzini return; 304b061f059SPaolo Bonzini } 305b061f059SPaolo Bonzini if (cpu->die_id < 0) { 306b061f059SPaolo Bonzini error_setg(errp, "CPU die-id is not set"); 307b061f059SPaolo Bonzini return; 308b061f059SPaolo Bonzini } else if (cpu->die_id > ms->smp.dies - 1) { 309b061f059SPaolo Bonzini error_setg(errp, "Invalid CPU die-id: %u must be in range 0:%u", 310b061f059SPaolo Bonzini cpu->die_id, ms->smp.dies - 1); 311b061f059SPaolo Bonzini return; 312b061f059SPaolo Bonzini } 313b061f059SPaolo Bonzini if (cpu->core_id < 0) { 314b061f059SPaolo Bonzini error_setg(errp, "CPU core-id is not set"); 315b061f059SPaolo Bonzini return; 316b061f059SPaolo Bonzini } else if (cpu->core_id > (smp_cores - 1)) { 317b061f059SPaolo Bonzini error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u", 318b061f059SPaolo Bonzini cpu->core_id, smp_cores - 1); 319b061f059SPaolo Bonzini return; 320b061f059SPaolo Bonzini } 321b061f059SPaolo Bonzini if (cpu->thread_id < 0) { 322b061f059SPaolo Bonzini error_setg(errp, "CPU thread-id is not set"); 323b061f059SPaolo Bonzini return; 324b061f059SPaolo Bonzini } else if (cpu->thread_id > (smp_threads - 1)) { 325b061f059SPaolo Bonzini error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u", 326b061f059SPaolo Bonzini cpu->thread_id, smp_threads - 1); 327b061f059SPaolo Bonzini return; 328b061f059SPaolo Bonzini } 329b061f059SPaolo Bonzini 330b061f059SPaolo Bonzini topo_ids.pkg_id = cpu->socket_id; 331b061f059SPaolo Bonzini topo_ids.die_id = cpu->die_id; 332b061f059SPaolo Bonzini topo_ids.core_id = cpu->core_id; 333b061f059SPaolo Bonzini topo_ids.smt_id = cpu->thread_id; 334*b17a26bcSZhao Liu 335*b17a26bcSZhao Liu /* 336*b17a26bcSZhao Liu * TODO: This is the temporary initialization for topo_ids.module_id to 337*b17a26bcSZhao Liu * avoid "maybe-uninitialized" compilation errors. Will remove when 338*b17a26bcSZhao Liu * X86CPU supports module_id. 339*b17a26bcSZhao Liu */ 340*b17a26bcSZhao Liu topo_ids.module_id = 0; 341*b17a26bcSZhao Liu 342b061f059SPaolo Bonzini cpu->apic_id = x86_apicid_from_topo_ids(&topo_info, &topo_ids); 343b061f059SPaolo Bonzini } 344b061f059SPaolo Bonzini 345b061f059SPaolo Bonzini cpu_slot = x86_find_cpu_slot(MACHINE(x86ms), cpu->apic_id, &idx); 346b061f059SPaolo Bonzini if (!cpu_slot) { 347b061f059SPaolo Bonzini x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); 348*b17a26bcSZhao Liu 349b061f059SPaolo Bonzini error_setg(errp, 350*b17a26bcSZhao Liu "Invalid CPU [socket: %u, die: %u, module: %u, core: %u, thread: %u]" 351*b17a26bcSZhao Liu " with APIC ID %" PRIu32 ", valid index range 0:%d", 352*b17a26bcSZhao Liu topo_ids.pkg_id, topo_ids.die_id, topo_ids.module_id, 353*b17a26bcSZhao Liu topo_ids.core_id, topo_ids.smt_id, cpu->apic_id, 354*b17a26bcSZhao Liu ms->possible_cpus->len - 1); 355b061f059SPaolo Bonzini return; 356b061f059SPaolo Bonzini } 357b061f059SPaolo Bonzini 358b061f059SPaolo Bonzini if (cpu_slot->cpu) { 359b061f059SPaolo Bonzini error_setg(errp, "CPU[%d] with APIC ID %" PRIu32 " exists", 360b061f059SPaolo Bonzini idx, cpu->apic_id); 361b061f059SPaolo Bonzini return; 362b061f059SPaolo Bonzini } 363b061f059SPaolo Bonzini 364b061f059SPaolo Bonzini /* if 'address' properties socket-id/core-id/thread-id are not set, set them 365b061f059SPaolo Bonzini * so that machine_query_hotpluggable_cpus would show correct values 366b061f059SPaolo Bonzini */ 367b061f059SPaolo Bonzini /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn() 368b061f059SPaolo Bonzini * once -smp refactoring is complete and there will be CPU private 369b061f059SPaolo Bonzini * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */ 370b061f059SPaolo Bonzini x86_topo_ids_from_apicid(cpu->apic_id, &topo_info, &topo_ids); 371b061f059SPaolo Bonzini if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) { 372b061f059SPaolo Bonzini error_setg(errp, "property socket-id: %u doesn't match set apic-id:" 373b061f059SPaolo Bonzini " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, 374b061f059SPaolo Bonzini topo_ids.pkg_id); 375b061f059SPaolo Bonzini return; 376b061f059SPaolo Bonzini } 377b061f059SPaolo Bonzini cpu->socket_id = topo_ids.pkg_id; 378b061f059SPaolo Bonzini 379b061f059SPaolo Bonzini if (cpu->die_id != -1 && cpu->die_id != topo_ids.die_id) { 380b061f059SPaolo Bonzini error_setg(errp, "property die-id: %u doesn't match set apic-id:" 381b061f059SPaolo Bonzini " 0x%x (die-id: %u)", cpu->die_id, cpu->apic_id, topo_ids.die_id); 382b061f059SPaolo Bonzini return; 383b061f059SPaolo Bonzini } 384b061f059SPaolo Bonzini cpu->die_id = topo_ids.die_id; 385b061f059SPaolo Bonzini 386b061f059SPaolo Bonzini if (cpu->core_id != -1 && cpu->core_id != topo_ids.core_id) { 387b061f059SPaolo Bonzini error_setg(errp, "property core-id: %u doesn't match set apic-id:" 388b061f059SPaolo Bonzini " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, 389b061f059SPaolo Bonzini topo_ids.core_id); 390b061f059SPaolo Bonzini return; 391b061f059SPaolo Bonzini } 392b061f059SPaolo Bonzini cpu->core_id = topo_ids.core_id; 393b061f059SPaolo Bonzini 394b061f059SPaolo Bonzini if (cpu->thread_id != -1 && cpu->thread_id != topo_ids.smt_id) { 395b061f059SPaolo Bonzini error_setg(errp, "property thread-id: %u doesn't match set apic-id:" 396b061f059SPaolo Bonzini " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, 397b061f059SPaolo Bonzini topo_ids.smt_id); 398b061f059SPaolo Bonzini return; 399b061f059SPaolo Bonzini } 400b061f059SPaolo Bonzini cpu->thread_id = topo_ids.smt_id; 401b061f059SPaolo Bonzini 402b061f059SPaolo Bonzini /* 403b061f059SPaolo Bonzini * kvm_enabled() must go first to ensure that kvm_* references are 404b061f059SPaolo Bonzini * not emitted for the linker to consume (kvm_enabled() is 405b061f059SPaolo Bonzini * a literal `0` in configurations where kvm_* aren't defined) 406b061f059SPaolo Bonzini */ 407b061f059SPaolo Bonzini if (kvm_enabled() && hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX) && 408b061f059SPaolo Bonzini !kvm_hv_vpindex_settable()) { 409b061f059SPaolo Bonzini error_setg(errp, "kernel doesn't allow setting HyperV VP_INDEX"); 410b061f059SPaolo Bonzini return; 411b061f059SPaolo Bonzini } 412b061f059SPaolo Bonzini 413b061f059SPaolo Bonzini cs = CPU(cpu); 414b061f059SPaolo Bonzini cs->cpu_index = idx; 415b061f059SPaolo Bonzini 416b061f059SPaolo Bonzini numa_cpu_pre_plug(cpu_slot, dev, errp); 417b061f059SPaolo Bonzini } 418b061f059SPaolo Bonzini 419b061f059SPaolo Bonzini static long get_file_size(FILE *f) 420b061f059SPaolo Bonzini { 421b061f059SPaolo Bonzini long where, size; 422b061f059SPaolo Bonzini 423b061f059SPaolo Bonzini /* XXX: on Unix systems, using fstat() probably makes more sense */ 424b061f059SPaolo Bonzini 425b061f059SPaolo Bonzini where = ftell(f); 426b061f059SPaolo Bonzini fseek(f, 0, SEEK_END); 427b061f059SPaolo Bonzini size = ftell(f); 428b061f059SPaolo Bonzini fseek(f, where, SEEK_SET); 429b061f059SPaolo Bonzini 430b061f059SPaolo Bonzini return size; 431b061f059SPaolo Bonzini } 432b061f059SPaolo Bonzini 433b061f059SPaolo Bonzini void gsi_handler(void *opaque, int n, int level) 434b061f059SPaolo Bonzini { 435b061f059SPaolo Bonzini GSIState *s = opaque; 436b061f059SPaolo Bonzini 437b061f059SPaolo Bonzini trace_x86_gsi_interrupt(n, level); 438b061f059SPaolo Bonzini switch (n) { 439b061f059SPaolo Bonzini case 0 ... ISA_NUM_IRQS - 1: 440b061f059SPaolo Bonzini if (s->i8259_irq[n]) { 441b061f059SPaolo Bonzini /* Under KVM, Kernel will forward to both PIC and IOAPIC */ 442b061f059SPaolo Bonzini qemu_set_irq(s->i8259_irq[n], level); 443b061f059SPaolo Bonzini } 444b061f059SPaolo Bonzini /* fall through */ 445b061f059SPaolo Bonzini case ISA_NUM_IRQS ... IOAPIC_NUM_PINS - 1: 446b061f059SPaolo Bonzini #ifdef CONFIG_XEN_EMU 447b061f059SPaolo Bonzini /* 448b061f059SPaolo Bonzini * Xen delivers the GSI to the Legacy PIC (not that Legacy PIC 449b061f059SPaolo Bonzini * routing actually works properly under Xen). And then to 450b061f059SPaolo Bonzini * *either* the PIRQ handling or the I/OAPIC depending on 451b061f059SPaolo Bonzini * whether the former wants it. 452b061f059SPaolo Bonzini */ 453b061f059SPaolo Bonzini if (xen_mode == XEN_EMULATE && xen_evtchn_set_gsi(n, level)) { 454b061f059SPaolo Bonzini break; 455b061f059SPaolo Bonzini } 456b061f059SPaolo Bonzini #endif 457b061f059SPaolo Bonzini qemu_set_irq(s->ioapic_irq[n], level); 458b061f059SPaolo Bonzini break; 459b061f059SPaolo Bonzini case IO_APIC_SECONDARY_IRQBASE 460b061f059SPaolo Bonzini ... IO_APIC_SECONDARY_IRQBASE + IOAPIC_NUM_PINS - 1: 461b061f059SPaolo Bonzini qemu_set_irq(s->ioapic2_irq[n - IO_APIC_SECONDARY_IRQBASE], level); 462b061f059SPaolo Bonzini break; 463b061f059SPaolo Bonzini } 464b061f059SPaolo Bonzini } 465b061f059SPaolo Bonzini 466b061f059SPaolo Bonzini void ioapic_init_gsi(GSIState *gsi_state, Object *parent) 467b061f059SPaolo Bonzini { 468b061f059SPaolo Bonzini DeviceState *dev; 469b061f059SPaolo Bonzini SysBusDevice *d; 470b061f059SPaolo Bonzini unsigned int i; 471b061f059SPaolo Bonzini 472b061f059SPaolo Bonzini assert(parent); 473b061f059SPaolo Bonzini if (kvm_ioapic_in_kernel()) { 474b061f059SPaolo Bonzini dev = qdev_new(TYPE_KVM_IOAPIC); 475b061f059SPaolo Bonzini } else { 476b061f059SPaolo Bonzini dev = qdev_new(TYPE_IOAPIC); 477b061f059SPaolo Bonzini } 478b061f059SPaolo Bonzini object_property_add_child(parent, "ioapic", OBJECT(dev)); 479b061f059SPaolo Bonzini d = SYS_BUS_DEVICE(dev); 480b061f059SPaolo Bonzini sysbus_realize_and_unref(d, &error_fatal); 481b061f059SPaolo Bonzini sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); 482b061f059SPaolo Bonzini 483b061f059SPaolo Bonzini for (i = 0; i < IOAPIC_NUM_PINS; i++) { 484b061f059SPaolo Bonzini gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); 485b061f059SPaolo Bonzini } 486b061f059SPaolo Bonzini } 487b061f059SPaolo Bonzini 488b061f059SPaolo Bonzini DeviceState *ioapic_init_secondary(GSIState *gsi_state) 489b061f059SPaolo Bonzini { 490b061f059SPaolo Bonzini DeviceState *dev; 491b061f059SPaolo Bonzini SysBusDevice *d; 492b061f059SPaolo Bonzini unsigned int i; 493b061f059SPaolo Bonzini 494b061f059SPaolo Bonzini dev = qdev_new(TYPE_IOAPIC); 495b061f059SPaolo Bonzini d = SYS_BUS_DEVICE(dev); 496b061f059SPaolo Bonzini sysbus_realize_and_unref(d, &error_fatal); 497b061f059SPaolo Bonzini sysbus_mmio_map(d, 0, IO_APIC_SECONDARY_ADDRESS); 498b061f059SPaolo Bonzini 499b061f059SPaolo Bonzini for (i = 0; i < IOAPIC_NUM_PINS; i++) { 500b061f059SPaolo Bonzini gsi_state->ioapic2_irq[i] = qdev_get_gpio_in(dev, i); 501b061f059SPaolo Bonzini } 502b061f059SPaolo Bonzini return dev; 503b061f059SPaolo Bonzini } 504b061f059SPaolo Bonzini 505b061f059SPaolo Bonzini /* 506b061f059SPaolo Bonzini * The entry point into the kernel for PVH boot is different from 507b061f059SPaolo Bonzini * the native entry point. The PVH entry is defined by the x86/HVM 508b061f059SPaolo Bonzini * direct boot ABI and is available in an ELFNOTE in the kernel binary. 509b061f059SPaolo Bonzini * 510b061f059SPaolo Bonzini * This function is passed to load_elf() when it is called from 511b061f059SPaolo Bonzini * load_elfboot() which then additionally checks for an ELF Note of 512b061f059SPaolo Bonzini * type XEN_ELFNOTE_PHYS32_ENTRY and passes it to this function to 513b061f059SPaolo Bonzini * parse the PVH entry address from the ELF Note. 514b061f059SPaolo Bonzini * 515b061f059SPaolo Bonzini * Due to trickery in elf_opts.h, load_elf() is actually available as 516b061f059SPaolo Bonzini * load_elf32() or load_elf64() and this routine needs to be able 517b061f059SPaolo Bonzini * to deal with being called as 32 or 64 bit. 518b061f059SPaolo Bonzini * 519b061f059SPaolo Bonzini * The address of the PVH entry point is saved to the 'pvh_start_addr' 520b061f059SPaolo Bonzini * global variable. (although the entry point is 32-bit, the kernel 521b061f059SPaolo Bonzini * binary can be either 32-bit or 64-bit). 522b061f059SPaolo Bonzini */ 523b061f059SPaolo Bonzini static uint64_t read_pvh_start_addr(void *arg1, void *arg2, bool is64) 524b061f059SPaolo Bonzini { 525b061f059SPaolo Bonzini size_t *elf_note_data_addr; 526b061f059SPaolo Bonzini 527b061f059SPaolo Bonzini /* Check if ELF Note header passed in is valid */ 528b061f059SPaolo Bonzini if (arg1 == NULL) { 529b061f059SPaolo Bonzini return 0; 530b061f059SPaolo Bonzini } 531b061f059SPaolo Bonzini 532b061f059SPaolo Bonzini if (is64) { 533b061f059SPaolo Bonzini struct elf64_note *nhdr64 = (struct elf64_note *)arg1; 534b061f059SPaolo Bonzini uint64_t nhdr_size64 = sizeof(struct elf64_note); 535b061f059SPaolo Bonzini uint64_t phdr_align = *(uint64_t *)arg2; 536b061f059SPaolo Bonzini uint64_t nhdr_namesz = nhdr64->n_namesz; 537b061f059SPaolo Bonzini 538b061f059SPaolo Bonzini elf_note_data_addr = 539b061f059SPaolo Bonzini ((void *)nhdr64) + nhdr_size64 + 540b061f059SPaolo Bonzini QEMU_ALIGN_UP(nhdr_namesz, phdr_align); 541b061f059SPaolo Bonzini 542b061f059SPaolo Bonzini pvh_start_addr = *elf_note_data_addr; 543b061f059SPaolo Bonzini } else { 544b061f059SPaolo Bonzini struct elf32_note *nhdr32 = (struct elf32_note *)arg1; 545b061f059SPaolo Bonzini uint32_t nhdr_size32 = sizeof(struct elf32_note); 546b061f059SPaolo Bonzini uint32_t phdr_align = *(uint32_t *)arg2; 547b061f059SPaolo Bonzini uint32_t nhdr_namesz = nhdr32->n_namesz; 548b061f059SPaolo Bonzini 549b061f059SPaolo Bonzini elf_note_data_addr = 550b061f059SPaolo Bonzini ((void *)nhdr32) + nhdr_size32 + 551b061f059SPaolo Bonzini QEMU_ALIGN_UP(nhdr_namesz, phdr_align); 552b061f059SPaolo Bonzini 553b061f059SPaolo Bonzini pvh_start_addr = *(uint32_t *)elf_note_data_addr; 554b061f059SPaolo Bonzini } 555b061f059SPaolo Bonzini 556b061f059SPaolo Bonzini return pvh_start_addr; 557b061f059SPaolo Bonzini } 558b061f059SPaolo Bonzini 559b061f059SPaolo Bonzini static bool load_elfboot(const char *kernel_filename, 560b061f059SPaolo Bonzini int kernel_file_size, 561b061f059SPaolo Bonzini uint8_t *header, 562b061f059SPaolo Bonzini size_t pvh_xen_start_addr, 563b061f059SPaolo Bonzini FWCfgState *fw_cfg) 564b061f059SPaolo Bonzini { 565b061f059SPaolo Bonzini uint32_t flags = 0; 566b061f059SPaolo Bonzini uint32_t mh_load_addr = 0; 567b061f059SPaolo Bonzini uint32_t elf_kernel_size = 0; 568b061f059SPaolo Bonzini uint64_t elf_entry; 569b061f059SPaolo Bonzini uint64_t elf_low, elf_high; 570b061f059SPaolo Bonzini int kernel_size; 571b061f059SPaolo Bonzini 572b061f059SPaolo Bonzini if (ldl_p(header) != 0x464c457f) { 573b061f059SPaolo Bonzini return false; /* no elfboot */ 574b061f059SPaolo Bonzini } 575b061f059SPaolo Bonzini 576b061f059SPaolo Bonzini bool elf_is64 = header[EI_CLASS] == ELFCLASS64; 577b061f059SPaolo Bonzini flags = elf_is64 ? 578b061f059SPaolo Bonzini ((Elf64_Ehdr *)header)->e_flags : ((Elf32_Ehdr *)header)->e_flags; 579b061f059SPaolo Bonzini 580b061f059SPaolo Bonzini if (flags & 0x00010004) { /* LOAD_ELF_HEADER_HAS_ADDR */ 581b061f059SPaolo Bonzini error_report("elfboot unsupported flags = %x", flags); 582b061f059SPaolo Bonzini exit(1); 583b061f059SPaolo Bonzini } 584b061f059SPaolo Bonzini 585b061f059SPaolo Bonzini uint64_t elf_note_type = XEN_ELFNOTE_PHYS32_ENTRY; 586b061f059SPaolo Bonzini kernel_size = load_elf(kernel_filename, read_pvh_start_addr, 587b061f059SPaolo Bonzini NULL, &elf_note_type, &elf_entry, 588b061f059SPaolo Bonzini &elf_low, &elf_high, NULL, 0, I386_ELF_MACHINE, 589b061f059SPaolo Bonzini 0, 0); 590b061f059SPaolo Bonzini 591b061f059SPaolo Bonzini if (kernel_size < 0) { 592b061f059SPaolo Bonzini error_report("Error while loading elf kernel"); 593b061f059SPaolo Bonzini exit(1); 594b061f059SPaolo Bonzini } 595b061f059SPaolo Bonzini mh_load_addr = elf_low; 596b061f059SPaolo Bonzini elf_kernel_size = elf_high - elf_low; 597b061f059SPaolo Bonzini 598b061f059SPaolo Bonzini if (pvh_start_addr == 0) { 599b061f059SPaolo Bonzini error_report("Error loading uncompressed kernel without PVH ELF Note"); 600b061f059SPaolo Bonzini exit(1); 601b061f059SPaolo Bonzini } 602b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, pvh_start_addr); 603b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, mh_load_addr); 604b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, elf_kernel_size); 605b061f059SPaolo Bonzini 606b061f059SPaolo Bonzini return true; 607b061f059SPaolo Bonzini } 608b061f059SPaolo Bonzini 609b061f059SPaolo Bonzini void x86_load_linux(X86MachineState *x86ms, 610b061f059SPaolo Bonzini FWCfgState *fw_cfg, 611b061f059SPaolo Bonzini int acpi_data_size, 612b061f059SPaolo Bonzini bool pvh_enabled) 613b061f059SPaolo Bonzini { 614b061f059SPaolo Bonzini bool linuxboot_dma_enabled = X86_MACHINE_GET_CLASS(x86ms)->fwcfg_dma_enabled; 615b061f059SPaolo Bonzini uint16_t protocol; 616b061f059SPaolo Bonzini int setup_size, kernel_size, cmdline_size; 617b061f059SPaolo Bonzini int dtb_size, setup_data_offset; 618b061f059SPaolo Bonzini uint32_t initrd_max; 619b061f059SPaolo Bonzini uint8_t header[8192], *setup, *kernel; 620b061f059SPaolo Bonzini hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0; 621b061f059SPaolo Bonzini FILE *f; 622b061f059SPaolo Bonzini char *vmode; 623b061f059SPaolo Bonzini MachineState *machine = MACHINE(x86ms); 624b061f059SPaolo Bonzini struct setup_data *setup_data; 625b061f059SPaolo Bonzini const char *kernel_filename = machine->kernel_filename; 626b061f059SPaolo Bonzini const char *initrd_filename = machine->initrd_filename; 627b061f059SPaolo Bonzini const char *dtb_filename = machine->dtb; 628b061f059SPaolo Bonzini const char *kernel_cmdline = machine->kernel_cmdline; 629b061f059SPaolo Bonzini SevKernelLoaderContext sev_load_ctx = {}; 630b061f059SPaolo Bonzini 631b061f059SPaolo Bonzini /* Align to 16 bytes as a paranoia measure */ 632b061f059SPaolo Bonzini cmdline_size = (strlen(kernel_cmdline) + 16) & ~15; 633b061f059SPaolo Bonzini 634b061f059SPaolo Bonzini /* load the kernel header */ 635b061f059SPaolo Bonzini f = fopen(kernel_filename, "rb"); 636b061f059SPaolo Bonzini if (!f) { 637b061f059SPaolo Bonzini fprintf(stderr, "qemu: could not open kernel file '%s': %s\n", 638b061f059SPaolo Bonzini kernel_filename, strerror(errno)); 639b061f059SPaolo Bonzini exit(1); 640b061f059SPaolo Bonzini } 641b061f059SPaolo Bonzini 642b061f059SPaolo Bonzini kernel_size = get_file_size(f); 643b061f059SPaolo Bonzini if (!kernel_size || 644b061f059SPaolo Bonzini fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != 645b061f059SPaolo Bonzini MIN(ARRAY_SIZE(header), kernel_size)) { 646b061f059SPaolo Bonzini fprintf(stderr, "qemu: could not load kernel '%s': %s\n", 647b061f059SPaolo Bonzini kernel_filename, strerror(errno)); 648b061f059SPaolo Bonzini exit(1); 649b061f059SPaolo Bonzini } 650b061f059SPaolo Bonzini 651b061f059SPaolo Bonzini /* kernel protocol version */ 652b061f059SPaolo Bonzini if (ldl_p(header + 0x202) == 0x53726448) { 653b061f059SPaolo Bonzini protocol = lduw_p(header + 0x206); 654b061f059SPaolo Bonzini } else { 655b061f059SPaolo Bonzini /* 656b061f059SPaolo Bonzini * This could be a multiboot kernel. If it is, let's stop treating it 657b061f059SPaolo Bonzini * like a Linux kernel. 658b061f059SPaolo Bonzini * Note: some multiboot images could be in the ELF format (the same of 659b061f059SPaolo Bonzini * PVH), so we try multiboot first since we check the multiboot magic 660b061f059SPaolo Bonzini * header before to load it. 661b061f059SPaolo Bonzini */ 662b061f059SPaolo Bonzini if (load_multiboot(x86ms, fw_cfg, f, kernel_filename, initrd_filename, 663b061f059SPaolo Bonzini kernel_cmdline, kernel_size, header)) { 664b061f059SPaolo Bonzini return; 665b061f059SPaolo Bonzini } 666b061f059SPaolo Bonzini /* 667b061f059SPaolo Bonzini * Check if the file is an uncompressed kernel file (ELF) and load it, 668b061f059SPaolo Bonzini * saving the PVH entry point used by the x86/HVM direct boot ABI. 669b061f059SPaolo Bonzini * If load_elfboot() is successful, populate the fw_cfg info. 670b061f059SPaolo Bonzini */ 671b061f059SPaolo Bonzini if (pvh_enabled && 672b061f059SPaolo Bonzini load_elfboot(kernel_filename, kernel_size, 673b061f059SPaolo Bonzini header, pvh_start_addr, fw_cfg)) { 674b061f059SPaolo Bonzini fclose(f); 675b061f059SPaolo Bonzini 676b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 677b061f059SPaolo Bonzini strlen(kernel_cmdline) + 1); 678b061f059SPaolo Bonzini fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); 679b061f059SPaolo Bonzini 680b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, sizeof(header)); 681b061f059SPaolo Bonzini fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, 682b061f059SPaolo Bonzini header, sizeof(header)); 683b061f059SPaolo Bonzini 684b061f059SPaolo Bonzini /* load initrd */ 685b061f059SPaolo Bonzini if (initrd_filename) { 686b061f059SPaolo Bonzini GMappedFile *mapped_file; 687b061f059SPaolo Bonzini gsize initrd_size; 688b061f059SPaolo Bonzini gchar *initrd_data; 689b061f059SPaolo Bonzini GError *gerr = NULL; 690b061f059SPaolo Bonzini 691b061f059SPaolo Bonzini mapped_file = g_mapped_file_new(initrd_filename, false, &gerr); 692b061f059SPaolo Bonzini if (!mapped_file) { 693b061f059SPaolo Bonzini fprintf(stderr, "qemu: error reading initrd %s: %s\n", 694b061f059SPaolo Bonzini initrd_filename, gerr->message); 695b061f059SPaolo Bonzini exit(1); 696b061f059SPaolo Bonzini } 697b061f059SPaolo Bonzini x86ms->initrd_mapped_file = mapped_file; 698b061f059SPaolo Bonzini 699b061f059SPaolo Bonzini initrd_data = g_mapped_file_get_contents(mapped_file); 700b061f059SPaolo Bonzini initrd_size = g_mapped_file_get_length(mapped_file); 701b061f059SPaolo Bonzini initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1; 702b061f059SPaolo Bonzini if (initrd_size >= initrd_max) { 703b061f059SPaolo Bonzini fprintf(stderr, "qemu: initrd is too large, cannot support." 704b061f059SPaolo Bonzini "(max: %"PRIu32", need %"PRId64")\n", 705b061f059SPaolo Bonzini initrd_max, (uint64_t)initrd_size); 706b061f059SPaolo Bonzini exit(1); 707b061f059SPaolo Bonzini } 708b061f059SPaolo Bonzini 709b061f059SPaolo Bonzini initrd_addr = (initrd_max - initrd_size) & ~4095; 710b061f059SPaolo Bonzini 711b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); 712b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 713b061f059SPaolo Bonzini fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, 714b061f059SPaolo Bonzini initrd_size); 715b061f059SPaolo Bonzini } 716b061f059SPaolo Bonzini 717b061f059SPaolo Bonzini option_rom[nb_option_roms].bootindex = 0; 718b061f059SPaolo Bonzini option_rom[nb_option_roms].name = "pvh.bin"; 719b061f059SPaolo Bonzini nb_option_roms++; 720b061f059SPaolo Bonzini 721b061f059SPaolo Bonzini return; 722b061f059SPaolo Bonzini } 723b061f059SPaolo Bonzini protocol = 0; 724b061f059SPaolo Bonzini } 725b061f059SPaolo Bonzini 726b061f059SPaolo Bonzini if (protocol < 0x200 || !(header[0x211] & 0x01)) { 727b061f059SPaolo Bonzini /* Low kernel */ 728b061f059SPaolo Bonzini real_addr = 0x90000; 729b061f059SPaolo Bonzini cmdline_addr = 0x9a000 - cmdline_size; 730b061f059SPaolo Bonzini prot_addr = 0x10000; 731b061f059SPaolo Bonzini } else if (protocol < 0x202) { 732b061f059SPaolo Bonzini /* High but ancient kernel */ 733b061f059SPaolo Bonzini real_addr = 0x90000; 734b061f059SPaolo Bonzini cmdline_addr = 0x9a000 - cmdline_size; 735b061f059SPaolo Bonzini prot_addr = 0x100000; 736b061f059SPaolo Bonzini } else { 737b061f059SPaolo Bonzini /* High and recent kernel */ 738b061f059SPaolo Bonzini real_addr = 0x10000; 739b061f059SPaolo Bonzini cmdline_addr = 0x20000; 740b061f059SPaolo Bonzini prot_addr = 0x100000; 741b061f059SPaolo Bonzini } 742b061f059SPaolo Bonzini 743b061f059SPaolo Bonzini /* highest address for loading the initrd */ 744b061f059SPaolo Bonzini if (protocol >= 0x20c && 745b061f059SPaolo Bonzini lduw_p(header + 0x236) & XLF_CAN_BE_LOADED_ABOVE_4G) { 746b061f059SPaolo Bonzini /* 747b061f059SPaolo Bonzini * Linux has supported initrd up to 4 GB for a very long time (2007, 748b061f059SPaolo Bonzini * long before XLF_CAN_BE_LOADED_ABOVE_4G which was added in 2013), 749b061f059SPaolo Bonzini * though it only sets initrd_max to 2 GB to "work around bootloader 750b061f059SPaolo Bonzini * bugs". Luckily, QEMU firmware(which does something like bootloader) 751b061f059SPaolo Bonzini * has supported this. 752b061f059SPaolo Bonzini * 753b061f059SPaolo Bonzini * It's believed that if XLF_CAN_BE_LOADED_ABOVE_4G is set, initrd can 754b061f059SPaolo Bonzini * be loaded into any address. 755b061f059SPaolo Bonzini * 756b061f059SPaolo Bonzini * In addition, initrd_max is uint32_t simply because QEMU doesn't 757b061f059SPaolo Bonzini * support the 64-bit boot protocol (specifically the ext_ramdisk_image 758b061f059SPaolo Bonzini * field). 759b061f059SPaolo Bonzini * 760b061f059SPaolo Bonzini * Therefore here just limit initrd_max to UINT32_MAX simply as well. 761b061f059SPaolo Bonzini */ 762b061f059SPaolo Bonzini initrd_max = UINT32_MAX; 763b061f059SPaolo Bonzini } else if (protocol >= 0x203) { 764b061f059SPaolo Bonzini initrd_max = ldl_p(header + 0x22c); 765b061f059SPaolo Bonzini } else { 766b061f059SPaolo Bonzini initrd_max = 0x37ffffff; 767b061f059SPaolo Bonzini } 768b061f059SPaolo Bonzini 769b061f059SPaolo Bonzini if (initrd_max >= x86ms->below_4g_mem_size - acpi_data_size) { 770b061f059SPaolo Bonzini initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1; 771b061f059SPaolo Bonzini } 772b061f059SPaolo Bonzini 773b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr); 774b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline) + 1); 775b061f059SPaolo Bonzini fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline); 776b061f059SPaolo Bonzini sev_load_ctx.cmdline_data = (char *)kernel_cmdline; 777b061f059SPaolo Bonzini sev_load_ctx.cmdline_size = strlen(kernel_cmdline) + 1; 778b061f059SPaolo Bonzini 779b061f059SPaolo Bonzini if (protocol >= 0x202) { 780b061f059SPaolo Bonzini stl_p(header + 0x228, cmdline_addr); 781b061f059SPaolo Bonzini } else { 782b061f059SPaolo Bonzini stw_p(header + 0x20, 0xA33F); 783b061f059SPaolo Bonzini stw_p(header + 0x22, cmdline_addr - real_addr); 784b061f059SPaolo Bonzini } 785b061f059SPaolo Bonzini 786b061f059SPaolo Bonzini /* handle vga= parameter */ 787b061f059SPaolo Bonzini vmode = strstr(kernel_cmdline, "vga="); 788b061f059SPaolo Bonzini if (vmode) { 789b061f059SPaolo Bonzini unsigned int video_mode; 790b061f059SPaolo Bonzini const char *end; 791b061f059SPaolo Bonzini int ret; 792b061f059SPaolo Bonzini /* skip "vga=" */ 793b061f059SPaolo Bonzini vmode += 4; 794b061f059SPaolo Bonzini if (!strncmp(vmode, "normal", 6)) { 795b061f059SPaolo Bonzini video_mode = 0xffff; 796b061f059SPaolo Bonzini } else if (!strncmp(vmode, "ext", 3)) { 797b061f059SPaolo Bonzini video_mode = 0xfffe; 798b061f059SPaolo Bonzini } else if (!strncmp(vmode, "ask", 3)) { 799b061f059SPaolo Bonzini video_mode = 0xfffd; 800b061f059SPaolo Bonzini } else { 801b061f059SPaolo Bonzini ret = qemu_strtoui(vmode, &end, 0, &video_mode); 802b061f059SPaolo Bonzini if (ret != 0 || (*end && *end != ' ')) { 803b061f059SPaolo Bonzini fprintf(stderr, "qemu: invalid 'vga=' kernel parameter.\n"); 804b061f059SPaolo Bonzini exit(1); 805b061f059SPaolo Bonzini } 806b061f059SPaolo Bonzini } 807b061f059SPaolo Bonzini stw_p(header + 0x1fa, video_mode); 808b061f059SPaolo Bonzini } 809b061f059SPaolo Bonzini 810b061f059SPaolo Bonzini /* loader type */ 811b061f059SPaolo Bonzini /* 812b061f059SPaolo Bonzini * High nybble = B reserved for QEMU; low nybble is revision number. 813b061f059SPaolo Bonzini * If this code is substantially changed, you may want to consider 814b061f059SPaolo Bonzini * incrementing the revision. 815b061f059SPaolo Bonzini */ 816b061f059SPaolo Bonzini if (protocol >= 0x200) { 817b061f059SPaolo Bonzini header[0x210] = 0xB0; 818b061f059SPaolo Bonzini } 819b061f059SPaolo Bonzini /* heap */ 820b061f059SPaolo Bonzini if (protocol >= 0x201) { 821b061f059SPaolo Bonzini header[0x211] |= 0x80; /* CAN_USE_HEAP */ 822b061f059SPaolo Bonzini stw_p(header + 0x224, cmdline_addr - real_addr - 0x200); 823b061f059SPaolo Bonzini } 824b061f059SPaolo Bonzini 825b061f059SPaolo Bonzini /* load initrd */ 826b061f059SPaolo Bonzini if (initrd_filename) { 827b061f059SPaolo Bonzini GMappedFile *mapped_file; 828b061f059SPaolo Bonzini gsize initrd_size; 829b061f059SPaolo Bonzini gchar *initrd_data; 830b061f059SPaolo Bonzini GError *gerr = NULL; 831b061f059SPaolo Bonzini 832b061f059SPaolo Bonzini if (protocol < 0x200) { 833b061f059SPaolo Bonzini fprintf(stderr, "qemu: linux kernel too old to load a ram disk\n"); 834b061f059SPaolo Bonzini exit(1); 835b061f059SPaolo Bonzini } 836b061f059SPaolo Bonzini 837b061f059SPaolo Bonzini mapped_file = g_mapped_file_new(initrd_filename, false, &gerr); 838b061f059SPaolo Bonzini if (!mapped_file) { 839b061f059SPaolo Bonzini fprintf(stderr, "qemu: error reading initrd %s: %s\n", 840b061f059SPaolo Bonzini initrd_filename, gerr->message); 841b061f059SPaolo Bonzini exit(1); 842b061f059SPaolo Bonzini } 843b061f059SPaolo Bonzini x86ms->initrd_mapped_file = mapped_file; 844b061f059SPaolo Bonzini 845b061f059SPaolo Bonzini initrd_data = g_mapped_file_get_contents(mapped_file); 846b061f059SPaolo Bonzini initrd_size = g_mapped_file_get_length(mapped_file); 847b061f059SPaolo Bonzini if (initrd_size >= initrd_max) { 848b061f059SPaolo Bonzini fprintf(stderr, "qemu: initrd is too large, cannot support." 849b061f059SPaolo Bonzini "(max: %"PRIu32", need %"PRId64")\n", 850b061f059SPaolo Bonzini initrd_max, (uint64_t)initrd_size); 851b061f059SPaolo Bonzini exit(1); 852b061f059SPaolo Bonzini } 853b061f059SPaolo Bonzini 854b061f059SPaolo Bonzini initrd_addr = (initrd_max - initrd_size) & ~4095; 855b061f059SPaolo Bonzini 856b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); 857b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); 858b061f059SPaolo Bonzini fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size); 859b061f059SPaolo Bonzini sev_load_ctx.initrd_data = initrd_data; 860b061f059SPaolo Bonzini sev_load_ctx.initrd_size = initrd_size; 861b061f059SPaolo Bonzini 862b061f059SPaolo Bonzini stl_p(header + 0x218, initrd_addr); 863b061f059SPaolo Bonzini stl_p(header + 0x21c, initrd_size); 864b061f059SPaolo Bonzini } 865b061f059SPaolo Bonzini 866b061f059SPaolo Bonzini /* load kernel and setup */ 867b061f059SPaolo Bonzini setup_size = header[0x1f1]; 868b061f059SPaolo Bonzini if (setup_size == 0) { 869b061f059SPaolo Bonzini setup_size = 4; 870b061f059SPaolo Bonzini } 871b061f059SPaolo Bonzini setup_size = (setup_size + 1) * 512; 872b061f059SPaolo Bonzini if (setup_size > kernel_size) { 873b061f059SPaolo Bonzini fprintf(stderr, "qemu: invalid kernel header\n"); 874b061f059SPaolo Bonzini exit(1); 875b061f059SPaolo Bonzini } 876b061f059SPaolo Bonzini kernel_size -= setup_size; 877b061f059SPaolo Bonzini 878b061f059SPaolo Bonzini setup = g_malloc(setup_size); 879b061f059SPaolo Bonzini kernel = g_malloc(kernel_size); 880b061f059SPaolo Bonzini fseek(f, 0, SEEK_SET); 881b061f059SPaolo Bonzini if (fread(setup, 1, setup_size, f) != setup_size) { 882b061f059SPaolo Bonzini fprintf(stderr, "fread() failed\n"); 883b061f059SPaolo Bonzini exit(1); 884b061f059SPaolo Bonzini } 885b061f059SPaolo Bonzini if (fread(kernel, 1, kernel_size, f) != kernel_size) { 886b061f059SPaolo Bonzini fprintf(stderr, "fread() failed\n"); 887b061f059SPaolo Bonzini exit(1); 888b061f059SPaolo Bonzini } 889b061f059SPaolo Bonzini fclose(f); 890b061f059SPaolo Bonzini 891b061f059SPaolo Bonzini /* append dtb to kernel */ 892b061f059SPaolo Bonzini if (dtb_filename) { 893b061f059SPaolo Bonzini if (protocol < 0x209) { 894b061f059SPaolo Bonzini fprintf(stderr, "qemu: Linux kernel too old to load a dtb\n"); 895b061f059SPaolo Bonzini exit(1); 896b061f059SPaolo Bonzini } 897b061f059SPaolo Bonzini 898b061f059SPaolo Bonzini dtb_size = get_image_size(dtb_filename); 899b061f059SPaolo Bonzini if (dtb_size <= 0) { 900b061f059SPaolo Bonzini fprintf(stderr, "qemu: error reading dtb %s: %s\n", 901b061f059SPaolo Bonzini dtb_filename, strerror(errno)); 902b061f059SPaolo Bonzini exit(1); 903b061f059SPaolo Bonzini } 904b061f059SPaolo Bonzini 905b061f059SPaolo Bonzini setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16); 906b061f059SPaolo Bonzini kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size; 907b061f059SPaolo Bonzini kernel = g_realloc(kernel, kernel_size); 908b061f059SPaolo Bonzini 909b061f059SPaolo Bonzini stq_p(header + 0x250, prot_addr + setup_data_offset); 910b061f059SPaolo Bonzini 911b061f059SPaolo Bonzini setup_data = (struct setup_data *)(kernel + setup_data_offset); 912b061f059SPaolo Bonzini setup_data->next = 0; 913b061f059SPaolo Bonzini setup_data->type = cpu_to_le32(SETUP_DTB); 914b061f059SPaolo Bonzini setup_data->len = cpu_to_le32(dtb_size); 915b061f059SPaolo Bonzini 916b061f059SPaolo Bonzini load_image_size(dtb_filename, setup_data->data, dtb_size); 917b061f059SPaolo Bonzini } 918b061f059SPaolo Bonzini 919b061f059SPaolo Bonzini /* 920b061f059SPaolo Bonzini * If we're starting an encrypted VM, it will be OVMF based, which uses the 921b061f059SPaolo Bonzini * efi stub for booting and doesn't require any values to be placed in the 922b061f059SPaolo Bonzini * kernel header. We therefore don't update the header so the hash of the 923b061f059SPaolo Bonzini * kernel on the other side of the fw_cfg interface matches the hash of the 924b061f059SPaolo Bonzini * file the user passed in. 925b061f059SPaolo Bonzini */ 926b061f059SPaolo Bonzini if (!sev_enabled()) { 927b061f059SPaolo Bonzini memcpy(setup, header, MIN(sizeof(header), setup_size)); 928b061f059SPaolo Bonzini } 929b061f059SPaolo Bonzini 930b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr); 931b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); 932b061f059SPaolo Bonzini fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size); 933b061f059SPaolo Bonzini sev_load_ctx.kernel_data = (char *)kernel; 934b061f059SPaolo Bonzini sev_load_ctx.kernel_size = kernel_size; 935b061f059SPaolo Bonzini 936b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr); 937b061f059SPaolo Bonzini fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size); 938b061f059SPaolo Bonzini fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size); 939b061f059SPaolo Bonzini sev_load_ctx.setup_data = (char *)setup; 940b061f059SPaolo Bonzini sev_load_ctx.setup_size = setup_size; 941b061f059SPaolo Bonzini 942b061f059SPaolo Bonzini if (sev_enabled()) { 943b061f059SPaolo Bonzini sev_add_kernel_loader_hashes(&sev_load_ctx, &error_fatal); 944b061f059SPaolo Bonzini } 945b061f059SPaolo Bonzini 946b061f059SPaolo Bonzini option_rom[nb_option_roms].bootindex = 0; 947b061f059SPaolo Bonzini option_rom[nb_option_roms].name = "linuxboot.bin"; 948b061f059SPaolo Bonzini if (linuxboot_dma_enabled && fw_cfg_dma_enabled(fw_cfg)) { 949b061f059SPaolo Bonzini option_rom[nb_option_roms].name = "linuxboot_dma.bin"; 950b061f059SPaolo Bonzini } 951b061f059SPaolo Bonzini nb_option_roms++; 952b061f059SPaolo Bonzini } 953b061f059SPaolo Bonzini 954b061f059SPaolo Bonzini void x86_isa_bios_init(MemoryRegion *isa_bios, MemoryRegion *isa_memory, 955b061f059SPaolo Bonzini MemoryRegion *bios, bool read_only) 956b061f059SPaolo Bonzini { 957b061f059SPaolo Bonzini uint64_t bios_size = memory_region_size(bios); 958b061f059SPaolo Bonzini uint64_t isa_bios_size = MIN(bios_size, 128 * KiB); 959b061f059SPaolo Bonzini 960b061f059SPaolo Bonzini memory_region_init_alias(isa_bios, NULL, "isa-bios", bios, 961b061f059SPaolo Bonzini bios_size - isa_bios_size, isa_bios_size); 962b061f059SPaolo Bonzini memory_region_add_subregion_overlap(isa_memory, 1 * MiB - isa_bios_size, 963b061f059SPaolo Bonzini isa_bios, 1); 964b061f059SPaolo Bonzini memory_region_set_readonly(isa_bios, read_only); 965b061f059SPaolo Bonzini } 966b061f059SPaolo Bonzini 967b061f059SPaolo Bonzini void x86_bios_rom_init(X86MachineState *x86ms, const char *default_firmware, 968b061f059SPaolo Bonzini MemoryRegion *rom_memory, bool isapc_ram_fw) 969b061f059SPaolo Bonzini { 970b061f059SPaolo Bonzini const char *bios_name; 971b061f059SPaolo Bonzini char *filename; 972b061f059SPaolo Bonzini int bios_size; 973b061f059SPaolo Bonzini ssize_t ret; 974b061f059SPaolo Bonzini 975b061f059SPaolo Bonzini /* BIOS load */ 976b061f059SPaolo Bonzini bios_name = MACHINE(x86ms)->firmware ?: default_firmware; 977b061f059SPaolo Bonzini filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 978b061f059SPaolo Bonzini if (filename) { 979b061f059SPaolo Bonzini bios_size = get_image_size(filename); 980b061f059SPaolo Bonzini } else { 981b061f059SPaolo Bonzini bios_size = -1; 982b061f059SPaolo Bonzini } 983b061f059SPaolo Bonzini if (bios_size <= 0 || 984b061f059SPaolo Bonzini (bios_size % 65536) != 0) { 985b061f059SPaolo Bonzini goto bios_error; 986b061f059SPaolo Bonzini } 987b061f059SPaolo Bonzini memory_region_init_ram(&x86ms->bios, NULL, "pc.bios", bios_size, 988b061f059SPaolo Bonzini &error_fatal); 989b061f059SPaolo Bonzini if (sev_enabled()) { 990b061f059SPaolo Bonzini /* 991b061f059SPaolo Bonzini * The concept of a "reset" simply doesn't exist for 992b061f059SPaolo Bonzini * confidential computing guests, we have to destroy and 993b061f059SPaolo Bonzini * re-launch them instead. So there is no need to register 994b061f059SPaolo Bonzini * the firmware as rom to properly re-initialize on reset. 995b061f059SPaolo Bonzini * Just go for a straight file load instead. 996b061f059SPaolo Bonzini */ 997b061f059SPaolo Bonzini void *ptr = memory_region_get_ram_ptr(&x86ms->bios); 998b061f059SPaolo Bonzini load_image_size(filename, ptr, bios_size); 999b061f059SPaolo Bonzini x86_firmware_configure(ptr, bios_size); 1000b061f059SPaolo Bonzini } else { 1001b061f059SPaolo Bonzini memory_region_set_readonly(&x86ms->bios, !isapc_ram_fw); 1002b061f059SPaolo Bonzini ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1); 1003b061f059SPaolo Bonzini if (ret != 0) { 1004b061f059SPaolo Bonzini goto bios_error; 1005b061f059SPaolo Bonzini } 1006b061f059SPaolo Bonzini } 1007b061f059SPaolo Bonzini g_free(filename); 1008b061f059SPaolo Bonzini 1009b061f059SPaolo Bonzini /* map the last 128KB of the BIOS in ISA space */ 1010b061f059SPaolo Bonzini x86_isa_bios_init(&x86ms->isa_bios, rom_memory, &x86ms->bios, 1011b061f059SPaolo Bonzini !isapc_ram_fw); 1012b061f059SPaolo Bonzini 1013b061f059SPaolo Bonzini /* map all the bios at the top of memory */ 1014b061f059SPaolo Bonzini memory_region_add_subregion(rom_memory, 1015b061f059SPaolo Bonzini (uint32_t)(-bios_size), 1016b061f059SPaolo Bonzini &x86ms->bios); 1017b061f059SPaolo Bonzini return; 1018b061f059SPaolo Bonzini 1019b061f059SPaolo Bonzini bios_error: 1020b061f059SPaolo Bonzini fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name); 1021b061f059SPaolo Bonzini exit(1); 1022b061f059SPaolo Bonzini } 1023