Skip to content

Commit c7586a4

Browse files
cricard13Jarkko Sakkinen
authored andcommitted
tpm: Move tpm_vendor_specific data related with PTP specification to tpm_chip
Move tpm_vendor_specific data related to TCG PTP specification to tpm_chip. Move all fields directly linked with well known TCG concepts and used in TPM drivers (tpm_i2c_atmel, tpm_i2c_infineon, tpm_i2c_nuvoton, tpm_tis and xen-tpmfront) as well as in TPM core files (tpm-sysfs, tpm-interface and tpm2-cmd) in tpm_chip. 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 de44b20 commit c7586a4

File tree

10 files changed

+91
-88
lines changed

10 files changed

+91
-88
lines changed

drivers/char/tpm/st33zp24/st33zp24.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int request_locality(struct tpm_chip *chip)
163163
if (ret < 0)
164164
return ret;
165165

166-
stop = jiffies + chip->vendor.timeout_a;
166+
stop = jiffies + chip->timeout_a;
167167

168168
/* Request locality is usually effective after the request */
169169
do {
@@ -205,7 +205,7 @@ static int get_burstcount(struct tpm_chip *chip)
205205

206206
tpm_dev = (struct st33zp24_dev *)TPM_VPRIV(chip);
207207

208-
stop = jiffies + chip->vendor.timeout_d;
208+
stop = jiffies + chip->timeout_d;
209209
do {
210210
status = tpm_dev->ops->recv(tpm_dev->phy_id, TPM_STS + 1,
211211
&temp, 1);
@@ -337,7 +337,7 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
337337
while (size < count &&
338338
wait_for_stat(chip,
339339
TPM_STS_DATA_AVAIL | TPM_STS_VALID,
340-
chip->vendor.timeout_c,
340+
chip->timeout_c,
341341
&tpm_dev->read_queue, true) == 0) {
342342
burstcnt = get_burstcount(chip);
343343
if (burstcnt < 0)
@@ -406,7 +406,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned char *buf,
406406
if ((status & TPM_STS_COMMAND_READY) == 0) {
407407
st33zp24_cancel(chip);
408408
if (wait_for_stat
409-
(chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
409+
(chip, TPM_STS_COMMAND_READY, chip->timeout_b,
410410
&tpm_dev->read_queue, false) < 0) {
411411
ret = -ETIME;
412412
goto out_err;
@@ -561,10 +561,10 @@ int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
561561
tpm_dev->phy_id = phy_id;
562562
tpm_dev->ops = ops;
563563

564-
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
565-
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
566-
chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
567-
chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
564+
chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
565+
chip->timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
566+
chip->timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
567+
chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
568568

569569
tpm_dev->locality = LOCALITY0;
570570

@@ -673,7 +673,7 @@ int st33zp24_pm_resume(struct device *dev)
673673
if (gpio_is_valid(tpm_dev->io_lpcpd)) {
674674
gpio_set_value(tpm_dev->io_lpcpd, 1);
675675
ret = wait_for_stat(chip,
676-
TPM_STS_VALID, chip->vendor.timeout_b,
676+
TPM_STS_VALID, chip->timeout_b,
677677
&tpm_dev->read_queue, false);
678678
} else {
679679
ret = tpm_pm_resume(dev);

drivers/char/tpm/tpm-interface.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
319319
duration_idx = tpm_ordinal_duration[ordinal];
320320

321321
if (duration_idx != TPM_UNDEFINED)
322-
duration = chip->vendor.duration[duration_idx];
322+
duration = chip->duration[duration_idx];
323323
if (duration <= 0)
324324
return 2 * 60 * HZ;
325325
else
@@ -505,15 +505,15 @@ int tpm_get_timeouts(struct tpm_chip *chip)
505505

506506
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
507507
/* Fixed timeouts for TPM2 */
508-
chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
509-
chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
510-
chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
511-
chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
512-
chip->vendor.duration[TPM_SHORT] =
508+
chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
509+
chip->timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
510+
chip->timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
511+
chip->timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
512+
chip->duration[TPM_SHORT] =
513513
msecs_to_jiffies(TPM2_DURATION_SHORT);
514-
chip->vendor.duration[TPM_MEDIUM] =
514+
chip->duration[TPM_MEDIUM] =
515515
msecs_to_jiffies(TPM2_DURATION_MEDIUM);
516-
chip->vendor.duration[TPM_LONG] =
516+
chip->duration[TPM_LONG] =
517517
msecs_to_jiffies(TPM2_DURATION_LONG);
518518
return 0;
519519
}
@@ -561,23 +561,23 @@ int tpm_get_timeouts(struct tpm_chip *chip)
561561
* of misreporting.
562562
*/
563563
if (chip->ops->update_timeouts != NULL)
564-
chip->vendor.timeout_adjusted =
564+
chip->timeout_adjusted =
565565
chip->ops->update_timeouts(chip, new_timeout);
566566

567-
if (!chip->vendor.timeout_adjusted) {
567+
if (!chip->timeout_adjusted) {
568568
/* Don't overwrite default if value is 0 */
569569
if (new_timeout[0] != 0 && new_timeout[0] < 1000) {
570570
int i;
571571

572572
/* timeouts in msec rather usec */
573573
for (i = 0; i != ARRAY_SIZE(new_timeout); i++)
574574
new_timeout[i] *= 1000;
575-
chip->vendor.timeout_adjusted = true;
575+
chip->timeout_adjusted = true;
576576
}
577577
}
578578

579579
/* Report adjusted timeouts */
580-
if (chip->vendor.timeout_adjusted) {
580+
if (chip->timeout_adjusted) {
581581
dev_info(&chip->dev,
582582
HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
583583
old_timeout[0], new_timeout[0],
@@ -586,10 +586,10 @@ int tpm_get_timeouts(struct tpm_chip *chip)
586586
old_timeout[3], new_timeout[3]);
587587
}
588588

589-
chip->vendor.timeout_a = usecs_to_jiffies(new_timeout[0]);
590-
chip->vendor.timeout_b = usecs_to_jiffies(new_timeout[1]);
591-
chip->vendor.timeout_c = usecs_to_jiffies(new_timeout[2]);
592-
chip->vendor.timeout_d = usecs_to_jiffies(new_timeout[3]);
589+
chip->timeout_a = usecs_to_jiffies(new_timeout[0]);
590+
chip->timeout_b = usecs_to_jiffies(new_timeout[1]);
591+
chip->timeout_c = usecs_to_jiffies(new_timeout[2]);
592+
chip->timeout_d = usecs_to_jiffies(new_timeout[3]);
593593

594594
duration:
595595
tpm_cmd.header.in = tpm_getcap_header;
@@ -608,23 +608,23 @@ int tpm_get_timeouts(struct tpm_chip *chip)
608608
return -EINVAL;
609609

610610
duration_cap = &tpm_cmd.params.getcap_out.cap.duration;
611-
chip->vendor.duration[TPM_SHORT] =
611+
chip->duration[TPM_SHORT] =
612612
usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short));
613-
chip->vendor.duration[TPM_MEDIUM] =
613+
chip->duration[TPM_MEDIUM] =
614614
usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_medium));
615-
chip->vendor.duration[TPM_LONG] =
615+
chip->duration[TPM_LONG] =
616616
usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_long));
617617

618618
/* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above
619619
* value wrong and apparently reports msecs rather than usecs. So we
620620
* fix up the resulting too-small TPM_SHORT value to make things work.
621621
* We also scale the TPM_MEDIUM and -_LONG values by 1000.
622622
*/
623-
if (chip->vendor.duration[TPM_SHORT] < (HZ / 100)) {
624-
chip->vendor.duration[TPM_SHORT] = HZ;
625-
chip->vendor.duration[TPM_MEDIUM] *= 1000;
626-
chip->vendor.duration[TPM_LONG] *= 1000;
627-
chip->vendor.duration_adjusted = true;
623+
if (chip->duration[TPM_SHORT] < (HZ / 100)) {
624+
chip->duration[TPM_SHORT] = HZ;
625+
chip->duration[TPM_MEDIUM] *= 1000;
626+
chip->duration[TPM_LONG] *= 1000;
627+
chip->duration_adjusted = true;
628628
dev_info(&chip->dev, "Adjusting TPM timeout parameters.");
629629
}
630630
return 0;

drivers/char/tpm/tpm-sysfs.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ static ssize_t durations_show(struct device *dev, struct device_attribute *attr,
236236
{
237237
struct tpm_chip *chip = dev_get_drvdata(dev);
238238

239-
if (chip->vendor.duration[TPM_LONG] == 0)
239+
if (chip->duration[TPM_LONG] == 0)
240240
return 0;
241241

242242
return sprintf(buf, "%d %d %d [%s]\n",
243-
jiffies_to_usecs(chip->vendor.duration[TPM_SHORT]),
244-
jiffies_to_usecs(chip->vendor.duration[TPM_MEDIUM]),
245-
jiffies_to_usecs(chip->vendor.duration[TPM_LONG]),
246-
chip->vendor.duration_adjusted
243+
jiffies_to_usecs(chip->duration[TPM_SHORT]),
244+
jiffies_to_usecs(chip->duration[TPM_MEDIUM]),
245+
jiffies_to_usecs(chip->duration[TPM_LONG]),
246+
chip->duration_adjusted
247247
? "adjusted" : "original");
248248
}
249249
static DEVICE_ATTR_RO(durations);
@@ -254,11 +254,11 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
254254
struct tpm_chip *chip = dev_get_drvdata(dev);
255255

256256
return sprintf(buf, "%d %d %d %d [%s]\n",
257-
jiffies_to_usecs(chip->vendor.timeout_a),
258-
jiffies_to_usecs(chip->vendor.timeout_b),
259-
jiffies_to_usecs(chip->vendor.timeout_c),
260-
jiffies_to_usecs(chip->vendor.timeout_d),
261-
chip->vendor.timeout_adjusted
257+
jiffies_to_usecs(chip->timeout_a),
258+
jiffies_to_usecs(chip->timeout_b),
259+
jiffies_to_usecs(chip->timeout_c),
260+
jiffies_to_usecs(chip->timeout_d),
261+
chip->timeout_adjusted
262262
? "adjusted" : "original");
263263
}
264264
static DEVICE_ATTR_RO(timeouts);

drivers/char/tpm/tpm.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ enum tpm2_startup_types {
131131
struct tpm_chip;
132132

133133
struct tpm_vendor_specific {
134-
unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
135-
bool timeout_adjusted;
136-
unsigned long duration[3]; /* jiffies */
137-
bool duration_adjusted;
138134
void *priv;
139135
};
140136

@@ -171,6 +167,13 @@ struct tpm_chip {
171167
struct mutex tpm_mutex; /* tpm is processing */
172168

173169
struct tpm_vendor_specific vendor;
170+
unsigned long timeout_a; /* jiffies */
171+
unsigned long timeout_b; /* jiffies */
172+
unsigned long timeout_c; /* jiffies */
173+
unsigned long timeout_d; /* jiffies */
174+
bool timeout_adjusted;
175+
unsigned long duration[3]; /* jiffies */
176+
bool duration_adjusted;
174177

175178
struct dentry **bios_dir;
176179

drivers/char/tpm/tpm2-cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
792792
index = tpm2_ordinal_duration[ordinal - TPM2_CC_FIRST];
793793

794794
if (index != TPM_UNDEFINED)
795-
duration = chip->vendor.duration[index];
795+
duration = chip->duration[index];
796796

797797
if (duration <= 0)
798798
duration = 2 * 60 * HZ;

drivers/char/tpm/tpm_i2c_atmel.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ static int i2c_atmel_probe(struct i2c_client *client,
169169
return -ENOMEM;
170170

171171
/* Default timeouts */
172-
chip->vendor.timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
173-
chip->vendor.timeout_b = msecs_to_jiffies(TPM_I2C_LONG_TIMEOUT);
174-
chip->vendor.timeout_c = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
175-
chip->vendor.timeout_d = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
172+
chip->timeout_a = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
173+
chip->timeout_b = msecs_to_jiffies(TPM_I2C_LONG_TIMEOUT);
174+
chip->timeout_c = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
175+
chip->timeout_d = msecs_to_jiffies(TPM_I2C_SHORT_TIMEOUT);
176176

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

drivers/char/tpm/tpm_i2c_infineon.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static int request_locality(struct tpm_chip *chip, int loc)
321321
iic_tpm_write(TPM_ACCESS(loc), &buf, 1);
322322

323323
/* wait for burstcount */
324-
stop = jiffies + chip->vendor.timeout_a;
324+
stop = jiffies + chip->timeout_a;
325325
do {
326326
if (check_locality(chip, loc) >= 0)
327327
return loc;
@@ -363,7 +363,7 @@ static ssize_t get_burstcount(struct tpm_chip *chip)
363363

364364
/* wait for burstcount */
365365
/* which timeout value, spec has 2 answers (c & d) */
366-
stop = jiffies + chip->vendor.timeout_d;
366+
stop = jiffies + chip->timeout_d;
367367
do {
368368
/* Note: STS is little endian */
369369
if (iic_tpm_read(TPM_STS(tpm_dev.locality)+1, buf, 3) < 0)
@@ -465,7 +465,7 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
465465
goto out;
466466
}
467467

468-
wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status);
468+
wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status);
469469
if (status & TPM_STS_DATA_AVAIL) { /* retry? */
470470
dev_err(&chip->dev, "Error left over data\n");
471471
size = -EIO;
@@ -501,7 +501,7 @@ static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
501501
tpm_tis_i2c_ready(chip);
502502
if (wait_for_stat
503503
(chip, TPM_STS_COMMAND_READY,
504-
chip->vendor.timeout_b, &status) < 0) {
504+
chip->timeout_b, &status) < 0) {
505505
rc = -ETIME;
506506
goto out_err;
507507
}
@@ -531,7 +531,7 @@ static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
531531
}
532532

533533
wait_for_stat(chip, TPM_STS_VALID,
534-
chip->vendor.timeout_c, &status);
534+
chip->timeout_c, &status);
535535

536536
if ((status & TPM_STS_DATA_EXPECT) == 0) {
537537
rc = -EIO;
@@ -541,7 +541,7 @@ static int tpm_tis_i2c_send(struct tpm_chip *chip, u8 *buf, size_t len)
541541

542542
/* write last byte */
543543
iic_tpm_write(TPM_DATA_FIFO(tpm_dev.locality), &(buf[count]), 1);
544-
wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status);
544+
wait_for_stat(chip, TPM_STS_VALID, chip->timeout_c, &status);
545545
if ((status & TPM_STS_DATA_EXPECT) != 0) {
546546
rc = -EIO;
547547
goto out_err;
@@ -587,10 +587,10 @@ static int tpm_tis_i2c_init(struct device *dev)
587587
return PTR_ERR(chip);
588588

589589
/* Default timeouts */
590-
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
591-
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
592-
chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
593-
chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
590+
chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
591+
chip->timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
592+
chip->timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
593+
chip->timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
594594

595595
if (request_locality(chip, 0) != 0) {
596596
dev_err(dev, "could not request locality\n");

0 commit comments

Comments
 (0)