public inbox for linux-integrity@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] tpm_crb: Convert ACPI driver to a platform one
@ 2026-02-23 15:55 Rafael J. Wysocki
  2026-03-03 21:47 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Rafael J. Wysocki @ 2026-02-23 15:55 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Peter Huewe, Jason Gunthorpe, linux-integrity, LKML, Linux ACPI

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

In all cases in which a struct acpi_driver is used for binding a driver
to an ACPI device object, a corresponding platform device is created by
the ACPI core and that device is regarded as a proper representation of
underlying hardware.  Accordingly, a struct platform_driver should be
used by driver code to bind to that device.  There are multiple reasons
why drivers should not bind directly to ACPI device objects [1].

Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the tpm_crb ACPI driver to a platform one.

While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/char/tpm/tpm_crb.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 6c25305c256e..7d1377e8e616 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -15,6 +15,7 @@
 #include <linux/highmem.h>
 #include <linux/rculist.h>
 #include <linux/module.h>
+#include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #ifdef CONFIG_ARM64
 #include <linux/arm-smccc.h>
@@ -602,13 +603,13 @@ static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res,
 	return io_res->end - start + 1;
 }
 
-static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
+static int crb_map_io(struct device *dev, struct crb_priv *priv,
 		      struct acpi_table_tpm2 *buf)
 {
+	struct acpi_device *device = ACPI_COMPANION(dev);
 	struct list_head acpi_resource_list;
 	struct resource iores_array[TPM_CRB_MAX_RESOURCES + 1] = { {0} };
 	void __iomem *iobase_array[TPM_CRB_MAX_RESOURCES] = {NULL};
-	struct device *dev = &device->dev;
 	struct resource *iores;
 	void __iomem **iobase_ptr;
 	int i;
@@ -782,12 +783,13 @@ static int crb_map_pluton(struct device *dev, struct crb_priv *priv,
 	return 0;
 }
 
-static int crb_acpi_add(struct acpi_device *device)
+static int crb_acpi_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
+	struct acpi_device *device = ACPI_COMPANION(dev);
 	struct acpi_table_tpm2 *buf;
 	struct crb_priv *priv;
 	struct tpm_chip *chip;
-	struct device *dev = &device->dev;
 	struct tpm2_crb_smc *crb_smc;
 	struct tpm2_crb_ffa *crb_ffa;
 	struct tpm2_crb_pluton *crb_pluton;
@@ -867,7 +869,7 @@ static int crb_acpi_add(struct acpi_device *device)
 	priv->sm = sm;
 	priv->hid = acpi_device_hid(device);
 
-	rc = crb_map_io(device, priv, buf);
+	rc = crb_map_io(dev, priv, buf);
 	if (rc)
 		goto out;
 
@@ -901,12 +903,9 @@ static int crb_acpi_add(struct acpi_device *device)
 	return rc;
 }
 
-static void crb_acpi_remove(struct acpi_device *device)
+static void crb_acpi_remove(struct platform_device *pdev)
 {
-	struct device *dev = &device->dev;
-	struct tpm_chip *chip = dev_get_drvdata(dev);
-
-	tpm_chip_unregister(chip);
+	tpm_chip_unregister(platform_get_drvdata(pdev));
 }
 
 static const struct dev_pm_ops crb_pm = {
@@ -919,19 +918,17 @@ static const struct acpi_device_id crb_device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, crb_device_ids);
 
-static struct acpi_driver crb_acpi_driver = {
-	.name = "tpm_crb",
-	.ids = crb_device_ids,
-	.ops = {
-		.add = crb_acpi_add,
-		.remove = crb_acpi_remove,
-	},
-	.drv = {
+static struct platform_driver crb_acpi_driver = {
+	.probe = crb_acpi_probe,
+	.remove = crb_acpi_remove,
+	.driver = {
+		.name = "tpm_crb_acpi",
+		.acpi_match_table = crb_device_ids,
 		.pm = &crb_pm,
 	},
 };
 
-module_acpi_driver(crb_acpi_driver);
+module_platform_driver(crb_acpi_driver);
 MODULE_AUTHOR("Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>");
 MODULE_DESCRIPTION("TPM2 Driver");
 MODULE_VERSION("0.1");
-- 
2.51.0





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

* Re: [PATCH v1] tpm_crb: Convert ACPI driver to a platform one
  2026-02-23 15:55 [PATCH v1] tpm_crb: Convert ACPI driver to a platform one Rafael J. Wysocki
@ 2026-03-03 21:47 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2026-03-03 21:47 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Peter Huewe, Jason Gunthorpe, linux-integrity, LKML, Linux ACPI

On Mon, Feb 23, 2026 at 04:55:21PM +0100, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> 
> In all cases in which a struct acpi_driver is used for binding a driver
> to an ACPI device object, a corresponding platform device is created by
> the ACPI core and that device is regarded as a proper representation of
> underlying hardware.  Accordingly, a struct platform_driver should be
> used by driver code to bind to that device.  There are multiple reasons
> why drivers should not bind directly to ACPI device objects [1].
> 
> Overall, it is better to bind drivers to platform devices than to their
> ACPI companions, so convert the tpm_crb ACPI driver to a platform one.
> 
> While this is not expected to alter functionality, it changes sysfs
> layout and so it will be visible to user space.
> 
> Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/char/tpm/tpm_crb.c | 35 ++++++++++++++++-------------------
>  1 file changed, 16 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index 6c25305c256e..7d1377e8e616 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -15,6 +15,7 @@
>  #include <linux/highmem.h>
>  #include <linux/rculist.h>
>  #include <linux/module.h>
> +#include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
>  #ifdef CONFIG_ARM64
>  #include <linux/arm-smccc.h>
> @@ -602,13 +603,13 @@ static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res,
>  	return io_res->end - start + 1;
>  }
>  
> -static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
> +static int crb_map_io(struct device *dev, struct crb_priv *priv,
>  		      struct acpi_table_tpm2 *buf)
>  {
> +	struct acpi_device *device = ACPI_COMPANION(dev);
>  	struct list_head acpi_resource_list;
>  	struct resource iores_array[TPM_CRB_MAX_RESOURCES + 1] = { {0} };
>  	void __iomem *iobase_array[TPM_CRB_MAX_RESOURCES] = {NULL};
> -	struct device *dev = &device->dev;
>  	struct resource *iores;
>  	void __iomem **iobase_ptr;
>  	int i;
> @@ -782,12 +783,13 @@ static int crb_map_pluton(struct device *dev, struct crb_priv *priv,
>  	return 0;
>  }
>  
> -static int crb_acpi_add(struct acpi_device *device)
> +static int crb_acpi_probe(struct platform_device *pdev)
>  {
> +	struct device *dev = &pdev->dev;
> +	struct acpi_device *device = ACPI_COMPANION(dev);
>  	struct acpi_table_tpm2 *buf;
>  	struct crb_priv *priv;
>  	struct tpm_chip *chip;
> -	struct device *dev = &device->dev;
>  	struct tpm2_crb_smc *crb_smc;
>  	struct tpm2_crb_ffa *crb_ffa;
>  	struct tpm2_crb_pluton *crb_pluton;
> @@ -867,7 +869,7 @@ static int crb_acpi_add(struct acpi_device *device)
>  	priv->sm = sm;
>  	priv->hid = acpi_device_hid(device);
>  
> -	rc = crb_map_io(device, priv, buf);
> +	rc = crb_map_io(dev, priv, buf);
>  	if (rc)
>  		goto out;
>  
> @@ -901,12 +903,9 @@ static int crb_acpi_add(struct acpi_device *device)
>  	return rc;
>  }
>  
> -static void crb_acpi_remove(struct acpi_device *device)
> +static void crb_acpi_remove(struct platform_device *pdev)
>  {
> -	struct device *dev = &device->dev;
> -	struct tpm_chip *chip = dev_get_drvdata(dev);
> -
> -	tpm_chip_unregister(chip);
> +	tpm_chip_unregister(platform_get_drvdata(pdev));
>  }
>  
>  static const struct dev_pm_ops crb_pm = {
> @@ -919,19 +918,17 @@ static const struct acpi_device_id crb_device_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(acpi, crb_device_ids);
>  
> -static struct acpi_driver crb_acpi_driver = {
> -	.name = "tpm_crb",
> -	.ids = crb_device_ids,
> -	.ops = {
> -		.add = crb_acpi_add,
> -		.remove = crb_acpi_remove,
> -	},
> -	.drv = {
> +static struct platform_driver crb_acpi_driver = {
> +	.probe = crb_acpi_probe,
> +	.remove = crb_acpi_remove,
> +	.driver = {
> +		.name = "tpm_crb_acpi",
> +		.acpi_match_table = crb_device_ids,
>  		.pm = &crb_pm,
>  	},
>  };
>  
> -module_acpi_driver(crb_acpi_driver);
> +module_platform_driver(crb_acpi_driver);
>  MODULE_AUTHOR("Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>");
>  MODULE_DESCRIPTION("TPM2 Driver");
>  MODULE_VERSION("0.1");
> -- 
> 2.51.0
> 
> 
> 
> 

Yep, historical relic, thank you.

Applied.

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko


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

end of thread, other threads:[~2026-03-03 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 15:55 [PATCH v1] tpm_crb: Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-03 21:47 ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox