Commit 52da6d51 authored by Jordan Crouse's avatar Jordan Crouse Committed by Rob Clark
Browse files

drm/msm: Attach the IOMMU device during initialization



Everywhere an IOMMU object is created by msm_gpu_create_address_space
the IOMMU device is attached immediately after. Instead of carrying around
the infrastructure to do the attach from the device specific code do it
directly in the msm_iommu_init() function. This gets it out of the way for
more aggressive cleanups that follow.

Reviewed-by: default avatarRob Clark <robdclark@gmail.com>
Signed-off-by: default avatarJordan Crouse <jcrouse@codeaurora.org>
Tested-by: default avatarShawn Guo <shawn.guo@linaro.org>
[squash in rebase fixups and fix for unused fxn]
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
parent 7d4eedb0
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -1114,7 +1114,6 @@ static int a6xx_gmu_memory_alloc(struct a6xx_gmu *gmu, struct a6xx_gmu_bo *bo,
static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
{
{
	struct iommu_domain *domain;
	struct iommu_domain *domain;
	int ret;


	domain = iommu_domain_alloc(&platform_bus_type);
	domain = iommu_domain_alloc(&platform_bus_type);
	if (!domain)
	if (!domain)
@@ -1129,12 +1128,6 @@ static int a6xx_gmu_memory_probe(struct a6xx_gmu *gmu)
		return PTR_ERR(gmu->aspace);
		return PTR_ERR(gmu->aspace);
	}
	}


	ret = gmu->aspace->mmu->funcs->attach(gmu->aspace->mmu);
	if (ret) {
		msm_gem_address_space_put(gmu->aspace);
		return ret;
	}

	return 0;
	return 0;
}
}


+0 −8
Original line number Original line Diff line number Diff line
@@ -794,7 +794,6 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
{
{
	struct iommu_domain *domain;
	struct iommu_domain *domain;
	struct msm_gem_address_space *aspace;
	struct msm_gem_address_space *aspace;
	int ret;


	domain = iommu_domain_alloc(&platform_bus_type);
	domain = iommu_domain_alloc(&platform_bus_type);
	if (!domain)
	if (!domain)
@@ -810,13 +809,6 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms)
		return PTR_ERR(aspace);
		return PTR_ERR(aspace);
	}
	}


	ret = aspace->mmu->funcs->attach(aspace->mmu);
	if (ret) {
		DPU_ERROR("failed to attach iommu %d\n", ret);
		msm_gem_address_space_put(aspace);
		return ret;
	}

	dpu_kms->base.aspace = aspace;
	dpu_kms->base.aspace = aspace;
	return 0;
	return 0;
}
}
+0 −4
Original line number Original line Diff line number Diff line
@@ -518,10 +518,6 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev)
		}
		}


		kms->aspace = aspace;
		kms->aspace = aspace;

		ret = aspace->mmu->funcs->attach(aspace->mmu);
		if (ret)
			goto fail;
	} else {
	} else {
		DRM_DEV_INFO(dev->dev, "no iommu, fallback to phys "
		DRM_DEV_INFO(dev->dev, "no iommu, fallback to phys "
				"contig buffers for scanout\n");
				"contig buffers for scanout\n");
+0 −7
Original line number Original line Diff line number Diff line
@@ -644,13 +644,6 @@ struct msm_kms *mdp5_kms_init(struct drm_device *dev)
		}
		}


		kms->aspace = aspace;
		kms->aspace = aspace;

		ret = aspace->mmu->funcs->attach(aspace->mmu);
		if (ret) {
			DRM_DEV_ERROR(&pdev->dev, "failed to attach iommu: %d\n",
				ret);
			goto fail;
		}
	} else {
	} else {
		DRM_DEV_INFO(&pdev->dev,
		DRM_DEV_INFO(&pdev->dev,
			 "no iommu, fallback to phys contig buffers for scanout\n");
			 "no iommu, fallback to phys contig buffers for scanout\n");
+19 −4
Original line number Original line Diff line number Diff line
@@ -133,8 +133,8 @@ msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
		const char *name)
		const char *name)
{
{
	struct msm_gem_address_space *aspace;
	struct msm_gem_address_space *aspace;
	u64 size = domain->geometry.aperture_end -
	u64 start = domain->geometry.aperture_start;
		domain->geometry.aperture_start;
	u64 size = domain->geometry.aperture_end - start;


	aspace = kzalloc(sizeof(*aspace), GFP_KERNEL);
	aspace = kzalloc(sizeof(*aspace), GFP_KERNEL);
	if (!aspace)
	if (!aspace)
@@ -143,9 +143,18 @@ msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain,
	spin_lock_init(&aspace->lock);
	spin_lock_init(&aspace->lock);
	aspace->name = name;
	aspace->name = name;
	aspace->mmu = msm_iommu_new(dev, domain);
	aspace->mmu = msm_iommu_new(dev, domain);
	if (IS_ERR(aspace->mmu)) {
		int ret = PTR_ERR(aspace->mmu);


	drm_mm_init(&aspace->mm, (domain->geometry.aperture_start >> PAGE_SHIFT),
		kfree(aspace);
		size >> PAGE_SHIFT);
		return ERR_PTR(ret);
	}

	/*
	 * Attaching the IOMMU device changes the aperture values so use the
	 * cached values instead
	 */
	drm_mm_init(&aspace->mm, start >> PAGE_SHIFT, size >> PAGE_SHIFT);


	kref_init(&aspace->kref);
	kref_init(&aspace->kref);


@@ -166,6 +175,12 @@ msm_gem_address_space_create_a2xx(struct device *dev, struct msm_gpu *gpu,
	spin_lock_init(&aspace->lock);
	spin_lock_init(&aspace->lock);
	aspace->name = name;
	aspace->name = name;
	aspace->mmu = msm_gpummu_new(dev, gpu);
	aspace->mmu = msm_gpummu_new(dev, gpu);
	if (IS_ERR(aspace->mmu)) {
		int ret = PTR_ERR(aspace->mmu);

		kfree(aspace);
		return ERR_PTR(ret);
	}


	drm_mm_init(&aspace->mm, (va_start >> PAGE_SHIFT),
	drm_mm_init(&aspace->mm, (va_start >> PAGE_SHIFT),
		size >> PAGE_SHIFT);
		size >> PAGE_SHIFT);
Loading