[PATCH v3 1/5] hw/tpm: Factor tpm_ppi_enabled() out

Philippe Mathieu-Daudé posted 5 patches 2 weeks, 6 days ago
Maintainers: "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>, Stefan Berger <stefanb@linux.vnet.ibm.com>
[PATCH v3 1/5] hw/tpm: Factor tpm_ppi_enabled() out
Posted by Philippe Mathieu-Daudé 2 weeks, 6 days ago
Factor tpm_ppi_enabled() out before modifying it in a unique place.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/tpm.h | 9 +++++++++
 hw/acpi/tpm.c        | 2 +-
 hw/i386/acpi-build.c | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/system/tpm.h b/include/system/tpm.h
index 1ee568b3b62..b90dd4e8cb0 100644
--- a/include/system/tpm.h
+++ b/include/system/tpm.h
@@ -13,6 +13,7 @@
 #define QEMU_TPM_H
 
 #include "qapi/qapi-types-tpm.h"
+#include "qapi/error.h"
 #include "qom/object.h"
 
 #ifdef CONFIG_TPM
@@ -78,6 +79,14 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
     return TPM_IF_GET_CLASS(ti)->get_version(ti);
 }
 
+static inline bool tpm_ppi_enabled(TPMIf *ti)
+{
+    if (!ti) {
+        return false;
+    }
+    return object_property_get_bool(OBJECT(ti), "ppi", &error_abort);
+}
+
 #else /* CONFIG_TPM */
 
 #define tpm_init()  (0)
diff --git a/hw/acpi/tpm.c b/hw/acpi/tpm.c
index cdc02275365..5fe95f2e3f1 100644
--- a/hw/acpi/tpm.c
+++ b/hw/acpi/tpm.c
@@ -25,7 +25,7 @@ void tpm_build_ppi_acpi(TPMIf *tpm, Aml *dev)
     Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *func_mask,
         *not_implemented, *pak, *tpm2, *tpm3, *pprm, *pprq, *zero, *one;
 
-    if (!object_property_get_bool(OBJECT(tpm), "ppi", &error_abort)) {
+    if (!tpm_ppi_enabled(tpm)) {
         return;
     }
 
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index f622b91b76a..4f01e2c476e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2218,7 +2218,7 @@ void acpi_setup(void)
                     tables.tcpalog->data, acpi_data_len(tables.tcpalog));
 
     tpm = tpm_find();
-    if (tpm && object_property_get_bool(OBJECT(tpm), "ppi", &error_abort)) {
+    if (tpm_ppi_enabled(tpm)) {
         tpm_config = (FwCfgTPMConfig) {
             .tpmppi_address = cpu_to_le32(TPM_PPI_ADDR_BASE),
             .tpm_version = tpm_get_version(tpm),
-- 
2.53.0


Re: [PATCH v3 1/5] hw/tpm: Factor tpm_ppi_enabled() out
Posted by Stefan Berger 2 weeks, 6 days ago

On 3/17/26 8:02 AM, Philippe Mathieu-Daudé wrote:
> Factor tpm_ppi_enabled() out before modifying it in a unique place.

Factor-out ...

> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/system/tpm.h | 9 +++++++++
>   hw/acpi/tpm.c        | 2 +-
>   hw/i386/acpi-build.c | 2 +-
>   3 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/include/system/tpm.h b/include/system/tpm.h
> index 1ee568b3b62..b90dd4e8cb0 100644
> --- a/include/system/tpm.h
> +++ b/include/system/tpm.h
> @@ -13,6 +13,7 @@
>   #define QEMU_TPM_H
> 
>   #include "qapi/qapi-types-tpm.h"
> +#include "qapi/error.h"
>   #include "qom/object.h"
> 
>   #ifdef CONFIG_TPM
> @@ -78,6 +79,14 @@ static inline TPMVersion tpm_get_version(TPMIf *ti)
>       return TPM_IF_GET_CLASS(ti)->get_version(ti);
>   }
> 
> +static inline bool tpm_ppi_enabled(TPMIf *ti)
> +{
> +    if (!ti) {
> +        return false;
> +    }
> +    return object_property_get_bool(OBJECT(ti), "ppi", &error_abort);
> +}
> +
>   #else /* CONFIG_TPM */
> 
>   #define tpm_init()  (0)
> diff --git a/hw/acpi/tpm.c b/hw/acpi/tpm.c
> index cdc02275365..5fe95f2e3f1 100644
> --- a/hw/acpi/tpm.c
> +++ b/hw/acpi/tpm.c
> @@ -25,7 +25,7 @@ void tpm_build_ppi_acpi(TPMIf *tpm, Aml *dev)
>       Aml *method, *field, *ifctx, *ifctx2, *ifctx3, *func_mask,
>           *not_implemented, *pak, *tpm2, *tpm3, *pprm, *pprq, *zero, *one;
> 
> -    if (!object_property_get_bool(OBJECT(tpm), "ppi", &error_abort)) {
> +    if (!tpm_ppi_enabled(tpm)) {
>           return;
>       }
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index f622b91b76a..4f01e2c476e 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -2218,7 +2218,7 @@ void acpi_setup(void)
>                       tables.tcpalog->data, acpi_data_len(tables.tcpalog));
> 
>       tpm = tpm_find();
> -    if (tpm && object_property_get_bool(OBJECT(tpm), "ppi", &error_abort)) {
> +    if (tpm_ppi_enabled(tpm)) {
>           tpm_config = (FwCfgTPMConfig) {
>               .tpmppi_address = cpu_to_le32(TPM_PPI_ADDR_BASE),
>               .tpm_version = tpm_get_version(tpm),

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>