hw/i386: make x86.c independent from PCMachineState

As a last step into splitting PCMachineState and deriving
X86MachineState from it, make the functions previously extracted from
pc.c to x86.c independent from PCMachineState, using X86MachineState
instead.

Signed-off-by: Sergio Lopez <slp@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Sergio Lopez 2019-09-30 17:26:29 +02:00 committed by Paolo Bonzini
parent f0bb276bf8
commit 703a548aa9
5 changed files with 44 additions and 40 deletions

View file

@ -983,8 +983,8 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts)
void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp) void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp)
{ {
PCMachineState *pcms = PC_MACHINE(ms); X86MachineState *x86ms = X86_MACHINE(ms);
int64_t apic_id = x86_cpu_apic_id_from_index(pcms, id); int64_t apic_id = x86_cpu_apic_id_from_index(x86ms, id);
Error *local_err = NULL; Error *local_err = NULL;
if (id < 0) { if (id < 0) {
@ -999,7 +999,8 @@ void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp)
return; return;
} }
x86_cpu_new(PC_MACHINE(ms), apic_id, &local_err);
x86_cpu_new(X86_MACHINE(ms), apic_id, &local_err);
if (local_err) { if (local_err) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
return; return;
@ -1100,6 +1101,7 @@ void xen_load_linux(PCMachineState *pcms)
{ {
int i; int i;
FWCfgState *fw_cfg; FWCfgState *fw_cfg;
PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
X86MachineState *x86ms = X86_MACHINE(pcms); X86MachineState *x86ms = X86_MACHINE(pcms);
assert(MACHINE(pcms)->kernel_filename != NULL); assert(MACHINE(pcms)->kernel_filename != NULL);
@ -1108,7 +1110,8 @@ void xen_load_linux(PCMachineState *pcms)
fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus);
rom_set_fw(fw_cfg); rom_set_fw(fw_cfg);
x86_load_linux(pcms, fw_cfg); x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
pcmc->pvh_enabled, pcmc->linuxboot_dma_enabled);
for (i = 0; i < nb_option_roms; i++) { for (i = 0; i < nb_option_roms; i++) {
assert(!strcmp(option_rom[i].name, "linuxboot.bin") || assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
!strcmp(option_rom[i].name, "linuxboot_dma.bin") || !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@ -1244,7 +1247,8 @@ void pc_memory_init(PCMachineState *pcms,
} }
if (linux_boot) { if (linux_boot) {
x86_load_linux(pcms, fw_cfg); x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
pcmc->pvh_enabled, pcmc->linuxboot_dma_enabled);
} }
for (i = 0; i < nb_option_roms; i++) { for (i = 0; i < nb_option_roms; i++) {

View file

@ -154,7 +154,7 @@ static void pc_init1(MachineState *machine,
} }
} }
x86_cpus_init(pcms); x86_cpus_init(x86ms, pcmc->default_cpu_version);
if (kvm_enabled() && pcmc->kvmclock_enabled) { if (kvm_enabled() && pcmc->kvmclock_enabled) {
kvmclock_create(); kvmclock_create();

View file

@ -181,7 +181,7 @@ static void pc_q35_init(MachineState *machine)
xen_hvm_init(pcms, &ram_memory); xen_hvm_init(pcms, &ram_memory);
} }
x86_cpus_init(pcms); x86_cpus_init(x86ms, pcmc->default_cpu_version);
kvmclock_create(); kvmclock_create();

View file

@ -36,7 +36,6 @@
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"
#include "hw/i386/x86.h" #include "hw/i386/x86.h"
#include "hw/i386/pc.h"
#include "target/i386/cpu.h" #include "target/i386/cpu.h"
#include "hw/i386/topology.h" #include "hw/i386/topology.h"
#include "hw/i386/fw_cfg.h" #include "hw/i386/fw_cfg.h"
@ -61,11 +60,10 @@ static size_t pvh_start_addr;
* no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of * no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
* all CPUs up to max_cpus. * all CPUs up to max_cpus.
*/ */
uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
unsigned int cpu_index) unsigned int cpu_index)
{ {
MachineState *ms = MACHINE(pcms); MachineState *ms = MACHINE(x86ms);
X86MachineState *x86ms = X86_MACHINE(pcms);
X86MachineClass *x86mc = X86_MACHINE_GET_CLASS(x86ms); X86MachineClass *x86mc = X86_MACHINE_GET_CLASS(x86ms);
uint32_t correct_id; uint32_t correct_id;
static bool warned; static bool warned;
@ -84,14 +82,14 @@ uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms,
} }
} }
void x86_cpu_new(PCMachineState *pcms, int64_t apic_id, Error **errp)
void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)
{ {
Object *cpu = NULL; Object *cpu = NULL;
Error *local_err = NULL; Error *local_err = NULL;
CPUX86State *env = NULL; CPUX86State *env = NULL;
X86MachineState *x86ms = X86_MACHINE(pcms);
cpu = object_new(MACHINE(pcms)->cpu_type); cpu = object_new(MACHINE(x86ms)->cpu_type);
env = &X86_CPU(cpu)->env; env = &X86_CPU(cpu)->env;
env->nr_dies = x86ms->smp_dies; env->nr_dies = x86ms->smp_dies;
@ -103,30 +101,28 @@ void x86_cpu_new(PCMachineState *pcms, int64_t apic_id, Error **errp)
error_propagate(errp, local_err); error_propagate(errp, local_err);
} }
void x86_cpus_init(PCMachineState *pcms) void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
{ {
int i; int i;
const CPUArchIdList *possible_cpus; const CPUArchIdList *possible_cpus;
MachineState *ms = MACHINE(pcms); MachineState *ms = MACHINE(x86ms);
MachineClass *mc = MACHINE_GET_CLASS(pcms); MachineClass *mc = MACHINE_GET_CLASS(x86ms);
PCMachineClass *pcmc = PC_MACHINE_CLASS(mc);
X86MachineState *x86ms = X86_MACHINE(pcms);
x86_cpu_set_default_version(pcmc->default_cpu_version); x86_cpu_set_default_version(default_cpu_version);
/* /*
* Calculates the limit to CPU APIC ID values * Calculates the limit to CPU APIC ID values
* *
* Limit for the APIC ID value, so that all * Limit for the APIC ID value, so that all
* CPU APIC IDs are < pcms->apic_id_limit. * CPU APIC IDs are < x86ms->apic_id_limit.
* *
* This is used for FW_CFG_MAX_CPUS. See comments on fw_cfg_arch_create(). * This is used for FW_CFG_MAX_CPUS. See comments on fw_cfg_arch_create().
*/ */
x86ms->apic_id_limit = x86_cpu_apic_id_from_index(pcms, x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms,
ms->smp.max_cpus - 1) + 1; ms->smp.max_cpus - 1) + 1;
possible_cpus = mc->possible_cpu_arch_ids(ms); possible_cpus = mc->possible_cpu_arch_ids(ms);
for (i = 0; i < ms->smp.cpus; i++) { for (i = 0; i < ms->smp.cpus; i++) {
x86_cpu_new(pcms, possible_cpus->cpus[i].arch_id, &error_fatal); x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal);
} }
} }
@ -154,7 +150,6 @@ int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx)
const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
{ {
PCMachineState *pcms = PC_MACHINE(ms);
X86MachineState *x86ms = X86_MACHINE(ms); X86MachineState *x86ms = X86_MACHINE(ms);
int i; int i;
unsigned int max_cpus = ms->smp.max_cpus; unsigned int max_cpus = ms->smp.max_cpus;
@ -177,7 +172,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
ms->possible_cpus->cpus[i].type = ms->cpu_type; ms->possible_cpus->cpus[i].type = ms->cpu_type;
ms->possible_cpus->cpus[i].vcpus_count = 1; ms->possible_cpus->cpus[i].vcpus_count = 1;
ms->possible_cpus->cpus[i].arch_id = ms->possible_cpus->cpus[i].arch_id =
x86_cpu_apic_id_from_index(pcms, i); x86_cpu_apic_id_from_index(x86ms, i);
x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id, x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id,
x86ms->smp_dies, ms->smp.cores, x86ms->smp_dies, ms->smp.cores,
ms->smp.threads, &topo); ms->smp.threads, &topo);
@ -335,8 +330,11 @@ static bool load_elfboot(const char *kernel_filename,
return true; return true;
} }
void x86_load_linux(PCMachineState *pcms, void x86_load_linux(X86MachineState *x86ms,
FWCfgState *fw_cfg) FWCfgState *fw_cfg,
int acpi_data_size,
bool pvh_enabled,
bool linuxboot_dma_enabled)
{ {
uint16_t protocol; uint16_t protocol;
int setup_size, kernel_size, cmdline_size; int setup_size, kernel_size, cmdline_size;
@ -346,9 +344,7 @@ void x86_load_linux(PCMachineState *pcms,
hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0; hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
FILE *f; FILE *f;
char *vmode; char *vmode;
MachineState *machine = MACHINE(pcms); MachineState *machine = MACHINE(x86ms);
PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
X86MachineState *x86ms = X86_MACHINE(pcms);
struct setup_data *setup_data; struct setup_data *setup_data;
const char *kernel_filename = machine->kernel_filename; const char *kernel_filename = machine->kernel_filename;
const char *initrd_filename = machine->initrd_filename; const char *initrd_filename = machine->initrd_filename;
@ -395,7 +391,7 @@ void x86_load_linux(PCMachineState *pcms,
* saving the PVH entry point used by the x86/HVM direct boot ABI. * saving the PVH entry point used by the x86/HVM direct boot ABI.
* If load_elfboot() is successful, populate the fw_cfg info. * If load_elfboot() is successful, populate the fw_cfg info.
*/ */
if (pcmc->pvh_enabled && if (pvh_enabled &&
load_elfboot(kernel_filename, kernel_size, load_elfboot(kernel_filename, kernel_size,
header, pvh_start_addr, fw_cfg)) { header, pvh_start_addr, fw_cfg)) {
fclose(f); fclose(f);
@ -425,8 +421,7 @@ void x86_load_linux(PCMachineState *pcms,
initrd_data = g_mapped_file_get_contents(mapped_file); initrd_data = g_mapped_file_get_contents(mapped_file);
initrd_size = g_mapped_file_get_length(mapped_file); initrd_size = g_mapped_file_get_length(mapped_file);
initrd_max = initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1;
x86ms->below_4g_mem_size - pcmc->acpi_data_size - 1;
if (initrd_size >= initrd_max) { if (initrd_size >= initrd_max) {
fprintf(stderr, "qemu: initrd is too large, cannot support." fprintf(stderr, "qemu: initrd is too large, cannot support."
"(max: %"PRIu32", need %"PRId64")\n", "(max: %"PRIu32", need %"PRId64")\n",
@ -494,8 +489,8 @@ void x86_load_linux(PCMachineState *pcms,
initrd_max = 0x37ffffff; initrd_max = 0x37ffffff;
} }
if (initrd_max >= x86ms->below_4g_mem_size - pcmc->acpi_data_size) { if (initrd_max >= x86ms->below_4g_mem_size - acpi_data_size) {
initrd_max = x86ms->below_4g_mem_size - pcmc->acpi_data_size - 1; initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1;
} }
fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr); fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
@ -652,7 +647,7 @@ void x86_load_linux(PCMachineState *pcms,
option_rom[nb_option_roms].bootindex = 0; option_rom[nb_option_roms].bootindex = 0;
option_rom[nb_option_roms].name = "linuxboot.bin"; option_rom[nb_option_roms].name = "linuxboot.bin";
if (pcmc->linuxboot_dma_enabled && fw_cfg_dma_enabled(fw_cfg)) { if (linuxboot_dma_enabled && fw_cfg_dma_enabled(fw_cfg)) {
option_rom[nb_option_roms].name = "linuxboot_dma.bin"; option_rom[nb_option_roms].name = "linuxboot_dma.bin";
} }
nb_option_roms++; nb_option_roms++;

View file

@ -75,10 +75,11 @@ typedef struct {
#define X86_MACHINE_CLASS(class) \ #define X86_MACHINE_CLASS(class) \
OBJECT_CLASS_CHECK(X86MachineClass, class, TYPE_X86_MACHINE) OBJECT_CLASS_CHECK(X86MachineClass, class, TYPE_X86_MACHINE)
uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, uint32_t x86_cpu_apic_id_from_index(X86MachineState *pcms,
unsigned int cpu_index); unsigned int cpu_index);
void x86_cpu_new(PCMachineState *pcms, int64_t apic_id, Error **errp);
void x86_cpus_init(PCMachineState *pcms); void x86_cpu_new(X86MachineState *pcms, int64_t apic_id, Error **errp);
void x86_cpus_init(X86MachineState *pcms, int default_cpu_version);
CpuInstanceProperties x86_cpu_index_to_props(MachineState *ms, CpuInstanceProperties x86_cpu_index_to_props(MachineState *ms,
unsigned cpu_index); unsigned cpu_index);
int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx); int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx);
@ -86,6 +87,10 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms);
void x86_bios_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw); void x86_bios_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw);
void x86_load_linux(PCMachineState *pcms, FWCfgState *fw_cfg); void x86_load_linux(X86MachineState *x86ms,
FWCfgState *fw_cfg,
int acpi_data_size,
bool pvh_enabled,
bool linuxboot_dma_enabled);
#endif #endif