From b4ed3e3cbb312869929cf4528d71e52629a6cacb Mon Sep 17 00:00:00 2001 From: Kylene Jo Hall Date: Sun, 30 Oct 2005 15:03:23 -0800 Subject: [PATCH] tpm: add status function to allow non-lpc bus chips This patch is in preparation of supporting chips that are not necessarily on the lpc bus and thus are not accessed with inb's and outb's. The patch replaces the call to get the chip's status in the tpm.c file with a vendor specific status function. The patch also defines the function for each of the current supported devices. Signed-off-by: Kylene Hall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_infineon.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/char/tpm/tpm_infineon.c') diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index 939e51e119e6..5b2ed539c26f 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -316,6 +316,11 @@ static void tpm_inf_cancel(struct tpm_chip *chip) */ } +static u8 tpm_inf_status(struct tpm_chip *chip) +{ + return inb(chip->vendor->base + 1); +} + static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL); @@ -344,6 +349,7 @@ static struct tpm_vendor_specific tpm_inf = { .recv = tpm_inf_recv, .send = tpm_inf_send, .cancel = tpm_inf_cancel, + .status = tpm_inf_status, .req_complete_mask = 0, .req_complete_val = 0, .attr_group = &inf_attr_grp, -- cgit v1.2.1 From e659a3fe2027b19ecd8abb7ad79253672763454b Mon Sep 17 00:00:00 2001 From: Kylene Jo Hall Date: Sun, 30 Oct 2005 15:03:24 -0800 Subject: [PATCH] tpm: remove pci dependency Since the tpm does not have it's own pci id we have been consuming the lpc bus. This is not correct and causes problems to support non lpc bus chips. This patch removes the dependency on pci_dev from tpm.c The subsequent patches will stop the supported chips from registering as pci drivers. Signed-off-by: Kylene Hall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_infineon.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'drivers/char/tpm/tpm_infineon.c') diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index 5b2ed539c26f..5c3aeaffaf88 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -143,10 +143,10 @@ static int wait(struct tpm_chip *chip, int wait_for_bit) } if (i == TPM_MAX_TRIES) { /* timeout occurs */ if (wait_for_bit == STAT_XFE) - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "Timeout in wait(STAT_XFE)\n"); if (wait_for_bit == STAT_RDA) - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "Timeout in wait(STAT_RDA)\n"); return -EIO; } @@ -170,7 +170,7 @@ static void wait_and_send(struct tpm_chip *chip, u8 sendbyte) static void tpm_wtx(struct tpm_chip *chip) { number_of_wtx++; - dev_info(&chip->pci_dev->dev, "Granting WTX (%02d / %02d)\n", + dev_info(chip->dev, "Granting WTX (%02d / %02d)\n", number_of_wtx, TPM_MAX_WTX_PACKAGES); wait_and_send(chip, TPM_VL_VER); wait_and_send(chip, TPM_CTRL_WTX); @@ -181,7 +181,7 @@ static void tpm_wtx(struct tpm_chip *chip) static void tpm_wtx_abort(struct tpm_chip *chip) { - dev_info(&chip->pci_dev->dev, "Aborting WTX\n"); + dev_info(chip->dev, "Aborting WTX\n"); wait_and_send(chip, TPM_VL_VER); wait_and_send(chip, TPM_CTRL_WTX_ABORT); wait_and_send(chip, 0x00); @@ -206,7 +206,7 @@ recv_begin: } if (buf[0] != TPM_VL_VER) { - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "Wrong transport protocol implementation!\n"); return -EIO; } @@ -221,7 +221,7 @@ recv_begin: } if ((size == 0x6D00) && (buf[1] == 0x80)) { - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "Error handling on vendor layer!\n"); return -EIO; } @@ -234,7 +234,7 @@ recv_begin: } if (buf[1] == TPM_CTRL_WTX) { - dev_info(&chip->pci_dev->dev, "WTX-package received\n"); + dev_info(chip->dev, "WTX-package received\n"); if (number_of_wtx < TPM_MAX_WTX_PACKAGES) { tpm_wtx(chip); goto recv_begin; @@ -245,14 +245,14 @@ recv_begin: } if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) { - dev_info(&chip->pci_dev->dev, "WTX-abort acknowledged\n"); + dev_info(chip->dev, "WTX-abort acknowledged\n"); return size; } if (buf[1] == TPM_CTRL_ERROR) { - dev_err(&chip->pci_dev->dev, "ERROR-package received:\n"); + dev_err(chip->dev, "ERROR-package received:\n"); if (buf[4] == TPM_INF_NAK) - dev_err(&chip->pci_dev->dev, + dev_err(chip->dev, "-> Negative acknowledgement" " - retransmit command!\n"); return -EIO; @@ -271,7 +271,7 @@ static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count) ret = empty_fifo(chip, 1); if (ret) { - dev_err(&chip->pci_dev->dev, "Timeout while clearing FIFO\n"); + dev_err(chip->dev, "Timeout while clearing FIFO\n"); return -EIO; } @@ -494,7 +494,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, vendorid[0], vendorid[1], productid[0], productid[1], chipname); - rc = tpm_register_hardware(pci_dev, &tpm_inf); + rc = tpm_register_hardware(&pci_dev->dev, &tpm_inf); if (rc < 0) goto error; return 0; @@ -509,6 +509,14 @@ error2: } } +static __devexit void tpm_inf_remove(struct pci_dev* pci_dev) +{ + struct tpm_chip* chip = pci_get_drvdata(pci_dev); + + if( chip ) + tpm_remove_hardware(chip->dev); +} + static struct pci_device_id tpm_pci_tbl[] __devinitdata = { {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, @@ -527,7 +535,7 @@ static struct pci_driver inf_pci_driver = { .name = "tpm_inf", .id_table = tpm_pci_tbl, .probe = tpm_inf_probe, - .remove = __devexit_p(tpm_remove), + .remove = __devexit_p(tpm_inf_remove), .suspend = tpm_pm_suspend, .resume = tpm_pm_resume, }; -- cgit v1.2.1 From 1b8333b02aa281a2849331ad62ee595c46a1c5ac Mon Sep 17 00:00:00 2001 From: Marcel Selhorst Date: Sun, 30 Oct 2005 15:03:27 -0800 Subject: [PATCH] Infineon TPM: move infineon driver off pci_dev Move the Infineon TPM driver off pci device and makes it a pure pnp-driver. It includes pnp-port validation and region requesting. Signed-off-by: Marcel Selhorst Signed-off-by: Kylene Hall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_infineon.c | 157 +++++++++++++++------------------------- 1 file changed, 59 insertions(+), 98 deletions(-) (limited to 'drivers/char/tpm/tpm_infineon.c') diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index 5c3aeaffaf88..d356f53c49b4 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -5,6 +5,7 @@ * Specifications at www.trustedcomputinggroup.org * * Copyright (C) 2005, Marcel Selhorst + * Sirrix AG - security technologies, http://www.sirrix.com and * Applied Data Security Group, Ruhr-University Bochum, Germany * Project-Homepage: http://www.prosec.rub.de/tpm * @@ -31,7 +32,8 @@ /* These values will be filled after PnP-call */ static int TPM_INF_DATA = 0; static int TPM_INF_ADDR = 0; -static int pnp_registered = 0; +static int TPM_INF_BASE = 0; +static int TPM_INF_PORT_LEN = 0; /* TPM header definitions */ enum infineon_tpm_header { @@ -143,11 +145,9 @@ static int wait(struct tpm_chip *chip, int wait_for_bit) } if (i == TPM_MAX_TRIES) { /* timeout occurs */ if (wait_for_bit == STAT_XFE) - dev_err(chip->dev, - "Timeout in wait(STAT_XFE)\n"); + dev_err(chip->dev, "Timeout in wait(STAT_XFE)\n"); if (wait_for_bit == STAT_RDA) - dev_err(chip->dev, - "Timeout in wait(STAT_RDA)\n"); + dev_err(chip->dev, "Timeout in wait(STAT_RDA)\n"); return -EIO; } return 0; @@ -221,8 +221,7 @@ recv_begin: } if ((size == 0x6D00) && (buf[1] == 0x80)) { - dev_err(chip->dev, - "Error handling on vendor layer!\n"); + dev_err(chip->dev, "Error handling on vendor layer!\n"); return -EIO; } @@ -318,7 +317,7 @@ static void tpm_inf_cancel(struct tpm_chip *chip) static u8 tpm_inf_status(struct tpm_chip *chip) { - return inb(chip->vendor->base + 1); + return inb(chip->vendor->base + STAT); } static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); @@ -362,30 +361,11 @@ static const struct pnp_device_id tpm_pnp_tbl[] = { {"IFX0102", 0}, {"", 0} }; + MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl); static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev, - const struct pnp_device_id *dev_id) -{ - if (pnp_port_valid(dev, 0)) { - TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff); - TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff); - tpm_inf.base = pnp_port_start(dev, 1); - dev_info(&dev->dev, "Found %s with ID %s\n", - dev->name, dev_id->id); - return 0; - } - return -ENODEV; -} - -static struct pnp_driver tpm_inf_pnp = { - .name = "tpm_inf_pnp", - .id_table = tpm_pnp_tbl, - .probe = tpm_inf_pnp_probe, -}; - -static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, - const struct pci_device_id *pci_id) + const struct pnp_device_id *dev_id) { int rc = 0; u8 iol, ioh; @@ -394,30 +374,28 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, int productid[2]; char chipname[20]; - rc = pci_enable_device(pci_dev); - if (rc) - return rc; - - dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device); - - /* read IO-ports from PnP */ - rc = pnp_register_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; + /* read IO-ports through PnP */ + if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && + !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) { + TPM_INF_ADDR = pnp_port_start(dev, 0); + TPM_INF_DATA = (TPM_INF_ADDR + 1); + TPM_INF_BASE = pnp_port_start(dev, 1); + TPM_INF_PORT_LEN = pnp_port_len(dev, 1); + if (!TPM_INF_PORT_LEN) + return -EINVAL; + dev_info(&dev->dev, "Found %s with ID %s\n", + dev->name, dev_id->id); + if (!((TPM_INF_BASE >> 8) & 0xff)) + return -EINVAL; + /* publish my base address and request region */ + tpm_inf.base = TPM_INF_BASE; + if (request_region + (tpm_inf.base, TPM_INF_PORT_LEN, "tpm_infineon0") == NULL) { + release_region(tpm_inf.base, TPM_INF_PORT_LEN); + return -EINVAL; + } } else { - pnp_registered = 1; - } - - /* Make sure, we have received valid config ports */ - if (!TPM_INF_ADDR) { - dev_err(&pci_dev->dev, "No valid IO-ports received!\n"); - goto error; + return -EINVAL; } /* query chip for its vendor, its version number a.s.o. */ @@ -449,10 +427,6 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) { - if (tpm_inf.base == 0) { - dev_err(&pci_dev->dev, "No IO-ports found!\n"); - goto error; - } /* configure TPM with IO-ports */ outb(IOLIMH, TPM_INF_ADDR); outb(((tpm_inf.base >> 8) & 0xff), TPM_INF_DATA); @@ -466,10 +440,11 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, iol = inb(TPM_INF_DATA); if ((ioh << 8 | iol) != tpm_inf.base) { - dev_err(&pci_dev->dev, + dev_err(&dev->dev, "Could not set IO-ports to %04x\n", tpm_inf.base); - goto error; + release_region(tpm_inf.base, TPM_INF_PORT_LEN); + return -EIO; } /* activate register */ @@ -481,7 +456,7 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, outb(RESET_LP_IRQC_DISABLE, tpm_inf.base + CMD); /* Finally, we're done, print some infos */ - dev_info(&pci_dev->dev, "TPM found: " + dev_info(&dev->dev, "TPM found: " "config base 0x%x, " "io base 0x%x, " "chip version %02x%02x, " @@ -489,67 +464,53 @@ static int __devinit tpm_inf_probe(struct pci_dev *pci_dev, "product id %02x%02x" "%s\n", TPM_INF_ADDR, - tpm_inf.base, + TPM_INF_BASE, version[0], version[1], vendorid[0], vendorid[1], productid[0], productid[1], chipname); - rc = tpm_register_hardware(&pci_dev->dev, &tpm_inf); - if (rc < 0) - goto error; + rc = tpm_register_hardware(&dev->dev, &tpm_inf); + if (rc < 0) { + release_region(tpm_inf.base, TPM_INF_PORT_LEN); + return -ENODEV; + } return 0; } else { - dev_info(&pci_dev->dev, "No Infineon TPM found!\n"); -error: - pnp_unregister_driver(&tpm_inf_pnp); -error2: - pci_disable_device(pci_dev); - pnp_registered = 0; + dev_info(&dev->dev, "No Infineon TPM found!\n"); return -ENODEV; } } -static __devexit void tpm_inf_remove(struct pci_dev* pci_dev) +static __devexit void tpm_inf_pnp_remove(struct pnp_dev *dev) { - struct tpm_chip* chip = pci_get_drvdata(pci_dev); + struct tpm_chip *chip = pnp_get_drvdata(dev); - if( chip ) + if (chip) { + release_region(chip->vendor->base, TPM_INF_PORT_LEN); tpm_remove_hardware(chip->dev); + } } -static struct pci_device_id tpm_pci_tbl[] __devinitdata = { - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)}, - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_2)}, - {0,} -}; - -MODULE_DEVICE_TABLE(pci, tpm_pci_tbl); - -static struct pci_driver inf_pci_driver = { - .name = "tpm_inf", - .id_table = tpm_pci_tbl, - .probe = tpm_inf_probe, - .remove = __devexit_p(tpm_inf_remove), - .suspend = tpm_pm_suspend, - .resume = tpm_pm_resume, +static struct pnp_driver tpm_inf_pnp = { + .name = "tpm_inf_pnp", + .driver = { + .owner = THIS_MODULE, + .suspend = tpm_pm_suspend, + .resume = tpm_pm_resume, + }, + .id_table = tpm_pnp_tbl, + .probe = tpm_inf_pnp_probe, + .remove = tpm_inf_pnp_remove, }; static int __init init_inf(void) { - return pci_register_driver(&inf_pci_driver); + return pnp_register_driver(&tpm_inf_pnp); } static void __exit cleanup_inf(void) { - if (pnp_registered) - pnp_unregister_driver(&tpm_inf_pnp); - pci_unregister_driver(&inf_pci_driver); + pnp_unregister_driver(&tpm_inf_pnp); } module_init(init_inf); @@ -557,5 +518,5 @@ module_exit(cleanup_inf); MODULE_AUTHOR("Marcel Selhorst "); MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2"); -MODULE_VERSION("1.5"); +MODULE_VERSION("1.6"); MODULE_LICENSE("GPL"); -- cgit v1.2.1 From b888c87b7498557d1dbb9de3d4b8402b1bb89193 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 30 Oct 2005 15:03:28 -0800 Subject: [PATCH] tpm-tidies - Various whitespace fixes - Use kzalloc() Acked-by: Kylene Hall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/char/tpm/tpm_infineon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/char/tpm/tpm_infineon.c') diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c index d356f53c49b4..8198dbb7370f 100644 --- a/drivers/char/tpm/tpm_infineon.c +++ b/drivers/char/tpm/tpm_infineon.c @@ -30,10 +30,10 @@ #define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 /* These values will be filled after PnP-call */ -static int TPM_INF_DATA = 0; -static int TPM_INF_ADDR = 0; -static int TPM_INF_BASE = 0; -static int TPM_INF_PORT_LEN = 0; +static int TPM_INF_DATA; +static int TPM_INF_ADDR; +static int TPM_INF_BASE; +static int TPM_INF_PORT_LEN; /* TPM header definitions */ enum infineon_tpm_header { -- cgit v1.2.1