22 #include <linux/module.h>
25 #include <linux/slab.h>
27 #include <linux/wait.h>
67 #define TPM_ACCESS(l) (0x0000 | ((l) << 12))
68 #define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
69 #define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
70 #define TPM_INT_STATUS(l) (0x0010 | ((l) << 12))
71 #define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
72 #define TPM_STS(l) (0x0018 | ((l) << 12))
73 #define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
75 #define TPM_DID_VID(l) (0x0F00 | ((l) << 12))
76 #define TPM_RID(l) (0x0F04 | ((l) << 12))
81 #if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
85 struct acpi_hardware_id *
id;
88 if (!
strcmp(
"INTC0102", id->id))
95 static inline int is_itpm(
struct pnp_dev *dev)
106 return chip->
vendor.locality =
l;
111 static void release_locality(
struct tpm_chip *chip,
int l,
int force)
120 static int request_locality(
struct tpm_chip *chip,
int l)
125 if (check_locality(chip, l) >= 0)
136 if ((
long)timeout <= 0)
151 if (check_locality(chip, l) >= 0)
160 static u8 tpm_tis_status(
struct tpm_chip *chip)
166 static void tpm_tis_ready(
struct tpm_chip *chip)
173 static int get_burstcount(
struct tpm_chip *chip)
180 stop = jiffies + chip->
vendor.timeout_d;
196 int size = 0, burstcnt;
197 while (size < count &&
203 burstcnt = get_burstcount(chip);
204 for (; burstcnt > 0 && size <
count; burstcnt--)
212 static int tpm_tis_recv(
struct tpm_chip *chip,
u8 *buf,
size_t count)
225 dev_err(chip->
dev,
"Unable to read header\n");
230 if (expected > count) {
237 expected - TPM_HEADER_SIZE)) < expected) {
238 dev_err(chip->
dev,
"Unable to read remainder of result\n");
245 status = tpm_tis_status(chip);
254 release_locality(chip, chip->
vendor.locality, 0);
260 MODULE_PARM_DESC(itpm,
"Force iTPM workarounds (found on some Lenovo laptops)");
267 static int tpm_tis_send_data(
struct tpm_chip *chip,
u8 *buf,
size_t len)
272 if (request_locality(chip, 0) < 0)
275 status = tpm_tis_status(chip);
279 (chip, TPM_STS_COMMAND_READY, chip->
vendor.timeout_b,
280 &chip->
vendor.int_queue) < 0) {
286 while (count < len - 1) {
287 burstcnt = get_burstcount(chip);
288 for (; burstcnt > 0 && count < len - 1; burstcnt--) {
296 status = tpm_tis_status(chip);
308 status = tpm_tis_status(chip);
318 release_locality(chip, chip->
vendor.locality, 0);
327 static int tpm_tis_send(
struct tpm_chip *chip,
u8 *buf,
size_t len)
332 rc = tpm_tis_send_data(chip, buf, len);
345 &chip->
vendor.read_queue) < 0) {
353 release_locality(chip, chip->
vendor.locality, 0);
362 static int probe_itpm(
struct tpm_chip *chip)
365 u8 cmd_getticks[] = {
366 0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
367 0x00, 0x00, 0x00, 0xf1
369 size_t len =
sizeof(cmd_getticks);
370 bool rem_itpm = itpm;
379 rc = tpm_tis_send_data(chip, cmd_getticks, len);
384 release_locality(chip, chip->
vendor.locality, 0);
388 rc = tpm_tis_send_data(chip, cmd_getticks, len);
398 release_locality(chip, chip->
vendor.locality, 0);
425 &dev_attr_pubek.attr,
427 &dev_attr_enabled.attr,
428 &dev_attr_active.attr,
429 &dev_attr_owned.attr,
430 &dev_attr_temp_deactivated.attr,
432 &dev_attr_cancel.attr,
433 &dev_attr_durations.attr,
434 &dev_attr_timeouts.attr,
NULL,
442 .status = tpm_tis_status,
443 .recv = tpm_tis_recv,
444 .send = tpm_tis_send,
445 .cancel = tpm_tis_ready,
449 .attr_group = &tis_attr_grp,
465 chip->
vendor.probed_irq = irq;
489 for (i = 0; i < 5; i++)
490 if (check_locality(chip, i) >= 0)
505 static bool interrupts = 1;
513 int rc,
i, irq_s, irq_e, probe;
520 if (!chip->
vendor.iobase) {
531 if (request_locality(chip, 0) != 0) {
539 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
543 probe = probe_itpm(chip);
548 itpm = (probe == 0) ? 0 : 1;
552 dev_info(dev,
"Intel iTPM workaround enabled\n");
559 dev_dbg(dev,
"TPM interface capabilities (0x%x):\n",
562 dev_dbg(dev,
"\tBurst Count Static\n");
564 dev_dbg(dev,
"\tCommand Ready Int Support\n");
566 dev_dbg(dev,
"\tInterrupt Edge Falling\n");
568 dev_dbg(dev,
"\tInterrupt Edge Rising\n");
570 dev_dbg(dev,
"\tInterrupt Level Low\n");
572 dev_dbg(dev,
"\tInterrupt Level High\n");
573 if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
574 dev_dbg(dev,
"\tLocality Change Int Support\n");
576 dev_dbg(dev,
"\tSts Valid Int Support\n");
577 if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
578 dev_dbg(dev,
"\tData Avail Int Support\n");
582 dev_err(dev,
"Could not get TPM timeouts and durations\n");
588 dev_err(dev,
"TPM self test failed\n");
601 intmask |= TPM_INTF_CMD_READY_INT
602 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
610 if (interrupts && !chip->
vendor.irq) {
621 for (i = irq_s; i <= irq_e && chip->
vendor.irq == 0; i++) {
626 chip->
vendor.miscdev.name, chip) != 0) {
628 "Unable to request irq: %d for probe\n",
645 chip->
vendor.probed_irq = 0;
674 chip->
vendor.miscdev.name, chip) != 0) {
676 "Unable to request irq: %d for use\n",
694 INIT_LIST_HEAD(&chip->
vendor.list);
696 list_add(&chip->
vendor.list, &tis_chips);
708 #if defined(CONFIG_PNP) || defined(CONFIG_PM_SLEEP)
709 static void tpm_tis_reenable_interrupts(
struct tpm_chip *chip)
722 intmask |= TPM_INTF_CMD_READY_INT
723 | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
736 unsigned int irq = 0;
738 start = pnp_mem_start(pnp_dev, 0);
739 len = pnp_mem_len(pnp_dev, 0);
741 if (pnp_irq_valid(pnp_dev, 0))
746 if (is_itpm(pnp_dev))
749 return tpm_tis_init(&pnp_dev->
dev, start, len, irq);
757 static int tpm_tis_pnp_resume(
struct pnp_dev *dev)
759 struct tpm_chip *chip = pnp_get_drvdata(dev);
763 tpm_tis_reenable_interrupts(chip);
786 static __devexit void tpm_tis_pnp_remove(
struct pnp_dev *dev)
788 struct tpm_chip *chip = pnp_get_drvdata(dev);
798 .id_table = tpm_pnp_tbl,
799 .probe = tpm_tis_pnp_init,
800 .suspend = tpm_tis_pnp_suspend,
801 .resume = tpm_tis_pnp_resume,
802 .remove = tpm_tis_pnp_remove,
805 #define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
807 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].
id), 0444);
808 MODULE_PARM_DESC(hid,
"Set additional specific HID for this driver to probe");
811 #ifdef CONFIG_PM_SLEEP
812 static int tpm_tis_resume(
struct device *dev)
817 tpm_tis_reenable_interrupts(chip);
838 static int __init init_tis(
void)
849 if (IS_ERR(pdev=platform_device_register_simple(
"tpm_tis", -1,
NULL, 0)))
850 return PTR_ERR(pdev);
858 static void __exit cleanup_tis(
void)
872 release_locality(chip, chip->
vendor.locality, 1);