tpm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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 schedule_timeout.
  23. *
  24. */
  25. #include <linux/sched.h>
  26. #include <linux/poll.h>
  27. #include <linux/spinlock.h>
  28. #include "tpm.h"
  29. #define TPM_MINOR 224 /* officially assigned */
  30. #define TPM_BUFSIZE 2048
  31. /* PCI configuration addresses */
  32. #define PCI_GEN_PMCON_1 0xA0
  33. #define PCI_GEN1_DEC 0xE4
  34. #define PCI_LPC_EN 0xE6
  35. #define PCI_GEN2_DEC 0xEC
  36. static LIST_HEAD(tpm_chip_list);
  37. static DEFINE_SPINLOCK(driver_lock);
  38. static int dev_mask[32];
  39. static void user_reader_timeout(unsigned long ptr)
  40. {
  41. struct tpm_chip *chip = (struct tpm_chip *) ptr;
  42. down(&chip->buffer_mutex);
  43. atomic_set(&chip->data_pending, 0);
  44. memset(chip->data_buffer, 0, TPM_BUFSIZE);
  45. up(&chip->buffer_mutex);
  46. }
  47. void tpm_time_expired(unsigned long ptr)
  48. {
  49. int *exp = (int *) ptr;
  50. *exp = 1;
  51. }
  52. EXPORT_SYMBOL_GPL(tpm_time_expired);
  53. /*
  54. * Initialize the LPC bus and enable the TPM ports
  55. */
  56. int tpm_lpc_bus_init(struct pci_dev *pci_dev, u16 base)
  57. {
  58. u32 lpcenable, tmp;
  59. int is_lpcm = 0;
  60. switch (pci_dev->vendor) {
  61. case PCI_VENDOR_ID_INTEL:
  62. switch (pci_dev->device) {
  63. case PCI_DEVICE_ID_INTEL_82801CA_12:
  64. case PCI_DEVICE_ID_INTEL_82801DB_12:
  65. is_lpcm = 1;
  66. break;
  67. }
  68. /* init ICH (enable LPC) */
  69. pci_read_config_dword(pci_dev, PCI_GEN1_DEC, &lpcenable);
  70. lpcenable |= 0x20000000;
  71. pci_write_config_dword(pci_dev, PCI_GEN1_DEC, lpcenable);
  72. if (is_lpcm) {
  73. pci_read_config_dword(pci_dev, PCI_GEN1_DEC,
  74. &lpcenable);
  75. if ((lpcenable & 0x20000000) == 0) {
  76. dev_err(&pci_dev->dev,
  77. "cannot enable LPC\n");
  78. return -ENODEV;
  79. }
  80. }
  81. /* initialize TPM registers */
  82. pci_read_config_dword(pci_dev, PCI_GEN2_DEC, &tmp);
  83. if (!is_lpcm)
  84. tmp = (tmp & 0xFFFF0000) | (base & 0xFFF0);
  85. else
  86. tmp =
  87. (tmp & 0xFFFF0000) | (base & 0xFFF0) |
  88. 0x00000001;
  89. pci_write_config_dword(pci_dev, PCI_GEN2_DEC, tmp);
  90. if (is_lpcm) {
  91. pci_read_config_dword(pci_dev, PCI_GEN_PMCON_1,
  92. &tmp);
  93. tmp |= 0x00000004; /* enable CLKRUN */
  94. pci_write_config_dword(pci_dev, PCI_GEN_PMCON_1,
  95. tmp);
  96. }
  97. tpm_write_index(0x0D, 0x55); /* unlock 4F */
  98. tpm_write_index(0x0A, 0x00); /* int disable */
  99. tpm_write_index(0x08, base); /* base addr lo */
  100. tpm_write_index(0x09, (base & 0xFF00) >> 8); /* base addr hi */
  101. tpm_write_index(0x0D, 0xAA); /* lock 4F */
  102. break;
  103. case PCI_VENDOR_ID_AMD:
  104. /* nothing yet */
  105. break;
  106. }
  107. return 0;
  108. }
  109. EXPORT_SYMBOL_GPL(tpm_lpc_bus_init);
  110. /*
  111. * Internal kernel interface to transmit TPM commands
  112. */
  113. static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
  114. size_t bufsiz)
  115. {
  116. ssize_t len;
  117. u32 count;
  118. __be32 *native_size;
  119. native_size = (__force __be32 *) (buf + 2);
  120. count = be32_to_cpu(*native_size);
  121. if (count == 0)
  122. return -ENODATA;
  123. if (count > bufsiz) {
  124. dev_err(&chip->pci_dev->dev,
  125. "invalid count value %x %zx \n", count, bufsiz);
  126. return -E2BIG;
  127. }
  128. down(&chip->tpm_mutex);
  129. if ((len = chip->vendor->send(chip, (u8 *) buf, count)) < 0) {
  130. dev_err(&chip->pci_dev->dev,
  131. "tpm_transmit: tpm_send: error %zd\n", len);
  132. return len;
  133. }
  134. down(&chip->timer_manipulation_mutex);
  135. chip->time_expired = 0;
  136. init_timer(&chip->device_timer);
  137. chip->device_timer.function = tpm_time_expired;
  138. chip->device_timer.expires = jiffies + 2 * 60 * HZ;
  139. chip->device_timer.data = (unsigned long) &chip->time_expired;
  140. add_timer(&chip->device_timer);
  141. up(&chip->timer_manipulation_mutex);
  142. do {
  143. u8 status = inb(chip->vendor->base + 1);
  144. if ((status & chip->vendor->req_complete_mask) ==
  145. chip->vendor->req_complete_val) {
  146. down(&chip->timer_manipulation_mutex);
  147. del_singleshot_timer_sync(&chip->device_timer);
  148. up(&chip->timer_manipulation_mutex);
  149. goto out_recv;
  150. }
  151. set_current_state(TASK_UNINTERRUPTIBLE);
  152. schedule_timeout(TPM_TIMEOUT);
  153. rmb();
  154. } while (!chip->time_expired);
  155. chip->vendor->cancel(chip);
  156. dev_err(&chip->pci_dev->dev, "Time expired\n");
  157. up(&chip->tpm_mutex);
  158. return -EIO;
  159. out_recv:
  160. len = chip->vendor->recv(chip, (u8 *) buf, bufsiz);
  161. if (len < 0)
  162. dev_err(&chip->pci_dev->dev,
  163. "tpm_transmit: tpm_recv: error %zd\n", len);
  164. up(&chip->tpm_mutex);
  165. return len;
  166. }
  167. #define TPM_DIGEST_SIZE 20
  168. #define CAP_PCR_RESULT_SIZE 18
  169. static u8 cap_pcr[] = {
  170. 0, 193, /* TPM_TAG_RQU_COMMAND */
  171. 0, 0, 0, 22, /* length */
  172. 0, 0, 0, 101, /* TPM_ORD_GetCapability */
  173. 0, 0, 0, 5,
  174. 0, 0, 0, 4,
  175. 0, 0, 1, 1
  176. };
  177. #define READ_PCR_RESULT_SIZE 30
  178. static u8 pcrread[] = {
  179. 0, 193, /* TPM_TAG_RQU_COMMAND */
  180. 0, 0, 0, 14, /* length */
  181. 0, 0, 0, 21, /* TPM_ORD_PcrRead */
  182. 0, 0, 0, 0 /* PCR index */
  183. };
  184. static ssize_t show_pcrs(struct device *dev, struct device_attribute *attr, char *buf)
  185. {
  186. u8 data[READ_PCR_RESULT_SIZE];
  187. ssize_t len;
  188. int i, j, index, num_pcrs;
  189. char *str = buf;
  190. struct tpm_chip *chip =
  191. pci_get_drvdata(container_of(dev, struct pci_dev, dev));
  192. if (chip == NULL)
  193. return -ENODEV;
  194. memcpy(data, cap_pcr, sizeof(cap_pcr));
  195. if ((len = tpm_transmit(chip, data, sizeof(data)))
  196. < CAP_PCR_RESULT_SIZE)
  197. return len;
  198. num_pcrs = be32_to_cpu(*((__force __be32 *) (data + 14)));
  199. for (i = 0; i < num_pcrs; i++) {
  200. memcpy(data, pcrread, sizeof(pcrread));
  201. index = cpu_to_be32(i);
  202. memcpy(data + 10, &index, 4);
  203. if ((len = tpm_transmit(chip, data, sizeof(data)))
  204. < READ_PCR_RESULT_SIZE)
  205. return len;
  206. str += sprintf(str, "PCR-%02d: ", i);
  207. for (j = 0; j < TPM_DIGEST_SIZE; j++)
  208. str += sprintf(str, "%02X ", *(data + 10 + j));
  209. str += sprintf(str, "\n");
  210. }
  211. return str - buf;
  212. }
  213. static DEVICE_ATTR(pcrs, S_IRUGO, show_pcrs, NULL);
  214. #define READ_PUBEK_RESULT_SIZE 314
  215. static u8 readpubek[] = {
  216. 0, 193, /* TPM_TAG_RQU_COMMAND */
  217. 0, 0, 0, 30, /* length */
  218. 0, 0, 0, 124, /* TPM_ORD_ReadPubek */
  219. };
  220. static ssize_t show_pubek(struct device *dev, struct device_attribute *attr, char *buf)
  221. {
  222. u8 data[READ_PUBEK_RESULT_SIZE];
  223. ssize_t len;
  224. __be32 *native_val;
  225. int i;
  226. char *str = buf;
  227. struct tpm_chip *chip =
  228. pci_get_drvdata(container_of(dev, struct pci_dev, dev));
  229. if (chip == NULL)
  230. return -ENODEV;
  231. memcpy(data, readpubek, sizeof(readpubek));
  232. memset(data + sizeof(readpubek), 0, 20); /* zero nonce */
  233. if ((len = tpm_transmit(chip, data, sizeof(data))) <
  234. READ_PUBEK_RESULT_SIZE)
  235. return len;
  236. /*
  237. ignore header 10 bytes
  238. algorithm 32 bits (1 == RSA )
  239. encscheme 16 bits
  240. sigscheme 16 bits
  241. parameters (RSA 12->bytes: keybit, #primes, expbit)
  242. keylenbytes 32 bits
  243. 256 byte modulus
  244. ignore checksum 20 bytes
  245. */
  246. native_val = (__force __be32 *) (data + 34);
  247. str +=
  248. sprintf(str,
  249. "Algorithm: %02X %02X %02X %02X\nEncscheme: %02X %02X\n"
  250. "Sigscheme: %02X %02X\nParameters: %02X %02X %02X %02X"
  251. " %02X %02X %02X %02X %02X %02X %02X %02X\n"
  252. "Modulus length: %d\nModulus: \n",
  253. data[10], data[11], data[12], data[13], data[14],
  254. data[15], data[16], data[17], data[22], data[23],
  255. data[24], data[25], data[26], data[27], data[28],
  256. data[29], data[30], data[31], data[32], data[33],
  257. be32_to_cpu(*native_val)
  258. );
  259. for (i = 0; i < 256; i++) {
  260. str += sprintf(str, "%02X ", data[i + 39]);
  261. if ((i + 1) % 16 == 0)
  262. str += sprintf(str, "\n");
  263. }
  264. return str - buf;
  265. }
  266. static DEVICE_ATTR(pubek, S_IRUGO, show_pubek, NULL);
  267. #define CAP_VER_RESULT_SIZE 18
  268. static u8 cap_version[] = {
  269. 0, 193, /* TPM_TAG_RQU_COMMAND */
  270. 0, 0, 0, 18, /* length */
  271. 0, 0, 0, 101, /* TPM_ORD_GetCapability */
  272. 0, 0, 0, 6,
  273. 0, 0, 0, 0
  274. };
  275. #define CAP_MANUFACTURER_RESULT_SIZE 18
  276. static u8 cap_manufacturer[] = {
  277. 0, 193, /* TPM_TAG_RQU_COMMAND */
  278. 0, 0, 0, 22, /* length */
  279. 0, 0, 0, 101, /* TPM_ORD_GetCapability */
  280. 0, 0, 0, 5,
  281. 0, 0, 0, 4,
  282. 0, 0, 1, 3
  283. };
  284. static ssize_t show_caps(struct device *dev, struct device_attribute *attr, char *buf)
  285. {
  286. u8 data[READ_PUBEK_RESULT_SIZE];
  287. ssize_t len;
  288. char *str = buf;
  289. struct tpm_chip *chip =
  290. pci_get_drvdata(container_of(dev, struct pci_dev, dev));
  291. if (chip == NULL)
  292. return -ENODEV;
  293. memcpy(data, cap_manufacturer, sizeof(cap_manufacturer));
  294. if ((len = tpm_transmit(chip, data, sizeof(data))) <
  295. CAP_MANUFACTURER_RESULT_SIZE)
  296. return len;
  297. str += sprintf(str, "Manufacturer: 0x%x\n",
  298. be32_to_cpu(*(data + 14)));
  299. memcpy(data, cap_version, sizeof(cap_version));
  300. if ((len = tpm_transmit(chip, data, sizeof(data))) <
  301. CAP_VER_RESULT_SIZE)
  302. return len;
  303. str +=
  304. sprintf(str, "TCG version: %d.%d\nFirmware version: %d.%d\n",
  305. (int) data[14], (int) data[15], (int) data[16],
  306. (int) data[17]);
  307. return str - buf;
  308. }
  309. static DEVICE_ATTR(caps, S_IRUGO, show_caps, NULL);
  310. /*
  311. * Device file system interface to the TPM
  312. */
  313. int tpm_open(struct inode *inode, struct file *file)
  314. {
  315. int rc = 0, minor = iminor(inode);
  316. struct tpm_chip *chip = NULL, *pos;
  317. spin_lock(&driver_lock);
  318. list_for_each_entry(pos, &tpm_chip_list, list) {
  319. if (pos->vendor->miscdev.minor == minor) {
  320. chip = pos;
  321. break;
  322. }
  323. }
  324. if (chip == NULL) {
  325. rc = -ENODEV;
  326. goto err_out;
  327. }
  328. if (chip->num_opens) {
  329. dev_dbg(&chip->pci_dev->dev,
  330. "Another process owns this TPM\n");
  331. rc = -EBUSY;
  332. goto err_out;
  333. }
  334. chip->num_opens++;
  335. pci_dev_get(chip->pci_dev);
  336. spin_unlock(&driver_lock);
  337. chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
  338. if (chip->data_buffer == NULL) {
  339. chip->num_opens--;
  340. pci_dev_put(chip->pci_dev);
  341. return -ENOMEM;
  342. }
  343. atomic_set(&chip->data_pending, 0);
  344. file->private_data = chip;
  345. return 0;
  346. err_out:
  347. spin_unlock(&driver_lock);
  348. return rc;
  349. }
  350. EXPORT_SYMBOL_GPL(tpm_open);
  351. int tpm_release(struct inode *inode, struct file *file)
  352. {
  353. struct tpm_chip *chip = file->private_data;
  354. file->private_data = NULL;
  355. spin_lock(&driver_lock);
  356. chip->num_opens--;
  357. spin_unlock(&driver_lock);
  358. down(&chip->timer_manipulation_mutex);
  359. if (timer_pending(&chip->user_read_timer))
  360. del_singleshot_timer_sync(&chip->user_read_timer);
  361. else if (timer_pending(&chip->device_timer))
  362. del_singleshot_timer_sync(&chip->device_timer);
  363. up(&chip->timer_manipulation_mutex);
  364. kfree(chip->data_buffer);
  365. atomic_set(&chip->data_pending, 0);
  366. pci_dev_put(chip->pci_dev);
  367. return 0;
  368. }
  369. EXPORT_SYMBOL_GPL(tpm_release);
  370. ssize_t tpm_write(struct file * file, const char __user * buf,
  371. size_t size, loff_t * off)
  372. {
  373. struct tpm_chip *chip = file->private_data;
  374. int in_size = size, out_size;
  375. /* cannot perform a write until the read has cleared
  376. either via tpm_read or a user_read_timer timeout */
  377. while (atomic_read(&chip->data_pending) != 0) {
  378. set_current_state(TASK_UNINTERRUPTIBLE);
  379. schedule_timeout(TPM_TIMEOUT);
  380. }
  381. down(&chip->buffer_mutex);
  382. if (in_size > TPM_BUFSIZE)
  383. in_size = TPM_BUFSIZE;
  384. if (copy_from_user
  385. (chip->data_buffer, (void __user *) buf, in_size)) {
  386. up(&chip->buffer_mutex);
  387. return -EFAULT;
  388. }
  389. /* atomic tpm command send and result receive */
  390. out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
  391. atomic_set(&chip->data_pending, out_size);
  392. up(&chip->buffer_mutex);
  393. /* Set a timeout by which the reader must come claim the result */
  394. down(&chip->timer_manipulation_mutex);
  395. init_timer(&chip->user_read_timer);
  396. chip->user_read_timer.function = user_reader_timeout;
  397. chip->user_read_timer.data = (unsigned long) chip;
  398. chip->user_read_timer.expires = jiffies + (60 * HZ);
  399. add_timer(&chip->user_read_timer);
  400. up(&chip->timer_manipulation_mutex);
  401. return in_size;
  402. }
  403. EXPORT_SYMBOL_GPL(tpm_write);
  404. ssize_t tpm_read(struct file * file, char __user * buf,
  405. size_t size, loff_t * off)
  406. {
  407. struct tpm_chip *chip = file->private_data;
  408. int ret_size = -ENODATA;
  409. if (atomic_read(&chip->data_pending) != 0) { /* Result available */
  410. down(&chip->timer_manipulation_mutex);
  411. del_singleshot_timer_sync(&chip->user_read_timer);
  412. up(&chip->timer_manipulation_mutex);
  413. down(&chip->buffer_mutex);
  414. ret_size = atomic_read(&chip->data_pending);
  415. atomic_set(&chip->data_pending, 0);
  416. if (ret_size == 0) /* timeout just occurred */
  417. ret_size = -ETIME;
  418. else if (ret_size > 0) { /* relay data */
  419. if (size < ret_size)
  420. ret_size = size;
  421. if (copy_to_user((void __user *) buf,
  422. chip->data_buffer, ret_size)) {
  423. ret_size = -EFAULT;
  424. }
  425. }
  426. up(&chip->buffer_mutex);
  427. }
  428. return ret_size;
  429. }
  430. EXPORT_SYMBOL_GPL(tpm_read);
  431. void __devexit tpm_remove(struct pci_dev *pci_dev)
  432. {
  433. struct tpm_chip *chip = pci_get_drvdata(pci_dev);
  434. if (chip == NULL) {
  435. dev_err(&pci_dev->dev, "No device data found\n");
  436. return;
  437. }
  438. spin_lock(&driver_lock);
  439. list_del(&chip->list);
  440. spin_unlock(&driver_lock);
  441. pci_set_drvdata(pci_dev, NULL);
  442. misc_deregister(&chip->vendor->miscdev);
  443. device_remove_file(&pci_dev->dev, &dev_attr_pubek);
  444. device_remove_file(&pci_dev->dev, &dev_attr_pcrs);
  445. device_remove_file(&pci_dev->dev, &dev_attr_caps);
  446. pci_disable_device(pci_dev);
  447. dev_mask[chip->dev_num / 32] &= !(1 << (chip->dev_num % 32));
  448. kfree(chip);
  449. pci_dev_put(pci_dev);
  450. }
  451. EXPORT_SYMBOL_GPL(tpm_remove);
  452. static u8 savestate[] = {
  453. 0, 193, /* TPM_TAG_RQU_COMMAND */
  454. 0, 0, 0, 10, /* blob length (in bytes) */
  455. 0, 0, 0, 152 /* TPM_ORD_SaveState */
  456. };
  457. /*
  458. * We are about to suspend. Save the TPM state
  459. * so that it can be restored.
  460. */
  461. int tpm_pm_suspend(struct pci_dev *pci_dev, pm_message_t pm_state)
  462. {
  463. struct tpm_chip *chip = pci_get_drvdata(pci_dev);
  464. if (chip == NULL)
  465. return -ENODEV;
  466. tpm_transmit(chip, savestate, sizeof(savestate));
  467. return 0;
  468. }
  469. EXPORT_SYMBOL_GPL(tpm_pm_suspend);
  470. /*
  471. * Resume from a power safe. The BIOS already restored
  472. * the TPM state.
  473. */
  474. int tpm_pm_resume(struct pci_dev *pci_dev)
  475. {
  476. struct tpm_chip *chip = pci_get_drvdata(pci_dev);
  477. if (chip == NULL)
  478. return -ENODEV;
  479. spin_lock(&driver_lock);
  480. tpm_lpc_bus_init(pci_dev, chip->vendor->base);
  481. spin_unlock(&driver_lock);
  482. return 0;
  483. }
  484. EXPORT_SYMBOL_GPL(tpm_pm_resume);
  485. /*
  486. * Called from tpm_<specific>.c probe function only for devices
  487. * the driver has determined it should claim. Prior to calling
  488. * this function the specific probe function has called pci_enable_device
  489. * upon errant exit from this function specific probe function should call
  490. * pci_disable_device
  491. */
  492. int tpm_register_hardware(struct pci_dev *pci_dev,
  493. struct tpm_vendor_specific *entry)
  494. {
  495. char devname[7];
  496. struct tpm_chip *chip;
  497. int i, j;
  498. /* Driver specific per-device data */
  499. chip = kmalloc(sizeof(*chip), GFP_KERNEL);
  500. if (chip == NULL)
  501. return -ENOMEM;
  502. memset(chip, 0, sizeof(struct tpm_chip));
  503. init_MUTEX(&chip->buffer_mutex);
  504. init_MUTEX(&chip->tpm_mutex);
  505. init_MUTEX(&chip->timer_manipulation_mutex);
  506. INIT_LIST_HEAD(&chip->list);
  507. chip->vendor = entry;
  508. chip->dev_num = -1;
  509. for (i = 0; i < 32; i++)
  510. for (j = 0; j < 8; j++)
  511. if ((dev_mask[i] & (1 << j)) == 0) {
  512. chip->dev_num = i * 32 + j;
  513. dev_mask[i] |= 1 << j;
  514. goto dev_num_search_complete;
  515. }
  516. dev_num_search_complete:
  517. if (chip->dev_num < 0) {
  518. dev_err(&pci_dev->dev,
  519. "No available tpm device numbers\n");
  520. kfree(chip);
  521. return -ENODEV;
  522. } else if (chip->dev_num == 0)
  523. chip->vendor->miscdev.minor = TPM_MINOR;
  524. else
  525. chip->vendor->miscdev.minor = MISC_DYNAMIC_MINOR;
  526. snprintf(devname, sizeof(devname), "%s%d", "tpm", chip->dev_num);
  527. chip->vendor->miscdev.name = devname;
  528. chip->vendor->miscdev.dev = &(pci_dev->dev);
  529. chip->pci_dev = pci_dev_get(pci_dev);
  530. if (misc_register(&chip->vendor->miscdev)) {
  531. dev_err(&chip->pci_dev->dev,
  532. "unable to misc_register %s, minor %d\n",
  533. chip->vendor->miscdev.name,
  534. chip->vendor->miscdev.minor);
  535. pci_dev_put(pci_dev);
  536. kfree(chip);
  537. dev_mask[i] &= !(1 << j);
  538. return -ENODEV;
  539. }
  540. pci_set_drvdata(pci_dev, chip);
  541. list_add(&chip->list, &tpm_chip_list);
  542. device_create_file(&pci_dev->dev, &dev_attr_pubek);
  543. device_create_file(&pci_dev->dev, &dev_attr_pcrs);
  544. device_create_file(&pci_dev->dev, &dev_attr_caps);
  545. return 0;
  546. }
  547. EXPORT_SYMBOL_GPL(tpm_register_hardware);
  548. static int __init init_tpm(void)
  549. {
  550. return 0;
  551. }
  552. static void __exit cleanup_tpm(void)
  553. {
  554. }
  555. module_init(init_tpm);
  556. module_exit(cleanup_tpm);
  557. MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
  558. MODULE_DESCRIPTION("TPM Driver");
  559. MODULE_VERSION("2.0");
  560. MODULE_LICENSE("GPL");