
* Update to QEMU v9.0.0 --------- Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com> Signed-off-by: Ido Plat <ido.plat@ibm.com> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Signed-off-by: Gregory Price <gregory.price@memverge.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Lorenz Brun <lorenz@brun.one> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Signed-off-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Sven Schnelle <svens@stackframe.org> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com> Signed-off-by: Avihai Horon <avihaih@nvidia.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Joonas Kankaala <joonas.a.kankaala@gmail.com> Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Glenn Miles <milesg@linux.ibm.com> Signed-off-by: Oleg Sviridov <oleg.sviridov@red-soft.ru> Signed-off-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Signed-off-by: Yajun Wu <yajunw@nvidia.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Signed-off-by: Lei Wang <lei4.wang@intel.com> Signed-off-by: Wei Wang <wei.w.wang@intel.com> Signed-off-by: Martin Hundebøll <martin@geanix.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Wafer <wafer@jaguarmicro.com> Signed-off-by: Yuxue Liu <yuxue.liu@jaguarmicro.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com> Signed-off-by: Zack Buhman <zack@buhman.org> Signed-off-by: Keith Packard <keithp@keithp.com> Signed-off-by: Yuquan Wang wangyuquan1236@phytium.com.cn Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Signed-off-by: Cindy Lu <lulu@redhat.com> Co-authored-by: Peter Maydell <peter.maydell@linaro.org> Co-authored-by: Fabiano Rosas <farosas@suse.de> Co-authored-by: Peter Xu <peterx@redhat.com> Co-authored-by: Thomas Huth <thuth@redhat.com> Co-authored-by: Cédric Le Goater <clg@redhat.com> Co-authored-by: Zheyu Ma <zheyuma97@gmail.com> Co-authored-by: Ido Plat <ido.plat@ibm.com> Co-authored-by: Ilya Leoshkevich <iii@linux.ibm.com> Co-authored-by: Markus Armbruster <armbru@redhat.com> Co-authored-by: Marc-André Lureau <marcandre.lureau@redhat.com> Co-authored-by: Paolo Bonzini <pbonzini@redhat.com> Co-authored-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Co-authored-by: David Hildenbrand <david@redhat.com> Co-authored-by: Kevin Wolf <kwolf@redhat.com> Co-authored-by: Stefan Reiter <s.reiter@proxmox.com> Co-authored-by: Fiona Ebner <f.ebner@proxmox.com> Co-authored-by: Gregory Price <gregory.price@memverge.com> Co-authored-by: Lorenz Brun <lorenz@brun.one> Co-authored-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> Co-authored-by: Philippe Mathieu-Daudé <philmd@linaro.org> Co-authored-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> Co-authored-by: BALATON Zoltan <balaton@eik.bme.hu> Co-authored-by: Igor Mammedov <imammedo@redhat.com> Co-authored-by: Akihiko Odaki <akihiko.odaki@daynix.com> Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Co-authored-by: Sven Schnelle <svens@stackframe.org> Co-authored-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Co-authored-by: Helge Deller <deller@kernel.org> Co-authored-by: Harsh Prateek Bora <harshpb@linux.ibm.com> Co-authored-by: Benjamin Gray <bgray@linux.ibm.com> Co-authored-by: Nicholas Piggin <npiggin@gmail.com> Co-authored-by: Avihai Horon <avihaih@nvidia.com> Co-authored-by: Michael Tokarev <mjt@tls.msk.ru> Co-authored-by: Joonas Kankaala <joonas.a.kankaala@gmail.com> Co-authored-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> Co-authored-by: Stefan Weil <sw@weilnetz.de> Co-authored-by: Dayu Liu <liu.dayu@zte.com.cn> Co-authored-by: Zhao Liu <zhao1.liu@intel.com> Co-authored-by: Glenn Miles <milesg@linux.vnet.ibm.com> Co-authored-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Co-authored-by: Yajun Wu <yajunw@nvidia.com> Co-authored-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Co-authored-by: Pierre-Clément Tosi <ptosi@google.com> Co-authored-by: Wei Wang <wei.w.wang@intel.com> Co-authored-by: Martin Hundebøll <martin@geanix.com> Co-authored-by: Michael S. Tsirkin <mst@redhat.com> Co-authored-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Co-authored-by: Wafer <wafer@jaguarmicro.com> Co-authored-by: lyx634449800 <yuxue.liu@jaguarmicro.com> Co-authored-by: Gerd Hoffmann <kraxel@redhat.com> Co-authored-by: Nguyen Dinh Phi <phind.uet@gmail.com> Co-authored-by: Zack Buhman <zack@buhman.org> Co-authored-by: Keith Packard <keithp@keithp.com> Co-authored-by: Yuquan Wang <wangyuquan1236@phytium.com.cn> Co-authored-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Co-authored-by: Cindy Lu <lulu@redhat.com>
269 lines
8.5 KiB
C
269 lines
8.5 KiB
C
/* Support for generating ACPI tables and passing them to Guests
|
|
*
|
|
* Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
|
|
* Copyright (C) 2006 Fabrice Bellard
|
|
* Copyright (C) 2013 Red Hat Inc
|
|
*
|
|
* Author: Michael S. Tsirkin <mst@redhat.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/cutils.h"
|
|
#include "qapi/error.h"
|
|
|
|
#include "exec/memory.h"
|
|
#include "hw/acpi/acpi.h"
|
|
#include "hw/acpi/acpi_aml_interface.h"
|
|
#include "hw/acpi/aml-build.h"
|
|
#include "hw/acpi/bios-linker-loader.h"
|
|
#include "hw/acpi/generic_event_device.h"
|
|
#include "hw/acpi/utils.h"
|
|
#include "hw/acpi/erst.h"
|
|
#include "hw/i386/fw_cfg.h"
|
|
#include "hw/i386/microvm.h"
|
|
#include "hw/pci/pci.h"
|
|
#include "hw/pci/pcie_host.h"
|
|
#include "hw/usb/xhci.h"
|
|
#include "hw/virtio/virtio-acpi.h"
|
|
#include "hw/virtio/virtio-mmio.h"
|
|
#include "hw/input/i8042.h"
|
|
|
|
#include "acpi-common.h"
|
|
#include "acpi-microvm.h"
|
|
|
|
#include CONFIG_DEVICES
|
|
|
|
static void acpi_dsdt_add_virtio(Aml *scope,
|
|
MicrovmMachineState *mms)
|
|
{
|
|
gchar *separator;
|
|
long int index;
|
|
BusState *bus;
|
|
BusChild *kid;
|
|
|
|
bus = sysbus_get_default();
|
|
QTAILQ_FOREACH(kid, &bus->children, sibling) {
|
|
Object *obj = object_dynamic_cast(OBJECT(kid->child),
|
|
TYPE_VIRTIO_MMIO);
|
|
|
|
if (obj) {
|
|
VirtIOMMIOProxy *mmio = VIRTIO_MMIO(obj);
|
|
VirtioBusState *mmio_virtio_bus = &mmio->bus;
|
|
BusState *mmio_bus = &mmio_virtio_bus->parent_obj;
|
|
|
|
if (QTAILQ_EMPTY(&mmio_bus->children)) {
|
|
continue;
|
|
}
|
|
separator = g_strrstr(mmio_bus->name, ".");
|
|
if (!separator) {
|
|
continue;
|
|
}
|
|
if (qemu_strtol(separator + 1, NULL, 10, &index) != 0) {
|
|
continue;
|
|
}
|
|
|
|
uint32_t irq = mms->virtio_irq_base + index;
|
|
hwaddr base = VIRTIO_MMIO_BASE + index * 512;
|
|
hwaddr size = 512;
|
|
virtio_acpi_dsdt_add(scope, base, size, irq, index, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void acpi_dsdt_add_xhci(Aml *scope, MicrovmMachineState *mms)
|
|
{
|
|
if (machine_usb(MACHINE(mms))) {
|
|
xhci_sysbus_build_aml(scope, MICROVM_XHCI_BASE, MICROVM_XHCI_IRQ);
|
|
}
|
|
}
|
|
|
|
static void acpi_dsdt_add_pci(Aml *scope, MicrovmMachineState *mms)
|
|
{
|
|
if (mms->pcie != ON_OFF_AUTO_ON) {
|
|
return;
|
|
}
|
|
|
|
acpi_dsdt_add_gpex(scope, &mms->gpex);
|
|
}
|
|
|
|
static void
|
|
build_dsdt_microvm(GArray *table_data, BIOSLinker *linker,
|
|
MicrovmMachineState *mms)
|
|
{
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
|
Aml *dsdt, *sb_scope, *scope, *pkg;
|
|
bool ambiguous;
|
|
Object *isabus;
|
|
AcpiTable table = { .sig = "DSDT", .rev = 2, .oem_id = x86ms->oem_id,
|
|
.oem_table_id = x86ms->oem_table_id };
|
|
|
|
isabus = object_resolve_path_type("", TYPE_ISA_BUS, &ambiguous);
|
|
assert(isabus);
|
|
assert(!ambiguous);
|
|
|
|
acpi_table_begin(&table, table_data);
|
|
dsdt = init_aml_allocator();
|
|
|
|
sb_scope = aml_scope("_SB");
|
|
fw_cfg_add_acpi_dsdt(sb_scope, x86ms->fw_cfg);
|
|
qbus_build_aml(BUS(isabus), sb_scope);
|
|
build_ged_aml(sb_scope, GED_DEVICE, x86ms->acpi_dev,
|
|
GED_MMIO_IRQ, AML_SYSTEM_MEMORY, GED_MMIO_BASE);
|
|
acpi_dsdt_add_power_button(sb_scope);
|
|
acpi_dsdt_add_virtio(sb_scope, mms);
|
|
acpi_dsdt_add_xhci(sb_scope, mms);
|
|
acpi_dsdt_add_pci(sb_scope, mms);
|
|
aml_append(dsdt, sb_scope);
|
|
|
|
/* ACPI 5.0: Table 7-209 System State Package */
|
|
scope = aml_scope("\\");
|
|
pkg = aml_package(4);
|
|
aml_append(pkg, aml_int(ACPI_GED_SLP_TYP_S5));
|
|
aml_append(pkg, aml_int(0)); /* ignored */
|
|
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 bytecode into ACPI tables blob */
|
|
g_array_append_vals(table_data, dsdt->buf->data, dsdt->buf->len);
|
|
|
|
acpi_table_end(linker, &table);
|
|
free_aml_allocator();
|
|
}
|
|
|
|
static void acpi_build_microvm(AcpiBuildTables *tables,
|
|
MicrovmMachineState *mms)
|
|
{
|
|
MachineState *machine = MACHINE(mms);
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
|
GArray *table_offsets;
|
|
GArray *tables_blob = tables->table_data;
|
|
unsigned dsdt, xsdt;
|
|
AcpiFadtData pmfadt = {
|
|
/* ACPI 5.0: 4.1 Hardware-Reduced ACPI */
|
|
.rev = 5,
|
|
.flags = ((1 << ACPI_FADT_F_HW_REDUCED_ACPI) |
|
|
(1 << ACPI_FADT_F_RESET_REG_SUP)),
|
|
|
|
/* ACPI 5.0: 4.8.3.7 Sleep Control and Status Registers */
|
|
.sleep_ctl = {
|
|
.space_id = AML_AS_SYSTEM_MEMORY,
|
|
.bit_width = 8,
|
|
.address = GED_MMIO_BASE_REGS + ACPI_GED_REG_SLEEP_CTL,
|
|
},
|
|
.sleep_sts = {
|
|
.space_id = AML_AS_SYSTEM_MEMORY,
|
|
.bit_width = 8,
|
|
.address = GED_MMIO_BASE_REGS + ACPI_GED_REG_SLEEP_STS,
|
|
},
|
|
|
|
/* ACPI 5.0: 4.8.3.6 Reset Register */
|
|
.reset_reg = {
|
|
.space_id = AML_AS_SYSTEM_MEMORY,
|
|
.bit_width = 8,
|
|
.address = GED_MMIO_BASE_REGS + ACPI_GED_REG_RESET,
|
|
},
|
|
.reset_val = ACPI_GED_RESET_VALUE,
|
|
/*
|
|
* ACPI v2, Table 5-10 - Fixed ACPI Description Table Boot Architecture
|
|
* Flags, bit offset 1 - 8042.
|
|
*/
|
|
.iapc_boot_arch = iapc_boot_arch_8042(),
|
|
};
|
|
|
|
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 */);
|
|
|
|
dsdt = tables_blob->len;
|
|
build_dsdt_microvm(tables_blob, tables->linker, mms);
|
|
|
|
pmfadt.dsdt_tbl_offset = &dsdt;
|
|
pmfadt.xdsdt_tbl_offset = &dsdt;
|
|
acpi_add_table(table_offsets, tables_blob);
|
|
build_fadt(tables_blob, tables->linker, &pmfadt, x86ms->oem_id,
|
|
x86ms->oem_table_id);
|
|
|
|
acpi_add_table(table_offsets, tables_blob);
|
|
acpi_build_madt(tables_blob, tables->linker, X86_MACHINE(machine),
|
|
x86ms->oem_id, x86ms->oem_table_id);
|
|
|
|
#ifdef CONFIG_ACPI_ERST
|
|
{
|
|
Object *erst_dev;
|
|
erst_dev = find_erst_dev();
|
|
if (erst_dev) {
|
|
acpi_add_table(table_offsets, tables_blob);
|
|
build_erst(tables_blob, tables->linker, erst_dev,
|
|
x86ms->oem_id, x86ms->oem_table_id);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
xsdt = tables_blob->len;
|
|
build_xsdt(tables_blob, tables->linker, table_offsets, x86ms->oem_id,
|
|
x86ms->oem_table_id);
|
|
|
|
/* RSDP is in FSEG memory, so allocate it separately */
|
|
{
|
|
AcpiRsdpData rsdp_data = {
|
|
/* ACPI 2.0: 5.2.4.3 RSDP Structure */
|
|
.revision = 2, /* xsdt needs v2 */
|
|
.oem_id = x86ms->oem_id,
|
|
.xsdt_tbl_offset = &xsdt,
|
|
.rsdt_tbl_offset = NULL,
|
|
};
|
|
build_rsdp(tables->rsdp, tables->linker, &rsdp_data);
|
|
}
|
|
|
|
/* Cleanup memory that's no longer used. */
|
|
g_array_free(table_offsets, true);
|
|
}
|
|
|
|
static void acpi_build_no_update(void *build_opaque)
|
|
{
|
|
/* nothing, microvm tables don't change at runtime */
|
|
}
|
|
|
|
void acpi_setup_microvm(MicrovmMachineState *mms)
|
|
{
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
|
AcpiBuildTables tables;
|
|
|
|
assert(x86ms->fw_cfg);
|
|
|
|
if (!x86_machine_is_acpi_enabled(x86ms)) {
|
|
return;
|
|
}
|
|
|
|
acpi_build_tables_init(&tables);
|
|
acpi_build_microvm(&tables, mms);
|
|
|
|
/* Now expose it all to Guest */
|
|
acpi_add_rom_blob(acpi_build_no_update, NULL, tables.table_data,
|
|
ACPI_BUILD_TABLE_FILE);
|
|
acpi_add_rom_blob(acpi_build_no_update, NULL, tables.linker->cmd_blob,
|
|
ACPI_BUILD_LOADER_FILE);
|
|
acpi_add_rom_blob(acpi_build_no_update, NULL, tables.rsdp,
|
|
ACPI_BUILD_RSDP_FILE);
|
|
|
|
acpi_build_tables_cleanup(&tables, false);
|
|
}
|