tpm-interface.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /*
  2. * Copyright (C) 2004 IBM Corporation
  3. * Copyright (C) 2014 Intel Corporation
  4. *
  5. * Authors:
  6. * Leendert van Doorn <leendert@watson.ibm.com>
  7. * Dave Safford <safford@watson.ibm.com>
  8. * Reiner Sailer <sailer@watson.ibm.com>
  9. * Kylene Hall <kjhall@us.ibm.com>
  10. *
  11. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  12. *
  13. * Device driver for TCG/TCPA TPM (trusted platform module).
  14. * Specifications at www.trustedcomputinggroup.org
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation, version 2 of the
  19. * License.
  20. *
  21. * Note, the TPM chip is not interrupt driven (only polling)
  22. * and can have very long timeouts (minutes!). Hence the unusual
  23. * calls to msleep.
  24. *
  25. */
  26. #include <linux/poll.h>
  27. #include <linux/slab.h>
  28. #include <linux/mutex.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/freezer.h>
  31. #include "tpm.h"
  32. #include "tpm_eventlog.h"
  33. #define TPM_MAX_ORDINAL 243
  34. #define TSC_MAX_ORDINAL 12
  35. #define TPM_PROTECTED_COMMAND 0x00
  36. #define TPM_CONNECTION_COMMAND 0x40
  37. /*
  38. * Bug workaround - some TPM's don't flush the most
  39. * recently changed pcr on suspend, so force the flush
  40. * with an extend to the selected _unused_ non-volatile pcr.
  41. */
  42. static int tpm_suspend_pcr;
  43. module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
  44. MODULE_PARM_DESC(suspend_pcr,
  45. "PCR to use for dummy writes to faciltate flush on suspend.");
  46. /*
  47. * Array with one entry per ordinal defining the maximum amount
  48. * of time the chip could take to return the result. The ordinal
  49. * designation of short, medium or long is defined in a table in
  50. * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
  51. * values of the SHORT, MEDIUM, and LONG durations are retrieved
  52. * from the chip during initialization with a call to tpm_get_timeouts.
  53. */
  54. static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
  55. TPM_UNDEFINED, /* 0 */
  56. TPM_UNDEFINED,
  57. TPM_UNDEFINED,
  58. TPM_UNDEFINED,
  59. TPM_UNDEFINED,
  60. TPM_UNDEFINED, /* 5 */
  61. TPM_UNDEFINED,
  62. TPM_UNDEFINED,
  63. TPM_UNDEFINED,
  64. TPM_UNDEFINED,
  65. TPM_SHORT, /* 10 */
  66. TPM_SHORT,
  67. TPM_MEDIUM,
  68. TPM_LONG,
  69. TPM_LONG,
  70. TPM_MEDIUM, /* 15 */
  71. TPM_SHORT,
  72. TPM_SHORT,
  73. TPM_MEDIUM,
  74. TPM_LONG,
  75. TPM_SHORT, /* 20 */
  76. TPM_SHORT,
  77. TPM_MEDIUM,
  78. TPM_MEDIUM,
  79. TPM_MEDIUM,
  80. TPM_SHORT, /* 25 */
  81. TPM_SHORT,
  82. TPM_MEDIUM,
  83. TPM_SHORT,
  84. TPM_SHORT,
  85. TPM_MEDIUM, /* 30 */
  86. TPM_LONG,
  87. TPM_MEDIUM,
  88. TPM_SHORT,
  89. TPM_SHORT,
  90. TPM_SHORT, /* 35 */
  91. TPM_MEDIUM,
  92. TPM_MEDIUM,
  93. TPM_UNDEFINED,
  94. TPM_UNDEFINED,
  95. TPM_MEDIUM, /* 40 */
  96. TPM_LONG,
  97. TPM_MEDIUM,
  98. TPM_SHORT,
  99. TPM_SHORT,
  100. TPM_SHORT, /* 45 */
  101. TPM_SHORT,
  102. TPM_SHORT,
  103. TPM_SHORT,
  104. TPM_LONG,
  105. TPM_MEDIUM, /* 50 */
  106. TPM_MEDIUM,
  107. TPM_UNDEFINED,
  108. TPM_UNDEFINED,
  109. TPM_UNDEFINED,
  110. TPM_UNDEFINED, /* 55 */
  111. TPM_UNDEFINED,
  112. TPM_UNDEFINED,
  113. TPM_UNDEFINED,
  114. TPM_UNDEFINED,
  115. TPM_MEDIUM, /* 60 */
  116. TPM_MEDIUM,
  117. TPM_MEDIUM,
  118. TPM_SHORT,
  119. TPM_SHORT,
  120. TPM_MEDIUM, /* 65 */
  121. TPM_UNDEFINED,
  122. TPM_UNDEFINED,
  123. TPM_UNDEFINED,
  124. TPM_UNDEFINED,
  125. TPM_SHORT, /* 70 */
  126. TPM_SHORT,
  127. TPM_UNDEFINED,
  128. TPM_UNDEFINED,
  129. TPM_UNDEFINED,
  130. TPM_UNDEFINED, /* 75 */
  131. TPM_UNDEFINED,
  132. TPM_UNDEFINED,
  133. TPM_UNDEFINED,
  134. TPM_UNDEFINED,
  135. TPM_LONG, /* 80 */
  136. TPM_UNDEFINED,
  137. TPM_MEDIUM,
  138. TPM_LONG,
  139. TPM_SHORT,
  140. TPM_UNDEFINED, /* 85 */
  141. TPM_UNDEFINED,
  142. TPM_UNDEFINED,
  143. TPM_UNDEFINED,
  144. TPM_UNDEFINED,
  145. TPM_SHORT, /* 90 */
  146. TPM_SHORT,
  147. TPM_SHORT,
  148. TPM_SHORT,
  149. TPM_SHORT,
  150. TPM_UNDEFINED, /* 95 */
  151. TPM_UNDEFINED,
  152. TPM_UNDEFINED,
  153. TPM_UNDEFINED,
  154. TPM_UNDEFINED,
  155. TPM_MEDIUM, /* 100 */
  156. TPM_SHORT,
  157. TPM_SHORT,
  158. TPM_UNDEFINED,
  159. TPM_UNDEFINED,
  160. TPM_UNDEFINED, /* 105 */
  161. TPM_UNDEFINED,
  162. TPM_UNDEFINED,
  163. TPM_UNDEFINED,
  164. TPM_UNDEFINED,
  165. TPM_SHORT, /* 110 */
  166. TPM_SHORT,
  167. TPM_SHORT,
  168. TPM_SHORT,
  169. TPM_SHORT,
  170. TPM_SHORT, /* 115 */
  171. TPM_SHORT,
  172. TPM_SHORT,
  173. TPM_UNDEFINED,
  174. TPM_UNDEFINED,
  175. TPM_LONG, /* 120 */
  176. TPM_LONG,
  177. TPM_MEDIUM,
  178. TPM_UNDEFINED,
  179. TPM_SHORT,
  180. TPM_SHORT, /* 125 */
  181. TPM_SHORT,
  182. TPM_LONG,
  183. TPM_SHORT,
  184. TPM_SHORT,
  185. TPM_SHORT, /* 130 */
  186. TPM_MEDIUM,
  187. TPM_UNDEFINED,
  188. TPM_SHORT,
  189. TPM_MEDIUM,
  190. TPM_UNDEFINED, /* 135 */
  191. TPM_UNDEFINED,
  192. TPM_UNDEFINED,
  193. TPM_UNDEFINED,
  194. TPM_UNDEFINED,
  195. TPM_SHORT, /* 140 */
  196. TPM_SHORT,
  197. TPM_UNDEFINED,
  198. TPM_UNDEFINED,
  199. TPM_UNDEFINED,
  200. TPM_UNDEFINED, /* 145 */
  201. TPM_UNDEFINED,
  202. TPM_UNDEFINED,
  203. TPM_UNDEFINED,
  204. TPM_UNDEFINED,
  205. TPM_SHORT, /* 150 */
  206. TPM_MEDIUM,
  207. TPM_MEDIUM,
  208. TPM_SHORT,
  209. TPM_SHORT,
  210. TPM_UNDEFINED, /* 155 */
  211. TPM_UNDEFINED,
  212. TPM_UNDEFINED,
  213. TPM_UNDEFINED,
  214. TPM_UNDEFINED,
  215. TPM_SHORT, /* 160 */
  216. TPM_SHORT,
  217. TPM_SHORT,
  218. TPM_SHORT,
  219. TPM_UNDEFINED,
  220. TPM_UNDEFINED, /* 165 */
  221. TPM_UNDEFINED,
  222. TPM_UNDEFINED,
  223. TPM_UNDEFINED,
  224. TPM_UNDEFINED,
  225. TPM_LONG, /* 170 */
  226. TPM_UNDEFINED,
  227. TPM_UNDEFINED,
  228. TPM_UNDEFINED,
  229. TPM_UNDEFINED,
  230. TPM_UNDEFINED, /* 175 */
  231. TPM_UNDEFINED,
  232. TPM_UNDEFINED,
  233. TPM_UNDEFINED,
  234. TPM_UNDEFINED,
  235. TPM_MEDIUM, /* 180 */
  236. TPM_SHORT,
  237. TPM_MEDIUM,
  238. TPM_MEDIUM,
  239. TPM_MEDIUM,
  240. TPM_MEDIUM, /* 185 */
  241. TPM_SHORT,
  242. TPM_UNDEFINED,
  243. TPM_UNDEFINED,
  244. TPM_UNDEFINED,
  245. TPM_UNDEFINED, /* 190 */
  246. TPM_UNDEFINED,
  247. TPM_UNDEFINED,
  248. TPM_UNDEFINED,
  249. TPM_UNDEFINED,
  250. TPM_UNDEFINED, /* 195 */
  251. TPM_UNDEFINED,
  252. TPM_UNDEFINED,
  253. TPM_UNDEFINED,
  254. TPM_UNDEFINED,
  255. TPM_SHORT, /* 200 */
  256. TPM_UNDEFINED,
  257. TPM_UNDEFINED,
  258. TPM_UNDEFINED,
  259. TPM_SHORT,
  260. TPM_SHORT, /* 205 */
  261. TPM_SHORT,
  262. TPM_SHORT,
  263. TPM_SHORT,
  264. TPM_SHORT,
  265. TPM_MEDIUM, /* 210 */
  266. TPM_UNDEFINED,
  267. TPM_MEDIUM,
  268. TPM_MEDIUM,
  269. TPM_MEDIUM,
  270. TPM_UNDEFINED, /* 215 */
  271. TPM_MEDIUM,
  272. TPM_UNDEFINED,
  273. TPM_UNDEFINED,
  274. TPM_SHORT,
  275. TPM_SHORT, /* 220 */
  276. TPM_SHORT,
  277. TPM_SHORT,
  278. TPM_SHORT,
  279. TPM_SHORT,
  280. TPM_UNDEFINED, /* 225 */
  281. TPM_UNDEFINED,
  282. TPM_UNDEFINED,
  283. TPM_UNDEFINED,
  284. TPM_UNDEFINED,
  285. TPM_SHORT, /* 230 */
  286. TPM_LONG,
  287. TPM_MEDIUM,
  288. TPM_UNDEFINED,
  289. TPM_UNDEFINED,
  290. TPM_UNDEFINED, /* 235 */
  291. TPM_UNDEFINED,
  292. TPM_UNDEFINED,
  293. TPM_UNDEFINED,
  294. TPM_UNDEFINED,
  295. TPM_SHORT, /* 240 */
  296. TPM_UNDEFINED,
  297. TPM_MEDIUM,
  298. };
  299. /*
  300. * Returns max number of jiffies to wait
  301. */
  302. unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
  303. u32 ordinal)
  304. {
  305. int duration_idx = TPM_UNDEFINED;
  306. int duration = 0;
  307. /*
  308. * We only have a duration table for protected commands, where the upper
  309. * 16 bits are 0. For the few other ordinals the fallback will be used.
  310. */
  311. if (ordinal < TPM_MAX_ORDINAL)
  312. duration_idx = tpm_ordinal_duration[ordinal];
  313. if (duration_idx != TPM_UNDEFINED)
  314. duration = chip->duration[duration_idx];
  315. if (duration <= 0)
  316. return 2 * 60 * HZ;
  317. else
  318. return duration;
  319. }
  320. EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
  321. /*
  322. * Internal kernel interface to transmit TPM commands
  323. */
  324. ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
  325. size_t bufsiz)
  326. {
  327. ssize_t rc;
  328. u32 count, ordinal;
  329. unsigned long stop;
  330. if (bufsiz > TPM_BUFSIZE)
  331. bufsiz = TPM_BUFSIZE;
  332. count = be32_to_cpu(*((__be32 *) (buf + 2)));
  333. ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
  334. if (count == 0)
  335. return -ENODATA;
  336. if (count > bufsiz) {
  337. dev_err(&chip->dev,
  338. "invalid count value %x %zx\n", count, bufsiz);
  339. return -E2BIG;
  340. }
  341. mutex_lock(&chip->tpm_mutex);
  342. rc = chip->ops->send(chip, (u8 *) buf, count);
  343. if (rc < 0) {
  344. dev_err(&chip->dev,
  345. "tpm_transmit: tpm_send: error %zd\n", rc);
  346. goto out;
  347. }
  348. if (chip->flags & TPM_CHIP_FLAG_IRQ)
  349. goto out_recv;
  350. if (chip->flags & TPM_CHIP_FLAG_TPM2)
  351. stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal);
  352. else
  353. stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
  354. do {
  355. u8 status = chip->ops->status(chip);
  356. if ((status & chip->ops->req_complete_mask) ==
  357. chip->ops->req_complete_val)
  358. goto out_recv;
  359. if (chip->ops->req_canceled(chip, status)) {
  360. dev_err(&chip->dev, "Operation Canceled\n");
  361. rc = -ECANCELED;
  362. goto out;
  363. }
  364. msleep(TPM_TIMEOUT); /* CHECK */
  365. rmb();
  366. } while (time_before(jiffies, stop));
  367. chip->ops->cancel(chip);
  368. dev_err(&chip->dev, "Operation Timed out\n");
  369. rc = -ETIME;
  370. goto out;
  371. out_recv:
  372. rc = chip->ops->recv(chip, (u8 *) buf, bufsiz);
  373. if (rc < 0)
  374. dev_err(&chip->dev,
  375. "tpm_transmit: tpm_recv: error %zd\n", rc);
  376. out:
  377. mutex_unlock(&chip->tpm_mutex);
  378. return rc;
  379. }
  380. #define TPM_DIGEST_SIZE 20
  381. #define TPM_RET_CODE_IDX 6
  382. ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd,
  383. int len, const char *desc)
  384. {
  385. struct tpm_output_header *header;
  386. int err;
  387. len = tpm_transmit(chip, (u8 *) cmd, len);
  388. if (len < 0)
  389. return len;
  390. else if (len < TPM_HEADER_SIZE)
  391. return -EFAULT;
  392. header = cmd;
  393. err = be32_to_cpu(header->return_code);
  394. if (err != 0 && desc)
  395. dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err,
  396. desc);
  397. return err;
  398. }
  399. #define TPM_INTERNAL_RESULT_SIZE 200
  400. #define TPM_ORD_GET_CAP cpu_to_be32(101)
  401. #define TPM_ORD_GET_RANDOM cpu_to_be32(70)
  402. static const struct tpm_input_header tpm_getcap_header = {
  403. .tag = TPM_TAG_RQU_COMMAND,
  404. .length = cpu_to_be32(22),
  405. .ordinal = TPM_ORD_GET_CAP
  406. };
  407. ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap,
  408. const char *desc)
  409. {
  410. struct tpm_cmd_t tpm_cmd;
  411. int rc;
  412. tpm_cmd.header.in = tpm_getcap_header;
  413. if (subcap_id == CAP_VERSION_1_1 || subcap_id == CAP_VERSION_1_2) {
  414. tpm_cmd.params.getcap_in.cap = subcap_id;
  415. /*subcap field not necessary */
  416. tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(0);
  417. tpm_cmd.header.in.length -= cpu_to_be32(sizeof(__be32));
  418. } else {
  419. if (subcap_id == TPM_CAP_FLAG_PERM ||
  420. subcap_id == TPM_CAP_FLAG_VOL)
  421. tpm_cmd.params.getcap_in.cap = TPM_CAP_FLAG;
  422. else
  423. tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
  424. tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
  425. tpm_cmd.params.getcap_in.subcap = subcap_id;
  426. }
  427. rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc);
  428. if (!rc)
  429. *cap = tpm_cmd.params.getcap_out.cap;
  430. return rc;
  431. }
  432. void tpm_gen_interrupt(struct tpm_chip *chip)
  433. {
  434. struct tpm_cmd_t tpm_cmd;
  435. ssize_t rc;
  436. tpm_cmd.header.in = tpm_getcap_header;
  437. tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
  438. tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
  439. tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
  440. rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
  441. "attempting to determine the timeouts");
  442. }
  443. EXPORT_SYMBOL_GPL(tpm_gen_interrupt);
  444. #define TPM_ORD_STARTUP cpu_to_be32(153)
  445. #define TPM_ST_CLEAR cpu_to_be16(1)
  446. #define TPM_ST_STATE cpu_to_be16(2)
  447. #define TPM_ST_DEACTIVATED cpu_to_be16(3)
  448. static const struct tpm_input_header tpm_startup_header = {
  449. .tag = TPM_TAG_RQU_COMMAND,
  450. .length = cpu_to_be32(12),
  451. .ordinal = TPM_ORD_STARTUP
  452. };
  453. static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
  454. {
  455. struct tpm_cmd_t start_cmd;
  456. start_cmd.header.in = tpm_startup_header;
  457. start_cmd.params.startup_in.startup_type = startup_type;
  458. return tpm_transmit_cmd(chip, &start_cmd, TPM_INTERNAL_RESULT_SIZE,
  459. "attempting to start the TPM");
  460. }
  461. int tpm_get_timeouts(struct tpm_chip *chip)
  462. {
  463. struct tpm_cmd_t tpm_cmd;
  464. unsigned long new_timeout[4];
  465. unsigned long old_timeout[4];
  466. struct duration_t *duration_cap;
  467. ssize_t rc;
  468. if (chip->flags & TPM_CHIP_FLAG_TPM2) {
  469. /* Fixed timeouts for TPM2 */
  470. chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
  471. chip->timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
  472. chip->timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
  473. chip->timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
  474. chip->duration[TPM_SHORT] =
  475. msecs_to_jiffies(TPM2_DURATION_SHORT);
  476. chip->duration[TPM_MEDIUM] =
  477. msecs_to_jiffies(TPM2_DURATION_MEDIUM);
  478. chip->duration[TPM_LONG] =
  479. msecs_to_jiffies(TPM2_DURATION_LONG);
  480. return 0;
  481. }
  482. tpm_cmd.header.in = tpm_getcap_header;
  483. tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
  484. tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
  485. tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
  486. rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL);
  487. if (rc == TPM_ERR_INVALID_POSTINIT) {
  488. /* The TPM is not started, we are the first to talk to it.
  489. Execute a startup command. */
  490. dev_info(&chip->dev, "Issuing TPM_STARTUP");
  491. if (tpm_startup(chip, TPM_ST_CLEAR))
  492. return rc;
  493. tpm_cmd.header.in = tpm_getcap_header;
  494. tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
  495. tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
  496. tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
  497. rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
  498. NULL);
  499. }
  500. if (rc) {
  501. dev_err(&chip->dev,
  502. "A TPM error (%zd) occurred attempting to determine the timeouts\n",
  503. rc);
  504. goto duration;
  505. }
  506. if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
  507. be32_to_cpu(tpm_cmd.header.out.length)
  508. != sizeof(tpm_cmd.header.out) + sizeof(u32) + 4 * sizeof(u32))
  509. return -EINVAL;
  510. old_timeout[0] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.a);
  511. old_timeout[1] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.b);
  512. old_timeout[2] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.c);
  513. old_timeout[3] = be32_to_cpu(tpm_cmd.params.getcap_out.cap.timeout.d);
  514. memcpy(new_timeout, old_timeout, sizeof(new_timeout));
  515. /*
  516. * Provide ability for vendor overrides of timeout values in case
  517. * of misreporting.
  518. */
  519. if (chip->ops->update_timeouts != NULL)
  520. chip->timeout_adjusted =
  521. chip->ops->update_timeouts(chip, new_timeout);
  522. if (!chip->timeout_adjusted) {
  523. /* Don't overwrite default if value is 0 */
  524. if (new_timeout[0] != 0 && new_timeout[0] < 1000) {
  525. int i;
  526. /* timeouts in msec rather usec */
  527. for (i = 0; i != ARRAY_SIZE(new_timeout); i++)
  528. new_timeout[i] *= 1000;
  529. chip->timeout_adjusted = true;
  530. }
  531. }
  532. /* Report adjusted timeouts */
  533. if (chip->timeout_adjusted) {
  534. dev_info(&chip->dev,
  535. HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n",
  536. old_timeout[0], new_timeout[0],
  537. old_timeout[1], new_timeout[1],
  538. old_timeout[2], new_timeout[2],
  539. old_timeout[3], new_timeout[3]);
  540. }
  541. chip->timeout_a = usecs_to_jiffies(new_timeout[0]);
  542. chip->timeout_b = usecs_to_jiffies(new_timeout[1]);
  543. chip->timeout_c = usecs_to_jiffies(new_timeout[2]);
  544. chip->timeout_d = usecs_to_jiffies(new_timeout[3]);
  545. duration:
  546. tpm_cmd.header.in = tpm_getcap_header;
  547. tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
  548. tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
  549. tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_DURATION;
  550. rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
  551. "attempting to determine the durations");
  552. if (rc)
  553. return rc;
  554. if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 ||
  555. be32_to_cpu(tpm_cmd.header.out.length)
  556. != sizeof(tpm_cmd.header.out) + sizeof(u32) + 3 * sizeof(u32))
  557. return -EINVAL;
  558. duration_cap = &tpm_cmd.params.getcap_out.cap.duration;
  559. chip->duration[TPM_SHORT] =
  560. usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short));
  561. chip->duration[TPM_MEDIUM] =
  562. usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_medium));
  563. chip->duration[TPM_LONG] =
  564. usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_long));
  565. /* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above
  566. * value wrong and apparently reports msecs rather than usecs. So we
  567. * fix up the resulting too-small TPM_SHORT value to make things work.
  568. * We also scale the TPM_MEDIUM and -_LONG values by 1000.
  569. */
  570. if (chip->duration[TPM_SHORT] < (HZ / 100)) {
  571. chip->duration[TPM_SHORT] = HZ;
  572. chip->duration[TPM_MEDIUM] *= 1000;
  573. chip->duration[TPM_LONG] *= 1000;
  574. chip->duration_adjusted = true;
  575. dev_info(&chip->dev, "Adjusting TPM timeout parameters.");
  576. }
  577. return 0;
  578. }
  579. EXPORT_SYMBOL_GPL(tpm_get_timeouts);
  580. #define TPM_ORD_CONTINUE_SELFTEST 83
  581. #define CONTINUE_SELFTEST_RESULT_SIZE 10
  582. static struct tpm_input_header continue_selftest_header = {
  583. .tag = TPM_TAG_RQU_COMMAND,
  584. .length = cpu_to_be32(10),
  585. .ordinal = cpu_to_be32(TPM_ORD_CONTINUE_SELFTEST),
  586. };
  587. /**
  588. * tpm_continue_selftest -- run TPM's selftest
  589. * @chip: TPM chip to use
  590. *
  591. * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing
  592. * a TPM error code.
  593. */
  594. static int tpm_continue_selftest(struct tpm_chip *chip)
  595. {
  596. int rc;
  597. struct tpm_cmd_t cmd;
  598. cmd.header.in = continue_selftest_header;
  599. rc = tpm_transmit_cmd(chip, &cmd, CONTINUE_SELFTEST_RESULT_SIZE,
  600. "continue selftest");
  601. return rc;
  602. }
  603. #define TPM_ORDINAL_PCRREAD cpu_to_be32(21)
  604. #define READ_PCR_RESULT_SIZE 30
  605. static struct tpm_input_header pcrread_header = {
  606. .tag = TPM_TAG_RQU_COMMAND,
  607. .length = cpu_to_be32(14),
  608. .ordinal = TPM_ORDINAL_PCRREAD
  609. };
  610. int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
  611. {
  612. int rc;
  613. struct tpm_cmd_t cmd;
  614. cmd.header.in = pcrread_header;
  615. cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx);
  616. rc = tpm_transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
  617. "attempting to read a pcr value");
  618. if (rc == 0)
  619. memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
  620. TPM_DIGEST_SIZE);
  621. return rc;
  622. }
  623. /**
  624. * tpm_is_tpm2 - is the chip a TPM2 chip?
  625. * @chip_num: tpm idx # or ANY
  626. *
  627. * Returns < 0 on error, and 1 or 0 on success depending whether the chip
  628. * is a TPM2 chip.
  629. */
  630. int tpm_is_tpm2(u32 chip_num)
  631. {
  632. struct tpm_chip *chip;
  633. int rc;
  634. chip = tpm_chip_find_get(chip_num);
  635. if (chip == NULL)
  636. return -ENODEV;
  637. rc = (chip->flags & TPM_CHIP_FLAG_TPM2) != 0;
  638. tpm_put_ops(chip);
  639. return rc;
  640. }
  641. EXPORT_SYMBOL_GPL(tpm_is_tpm2);
  642. /**
  643. * tpm_pcr_read - read a pcr value
  644. * @chip_num: tpm idx # or ANY
  645. * @pcr_idx: pcr idx to retrieve
  646. * @res_buf: TPM_PCR value
  647. * size of res_buf is 20 bytes (or NULL if you don't care)
  648. *
  649. * The TPM driver should be built-in, but for whatever reason it
  650. * isn't, protect against the chip disappearing, by incrementing
  651. * the module usage count.
  652. */
  653. int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
  654. {
  655. struct tpm_chip *chip;
  656. int rc;
  657. chip = tpm_chip_find_get(chip_num);
  658. if (chip == NULL)
  659. return -ENODEV;
  660. if (chip->flags & TPM_CHIP_FLAG_TPM2)
  661. rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
  662. else
  663. rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
  664. tpm_put_ops(chip);
  665. return rc;
  666. }
  667. EXPORT_SYMBOL_GPL(tpm_pcr_read);
  668. /**
  669. * tpm_pcr_extend - extend pcr value with hash
  670. * @chip_num: tpm idx # or AN&
  671. * @pcr_idx: pcr idx to extend
  672. * @hash: hash value used to extend pcr value
  673. *
  674. * The TPM driver should be built-in, but for whatever reason it
  675. * isn't, protect against the chip disappearing, by incrementing
  676. * the module usage count.
  677. */
  678. #define TPM_ORD_PCR_EXTEND cpu_to_be32(20)
  679. #define EXTEND_PCR_RESULT_SIZE 34
  680. static struct tpm_input_header pcrextend_header = {
  681. .tag = TPM_TAG_RQU_COMMAND,
  682. .length = cpu_to_be32(34),
  683. .ordinal = TPM_ORD_PCR_EXTEND
  684. };
  685. int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
  686. {
  687. struct tpm_cmd_t cmd;
  688. int rc;
  689. struct tpm_chip *chip;
  690. chip = tpm_chip_find_get(chip_num);
  691. if (chip == NULL)
  692. return -ENODEV;
  693. if (chip->flags & TPM_CHIP_FLAG_TPM2) {
  694. rc = tpm2_pcr_extend(chip, pcr_idx, hash);
  695. tpm_put_ops(chip);
  696. return rc;
  697. }
  698. cmd.header.in = pcrextend_header;
  699. cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(pcr_idx);
  700. memcpy(cmd.params.pcrextend_in.hash, hash, TPM_DIGEST_SIZE);
  701. rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
  702. "attempting extend a PCR value");
  703. tpm_put_ops(chip);
  704. return rc;
  705. }
  706. EXPORT_SYMBOL_GPL(tpm_pcr_extend);
  707. /**
  708. * tpm_do_selftest - have the TPM continue its selftest and wait until it
  709. * can receive further commands
  710. * @chip: TPM chip to use
  711. *
  712. * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing
  713. * a TPM error code.
  714. */
  715. int tpm_do_selftest(struct tpm_chip *chip)
  716. {
  717. int rc;
  718. unsigned int loops;
  719. unsigned int delay_msec = 100;
  720. unsigned long duration;
  721. struct tpm_cmd_t cmd;
  722. duration = tpm_calc_ordinal_duration(chip, TPM_ORD_CONTINUE_SELFTEST);
  723. loops = jiffies_to_msecs(duration) / delay_msec;
  724. rc = tpm_continue_selftest(chip);
  725. /* This may fail if there was no TPM driver during a suspend/resume
  726. * cycle; some may return 10 (BAD_ORDINAL), others 28 (FAILEDSELFTEST)
  727. */
  728. if (rc)
  729. return rc;
  730. do {
  731. /* Attempt to read a PCR value */
  732. cmd.header.in = pcrread_header;
  733. cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0);
  734. rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE);
  735. /* Some buggy TPMs will not respond to tpm_tis_ready() for
  736. * around 300ms while the self test is ongoing, keep trying
  737. * until the self test duration expires. */
  738. if (rc == -ETIME) {
  739. dev_info(
  740. &chip->dev, HW_ERR
  741. "TPM command timed out during continue self test");
  742. msleep(delay_msec);
  743. continue;
  744. }
  745. if (rc < TPM_HEADER_SIZE)
  746. return -EFAULT;
  747. rc = be32_to_cpu(cmd.header.out.return_code);
  748. if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) {
  749. dev_info(&chip->dev,
  750. "TPM is disabled/deactivated (0x%X)\n", rc);
  751. /* TPM is disabled and/or deactivated; driver can
  752. * proceed and TPM does handle commands for
  753. * suspend/resume correctly
  754. */
  755. return 0;
  756. }
  757. if (rc != TPM_WARN_DOING_SELFTEST)
  758. return rc;
  759. msleep(delay_msec);
  760. } while (--loops > 0);
  761. return rc;
  762. }
  763. EXPORT_SYMBOL_GPL(tpm_do_selftest);
  764. /**
  765. * tpm1_auto_startup - Perform the standard automatic TPM initialization
  766. * sequence
  767. * @chip: TPM chip to use
  768. *
  769. * Returns 0 on success, < 0 in case of fatal error.
  770. */
  771. int tpm1_auto_startup(struct tpm_chip *chip)
  772. {
  773. int rc;
  774. rc = tpm_get_timeouts(chip);
  775. if (rc)
  776. goto out;
  777. rc = tpm_do_selftest(chip);
  778. if (rc) {
  779. dev_err(&chip->dev, "TPM self test failed\n");
  780. goto out;
  781. }
  782. return rc;
  783. out:
  784. if (rc > 0)
  785. rc = -ENODEV;
  786. return rc;
  787. }
  788. int tpm_send(u32 chip_num, void *cmd, size_t buflen)
  789. {
  790. struct tpm_chip *chip;
  791. int rc;
  792. chip = tpm_chip_find_get(chip_num);
  793. if (chip == NULL)
  794. return -ENODEV;
  795. rc = tpm_transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd");
  796. tpm_put_ops(chip);
  797. return rc;
  798. }
  799. EXPORT_SYMBOL_GPL(tpm_send);
  800. static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,
  801. bool check_cancel, bool *canceled)
  802. {
  803. u8 status = chip->ops->status(chip);
  804. *canceled = false;
  805. if ((status & mask) == mask)
  806. return true;
  807. if (check_cancel && chip->ops->req_canceled(chip, status)) {
  808. *canceled = true;
  809. return true;
  810. }
  811. return false;
  812. }
  813. int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
  814. wait_queue_head_t *queue, bool check_cancel)
  815. {
  816. unsigned long stop;
  817. long rc;
  818. u8 status;
  819. bool canceled = false;
  820. /* check current status */
  821. status = chip->ops->status(chip);
  822. if ((status & mask) == mask)
  823. return 0;
  824. stop = jiffies + timeout;
  825. if (chip->flags & TPM_CHIP_FLAG_IRQ) {
  826. again:
  827. timeout = stop - jiffies;
  828. if ((long)timeout <= 0)
  829. return -ETIME;
  830. rc = wait_event_interruptible_timeout(*queue,
  831. wait_for_tpm_stat_cond(chip, mask, check_cancel,
  832. &canceled),
  833. timeout);
  834. if (rc > 0) {
  835. if (canceled)
  836. return -ECANCELED;
  837. return 0;
  838. }
  839. if (rc == -ERESTARTSYS && freezing(current)) {
  840. clear_thread_flag(TIF_SIGPENDING);
  841. goto again;
  842. }
  843. } else {
  844. do {
  845. msleep(TPM_TIMEOUT);
  846. status = chip->ops->status(chip);
  847. if ((status & mask) == mask)
  848. return 0;
  849. } while (time_before(jiffies, stop));
  850. }
  851. return -ETIME;
  852. }
  853. EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
  854. #define TPM_ORD_SAVESTATE cpu_to_be32(152)
  855. #define SAVESTATE_RESULT_SIZE 10
  856. static struct tpm_input_header savestate_header = {
  857. .tag = TPM_TAG_RQU_COMMAND,
  858. .length = cpu_to_be32(10),
  859. .ordinal = TPM_ORD_SAVESTATE
  860. };
  861. /*
  862. * We are about to suspend. Save the TPM state
  863. * so that it can be restored.
  864. */
  865. int tpm_pm_suspend(struct device *dev)
  866. {
  867. struct tpm_chip *chip = dev_get_drvdata(dev);
  868. struct tpm_cmd_t cmd;
  869. int rc, try;
  870. u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 };
  871. if (chip == NULL)
  872. return -ENODEV;
  873. if (chip->flags & TPM_CHIP_FLAG_TPM2) {
  874. tpm2_shutdown(chip, TPM2_SU_STATE);
  875. return 0;
  876. }
  877. /* for buggy tpm, flush pcrs with extend to selected dummy */
  878. if (tpm_suspend_pcr) {
  879. cmd.header.in = pcrextend_header;
  880. cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(tpm_suspend_pcr);
  881. memcpy(cmd.params.pcrextend_in.hash, dummy_hash,
  882. TPM_DIGEST_SIZE);
  883. rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
  884. "extending dummy pcr before suspend");
  885. }
  886. /* now do the actual savestate */
  887. for (try = 0; try < TPM_RETRY; try++) {
  888. cmd.header.in = savestate_header;
  889. rc = tpm_transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE, NULL);
  890. /*
  891. * If the TPM indicates that it is too busy to respond to
  892. * this command then retry before giving up. It can take
  893. * several seconds for this TPM to be ready.
  894. *
  895. * This can happen if the TPM has already been sent the
  896. * SaveState command before the driver has loaded. TCG 1.2
  897. * specification states that any communication after SaveState
  898. * may cause the TPM to invalidate previously saved state.
  899. */
  900. if (rc != TPM_WARN_RETRY)
  901. break;
  902. msleep(TPM_TIMEOUT_RETRY);
  903. }
  904. if (rc)
  905. dev_err(&chip->dev,
  906. "Error (%d) sending savestate before suspend\n", rc);
  907. else if (try > 0)
  908. dev_warn(&chip->dev, "TPM savestate took %dms\n",
  909. try * TPM_TIMEOUT_RETRY);
  910. return rc;
  911. }
  912. EXPORT_SYMBOL_GPL(tpm_pm_suspend);
  913. /*
  914. * Resume from a power safe. The BIOS already restored
  915. * the TPM state.
  916. */
  917. int tpm_pm_resume(struct device *dev)
  918. {
  919. struct tpm_chip *chip = dev_get_drvdata(dev);
  920. if (chip == NULL)
  921. return -ENODEV;
  922. return 0;
  923. }
  924. EXPORT_SYMBOL_GPL(tpm_pm_resume);
  925. #define TPM_GETRANDOM_RESULT_SIZE 18
  926. static struct tpm_input_header tpm_getrandom_header = {
  927. .tag = TPM_TAG_RQU_COMMAND,
  928. .length = cpu_to_be32(14),
  929. .ordinal = TPM_ORD_GET_RANDOM
  930. };
  931. /**
  932. * tpm_get_random() - Get random bytes from the tpm's RNG
  933. * @chip_num: A specific chip number for the request or TPM_ANY_NUM
  934. * @out: destination buffer for the random bytes
  935. * @max: the max number of bytes to write to @out
  936. *
  937. * Returns < 0 on error and the number of bytes read on success
  938. */
  939. int tpm_get_random(u32 chip_num, u8 *out, size_t max)
  940. {
  941. struct tpm_chip *chip;
  942. struct tpm_cmd_t tpm_cmd;
  943. u32 recd, num_bytes = min_t(u32, max, TPM_MAX_RNG_DATA);
  944. int err, total = 0, retries = 5;
  945. u8 *dest = out;
  946. if (!out || !num_bytes || max > TPM_MAX_RNG_DATA)
  947. return -EINVAL;
  948. chip = tpm_chip_find_get(chip_num);
  949. if (chip == NULL)
  950. return -ENODEV;
  951. if (chip->flags & TPM_CHIP_FLAG_TPM2) {
  952. err = tpm2_get_random(chip, out, max);
  953. tpm_put_ops(chip);
  954. return err;
  955. }
  956. do {
  957. tpm_cmd.header.in = tpm_getrandom_header;
  958. tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
  959. err = tpm_transmit_cmd(chip, &tpm_cmd,
  960. TPM_GETRANDOM_RESULT_SIZE + num_bytes,
  961. "attempting get random");
  962. if (err)
  963. break;
  964. recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
  965. memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd);
  966. dest += recd;
  967. total += recd;
  968. num_bytes -= recd;
  969. } while (retries-- && total < max);
  970. tpm_put_ops(chip);
  971. return total ? total : -EIO;
  972. }
  973. EXPORT_SYMBOL_GPL(tpm_get_random);
  974. /**
  975. * tpm_seal_trusted() - seal a trusted key
  976. * @chip_num: A specific chip number for the request or TPM_ANY_NUM
  977. * @options: authentication values and other options
  978. * @payload: the key data in clear and encrypted form
  979. *
  980. * Returns < 0 on error and 0 on success. At the moment, only TPM 2.0 chips
  981. * are supported.
  982. */
  983. int tpm_seal_trusted(u32 chip_num, struct trusted_key_payload *payload,
  984. struct trusted_key_options *options)
  985. {
  986. struct tpm_chip *chip;
  987. int rc;
  988. chip = tpm_chip_find_get(chip_num);
  989. if (chip == NULL || !(chip->flags & TPM_CHIP_FLAG_TPM2))
  990. return -ENODEV;
  991. rc = tpm2_seal_trusted(chip, payload, options);
  992. tpm_put_ops(chip);
  993. return rc;
  994. }
  995. EXPORT_SYMBOL_GPL(tpm_seal_trusted);
  996. /**
  997. * tpm_unseal_trusted() - unseal a trusted key
  998. * @chip_num: A specific chip number for the request or TPM_ANY_NUM
  999. * @options: authentication values and other options
  1000. * @payload: the key data in clear and encrypted form
  1001. *
  1002. * Returns < 0 on error and 0 on success. At the moment, only TPM 2.0 chips
  1003. * are supported.
  1004. */
  1005. int tpm_unseal_trusted(u32 chip_num, struct trusted_key_payload *payload,
  1006. struct trusted_key_options *options)
  1007. {
  1008. struct tpm_chip *chip;
  1009. int rc;
  1010. chip = tpm_chip_find_get(chip_num);
  1011. if (chip == NULL || !(chip->flags & TPM_CHIP_FLAG_TPM2))
  1012. return -ENODEV;
  1013. rc = tpm2_unseal_trusted(chip, payload, options);
  1014. tpm_put_ops(chip);
  1015. return rc;
  1016. }
  1017. EXPORT_SYMBOL_GPL(tpm_unseal_trusted);
  1018. static int __init tpm_init(void)
  1019. {
  1020. int rc;
  1021. tpm_class = class_create(THIS_MODULE, "tpm");
  1022. if (IS_ERR(tpm_class)) {
  1023. pr_err("couldn't create tpm class\n");
  1024. return PTR_ERR(tpm_class);
  1025. }
  1026. rc = alloc_chrdev_region(&tpm_devt, 0, TPM_NUM_DEVICES, "tpm");
  1027. if (rc < 0) {
  1028. pr_err("tpm: failed to allocate char dev region\n");
  1029. class_destroy(tpm_class);
  1030. return rc;
  1031. }
  1032. return 0;
  1033. }
  1034. static void __exit tpm_exit(void)
  1035. {
  1036. idr_destroy(&dev_nums_idr);
  1037. class_destroy(tpm_class);
  1038. unregister_chrdev_region(tpm_devt, TPM_NUM_DEVICES);
  1039. }
  1040. subsys_initcall(tpm_init);
  1041. module_exit(tpm_exit);
  1042. MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
  1043. MODULE_DESCRIPTION("TPM Driver");
  1044. MODULE_VERSION("2.0");
  1045. MODULE_LICENSE("GPL");