Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/msm: use upstream iommu

Downstream kernel IOMMU had a non-standard way of dealing with multiple
devices and multiple ports/contexts. We don't need that on upstream
kernel, so rip out the crazy.

Note that we have to move the pinning of the ringbuffer to after the
IOMMU is attached. No idea how that managed to work properly on the
downstream kernel.

For now, I am leaving the IOMMU port name stuff in place, to simplify
things for folks trying to backport latest drm/msm to device kernels.
Once we no longer have to care about pre-DT kernels, we can drop this
and instead backport upstream IOMMU driver.

Signed-off-by: Rob Clark <robdclark@gmail.com>

Rob Clark 944fc36c 1c4997fe

+18 -43
-1
drivers/gpu/drm/msm/Kconfig
··· 2 2 config DRM_MSM 3 3 tristate "MSM DRM" 4 4 depends on DRM 5 - depends on MSM_IOMMU 6 5 depends on ARCH_QCOM || (ARM && COMPILE_TEST) 7 6 select DRM_KMS_HELPER 8 7 select SHMEM
+8
drivers/gpu/drm/msm/adreno/adreno_gpu.c
··· 91 91 int adreno_hw_init(struct msm_gpu *gpu) 92 92 { 93 93 struct adreno_gpu *adreno_gpu = to_adreno_gpu(gpu); 94 + int ret; 94 95 95 96 DBG("%s", gpu->name); 97 + 98 + ret = msm_gem_get_iova_locked(gpu->rb->bo, gpu->id, &gpu->rb_iova); 99 + if (ret) { 100 + gpu->rb_iova = 0; 101 + dev_err(gpu->dev->dev, "could not map ringbuffer: %d\n", ret); 102 + return ret; 103 + } 96 104 97 105 /* Setup REG_CP_RB_CNTL: */ 98 106 gpu_write(gpu, REG_AXXX_CP_RB_CNTL,
+1 -1
drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.c
··· 361 361 mdelay(16); 362 362 363 363 if (config->iommu) { 364 - mmu = msm_iommu_new(dev, config->iommu); 364 + mmu = msm_iommu_new(&pdev->dev, config->iommu); 365 365 if (IS_ERR(mmu)) { 366 366 ret = PTR_ERR(mmu); 367 367 goto fail;
+1 -1
drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c
··· 320 320 mdelay(16); 321 321 322 322 if (config->iommu) { 323 - mmu = msm_iommu_new(dev, config->iommu); 323 + mmu = msm_iommu_new(&pdev->dev, config->iommu); 324 324 if (IS_ERR(mmu)) { 325 325 ret = PTR_ERR(mmu); 326 326 dev_err(dev->dev, "failed to init iommu: %d\n", ret);
+1 -8
drivers/gpu/drm/msm/msm_gpu.c
··· 606 606 iommu = iommu_domain_alloc(&platform_bus_type); 607 607 if (iommu) { 608 608 dev_info(drm->dev, "%s: using IOMMU\n", name); 609 - gpu->mmu = msm_iommu_new(drm, iommu); 609 + gpu->mmu = msm_iommu_new(&pdev->dev, iommu); 610 610 } else { 611 611 dev_info(drm->dev, "%s: no IOMMU, fallback to VRAM carveout!\n", name); 612 612 } ··· 618 618 ret = PTR_ERR(gpu->rb); 619 619 gpu->rb = NULL; 620 620 dev_err(drm->dev, "could not create ringbuffer: %d\n", ret); 621 - goto fail; 622 - } 623 - 624 - ret = msm_gem_get_iova_locked(gpu->rb->bo, gpu->id, &gpu->rb_iova); 625 - if (ret) { 626 - gpu->rb_iova = 0; 627 - dev_err(drm->dev, "could not map ringbuffer: %d\n", ret); 628 621 goto fail; 629 622 } 630 623
+3 -28
drivers/gpu/drm/msm/msm_iommu.c
··· 33 33 34 34 static int msm_iommu_attach(struct msm_mmu *mmu, const char **names, int cnt) 35 35 { 36 - struct drm_device *dev = mmu->dev; 37 36 struct msm_iommu *iommu = to_msm_iommu(mmu); 38 - int i, ret; 39 - 40 - for (i = 0; i < cnt; i++) { 41 - struct device *msm_iommu_get_ctx(const char *ctx_name); 42 - struct device *ctx = msm_iommu_get_ctx(names[i]); 43 - if (IS_ERR_OR_NULL(ctx)) { 44 - dev_warn(dev->dev, "couldn't get %s context", names[i]); 45 - continue; 46 - } 47 - ret = iommu_attach_device(iommu->domain, ctx); 48 - if (ret) { 49 - dev_warn(dev->dev, "could not attach iommu to %s", names[i]); 50 - return ret; 51 - } 52 - } 53 - 54 - return 0; 37 + return iommu_attach_device(iommu->domain, mmu->dev); 55 38 } 56 39 57 40 static void msm_iommu_detach(struct msm_mmu *mmu, const char **names, int cnt) 58 41 { 59 42 struct msm_iommu *iommu = to_msm_iommu(mmu); 60 - int i; 61 - 62 - for (i = 0; i < cnt; i++) { 63 - struct device *msm_iommu_get_ctx(const char *ctx_name); 64 - struct device *ctx = msm_iommu_get_ctx(names[i]); 65 - if (IS_ERR_OR_NULL(ctx)) 66 - continue; 67 - iommu_detach_device(iommu->domain, ctx); 68 - } 43 + iommu_detach_device(iommu->domain, mmu->dev); 69 44 } 70 45 71 46 static int msm_iommu_map(struct msm_mmu *mmu, uint32_t iova, ··· 124 149 .destroy = msm_iommu_destroy, 125 150 }; 126 151 127 - struct msm_mmu *msm_iommu_new(struct drm_device *dev, struct iommu_domain *domain) 152 + struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) 128 153 { 129 154 struct msm_iommu *iommu; 130 155
+4 -4
drivers/gpu/drm/msm/msm_mmu.h
··· 32 32 33 33 struct msm_mmu { 34 34 const struct msm_mmu_funcs *funcs; 35 - struct drm_device *dev; 35 + struct device *dev; 36 36 }; 37 37 38 - static inline void msm_mmu_init(struct msm_mmu *mmu, struct drm_device *dev, 38 + static inline void msm_mmu_init(struct msm_mmu *mmu, struct device *dev, 39 39 const struct msm_mmu_funcs *funcs) 40 40 { 41 41 mmu->dev = dev; 42 42 mmu->funcs = funcs; 43 43 } 44 44 45 - struct msm_mmu *msm_iommu_new(struct drm_device *dev, struct iommu_domain *domain); 46 - struct msm_mmu *msm_gpummu_new(struct drm_device *dev, struct msm_gpu *gpu); 45 + struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain); 46 + struct msm_mmu *msm_gpummu_new(struct device *dev, struct msm_gpu *gpu); 47 47 48 48 #endif /* __MSM_MMU_H__ */