Skip to content

Commit a05d585

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu/sprd: Update to {map,unmap}_pages
Now that the core API has a proper notion of multi-page mappings, clean up the old pgsize_bitmap hack by implementing the new interfaces instead. This time we'll get the return values for unmaps correct too. Signed-off-by: Robin Murphy <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/9026464e8380b92d10d09103e215eb4306a5df7c.1668100209.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent b577f7e commit a05d585

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/iommu/sprd-iommu.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,11 @@ static void sprd_iommu_detach_device(struct iommu_domain *domain,
271271
}
272272

273273
static int sprd_iommu_map(struct iommu_domain *domain, unsigned long iova,
274-
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
274+
phys_addr_t paddr, size_t pgsize, size_t pgcount,
275+
int prot, gfp_t gfp, size_t *mapped)
275276
{
276277
struct sprd_iommu_domain *dom = to_sprd_domain(domain);
277-
unsigned int page_num = size >> SPRD_IOMMU_PAGE_SHIFT;
278+
size_t size = pgcount * SPRD_IOMMU_PAGE_SIZE;
278279
unsigned long flags;
279280
unsigned int i;
280281
u32 *pgt_base_iova;
@@ -296,35 +297,37 @@ static int sprd_iommu_map(struct iommu_domain *domain, unsigned long iova,
296297
pgt_base_iova = dom->pgt_va + ((iova - start) >> SPRD_IOMMU_PAGE_SHIFT);
297298

298299
spin_lock_irqsave(&dom->pgtlock, flags);
299-
for (i = 0; i < page_num; i++) {
300+
for (i = 0; i < pgcount; i++) {
300301
pgt_base_iova[i] = pabase >> SPRD_IOMMU_PAGE_SHIFT;
301302
pabase += SPRD_IOMMU_PAGE_SIZE;
302303
}
303304
spin_unlock_irqrestore(&dom->pgtlock, flags);
304305

306+
*mapped = size;
305307
return 0;
306308
}
307309

308310
static size_t sprd_iommu_unmap(struct iommu_domain *domain, unsigned long iova,
309-
size_t size, struct iommu_iotlb_gather *iotlb_gather)
311+
size_t pgsize, size_t pgcount,
312+
struct iommu_iotlb_gather *iotlb_gather)
310313
{
311314
struct sprd_iommu_domain *dom = to_sprd_domain(domain);
312315
unsigned long flags;
313316
u32 *pgt_base_iova;
314-
unsigned int page_num = size >> SPRD_IOMMU_PAGE_SHIFT;
317+
size_t size = pgcount * SPRD_IOMMU_PAGE_SIZE;
315318
unsigned long start = domain->geometry.aperture_start;
316319
unsigned long end = domain->geometry.aperture_end;
317320

318321
if (iova < start || (iova + size) > (end + 1))
319-
return -EINVAL;
322+
return 0;
320323

321324
pgt_base_iova = dom->pgt_va + ((iova - start) >> SPRD_IOMMU_PAGE_SHIFT);
322325

323326
spin_lock_irqsave(&dom->pgtlock, flags);
324-
memset(pgt_base_iova, 0, page_num * sizeof(u32));
327+
memset(pgt_base_iova, 0, pgcount * sizeof(u32));
325328
spin_unlock_irqrestore(&dom->pgtlock, flags);
326329

327-
return 0;
330+
return size;
328331
}
329332

330333
static void sprd_iommu_sync_map(struct iommu_domain *domain,
@@ -407,13 +410,13 @@ static const struct iommu_ops sprd_iommu_ops = {
407410
.probe_device = sprd_iommu_probe_device,
408411
.device_group = sprd_iommu_device_group,
409412
.of_xlate = sprd_iommu_of_xlate,
410-
.pgsize_bitmap = ~0UL << SPRD_IOMMU_PAGE_SHIFT,
413+
.pgsize_bitmap = SPRD_IOMMU_PAGE_SIZE,
411414
.owner = THIS_MODULE,
412415
.default_domain_ops = &(const struct iommu_domain_ops) {
413416
.attach_dev = sprd_iommu_attach_device,
414417
.detach_dev = sprd_iommu_detach_device,
415-
.map = sprd_iommu_map,
416-
.unmap = sprd_iommu_unmap,
418+
.map_pages = sprd_iommu_map,
419+
.unmap_pages = sprd_iommu_unmap,
417420
.iotlb_sync_map = sprd_iommu_sync_map,
418421
.iotlb_sync = sprd_iommu_sync,
419422
.iova_to_phys = sprd_iommu_iova_to_phys,

0 commit comments

Comments
 (0)