QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>,
	Sergio Lopez <slp@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH 04/13] microvm: add minimal acpi support.
Date: Thu, 19 Mar 2020 15:00:33 +0100
Message-ID: <20200319150033.13f50947@redhat.com> (raw)
In-Reply-To: <20200319080117.7725-5-kraxel@redhat.com>

On Thu, 19 Mar 2020 09:01:08 +0100
Gerd Hoffmann <kraxel@redhat.com> wrote:

> $subject says all.  Can be disabled using the usual -no-acpi switch.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  include/hw/i386/microvm.h |   3 +
>  hw/i386/acpi-build.c      | 124 +++++++++++++++++++++++++++++++++++---
>  hw/i386/microvm.c         |  14 +++++
>  3 files changed, 133 insertions(+), 8 deletions(-)
> 
> diff --git a/include/hw/i386/microvm.h b/include/hw/i386/microvm.h
> index ba68d1f22bb3..da2852a70195 100644
> --- a/include/hw/i386/microvm.h
> +++ b/include/hw/i386/microvm.h
> @@ -24,6 +24,7 @@
>  
>  #include "hw/boards.h"
>  #include "hw/i386/x86.h"
> +#include "hw/acpi/acpi_dev_interface.h"
>  
>  /* Platform virtio definitions */
>  #define VIRTIO_MMIO_BASE      0xc0000000
> @@ -58,6 +59,8 @@ typedef struct {
>  
>      /* Machine state */
>      bool kernel_cmdline_fixed;
> +    Notifier machine_done;
> +    AcpiDeviceIf *acpi_dev;
>  } MicrovmMachineState;
>  
>  #define TYPE_MICROVM_MACHINE   MACHINE_TYPE_NAME("microvm")
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 9c98b07116cc..0e45a646af56 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -59,6 +59,7 @@
>  #include "hw/pci/pci_bus.h"
>  #include "hw/pci-host/q35.h"
>  #include "hw/i386/x86-iommu.h"
> +#include "hw/i386/microvm.h"
>  
>  #include "hw/acpi/aml-build.h"
>  #include "hw/acpi/utils.h"
> @@ -2749,12 +2750,103 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
>      return true;
>  }
>  
> +static void
> +build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
> +                   MicrovmMachineState *mms)
> +{
> +    X86MachineState *x86ms = X86_MACHINE(mms);
> +    Aml *dsdt, *sb_scope, *scope, *pkg;
> +
> +    dsdt = init_aml_allocator();
> +
> +    /* Reserve space for header */
> +    acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
> +
> +    build_dbg_aml(dsdt);
I'd drop/comment out as it's usually not used and whoever need
to debug aml can enable it when necessary.

> +
> +    sb_scope = aml_scope("_SB");
> +    acpi_dsdt_add_fw_cfg(sb_scope, OBJECT(x86ms->fw_cfg));
> +    aml_append(dsdt, sb_scope);
> +
> +    scope = aml_scope("\\");
> +    pkg = aml_package(4);
> +    aml_append(pkg, aml_int(0)); /* PM1a_CNT.SLP_TYP */
> +    aml_append(pkg, aml_int(0)); /* PM1b_CNT.SLP_TYP not impl. */
> +    aml_append(pkg, aml_int(0)); /* reserved */
> +    aml_append(pkg, aml_int(0)); /* reserved */
> +    aml_append(scope, aml_name_decl("_S5", pkg));
> +    aml_append(dsdt, scope);
> +
> +    /* copy AML table into ACPI tables blob and patch header there */
> +    g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
> +    build_header(linker, table_data,
> +        (void *)(table_data->data + table_data->len - dsdt->buf->len),
> +        "DSDT", dsdt->buf->len, 1, NULL, NULL);

make revision at least 2 or newer (like copy arm/virt 5th rev)


> +    free_aml_allocator();
> +}
> +
> +static
> +void acpi_build_microvm(AcpiBuildTables *tables, MachineState *machine)
> +{
> +    MicrovmMachineState *mms = MICROVM_MACHINE(machine);
> +    GArray *table_offsets;
> +    GArray *tables_blob = tables->table_data;
> +    AcpiFadtData pmfadt;
> +    unsigned facs, dsdt, rsdt;
> +
> +    init_common_fadt_data(machine, OBJECT(mms->acpi_dev), &pmfadt);
> +    pmfadt.smi_cmd = 0;
> +
> +    table_offsets = g_array_new(false, true /* clear */,
> +                                        sizeof(uint32_t));
> +    bios_linker_loader_alloc(tables->linker,
> +                             ACPI_BUILD_TABLE_FILE, tables_blob,
> +                             64 /* Ensure FACS is aligned */,
> +                             false /* high memory */);
> +
> +    facs = tables_blob->len;
> +    build_facs(tables_blob);
> +
> +    dsdt = tables_blob->len;
> +    build_dsdt_microvm(tables_blob, tables->linker, mms);
> +
> +    pmfadt.facs_tbl_offset = &facs;
> +    pmfadt.dsdt_tbl_offset = &dsdt;
> +    pmfadt.xdsdt_tbl_offset = &dsdt;
> +    acpi_add_table(table_offsets, tables_blob);
> +    build_fadt(tables_blob, tables->linker, &pmfadt, NULL, NULL);
> +
> +    acpi_add_table(table_offsets, tables_blob);
> +    build_madt(tables_blob, tables->linker, X86_MACHINE(machine),
> +               mms->acpi_dev);
> +
> +    rsdt = tables_blob->len;
> +    build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
> +
> +    /* RSDP is in FSEG memory, so allocate it separately */
> +    {
> +        AcpiRsdpData rsdp_data = {
> +            .revision = 0,
> +            .oem_id = ACPI_BUILD_APPNAME6,
> +            .xsdt_tbl_offset = NULL,
> +            .rsdt_tbl_offset = &rsdt,
are we interested in 32-bit guests?
if not than maybe use xsdt and newer revision like arm/virt does

> +        };
> +        build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> +    }
> +
> +    acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
> +    acpi_align_size(tables->linker->cmd_blob, ACPI_BUILD_ALIGN_SIZE);
> +
> +    /* Cleanup memory that's no longer used. */
> +    g_array_free(table_offsets, true);
> +}
> +
>  static
>  void acpi_build(AcpiBuildTables *tables, MachineState *machine)
>  {
> -    PCMachineState *pcms = PC_MACHINE(machine);
> -    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
>      X86MachineState *x86ms = X86_MACHINE(machine);
> +    PCMachineState *pcms;
> +    PCMachineClass *pcmc;
>      GArray *table_offsets;
>      unsigned facs, dsdt, rsdt, fadt;
>      AcpiPmInfo pm;
> @@ -2767,6 +2859,14 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
>      AcpiSlicOem slic_oem = { .id = NULL, .table_id = NULL };
>      Object *vmgenid_dev;
>  
> +    if (strcmp(object_get_typename(OBJECT(x86ms)), TYPE_MICROVM_MACHINE) == 0) {
maybe use object_dynamic_cast(OBJECT(x86ms)), TYPE_MICROVM_MACHINE)

> +        acpi_build_microvm(tables, machine);
> +        return;
> +    } else {
> +        pcms = PC_MACHINE(machine);
> +        pcmc = PC_MACHINE_GET_CLASS(pcms);
> +    }
> +
>      acpi_get_pm_info(machine, &pm);
>      acpi_get_misc_info(&misc);
>      acpi_get_pci_holes(&pci_hole, &pci_hole64);
> @@ -3009,21 +3109,29 @@ static const VMStateDescription vmstate_acpi_build = {
>  
>  void acpi_setup(void)
>  {
> -    PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
> -    PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
> -    X86MachineState *x86ms = X86_MACHINE(pcms);
> +    X86MachineState *x86ms = X86_MACHINE(qdev_get_machine());
> +    PCMachineState *pcms;
> +    PCMachineClass *pcmc;
>      AcpiBuildTables tables;
>      AcpiBuildState *build_state;
>      Object *vmgenid_dev;
>      TPMIf *tpm;
>      static FwCfgTPMConfig tpm_config;
>  
> +    if (strcmp(object_get_typename(OBJECT(x86ms)), TYPE_MICROVM_MACHINE) == 0) {
> +        pcms = NULL;
> +        pcmc = NULL;
> +    } else {
> +        pcms = PC_MACHINE(x86ms);
> +        pcmc = PC_MACHINE_GET_CLASS(pcms);
> +    }
> +
>      if (!x86ms->fw_cfg) {
>          ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n");
>          return;
>      }
>  
> -    if (!pcms->acpi_build_enabled) {
> +    if (pcms && !pcms->acpi_build_enabled) {
>          ACPI_BUILD_DPRINTF("ACPI build disabled. Bailing out.\n");
>          return;
>      }
> @@ -3036,7 +3144,7 @@ void acpi_setup(void)
>      build_state = g_malloc0(sizeof *build_state);
>  
>      acpi_build_tables_init(&tables);
> -    acpi_build(&tables, MACHINE(pcms));
> +    acpi_build(&tables, MACHINE(x86ms));
>  
>      /* Now expose it all to Guest */
>      build_state->table_mr = acpi_add_rom_blob(acpi_build_update,
> @@ -3069,7 +3177,7 @@ void acpi_setup(void)
>                             tables.vmgenid);
>      }
>  
> -    if (!pcmc->rsdp_in_ram) {
> +    if (pcmc && !pcmc->rsdp_in_ram) {
>          /*
>           * Keep for compatibility with old machine types.
>           * Though RSDP is small, its contents isn't immutable, so
> diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c
> index 38d8e5170323..362d513f38e1 100644
> --- a/hw/i386/microvm.c
> +++ b/hw/i386/microvm.c
> @@ -26,6 +26,7 @@
>  #include "sysemu/cpus.h"
>  #include "sysemu/numa.h"
>  #include "sysemu/reset.h"
> +#include "acpi-build.h"
>  
>  #include "hw/loader.h"
>  #include "hw/irq.h"
> @@ -41,6 +42,7 @@
>  #include "hw/i386/e820_memory_layout.h"
>  #include "hw/i386/fw_cfg.h"
>  #include "hw/virtio/virtio-mmio.h"
> +#include "hw/acpi/acpi.h"
>  
>  #include "cpu.h"
>  #include "elf.h"
> @@ -128,6 +130,10 @@ static void microvm_devices_init(MicrovmMachineState *mms)
>      }
>  
>      /* Optional and legacy devices */
> +    if (acpi_enabled) {
> +        ISADevice *acpi = isa_create_simple(isa_bus, "isa-acpi" /* FIXME */);
> +        mms->acpi_dev = ACPI_DEVICE_IF(acpi);
> +    }
>  
>      if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) {
>          qemu_irq *i8259;
> @@ -468,6 +474,11 @@ static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value,
>      mms->auto_kernel_cmdline = value;
>  }
>  
> +static void microvm_machine_done(Notifier *notifier, void *data)
> +{
> +    acpi_setup();
> +}
> +
>  static void microvm_machine_initfn(Object *obj)
>  {
>      MicrovmMachineState *mms = MICROVM_MACHINE(obj);
> @@ -482,6 +493,9 @@ static void microvm_machine_initfn(Object *obj)
>  
>      /* State */
>      mms->kernel_cmdline_fixed = false;
> +
> +    mms->machine_done.notify = microvm_machine_done;
> +    qemu_add_machine_init_done_notifier(&mms->machine_done);
>  }
>  
>  static void microvm_class_init(ObjectClass *oc, void *data)



  reply index

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19  8:01 [PATCH 00/13] microvm: add " Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 01/13] acpi: make build_madt() more generic Gerd Hoffmann
2020-03-19  9:34   ` Philippe Mathieu-Daudé
2020-03-19  8:01 ` [PATCH 02/13] acpi: factor out acpi_dsdt_add_fw_cfg() Gerd Hoffmann
2020-03-19  9:36   ` Philippe Mathieu-Daudé
2020-03-19 12:16   ` Igor Mammedov
2020-03-19  8:01 ` [PATCH 03/13] microvm: add isa-acpi device Gerd Hoffmann
2020-03-19 13:42   ` Igor Mammedov
2020-03-20  8:22     ` Gerd Hoffmann
2020-03-20 14:54       ` Igor Mammedov
2020-03-19  8:01 ` [PATCH 04/13] microvm: add minimal acpi support Gerd Hoffmann
2020-03-19 14:00   ` Igor Mammedov [this message]
2020-03-25  9:04     ` Gerd Hoffmann
2020-03-25 18:59       ` Igor Mammedov
2020-03-19  8:01 ` [PATCH 05/13] microvm: add acpi_dsdt_add_virtio() for x86 Gerd Hoffmann
2020-03-19 14:30   ` Igor Mammedov
2020-03-20  8:19     ` Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 06/13] microvm: disable virtio-mmio cmdline hack Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 07/13] [testing] seabios: update submodule to experimental microvm branch Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 08/13] [testing] seabios: update config & build rules Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 09/13] [testing] seabios: update binaries to experimental microvm branch Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 10/13] microvm/acpi: add rtc Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 11/13] microvm/acpi: add serial Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 12/13] microvm: make virtio irq base runtime configurable Gerd Hoffmann
2020-03-19  8:01 ` [PATCH 13/13] microvm/acpi: use GSI 16-23 for virtio Gerd Hoffmann
2020-03-20 15:30   ` Konrad Rzeszutek Wilk
2020-03-23 10:23     ` Gerd Hoffmann
2020-03-19  8:19 ` [PATCH 00/13] microvm: add acpi support no-reply
2020-03-19  8:23 ` no-reply
2020-03-19  8:24 ` no-reply
2020-03-19  8:49 ` Paolo Bonzini
2020-03-19  9:33   ` Gerd Hoffmann
2020-03-19  9:59     ` Paolo Bonzini
2020-03-19 11:28       ` Gerd Hoffmann
2020-03-19 13:40   ` Gerd Hoffmann
2020-03-19 17:34     ` Paolo Bonzini
2020-03-20  8:32       ` Gerd Hoffmann
2020-03-20 10:41         ` Paolo Bonzini
2020-03-23 10:51 ` Michael S. Tsirkin
2020-03-23 12:09   ` Gerd Hoffmann
2020-03-23 12:16     ` Igor Mammedov
2020-03-25  9:16       ` Gerd Hoffmann
2020-03-25  9:53         ` Igor Mammedov
2020-03-25 18:56         ` Igor Mammedov
2020-03-25 12:32 ` Igor Mammedov
2020-03-25 15:03   ` Gerd Hoffmann
2020-03-25 18:44     ` Igor Mammedov
2020-03-26  7:33       ` Michael S. Tsirkin
2020-03-26 10:59         ` Igor Mammedov
2020-03-27 12:06       ` Gerd Hoffmann
2020-03-27 14:05         ` Igor Mammedov

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=20200319150033.13f50947@redhat.com \
    --to=imammedo@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --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

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git