aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorAlexey Kardashevskiy <aik@ozlabs.ru>2013-03-24 19:23:49 -0400
committerJoerg Roedel <joro@8bytes.org>2013-04-24 13:56:51 -0400
commitaa16bea929aed6ea854b55d2be8306a9fb40e694 (patch)
tree2a2cead5f2b1123b4b4b13d307d6db035e2c13fe /drivers/iommu
parent61e015ac5b4d46c2054a78d9bc82c840274929a0 (diff)
iommu: Add a function to find an iommu group by id
As IOMMU groups are exposed to the user space by their numbers, the user space can use them in various kernel APIs so the kernel might need an API to find a group by its ID. As an example, QEMU VFIO on PPC64 platform needs it to associate a logical bus number (LIOBN) with a specific IOMMU group in order to support in-kernel handling of DMA map/unmap requests. The patch adds the iommu_group_get_by_id(id) function which performs such search. v2: fixed reference counting. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Acked-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Joerg Roedel <joro@8bytes.org>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/iommu.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b972d430d92b..db01af01ce0a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -204,6 +204,35 @@ again:
204} 204}
205EXPORT_SYMBOL_GPL(iommu_group_alloc); 205EXPORT_SYMBOL_GPL(iommu_group_alloc);
206 206
207struct iommu_group *iommu_group_get_by_id(int id)
208{
209 struct kobject *group_kobj;
210 struct iommu_group *group;
211 const char *name;
212
213 if (!iommu_group_kset)
214 return NULL;
215
216 name = kasprintf(GFP_KERNEL, "%d", id);
217 if (!name)
218 return NULL;
219
220 group_kobj = kset_find_obj(iommu_group_kset, name);
221 kfree(name);
222
223 if (!group_kobj)
224 return NULL;
225
226 group = container_of(group_kobj, struct iommu_group, kobj);
227 BUG_ON(group->id != id);
228
229 kobject_get(group->devices_kobj);
230 kobject_put(&group->kobj);
231
232 return group;
233}
234EXPORT_SYMBOL_GPL(iommu_group_get_by_id);
235
207/** 236/**
208 * iommu_group_get_iommudata - retrieve iommu_data registered for a group 237 * iommu_group_get_iommudata - retrieve iommu_data registered for a group
209 * @group: the group 238 * @group: the group