tpm_crb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * Copyright (C) 2014 Intel Corporation
  3. *
  4. * Authors:
  5. * Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
  6. *
  7. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  8. *
  9. * This device driver implements the TPM interface as defined in
  10. * the TCG CRB 2.0 TPM specification.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; version 2
  15. * of the License.
  16. */
  17. #include <linux/acpi.h>
  18. #include <linux/highmem.h>
  19. #include <linux/rculist.h>
  20. #include <linux/module.h>
  21. #include <linux/pm_runtime.h>
  22. #ifdef CONFIG_ARM64
  23. #include <linux/arm-smccc.h>
  24. #endif
  25. #include "tpm.h"
  26. #define ACPI_SIG_TPM2 "TPM2"
  27. static const u8 CRB_ACPI_START_UUID[] = {
  28. /* 0000 */ 0xAB, 0x6C, 0xBF, 0x6B, 0x63, 0x54, 0x14, 0x47,
  29. /* 0008 */ 0xB7, 0xCD, 0xF0, 0x20, 0x3C, 0x03, 0x68, 0xD4
  30. };
  31. enum crb_defaults {
  32. CRB_ACPI_START_REVISION_ID = 1,
  33. CRB_ACPI_START_INDEX = 1,
  34. };
  35. enum crb_loc_ctrl {
  36. CRB_LOC_CTRL_REQUEST_ACCESS = BIT(0),
  37. CRB_LOC_CTRL_RELINQUISH = BIT(1),
  38. };
  39. enum crb_loc_state {
  40. CRB_LOC_STATE_LOC_ASSIGNED = BIT(1),
  41. CRB_LOC_STATE_TPM_REG_VALID_STS = BIT(7),
  42. };
  43. enum crb_ctrl_req {
  44. CRB_CTRL_REQ_CMD_READY = BIT(0),
  45. CRB_CTRL_REQ_GO_IDLE = BIT(1),
  46. };
  47. enum crb_ctrl_sts {
  48. CRB_CTRL_STS_ERROR = BIT(0),
  49. CRB_CTRL_STS_TPM_IDLE = BIT(1),
  50. };
  51. enum crb_start {
  52. CRB_START_INVOKE = BIT(0),
  53. };
  54. enum crb_cancel {
  55. CRB_CANCEL_INVOKE = BIT(0),
  56. };
  57. struct crb_regs_head {
  58. u32 loc_state;
  59. u32 reserved1;
  60. u32 loc_ctrl;
  61. u32 loc_sts;
  62. u8 reserved2[32];
  63. u64 intf_id;
  64. u64 ctrl_ext;
  65. } __packed;
  66. struct crb_regs_tail {
  67. u32 ctrl_req;
  68. u32 ctrl_sts;
  69. u32 ctrl_cancel;
  70. u32 ctrl_start;
  71. u32 ctrl_int_enable;
  72. u32 ctrl_int_sts;
  73. u32 ctrl_cmd_size;
  74. u32 ctrl_cmd_pa_low;
  75. u32 ctrl_cmd_pa_high;
  76. u32 ctrl_rsp_size;
  77. u64 ctrl_rsp_pa;
  78. } __packed;
  79. enum crb_status {
  80. CRB_DRV_STS_COMPLETE = BIT(0),
  81. };
  82. enum crb_flags {
  83. CRB_FL_ACPI_START = BIT(0),
  84. CRB_FL_CRB_START = BIT(1),
  85. CRB_FL_CRB_SMC_START = BIT(2),
  86. };
  87. struct crb_priv {
  88. unsigned int flags;
  89. void __iomem *iobase;
  90. struct crb_regs_head __iomem *regs_h;
  91. struct crb_regs_tail __iomem *regs_t;
  92. u8 __iomem *cmd;
  93. u8 __iomem *rsp;
  94. u32 cmd_size;
  95. u32 smc_func_id;
  96. };
  97. struct tpm2_crb_smc {
  98. u32 interrupt;
  99. u8 interrupt_flags;
  100. u8 op_flags;
  101. u16 reserved2;
  102. u32 smc_func_id;
  103. };
  104. /**
  105. * crb_go_idle - request tpm crb device to go the idle state
  106. *
  107. * @dev: crb device
  108. * @priv: crb private data
  109. *
  110. * Write CRB_CTRL_REQ_GO_IDLE to TPM_CRB_CTRL_REQ
  111. * The device should respond within TIMEOUT_C by clearing the bit.
  112. * Anyhow, we do not wait here as a consequent CMD_READY request
  113. * will be handled correctly even if idle was not completed.
  114. *
  115. * The function does nothing for devices with ACPI-start method.
  116. *
  117. * Return: 0 always
  118. */
  119. static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
  120. {
  121. if ((priv->flags & CRB_FL_ACPI_START) ||
  122. (priv->flags & CRB_FL_CRB_SMC_START))
  123. return 0;
  124. iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->regs_t->ctrl_req);
  125. /* we don't really care when this settles */
  126. return 0;
  127. }
  128. static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
  129. unsigned long timeout)
  130. {
  131. ktime_t start;
  132. ktime_t stop;
  133. start = ktime_get();
  134. stop = ktime_add(start, ms_to_ktime(timeout));
  135. do {
  136. if ((ioread32(reg) & mask) == value)
  137. return true;
  138. usleep_range(50, 100);
  139. } while (ktime_before(ktime_get(), stop));
  140. return false;
  141. }
  142. /**
  143. * crb_cmd_ready - request tpm crb device to enter ready state
  144. *
  145. * @dev: crb device
  146. * @priv: crb private data
  147. *
  148. * Write CRB_CTRL_REQ_CMD_READY to TPM_CRB_CTRL_REQ
  149. * and poll till the device acknowledge it by clearing the bit.
  150. * The device should respond within TIMEOUT_C.
  151. *
  152. * The function does nothing for devices with ACPI-start method
  153. *
  154. * Return: 0 on success -ETIME on timeout;
  155. */
  156. static int __maybe_unused crb_cmd_ready(struct device *dev,
  157. struct crb_priv *priv)
  158. {
  159. if ((priv->flags & CRB_FL_ACPI_START) ||
  160. (priv->flags & CRB_FL_CRB_SMC_START))
  161. return 0;
  162. iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->regs_t->ctrl_req);
  163. if (!crb_wait_for_reg_32(&priv->regs_t->ctrl_req,
  164. CRB_CTRL_REQ_CMD_READY /* mask */,
  165. 0, /* value */
  166. TPM2_TIMEOUT_C)) {
  167. dev_warn(dev, "cmdReady timed out\n");
  168. return -ETIME;
  169. }
  170. return 0;
  171. }
  172. static int crb_request_locality(struct tpm_chip *chip, int loc)
  173. {
  174. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  175. u32 value = CRB_LOC_STATE_LOC_ASSIGNED |
  176. CRB_LOC_STATE_TPM_REG_VALID_STS;
  177. if (!priv->regs_h)
  178. return 0;
  179. iowrite32(CRB_LOC_CTRL_REQUEST_ACCESS, &priv->regs_h->loc_ctrl);
  180. if (!crb_wait_for_reg_32(&priv->regs_h->loc_state, value, value,
  181. TPM2_TIMEOUT_C)) {
  182. dev_warn(&chip->dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
  183. return -ETIME;
  184. }
  185. return 0;
  186. }
  187. static void crb_relinquish_locality(struct tpm_chip *chip, int loc)
  188. {
  189. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  190. if (!priv->regs_h)
  191. return;
  192. iowrite32(CRB_LOC_CTRL_RELINQUISH, &priv->regs_h->loc_ctrl);
  193. }
  194. static u8 crb_status(struct tpm_chip *chip)
  195. {
  196. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  197. u8 sts = 0;
  198. if ((ioread32(&priv->regs_t->ctrl_start) & CRB_START_INVOKE) !=
  199. CRB_START_INVOKE)
  200. sts |= CRB_DRV_STS_COMPLETE;
  201. return sts;
  202. }
  203. static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
  204. {
  205. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  206. unsigned int expected;
  207. /* sanity check */
  208. if (count < 6)
  209. return -EIO;
  210. if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
  211. return -EIO;
  212. memcpy_fromio(buf, priv->rsp, 6);
  213. expected = be32_to_cpup((__be32 *) &buf[2]);
  214. if (expected > count || expected < 6)
  215. return -EIO;
  216. memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6);
  217. return expected;
  218. }
  219. static int crb_do_acpi_start(struct tpm_chip *chip)
  220. {
  221. union acpi_object *obj;
  222. int rc;
  223. obj = acpi_evaluate_dsm(chip->acpi_dev_handle,
  224. CRB_ACPI_START_UUID,
  225. CRB_ACPI_START_REVISION_ID,
  226. CRB_ACPI_START_INDEX,
  227. NULL);
  228. if (!obj)
  229. return -ENXIO;
  230. rc = obj->integer.value == 0 ? 0 : -ENXIO;
  231. ACPI_FREE(obj);
  232. return rc;
  233. }
  234. #ifdef CONFIG_ARM64
  235. /*
  236. * This is a TPM Command Response Buffer start method that invokes a
  237. * Secure Monitor Call to requrest the firmware to execute or cancel
  238. * a TPM 2.0 command.
  239. */
  240. static int tpm_crb_smc_start(struct device *dev, unsigned long func_id)
  241. {
  242. struct arm_smccc_res res;
  243. arm_smccc_smc(func_id, 0, 0, 0, 0, 0, 0, 0, &res);
  244. if (res.a0 != 0) {
  245. dev_err(dev,
  246. FW_BUG "tpm_crb_smc_start() returns res.a0 = 0x%lx\n",
  247. res.a0);
  248. return -EIO;
  249. }
  250. return 0;
  251. }
  252. #else
  253. static int tpm_crb_smc_start(struct device *dev, unsigned long func_id)
  254. {
  255. dev_err(dev, FW_BUG "tpm_crb: incorrect start method\n");
  256. return -EINVAL;
  257. }
  258. #endif
  259. static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
  260. {
  261. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  262. int rc = 0;
  263. /* Zero the cancel register so that the next command will not get
  264. * canceled.
  265. */
  266. iowrite32(0, &priv->regs_t->ctrl_cancel);
  267. if (len > priv->cmd_size) {
  268. dev_err(&chip->dev, "invalid command count value %zd %d\n",
  269. len, priv->cmd_size);
  270. return -E2BIG;
  271. }
  272. memcpy_toio(priv->cmd, buf, len);
  273. /* Make sure that cmd is populated before issuing start. */
  274. wmb();
  275. if (priv->flags & CRB_FL_CRB_START)
  276. iowrite32(CRB_START_INVOKE, &priv->regs_t->ctrl_start);
  277. if (priv->flags & CRB_FL_ACPI_START)
  278. rc = crb_do_acpi_start(chip);
  279. if (priv->flags & CRB_FL_CRB_SMC_START) {
  280. iowrite32(CRB_START_INVOKE, &priv->regs_t->ctrl_start);
  281. rc = tpm_crb_smc_start(&chip->dev, priv->smc_func_id);
  282. }
  283. return rc;
  284. }
  285. static void crb_cancel(struct tpm_chip *chip)
  286. {
  287. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  288. iowrite32(CRB_CANCEL_INVOKE, &priv->regs_t->ctrl_cancel);
  289. if ((priv->flags & CRB_FL_ACPI_START) && crb_do_acpi_start(chip))
  290. dev_err(&chip->dev, "ACPI Start failed\n");
  291. }
  292. static bool crb_req_canceled(struct tpm_chip *chip, u8 status)
  293. {
  294. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  295. u32 cancel = ioread32(&priv->regs_t->ctrl_cancel);
  296. return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE;
  297. }
  298. static const struct tpm_class_ops tpm_crb = {
  299. .flags = TPM_OPS_AUTO_STARTUP,
  300. .status = crb_status,
  301. .recv = crb_recv,
  302. .send = crb_send,
  303. .cancel = crb_cancel,
  304. .req_canceled = crb_req_canceled,
  305. .request_locality = crb_request_locality,
  306. .relinquish_locality = crb_relinquish_locality,
  307. .req_complete_mask = CRB_DRV_STS_COMPLETE,
  308. .req_complete_val = CRB_DRV_STS_COMPLETE,
  309. };
  310. static int crb_check_resource(struct acpi_resource *ares, void *data)
  311. {
  312. struct resource *io_res = data;
  313. struct resource_win win;
  314. struct resource *res = &(win.res);
  315. if (acpi_dev_resource_memory(ares, res) ||
  316. acpi_dev_resource_address_space(ares, &win)) {
  317. *io_res = *res;
  318. io_res->name = NULL;
  319. }
  320. return 1;
  321. }
  322. static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
  323. struct resource *io_res, u64 start, u32 size)
  324. {
  325. struct resource new_res = {
  326. .start = start,
  327. .end = start + size - 1,
  328. .flags = IORESOURCE_MEM,
  329. };
  330. /* Detect a 64 bit address on a 32 bit system */
  331. if (start != new_res.start)
  332. return (void __iomem *) ERR_PTR(-EINVAL);
  333. if (!resource_contains(io_res, &new_res))
  334. return devm_ioremap_resource(dev, &new_res);
  335. return priv->iobase + (new_res.start - io_res->start);
  336. }
  337. /*
  338. * Work around broken BIOSs that return inconsistent values from the ACPI
  339. * region vs the registers. Trust the ACPI region. Such broken systems
  340. * probably cannot send large TPM commands since the buffer will be truncated.
  341. */
  342. static u64 crb_fixup_cmd_size(struct device *dev, struct resource *io_res,
  343. u64 start, u64 size)
  344. {
  345. if (io_res->start > start || io_res->end < start)
  346. return size;
  347. if (start + size - 1 <= io_res->end)
  348. return size;
  349. dev_err(dev,
  350. FW_BUG "ACPI region does not cover the entire command/response buffer. %pr vs %llx %llx\n",
  351. io_res, start, size);
  352. return io_res->end - start + 1;
  353. }
  354. static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
  355. struct acpi_table_tpm2 *buf)
  356. {
  357. struct list_head resources;
  358. struct resource io_res;
  359. struct device *dev = &device->dev;
  360. u32 pa_high, pa_low;
  361. u64 cmd_pa;
  362. u32 cmd_size;
  363. u64 rsp_pa;
  364. u32 rsp_size;
  365. int ret;
  366. INIT_LIST_HEAD(&resources);
  367. ret = acpi_dev_get_resources(device, &resources, crb_check_resource,
  368. &io_res);
  369. if (ret < 0)
  370. return ret;
  371. acpi_dev_free_resource_list(&resources);
  372. if (resource_type(&io_res) != IORESOURCE_MEM) {
  373. dev_err(dev, FW_BUG "TPM2 ACPI table does not define a memory resource\n");
  374. return -EINVAL;
  375. }
  376. priv->iobase = devm_ioremap_resource(dev, &io_res);
  377. if (IS_ERR(priv->iobase))
  378. return PTR_ERR(priv->iobase);
  379. /* The ACPI IO region starts at the head area and continues to include
  380. * the control area, as one nice sane region except for some older
  381. * stuff that puts the control area outside the ACPI IO region.
  382. */
  383. if (!(priv->flags & CRB_FL_ACPI_START)) {
  384. if (buf->control_address == io_res.start +
  385. sizeof(*priv->regs_h))
  386. priv->regs_h = priv->iobase;
  387. else
  388. dev_warn(dev, FW_BUG "Bad ACPI memory layout");
  389. }
  390. priv->regs_t = crb_map_res(dev, priv, &io_res, buf->control_address,
  391. sizeof(struct crb_regs_tail));
  392. if (IS_ERR(priv->regs_t))
  393. return PTR_ERR(priv->regs_t);
  394. /*
  395. * PTT HW bug w/a: wake up the device to access
  396. * possibly not retained registers.
  397. */
  398. ret = crb_cmd_ready(dev, priv);
  399. if (ret)
  400. return ret;
  401. pa_high = ioread32(&priv->regs_t->ctrl_cmd_pa_high);
  402. pa_low = ioread32(&priv->regs_t->ctrl_cmd_pa_low);
  403. cmd_pa = ((u64)pa_high << 32) | pa_low;
  404. cmd_size = crb_fixup_cmd_size(dev, &io_res, cmd_pa,
  405. ioread32(&priv->regs_t->ctrl_cmd_size));
  406. dev_dbg(dev, "cmd_hi = %X cmd_low = %X cmd_size %X\n",
  407. pa_high, pa_low, cmd_size);
  408. priv->cmd = crb_map_res(dev, priv, &io_res, cmd_pa, cmd_size);
  409. if (IS_ERR(priv->cmd)) {
  410. ret = PTR_ERR(priv->cmd);
  411. goto out;
  412. }
  413. memcpy_fromio(&rsp_pa, &priv->regs_t->ctrl_rsp_pa, 8);
  414. rsp_pa = le64_to_cpu(rsp_pa);
  415. rsp_size = crb_fixup_cmd_size(dev, &io_res, rsp_pa,
  416. ioread32(&priv->regs_t->ctrl_rsp_size));
  417. if (cmd_pa != rsp_pa) {
  418. priv->rsp = crb_map_res(dev, priv, &io_res, rsp_pa, rsp_size);
  419. ret = PTR_ERR_OR_ZERO(priv->rsp);
  420. goto out;
  421. }
  422. /* According to the PTP specification, overlapping command and response
  423. * buffer sizes must be identical.
  424. */
  425. if (cmd_size != rsp_size) {
  426. dev_err(dev, FW_BUG "overlapping command and response buffer sizes are not identical");
  427. ret = -EINVAL;
  428. goto out;
  429. }
  430. priv->cmd_size = cmd_size;
  431. priv->rsp = priv->cmd;
  432. out:
  433. crb_go_idle(dev, priv);
  434. return ret;
  435. }
  436. static int crb_acpi_add(struct acpi_device *device)
  437. {
  438. struct acpi_table_tpm2 *buf;
  439. struct crb_priv *priv;
  440. struct tpm_chip *chip;
  441. struct device *dev = &device->dev;
  442. struct tpm2_crb_smc *crb_smc;
  443. acpi_status status;
  444. u32 sm;
  445. int rc;
  446. status = acpi_get_table(ACPI_SIG_TPM2, 1,
  447. (struct acpi_table_header **) &buf);
  448. if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) {
  449. dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
  450. return -EINVAL;
  451. }
  452. /* Should the FIFO driver handle this? */
  453. sm = buf->start_method;
  454. if (sm == ACPI_TPM2_MEMORY_MAPPED)
  455. return -ENODEV;
  456. priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL);
  457. if (!priv)
  458. return -ENOMEM;
  459. /* The reason for the extra quirk is that the PTT in 4th Gen Core CPUs
  460. * report only ACPI start but in practice seems to require both
  461. * ACPI start and CRB start.
  462. */
  463. if (sm == ACPI_TPM2_COMMAND_BUFFER || sm == ACPI_TPM2_MEMORY_MAPPED ||
  464. !strcmp(acpi_device_hid(device), "MSFT0101"))
  465. priv->flags |= CRB_FL_CRB_START;
  466. if (sm == ACPI_TPM2_START_METHOD ||
  467. sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD)
  468. priv->flags |= CRB_FL_ACPI_START;
  469. if (sm == ACPI_TPM2_COMMAND_BUFFER_WITH_SMC) {
  470. if (buf->header.length < (sizeof(*buf) + sizeof(*crb_smc))) {
  471. dev_err(dev,
  472. FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n",
  473. buf->header.length,
  474. ACPI_TPM2_COMMAND_BUFFER_WITH_SMC);
  475. return -EINVAL;
  476. }
  477. crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf));
  478. priv->smc_func_id = crb_smc->smc_func_id;
  479. priv->flags |= CRB_FL_CRB_SMC_START;
  480. }
  481. rc = crb_map_io(device, priv, buf);
  482. if (rc)
  483. return rc;
  484. chip = tpmm_chip_alloc(dev, &tpm_crb);
  485. if (IS_ERR(chip))
  486. return PTR_ERR(chip);
  487. dev_set_drvdata(&chip->dev, priv);
  488. chip->acpi_dev_handle = device->handle;
  489. chip->flags = TPM_CHIP_FLAG_TPM2;
  490. rc = crb_cmd_ready(dev, priv);
  491. if (rc)
  492. return rc;
  493. pm_runtime_get_noresume(dev);
  494. pm_runtime_set_active(dev);
  495. pm_runtime_enable(dev);
  496. rc = tpm_chip_register(chip);
  497. if (rc) {
  498. crb_go_idle(dev, priv);
  499. pm_runtime_put_noidle(dev);
  500. pm_runtime_disable(dev);
  501. return rc;
  502. }
  503. pm_runtime_put(dev);
  504. return 0;
  505. }
  506. static int crb_acpi_remove(struct acpi_device *device)
  507. {
  508. struct device *dev = &device->dev;
  509. struct tpm_chip *chip = dev_get_drvdata(dev);
  510. tpm_chip_unregister(chip);
  511. pm_runtime_disable(dev);
  512. return 0;
  513. }
  514. static int __maybe_unused crb_pm_runtime_suspend(struct device *dev)
  515. {
  516. struct tpm_chip *chip = dev_get_drvdata(dev);
  517. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  518. return crb_go_idle(dev, priv);
  519. }
  520. static int __maybe_unused crb_pm_runtime_resume(struct device *dev)
  521. {
  522. struct tpm_chip *chip = dev_get_drvdata(dev);
  523. struct crb_priv *priv = dev_get_drvdata(&chip->dev);
  524. return crb_cmd_ready(dev, priv);
  525. }
  526. static int __maybe_unused crb_pm_suspend(struct device *dev)
  527. {
  528. int ret;
  529. ret = tpm_pm_suspend(dev);
  530. if (ret)
  531. return ret;
  532. return crb_pm_runtime_suspend(dev);
  533. }
  534. static int __maybe_unused crb_pm_resume(struct device *dev)
  535. {
  536. int ret;
  537. ret = crb_pm_runtime_resume(dev);
  538. if (ret)
  539. return ret;
  540. return tpm_pm_resume(dev);
  541. }
  542. static const struct dev_pm_ops crb_pm = {
  543. SET_SYSTEM_SLEEP_PM_OPS(crb_pm_suspend, crb_pm_resume)
  544. SET_RUNTIME_PM_OPS(crb_pm_runtime_suspend, crb_pm_runtime_resume, NULL)
  545. };
  546. static struct acpi_device_id crb_device_ids[] = {
  547. {"MSFT0101", 0},
  548. {"", 0},
  549. };
  550. MODULE_DEVICE_TABLE(acpi, crb_device_ids);
  551. static struct acpi_driver crb_acpi_driver = {
  552. .name = "tpm_crb",
  553. .ids = crb_device_ids,
  554. .ops = {
  555. .add = crb_acpi_add,
  556. .remove = crb_acpi_remove,
  557. },
  558. .drv = {
  559. .pm = &crb_pm,
  560. },
  561. };
  562. module_acpi_driver(crb_acpi_driver);
  563. MODULE_AUTHOR("Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>");
  564. MODULE_DESCRIPTION("TPM2 Driver");
  565. MODULE_VERSION("0.1");
  566. MODULE_LICENSE("GPL");