Skip to content

Commit 3136895

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Improve iommu_iotlb_gather helpers
The Mediatek driver is not the only one which might want a basic address-based gathering behaviour, so although it's arguably simple enough to open-code, let's factor it out for the sake of cleanliness. Let's also take this opportunity to document the intent of these helpers for clarity. Cc: Joerg Roedel <[email protected]> Cc: Will Deacon <[email protected]> Cc: Jiajun Cao <[email protected]> Cc: Robin Murphy <[email protected]> Cc: Lu Baolu <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Robin Murphy <[email protected]> Signed-off-by: Nadav Amit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 6664340 commit 3136895

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,8 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain,
520520
struct iommu_iotlb_gather *gather)
521521
{
522522
struct mtk_iommu_domain *dom = to_mtk_domain(domain);
523-
unsigned long end = iova + size - 1;
524523

525-
if (gather->start > iova)
526-
gather->start = iova;
527-
if (gather->end < end)
528-
gather->end = end;
524+
iommu_iotlb_gather_add_range(gather, iova, size);
529525
return dom->iop->unmap(dom->iop, iova, size, gather);
530526
}
531527

include/linux/iommu.h

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,38 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain,
497497
iommu_iotlb_gather_init(iotlb_gather);
498498
}
499499

500+
/**
501+
* iommu_iotlb_gather_add_range - Gather for address-based TLB invalidation
502+
* @gather: TLB gather data
503+
* @iova: start of page to invalidate
504+
* @size: size of page to invalidate
505+
*
506+
* Helper for IOMMU drivers to build arbitrarily-sized invalidation commands
507+
* where only the address range matters, and simply minimising intermediate
508+
* syncs is preferred.
509+
*/
510+
static inline void iommu_iotlb_gather_add_range(struct iommu_iotlb_gather *gather,
511+
unsigned long iova, size_t size)
512+
{
513+
unsigned long end = iova + size - 1;
514+
515+
if (gather->start > iova)
516+
gather->start = iova;
517+
if (gather->end < end)
518+
gather->end = end;
519+
}
520+
521+
/**
522+
* iommu_iotlb_gather_add_page - Gather for page-based TLB invalidation
523+
* @domain: IOMMU domain to be invalidated
524+
* @gather: TLB gather data
525+
* @iova: start of page to invalidate
526+
* @size: size of page to invalidate
527+
*
528+
* Helper for IOMMU drivers to build invalidation commands based on individual
529+
* pages, or with page size/table level hints which cannot be gathered if they
530+
* differ.
531+
*/
500532
static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
501533
struct iommu_iotlb_gather *gather,
502534
unsigned long iova, size_t size)
@@ -515,11 +547,7 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain,
515547
gather->pgsize = size;
516548
}
517549

518-
if (gather->end < end)
519-
gather->end = end;
520-
521-
if (gather->start > start)
522-
gather->start = start;
550+
iommu_iotlb_gather_add_range(gather, iova, size);
523551
}
524552

525553
/* PCI device grouping function */

0 commit comments

Comments
 (0)