All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support
@ 2025-12-03  0:22 Tuan Phan
  2025-12-04  7:14 ` Sunil V L
  2025-12-19  8:29 ` Chao Liu
  0 siblings, 2 replies; 6+ messages in thread
From: Tuan Phan @ 2025-12-03  0:22 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alistair Francis, Sunil V L, Daniel Henrique Barboza, Liu Zhiwei,
	qemu-riscv, Palmer Dabbelt, Weiwei Li, Tuan Phan

This patch enables TPM2 support in the RISC-V virt machine ACPI builder.

Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
---
 hw/riscv/virt-acpi-build.c | 56 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
index f1406cb68339..b5bf812a9d36 100644
--- a/hw/riscv/virt-acpi-build.c
+++ b/hw/riscv/virt-acpi-build.c
@@ -32,6 +32,7 @@
 #include "hw/intc/riscv_aclint.h"
 #include "hw/nvram/fw_cfg_acpi.h"
 #include "hw/pci-host/gpex.h"
+#include "hw/platform-bus.h"
 #include "hw/riscv/virt.h"
 #include "hw/riscv/numa.h"
 #include "hw/virtio/virtio-acpi.h"
@@ -39,6 +40,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "system/reset.h"
+#include "system/tpm.h"
 
 #define ACPI_BUILD_TABLE_SIZE             0x20000
 #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
@@ -224,6 +226,41 @@ static void acpi_dsdt_add_iommu_sys(Aml *scope, const MemMapEntry *iommu_memmap,
     aml_append(scope, dev);
 }
 
+#ifdef CONFIG_TPM
+static void acpi_dsdt_add_tpm(Aml *scope, RISCVVirtState *s)
+{
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(s->platform_bus_dev);
+    hwaddr pbus_base = s->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
+
 /*
  * Serial Port Console Redirection Table (SPCR)
  * Rev: 1.10
@@ -479,6 +516,10 @@ static void build_dsdt(GArray *table_data,
         acpi_dsdt_add_iommu_sys(scope, &memmap[VIRT_IOMMU_SYS], IOMMU_SYS_IRQ);
     }
 
+#ifdef CONFIG_TPM
+    acpi_dsdt_add_tpm(scope, s);
+#endif
+
     if (socket_count == 1) {
         virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base,
                              memmap[VIRT_VIRTIO].size,
@@ -914,6 +955,16 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)
         }
     }
 
+#ifdef CONFIG_TPM
+    /* TPM info */
+    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm2(tables_blob, tables->linker,
+                   tables->tcpalog, s->oem_id,
+                   s->oem_table_id);
+    }
+#endif
+
     /* XSDT is pointed to by RSDP */
     xsdt = tables_blob->len;
     build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
@@ -1025,6 +1076,11 @@ void virt_acpi_setup(RISCVVirtState *s)
                                              build_state, tables.rsdp,
                                              ACPI_BUILD_RSDP_FILE);
 
+#ifdef CONFIG_TPM
+    fw_cfg_add_file(s->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data,
+                    acpi_data_len(tables.tcpalog));
+#endif
+
     qemu_register_reset(virt_acpi_build_reset, build_state);
     virt_acpi_build_reset(build_state);
     vmstate_register(NULL, 0, &vmstate_virt_acpi_build, build_state);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support
  2025-12-03  0:22 [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support Tuan Phan
@ 2025-12-04  7:14 ` Sunil V L
  2025-12-19  8:29 ` Chao Liu
  1 sibling, 0 replies; 6+ messages in thread
From: Sunil V L @ 2025-12-04  7:14 UTC (permalink / raw)
  To: Tuan Phan
  Cc: qemu-devel, Alistair Francis, Daniel Henrique Barboza, Liu Zhiwei,
	qemu-riscv, Palmer Dabbelt, Weiwei Li

Hi Tuan,

On Tue, Dec 02, 2025 at 04:22:59PM -0800, Tuan Phan wrote:
> This patch enables TPM2 support in the RISC-V virt machine ACPI builder.
> 
> Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
> ---
>  hw/riscv/virt-acpi-build.c | 56 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index f1406cb68339..b5bf812a9d36 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -32,6 +32,7 @@
>  #include "hw/intc/riscv_aclint.h"
>  #include "hw/nvram/fw_cfg_acpi.h"
>  #include "hw/pci-host/gpex.h"
> +#include "hw/platform-bus.h"
>  #include "hw/riscv/virt.h"
>  #include "hw/riscv/numa.h"
>  #include "hw/virtio/virtio-acpi.h"
> @@ -39,6 +40,7 @@
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "system/reset.h"
> +#include "system/tpm.h"
>  
>  #define ACPI_BUILD_TABLE_SIZE             0x20000
>  #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
> @@ -224,6 +226,41 @@ static void acpi_dsdt_add_iommu_sys(Aml *scope, const MemMapEntry *iommu_memmap,
>      aml_append(scope, dev);
>  }
>  
> +#ifdef CONFIG_TPM
> +static void acpi_dsdt_add_tpm(Aml *scope, RISCVVirtState *s)
> +{
> +    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(s->platform_bus_dev);
> +    hwaddr pbus_base = s->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
> +
It looks like this logic is duplicated in several places. Would it make
sense to create a shared function for it?

Thanks,
Sunil


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support
  2025-12-03  0:22 [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support Tuan Phan
  2025-12-04  7:14 ` Sunil V L
@ 2025-12-19  8:29 ` Chao Liu
  2026-01-09 19:18   ` Tuan Phan
  1 sibling, 1 reply; 6+ messages in thread
From: Chao Liu @ 2025-12-19  8:29 UTC (permalink / raw)
  To: tphan
  Cc: alistair.francis, dbarboza, liwei1518, palmer, qemu-devel,
	qemu-riscv, sunilvl, zhiwei_liu

On Tue,  2 Dec 2025 16:22:59 -0800, Tuan Phan wrote:
> This patch enables TPM2 support in the RISC-V virt machine ACPI builder.
>
> Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
> ---
>  hw/riscv/virt-acpi-build.c | 56 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
>
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index f1406cb68339..b5bf812a9d36 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -32,6 +32,7 @@
>  #include "hw/intc/riscv_aclint.h"
>  #include "hw/nvram/fw_cfg_acpi.h"
>  #include "hw/pci-host/gpex.h"
> +#include "hw/platform-bus.h"
>  #include "hw/riscv/virt.h"
>  #include "hw/riscv/numa.h"
>  #include "hw/virtio/virtio-acpi.h"
> @@ -39,6 +40,7 @@
>  #include "qapi/error.h"
>  #include "qemu/error-report.h"
>  #include "system/reset.h"
> +#include "system/tpm.h"
>
>  #define ACPI_BUILD_TABLE_SIZE             0x20000
>  #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
> @@ -224,6 +226,41 @@ static void acpi_dsdt_add_iommu_sys(Aml *scope, const
MemMapEntry *iommu_memmap,
>      aml_append(scope, dev);
>  }
>
> +#ifdef CONFIG_TPM
> +static void acpi_dsdt_add_tpm(Aml *scope, RISCVVirtState *s)
> +{
> +    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(s->platform_bus_dev);
> +    hwaddr pbus_base = s->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);
> +
I suggest reporting an error message when the tpm_base check fails.

    if (tpm_base == -1) {
        error_report("Failed to get TPM MMIO address");
        exit(1);
    }

Thanks,
Chao


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support
  2025-12-19  8:29 ` Chao Liu
@ 2026-01-09 19:18   ` Tuan Phan
  0 siblings, 0 replies; 6+ messages in thread
From: Tuan Phan @ 2026-01-09 19:18 UTC (permalink / raw)
  To: Chao Liu
  Cc: alistair.francis, dbarboza, liwei1518, palmer, qemu-devel,
	qemu-riscv, sunilvl, zhiwei_liu

[-- Attachment #1: Type: text/plain, Size: 2207 bytes --]

On Fri, Dec 19, 2025 at 12:30 AM Chao Liu <chao.liu.zevorn@gmail.com> wrote:

> On Tue,  2 Dec 2025 16:22:59 -0800, Tuan Phan wrote:
> > This patch enables TPM2 support in the RISC-V virt machine ACPI builder.
> >
> > Signed-off-by: Tuan Phan <tphan@ventanamicro.com>
> > ---
> >  hw/riscv/virt-acpi-build.c | 56 ++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 56 insertions(+)
> >
> > diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> > index f1406cb68339..b5bf812a9d36 100644
> > --- a/hw/riscv/virt-acpi-build.c
> > +++ b/hw/riscv/virt-acpi-build.c
> > @@ -32,6 +32,7 @@
> >  #include "hw/intc/riscv_aclint.h"
> >  #include "hw/nvram/fw_cfg_acpi.h"
> >  #include "hw/pci-host/gpex.h"
> > +#include "hw/platform-bus.h"
> >  #include "hw/riscv/virt.h"
> >  #include "hw/riscv/numa.h"
> >  #include "hw/virtio/virtio-acpi.h"
> > @@ -39,6 +40,7 @@
> >  #include "qapi/error.h"
> >  #include "qemu/error-report.h"
> >  #include "system/reset.h"
> > +#include "system/tpm.h"
> >
> >  #define ACPI_BUILD_TABLE_SIZE             0x20000
> >  #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
> > @@ -224,6 +226,41 @@ static void acpi_dsdt_add_iommu_sys(Aml *scope,
> const
> MemMapEntry *iommu_memmap,
> >      aml_append(scope, dev);
> >  }
> >
> > +#ifdef CONFIG_TPM
> > +static void acpi_dsdt_add_tpm(Aml *scope, RISCVVirtState *s)
> > +{
> > +    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(s->platform_bus_dev);
> > +    hwaddr pbus_base = s->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);
> > +
> I suggest reporting an error message when the tpm_base check fails.
>
>     if (tpm_base == -1) {
>         error_report("Failed to get TPM MMIO address");
>         exit(1);
>     }
>
> Thanks,
> Chao
>

Thanks Chao, I will change it as per your suggestion. BTW, I will resend
this patch from my new email from Qualcomm.

[-- Attachment #2: Type: text/html, Size: 3112 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support
@ 2026-01-20 19:40 Tuan Phan
  2026-01-26 11:59 ` Daniel Henrique Barboza
  0 siblings, 1 reply; 6+ messages in thread
From: Tuan Phan @ 2026-01-20 19:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Sunil V L, Alistair Francis, Weiwei Li, Daniel Henrique Barboza,
	qemu-riscv, Liu Zhiwei, Palmer Dabbelt, Tuan Phan

This patch enables TPM2 support in the RISC-V virt machine ACPI builder.

Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
---
 hw/riscv/virt-acpi-build.c | 59 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
index f1406cb683..b300492b2f 100644
--- a/hw/riscv/virt-acpi-build.c
+++ b/hw/riscv/virt-acpi-build.c
@@ -32,6 +32,7 @@
 #include "hw/intc/riscv_aclint.h"
 #include "hw/nvram/fw_cfg_acpi.h"
 #include "hw/pci-host/gpex.h"
+#include "hw/core/platform-bus.h"
 #include "hw/riscv/virt.h"
 #include "hw/riscv/numa.h"
 #include "hw/virtio/virtio-acpi.h"
@@ -39,6 +40,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "system/reset.h"
+#include "system/tpm.h"
 
 #define ACPI_BUILD_TABLE_SIZE             0x20000
 #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
@@ -224,6 +226,44 @@ static void acpi_dsdt_add_iommu_sys(Aml *scope, const MemMapEntry *iommu_memmap,
     aml_append(scope, dev);
 }
 
+#ifdef CONFIG_TPM
+static void acpi_dsdt_add_tpm(Aml *scope, RISCVVirtState *s)
+{
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(s->platform_bus_dev);
+    hwaddr pbus_base = s->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);
+    if (tpm_base == -1) {
+        error_report("Failed to get TPM MMIO address");
+        exit(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
+
 /*
  * Serial Port Console Redirection Table (SPCR)
  * Rev: 1.10
@@ -479,6 +519,10 @@ static void build_dsdt(GArray *table_data,
         acpi_dsdt_add_iommu_sys(scope, &memmap[VIRT_IOMMU_SYS], IOMMU_SYS_IRQ);
     }
 
+#ifdef CONFIG_TPM
+    acpi_dsdt_add_tpm(scope, s);
+#endif
+
     if (socket_count == 1) {
         virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base,
                              memmap[VIRT_VIRTIO].size,
@@ -914,6 +958,16 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)
         }
     }
 
+#ifdef CONFIG_TPM
+    /* TPM info */
+    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm2(tables_blob, tables->linker,
+                   tables->tcpalog, s->oem_id,
+                   s->oem_table_id);
+    }
+#endif
+
     /* XSDT is pointed to by RSDP */
     xsdt = tables_blob->len;
     build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
@@ -1025,6 +1079,11 @@ void virt_acpi_setup(RISCVVirtState *s)
                                              build_state, tables.rsdp,
                                              ACPI_BUILD_RSDP_FILE);
 
+#ifdef CONFIG_TPM
+    fw_cfg_add_file(s->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data,
+                    acpi_data_len(tables.tcpalog));
+#endif
+
     qemu_register_reset(virt_acpi_build_reset, build_state);
     virt_acpi_build_reset(build_state);
     vmstate_register(NULL, 0, &vmstate_virt_acpi_build, build_state);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support
  2026-01-20 19:40 Tuan Phan
@ 2026-01-26 11:59 ` Daniel Henrique Barboza
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Henrique Barboza @ 2026-01-26 11:59 UTC (permalink / raw)
  To: Tuan Phan, qemu-devel
  Cc: Sunil V L, Alistair Francis, Weiwei Li, qemu-riscv, Liu Zhiwei,
	Palmer Dabbelt



On 1/20/2026 4:40 PM, Tuan Phan wrote:
> This patch enables TPM2 support in the RISC-V virt machine ACPI builder.
> 
> Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
> ---


Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>

>   hw/riscv/virt-acpi-build.c | 59 ++++++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
> 
> diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c
> index f1406cb683..b300492b2f 100644
> --- a/hw/riscv/virt-acpi-build.c
> +++ b/hw/riscv/virt-acpi-build.c
> @@ -32,6 +32,7 @@
>   #include "hw/intc/riscv_aclint.h"
>   #include "hw/nvram/fw_cfg_acpi.h"
>   #include "hw/pci-host/gpex.h"
> +#include "hw/core/platform-bus.h"
>   #include "hw/riscv/virt.h"
>   #include "hw/riscv/numa.h"
>   #include "hw/virtio/virtio-acpi.h"
> @@ -39,6 +40,7 @@
>   #include "qapi/error.h"
>   #include "qemu/error-report.h"
>   #include "system/reset.h"
> +#include "system/tpm.h"
>   
>   #define ACPI_BUILD_TABLE_SIZE             0x20000
>   #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index))
> @@ -224,6 +226,44 @@ static void acpi_dsdt_add_iommu_sys(Aml *scope, const MemMapEntry *iommu_memmap,
>       aml_append(scope, dev);
>   }
>   
> +#ifdef CONFIG_TPM
> +static void acpi_dsdt_add_tpm(Aml *scope, RISCVVirtState *s)
> +{
> +    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(s->platform_bus_dev);
> +    hwaddr pbus_base = s->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);
> +    if (tpm_base == -1) {
> +        error_report("Failed to get TPM MMIO address");
> +        exit(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
> +
>   /*
>    * Serial Port Console Redirection Table (SPCR)
>    * Rev: 1.10
> @@ -479,6 +519,10 @@ static void build_dsdt(GArray *table_data,
>           acpi_dsdt_add_iommu_sys(scope, &memmap[VIRT_IOMMU_SYS], IOMMU_SYS_IRQ);
>       }
>   
> +#ifdef CONFIG_TPM
> +    acpi_dsdt_add_tpm(scope, s);
> +#endif
> +
>       if (socket_count == 1) {
>           virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base,
>                                memmap[VIRT_VIRTIO].size,
> @@ -914,6 +958,16 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)
>           }
>       }
>   
> +#ifdef CONFIG_TPM
> +    /* TPM info */
> +    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
> +        acpi_add_table(table_offsets, tables_blob);
> +        build_tpm2(tables_blob, tables->linker,
> +                   tables->tcpalog, s->oem_id,
> +                   s->oem_table_id);
> +    }
> +#endif
> +
>       /* XSDT is pointed to by RSDP */
>       xsdt = tables_blob->len;
>       build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id,
> @@ -1025,6 +1079,11 @@ void virt_acpi_setup(RISCVVirtState *s)
>                                                build_state, tables.rsdp,
>                                                ACPI_BUILD_RSDP_FILE);
>   
> +#ifdef CONFIG_TPM
> +    fw_cfg_add_file(s->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data,
> +                    acpi_data_len(tables.tcpalog));
> +#endif
> +
>       qemu_register_reset(virt_acpi_build_reset, build_state);
>       virt_acpi_build_reset(build_state);
>       vmstate_register(NULL, 0, &vmstate_virt_acpi_build, build_state);



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-01-26 12:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-03  0:22 [PATCH] hw/riscv/virt-acpi-build.c: Add TPM2 device node and ACPI table support Tuan Phan
2025-12-04  7:14 ` Sunil V L
2025-12-19  8:29 ` Chao Liu
2026-01-09 19:18   ` Tuan Phan
  -- strict thread matches above, loose matches on Subject: below --
2026-01-20 19:40 Tuan Phan
2026-01-26 11:59 ` Daniel Henrique Barboza

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.