hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/crypto/ccp/ccp-dev-v5.c
....@@ -1,20 +1,14 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * AMD Cryptographic Coprocessor (CCP) driver
34 *
4
- * Copyright (C) 2016,2017 Advanced Micro Devices, Inc.
5
+ * Copyright (C) 2016,2019 Advanced Micro Devices, Inc.
56 *
67 * Author: Gary R Hook <gary.hook@amd.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License version 2 as
10
- * published by the Free Software Foundation.
118 */
129
13
-#include <linux/module.h>
1410 #include <linux/kernel.h>
15
-#include <linux/pci.h>
1611 #include <linux/kthread.h>
17
-#include <linux/debugfs.h>
1812 #include <linux/dma-mapping.h>
1913 #include <linux/interrupt.h>
2014 #include <linux/compiler.h>
....@@ -227,8 +221,8 @@
227221 static int ccp5_do_cmd(struct ccp5_desc *desc,
228222 struct ccp_cmd_queue *cmd_q)
229223 {
230
- u32 *mP;
231
- __le32 *dP;
224
+ __le32 *mP;
225
+ u32 *dP;
232226 u32 tail;
233227 int i;
234228 int ret = 0;
....@@ -241,8 +235,8 @@
241235 }
242236 mutex_lock(&cmd_q->q_mutex);
243237
244
- mP = (u32 *) &cmd_q->qbase[cmd_q->qidx];
245
- dP = (__le32 *) desc;
238
+ mP = (__le32 *)&cmd_q->qbase[cmd_q->qidx];
239
+ dP = (u32 *)desc;
246240 for (i = 0; i < 8; i++)
247241 mP[i] = cpu_to_le32(dP[i]); /* handle endianness */
248242
....@@ -795,8 +789,19 @@
795789
796790 /* Find available queues */
797791 qmr = ioread32(ccp->io_regs + Q_MASK_REG);
798
- for (i = 0; i < MAX_HW_QUEUES; i++) {
792
+ /*
793
+ * Check for a access to the registers. If this read returns
794
+ * 0xffffffff, it's likely that the system is running a broken
795
+ * BIOS which disallows access to the device. Stop here and fail
796
+ * the initialization (but not the load, as the PSP could get
797
+ * properly initialized).
798
+ */
799
+ if (qmr == 0xffffffff) {
800
+ dev_notice(dev, "ccp: unable to access the device: you might be running a broken BIOS.\n");
801
+ return 1;
802
+ }
799803
804
+ for (i = 0; (i < MAX_HW_QUEUES) && (ccp->cmd_q_count < ccp->max_q_count); i++) {
800805 if (!(qmr & (1 << i)))
801806 continue;
802807
....@@ -809,6 +814,7 @@
809814 if (!dma_pool) {
810815 dev_err(dev, "unable to allocate dma pool\n");
811816 ret = -ENOMEM;
817
+ goto e_pool;
812818 }
813819
814820 cmd_q = &ccp->cmd_q[ccp->cmd_q_count];
....@@ -822,7 +828,7 @@
822828 /* Page alignment satisfies our needs for N <= 128 */
823829 BUILD_BUG_ON(COMMANDS_PER_QUEUE > 128);
824830 cmd_q->qsize = Q_SIZE(Q_DESC_SIZE);
825
- cmd_q->qbase = dma_zalloc_coherent(dev, cmd_q->qsize,
831
+ cmd_q->qbase = dmam_alloc_coherent(dev, cmd_q->qsize,
826832 &cmd_q->qbase_dma,
827833 GFP_KERNEL);
828834 if (!cmd_q->qbase) {
....@@ -860,7 +866,7 @@
860866
861867 if (ccp->cmd_q_count == 0) {
862868 dev_notice(dev, "no command queues available\n");
863
- ret = -EIO;
869
+ ret = 1;
864870 goto e_pool;
865871 }
866872
....@@ -973,8 +979,10 @@
973979 if (ret)
974980 goto e_hwrng;
975981
982
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
976983 /* Set up debugfs entries */
977984 ccp5_debugfs_setup(ccp);
985
+#endif
978986
979987 return 0;
980988
....@@ -998,7 +1006,6 @@
9981006
9991007 static void ccp5_destroy(struct ccp_device *ccp)
10001008 {
1001
- struct device *dev = ccp->dev;
10021009 struct ccp_cmd_queue *cmd_q;
10031010 struct ccp_cmd *cmd;
10041011 unsigned int i;
....@@ -1012,11 +1019,13 @@
10121019 /* Remove this device from the list of available units first */
10131020 ccp_del_device(ccp);
10141021
1022
+#ifdef CONFIG_CRYPTO_DEV_CCP_DEBUGFS
10151023 /* We're in the process of tearing down the entire driver;
10161024 * when all the devices are gone clean up debugfs
10171025 */
10181026 if (ccp_present())
10191027 ccp5_debugfs_destroy();
1028
+#endif
10201029
10211030 /* Disable and clear interrupts */
10221031 ccp5_disable_queue_interrupts(ccp);
....@@ -1038,12 +1047,6 @@
10381047 kthread_stop(ccp->cmd_q[i].kthread);
10391048
10401049 sp_free_ccp_irq(ccp->sp, ccp);
1041
-
1042
- for (i = 0; i < ccp->cmd_q_count; i++) {
1043
- cmd_q = &ccp->cmd_q[i];
1044
- dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase,
1045
- cmd_q->qbase_dma);
1046
- }
10471050
10481051 /* Flush the cmd and backlog queue */
10491052 while (!list_empty(&ccp->cmd)) {