Message ID | 20200522220316.23772-2-jcrouse@codeaurora.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm/msm: Cleanups ahead of per-instance pagetables | expand |
On Fri, May 22, 2020 at 04:03:14PM -0600, Jordan Crouse wrote: > diff --git a/drivers/gpu/drm/msm/msm_gpummu.c b/drivers/gpu/drm/msm/msm_gpummu.c > index 34980d8eb7ad..0ad0f848560a 100644 > --- a/drivers/gpu/drm/msm/msm_gpummu.c > +++ b/drivers/gpu/drm/msm/msm_gpummu.c > @@ -21,11 +21,6 @@ struct msm_gpummu { > #define GPUMMU_PAGE_SIZE SZ_4K > #define TABLE_SIZE (sizeof(uint32_t) * GPUMMU_VA_RANGE / GPUMMU_PAGE_SIZE) > > -static int msm_gpummu_attach(struct msm_mmu *mmu) > -{ > - return 0; > -} > - > static void msm_gpummu_detach(struct msm_mmu *mmu) > { > } > @@ -85,7 +80,6 @@ static void msm_gpummu_destroy(struct msm_mmu *mmu) > } > > static const struct msm_mmu_funcs funcs = { > - .attach = msm_gpummu_attach, > .detach = msm_gpummu_detach, > .map = msm_gpummu_map, > .unmap = msm_gpummu_unmap, > diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c > index ad58cfe5998e..e35dab5792cf 100644 > --- a/drivers/gpu/drm/msm/msm_iommu.c > +++ b/drivers/gpu/drm/msm/msm_iommu.c > @@ -66,7 +66,6 @@ static void msm_iommu_destroy(struct msm_mmu *mmu) > } > > static const struct msm_mmu_funcs funcs = { > - .attach = msm_iommu_attach, It causes an unused function warning as below. drivers/gpu/drm/msm/msm_iommu.c:26:12: warning: ‘msm_iommu_attach’ defined but not used [-Wunused-function] static int msm_iommu_attach(struct msm_mmu *mmu) ^~~~~~~~~~~~~~~~ Not sure if you will use it again in future patches though. Shawn > .detach = msm_iommu_detach, > .map = msm_iommu_map, > .unmap = msm_iommu_unmap, > @@ -76,6 +75,7 @@ static const struct msm_mmu_funcs funcs = { > struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) > { > struct msm_iommu *iommu; > + int ret; > > iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); > if (!iommu) > @@ -85,5 +85,11 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) > msm_mmu_init(&iommu->base, dev, &funcs); > iommu_set_fault_handler(domain, msm_fault_handler, iommu); > > + ret = iommu_attach_device(iommu->domain, dev); > + if (ret) { > + kfree(iommu); > + return ERR_PTR(ret); > + } > + > return &iommu->base; > } > diff --git a/drivers/gpu/drm/msm/msm_mmu.h b/drivers/gpu/drm/msm/msm_mmu.h > index 67a623f14319..bae9e8e67ec1 100644 > --- a/drivers/gpu/drm/msm/msm_mmu.h > +++ b/drivers/gpu/drm/msm/msm_mmu.h > @@ -10,7 +10,6 @@ > #include <linux/iommu.h> > > struct msm_mmu_funcs { > - int (*attach)(struct msm_mmu *mmu); > void (*detach)(struct msm_mmu *mmu); > int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt, > unsigned len, int prot); > -- > 2.17.1 >
On Sat, May 23, 2020 at 12:23 AM Shawn Guo <shawn.guo@linaro.org> wrote: > > On Fri, May 22, 2020 at 04:03:14PM -0600, Jordan Crouse wrote: > > diff --git a/drivers/gpu/drm/msm/msm_gpummu.c b/drivers/gpu/drm/msm/msm_gpummu.c > > index 34980d8eb7ad..0ad0f848560a 100644 > > --- a/drivers/gpu/drm/msm/msm_gpummu.c > > +++ b/drivers/gpu/drm/msm/msm_gpummu.c > > @@ -21,11 +21,6 @@ struct msm_gpummu { > > #define GPUMMU_PAGE_SIZE SZ_4K > > #define TABLE_SIZE (sizeof(uint32_t) * GPUMMU_VA_RANGE / GPUMMU_PAGE_SIZE) > > > > -static int msm_gpummu_attach(struct msm_mmu *mmu) > > -{ > > - return 0; > > -} > > - > > static void msm_gpummu_detach(struct msm_mmu *mmu) > > { > > } > > @@ -85,7 +80,6 @@ static void msm_gpummu_destroy(struct msm_mmu *mmu) > > } > > > > static const struct msm_mmu_funcs funcs = { > > - .attach = msm_gpummu_attach, > > .detach = msm_gpummu_detach, > > .map = msm_gpummu_map, > > .unmap = msm_gpummu_unmap, > > diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c > > index ad58cfe5998e..e35dab5792cf 100644 > > --- a/drivers/gpu/drm/msm/msm_iommu.c > > +++ b/drivers/gpu/drm/msm/msm_iommu.c > > @@ -66,7 +66,6 @@ static void msm_iommu_destroy(struct msm_mmu *mmu) > > } > > > > static const struct msm_mmu_funcs funcs = { > > - .attach = msm_iommu_attach, > > It causes an unused function warning as below. > > drivers/gpu/drm/msm/msm_iommu.c:26:12: warning: ‘msm_iommu_attach’ defined but not used [-Wunused-function] > static int msm_iommu_attach(struct msm_mmu *mmu) > ^~~~~~~~~~~~~~~~ > > Not sure if you will use it again in future patches though. looks like this was removed in msm_gpummu (a2xx) but not msm_iommu (a3xx+).. I've squashed a fixup and pushed to msm-next thx BR, -R > Shawn > > > .detach = msm_iommu_detach, > > .map = msm_iommu_map, > > .unmap = msm_iommu_unmap, > > @@ -76,6 +75,7 @@ static const struct msm_mmu_funcs funcs = { > > struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) > > { > > struct msm_iommu *iommu; > > + int ret; > > > > iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); > > if (!iommu) > > @@ -85,5 +85,11 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) > > msm_mmu_init(&iommu->base, dev, &funcs); > > iommu_set_fault_handler(domain, msm_fault_handler, iommu); > > > > + ret = iommu_attach_device(iommu->domain, dev); > > + if (ret) { > > + kfree(iommu); > > + return ERR_PTR(ret); > > + } > > + > > return &iommu->base; > > } > > diff --git a/drivers/gpu/drm/msm/msm_mmu.h b/drivers/gpu/drm/msm/msm_mmu.h > > index 67a623f14319..bae9e8e67ec1 100644 > > --- a/drivers/gpu/drm/msm/msm_mmu.h > > +++ b/drivers/gpu/drm/msm/msm_mmu.h > > @@ -10,7 +10,6 @@ > > #include <linux/iommu.h> > > > > struct msm_mmu_funcs { > > - int (*attach)(struct msm_mmu *mmu); > > void (*detach)(struct msm_mmu *mmu); > > int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt, > > unsigned len, int prot); > > -- > > 2.17.1 > >
diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c index 10c33cf7a5d7..c5150c67a3b8 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c @@ -794,7 +794,6 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms) { struct iommu_domain *domain; struct msm_gem_address_space *aspace; - int ret; domain = iommu_domain_alloc(&platform_bus_type); if (!domain) @@ -810,13 +809,6 @@ static int _dpu_kms_mmu_init(struct dpu_kms *dpu_kms) 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; return 0; } diff --git a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c index dda05436f716..9dba37c6344f 100644 --- a/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c @@ -518,10 +518,6 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev) } kms->aspace = aspace; - - ret = aspace->mmu->funcs->attach(aspace->mmu); - if (ret) - goto fail; } else { DRM_DEV_INFO(dev->dev, "no iommu, fallback to phys " "contig buffers for scanout\n"); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c index 46c1c4707292..eba8ff480296 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c @@ -636,13 +636,6 @@ struct msm_kms *mdp5_kms_init(struct drm_device *dev) } 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 { DRM_DEV_INFO(&pdev->dev, "no iommu, fallback to phys contig buffers for scanout\n"); diff --git a/drivers/gpu/drm/msm/msm_gem_vma.c b/drivers/gpu/drm/msm/msm_gem_vma.c index 407b7ab82818..72fc1980fff6 100644 --- a/drivers/gpu/drm/msm/msm_gem_vma.c +++ b/drivers/gpu/drm/msm/msm_gem_vma.c @@ -133,8 +133,8 @@ msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain, const char *name) { struct msm_gem_address_space *aspace; - u64 size = domain->geometry.aperture_end - - domain->geometry.aperture_start; + u64 start = domain->geometry.aperture_start; + u64 size = domain->geometry.aperture_end - start; aspace = kzalloc(sizeof(*aspace), GFP_KERNEL); if (!aspace) @@ -143,9 +143,18 @@ msm_gem_address_space_create(struct device *dev, struct iommu_domain *domain, spin_lock_init(&aspace->lock); aspace->name = name; 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), - size >> PAGE_SHIFT); + kfree(aspace); + 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); @@ -166,6 +175,12 @@ msm_gem_address_space_create_a2xx(struct device *dev, struct msm_gpu *gpu, spin_lock_init(&aspace->lock); aspace->name = name; 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), size >> PAGE_SHIFT); diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c index 615c5cda5389..b6f0d7204da9 100644 --- a/drivers/gpu/drm/msm/msm_gpu.c +++ b/drivers/gpu/drm/msm/msm_gpu.c @@ -826,7 +826,6 @@ msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev, uint64_t va_start, uint64_t va_end) { struct msm_gem_address_space *aspace; - int ret; /* * Setup IOMMU.. eventually we will (I think) do this once per context @@ -851,17 +850,9 @@ msm_gpu_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev, va_start, va_end); } - if (IS_ERR(aspace)) { + if (IS_ERR(aspace)) DRM_DEV_ERROR(gpu->dev->dev, "failed to init mmu: %ld\n", PTR_ERR(aspace)); - return ERR_CAST(aspace); - } - - ret = aspace->mmu->funcs->attach(aspace->mmu); - if (ret) { - msm_gem_address_space_put(aspace); - return ERR_PTR(ret); - } return aspace; } diff --git a/drivers/gpu/drm/msm/msm_gpummu.c b/drivers/gpu/drm/msm/msm_gpummu.c index 34980d8eb7ad..0ad0f848560a 100644 --- a/drivers/gpu/drm/msm/msm_gpummu.c +++ b/drivers/gpu/drm/msm/msm_gpummu.c @@ -21,11 +21,6 @@ struct msm_gpummu { #define GPUMMU_PAGE_SIZE SZ_4K #define TABLE_SIZE (sizeof(uint32_t) * GPUMMU_VA_RANGE / GPUMMU_PAGE_SIZE) -static int msm_gpummu_attach(struct msm_mmu *mmu) -{ - return 0; -} - static void msm_gpummu_detach(struct msm_mmu *mmu) { } @@ -85,7 +80,6 @@ static void msm_gpummu_destroy(struct msm_mmu *mmu) } static const struct msm_mmu_funcs funcs = { - .attach = msm_gpummu_attach, .detach = msm_gpummu_detach, .map = msm_gpummu_map, .unmap = msm_gpummu_unmap, diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c index ad58cfe5998e..e35dab5792cf 100644 --- a/drivers/gpu/drm/msm/msm_iommu.c +++ b/drivers/gpu/drm/msm/msm_iommu.c @@ -66,7 +66,6 @@ static void msm_iommu_destroy(struct msm_mmu *mmu) } static const struct msm_mmu_funcs funcs = { - .attach = msm_iommu_attach, .detach = msm_iommu_detach, .map = msm_iommu_map, .unmap = msm_iommu_unmap, @@ -76,6 +75,7 @@ static const struct msm_mmu_funcs funcs = { struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) { struct msm_iommu *iommu; + int ret; iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); if (!iommu) @@ -85,5 +85,11 @@ struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) msm_mmu_init(&iommu->base, dev, &funcs); iommu_set_fault_handler(domain, msm_fault_handler, iommu); + ret = iommu_attach_device(iommu->domain, dev); + if (ret) { + kfree(iommu); + return ERR_PTR(ret); + } + return &iommu->base; } diff --git a/drivers/gpu/drm/msm/msm_mmu.h b/drivers/gpu/drm/msm/msm_mmu.h index 67a623f14319..bae9e8e67ec1 100644 --- a/drivers/gpu/drm/msm/msm_mmu.h +++ b/drivers/gpu/drm/msm/msm_mmu.h @@ -10,7 +10,6 @@ #include <linux/iommu.h> struct msm_mmu_funcs { - int (*attach)(struct msm_mmu *mmu); void (*detach)(struct msm_mmu *mmu); int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt, unsigned len, int prot);