Message ID | 20200505144419.29174-4-eric.auger@redhat.com |
---|---|
State | New |
Headers | show |
Series | vTPM/aarch64 ACPI support | expand |
Hi, On 2020/5/5 22:44, Eric Auger wrote: > +static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms) > +{ > + hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base; > + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev); > + MemoryRegion *sbdev_mr; > + SysBusDevice *sbdev; > + hwaddr tpm_base; > + > + sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()), > + TYPE_SYS_BUS_DEVICE); Does it need to check the tpm version like you do in previous patch? tpm_get_version(tpm_find()) == TPM_VERSION_2_0 Thanks, Shannon
On Fri, 8 May 2020 at 17:24, Shannon Zhao <shannon.zhaosl@gmail.com> wrote: > > Hi, > > On 2020/5/5 22:44, Eric Auger wrote: > > +static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms) > > +{ > > + hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base; > > + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev); > > + MemoryRegion *sbdev_mr; > > + SysBusDevice *sbdev; > > + hwaddr tpm_base; > > + > > + sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()), > > + TYPE_SYS_BUS_DEVICE); > > Does it need to check the tpm version like you do in previous patch? > > tpm_get_version(tpm_find()) == TPM_VERSION_2_0 > I don't think so. The device node could in theory be used to describe a TPM 1.2/1.3 as well, even though we never actually do that.
On 5/8/20 11:25 AM, Ard Biesheuvel wrote: > On Fri, 8 May 2020 at 17:24, Shannon Zhao <shannon.zhaosl@gmail.com> wrote: >> Hi, >> >> On 2020/5/5 22:44, Eric Auger wrote: >>> +static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms) >>> +{ >>> + hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base; >>> + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev); >>> + MemoryRegion *sbdev_mr; >>> + SysBusDevice *sbdev; >>> + hwaddr tpm_base; >>> + >>> + sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()), >>> + TYPE_SYS_BUS_DEVICE); >> Does it need to check the tpm version like you do in previous patch? >> >> tpm_get_version(tpm_find()) == TPM_VERSION_2_0 >> > I don't think so. The device node could in theory be used to describe > a TPM 1.2/1.3 as well, even though we never actually do that. There is no TPM 1.3. There may be a TIS v1.3.
On Tue, 5 May 2020 16:44:19 +0200 Eric Auger <eric.auger@redhat.com> wrote: > In case it is dynamically instantiated, add the TPM 2.0 device object > under the DSDT table in the ACPI namespace. Its HID is MSFT0101 > while its current resource settings (CRS) property is initialized > with the guest physical address and MMIO size of the device. > > Signed-off-by: Eric Auger <eric.auger@redhat.com> > Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> > > --- > > v1 -> v2: > - use memory_region_size > - fix mingw compilation issue by casting to uint32_t > - added Stefan's R-b > --- > hw/arm/virt-acpi-build.c | 36 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 36 insertions(+) > > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > index 1a2ec10c8f..8534d14e20 100644 > --- a/hw/arm/virt-acpi-build.c > +++ b/hw/arm/virt-acpi-build.c > @@ -45,6 +45,7 @@ > #include "hw/pci/pcie_host.h" > #include "hw/pci/pci.h" > #include "hw/arm/virt.h" > +#include "hw/platform-bus.h" > #include "sysemu/numa.h" > #include "sysemu/reset.h" > #include "sysemu/tpm.h" > @@ -362,6 +363,40 @@ static void acpi_dsdt_add_power_button(Aml *scope) > aml_append(scope, dev); > } > > +static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms) > +{ > + hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base; > + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev); > + MemoryRegion *sbdev_mr; > + SysBusDevice *sbdev; > + hwaddr tpm_base; > + > + sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()), > + TYPE_SYS_BUS_DEVICE); SYS_BUS_DEVICE(object_dynamic_cast()) > + 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("_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); > +} > + > static void > build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > { > @@ -756,6 +791,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) > } > > acpi_dsdt_add_power_button(scope); > + acpi_dsdt_add_tpm(scope, vms); > > aml_append(dsdt, scope); >
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 1a2ec10c8f..8534d14e20 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -45,6 +45,7 @@ #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" #include "hw/arm/virt.h" +#include "hw/platform-bus.h" #include "sysemu/numa.h" #include "sysemu/reset.h" #include "sysemu/tpm.h" @@ -362,6 +363,40 @@ static void acpi_dsdt_add_power_button(Aml *scope) aml_append(scope, dev); } +static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms) +{ + hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base; + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev); + MemoryRegion *sbdev_mr; + SysBusDevice *sbdev; + hwaddr tpm_base; + + sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()), + TYPE_SYS_BUS_DEVICE); + 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("_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); +} + static void build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { @@ -756,6 +791,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) } acpi_dsdt_add_power_button(scope); + acpi_dsdt_add_tpm(scope, vms); aml_append(dsdt, scope);