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

Commit b71bd824 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "arm: mm: call __iommu_map_sg for unaligned buffers"

parents 7825502d 14568e72
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -1811,7 +1811,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
	int ret = 0;
	unsigned int count;
	struct scatterlist *s;
	int prot;
	int prot = 0;

	size = PAGE_ALIGN(size);
	*handle = ARM_MAPPING_ERROR;
@@ -1820,6 +1820,11 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
	if (iova == ARM_MAPPING_ERROR)
		return -ENOMEM;

	/*
	 * Check for coherency.
	 */
	prot |= is_coherent ? IOMMU_CACHE : 0;

	for (count = 0, s = sg; count < (size >> PAGE_SHIFT); s = sg_next(s)) {
		phys_addr_t phys = page_to_phys(sg_page(s));
		unsigned int len = PAGE_ALIGN(s->offset + s->length);
@@ -1827,7 +1832,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
		if (!is_coherent && (attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
			__dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);

		prot = __dma_info_to_prot(dir, attrs);
		prot |= __dma_info_to_prot(dir, attrs);

		ret = iommu_map(mapping->domain, iova, phys, len, prot);
		if (ret < 0)
@@ -1931,9 +1936,23 @@ int arm_iommu_map_sg(struct device *dev, struct scatterlist *sg,
	dma_addr_t iova;
	int prot = __dma_info_to_prot(dir, attrs);
	bool coherent;
	/*
	 * This is used to check if there are any unaligned offset/size
	 * given in the scatter list.
	 */
	bool unaligned_offset_size = false;

	for_each_sg(sg, s, nents, i)
	for_each_sg(sg, s, nents, i) {
		total_length += s->length;
		if ((s->offset & ~PAGE_MASK) || (s->length & ~PAGE_MASK)) {
			unaligned_offset_size = true;
			break;
		}
	}

	if (unaligned_offset_size)
		return __iommu_map_sg(dev, sg, nents, dir, attrs,
				      is_dma_coherent(dev, attrs, false));

	iova = __alloc_iova(mapping, total_length);
	if (iova == ARM_MAPPING_ERROR)