Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004 IBM Corporation |
| 3 | * |
| 4 | * Authors: |
| 5 | * Leendert van Doorn <leendert@watson.ibm.com> |
| 6 | * Dave Safford <safford@watson.ibm.com> |
| 7 | * Reiner Sailer <sailer@watson.ibm.com> |
| 8 | * Kylene Hall <kjhall@us.ibm.com> |
| 9 | * |
| 10 | * Maintained by: <tpmdd_devel@lists.sourceforge.net> |
| 11 | * |
| 12 | * Device driver for TCG/TCPA TPM (trusted platform module). |
| 13 | * Specifications at www.trustedcomputinggroup.org |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License as |
| 17 | * published by the Free Software Foundation, version 2 of the |
| 18 | * License. |
| 19 | * |
| 20 | * Note, the TPM chip is not interrupt driven (only polling) |
| 21 | * and can have very long timeouts (minutes!). Hence the unusual |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 22 | * calls to msleep. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/poll.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include "tpm.h" |
| 30 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 31 | enum tpm_const { |
| 32 | TPM_MINOR = 224, /* officially assigned */ |
| 33 | TPM_BUFSIZE = 2048, |
| 34 | TPM_NUM_DEVICES = 256, |
| 35 | TPM_NUM_MASK_ENTRIES = TPM_NUM_DEVICES / (8 * sizeof(int)) |
| 36 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static LIST_HEAD(tpm_chip_list); |
| 39 | static DEFINE_SPINLOCK(driver_lock); |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 40 | static int dev_mask[TPM_NUM_MASK_ENTRIES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | static void user_reader_timeout(unsigned long ptr) |
| 43 | { |
| 44 | struct tpm_chip *chip = (struct tpm_chip *) ptr; |
| 45 | |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 46 | schedule_work(&chip->work); |
| 47 | } |
| 48 | |
Kylene Jo Hall | 3c2f606 | 2006-04-22 02:36:56 -0700 | [diff] [blame] | 49 | static void timeout_work(void *ptr) |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 50 | { |
| 51 | struct tpm_chip *chip = ptr; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | down(&chip->buffer_mutex); |
| 54 | atomic_set(&chip->data_pending, 0); |
| 55 | memset(chip->data_buffer, 0, TPM_BUFSIZE); |
| 56 | up(&chip->buffer_mutex); |
| 57 | } |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * Internal kernel interface to transmit TPM commands |
| 61 | */ |
| 62 | static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, |
| 63 | size_t bufsiz) |
| 64 | { |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 65 | ssize_t rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | u32 count; |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 67 | unsigned long stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 69 | count = be32_to_cpu(*((__be32 *) (buf + 2))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | if (count == 0) |
| 72 | return -ENODATA; |
| 73 | if (count > bufsiz) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 74 | dev_err(chip->dev, |
Al Viro | b76be68 | 2005-04-26 07:43:41 -0700 | [diff] [blame] | 75 | "invalid count value %x %zx \n", count, bufsiz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return -E2BIG; |
| 77 | } |
| 78 | |
| 79 | down(&chip->tpm_mutex); |
| 80 | |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 81 | if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 82 | dev_err(chip->dev, |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 83 | "tpm_transmit: tpm_send: error %zd\n", rc); |
| 84 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 87 | stop = jiffies + 2 * 60 * HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | do { |
Kylene Jo Hall | b4ed3e3 | 2005-10-30 15:03:23 -0800 | [diff] [blame] | 89 | u8 status = chip->vendor->status(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | if ((status & chip->vendor->req_complete_mask) == |
| 91 | chip->vendor->req_complete_val) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | goto out_recv; |
| 93 | } |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 94 | |
| 95 | if ((status == chip->vendor->req_canceled)) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 96 | dev_err(chip->dev, "Operation Canceled\n"); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 97 | rc = -ECANCELED; |
| 98 | goto out; |
| 99 | } |
| 100 | |
| 101 | msleep(TPM_TIMEOUT); /* CHECK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | rmb(); |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 103 | } while (time_before(jiffies, stop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | |
| 106 | chip->vendor->cancel(chip); |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 107 | dev_err(chip->dev, "Operation Timed out\n"); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 108 | rc = -ETIME; |
| 109 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | out_recv: |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 112 | rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); |
| 113 | if (rc < 0) |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 114 | dev_err(chip->dev, |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 115 | "tpm_transmit: tpm_recv: error %zd\n", rc); |
| 116 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | up(&chip->tpm_mutex); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 118 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | #define TPM_DIGEST_SIZE 20 |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 122 | #define TPM_ERROR_SIZE 10 |
| 123 | #define TPM_RET_CODE_IDX 6 |
| 124 | #define TPM_GET_CAP_RET_SIZE_IDX 10 |
| 125 | #define TPM_GET_CAP_RET_UINT32_1_IDX 14 |
| 126 | #define TPM_GET_CAP_RET_UINT32_2_IDX 18 |
| 127 | #define TPM_GET_CAP_RET_UINT32_3_IDX 22 |
| 128 | #define TPM_GET_CAP_RET_UINT32_4_IDX 26 |
| 129 | |
| 130 | #define TPM_CAP_IDX 13 |
| 131 | #define TPM_CAP_SUBCAP_IDX 21 |
| 132 | |
| 133 | enum tpm_capabilities { |
| 134 | TPM_CAP_PROP = 5, |
| 135 | }; |
| 136 | |
| 137 | enum tpm_sub_capabilities { |
| 138 | TPM_CAP_PROP_PCR = 0x1, |
| 139 | TPM_CAP_PROP_MANUFACTURER = 0x3, |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * This is a semi generic GetCapability command for use |
| 144 | * with the capability type TPM_CAP_PROP or TPM_CAP_FLAG |
| 145 | * and their associated sub_capabilities. |
| 146 | */ |
| 147 | |
| 148 | static const u8 tpm_cap[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 150 | 0, 0, 0, 22, /* length */ |
| 151 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 152 | 0, 0, 0, 0, /* TPM_CAP_<TYPE> */ |
| 153 | 0, 0, 0, 4, /* TPM_CAP_SUB_<TYPE> size */ |
| 154 | 0, 0, 1, 0 /* TPM_CAP_SUB_<TYPE> */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 157 | static ssize_t transmit_cmd(struct tpm_chip *chip, u8 *data, int len, |
| 158 | char *desc) |
| 159 | { |
| 160 | int err; |
| 161 | |
| 162 | len = tpm_transmit(chip, data, len); |
| 163 | if (len < 0) |
| 164 | return len; |
| 165 | if (len == TPM_ERROR_SIZE) { |
| 166 | err = be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))); |
| 167 | dev_dbg(chip->dev, "A TPM error (%d) occurred %s\n", err, desc); |
| 168 | return err; |
| 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | |
Kylene Hall | dff37e4 | 2005-06-23 22:01:50 -0700 | [diff] [blame] | 173 | static const u8 pcrread[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 175 | 0, 0, 0, 14, /* length */ |
| 176 | 0, 0, 0, 21, /* TPM_ORD_PcrRead */ |
| 177 | 0, 0, 0, 0 /* PCR index */ |
| 178 | }; |
| 179 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 180 | ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr, |
| 181 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 183 | u8 data[30]; |
| 184 | ssize_t rc; |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 185 | int i, j, num_pcrs; |
| 186 | __be32 index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | char *str = buf; |
| 188 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 189 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | if (chip == NULL) |
| 191 | return -ENODEV; |
| 192 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 193 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 194 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 195 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_PCR; |
| 196 | |
| 197 | rc = transmit_cmd(chip, data, sizeof(data), |
| 198 | "attempting to determine the number of PCRS"); |
| 199 | if (rc) |
Kylene Hall | e234bc9 | 2005-06-23 22:02:08 -0700 | [diff] [blame] | 200 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 202 | num_pcrs = be32_to_cpu(*((__be32 *) (data + 14))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | for (i = 0; i < num_pcrs; i++) { |
| 204 | memcpy(data, pcrread, sizeof(pcrread)); |
| 205 | index = cpu_to_be32(i); |
| 206 | memcpy(data + 10, &index, 4); |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 207 | rc = transmit_cmd(chip, data, sizeof(data), |
| 208 | "attempting to read a PCR"); |
| 209 | if (rc) |
Kylene Hall | e234bc9 | 2005-06-23 22:02:08 -0700 | [diff] [blame] | 210 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | str += sprintf(str, "PCR-%02d: ", i); |
| 212 | for (j = 0; j < TPM_DIGEST_SIZE; j++) |
| 213 | str += sprintf(str, "%02X ", *(data + 10 + j)); |
| 214 | str += sprintf(str, "\n"); |
| 215 | } |
Kylene Hall | e234bc9 | 2005-06-23 22:02:08 -0700 | [diff] [blame] | 216 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return str - buf; |
| 218 | } |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 219 | EXPORT_SYMBOL_GPL(tpm_show_pcrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | #define READ_PUBEK_RESULT_SIZE 314 |
Kylene Hall | dff37e4 | 2005-06-23 22:01:50 -0700 | [diff] [blame] | 222 | static const u8 readpubek[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 224 | 0, 0, 0, 30, /* length */ |
| 225 | 0, 0, 0, 124, /* TPM_ORD_ReadPubek */ |
| 226 | }; |
| 227 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 228 | ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr, |
| 229 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Kylene Hall | 2df7111 | 2005-06-23 22:01:54 -0700 | [diff] [blame] | 231 | u8 *data; |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 232 | ssize_t err; |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 233 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | char *str = buf; |
| 235 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 236 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | if (chip == NULL) |
| 238 | return -ENODEV; |
| 239 | |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 240 | data = kzalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL); |
Kylene Hall | 2df7111 | 2005-06-23 22:01:54 -0700 | [diff] [blame] | 241 | if (!data) |
| 242 | return -ENOMEM; |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | memcpy(data, readpubek, sizeof(readpubek)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 246 | err = transmit_cmd(chip, data, READ_PUBEK_RESULT_SIZE, |
| 247 | "attempting to read the PUBEK"); |
| 248 | if (err) |
Kylene Jo Hall | 34d6e07 | 2005-06-23 22:02:10 -0700 | [diff] [blame] | 249 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | /* |
| 252 | ignore header 10 bytes |
| 253 | algorithm 32 bits (1 == RSA ) |
| 254 | encscheme 16 bits |
| 255 | sigscheme 16 bits |
| 256 | parameters (RSA 12->bytes: keybit, #primes, expbit) |
| 257 | keylenbytes 32 bits |
| 258 | 256 byte modulus |
| 259 | ignore checksum 20 bytes |
| 260 | */ |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | str += |
| 263 | sprintf(str, |
| 264 | "Algorithm: %02X %02X %02X %02X\nEncscheme: %02X %02X\n" |
| 265 | "Sigscheme: %02X %02X\nParameters: %02X %02X %02X %02X" |
| 266 | " %02X %02X %02X %02X %02X %02X %02X %02X\n" |
| 267 | "Modulus length: %d\nModulus: \n", |
| 268 | data[10], data[11], data[12], data[13], data[14], |
| 269 | data[15], data[16], data[17], data[22], data[23], |
| 270 | data[24], data[25], data[26], data[27], data[28], |
| 271 | data[29], data[30], data[31], data[32], data[33], |
Kylene Jo Hall | 1dda8ab | 2005-06-25 14:55:40 -0700 | [diff] [blame] | 272 | be32_to_cpu(*((__be32 *) (data + 34)))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | for (i = 0; i < 256; i++) { |
Kylene Jo Hall | 1dda8ab | 2005-06-25 14:55:40 -0700 | [diff] [blame] | 275 | str += sprintf(str, "%02X ", data[i + 38]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | if ((i + 1) % 16 == 0) |
| 277 | str += sprintf(str, "\n"); |
| 278 | } |
Kylene Jo Hall | 34d6e07 | 2005-06-23 22:02:10 -0700 | [diff] [blame] | 279 | out: |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 280 | rc = str - buf; |
Kylene Hall | 2df7111 | 2005-06-23 22:01:54 -0700 | [diff] [blame] | 281 | kfree(data); |
| 282 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 284 | EXPORT_SYMBOL_GPL(tpm_show_pubek); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 286 | #define CAP_VERSION_1_1 6 |
| 287 | #define CAP_VERSION_IDX 13 |
Kylene Hall | dff37e4 | 2005-06-23 22:01:50 -0700 | [diff] [blame] | 288 | static const u8 cap_version[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 290 | 0, 0, 0, 18, /* length */ |
| 291 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 292 | 0, 0, 0, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | 0, 0, 0, 0 |
| 294 | }; |
| 295 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 296 | ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr, |
| 297 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 299 | u8 data[30]; |
| 300 | ssize_t rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | char *str = buf; |
| 302 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 303 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | if (chip == NULL) |
| 305 | return -ENODEV; |
| 306 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 307 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 308 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 309 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 311 | rc = transmit_cmd(chip, data, sizeof(data), |
| 312 | "attempting to determine the manufacturer"); |
| 313 | if (rc) |
| 314 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | str += sprintf(str, "Manufacturer: 0x%x\n", |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 317 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | memcpy(data, cap_version, sizeof(cap_version)); |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 320 | data[CAP_VERSION_IDX] = CAP_VERSION_1_1; |
| 321 | rc = transmit_cmd(chip, data, sizeof(data), |
| 322 | "attempting to determine the 1.1 version"); |
| 323 | if (rc) |
| 324 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 326 | str += sprintf(str, |
| 327 | "TCG version: %d.%d\nFirmware version: %d.%d\n", |
| 328 | (int) data[14], (int) data[15], (int) data[16], |
| 329 | (int) data[17]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame^] | 331 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | return str - buf; |
| 333 | } |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 334 | EXPORT_SYMBOL_GPL(tpm_show_caps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 336 | ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, |
| 337 | const char *buf, size_t count) |
| 338 | { |
| 339 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 340 | if (chip == NULL) |
| 341 | return 0; |
| 342 | |
| 343 | chip->vendor->cancel(chip); |
| 344 | return count; |
| 345 | } |
| 346 | EXPORT_SYMBOL_GPL(tpm_store_cancel); |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | /* |
| 349 | * Device file system interface to the TPM |
| 350 | */ |
| 351 | int tpm_open(struct inode *inode, struct file *file) |
| 352 | { |
| 353 | int rc = 0, minor = iminor(inode); |
| 354 | struct tpm_chip *chip = NULL, *pos; |
| 355 | |
| 356 | spin_lock(&driver_lock); |
| 357 | |
| 358 | list_for_each_entry(pos, &tpm_chip_list, list) { |
| 359 | if (pos->vendor->miscdev.minor == minor) { |
| 360 | chip = pos; |
| 361 | break; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if (chip == NULL) { |
| 366 | rc = -ENODEV; |
| 367 | goto err_out; |
| 368 | } |
| 369 | |
| 370 | if (chip->num_opens) { |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 371 | dev_dbg(chip->dev, "Another process owns this TPM\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | rc = -EBUSY; |
| 373 | goto err_out; |
| 374 | } |
| 375 | |
| 376 | chip->num_opens++; |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 377 | get_device(chip->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | spin_unlock(&driver_lock); |
| 380 | |
| 381 | chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); |
| 382 | if (chip->data_buffer == NULL) { |
| 383 | chip->num_opens--; |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 384 | put_device(chip->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return -ENOMEM; |
| 386 | } |
| 387 | |
| 388 | atomic_set(&chip->data_pending, 0); |
| 389 | |
| 390 | file->private_data = chip; |
| 391 | return 0; |
| 392 | |
| 393 | err_out: |
| 394 | spin_unlock(&driver_lock); |
| 395 | return rc; |
| 396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | EXPORT_SYMBOL_GPL(tpm_open); |
| 398 | |
| 399 | int tpm_release(struct inode *inode, struct file *file) |
| 400 | { |
| 401 | struct tpm_chip *chip = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | spin_lock(&driver_lock); |
Kylene Hall | 5e976d5 | 2005-06-23 22:02:03 -0700 | [diff] [blame] | 404 | file->private_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | chip->num_opens--; |
Kylene Hall | fe3fd483 | 2005-06-23 22:01:56 -0700 | [diff] [blame] | 406 | del_singleshot_timer_sync(&chip->user_read_timer); |
Kylene Jo Hall | ba39611 | 2005-11-18 01:10:57 -0800 | [diff] [blame] | 407 | flush_scheduled_work(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | atomic_set(&chip->data_pending, 0); |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 409 | put_device(chip->dev); |
Kylene Hall | 5e976d5 | 2005-06-23 22:02:03 -0700 | [diff] [blame] | 410 | kfree(chip->data_buffer); |
| 411 | spin_unlock(&driver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | return 0; |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | EXPORT_SYMBOL_GPL(tpm_release); |
| 415 | |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 416 | ssize_t tpm_write(struct file *file, const char __user *buf, |
Kylene Jo Hall | 3c2f606 | 2006-04-22 02:36:56 -0700 | [diff] [blame] | 417 | size_t size, loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
| 419 | struct tpm_chip *chip = file->private_data; |
| 420 | int in_size = size, out_size; |
| 421 | |
| 422 | /* cannot perform a write until the read has cleared |
| 423 | either via tpm_read or a user_read_timer timeout */ |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 424 | while (atomic_read(&chip->data_pending) != 0) |
| 425 | msleep(TPM_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | down(&chip->buffer_mutex); |
| 428 | |
| 429 | if (in_size > TPM_BUFSIZE) |
| 430 | in_size = TPM_BUFSIZE; |
| 431 | |
| 432 | if (copy_from_user |
| 433 | (chip->data_buffer, (void __user *) buf, in_size)) { |
| 434 | up(&chip->buffer_mutex); |
| 435 | return -EFAULT; |
| 436 | } |
| 437 | |
| 438 | /* atomic tpm command send and result receive */ |
| 439 | out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); |
| 440 | |
| 441 | atomic_set(&chip->data_pending, out_size); |
| 442 | up(&chip->buffer_mutex); |
| 443 | |
| 444 | /* Set a timeout by which the reader must come claim the result */ |
Kylene Hall | fe3fd483 | 2005-06-23 22:01:56 -0700 | [diff] [blame] | 445 | mod_timer(&chip->user_read_timer, jiffies + (60 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
| 447 | return in_size; |
| 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | EXPORT_SYMBOL_GPL(tpm_write); |
| 450 | |
Kylene Jo Hall | 3c2f606 | 2006-04-22 02:36:56 -0700 | [diff] [blame] | 451 | ssize_t tpm_read(struct file *file, char __user *buf, |
| 452 | size_t size, loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
| 454 | struct tpm_chip *chip = file->private_data; |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 455 | int ret_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 457 | del_singleshot_timer_sync(&chip->user_read_timer); |
Kylene Jo Hall | ba39611 | 2005-11-18 01:10:57 -0800 | [diff] [blame] | 458 | flush_scheduled_work(); |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 459 | ret_size = atomic_read(&chip->data_pending); |
| 460 | atomic_set(&chip->data_pending, 0); |
| 461 | if (ret_size > 0) { /* relay data */ |
| 462 | if (size < ret_size) |
| 463 | ret_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | down(&chip->buffer_mutex); |
Kylene Jo Hall | f6a2382 | 2005-11-13 16:07:42 -0800 | [diff] [blame] | 466 | if (copy_to_user(buf, chip->data_buffer, ret_size)) |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 467 | ret_size = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | up(&chip->buffer_mutex); |
| 469 | } |
| 470 | |
| 471 | return ret_size; |
| 472 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | EXPORT_SYMBOL_GPL(tpm_read); |
| 474 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 475 | void tpm_remove_hardware(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 477 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | if (chip == NULL) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 480 | dev_err(dev, "No device data found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | return; |
| 482 | } |
| 483 | |
| 484 | spin_lock(&driver_lock); |
| 485 | |
| 486 | list_del(&chip->list); |
| 487 | |
| 488 | spin_unlock(&driver_lock); |
| 489 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 490 | dev_set_drvdata(dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | misc_deregister(&chip->vendor->miscdev); |
Kylene Jo Hall | 9a936eb | 2005-06-30 02:58:50 -0700 | [diff] [blame] | 492 | kfree(chip->vendor->miscdev.name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 494 | sysfs_remove_group(&dev->kobj, chip->vendor->attr_group); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 495 | tpm_bios_log_teardown(chip->bios_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 497 | dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= |
Kylene Jo Hall | f6a2382 | 2005-11-13 16:07:42 -0800 | [diff] [blame] | 498 | ~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | kfree(chip); |
| 501 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 502 | put_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 504 | EXPORT_SYMBOL_GPL(tpm_remove_hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
| 506 | static u8 savestate[] = { |
| 507 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 508 | 0, 0, 0, 10, /* blob length (in bytes) */ |
| 509 | 0, 0, 0, 152 /* TPM_ORD_SaveState */ |
| 510 | }; |
| 511 | |
| 512 | /* |
| 513 | * We are about to suspend. Save the TPM state |
| 514 | * so that it can be restored. |
| 515 | */ |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 516 | int tpm_pm_suspend(struct device *dev, pm_message_t pm_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 518 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (chip == NULL) |
| 520 | return -ENODEV; |
| 521 | |
| 522 | tpm_transmit(chip, savestate, sizeof(savestate)); |
| 523 | return 0; |
| 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | EXPORT_SYMBOL_GPL(tpm_pm_suspend); |
| 526 | |
| 527 | /* |
| 528 | * Resume from a power safe. The BIOS already restored |
| 529 | * the TPM state. |
| 530 | */ |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 531 | int tpm_pm_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 533 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | if (chip == NULL) |
| 536 | return -ENODEV; |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return 0; |
| 539 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | EXPORT_SYMBOL_GPL(tpm_pm_resume); |
| 541 | |
| 542 | /* |
| 543 | * Called from tpm_<specific>.c probe function only for devices |
| 544 | * the driver has determined it should claim. Prior to calling |
| 545 | * this function the specific probe function has called pci_enable_device |
| 546 | * upon errant exit from this function specific probe function should call |
| 547 | * pci_disable_device |
| 548 | */ |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 549 | int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Kylene Jo Hall | 6f9becc | 2005-06-25 14:55:41 -0700 | [diff] [blame] | 551 | #define DEVNAME_SIZE 7 |
| 552 | |
| 553 | char *devname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | struct tpm_chip *chip; |
| 555 | int i, j; |
| 556 | |
| 557 | /* Driver specific per-device data */ |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 558 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if (chip == NULL) |
| 560 | return -ENOMEM; |
| 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | init_MUTEX(&chip->buffer_mutex); |
| 563 | init_MUTEX(&chip->tpm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | INIT_LIST_HEAD(&chip->list); |
| 565 | |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 566 | INIT_WORK(&chip->work, timeout_work, chip); |
| 567 | |
Kylene Hall | fe3fd483 | 2005-06-23 22:01:56 -0700 | [diff] [blame] | 568 | init_timer(&chip->user_read_timer); |
| 569 | chip->user_read_timer.function = user_reader_timeout; |
| 570 | chip->user_read_timer.data = (unsigned long) chip; |
| 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | chip->vendor = entry; |
| 573 | |
| 574 | chip->dev_num = -1; |
| 575 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 576 | for (i = 0; i < TPM_NUM_MASK_ENTRIES; i++) |
| 577 | for (j = 0; j < 8 * sizeof(int); j++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | if ((dev_mask[i] & (1 << j)) == 0) { |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 579 | chip->dev_num = |
| 580 | i * TPM_NUM_MASK_ENTRIES + j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | dev_mask[i] |= 1 << j; |
| 582 | goto dev_num_search_complete; |
| 583 | } |
| 584 | |
| 585 | dev_num_search_complete: |
| 586 | if (chip->dev_num < 0) { |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 587 | dev_err(dev, "No available tpm device numbers\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | kfree(chip); |
| 589 | return -ENODEV; |
| 590 | } else if (chip->dev_num == 0) |
| 591 | chip->vendor->miscdev.minor = TPM_MINOR; |
| 592 | else |
| 593 | chip->vendor->miscdev.minor = MISC_DYNAMIC_MINOR; |
| 594 | |
Kylene Jo Hall | 6f9becc | 2005-06-25 14:55:41 -0700 | [diff] [blame] | 595 | devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); |
| 596 | scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | chip->vendor->miscdev.name = devname; |
| 598 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 599 | chip->vendor->miscdev.dev = dev; |
| 600 | chip->dev = get_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | if (misc_register(&chip->vendor->miscdev)) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 603 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | "unable to misc_register %s, minor %d\n", |
| 605 | chip->vendor->miscdev.name, |
| 606 | chip->vendor->miscdev.minor); |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 607 | put_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | kfree(chip); |
| 609 | dev_mask[i] &= !(1 << j); |
| 610 | return -ENODEV; |
| 611 | } |
| 612 | |
Kylene Hall | 5e976d5 | 2005-06-23 22:02:03 -0700 | [diff] [blame] | 613 | spin_lock(&driver_lock); |
| 614 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 615 | dev_set_drvdata(dev, chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
| 617 | list_add(&chip->list, &tpm_chip_list); |
| 618 | |
Kylene Hall | 5e976d5 | 2005-06-23 22:02:03 -0700 | [diff] [blame] | 619 | spin_unlock(&driver_lock); |
| 620 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 621 | sysfs_create_group(&dev->kobj, chip->vendor->attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 623 | chip->bios_dir = tpm_bios_log_setup(devname); |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return 0; |
| 626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | EXPORT_SYMBOL_GPL(tpm_register_hardware); |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); |
| 630 | MODULE_DESCRIPTION("TPM Driver"); |
| 631 | MODULE_VERSION("2.0"); |
| 632 | MODULE_LICENSE("GPL"); |