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

Commit ad9f9137 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "ion: ion_cma_heap: Add no-map detection"

parents c2f65901 6b8f1b71
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <asm/dma-iommu.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <trace/events/iommu.h>

#include <soc/qcom/secure_buffer.h>
#include <linux/arm-smmu-errata.h>
@@ -404,6 +405,8 @@ static dma_addr_t fast_smmu_map_page(struct device *dev, struct page *page,
	fast_dmac_clean_range(mapping, pmd, pmd + nptes);

	spin_unlock_irqrestore(&mapping->lock, flags);

	trace_map(mapping->domain, iova, phys_to_map, len, prot);
	return iova + offset_from_phys_to_map;

fail_free_iova:
@@ -435,6 +438,8 @@ static void fast_smmu_unmap_page(struct device *dev, dma_addr_t iova,
	fast_dmac_clean_range(mapping, pmd, pmd + nptes);
	__fast_smmu_free_iova(mapping, iova, len);
	spin_unlock_irqrestore(&mapping->lock, flags);

	trace_unmap(mapping->domain, iova - offset, len, len);
}

static void fast_smmu_sync_single_for_cpu(struct device *dev,
+21 −2
Original line number Diff line number Diff line
@@ -426,6 +426,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev)
	if (ret)
		goto err_put_group;


	/* Notify any listeners about change to group. */
	blocking_notifier_call_chain(&group->notifier,
				     IOMMU_GROUP_NOTIFY_ADD_DEVICE, dev);
@@ -1077,6 +1078,7 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
	domain->type = type;
	/* Assume all sizes by default; the driver may override this later */
	domain->pgsize_bitmap  = bus->iommu_ops->pgsize_bitmap;
	memset(domain->name, 0, IOMMU_DOMAIN_NAME_LEN);

	return domain;
}
@@ -1105,6 +1107,11 @@ static int __iommu_attach_device(struct iommu_domain *domain,
	if (!ret) {
		trace_attach_device_to_domain(dev);
		iommu_debug_attach_device(domain, dev);

		if (!strnlen(domain->name, IOMMU_DOMAIN_NAME_LEN)) {
			strlcpy(domain->name, dev_name(dev),
				IOMMU_DOMAIN_NAME_LEN);
		}
	}
	return ret;
}
@@ -1398,7 +1405,7 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova,
	if (ret)
		iommu_unmap(domain, orig_iova, orig_size - size);
	else
		trace_map(orig_iova, orig_paddr, orig_size);
		trace_map(domain, orig_iova, orig_paddr, orig_size, prot);

	return ret;
}
@@ -1451,11 +1458,23 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size)
		unmapped += unmapped_page;
	}

	trace_unmap(orig_iova, size, unmapped);
	trace_unmap(domain, orig_iova, size, unmapped);
	return unmapped;
}
EXPORT_SYMBOL_GPL(iommu_unmap);

size_t iommu_map_sg(struct iommu_domain *domain,
				  unsigned long iova, struct scatterlist *sg,
				  unsigned int nents, int prot)
{
	size_t mapped;

	mapped = domain->ops->map_sg(domain, iova, sg, nents, prot);
	trace_map_sg(domain, iova, mapped, prot);
	return mapped;
}
EXPORT_SYMBOL(iommu_map_sg);

size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
			 struct scatterlist *sg, unsigned int nents, int prot)
{
+0 −1
Original line number Diff line number Diff line
@@ -215,7 +215,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,

	buffer->dev = dev;
	buffer->size = len;
	buffer->flags = flags;
	INIT_LIST_HEAD(&buffer->vmas);

	table = heap->ops->map_dma(heap, buffer);
+19 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <linux/err.h>
#include <linux/dma-mapping.h>
#include <linux/msm_ion.h>
#include <linux/of.h>

#include <asm/cacheflush.h>
#include <soc/qcom/secure_buffer.h>
@@ -59,6 +60,18 @@ static int ion_cma_get_sgtable(struct device *dev, struct sg_table *sgt,
	return 0;
}

static bool ion_cma_has_kernel_mapping(struct ion_heap *heap)
{
	struct device *dev = heap->priv;
	struct device_node *mem_region;

	mem_region = of_parse_phandle(dev->of_node, "memory-region", 0);
	if (IS_ERR(mem_region))
		return false;

	return !of_property_read_bool(mem_region, "no-map");
}

/* ION CMA heap operations functions */
static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
			    unsigned long len, unsigned long align,
@@ -73,6 +86,12 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
	if (!info)
		return ION_CMA_ALLOCATE_FAILED;

	/* Override flags if cached-mappings are not supported */
	if (!ion_cma_has_kernel_mapping(heap)) {
		flags &= ~((unsigned long)ION_FLAG_CACHED);
		buffer->flags = flags;
	}

	if (!ION_IS_CACHED(flags))
		info->cpu_addr = dma_alloc_writecombine(dev, len,
							&info->handle,
+6 −7
Original line number Diff line number Diff line
@@ -88,6 +88,8 @@ struct iommu_pgtbl_info {
#define IOMMU_DOMAIN_DMA	(__IOMMU_DOMAIN_PAGING |	\
				 __IOMMU_DOMAIN_DMA_API)


#define IOMMU_DOMAIN_NAME_LEN 32
struct iommu_domain {
	unsigned type;
	const struct iommu_ops *ops;
@@ -96,6 +98,7 @@ struct iommu_domain {
	void *handler_token;
	struct iommu_domain_geometry geometry;
	void *iova_cookie;
	char name[IOMMU_DOMAIN_NAME_LEN];
};

enum iommu_cap {
@@ -281,6 +284,9 @@ extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
		     phys_addr_t paddr, size_t size, int prot);
extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova,
		       size_t size);
extern size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
				struct scatterlist *sg, unsigned int nents,
				int prot);
extern size_t default_iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
				struct scatterlist *sg,unsigned int nents,
				int prot);
@@ -344,13 +350,6 @@ extern uint64_t iommu_iova_to_pte(struct iommu_domain *domain,
extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev,
			      unsigned long iova, int flags);

static inline size_t iommu_map_sg(struct iommu_domain *domain,
				  unsigned long iova, struct scatterlist *sg,
				  unsigned int nents, int prot)
{
	return domain->ops->map_sg(domain, iova, sg, nents, prot);
}

extern void iommu_trigger_fault(struct iommu_domain *domain,
				unsigned long flags);

Loading