Skip to content

Commit b4d79ec

Browse files
iommu: bcm2712-iommu: Map and unmap multiple pages in a single call
For efficiency, the map_pages() and unmap_pages() calls now pay attention to their "count" argument, at least in successful cases. Fix a bugette where we omitted to set mapped to 0 in case of error. Minor style fix. Signed-off-by: Nick Hollinghurst <[email protected]>
1 parent abb8043 commit b4d79ec

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/iommu/bcm2712-iommu.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ static int bcm2712_iommu_map(struct iommu_domain *domain, unsigned long iova,
265265
mmu->dirty = true;
266266
}
267267

268+
/* Make iova relative to table base; amalgamate count pages */
268269
iova -= APERTURE_BASE;
270+
bytes = min(APERTURE_SIZE - iova, count * bytes);
271+
272+
/* Iterate over table by smallest native IOMMU page size */
269273
for (p = iova >> MMU_PAGE_SHIFT;
270274
p < (iova + bytes) >> MMU_PAGE_SHIFT; p++) {
271275
mmu->nmapped_pages += !(mmu->tables[p]);
@@ -275,6 +279,8 @@ static int bcm2712_iommu_map(struct iommu_domain *domain, unsigned long iova,
275279
dev_warn(mmu->dev, "%s: iova=0x%lx pa=0x%llx size=0x%llx OUT OF RANGE!\n",
276280
__func__, iova,
277281
(unsigned long long)pa, (unsigned long long)bytes);
282+
*mapped = 0;
283+
278284
return -EINVAL;
279285
}
280286
*mapped = bytes;
@@ -308,8 +314,11 @@ static size_t bcm2712_iommu_unmap(struct iommu_domain *domain, unsigned long iov
308314
mmu->dirty = true;
309315
}
310316

311-
/* Clear table entries, this marks the addresses as illegal */
317+
/* Make iova relative to table base; amalgamate count pages */
312318
iova -= (mmu->dma_iova_offset + APERTURE_BASE);
319+
bytes = min(APERTURE_SIZE - iova, bytes * count);
320+
321+
/* Clear table entries, this marks the addresses as illegal */
313322
for (p = iova >> MMU_PAGE_SHIFT;
314323
p < (iova + bytes) >> MMU_PAGE_SHIFT;
315324
p++) {
@@ -322,7 +331,7 @@ static size_t bcm2712_iommu_unmap(struct iommu_domain *domain, unsigned long iov
322331
}
323332

324333
static int bcm2712_iommu_sync_range(struct iommu_domain *domain,
325-
unsigned long iova, size_t size)
334+
unsigned long iova, size_t size)
326335
{
327336
struct bcm2712_iommu *mmu = domain_to_mmu(domain);
328337
unsigned long iova_end;

0 commit comments

Comments
 (0)