Skip to content

Commit 4a0b77e

Browse files
soleenjoergroedel
authored andcommitted
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: Pasha Tatashin <[email protected]> Reviewed-by: Janne Grunau <[email protected]> Acked-by: David Rientjes <[email protected]> Tested-by: Bagas Sanjaya <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9a3dd4c commit 4a0b77e

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

drivers/iommu/io-pgtable-dart.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/types.h>
2424

2525
#include <asm/barrier.h>
26+
#include "iommu-pages.h"
2627

2728
#define DART1_MAX_ADDR_BITS 36
2829

@@ -106,18 +107,12 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte,
106107
return paddr;
107108
}
108109

109-
static void *__dart_alloc_pages(size_t size, gfp_t gfp,
110-
struct io_pgtable_cfg *cfg)
110+
static void *__dart_alloc_pages(size_t size, gfp_t gfp)
111111
{
112112
int order = get_order(size);
113-
struct page *p;
114113

115114
VM_BUG_ON((gfp & __GFP_HIGHMEM));
116-
p = alloc_pages(gfp | __GFP_ZERO, order);
117-
if (!p)
118-
return NULL;
119-
120-
return page_address(p);
115+
return iommu_alloc_pages(gfp, order);
121116
}
122117

123118
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,
262257

263258
/* no L2 table present */
264259
if (!pte) {
265-
cptep = __dart_alloc_pages(tblsz, gfp, cfg);
260+
cptep = __dart_alloc_pages(tblsz, gfp);
266261
if (!cptep)
267262
return -ENOMEM;
268263

269264
pte = dart_install_table(cptep, ptep, 0, data);
270265
if (pte)
271-
free_pages((unsigned long)cptep, get_order(tblsz));
266+
iommu_free_pages(cptep, get_order(tblsz));
272267

273268
/* L2 table is present (now) */
274269
pte = READ_ONCE(*ptep);
@@ -419,8 +414,7 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
419414
cfg->apple_dart_cfg.n_ttbrs = 1 << data->tbl_bits;
420415

421416
for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) {
422-
data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL,
423-
cfg);
417+
data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL);
424418
if (!data->pgd[i])
425419
goto out_free_data;
426420
cfg->apple_dart_cfg.ttbr[i] = virt_to_phys(data->pgd[i]);
@@ -429,16 +423,18 @@ apple_dart_alloc_pgtable(struct io_pgtable_cfg *cfg, void *cookie)
429423
return &data->iop;
430424

431425
out_free_data:
432-
while (--i >= 0)
433-
free_pages((unsigned long)data->pgd[i],
434-
get_order(DART_GRANULE(data)));
426+
while (--i >= 0) {
427+
iommu_free_pages(data->pgd[i],
428+
get_order(DART_GRANULE(data)));
429+
}
435430
kfree(data);
436431
return NULL;
437432
}
438433

439434
static void apple_dart_free_pgtable(struct io_pgtable *iop)
440435
{
441436
struct dart_io_pgtable *data = io_pgtable_to_data(iop);
437+
int order = get_order(DART_GRANULE(data));
442438
dart_iopte *ptep, *end;
443439
int i;
444440

@@ -449,15 +445,10 @@ static void apple_dart_free_pgtable(struct io_pgtable *iop)
449445
while (ptep != end) {
450446
dart_iopte pte = *ptep++;
451447

452-
if (pte) {
453-
unsigned long page =
454-
(unsigned long)iopte_deref(pte, data);
455-
456-
free_pages(page, get_order(DART_GRANULE(data)));
457-
}
448+
if (pte)
449+
iommu_free_pages(iopte_deref(pte, data), order);
458450
}
459-
free_pages((unsigned long)data->pgd[i],
460-
get_order(DART_GRANULE(data)));
451+
iommu_free_pages(data->pgd[i], order);
461452
}
462453

463454
kfree(data);

0 commit comments

Comments
 (0)