blob: c410838fc21ada930731259c7820a47953696b03 [file] [log] [blame]
Stefan Reinauer7cb01e02013-08-29 16:05:02 -07001/*
Stefan Reinauerd518c7a2013-11-04 17:38:32 -08002 * This file is part of the coreboot project.
3 *
Stefan Reinauer7cb01e02013-08-29 16:05:02 -07004 * Copyright 2011 Google Inc.
5 *
Stefan Reinauerd518c7a2013-11-04 17:38:32 -08006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
Stefan Reinauer7cb01e02013-08-29 16:05:02 -07009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070014 */
15
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +020016#ifndef TIS_H_
17#define TIS_H_
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070018
19#include <stddef.h>
20#include <stdint.h>
21
Furquan Shaikh260b2972017-04-07 13:26:01 -070022enum tis_access {
23 TPM_ACCESS_VALID = (1 << 7),
24 TPM_ACCESS_ACTIVE_LOCALITY = (1 << 5),
25 TPM_ACCESS_REQUEST_PENDING = (1 << 2),
26 TPM_ACCESS_REQUEST_USE = (1 << 1),
27 TPM_ACCESS_ESTABLISHMENT = (1 << 0),
28};
29
30enum tis_status {
31 TPM_STS_FAMILY_SHIFT = 26,
32 TPM_STS_FAMILY_MASK = (0x3 << TPM_STS_FAMILY_SHIFT),
33 TPM_STS_FAMILY_TPM_2_0 = (1 << TPM_STS_FAMILY_SHIFT),
34 TPM_STS_FAMILY_TPM_1_2 = (0 << TPM_STS_FAMILY_SHIFT),
35 TPM_STS_RESET_ESTABLISHMENT = (1 << 25),
36 TPM_STS_COMMAND_CANCEL = (1 << 24),
37 TPM_STS_BURST_COUNT_SHIFT = 8,
38 TPM_STS_BURST_COUNT_MASK = (0xFFFF << TPM_STS_BURST_COUNT_SHIFT),
39 TPM_STS_VALID = (1 << 7),
40 TPM_STS_COMMAND_READY = (1 << 6),
41 TPM_STS_GO = (1 << 5),
42 TPM_STS_DATA_AVAIL = (1 << 4),
43 TPM_STS_DATA_EXPECT = (1 << 3),
44 TPM_STS_SELF_TEST_DONE = (1 << 2),
45 TPM_STS_RESPONSE_RETRY = (1 << 1),
46};
47
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070048/*
49 * tis_init()
50 *
51 * Initialize the TPM device. Returns 0 on success or -1 on
52 * failure (in case device probing did not succeed).
53 */
54int tis_init(void);
55
56/*
57 * tis_open()
58 *
59 * Requests access to locality 0 for the caller. After all commands have been
60 * completed the caller is supposed to call tis_close().
61 *
62 * Returns 0 on success, -1 on failure.
63 */
64int tis_open(void);
65
66/*
67 * tis_close()
68 *
69 * terminate the currect session with the TPM by releasing the locked
70 * locality. Returns 0 on success of -1 on failure (in case lock
71 * removal did not succeed).
72 */
73int tis_close(void);
74
75/*
76 * tis_sendrecv()
77 *
78 * Send the requested data to the TPM and then try to get its response
79 *
80 * @sendbuf - buffer of the data to send
81 * @send_size size of the data to send
82 * @recvbuf - memory to save the response to
83 * @recv_len - pointer to the size of the response buffer
84 *
85 * Returns 0 on success (and places the number of response bytes at recv_len)
86 * or -1 on failure.
87 */
Stefan Reinauerd518c7a2013-11-04 17:38:32 -080088int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf,
Stefan Reinauer7cb01e02013-08-29 16:05:02 -070089 size_t *recv_len);
90
Jeffy Chen19e3d332017-03-03 18:24:02 +080091/*
92 * tis_plat_irq_status()
93 *
94 * Check tpm irq and clear it.
95 *
96 * Returns 1 when irq pending or 0 when not.
97 */
98int tis_plat_irq_status(void);
99
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +0200100#endif /* TIS_H_ */