coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tis.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef TIS_H_
4 #define TIS_H_
5 
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <types.h>
9 
10 enum tis_access {
11  TPM_ACCESS_VALID = (1 << 7),
16 };
17 
18 enum tis_status {
27  TPM_STS_VALID = (1 << 7),
29  TPM_STS_GO = (1 << 5),
30  TPM_STS_DATA_AVAIL = (1 << 4),
31  TPM_STS_DATA_EXPECT = (1 << 3),
34 };
35 
36 /*
37  * tis_init()
38  *
39  * Initialize the TPM device. Returns 0 on success or -1 on
40  * failure (in case device probing did not succeed).
41  */
42 int tis_init(void);
43 
44 /*
45  * tis_open()
46  *
47  * Requests access to locality 0 for the caller. After all commands have been
48  * completed the caller is supposed to call tis_close().
49  *
50  * Returns 0 on success, -1 on failure.
51  */
52 int tis_open(void);
53 
54 /*
55  * tis_close()
56  *
57  * terminate the current session with the TPM by releasing the locked
58  * locality. Returns 0 on success of -1 on failure (in case lock
59  * removal did not succeed).
60  */
61 int tis_close(void);
62 
63 /*
64  * tis_sendrecv()
65  *
66  * Send the requested data to the TPM and then try to get its response
67  *
68  * @sendbuf - buffer of the data to send
69  * @send_size size of the data to send
70  * @recvbuf - memory to save the response to
71  * @recv_len - pointer to the size of the response buffer
72  *
73  * Returns 0 on success (and places the number of response bytes at recv_len)
74  * or -1 on failure.
75  */
76 int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf,
77  size_t *recv_len);
78 
79 /*
80  * tis_plat_irq_status()
81  *
82  * Check tpm irq and clear it.
83  *
84  * Returns 1 when irq pending or 0 when not.
85  */
86 int tis_plat_irq_status(void);
87 
88 /*
89  * tis_vendor_write()
90  *
91  * Vendor-specific function to send the requested data to the TPM.
92  *
93  * @addr - address of the register to write to
94  * @sendbuf - buffer of the data to send
95  * @send_size - size of the data to send
96  *
97  * Returns CB_SUCCESS 0 on success, CB_ERR on failure.
98  */
99 enum cb_err tis_vendor_write(unsigned int addr, const void *sendbuf, size_t send_size);
100 
101 /*
102  * tis_vendor_read()
103  *
104  * Vendor-specific function to read the requested data from the TPM.
105  *
106  * @addr - address of the register to read from
107  * @recvbuf - buffer of the data to read
108  * @recv_size - size of the output buffer
109  *
110  * Returns CB_SUCCESS on success or -1 on failure.
111  */
112 enum cb_err tis_vendor_read(unsigned int addr, void *recvbuf, size_t recv_size);
113 
114 static inline bool tpm_first_access_this_boot(void)
115 {
116  return ENV_SEPARATE_VERSTAGE || ENV_BOOTBLOCK || !CONFIG(VBOOT);
117 }
118 
119 #endif /* TIS_H_ */
cb_err
coreboot error codes
Definition: cb_err.h:15
static u32 addr
Definition: cirrus.c:14
@ CONFIG
Definition: dsi_common.h:201
#define ENV_BOOTBLOCK
Definition: rules.h:148
#define ENV_SEPARATE_VERSTAGE
Definition: rules.h:152
uint8_t u8
Definition: stdint.h:45
int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf, size_t *recv_len)
Definition: tis.c:81
tis_status
Definition: tis.h:18
@ TPM_STS_FAMILY_TPM_1_2
Definition: tis.h:22
@ TPM_STS_RESPONSE_RETRY
Definition: tis.h:33
@ TPM_STS_BURST_COUNT_MASK
Definition: tis.h:26
@ TPM_STS_FAMILY_SHIFT
Definition: tis.h:19
@ TPM_STS_RESET_ESTABLISHMENT
Definition: tis.h:23
@ TPM_STS_FAMILY_TPM_2_0
Definition: tis.h:21
@ TPM_STS_SELF_TEST_DONE
Definition: tis.h:32
@ TPM_STS_COMMAND_CANCEL
Definition: tis.h:24
@ TPM_STS_DATA_EXPECT
Definition: tis.h:31
@ TPM_STS_GO
Definition: tis.h:29
@ TPM_STS_VALID
Definition: tis.h:27
@ TPM_STS_FAMILY_MASK
Definition: tis.h:20
@ TPM_STS_DATA_AVAIL
Definition: tis.h:30
@ TPM_STS_COMMAND_READY
Definition: tis.h:28
@ TPM_STS_BURST_COUNT_SHIFT
Definition: tis.h:25
static bool tpm_first_access_this_boot(void)
Definition: tis.h:114
int tis_plat_irq_status(void)
Definition: cr50.c:49
enum cb_err tis_vendor_read(unsigned int addr, void *recvbuf, size_t recv_size)
Definition: cr50.c:522
int tis_close(void)
Definition: tis.c:51
enum cb_err tis_vendor_write(unsigned int addr, const void *sendbuf, size_t send_size)
Definition: cr50.c:517
int tis_open(void)
Definition: tis.c:33
int tis_init(void)
Definition: tis.c:65
tis_access
Definition: tis.h:10
@ TPM_ACCESS_REQUEST_USE
Definition: tis.h:14
@ TPM_ACCESS_ACTIVE_LOCALITY
Definition: tis.h:12
@ TPM_ACCESS_REQUEST_PENDING
Definition: tis.h:13
@ TPM_ACCESS_ESTABLISHMENT
Definition: tis.h:15
@ TPM_ACCESS_VALID
Definition: tis.h:11