CHROMIUM: tpm: always run ContinueSelftest at resume
[cascardo/linux.git] / drivers / char / tpm / tpm.c
index 60add08..547f5df 100644 (file)
@@ -352,7 +352,6 @@ static void timeout_work(struct work_struct *work)
 static void set_needs_resume(struct tpm_chip *chip)
 {
        mutex_lock(&chip->resume_mutex);
-       chip->resume_time = jiffies;
        chip->needs_resume = 1;
        mutex_unlock(&chip->resume_mutex);
 }
@@ -448,6 +447,7 @@ void tpm_continue_selftest_nocheck(struct tpm_chip *chip)
        cmd.header.in = continue_selftest_header;
        tpm_transmit(chip, (u8 *) &cmd, CONTINUE_SELFTEST_RESULT_SIZE);
 }
+EXPORT_SYMBOL_GPL(tpm_continue_selftest_nocheck);
 
 /* The maximum time in milliseconds that the TPM self test will take to
  * complete.  TODO(semenzato): 1s should be plenty for all TPMs, but how can we
@@ -469,22 +469,16 @@ static void resume_if_needed(struct tpm_chip *chip)
 {
        mutex_lock(&chip->resume_mutex);
        if (chip->needs_resume) {
-               /* If it's been TPM_SELF_TEST_DURATION_MSEC msec since resume,
-                * then selftest has completed and we don't need to wait.
-                */
-               if (jiffies - chip->resume_time <
-                   msecs_to_jiffies(TPM_SELF_TEST_DURATION_MSEC)) {
-                       dev_info(chip->dev, "waiting for TPM self test");
-                       tpm_continue_selftest_nocheck(chip);
-               }
+               dev_info(chip->dev, "waiting for TPM self test\n");
+               tpm_continue_selftest_nocheck(chip);
                chip->needs_resume = 0;
-               dev_info(chip->dev, "TPM delayed resume completed");
+               dev_info(chip->dev, "TPM delayed resume completed\n");
        }
        mutex_unlock(&chip->resume_mutex);
 }
 
-static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd,
-                           int len, const char *desc)
+ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd,
+                        int len, const char *desc)
 {
        int err;
 
@@ -502,6 +496,7 @@ static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd,
 
        return err;
 }
+EXPORT_SYMBOL_GPL(tpm_transmit_cmd);
 
 /**
  * tpm_continue_selftest -- run TPM's selftest
@@ -516,8 +511,8 @@ int tpm_continue_selftest(struct tpm_chip *chip)
        struct tpm_cmd_t cmd;
 
        cmd.header.in = continue_selftest_header;
-       rc = transmit_cmd(chip, (const u8 *) &cmd,
-                         CONTINUE_SELFTEST_RESULT_SIZE, "continue selftest");
+       rc = tpm_transmit_cmd(chip, &cmd,
+                             CONTINUE_SELFTEST_RESULT_SIZE, "continue selftest");
        return rc;
 }
 EXPORT_SYMBOL_GPL(tpm_continue_selftest);
@@ -591,7 +586,7 @@ ssize_t tpm_getcap(struct device *dev, __be32 subcap_id, cap_t *cap,
                tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
                tpm_cmd.params.getcap_in.subcap = subcap_id;
        }
-       rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc);
+       rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc);
        if (!rc)
                *cap = tpm_cmd.params.getcap_out.cap;
        return rc;
@@ -607,8 +602,8 @@ void tpm_gen_interrupt(struct tpm_chip *chip)
        tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
        tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
 
-       rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
-                       "attempting to determine the timeouts");
+       rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
+                             "attempting to determine the timeouts");
 }
 EXPORT_SYMBOL_GPL(tpm_gen_interrupt);
 
@@ -626,8 +621,8 @@ int tpm_get_timeouts(struct tpm_chip *chip)
        tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
        tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
 
-       rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
-                       "attempting to determine the timeouts");
+       rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
+                             "attempting to determine the timeouts");
        if (rc)
                goto duration;
 
@@ -662,8 +657,8 @@ duration:
        tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
        tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_DURATION;
 
-       rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
-                       "attempting to determine the durations");
+       rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
+                             "attempting to determine the durations");
        if (rc)
                return rc;
 
@@ -690,7 +685,7 @@ duration:
                chip->vendor.duration[TPM_MEDIUM] *= 1000;
                chip->vendor.duration[TPM_LONG] *= 1000;
                chip->vendor.duration_adjusted = true;
-               dev_info(chip->dev, "Adjusting TPM timeout parameters.");
+               dev_info(chip->dev, "Adjusting TPM timeout parameters.\n");
        }
        return 0;
 }
@@ -796,8 +791,8 @@ static int __tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
 
        cmd.header.in = pcrread_header;
        cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx);
-       rc = transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
-                         "attempting to read a pcr value");
+       rc = tpm_transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
+                             "attempting to read a pcr value");
 
        if (rc == 0)
                memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
@@ -861,8 +856,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
        cmd.header.in = pcrextend_header;
        cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(pcr_idx);
        memcpy(cmd.params.pcrextend_in.hash, hash, TPM_DIGEST_SIZE);
-       rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
-                         "attempting extend a PCR value");
+       rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
+                             "attempting extend a PCR value");
 
        tpm_chip_put(chip);
        return rc;
@@ -926,7 +921,7 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
        if (chip == NULL)
                return -ENODEV;
 
-       rc = transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd");
+       rc = tpm_transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd");
 
        tpm_chip_put(chip);
        return rc;
@@ -982,8 +977,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
        struct tpm_chip *chip = dev_get_drvdata(dev);
 
        tpm_cmd.header.in = tpm_readpubek_header;
-       err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
-                       "attempting to read the PUBEK");
+       err = tpm_transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
+                              "attempting to read the PUBEK");
        if (err)
                goto out;
 
@@ -1347,14 +1342,14 @@ int tpm_pm_suspend(struct device *dev, pm_message_t pm_state)
                cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(tpm_suspend_pcr);
                memcpy(cmd.params.pcrextend_in.hash, dummy_hash,
                       TPM_DIGEST_SIZE);
-               rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
-                                 "extending dummy pcr before suspend");
+               rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
+                                     "extending dummy pcr before suspend");
        }
 
        /* now do the actual savestate */
        cmd.header.in = savestate_header;
-       rc = transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE,
-                         "sending savestate before suspend");
+       rc = tpm_transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE,
+                             "sending savestate before suspend");
        return rc;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_suspend);