Commit e8a65015 authored by Marcel Selhorst's avatar Marcel Selhorst Committed by Linus Torvalds

[PATCH] tpm_infineon: Bugfix in PNPACPI-handling

This patch corrects the PNP-handling inside the tpm-driver
and some minor coding style bugs.
Note: the pci-device and pnp-device mixture is currently necessary,
since the used "tpm"-interface requires a pci-dev in order to register
the driver. This will be fixed within the next iterations.
Signed-off-by: default avatarMarcel Selhorst <selhorst@crypto.rub.de>
Cc: Kylene Hall <kjhall@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e770e850
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* License. * License.
*/ */
#include <acpi/acpi_bus.h>
#include <linux/pnp.h> #include <linux/pnp.h>
#include "tpm.h" #include "tpm.h"
...@@ -29,9 +28,10 @@ ...@@ -29,9 +28,10 @@
#define TPM_MAX_TRIES 5000 #define TPM_MAX_TRIES 5000
#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 #define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
/* These values will be filled after ACPI-call */ /* These values will be filled after PnP-call */
static int TPM_INF_DATA = 0; static int TPM_INF_DATA = 0;
static int TPM_INF_ADDR = 0; static int TPM_INF_ADDR = 0;
static int pnp_registered = 0;
/* TPM header definitions */ /* TPM header definitions */
enum infineon_tpm_header { enum infineon_tpm_header {
...@@ -356,24 +356,26 @@ static const struct pnp_device_id tpm_pnp_tbl[] = { ...@@ -356,24 +356,26 @@ static const struct pnp_device_id tpm_pnp_tbl[] = {
{"IFX0102", 0}, {"IFX0102", 0},
{"", 0} {"", 0}
}; };
MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
static int __devinit tpm_inf_acpi_probe(struct pnp_dev *dev, static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
const struct pnp_device_id *dev_id) const struct pnp_device_id *dev_id)
{ {
if (pnp_port_valid(dev, 0)) {
TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff); TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff);
TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff); TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff);
tpm_inf.base = pnp_port_start(dev, 1); tpm_inf.base = pnp_port_start(dev, 1);
dev_info(&dev->dev, "Found %s with ID %s\n", dev_info(&dev->dev, "Found %s with ID %s\n",
dev->name, dev_id->id); dev->name, dev_id->id);
if (!((tpm_inf.base >> 8) & 0xff))
tpm_inf.base = 0;
return 0; return 0;
}
return -ENODEV;
} }
static struct pnp_driver tpm_inf_pnp = { static struct pnp_driver tpm_inf_pnp = {
.name = "tpm_inf_pnp", .name = "tpm_inf_pnp",
.id_table = tpm_pnp_tbl, .id_table = tpm_pnp_tbl,
.probe = tpm_inf_acpi_probe, .probe = tpm_inf_pnp_probe,
}; };
static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
...@@ -386,19 +388,30 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, ...@@ -386,19 +388,30 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
int productid[2]; int productid[2];
char chipname[20]; char chipname[20];
if (pci_enable_device(pci_dev)) rc = pci_enable_device(pci_dev);
return -EIO; if (rc)
return rc;
dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device); dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device);
/* read IO-ports from ACPI */ /* read IO-ports from PnP */
pnp_register_driver(&tpm_inf_pnp); rc = pnp_register_driver(&tpm_inf_pnp);
pnp_unregister_driver(&tpm_inf_pnp); if (rc < 0) {
dev_err(&pci_dev->dev,
"Error %x from pnp_register_driver!\n",rc);
goto error2;
}
if (!rc) {
dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
goto error;
} else {
pnp_registered = 1;
}
/* Make sure, we have received valid config ports */ /* Make sure, we have received valid config ports */
if (!TPM_INF_ADDR) { if (!TPM_INF_ADDR) {
pci_disable_device(pci_dev); dev_err(&pci_dev->dev, "No valid IO-ports received!\n");
return -EIO; goto error;
} }
/* query chip for its vendor, its version number a.s.o. */ /* query chip for its vendor, its version number a.s.o. */
...@@ -418,23 +431,21 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, ...@@ -418,23 +431,21 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
switch ((productid[0] << 8) | productid[1]) { switch ((productid[0] << 8) | productid[1]) {
case 6: case 6:
sprintf(chipname, " (SLD 9630 TT 1.1)"); snprintf(chipname, sizeof(chipname), " (SLD 9630 TT 1.1)");
break; break;
case 11: case 11:
sprintf(chipname, " (SLB 9635 TT 1.2)"); snprintf(chipname, sizeof(chipname), " (SLB 9635 TT 1.2)");
break; break;
default: default:
sprintf(chipname, " (unknown chip)"); snprintf(chipname, sizeof(chipname), " (unknown chip)");
break; break;
} }
chipname[19] = 0;
if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) { if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) {
if (tpm_inf.base == 0) { if (tpm_inf.base == 0) {
dev_err(&pci_dev->dev, "No IO-ports found!\n"); dev_err(&pci_dev->dev, "No IO-ports found!\n");
pci_disable_device(pci_dev); goto error;
return -EIO;
} }
/* configure TPM with IO-ports */ /* configure TPM with IO-ports */
outb(IOLIMH, TPM_INF_ADDR); outb(IOLIMH, TPM_INF_ADDR);
...@@ -452,8 +463,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, ...@@ -452,8 +463,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
dev_err(&pci_dev->dev, dev_err(&pci_dev->dev,
"Could not set IO-ports to %04x\n", "Could not set IO-ports to %04x\n",
tpm_inf.base); tpm_inf.base);
pci_disable_device(pci_dev); goto error;
return -EIO;
} }
/* activate register */ /* activate register */
...@@ -479,14 +489,16 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, ...@@ -479,14 +489,16 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
productid[0], productid[1], chipname); productid[0], productid[1], chipname);
rc = tpm_register_hardware(pci_dev, &tpm_inf); rc = tpm_register_hardware(pci_dev, &tpm_inf);
if (rc < 0) { if (rc < 0)
pci_disable_device(pci_dev); goto error;
return -ENODEV;
}
return 0; return 0;
} else { } else {
dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
error:
pnp_unregister_driver(&tpm_inf_pnp);
error2:
pci_disable_device(pci_dev); pci_disable_device(pci_dev);
pnp_registered = 0;
return -ENODEV; return -ENODEV;
} }
} }
...@@ -521,6 +533,8 @@ static int __init init_inf(void) ...@@ -521,6 +533,8 @@ static int __init init_inf(void)
static void __exit cleanup_inf(void) static void __exit cleanup_inf(void)
{ {
if (pnp_registered)
pnp_unregister_driver(&tpm_inf_pnp);
pci_unregister_driver(&inf_pci_driver); pci_unregister_driver(&inf_pci_driver);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment