hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/char/tpm/tpm_ibmvtpm.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2012-2020 IBM Corporation
34 *
....@@ -7,12 +8,6 @@
78 *
89 * Device driver for TCG/TCPA TPM (trusted platform module).
910 * Specifications at www.trustedcomputinggroup.org
10
- *
11
- * This program is free software; you can redistribute it and/or
12
- * modify it under the terms of the GNU General Public License as
13
- * published by the Free Software Foundation, version 2 of the
14
- * License.
15
- *
1611 */
1712
1813 #include <linux/dma-mapping.h>
....@@ -34,13 +29,13 @@
3429
3530 static const struct vio_device_id tpm_ibmvtpm_device_table[] = {
3631 { "IBM,vtpm", "IBM,vtpm"},
32
+ { "IBM,vtpm", "IBM,vtpm20"},
3733 { "", "" }
3834 };
3935 MODULE_DEVICE_TABLE(vio, tpm_ibmvtpm_device_table);
4036
4137 /**
42
- *
43
- * ibmvtpm_send_crq_word - Send a CRQ request
38
+ * ibmvtpm_send_crq_word() - Send a CRQ request
4439 * @vdev: vio device struct
4540 * @w1: pre-constructed first word of tpm crq (second word is reserved)
4641 *
....@@ -54,8 +49,7 @@
5449 }
5550
5651 /**
57
- *
58
- * ibmvtpm_send_crq - Send a CRQ request
52
+ * ibmvtpm_send_crq() - Send a CRQ request
5953 *
6054 * @vdev: vio device struct
6155 * @valid: Valid field
....@@ -112,16 +106,11 @@
112106 {
113107 struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
114108 u16 len;
115
- int sig;
116109
117110 if (!ibmvtpm->rtce_buf) {
118111 dev_err(ibmvtpm->dev, "ibmvtpm device is not ready\n");
119112 return 0;
120113 }
121
-
122
- sig = wait_event_interruptible(ibmvtpm->wq, !ibmvtpm->tpm_processing_cmd);
123
- if (sig)
124
- return -EINTR;
125114
126115 len = ibmvtpm->res_len;
127116
....@@ -243,7 +232,7 @@
243232 * set the processing flag before the Hcall, since we may get the
244233 * result (interrupt) before even being able to check rc.
245234 */
246
- ibmvtpm->tpm_processing_cmd = true;
235
+ ibmvtpm->tpm_processing_cmd = 1;
247236
248237 again:
249238 rc = ibmvtpm_send_crq(ibmvtpm->vdev,
....@@ -261,7 +250,7 @@
261250 goto again;
262251 }
263252 dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
264
- ibmvtpm->tpm_processing_cmd = false;
253
+ ibmvtpm->tpm_processing_cmd = 0;
265254 }
266255
267256 spin_unlock(&ibmvtpm->rtce_lock);
....@@ -275,7 +264,9 @@
275264
276265 static u8 tpm_ibmvtpm_status(struct tpm_chip *chip)
277266 {
278
- return 0;
267
+ struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
268
+
269
+ return ibmvtpm->tpm_processing_cmd;
279270 }
280271
281272 /**
....@@ -465,7 +456,7 @@
465456 .send = tpm_ibmvtpm_send,
466457 .cancel = tpm_ibmvtpm_cancel,
467458 .status = tpm_ibmvtpm_status,
468
- .req_complete_mask = 0,
459
+ .req_complete_mask = 1,
469460 .req_complete_val = 0,
470461 .req_canceled = tpm_ibmvtpm_req_canceled,
471462 };
....@@ -558,7 +549,7 @@
558549 case VTPM_TPM_COMMAND_RES:
559550 /* len of the data in rtce buffer */
560551 ibmvtpm->res_len = be16_to_cpu(crq->len);
561
- ibmvtpm->tpm_processing_cmd = false;
552
+ ibmvtpm->tpm_processing_cmd = 0;
562553 wake_up_interruptible(&ibmvtpm->wq);
563554 return;
564555 default:
....@@ -692,10 +683,25 @@
692683 if (!wait_event_timeout(ibmvtpm->crq_queue.wq,
693684 ibmvtpm->rtce_buf != NULL,
694685 HZ)) {
686
+ rc = -ENODEV;
695687 dev_err(dev, "CRQ response timed out\n");
696688 goto init_irq_cleanup;
697689 }
698690
691
+
692
+ if (!strcmp(id->compat, "IBM,vtpm20"))
693
+ chip->flags |= TPM_CHIP_FLAG_TPM2;
694
+
695
+ rc = tpm_get_timeouts(chip);
696
+ if (rc)
697
+ goto init_irq_cleanup;
698
+
699
+ if (chip->flags & TPM_CHIP_FLAG_TPM2) {
700
+ rc = tpm2_get_cc_attrs_tbl(chip);
701
+ if (rc)
702
+ goto init_irq_cleanup;
703
+ }
704
+
699705 return tpm_chip_register(chip);
700706 init_irq_cleanup:
701707 do {