tpm: allow TPM v1 and v2 to be compiled at the same time
[oweals/u-boot.git] / include / tpm-common.h
index 68bf8fd62799f5bd4bd536d5c7351bb919fb8e62..5f8bc6bc5287189d48ee1829d60fd5a9be4c4bc4 100644 (file)
@@ -26,6 +26,16 @@ enum tpm_duration {
 /* Max buffer size supported by our tpm */
 #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
  *
@@ -33,20 +43,23 @@ enum tpm_duration {
  * 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 */