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