From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
"Martin Wilck" <Martin.Wilck@ts.fujitsu.com>,
"Peter Huewe" <peterhuewe@gmx.de>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH v3 5/7] tpm_tis: Clean up the force=1 module parameter
Date: Sun, 3 Jan 2016 19:26:50 +0200 [thread overview]
Message-ID: <20160103172650.GD4155@intel.com> (raw)
In-Reply-To: <1450376600-6970-6-git-send-email-jgunthorpe@obsidianresearch.com>
On Thu, Dec 17, 2015 at 11:23:18AM -0700, Jason Gunthorpe wrote:
> The TPM core has long assumed that every device has a driver attached,
> however the force path was attaching the TPM core outside of a driver
> context. This isn't generally reliable as the user could detatch the
> driver using sysfs or something, but commit b8b2c7d845d5 ("base/platform:
> assert that dev_pm_domain callbacks are called unconditionally")
> forced the issue by leaving the driver pointer NULL if there is
> no probe.
>
> Rework the TPM setup to create a platform device with resources and
> then allow the driver core to naturally bind and probe it through the
> normal mechanisms. All this structure is needed anyhow to enable TPM
> for OF environments.
>
> Finally, since the entire flow is changing convert the init/exit to use
> the modern ifdef-less coding style when possible
>
> Reported-by: "Wilck, Martin" <martin.wilck@ts.fujitsu.com>
> Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> Tested-by: Wilck, Martin <martin.wilck@ts.fujitsu.com>
> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
> drivers/char/tpm/tpm_tis.c | 173 +++++++++++++++++++++++++++------------------
> 1 file changed, 106 insertions(+), 67 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
> index 856fb35e574c..12aa96a69b6c 100644
> --- a/drivers/char/tpm/tpm_tis.c
> +++ b/drivers/char/tpm/tpm_tis.c
> @@ -60,7 +60,6 @@ enum tis_int_flags {
> };
>
> enum tis_defaults {
> - TIS_MEM_BASE = 0xFED40000,
> TIS_MEM_LEN = 0x5000,
> TIS_SHORT_TIMEOUT = 750, /* ms */
> TIS_LONG_TIMEOUT = 2000, /* 2 sec */
> @@ -75,15 +74,6 @@ struct tpm_info {
> int irq;
> };
>
> -static struct tpm_info tis_default_info = {
> - .res = {
> - .start = TIS_MEM_BASE,
> - .end = TIS_MEM_BASE + TIS_MEM_LEN - 1,
> - .flags = IORESOURCE_MEM,
> - },
> - .irq = 0,
> -};
> -
> /* Some timeout values are needed before it is known whether the chip is
> * TPM 1.0 or TPM 2.0.
> */
> @@ -695,8 +685,8 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
> #endif
>
> chip->vendor.iobase = devm_ioremap_resource(dev, &tpm_info->res);
> - if (!chip->vendor.iobase)
> - return -EIO;
> + if (IS_ERR(chip->vendor.iobase))
> + return PTR_ERR(chip->vendor.iobase);
Isn't this a regression in the descendig patch in this series?
> /* Maximum timeouts */
> chip->vendor.timeout_a = TIS_TIMEOUT_A_MAX;
> @@ -825,7 +815,6 @@ out_err:
> return rc;
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
> {
> u32 intmask;
> @@ -867,11 +856,9 @@ static int tpm_tis_resume(struct device *dev)
>
> return 0;
> }
> -#endif
>
> static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
>
> -#ifdef CONFIG_PNP
> static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
> const struct pnp_device_id *pnp_id)
> {
> @@ -889,14 +876,12 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
> else
> tpm_info.irq = -1;
>
> -#ifdef CONFIG_ACPI
> if (pnp_acpi_device(pnp_dev)) {
> if (is_itpm(pnp_acpi_device(pnp_dev)))
> itpm = true;
>
> - acpi_dev_handle = pnp_acpi_device(pnp_dev)->handle;
> + acpi_dev_handle = ACPI_HANDLE(&pnp_dev->dev);
> }
> -#endif
>
> return tpm_tis_init(&pnp_dev->dev, &tpm_info, acpi_dev_handle);
> }
> @@ -937,7 +922,6 @@ static struct pnp_driver tis_pnp_driver = {
> module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
> sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
> MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
> -#endif
>
> #ifdef CONFIG_ACPI
> static int tpm_check_resource(struct acpi_resource *ares, void *data)
> @@ -1024,80 +1008,135 @@ static struct acpi_driver tis_acpi_driver = {
> };
> #endif
>
> +static struct platform_device *force_pdev;
> +
> +static int tpm_tis_plat_probe(struct platform_device *pdev)
> +{
> + struct tpm_info tpm_info = {};
> + struct resource *res;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + if (res == NULL) {
> + dev_err(&pdev->dev, "no memory resource defined\n");
> + return -ENODEV;
> + }
> + tpm_info.res = *res;
> +
> + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> + if (res) {
> + tpm_info.irq = res->start;
> + } else {
> + if (pdev == force_pdev)
> + tpm_info.irq = -1;
> + else
> + /* When forcing auto probe the IRQ */
> + tpm_info.irq = 0;
> + }
> +
> + return tpm_tis_init(&pdev->dev, &tpm_info, NULL);
> +}
> +
> +static int tpm_tis_plat_remove(struct platform_device *pdev)
> +{
> + struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
> +
> + tpm_chip_unregister(chip);
> + tpm_tis_remove(chip);
> +
> + return 0;
> +}
> +
> static struct platform_driver tis_drv = {
> + .probe = tpm_tis_plat_probe,
> + .remove = tpm_tis_plat_remove,
> .driver = {
> .name = "tpm_tis",
> .pm = &tpm_tis_pm,
> },
> };
>
> -static struct platform_device *pdev;
> -
> static bool force;
> +#ifdef CONFIG_X86
> module_param(force, bool, 0444);
> MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
> +#endif
> +
> +static int tpm_tis_force_device(void)
> +{
> + struct platform_device *pdev;
> + static const struct resource x86_resources[] = {
> + {
> + .start = 0xFED40000,
> + .end = 0xFED40000 + TIS_MEM_LEN - 1,
> + .flags = IORESOURCE_MEM,
> + },
> + };
> +
> + if (!force)
> + return 0;
> +
> + /* The driver core will match the name tpm_tis of the device to
> + * the tpm_tis platform driver and complete the setup via
> + * tpm_tis_plat_probe
> + */
> + pdev = platform_device_register_simple("tpm_tis", -1, x86_resources,
> + ARRAY_SIZE(x86_resources));
> + if (IS_ERR(pdev))
> + return PTR_ERR(pdev);
> + force_pdev = pdev;
> +
> + return 0;
> +}
> +
> static int __init init_tis(void)
> {
> int rc;
> -#ifdef CONFIG_PNP
> - if (!force) {
> - rc = pnp_register_driver(&tis_pnp_driver);
> - if (rc)
> - return rc;
> - }
> -#endif
> +
> + rc = tpm_tis_force_device();
> + if (rc)
> + goto err_force;
> +
> + rc = platform_driver_register(&tis_drv);
> + if (rc)
> + goto err_platform;
> +
> #ifdef CONFIG_ACPI
> - if (!force) {
> - rc = acpi_bus_register_driver(&tis_acpi_driver);
> - if (rc) {
> -#ifdef CONFIG_PNP
> - pnp_unregister_driver(&tis_pnp_driver);
> -#endif
> - return rc;
> - }
> - }
> + rc = acpi_bus_register_driver(&tis_acpi_driver);
> + if (rc)
> + goto err_acpi;
> #endif
> - if (!force)
> - return 0;
>
> - rc = platform_driver_register(&tis_drv);
> - if (rc < 0)
> - return rc;
> - pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0);
> - if (IS_ERR(pdev)) {
> - rc = PTR_ERR(pdev);
> - goto err_dev;
> + if (IS_ENABLED(CONFIG_PNP)) {
> + rc = pnp_register_driver(&tis_pnp_driver);
> + if (rc)
> + goto err_pnp;
> }
> - rc = tpm_tis_init(&pdev->dev, &tis_default_info, NULL);
> - if (rc)
> - goto err_init;
> +
> return 0;
> -err_init:
> - platform_device_unregister(pdev);
> -err_dev:
> - platform_driver_unregister(&tis_drv);
> +
> +err_pnp:
> +#ifdef CONFIG_ACPI
> + acpi_bus_unregister_driver(&tis_acpi_driver);
> +err_acpi:
> +#endif
> + platform_device_unregister(force_pdev);
> +err_platform:
> + if (force_pdev)
> + platform_device_unregister(force_pdev);
> +err_force:
> return rc;
> }
>
> static void __exit cleanup_tis(void)
> {
> - struct tpm_chip *chip;
> -#if defined(CONFIG_PNP) || defined(CONFIG_ACPI)
> - if (!force) {
> + pnp_unregister_driver(&tis_pnp_driver);
> #ifdef CONFIG_ACPI
> - acpi_bus_unregister_driver(&tis_acpi_driver);
> -#endif
> -#ifdef CONFIG_PNP
> - pnp_unregister_driver(&tis_pnp_driver);
> -#endif
> - return;
> - }
> + acpi_bus_unregister_driver(&tis_acpi_driver);
> #endif
> - chip = dev_get_drvdata(&pdev->dev);
> - tpm_chip_unregister(chip);
> - tpm_tis_remove(chip);
> - platform_device_unregister(pdev);
> platform_driver_unregister(&tis_drv);
> +
> + if (force_pdev)
> + platform_device_unregister(force_pdev);
> }
>
> module_init(init_tis);
> --
> 2.1.4
>
/Jarkko
next prev parent reply other threads:[~2016-01-03 17:26 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-17 18:23 [PATCH v3 0/7] tpm_tis: Clean up force module parameter Jason Gunthorpe
2015-12-17 18:23 ` [PATCH v3 1/7] tpm_crb: Use the common ACPI definition of struct acpi_tpm2 Jason Gunthorpe
[not found] ` <1450376600-6970-2-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-03 17:09 ` Jarkko Sakkinen
2016-01-03 17:09 ` Jarkko Sakkinen
[not found] ` <20160103170906.GA4155-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-01-04 18:23 ` Jason Gunthorpe
2016-01-04 18:23 ` Jason Gunthorpe
[not found] ` <20160104182317.GB20016-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-04 18:49 ` Jarkko Sakkinen
2016-01-04 18:49 ` Jarkko Sakkinen
2015-12-17 18:23 ` [PATCH v3 2/7] tpm_tis: Disable interrupt auto probing on a per-device basis Jason Gunthorpe
[not found] ` <1450376600-6970-3-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-03 17:20 ` Jarkko Sakkinen
2016-01-03 17:20 ` Jarkko Sakkinen
[not found] ` <20160103172040.GB4155-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-01-04 18:24 ` Jason Gunthorpe
2016-01-04 18:24 ` Jason Gunthorpe
[not found] ` <20160104182442.GC20016-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-04 18:32 ` Jarkko Sakkinen
2016-01-04 18:32 ` Jarkko Sakkinen
2015-12-17 18:23 ` [PATCH v3 3/7] tpm_tis: Do not fall back to a hardcoded address for TPM2 Jason Gunthorpe
[not found] ` <1450376600-6970-4-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-12-18 9:34 ` Jarkko Sakkinen
2015-12-18 9:34 ` Jarkko Sakkinen
2015-12-18 16:51 ` Jason Gunthorpe
[not found] ` <20151218165127.GC7354-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2015-12-20 12:34 ` Jarkko Sakkinen
2015-12-20 12:34 ` Jarkko Sakkinen
2015-12-17 18:23 ` [PATCH v3 4/7] tpm_tis: Use devm_ioremap_resource Jason Gunthorpe
[not found] ` <1450376600-6970-5-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-03 17:23 ` Jarkko Sakkinen
2016-01-03 17:23 ` Jarkko Sakkinen
2015-12-17 18:23 ` [PATCH v3 5/7] tpm_tis: Clean up the force=1 module parameter Jason Gunthorpe
2016-01-03 17:26 ` Jarkko Sakkinen [this message]
2016-01-04 18:27 ` Jason Gunthorpe
2015-12-17 18:23 ` [PATCH v3 6/7] tpm_crb: Drop le32_to_cpu(ioread32(..)) Jason Gunthorpe
[not found] ` <1450376600-6970-7-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-03 17:28 ` Jarkko Sakkinen
2016-01-03 17:28 ` Jarkko Sakkinen
2015-12-17 18:23 ` [PATCH v3 7/7] tpm_crb: Use devm_ioremap_resource Jason Gunthorpe
[not found] ` <1450376600-6970-8-git-send-email-jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-01-03 17:32 ` Jarkko Sakkinen
2016-01-03 17:32 ` Jarkko Sakkinen
[not found] ` <20160103173213.GF4155-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-01-04 18:30 ` Jason Gunthorpe
2016-01-04 18:30 ` Jason Gunthorpe
2016-01-04 19:43 ` Jarkko Sakkinen
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=20160103172650.GD4155@intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=Martin.Wilck@ts.fujitsu.com \
--cc=jgunthorpe@obsidianresearch.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=tpmdd-devel@lists.sourceforge.net \
--cc=u.kleine-koenig@pengutronix.de \
/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 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.