From: Igor Mammedov <imammedo@redhat.com>
To: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Cc: qemu-devel@nongnu.org, richard.henderson@linaro.org,
gaosong@loongson.cn, maobibo@loongson.cn,
mark.cave-ayland@ilande.co.uk, mst@redhat.com, ani@anisinha.ca,
f4bug@amsat.org, peter.maydell@linaro.org
Subject: Re: [PATCH 5/6] hw/loongarch: Add acpi ged support
Date: Thu, 28 Jul 2022 16:03:07 +0200 [thread overview]
Message-ID: <20220728160307.4fcc3ce0@redhat.com> (raw)
In-Reply-To: <20220712083206.4187715-6-yangxiaojuan@loongson.cn>
On Tue, 12 Jul 2022 16:32:05 +0800
Xiaojuan Yang <yangxiaojuan@loongson.cn> wrote:
> Loongarch virt machine uses general hardware reduces acpi method, rather
> than LS7A acpi device. Now only power management function is used in
> acpi ged device, memory hotplug will be added later. Also acpi tables
> such as RSDP/RSDT/FADT etc.
>
> The acpi table has submited to acpi spec, and will release soon.
>
> Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
> ---
> hw/loongarch/Kconfig | 2 +
> hw/loongarch/acpi-build.c | 609 ++++++++++++++++++++++++++++++++++++
> hw/loongarch/loongson3.c | 78 ++++-
> hw/loongarch/meson.build | 1 +
> include/hw/loongarch/virt.h | 13 +
> include/hw/pci-host/ls7a.h | 4 +
> 6 files changed, 704 insertions(+), 3 deletions(-)
> create mode 100644 hw/loongarch/acpi-build.c
>
> diff --git a/hw/loongarch/Kconfig b/hw/loongarch/Kconfig
> index 610552e522..a99aa387c3 100644
> --- a/hw/loongarch/Kconfig
> +++ b/hw/loongarch/Kconfig
> @@ -15,3 +15,5 @@ config LOONGARCH_VIRT
> select LOONGARCH_EXTIOI
> select LS7A_RTC
> select SMBIOS
> + select ACPI_PCI
> + select ACPI_HW_REDUCED
> diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
> new file mode 100644
> index 0000000000..b95b83b079
> --- /dev/null
> +++ b/hw/loongarch/acpi-build.c
[...]
Most of the following code copied from x86 which is needlessly
complicated for loongarch wich doesn't have all that legacy to care about,
see ARM's variant virt_acpi_setup() for a cleaner example and
drop not needed parts.
> +static void acpi_build(AcpiBuildTables *tables, MachineState *machine)
> +{
> + LoongArchMachineState *lams = LOONGARCH_MACHINE(machine);
> + GArray *table_offsets;
> + AcpiFadtData fadt_data;
> + unsigned facs, rsdt, fadt, dsdt;
> + uint8_t *u;
> + size_t aml_len = 0;
> + GArray *tables_blob = tables->table_data;
> +
> + init_common_fadt_data(&fadt_data);
> +
> + table_offsets = g_array_new(false, true, sizeof(uint32_t));
> + ACPI_BUILD_DPRINTF("init ACPI tables\n");
> +
> + bios_linker_loader_alloc(tables->linker,
> + ACPI_BUILD_TABLE_FILE, tables_blob,
> + 64, false);
> +
> + /*
> + * FACS is pointed to by FADT.
> + * We place it first since it's the only table that has alignment
> + * requirements.
> + */
> + facs = tables_blob->len;
> + build_facs(tables_blob);
> +
> + /* DSDT is pointed to by FADT */
> + dsdt = tables_blob->len;
> + build_dsdt(tables_blob, tables->linker, machine);
> +
> + /*
> + * Count the size of the DSDT, we will need it for
> + * legacy sizing of ACPI tables.
> + */
> + aml_len += tables_blob->len - dsdt;
> +
> + /* ACPI tables pointed to by RSDT */
> + fadt = tables_blob->len;
> + acpi_add_table(table_offsets, tables_blob);
> + fadt_data.facs_tbl_offset = &facs;
> + fadt_data.dsdt_tbl_offset = &dsdt;
> + fadt_data.xdsdt_tbl_offset = &dsdt;
> + build_fadt(tables_blob, tables->linker, &fadt_data,
> + lams->oem_id, lams->oem_table_id);
> + aml_len += tables_blob->len - fadt;
> +
> + acpi_add_table(table_offsets, tables_blob);
> + build_madt(tables_blob, tables->linker, lams);
> +
> + acpi_add_table(table_offsets, tables_blob);
> + build_srat(tables_blob, tables->linker, machine);
> +
> + acpi_add_table(table_offsets, tables_blob);
> + {
> + AcpiMcfgInfo mcfg = {
> + .base = cpu_to_le64(LS_PCIECFG_BASE),
> + .size = cpu_to_le64(LS_PCIECFG_SIZE),
> + };
> + build_mcfg(tables_blob, tables->linker, &mcfg, lams->oem_id,
> + lams->oem_table_id);
> + }
> +
> + /* Add tables supplied by user (if any) */
> + for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
> + unsigned len = acpi_table_len(u);
> +
> + acpi_add_table(table_offsets, tables_blob);
> + g_array_append_vals(tables_blob, u, len);
> + }
> +
> + /* RSDT is pointed to by RSDP */
> + rsdt = tables_blob->len;
> + build_rsdt(tables_blob, tables->linker, table_offsets,
> + lams->oem_id, lams->oem_table_id);
> +
> + /* RSDP is in FSEG memory, so allocate it separately */
> + {
> + AcpiRsdpData rsdp_data = {
> + .revision = 0,
> + .oem_id = lams->oem_id,
> + .xsdt_tbl_offset = NULL,
> + .rsdt_tbl_offset = &rsdt,
> + };
> + build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
> + }
> +
> + /*
> + * The align size is 128, warn if 64k is not enough therefore
> + * the align size could be resized.
> + */
> + if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
> + warn_report("ACPI table size %u exceeds %d bytes,"
> + " migration may not work",
> + tables_blob->len, ACPI_BUILD_TABLE_SIZE / 2);
> + error_printf("Try removing CPUs, NUMA nodes, memory slots"
> + " or PCI bridges.");
> + }
> +
> + 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_ram_update(MemoryRegion *mr, GArray *data)
> +{
> + uint32_t size = acpi_data_len(data);
> +
> + /*
> + * Make sure RAM size is correct - in case it got changed
> + * e.g. by migration
> + */
> + memory_region_ram_resize(mr, size, &error_abort);
> +
> + memcpy(memory_region_get_ram_ptr(mr), data->data, size);
> + memory_region_set_dirty(mr, 0, size);
> +}
> +
> +static void acpi_build_update(void *build_opaque)
> +{
> + AcpiBuildState *build_state = build_opaque;
> + AcpiBuildTables tables;
> +
> + /* No state to update or already patched? Nothing to do. */
> + if (!build_state || build_state->patched) {
> + return;
> + }
> + build_state->patched = 1;
> +
> + acpi_build_tables_init(&tables);
> +
> + acpi_build(&tables, MACHINE(qdev_get_machine()));
> +
> + acpi_ram_update(build_state->table_mr, tables.table_data);
> + acpi_ram_update(build_state->rsdp_mr, tables.rsdp);
> + acpi_ram_update(build_state->linker_mr, tables.linker->cmd_blob);
> +
> + acpi_build_tables_cleanup(&tables, true);
> +}
> +
> +static void acpi_build_reset(void *build_opaque)
> +{
> + AcpiBuildState *build_state = build_opaque;
> + build_state->patched = 0;
> +}
> +
> +static const VMStateDescription vmstate_acpi_build = {
> + .name = "acpi_build",
> + .version_id = 1,
> + .minimum_version_id = 1,
> + .fields = (VMStateField[]) {
> + VMSTATE_UINT8(patched, AcpiBuildState),
> + VMSTATE_END_OF_LIST()
> + },
> +};
> +
> +void loongarch_acpi_setup(LoongArchMachineState *lams)
> +{
> + AcpiBuildTables tables;
> + AcpiBuildState *build_state;
> +
> + if (!lams->fw_cfg) {
> + ACPI_BUILD_DPRINTF("No fw cfg. Bailing out.\n");
> + return;
> + }
> +
> + if (!loongarch_is_acpi_enabled(lams)) {
> + ACPI_BUILD_DPRINTF("ACPI disabled. Bailing out.\n");
> + return;
> + }
> +
> + build_state = g_malloc0(sizeof *build_state);
> +
> + acpi_build_tables_init(&tables);
> + acpi_build(&tables, MACHINE(lams));
> +
> + /* Now expose it all to Guest */
> + build_state->table_mr = acpi_add_rom_blob(acpi_build_update,
> + build_state, tables.table_data,
> + ACPI_BUILD_TABLE_FILE);
> + assert(build_state->table_mr != NULL);
> +
> + build_state->linker_mr =
> + acpi_add_rom_blob(acpi_build_update, build_state,
> + tables.linker->cmd_blob, ACPI_BUILD_LOADER_FILE);
> +
> + build_state->rsdp_mr = acpi_add_rom_blob(acpi_build_update,
> + build_state, tables.rsdp,
> + ACPI_BUILD_RSDP_FILE);
> +
> + qemu_register_reset(acpi_build_reset, build_state);
> + acpi_build_reset(build_state);
> + vmstate_register(NULL, 0, &vmstate_acpi_build, build_state);
> +
> + /*
> + * Cleanup tables but don't free the memory: we track it
> + * in build_state.
> + */
> + acpi_build_tables_cleanup(&tables, false);
> +}
[...]
next prev parent reply other threads:[~2022-07-28 14:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 8:32 [PATCH v1 0/6] Support booting bios and kernel for LoongArch Xiaojuan Yang
2022-07-12 8:32 ` [PATCH 1/6] hw/loongarch: Add fw_cfg table support Xiaojuan Yang
2022-07-19 7:42 ` Richard Henderson
2022-07-12 8:32 ` [PATCH 2/6] hw/loongarch: Add uefi bios loading support Xiaojuan Yang
2022-07-19 8:03 ` Richard Henderson
2022-07-12 8:32 ` [PATCH 3/6] hw/loongarch: Add linux kernel booting support Xiaojuan Yang
2022-07-19 8:03 ` Richard Henderson
2022-07-12 8:32 ` [PATCH 4/6] hw/loongarch: Add smbios support Xiaojuan Yang
2022-07-19 8:04 ` Richard Henderson
2022-07-12 8:32 ` [PATCH 5/6] hw/loongarch: Add acpi ged support Xiaojuan Yang
2022-07-19 8:06 ` Richard Henderson
2022-07-28 14:03 ` Igor Mammedov [this message]
2022-07-29 1:32 ` gaosong
2022-07-12 8:32 ` [PATCH 6/6] hw/loongarch: Add fdt support Xiaojuan Yang
2022-07-19 8:07 ` Richard Henderson
2022-07-19 8:10 ` [PATCH v1 0/6] Support booting bios and kernel for LoongArch Richard Henderson
2022-07-19 16:21 ` Richard Henderson
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=20220728160307.4fcc3ce0@redhat.com \
--to=imammedo@redhat.com \
--cc=ani@anisinha.ca \
--cc=f4bug@amsat.org \
--cc=gaosong@loongson.cn \
--cc=maobibo@loongson.cn \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=yangxiaojuan@loongson.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.