Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 315786eb authored by Olav Haugan's avatar Olav Haugan Committed by Joerg Roedel
Browse files

iommu: Add iommu_map_sg() function



Mapping and unmapping are more often than not in the critical path.
map_sg allows IOMMU driver implementations to optimize the process
of mapping buffers into the IOMMU page tables.

Instead of mapping a buffer one page at a time and requiring potentially
expensive TLB operations for each page, this function allows the driver
to map all pages in one go and defer TLB maintenance until after all
pages have been mapped.

Additionally, the mapping operation would be faster in general since
clients does not have to keep calling map API over and over again for
each physically contiguous chunk of memory that needs to be mapped to a
virtually contiguous region.

Signed-off-by: default avatarOlav Haugan <ohaugan@codeaurora.org>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 0df1f248
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -3424,6 +3424,7 @@ static const struct iommu_ops amd_iommu_ops = {
	.detach_dev = amd_iommu_detach_device,
	.detach_dev = amd_iommu_detach_device,
	.map = amd_iommu_map,
	.map = amd_iommu_map,
	.unmap = amd_iommu_unmap,
	.unmap = amd_iommu_unmap,
	.map_sg = default_iommu_map_sg,
	.iova_to_phys = amd_iommu_iova_to_phys,
	.iova_to_phys = amd_iommu_iova_to_phys,
	.pgsize_bitmap	= AMD_IOMMU_PGSIZES,
	.pgsize_bitmap	= AMD_IOMMU_PGSIZES,
};
};
+1 −0
Original line number Original line Diff line number Diff line
@@ -1652,6 +1652,7 @@ static const struct iommu_ops arm_smmu_ops = {
	.detach_dev	= arm_smmu_detach_dev,
	.detach_dev	= arm_smmu_detach_dev,
	.map		= arm_smmu_map,
	.map		= arm_smmu_map,
	.unmap		= arm_smmu_unmap,
	.unmap		= arm_smmu_unmap,
	.map_sg		= default_iommu_map_sg,
	.iova_to_phys	= arm_smmu_iova_to_phys,
	.iova_to_phys	= arm_smmu_iova_to_phys,
	.add_device	= arm_smmu_add_device,
	.add_device	= arm_smmu_add_device,
	.remove_device	= arm_smmu_remove_device,
	.remove_device	= arm_smmu_remove_device,
+1 −0
Original line number Original line Diff line number Diff line
@@ -1178,6 +1178,7 @@ static const struct iommu_ops exynos_iommu_ops = {
	.detach_dev = exynos_iommu_detach_device,
	.detach_dev = exynos_iommu_detach_device,
	.map = exynos_iommu_map,
	.map = exynos_iommu_map,
	.unmap = exynos_iommu_unmap,
	.unmap = exynos_iommu_unmap,
	.map_sg = default_iommu_map_sg,
	.iova_to_phys = exynos_iommu_iova_to_phys,
	.iova_to_phys = exynos_iommu_iova_to_phys,
	.add_device = exynos_iommu_add_device,
	.add_device = exynos_iommu_add_device,
	.remove_device = exynos_iommu_remove_device,
	.remove_device = exynos_iommu_remove_device,
+1 −0
Original line number Original line Diff line number Diff line
@@ -4467,6 +4467,7 @@ static const struct iommu_ops intel_iommu_ops = {
	.detach_dev	= intel_iommu_detach_device,
	.detach_dev	= intel_iommu_detach_device,
	.map		= intel_iommu_map,
	.map		= intel_iommu_map,
	.unmap		= intel_iommu_unmap,
	.unmap		= intel_iommu_unmap,
	.map_sg		= default_iommu_map_sg,
	.iova_to_phys	= intel_iommu_iova_to_phys,
	.iova_to_phys	= intel_iommu_iova_to_phys,
	.add_device	= intel_iommu_add_device,
	.add_device	= intel_iommu_add_device,
	.remove_device	= intel_iommu_remove_device,
	.remove_device	= intel_iommu_remove_device,
+25 −0
Original line number Original line Diff line number Diff line
@@ -1124,6 +1124,31 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
}
}
EXPORT_SYMBOL_GPL(iommu_unmap);
EXPORT_SYMBOL_GPL(iommu_unmap);


size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
			 struct scatterlist *sg, unsigned int nents, int prot)
{
	int ret;
	size_t mapped = 0;
	unsigned int i;
	struct scatterlist *s;

	for_each_sg(sg, s, nents, i) {
		phys_addr_t phys = page_to_phys(sg_page(s));
		size_t page_len = s->offset + s->length;

		ret = iommu_map(domain, iova + mapped, phys, page_len, prot);
		if (ret) {
			/* undo mappings already done */
			iommu_unmap(domain, iova, mapped);
			mapped = 0;
			break;
		}
		mapped += page_len;
	}

	return mapped;
}
EXPORT_SYMBOL_GPL(default_iommu_map_sg);


int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr,
			       phys_addr_t paddr, u64 size, int prot)
			       phys_addr_t paddr, u64 size, int prot)
Loading