mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-06 13:23:18 +00:00
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 <pasha.tatashin@soleen.com> Reviewed-by: Janne Grunau <j@jannau.net> Acked-by: David Rientjes <rientjes@google.com> Tested-by: Bagas Sanjaya <bagasdotme@gmail.com> Link: https://lore.kernel.org/r/20240413002522.1101315-6-pasha.tatashin@soleen.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
9a3dd4c1ee
commit
4a0b77e7c8
@ -23,6 +23,7 @@
|
||||
#include <linux/types.h>
|
||||
|
||||
#include <asm/barrier.h>
|
||||
#include "iommu-pages.h"
|
||||
|
||||
#define DART1_MAX_ADDR_BITS 36
|
||||
|
||||
@ -106,18 +107,12 @@ static phys_addr_t iopte_to_paddr(dart_iopte pte,
|
||||
return paddr;
|
||||
}
|
||||
|
||||
static void *__dart_alloc_pages(size_t size, gfp_t gfp,
|
||||
struct io_pgtable_cfg *cfg)
|
||||
static void *__dart_alloc_pages(size_t size, gfp_t gfp)
|
||||
{
|
||||
int order = get_order(size);
|
||||
struct page *p;
|
||||
|
||||
VM_BUG_ON((gfp & __GFP_HIGHMEM));
|
||||
p = alloc_pages(gfp | __GFP_ZERO, order);
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
return page_address(p);
|
||||
return iommu_alloc_pages(gfp, order);
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
/* no L2 table present */
|
||||
if (!pte) {
|
||||
cptep = __dart_alloc_pages(tblsz, gfp, cfg);
|
||||
cptep = __dart_alloc_pages(tblsz, gfp);
|
||||
if (!cptep)
|
||||
return -ENOMEM;
|
||||
|
||||
pte = dart_install_table(cptep, ptep, 0, data);
|
||||
if (pte)
|
||||
free_pages((unsigned long)cptep, get_order(tblsz));
|
||||
iommu_free_pages(cptep, get_order(tblsz));
|
||||
|
||||
/* L2 table is present (now) */
|
||||
pte = READ_ONCE(*ptep);
|
||||
@ -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;
|
||||
|
||||
for (i = 0; i < cfg->apple_dart_cfg.n_ttbrs; ++i) {
|
||||
data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL,
|
||||
cfg);
|
||||
data->pgd[i] = __dart_alloc_pages(DART_GRANULE(data), GFP_KERNEL);
|
||||
if (!data->pgd[i])
|
||||
goto out_free_data;
|
||||
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)
|
||||
return &data->iop;
|
||||
|
||||
out_free_data:
|
||||
while (--i >= 0)
|
||||
free_pages((unsigned long)data->pgd[i],
|
||||
get_order(DART_GRANULE(data)));
|
||||
while (--i >= 0) {
|
||||
iommu_free_pages(data->pgd[i],
|
||||
get_order(DART_GRANULE(data)));
|
||||
}
|
||||
kfree(data);
|
||||
return NULL;
|
||||
}
|
||||
@ -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)
|
||||
{
|
||||
struct dart_io_pgtable *data = io_pgtable_to_data(iop);
|
||||
int order = get_order(DART_GRANULE(data));
|
||||
dart_iopte *ptep, *end;
|
||||
int i;
|
||||
|
||||
@ -449,15 +445,10 @@ static void apple_dart_free_pgtable(struct io_pgtable *iop)
|
||||
while (ptep != end) {
|
||||
dart_iopte pte = *ptep++;
|
||||
|
||||
if (pte) {
|
||||
unsigned long page =
|
||||
(unsigned long)iopte_deref(pte, data);
|
||||
|
||||
free_pages(page, get_order(DART_GRANULE(data)));
|
||||
}
|
||||
if (pte)
|
||||
iommu_free_pages(iopte_deref(pte, data), order);
|
||||
}
|
||||
free_pages((unsigned long)data->pgd[i],
|
||||
get_order(DART_GRANULE(data)));
|
||||
iommu_free_pages(data->pgd[i], order);
|
||||
}
|
||||
|
||||
kfree(data);
|
||||
|
Loading…
Reference in New Issue
Block a user