hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/thunderbolt/domain.c
....@@ -1,16 +1,15 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Thunderbolt bus support
34 *
45 * Copyright (C) 2017, Intel Corporation
5
- * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
6
+ * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
107 */
118
129 #include <linux/device.h>
10
+#include <linux/dmar.h>
1311 #include <linux/idr.h>
12
+#include <linux/iommu.h>
1413 #include <linux/module.h>
1514 #include <linux/pm_runtime.h>
1615 #include <linux/slab.h>
....@@ -148,10 +147,10 @@
148147
149148 for (ret = 0, i = 0; i < tb->nboot_acl; i++) {
150149 if (!uuid_is_null(&uuids[i]))
151
- ret += snprintf(buf + ret, PAGE_SIZE - ret, "%pUb",
150
+ ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%pUb",
152151 &uuids[i]);
153152
154
- ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s",
153
+ ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s",
155154 i < tb->nboot_acl - 1 ? "," : "\n");
156155 }
157156
....@@ -239,6 +238,20 @@
239238 }
240239 static DEVICE_ATTR_RW(boot_acl);
241240
241
+static ssize_t iommu_dma_protection_show(struct device *dev,
242
+ struct device_attribute *attr,
243
+ char *buf)
244
+{
245
+ /*
246
+ * Kernel DMA protection is a feature where Thunderbolt security is
247
+ * handled natively using IOMMU. It is enabled when IOMMU is
248
+ * enabled and ACPI DMAR table has DMAR_PLATFORM_OPT_IN set.
249
+ */
250
+ return sprintf(buf, "%d\n",
251
+ iommu_present(&pci_bus_type) && dmar_platform_optin());
252
+}
253
+static DEVICE_ATTR_RO(iommu_dma_protection);
254
+
242255 static ssize_t security_show(struct device *dev, struct device_attribute *attr,
243256 char *buf)
244257 {
....@@ -254,6 +267,7 @@
254267
255268 static struct attribute *domain_attrs[] = {
256269 &dev_attr_boot_acl.attr,
270
+ &dev_attr_iommu_dma_protection.attr,
257271 &dev_attr_security.attr,
258272 NULL,
259273 };
....@@ -261,7 +275,7 @@
261275 static umode_t domain_attr_is_visible(struct kobject *kobj,
262276 struct attribute *attr, int n)
263277 {
264
- struct device *dev = container_of(kobj, struct device, kobj);
278
+ struct device *dev = kobj_to_dev(kobj);
265279 struct tb *tb = container_of(dev, struct tb, dev);
266280
267281 if (attr == &dev_attr_boot_acl.attr) {
....@@ -441,6 +455,8 @@
441455 /* This starts event processing */
442456 mutex_unlock(&tb->lock);
443457
458
+ device_init_wakeup(&tb->dev, true);
459
+
444460 pm_runtime_no_callbacks(&tb->dev);
445461 pm_runtime_set_active(&tb->dev);
446462 pm_runtime_enable(&tb->dev);
....@@ -528,6 +544,33 @@
528544 int tb_domain_suspend(struct tb *tb)
529545 {
530546 return tb->cm_ops->suspend ? tb->cm_ops->suspend(tb) : 0;
547
+}
548
+
549
+int tb_domain_freeze_noirq(struct tb *tb)
550
+{
551
+ int ret = 0;
552
+
553
+ mutex_lock(&tb->lock);
554
+ if (tb->cm_ops->freeze_noirq)
555
+ ret = tb->cm_ops->freeze_noirq(tb);
556
+ if (!ret)
557
+ tb_ctl_stop(tb->ctl);
558
+ mutex_unlock(&tb->lock);
559
+
560
+ return ret;
561
+}
562
+
563
+int tb_domain_thaw_noirq(struct tb *tb)
564
+{
565
+ int ret = 0;
566
+
567
+ mutex_lock(&tb->lock);
568
+ tb_ctl_start(tb->ctl);
569
+ if (tb->cm_ops->thaw_noirq)
570
+ ret = tb->cm_ops->thaw_noirq(tb);
571
+ mutex_unlock(&tb->lock);
572
+
573
+ return ret;
531574 }
532575
533576 void tb_domain_complete(struct tb *tb)
....@@ -664,7 +707,6 @@
664707 }
665708
666709 shash->tfm = tfm;
667
- shash->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
668710
669711 memset(hmac, 0, sizeof(hmac));
670712 ret = crypto_shash_digest(shash, challenge, sizeof(hmac), hmac);
....@@ -785,12 +827,23 @@
785827 {
786828 int ret;
787829
830
+ tb_test_init();
831
+
832
+ tb_debugfs_init();
788833 ret = tb_xdomain_init();
789834 if (ret)
790
- return ret;
835
+ goto err_debugfs;
791836 ret = bus_register(&tb_bus_type);
792837 if (ret)
793
- tb_xdomain_exit();
838
+ goto err_xdomain;
839
+
840
+ return 0;
841
+
842
+err_xdomain:
843
+ tb_xdomain_exit();
844
+err_debugfs:
845
+ tb_debugfs_exit();
846
+ tb_test_exit();
794847
795848 return ret;
796849 }
....@@ -799,6 +852,8 @@
799852 {
800853 bus_unregister(&tb_bus_type);
801854 ida_destroy(&tb_domain_ida);
802
- tb_switch_exit();
855
+ tb_nvm_exit();
803856 tb_xdomain_exit();
857
+ tb_debugfs_exit();
858
+ tb_test_exit();
804859 }