Source
1
1
// SPDX-License-Identifier: GPL-2.0
2
2
/*
3
3
* Thunderbolt bus support
4
4
*
5
5
* Copyright (C) 2017, Intel Corporation
6
6
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7
7
*/
8
8
9
9
#include <linux/device.h>
10
+
#include <linux/dmar.h>
10
11
#include <linux/idr.h>
12
+
#include <linux/iommu.h>
11
13
#include <linux/module.h>
12
14
#include <linux/pm_runtime.h>
13
15
#include <linux/slab.h>
14
16
#include <linux/random.h>
15
17
#include <crypto/hash.h>
16
18
17
19
#include "tb.h"
18
20
19
21
static DEFINE_IDA(tb_domain_ida);
20
22
229
231
pm_runtime_put_autosuspend(&tb->dev);
230
232
err_free_acl:
231
233
kfree(acl);
232
234
err_free_str:
233
235
kfree(str);
234
236
235
237
return ret ?: count;
236
238
}
237
239
static DEVICE_ATTR_RW(boot_acl);
238
240
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
+
239
255
static ssize_t security_show(struct device *dev, struct device_attribute *attr,
240
256
char *buf)
241
257
{
242
258
struct tb *tb = container_of(dev, struct tb, dev);
243
259
const char *name = "unknown";
244
260
245
261
if (tb->security_level < ARRAY_SIZE(tb_security_names))
246
262
name = tb_security_names[tb->security_level];
247
263
248
264
return sprintf(buf, "%s\n", name);
249
265
}
250
266
static DEVICE_ATTR_RO(security);
251
267
252
268
static struct attribute *domain_attrs[] = {
253
269
&dev_attr_boot_acl.attr,
270
+
&dev_attr_iommu_dma_protection.attr,
254
271
&dev_attr_security.attr,
255
272
NULL,
256
273
};
257
274
258
275
static umode_t domain_attr_is_visible(struct kobject *kobj,
259
276
struct attribute *attr, int n)
260
277
{
261
278
struct device *dev = container_of(kobj, struct device, kobj);
262
279
struct tb *tb = container_of(dev, struct tb, dev);
263
280