qcom-io-pgtable-arm: Implement the unmap_pages() callback
Implement the unmap_pages() for the qcom-io-pgtable-arm format code. Change-Id: I2e94b25c736cdc5ee1346941f986c5ddeca30ba4 Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
This commit is contained in:
@@ -47,6 +47,9 @@
|
|||||||
#define ARM_LPAE_PGD_SIZE(d) \
|
#define ARM_LPAE_PGD_SIZE(d) \
|
||||||
(sizeof(arm_lpae_iopte) << (d)->pgd_bits)
|
(sizeof(arm_lpae_iopte) << (d)->pgd_bits)
|
||||||
|
|
||||||
|
#define ARM_LPAE_PTES_PER_TABLE(d) \
|
||||||
|
(ARM_LPAE_GRANULE(d) >> ilog2(sizeof(arm_lpae_iopte)))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate the index at level l used to map virtual address a using the
|
* Calculate the index at level l used to map virtual address a using the
|
||||||
* pagetable in d.
|
* pagetable in d.
|
||||||
@@ -323,8 +326,8 @@ static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte,
|
|||||||
|
|
||||||
static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
|
static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
|
||||||
struct iommu_iotlb_gather *gather,
|
struct iommu_iotlb_gather *gather,
|
||||||
unsigned long iova, size_t size, int lvl,
|
unsigned long iova, size_t size, size_t pgcount,
|
||||||
arm_lpae_iopte *ptep);
|
int lvl, arm_lpae_iopte *ptep);
|
||||||
|
|
||||||
static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data,
|
static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data,
|
||||||
phys_addr_t paddr, arm_lpae_iopte prot,
|
phys_addr_t paddr, arm_lpae_iopte prot,
|
||||||
@@ -800,14 +803,15 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data,
|
|||||||
struct iommu_iotlb_gather *gather,
|
struct iommu_iotlb_gather *gather,
|
||||||
unsigned long iova, size_t size,
|
unsigned long iova, size_t size,
|
||||||
arm_lpae_iopte blk_pte, int lvl,
|
arm_lpae_iopte blk_pte, int lvl,
|
||||||
arm_lpae_iopte *ptep)
|
arm_lpae_iopte *ptep, size_t pgcount)
|
||||||
{
|
{
|
||||||
struct io_pgtable_cfg *cfg = &data->iop.cfg;
|
struct io_pgtable_cfg *cfg = &data->iop.cfg;
|
||||||
arm_lpae_iopte pte, *tablep;
|
arm_lpae_iopte pte, *tablep;
|
||||||
phys_addr_t blk_paddr;
|
phys_addr_t blk_paddr;
|
||||||
size_t tablesz = ARM_LPAE_GRANULE(data);
|
size_t tablesz = ARM_LPAE_GRANULE(data);
|
||||||
size_t split_sz = ARM_LPAE_BLOCK_SIZE(lvl, data);
|
size_t split_sz = ARM_LPAE_BLOCK_SIZE(lvl, data);
|
||||||
int i, unmap_idx = -1;
|
int ptes_per_table = ARM_LPAE_PTES_PER_TABLE(data);
|
||||||
|
int i, unmap_idx_start = -1, num_entries = 0, max_entries;
|
||||||
void *cookie = data->iop.cookie;
|
void *cookie = data->iop.cookie;
|
||||||
int child_cnt = 0;
|
int child_cnt = 0;
|
||||||
|
|
||||||
@@ -818,15 +822,18 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data,
|
|||||||
if (!tablep)
|
if (!tablep)
|
||||||
return 0; /* Bytes unmapped */
|
return 0; /* Bytes unmapped */
|
||||||
|
|
||||||
if (size == split_sz)
|
if (size == split_sz) {
|
||||||
unmap_idx = ARM_LPAE_LVL_IDX(iova, lvl, data);
|
unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data);
|
||||||
|
max_entries = ptes_per_table - unmap_idx_start;
|
||||||
|
num_entries = min_t(int, pgcount, max_entries);
|
||||||
|
}
|
||||||
|
|
||||||
blk_paddr = iopte_to_paddr(blk_pte, data);
|
blk_paddr = iopte_to_paddr(blk_pte, data);
|
||||||
pte = iopte_prot(blk_pte);
|
pte = iopte_prot(blk_pte);
|
||||||
|
|
||||||
for (i = 0; i < tablesz / sizeof(pte); i++, blk_paddr += split_sz) {
|
for (i = 0; i < ptes_per_table; i++, blk_paddr += split_sz) {
|
||||||
/* Unmap! */
|
/* Unmap! */
|
||||||
if (i == unmap_idx)
|
if (i >= unmap_idx_start && i < (unmap_idx_start + num_entries))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
__arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i], true);
|
__arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i], true);
|
||||||
@@ -845,33 +852,38 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
tablep = iopte_deref(pte, data);
|
tablep = iopte_deref(pte, data);
|
||||||
} else if (unmap_idx >= 0) {
|
} else if (unmap_idx_start >= 0) {
|
||||||
return size;
|
return num_entries * size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return __arm_lpae_unmap(data, gather, iova, size, lvl, tablep);
|
return __arm_lpae_unmap(data, gather, iova, size, pgcount, lvl, tablep);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
|
static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
|
||||||
struct iommu_iotlb_gather *gather,
|
struct iommu_iotlb_gather *gather,
|
||||||
unsigned long iova, size_t size, int lvl,
|
unsigned long iova, size_t size, size_t pgcount,
|
||||||
arm_lpae_iopte *ptep)
|
int lvl, arm_lpae_iopte *ptep)
|
||||||
{
|
{
|
||||||
arm_lpae_iopte pte;
|
arm_lpae_iopte pte;
|
||||||
struct io_pgtable *iop = &data->iop;
|
struct io_pgtable *iop = &data->iop;
|
||||||
|
int ptes_per_table = ARM_LPAE_PTES_PER_TABLE(data);
|
||||||
|
int num_entries, max_entries, unmap_idx_start;
|
||||||
|
|
||||||
/* Something went horribly wrong and we ran out of page table */
|
/* Something went horribly wrong and we ran out of page table */
|
||||||
if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS))
|
if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ptep += ARM_LPAE_LVL_IDX(iova, lvl, data);
|
unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data);
|
||||||
|
ptep += unmap_idx_start;
|
||||||
pte = READ_ONCE(*ptep);
|
pte = READ_ONCE(*ptep);
|
||||||
if (WARN_ON(!pte))
|
if (WARN_ON(!pte))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* If the size matches this level, we're in the right place */
|
/* If the size matches this level, we're in the right place */
|
||||||
if (size == ARM_LPAE_BLOCK_SIZE(lvl, data)) {
|
if (size == ARM_LPAE_BLOCK_SIZE(lvl, data)) {
|
||||||
__arm_lpae_set_pte(ptep, 0, 1, &iop->cfg);
|
max_entries = ptes_per_table - unmap_idx_start;
|
||||||
|
num_entries = min_t(int, pgcount, max_entries);
|
||||||
|
__arm_lpae_set_pte(ptep, 0, num_entries, &iop->cfg);
|
||||||
|
|
||||||
if (!iopte_leaf(pte, lvl, iop->fmt)) {
|
if (!iopte_leaf(pte, lvl, iop->fmt)) {
|
||||||
ptep = iopte_deref(pte, data);
|
ptep = iopte_deref(pte, data);
|
||||||
@@ -885,15 +897,17 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
|
|||||||
smp_wmb();
|
smp_wmb();
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return num_entries * size;
|
||||||
} else if ((lvl == ARM_LPAE_MAX_LEVELS - 2) && !iopte_leaf(pte, lvl,
|
} else if ((lvl == ARM_LPAE_MAX_LEVELS - 2) && !iopte_leaf(pte, lvl,
|
||||||
iop->fmt)) {
|
iop->fmt)) {
|
||||||
arm_lpae_iopte *table = iopte_deref(pte, data);
|
arm_lpae_iopte *table = iopte_deref(pte, data);
|
||||||
arm_lpae_iopte *entry = table + ARM_LPAE_LVL_IDX(iova, lvl + 1, data);
|
arm_lpae_iopte *entry = table + ARM_LPAE_LVL_IDX(iova, lvl + 1, data);
|
||||||
|
|
||||||
__arm_lpae_set_pte(entry, 0, 1, &iop->cfg);
|
max_entries = ptes_per_table - unmap_idx_start;
|
||||||
|
num_entries = min_t(int, pgcount, max_entries);
|
||||||
|
__arm_lpae_set_pte(entry, 0, num_entries, &iop->cfg);
|
||||||
|
|
||||||
iopte_tblcnt_sub(ptep, 1);
|
iopte_tblcnt_sub(ptep, num_entries);
|
||||||
if (!iopte_tblcnt(*ptep)) {
|
if (!iopte_tblcnt(*ptep)) {
|
||||||
size_t block_size = ARM_LPAE_BLOCK_SIZE(lvl, data);
|
size_t block_size = ARM_LPAE_BLOCK_SIZE(lvl, data);
|
||||||
/*
|
/*
|
||||||
@@ -909,32 +923,33 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
|
|||||||
block_size);
|
block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return num_entries * size;
|
||||||
} else if (iopte_leaf(pte, lvl, iop->fmt)) {
|
} else if (iopte_leaf(pte, lvl, iop->fmt)) {
|
||||||
/*
|
/*
|
||||||
* Insert a table at the next level to map the old region,
|
* Insert a table at the next level to map the old region,
|
||||||
* minus the part we want to unmap
|
* minus the part we want to unmap
|
||||||
*/
|
*/
|
||||||
return arm_lpae_split_blk_unmap(data, gather, iova, size, pte,
|
return arm_lpae_split_blk_unmap(data, gather, iova, size, pte,
|
||||||
lvl + 1, ptep);
|
lvl + 1, ptep, pgcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep on walkin' */
|
/* Keep on walkin' */
|
||||||
ptep = iopte_deref(pte, data);
|
ptep = iopte_deref(pte, data);
|
||||||
return __arm_lpae_unmap(data, gather, iova, size, lvl + 1, ptep);
|
return __arm_lpae_unmap(data, gather, iova, size, pgcount, lvl + 1, ptep);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t arm_lpae_unmap(struct io_pgtable_ops *ops, unsigned long iova,
|
static size_t arm_lpae_unmap_pages(struct io_pgtable_ops *ops, unsigned long iova,
|
||||||
size_t size, struct iommu_iotlb_gather *gather)
|
size_t pgsize, size_t pgcount,
|
||||||
|
struct iommu_iotlb_gather *gather)
|
||||||
{
|
{
|
||||||
struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops);
|
struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops);
|
||||||
struct io_pgtable_cfg *cfg = &data->iop.cfg;
|
struct io_pgtable_cfg *cfg = &data->iop.cfg;
|
||||||
arm_lpae_iopte *ptep = data->pgd;
|
arm_lpae_iopte *ptep = data->pgd;
|
||||||
long iaext = (s64)iova >> cfg->ias;
|
long iaext = (s64)iova >> cfg->ias;
|
||||||
|
size_t unmapped;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
size_t ret;
|
|
||||||
|
|
||||||
if (WARN_ON(!size || (size & cfg->pgsize_bitmap) != size))
|
if (WARN_ON(!pgsize || (pgsize & cfg->pgsize_bitmap) != pgsize || !pgcount))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1)
|
if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1)
|
||||||
@@ -943,9 +958,17 @@ static size_t arm_lpae_unmap(struct io_pgtable_ops *ops, unsigned long iova,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
spin_lock_irqsave(&data->lock, flags);
|
spin_lock_irqsave(&data->lock, flags);
|
||||||
ret = __arm_lpae_unmap(data, gather, iova, size, data->start_level, ptep);
|
unmapped = __arm_lpae_unmap(data, gather, iova, pgsize, pgcount,
|
||||||
|
data->start_level, ptep);
|
||||||
spin_unlock_irqrestore(&data->lock, flags);
|
spin_unlock_irqrestore(&data->lock, flags);
|
||||||
return ret;
|
|
||||||
|
return unmapped;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t arm_lpae_unmap(struct io_pgtable_ops *ops, unsigned long iova,
|
||||||
|
size_t size, struct iommu_iotlb_gather *gather)
|
||||||
|
{
|
||||||
|
return arm_lpae_unmap_pages(ops, iova, size, 1, gather);
|
||||||
}
|
}
|
||||||
|
|
||||||
static phys_addr_t arm_lpae_iova_to_phys(struct io_pgtable_ops *ops,
|
static phys_addr_t arm_lpae_iova_to_phys(struct io_pgtable_ops *ops,
|
||||||
@@ -1068,6 +1091,7 @@ arm_lpae_alloc_pgtable(struct io_pgtable_cfg *cfg)
|
|||||||
.map = arm_lpae_map,
|
.map = arm_lpae_map,
|
||||||
.map_sg = arm_lpae_map_sg,
|
.map_sg = arm_lpae_map_sg,
|
||||||
.unmap = arm_lpae_unmap,
|
.unmap = arm_lpae_unmap,
|
||||||
|
.unmap_pages = arm_lpae_unmap_pages,
|
||||||
.iova_to_phys = arm_lpae_iova_to_phys,
|
.iova_to_phys = arm_lpae_iova_to_phys,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user