From: Stefan Berger <stefanb@linux.ibm.com>
To: Joelle van Dyne <j@getutm.app>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
Ani Sinha <anisinha@redhat.com>,
Shannon Zhao <shannon.zhaosl@gmail.com>,
Song Gao <gaosong@loongson.cn>,
Stefan Berger <stefanb@linux.vnet.ibm.com>,
"open list:Virt" <qemu-arm@nongnu.org>
Subject: Re: [PATCH v3 09/14] tpm_tis_sysbus: move DSDT AML generation to device
Date: Mon, 30 Oct 2023 16:55:09 -0400 [thread overview]
Message-ID: <7dbcf9fe-4869-47ad-a2b5-ef91f9c223be@linux.ibm.com> (raw)
In-Reply-To: <20231029060404.71196-10-j@getutm.app>
On 10/29/23 02:03, Joelle van Dyne wrote:
> This reduces redundent code in different machine types with ACPI table
s/redundent/redundant
> generation. Additionally, this will allow us to support different TPM
> interfaces with the same AML logic. Finally, this matches up with the
> TPM TIS ISA implementation.
>
> Ideally, we would be able to call `qbus_build_aml` and avoid any TPM
> specific code in the ACPI table generation. However, currently we
> still have to call `build_tpm2` anyways and it does not look like
> most other ACPI devices support the `ACPI_DEV_AML_IF` interface.
>
> Signed-off-by: Joelle van Dyne <j@getutm.app>
> ---
> hw/arm/virt-acpi-build.c | 38 ++------------------------------------
> hw/loongarch/acpi-build.c | 38 ++------------------------------------
> hw/tpm/tpm_tis_sysbus.c | 37 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 41 insertions(+), 72 deletions(-)
>
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index 9ce136cd88..3efbe6bd09 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -35,6 +35,7 @@
> #include "target/arm/cpu.h"
> #include "hw/acpi/acpi-defs.h"
> #include "hw/acpi/acpi.h"
> +#include "hw/acpi/acpi_aml_interface.h"
> #include "hw/nvram/fw_cfg.h"
> #include "hw/acpi/bios-linker-loader.h"
> #include "hw/acpi/aml-build.h"
> @@ -208,41 +209,6 @@ static void acpi_dsdt_add_gpio(Aml *scope, const MemMapEntry *gpio_memmap,
> aml_append(scope, dev);
> }
>
> -#ifdef CONFIG_TPM
> -static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
> -{
> - PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
> - hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
> - SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find());
> - MemoryRegion *sbdev_mr;
> - hwaddr tpm_base;
> -
> - if (!sbdev) {
> - return;
> - }
> -
> - tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
> - assert(tpm_base != -1);
> -
> - tpm_base += pbus_base;
> -
> - sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
> -
> - Aml *dev = aml_device("TPM0");
> - aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
> - aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
> - aml_append(dev, aml_name_decl("_UID", aml_int(0)));
> -
> - Aml *crs = aml_resource_template();
> - aml_append(crs,
> - aml_memory32_fixed(tpm_base,
> - (uint32_t)memory_region_size(sbdev_mr),
> - AML_READ_WRITE));
> - aml_append(dev, aml_name_decl("_CRS", crs));
> - aml_append(scope, dev);
> -}
> -#endif
> -
> #define ID_MAPPING_ENTRY_SIZE 20
> #define SMMU_V3_ENTRY_SIZE 68
> #define ROOT_COMPLEX_ENTRY_SIZE 36
> @@ -891,7 +857,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
>
> acpi_dsdt_add_power_button(scope);
> #ifdef CONFIG_TPM
> - acpi_dsdt_add_tpm(scope, vms);
> + call_dev_aml_func(DEVICE(tpm_find()), scope);
> #endif
>
> aml_append(dsdt, scope);
> diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
> index ae292fc543..1969bfc8f9 100644
> --- a/hw/loongarch/acpi-build.c
> +++ b/hw/loongarch/acpi-build.c
> @@ -14,6 +14,7 @@
> #include "target/loongarch/cpu.h"
> #include "hw/acpi/acpi-defs.h"
> #include "hw/acpi/acpi.h"
> +#include "hw/acpi/acpi_aml_interface.h"
> #include "hw/nvram/fw_cfg.h"
> #include "hw/acpi/bios-linker-loader.h"
> #include "migration/vmstate.h"
> @@ -328,41 +329,6 @@ static void build_flash_aml(Aml *scope, LoongArchMachineState *lams)
> aml_append(scope, dev);
> }
>
> -#ifdef CONFIG_TPM
> -static void acpi_dsdt_add_tpm(Aml *scope, LoongArchMachineState *vms)
> -{
> - PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
> - hwaddr pbus_base = VIRT_PLATFORM_BUS_BASEADDRESS;
> - SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find());
> - MemoryRegion *sbdev_mr;
> - hwaddr tpm_base;
> -
> - if (!sbdev) {
> - return;
> - }
> -
> - tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
> - assert(tpm_base != -1);
> -
> - tpm_base += pbus_base;
> -
> - sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
> -
> - Aml *dev = aml_device("TPM0");
> - aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
> - aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
> - aml_append(dev, aml_name_decl("_UID", aml_int(0)));
> -
> - Aml *crs = aml_resource_template();
> - aml_append(crs,
> - aml_memory32_fixed(tpm_base,
> - (uint32_t)memory_region_size(sbdev_mr),
> - AML_READ_WRITE));
> - aml_append(dev, aml_name_decl("_CRS", crs));
> - aml_append(scope, dev);
> -}
> -#endif
> -
> /* build DSDT */
> static void
> build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> @@ -379,7 +345,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine)
> build_la_ged_aml(dsdt, machine);
> build_flash_aml(dsdt, lams);
> #ifdef CONFIG_TPM
> - acpi_dsdt_add_tpm(dsdt, lams);
> + call_dev_aml_func(DEVICE(tpm_find()), dsdt);
> #endif
> /* System State Package */
> scope = aml_scope("\\");
> diff --git a/hw/tpm/tpm_tis_sysbus.c b/hw/tpm/tpm_tis_sysbus.c
> index 2fc550f119..462b0e1571 100644
> --- a/hw/tpm/tpm_tis_sysbus.c
> +++ b/hw/tpm/tpm_tis_sysbus.c
> @@ -30,6 +30,7 @@
> #include "hw/sysbus.h"
> #include "tpm_tis.h"
> #include "qom/object.h"
> +#include "hw/acpi/acpi_aml_interface.h"
>
> struct TPMStateSysBus {
> /*< private >*/
> @@ -37,6 +38,8 @@ struct TPMStateSysBus {
>
> /*< public >*/
> TPMState state; /* not a QOM object */
> + uint64_t baseaddr;
> + uint64_t size;
> };
>
> OBJECT_DECLARE_SIMPLE_TYPE(TPMStateSysBus, TPM_TIS_SYSBUS)
> @@ -93,6 +96,10 @@ static void tpm_tis_sysbus_reset(DeviceState *dev)
> static Property tpm_tis_sysbus_properties[] = {
> DEFINE_PROP_UINT32("irq", TPMStateSysBus, state.irq_num, TPM_TIS_IRQ),
> DEFINE_PROP_TPMBE("tpmdev", TPMStateSysBus, state.be_driver),
> + DEFINE_PROP_UINT64("x-baseaddr", TPMStateSysBus, baseaddr,
> + TPM_TIS_ADDR_BASE),
> + DEFINE_PROP_UINT64("x-size", TPMStateSysBus, size,
> + TPM_TIS_ADDR_SIZE),
> DEFINE_PROP_END_OF_LIST(),
> };
>
> @@ -125,10 +132,38 @@ static void tpm_tis_sysbus_realizefn(DeviceState *dev, Error **errp)
> }
> }
>
> +static void build_tpm_tis_sysbus_aml(AcpiDevAmlIf *adev, Aml *scope)
> +{
> + Aml *dev, *crs;
> + TPMStateSysBus *sbdev = TPM_TIS_SYSBUS(adev);
> + TPMIf *ti = TPM_IF(sbdev);
> +
> + dev = aml_device("TPM");
> + if (tpm_tis_sysbus_get_tpm_version(ti) == TPM_VERSION_2_0) {
> + aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
> + aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device")));
> + } else {
> + aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C31")));
> + }
> + aml_append(dev, aml_name_decl("_UID", aml_int(0)));
> + aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
> + crs = aml_resource_template();
> + aml_append(crs, aml_memory32_fixed(sbdev->baseaddr, sbdev->size,
> + AML_READ_WRITE));
> + /*
> + * FIXME: TPM_TIS_IRQ=5 conflicts with PNP0C0F irqs,
> + * fix default TPM_TIS_IRQ value there to use some unused IRQ
> + */
> + /* aml_append(crs, aml_irq_no_flags(sbdev->state.irq_num)); */
> + aml_append(dev, aml_name_decl("_CRS", crs));
> + aml_append(scope, dev);
> +}
> +
> static void tpm_tis_sysbus_class_init(ObjectClass *klass, void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
> TPMIfClass *tc = TPM_IF_CLASS(klass);
> + AcpiDevAmlIfClass *adevc = ACPI_DEV_AML_IF_CLASS(klass);
>
> device_class_set_props(dc, tpm_tis_sysbus_properties);
> dc->vmsd = &vmstate_tpm_tis_sysbus;
> @@ -139,6 +174,7 @@ static void tpm_tis_sysbus_class_init(ObjectClass *klass, void *data)
> tc->request_completed = tpm_tis_sysbus_request_completed;
> tc->get_version = tpm_tis_sysbus_get_tpm_version;
> set_bit(DEVICE_CATEGORY_MISC, dc->categories);
> + adevc->build_dev_aml = build_tpm_tis_sysbus_aml;
> }
>
> static const TypeInfo tpm_tis_sysbus_info = {
> @@ -149,6 +185,7 @@ static const TypeInfo tpm_tis_sysbus_info = {
> .class_init = tpm_tis_sysbus_class_init,
> .interfaces = (InterfaceInfo[]) {
> { TYPE_TPM_IF },
> + { TYPE_ACPI_DEV_AML_IF },
> { }
> }
> };
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
next prev parent reply other threads:[~2023-10-30 20:56 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-29 6:03 [PATCH v3 00/14] tpm: introduce TPM CRB SysBus device Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 01/14] tpm_crb: refactor common code Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 02/14] tpm_crb: CTRL_RSP_ADDR is 64-bits wide Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 03/14] tpm_ppi: refactor memory space initialization Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 04/14] tpm_crb: use a single read-as-mem/write-as-mmio mapping Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 05/14] tpm_crb: move ACPI table building to device interface Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 06/14] tpm-sysbus: add plug handler for TPM on SysBus Joelle van Dyne
2023-10-30 16:52 ` Stefan Berger
2023-10-30 16:55 ` Joelle van Dyne
2023-10-30 17:01 ` Stefan Berger
2023-10-29 6:03 ` [PATCH v3 07/14] hw/arm/virt: connect TPM to platform bus Joelle van Dyne
2023-10-30 23:25 ` Stefan Berger
2023-10-29 6:03 ` [PATCH v3 08/14] hw/loongarch/virt: " Joelle van Dyne
2023-10-30 23:25 ` Stefan Berger
2023-10-29 6:03 ` [PATCH v3 09/14] tpm_tis_sysbus: move DSDT AML generation to device Joelle van Dyne
2023-10-30 20:55 ` Stefan Berger [this message]
2023-10-29 6:03 ` [PATCH v3 10/14] tests: acpi: prepare for TPM CRB tests Joelle van Dyne
2023-10-30 22:18 ` Stefan Berger
2023-10-29 6:03 ` [PATCH v3 11/14] tpm_crb_sysbus: introduce TPM CRB SysBus device Joelle van Dyne
2023-10-30 21:08 ` Stefan Berger
2023-10-30 21:21 ` Stefan Berger
2023-10-31 3:39 ` Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 12/14] tests: acpi: implement TPM CRB tests for ARM virt Joelle van Dyne
2023-10-30 22:19 ` Stefan Berger
2023-10-29 6:03 ` [PATCH v3 13/14] tests: acpi: updated expected blobs for TPM CRB Joelle van Dyne
2023-10-30 22:42 ` Stefan Berger
2023-10-31 0:35 ` Stefan Berger
2023-10-31 3:40 ` Joelle van Dyne
2023-10-29 6:03 ` [PATCH v3 14/14] tests: add TPM-CRB sysbus tests for aarch64 Joelle van Dyne
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=7dbcf9fe-4869-47ad-a2b5-ef91f9c223be@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=anisinha@redhat.com \
--cc=gaosong@loongson.cn \
--cc=imammedo@redhat.com \
--cc=j@getutm.app \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=shannon.zhaosl@gmail.com \
--cc=stefanb@linux.vnet.ibm.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).