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