Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 1 | /* |
Stefan Reinauer | d518c7a | 2013-11-04 17:38:32 -0800 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 4 | * Copyright 2011 Google Inc. |
| 5 | * |
Stefan Reinauer | d518c7a | 2013-11-04 17:38:32 -0800 | [diff] [blame] | 6 | * 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 Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 9 | * |
| 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 Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Philipp Deppenwiese | d88fb36 | 2017-10-18 20:26:18 +0200 | [diff] [blame] | 16 | #ifndef TIS_H_ |
| 17 | #define TIS_H_ |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 18 | |
| 19 | #include <stddef.h> |
| 20 | #include <stdint.h> |
| 21 | |
Furquan Shaikh | 260b297 | 2017-04-07 13:26:01 -0700 | [diff] [blame] | 22 | enum 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 | |
| 30 | enum 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 Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 48 | /* |
| 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 | */ |
| 54 | int 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 | */ |
| 64 | int 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 | */ |
| 73 | int 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 Reinauer | d518c7a | 2013-11-04 17:38:32 -0800 | [diff] [blame] | 88 | int tis_sendrecv(const u8 *sendbuf, size_t send_size, u8 *recvbuf, |
Stefan Reinauer | 7cb01e0 | 2013-08-29 16:05:02 -0700 | [diff] [blame] | 89 | size_t *recv_len); |
| 90 | |
Jeffy Chen | 19e3d33 | 2017-03-03 18:24:02 +0800 | [diff] [blame] | 91 | /* |
| 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 | */ |
| 98 | int tis_plat_irq_status(void); |
| 99 | |
Philipp Deppenwiese | d88fb36 | 2017-10-18 20:26:18 +0200 | [diff] [blame] | 100 | #endif /* TIS_H_ */ |