diff mbox series

[v6,17/25] iommu/qcom_iommu: Add an IOMMU_IDENTITIY_DOMAIN

Message ID 17-v6-e8114faedade+425-iommu_all_defdom_jgg@nvidia.com
State Superseded
Headers show
Series iommu: Make default_domain's mandatory | expand

Commit Message

Jason Gunthorpe Aug. 3, 2023, 12:08 a.m. UTC
This brings back the ops->detach_dev() code that commit
1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it
into an IDENTITY domain.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 +++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Comments

Baolu Lu Aug. 14, 2023, 6:32 a.m. UTC | #1
On 2023/8/3 8:08, Jason Gunthorpe wrote:
> This brings back the ops->detach_dev() code that commit
> 1b932ceddd19 ("iommu: Remove detach_dev callbacks") deleted and turns it
> into an IDENTITY domain.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   drivers/iommu/arm/arm-smmu/qcom_iommu.c | 39 +++++++++++++++++++++++++
>   1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> index a503ed758ec302..9d7b9d8b4386d4 100644
> --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
> @@ -387,6 +387,44 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
>   	return 0;
>   }
>   
> +static int qcom_iommu_identity_attach(struct iommu_domain *identity_domain,
> +				      struct device *dev)
> +{
> +	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
> +	struct qcom_iommu_domain *qcom_domain;
> +	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
> +	struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
> +	unsigned int i;
> +
> +	if (domain == identity_domain || !domain)
> +		return 0;
> +
> +	qcom_domain = to_qcom_iommu_domain(domain);
> +	if (WARN_ON(!qcom_domain->iommu))
> +		return -EINVAL;
> +
> +	pm_runtime_get_sync(qcom_iommu->dev);
> +	for (i = 0; i < fwspec->num_ids; i++) {
> +		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
> +
> +		/* Disable the context bank: */
> +		iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
> +
> +		ctx->domain = NULL;

Does setting ctx->domain to NULL still match this semantics?

> +	}
> +	pm_runtime_put_sync(qcom_iommu->dev);
> +	return 0;
> +}
> +
> +static struct iommu_domain_ops qcom_iommu_identity_ops = {
> +	.attach_dev = qcom_iommu_identity_attach,
> +};
> +
> +static struct iommu_domain qcom_iommu_identity_domain = {
> +	.type = IOMMU_DOMAIN_IDENTITY,
> +	.ops = &qcom_iommu_identity_ops,
> +};
> +
>   static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova,
>   			  phys_addr_t paddr, size_t pgsize, size_t pgcount,
>   			  int prot, gfp_t gfp, size_t *mapped)
> @@ -553,6 +591,7 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
>   }
>   
>   static const struct iommu_ops qcom_iommu_ops = {
> +	.identity_domain = &qcom_iommu_identity_domain,
>   	.capable	= qcom_iommu_capable,
>   	.domain_alloc	= qcom_iommu_domain_alloc,
>   	.probe_device	= qcom_iommu_probe_device,

Anyway,

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu
Jason Gunthorpe Aug. 14, 2023, 3:36 p.m. UTC | #2
On Mon, Aug 14, 2023 at 02:32:33PM +0800, Baolu Lu wrote:

> > +	pm_runtime_get_sync(qcom_iommu->dev);
> > +	for (i = 0; i < fwspec->num_ids; i++) {
> > +		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
> > +
> > +		/* Disable the context bank: */
> > +		iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
> > +
> > +		ctx->domain = NULL;
> 
> Does setting ctx->domain to NULL still match this semantics?

Yes, I did not try to fix this driver. NULL means identity in the
ctx->domain.

Thanks,
Jason
Baolu Lu Aug. 15, 2023, 12:56 a.m. UTC | #3
On 2023/8/14 23:36, Jason Gunthorpe wrote:
> On Mon, Aug 14, 2023 at 02:32:33PM +0800, Baolu Lu wrote:
> 
>>> +	pm_runtime_get_sync(qcom_iommu->dev);
>>> +	for (i = 0; i < fwspec->num_ids; i++) {
>>> +		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
>>> +
>>> +		/* Disable the context bank: */
>>> +		iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
>>> +
>>> +		ctx->domain = NULL;
>> Does setting ctx->domain to NULL still match this semantics?
> Yes, I did not try to fix this driver. NULL means identity in the
> ctx->domain.

Okay.

Best regards,
baolu
diff mbox series

Patch

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index a503ed758ec302..9d7b9d8b4386d4 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -387,6 +387,44 @@  static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
 	return 0;
 }
 
+static int qcom_iommu_identity_attach(struct iommu_domain *identity_domain,
+				      struct device *dev)
+{
+	struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
+	struct qcom_iommu_domain *qcom_domain;
+	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+	struct qcom_iommu_dev *qcom_iommu = to_iommu(dev);
+	unsigned int i;
+
+	if (domain == identity_domain || !domain)
+		return 0;
+
+	qcom_domain = to_qcom_iommu_domain(domain);
+	if (WARN_ON(!qcom_domain->iommu))
+		return -EINVAL;
+
+	pm_runtime_get_sync(qcom_iommu->dev);
+	for (i = 0; i < fwspec->num_ids; i++) {
+		struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]);
+
+		/* Disable the context bank: */
+		iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0);
+
+		ctx->domain = NULL;
+	}
+	pm_runtime_put_sync(qcom_iommu->dev);
+	return 0;
+}
+
+static struct iommu_domain_ops qcom_iommu_identity_ops = {
+	.attach_dev = qcom_iommu_identity_attach,
+};
+
+static struct iommu_domain qcom_iommu_identity_domain = {
+	.type = IOMMU_DOMAIN_IDENTITY,
+	.ops = &qcom_iommu_identity_ops,
+};
+
 static int qcom_iommu_map(struct iommu_domain *domain, unsigned long iova,
 			  phys_addr_t paddr, size_t pgsize, size_t pgcount,
 			  int prot, gfp_t gfp, size_t *mapped)
@@ -553,6 +591,7 @@  static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 }
 
 static const struct iommu_ops qcom_iommu_ops = {
+	.identity_domain = &qcom_iommu_identity_domain,
 	.capable	= qcom_iommu_capable,
 	.domain_alloc	= qcom_iommu_domain_alloc,
 	.probe_device	= qcom_iommu_probe_device,