Revert "security/tpm/: turn tis_{init,open} into tis_probe"

This reverts commit d43154486d.

From CB:68991: This causes CraterLake boot up process to die.
Investigation in progress.

Change-Id: I4a6c11b0e638a891108fe230bdaea92d5fbca020
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/71205
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Tested-by: siemens-bot
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
This commit is contained in:
Sergii Dmytruk 2022-12-22 19:35:25 +02:00 committed by Felix Held
commit 4ee03170e0
11 changed files with 157 additions and 101 deletions

View file

@ -32,6 +32,25 @@ enum tis_status {
};
/*
* tis_init()
*
* Initialize the TPM device. Returns 0 on success or -1 on
* failure (in case device probing did not succeed).
*/
int tis_init(void);
/*
* tis_open()
*
* Requests access to locality 0 for the caller.
*
* Returns 0 on success, -1 on failure.
*/
int tis_open(void);
/*
* tis_sendrecv()
*
* Send the requested data to the TPM and then try to get its response
*
* @sendbuf - buffer of the data to send
@ -42,19 +61,8 @@ enum tis_status {
* Returns 0 on success (and places the number of response bytes at recv_len)
* or -1 on failure.
*/
typedef int (*tis_sendrecv_fn)(const u8 *sendbuf, size_t send_size, u8 *recvbuf,
size_t *recv_len);
/*
* tis_probe()
*
* Probe for the TPM device and set it up for use within locality 0. Returns
* pointer to send-receive function on success or NULL on failure.
*
* Do not call this explicitly, it's meant to be used exclusively by TSS
* implementation (tlcl_lib_init() function to be specific).
*/
tis_sendrecv_fn tis_probe(void);
int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf,
size_t *recv_len);
/* TODO: This is supposed to be used only for Google TPM.
Consider moving this to drivers/tpm/cr50.h. */

View file

@ -24,18 +24,12 @@
#include <console/console.h>
#define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args)
static tis_sendrecv_fn tis_sendrecv;
static int tpm_send_receive(const uint8_t *request,
uint32_t request_length,
uint8_t *response,
uint32_t *response_length)
{
size_t len = *response_length;
if (tis_sendrecv == NULL)
die("TSS 1.2 wasn't initialized\n");
if (tis_sendrecv(request, request_length, response, &len))
return VB2_ERROR_UNKNOWN;
/* check 64->32bit overflow and (re)check response buffer overflow */
@ -146,14 +140,19 @@ static uint32_t send(const uint8_t *command)
/* Exported functions. */
static uint8_t tlcl_init_done;
uint32_t tlcl_lib_init(void)
{
if (tis_sendrecv != NULL)
if (tlcl_init_done)
return VB2_SUCCESS;
tis_sendrecv = tis_probe();
if (tis_sendrecv == NULL)
if (tis_init())
return VB2_ERROR_UNKNOWN;
if (tis_open())
return VB2_ERROR_UNKNOWN;
tlcl_init_done = 1;
return VB2_SUCCESS;
}

View file

@ -16,8 +16,6 @@
* TPM2 specification.
*/
static tis_sendrecv_fn tis_sendrecv;
void *tpm_process_command(TPM_CC command, void *command_body)
{
struct obuf ob;
@ -28,9 +26,6 @@ void *tpm_process_command(TPM_CC command, void *command_body)
/* Command/response buffer. */
static uint8_t cr_buffer[TPM_BUFFER_SIZE];
if (tis_sendrecv == NULL)
die("TSS 2.0 wasn't initialized\n");
obuf_init(&ob, cr_buffer, sizeof(cr_buffer));
if (tpm_marshal_command(command, command_body, &ob) < 0) {
@ -206,18 +201,26 @@ uint32_t tlcl_clear_control(bool disable)
return TPM_SUCCESS;
}
static uint8_t tlcl_init_done;
/* This function is called directly by vboot, uses vboot return types. */
uint32_t tlcl_lib_init(void)
{
if (tis_sendrecv != NULL)
if (tlcl_init_done)
return VB2_SUCCESS;
tis_sendrecv = tis_probe();
if (tis_sendrecv == NULL) {
printk(BIOS_ERR, "%s: tis_probe returned error\n", __func__);
if (tis_init()) {
printk(BIOS_ERR, "%s: tis_init returned error\n", __func__);
return VB2_ERROR_UNKNOWN;
}
if (tis_open()) {
printk(BIOS_ERR, "%s: tis_open returned error\n", __func__);
return VB2_ERROR_UNKNOWN;
}
tlcl_init_done = 1;
return VB2_SUCCESS;
}