Skip to content

Commit 541b967

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Refactor __iommu_domain_alloc()
Following patch will introduce iommu_paging_domain_alloc_flags() API. Hence move domain init code to separate function so that it can be reused. Also move iommu_get_dma_cookie() setup iommu_setup_default_domain() as it is required in DMA API mode only. Signed-off-by: Jason Gunthorpe <[email protected]> [Split the patch and added description - Vasant] Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Yi Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent f6440fc commit 541b967

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

drivers/iommu/iommu.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,22 @@ void iommu_set_fault_handler(struct iommu_domain *domain,
19051905
}
19061906
EXPORT_SYMBOL_GPL(iommu_set_fault_handler);
19071907

1908+
static void iommu_domain_init(struct iommu_domain *domain, unsigned int type,
1909+
const struct iommu_ops *ops)
1910+
{
1911+
domain->type = type;
1912+
domain->owner = ops;
1913+
if (!domain->ops)
1914+
domain->ops = ops->default_domain_ops;
1915+
1916+
/*
1917+
* If not already set, assume all sizes by default; the driver
1918+
* may override this later
1919+
*/
1920+
if (!domain->pgsize_bitmap)
1921+
domain->pgsize_bitmap = ops->pgsize_bitmap;
1922+
}
1923+
19081924
static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
19091925
struct device *dev,
19101926
unsigned int type)
@@ -1933,27 +1949,7 @@ static struct iommu_domain *__iommu_domain_alloc(const struct iommu_ops *ops,
19331949
if (!domain)
19341950
return ERR_PTR(-ENOMEM);
19351951

1936-
domain->type = type;
1937-
domain->owner = ops;
1938-
/*
1939-
* If not already set, assume all sizes by default; the driver
1940-
* may override this later
1941-
*/
1942-
if (!domain->pgsize_bitmap)
1943-
domain->pgsize_bitmap = ops->pgsize_bitmap;
1944-
1945-
if (!domain->ops)
1946-
domain->ops = ops->default_domain_ops;
1947-
1948-
if (iommu_is_dma_domain(domain)) {
1949-
int rc;
1950-
1951-
rc = iommu_get_dma_cookie(domain);
1952-
if (rc) {
1953-
iommu_domain_free(domain);
1954-
return ERR_PTR(rc);
1955-
}
1956-
}
1952+
iommu_domain_init(domain, type, ops);
19571953
return domain;
19581954
}
19591955

@@ -2900,6 +2896,14 @@ static int iommu_setup_default_domain(struct iommu_group *group,
29002896
if (group->default_domain == dom)
29012897
return 0;
29022898

2899+
if (iommu_is_dma_domain(dom)) {
2900+
ret = iommu_get_dma_cookie(dom);
2901+
if (ret) {
2902+
iommu_domain_free(dom);
2903+
return ret;
2904+
}
2905+
}
2906+
29032907
/*
29042908
* IOMMU_RESV_DIRECT and IOMMU_RESV_DIRECT_RELAXABLE regions must be
29052909
* mapped before their device is attached, in order to guarantee

0 commit comments

Comments
 (0)