Skip to content

Commit c52c72d

Browse files
olofjjoergroedel
authored andcommitted
iommu: Add sysfs attribyte for domain type
While we could print it at setup time, this is an easier way to match each device to their default IOMMU allocation type. Signed-off-by: Olof Johansson <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent 7d0f5fd commit c52c72d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/iommu/iommu.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,39 @@ static ssize_t iommu_group_show_resv_regions(struct iommu_group *group,
294294
return (str - buf);
295295
}
296296

297+
static ssize_t iommu_group_show_type(struct iommu_group *group,
298+
char *buf)
299+
{
300+
char *type = "unknown\n";
301+
302+
if (group->default_domain) {
303+
switch (group->default_domain->type) {
304+
case IOMMU_DOMAIN_BLOCKED:
305+
type = "blocked\n";
306+
break;
307+
case IOMMU_DOMAIN_IDENTITY:
308+
type = "identity\n";
309+
break;
310+
case IOMMU_DOMAIN_UNMANAGED:
311+
type = "unmanaged\n";
312+
break;
313+
case IOMMU_DOMAIN_DMA:
314+
type = "DMA";
315+
break;
316+
}
317+
}
318+
strcpy(buf, type);
319+
320+
return strlen(type);
321+
}
322+
297323
static IOMMU_GROUP_ATTR(name, S_IRUGO, iommu_group_show_name, NULL);
298324

299325
static IOMMU_GROUP_ATTR(reserved_regions, 0444,
300326
iommu_group_show_resv_regions, NULL);
301327

328+
static IOMMU_GROUP_ATTR(type, 0444, iommu_group_show_type, NULL);
329+
302330
static void iommu_group_release(struct kobject *kobj)
303331
{
304332
struct iommu_group *group = to_iommu_group(kobj);
@@ -380,6 +408,10 @@ struct iommu_group *iommu_group_alloc(void)
380408
if (ret)
381409
return ERR_PTR(ret);
382410

411+
ret = iommu_group_create_file(group, &iommu_group_attr_type);
412+
if (ret)
413+
return ERR_PTR(ret);
414+
383415
pr_debug("Allocated group %d\n", group->id);
384416

385417
return group;

0 commit comments

Comments
 (0)