All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will.deacon@arm.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	David Woodhouse <dwmw2@infradead.org>
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Joerg Roedel <jroedel@suse.de>
Subject: Re: [PATCH 07/11] iommu/arm-smmu: Make use of the iommu_register interface
Date: Fri, 10 Feb 2017 14:20:34 +0000	[thread overview]
Message-ID: <9bba214f-4d83-1e37-2df8-2f7db11f7d1f@arm.com> (raw)
In-Reply-To: <1486639981-32368-8-git-send-email-joro@8bytes.org>

On 09/02/17 11:32, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel@suse.de>
> 
> Also add the smmu devices to sysfs.
> 
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> ---
>  drivers/iommu/arm-smmu-v3.c | 22 +++++++++++++++++++++-
>  drivers/iommu/arm-smmu.c    | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index 4d6ec44..32133e2 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -616,6 +616,9 @@ struct arm_smmu_device {
>  	unsigned int			sid_bits;
>  
>  	struct arm_smmu_strtab_cfg	strtab_cfg;
> +
> +	/* IOMMU core code handle */
> +	struct iommu_device		iommu;
>  };
>  
>  /* SMMU private data for each master */
> @@ -1795,8 +1798,10 @@ static int arm_smmu_add_device(struct device *dev)
>  	}
>  
>  	group = iommu_group_get_for_dev(dev);
> -	if (!IS_ERR(group))
> +	if (!IS_ERR(group)) {
>  		iommu_group_put(group);
> +		iommu_device_link(&smmu->iommu, dev);

Given the coupling evident from this and the other patches, might it
work to simply do the linking/unlinking automatically in
iommu_group_{add,remove}_device()?

Robin.

> +	}
>  
>  	return PTR_ERR_OR_ZERO(group);
>  }
> @@ -1805,14 +1810,17 @@ static void arm_smmu_remove_device(struct device *dev)
>  {
>  	struct iommu_fwspec *fwspec = dev->iommu_fwspec;
>  	struct arm_smmu_master_data *master;
> +	struct arm_smmu_device *smmu;
>  
>  	if (!fwspec || fwspec->ops != &arm_smmu_ops)
>  		return;
>  
>  	master = fwspec->iommu_priv;
> +	smmu = master->smmu;
>  	if (master && master->ste.valid)
>  		arm_smmu_detach_dev(dev);
>  	iommu_group_remove_device(dev);
> +	iommu_device_unlink(&smmu->iommu, dev);
>  	kfree(master);
>  	iommu_fwspec_free(dev);
>  }
> @@ -2613,6 +2621,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  {
>  	int irq, ret;
>  	struct resource *res;
> +	resource_size_t ioaddr;
>  	struct arm_smmu_device *smmu;
>  	struct device *dev = &pdev->dev;
>  	bool bypass;
> @@ -2630,6 +2639,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		dev_err(dev, "MMIO region too small (%pr)\n", res);
>  		return -EINVAL;
>  	}
> +	ioaddr = res->start;
>  
>  	smmu->base = devm_ioremap_resource(dev, res);
>  	if (IS_ERR(smmu->base))
> @@ -2682,6 +2692,16 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		return ret;
>  
>  	/* And we're up. Go go go! */
> +	ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL,
> +				     "smmu3.%pa", &ioaddr);
> +	if (ret)
> +		return ret;
> +
> +	iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops);
> +	iommu_device_set_fwnode(&smmu->iommu, dev->fwnode);
> +
> +	ret = iommu_device_register(&smmu->iommu);
> +
>  	iommu_register_instance(dev->fwnode, &arm_smmu_ops);
>  
>  #ifdef CONFIG_PCI
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index a60cded..f4ce1e7 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -380,6 +380,9 @@ struct arm_smmu_device {
>  	unsigned int			*irqs;
>  
>  	u32				cavium_id_base; /* Specific to Cavium */
> +
> +	/* IOMMU core code handle */
> +	struct iommu_device		iommu;
>  };
>  
>  enum arm_smmu_context_fmt {
> @@ -1444,6 +1447,8 @@ static int arm_smmu_add_device(struct device *dev)
>  	if (ret)
>  		goto out_free;
>  
> +	iommu_device_link(&smmu->iommu, dev);
> +
>  	return 0;
>  
>  out_free:
> @@ -1456,10 +1461,17 @@ static int arm_smmu_add_device(struct device *dev)
>  static void arm_smmu_remove_device(struct device *dev)
>  {
>  	struct iommu_fwspec *fwspec = dev->iommu_fwspec;
> +	struct arm_smmu_master_cfg *cfg;
> +	struct arm_smmu_device *smmu;
> +
>  
>  	if (!fwspec || fwspec->ops != &arm_smmu_ops)
>  		return;
>  
> +	cfg  = fwspec->iommu_priv;
> +	smmu = cfg->smmu;
> +
> +	iommu_device_unlink(&smmu->iommu, dev);
>  	arm_smmu_master_free_smes(fwspec);
>  	iommu_group_remove_device(dev);
>  	kfree(fwspec->iommu_priv);
> @@ -2011,6 +2023,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev,
>  static int arm_smmu_device_probe(struct platform_device *pdev)
>  {
>  	struct resource *res;
> +	resource_size_t ioaddr;
>  	struct arm_smmu_device *smmu;
>  	struct device *dev = &pdev->dev;
>  	int num_irqs, i, err;
> @@ -2031,6 +2044,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		return err;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	ioaddr = res->start;
>  	smmu->base = devm_ioremap_resource(dev, res);
>  	if (IS_ERR(smmu->base))
>  		return PTR_ERR(smmu->base);
> @@ -2091,6 +2105,22 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> +	err = iommu_device_sysfs_add(&smmu->iommu, smmu->dev, NULL,
> +				     "smmu.%pa", &ioaddr);
> +	if (err) {
> +		dev_err(dev, "Failed to register iommu in sysfs\n");
> +		return err;
> +	}
> +
> +	iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops);
> +	iommu_device_set_fwnode(&smmu->iommu, dev->fwnode);
> +
> +	err = iommu_device_register(&smmu->iommu);
> +	if (err) {
> +		dev_err(dev, "Failed to register iommu\n");
> +		return err;
> +	}
> +
>  	iommu_register_instance(dev->fwnode, &arm_smmu_ops);
>  	platform_set_drvdata(pdev, smmu);
>  	arm_smmu_device_reset(smmu);
> 

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>,
	Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>,
	Lorenzo Pieralisi
	<lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org>,
	Alex Williamson
	<alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 07/11] iommu/arm-smmu: Make use of the iommu_register interface
Date: Fri, 10 Feb 2017 14:20:34 +0000	[thread overview]
Message-ID: <9bba214f-4d83-1e37-2df8-2f7db11f7d1f@arm.com> (raw)
In-Reply-To: <1486639981-32368-8-git-send-email-joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>

On 09/02/17 11:32, Joerg Roedel wrote:
> From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
> 
> Also add the smmu devices to sysfs.
> 
> Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
> ---
>  drivers/iommu/arm-smmu-v3.c | 22 +++++++++++++++++++++-
>  drivers/iommu/arm-smmu.c    | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c
> index 4d6ec44..32133e2 100644
> --- a/drivers/iommu/arm-smmu-v3.c
> +++ b/drivers/iommu/arm-smmu-v3.c
> @@ -616,6 +616,9 @@ struct arm_smmu_device {
>  	unsigned int			sid_bits;
>  
>  	struct arm_smmu_strtab_cfg	strtab_cfg;
> +
> +	/* IOMMU core code handle */
> +	struct iommu_device		iommu;
>  };
>  
>  /* SMMU private data for each master */
> @@ -1795,8 +1798,10 @@ static int arm_smmu_add_device(struct device *dev)
>  	}
>  
>  	group = iommu_group_get_for_dev(dev);
> -	if (!IS_ERR(group))
> +	if (!IS_ERR(group)) {
>  		iommu_group_put(group);
> +		iommu_device_link(&smmu->iommu, dev);

Given the coupling evident from this and the other patches, might it
work to simply do the linking/unlinking automatically in
iommu_group_{add,remove}_device()?

Robin.

> +	}
>  
>  	return PTR_ERR_OR_ZERO(group);
>  }
> @@ -1805,14 +1810,17 @@ static void arm_smmu_remove_device(struct device *dev)
>  {
>  	struct iommu_fwspec *fwspec = dev->iommu_fwspec;
>  	struct arm_smmu_master_data *master;
> +	struct arm_smmu_device *smmu;
>  
>  	if (!fwspec || fwspec->ops != &arm_smmu_ops)
>  		return;
>  
>  	master = fwspec->iommu_priv;
> +	smmu = master->smmu;
>  	if (master && master->ste.valid)
>  		arm_smmu_detach_dev(dev);
>  	iommu_group_remove_device(dev);
> +	iommu_device_unlink(&smmu->iommu, dev);
>  	kfree(master);
>  	iommu_fwspec_free(dev);
>  }
> @@ -2613,6 +2621,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  {
>  	int irq, ret;
>  	struct resource *res;
> +	resource_size_t ioaddr;
>  	struct arm_smmu_device *smmu;
>  	struct device *dev = &pdev->dev;
>  	bool bypass;
> @@ -2630,6 +2639,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		dev_err(dev, "MMIO region too small (%pr)\n", res);
>  		return -EINVAL;
>  	}
> +	ioaddr = res->start;
>  
>  	smmu->base = devm_ioremap_resource(dev, res);
>  	if (IS_ERR(smmu->base))
> @@ -2682,6 +2692,16 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		return ret;
>  
>  	/* And we're up. Go go go! */
> +	ret = iommu_device_sysfs_add(&smmu->iommu, dev, NULL,
> +				     "smmu3.%pa", &ioaddr);
> +	if (ret)
> +		return ret;
> +
> +	iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops);
> +	iommu_device_set_fwnode(&smmu->iommu, dev->fwnode);
> +
> +	ret = iommu_device_register(&smmu->iommu);
> +
>  	iommu_register_instance(dev->fwnode, &arm_smmu_ops);
>  
>  #ifdef CONFIG_PCI
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index a60cded..f4ce1e7 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -380,6 +380,9 @@ struct arm_smmu_device {
>  	unsigned int			*irqs;
>  
>  	u32				cavium_id_base; /* Specific to Cavium */
> +
> +	/* IOMMU core code handle */
> +	struct iommu_device		iommu;
>  };
>  
>  enum arm_smmu_context_fmt {
> @@ -1444,6 +1447,8 @@ static int arm_smmu_add_device(struct device *dev)
>  	if (ret)
>  		goto out_free;
>  
> +	iommu_device_link(&smmu->iommu, dev);
> +
>  	return 0;
>  
>  out_free:
> @@ -1456,10 +1461,17 @@ static int arm_smmu_add_device(struct device *dev)
>  static void arm_smmu_remove_device(struct device *dev)
>  {
>  	struct iommu_fwspec *fwspec = dev->iommu_fwspec;
> +	struct arm_smmu_master_cfg *cfg;
> +	struct arm_smmu_device *smmu;
> +
>  
>  	if (!fwspec || fwspec->ops != &arm_smmu_ops)
>  		return;
>  
> +	cfg  = fwspec->iommu_priv;
> +	smmu = cfg->smmu;
> +
> +	iommu_device_unlink(&smmu->iommu, dev);
>  	arm_smmu_master_free_smes(fwspec);
>  	iommu_group_remove_device(dev);
>  	kfree(fwspec->iommu_priv);
> @@ -2011,6 +2023,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev,
>  static int arm_smmu_device_probe(struct platform_device *pdev)
>  {
>  	struct resource *res;
> +	resource_size_t ioaddr;
>  	struct arm_smmu_device *smmu;
>  	struct device *dev = &pdev->dev;
>  	int num_irqs, i, err;
> @@ -2031,6 +2044,7 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		return err;
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	ioaddr = res->start;
>  	smmu->base = devm_ioremap_resource(dev, res);
>  	if (IS_ERR(smmu->base))
>  		return PTR_ERR(smmu->base);
> @@ -2091,6 +2105,22 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> +	err = iommu_device_sysfs_add(&smmu->iommu, smmu->dev, NULL,
> +				     "smmu.%pa", &ioaddr);
> +	if (err) {
> +		dev_err(dev, "Failed to register iommu in sysfs\n");
> +		return err;
> +	}
> +
> +	iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops);
> +	iommu_device_set_fwnode(&smmu->iommu, dev->fwnode);
> +
> +	err = iommu_device_register(&smmu->iommu);
> +	if (err) {
> +		dev_err(dev, "Failed to register iommu\n");
> +		return err;
> +	}
> +
>  	iommu_register_instance(dev->fwnode, &arm_smmu_ops);
>  	platform_set_drvdata(pdev, smmu);
>  	arm_smmu_device_reset(smmu);
> 

  reply	other threads:[~2017-02-10 14:21 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-09 11:32 [PATCH 00/11 v3] Let IOMMU core know about individual IOMMUs Joerg Roedel
2017-02-09 11:32 ` Joerg Roedel
2017-02-09 11:32 ` [PATCH 01/11] iommu: Rename iommu_get_instance() Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-10 14:12   ` Robin Murphy
2017-02-10 14:12     ` Robin Murphy
2017-02-10 15:36     ` Joerg Roedel
2017-02-10 15:36       ` Joerg Roedel
2017-02-09 11:32 ` [PATCH 02/11] iommu: Rename struct iommu_device Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 11:32 ` [PATCH 03/11] iommu: Introduce new 'struct iommu_device' Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 20:42   ` kbuild test robot
2017-02-09 20:42     ` kbuild test robot
2017-02-09 11:32 ` [PATCH 04/11] iommu: Add sysfs bindings for struct iommu_device Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 11:32 ` [PATCH 05/11] iommu: Make iommu_device_link/unlink take a " Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 11:32 ` [PATCH 06/11] iommu: Add iommu_device_set_fwnode() interface Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-10 14:16   ` Robin Murphy
2017-02-10 14:16     ` Robin Murphy
2017-02-10 15:22     ` Joerg Roedel
2017-02-10 15:22       ` Joerg Roedel
2017-02-10 16:03       ` Robin Murphy
2017-02-10 16:03         ` Robin Murphy
2017-02-10 16:11         ` Joerg Roedel
2017-02-10 16:11           ` Joerg Roedel
2017-02-10 16:59           ` Robin Murphy
2017-02-10 16:59             ` Robin Murphy
2017-02-09 11:32 ` [PATCH 07/11] iommu/arm-smmu: Make use of the iommu_register interface Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-10 14:20   ` Robin Murphy [this message]
2017-02-10 14:20     ` Robin Murphy
2017-02-10 15:25     ` Joerg Roedel
2017-02-10 15:25       ` Joerg Roedel
2017-02-10 17:07       ` Robin Murphy
2017-02-10 17:07         ` Robin Murphy
2017-02-09 11:32 ` [PATCH 08/11] iommu/msm: Make use of iommu_device_register interface Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-10 14:35   ` Robin Murphy
2017-02-10 14:35     ` Robin Murphy
2017-02-10 15:33     ` Joerg Roedel
2017-02-10 15:33       ` Joerg Roedel
2017-02-10 17:36       ` Robin Murphy
2017-02-10 17:36         ` Robin Murphy
2017-02-09 11:32 ` [PATCH 09/11] iommu/mediatek: " Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 11:32 ` [PATCH 10/11] iommu/exynos: " Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-09 11:32   ` Joerg Roedel
2017-02-10 13:46   ` Marek Szyprowski
2017-02-10 13:46     ` Marek Szyprowski
2017-02-10 13:46     ` Marek Szyprowski
2017-02-10 13:59     ` Joerg Roedel
2017-02-10 13:59       ` Joerg Roedel
2017-02-10 13:59       ` Joerg Roedel
2017-02-09 11:33 ` [PATCH 11/11] iommu: Remove iommu_register_instance interface Joerg Roedel
2017-02-09 11:33   ` Joerg Roedel
2017-02-09 11:33   ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9bba214f-4d83-1e37-2df8-2f7db11f7d1f@arm.com \
    --to=robin.murphy@arm.com \
    --cc=alex.williamson@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.