From nobody Thu Nov 6 14:34:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541382729280969.6048660833819; Sun, 4 Nov 2018 17:52:09 -0800 (PST) Received: from localhost ([::1]:60903 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJU3j-00085w-Rx for importer@patchew.org; Sun, 04 Nov 2018 20:52:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJTvc-0000rX-GE for qemu-devel@nongnu.org; Sun, 04 Nov 2018 20:43:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJTvW-0003ia-N8 for qemu-devel@nongnu.org; Sun, 04 Nov 2018 20:43:44 -0500 Received: from mga18.intel.com ([134.134.136.126]:8015) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJTvT-0003UX-5N; Sun, 04 Nov 2018 20:43:36 -0500 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Nov 2018 17:43:25 -0800 Received: from emurphy1-mobl1.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.26.250]) by fmsmga005.fm.intel.com with ESMTP; 04 Nov 2018 17:43:20 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,466,1534834800"; d="scan'208";a="277074510" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Mon, 5 Nov 2018 02:40:43 +0100 Message-Id: <20181105014047.26447-21-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181105014047.26447-1-sameo@linux.intel.com> References: <20181105014047.26447-1-sameo@linux.intel.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: 134.134.136.126 Subject: [Qemu-devel] [PATCH v5 20/24] hw: acpi: Define ACPI tables builder interface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Stefano Stabellini , Eduardo Habkost , "Michael S. Tsirkin" , Shannon Zhao , Igor Mammedov , qemu-arm@nongnu.org, Paolo Bonzini , Anthony Perard , xen-devel@lists.xenproject.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" In order to decouple ACPI APIs from specific machine types, we are creating an ACPI builder interface that each ACPI platform can choose to implement. This way, a new machine type can re-use the high level ACPI APIs and define some custom table build methods, without having to duplicate most of the existing implementation only to add small variations to it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Samuel Ortiz --- include/hw/acpi/builder.h | 100 ++++++++++++++++++++++++++++++++++++++ hw/acpi/builder.c | 97 ++++++++++++++++++++++++++++++++++++ hw/acpi/Makefile.objs | 1 + 3 files changed, 198 insertions(+) create mode 100644 include/hw/acpi/builder.h create mode 100644 hw/acpi/builder.c diff --git a/include/hw/acpi/builder.h b/include/hw/acpi/builder.h new file mode 100644 index 0000000000..a63b88ffe9 --- /dev/null +++ b/include/hw/acpi/builder.h @@ -0,0 +1,100 @@ +/* + * + * Copyright (c) 2018 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef ACPI_BUILDER_H +#define ACPI_BUILDER_H + +#include "qemu/osdep.h" +#include "hw/acpi/bios-linker-loader.h" +#include "qom/object.h" + +#define TYPE_ACPI_BUILDER "acpi-builder" + +#define ACPI_BUILDER_METHODS(klass) \ + OBJECT_CLASS_CHECK(AcpiBuilderMethods, (klass), TYPE_ACPI_BUILDER) +#define ACPI_BUILDER_GET_METHODS(obj) \ + OBJECT_GET_CLASS(AcpiBuilderMethods, (obj), TYPE_ACPI_BUILDER) +#define ACPI_BUILDER(obj) \ + INTERFACE_CHECK(AcpiBuilder, (obj), TYPE_ACPI_BUILDER) + +typedef struct AcpiConfiguration AcpiConfiguration; +typedef struct AcpiBuildState AcpiBuildState; +typedef struct AcpiMcfgInfo AcpiMcfgInfo; + +typedef struct AcpiBuilder { + /* */ + Object Parent; +} AcpiBuilder; + +/** + * AcpiBuildMethods: + * + * Interface to be implemented by a machine type that needs to provide + * custom ACPI tables build method. + * + * @parent: Opaque parent interface. + * @rsdp: ACPI RSDP (Root System Description Pointer) table build callback. + * @madt: ACPI MADT (Multiple APIC Description Table) table build callback. + * @mcfg: ACPI MCFG table build callback. + * @srat: ACPI SRAT (System/Static Resource Affinity Table) + * table build callback. + * @slit: ACPI SLIT (System Locality System Information Table) + * table build callback. + * @configuration: ACPI configuration getter. + * This is used to query the machine instance for its + * AcpiConfiguration pointer. + */ +typedef struct AcpiBuilderMethods { + /* */ + InterfaceClass parent; + + /* */ + void (*rsdp)(GArray *table_data, BIOSLinker *linker, + unsigned rsdt_tbl_offset); + void (*madt)(GArray *table_data, BIOSLinker *linker, + MachineState *ms, AcpiConfiguration *conf); + void (*mcfg)(GArray *table_data, BIOSLinker *linker, + AcpiMcfgInfo *info); + void (*srat)(GArray *table_data, BIOSLinker *linker, + MachineState *machine, AcpiConfiguration *conf); + void (*slit)(GArray *table_data, BIOSLinker *linker); + + AcpiConfiguration *(*configuration)(AcpiBuilder *builder); +} AcpiBuilderMethods; + +void acpi_builder_rsdp(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + unsigned rsdt_tbl_offset); + +void acpi_builder_madt(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + MachineState *ms, AcpiConfiguration *conf); + +void acpi_builder_mcfg(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + AcpiMcfgInfo *info); + +void acpi_builder_srat(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + MachineState *machine, AcpiConfiguration *conf); + +void acpi_builder_slit(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker); + +AcpiConfiguration *acpi_builder_configuration(AcpiBuilder *builder); + +#endif diff --git a/hw/acpi/builder.c b/hw/acpi/builder.c new file mode 100644 index 0000000000..c29a614793 --- /dev/null +++ b/hw/acpi/builder.c @@ -0,0 +1,97 @@ +/* + * + * Copyright (c) 2018 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "qom/object.h" +#include "hw/acpi/builder.h" + +void acpi_builder_rsdp(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + unsigned rsdt_tbl_offset) +{ + AcpiBuilderMethods *abm =3D ACPI_BUILDER_GET_METHODS(builder); + + if (abm && abm->rsdp) { + abm->rsdp(table_data, linker, rsdt_tbl_offset); + } +} + +void acpi_builder_madt(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + MachineState *ms, AcpiConfiguration *conf) +{ + AcpiBuilderMethods *abm =3D ACPI_BUILDER_GET_METHODS(builder); + + if (abm && abm->madt) { + abm->madt(table_data, linker, ms, conf); + } +} + +void acpi_builder_mcfg(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + AcpiMcfgInfo *info) +{ + AcpiBuilderMethods *abm =3D ACPI_BUILDER_GET_METHODS(builder); + + if (abm && abm->mcfg) { + abm->mcfg(table_data, linker, info); + } +} + +void acpi_builder_srat(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker, + MachineState *machine, AcpiConfiguration *conf) +{ + AcpiBuilderMethods *abm =3D ACPI_BUILDER_GET_METHODS(builder); + + if (abm && abm->srat) { + abm->srat(table_data, linker, machine, conf); + } +} + +void acpi_builder_slit(AcpiBuilder *builder, + GArray *table_data, BIOSLinker *linker) +{ + AcpiBuilderMethods *abm =3D ACPI_BUILDER_GET_METHODS(builder); + + if (abm && abm->slit) { + abm->slit(table_data, linker); + } +} + +AcpiConfiguration *acpi_builder_configuration(AcpiBuilder *builder) +{ + AcpiBuilderMethods *abm =3D ACPI_BUILDER_GET_METHODS(builder); + if (abm && abm->configuration) { + return abm->configuration(builder); + } + return NULL; +} + +static const TypeInfo acpi_builder_info =3D { + .name =3D TYPE_ACPI_BUILDER, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(AcpiBuilderMethods), +}; + +static void acpi_builder_register_type(void) +{ + type_register_static(&acpi_builder_info); +} + +type_init(acpi_builder_register_type) diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 11c35bcb44..2f383adc6f 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -11,6 +11,7 @@ common-obj-$(call lnot,$(CONFIG_ACPI_X86)) +=3D acpi-stub= .o common-obj-y +=3D acpi_interface.o common-obj-y +=3D bios-linker-loader.o common-obj-y +=3D aml-build.o +common-obj-y +=3D builder.o =20 common-obj-$(CONFIG_IPMI) +=3D ipmi.o common-obj-$(call lnot,$(CONFIG_IPMI)) +=3D ipmi-stub.o --=20 2.19.1