Skip to content

Commit a7b6682

Browse files
stefanbergersrajiv
authored andcommitted
tpm_tis: Fix the probing for interrupts
This patch fixes several aspects of the probing for interrupts. This patch reads the TPM's timeouts before probing for the interrupts. The tpm_get_timeouts() function is invoked in polling mode and gets the proper timeouts from the TPM so that we don't need to fall back to 2 minutes timeouts for short duration commands while the interrupt probing is happening. This patch introduces a variable probed_irq into the vendor structure that gets the irq number if an interrupt is received while the the tpm_gen_interrupt() function is run in polling mode during interrupt probing. Previously some parts of tpm_gen_interrupt() were run in polling mode, then the irq variable was set in the interrupt handler when an interrupt was received and execution of tpm_gen_interrupt() ended up switching over to interrupt mode. tpm_gen_interrupt() execution ended up on an event queue where it eventually timed out since the probing handler doesn't wake any queues. Before calling into free_irq() clear all interrupt flags that may have been set by the TPM. The reason is that free_irq() will call into the probing interrupt handler and may otherwise fool us into thinking that a real interrupt happened (because we see the flags as being set) while the TPM's interrupt line is not even connected to anything on the motherboard. This solves a problem on one machine I did testing on (Thinkpad T60). If a TPM claims to use a specifc interrupt, the probing is done as well to verify that the interrupt is actually working. If a TPM indicates that it does not use a specific interrupt (returns '0'), probe all interrupts from 3 to 15. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
1 parent 20b87bb commit a7b6682

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎drivers/char/tpm/tpm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct tpm_vendor_specific {
7171
unsigned long base; /* TPM base address */
7272

7373
int irq;
74+
int probed_irq;
7475

7576
int region_size;
7677
int have_region;

‎drivers/char/tpm/tpm_tis.c‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static irqreturn_t tis_int_probe(int irq, void *dev_id)
438438
if (interrupt == 0)
439439
return IRQ_NONE;
440440

441-
chip->vendor.irq = irq;
441+
chip->vendor.probed_irq = irq;
442442

443443
/* Clear interrupts handled with TPM_EOI */
444444
iowrite32(interrupt,
@@ -486,7 +486,7 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
486486
resource_size_t len, unsigned int irq)
487487
{
488488
u32 vendor, intfcaps, intmask;
489-
int rc, i;
489+
int rc, i, irq_s, irq_e;
490490
struct tpm_chip *chip;
491491

492492
if (!(chip = tpm_register_hardware(dev, &tpm_tis)))
@@ -544,6 +544,9 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
544544
if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
545545
dev_dbg(dev, "\tData Avail Int Support\n");
546546

547+
/* get the timeouts before testing for irqs */
548+
tpm_get_timeouts(chip);
549+
547550
/* INTERRUPT Setup */
548551
init_waitqueue_head(&chip->vendor.read_queue);
549552
init_waitqueue_head(&chip->vendor.int_queue);
@@ -562,13 +565,19 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
562565
if (interrupts)
563566
chip->vendor.irq = irq;
564567
if (interrupts && !chip->vendor.irq) {
565-
chip->vendor.irq =
568+
irq_s =
566569
ioread8(chip->vendor.iobase +
567570
TPM_INT_VECTOR(chip->vendor.locality));
571+
if (irq_s) {
572+
irq_e = irq_s;
573+
} else {
574+
irq_s = 3;
575+
irq_e = 15;
576+
}
568577

569-
for (i = 3; i < 16 && chip->vendor.irq == 0; i++) {
578+
for (i = irq_s; i <= irq_e && chip->vendor.irq == 0; i++) {
570579
iowrite8(i, chip->vendor.iobase +
571-
TPM_INT_VECTOR(chip->vendor.locality));
580+
TPM_INT_VECTOR(chip->vendor.locality));
572581
if (request_irq
573582
(i, tis_int_probe, IRQF_SHARED,
574583
chip->vendor.miscdev.name, chip) != 0) {
@@ -590,9 +599,22 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
590599
chip->vendor.iobase +
591600
TPM_INT_ENABLE(chip->vendor.locality));
592601

602+
chip->vendor.probed_irq = 0;
603+
593604
/* Generate Interrupts */
594605
tpm_gen_interrupt(chip);
595606

607+
chip->vendor.irq = chip->vendor.probed_irq;
608+
609+
/* free_irq will call into tis_int_probe;
610+
clear all irqs we haven't seen while doing
611+
tpm_gen_interrupt */
612+
iowrite32(ioread32
613+
(chip->vendor.iobase +
614+
TPM_INT_STATUS(chip->vendor.locality)),
615+
chip->vendor.iobase +
616+
TPM_INT_STATUS(chip->vendor.locality));
617+
596618
/* Turn off */
597619
iowrite32(intmask,
598620
chip->vendor.iobase +
@@ -631,7 +653,6 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
631653
list_add(&chip->vendor.list, &tis_chips);
632654
spin_unlock(&tis_lock);
633655

634-
tpm_get_timeouts(chip);
635656
tpm_continue_selftest(chip);
636657

637658
return 0;

0 commit comments

Comments
 (0)