mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 15:01:13 +07:00
iommu/vt-d: Make use of IOMMU sysfs support
Register our DRHD IOMMUs, cross link devices, and provide a base set of attributes for the IOMMU. Note that IRQ remapping support parses the DMAR table very early in boot, well before the iommu_class can reasonably be setup, so our registration is split between intel_iommu_init(), which occurs later, and alloc_iommu(), which typically occurs much earlier, but may happen at any time later with IOMMU hot-add support. On a typical desktop system, this provides the following (pruned): $ find /sys | grep dmar /sys/devices/virtual/iommu/dmar0 /sys/devices/virtual/iommu/dmar0/devices /sys/devices/virtual/iommu/dmar0/devices/0000:00:02.0 /sys/devices/virtual/iommu/dmar0/intel-iommu /sys/devices/virtual/iommu/dmar0/intel-iommu/cap /sys/devices/virtual/iommu/dmar0/intel-iommu/ecap /sys/devices/virtual/iommu/dmar0/intel-iommu/address /sys/devices/virtual/iommu/dmar0/intel-iommu/version /sys/devices/virtual/iommu/dmar1 /sys/devices/virtual/iommu/dmar1/devices /sys/devices/virtual/iommu/dmar1/devices/0000:00:00.0 /sys/devices/virtual/iommu/dmar1/devices/0000:00:01.0 /sys/devices/virtual/iommu/dmar1/devices/0000:00:16.0 /sys/devices/virtual/iommu/dmar1/devices/0000:00:1a.0 /sys/devices/virtual/iommu/dmar1/devices/0000:00:1b.0 /sys/devices/virtual/iommu/dmar1/devices/0000:00:1c.0 ... /sys/devices/virtual/iommu/dmar1/intel-iommu /sys/devices/virtual/iommu/dmar1/intel-iommu/cap /sys/devices/virtual/iommu/dmar1/intel-iommu/ecap /sys/devices/virtual/iommu/dmar1/intel-iommu/address /sys/devices/virtual/iommu/dmar1/intel-iommu/version /sys/class/iommu/dmar0 /sys/class/iommu/dmar1 (devices also link back to the dmar units) This makes address, version, capabilities, and extended capabilities available, just like printed on boot. I've tried not to duplicate data that can be found in the DMAR table, with the exception of the address, which provides an easy way to associate the sysfs device with a DRHD entry in the DMAR. It's tempting to add scopes and RMRR data here, but the full DMAR table is already exposed under /sys/firmware/ and therefore already provides a way for userspace to learn such details. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
c61959ecbb
commit
a5459cfece
32
Documentation/ABI/testing/sysfs-class-iommu-intel-iommu
Normal file
32
Documentation/ABI/testing/sysfs-class-iommu-intel-iommu
Normal file
@ -0,0 +1,32 @@
|
||||
What: /sys/class/iommu/<iommu>/intel-iommu/address
|
||||
Date: June 2014
|
||||
KernelVersion: 3.17
|
||||
Contact: Alex Williamson <alex.williamson@redhat.com>
|
||||
Description:
|
||||
Physical address of the VT-d DRHD for this IOMMU.
|
||||
Format: %llx. This allows association of a sysfs
|
||||
intel-iommu with a DMAR DRHD table entry.
|
||||
|
||||
What: /sys/class/iommu/<iommu>/intel-iommu/cap
|
||||
Date: June 2014
|
||||
KernelVersion: 3.17
|
||||
Contact: Alex Williamson <alex.williamson@redhat.com>
|
||||
Description:
|
||||
The cached hardware capability register value
|
||||
of this DRHD unit. Format: %llx.
|
||||
|
||||
What: /sys/class/iommu/<iommu>/intel-iommu/ecap
|
||||
Date: June 2014
|
||||
KernelVersion: 3.17
|
||||
Contact: Alex Williamson <alex.williamson@redhat.com>
|
||||
Description:
|
||||
The cached hardware extended capability register
|
||||
value of this DRHD unit. Format: %llx.
|
||||
|
||||
What: /sys/class/iommu/<iommu>/intel-iommu/version
|
||||
Date: June 2014
|
||||
KernelVersion: 3.17
|
||||
Contact: Alex Williamson <alex.williamson@redhat.com>
|
||||
Description:
|
||||
The architecture version as reported from the
|
||||
VT-d VER_REG. Format: %d:%d, major:minor
|
@ -38,6 +38,7 @@
|
||||
#include <linux/tboot.h>
|
||||
#include <linux/dmi.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/iommu.h>
|
||||
#include <asm/irq_remapping.h>
|
||||
#include <asm/iommu_table.h>
|
||||
|
||||
@ -980,6 +981,12 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
|
||||
raw_spin_lock_init(&iommu->register_lock);
|
||||
|
||||
drhd->iommu = iommu;
|
||||
|
||||
if (intel_iommu_enabled)
|
||||
iommu->iommu_dev = iommu_device_create(NULL, iommu,
|
||||
intel_iommu_groups,
|
||||
iommu->name);
|
||||
|
||||
return 0;
|
||||
|
||||
err_unmap:
|
||||
@ -991,6 +998,8 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
|
||||
|
||||
static void free_iommu(struct intel_iommu *iommu)
|
||||
{
|
||||
iommu_device_destroy(iommu->iommu_dev);
|
||||
|
||||
if (iommu->irq) {
|
||||
free_irq(iommu->irq, iommu);
|
||||
irq_set_handler_data(iommu->irq, NULL);
|
||||
|
@ -3944,6 +3944,63 @@ static struct notifier_block intel_iommu_memory_nb = {
|
||||
.priority = 0
|
||||
};
|
||||
|
||||
|
||||
static ssize_t intel_iommu_show_version(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct intel_iommu *iommu = dev_get_drvdata(dev);
|
||||
u32 ver = readl(iommu->reg + DMAR_VER_REG);
|
||||
return sprintf(buf, "%d:%d\n",
|
||||
DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver));
|
||||
}
|
||||
static DEVICE_ATTR(version, S_IRUGO, intel_iommu_show_version, NULL);
|
||||
|
||||
static ssize_t intel_iommu_show_address(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct intel_iommu *iommu = dev_get_drvdata(dev);
|
||||
return sprintf(buf, "%llx\n", iommu->reg_phys);
|
||||
}
|
||||
static DEVICE_ATTR(address, S_IRUGO, intel_iommu_show_address, NULL);
|
||||
|
||||
static ssize_t intel_iommu_show_cap(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct intel_iommu *iommu = dev_get_drvdata(dev);
|
||||
return sprintf(buf, "%llx\n", iommu->cap);
|
||||
}
|
||||
static DEVICE_ATTR(cap, S_IRUGO, intel_iommu_show_cap, NULL);
|
||||
|
||||
static ssize_t intel_iommu_show_ecap(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct intel_iommu *iommu = dev_get_drvdata(dev);
|
||||
return sprintf(buf, "%llx\n", iommu->ecap);
|
||||
}
|
||||
static DEVICE_ATTR(ecap, S_IRUGO, intel_iommu_show_ecap, NULL);
|
||||
|
||||
static struct attribute *intel_iommu_attrs[] = {
|
||||
&dev_attr_version.attr,
|
||||
&dev_attr_address.attr,
|
||||
&dev_attr_cap.attr,
|
||||
&dev_attr_ecap.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct attribute_group intel_iommu_group = {
|
||||
.name = "intel-iommu",
|
||||
.attrs = intel_iommu_attrs,
|
||||
};
|
||||
|
||||
const struct attribute_group *intel_iommu_groups[] = {
|
||||
&intel_iommu_group,
|
||||
NULL,
|
||||
};
|
||||
|
||||
int __init intel_iommu_init(void)
|
||||
{
|
||||
int ret = -ENODEV;
|
||||
@ -4015,6 +4072,11 @@ int __init intel_iommu_init(void)
|
||||
|
||||
init_iommu_pm_ops();
|
||||
|
||||
for_each_active_iommu(iommu, drhd)
|
||||
iommu->iommu_dev = iommu_device_create(NULL, iommu,
|
||||
intel_iommu_groups,
|
||||
iommu->name);
|
||||
|
||||
bus_set_iommu(&pci_bus_type, &intel_iommu_ops);
|
||||
bus_register_notifier(&pci_bus_type, &device_nb);
|
||||
if (si_domain && !hw_pass_through)
|
||||
@ -4358,12 +4420,16 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain,
|
||||
|
||||
static int intel_iommu_add_device(struct device *dev)
|
||||
{
|
||||
struct intel_iommu *iommu;
|
||||
struct iommu_group *group;
|
||||
u8 bus, devfn;
|
||||
|
||||
if (!device_to_iommu(dev, &bus, &devfn))
|
||||
iommu = device_to_iommu(dev, &bus, &devfn);
|
||||
if (!iommu)
|
||||
return -ENODEV;
|
||||
|
||||
iommu_device_link(iommu->iommu_dev, dev);
|
||||
|
||||
group = iommu_group_get_for_dev(dev);
|
||||
|
||||
if (IS_ERR(group))
|
||||
@ -4375,7 +4441,16 @@ static int intel_iommu_add_device(struct device *dev)
|
||||
|
||||
static void intel_iommu_remove_device(struct device *dev)
|
||||
{
|
||||
struct intel_iommu *iommu;
|
||||
u8 bus, devfn;
|
||||
|
||||
iommu = device_to_iommu(dev, &bus, &devfn);
|
||||
if (!iommu)
|
||||
return;
|
||||
|
||||
iommu_group_remove_device(dev);
|
||||
|
||||
iommu_device_unlink(iommu->iommu_dev, dev);
|
||||
}
|
||||
|
||||
static struct iommu_ops intel_iommu_ops = {
|
||||
|
@ -336,6 +336,7 @@ struct intel_iommu {
|
||||
#ifdef CONFIG_IRQ_REMAP
|
||||
struct ir_table *ir_table; /* Interrupt remapping info */
|
||||
#endif
|
||||
struct device *iommu_dev; /* IOMMU-sysfs device */
|
||||
int node;
|
||||
};
|
||||
|
||||
@ -365,4 +366,6 @@ extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);
|
||||
|
||||
extern int dmar_ir_support(void);
|
||||
|
||||
extern const struct attribute_group *intel_iommu_groups[];
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user