blob: 0d238e8011dd72cc74de62c8c34ce84120671466 [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>
Jon Murphyd7b8dc92023-09-05 11:36:43 -06007#include <security/tpm/tss_errors.h>
Vadim Bendeburye31d2432016-04-09 18:33:49 -07008#include <stddef.h>
9#include <spi-generic.h>
10
Tim Wawrzynczak6b8599f2022-02-14 16:04:21 -070011#define TPM_LOCALITY_0_SPI_BASE 0x00d40000
12
Vadim Bendeburye31d2432016-04-09 18:33:49 -070013/*
Martin Roth3e25f852023-09-04 15:37:07 -060014 * A TPM device descriptor, values read from the appropriate device registers
Vadim Bendeburye31d2432016-04-09 18:33:49 -070015 * are cached here.
16 */
17struct tpm2_info {
18 uint16_t vendor_id;
19 uint16_t device_id;
20 uint16_t revision;
21};
22
23/*
24 * Initialize a TPM2 device: read its id, claim locality of zero, verify that
25 * this indeed is a TPM2 device. Use the passed in handle to access the right
26 * SPI port.
27 *
28 * Return 0 on success, non-zero on failure.
29 */
Jon Murphyd7b8dc92023-09-05 11:36:43 -060030tpm_result_t tpm2_init(struct spi_slave *spi_if);
Vadim Bendeburye31d2432016-04-09 18:33:49 -070031
Vadim Bendeburye31d2432016-04-09 18:33:49 -070032/*
33 * Each command processing consists of sending the command to the TPM, by
34 * writing it into the FIFO register, then polling the status register until
35 * the TPM is ready to respond, then reading the response from the FIFO
Martin Roth3e25f852023-09-04 15:37:07 -060036 * register. The size of the response can be gleaned from the 6 byte header.
Vadim Bendeburye31d2432016-04-09 18:33:49 -070037 *
38 * This function places the response into the tpm2_response buffer and returns
39 * the size of the response.
40 */
41size_t tpm2_process_command(const void *tpm2_command, size_t command_size,
42 void *tpm2_response, size_t max_response);
43
44/* Get information about previously initialized TPM device. */
45void tpm2_get_info(struct tpm2_info *info);
46
Vadim Bendeburye31d2432016-04-09 18:33:49 -070047#endif /* ! __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H */