Re: [PATCH v1 1/3] drm/msm: Attach the IOMMU device during initialization
From: Shawn Guo
Date: Sat May 23 2020 - 03:23:30 EST
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
>