xref: /aosp_15_r20/external/coreboot/src/drivers/spi/tpm/tpm.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #ifndef __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H
4 #define __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H
5 
6 #include <drivers/tpm/cr50.h>
7 #include <security/tpm/tis.h>
8 #include <security/tpm/tss_errors.h>
9 #include <stddef.h>
10 #include <spi-generic.h>
11 
12 #define TPM_LOCALITY_0_SPI_BASE 0x00d40000
13 
14 /*
15  * A TPM device descriptor, values read from the appropriate device registers
16  * are cached here.
17  */
18 struct 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  */
31 tpm_result_t tpm2_init(struct spi_slave *spi_if);
32 
33 /*
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
37  * register. The size of the response can be gleaned from the 6 byte header.
38  *
39  * This function places the response into the tpm2_response buffer and returns
40  * the size of the response.
41  */
42 size_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. */
46 void tpm2_get_info(struct tpm2_info *info);
47 
48 tis_sendrecv_fn spi_tis_probe(enum tpm_family *family);
49 
50 #endif  /* ! __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H */
51