Message ID | 21-v3-e797f4dc6918+93057-iommu_pages_jgg@nvidia.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | iommu: Further abstract iommu-pages | expand |
On 25.02.2025 20:39, Jason Gunthorpe wrote: > A few small changes to the remaining drivers using these will allow > them to be removed: > > - Exynos wants to allocate fixed 16K/8K allocations > - Rockchip already has a define SPAGE_SIZE which is used by the > dma_map immediately following, using SPAGE_ORDER which is a lg2size > - tegra has size constants already for its two allocations > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> For exynos-iommu: Acked-by: Marek Szyprowski <m.szyprowski@samsung.com> > --- > drivers/iommu/exynos-iommu.c | 4 ++-- > drivers/iommu/iommu-pages.h | 26 -------------------------- > drivers/iommu/rockchip-iommu.c | 6 ++++-- > drivers/iommu/tegra-smmu.c | 4 ++-- > 4 files changed, 8 insertions(+), 32 deletions(-) > > diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c > index 1019e08b43b71c..74337081278551 100644 > --- a/drivers/iommu/exynos-iommu.c > +++ b/drivers/iommu/exynos-iommu.c > @@ -902,11 +902,11 @@ static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev) > if (!domain) > return NULL; > > - domain->pgtable = iommu_alloc_pages(GFP_KERNEL, 2); > + domain->pgtable = iommu_alloc_pages_sz(GFP_KERNEL, SZ_16K); > if (!domain->pgtable) > goto err_pgtable; > > - domain->lv2entcnt = iommu_alloc_pages(GFP_KERNEL, 1); > + domain->lv2entcnt = iommu_alloc_pages_sz(GFP_KERNEL, SZ_8K); > if (!domain->lv2entcnt) > goto err_counter; > > diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h > index 3c4575d637da6d..4513fbc76260cd 100644 > --- a/drivers/iommu/iommu-pages.h > +++ b/drivers/iommu/iommu-pages.h > @@ -100,20 +100,6 @@ static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, > return iommu_alloc_pages_node_sz(nid, gfp, 1 << (order + PAGE_SHIFT)); > } > > -/** > - * iommu_alloc_pages - allocate a zeroed page of a given order > - * @gfp: buddy allocator flags > - * @order: page order > - * > - * returns the virtual address of the allocated page > - * Prefer to use iommu_alloc_pages_lg2() > - */ > -static inline void *iommu_alloc_pages(gfp_t gfp, int order) > -{ > - return iommu_alloc_pages_node_sz(NUMA_NO_NODE, gfp, > - 1 << (order + PAGE_SHIFT)); > -} > - > /** > * iommu_alloc_pages_sz - Allocate a zeroed page of a given size from > * specific NUMA node > @@ -141,16 +127,4 @@ static inline void *iommu_alloc_page_node(int nid, gfp_t gfp) > return iommu_alloc_pages_node_sz(nid, gfp, PAGE_SIZE); > } > > -/** > - * iommu_alloc_page - allocate a zeroed page > - * @gfp: buddy allocator flags > - * > - * returns the virtual address of the allocated page > - * Prefer to use iommu_alloc_pages_lg2() > - */ > -static inline void *iommu_alloc_page(gfp_t gfp) > -{ > - return iommu_alloc_pages_node_sz(NUMA_NO_NODE, gfp, PAGE_SIZE); > -} > - > #endif /* __IOMMU_PAGES_H */ > diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c > index 798e85bd994d56..5af82072b03a17 100644 > --- a/drivers/iommu/rockchip-iommu.c > +++ b/drivers/iommu/rockchip-iommu.c > @@ -730,7 +730,8 @@ static u32 *rk_dte_get_page_table(struct rk_iommu_domain *rk_domain, > if (rk_dte_is_pt_valid(dte)) > goto done; > > - page_table = iommu_alloc_page(GFP_ATOMIC | rk_ops->gfp_flags); > + page_table = iommu_alloc_pages_sz(GFP_ATOMIC | rk_ops->gfp_flags, > + SPAGE_SIZE); > if (!page_table) > return ERR_PTR(-ENOMEM); > > @@ -1064,7 +1065,8 @@ static struct iommu_domain *rk_iommu_domain_alloc_paging(struct device *dev) > * Each level1 (dt) and level2 (pt) table has 1024 4-byte entries. > * Allocate one 4 KiB page for each table. > */ > - rk_domain->dt = iommu_alloc_page(GFP_KERNEL | rk_ops->gfp_flags); > + rk_domain->dt = iommu_alloc_pages_sz(GFP_KERNEL | rk_ops->gfp_flags, > + SPAGE_SIZE); > if (!rk_domain->dt) > goto err_free_domain; > > diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c > index 844682a41afa66..a9c35efde56969 100644 > --- a/drivers/iommu/tegra-smmu.c > +++ b/drivers/iommu/tegra-smmu.c > @@ -295,7 +295,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) > > as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE; > > - as->pd = iommu_alloc_page(GFP_KERNEL | __GFP_DMA); > + as->pd = iommu_alloc_pages_sz(GFP_KERNEL | __GFP_DMA, SMMU_SIZE_PD); > if (!as->pd) { > kfree(as); > return NULL; > @@ -695,7 +695,7 @@ static struct tegra_pt *as_get_pde_page(struct tegra_smmu_as *as, > if (gfpflags_allow_blocking(gfp)) > spin_unlock_irqrestore(&as->lock, *flags); > > - pt = iommu_alloc_page(gfp | __GFP_DMA); > + pt = iommu_alloc_pages_sz(gfp | __GFP_DMA, SMMU_SIZE_PT); > > if (gfpflags_allow_blocking(gfp)) > spin_lock_irqsave(&as->lock, *flags); Best regards
diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 1019e08b43b71c..74337081278551 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -902,11 +902,11 @@ static struct iommu_domain *exynos_iommu_domain_alloc_paging(struct device *dev) if (!domain) return NULL; - domain->pgtable = iommu_alloc_pages(GFP_KERNEL, 2); + domain->pgtable = iommu_alloc_pages_sz(GFP_KERNEL, SZ_16K); if (!domain->pgtable) goto err_pgtable; - domain->lv2entcnt = iommu_alloc_pages(GFP_KERNEL, 1); + domain->lv2entcnt = iommu_alloc_pages_sz(GFP_KERNEL, SZ_8K); if (!domain->lv2entcnt) goto err_counter; diff --git a/drivers/iommu/iommu-pages.h b/drivers/iommu/iommu-pages.h index 3c4575d637da6d..4513fbc76260cd 100644 --- a/drivers/iommu/iommu-pages.h +++ b/drivers/iommu/iommu-pages.h @@ -100,20 +100,6 @@ static inline void *iommu_alloc_pages_node(int nid, gfp_t gfp, return iommu_alloc_pages_node_sz(nid, gfp, 1 << (order + PAGE_SHIFT)); } -/** - * iommu_alloc_pages - allocate a zeroed page of a given order - * @gfp: buddy allocator flags - * @order: page order - * - * returns the virtual address of the allocated page - * Prefer to use iommu_alloc_pages_lg2() - */ -static inline void *iommu_alloc_pages(gfp_t gfp, int order) -{ - return iommu_alloc_pages_node_sz(NUMA_NO_NODE, gfp, - 1 << (order + PAGE_SHIFT)); -} - /** * iommu_alloc_pages_sz - Allocate a zeroed page of a given size from * specific NUMA node @@ -141,16 +127,4 @@ static inline void *iommu_alloc_page_node(int nid, gfp_t gfp) return iommu_alloc_pages_node_sz(nid, gfp, PAGE_SIZE); } -/** - * iommu_alloc_page - allocate a zeroed page - * @gfp: buddy allocator flags - * - * returns the virtual address of the allocated page - * Prefer to use iommu_alloc_pages_lg2() - */ -static inline void *iommu_alloc_page(gfp_t gfp) -{ - return iommu_alloc_pages_node_sz(NUMA_NO_NODE, gfp, PAGE_SIZE); -} - #endif /* __IOMMU_PAGES_H */ diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 798e85bd994d56..5af82072b03a17 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -730,7 +730,8 @@ static u32 *rk_dte_get_page_table(struct rk_iommu_domain *rk_domain, if (rk_dte_is_pt_valid(dte)) goto done; - page_table = iommu_alloc_page(GFP_ATOMIC | rk_ops->gfp_flags); + page_table = iommu_alloc_pages_sz(GFP_ATOMIC | rk_ops->gfp_flags, + SPAGE_SIZE); if (!page_table) return ERR_PTR(-ENOMEM); @@ -1064,7 +1065,8 @@ static struct iommu_domain *rk_iommu_domain_alloc_paging(struct device *dev) * Each level1 (dt) and level2 (pt) table has 1024 4-byte entries. * Allocate one 4 KiB page for each table. */ - rk_domain->dt = iommu_alloc_page(GFP_KERNEL | rk_ops->gfp_flags); + rk_domain->dt = iommu_alloc_pages_sz(GFP_KERNEL | rk_ops->gfp_flags, + SPAGE_SIZE); if (!rk_domain->dt) goto err_free_domain; diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 844682a41afa66..a9c35efde56969 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -295,7 +295,7 @@ static struct iommu_domain *tegra_smmu_domain_alloc_paging(struct device *dev) as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE; - as->pd = iommu_alloc_page(GFP_KERNEL | __GFP_DMA); + as->pd = iommu_alloc_pages_sz(GFP_KERNEL | __GFP_DMA, SMMU_SIZE_PD); if (!as->pd) { kfree(as); return NULL; @@ -695,7 +695,7 @@ static struct tegra_pt *as_get_pde_page(struct tegra_smmu_as *as, if (gfpflags_allow_blocking(gfp)) spin_unlock_irqrestore(&as->lock, *flags); - pt = iommu_alloc_page(gfp | __GFP_DMA); + pt = iommu_alloc_pages_sz(gfp | __GFP_DMA, SMMU_SIZE_PT); if (gfpflags_allow_blocking(gfp)) spin_lock_irqsave(&as->lock, *flags);
A few small changes to the remaining drivers using these will allow them to be removed: - Exynos wants to allocate fixed 16K/8K allocations - Rockchip already has a define SPAGE_SIZE which is used by the dma_map immediately following, using SPAGE_ORDER which is a lg2size - tegra has size constants already for its two allocations Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> --- drivers/iommu/exynos-iommu.c | 4 ++-- drivers/iommu/iommu-pages.h | 26 -------------------------- drivers/iommu/rockchip-iommu.c | 6 ++++-- drivers/iommu/tegra-smmu.c | 4 ++-- 4 files changed, 8 insertions(+), 32 deletions(-)