blob: d6e0e7422785a26f50f5f0cd8f826726987c6d4e [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001/* SPDX-License-Identifier: BSD-3-Clause */
Vadim Bendeburye31d2432016-04-09 18:33:49 -07002
3#ifndef __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H
4#define __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H
5
Tim Wawrzynczak6b8599f2022-02-14 16:04:21 -07006#include <drivers/tpm/cr50.h>
Sergii Dmytruk3e5cefc2022-11-01 00:48:43 +02007#include <security/tpm/tis.h>
Jon Murphyd7b8dc92023-09-05 11:36:43 -06008#include <security/tpm/tss_errors.h>
Vadim Bendeburye31d2432016-04-09 18:33:49 -07009#include <stddef.h>
10#include <spi-generic.h>
11
Tim Wawrzynczak6b8599f2022-02-14 16:04:21 -070012#define TPM_LOCALITY_0_SPI_BASE 0x00d40000
13
Vadim Bendeburye31d2432016-04-09 18:33:49 -070014/*
Martin Roth3e25f852023-09-04 15:37:07 -060015 * A TPM device descriptor, values read from the appropriate device registers
Vadim Bendeburye31d2432016-04-09 18:33:49 -070016 * are cached here.
17 */
18struct tpm2_info {
19 uint16_t vendor_id;
20 uint16_t device_id;
21 uint16_t revision;
22};
23
24/*
25 * Initialize a TPM2 device: read its id, claim locality of zero, verify that
26 * this indeed is a TPM2 device. Use the passed in handle to access the right
27 * SPI port.
28 *
29 * Return 0 on success, non-zero on failure.
30 */
Jon Murphyd7b8dc92023-09-05 11:36:43 -060031tpm_result_t tpm2_init(struct spi_slave *spi_if);
Vadim Bendeburye31d2432016-04-09 18:33:49 -070032
Vadim Bendeburye31d2432016-04-09 18:33:49 -070033/*
34 * Each command processing consists of sending the command to the TPM, by
35 * writing it into the FIFO register, then polling the status register until
36 * the TPM is ready to respond, then reading the response from the FIFO
Martin Roth3e25f852023-09-04 15:37:07 -060037 * register. The size of the response can be gleaned from the 6 byte header.
Vadim Bendeburye31d2432016-04-09 18:33:49 -070038 *
39 * This function places the response into the tpm2_response buffer and returns
40 * the size of the response.
41 */
42size_t tpm2_process_command(const void *tpm2_command, size_t command_size,
43 void *tpm2_response, size_t max_response);
44
45/* Get information about previously initialized TPM device. */
46void tpm2_get_info(struct tpm2_info *info);
47
Sergii Dmytruk3e5cefc2022-11-01 00:48:43 +020048tis_sendrecv_fn spi_tis_probe(enum tpm_family *family);
49
Vadim Bendeburye31d2432016-04-09 18:33:49 -070050#endif /* ! __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H */