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

Commit 217a38d4 authored by Patrick Daly's avatar Patrick Daly
Browse files

arm64: dma-mapping: Don't initialize iova_cookie twice



When multiple devices share the same iommu_domain, only the
first device needs to initialize the iova_cookie.

Change-Id: Id68ac321ae2ae08a9be3ed6b60c95dbcf74165d8
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 00f16d0c
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -1915,20 +1915,34 @@ iommu_init_mapping(struct device *dev, struct dma_iommu_mapping *mapping)
	struct iommu_domain *domain = mapping->domain;
	dma_addr_t dma_base = mapping->base;
	u64 size = mapping->bits << PAGE_SHIFT;
	int ret;
	bool own_cookie;

	/* Prepare the domain */
	if (iommu_get_dma_cookie(domain))
		return -EINVAL;
	/*
	 * if own_cookie is false, then we are sharing the iova_cookie with
	 * another driver, and should not free it on error. Cleanup will be
	 * done when the iommu_domain is freed.
	 */
	own_cookie = !domain->iova_cookie;

	if (iommu_dma_init_domain(domain, dma_base, size, dev))
		goto out_put_cookie;
	if (own_cookie) {
		ret = iommu_get_dma_cookie(domain);
		if (ret) {
			dev_err(dev, "iommu_get_dma_cookie failed: %d\n", ret);
			return ret;
		}
	}

	ret = iommu_dma_init_domain(domain, dma_base, size, dev);
	if (ret) {
		dev_err(dev, "iommu_dma_init_domain failed: %d\n", ret);
		if (own_cookie)
			iommu_put_dma_cookie(domain);
		return ret;
	}

	mapping->ops = &iommu_dma_ops;
	return 0;

out_put_cookie:
	iommu_put_dma_cookie(domain);
	return -EINVAL;
}

static int
+4 −0
Original line number Diff line number Diff line
@@ -267,6 +267,10 @@ static int iommu_dma_arm_smmu_errata_init(struct iommu_domain *domain)
	int vmid = VMID_HLOS;
	int min_iova_align = 0;

	/* Called for each device in the iommu group */
	if (cookie->guard_page)
		return 0;

	iommu_domain_get_attr(domain,
			DOMAIN_ATTR_QCOM_MMU500_ERRATA_MIN_IOVA_ALIGN,
			&min_iova_align);