Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39ab9555 authored by Joerg Roedel's avatar Joerg Roedel
Browse files

iommu: Add sysfs bindings for struct iommu_device



There is currently support for iommu sysfs bindings, but
those need to be implemented in the IOMMU drivers. Add a
more generic version of this by adding a struct device to
struct iommu_device and use that for the sysfs bindings.

Also convert the AMD and Intel IOMMU driver to make use of
it.

Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent b0119e87
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -445,6 +445,7 @@ static void init_iommu_group(struct device *dev)
static int iommu_init_device(struct device *dev)
{
	struct iommu_dev_data *dev_data;
	struct amd_iommu *iommu;
	int devid;

	if (dev->archdata.iommu)
@@ -454,6 +455,8 @@ static int iommu_init_device(struct device *dev)
	if (devid < 0)
		return devid;

	iommu = amd_iommu_rlookup_table[devid];

	dev_data = find_dev_data(devid);
	if (!dev_data)
		return -ENOMEM;
@@ -469,8 +472,7 @@ static int iommu_init_device(struct device *dev)

	dev->archdata.iommu = dev_data;

	iommu_device_link(amd_iommu_rlookup_table[dev_data->devid]->iommu_dev,
			  dev);
	iommu_device_link(&iommu->iommu.dev, dev);

	return 0;
}
@@ -495,13 +497,16 @@ static void iommu_ignore_device(struct device *dev)

static void iommu_uninit_device(struct device *dev)
{
	int devid;
	struct iommu_dev_data *dev_data;
	struct amd_iommu *iommu;
	int devid;

	devid = get_device_id(dev);
	if (devid < 0)
		return;

	iommu = amd_iommu_rlookup_table[devid];

	dev_data = search_dev_data(devid);
	if (!dev_data)
		return;
@@ -509,8 +514,7 @@ static void iommu_uninit_device(struct device *dev)
	if (dev_data->domain)
		detach_device(dev);

	iommu_device_unlink(amd_iommu_rlookup_table[dev_data->devid]->iommu_dev,
			    dev);
	iommu_device_unlink(&iommu->iommu.dev, dev);

	iommu_group_remove_device(dev);

+2 −4
Original line number Diff line number Diff line
@@ -1637,10 +1637,8 @@ static int iommu_init_pci(struct amd_iommu *iommu)
	amd_iommu_erratum_746_workaround(iommu);
	amd_iommu_ats_write_check_workaround(iommu);

	iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu,
					       amd_iommu_groups, "ivhd%d",
					       iommu->index);

	iommu_device_sysfs_add(&iommu->iommu, &iommu->dev->dev,
			       amd_iommu_groups, "ivhd%d", iommu->index);
	iommu_device_set_ops(&iommu->iommu, &amd_iommu_ops);
	iommu_device_register(&iommu->iommu);

+0 −3
Original line number Diff line number Diff line
@@ -535,9 +535,6 @@ struct amd_iommu {
	/* if one, we need to send a completion wait command */
	bool need_sync;

	/* IOMMU sysfs device */
	struct device *iommu_dev;

	/* Handle for IOMMU core code */
	struct iommu_device iommu;

+5 −8
Original line number Diff line number Diff line
@@ -1078,14 +1078,11 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
	raw_spin_lock_init(&iommu->register_lock);

	if (intel_iommu_enabled) {
		iommu->iommu_dev = iommu_device_create(NULL, iommu,
		err = iommu_device_sysfs_add(&iommu->iommu, NULL,
					     intel_iommu_groups,
					     "%s", iommu->name);

		if (IS_ERR(iommu->iommu_dev)) {
			err = PTR_ERR(iommu->iommu_dev);
		if (err)
			goto err_unmap;
		}

		iommu_device_set_ops(&iommu->iommu, &intel_iommu_ops);

@@ -1109,7 +1106,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)

static void free_iommu(struct intel_iommu *iommu)
{
	iommu_device_destroy(iommu->iommu_dev);
	iommu_device_sysfs_remove(&iommu->iommu);
	iommu_device_unregister(&iommu->iommu);

	if (iommu->irq) {
+9 −6
Original line number Diff line number Diff line
@@ -4834,10 +4834,13 @@ int __init intel_iommu_init(void)

	init_iommu_pm_ops();

	for_each_active_iommu(iommu, drhd)
		iommu->iommu_dev = iommu_device_create(NULL, iommu,
	for_each_active_iommu(iommu, drhd) {
		iommu_device_sysfs_add(&iommu->iommu, NULL,
				       intel_iommu_groups,
				       "%s", iommu->name);
		iommu_device_set_ops(&iommu->iommu, &intel_iommu_ops);
		iommu_device_register(&iommu->iommu);
	}

	bus_set_iommu(&pci_bus_type, &intel_iommu_ops);
	bus_register_notifier(&pci_bus_type, &device_nb);
@@ -5159,7 +5162,7 @@ static int intel_iommu_add_device(struct device *dev)
	if (!iommu)
		return -ENODEV;

	iommu_device_link(iommu->iommu_dev, dev);
	iommu_device_link(&iommu->iommu.dev, dev);

	group = iommu_group_get_for_dev(dev);

@@ -5181,7 +5184,7 @@ static void intel_iommu_remove_device(struct device *dev)

	iommu_group_remove_device(dev);

	iommu_device_unlink(iommu->iommu_dev, dev);
	iommu_device_unlink(&iommu->iommu.dev, dev);
}

#ifdef CONFIG_INTEL_IOMMU_SVM
Loading