Since we have the infrastructure for IOMMU function tables it makes sense to use it to differentiate between v1 and v2 targets. It adds a bit more infrastructure but it also gives us the freedom to expand on each flavor (especially v2) for things like dynamic domains. Signed-off-by: Jordan Crouse <jcrouse@xxxxxxxxxxxxxx> --- drivers/gpu/drm/msm/msm_iommu.c | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c index d520db2..c1bfc92 100644 --- a/drivers/gpu/drm/msm/msm_iommu.c +++ b/drivers/gpu/drm/msm/msm_iommu.c @@ -21,7 +21,6 @@ struct msm_iommu { struct msm_mmu base; struct iommu_domain *domain; - bool has_ctx; }; #define to_msm_iommu(x) container_of(x, struct msm_iommu, base) @@ -40,15 +39,12 @@ static int msm_fault_handler(struct iommu_domain *domain, struct device *dev, return 0; } -static int msm_iommu_attach(struct msm_mmu *mmu, const char * const *names, - int cnt) +static int msm_iommu_v1_attach(struct msm_mmu *mmu, const char *const *names, + int cnt) { struct msm_iommu *iommu = to_msm_iommu(mmu); int i, ret; - if (!iommu->has_ctx) - return iommu_attach_device(iommu->domain, mmu->dev); - for (i = 0; i < cnt; i++) { struct device *ctx = msm_iommu_get_ctx(names[i]); @@ -67,15 +63,12 @@ static int msm_iommu_attach(struct msm_mmu *mmu, const char * const *names, return 0; } -static void msm_iommu_detach(struct msm_mmu *mmu, const char * const *names, - int cnt) +static void msm_iommu_v1_detach(struct msm_mmu *mmu, const char * const *names, + int cnt) { struct msm_iommu *iommu = to_msm_iommu(mmu); int i; - if (!iommu->has_ctx) - iommu_detach_device(iommu->domain, mmu->dev); - for (i = 0; i < cnt; i++) { struct device *ctx = msm_iommu_get_ctx(names[i]); @@ -86,6 +79,22 @@ static void msm_iommu_detach(struct msm_mmu *mmu, const char * const *names, } } +static int msm_iommu_v2_attach(struct msm_mmu *mmu, const char * const *names, + int cnt) +{ + struct msm_iommu *iommu = to_msm_iommu(mmu); + + return iommu_attach_device(iommu->domain, mmu->dev); +} + +static void msm_iommu_v2_detach(struct msm_mmu *mmu, const char * const *names, + int cnt) +{ + struct msm_iommu *iommu = to_msm_iommu(mmu); + + iommu_detach_device(iommu->domain, mmu->dev); +} + static int msm_iommu_map(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt, unsigned len, int prot) { @@ -159,9 +168,19 @@ static void msm_iommu_destroy(struct msm_mmu *mmu) kfree(iommu); } -static const struct msm_mmu_funcs funcs = { - .attach = msm_iommu_attach, - .detach = msm_iommu_detach, +/* These are for qcom,msm-smmu-v2 and qcom,msm-mmu-500 based targets */ +static const struct msm_mmu_funcs funcs_v1 = { + .attach = msm_iommu_v1_attach, + .detach = msm_iommu_v1_detach, + .map = msm_iommu_map, + .unmap = msm_iommu_unmap, + .destroy = msm_iommu_destroy, +}; + +/* These are for the arm-smmu based targets */ +static const struct msm_mmu_funcs funcs_v2 = { + .attach = msm_iommu_v2_attach, + .detach = msm_iommu_v2_detach, .map = msm_iommu_map, .unmap = msm_iommu_unmap, .destroy = msm_iommu_destroy, @@ -170,18 +189,21 @@ static void msm_iommu_destroy(struct msm_mmu *mmu) struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain) { struct msm_iommu *iommu; + const struct msm_mmu_funcs *funcs; iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); if (!iommu) return ERR_PTR(-ENOMEM); - iommu->domain = domain; - msm_mmu_init(&iommu->base, dev, &funcs); - iommu_set_fault_handler(domain, msm_fault_handler, iommu, true); - if (of_find_compatible_node(NULL, NULL, "qcom,msm-smmu-v2") || of_find_compatible_node(NULL, NULL, "qcom,msm-mmu-500")) - iommu->has_ctx = true; + funcs = &funcs_v1; + else + funcs = &funcs_v2; + + iommu->domain = domain; + msm_mmu_init(&iommu->base, dev, funcs); + iommu_set_fault_handler(domain, msm_fault_handler, iommu, true); return &iommu->base; } -- 1.9.1 _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel