Re: [PATCH 4/5] iommu/tegra-smmu: Add PCI support

2020-09-28 Thread Nicolin Chen
On Mon, Sep 28, 2020 at 09:55:45AM +0200, Thierry Reding wrote:
> On Sat, Sep 26, 2020 at 01:07:18AM -0700, Nicolin Chen wrote:
> > +#ifdef CONFIG_PCI
> > +   if (!iommu_present(_bus_type)) {
> > +   pci_request_acs();
> > +   err = bus_set_iommu(_bus_type, _smmu_ops);
> > +   if (err < 0) {
> > +   bus_set_iommu(_bus_type, NULL);
> > +   iommu_device_unregister(>iommu);
> > +   iommu_device_sysfs_remove(>iommu);
> > +   return ERR_PTR(err);
> 
> It might be worth factoring out the cleanup code now that there are
> multiple failures from which we may need to clean up.

Will do.

> Also, it'd be great if somehow we could do this without the #ifdef,
> but I guess since we're using the pci_bus_type global variable directly,
> there isn't much we can do here?

Probably no -- both pci_bus_type and pci_request_acs seem to depend
on it.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH 4/5] iommu/tegra-smmu: Add PCI support

2020-09-28 Thread Nicolin Chen
On Sun, Sep 27, 2020 at 01:18:15AM +0300, Dmitry Osipenko wrote:
> 26.09.2020 11:07, Nicolin Chen пишет:
> ...
> > +#ifdef CONFIG_PCI
> > +   if (!iommu_present(_bus_type)) {
> 
> Is this iommu_present() check really needed?
> 
> > +   pci_request_acs();
> 
> Shouldn't pci_request_acs() be invoked *after* bus_set_iommu() succeeds?

Will move it after that. Thanks!
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Re: [PATCH 4/5] iommu/tegra-smmu: Add PCI support

2020-09-28 Thread Thierry Reding
On Sat, Sep 26, 2020 at 01:07:18AM -0700, Nicolin Chen wrote:
> This patch simply adds support for PCI devices.
> 
> Signed-off-by: Nicolin Chen 
> ---
>  drivers/iommu/tegra-smmu.c | 17 -
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
> index 97a7185b4578..9dbc5d7183cc 100644
> --- a/drivers/iommu/tegra-smmu.c
> +++ b/drivers/iommu/tegra-smmu.c
> @@ -15,6 +15,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  #include 
> @@ -935,6 +936,7 @@ static struct iommu_group *tegra_smmu_device_group(struct 
> device *dev)
>   const struct tegra_smmu_group_soc *soc;
>   struct tegra_smmu_group *group;
>   int swgroup = fwspec->ids[0];
> + bool pci = dev_is_pci(dev);
>   struct iommu_group *grp;
>  
>   /* Find group_soc associating with swgroup */
> @@ -961,7 +963,7 @@ static struct iommu_group *tegra_smmu_device_group(struct 
> device *dev)
>   group->smmu = smmu;
>   group->soc = soc;
>  
> - group->group = iommu_group_alloc();
> + group->group = pci ? pci_device_group(dev) : iommu_group_alloc();
>   if (IS_ERR(group->group)) {
>   devm_kfree(smmu->dev, group);
>   mutex_unlock(>lock);
> @@ -1180,6 +1182,19 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
>   return ERR_PTR(err);
>   }
>  
> +#ifdef CONFIG_PCI
> + if (!iommu_present(_bus_type)) {
> + pci_request_acs();
> + err = bus_set_iommu(_bus_type, _smmu_ops);
> + if (err < 0) {
> + bus_set_iommu(_bus_type, NULL);
> + iommu_device_unregister(>iommu);
> + iommu_device_sysfs_remove(>iommu);
> + return ERR_PTR(err);

It might be worth factoring out the cleanup code now that there are
multiple failures from which we may need to clean up.

Also, it'd be great if somehow we could do this without the #ifdef,
but I guess since we're using the pci_bus_type global variable directly,
there isn't much we can do here?

Thierry


signature.asc
Description: PGP signature
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Re: [PATCH 4/5] iommu/tegra-smmu: Add PCI support

2020-09-26 Thread Dmitry Osipenko
26.09.2020 11:07, Nicolin Chen пишет:
...
> +#ifdef CONFIG_PCI
> + if (!iommu_present(_bus_type)) {

Is this iommu_present() check really needed?

> + pci_request_acs();

Shouldn't pci_request_acs() be invoked *after* bus_set_iommu() succeeds?

> + err = bus_set_iommu(_bus_type, _smmu_ops);
> + if (err < 0) {
> + bus_set_iommu(_bus_type, NULL);
> + iommu_device_unregister(>iommu);
> + iommu_device_sysfs_remove(>iommu);
> + return ERR_PTR(err);
> + }
> + }
> +#endif
> +
>   if (IS_ENABLED(CONFIG_DEBUG_FS))
>   tegra_smmu_debugfs_init(smmu);
>  
> 

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

[PATCH 4/5] iommu/tegra-smmu: Add PCI support

2020-09-26 Thread Nicolin Chen
This patch simply adds support for PCI devices.

Signed-off-by: Nicolin Chen 
---
 drivers/iommu/tegra-smmu.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 97a7185b4578..9dbc5d7183cc 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -935,6 +936,7 @@ static struct iommu_group *tegra_smmu_device_group(struct 
device *dev)
const struct tegra_smmu_group_soc *soc;
struct tegra_smmu_group *group;
int swgroup = fwspec->ids[0];
+   bool pci = dev_is_pci(dev);
struct iommu_group *grp;
 
/* Find group_soc associating with swgroup */
@@ -961,7 +963,7 @@ static struct iommu_group *tegra_smmu_device_group(struct 
device *dev)
group->smmu = smmu;
group->soc = soc;
 
-   group->group = iommu_group_alloc();
+   group->group = pci ? pci_device_group(dev) : iommu_group_alloc();
if (IS_ERR(group->group)) {
devm_kfree(smmu->dev, group);
mutex_unlock(>lock);
@@ -1180,6 +1182,19 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
return ERR_PTR(err);
}
 
+#ifdef CONFIG_PCI
+   if (!iommu_present(_bus_type)) {
+   pci_request_acs();
+   err = bus_set_iommu(_bus_type, _smmu_ops);
+   if (err < 0) {
+   bus_set_iommu(_bus_type, NULL);
+   iommu_device_unregister(>iommu);
+   iommu_device_sysfs_remove(>iommu);
+   return ERR_PTR(err);
+   }
+   }
+#endif
+
if (IS_ENABLED(CONFIG_DEBUG_FS))
tegra_smmu_debugfs_init(smmu);
 
-- 
2.17.1

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH 4/5] iommu/tegra-smmu: Add PCI support

2019-01-16 Thread Navneet Kumar
Add support for PCI devices.

Signed-off-by: Navneet Kumar 
---
 drivers/iommu/tegra-smmu.c | 47 +-
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 1a44cf6..4b43c63 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -820,7 +821,8 @@ tegra_smmu_find_group(struct tegra_smmu *smmu, unsigned int 
swgroup)
return NULL;
 }
 
-static struct iommu_group *tegra_smmu_group_get(struct tegra_smmu *smmu,
+static struct iommu_group *tegra_smmu_group_get(struct device *dev,
+   struct tegra_smmu *smmu,
unsigned int swgroup)
 {
const struct tegra_smmu_group_soc *soc;
@@ -847,7 +849,11 @@ static struct iommu_group *tegra_smmu_group_get(struct 
tegra_smmu *smmu,
INIT_LIST_HEAD(>list);
group->soc = soc;
 
-   group->group = iommu_group_alloc();
+   if (dev_is_pci(dev))
+   group->group = pci_device_group(dev);
+   else
+   group->group = generic_device_group(dev);
+
if (IS_ERR(group->group)) {
devm_kfree(smmu->dev, group);
mutex_unlock(>lock);
@@ -864,13 +870,8 @@ static struct iommu_group *tegra_smmu_device_group(struct 
device *dev)
 {
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
struct tegra_smmu *smmu = dev->archdata.iommu;
-   struct iommu_group *group;
 
-   group = tegra_smmu_group_get(smmu, fwspec->ids[0]);
-   if (!group)
-   group = generic_device_group(dev);
-
-   return group;
+   return tegra_smmu_group_get(dev, smmu, fwspec->ids[0]);
 }
 
 static int tegra_smmu_of_xlate(struct device *dev,
@@ -989,6 +990,28 @@ static void tegra_smmu_debugfs_exit(struct tegra_smmu 
*smmu)
debugfs_remove_recursive(smmu->debugfs);
 }
 
+static int tegra_smmu_iommu_bus_init(struct tegra_smmu *smmu)
+{
+   int err;
+
+   err = bus_set_iommu(_bus_type, _smmu_ops);
+   if (err < 0) {
+   iommu_device_unregister(>iommu);
+   iommu_device_sysfs_remove(>iommu);
+   return err;
+   }
+
+#ifdef CONFIG_PCI
+   if (!iommu_present(_bus_type)) {
+   pci_request_acs();
+   err = bus_set_iommu(_bus_type, _smmu_ops);
+   if (err < 0)
+   return err;
+   }
+#endif
+   return 0;
+}
+
 struct tegra_smmu *tegra_smmu_probe(struct device *dev,
const struct tegra_smmu_soc *soc,
struct tegra_mc *mc)
@@ -1072,12 +1095,10 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
return ERR_PTR(err);
}
 
-   err = bus_set_iommu(_bus_type, _smmu_ops);
-   if (err < 0) {
-   iommu_device_unregister(>iommu);
-   iommu_device_sysfs_remove(>iommu);
+   err = tegra_smmu_iommu_bus_init(smmu);
+   if (err)
return ERR_PTR(err);
-   }
+   err = bus_set_iommu(_bus_type, _smmu_ops);
 
if (IS_ENABLED(CONFIG_DEBUG_FS))
tegra_smmu_debugfs_init(smmu);
-- 
2.7.4

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu