summaryrefslogtreecommitdiff
path: root/include/tpm-common.h
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2018-07-19 22:35:09 +0200
committerTom Rini <trini@konsulko.com>2018-07-28 11:57:38 -0400
commit2a2096ea6001cc65fa91e2bc622da48c8eb26a06 (patch)
tree1a4f9362a861e40c3c87f51e0736a53513a6c569 /include/tpm-common.h
parent8a7aa3e27921d330ed9828c7ef09079007c5fcee (diff)
tpm: allow TPM v1 and v2 to be compiled at the same time
While there is probably no reason to do so in a real life situation, it will allow to compile test both stacks with the same sandbox defconfig. As we cannot define two 'tpm' commands at the same time, the command for TPM v1 is still called 'tpm' and the one for TPM v2 'tpm2'. While this is the exact command name that must be written into eg. test files, any user already using the TPM v2 stack can continue to do so by just writing 'tpm' because as long as TPM v1 support is not compiled, U-Boot prompt will search for the closest command named after 'tpm'. The command set can also be changed at runtime (not supported yet, but ready to be), but as one can compile only either one stack or the other, there is still one spot in the code where conditionals are used: to retrieve the v1 or v2 command set. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Simon Glass <sjg@chromium.org> [trini: In sandbox_tpm2_fill_buf() use NULL not \0 to ensure NULL terminated string due to LLVM warning] Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'include/tpm-common.h')
-rw-r--r--include/tpm-common.h40
1 files changed, 34 insertions, 6 deletions
diff --git a/include/tpm-common.h b/include/tpm-common.h
index 68bf8fd627..5f8bc6bc52 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -27,26 +27,39 @@ enum tpm_duration {
#define TPM_DEV_BUFSIZE 1260
/**
+ * enum tpm_version - The version of the TPM stack to be used
+ * @TPM_V1: Use TPM v1.x stack
+ * @TPM_V2: Use TPM v2.x stack
+ */
+enum tpm_version {
+ TPM_V1 = 0,
+ TPM_V2,
+};
+
+/**
* struct tpm_chip_priv - Information about a TPM, stored by the uclass
*
* These values must be set up by the device's probe() method before
* communcation is attempted. If the device has an xfer() method, this is
* not needed. There is no need to set up @buf.
*
+ * @version: TPM stack to be used
* @duration_ms: Length of each duration type in milliseconds
* @retry_time_ms: Time to wait before retrying receive
+ * @buf: Buffer used during the exchanges with the chip
* @pcr_count: Number of PCR per bank
* @pcr_select_min: Minimum size in bytes of the pcrSelect array
- * @buf: Buffer used during the exchanges with the chip
*/
struct tpm_chip_priv {
+ enum tpm_version version;
+
uint duration_ms[TPM_DURATION_COUNT];
uint retry_time_ms;
-#if defined(CONFIG_TPM_V2)
+ u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
+
+ /* TPM v2 specific data */
uint pcr_count;
uint pcr_select_min;
-#endif
- u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
};
/**
@@ -208,10 +221,25 @@ int tpm_xfer(struct udevice *dev, const u8 *sendbuf, size_t send_size,
int tpm_init(void);
/**
- * Retrieve the array containing all the commands.
+ * Retrieve the array containing all the v1 (resp. v2) commands.
*
* @return a cmd_tbl_t array.
*/
-cmd_tbl_t *get_tpm_commands(unsigned int *size);
+#if defined(CONFIG_TPM_V1)
+cmd_tbl_t *get_tpm1_commands(unsigned int *size);
+#else
+static inline cmd_tbl_t *get_tpm1_commands(unsigned int *size)
+{
+ return NULL;
+}
+#endif
+#if defined(CONFIG_TPM_V2)
+cmd_tbl_t *get_tpm2_commands(unsigned int *size);
+#else
+static inline cmd_tbl_t *get_tpm2_commands(unsigned int *size)
+{
+ return NULL;
+}
+#endif
#endif /* __TPM_COMMON_H */