From b5f2204f08d14b743b447d158f3b9b4dbe242b66 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Thu, 20 Feb 2020 23:08:48 -0800 Subject: [PATCH 1/2] iommu/arm-smmu: Cleanup arm_smmu_init() arm_smmu_init() has retained some workarounds for back when it could be invoked multiple times as either part of the initcall sequences, or through the IOMMU OF table. This was necessary before the driver core handled dependencies between an IOMMU master and an IOMMU device. Since this is no longer the case, we can remove this logic. Also, while we're here, unregister the TBU driver if the SMMU driver cannot be registered. Change-Id: I5c2ed4a046c63babb3bd60390c468a4e5e27de6e Signed-off-by: Isaac J. Manjarres --- drivers/iommu/arm-smmu.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 2b9c457a3680..bd8c3d9d1790 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -4963,22 +4963,21 @@ static struct platform_driver arm_smmu_driver = { static struct platform_driver qsmmuv500_tbu_driver; static int __init arm_smmu_init(void) { - static bool registered; - int ret = 0; + int ret; ktime_t cur; - if (registered) - return 0; - cur = ktime_get(); ret = platform_driver_register(&qsmmuv500_tbu_driver); if (ret) return ret; ret = platform_driver_register(&arm_smmu_driver); - registered = !ret; - trace_smmu_init(ktime_us_delta(ktime_get(), cur)); + if (ret) { + platform_driver_unregister(&qsmmuv500_tbu_driver); + return ret; + } + trace_smmu_init(ktime_us_delta(ktime_get(), cur)); return ret; } From 24edad3d95704178283c4b99cd96afe8107f77fc Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Fri, 21 Feb 2020 12:11:21 -0800 Subject: [PATCH 2/2] iommu/arm-smmu: Remove DOMAIN_ATTR_DEBUG DOMAIN_ATTR_DEBUG is queried by the qsmmuv500_iova_to_phys() function, which will move outside of arm-smmu.c, requiring arm_smmu_domain_get_attr() to be exposed, which doesn't make sense for only one attribute. Thus, remove this domain attribute and inform the SMMU driver that it is operating on a debug domain by introducing a new marker in the msm_iommu_domain for debug domains. This patch has no functional impact. Change-Id: I86dfbadab0a74f9018acc602eea28b2a3a2c38b5 Signed-off-by: Isaac J. Manjarres --- drivers/iommu/arm-smmu.c | 21 ++------------------- drivers/iommu/iommu-debug.c | 6 ++++-- include/linux/iommu.h | 4 ++-- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index bd8c3d9d1790..a83d294386df 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -3526,11 +3526,6 @@ static int arm_smmu_domain_get_attr(struct iommu_domain *domain, smmu_domain->attributes); ret = 0; break; - case DOMAIN_ATTR_DEBUG: - *((int *)data) = test_bit(DOMAIN_ATTR_DEBUG, - smmu_domain->attributes); - ret = 0; - break; default: ret = -ENODEV; break; @@ -3765,16 +3760,6 @@ static int __arm_smmu_domain_set_attr2(struct iommu_domain *domain, } break; } - case DOMAIN_ATTR_DEBUG: { - int is_debug_domain = *((int *)data); - - if (is_debug_domain) - set_bit(DOMAIN_ATTR_DEBUG, smmu_domain->attributes); - else - clear_bit(DOMAIN_ATTR_DEBUG, smmu_domain->attributes); - ret = 0; - break; - } default: ret = -ENODEV; } @@ -5595,19 +5580,17 @@ static phys_addr_t qsmmuv500_iova_to_phys_hard( { u16 sid; struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct msm_iommu_domain *msm_domain = to_msm_iommu_domain(domain); struct arm_smmu_cfg *cfg = &smmu_domain->cfg; struct arm_smmu_device *smmu = smmu_domain->smmu; struct iommu_fwspec *fwspec; u32 frsynra; - int is_debug_domain; - - arm_smmu_domain_get_attr(domain, DOMAIN_ATTR_DEBUG, &is_debug_domain); /* Check to see if the domain is associated with the test * device. If the domain belongs to the test device, then * pick the SID from fwspec. */ - if (is_debug_domain) { + if (msm_domain->is_debug_domain) { fwspec = dev_iommu_fwspec_get(smmu_domain->dev); sid = (u16)fwspec->ids[0]; } else { diff --git a/drivers/iommu/iommu-debug.c b/drivers/iommu/iommu-debug.c index 958b11aa49a5..246e44e0b497 100644 --- a/drivers/iommu/iommu-debug.c +++ b/drivers/iommu/iommu-debug.c @@ -209,8 +209,6 @@ static int iommu_debug_set_attrs(struct iommu_debug_device *ddev, iommu_domain_set_attr(domain, DOMAIN_ATTR_SECURE_VMID, &attrs->vmid); - iommu_domain_set_attr(domain, DOMAIN_ATTR_DEBUG, &val); - return 0; } @@ -237,6 +235,7 @@ static int iommu_debug_dma_reconfigure(struct iommu_debug_device *ddev, const struct iommu_ops *iommu; struct iommu_domain *domain; + struct msm_iommu_domain *msm_domain; struct device *dev = ddev->dev; int is_fast; bool coherent; @@ -276,6 +275,9 @@ static int iommu_debug_dma_reconfigure(struct iommu_debug_device *ddev, return -EINVAL; } + msm_domain = to_msm_iommu_domain(domain); + msm_domain->is_debug_domain = true; + if (iommu_debug_set_attrs(ddev, domain, attrs)) { dev_err_ratelimited(dev, "Setting attrs failed\n"); goto out_free_domain; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 923a8ec9040d..38e470ea32bb 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -117,6 +117,7 @@ struct iommu_domain { struct msm_iommu_domain { char name[IOMMU_DOMAIN_NAME_LEN]; + bool is_debug_domain; struct iommu_domain iommu_domain; }; @@ -178,8 +179,7 @@ enum iommu_attr { #define DOMAIN_ATTR_CB_STALL_DISABLE (EXTENDED_ATTR_BASE + 16) #define DOMAIN_ATTR_USE_LLC_NWA (EXTENDED_ATTR_BASE + 17) #define DOMAIN_ATTR_NO_CFRE (EXTENDED_ATTR_BASE + 18) -#define DOMAIN_ATTR_DEBUG (EXTENDED_ATTR_BASE + 19) -#define DOMAIN_ATTR_EXTENDED_MAX (EXTENDED_ATTR_BASE + 20) +#define DOMAIN_ATTR_EXTENDED_MAX (EXTENDED_ATTR_BASE + 19) /* These are the possible reserved region types */ enum iommu_resv_type {