[SLOF] [PATCH v4 22/33] tpm2: Implement tpm20_startup()
Stefan Berger
stefanb at linux.vnet.ibm.com
Thu Dec 12 07:27:17 AEDT 2019
Rename the existing startup() function to tpm12_startup and
also prefix all the function it calls with tpm12_. Then implement
tpm20_startup().
Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
---
lib/libtpm/tcgbios.c | 56 +++++++++++++++++++++++++++++++++++++++-
lib/libtpm/tcgbios_int.h | 5 ++++
lib/libtpm/tpm_drivers.h | 9 +++++++
3 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index f41db64..cd5e13c 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -213,6 +213,17 @@ static int tpm12_determine_timeouts(void)
return 0;
}
+static void tpm20_set_timeouts(void)
+{
+ uint32_t durations[3] = {
+ TPM2_DEFAULT_DURATION_SHORT,
+ TPM2_DEFAULT_DURATION_MEDIUM,
+ TPM2_DEFAULT_DURATION_LONG,
+ };
+
+ spapr_vtpm_set_durations(durations);
+}
+
/*
* Extend a PCR of the TPM with the given hash
*
@@ -417,6 +428,49 @@ err_exit:
return -1;
}
+static int tpm20_startup(void)
+{
+ int ret;
+
+ tpm20_set_timeouts();
+
+ ret = tpm_simple_cmd(0, TPM2_CC_Startup,
+ 2, TPM2_SU_CLEAR, TPM_DURATION_TYPE_SHORT);
+ dprintf("TCGBIOS: Return value from sending TPM2_CC_Startup(SU_CLEAR) = 0x%08x\n",
+ ret);
+
+ if (ret)
+ goto err_exit;
+
+ ret = tpm_simple_cmd(0, TPM2_CC_SelfTest,
+ 1, TPM2_YES, TPM_DURATION_TYPE_LONG);
+
+ dprintf("TCGBIOS: Return value from sending TPM2_CC_SELF_TEST = 0x%08x\n",
+ ret);
+
+ if (ret)
+ goto err_exit;
+
+ return 0;
+
+err_exit:
+ dprintf("TCGBIOS: TPM malfunctioning (line %d).\n", __LINE__);
+
+ tpm_set_failure();
+ return -1;
+}
+
+static int tpm_startup(void)
+{
+ switch (TPM_version) {
+ case TPM_VERSION_1_2:
+ return tpm12_startup();
+ case TPM_VERSION_2:
+ return tpm20_startup();
+ }
+ return -1;
+}
+
uint32_t tpm_start(void)
{
tpm_state.has_physical_presence = false;
@@ -429,7 +483,7 @@ uint32_t tpm_start(void)
return TCGBIOS_FATAL_COM_ERROR;
}
- return tpm12_startup();
+ return tpm_startup();
}
void tpm_finalize(void)
diff --git a/lib/libtpm/tcgbios_int.h b/lib/libtpm/tcgbios_int.h
index 7e9d0f2..aeba9d9 100644
--- a/lib/libtpm/tcgbios_int.h
+++ b/lib/libtpm/tcgbios_int.h
@@ -202,6 +202,9 @@ struct tpm_rsp_getcap_buffersize {
#define TPM2_NO 0
#define TPM2_YES 1
+#define TPM2_SU_CLEAR 0x0000
+#define TPM2_SU_STATE 0x0001
+
#define TPM2_RH_OWNER 0x40000001
#define TPM2_RS_PW 0x40000009
#define TPM2_RH_ENDORSEMENT 0x4000000b
@@ -213,6 +216,8 @@ struct tpm_rsp_getcap_buffersize {
/* TPM 2 commands */
#define TPM2_CC_HierarchyControl 0x121
+#define TPM2_CC_SelfTest 0x143
+#define TPM2_CC_Startup 0x144
struct tpm2_authblock {
uint32_t handle;
diff --git a/lib/libtpm/tpm_drivers.h b/lib/libtpm/tpm_drivers.h
index 5b7f84d..cfb7b72 100644
--- a/lib/libtpm/tpm_drivers.h
+++ b/lib/libtpm/tpm_drivers.h
@@ -30,6 +30,15 @@ enum tpm_duration_type {
#define TPM_DEFAULT_DURATION_MEDIUM 20000000 /* us */
#define TPM_DEFAULT_DURATION_LONG 60000000 /* us */
+/*
+ * TPM 2 command durations; we set them to the timeout values
+ * given in TPM Profile (PTP) Specification; exceeding those
+ * timeout values indicates a faulty TPM.
+ */
+#define TPM2_DEFAULT_DURATION_SHORT 750000 /* us */
+#define TPM2_DEFAULT_DURATION_MEDIUM 2000000 /* us */
+#define TPM2_DEFAULT_DURATION_LONG 2000000 /* us */
+
/* firmware driver states */
typedef enum {
VTPM_DRV_STATE_INVALID = 0,
--
2.17.1
More information about the SLOF
mailing list