tpm_tis.c 18 KB

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