tpm.c 15 KB

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