Commit 5fc63a7c authored by Antonios Motakis's avatar Antonios Motakis Committed by Will Deacon

iommu/arm-smmu: add devices attached to the SMMU to an IOMMU group

IOMMU groups are expected by certain users of the IOMMU API,
e.g. VFIO. Add new devices found by the SMMU driver to an IOMMU
group to satisfy those users.
Acked-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: default avatarAntonios Motakis <a.motakis@virtualopensystems.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 319e2e3f
...@@ -1494,6 +1494,13 @@ static int arm_smmu_add_device(struct device *dev) ...@@ -1494,6 +1494,13 @@ static int arm_smmu_add_device(struct device *dev)
{ {
struct arm_smmu_device *child, *parent, *smmu; struct arm_smmu_device *child, *parent, *smmu;
struct arm_smmu_master *master = NULL; struct arm_smmu_master *master = NULL;
struct iommu_group *group;
int ret;
if (dev->archdata.iommu) {
dev_warn(dev, "IOMMU driver already assigned to device\n");
return -EINVAL;
}
spin_lock(&arm_smmu_devices_lock); spin_lock(&arm_smmu_devices_lock);
list_for_each_entry(parent, &arm_smmu_devices, list) { list_for_each_entry(parent, &arm_smmu_devices, list) {
...@@ -1526,13 +1533,23 @@ static int arm_smmu_add_device(struct device *dev) ...@@ -1526,13 +1533,23 @@ static int arm_smmu_add_device(struct device *dev)
if (!master) if (!master)
return -ENODEV; return -ENODEV;
group = iommu_group_alloc();
if (IS_ERR(group)) {
dev_err(dev, "Failed to allocate IOMMU group\n");
return PTR_ERR(group);
}
ret = iommu_group_add_device(group, dev);
iommu_group_put(group);
dev->archdata.iommu = smmu; dev->archdata.iommu = smmu;
return 0;
return ret;
} }
static void arm_smmu_remove_device(struct device *dev) static void arm_smmu_remove_device(struct device *dev)
{ {
dev->archdata.iommu = NULL; dev->archdata.iommu = NULL;
iommu_group_remove_device(dev);
} }
static struct iommu_ops arm_smmu_ops = { static struct iommu_ops arm_smmu_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment