Rong Chang | 8faa945 | 2013-04-12 10:44:57 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2011 Infineon Technologies |
| 3 | * |
| 4 | * Authors: |
| 5 | * Peter Huewe <huewe.external@infineon.com> |
| 6 | * |
| 7 | * Version: 2.1.1 |
| 8 | * |
| 9 | * Description: |
| 10 | * Device driver for TCG/TCPA TPM (trusted platform module). |
| 11 | * Specifications at www.trustedcomputinggroup.org |
| 12 | * |
| 13 | * It is based on the Linux kernel driver tpm.c from Leendert van |
| 14 | * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall. |
| 15 | * |
| 16 | * |
| 17 | * See file CREDITS for list of people who contributed to this |
| 18 | * project. |
| 19 | * |
| 20 | * This program is free software; you can redistribute it and/or |
| 21 | * modify it under the terms of the GNU General Public License as |
| 22 | * published by the Free Software Foundation, version 2 of the |
| 23 | * License. |
| 24 | * |
| 25 | * This program is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | * GNU General Public License for more details. |
| 29 | * |
| 30 | * You should have received a copy of the GNU General Public License |
| 31 | * along with this program; if not, write to the Free Software |
| 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 33 | * MA 02111-1307 USA |
| 34 | */ |
| 35 | |
| 36 | #ifndef _TPM_H_ |
| 37 | #define _TPM_H_ |
| 38 | |
| 39 | #include <linux/compiler.h> |
| 40 | |
| 41 | #include "compatibility.h" |
| 42 | |
| 43 | enum tpm_timeout { |
| 44 | TPM_TIMEOUT = 5, /* msecs */ |
| 45 | }; |
| 46 | |
| 47 | /* Size of external transmit buffer (used in tpm_transmit)*/ |
| 48 | #define TPM_BUFSIZE 4096 |
| 49 | |
| 50 | /* Index of fields in TPM command buffer */ |
| 51 | #define TPM_CMD_SIZE_BYTE 2 |
| 52 | #define TPM_CMD_ORDINAL_BYTE 6 |
| 53 | |
| 54 | /* Index of Count field in TPM response buffer */ |
| 55 | #define TPM_RSP_SIZE_BYTE 2 |
| 56 | #define TPM_RSP_RC_BYTE 6 |
| 57 | |
| 58 | struct tpm_chip; |
| 59 | |
| 60 | struct tpm_vendor_specific { |
| 61 | const u8 req_complete_mask; |
| 62 | const u8 req_complete_val; |
| 63 | const u8 req_canceled; |
| 64 | int irq; |
| 65 | int (*recv) (struct tpm_chip *, u8 *, size_t); |
| 66 | int (*send) (struct tpm_chip *, u8 *, size_t); |
| 67 | void (*cancel) (struct tpm_chip *); |
| 68 | u8(*status) (struct tpm_chip *); |
| 69 | int locality; |
| 70 | unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */ |
| 71 | unsigned long duration[3]; /* msec */ |
| 72 | }; |
| 73 | |
| 74 | struct tpm_chip { |
| 75 | int is_open; |
| 76 | struct tpm_vendor_specific vendor; |
| 77 | }; |
| 78 | |
| 79 | struct tpm_input_header { |
| 80 | __be16 tag; |
| 81 | __be32 length; |
| 82 | __be32 ordinal; |
| 83 | } __packed; |
| 84 | |
| 85 | struct tpm_output_header { |
| 86 | __be16 tag; |
| 87 | __be32 length; |
| 88 | __be32 return_code; |
| 89 | } __packed; |
| 90 | |
| 91 | struct timeout_t { |
| 92 | __be32 a; |
| 93 | __be32 b; |
| 94 | __be32 c; |
| 95 | __be32 d; |
| 96 | } __packed; |
| 97 | |
| 98 | struct duration_t { |
| 99 | __be32 tpm_short; |
| 100 | __be32 tpm_medium; |
| 101 | __be32 tpm_long; |
| 102 | } __packed; |
| 103 | |
| 104 | union cap_t { |
| 105 | struct timeout_t timeout; |
| 106 | struct duration_t duration; |
| 107 | }; |
| 108 | |
| 109 | struct tpm_getcap_params_in { |
| 110 | __be32 cap; |
| 111 | __be32 subcap_size; |
| 112 | __be32 subcap; |
| 113 | } __packed; |
| 114 | |
| 115 | struct tpm_getcap_params_out { |
| 116 | __be32 cap_size; |
| 117 | union cap_t cap; |
| 118 | } __packed; |
| 119 | |
| 120 | union tpm_cmd_header { |
| 121 | struct tpm_input_header in; |
| 122 | struct tpm_output_header out; |
| 123 | }; |
| 124 | |
| 125 | union tpm_cmd_params { |
| 126 | struct tpm_getcap_params_out getcap_out; |
| 127 | struct tpm_getcap_params_in getcap_in; |
| 128 | }; |
| 129 | |
| 130 | struct tpm_cmd_t { |
| 131 | union tpm_cmd_header header; |
| 132 | union tpm_cmd_params params; |
| 133 | } __packed; |
| 134 | |
| 135 | |
| 136 | /* ---------- Interface for TPM vendor ------------ */ |
| 137 | |
| 138 | extern struct tpm_chip *tpm_register_hardware( |
| 139 | const struct tpm_vendor_specific *); |
| 140 | |
| 141 | extern int tpm_vendor_init(uint32_t dev_addr); |
| 142 | |
| 143 | extern void tpm_vendor_cleanup(struct tpm_chip *chip); |
| 144 | |
| 145 | /* ---------- Interface for TDDL ------------------- */ |
| 146 | |
| 147 | /* |
| 148 | * if dev_addr != 0 - redefines TPM device address |
| 149 | * Returns < 0 on error, 0 on success. |
| 150 | */ |
| 151 | extern int tpm_open(uint32_t dev_addr); |
| 152 | |
| 153 | extern void tpm_close(void); |
| 154 | |
| 155 | /* |
| 156 | * Transmit bufsiz bytes out of buf to TPM and get results back in buf, too. |
| 157 | * Returns < 0 on error, 0 on success. |
| 158 | */ |
| 159 | extern ssize_t tpm_transmit(const unsigned char *buf, size_t bufsiz); |
| 160 | |
| 161 | #endif |