Commit 4a0b77e7 authored by Pasha Tatashin's avatar Pasha Tatashin Committed by Joerg Roedel

iommu/io-pgtable-dart: use page allocation function provided by iommu-pages.h

Convert iommu/io-pgtable-dart.c to use the new page allocation functions
provided in iommu-pages.h., and remove unnecessary struct io_pgtable_cfg
argument from __dart_alloc_pages().
Signed-off-by: default avatarPasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: default avatarJanne Grunau <j@jannau.net>
Acked-by: default avatarDavid Rientjes <rientjes@google.com>
Tested-by: default avatarBagas Sanjaya <bagasdotme@gmail.com>
Link: https://lore.kernel.org/r/20240413002522.1101315-6-pasha.tatashin@soleen.comSigned-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 9a3dd4c1
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <asm/barrier.h> #include <asm/barrier.h>
#include "iommu-pages.h"
#define DART1_MAX_ADDR_BITS 36 #define DART1_MAX_ADDR_BITS 36
...@@ -106,18 +107,12 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte, ...@@ -106,18 +107,12 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte,
return paddr; return paddr;
} }
static void *__dart_alloc_pages(size_t size, gfp_t gfp, static void *__dart_alloc_pages(size_t size, gfp_t gfp)
struct io_pgtable_cfg *cfg)
{ {
int order = get_order(size); int order = get_order(size);
struct page *p;
VM_BUG_ON((gfp & __GFP_HIGHMEM)); VM_BUG_ON((gfp & __GFP_HIGHMEM));
p = alloc_pages(gfp | __GFP_ZERO, order); return iommu_alloc_pages(gfp, order);
if (!p)
return NULL;
return page_address(p);
} }
static int dart_init_pte(struct dart_io_pgtable *data, static int dart_init_pte(struct dart_io_pgtable *data,
...@@ -262,13 +257,13 @@ static int dart_map_pages(struct io_pgtable_ops *ops, unsigned long iova, ...@@ -262,13 +257,13 @@ static int dart_map_pages(struct io_pgtable_ops *ops, unsigned long iova,
/* no L2 table present */ /* no L2 table present */
if (!pte) { if (!pte) {
cptep = __dart_alloc_pages(tblsz, gfp, cfg); cptep = __dart_alloc_pages(tblsz, gfp);
if (!cptep) if (!cptep)
return -ENOMEM; return -ENOMEM;
pte = dart_install_table(cptep, ptep, 0, data); pte = dart_install_table(cptep, ptep, 0, data);
if (pte) if (pte)
free_pages((unsigned long)cptep, get_order(tblsz)); iommu_free_pages(cptep, get_order(tblsz));
/* L2 table is present (now) */ /* L2 table is present (now) */
pte = READ_ONCE(*ptep); pte = READ_ONCE(*ptep);
...@@ -419,8 +414,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) ...@@ -419,8 +414,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
cfg->apple_dart_cfg.n_ttbrs = 1 << data->tbl_bits; cfg->apple_dart_cfg.n_ttbrs = 1 << data->tbl_bits;
for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) { for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) {
data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL, data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL);
cfg);
if (!data->pgd[i]) if (!data->pgd[i])
goto out_free_data; goto out_free_data;
cfg->apple_dart_cfg.ttbr[i] = virt_to_phys(data->pgd[i]); cfg->apple_dart_cfg.ttbr[i] = virt_to_phys(data->pgd[i]);
...@@ -429,9 +423,10 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) ...@@ -429,9 +423,10 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
return &data->iop; return &data->iop;
out_free_data: out_free_data:
while (--i >= 0) while (--i >= 0) {
free_pages((unsigned long)data->pgd[i], iommu_free_pages(data->pgd[i],
get_order(DART_GRANULE(data))); get_order(DART_GRANULE(data)));
}
kfree(data); kfree(data);
return NULL; return NULL;
} }
...@@ -439,6 +434,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie) ...@@ -439,6 +434,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
static void apple_dart_free_pgtable(struct io_pgtable *iop) static void apple_dart_free_pgtable(struct io_pgtable *iop)
{ {
struct dart_io_pgtable *data = io_pgtable_to_data(iop); struct dart_io_pgtable *data = io_pgtable_to_data(iop);
int order = get_order(DART_GRANULE(data));
dart_iopte *ptep, *end; dart_iopte *ptep, *end;
int i; int i;
...@@ -449,15 +445,10 @@ static void apple_dart_free_pgtable(struct io_pgtable *iop) ...@@ -449,15 +445,10 @@ static void apple_dart_free_pgtable(struct io_pgtable *iop)
while (ptep != end) { while (ptep != end) {
dart_iopte pte = *ptep++; dart_iopte pte = *ptep++;
if (pte) { if (pte)
unsigned long page = iommu_free_pages(iopte_deref(pte, data), order);
(unsigned long)iopte_deref(pte, data);
free_pages(page, get_order(DART_GRANULE(data)));
}
} }
free_pages((unsigned long)data->pgd[i], iommu_free_pages(data->pgd[i], order);
get_order(DART_GRANULE(data)));
} }
kfree(data); kfree(data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment