aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tpm/tpm.c
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.vnet.ibm.com>2011-11-11 12:57:04 -0500
committerRajiv Andrade <srajiv@linux.vnet.ibm.com>2011-11-16 06:42:59 -0500
commit68d6e6713fcb2ea6278661aaaf5f1c9c821b3751 (patch)
treefb02641cb1941a6d9c23ac3df37d6aafcd4f7f3a /drivers/char/tpm/tpm.c
parentd97c6ade5926afb6d52df36c33a3491d62cd0dc0 (diff)
tpm: Introduce function to poll for result of self test
This patch introduces a function that runs the TPM_ContinueSelfTest() function and then polls the TPM to check whether it finished the selftest and can receive new commands. Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'drivers/char/tpm/tpm.c')
-rw-r--r--drivers/char/tpm/tpm.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 9bd4668e2855..2e12b3f98139 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -627,7 +627,7 @@ static struct tpm_input_header continue_selftest_header = {
627 * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing 627 * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing
628 * a TPM error code. 628 * a TPM error code.
629 */ 629 */
630int tpm_continue_selftest(struct tpm_chip *chip) 630static int tpm_continue_selftest(struct tpm_chip *chip)
631{ 631{
632 int rc; 632 int rc;
633 struct tpm_cmd_t cmd; 633 struct tpm_cmd_t cmd;
@@ -637,7 +637,6 @@ int tpm_continue_selftest(struct tpm_chip *chip)
637 "continue selftest"); 637 "continue selftest");
638 return rc; 638 return rc;
639} 639}
640EXPORT_SYMBOL_GPL(tpm_continue_selftest);
641 640
642ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr, 641ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr,
643 char *buf) 642 char *buf)
@@ -732,7 +731,7 @@ static struct tpm_input_header pcrread_header = {
732 .ordinal = TPM_ORDINAL_PCRREAD 731 .ordinal = TPM_ORDINAL_PCRREAD
733}; 732};
734 733
735int __tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) 734static int __tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
736{ 735{
737 int rc; 736 int rc;
738 struct tpm_cmd_t cmd; 737 struct tpm_cmd_t cmd;
@@ -812,6 +811,45 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
812} 811}
813EXPORT_SYMBOL_GPL(tpm_pcr_extend); 812EXPORT_SYMBOL_GPL(tpm_pcr_extend);
814 813
814/**
815 * tpm_do_selftest - have the TPM continue its selftest and wait until it
816 * can receive further commands
817 * @chip: TPM chip to use
818 *
819 * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing
820 * a TPM error code.
821 */
822int tpm_do_selftest(struct tpm_chip *chip)
823{
824 int rc;
825 u8 digest[TPM_DIGEST_SIZE];
826 unsigned int loops;
827 unsigned int delay_msec = 1000;
828 unsigned long duration;
829
830 duration = tpm_calc_ordinal_duration(chip,
831 TPM_ORD_CONTINUE_SELFTEST);
832
833 loops = jiffies_to_msecs(duration) / delay_msec;
834
835 rc = tpm_continue_selftest(chip);
836 /* This may fail if there was no TPM driver during a suspend/resume
837 * cycle; some may return 10 (BAD_ORDINAL), others 28 (FAILEDSELFTEST)
838 */
839 if (rc)
840 return rc;
841
842 do {
843 rc = __tpm_pcr_read(chip, 0, digest);
844 if (rc != TPM_WARN_DOING_SELFTEST)
845 return rc;
846 msleep(delay_msec);
847 } while (--loops > 0);
848
849 return rc;
850}
851EXPORT_SYMBOL_GPL(tpm_do_selftest);
852
815int tpm_send(u32 chip_num, void *cmd, size_t buflen) 853int tpm_send(u32 chip_num, void *cmd, size_t buflen)
816{ 854{
817 struct tpm_chip *chip; 855 struct tpm_chip *chip;