From: Stefan Berger <stefanb@linux.ibm.com>
To: Joelle van Dyne <j@getutm.app>
Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
Ani Sinha <anisinha@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Eduardo Habkost <eduardo@habkost.net>,
Stefan Berger <stefanb@linux.vnet.ibm.com>
Subject: Re: [PATCH v4 05/14] tpm_crb: move ACPI table building to device interface
Date: Fri, 3 Nov 2023 08:43:17 -0400 [thread overview]
Message-ID: <1cf94fa2-bf6b-4817-ac1d-eb9a22793761@linux.ibm.com> (raw)
In-Reply-To: <CA+E+eSACJs1oHPjqT4h7F32+y+HS_en45aVYSPKoUyAmoax11w@mail.gmail.com>
On 11/2/23 22:37, Joelle van Dyne wrote:
> On Thu, Nov 2, 2023 at 11:50 AM Stefan Berger <stefanb@linux.ibm.com> wrote:
>>
>>
>>
>> On 10/31/23 00:00, Joelle van Dyne wrote:
>>> This logic is similar to TPM TIS ISA device. Since TPM CRB can only
>>> support TPM 2.0 backends, we check for this in realize.
>>
>> The problem on x86_64 is that the creation of the ACPI doesn't seem to
>> get invoked. The device then ends up not working under Linux. The
>> problem seems to be
>>
>> .parent = TYPE_DEVICE
>>
>> When I change this to TYPE_ISA_DEVICE it starts generating the ACPI
>> table. I am not sure what other side effects this may have, though.
> Ah sorry, this is probably a side effect of the patch I dropped where
> the bus was moved back from ISA to SysBus. The patch was dropped
> because people complained that the side effects of a new device
> appearing on the ISA bus during migration is unknown. That means we
> will probably have to add some logic to call the ACPI build methods on
> non-ISA devices.
If you moved tpm_crb_build_aml() into a common file like tpm_acpi.c as
tpm_build_aml() it could be called from multiple drivers. For the x86_64
driver I would just call this function from its old location then.
Stefan
>
>>
>> Stefan
>>>
>>> Signed-off-by: Joelle van Dyne <j@getutm.app>
>>> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
>>> ---
>>> hw/tpm/tpm_crb.h | 2 ++
>>> hw/i386/acpi-build.c | 23 -----------------------
>>> hw/tpm/tpm_crb.c | 16 ++++++++++++++++
>>> hw/tpm/tpm_crb_common.c | 19 +++++++++++++++++++
>>> 4 files changed, 37 insertions(+), 23 deletions(-)
>>>
>>> diff --git a/hw/tpm/tpm_crb.h b/hw/tpm/tpm_crb.h
>>> index 36863e1664..e6a86e3fd1 100644
>>> --- a/hw/tpm/tpm_crb.h
>>> +++ b/hw/tpm/tpm_crb.h
>>> @@ -73,5 +73,7 @@ void tpm_crb_init_memory(Object *obj, TPMCRBState *s, Error **errp);
>>> void tpm_crb_mem_save(TPMCRBState *s, uint32_t *saved_regs, void *saved_cmdmem);
>>> void tpm_crb_mem_load(TPMCRBState *s, const uint32_t *saved_regs,
>>> const void *saved_cmdmem);
>>> +void tpm_crb_build_aml(TPMIf *ti, Aml *scope, uint32_t baseaddr, uint32_t size,
>>> + bool build_ppi);
>>>
>>> #endif /* TPM_TPM_CRB_H */
>>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>>> index 80db183b78..ce3f7b2d91 100644
>>> --- a/hw/i386/acpi-build.c
>>> +++ b/hw/i386/acpi-build.c
>>> @@ -1441,9 +1441,6 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
>>> uint32_t nr_mem = machine->ram_slots;
>>> int root_bus_limit = 0xFF;
>>> PCIBus *bus = NULL;
>>> -#ifdef CONFIG_TPM
>>> - TPMIf *tpm = tpm_find();
>>> -#endif
>>> bool cxl_present = false;
>>> int i;
>>> VMBusBridge *vmbus_bridge = vmbus_bridge_find();
>>> @@ -1790,26 +1787,6 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
>>> }
>>> }
>>>
>>> -#ifdef CONFIG_TPM
>>> - if (TPM_IS_CRB(tpm)) {
>>> - dev = aml_device("TPM");
>>> - aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
>>> - aml_append(dev, aml_name_decl("_STR",
>>> - aml_string("TPM 2.0 Device")));
>>> - crs = aml_resource_template();
>>> - aml_append(crs, aml_memory32_fixed(TPM_CRB_ADDR_BASE,
>>> - TPM_CRB_ADDR_SIZE, AML_READ_WRITE));
>>> - aml_append(dev, aml_name_decl("_CRS", crs));
>>> -
>>> - aml_append(dev, aml_name_decl("_STA", aml_int(0xf)));
>>> - aml_append(dev, aml_name_decl("_UID", aml_int(1)));
>>> -
>>> - tpm_build_ppi_acpi(tpm, dev);
>>> -
>>> - aml_append(sb_scope, dev);
>>> - }
>>> -#endif
>>> -
>>> if (pcms->sgx_epc.size != 0) {
>>> uint64_t epc_base = pcms->sgx_epc.base;
>>> uint64_t epc_size = pcms->sgx_epc.size;
>>> diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c
>>> index 99c64dd72a..8d57295b15 100644
>>> --- a/hw/tpm/tpm_crb.c
>>> +++ b/hw/tpm/tpm_crb.c
>>> @@ -19,6 +19,8 @@
>>> #include "qemu/module.h"
>>> #include "qapi/error.h"
>>> #include "exec/address-spaces.h"
>>> +#include "hw/acpi/acpi_aml_interface.h"
>>> +#include "hw/acpi/tpm.h"
>>> #include "hw/qdev-properties.h"
>>> #include "hw/pci/pci_ids.h"
>>> #include "hw/acpi/tpm.h"
>>> @@ -121,6 +123,11 @@ static void tpm_crb_none_realize(DeviceState *dev, Error **errp)
>>> return;
>>> }
>>>
>>> + if (tpm_crb_none_get_version(TPM_IF(s)) != TPM_VERSION_2_0) {
>>> + error_setg(errp, "TPM CRB only supports TPM 2.0 backends");
>>> + return;
>>> + }
>>> +
>>> tpm_crb_init_memory(OBJECT(s), &s->state, errp);
>>>
>>> /* only used for migration */
>>> @@ -142,10 +149,17 @@ static void tpm_crb_none_realize(DeviceState *dev, Error **errp)
>>> }
>>> }
>>>
>>> +static void build_tpm_crb_none_aml(AcpiDevAmlIf *adev, Aml *scope)
>>> +{
>>> + tpm_crb_build_aml(TPM_IF(adev), scope, TPM_CRB_ADDR_BASE, TPM_CRB_ADDR_SIZE,
>>> + true);
>>> +}
>>> +
>>> static void tpm_crb_none_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);
>>>
>>> dc->realize = tpm_crb_none_realize;
>>> device_class_set_props(dc, tpm_crb_none_properties);
>>> @@ -154,6 +168,7 @@ static void tpm_crb_none_class_init(ObjectClass *klass, void *data)
>>> tc->model = TPM_MODEL_TPM_CRB;
>>> tc->get_version = tpm_crb_none_get_version;
>>> tc->request_completed = tpm_crb_none_request_completed;
>>> + adevc->build_dev_aml = build_tpm_crb_none_aml;
>>>
>>> set_bit(DEVICE_CATEGORY_MISC, dc->categories);
>>> }
>>> @@ -166,6 +181,7 @@ static const TypeInfo tpm_crb_none_info = {
>>> .class_init = tpm_crb_none_class_init,
>>> .interfaces = (InterfaceInfo[]) {
>>> { TYPE_TPM_IF },
>>> + { TYPE_ACPI_DEV_AML_IF },
>>> { }
>>> }
>>> };
>>> diff --git a/hw/tpm/tpm_crb_common.c b/hw/tpm/tpm_crb_common.c
>>> index 605e8576e9..4fff0c6b59 100644
>>> --- a/hw/tpm/tpm_crb_common.c
>>> +++ b/hw/tpm/tpm_crb_common.c
>>> @@ -239,3 +239,22 @@ void tpm_crb_mem_load(TPMCRBState *s, const uint32_t *saved_regs,
>>> memcpy(regs, saved_regs, TPM_CRB_R_MAX);
>>> memcpy(®s[R_CRB_DATA_BUFFER], saved_cmdmem, A_CRB_DATA_BUFFER);
>>> }
>>> +
>>> +void tpm_crb_build_aml(TPMIf *ti, Aml *scope, uint32_t baseaddr, uint32_t size,
>>> + bool build_ppi)
>>> +{
>>> + Aml *dev, *crs;
>>> +
>>> + dev = aml_device("TPM");
>>> + 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(1)));
>>> + aml_append(dev, aml_name_decl("_STA", aml_int(0xF)));
>>> + crs = aml_resource_template();
>>> + aml_append(crs, aml_memory32_fixed(baseaddr, size, AML_READ_WRITE));
>>> + aml_append(dev, aml_name_decl("_CRS", crs));
>>> + if (build_ppi) {
>>> + tpm_build_ppi_acpi(ti, dev);
>>> + }
>>> + aml_append(scope, dev);
>>> +}
next prev parent reply other threads:[~2023-11-03 12:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-31 4:00 [PATCH v4 00/14] tpm: introduce TPM CRB SysBus device Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 01/14] tpm_crb: refactor common code Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 02/14] tpm_crb: CTRL_RSP_ADDR is 64-bits wide Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 03/14] tpm_ppi: refactor memory space initialization Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 04/14] tpm_crb: use a single read-as-mem/write-as-mmio mapping Joelle van Dyne
2023-11-01 21:25 ` Stefan Berger
2023-11-14 1:37 ` Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 05/14] tpm_crb: move ACPI table building to device interface Joelle van Dyne
2023-11-02 18:50 ` Stefan Berger
2023-11-03 2:37 ` Joelle van Dyne
2023-11-03 12:43 ` Stefan Berger [this message]
2023-10-31 4:00 ` [PATCH v4 06/14] tpm-sysbus: add plug handler for TPM on SysBus Joelle van Dyne
2023-10-31 13:19 ` Stefan Berger
2023-10-31 4:00 ` [PATCH v4 07/14] hw/arm/virt: connect TPM to platform bus Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 08/14] hw/loongarch/virt: " Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 09/14] tpm_tis_sysbus: move DSDT AML generation to device Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 10/14] tests: acpi: prepare for TPM CRB tests Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 11/14] tpm_crb_sysbus: introduce TPM CRB SysBus device Joelle van Dyne
2023-10-31 13:25 ` Stefan Berger
2023-10-31 4:00 ` [PATCH v4 12/14] tests: acpi: implement TPM CRB tests for ARM virt Joelle van Dyne
2023-10-31 4:00 ` [PATCH v4 13/14] tests: acpi: updated expected blobs for TPM CRB Joelle van Dyne
2023-10-31 12:43 ` Stefan Berger
2023-10-31 4:00 ` [PATCH v4 14/14] tests: add TPM-CRB sysbus tests for aarch64 Joelle van Dyne
2023-10-31 13:05 ` Stefan Berger
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=1cf94fa2-bf6b-4817-ac1d-eb9a22793761@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=anisinha@redhat.com \
--cc=eduardo@habkost.net \
--cc=imammedo@redhat.com \
--cc=j@getutm.app \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--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).