qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Sergio Lopez <slp@redhat.com>, qemu-devel@nongnu.org
Cc: ehabkost@redhat.com, mst@redhat.com, kraxel@redhat.com,
	pbonzini@redhat.com, imammedo@redhat.com, sgarzare@redhat.com,
	lersek@redhat.com, rth@twiddle.net
Subject: Re: [PATCH v6 05/10] hw/i386: make x86.c independent from PCMachineState
Date: Fri, 4 Oct 2019 11:51:01 +0200	[thread overview]
Message-ID: <8285d054-145c-14aa-b029-2f48a7f7333c@redhat.com> (raw)
In-Reply-To: <20191004093752.16564-6-slp@redhat.com>

On 10/4/19 11:37 AM, Sergio Lopez wrote:
> 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>

> ---
>   include/hw/i386/x86.h | 13 ++++++++----
>   hw/i386/pc.c          | 14 ++++++++-----
>   hw/i386/pc_piix.c     |  2 +-
>   hw/i386/pc_q35.c      |  2 +-
>   hw/i386/x86.c         | 49 ++++++++++++++++++++-----------------------
>   5 files changed, 43 insertions(+), 37 deletions(-)
> 
> diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
> index a930a7ad9d..f44359e9e9 100644
> --- a/include/hw/i386/x86.h
> +++ b/include/hw/i386/x86.h
> @@ -73,10 +73,11 @@ typedef struct {
>   #define X86_MACHINE_CLASS(class) \
>       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);
> -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);
> @@ -84,6 +85,10 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms);
>   
>   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
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index 0dc1420a1f..0bf93d489c 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -982,8 +982,8 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts)
>   
>   void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp)
>   {
> -    PCMachineState *pcms = PC_MACHINE(ms);
> -    int64_t apic_id = x86_cpu_apic_id_from_index(pcms, id);
> +    X86MachineState *x86ms = X86_MACHINE(ms);
> +    int64_t apic_id = x86_cpu_apic_id_from_index(x86ms, id);
>       Error *local_err = NULL;
>   
>       if (id < 0) {
> @@ -998,7 +998,8 @@ void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp)
>           return;
>       }
>   
> -    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;
> @@ -1099,6 +1100,7 @@ void xen_load_linux(PCMachineState *pcms)
>   {
>       int i;
>       FWCfgState *fw_cfg;
> +    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
>       X86MachineState *x86ms = X86_MACHINE(pcms);
>   
>       assert(MACHINE(pcms)->kernel_filename != NULL);
> @@ -1107,7 +1109,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);
>   
> -    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++) {
>           assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
>                  !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
> @@ -1243,7 +1246,8 @@ void pc_memory_init(PCMachineState *pcms,
>       }
>   
>       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++) {
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 0afa8fe6ea..a86317cdff 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -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) {
>           kvmclock_create();
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 8e7beb9415..8bdca373d6 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);
>       }
>   
> -    x86_cpus_init(pcms);
> +    x86_cpus_init(x86ms, pcmc->default_cpu_version);
>   
>       kvmclock_create();
>   
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index 4a8e254d69..55944a9a02 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -60,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 = MACHINE(pcms);
> -    X86MachineState *x86ms = X86_MACHINE(pcms);
> +    MachineState *ms = MACHINE(x86ms);
>       X86MachineClass *x86mc = X86_MACHINE_GET_CLASS(x86ms);
>       uint32_t correct_id;
>       static bool warned;
> @@ -83,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;
>       Error *local_err = 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->nr_dies = x86ms->smp_dies;
> @@ -102,16 +101,14 @@ void x86_cpu_new(PCMachineState *pcms, int64_t apic_id, Error **errp)
>       error_propagate(errp, local_err);
>   }
>   
> -void x86_cpus_init(PCMachineState *pcms)
> +void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
>   {
>       int i;
>       const CPUArchIdList *possible_cpus;
> -    MachineState *ms = MACHINE(pcms);
> -    MachineClass *mc = MACHINE_GET_CLASS(pcms);
> -    PCMachineClass *pcmc = PC_MACHINE_CLASS(mc);
> -    X86MachineState *x86ms = X86_MACHINE(pcms);
> +    MachineState *ms = MACHINE(x86ms);
> +    MachineClass *mc = MACHINE_GET_CLASS(x86ms);
>   
> -    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
>        *
> @@ -120,11 +117,11 @@ void x86_cpus_init(PCMachineState *pcms)
>        *
>        * 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;
>       possible_cpus = mc->possible_cpu_arch_ids(ms);
>       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);
>       }
>   }
>   
> @@ -152,7 +149,6 @@ int64_t x86_get_default_cpu_node_id(const MachineState *ms, int idx)
>   
>   const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
>   {
> -    PCMachineState *pcms = PC_MACHINE(ms);
>       X86MachineState *x86ms = X86_MACHINE(ms);
>       int i;
>       unsigned int max_cpus = ms->smp.max_cpus;
> @@ -174,7 +170,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
>   
>           ms->possible_cpus->cpus[i].type = ms->cpu_type;
>           ms->possible_cpus->cpus[i].vcpus_count = 1;
> -        ms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(pcms, i);
> +        ms->possible_cpus->cpus[i].arch_id = 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);
> @@ -331,8 +327,11 @@ static bool load_elfboot(const char *kernel_filename,
>       return true;
>   }
>   
> -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;
> @@ -342,9 +341,7 @@ void x86_load_linux(PCMachineState *pcms,
>       hwaddr real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
>       FILE *f;
>       char *vmode;
> -    MachineState *machine = MACHINE(pcms);
> -    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
> -    X86MachineState *x86ms = X86_MACHINE(pcms);
> +    MachineState *machine = MACHINE(x86ms);
>       struct setup_data *setup_data;
>       const char *kernel_filename = machine->kernel_filename;
>       const char *initrd_filename = machine->initrd_filename;
> @@ -387,7 +384,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);
> @@ -417,7 +414,7 @@ void x86_load_linux(PCMachineState *pcms,
>   
>                   initrd_data = g_mapped_file_get_contents(mapped_file);
>                   initrd_size = g_mapped_file_get_length(mapped_file);
> -                initrd_max = x86ms->below_4g_mem_size - pcmc->acpi_data_size - 1;
> +                initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1;
>                   if (initrd_size >= initrd_max) {
>                       fprintf(stderr, "qemu: initrd is too large, cannot support."
>                               "(max: %"PRIu32", need %"PRId64")\n",
> @@ -495,8 +492,8 @@ void x86_load_linux(PCMachineState *pcms,
>           initrd_max = 0x37ffffff;
>       }
>   
> -    if (initrd_max >= x86ms->below_4g_mem_size - pcmc->acpi_data_size) {
> -        initrd_max = x86ms->below_4g_mem_size - pcmc->acpi_data_size - 1;
> +    if (initrd_max >= x86ms->below_4g_mem_size - acpi_data_size) {
> +        initrd_max = x86ms->below_4g_mem_size - acpi_data_size - 1;
>       }
>   
>       fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
> @@ -645,7 +642,7 @@ void x86_load_linux(PCMachineState *pcms,
>   
>       option_rom[nb_option_roms].bootindex = 0;
>       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";
>       }
>       nb_option_roms++;
> 


  reply	other threads:[~2019-10-04 10:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04  9:37 [PATCH v6 00/10] Introduce the microvm machine type Sergio Lopez
2019-10-04  9:37 ` [PATCH v6 01/10] hw/virtio: Factorize virtio-mmio headers Sergio Lopez
2019-10-04  9:43   ` Philippe Mathieu-Daudé
2019-10-04  9:37 ` [PATCH v6 02/10] hw/i386/pc: rename functions shared with non-PC machines Sergio Lopez
2019-10-04  9:46   ` Philippe Mathieu-Daudé
2019-10-04 11:24   ` Stefano Garzarella
2019-10-04  9:37 ` [PATCH v6 03/10] hw/i386/pc: move shared x86 functions to x86.c and export them Sergio Lopez
2019-10-04  9:46   ` Philippe Mathieu-Daudé
2019-10-04 11:23   ` Stefano Garzarella
2019-10-04 11:36   ` Stefano Garzarella
2019-10-07 13:46     ` Sergio Lopez
2019-10-04  9:37 ` [PATCH v6 04/10] hw/i386: split PCMachineState deriving X86MachineState from it Sergio Lopez
2019-10-04  9:49   ` Philippe Mathieu-Daudé
2019-10-04  9:37 ` [PATCH v6 05/10] hw/i386: make x86.c independent from PCMachineState Sergio Lopez
2019-10-04  9:51   ` Philippe Mathieu-Daudé [this message]
2019-10-04  9:37 ` [PATCH v6 06/10] fw_cfg: add "modify" functions for all types Sergio Lopez
2019-10-04  9:37 ` [PATCH v6 07/10] hw/intc/apic: reject pic ints if isa_pic == NULL Sergio Lopez
2019-10-04  9:37 ` [PATCH v6 08/10] roms: add microvm-bios (qboot) as binary and git submodule Sergio Lopez
2019-10-04 11:50   ` Stefano Garzarella
2019-10-04  9:37 ` [PATCH v6 09/10] docs/microvm.rst: document the new microvm machine type Sergio Lopez
2019-10-04  9:37 ` [PATCH v6 10/10] hw/i386: Introduce the " Sergio Lopez
2019-10-04 13:57 ` [PATCH v6 00/10] " Michael S. Tsirkin
2019-10-04 17:21 ` no-reply
2019-10-08 12:37   ` Paolo Bonzini
2019-10-08 13:14     ` Sergio Lopez
2019-10-04 17:22 ` no-reply
2019-10-05 22:08 ` Michael S. Tsirkin
2019-10-07 13:44   ` Sergio Lopez
2019-10-07 13:59     ` Philippe Mathieu-Daudé
2019-10-09 19:21     ` Michael S. Tsirkin
2019-10-09 20:52       ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8285d054-145c-14aa-b029-2f48a7f7333c@redhat.com \
    --to=philmd@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sgarzare@redhat.com \
    --cc=slp@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).