Skip to content

Commit 9519de3

Browse files
stefanbergersrajiv
authored andcommitted
tpm_tis: Probing function for Intel iTPM bug
This patch introduces a function for automatic probing for the Intel iTPM STS_DATA_EXPECT flaw. The patch splits the current tpm_tis_send function into 2 parts where the 1st part is now called tpm_tis_send_data() and merely sends the data to the TPM. This function is then used for probing. The new tpm_tis_send function now first calls tpm_tis_send_data and if that succeeds has the TPM process the command and waits until the response is there. The probing for the Intel iTPM is only invoked if the user has not passed itpm=1 as parameter for the module *or* if such a TPM was detected via ACPI. Previously it was necessary to pass itpm=1 when also passing force=1 to the module when doing a 'modprobe'. This function is more general than the ACPI test function and the function relying on ACPI could probably be removed. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
1 parent a7b6682 commit 9519de3

1 file changed

Lines changed: 73 additions & 4 deletions

File tree

‎drivers/char/tpm/tpm_tis.c‎

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,10 @@ MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
306306
* tpm.c can skip polling for the data to be available as the interrupt is
307307
* waited for here
308308
*/
309-
static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
309+
static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
310310
{
311311
int rc, status, burstcnt;
312312
size_t count = 0;
313-
u32 ordinal;
314313

315314
if (request_locality(chip, 0) < 0)
316315
return -EBUSY;
@@ -345,8 +344,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
345344

346345
/* write last byte */
347346
iowrite8(buf[count],
348-
chip->vendor.iobase +
349-
TPM_DATA_FIFO(chip->vendor.locality));
347+
chip->vendor.iobase + TPM_DATA_FIFO(chip->vendor.locality));
350348
wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
351349
&chip->vendor.int_queue);
352350
status = tpm_tis_status(chip);
@@ -355,6 +353,28 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
355353
goto out_err;
356354
}
357355

356+
return 0;
357+
358+
out_err:
359+
tpm_tis_ready(chip);
360+
release_locality(chip, chip->vendor.locality, 0);
361+
return rc;
362+
}
363+
364+
/*
365+
* If interrupts are used (signaled by an irq set in the vendor structure)
366+
* tpm.c can skip polling for the data to be available as the interrupt is
367+
* waited for here
368+
*/
369+
static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
370+
{
371+
int rc;
372+
u32 ordinal;
373+
374+
rc = tpm_tis_send_data(chip, buf, len);
375+
if (rc < 0)
376+
return rc;
377+
358378
/* go and do it */
359379
iowrite8(TPM_STS_GO,
360380
chip->vendor.iobase + TPM_STS(chip->vendor.locality));
@@ -376,6 +396,47 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
376396
return rc;
377397
}
378398

399+
/*
400+
* Early probing for iTPM with STS_DATA_EXPECT flaw.
401+
* Try sending command without itpm flag set and if that
402+
* fails, repeat with itpm flag set.
403+
*/
404+
static int probe_itpm(struct tpm_chip *chip)
405+
{
406+
int rc = 0;
407+
u8 cmd_getticks[] = {
408+
0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
409+
0x00, 0x00, 0x00, 0xf1
410+
};
411+
size_t len = sizeof(cmd_getticks);
412+
int rem_itpm = itpm;
413+
414+
itpm = 0;
415+
416+
rc = tpm_tis_send_data(chip, cmd_getticks, len);
417+
if (rc == 0)
418+
goto out;
419+
420+
tpm_tis_ready(chip);
421+
release_locality(chip, chip->vendor.locality, 0);
422+
423+
itpm = 1;
424+
425+
rc = tpm_tis_send_data(chip, cmd_getticks, len);
426+
if (rc == 0) {
427+
dev_info(chip->dev, "Detected an iTPM.\n");
428+
rc = 1;
429+
} else
430+
rc = -EFAULT;
431+
432+
out:
433+
itpm = rem_itpm;
434+
tpm_tis_ready(chip);
435+
release_locality(chip, chip->vendor.locality, 0);
436+
437+
return rc;
438+
}
439+
379440
static const struct file_operations tis_ops = {
380441
.owner = THIS_MODULE,
381442
.llseek = no_llseek,
@@ -515,6 +576,14 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
515576
"1.2 TPM (device-id 0x%X, rev-id %d)\n",
516577
vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
517578

579+
if (!itpm) {
580+
itpm = probe_itpm(chip);
581+
if (itpm < 0) {
582+
rc = -ENODEV;
583+
goto out_err;
584+
}
585+
}
586+
518587
if (itpm)
519588
dev_info(dev, "Intel iTPM workaround enabled\n");
520589

0 commit comments

Comments
 (0)