summaryrefslogtreecommitdiff
path: root/src/drivers/crb/tis.c
diff options
context:
space:
mode:
authorSergii Dmytruk <sergii.dmytruk@3mdeb.com>2022-10-29 20:42:28 +0300
committerFelix Held <felix-coreboot@felixheld.de>2023-11-13 14:17:38 +0000
commit963f7b9e5ec4713eb45dfb656659d2c9cf5d9f83 (patch)
tree514b17f5c5395dac6e9030d518459bf363bcebc6 /src/drivers/crb/tis.c
parentbf0b06d9bd71b9e188e2a1c509f7b90ca395e164 (diff)
security/tpm/: turn tis_{init,open} into tis_probe
init() was always followed by open() and after successful initialization we only need send-receive function which is now returned by tis_probe() on success, thus further reducing number of functions to export from drivers. This also removes check for opening TIS twice that seems to have no value. Change-Id: I52ad8d69d50d449f031c36b15bf70ef07986946c Ticket: https://ticket.coreboot.org/issues/433 Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/76954 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/drivers/crb/tis.c')
-rw-r--r--src/drivers/crb/tis.c49
1 files changed, 18 insertions, 31 deletions
diff --git a/src/drivers/crb/tis.c b/src/drivers/crb/tis.c
index cdb0dbb612..2c9128e5d7 100644
--- a/src/drivers/crb/tis.c
+++ b/src/drivers/crb/tis.c
@@ -14,8 +14,6 @@
#include "tpm.h"
#include "chip.h"
-static unsigned int tpm_is_open;
-
static const struct {
uint16_t vid;
uint16_t did;
@@ -35,52 +33,41 @@ static const char *tis_get_dev_name(struct tpm2_info *info)
return "Unknown";
}
-tpm_result_t tis_open(void)
+static tpm_result_t crb_tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, uint8_t *recvbuf,
+ size_t *rbuf_len)
{
- if (tpm_is_open) {
- printk(BIOS_ERR, "%s called twice.\n", __func__);
+ int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
+
+ if (len == 0)
return TPM_CB_FAIL;
- }
- if (CONFIG(HAVE_INTEL_PTT)) {
- if (!ptt_active()) {
- printk(BIOS_ERR, "%s: Intel PTT is not active.\n", __func__);
- return TPM_CB_FAIL;
- }
- printk(BIOS_DEBUG, "%s: Intel PTT is active.\n", __func__);
- }
+ *rbuf_len = len;
return TPM_SUCCESS;
}
-tpm_result_t tis_init(void)
+tis_sendrecv_fn tis_probe(void)
{
struct tpm2_info info;
- // Wake TPM up (if necessary)
- tpm_result_t rc = tpm2_init();
- if (rc)
- return rc;
+ /* Wake TPM up (if necessary) */
+ if (tpm2_init())
+ return NULL;
tpm2_get_info(&info);
printk(BIOS_INFO, "Initialized TPM device %s revision %d\n", tis_get_dev_name(&info),
info.revision);
- return TPM_SUCCESS;
-}
-
-tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
- uint8_t *recvbuf, size_t *rbuf_len)
-{
- int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
-
- if (len == 0)
- return TPM_CB_FAIL;
-
- *rbuf_len = len;
+ if (CONFIG(HAVE_INTEL_PTT)) {
+ if (!ptt_active()) {
+ printk(BIOS_ERR, "%s: Intel PTT is not active.\n", __func__);
+ return NULL;
+ }
+ printk(BIOS_DEBUG, "%s: Intel PTT is active.\n", __func__);
+ }
- return TPM_SUCCESS;
+ return &crb_tpm_sendrecv;
}
static void crb_tpm_fill_ssdt(const struct device *dev)