Skip to content

Commit d18c574

Browse files
cricard13Jarkko Sakkinen
authored andcommitted
tpm: drop 'irq' from struct tpm_vendor_specific
Dropped the field 'irq' from struct tpm_vendor_specific and make it available to the various private structures in the drivers using irqs. A dedicated flag TPM_CHIP_FLAG_IRQ is added for the upper layers. In st33zp24, struct st33zp24_dev declaration is moved to st33zp24.h in order to make accessible irq from other phy's(i2c, spi). In tpm_i2c_nuvoton, chip->vendor.priv is not directly allocated. We can access irq field from priv_data in a cleaner way. Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent 4490e38 commit d18c574

File tree

9 files changed

+58
-51
lines changed

9 files changed

+58
-51
lines changed

drivers/char/tpm/st33zp24/st33zp24.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ enum tis_defaults {
7373
TIS_LONG_TIMEOUT = 2000,
7474
};
7575

76-
struct st33zp24_dev {
77-
struct tpm_chip *chip;
78-
void *phy_id;
79-
const struct st33zp24_phy_ops *ops;
80-
u32 intrs;
81-
int io_lpcpd;
82-
};
83-
8476
/*
8577
* clear_interruption clear the pending interrupt.
8678
* @param: tpm_dev, the tpm device device.
@@ -288,10 +280,10 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
288280

289281
stop = jiffies + timeout;
290282

291-
if (chip->vendor.irq) {
283+
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
292284
cur_intrs = tpm_dev->intrs;
293285
clear_interruption(tpm_dev);
294-
enable_irq(chip->vendor.irq);
286+
enable_irq(tpm_dev->irq);
295287

296288
do {
297289
if (ret == -ERESTARTSYS && freezing(current))
@@ -314,7 +306,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
314306
}
315307
} while (ret == -ERESTARTSYS && freezing(current));
316308

317-
disable_irq_nosync(chip->vendor.irq);
309+
disable_irq_nosync(tpm_dev->irq);
318310

319311
} else {
320312
do {
@@ -376,7 +368,7 @@ static irqreturn_t tpm_ioserirq_handler(int irq, void *dev_id)
376368

377369
tpm_dev->intrs++;
378370
wake_up_interruptible(&chip->vendor.read_queue);
379-
disable_irq_nosync(chip->vendor.irq);
371+
disable_irq_nosync(tpm_dev->irq);
380372

381373
return IRQ_HANDLED;
382374
} /* tpm_ioserirq_handler() */
@@ -456,7 +448,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
456448
if (ret < 0)
457449
goto out_err;
458450

459-
if (chip->vendor.irq) {
451+
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
460452
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
461453

462454
ret = wait_for_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
@@ -611,9 +603,10 @@ int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
611603
if (ret < 0)
612604
goto _tpm_clean_answer;
613605

614-
chip->vendor.irq = irq;
606+
tpm_dev->irq = irq;
607+
chip->flags |= TPM_CHIP_FLAG_IRQ;
615608

616-
disable_irq_nosync(chip->vendor.irq);
609+
disable_irq_nosync(tpm_dev->irq);
617610

618611
tpm_gen_interrupt(chip);
619612
}

drivers/char/tpm/st33zp24/st33zp24.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
#define TPM_WRITE_DIRECTION 0x80
2222
#define TPM_BUFSIZE 2048
2323

24+
struct st33zp24_dev {
25+
struct tpm_chip *chip;
26+
void *phy_id;
27+
const struct st33zp24_phy_ops *ops;
28+
int irq;
29+
u32 intrs;
30+
int io_lpcpd;
31+
};
32+
33+
2434
struct st33zp24_phy_ops {
2535
int (*send)(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size);
2636
int (*recv)(void *phy_id, u8 tpm_register, u8 *tpm_data, int tpm_size);

drivers/char/tpm/tpm-interface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
359359
goto out;
360360
}
361361

362-
if (chip->vendor.irq)
362+
if (chip->flags & TPM_CHIP_FLAG_IRQ)
363363
goto out_recv;
364364

365365
if (chip->flags & TPM_CHIP_FLAG_TPM2)
@@ -890,7 +890,7 @@ int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
890890

891891
stop = jiffies + timeout;
892892

893-
if (chip->vendor.irq) {
893+
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
894894
again:
895895
timeout = stop - jiffies;
896896
if ((long)timeout <= 0)

drivers/char/tpm/tpm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ enum tpm2_startup_types {
131131
struct tpm_chip;
132132

133133
struct tpm_vendor_specific {
134-
int irq;
135-
136134
int locality;
137135
unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
138136
bool timeout_adjusted;
@@ -154,6 +152,7 @@ struct tpm_vendor_specific {
154152
enum tpm_chip_flags {
155153
TPM_CHIP_FLAG_REGISTERED = BIT(0),
156154
TPM_CHIP_FLAG_TPM2 = BIT(1),
155+
TPM_CHIP_FLAG_IRQ = BIT(2),
157156
};
158157

159158
struct tpm_chip {

drivers/char/tpm/tpm_i2c_atmel.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ static int i2c_atmel_probe(struct i2c_client *client,
173173
chip->vendor.timeout_b = msecs_to_jiffies(TPM_I2C_LONG_TIMEOUT);
174174
chip->vendor.timeout_c = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
175175
chip->vendor.timeout_d = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
176-
chip->vendor.irq = 0;
177176

178177
/* There is no known way to probe for this device, and all version
179178
* information seems to be read via TPM commands. Thus we rely on the

drivers/char/tpm/tpm_i2c_infineon.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,6 @@ static int tpm_tis_i2c_init(struct device *dev)
585585
if (IS_ERR(chip))
586586
return PTR_ERR(chip);
587587

588-
/* Disable interrupts */
589-
chip->vendor.irq = 0;
590-
591588
/* Default timeouts */
592589
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
593590
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);

drivers/char/tpm/tpm_i2c_nuvoton.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define I2C_DRIVER_NAME "tpm_i2c_nuvoton"
5656

5757
struct priv_data {
58+
int irq;
5859
unsigned int intrs;
5960
};
6061

@@ -176,12 +177,12 @@ static bool i2c_nuvoton_check_status(struct tpm_chip *chip, u8 mask, u8 value)
176177
static int i2c_nuvoton_wait_for_stat(struct tpm_chip *chip, u8 mask, u8 value,
177178
u32 timeout, wait_queue_head_t *queue)
178179
{
179-
if (chip->vendor.irq && queue) {
180+
if ((chip->flags & TPM_CHIP_FLAG_IRQ) && queue) {
180181
s32 rc;
181182
struct priv_data *priv = chip->vendor.priv;
182183
unsigned int cur_intrs = priv->intrs;
183184

184-
enable_irq(chip->vendor.irq);
185+
enable_irq(priv->irq);
185186
rc = wait_event_interruptible_timeout(*queue,
186187
cur_intrs != priv->intrs,
187188
timeout);
@@ -477,7 +478,7 @@ static irqreturn_t i2c_nuvoton_int_handler(int dummy, void *dev_id)
477478

478479
priv->intrs++;
479480
wake_up(&chip->vendor.read_queue);
480-
disable_irq_nosync(chip->vendor.irq);
481+
disable_irq_nosync(priv->irq);
481482
return IRQ_HANDLED;
482483
}
483484

@@ -521,6 +522,7 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
521522
int rc;
522523
struct tpm_chip *chip;
523524
struct device *dev = &client->dev;
525+
struct priv_data *priv;
524526
u32 vid = 0;
525527

526528
rc = get_vid(client, &vid);
@@ -534,10 +536,10 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
534536
if (IS_ERR(chip))
535537
return PTR_ERR(chip);
536538

537-
chip->vendor.priv = devm_kzalloc(dev, sizeof(struct priv_data),
538-
GFP_KERNEL);
539-
if (!chip->vendor.priv)
539+
priv = devm_kzalloc(dev, sizeof(struct priv_data), GFP_KERNEL);
540+
if (!priv)
540541
return -ENOMEM;
542+
chip->vendor.priv = priv;
541543

542544
init_waitqueue_head(&chip->vendor.read_queue);
543545

@@ -552,19 +554,21 @@ static int i2c_nuvoton_probe(struct i2c_client *client,
552554
* TPM_INTF_INT_LEVEL_LOW | TPM_INTF_DATA_AVAIL_INT
553555
* The IRQ should be set in the i2c_board_info (which is done
554556
* automatically in of_i2c_register_devices, for device tree users */
555-
chip->vendor.irq = client->irq;
557+
chip->flags |= TPM_CHIP_FLAG_IRQ;
558+
priv->irq = client->irq;
556559

557-
if (chip->vendor.irq) {
558-
dev_dbg(dev, "%s() chip-vendor.irq\n", __func__);
559-
rc = devm_request_irq(dev, chip->vendor.irq,
560+
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
561+
dev_dbg(dev, "%s() priv->irq\n", __func__);
562+
rc = devm_request_irq(dev, client->irq,
560563
i2c_nuvoton_int_handler,
561564
IRQF_TRIGGER_LOW,
562565
dev_name(&chip->dev),
563566
chip);
564567
if (rc) {
565568
dev_err(dev, "%s() Unable to request irq: %d for use\n",
566-
__func__, chip->vendor.irq);
567-
chip->vendor.irq = 0;
569+
__func__, priv->irq);
570+
chip->flags &= ~TPM_CHIP_FLAG_IRQ;
571+
priv->irq = 0;
568572
} else {
569573
/* Clear any pending interrupt */
570574
i2c_nuvoton_ready(chip);

drivers/char/tpm/tpm_tis.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct tpm_info {
9696
struct priv_data {
9797
void __iomem *iobase;
9898
u16 manufacturer_id;
99+
int irq;
99100
bool irq_tested;
100101
wait_queue_head_t int_queue;
101102
};
@@ -177,7 +178,7 @@ static int request_locality(struct tpm_chip *chip, int l)
177178

178179
stop = jiffies + chip->vendor.timeout_a;
179180

180-
if (chip->vendor.irq) {
181+
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
181182
again:
182183
timeout = stop - jiffies;
183184
if ((long)timeout <= 0)
@@ -385,8 +386,9 @@ static void disable_interrupts(struct tpm_chip *chip)
385386
intmask &= ~TPM_GLOBAL_INT_ENABLE;
386387
iowrite32(intmask,
387388
priv->iobase + TPM_INT_ENABLE(chip->vendor.locality));
388-
devm_free_irq(&chip->dev, chip->vendor.irq, chip);
389-
chip->vendor.irq = 0;
389+
devm_free_irq(&chip->dev, priv->irq, chip);
390+
priv->irq = 0;
391+
chip->flags &= ~TPM_CHIP_FLAG_IRQ;
390392
}
391393

392394
/*
@@ -409,7 +411,7 @@ static int tpm_tis_send_main(struct tpm_chip *chip, u8 *buf, size_t len)
409411
iowrite8(TPM_STS_GO,
410412
priv->iobase + TPM_STS(chip->vendor.locality));
411413

412-
if (chip->vendor.irq) {
414+
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
413415
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
414416

415417
if (chip->flags & TPM_CHIP_FLAG_TPM2)
@@ -436,14 +438,16 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
436438
int rc, irq;
437439
struct priv_data *priv = chip->vendor.priv;
438440

439-
if (!chip->vendor.irq || priv->irq_tested)
441+
if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested)
440442
return tpm_tis_send_main(chip, buf, len);
441443

442444
/* Verify receipt of the expected IRQ */
443-
irq = chip->vendor.irq;
444-
chip->vendor.irq = 0;
445+
irq = priv->irq;
446+
priv->irq = 0;
447+
chip->flags &= ~TPM_CHIP_FLAG_IRQ;
445448
rc = tpm_tis_send_main(chip, buf, len);
446-
chip->vendor.irq = irq;
449+
priv->irq = irq;
450+
chip->flags |= TPM_CHIP_FLAG_IRQ;
447451
if (!priv->irq_tested)
448452
msleep(1);
449453
if (!priv->irq_tested)
@@ -605,7 +609,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
605609
irq);
606610
return -1;
607611
}
608-
chip->vendor.irq = irq;
612+
priv->irq = irq;
609613

610614
original_int_vec = ioread8(priv->iobase +
611615
TPM_INT_VECTOR(chip->vendor.locality));
@@ -634,7 +638,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
634638
/* tpm_tis_send will either confirm the interrupt is working or it
635639
* will call disable_irq which undoes all of the above.
636640
*/
637-
if (!chip->vendor.irq) {
641+
if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
638642
iowrite8(original_int_vec,
639643
priv->iobase + TPM_INT_VECTOR(chip->vendor.locality));
640644
return 1;
@@ -797,7 +801,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
797801
if (tpm_info->irq) {
798802
tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
799803
tpm_info->irq);
800-
if (!chip->vendor.irq)
804+
if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
801805
dev_err(&chip->dev, FW_BUG
802806
"TPM interrupt not working, polling instead\n");
803807
} else
@@ -841,7 +845,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
841845

842846
/* reenable interrupts that device may have lost or
843847
BIOS/firmware may have disabled */
844-
iowrite8(chip->vendor.irq, priv->iobase +
848+
iowrite8(priv->irq, priv->iobase +
845849
TPM_INT_VECTOR(chip->vendor.locality));
846850

847851
intmask =
@@ -860,7 +864,7 @@ static int tpm_tis_resume(struct device *dev)
860864
struct tpm_chip *chip = dev_get_drvdata(dev);
861865
int ret;
862866

863-
if (chip->vendor.irq)
867+
if (chip->flags & TPM_CHIP_FLAG_IRQ)
864868
tpm_tis_reenable_interrupts(chip);
865869

866870
ret = tpm_pm_resume(dev);

drivers/char/tpm/xen-tpmfront.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct tpm_private {
2828
unsigned int evtchn;
2929
int ring_ref;
3030
domid_t backend_id;
31+
int irq;
3132
};
3233

3334
enum status_bits {
@@ -217,7 +218,7 @@ static int setup_ring(struct xenbus_device *dev, struct tpm_private *priv)
217218
xenbus_dev_fatal(dev, rv, "allocating TPM irq");
218219
return rv;
219220
}
220-
priv->chip->vendor.irq = rv;
221+
priv->irq = rv;
221222

222223
again:
223224
rv = xenbus_transaction_start(&xbt);
@@ -277,8 +278,8 @@ static void ring_free(struct tpm_private *priv)
277278
else
278279
free_page((unsigned long)priv->shr);
279280

280-
if (priv->chip && priv->chip->vendor.irq)
281-
unbind_from_irqhandler(priv->chip->vendor.irq, priv);
281+
if (priv->irq)
282+
unbind_from_irqhandler(priv->irq, priv);
282283

283284
kfree(priv);
284285
}

0 commit comments

Comments
 (0)