From nobody Mon Feb 9 14:50:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571928418; cv=none; d=zoho.com; s=zohoarc; b=Tz7Fs+AaiY/dsgpyoAMHUkN6K/NRb9CvkhYS7PsFGs4dGYgNRl2aQdgmRiRt35G/BeKHHYC2QUF/YSjYgmBsVxexUDFFy35wgRW25KotmZSk1UWmrAT/f7KPqaL4LFkOriD5wiXMH6oUMiwxUvHKwQVeA/UPeuY3hc4UoOmsYgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571928418; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9Asy+EBJ1/DDN/7vzodpurF+OtN2EzDDhF7AXA5N1ZU=; b=FxYxggnhhFnKH/3ZFzYqH18XgQBsAOj4icsGQakyoDDQE+WibYSw/IEnh4WT+vZqmB1pwKLfuobs/L/5DXTn8qI7JZ0sDxaNvbOA6qnUPaRp0CeHGBSbAhQMxWDrr8PSP2SmOD5XNTglndk2xBHI5VIlQdYNQYQok2U0l1EOUkI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571928418016451.9880258232182; Thu, 24 Oct 2019 07:46:58 -0700 (PDT) Received: from localhost ([::1]:44520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNeO6-00079A-S2 for importer@patchew.org; Thu, 24 Oct 2019 10:46:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34773) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNdiw-0007mu-1C for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNdit-0007is-GZ for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:21 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:34394) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNdir-0007hO-PM for qemu-devel@nongnu.org; Thu, 24 Oct 2019 10:04:19 -0400 Received: by mail-wm1-x32a.google.com with SMTP id v3so2078072wmh.1 for ; Thu, 24 Oct 2019 07:04:16 -0700 (PDT) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id b7sm10610155wrn.53.2019.10.24.07.04.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Oct 2019 07:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Asy+EBJ1/DDN/7vzodpurF+OtN2EzDDhF7AXA5N1ZU=; b=KqpXAxEm7FMlXeqQ7esGju6LSVeHa78VE6YIJ9h/PEo7gXgObC/LtqALuVCTCeVkvl lApQF5n1W2mCQXm7L6kAS3zqxFONRQtuLlJFm9MB6/06Xog8hGRwlpDav6vkWRsBORlY hkPUP90YiIh+ikvdVcSGBDantabrAsk1eWhKJa9Ap+vni6cgjbxC+OCxcAz40n4PviNc pDXSflpoJyu2CZPjJUiGb3UCPj/XkfecAfckq/agJYCnyaMU3nT0dUwMXX7m4/oySU9k IbDaQpoKGz0tcVTO+x9NrJTq+pUT78scSyGWkmYh1w/9Bn/QpKAb+9ynet2B/xfPV/K6 wXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9Asy+EBJ1/DDN/7vzodpurF+OtN2EzDDhF7AXA5N1ZU=; b=V03N/kuFxPQA1ijxoFhJN3H0gad7B5cSEM8TBlSSnsjc8TI/TaTixd/LONEaQBi43T nQrAy1w3wVeI2WRQzbB0ktAc05RtNbFEv7EkvbiBSyTR5DSe4hHais0MFTOqzgDl2lzd tFcn90OWw3RTwSfrFKWsavlWV7h+SBL1PD8rNGxVOoPZFac2wvAMcWIMnTO0I95WxDLK K80Raqy96EswKwNGlEWmVvaUgt7izEfPe6JfIdD1CVrFqVpRumzjR4CjY3MIfDYHD63v afUtR7wGkNB8xycknhItGhvyZLt4is6HpqZqbb7C6aaRYStnqUwXBotD7dJZsnryfka3 bTVA== X-Gm-Message-State: APjAAAX61NHHcuQN0wkfw2UFIeTyIwxd+E/KEfkvCD3GEw+U2vhznHRd ycUytgBBn+wny1IfUgJLLC+77C6j X-Google-Smtp-Source: APXvYqyFZy3ZxxlDbhW5MvHqmghTkfOvqVwAxSEWgrV3L/n7+wFYQaS1JZKugaI7qCyWP6HRWBFz7g== X-Received: by 2002:a1c:9ec6:: with SMTP id h189mr4817182wme.71.1571925854459; Thu, 24 Oct 2019 07:04:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 15/39] hw/i386: make x86.c independent from PCMachineState Date: Thu, 24 Oct 2019 16:03:31 +0200 Message-Id: <1571925835-31930-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571925835-31930-1-git-send-email-pbonzini@redhat.com> References: <1571925835-31930-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32a X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sergio Lopez Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Sergio Lopez 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 Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Michael S. Tsirkin --- hw/i386/pc.c | 14 +++++++++----- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/i386/x86.c | 53 +++++++++++++++++++++++------------------------= ---- include/hw/i386/x86.h | 13 +++++++++---- 5 files changed, 44 insertions(+), 40 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e6ad1f1..a8888dd 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -983,8 +983,8 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) =20 void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp) { - PCMachineState *pcms =3D PC_MACHINE(ms); - int64_t apic_id =3D x86_cpu_apic_id_from_index(pcms, id); + X86MachineState *x86ms =3D X86_MACHINE(ms); + int64_t apic_id =3D x86_cpu_apic_id_from_index(x86ms, id); Error *local_err =3D NULL; =20 if (id < 0) { @@ -999,7 +999,8 @@ void pc_hot_add_cpu(MachineState *ms, const int64_t id,= Error **errp) return; } =20 - x86_cpu_new(PC_MACHINE(ms), apic_id, &local_err); + + x86_cpu_new(X86_MACHINE(ms), apic_id, &local_err); if (local_err) { error_propagate(errp, local_err); return; @@ -1100,6 +1101,7 @@ void xen_load_linux(PCMachineState *pcms) { int i; FWCfgState *fw_cfg; + PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); X86MachineState *x86ms =3D X86_MACHINE(pcms); =20 assert(MACHINE(pcms)->kernel_filename !=3D NULL); @@ -1108,7 +1110,8 @@ void xen_load_linux(PCMachineState *pcms) fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); rom_set_fw(fw_cfg); =20 - 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 =3D 0; i < nb_option_roms; i++) { assert(!strcmp(option_rom[i].name, "linuxboot.bin") || !strcmp(option_rom[i].name, "linuxboot_dma.bin") || @@ -1244,7 +1247,8 @@ void pc_memory_init(PCMachineState *pcms, } =20 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); } =20 for (i =3D 0; i < nb_option_roms; i++) { diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 0afa8fe..a86317c 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -154,7 +154,7 @@ static void pc_init1(MachineState *machine, } } =20 - x86_cpus_init(pcms); + x86_cpus_init(x86ms, pcmc->default_cpu_version); =20 if (kvm_enabled() && pcmc->kvmclock_enabled) { kvmclock_create(); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 374ac6c..75c8caf 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -181,7 +181,7 @@ static void pc_q35_init(MachineState *machine) xen_hvm_init(pcms, &ram_memory); } =20 - x86_cpus_init(pcms); + x86_cpus_init(x86ms, pcmc->default_cpu_version); =20 kvmclock_create(); =20 diff --git a/hw/i386/x86.c b/hw/i386/x86.c index de4fed0..fd84b23 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -36,7 +36,6 @@ #include "sysemu/sysemu.h" =20 #include "hw/i386/x86.h" -#include "hw/i386/pc.h" #include "target/i386/cpu.h" #include "hw/i386/topology.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 * 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) { - MachineState *ms =3D MACHINE(pcms); - X86MachineState *x86ms =3D X86_MACHINE(pcms); + MachineState *ms =3D MACHINE(x86ms); X86MachineClass *x86mc =3D X86_MACHINE_GET_CLASS(x86ms); uint32_t correct_id; static bool warned; @@ -84,14 +82,14 @@ uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcm= s, } } =20 -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 =3D NULL; Error *local_err =3D NULL; CPUX86State *env =3D NULL; - X86MachineState *x86ms =3D X86_MACHINE(pcms); =20 - cpu =3D object_new(MACHINE(pcms)->cpu_type); + cpu =3D object_new(MACHINE(x86ms)->cpu_type); =20 env =3D &X86_CPU(cpu)->env; env->nr_dies =3D x86ms->smp_dies; @@ -103,30 +101,28 @@ void x86_cpu_new(PCMachineState *pcms, int64_t apic_i= d, Error **errp) error_propagate(errp, local_err); } =20 -void x86_cpus_init(PCMachineState *pcms) +void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) { int i; const CPUArchIdList *possible_cpus; - MachineState *ms =3D MACHINE(pcms); - MachineClass *mc =3D MACHINE_GET_CLASS(pcms); - PCMachineClass *pcmc =3D PC_MACHINE_CLASS(mc); - X86MachineState *x86ms =3D X86_MACHINE(pcms); + MachineState *ms =3D MACHINE(x86ms); + MachineClass *mc =3D MACHINE_GET_CLASS(x86ms); =20 - x86_cpu_set_default_version(pcmc->default_cpu_version); + x86_cpu_set_default_version(default_cpu_version); =20 /* * Calculates the limit to CPU APIC ID values * * 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_creat= e(). */ - x86ms->apic_id_limit =3D x86_cpu_apic_id_from_index(pcms, + x86ms->apic_id_limit =3D x86_cpu_apic_id_from_index(x86ms, ms->smp.max_cpus - 1= ) + 1; possible_cpus =3D mc->possible_cpu_arch_ids(ms); for (i =3D 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); } } =20 @@ -154,7 +150,6 @@ int64_t x86_get_default_cpu_node_id(const MachineState = *ms, int idx) =20 const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms) { - PCMachineState *pcms =3D PC_MACHINE(ms); X86MachineState *x86ms =3D X86_MACHINE(ms); int i; unsigned int max_cpus =3D ms->smp.max_cpus; @@ -177,7 +172,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineS= tate *ms) ms->possible_cpus->cpus[i].type =3D ms->cpu_type; ms->possible_cpus->cpus[i].vcpus_count =3D 1; ms->possible_cpus->cpus[i].arch_id =3D - 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, x86ms->smp_dies, ms->smp.cores, ms->smp.threads, &topo); @@ -335,8 +330,11 @@ static bool load_elfboot(const char *kernel_filename, return true; } =20 -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) { uint16_t protocol; 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 =3D 0; FILE *f; char *vmode; - MachineState *machine =3D MACHINE(pcms); - PCMachineClass *pcmc =3D PC_MACHINE_GET_CLASS(pcms); - X86MachineState *x86ms =3D X86_MACHINE(pcms); + MachineState *machine =3D MACHINE(x86ms); struct setup_data *setup_data; const char *kernel_filename =3D machine->kernel_filename; const char *initrd_filename =3D 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. * If load_elfboot() is successful, populate the fw_cfg info. */ - if (pcmc->pvh_enabled && + if (pvh_enabled && load_elfboot(kernel_filename, kernel_size, header, pvh_start_addr, fw_cfg)) { fclose(f); @@ -425,8 +421,7 @@ void x86_load_linux(PCMachineState *pcms, =20 initrd_data =3D g_mapped_file_get_contents(mapped_file); initrd_size =3D g_mapped_file_get_length(mapped_file); - initrd_max =3D - x86ms->below_4g_mem_size - pcmc->acpi_data_size - 1; + initrd_max =3D x86ms->below_4g_mem_size - acpi_data_size -= 1; if (initrd_size >=3D initrd_max) { fprintf(stderr, "qemu: initrd is too large, cannot sup= port." "(max: %"PRIu32", need %"PRId64")\n", @@ -494,8 +489,8 @@ void x86_load_linux(PCMachineState *pcms, initrd_max =3D 0x37ffffff; } =20 - if (initrd_max >=3D x86ms->below_4g_mem_size - pcmc->acpi_data_size) { - initrd_max =3D x86ms->below_4g_mem_size - pcmc->acpi_data_size - 1; + if (initrd_max >=3D x86ms->below_4g_mem_size - acpi_data_size) { + initrd_max =3D x86ms->below_4g_mem_size - acpi_data_size - 1; } =20 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr); @@ -652,7 +647,7 @@ void x86_load_linux(PCMachineState *pcms, =20 option_rom[nb_option_roms].bootindex =3D 0; option_rom[nb_option_roms].name =3D "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 =3D "linuxboot_dma.bin"; } nb_option_roms++; diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index d15713e..82d09fd 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -75,10 +75,11 @@ typedef struct { #define X86_MACHINE_CLASS(class) \ OBJECT_CLASS_CHECK(X86MachineClass, class, TYPE_X86_MACHINE) =20 -uint32_t x86_cpu_apic_id_from_index(PCMachineState *pcms, +uint32_t x86_cpu_apic_id_from_index(X86MachineState *pcms, 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, unsigned cpu_index); int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx); @@ -86,6 +87,10 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineSt= ate *ms); =20 void x86_bios_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw); =20 -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); =20 #endif --=20 1.8.3.1