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 | * |
Kent Yoder | 8e81cc1 | 2007-08-22 14:01:04 -0700 | [diff] [blame] | 10 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/poll.h> |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 27 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/spinlock.h> |
Arnd Bergmann | 25368ca | 2008-05-20 19:16:51 +0200 | [diff] [blame] | 29 | #include <linux/smp_lock.h> |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "tpm.h" |
| 32 | |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 33 | enum tpm_const { |
| 34 | TPM_MINOR = 224, /* officially assigned */ |
| 35 | TPM_BUFSIZE = 2048, |
| 36 | TPM_NUM_DEVICES = 256, |
Kylene Hall | 3122a88 | 2005-06-23 22:01:48 -0700 | [diff] [blame] | 37 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 39 | enum tpm_duration { |
| 40 | TPM_SHORT = 0, |
| 41 | TPM_MEDIUM = 1, |
| 42 | TPM_LONG = 2, |
| 43 | TPM_UNDEFINED, |
| 44 | }; |
| 45 | |
| 46 | #define TPM_MAX_ORDINAL 243 |
| 47 | #define TPM_MAX_PROTECTED_ORDINAL 12 |
| 48 | #define TPM_PROTECTED_ORDINAL_MASK 0xFF |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static LIST_HEAD(tpm_chip_list); |
| 51 | static DEFINE_SPINLOCK(driver_lock); |
Kylene Jo Hall | 10685a9 | 2006-04-22 02:38:32 -0700 | [diff] [blame] | 52 | static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Array with one entry per ordinal defining the maximum amount |
| 56 | * of time the chip could take to return the result. The ordinal |
| 57 | * designation of short, medium or long is defined in a table in |
| 58 | * TCG Specification TPM Main Part 2 TPM Structures Section 17. The |
| 59 | * values of the SHORT, MEDIUM, and LONG durations are retrieved |
| 60 | * from the chip during initialization with a call to tpm_get_timeouts. |
| 61 | */ |
| 62 | static const u8 tpm_protected_ordinal_duration[TPM_MAX_PROTECTED_ORDINAL] = { |
| 63 | TPM_UNDEFINED, /* 0 */ |
| 64 | TPM_UNDEFINED, |
| 65 | TPM_UNDEFINED, |
| 66 | TPM_UNDEFINED, |
| 67 | TPM_UNDEFINED, |
| 68 | TPM_UNDEFINED, /* 5 */ |
| 69 | TPM_UNDEFINED, |
| 70 | TPM_UNDEFINED, |
| 71 | TPM_UNDEFINED, |
| 72 | TPM_UNDEFINED, |
| 73 | TPM_SHORT, /* 10 */ |
| 74 | TPM_SHORT, |
| 75 | }; |
| 76 | |
| 77 | static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = { |
| 78 | TPM_UNDEFINED, /* 0 */ |
| 79 | TPM_UNDEFINED, |
| 80 | TPM_UNDEFINED, |
| 81 | TPM_UNDEFINED, |
| 82 | TPM_UNDEFINED, |
| 83 | TPM_UNDEFINED, /* 5 */ |
| 84 | TPM_UNDEFINED, |
| 85 | TPM_UNDEFINED, |
| 86 | TPM_UNDEFINED, |
| 87 | TPM_UNDEFINED, |
| 88 | TPM_SHORT, /* 10 */ |
| 89 | TPM_SHORT, |
| 90 | TPM_MEDIUM, |
| 91 | TPM_LONG, |
| 92 | TPM_LONG, |
| 93 | TPM_MEDIUM, /* 15 */ |
| 94 | TPM_SHORT, |
| 95 | TPM_SHORT, |
| 96 | TPM_MEDIUM, |
| 97 | TPM_LONG, |
| 98 | TPM_SHORT, /* 20 */ |
| 99 | TPM_SHORT, |
| 100 | TPM_MEDIUM, |
| 101 | TPM_MEDIUM, |
| 102 | TPM_MEDIUM, |
| 103 | TPM_SHORT, /* 25 */ |
| 104 | TPM_SHORT, |
| 105 | TPM_MEDIUM, |
| 106 | TPM_SHORT, |
| 107 | TPM_SHORT, |
| 108 | TPM_MEDIUM, /* 30 */ |
| 109 | TPM_LONG, |
| 110 | TPM_MEDIUM, |
| 111 | TPM_SHORT, |
| 112 | TPM_SHORT, |
| 113 | TPM_SHORT, /* 35 */ |
| 114 | TPM_MEDIUM, |
| 115 | TPM_MEDIUM, |
| 116 | TPM_UNDEFINED, |
| 117 | TPM_UNDEFINED, |
| 118 | TPM_MEDIUM, /* 40 */ |
| 119 | TPM_LONG, |
| 120 | TPM_MEDIUM, |
| 121 | TPM_SHORT, |
| 122 | TPM_SHORT, |
| 123 | TPM_SHORT, /* 45 */ |
| 124 | TPM_SHORT, |
| 125 | TPM_SHORT, |
| 126 | TPM_SHORT, |
| 127 | TPM_LONG, |
| 128 | TPM_MEDIUM, /* 50 */ |
| 129 | TPM_MEDIUM, |
| 130 | TPM_UNDEFINED, |
| 131 | TPM_UNDEFINED, |
| 132 | TPM_UNDEFINED, |
| 133 | TPM_UNDEFINED, /* 55 */ |
| 134 | TPM_UNDEFINED, |
| 135 | TPM_UNDEFINED, |
| 136 | TPM_UNDEFINED, |
| 137 | TPM_UNDEFINED, |
| 138 | TPM_MEDIUM, /* 60 */ |
| 139 | TPM_MEDIUM, |
| 140 | TPM_MEDIUM, |
| 141 | TPM_SHORT, |
| 142 | TPM_SHORT, |
| 143 | TPM_MEDIUM, /* 65 */ |
| 144 | TPM_UNDEFINED, |
| 145 | TPM_UNDEFINED, |
| 146 | TPM_UNDEFINED, |
| 147 | TPM_UNDEFINED, |
| 148 | TPM_SHORT, /* 70 */ |
| 149 | TPM_SHORT, |
| 150 | TPM_UNDEFINED, |
| 151 | TPM_UNDEFINED, |
| 152 | TPM_UNDEFINED, |
| 153 | TPM_UNDEFINED, /* 75 */ |
| 154 | TPM_UNDEFINED, |
| 155 | TPM_UNDEFINED, |
| 156 | TPM_UNDEFINED, |
| 157 | TPM_UNDEFINED, |
| 158 | TPM_LONG, /* 80 */ |
| 159 | TPM_UNDEFINED, |
| 160 | TPM_MEDIUM, |
| 161 | TPM_LONG, |
| 162 | TPM_SHORT, |
| 163 | TPM_UNDEFINED, /* 85 */ |
| 164 | TPM_UNDEFINED, |
| 165 | TPM_UNDEFINED, |
| 166 | TPM_UNDEFINED, |
| 167 | TPM_UNDEFINED, |
| 168 | TPM_SHORT, /* 90 */ |
| 169 | TPM_SHORT, |
| 170 | TPM_SHORT, |
| 171 | TPM_SHORT, |
| 172 | TPM_SHORT, |
| 173 | TPM_UNDEFINED, /* 95 */ |
| 174 | TPM_UNDEFINED, |
| 175 | TPM_UNDEFINED, |
| 176 | TPM_UNDEFINED, |
| 177 | TPM_UNDEFINED, |
| 178 | TPM_MEDIUM, /* 100 */ |
| 179 | TPM_SHORT, |
| 180 | TPM_SHORT, |
| 181 | TPM_UNDEFINED, |
| 182 | TPM_UNDEFINED, |
| 183 | TPM_UNDEFINED, /* 105 */ |
| 184 | TPM_UNDEFINED, |
| 185 | TPM_UNDEFINED, |
| 186 | TPM_UNDEFINED, |
| 187 | TPM_UNDEFINED, |
| 188 | TPM_SHORT, /* 110 */ |
| 189 | TPM_SHORT, |
| 190 | TPM_SHORT, |
| 191 | TPM_SHORT, |
| 192 | TPM_SHORT, |
| 193 | TPM_SHORT, /* 115 */ |
| 194 | TPM_SHORT, |
| 195 | TPM_SHORT, |
| 196 | TPM_UNDEFINED, |
| 197 | TPM_UNDEFINED, |
| 198 | TPM_LONG, /* 120 */ |
| 199 | TPM_LONG, |
| 200 | TPM_MEDIUM, |
| 201 | TPM_UNDEFINED, |
| 202 | TPM_SHORT, |
| 203 | TPM_SHORT, /* 125 */ |
| 204 | TPM_SHORT, |
| 205 | TPM_LONG, |
| 206 | TPM_SHORT, |
| 207 | TPM_SHORT, |
| 208 | TPM_SHORT, /* 130 */ |
| 209 | TPM_MEDIUM, |
| 210 | TPM_UNDEFINED, |
| 211 | TPM_SHORT, |
| 212 | TPM_MEDIUM, |
| 213 | TPM_UNDEFINED, /* 135 */ |
| 214 | TPM_UNDEFINED, |
| 215 | TPM_UNDEFINED, |
| 216 | TPM_UNDEFINED, |
| 217 | TPM_UNDEFINED, |
| 218 | TPM_SHORT, /* 140 */ |
| 219 | TPM_SHORT, |
| 220 | TPM_UNDEFINED, |
| 221 | TPM_UNDEFINED, |
| 222 | TPM_UNDEFINED, |
| 223 | TPM_UNDEFINED, /* 145 */ |
| 224 | TPM_UNDEFINED, |
| 225 | TPM_UNDEFINED, |
| 226 | TPM_UNDEFINED, |
| 227 | TPM_UNDEFINED, |
| 228 | TPM_SHORT, /* 150 */ |
| 229 | TPM_MEDIUM, |
| 230 | TPM_MEDIUM, |
| 231 | TPM_SHORT, |
| 232 | TPM_SHORT, |
| 233 | TPM_UNDEFINED, /* 155 */ |
| 234 | TPM_UNDEFINED, |
| 235 | TPM_UNDEFINED, |
| 236 | TPM_UNDEFINED, |
| 237 | TPM_UNDEFINED, |
| 238 | TPM_SHORT, /* 160 */ |
| 239 | TPM_SHORT, |
| 240 | TPM_SHORT, |
| 241 | TPM_SHORT, |
| 242 | TPM_UNDEFINED, |
| 243 | TPM_UNDEFINED, /* 165 */ |
| 244 | TPM_UNDEFINED, |
| 245 | TPM_UNDEFINED, |
| 246 | TPM_UNDEFINED, |
| 247 | TPM_UNDEFINED, |
| 248 | TPM_LONG, /* 170 */ |
| 249 | TPM_UNDEFINED, |
| 250 | TPM_UNDEFINED, |
| 251 | TPM_UNDEFINED, |
| 252 | TPM_UNDEFINED, |
| 253 | TPM_UNDEFINED, /* 175 */ |
| 254 | TPM_UNDEFINED, |
| 255 | TPM_UNDEFINED, |
| 256 | TPM_UNDEFINED, |
| 257 | TPM_UNDEFINED, |
| 258 | TPM_MEDIUM, /* 180 */ |
| 259 | TPM_SHORT, |
| 260 | TPM_MEDIUM, |
| 261 | TPM_MEDIUM, |
| 262 | TPM_MEDIUM, |
| 263 | TPM_MEDIUM, /* 185 */ |
| 264 | TPM_SHORT, |
| 265 | TPM_UNDEFINED, |
| 266 | TPM_UNDEFINED, |
| 267 | TPM_UNDEFINED, |
| 268 | TPM_UNDEFINED, /* 190 */ |
| 269 | TPM_UNDEFINED, |
| 270 | TPM_UNDEFINED, |
| 271 | TPM_UNDEFINED, |
| 272 | TPM_UNDEFINED, |
| 273 | TPM_UNDEFINED, /* 195 */ |
| 274 | TPM_UNDEFINED, |
| 275 | TPM_UNDEFINED, |
| 276 | TPM_UNDEFINED, |
| 277 | TPM_UNDEFINED, |
| 278 | TPM_SHORT, /* 200 */ |
| 279 | TPM_UNDEFINED, |
| 280 | TPM_UNDEFINED, |
| 281 | TPM_UNDEFINED, |
| 282 | TPM_SHORT, |
| 283 | TPM_SHORT, /* 205 */ |
| 284 | TPM_SHORT, |
| 285 | TPM_SHORT, |
| 286 | TPM_SHORT, |
| 287 | TPM_SHORT, |
| 288 | TPM_MEDIUM, /* 210 */ |
| 289 | TPM_UNDEFINED, |
| 290 | TPM_MEDIUM, |
| 291 | TPM_MEDIUM, |
| 292 | TPM_MEDIUM, |
| 293 | TPM_UNDEFINED, /* 215 */ |
| 294 | TPM_MEDIUM, |
| 295 | TPM_UNDEFINED, |
| 296 | TPM_UNDEFINED, |
| 297 | TPM_SHORT, |
| 298 | TPM_SHORT, /* 220 */ |
| 299 | TPM_SHORT, |
| 300 | TPM_SHORT, |
| 301 | TPM_SHORT, |
| 302 | TPM_SHORT, |
| 303 | TPM_UNDEFINED, /* 225 */ |
| 304 | TPM_UNDEFINED, |
| 305 | TPM_UNDEFINED, |
| 306 | TPM_UNDEFINED, |
| 307 | TPM_UNDEFINED, |
| 308 | TPM_SHORT, /* 230 */ |
| 309 | TPM_LONG, |
| 310 | TPM_MEDIUM, |
| 311 | TPM_UNDEFINED, |
| 312 | TPM_UNDEFINED, |
| 313 | TPM_UNDEFINED, /* 235 */ |
| 314 | TPM_UNDEFINED, |
| 315 | TPM_UNDEFINED, |
| 316 | TPM_UNDEFINED, |
| 317 | TPM_UNDEFINED, |
| 318 | TPM_SHORT, /* 240 */ |
| 319 | TPM_UNDEFINED, |
| 320 | TPM_MEDIUM, |
| 321 | }; |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | static void user_reader_timeout(unsigned long ptr) |
| 324 | { |
| 325 | struct tpm_chip *chip = (struct tpm_chip *) ptr; |
| 326 | |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 327 | schedule_work(&chip->work); |
| 328 | } |
| 329 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 330 | static void timeout_work(struct work_struct *work) |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 331 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 332 | struct tpm_chip *chip = container_of(work, struct tpm_chip, work); |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 333 | |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 334 | mutex_lock(&chip->buffer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | atomic_set(&chip->data_pending, 0); |
| 336 | memset(chip->data_buffer, 0, TPM_BUFSIZE); |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 337 | mutex_unlock(&chip->buffer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 341 | * Returns max number of jiffies to wait |
| 342 | */ |
| 343 | unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, |
| 344 | u32 ordinal) |
| 345 | { |
| 346 | int duration_idx = TPM_UNDEFINED; |
| 347 | int duration = 0; |
| 348 | |
| 349 | if (ordinal < TPM_MAX_ORDINAL) |
| 350 | duration_idx = tpm_ordinal_duration[ordinal]; |
| 351 | else if ((ordinal & TPM_PROTECTED_ORDINAL_MASK) < |
| 352 | TPM_MAX_PROTECTED_ORDINAL) |
| 353 | duration_idx = |
| 354 | tpm_protected_ordinal_duration[ordinal & |
| 355 | TPM_PROTECTED_ORDINAL_MASK]; |
| 356 | |
| 357 | if (duration_idx != TPM_UNDEFINED) |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 358 | duration = chip->vendor.duration[duration_idx]; |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 359 | if (duration <= 0) |
| 360 | return 2 * 60 * HZ; |
| 361 | else |
| 362 | return duration; |
| 363 | } |
| 364 | EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration); |
| 365 | |
| 366 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * Internal kernel interface to transmit TPM commands |
| 368 | */ |
| 369 | static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, |
| 370 | size_t bufsiz) |
| 371 | { |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 372 | ssize_t rc; |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 373 | u32 count, ordinal; |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 374 | unsigned long stop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 376 | count = be32_to_cpu(*((__be32 *) (buf + 2))); |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 377 | ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | if (count == 0) |
| 379 | return -ENODATA; |
| 380 | if (count > bufsiz) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 381 | dev_err(chip->dev, |
Al Viro | b76be68 | 2005-04-26 07:43:41 -0700 | [diff] [blame] | 382 | "invalid count value %x %zx \n", count, bufsiz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | return -E2BIG; |
| 384 | } |
| 385 | |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 386 | mutex_lock(&chip->tpm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 388 | if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 389 | dev_err(chip->dev, |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 390 | "tpm_transmit: tpm_send: error %zd\n", rc); |
| 391 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Leendert van Doorn | 27084ef | 2006-04-22 02:38:03 -0700 | [diff] [blame] | 394 | if (chip->vendor.irq) |
| 395 | goto out_recv; |
| 396 | |
Kylene Jo Hall | 9e18ee1 | 2006-04-22 02:37:38 -0700 | [diff] [blame] | 397 | stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | do { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 399 | u8 status = chip->vendor.status(chip); |
| 400 | if ((status & chip->vendor.req_complete_mask) == |
| 401 | chip->vendor.req_complete_val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | goto out_recv; |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 403 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 404 | if ((status == chip->vendor.req_canceled)) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 405 | dev_err(chip->dev, "Operation Canceled\n"); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 406 | rc = -ECANCELED; |
| 407 | goto out; |
| 408 | } |
| 409 | |
| 410 | msleep(TPM_TIMEOUT); /* CHECK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | rmb(); |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 412 | } while (time_before(jiffies, stop)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 414 | chip->vendor.cancel(chip); |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 415 | dev_err(chip->dev, "Operation Timed out\n"); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 416 | rc = -ETIME; |
| 417 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | out_recv: |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 420 | rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 421 | if (rc < 0) |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 422 | dev_err(chip->dev, |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 423 | "tpm_transmit: tpm_recv: error %zd\n", rc); |
| 424 | out: |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 425 | mutex_unlock(&chip->tpm_mutex); |
Kylene Hall | d9e5b6b | 2005-06-23 22:02:02 -0700 | [diff] [blame] | 426 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | #define TPM_DIGEST_SIZE 20 |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 430 | #define TPM_ERROR_SIZE 10 |
| 431 | #define TPM_RET_CODE_IDX 6 |
| 432 | #define TPM_GET_CAP_RET_SIZE_IDX 10 |
| 433 | #define TPM_GET_CAP_RET_UINT32_1_IDX 14 |
| 434 | #define TPM_GET_CAP_RET_UINT32_2_IDX 18 |
| 435 | #define TPM_GET_CAP_RET_UINT32_3_IDX 22 |
| 436 | #define TPM_GET_CAP_RET_UINT32_4_IDX 26 |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 437 | #define TPM_GET_CAP_PERM_DISABLE_IDX 16 |
| 438 | #define TPM_GET_CAP_PERM_INACTIVE_IDX 18 |
| 439 | #define TPM_GET_CAP_RET_BOOL_1_IDX 14 |
| 440 | #define TPM_GET_CAP_TEMP_INACTIVE_IDX 16 |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 441 | |
| 442 | #define TPM_CAP_IDX 13 |
| 443 | #define TPM_CAP_SUBCAP_IDX 21 |
| 444 | |
| 445 | enum tpm_capabilities { |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 446 | TPM_CAP_FLAG = 4, |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 447 | TPM_CAP_PROP = 5, |
| 448 | }; |
| 449 | |
| 450 | enum tpm_sub_capabilities { |
| 451 | TPM_CAP_PROP_PCR = 0x1, |
| 452 | TPM_CAP_PROP_MANUFACTURER = 0x3, |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 453 | TPM_CAP_FLAG_PERM = 0x8, |
| 454 | TPM_CAP_FLAG_VOL = 0x9, |
| 455 | TPM_CAP_PROP_OWNER = 0x11, |
| 456 | TPM_CAP_PROP_TIS_TIMEOUT = 0x15, |
| 457 | TPM_CAP_PROP_TIS_DURATION = 0x20, |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | /* |
| 461 | * This is a semi generic GetCapability command for use |
| 462 | * with the capability type TPM_CAP_PROP or TPM_CAP_FLAG |
| 463 | * and their associated sub_capabilities. |
| 464 | */ |
| 465 | |
| 466 | static const u8 tpm_cap[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 468 | 0, 0, 0, 22, /* length */ |
| 469 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 470 | 0, 0, 0, 0, /* TPM_CAP_<TYPE> */ |
| 471 | 0, 0, 0, 4, /* TPM_CAP_SUB_<TYPE> size */ |
| 472 | 0, 0, 1, 0 /* TPM_CAP_SUB_<TYPE> */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | }; |
| 474 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 475 | static ssize_t transmit_cmd(struct tpm_chip *chip, u8 *data, int len, |
| 476 | char *desc) |
| 477 | { |
| 478 | int err; |
| 479 | |
| 480 | len = tpm_transmit(chip, data, len); |
| 481 | if (len < 0) |
| 482 | return len; |
| 483 | if (len == TPM_ERROR_SIZE) { |
| 484 | err = be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX))); |
| 485 | dev_dbg(chip->dev, "A TPM error (%d) occurred %s\n", err, desc); |
| 486 | return err; |
| 487 | } |
| 488 | return 0; |
| 489 | } |
| 490 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 491 | void tpm_gen_interrupt(struct tpm_chip *chip) |
| 492 | { |
| 493 | u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 30)]; |
| 494 | ssize_t rc; |
| 495 | |
| 496 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 497 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 498 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_TIMEOUT; |
| 499 | |
| 500 | rc = transmit_cmd(chip, data, sizeof(data), |
| 501 | "attempting to determine the timeouts"); |
| 502 | } |
| 503 | EXPORT_SYMBOL_GPL(tpm_gen_interrupt); |
| 504 | |
| 505 | void tpm_get_timeouts(struct tpm_chip *chip) |
| 506 | { |
| 507 | u8 data[max_t(int, ARRAY_SIZE(tpm_cap), 30)]; |
| 508 | ssize_t rc; |
| 509 | u32 timeout; |
| 510 | |
| 511 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 512 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 513 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_TIMEOUT; |
| 514 | |
| 515 | rc = transmit_cmd(chip, data, sizeof(data), |
| 516 | "attempting to determine the timeouts"); |
| 517 | if (rc) |
| 518 | goto duration; |
| 519 | |
| 520 | if (be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_SIZE_IDX))) |
| 521 | != 4 * sizeof(u32)) |
| 522 | goto duration; |
| 523 | |
| 524 | /* Don't overwrite default if value is 0 */ |
| 525 | timeout = |
| 526 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))); |
| 527 | if (timeout) |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 528 | chip->vendor.timeout_a = msecs_to_jiffies(timeout); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 529 | timeout = |
| 530 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX))); |
| 531 | if (timeout) |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 532 | chip->vendor.timeout_b = msecs_to_jiffies(timeout); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 533 | timeout = |
| 534 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX))); |
| 535 | if (timeout) |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 536 | chip->vendor.timeout_c = msecs_to_jiffies(timeout); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 537 | timeout = |
| 538 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX))); |
| 539 | if (timeout) |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 540 | chip->vendor.timeout_d = msecs_to_jiffies(timeout); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 541 | |
| 542 | duration: |
| 543 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 544 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 545 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_TIS_DURATION; |
| 546 | |
| 547 | rc = transmit_cmd(chip, data, sizeof(data), |
| 548 | "attempting to determine the durations"); |
| 549 | if (rc) |
| 550 | return; |
| 551 | |
| 552 | if (be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_SIZE_IDX))) |
| 553 | != 3 * sizeof(u32)) |
| 554 | return; |
| 555 | |
| 556 | chip->vendor.duration[TPM_SHORT] = |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 557 | msecs_to_jiffies(be32_to_cpu |
| 558 | (*((__be32 *) (data + |
| 559 | TPM_GET_CAP_RET_UINT32_1_IDX)))); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 560 | chip->vendor.duration[TPM_MEDIUM] = |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 561 | msecs_to_jiffies(be32_to_cpu |
| 562 | (*((__be32 *) (data + |
| 563 | TPM_GET_CAP_RET_UINT32_2_IDX)))); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 564 | chip->vendor.duration[TPM_LONG] = |
Kylene Jo Hall | 36b2002 | 2006-04-22 02:38:19 -0700 | [diff] [blame] | 565 | msecs_to_jiffies(be32_to_cpu |
| 566 | (*((__be32 *) (data + |
| 567 | TPM_GET_CAP_RET_UINT32_3_IDX)))); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 568 | } |
| 569 | EXPORT_SYMBOL_GPL(tpm_get_timeouts); |
| 570 | |
| 571 | void tpm_continue_selftest(struct tpm_chip *chip) |
| 572 | { |
| 573 | u8 data[] = { |
| 574 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 575 | 0, 0, 0, 10, /* length */ |
| 576 | 0, 0, 0, 83, /* TPM_ORD_GetCapability */ |
| 577 | }; |
| 578 | |
| 579 | tpm_transmit(chip, data, sizeof(data)); |
| 580 | } |
| 581 | EXPORT_SYMBOL_GPL(tpm_continue_selftest); |
| 582 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 583 | #define TPM_INTERNAL_RESULT_SIZE 200 |
| 584 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 585 | ssize_t tpm_show_enabled(struct device * dev, struct device_attribute * attr, |
| 586 | char *buf) |
| 587 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 588 | u8 *data; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 589 | ssize_t rc; |
| 590 | |
| 591 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 592 | if (chip == NULL) |
| 593 | return -ENODEV; |
| 594 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 595 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 596 | if (!data) |
| 597 | return -ENOMEM; |
| 598 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 599 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 600 | data[TPM_CAP_IDX] = TPM_CAP_FLAG; |
| 601 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM; |
| 602 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 603 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
| 604 | "attemtping to determine the permanent enabled state"); |
| 605 | if (rc) { |
| 606 | kfree(data); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 607 | return 0; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | rc = sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_DISABLE_IDX]); |
| 611 | |
| 612 | kfree(data); |
| 613 | return rc; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 614 | } |
| 615 | EXPORT_SYMBOL_GPL(tpm_show_enabled); |
| 616 | |
| 617 | ssize_t tpm_show_active(struct device * dev, struct device_attribute * attr, |
| 618 | char *buf) |
| 619 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 620 | u8 *data; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 621 | ssize_t rc; |
| 622 | |
| 623 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 624 | if (chip == NULL) |
| 625 | return -ENODEV; |
| 626 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 627 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 628 | if (!data) |
| 629 | return -ENOMEM; |
| 630 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 631 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 632 | data[TPM_CAP_IDX] = TPM_CAP_FLAG; |
| 633 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_PERM; |
| 634 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 635 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
| 636 | "attemtping to determine the permanent active state"); |
| 637 | if (rc) { |
| 638 | kfree(data); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 639 | return 0; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | rc = sprintf(buf, "%d\n", !data[TPM_GET_CAP_PERM_INACTIVE_IDX]); |
| 643 | |
| 644 | kfree(data); |
| 645 | return rc; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 646 | } |
| 647 | EXPORT_SYMBOL_GPL(tpm_show_active); |
| 648 | |
| 649 | ssize_t tpm_show_owned(struct device * dev, struct device_attribute * attr, |
| 650 | char *buf) |
| 651 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 652 | u8 *data; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 653 | ssize_t rc; |
| 654 | |
| 655 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 656 | if (chip == NULL) |
| 657 | return -ENODEV; |
| 658 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 659 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 660 | if (!data) |
| 661 | return -ENOMEM; |
| 662 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 663 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 664 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 665 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_OWNER; |
| 666 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 667 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 668 | "attempting to determine the owner state"); |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 669 | if (rc) { |
| 670 | kfree(data); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 671 | return 0; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | rc = sprintf(buf, "%d\n", data[TPM_GET_CAP_RET_BOOL_1_IDX]); |
| 675 | |
| 676 | kfree(data); |
| 677 | return rc; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 678 | } |
| 679 | EXPORT_SYMBOL_GPL(tpm_show_owned); |
| 680 | |
| 681 | ssize_t tpm_show_temp_deactivated(struct device * dev, |
| 682 | struct device_attribute * attr, char *buf) |
| 683 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 684 | u8 *data; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 685 | ssize_t rc; |
| 686 | |
| 687 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 688 | if (chip == NULL) |
| 689 | return -ENODEV; |
| 690 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 691 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 692 | if (!data) |
| 693 | return -ENOMEM; |
| 694 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 695 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 696 | data[TPM_CAP_IDX] = TPM_CAP_FLAG; |
| 697 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_FLAG_VOL; |
| 698 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 699 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 700 | "attempting to determine the temporary state"); |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 701 | if (rc) { |
| 702 | kfree(data); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 703 | return 0; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | rc = sprintf(buf, "%d\n", data[TPM_GET_CAP_TEMP_INACTIVE_IDX]); |
| 707 | |
| 708 | kfree(data); |
| 709 | return rc; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 710 | } |
| 711 | EXPORT_SYMBOL_GPL(tpm_show_temp_deactivated); |
| 712 | |
Kylene Hall | dff37e4 | 2005-06-23 22:01:50 -0700 | [diff] [blame] | 713 | static const u8 pcrread[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 715 | 0, 0, 0, 14, /* length */ |
| 716 | 0, 0, 0, 21, /* TPM_ORD_PcrRead */ |
| 717 | 0, 0, 0, 0 /* PCR index */ |
| 718 | }; |
| 719 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 720 | ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr, |
| 721 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 723 | u8 *data; |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 724 | ssize_t rc; |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 725 | int i, j, num_pcrs; |
| 726 | __be32 index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | char *str = buf; |
| 728 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 729 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | if (chip == NULL) |
| 731 | return -ENODEV; |
| 732 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 733 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 734 | if (!data) |
| 735 | return -ENOMEM; |
| 736 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 737 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 738 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 739 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_PCR; |
| 740 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 741 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 742 | "attempting to determine the number of PCRS"); |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 743 | if (rc) { |
| 744 | kfree(data); |
Kylene Hall | e234bc9 | 2005-06-23 22:02:08 -0700 | [diff] [blame] | 745 | return 0; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 746 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 748 | num_pcrs = be32_to_cpu(*((__be32 *) (data + 14))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | for (i = 0; i < num_pcrs; i++) { |
| 750 | memcpy(data, pcrread, sizeof(pcrread)); |
| 751 | index = cpu_to_be32(i); |
| 752 | memcpy(data + 10, &index, 4); |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 753 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 754 | "attempting to read a PCR"); |
| 755 | if (rc) |
Kylene Hall | e234bc9 | 2005-06-23 22:02:08 -0700 | [diff] [blame] | 756 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | str += sprintf(str, "PCR-%02d: ", i); |
| 758 | for (j = 0; j < TPM_DIGEST_SIZE; j++) |
| 759 | str += sprintf(str, "%02X ", *(data + 10 + j)); |
| 760 | str += sprintf(str, "\n"); |
| 761 | } |
Kylene Hall | e234bc9 | 2005-06-23 22:02:08 -0700 | [diff] [blame] | 762 | out: |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 763 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | return str - buf; |
| 765 | } |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 766 | EXPORT_SYMBOL_GPL(tpm_show_pcrs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | #define READ_PUBEK_RESULT_SIZE 314 |
Kylene Hall | dff37e4 | 2005-06-23 22:01:50 -0700 | [diff] [blame] | 769 | static const u8 readpubek[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 771 | 0, 0, 0, 30, /* length */ |
| 772 | 0, 0, 0, 124, /* TPM_ORD_ReadPubek */ |
| 773 | }; |
| 774 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 775 | ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr, |
| 776 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Kylene Hall | 2df7111 | 2005-06-23 22:01:54 -0700 | [diff] [blame] | 778 | u8 *data; |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 779 | ssize_t err; |
Kylene Hall | 81179bb | 2005-06-23 22:01:59 -0700 | [diff] [blame] | 780 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | char *str = buf; |
| 782 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 783 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | if (chip == NULL) |
| 785 | return -ENODEV; |
| 786 | |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 787 | data = kzalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL); |
Kylene Hall | 2df7111 | 2005-06-23 22:01:54 -0700 | [diff] [blame] | 788 | if (!data) |
| 789 | return -ENOMEM; |
| 790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | memcpy(data, readpubek, sizeof(readpubek)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 793 | err = transmit_cmd(chip, data, READ_PUBEK_RESULT_SIZE, |
| 794 | "attempting to read the PUBEK"); |
| 795 | if (err) |
Kylene Jo Hall | 34d6e07 | 2005-06-23 22:02:10 -0700 | [diff] [blame] | 796 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
| 798 | /* |
| 799 | ignore header 10 bytes |
| 800 | algorithm 32 bits (1 == RSA ) |
| 801 | encscheme 16 bits |
| 802 | sigscheme 16 bits |
| 803 | parameters (RSA 12->bytes: keybit, #primes, expbit) |
| 804 | keylenbytes 32 bits |
| 805 | 256 byte modulus |
| 806 | ignore checksum 20 bytes |
| 807 | */ |
| 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | str += |
| 810 | sprintf(str, |
| 811 | "Algorithm: %02X %02X %02X %02X\nEncscheme: %02X %02X\n" |
| 812 | "Sigscheme: %02X %02X\nParameters: %02X %02X %02X %02X" |
| 813 | " %02X %02X %02X %02X %02X %02X %02X %02X\n" |
| 814 | "Modulus length: %d\nModulus: \n", |
| 815 | data[10], data[11], data[12], data[13], data[14], |
| 816 | data[15], data[16], data[17], data[22], data[23], |
| 817 | data[24], data[25], data[26], data[27], data[28], |
| 818 | data[29], data[30], data[31], data[32], data[33], |
Kylene Jo Hall | 1dda8ab | 2005-06-25 14:55:40 -0700 | [diff] [blame] | 819 | be32_to_cpu(*((__be32 *) (data + 34)))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | for (i = 0; i < 256; i++) { |
Kylene Jo Hall | 1dda8ab | 2005-06-25 14:55:40 -0700 | [diff] [blame] | 822 | str += sprintf(str, "%02X ", data[i + 38]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | if ((i + 1) % 16 == 0) |
| 824 | str += sprintf(str, "\n"); |
| 825 | } |
Kylene Jo Hall | 34d6e07 | 2005-06-23 22:02:10 -0700 | [diff] [blame] | 826 | out: |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 827 | rc = str - buf; |
Kylene Hall | 2df7111 | 2005-06-23 22:01:54 -0700 | [diff] [blame] | 828 | kfree(data); |
| 829 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 831 | EXPORT_SYMBOL_GPL(tpm_show_pubek); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 833 | #define CAP_VERSION_1_1 6 |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 834 | #define CAP_VERSION_1_2 0x1A |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 835 | #define CAP_VERSION_IDX 13 |
Kylene Hall | dff37e4 | 2005-06-23 22:01:50 -0700 | [diff] [blame] | 836 | static const u8 cap_version[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 838 | 0, 0, 0, 18, /* length */ |
| 839 | 0, 0, 0, 101, /* TPM_ORD_GetCapability */ |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 840 | 0, 0, 0, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | 0, 0, 0, 0 |
| 842 | }; |
| 843 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 844 | ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr, |
| 845 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 847 | u8 *data; |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 848 | ssize_t rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | char *str = buf; |
| 850 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 851 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if (chip == NULL) |
| 853 | return -ENODEV; |
| 854 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 855 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 856 | if (!data) |
| 857 | return -ENOMEM; |
| 858 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 859 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 860 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 861 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 863 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 864 | "attempting to determine the manufacturer"); |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 865 | if (rc) { |
| 866 | kfree(data); |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 867 | return 0; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
| 870 | str += sprintf(str, "Manufacturer: 0x%x\n", |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 871 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | |
| 873 | memcpy(data, cap_version, sizeof(cap_version)); |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 874 | data[CAP_VERSION_IDX] = CAP_VERSION_1_1; |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 875 | rc = transmit_cmd(chip, data, TPM_INTERNAL_RESULT_SIZE, |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 876 | "attempting to determine the 1.1 version"); |
| 877 | if (rc) |
| 878 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 880 | str += sprintf(str, |
| 881 | "TCG version: %d.%d\nFirmware version: %d.%d\n", |
| 882 | (int) data[14], (int) data[15], (int) data[16], |
| 883 | (int) data[17]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Kylene Jo Hall | beed53a | 2006-04-22 02:37:05 -0700 | [diff] [blame] | 885 | out: |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 886 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | return str - buf; |
| 888 | } |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 889 | EXPORT_SYMBOL_GPL(tpm_show_caps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 891 | ssize_t tpm_show_caps_1_2(struct device * dev, |
| 892 | struct device_attribute * attr, char *buf) |
| 893 | { |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 894 | u8 *data; |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 895 | ssize_t len; |
| 896 | char *str = buf; |
| 897 | |
| 898 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 899 | if (chip == NULL) |
| 900 | return -ENODEV; |
| 901 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 902 | data = kzalloc(TPM_INTERNAL_RESULT_SIZE, GFP_KERNEL); |
| 903 | if (!data) |
| 904 | return -ENOMEM; |
| 905 | |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 906 | memcpy(data, tpm_cap, sizeof(tpm_cap)); |
| 907 | data[TPM_CAP_IDX] = TPM_CAP_PROP; |
| 908 | data[TPM_CAP_SUBCAP_IDX] = TPM_CAP_PROP_MANUFACTURER; |
| 909 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 910 | len = tpm_transmit(chip, data, TPM_INTERNAL_RESULT_SIZE); |
| 911 | if (len <= TPM_ERROR_SIZE) { |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 912 | dev_dbg(chip->dev, "A TPM error (%d) occurred " |
| 913 | "attempting to determine the manufacturer\n", |
| 914 | be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX)))); |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 915 | kfree(data); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | str += sprintf(str, "Manufacturer: 0x%x\n", |
| 920 | be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)))); |
| 921 | |
| 922 | memcpy(data, cap_version, sizeof(cap_version)); |
| 923 | data[CAP_VERSION_IDX] = CAP_VERSION_1_2; |
| 924 | |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 925 | len = tpm_transmit(chip, data, TPM_INTERNAL_RESULT_SIZE); |
| 926 | if (len <= TPM_ERROR_SIZE) { |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 927 | dev_err(chip->dev, "A TPM error (%d) occurred " |
| 928 | "attempting to determine the 1.2 version\n", |
| 929 | be32_to_cpu(*((__be32 *) (data + TPM_RET_CODE_IDX)))); |
| 930 | goto out; |
| 931 | } |
| 932 | str += sprintf(str, |
| 933 | "TCG version: %d.%d\nFirmware version: %d.%d\n", |
| 934 | (int) data[16], (int) data[17], (int) data[18], |
| 935 | (int) data[19]); |
| 936 | |
| 937 | out: |
Marcin Obara | ec288bd | 2008-07-25 19:44:59 -0700 | [diff] [blame] | 938 | kfree(data); |
Kylene Jo Hall | 08e96e4 | 2006-04-22 02:37:50 -0700 | [diff] [blame] | 939 | return str - buf; |
| 940 | } |
| 941 | EXPORT_SYMBOL_GPL(tpm_show_caps_1_2); |
| 942 | |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 943 | ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, |
| 944 | const char *buf, size_t count) |
| 945 | { |
| 946 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 947 | if (chip == NULL) |
| 948 | return 0; |
| 949 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 950 | chip->vendor.cancel(chip); |
Kylene Hall | 6659ca2 | 2005-06-23 22:02:00 -0700 | [diff] [blame] | 951 | return count; |
| 952 | } |
| 953 | EXPORT_SYMBOL_GPL(tpm_store_cancel); |
| 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | /* |
| 956 | * Device file system interface to the TPM |
Rajiv Andrade | f89c5ed | 2008-10-11 09:03:39 +1100 | [diff] [blame] | 957 | * |
| 958 | * It's assured that the chip will be opened just once, |
| 959 | * by the check of is_open variable, which is protected |
| 960 | * by driver_lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | */ |
| 962 | int tpm_open(struct inode *inode, struct file *file) |
| 963 | { |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 964 | int minor = iminor(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | struct tpm_chip *chip = NULL, *pos; |
| 966 | |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 967 | rcu_read_lock(); |
| 968 | list_for_each_entry_rcu(pos, &tpm_chip_list, list) { |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 969 | if (pos->vendor.miscdev.minor == minor) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | chip = pos; |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 971 | get_device(chip->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | break; |
| 973 | } |
| 974 | } |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 975 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 977 | if (!chip) |
| 978 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | |
Rajiv Andrade | dc36d32 | 2008-10-11 09:04:02 +1100 | [diff] [blame] | 980 | if (test_and_set_bit(0, &chip->is_open)) { |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 981 | dev_dbg(chip->dev, "Another process owns this TPM\n"); |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 982 | put_device(chip->dev); |
| 983 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); |
| 987 | if (chip->data_buffer == NULL) { |
Rajiv Andrade | dc36d32 | 2008-10-11 09:04:02 +1100 | [diff] [blame] | 988 | clear_bit(0, &chip->is_open); |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 989 | put_device(chip->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | return -ENOMEM; |
| 991 | } |
| 992 | |
| 993 | atomic_set(&chip->data_pending, 0); |
| 994 | |
| 995 | file->private_data = chip; |
| 996 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | EXPORT_SYMBOL_GPL(tpm_open); |
| 999 | |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1000 | /* |
| 1001 | * Called on file close |
| 1002 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | int tpm_release(struct inode *inode, struct file *file) |
| 1004 | { |
| 1005 | struct tpm_chip *chip = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
Parag Warudkar | 8e39c93 | 2007-05-08 00:31:09 -0700 | [diff] [blame] | 1007 | flush_scheduled_work(); |
Kylene Hall | 5e976d5 | 2005-06-23 22:02:03 -0700 | [diff] [blame] | 1008 | file->private_data = NULL; |
Kylene Hall | fe3fd483 | 2005-06-23 22:01:56 -0700 | [diff] [blame] | 1009 | del_singleshot_timer_sync(&chip->user_read_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | atomic_set(&chip->data_pending, 0); |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1011 | kfree(chip->data_buffer); |
Rajiv Andrade | dc36d32 | 2008-10-11 09:04:02 +1100 | [diff] [blame] | 1012 | clear_bit(0, &chip->is_open); |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1013 | put_device(chip->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | return 0; |
| 1015 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | EXPORT_SYMBOL_GPL(tpm_release); |
| 1017 | |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 1018 | ssize_t tpm_write(struct file *file, const char __user *buf, |
Kylene Jo Hall | 3c2f606 | 2006-04-22 02:36:56 -0700 | [diff] [blame] | 1019 | size_t size, loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
| 1021 | struct tpm_chip *chip = file->private_data; |
Michael Halcrow | 0147600 | 2008-07-25 19:45:00 -0700 | [diff] [blame] | 1022 | size_t in_size = size, out_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
| 1024 | /* cannot perform a write until the read has cleared |
| 1025 | either via tpm_read or a user_read_timer timeout */ |
Nishanth Aravamudan | 700d8bd | 2005-06-23 22:01:47 -0700 | [diff] [blame] | 1026 | while (atomic_read(&chip->data_pending) != 0) |
| 1027 | msleep(TPM_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 1029 | mutex_lock(&chip->buffer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | if (in_size > TPM_BUFSIZE) |
| 1032 | in_size = TPM_BUFSIZE; |
| 1033 | |
| 1034 | if (copy_from_user |
| 1035 | (chip->data_buffer, (void __user *) buf, in_size)) { |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 1036 | mutex_unlock(&chip->buffer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | return -EFAULT; |
| 1038 | } |
| 1039 | |
| 1040 | /* atomic tpm command send and result receive */ |
| 1041 | out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); |
| 1042 | |
| 1043 | atomic_set(&chip->data_pending, out_size); |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 1044 | mutex_unlock(&chip->buffer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | |
| 1046 | /* Set a timeout by which the reader must come claim the result */ |
Kylene Hall | fe3fd483 | 2005-06-23 22:01:56 -0700 | [diff] [blame] | 1047 | mod_timer(&chip->user_read_timer, jiffies + (60 * HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | |
| 1049 | return in_size; |
| 1050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | EXPORT_SYMBOL_GPL(tpm_write); |
| 1052 | |
Kylene Jo Hall | 3c2f606 | 2006-04-22 02:36:56 -0700 | [diff] [blame] | 1053 | ssize_t tpm_read(struct file *file, char __user *buf, |
| 1054 | size_t size, loff_t *off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | { |
| 1056 | struct tpm_chip *chip = file->private_data; |
Michael Halcrow | 0147600 | 2008-07-25 19:45:00 -0700 | [diff] [blame] | 1057 | ssize_t ret_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 1059 | del_singleshot_timer_sync(&chip->user_read_timer); |
Kylene Jo Hall | ba39611 | 2005-11-18 01:10:57 -0800 | [diff] [blame] | 1060 | flush_scheduled_work(); |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 1061 | ret_size = atomic_read(&chip->data_pending); |
| 1062 | atomic_set(&chip->data_pending, 0); |
| 1063 | if (ret_size > 0) { /* relay data */ |
| 1064 | if (size < ret_size) |
| 1065 | ret_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 1067 | mutex_lock(&chip->buffer_mutex); |
Kylene Jo Hall | f6a2382 | 2005-11-13 16:07:42 -0800 | [diff] [blame] | 1068 | if (copy_to_user(buf, chip->data_buffer, ret_size)) |
Kylene Hall | 5b44bd5 | 2005-06-23 22:01:53 -0700 | [diff] [blame] | 1069 | ret_size = -EFAULT; |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 1070 | mutex_unlock(&chip->buffer_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | return ret_size; |
| 1074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | EXPORT_SYMBOL_GPL(tpm_read); |
| 1076 | |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1077 | void tpm_remove_hardware(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1079 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
| 1081 | if (chip == NULL) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1082 | dev_err(dev, "No device data found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | |
| 1086 | spin_lock(&driver_lock); |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1087 | list_del_rcu(&chip->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | spin_unlock(&driver_lock); |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1089 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1091 | misc_deregister(&chip->vendor.miscdev); |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1092 | sysfs_remove_group(&dev->kobj, chip->vendor.attr_group); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 1093 | tpm_bios_log_teardown(chip->bios_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1095 | /* write it this way to be explicit (chip->dev == dev) */ |
| 1096 | put_device(chip->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | } |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1098 | EXPORT_SYMBOL_GPL(tpm_remove_hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | /* |
| 1101 | * We are about to suspend. Save the TPM state |
| 1102 | * so that it can be restored. |
| 1103 | */ |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 1104 | int tpm_pm_suspend(struct device *dev, pm_message_t pm_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | { |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 1106 | struct tpm_chip *chip = dev_get_drvdata(dev); |
David Smith | 2490c68 | 2008-01-14 00:55:12 -0800 | [diff] [blame] | 1107 | u8 savestate[] = { |
| 1108 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
| 1109 | 0, 0, 0, 10, /* blob length (in bytes) */ |
| 1110 | 0, 0, 0, 152 /* TPM_ORD_SaveState */ |
| 1111 | }; |
| 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | if (chip == NULL) |
| 1114 | return -ENODEV; |
| 1115 | |
| 1116 | tpm_transmit(chip, savestate, sizeof(savestate)); |
| 1117 | return 0; |
| 1118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | EXPORT_SYMBOL_GPL(tpm_pm_suspend); |
| 1120 | |
| 1121 | /* |
| 1122 | * Resume from a power safe. The BIOS already restored |
| 1123 | * the TPM state. |
| 1124 | */ |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 1125 | int tpm_pm_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | { |
Kylene Jo Hall | ce2c87d | 2005-10-30 15:03:25 -0800 | [diff] [blame] | 1127 | struct tpm_chip *chip = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
| 1129 | if (chip == NULL) |
| 1130 | return -ENODEV; |
| 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | return 0; |
| 1133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | EXPORT_SYMBOL_GPL(tpm_pm_resume); |
| 1135 | |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame^] | 1136 | /* In case vendor provided release function, call it too.*/ |
| 1137 | |
| 1138 | void tpm_dev_vendor_release(struct tpm_chip *chip) |
| 1139 | { |
| 1140 | if (chip->vendor.release) |
| 1141 | chip->vendor.release(chip->dev); |
| 1142 | |
| 1143 | clear_bit(chip->dev_num, dev_mask); |
| 1144 | kfree(chip->vendor.miscdev.name); |
| 1145 | } |
| 1146 | EXPORT_SYMBOL_GPL(tpm_dev_vendor_release); |
| 1147 | |
| 1148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | /* |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1150 | * Once all references to platform device are down to 0, |
| 1151 | * release all allocated structures. |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1152 | */ |
| 1153 | static void tpm_dev_release(struct device *dev) |
| 1154 | { |
| 1155 | struct tpm_chip *chip = dev_get_drvdata(dev); |
| 1156 | |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame^] | 1157 | tpm_dev_vendor_release(chip); |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1158 | |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame^] | 1159 | chip->release(dev); |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1160 | kfree(chip); |
| 1161 | } |
Rajiv Andrade | 253115b | 2008-10-11 09:04:39 +1100 | [diff] [blame^] | 1162 | EXPORT_SYMBOL_GPL(tpm_dev_release); |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | * Called from tpm_<specific>.c probe function only for devices |
| 1166 | * the driver has determined it should claim. Prior to calling |
| 1167 | * this function the specific probe function has called pci_enable_device |
| 1168 | * upon errant exit from this function specific probe function should call |
| 1169 | * pci_disable_device |
| 1170 | */ |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1171 | struct tpm_chip *tpm_register_hardware(struct device *dev, |
| 1172 | const struct tpm_vendor_specific *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | { |
Kylene Jo Hall | 6f9becc | 2005-06-25 14:55:41 -0700 | [diff] [blame] | 1174 | #define DEVNAME_SIZE 7 |
| 1175 | |
| 1176 | char *devname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | struct tpm_chip *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
| 1179 | /* Driver specific per-device data */ |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 1180 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Parag Warudkar | 8e39c93 | 2007-05-08 00:31:09 -0700 | [diff] [blame] | 1181 | devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); |
| 1182 | |
| 1183 | if (chip == NULL || devname == NULL) { |
| 1184 | kfree(chip); |
| 1185 | kfree(devname); |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 1186 | return NULL; |
Parag Warudkar | 8e39c93 | 2007-05-08 00:31:09 -0700 | [diff] [blame] | 1187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
Matthias Kaehlcke | d081d47 | 2007-05-08 00:32:02 -0700 | [diff] [blame] | 1189 | mutex_init(&chip->buffer_mutex); |
| 1190 | mutex_init(&chip->tpm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | INIT_LIST_HEAD(&chip->list); |
| 1192 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1193 | INIT_WORK(&chip->work, timeout_work); |
Kylene Jo Hall | 09e12f9 | 2005-11-13 16:07:43 -0800 | [diff] [blame] | 1194 | |
Jiri Slaby | 40565f1 | 2007-02-12 00:52:31 -0800 | [diff] [blame] | 1195 | setup_timer(&chip->user_read_timer, user_reader_timeout, |
| 1196 | (unsigned long)chip); |
Kylene Hall | fe3fd483 | 2005-06-23 22:01:56 -0700 | [diff] [blame] | 1197 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1198 | memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
Kylene Jo Hall | 10685a9 | 2006-04-22 02:38:32 -0700 | [diff] [blame] | 1200 | chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Kylene Jo Hall | 10685a9 | 2006-04-22 02:38:32 -0700 | [diff] [blame] | 1202 | if (chip->dev_num >= TPM_NUM_DEVICES) { |
Andrew Morton | b888c87 | 2005-10-30 15:03:28 -0800 | [diff] [blame] | 1203 | dev_err(dev, "No available tpm device numbers\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | kfree(chip); |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 1205 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } else if (chip->dev_num == 0) |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1207 | chip->vendor.miscdev.minor = TPM_MINOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | else |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1209 | chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
Kylene Jo Hall | 10685a9 | 2006-04-22 02:38:32 -0700 | [diff] [blame] | 1211 | set_bit(chip->dev_num, dev_mask); |
| 1212 | |
Kylene Jo Hall | 6f9becc | 2005-06-25 14:55:41 -0700 | [diff] [blame] | 1213 | scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1214 | chip->vendor.miscdev.name = devname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
Greg Kroah-Hartman | 94fbcde | 2006-07-27 16:16:04 -0700 | [diff] [blame] | 1216 | chip->vendor.miscdev.parent = dev; |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1217 | chip->dev = get_device(dev); |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1218 | chip->release = dev->release; |
| 1219 | dev->release = tpm_dev_release; |
| 1220 | dev_set_drvdata(dev, chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1222 | if (misc_register(&chip->vendor.miscdev)) { |
Kylene Jo Hall | e659a3f | 2005-10-30 15:03:24 -0800 | [diff] [blame] | 1223 | dev_err(chip->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | "unable to misc_register %s, minor %d\n", |
Kylene Jo Hall | 90dda52 | 2006-04-22 02:37:15 -0700 | [diff] [blame] | 1225 | chip->vendor.miscdev.name, |
| 1226 | chip->vendor.miscdev.minor); |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1227 | put_device(chip->dev); |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 1228 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
Jeff Garzik | f33d9bd | 2006-10-11 01:21:51 -0700 | [diff] [blame] | 1231 | if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) { |
Neil Horman | 5d469ec | 2006-12-06 20:37:08 -0800 | [diff] [blame] | 1232 | misc_deregister(&chip->vendor.miscdev); |
Richard MUSIL | 5bd91f1 | 2008-02-06 01:37:02 -0800 | [diff] [blame] | 1233 | put_device(chip->dev); |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1234 | |
Jeff Garzik | f33d9bd | 2006-10-11 01:21:51 -0700 | [diff] [blame] | 1235 | return NULL; |
| 1236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 1238 | chip->bios_dir = tpm_bios_log_setup(devname); |
| 1239 | |
Rajiv Andrade | f02a936 | 2008-10-11 09:04:23 +1100 | [diff] [blame] | 1240 | /* Make chip available */ |
| 1241 | spin_lock(&driver_lock); |
| 1242 | list_add_rcu(&chip->list, &tpm_chip_list); |
| 1243 | spin_unlock(&driver_lock); |
| 1244 | |
Kylene Jo Hall | e0dd03c | 2006-04-22 02:37:26 -0700 | [diff] [blame] | 1245 | return chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | EXPORT_SYMBOL_GPL(tpm_register_hardware); |
| 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)"); |
| 1250 | MODULE_DESCRIPTION("TPM Driver"); |
| 1251 | MODULE_VERSION("2.0"); |
| 1252 | MODULE_LICENSE("GPL"); |