浏览代码

iommu: Allow taking a reference on a group directly

iommu_group_get_for_dev() expects that the IOMMU driver's device_group
callback return a group with a reference held for the given device.
Whilst allocating a new group is fine, and pci_device_group() correctly
handles reusing an existing group, there is no general means for IOMMU
drivers doing their own group lookup to take additional references on an
existing group pointer without having to also store device pointers or
resort to elaborate trickery.

Add an IOMMU-driver-specific function to fill the hole.

Acked-by: Sricharan R <sricharan@codeaurora.org>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Robin Murphy 9 年之前
父节点
当前提交
13f59a78c6
共有 2 个文件被更改,包括 14 次插入0 次删除
  1. 13 0
      drivers/iommu/iommu.c
  2. 1 0
      include/linux/iommu.h

+ 13 - 0
drivers/iommu/iommu.c

@@ -551,6 +551,19 @@ struct iommu_group *iommu_group_get(struct device *dev)
 }
 }
 EXPORT_SYMBOL_GPL(iommu_group_get);
 EXPORT_SYMBOL_GPL(iommu_group_get);
 
 
+/**
+ * iommu_group_ref_get - Increment reference on a group
+ * @group: the group to use, must not be NULL
+ *
+ * This function is called by iommu drivers to take additional references on an
+ * existing group.  Returns the given group for convenience.
+ */
+struct iommu_group *iommu_group_ref_get(struct iommu_group *group)
+{
+	kobject_get(group->devices_kobj);
+	return group;
+}
+
 /**
 /**
  * iommu_group_put - Decrement group reference
  * iommu_group_put - Decrement group reference
  * @group: the group to use
  * @group: the group to use

+ 1 - 0
include/linux/iommu.h

@@ -253,6 +253,7 @@ extern void iommu_group_remove_device(struct device *dev);
 extern int iommu_group_for_each_dev(struct iommu_group *group, void *data,
 extern int iommu_group_for_each_dev(struct iommu_group *group, void *data,
 				    int (*fn)(struct device *, void *));
 				    int (*fn)(struct device *, void *));
 extern struct iommu_group *iommu_group_get(struct device *dev);
 extern struct iommu_group *iommu_group_get(struct device *dev);
+extern struct iommu_group *iommu_group_ref_get(struct iommu_group *group);
 extern void iommu_group_put(struct iommu_group *group);
 extern void iommu_group_put(struct iommu_group *group);
 extern int iommu_group_register_notifier(struct iommu_group *group,
 extern int iommu_group_register_notifier(struct iommu_group *group,
 					 struct notifier_block *nb);
 					 struct notifier_block *nb);