tpm_tis.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Copyright (C) 2005, 2006 IBM Corporation
  3. *
  4. * Authors:
  5. * Leendert van Doorn <leendert@watson.ibm.com>
  6. * Kylene Hall <kjhall@us.ibm.com>
  7. *
  8. * Device driver for TCG/TCPA TPM (trusted platform module).
  9. * Specifications at www.trustedcomputinggroup.org
  10. *
  11. * This device driver implements the TPM interface as defined in
  12. * the TCG TPM Interface Spec version 1.2, revision 1.0.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation, version 2 of the
  17. * License.
  18. */
  19. #include <linux/pnp.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/wait.h>
  22. #include "tpm.h"
  23. #define TPM_HEADER_SIZE 10
  24. enum tis_access {
  25. TPM_ACCESS_VALID = 0x80,
  26. TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
  27. TPM_ACCESS_REQUEST_PENDING = 0x04,
  28. TPM_ACCESS_REQUEST_USE = 0x02,
  29. };
  30. enum tis_status {
  31. TPM_STS_VALID = 0x80,
  32. TPM_STS_COMMAND_READY = 0x40,
  33. TPM_STS_GO = 0x20,
  34. TPM_STS_DATA_AVAIL = 0x10,
  35. TPM_STS_DATA_EXPECT = 0x08,
  36. };
  37. enum tis_int_flags {
  38. TPM_GLOBAL_INT_ENABLE = 0x80000000,
  39. TPM_INTF_BURST_COUNT_STATIC = 0x100,
  40. TPM_INTF_CMD_READY_INT = 0x080,
  41. TPM_INTF_INT_EDGE_FALLING = 0x040,
  42. TPM_INTF_INT_EDGE_RISING = 0x020,
  43. TPM_INTF_INT_LEVEL_LOW = 0x010,
  44. TPM_INTF_INT_LEVEL_HIGH = 0x008,
  45. TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
  46. TPM_INTF_STS_VALID_INT = 0x002,
  47. TPM_INTF_DATA_AVAIL_INT = 0x001,
  48. };
  49. #define TPM_ACCESS(l) (0x0000 | ((l) << 12))
  50. #define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
  51. #define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
  52. #define TPM_INT_STATUS(l) (0x0010 | ((l) << 12))
  53. #define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
  54. #define TPM_STS(l) (0x0018 | ((l) << 12))
  55. #define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
  56. #define TPM_DID_VID(l) (0x0F00 | ((l) << 12))
  57. #define TPM_RID(l) (0x0F04 | ((l) << 12))
  58. static LIST_HEAD(tis_chips);
  59. static DEFINE_SPINLOCK(tis_lock);
  60. static int check_locality(struct tpm_chip *chip, int l)
  61. {
  62. if ((ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
  63. (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
  64. (TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
  65. return chip->vendor.locality = l;
  66. return -1;
  67. }
  68. static void release_locality(struct tpm_chip *chip, int l, int force)
  69. {
  70. if (force || (ioread8(chip->vendor.iobase + TPM_ACCESS(l)) &
  71. (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) ==
  72. (TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID))
  73. iowrite8(TPM_ACCESS_ACTIVE_LOCALITY,
  74. chip->vendor.iobase + TPM_ACCESS(l));
  75. }
  76. static int request_locality(struct tpm_chip *chip, int l)
  77. {
  78. unsigned long stop;
  79. long rc;
  80. if (check_locality(chip, l) >= 0)
  81. return l;
  82. iowrite8(TPM_ACCESS_REQUEST_USE,
  83. chip->vendor.iobase + TPM_ACCESS(l));
  84. if (chip->vendor.irq) {
  85. rc = wait_event_interruptible_timeout(chip->vendor.
  86. int_queue,
  87. (check_locality
  88. (chip, l) >= 0),
  89. msecs_to_jiffies
  90. (chip->vendor.
  91. timeout_a));
  92. if (rc > 0)
  93. return l;
  94. } else {
  95. /* wait for burstcount */
  96. stop = jiffies + (HZ * chip->vendor.timeout_a / 1000);
  97. do {
  98. if (check_locality(chip, l) >= 0)
  99. return l;
  100. msleep(TPM_TIMEOUT);
  101. }
  102. while (time_before(jiffies, stop));
  103. }
  104. return -1;
  105. }
  106. static u8 tpm_tis_status(struct tpm_chip *chip)
  107. {
  108. return ioread8(chip->vendor.iobase +
  109. TPM_STS(chip->vendor.locality));
  110. }
  111. static void tpm_tis_ready(struct tpm_chip *chip)
  112. {
  113. /* this causes the current command to be aborted */
  114. iowrite8(TPM_STS_COMMAND_READY,
  115. chip->vendor.iobase + TPM_STS(chip->vendor.locality));
  116. }
  117. static int get_burstcount(struct tpm_chip *chip)
  118. {
  119. unsigned long stop;
  120. int burstcnt;
  121. /* wait for burstcount */
  122. /* which timeout value, spec has 2 answers (c & d) */
  123. stop = jiffies + (HZ * chip->vendor.timeout_d / 1000);
  124. do {
  125. burstcnt = ioread8(chip->vendor.iobase +
  126. TPM_STS(chip->vendor.locality) + 1);
  127. burstcnt += ioread8(chip->vendor.iobase +
  128. TPM_STS(chip->vendor.locality) +
  129. 2) << 8;
  130. if (burstcnt)
  131. return burstcnt;
  132. msleep(TPM_TIMEOUT);
  133. } while (time_before(jiffies, stop));
  134. return -EBUSY;
  135. }
  136. static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
  137. wait_queue_head_t *queue)
  138. {
  139. unsigned long stop;
  140. long rc;
  141. u8 status;
  142. /* check current status */
  143. status = tpm_tis_status(chip);
  144. if ((status & mask) == mask)
  145. return 0;
  146. if (chip->vendor.irq) {
  147. rc = wait_event_interruptible_timeout(*queue,
  148. ((tpm_tis_status
  149. (chip) & mask) ==
  150. mask),
  151. msecs_to_jiffies
  152. (timeout));
  153. if (rc > 0)
  154. return 0;
  155. } else {
  156. stop = jiffies + (HZ * timeout / 1000);
  157. do {
  158. msleep(TPM_TIMEOUT);
  159. status = tpm_tis_status(chip);
  160. if ((status & mask) == mask)
  161. return 0;
  162. } while (time_before(jiffies, stop));
  163. }
  164. return -ETIME;
  165. }
  166. static int recv_data(struct tpm_chip *chip, u8 * buf, size_t count)
  167. {
  168. int size = 0, burstcnt;
  169. while (size < count &&
  170. wait_for_stat(chip,
  171. TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  172. chip->vendor.timeout_c,
  173. &chip->vendor.read_queue)
  174. == 0) {
  175. burstcnt = get_burstcount(chip);
  176. for (; burstcnt > 0 && size < count; burstcnt--)
  177. buf[size++] = ioread8(chip->vendor.iobase +
  178. TPM_DATA_FIFO(chip->vendor.
  179. locality));
  180. }
  181. return size;
  182. }
  183. static int tpm_tis_recv(struct tpm_chip *chip, u8 * buf, size_t count)
  184. {
  185. int size = 0;
  186. int expected, status;
  187. if (count < TPM_HEADER_SIZE) {
  188. size = -EIO;
  189. goto out;
  190. }
  191. /* read first 10 bytes, including tag, paramsize, and result */
  192. if ((size =
  193. recv_data(chip, buf, TPM_HEADER_SIZE)) < TPM_HEADER_SIZE) {
  194. dev_err(chip->dev, "Unable to read header\n");
  195. goto out;
  196. }
  197. expected = be32_to_cpu(*(__be32 *) (buf + 2));
  198. if (expected > count) {
  199. size = -EIO;
  200. goto out;
  201. }
  202. if ((size +=
  203. recv_data(chip, &buf[TPM_HEADER_SIZE],
  204. expected - TPM_HEADER_SIZE)) < expected) {
  205. dev_err(chip->dev, "Unable to read remainder of result\n");
  206. size = -ETIME;
  207. goto out;
  208. }
  209. wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
  210. &chip->vendor.int_queue);
  211. status = tpm_tis_status(chip);
  212. if (status & TPM_STS_DATA_AVAIL) { /* retry? */
  213. dev_err(chip->dev, "Error left over data\n");
  214. size = -EIO;
  215. goto out;
  216. }
  217. out:
  218. tpm_tis_ready(chip);
  219. release_locality(chip, chip->vendor.locality, 0);
  220. return size;
  221. }
  222. /*
  223. * If interrupts are used (signaled by an irq set in the vendor structure)
  224. * tpm.c can skip polling for the data to be available as the interrupt is
  225. * waited for here
  226. */
  227. static int tpm_tis_send(struct tpm_chip *chip, u8 * buf, size_t len)
  228. {
  229. int rc, status, burstcnt;
  230. size_t count = 0;
  231. u32 ordinal;
  232. if (request_locality(chip, 0) < 0)
  233. return -EBUSY;
  234. status = tpm_tis_status(chip);
  235. if ((status & TPM_STS_COMMAND_READY) == 0) {
  236. tpm_tis_ready(chip);
  237. if (wait_for_stat
  238. (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b,
  239. &chip->vendor.int_queue) < 0) {
  240. rc = -ETIME;
  241. goto out_err;
  242. }
  243. }
  244. while (count < len - 1) {
  245. burstcnt = get_burstcount(chip);
  246. for (; burstcnt > 0 && count < len - 1; burstcnt--) {
  247. iowrite8(buf[count], chip->vendor.iobase +
  248. TPM_DATA_FIFO(chip->vendor.locality));
  249. count++;
  250. }
  251. wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
  252. &chip->vendor.int_queue);
  253. status = tpm_tis_status(chip);
  254. if ((status & TPM_STS_DATA_EXPECT) == 0) {
  255. rc = -EIO;
  256. goto out_err;
  257. }
  258. }
  259. /* write last byte */
  260. iowrite8(buf[count],
  261. chip->vendor.iobase +
  262. TPM_DATA_FIFO(chip->vendor.locality));
  263. wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
  264. &chip->vendor.int_queue);
  265. status = tpm_tis_status(chip);
  266. if ((status & TPM_STS_DATA_EXPECT) != 0) {
  267. rc = -EIO;
  268. goto out_err;
  269. }
  270. /* go and do it */
  271. iowrite8(TPM_STS_GO,
  272. chip->vendor.iobase + TPM_STS(chip->vendor.locality));
  273. if (chip->vendor.irq) {
  274. ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
  275. if (wait_for_stat
  276. (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  277. tpm_calc_ordinal_duration(chip, ordinal),
  278. &chip->vendor.read_queue) < 0) {
  279. rc = -ETIME;
  280. goto out_err;
  281. }
  282. }
  283. return len;
  284. out_err:
  285. tpm_tis_ready(chip);
  286. release_locality(chip, chip->vendor.locality, 0);
  287. return rc;
  288. }
  289. static struct file_operations tis_ops = {
  290. .owner = THIS_MODULE,
  291. .llseek = no_llseek,
  292. .open = tpm_open,
  293. .read = tpm_read,
  294. .write = tpm_write,
  295. .release = tpm_release,
  296. };
  297. static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
  298. static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
  299. static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
  300. static DEVICE_ATTR(active, S_IRUGO, tpm_show_active, NULL);
  301. static DEVICE_ATTR(owned, S_IRUGO, tpm_show_owned, NULL);
  302. static DEVICE_ATTR(temp_deactivated, S_IRUGO, tpm_show_temp_deactivated,
  303. NULL);
  304. static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps_1_2, NULL);
  305. static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel);
  306. static struct attribute *tis_attrs[] = {
  307. &dev_attr_pubek.attr,
  308. &dev_attr_pcrs.attr,
  309. &dev_attr_enabled.attr,
  310. &dev_attr_active.attr,
  311. &dev_attr_owned.attr,
  312. &dev_attr_temp_deactivated.attr,
  313. &dev_attr_caps.attr,
  314. &dev_attr_cancel.attr, NULL,
  315. };
  316. static struct attribute_group tis_attr_grp = {
  317. .attrs = tis_attrs
  318. };
  319. static struct tpm_vendor_specific tpm_tis = {
  320. .status = tpm_tis_status,
  321. .recv = tpm_tis_recv,
  322. .send = tpm_tis_send,
  323. .cancel = tpm_tis_ready,
  324. .req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  325. .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
  326. .req_canceled = TPM_STS_COMMAND_READY,
  327. .attr_group = &tis_attr_grp,
  328. .miscdev = {
  329. .fops = &tis_ops,},
  330. };
  331. static irqreturn_t tis_int_probe(int irq, void *dev_id, struct pt_regs
  332. *regs)
  333. {
  334. struct tpm_chip *chip = (struct tpm_chip *) dev_id;
  335. u32 interrupt;
  336. interrupt = ioread32(chip->vendor.iobase +
  337. TPM_INT_STATUS(chip->vendor.locality));
  338. if (interrupt == 0)
  339. return IRQ_NONE;
  340. chip->vendor.irq = irq;
  341. /* Clear interrupts handled with TPM_EOI */
  342. iowrite32(interrupt,
  343. chip->vendor.iobase +
  344. TPM_INT_STATUS(chip->vendor.locality));
  345. return IRQ_HANDLED;
  346. }
  347. static irqreturn_t tis_int_handler(int irq, void *dev_id, struct pt_regs
  348. *regs)
  349. {
  350. struct tpm_chip *chip = (struct tpm_chip *) dev_id;
  351. u32 interrupt;
  352. int i;
  353. interrupt = ioread32(chip->vendor.iobase +
  354. TPM_INT_STATUS(chip->vendor.locality));
  355. if (interrupt == 0)
  356. return IRQ_NONE;
  357. if (interrupt & TPM_INTF_DATA_AVAIL_INT)
  358. wake_up_interruptible(&chip->vendor.read_queue);
  359. if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
  360. for (i = 0; i < 5; i++)
  361. if (check_locality(chip, i) >= 0)
  362. break;
  363. if (interrupt &
  364. (TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
  365. TPM_INTF_CMD_READY_INT))
  366. wake_up_interruptible(&chip->vendor.int_queue);
  367. /* Clear interrupts handled with TPM_EOI */
  368. iowrite32(interrupt,
  369. chip->vendor.iobase +
  370. TPM_INT_STATUS(chip->vendor.locality));
  371. return IRQ_HANDLED;
  372. }
  373. static int __devinit tpm_tis_pnp_init(struct pnp_dev
  374. *pnp_dev, const struct
  375. pnp_device_id
  376. *pnp_id)
  377. {
  378. u32 vendor, intfcaps, intmask;
  379. int rc, i;
  380. unsigned long start, len;
  381. struct tpm_chip *chip;
  382. start = pnp_mem_start(pnp_dev, 0);
  383. len = pnp_mem_len(pnp_dev, 0);
  384. if (!(chip = tpm_register_hardware(&pnp_dev->dev, &tpm_tis)))
  385. return -ENODEV;
  386. chip->vendor.iobase = ioremap(start, len);
  387. if (!chip->vendor.iobase) {
  388. rc = -EIO;
  389. goto out_err;
  390. }
  391. vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
  392. if ((vendor & 0xFFFF) == 0xFFFF) {
  393. rc = -ENODEV;
  394. goto out_err;
  395. }
  396. /* Default timeouts */
  397. chip->vendor.timeout_a = 750; /* ms */
  398. chip->vendor.timeout_b = 2000; /* 2 sec */
  399. chip->vendor.timeout_c = 750; /* ms */
  400. chip->vendor.timeout_d = 750; /* ms */
  401. dev_info(&pnp_dev->dev,
  402. "1.2 TPM (device-id 0x%X, rev-id %d)\n",
  403. vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
  404. /* Figure out the capabilities */
  405. intfcaps =
  406. ioread32(chip->vendor.iobase +
  407. TPM_INTF_CAPS(chip->vendor.locality));
  408. dev_dbg(&pnp_dev->dev, "TPM interface capabilities (0x%x):\n",
  409. intfcaps);
  410. if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
  411. dev_dbg(&pnp_dev->dev, "\tBurst Count Static\n");
  412. if (intfcaps & TPM_INTF_CMD_READY_INT)
  413. dev_dbg(&pnp_dev->dev, "\tCommand Ready Int Support\n");
  414. if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
  415. dev_dbg(&pnp_dev->dev, "\tInterrupt Edge Falling\n");
  416. if (intfcaps & TPM_INTF_INT_EDGE_RISING)
  417. dev_dbg(&pnp_dev->dev, "\tInterrupt Edge Rising\n");
  418. if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
  419. dev_dbg(&pnp_dev->dev, "\tInterrupt Level Low\n");
  420. if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
  421. dev_dbg(&pnp_dev->dev, "\tInterrupt Level High\n");
  422. if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
  423. dev_dbg(&pnp_dev->dev, "\tLocality Change Int Support\n");
  424. if (intfcaps & TPM_INTF_STS_VALID_INT)
  425. dev_dbg(&pnp_dev->dev, "\tSts Valid Int Support\n");
  426. if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
  427. dev_dbg(&pnp_dev->dev, "\tData Avail Int Support\n");
  428. if (request_locality(chip, 0) != 0) {
  429. rc = -ENODEV;
  430. goto out_err;
  431. }
  432. /* INTERRUPT Setup */
  433. init_waitqueue_head(&chip->vendor.read_queue);
  434. init_waitqueue_head(&chip->vendor.int_queue);
  435. intmask =
  436. ioread32(chip->vendor.iobase +
  437. TPM_INT_ENABLE(chip->vendor.locality));
  438. intmask |= TPM_INTF_CMD_READY_INT
  439. | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
  440. | TPM_INTF_STS_VALID_INT;
  441. iowrite32(intmask,
  442. chip->vendor.iobase +
  443. TPM_INT_ENABLE(chip->vendor.locality));
  444. chip->vendor.irq =
  445. ioread8(chip->vendor.iobase +
  446. TPM_INT_VECTOR(chip->vendor.locality));
  447. for (i = 3; i < 16 && chip->vendor.irq == 0; i++) {
  448. iowrite8(i,
  449. chip->vendor.iobase +
  450. TPM_INT_VECTOR(chip->vendor.locality));
  451. if (request_irq
  452. (i, tis_int_probe, SA_SHIRQ,
  453. chip->vendor.miscdev.name, chip) != 0) {
  454. dev_info(chip->dev,
  455. "Unable to request irq: %d for probe\n",
  456. i);
  457. continue;
  458. }
  459. /* Clear all existing */
  460. iowrite32(ioread32
  461. (chip->vendor.iobase +
  462. TPM_INT_STATUS(chip->vendor.locality)),
  463. chip->vendor.iobase +
  464. TPM_INT_STATUS(chip->vendor.locality));
  465. /* Turn on */
  466. iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
  467. chip->vendor.iobase +
  468. TPM_INT_ENABLE(chip->vendor.locality));
  469. /* Generate Interrupts */
  470. tpm_gen_interrupt(chip);
  471. /* Turn off */
  472. iowrite32(intmask,
  473. chip->vendor.iobase +
  474. TPM_INT_ENABLE(chip->vendor.locality));
  475. free_irq(i, chip);
  476. }
  477. if (chip->vendor.irq) {
  478. iowrite8(chip->vendor.irq,
  479. chip->vendor.iobase +
  480. TPM_INT_VECTOR(chip->vendor.locality));
  481. if (request_irq
  482. (chip->vendor.irq, tis_int_handler, SA_SHIRQ,
  483. chip->vendor.miscdev.name, chip) != 0) {
  484. dev_info(chip->dev,
  485. "Unable to request irq: %d for use\n", i);
  486. chip->vendor.irq = 0;
  487. } else {
  488. /* Clear all existing */
  489. iowrite32(ioread32
  490. (chip->vendor.iobase +
  491. TPM_INT_STATUS(chip->vendor.locality)),
  492. chip->vendor.iobase +
  493. TPM_INT_STATUS(chip->vendor.locality));
  494. /* Turn on */
  495. iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
  496. chip->vendor.iobase +
  497. TPM_INT_ENABLE(chip->vendor.locality));
  498. }
  499. }
  500. INIT_LIST_HEAD(&chip->vendor.list);
  501. spin_lock(&tis_lock);
  502. list_add(&chip->vendor.list, &tis_chips);
  503. spin_unlock(&tis_lock);
  504. tpm_get_timeouts(chip);
  505. tpm_continue_selftest(chip);
  506. return 0;
  507. out_err:
  508. if (chip->vendor.iobase)
  509. iounmap(chip->vendor.iobase);
  510. tpm_remove_hardware(chip->dev);
  511. return rc;
  512. }
  513. static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg)
  514. {
  515. return tpm_pm_suspend(&dev->dev, msg);
  516. }
  517. static int tpm_tis_pnp_resume(struct pnp_dev *dev)
  518. {
  519. return tpm_pm_resume(&dev->dev);
  520. }
  521. static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
  522. {"PNP0C31", 0}, /* TPM */
  523. {"", 0}
  524. };
  525. static struct pnp_driver tis_pnp_driver = {
  526. .name = "tpm_tis",
  527. .id_table = tpm_pnp_tbl,
  528. .probe = tpm_tis_pnp_init,
  529. .suspend = tpm_tis_pnp_suspend,
  530. .resume = tpm_tis_pnp_resume,
  531. };
  532. static int __init init_tis(void)
  533. {
  534. return pnp_register_driver(&tis_pnp_driver);
  535. }
  536. static void __exit cleanup_tis(void)
  537. {
  538. struct tpm_vendor_specific *i, *j;
  539. struct tpm_chip *chip;
  540. spin_lock(&tis_lock);
  541. list_for_each_entry_safe(i, j, &tis_chips, list) {
  542. chip = to_tpm_chip(i);
  543. iowrite32(~TPM_GLOBAL_INT_ENABLE &
  544. ioread32(chip->vendor.iobase +
  545. TPM_INT_ENABLE(chip->vendor.
  546. locality)),
  547. chip->vendor.iobase +
  548. TPM_INT_ENABLE(chip->vendor.locality));
  549. release_locality(chip, chip->vendor.locality, 1);
  550. if (chip->vendor.irq)
  551. free_irq(chip->vendor.irq, chip);
  552. iounmap(i->iobase);
  553. list_del(&i->list);
  554. tpm_remove_hardware(chip->dev);
  555. }
  556. spin_unlock(&tis_lock);
  557. pnp_unregister_driver(&tis_pnp_driver);
  558. }
  559. module_init(init_tis);
  560. module_exit(cleanup_tis);
  561. MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
  562. MODULE_DESCRIPTION("TPM Driver");
  563. MODULE_VERSION("2.0");
  564. MODULE_LICENSE("GPL");