aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 14:33:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 14:33:45 -0400
commitbb7aeae3d680c2c777f54274b0270ced0599f33d (patch)
tree4801a103c2b157b5019cf38a19dc67d54bf38453 /drivers/char
parent70477371dc350746d10431d74f0f213a8d59924c (diff)
parent88a1b564a20e371e6be41b39b85673e9c1959491 (diff)
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security layer updates from James Morris: "There are a bunch of fixes to the TPM, IMA, and Keys code, with minor fixes scattered across the subsystem. IMA now requires signed policy, and that policy is also now measured and appraised" * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (67 commits) X.509: Make algo identifiers text instead of enum akcipher: Move the RSA DER encoding check to the crypto layer crypto: Add hash param to pkcs1pad sign-file: fix build with CMS support disabled MAINTAINERS: update tpmdd urls MODSIGN: linux/string.h should be #included to get memcpy() certs: Fix misaligned data in extra certificate list X.509: Handle midnight alternative notation in GeneralizedTime X.509: Support leap seconds Handle ISO 8601 leap seconds and encodings of midnight in mktime64() X.509: Fix leap year handling again PKCS#7: fix unitialized boolean 'want' firmware: change kernel read fail to dev_dbg() KEYS: Use the symbol value for list size, updated by scripts/insert-sys-cert KEYS: Reserve an extra certificate symbol for inserting without recompiling modsign: hide openssl output in silent builds tpm_tis: fix build warning with tpm_tis_resume ima: require signed IMA policy ima: measure and appraise the IMA policy itself ima: load policy using path ...
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/tpm/tpm-chip.c19
-rw-r--r--drivers/char/tpm/tpm.h7
-rw-r--r--drivers/char/tpm/tpm2-cmd.c22
-rw-r--r--drivers/char/tpm/tpm_crb.c196
-rw-r--r--drivers/char/tpm/tpm_eventlog.c14
-rw-r--r--drivers/char/tpm/tpm_tis.c253
6 files changed, 297 insertions, 214 deletions
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 45cc39aabeee..274dd0123237 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -88,6 +88,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
88 const struct tpm_class_ops *ops) 88 const struct tpm_class_ops *ops)
89{ 89{
90 struct tpm_chip *chip; 90 struct tpm_chip *chip;
91 int rc;
91 92
92 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 93 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
93 if (chip == NULL) 94 if (chip == NULL)
@@ -136,11 +137,17 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
136 chip->cdev.owner = chip->pdev->driver->owner; 137 chip->cdev.owner = chip->pdev->driver->owner;
137 chip->cdev.kobj.parent = &chip->dev.kobj; 138 chip->cdev.kobj.parent = &chip->dev.kobj;
138 139
140 rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
141 if (rc) {
142 put_device(&chip->dev);
143 return ERR_PTR(rc);
144 }
145
139 return chip; 146 return chip;
140} 147}
141EXPORT_SYMBOL_GPL(tpmm_chip_alloc); 148EXPORT_SYMBOL_GPL(tpmm_chip_alloc);
142 149
143static int tpm_dev_add_device(struct tpm_chip *chip) 150static int tpm_add_char_device(struct tpm_chip *chip)
144{ 151{
145 int rc; 152 int rc;
146 153
@@ -151,7 +158,6 @@ static int tpm_dev_add_device(struct tpm_chip *chip)
151 chip->devname, MAJOR(chip->dev.devt), 158 chip->devname, MAJOR(chip->dev.devt),
152 MINOR(chip->dev.devt), rc); 159 MINOR(chip->dev.devt), rc);
153 160
154 device_unregister(&chip->dev);
155 return rc; 161 return rc;
156 } 162 }
157 163
@@ -162,16 +168,17 @@ static int tpm_dev_add_device(struct tpm_chip *chip)
162 chip->devname, MAJOR(chip->dev.devt), 168 chip->devname, MAJOR(chip->dev.devt),
163 MINOR(chip->dev.devt), rc); 169 MINOR(chip->dev.devt), rc);
164 170
171 cdev_del(&chip->cdev);
165 return rc; 172 return rc;
166 } 173 }
167 174
168 return rc; 175 return rc;
169} 176}
170 177
171static void tpm_dev_del_device(struct tpm_chip *chip) 178static void tpm_del_char_device(struct tpm_chip *chip)
172{ 179{
173 cdev_del(&chip->cdev); 180 cdev_del(&chip->cdev);
174 device_unregister(&chip->dev); 181 device_del(&chip->dev);
175} 182}
176 183
177static int tpm1_chip_register(struct tpm_chip *chip) 184static int tpm1_chip_register(struct tpm_chip *chip)
@@ -222,7 +229,7 @@ int tpm_chip_register(struct tpm_chip *chip)
222 229
223 tpm_add_ppi(chip); 230 tpm_add_ppi(chip);
224 231
225 rc = tpm_dev_add_device(chip); 232 rc = tpm_add_char_device(chip);
226 if (rc) 233 if (rc)
227 goto out_err; 234 goto out_err;
228 235
@@ -274,6 +281,6 @@ void tpm_chip_unregister(struct tpm_chip *chip)
274 sysfs_remove_link(&chip->pdev->kobj, "ppi"); 281 sysfs_remove_link(&chip->pdev->kobj, "ppi");
275 282
276 tpm1_chip_unregister(chip); 283 tpm1_chip_unregister(chip);
277 tpm_dev_del_device(chip); 284 tpm_del_char_device(chip);
278} 285}
279EXPORT_SYMBOL_GPL(tpm_chip_unregister); 286EXPORT_SYMBOL_GPL(tpm_chip_unregister);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 542a80cbfd9c..28b477e8da6a 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -128,13 +128,6 @@ enum tpm2_startup_types {
128 TPM2_SU_STATE = 0x0001, 128 TPM2_SU_STATE = 0x0001,
129}; 129};
130 130
131enum tpm2_start_method {
132 TPM2_START_ACPI = 2,
133 TPM2_START_FIFO = 6,
134 TPM2_START_CRB = 7,
135 TPM2_START_CRB_WITH_ACPI = 8,
136};
137
138struct tpm_chip; 131struct tpm_chip;
139 132
140struct tpm_vendor_specific { 133struct tpm_vendor_specific {
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 45a634016f95..b28e4da3d2cf 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -20,7 +20,11 @@
20#include <keys/trusted-type.h> 20#include <keys/trusted-type.h>
21 21
22enum tpm2_object_attributes { 22enum tpm2_object_attributes {
23 TPM2_ATTR_USER_WITH_AUTH = BIT(6), 23 TPM2_OA_USER_WITH_AUTH = BIT(6),
24};
25
26enum tpm2_session_attributes {
27 TPM2_SA_CONTINUE_SESSION = BIT(0),
24}; 28};
25 29
26struct tpm2_startup_in { 30struct tpm2_startup_in {
@@ -478,22 +482,18 @@ int tpm2_seal_trusted(struct tpm_chip *chip,
478 tpm_buf_append_u8(&buf, payload->migratable); 482 tpm_buf_append_u8(&buf, payload->migratable);
479 483
480 /* public */ 484 /* public */
481 if (options->policydigest) 485 tpm_buf_append_u16(&buf, 14 + options->policydigest_len);
482 tpm_buf_append_u16(&buf, 14 + options->digest_len);
483 else
484 tpm_buf_append_u16(&buf, 14);
485
486 tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH); 486 tpm_buf_append_u16(&buf, TPM2_ALG_KEYEDHASH);
487 tpm_buf_append_u16(&buf, hash); 487 tpm_buf_append_u16(&buf, hash);
488 488
489 /* policy */ 489 /* policy */
490 if (options->policydigest) { 490 if (options->policydigest_len) {
491 tpm_buf_append_u32(&buf, 0); 491 tpm_buf_append_u32(&buf, 0);
492 tpm_buf_append_u16(&buf, options->digest_len); 492 tpm_buf_append_u16(&buf, options->policydigest_len);
493 tpm_buf_append(&buf, options->policydigest, 493 tpm_buf_append(&buf, options->policydigest,
494 options->digest_len); 494 options->policydigest_len);
495 } else { 495 } else {
496 tpm_buf_append_u32(&buf, TPM2_ATTR_USER_WITH_AUTH); 496 tpm_buf_append_u32(&buf, TPM2_OA_USER_WITH_AUTH);
497 tpm_buf_append_u16(&buf, 0); 497 tpm_buf_append_u16(&buf, 0);
498 } 498 }
499 499
@@ -631,7 +631,7 @@ static int tpm2_unseal(struct tpm_chip *chip,
631 options->policyhandle ? 631 options->policyhandle ?
632 options->policyhandle : TPM2_RS_PW, 632 options->policyhandle : TPM2_RS_PW,
633 NULL /* nonce */, 0, 633 NULL /* nonce */, 0,
634 0 /* session_attributes */, 634 TPM2_SA_CONTINUE_SESSION,
635 options->blobauth /* hmac */, 635 options->blobauth /* hmac */,
636 TPM_DIGEST_SIZE); 636 TPM_DIGEST_SIZE);
637 637
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 8342cf51ffdc..a12b31940344 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -34,14 +34,6 @@ enum crb_defaults {
34 CRB_ACPI_START_INDEX = 1, 34 CRB_ACPI_START_INDEX = 1,
35}; 35};
36 36
37struct acpi_tpm2 {
38 struct acpi_table_header hdr;
39 u16 platform_class;
40 u16 reserved;
41 u64 control_area_pa;
42 u32 start_method;
43} __packed;
44
45enum crb_ca_request { 37enum crb_ca_request {
46 CRB_CA_REQ_GO_IDLE = BIT(0), 38 CRB_CA_REQ_GO_IDLE = BIT(0),
47 CRB_CA_REQ_CMD_READY = BIT(1), 39 CRB_CA_REQ_CMD_READY = BIT(1),
@@ -85,6 +77,8 @@ enum crb_flags {
85 77
86struct crb_priv { 78struct crb_priv {
87 unsigned int flags; 79 unsigned int flags;
80 struct resource res;
81 void __iomem *iobase;
88 struct crb_control_area __iomem *cca; 82 struct crb_control_area __iomem *cca;
89 u8 __iomem *cmd; 83 u8 __iomem *cmd;
90 u8 __iomem *rsp; 84 u8 __iomem *rsp;
@@ -97,7 +91,7 @@ static u8 crb_status(struct tpm_chip *chip)
97 struct crb_priv *priv = chip->vendor.priv; 91 struct crb_priv *priv = chip->vendor.priv;
98 u8 sts = 0; 92 u8 sts = 0;
99 93
100 if ((le32_to_cpu(ioread32(&priv->cca->start)) & CRB_START_INVOKE) != 94 if ((ioread32(&priv->cca->start) & CRB_START_INVOKE) !=
101 CRB_START_INVOKE) 95 CRB_START_INVOKE)
102 sts |= CRB_STS_COMPLETE; 96 sts |= CRB_STS_COMPLETE;
103 97
@@ -113,7 +107,7 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
113 if (count < 6) 107 if (count < 6)
114 return -EIO; 108 return -EIO;
115 109
116 if (le32_to_cpu(ioread32(&priv->cca->sts)) & CRB_CA_STS_ERROR) 110 if (ioread32(&priv->cca->sts) & CRB_CA_STS_ERROR)
117 return -EIO; 111 return -EIO;
118 112
119 memcpy_fromio(buf, priv->rsp, 6); 113 memcpy_fromio(buf, priv->rsp, 6);
@@ -149,11 +143,11 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
149 struct crb_priv *priv = chip->vendor.priv; 143 struct crb_priv *priv = chip->vendor.priv;
150 int rc = 0; 144 int rc = 0;
151 145
152 if (len > le32_to_cpu(ioread32(&priv->cca->cmd_size))) { 146 if (len > ioread32(&priv->cca->cmd_size)) {
153 dev_err(&chip->dev, 147 dev_err(&chip->dev,
154 "invalid command count value %x %zx\n", 148 "invalid command count value %x %zx\n",
155 (unsigned int) len, 149 (unsigned int) len,
156 (size_t) le32_to_cpu(ioread32(&priv->cca->cmd_size))); 150 (size_t) ioread32(&priv->cca->cmd_size));
157 return -E2BIG; 151 return -E2BIG;
158 } 152 }
159 153
@@ -189,7 +183,7 @@ static void crb_cancel(struct tpm_chip *chip)
189static bool crb_req_canceled(struct tpm_chip *chip, u8 status) 183static bool crb_req_canceled(struct tpm_chip *chip, u8 status)
190{ 184{
191 struct crb_priv *priv = chip->vendor.priv; 185 struct crb_priv *priv = chip->vendor.priv;
192 u32 cancel = le32_to_cpu(ioread32(&priv->cca->cancel)); 186 u32 cancel = ioread32(&priv->cca->cancel);
193 187
194 return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE; 188 return (cancel & CRB_CANCEL_INVOKE) == CRB_CANCEL_INVOKE;
195} 189}
@@ -204,97 +198,145 @@ static const struct tpm_class_ops tpm_crb = {
204 .req_complete_val = CRB_STS_COMPLETE, 198 .req_complete_val = CRB_STS_COMPLETE,
205}; 199};
206 200
207static int crb_acpi_add(struct acpi_device *device) 201static int crb_init(struct acpi_device *device, struct crb_priv *priv)
208{ 202{
209 struct tpm_chip *chip; 203 struct tpm_chip *chip;
210 struct acpi_tpm2 *buf; 204 int rc;
205
206 chip = tpmm_chip_alloc(&device->dev, &tpm_crb);
207 if (IS_ERR(chip))
208 return PTR_ERR(chip);
209
210 chip->vendor.priv = priv;
211 chip->acpi_dev_handle = device->handle;
212 chip->flags = TPM_CHIP_FLAG_TPM2;
213
214 rc = tpm_get_timeouts(chip);
215 if (rc)
216 return rc;
217
218 rc = tpm2_do_selftest(chip);
219 if (rc)
220 return rc;
221
222 return tpm_chip_register(chip);
223}
224
225static int crb_check_resource(struct acpi_resource *ares, void *data)
226{
227 struct crb_priv *priv = data;
228 struct resource res;
229
230 if (acpi_dev_resource_memory(ares, &res)) {
231 priv->res = res;
232 priv->res.name = NULL;
233 }
234
235 return 1;
236}
237
238static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv,
239 u64 start, u32 size)
240{
241 struct resource new_res = {
242 .start = start,
243 .end = start + size - 1,
244 .flags = IORESOURCE_MEM,
245 };
246
247 /* Detect a 64 bit address on a 32 bit system */
248 if (start != new_res.start)
249 return ERR_PTR(-EINVAL);
250
251 if (!resource_contains(&priv->res, &new_res))
252 return devm_ioremap_resource(dev, &new_res);
253
254 return priv->iobase + (new_res.start - priv->res.start);
255}
256
257static int crb_map_io(struct acpi_device *device, struct crb_priv *priv,
258 struct acpi_table_tpm2 *buf)
259{
260 struct list_head resources;
261 struct device *dev = &device->dev;
262 u64 pa;
263 int ret;
264
265 INIT_LIST_HEAD(&resources);
266 ret = acpi_dev_get_resources(device, &resources, crb_check_resource,
267 priv);
268 if (ret < 0)
269 return ret;
270 acpi_dev_free_resource_list(&resources);
271
272 if (resource_type(&priv->res) != IORESOURCE_MEM) {
273 dev_err(dev,
274 FW_BUG "TPM2 ACPI table does not define a memory resource\n");
275 return -EINVAL;
276 }
277
278 priv->iobase = devm_ioremap_resource(dev, &priv->res);
279 if (IS_ERR(priv->iobase))
280 return PTR_ERR(priv->iobase);
281
282 priv->cca = crb_map_res(dev, priv, buf->control_address, 0x1000);
283 if (IS_ERR(priv->cca))
284 return PTR_ERR(priv->cca);
285
286 pa = ((u64) ioread32(&priv->cca->cmd_pa_high) << 32) |
287 (u64) ioread32(&priv->cca->cmd_pa_low);
288 priv->cmd = crb_map_res(dev, priv, pa, ioread32(&priv->cca->cmd_size));
289 if (IS_ERR(priv->cmd))
290 return PTR_ERR(priv->cmd);
291
292 memcpy_fromio(&pa, &priv->cca->rsp_pa, 8);
293 pa = le64_to_cpu(pa);
294 priv->rsp = crb_map_res(dev, priv, pa, ioread32(&priv->cca->rsp_size));
295 return PTR_ERR_OR_ZERO(priv->rsp);
296}
297
298static int crb_acpi_add(struct acpi_device *device)
299{
300 struct acpi_table_tpm2 *buf;
211 struct crb_priv *priv; 301 struct crb_priv *priv;
212 struct device *dev = &device->dev; 302 struct device *dev = &device->dev;
213 acpi_status status; 303 acpi_status status;
214 u32 sm; 304 u32 sm;
215 u64 pa;
216 int rc; 305 int rc;
217 306
218 status = acpi_get_table(ACPI_SIG_TPM2, 1, 307 status = acpi_get_table(ACPI_SIG_TPM2, 1,
219 (struct acpi_table_header **) &buf); 308 (struct acpi_table_header **) &buf);
220 if (ACPI_FAILURE(status)) { 309 if (ACPI_FAILURE(status) || buf->header.length < sizeof(*buf)) {
221 dev_err(dev, "failed to get TPM2 ACPI table\n"); 310 dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
222 return -ENODEV; 311 return -EINVAL;
223 } 312 }
224 313
225 /* Should the FIFO driver handle this? */ 314 /* Should the FIFO driver handle this? */
226 if (buf->start_method == TPM2_START_FIFO) 315 sm = buf->start_method;
316 if (sm == ACPI_TPM2_MEMORY_MAPPED)
227 return -ENODEV; 317 return -ENODEV;
228 318
229 chip = tpmm_chip_alloc(dev, &tpm_crb); 319 priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL);
230 if (IS_ERR(chip)) 320 if (!priv)
231 return PTR_ERR(chip);
232
233 chip->flags = TPM_CHIP_FLAG_TPM2;
234
235 if (buf->hdr.length < sizeof(struct acpi_tpm2)) {
236 dev_err(dev, "TPM2 ACPI table has wrong size");
237 return -EINVAL;
238 }
239
240 priv = (struct crb_priv *) devm_kzalloc(dev, sizeof(struct crb_priv),
241 GFP_KERNEL);
242 if (!priv) {
243 dev_err(dev, "failed to devm_kzalloc for private data\n");
244 return -ENOMEM; 321 return -ENOMEM;
245 }
246
247 sm = le32_to_cpu(buf->start_method);
248 322
249 /* The reason for the extra quirk is that the PTT in 4th Gen Core CPUs 323 /* The reason for the extra quirk is that the PTT in 4th Gen Core CPUs
250 * report only ACPI start but in practice seems to require both 324 * report only ACPI start but in practice seems to require both
251 * ACPI start and CRB start. 325 * ACPI start and CRB start.
252 */ 326 */
253 if (sm == TPM2_START_CRB || sm == TPM2_START_FIFO || 327 if (sm == ACPI_TPM2_COMMAND_BUFFER || sm == ACPI_TPM2_MEMORY_MAPPED ||
254 !strcmp(acpi_device_hid(device), "MSFT0101")) 328 !strcmp(acpi_device_hid(device), "MSFT0101"))
255 priv->flags |= CRB_FL_CRB_START; 329 priv->flags |= CRB_FL_CRB_START;
256 330
257 if (sm == TPM2_START_ACPI || sm == TPM2_START_CRB_WITH_ACPI) 331 if (sm == ACPI_TPM2_START_METHOD ||
332 sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD)
258 priv->flags |= CRB_FL_ACPI_START; 333 priv->flags |= CRB_FL_ACPI_START;
259 334
260 priv->cca = (struct crb_control_area __iomem *) 335 rc = crb_map_io(device, priv, buf);
261 devm_ioremap_nocache(dev, buf->control_area_pa, 0x1000);
262 if (!priv->cca) {
263 dev_err(dev, "ioremap of the control area failed\n");
264 return -ENOMEM;
265 }
266
267 pa = ((u64) le32_to_cpu(ioread32(&priv->cca->cmd_pa_high)) << 32) |
268 (u64) le32_to_cpu(ioread32(&priv->cca->cmd_pa_low));
269 priv->cmd = devm_ioremap_nocache(dev, pa,
270 ioread32(&priv->cca->cmd_size));
271 if (!priv->cmd) {
272 dev_err(dev, "ioremap of the command buffer failed\n");
273 return -ENOMEM;
274 }
275
276 memcpy_fromio(&pa, &priv->cca->rsp_pa, 8);
277 pa = le64_to_cpu(pa);
278 priv->rsp = devm_ioremap_nocache(dev, pa,
279 ioread32(&priv->cca->rsp_size));
280 if (!priv->rsp) {
281 dev_err(dev, "ioremap of the response buffer failed\n");
282 return -ENOMEM;
283 }
284
285 chip->vendor.priv = priv;
286
287 rc = tpm_get_timeouts(chip);
288 if (rc) 336 if (rc)
289 return rc; 337 return rc;
290 338
291 chip->acpi_dev_handle = device->handle; 339 return crb_init(device, priv);
292
293 rc = tpm2_do_selftest(chip);
294 if (rc)
295 return rc;
296
297 return tpm_chip_register(chip);
298} 340}
299 341
300static int crb_acpi_remove(struct acpi_device *device) 342static int crb_acpi_remove(struct acpi_device *device)
@@ -302,11 +344,11 @@ static int crb_acpi_remove(struct acpi_device *device)
302 struct device *dev = &device->dev; 344 struct device *dev = &device->dev;
303 struct tpm_chip *chip = dev_get_drvdata(dev); 345 struct tpm_chip *chip = dev_get_drvdata(dev);
304 346
305 tpm_chip_unregister(chip);
306
307 if (chip->flags & TPM_CHIP_FLAG_TPM2) 347 if (chip->flags & TPM_CHIP_FLAG_TPM2)
308 tpm2_shutdown(chip, TPM2_SU_CLEAR); 348 tpm2_shutdown(chip, TPM2_SU_CLEAR);
309 349
350 tpm_chip_unregister(chip);
351
310 return 0; 352 return 0;
311} 353}
312 354
diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
index bd72fb04225e..4e6940acf639 100644
--- a/drivers/char/tpm/tpm_eventlog.c
+++ b/drivers/char/tpm/tpm_eventlog.c
@@ -232,7 +232,7 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
232{ 232{
233 struct tcpa_event *event = v; 233 struct tcpa_event *event = v;
234 struct tcpa_event temp_event; 234 struct tcpa_event temp_event;
235 char *tempPtr; 235 char *temp_ptr;
236 int i; 236 int i;
237 237
238 memcpy(&temp_event, event, sizeof(struct tcpa_event)); 238 memcpy(&temp_event, event, sizeof(struct tcpa_event));
@@ -242,10 +242,16 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
242 temp_event.event_type = do_endian_conversion(event->event_type); 242 temp_event.event_type = do_endian_conversion(event->event_type);
243 temp_event.event_size = do_endian_conversion(event->event_size); 243 temp_event.event_size = do_endian_conversion(event->event_size);
244 244
245 tempPtr = (char *)&temp_event; 245 temp_ptr = (char *) &temp_event;
246 246
247 for (i = 0; i < sizeof(struct tcpa_event) + temp_event.event_size; i++) 247 for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)
248 seq_putc(m, tempPtr[i]); 248 seq_putc(m, temp_ptr[i]);
249
250 temp_ptr = (char *) v;
251
252 for (i = (sizeof(struct tcpa_event) - 1);
253 i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
254 seq_putc(m, temp_ptr[i]);
249 255
250 return 0; 256 return 0;
251 257
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 8a3509cb10da..a507006728e0 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -28,7 +28,6 @@
28#include <linux/wait.h> 28#include <linux/wait.h>
29#include <linux/acpi.h> 29#include <linux/acpi.h>
30#include <linux/freezer.h> 30#include <linux/freezer.h>
31#include <acpi/actbl2.h>
32#include "tpm.h" 31#include "tpm.h"
33 32
34enum tis_access { 33enum tis_access {
@@ -60,22 +59,18 @@ enum tis_int_flags {
60}; 59};
61 60
62enum tis_defaults { 61enum tis_defaults {
63 TIS_MEM_BASE = 0xFED40000,
64 TIS_MEM_LEN = 0x5000, 62 TIS_MEM_LEN = 0x5000,
65 TIS_SHORT_TIMEOUT = 750, /* ms */ 63 TIS_SHORT_TIMEOUT = 750, /* ms */
66 TIS_LONG_TIMEOUT = 2000, /* 2 sec */ 64 TIS_LONG_TIMEOUT = 2000, /* 2 sec */
67}; 65};
68 66
69struct tpm_info { 67struct tpm_info {
70 unsigned long start; 68 struct resource res;
71 unsigned long len; 69 /* irq > 0 means: use irq $irq;
72 unsigned int irq; 70 * irq = 0 means: autoprobe for an irq;
73}; 71 * irq = -1 means: no irq support
74 72 */
75static struct tpm_info tis_default_info = { 73 int irq;
76 .start = TIS_MEM_BASE,
77 .len = TIS_MEM_LEN,
78 .irq = 0,
79}; 74};
80 75
81/* Some timeout values are needed before it is known whether the chip is 76/* Some timeout values are needed before it is known whether the chip is
@@ -118,39 +113,11 @@ static inline int is_itpm(struct acpi_device *dev)
118{ 113{
119 return has_hid(dev, "INTC0102"); 114 return has_hid(dev, "INTC0102");
120} 115}
121
122static inline int is_fifo(struct acpi_device *dev)
123{
124 struct acpi_table_tpm2 *tbl;
125 acpi_status st;
126
127 /* TPM 1.2 FIFO */
128 if (!has_hid(dev, "MSFT0101"))
129 return 1;
130
131 st = acpi_get_table(ACPI_SIG_TPM2, 1,
132 (struct acpi_table_header **) &tbl);
133 if (ACPI_FAILURE(st)) {
134 dev_err(&dev->dev, "failed to get TPM2 ACPI table\n");
135 return 0;
136 }
137
138 if (le32_to_cpu(tbl->start_method) != TPM2_START_FIFO)
139 return 0;
140
141 /* TPM 2.0 FIFO */
142 return 1;
143}
144#else 116#else
145static inline int is_itpm(struct acpi_device *dev) 117static inline int is_itpm(struct acpi_device *dev)
146{ 118{
147 return 0; 119 return 0;
148} 120}
149
150static inline int is_fifo(struct acpi_device *dev)
151{
152 return 1;
153}
154#endif 121#endif
155 122
156/* Before we attempt to access the TPM we must see that the valid bit is set. 123/* Before we attempt to access the TPM we must see that the valid bit is set.
@@ -716,9 +683,9 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
716 chip->acpi_dev_handle = acpi_dev_handle; 683 chip->acpi_dev_handle = acpi_dev_handle;
717#endif 684#endif
718 685
719 chip->vendor.iobase = devm_ioremap(dev, tpm_info->start, tpm_info->len); 686 chip->vendor.iobase = devm_ioremap_resource(dev, &tpm_info->res);
720 if (!chip->vendor.iobase) 687 if (IS_ERR(chip->vendor.iobase))
721 return -EIO; 688 return PTR_ERR(chip->vendor.iobase);
722 689
723 /* Maximum timeouts */ 690 /* Maximum timeouts */
724 chip->vendor.timeout_a = TIS_TIMEOUT_A_MAX; 691 chip->vendor.timeout_a = TIS_TIMEOUT_A_MAX;
@@ -807,7 +774,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
807 /* INTERRUPT Setup */ 774 /* INTERRUPT Setup */
808 init_waitqueue_head(&chip->vendor.read_queue); 775 init_waitqueue_head(&chip->vendor.read_queue);
809 init_waitqueue_head(&chip->vendor.int_queue); 776 init_waitqueue_head(&chip->vendor.int_queue);
810 if (interrupts) { 777 if (interrupts && tpm_info->irq != -1) {
811 if (tpm_info->irq) { 778 if (tpm_info->irq) {
812 tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED, 779 tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
813 tpm_info->irq); 780 tpm_info->irq);
@@ -893,29 +860,29 @@ static int tpm_tis_resume(struct device *dev)
893 860
894static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume); 861static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
895 862
896#ifdef CONFIG_PNP
897static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev, 863static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
898 const struct pnp_device_id *pnp_id) 864 const struct pnp_device_id *pnp_id)
899{ 865{
900 struct tpm_info tpm_info = tis_default_info; 866 struct tpm_info tpm_info = {};
901 acpi_handle acpi_dev_handle = NULL; 867 acpi_handle acpi_dev_handle = NULL;
868 struct resource *res;
902 869
903 tpm_info.start = pnp_mem_start(pnp_dev, 0); 870 res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
904 tpm_info.len = pnp_mem_len(pnp_dev, 0); 871 if (!res)
872 return -ENODEV;
873 tpm_info.res = *res;
905 874
906 if (pnp_irq_valid(pnp_dev, 0)) 875 if (pnp_irq_valid(pnp_dev, 0))
907 tpm_info.irq = pnp_irq(pnp_dev, 0); 876 tpm_info.irq = pnp_irq(pnp_dev, 0);
908 else 877 else
909 interrupts = false; 878 tpm_info.irq = -1;
910 879
911#ifdef CONFIG_ACPI
912 if (pnp_acpi_device(pnp_dev)) { 880 if (pnp_acpi_device(pnp_dev)) {
913 if (is_itpm(pnp_acpi_device(pnp_dev))) 881 if (is_itpm(pnp_acpi_device(pnp_dev)))
914 itpm = true; 882 itpm = true;
915 883
916 acpi_dev_handle = pnp_acpi_device(pnp_dev)->handle; 884 acpi_dev_handle = ACPI_HANDLE(&pnp_dev->dev);
917 } 885 }
918#endif
919 886
920 return tpm_tis_init(&pnp_dev->dev, &tpm_info, acpi_dev_handle); 887 return tpm_tis_init(&pnp_dev->dev, &tpm_info, acpi_dev_handle);
921} 888}
@@ -956,7 +923,6 @@ static struct pnp_driver tis_pnp_driver = {
956module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id, 923module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
957 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); 924 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
958MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); 925MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
959#endif
960 926
961#ifdef CONFIG_ACPI 927#ifdef CONFIG_ACPI
962static int tpm_check_resource(struct acpi_resource *ares, void *data) 928static int tpm_check_resource(struct acpi_resource *ares, void *data)
@@ -964,11 +930,11 @@ static int tpm_check_resource(struct acpi_resource *ares, void *data)
964 struct tpm_info *tpm_info = (struct tpm_info *) data; 930 struct tpm_info *tpm_info = (struct tpm_info *) data;
965 struct resource res; 931 struct resource res;
966 932
967 if (acpi_dev_resource_interrupt(ares, 0, &res)) { 933 if (acpi_dev_resource_interrupt(ares, 0, &res))
968 tpm_info->irq = res.start; 934 tpm_info->irq = res.start;
969 } else if (acpi_dev_resource_memory(ares, &res)) { 935 else if (acpi_dev_resource_memory(ares, &res)) {
970 tpm_info->start = res.start; 936 tpm_info->res = res;
971 tpm_info->len = resource_size(&res); 937 tpm_info->res.name = NULL;
972 } 938 }
973 939
974 return 1; 940 return 1;
@@ -976,14 +942,25 @@ static int tpm_check_resource(struct acpi_resource *ares, void *data)
976 942
977static int tpm_tis_acpi_init(struct acpi_device *acpi_dev) 943static int tpm_tis_acpi_init(struct acpi_device *acpi_dev)
978{ 944{
945 struct acpi_table_tpm2 *tbl;
946 acpi_status st;
979 struct list_head resources; 947 struct list_head resources;
980 struct tpm_info tpm_info = tis_default_info; 948 struct tpm_info tpm_info = {};
981 int ret; 949 int ret;
982 950
983 if (!is_fifo(acpi_dev)) 951 st = acpi_get_table(ACPI_SIG_TPM2, 1,
952 (struct acpi_table_header **) &tbl);
953 if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
954 dev_err(&acpi_dev->dev,
955 FW_BUG "failed to get TPM2 ACPI table\n");
956 return -EINVAL;
957 }
958
959 if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
984 return -ENODEV; 960 return -ENODEV;
985 961
986 INIT_LIST_HEAD(&resources); 962 INIT_LIST_HEAD(&resources);
963 tpm_info.irq = -1;
987 ret = acpi_dev_get_resources(acpi_dev, &resources, tpm_check_resource, 964 ret = acpi_dev_get_resources(acpi_dev, &resources, tpm_check_resource,
988 &tpm_info); 965 &tpm_info);
989 if (ret < 0) 966 if (ret < 0)
@@ -991,8 +968,11 @@ static int tpm_tis_acpi_init(struct acpi_device *acpi_dev)
991 968
992 acpi_dev_free_resource_list(&resources); 969 acpi_dev_free_resource_list(&resources);
993 970
994 if (!tpm_info.irq) 971 if (resource_type(&tpm_info.res) != IORESOURCE_MEM) {
995 interrupts = false; 972 dev_err(&acpi_dev->dev,
973 FW_BUG "TPM2 ACPI table does not define a memory resource\n");
974 return -EINVAL;
975 }
996 976
997 if (is_itpm(acpi_dev)) 977 if (is_itpm(acpi_dev))
998 itpm = true; 978 itpm = true;
@@ -1031,80 +1011,135 @@ static struct acpi_driver tis_acpi_driver = {
1031}; 1011};
1032#endif 1012#endif
1033 1013
1014static struct platform_device *force_pdev;
1015
1016static int tpm_tis_plat_probe(struct platform_device *pdev)
1017{
1018 struct tpm_info tpm_info = {};
1019 struct resource *res;
1020
1021 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1022 if (res == NULL) {
1023 dev_err(&pdev->dev, "no memory resource defined\n");
1024 return -ENODEV;
1025 }
1026 tpm_info.res = *res;
1027
1028 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1029 if (res) {
1030 tpm_info.irq = res->start;
1031 } else {
1032 if (pdev == force_pdev)
1033 tpm_info.irq = -1;
1034 else
1035 /* When forcing auto probe the IRQ */
1036 tpm_info.irq = 0;
1037 }
1038
1039 return tpm_tis_init(&pdev->dev, &tpm_info, NULL);
1040}
1041
1042static int tpm_tis_plat_remove(struct platform_device *pdev)
1043{
1044 struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
1045
1046 tpm_chip_unregister(chip);
1047 tpm_tis_remove(chip);
1048
1049 return 0;
1050}
1051
1034static struct platform_driver tis_drv = { 1052static struct platform_driver tis_drv = {
1053 .probe = tpm_tis_plat_probe,
1054 .remove = tpm_tis_plat_remove,
1035 .driver = { 1055 .driver = {
1036 .name = "tpm_tis", 1056 .name = "tpm_tis",
1037 .pm = &tpm_tis_pm, 1057 .pm = &tpm_tis_pm,
1038 }, 1058 },
1039}; 1059};
1040 1060
1041static struct platform_device *pdev;
1042
1043static bool force; 1061static bool force;
1062#ifdef CONFIG_X86
1044module_param(force, bool, 0444); 1063module_param(force, bool, 0444);
1045MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry"); 1064MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
1065#endif
1066
1067static int tpm_tis_force_device(void)
1068{
1069 struct platform_device *pdev;
1070 static const struct resource x86_resources[] = {
1071 {
1072 .start = 0xFED40000,
1073 .end = 0xFED40000 + TIS_MEM_LEN - 1,
1074 .flags = IORESOURCE_MEM,
1075 },
1076 };
1077
1078 if (!force)
1079 return 0;
1080
1081 /* The driver core will match the name tpm_tis of the device to
1082 * the tpm_tis platform driver and complete the setup via
1083 * tpm_tis_plat_probe
1084 */
1085 pdev = platform_device_register_simple("tpm_tis", -1, x86_resources,
1086 ARRAY_SIZE(x86_resources));
1087 if (IS_ERR(pdev))
1088 return PTR_ERR(pdev);
1089 force_pdev = pdev;
1090
1091 return 0;
1092}
1093
1046static int __init init_tis(void) 1094static int __init init_tis(void)
1047{ 1095{
1048 int rc; 1096 int rc;
1049#ifdef CONFIG_PNP 1097
1050 if (!force) { 1098 rc = tpm_tis_force_device();
1051 rc = pnp_register_driver(&tis_pnp_driver); 1099 if (rc)
1052 if (rc) 1100 goto err_force;
1053 return rc; 1101
1054 } 1102 rc = platform_driver_register(&tis_drv);
1055#endif 1103 if (rc)
1104 goto err_platform;
1105
1056#ifdef CONFIG_ACPI 1106#ifdef CONFIG_ACPI
1057 if (!force) { 1107 rc = acpi_bus_register_driver(&tis_acpi_driver);
1058 rc = acpi_bus_register_driver(&tis_acpi_driver); 1108 if (rc)
1059 if (rc) { 1109 goto err_acpi;
1060#ifdef CONFIG_PNP
1061 pnp_unregister_driver(&tis_pnp_driver);
1062#endif
1063 return rc;
1064 }
1065 }
1066#endif 1110#endif
1067 if (!force)
1068 return 0;
1069 1111
1070 rc = platform_driver_register(&tis_drv); 1112 if (IS_ENABLED(CONFIG_PNP)) {
1071 if (rc < 0) 1113 rc = pnp_register_driver(&tis_pnp_driver);
1072 return rc; 1114 if (rc)
1073 pdev = platform_device_register_simple("tpm_tis", -1, NULL, 0); 1115 goto err_pnp;
1074 if (IS_ERR(pdev)) {
1075 rc = PTR_ERR(pdev);
1076 goto err_dev;
1077 } 1116 }
1078 rc = tpm_tis_init(&pdev->dev, &tis_default_info, NULL); 1117
1079 if (rc)
1080 goto err_init;
1081 return 0; 1118 return 0;
1082err_init: 1119
1083 platform_device_unregister(pdev); 1120err_pnp:
1084err_dev: 1121#ifdef CONFIG_ACPI
1085 platform_driver_unregister(&tis_drv); 1122 acpi_bus_unregister_driver(&tis_acpi_driver);
1123err_acpi:
1124#endif
1125 platform_device_unregister(force_pdev);
1126err_platform:
1127 if (force_pdev)
1128 platform_device_unregister(force_pdev);
1129err_force:
1086 return rc; 1130 return rc;
1087} 1131}
1088 1132
1089static void __exit cleanup_tis(void) 1133static void __exit cleanup_tis(void)
1090{ 1134{
1091 struct tpm_chip *chip; 1135 pnp_unregister_driver(&tis_pnp_driver);
1092#if defined(CONFIG_PNP) || defined(CONFIG_ACPI)
1093 if (!force) {
1094#ifdef CONFIG_ACPI 1136#ifdef CONFIG_ACPI
1095 acpi_bus_unregister_driver(&tis_acpi_driver); 1137 acpi_bus_unregister_driver(&tis_acpi_driver);
1096#endif
1097#ifdef CONFIG_PNP
1098 pnp_unregister_driver(&tis_pnp_driver);
1099#endif 1138#endif
1100 return;
1101 }
1102#endif
1103 chip = dev_get_drvdata(&pdev->dev);
1104 tpm_chip_unregister(chip);
1105 tpm_tis_remove(chip);
1106 platform_device_unregister(pdev);
1107 platform_driver_unregister(&tis_drv); 1139 platform_driver_unregister(&tis_drv);
1140
1141 if (force_pdev)
1142 platform_device_unregister(force_pdev);
1108} 1143}
1109 1144
1110module_init(init_tis); 1145module_init(init_tis);