All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
@ 2016-06-29 17:14 ` Nipun Gupta
  0 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-29 17:14 UTC (permalink / raw)
  To: will.deacon-5wv7dgnIgG8, robin.murphy-5wv7dgnIgG8,
	stuart.yoder-3arQi8VN3Tc,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan

Added a header file fsl_mc_smmu.h to provide basic support of creating
an IOMMU group for a fsl-mc type device and also provide helper macro
to get the stream ID of fsl-mc tyoe device.

Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45 ++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h

diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
new file mode 100644
index 0000000..9dff5ba
--- /dev/null
+++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Author: Nipun Gupta <nipun.gupta-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef _FSL_MC_SMMU_H_
+#define _FSL_MC_SMMU_H_
+
+#include <../drivers/staging/fsl-mc/include/mc.h>
+
+/* Macro to get the MC device ICID (Stream ID) */
+#define fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
+
+/* Macro to get the container device of a MC device */
+#define fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
+	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
+
+/* Macro to check if a device is a container device */
+#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
+
+static struct iommu_group *fslmc_device_group(struct device *dev)
+{
+	struct device *cont_dev = fslmc_cont_dev(dev);
+	struct iommu_group *group;
+
+	/* Container device is responsible for creating the iommu group */
+	if (is_cont_dev(dev)) {
+		group = iommu_group_alloc();
+
+		if (IS_ERR(group))
+			return NULL;
+	} else {
+		get_device(cont_dev);
+		group = iommu_group_get(cont_dev);
+		put_device(cont_dev);
+	}
+
+	return group;
+}
+
+#endif /* _FSL_MC_SMMU_H_ */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
@ 2016-06-29 17:14 ` Nipun Gupta
  0 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-29 17:14 UTC (permalink / raw)
  To: linux-arm-kernel

Added a header file fsl_mc_smmu.h to provide basic support of creating
an IOMMU group for a fsl-mc type device and also provide helper macro
to get the stream ID of fsl-mc tyoe device.

Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
---
 drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45 ++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h

diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
new file mode 100644
index 0000000..9dff5ba
--- /dev/null
+++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Author: Nipun Gupta <nipun.gupta@freescale.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef _FSL_MC_SMMU_H_
+#define _FSL_MC_SMMU_H_
+
+#include <../drivers/staging/fsl-mc/include/mc.h>
+
+/* Macro to get the MC device ICID (Stream ID) */
+#define fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
+
+/* Macro to get the container device of a MC device */
+#define fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
+	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
+
+/* Macro to check if a device is a container device */
+#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
+
+static struct iommu_group *fslmc_device_group(struct device *dev)
+{
+	struct device *cont_dev = fslmc_cont_dev(dev);
+	struct iommu_group *group;
+
+	/* Container device is responsible for creating the iommu group */
+	if (is_cont_dev(dev)) {
+		group = iommu_group_alloc();
+
+		if (IS_ERR(group))
+			return NULL;
+	} else {
+		get_device(cont_dev);
+		group = iommu_group_get(cont_dev);
+		put_device(cont_dev);
+	}
+
+	return group;
+}
+
+#endif /* _FSL_MC_SMMU_H_ */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
  2016-06-29 17:14 ` Nipun Gupta
@ 2016-06-29 17:14     ` Nipun Gupta
  -1 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-29 17:14 UTC (permalink / raw)
  To: will.deacon-5wv7dgnIgG8, robin.murphy-5wv7dgnIgG8,
	stuart.yoder-3arQi8VN3Tc,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan

Implement bus specific support for the fsl-mc bus including
registering the arm_smmu_ops and bus specific smmu device init.

Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
---
 drivers/iommu/arm-smmu.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index ab365ec..28d5dc8 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -47,6 +47,9 @@
 
 #include <linux/amba/bus.h>
 
+/* Include path will be changed once FSL-MC support is out from staging */
+#include <../drivers/staging/fsl-mc/include/fsl_mc_smmu.h>
+
 #include "io-pgtable.h"
 
 /* Maximum number of stream IDs assigned to a single device */
@@ -447,6 +450,11 @@ static struct device_node *dev_get_dev_node(struct device *dev)
 		return bus->bridge->parent->of_node;
 	}
 
+	if (dev_is_fsl_mc(dev)) {
+		while (dev_is_fsl_mc(dev))
+			dev = dev->parent;
+	}
+
 	return dev->of_node;
 }
 
@@ -1443,6 +1451,32 @@ static int arm_smmu_init_platform_device(struct device *dev,
 	return 0;
 }
 
+static void __arm_smmu_release_fslmc_iommudata(void *data)
+{
+	kfree(data);
+}
+
+static int arm_smmu_init_fslmc_device(struct device *dev,
+				      struct iommu_group *group)
+{
+	struct arm_smmu_master_cfg *cfg;
+
+	cfg = iommu_group_get_iommudata(group);
+	if (!cfg) {
+		cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
+		if (!cfg)
+			return -ENOMEM;
+
+		cfg->streamids[0] = fslmc_dev_streamid(dev);
+		cfg->num_streamids = 1;
+
+		iommu_group_set_iommudata(group, cfg,
+					  __arm_smmu_release_fslmc_iommudata);
+	}
+
+	return 0;
+}
+
 static int arm_smmu_add_device(struct device *dev)
 {
 	struct iommu_group *group;
@@ -1467,6 +1501,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
 
 	if (dev_is_pci(dev))
 		group = pci_device_group(dev);
+	else if (dev_is_fsl_mc(dev))
+		group = fslmc_device_group(dev);
 	else
 		group = generic_device_group(dev);
 
@@ -1475,6 +1511,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
 
 	if (dev_is_pci(dev))
 		ret = arm_smmu_init_pci_device(to_pci_dev(dev), group);
+	else if (dev_is_fsl_mc(dev))
+		ret = arm_smmu_init_fslmc_device(dev, group);
 	else
 		ret = arm_smmu_init_platform_device(dev, group);
 
@@ -2102,6 +2140,11 @@ static int __init arm_smmu_init(void)
 	}
 #endif
 
+#ifdef CONFIG_FSL_MC_BUS
+	if (!iommu_present(&fsl_mc_bus_type))
+		bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops);
+#endif
+
 	return 0;
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
@ 2016-06-29 17:14     ` Nipun Gupta
  0 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-29 17:14 UTC (permalink / raw)
  To: linux-arm-kernel

Implement bus specific support for the fsl-mc bus including
registering the arm_smmu_ops and bus specific smmu device init.

Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
---
 drivers/iommu/arm-smmu.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index ab365ec..28d5dc8 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -47,6 +47,9 @@
 
 #include <linux/amba/bus.h>
 
+/* Include path will be changed once FSL-MC support is out from staging */
+#include <../drivers/staging/fsl-mc/include/fsl_mc_smmu.h>
+
 #include "io-pgtable.h"
 
 /* Maximum number of stream IDs assigned to a single device */
@@ -447,6 +450,11 @@ static struct device_node *dev_get_dev_node(struct device *dev)
 		return bus->bridge->parent->of_node;
 	}
 
+	if (dev_is_fsl_mc(dev)) {
+		while (dev_is_fsl_mc(dev))
+			dev = dev->parent;
+	}
+
 	return dev->of_node;
 }
 
@@ -1443,6 +1451,32 @@ static int arm_smmu_init_platform_device(struct device *dev,
 	return 0;
 }
 
+static void __arm_smmu_release_fslmc_iommudata(void *data)
+{
+	kfree(data);
+}
+
+static int arm_smmu_init_fslmc_device(struct device *dev,
+				      struct iommu_group *group)
+{
+	struct arm_smmu_master_cfg *cfg;
+
+	cfg = iommu_group_get_iommudata(group);
+	if (!cfg) {
+		cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
+		if (!cfg)
+			return -ENOMEM;
+
+		cfg->streamids[0] = fslmc_dev_streamid(dev);
+		cfg->num_streamids = 1;
+
+		iommu_group_set_iommudata(group, cfg,
+					  __arm_smmu_release_fslmc_iommudata);
+	}
+
+	return 0;
+}
+
 static int arm_smmu_add_device(struct device *dev)
 {
 	struct iommu_group *group;
@@ -1467,6 +1501,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
 
 	if (dev_is_pci(dev))
 		group = pci_device_group(dev);
+	else if (dev_is_fsl_mc(dev))
+		group = fslmc_device_group(dev);
 	else
 		group = generic_device_group(dev);
 
@@ -1475,6 +1511,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
 
 	if (dev_is_pci(dev))
 		ret = arm_smmu_init_pci_device(to_pci_dev(dev), group);
+	else if (dev_is_fsl_mc(dev))
+		ret = arm_smmu_init_fslmc_device(dev, group);
 	else
 		ret = arm_smmu_init_platform_device(dev, group);
 
@@ -2102,6 +2140,11 @@ static int __init arm_smmu_init(void)
 	}
 #endif
 
+#ifdef CONFIG_FSL_MC_BUS
+	if (!iommu_present(&fsl_mc_bus_type))
+		bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops);
+#endif
+
 	return 0;
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
  2016-06-29 17:14 ` Nipun Gupta
@ 2016-06-30 10:55     ` Robin Murphy
  -1 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2016-06-30 10:55 UTC (permalink / raw)
  To: Nipun Gupta, will.deacon-5wv7dgnIgG8, stuart.yoder-3arQi8VN3Tc,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan

On 29/06/16 18:14, Nipun Gupta wrote:
> Added a header file fsl_mc_smmu.h to provide basic support of creating
> an IOMMU group for a fsl-mc type device and also provide helper macro
> to get the stream ID of fsl-mc tyoe device.
> 
> Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
> Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> ---
>  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45 ++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> 
> diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> new file mode 100644
> index 0000000..9dff5ba
> --- /dev/null
> +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> @@ -0,0 +1,45 @@
> +/*
> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> + * Author: Nipun Gupta <nipun.gupta-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + */
> +
> +#ifndef _FSL_MC_SMMU_H_
> +#define _FSL_MC_SMMU_H_
> +
> +#include <../drivers/staging/fsl-mc/include/mc.h>
> +
> +/* Macro to get the MC device ICID (Stream ID) */
> +#define fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)

Is the the full 15-bit ICID from the MC's point of view, just the 7 bits
that are actually routed to the SMMU, or the actual stream ID seen by
the SMMU? None of those three are necessarily the same, and unless it's
the third then I don't see the point of patches adding incomplete code
which isn't going to work.

> +/* Macro to get the container device of a MC device */
> +#define fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
> +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
> +
> +/* Macro to check if a device is a container device */
> +#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
> +
> +static struct iommu_group *fslmc_device_group(struct device *dev)
> +{
> +	struct device *cont_dev = fslmc_cont_dev(dev);
> +	struct iommu_group *group;
> +
> +	/* Container device is responsible for creating the iommu group */
> +	if (is_cont_dev(dev)) {
> +		group = iommu_group_alloc();
> +
> +		if (IS_ERR(group))
> +			return NULL;
> +	} else {
> +		get_device(cont_dev);
> +		group = iommu_group_get(cont_dev);
> +		put_device(cont_dev);
> +	}
> +
> +	return group;
> +}

In isolation, though, this part seems perfectly reasonable.

Robin.

> +
> +#endif /* _FSL_MC_SMMU_H_ */
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
@ 2016-06-30 10:55     ` Robin Murphy
  0 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2016-06-30 10:55 UTC (permalink / raw)
  To: linux-arm-kernel

On 29/06/16 18:14, Nipun Gupta wrote:
> Added a header file fsl_mc_smmu.h to provide basic support of creating
> an IOMMU group for a fsl-mc type device and also provide helper macro
> to get the stream ID of fsl-mc tyoe device.
> 
> Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
> Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
> ---
>  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45 ++++++++++++++++++++++++++++
>  1 file changed, 45 insertions(+)
>  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> 
> diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> new file mode 100644
> index 0000000..9dff5ba
> --- /dev/null
> +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> @@ -0,0 +1,45 @@
> +/*
> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> + * Author: Nipun Gupta <nipun.gupta@freescale.com>
> + *
> + * This file is licensed under the terms of the GNU General Public
> + * License version 2. This program is licensed "as is" without any
> + * warranty of any kind, whether express or implied.
> + */
> +
> +#ifndef _FSL_MC_SMMU_H_
> +#define _FSL_MC_SMMU_H_
> +
> +#include <../drivers/staging/fsl-mc/include/mc.h>
> +
> +/* Macro to get the MC device ICID (Stream ID) */
> +#define fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)

Is the the full 15-bit ICID from the MC's point of view, just the 7 bits
that are actually routed to the SMMU, or the actual stream ID seen by
the SMMU? None of those three are necessarily the same, and unless it's
the third then I don't see the point of patches adding incomplete code
which isn't going to work.

> +/* Macro to get the container device of a MC device */
> +#define fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
> +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
> +
> +/* Macro to check if a device is a container device */
> +#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
> +
> +static struct iommu_group *fslmc_device_group(struct device *dev)
> +{
> +	struct device *cont_dev = fslmc_cont_dev(dev);
> +	struct iommu_group *group;
> +
> +	/* Container device is responsible for creating the iommu group */
> +	if (is_cont_dev(dev)) {
> +		group = iommu_group_alloc();
> +
> +		if (IS_ERR(group))
> +			return NULL;
> +	} else {
> +		get_device(cont_dev);
> +		group = iommu_group_get(cont_dev);
> +		put_device(cont_dev);
> +	}
> +
> +	return group;
> +}

In isolation, though, this part seems perfectly reasonable.

Robin.

> +
> +#endif /* _FSL_MC_SMMU_H_ */
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
  2016-06-29 17:14     ` Nipun Gupta
@ 2016-06-30 11:23         ` Robin Murphy
  -1 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2016-06-30 11:23 UTC (permalink / raw)
  To: Nipun Gupta, will.deacon-5wv7dgnIgG8, stuart.yoder-3arQi8VN3Tc,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan

On 29/06/16 18:14, Nipun Gupta wrote:
> Implement bus specific support for the fsl-mc bus including
> registering the arm_smmu_ops and bus specific smmu device init.
> 
> Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
> Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> ---
>  drivers/iommu/arm-smmu.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index ab365ec..28d5dc8 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -47,6 +47,9 @@
>  
>  #include <linux/amba/bus.h>
>  
> +/* Include path will be changed once FSL-MC support is out from staging */

How about we do that first?

> +#include <../drivers/staging/fsl-mc/include/fsl_mc_smmu.h>
> +
>  #include "io-pgtable.h"
>  
>  /* Maximum number of stream IDs assigned to a single device */
> @@ -447,6 +450,11 @@ static struct device_node *dev_get_dev_node(struct device *dev)
>  		return bus->bridge->parent->of_node;
>  	}
>  
> +	if (dev_is_fsl_mc(dev)) {

Where is dev_is_fsl_mc() defined? I don't see it anywhere in mainline,
here, or in -next.

> +		while (dev_is_fsl_mc(dev))
> +			dev = dev->parent;
> +	}
> +
>  	return dev->of_node;
>  }
>  
> @@ -1443,6 +1451,32 @@ static int arm_smmu_init_platform_device(struct device *dev,
>  	return 0;
>  }
>  
> +static void __arm_smmu_release_fslmc_iommudata(void *data)
> +{
> +	kfree(data);
> +}

There's already a suitable callback for this; nobody needs an exact
duplicate of it.

> +static int arm_smmu_init_fslmc_device(struct device *dev,
> +				      struct iommu_group *group)
> +{
> +	struct arm_smmu_master_cfg *cfg;
> +
> +	cfg = iommu_group_get_iommudata(group);
> +	if (!cfg) {
> +		cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
> +		if (!cfg)
> +			return -ENOMEM;
> +
> +		cfg->streamids[0] = fslmc_dev_streamid(dev);
> +		cfg->num_streamids = 1;
> +
> +		iommu_group_set_iommudata(group, cfg,
> +					  __arm_smmu_release_fslmc_iommudata);
> +	}

So the group gets the ID of the container device (assuming that's the
first one added), and the subsequent IDs are just ignored and left to go
wrong? Or is it inherently guaranteed that all devices in the same
container are programmed with the same ID?

Robin.

> +	return 0;
> +}
> +
>  static int arm_smmu_add_device(struct device *dev)
>  {
>  	struct iommu_group *group;
> @@ -1467,6 +1501,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
>  
>  	if (dev_is_pci(dev))
>  		group = pci_device_group(dev);
> +	else if (dev_is_fsl_mc(dev))
> +		group = fslmc_device_group(dev);
>  	else
>  		group = generic_device_group(dev);
>  
> @@ -1475,6 +1511,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
>  
>  	if (dev_is_pci(dev))
>  		ret = arm_smmu_init_pci_device(to_pci_dev(dev), group);
> +	else if (dev_is_fsl_mc(dev))
> +		ret = arm_smmu_init_fslmc_device(dev, group);
>  	else
>  		ret = arm_smmu_init_platform_device(dev, group);
>  
> @@ -2102,6 +2140,11 @@ static int __init arm_smmu_init(void)
>  	}
>  #endif
>  
> +#ifdef CONFIG_FSL_MC_BUS
> +	if (!iommu_present(&fsl_mc_bus_type))
> +		bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops);
> +#endif
> +
>  	return 0;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
@ 2016-06-30 11:23         ` Robin Murphy
  0 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2016-06-30 11:23 UTC (permalink / raw)
  To: linux-arm-kernel

On 29/06/16 18:14, Nipun Gupta wrote:
> Implement bus specific support for the fsl-mc bus including
> registering the arm_smmu_ops and bus specific smmu device init.
> 
> Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
> Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
> ---
>  drivers/iommu/arm-smmu.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index ab365ec..28d5dc8 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -47,6 +47,9 @@
>  
>  #include <linux/amba/bus.h>
>  
> +/* Include path will be changed once FSL-MC support is out from staging */

How about we do that first?

> +#include <../drivers/staging/fsl-mc/include/fsl_mc_smmu.h>
> +
>  #include "io-pgtable.h"
>  
>  /* Maximum number of stream IDs assigned to a single device */
> @@ -447,6 +450,11 @@ static struct device_node *dev_get_dev_node(struct device *dev)
>  		return bus->bridge->parent->of_node;
>  	}
>  
> +	if (dev_is_fsl_mc(dev)) {

Where is dev_is_fsl_mc() defined? I don't see it anywhere in mainline,
here, or in -next.

> +		while (dev_is_fsl_mc(dev))
> +			dev = dev->parent;
> +	}
> +
>  	return dev->of_node;
>  }
>  
> @@ -1443,6 +1451,32 @@ static int arm_smmu_init_platform_device(struct device *dev,
>  	return 0;
>  }
>  
> +static void __arm_smmu_release_fslmc_iommudata(void *data)
> +{
> +	kfree(data);
> +}

There's already a suitable callback for this; nobody needs an exact
duplicate of it.

> +static int arm_smmu_init_fslmc_device(struct device *dev,
> +				      struct iommu_group *group)
> +{
> +	struct arm_smmu_master_cfg *cfg;
> +
> +	cfg = iommu_group_get_iommudata(group);
> +	if (!cfg) {
> +		cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
> +		if (!cfg)
> +			return -ENOMEM;
> +
> +		cfg->streamids[0] = fslmc_dev_streamid(dev);
> +		cfg->num_streamids = 1;
> +
> +		iommu_group_set_iommudata(group, cfg,
> +					  __arm_smmu_release_fslmc_iommudata);
> +	}

So the group gets the ID of the container device (assuming that's the
first one added), and the subsequent IDs are just ignored and left to go
wrong? Or is it inherently guaranteed that all devices in the same
container are programmed with the same ID?

Robin.

> +	return 0;
> +}
> +
>  static int arm_smmu_add_device(struct device *dev)
>  {
>  	struct iommu_group *group;
> @@ -1467,6 +1501,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
>  
>  	if (dev_is_pci(dev))
>  		group = pci_device_group(dev);
> +	else if (dev_is_fsl_mc(dev))
> +		group = fslmc_device_group(dev);
>  	else
>  		group = generic_device_group(dev);
>  
> @@ -1475,6 +1511,8 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
>  
>  	if (dev_is_pci(dev))
>  		ret = arm_smmu_init_pci_device(to_pci_dev(dev), group);
> +	else if (dev_is_fsl_mc(dev))
> +		ret = arm_smmu_init_fslmc_device(dev, group);
>  	else
>  		ret = arm_smmu_init_platform_device(dev, group);
>  
> @@ -2102,6 +2140,11 @@ static int __init arm_smmu_init(void)
>  	}
>  #endif
>  
> +#ifdef CONFIG_FSL_MC_BUS
> +	if (!iommu_present(&fsl_mc_bus_type))
> +		bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops);
> +#endif
> +
>  	return 0;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
  2016-06-30 10:55     ` Robin Murphy
@ 2016-06-30 11:43         ` Nipun Gupta
  -1 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-30 11:43 UTC (permalink / raw)
  To: Robin Murphy, will.deacon-5wv7dgnIgG8, Stuart Yoder,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan



> -----Original Message-----
> From: Robin Murphy [mailto:robin.murphy-5wv7dgnIgG8@public.gmane.org]
> Sent: Thursday, June 30, 2016 16:26
> To: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>; will.deacon-5wv7dgnIgG8@public.gmane.org; Stuart Yoder
> <stuart.yoder-3arQi8VN3Tc@public.gmane.org>; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linux-arm-
> kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> Cc: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus
> iommu group creation
> 
> On 29/06/16 18:14, Nipun Gupta wrote:
> > Added a header file fsl_mc_smmu.h to provide basic support of creating
> > an IOMMU group for a fsl-mc type device and also provide helper macro
> > to get the stream ID of fsl-mc tyoe device.
> >
> > Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
> > Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> > ---
> >  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45
> > ++++++++++++++++++++++++++++
> >  1 file changed, 45 insertions(+)
> >  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >
> > diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> > b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> > new file mode 100644
> > index 0000000..9dff5ba
> > --- /dev/null
> > +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> > @@ -0,0 +1,45 @@
> > +/*
> > + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> > + * Author: Nipun Gupta <nipun.gupta-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > + *
> > + * This file is licensed under the terms of the GNU General Public
> > + * License version 2. This program is licensed "as is" without any
> > + * warranty of any kind, whether express or implied.
> > + */
> > +
> > +#ifndef _FSL_MC_SMMU_H_
> > +#define _FSL_MC_SMMU_H_
> > +
> > +#include <../drivers/staging/fsl-mc/include/mc.h>
> > +
> > +/* Macro to get the MC device ICID (Stream ID) */ #define
> > +fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
> 
> Is the the full 15-bit ICID from the MC's point of view, just the 7 bits that are
> actually routed to the SMMU, or the actual stream ID seen by the SMMU? None
> of those three are necessarily the same, and unless it's the third then I don't see
> the point of patches adding incomplete code which isn't going to work.

Hi Robin,

It's the second one where just 7 bits are maintained in the 'fsl_mc_device--->icid' which is programmed in SMMU. Right, once the SMR masking support is there then only these patches would make more sense. 
We have sent these patches to get some early comments and to have you guys well informed beforehand about the changes which we require in the SMMU driver specific to fsl-mc bus :).

Thanks,
Nipun

> 
> > +/* Macro to get the container device of a MC device */ #define
> > +fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
> > +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
> > +
> > +/* Macro to check if a device is a container device */ #define
> > +is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
> > +
> > +static struct iommu_group *fslmc_device_group(struct device *dev) {
> > +	struct device *cont_dev = fslmc_cont_dev(dev);
> > +	struct iommu_group *group;
> > +
> > +	/* Container device is responsible for creating the iommu group */
> > +	if (is_cont_dev(dev)) {
> > +		group = iommu_group_alloc();
> > +
> > +		if (IS_ERR(group))
> > +			return NULL;
> > +	} else {
> > +		get_device(cont_dev);
> > +		group = iommu_group_get(cont_dev);
> > +		put_device(cont_dev);
> > +	}
> > +
> > +	return group;
> > +}
> 
> In isolation, though, this part seems perfectly reasonable.
> 
> Robin.
> 
> > +
> > +#endif /* _FSL_MC_SMMU_H_ */
> >

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
@ 2016-06-30 11:43         ` Nipun Gupta
  0 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-30 11:43 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Robin Murphy [mailto:robin.murphy at arm.com]
> Sent: Thursday, June 30, 2016 16:26
> To: Nipun Gupta <nipun.gupta@nxp.com>; will.deacon at arm.com; Stuart Yoder
> <stuart.yoder@nxp.com>; iommu at lists.linux-foundation.org; linux-arm-
> kernel at lists.infradead.org
> Cc: Bharat Bhushan <bharat.bhushan@nxp.com>
> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus
> iommu group creation
> 
> On 29/06/16 18:14, Nipun Gupta wrote:
> > Added a header file fsl_mc_smmu.h to provide basic support of creating
> > an IOMMU group for a fsl-mc type device and also provide helper macro
> > to get the stream ID of fsl-mc tyoe device.
> >
> > Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
> > Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
> > ---
> >  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45
> > ++++++++++++++++++++++++++++
> >  1 file changed, 45 insertions(+)
> >  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >
> > diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> > b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> > new file mode 100644
> > index 0000000..9dff5ba
> > --- /dev/null
> > +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> > @@ -0,0 +1,45 @@
> > +/*
> > + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> > + * Author: Nipun Gupta <nipun.gupta@freescale.com>
> > + *
> > + * This file is licensed under the terms of the GNU General Public
> > + * License version 2. This program is licensed "as is" without any
> > + * warranty of any kind, whether express or implied.
> > + */
> > +
> > +#ifndef _FSL_MC_SMMU_H_
> > +#define _FSL_MC_SMMU_H_
> > +
> > +#include <../drivers/staging/fsl-mc/include/mc.h>
> > +
> > +/* Macro to get the MC device ICID (Stream ID) */ #define
> > +fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
> 
> Is the the full 15-bit ICID from the MC's point of view, just the 7 bits that are
> actually routed to the SMMU, or the actual stream ID seen by the SMMU? None
> of those three are necessarily the same, and unless it's the third then I don't see
> the point of patches adding incomplete code which isn't going to work.

Hi Robin,

It's the second one where just 7 bits are maintained in the 'fsl_mc_device--->icid' which is programmed in SMMU. Right, once the SMR masking support is there then only these patches would make more sense. 
We have sent these patches to get some early comments and to have you guys well informed beforehand about the changes which we require in the SMMU driver specific to fsl-mc bus :).

Thanks,
Nipun

> 
> > +/* Macro to get the container device of a MC device */ #define
> > +fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
> > +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
> > +
> > +/* Macro to check if a device is a container device */ #define
> > +is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
> > +
> > +static struct iommu_group *fslmc_device_group(struct device *dev) {
> > +	struct device *cont_dev = fslmc_cont_dev(dev);
> > +	struct iommu_group *group;
> > +
> > +	/* Container device is responsible for creating the iommu group */
> > +	if (is_cont_dev(dev)) {
> > +		group = iommu_group_alloc();
> > +
> > +		if (IS_ERR(group))
> > +			return NULL;
> > +	} else {
> > +		get_device(cont_dev);
> > +		group = iommu_group_get(cont_dev);
> > +		put_device(cont_dev);
> > +	}
> > +
> > +	return group;
> > +}
> 
> In isolation, though, this part seems perfectly reasonable.
> 
> Robin.
> 
> > +
> > +#endif /* _FSL_MC_SMMU_H_ */
> >

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
  2016-06-30 11:23         ` Robin Murphy
@ 2016-06-30 12:11             ` Nipun Gupta
  -1 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-30 12:11 UTC (permalink / raw)
  To: Robin Murphy, will.deacon-5wv7dgnIgG8, Stuart Yoder,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan

[-- Attachment #1: Type: text/plain, Size: 4921 bytes --]



> -----Original Message-----
> From: Robin Murphy [mailto:robin.murphy-5wv7dgnIgG8@public.gmane.org]
> Sent: Thursday, June 30, 2016 16:53
> To: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>; will.deacon-5wv7dgnIgG8@public.gmane.org; Stuart Yoder
> <stuart.yoder-3arQi8VN3Tc@public.gmane.org>; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linux-arm-
> kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> Cc: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> Subject: Re: [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
> 
> On 29/06/16 18:14, Nipun Gupta wrote:
> > Implement bus specific support for the fsl-mc bus including
> > registering the arm_smmu_ops and bus specific smmu device init.
> >
> > Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
> > Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> > ---
> >  drivers/iommu/arm-smmu.c | 43
> > +++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 43 insertions(+)
> >
> > diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index
> > ab365ec..28d5dc8 100644
> > --- a/drivers/iommu/arm-smmu.c
> > +++ b/drivers/iommu/arm-smmu.c
> > @@ -47,6 +47,9 @@
> >
> >  #include <linux/amba/bus.h>
> >
> > +/* Include path will be changed once FSL-MC support is out from
> > +staging */
> 
> How about we do that first?

Agree. We are working on that part :)

> 
> > +#include <../drivers/staging/fsl-mc/include/fsl_mc_smmu.h>
> > +
> >  #include "io-pgtable.h"
> >
> >  /* Maximum number of stream IDs assigned to a single device */ @@
> > -447,6 +450,11 @@ static struct device_node *dev_get_dev_node(struct
> device *dev)
> >  		return bus->bridge->parent->of_node;
> >  	}
> >
> > +	if (dev_is_fsl_mc(dev)) {
> 
> Where is dev_is_fsl_mc() defined? I don't see it anywhere in mainline, here, or in
> -next.

My Bad. We have provided a patch on the devel-gWbeCf7V1WCQmaza687I9mD2FQJk+8+b@public.gmane.org ; linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org to have the macro dev_is_fsl_mc defined. Please see the attached patch.

> 
> > +		while (dev_is_fsl_mc(dev))
> > +			dev = dev->parent;
> > +	}
> > +
> >  	return dev->of_node;
> >  }
> >
> > @@ -1443,6 +1451,32 @@ static int arm_smmu_init_platform_device(struct
> device *dev,
> >  	return 0;
> >  }
> >
> > +static void __arm_smmu_release_fslmc_iommudata(void *data) {
> > +	kfree(data);
> > +}
> 
> There's already a suitable callback for this; nobody needs an exact duplicate of
> it.

I see '__arm_smmu_release_pci_iommudata' similarly defined for PCI bus.
We will probably need it renaming to '__arm_smmu_release_iommudata' to have a better readable code. Seems okay?

> 
> > +static int arm_smmu_init_fslmc_device(struct device *dev,
> > +				      struct iommu_group *group)
> > +{
> > +	struct arm_smmu_master_cfg *cfg;
> > +
> > +	cfg = iommu_group_get_iommudata(group);
> > +	if (!cfg) {
> > +		cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
> > +		if (!cfg)
> > +			return -ENOMEM;
> > +
> > +		cfg->streamids[0] = fslmc_dev_streamid(dev);
> > +		cfg->num_streamids = 1;
> > +
> > +		iommu_group_set_iommudata(group, cfg,
> > +
> __arm_smmu_release_fslmc_iommudata);
> > +	}
> 
> So the group gets the ID of the container device (assuming that's the first one
> added), and the subsequent IDs are just ignored and left to go wrong? Or is it
> inherently guaranteed that all devices in the same container are programmed
> with the same ID?

Yeah latter one is correct!! Each container is associated with an ID which is common for all the devices. Container device gets added first and is responsible for creating the iommu group and the master CFG.

Thanks,
Nipun

> 
> Robin.
> 
> > +	return 0;
> > +}
> > +
> >  static int arm_smmu_add_device(struct device *dev)  {
> >  	struct iommu_group *group;
> > @@ -1467,6 +1501,8 @@ static struct iommu_group
> > *arm_smmu_device_group(struct device *dev)
> >
> >  	if (dev_is_pci(dev))
> >  		group = pci_device_group(dev);
> > +	else if (dev_is_fsl_mc(dev))
> > +		group = fslmc_device_group(dev);
> >  	else
> >  		group = generic_device_group(dev);
> >
> > @@ -1475,6 +1511,8 @@ static struct iommu_group
> > *arm_smmu_device_group(struct device *dev)
> >
> >  	if (dev_is_pci(dev))
> >  		ret = arm_smmu_init_pci_device(to_pci_dev(dev), group);
> > +	else if (dev_is_fsl_mc(dev))
> > +		ret = arm_smmu_init_fslmc_device(dev, group);
> >  	else
> >  		ret = arm_smmu_init_platform_device(dev, group);
> >
> > @@ -2102,6 +2140,11 @@ static int __init arm_smmu_init(void)
> >  	}
> >  #endif
> >
> > +#ifdef CONFIG_FSL_MC_BUS
> > +	if (!iommu_present(&fsl_mc_bus_type))
> > +		bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops); #endif
> > +
> >  	return 0;
> >  }
> >
> >


[-- Attachment #2: Type: message/rfc822, Size: 9347 bytes --]

From: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
To: "gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org" <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>, Stuart Yoder <stuart.yoder-3arQi8VN3Tc@public.gmane.org>
Cc: "devel-gWbeCf7V1WCQmaza687I9mD2FQJk+8+b@public.gmane.org" <devel-gWbeCf7V1WCQmaza687I9mD2FQJk+8+b@public.gmane.org>, "linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org" <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>, Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>, Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
Subject: [PATCH v2] fsl-mc: add helper macro to determine if a device is of fsl_mc type
Date: Wed, 29 Jun 2016 17:14:39 +0000
Message-ID: <1467220479-16864-1-git-send-email-nipun.gupta-3arQi8VN3Tc@public.gmane.org>

Add a helper macro to return if a device has a bus type of fsl_mc.
This makes the bus driver code more readable and provides a way for
drivers like the SMMU driver to easily check the bus type.

Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
---
 drivers/staging/fsl-mc/bus/dprc-driver.c               | 4 ++--
 drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 2 +-
 drivers/staging/fsl-mc/bus/mc-allocator.c              | 6 +++---
 drivers/staging/fsl-mc/bus/mc-bus.c                    | 6 +++---
 drivers/staging/fsl-mc/include/mc.h                    | 7 +++++++
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 7fc4717..cd6d75a 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -649,7 +649,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
                /*
                 * This is a child DPRC:
                 */
-               if (WARN_ON(parent_dev->bus != &fsl_mc_bus_type))
+               if (WARN_ON(!dev_is_fsl_mc(parent_dev)))
                        return -EINVAL;

                if (WARN_ON(mc_dev->obj_desc.region_count == 0))
@@ -681,7 +681,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
                 */
                struct irq_domain *mc_msi_domain;

-               if (WARN_ON(parent_dev->bus == &fsl_mc_bus_type))
+               if (WARN_ON(dev_is_fsl_mc(parent_dev)))
                        return -EINVAL;

                error = fsl_mc_find_msi_domain(parent_dev,
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 720e2b0..d0c20d6 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -35,7 +35,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
        struct fsl_mc_device *mc_bus_dev;
        struct msi_domain_info *msi_info;

-       if (WARN_ON(dev->bus != &fsl_mc_bus_type))
+       if (WARN_ON(!dev_is_fsl_mc(dev)))
                return -EINVAL;

        mc_bus_dev = to_fsl_mc_device(dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fsl-mc/bus/mc-allocator.c
index fb08f22..9216c32 100644
--- a/drivers/staging/fsl-mc/bus/mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/mc-allocator.c
@@ -281,7 +281,7 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
        if (mc_dev->flags & FSL_MC_IS_DPRC) {
                mc_bus_dev = mc_dev;
        } else {
-               if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type))
+               if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent)))
                        return error;

                mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
@@ -420,7 +420,7 @@ int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
        if (WARN_ON(mc_dev->flags & FSL_MC_IS_DPRC))
                goto error;

-       if (WARN_ON(mc_dev->dev.parent->bus != &fsl_mc_bus_type))
+       if (WARN_ON(!dev_is_fsl_mc(mc_dev->dev.parent)))
                goto error;

        if (WARN_ON(pool_type == FSL_MC_POOL_DPMCP))
@@ -678,7 +678,7 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev)
                return -EINVAL;

        mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
-       if (WARN_ON(mc_bus_dev->dev.bus != &fsl_mc_bus_type))
+       if (WARN_ON(!dev_is_fsl_mc(&mc_bus_dev->dev)))
                return -EINVAL;

        mc_bus = to_fsl_mc_bus(mc_bus_dev);
diff --git a/drivers/staging/fsl-mc/bus/mc-bus.c b/drivers/staging/fsl-mc/bus/mc-bus.c
index 4053643..098f07c 100644
--- a/drivers/staging/fsl-mc/bus/mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/mc-bus.c
@@ -207,11 +207,11 @@ static void fsl_mc_get_root_dprc(struct device *dev,
 {
        if (WARN_ON(!dev)) {
                *root_dprc_dev = NULL;
-       } else if (WARN_ON(dev->bus != &fsl_mc_bus_type)) {
+       } else if (WARN_ON(!dev_is_fsl_mc(dev))) {
                *root_dprc_dev = NULL;
        } else {
                *root_dprc_dev = dev;
-               while ((*root_dprc_dev)->parent->bus == &fsl_mc_bus_type)
+               while (dev_is_fsl_mc((*root_dprc_dev)->parent))
                        *root_dprc_dev = (*root_dprc_dev)->parent;
        }
 }
@@ -405,7 +405,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
        struct fsl_mc_bus *mc_bus = NULL;
        struct fsl_mc_device *parent_mc_dev;

-       if (parent_dev->bus == &fsl_mc_bus_type)
+       if (dev_is_fsl_mc(parent_dev))
                parent_mc_dev = to_fsl_mc_device(parent_dev);
        else
                parent_mc_dev = NULL;
diff --git a/drivers/staging/fsl-mc/include/mc.h b/drivers/staging/fsl-mc/include/mc.h
index ac7c1ce..91213f5 100644
--- a/drivers/staging/fsl-mc/include/mc.h
+++ b/drivers/staging/fsl-mc/include/mc.h
@@ -183,6 +183,13 @@ struct fsl_mc_device {
 #define to_fsl_mc_device(_dev) \
        container_of(_dev, struct fsl_mc_device, dev)

+#ifdef CONFIG_FSL_MC_BUS
+#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type)
+#else
+/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */
+#define dev_is_fsl_mc(_dev) (0)
+#endif
+
 /*
  * module_fsl_mc_driver() - Helper macro for drivers that don't do
  * anything special in module init/exit.  This eliminates a lot of
--
1.9.1


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
@ 2016-06-30 12:11             ` Nipun Gupta
  0 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-06-30 12:11 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Robin Murphy [mailto:robin.murphy at arm.com]
> Sent: Thursday, June 30, 2016 16:53
> To: Nipun Gupta <nipun.gupta@nxp.com>; will.deacon at arm.com; Stuart Yoder
> <stuart.yoder@nxp.com>; iommu at lists.linux-foundation.org; linux-arm-
> kernel at lists.infradead.org
> Cc: Bharat Bhushan <bharat.bhushan@nxp.com>
> Subject: Re: [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus
> 
> On 29/06/16 18:14, Nipun Gupta wrote:
> > Implement bus specific support for the fsl-mc bus including
> > registering the arm_smmu_ops and bus specific smmu device init.
> >
> > Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
> > Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
> > ---
> >  drivers/iommu/arm-smmu.c | 43
> > +++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 43 insertions(+)
> >
> > diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index
> > ab365ec..28d5dc8 100644
> > --- a/drivers/iommu/arm-smmu.c
> > +++ b/drivers/iommu/arm-smmu.c
> > @@ -47,6 +47,9 @@
> >
> >  #include <linux/amba/bus.h>
> >
> > +/* Include path will be changed once FSL-MC support is out from
> > +staging */
> 
> How about we do that first?

Agree. We are working on that part :)

> 
> > +#include <../drivers/staging/fsl-mc/include/fsl_mc_smmu.h>
> > +
> >  #include "io-pgtable.h"
> >
> >  /* Maximum number of stream IDs assigned to a single device */ @@
> > -447,6 +450,11 @@ static struct device_node *dev_get_dev_node(struct
> device *dev)
> >  		return bus->bridge->parent->of_node;
> >  	}
> >
> > +	if (dev_is_fsl_mc(dev)) {
> 
> Where is dev_is_fsl_mc() defined? I don't see it anywhere in mainline, here, or in
> -next.

My Bad. We have provided a patch on the devel at driverdev.osuosl.org ; linux-kernel at vger.kernel.org to have the macro dev_is_fsl_mc defined. Please see the attached patch.

> 
> > +		while (dev_is_fsl_mc(dev))
> > +			dev = dev->parent;
> > +	}
> > +
> >  	return dev->of_node;
> >  }
> >
> > @@ -1443,6 +1451,32 @@ static int arm_smmu_init_platform_device(struct
> device *dev,
> >  	return 0;
> >  }
> >
> > +static void __arm_smmu_release_fslmc_iommudata(void *data) {
> > +	kfree(data);
> > +}
> 
> There's already a suitable callback for this; nobody needs an exact duplicate of
> it.

I see '__arm_smmu_release_pci_iommudata' similarly defined for PCI bus.
We will probably need it renaming to '__arm_smmu_release_iommudata' to have a better readable code. Seems okay?

> 
> > +static int arm_smmu_init_fslmc_device(struct device *dev,
> > +				      struct iommu_group *group)
> > +{
> > +	struct arm_smmu_master_cfg *cfg;
> > +
> > +	cfg = iommu_group_get_iommudata(group);
> > +	if (!cfg) {
> > +		cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
> > +		if (!cfg)
> > +			return -ENOMEM;
> > +
> > +		cfg->streamids[0] = fslmc_dev_streamid(dev);
> > +		cfg->num_streamids = 1;
> > +
> > +		iommu_group_set_iommudata(group, cfg,
> > +
> __arm_smmu_release_fslmc_iommudata);
> > +	}
> 
> So the group gets the ID of the container device (assuming that's the first one
> added), and the subsequent IDs are just ignored and left to go wrong? Or is it
> inherently guaranteed that all devices in the same container are programmed
> with the same ID?

Yeah latter one is correct!! Each container is associated with an ID which is common for all the devices. Container device gets added first and is responsible for creating the iommu group and the master CFG.

Thanks,
Nipun

> 
> Robin.
> 
> > +	return 0;
> > +}
> > +
> >  static int arm_smmu_add_device(struct device *dev)  {
> >  	struct iommu_group *group;
> > @@ -1467,6 +1501,8 @@ static struct iommu_group
> > *arm_smmu_device_group(struct device *dev)
> >
> >  	if (dev_is_pci(dev))
> >  		group = pci_device_group(dev);
> > +	else if (dev_is_fsl_mc(dev))
> > +		group = fslmc_device_group(dev);
> >  	else
> >  		group = generic_device_group(dev);
> >
> > @@ -1475,6 +1511,8 @@ static struct iommu_group
> > *arm_smmu_device_group(struct device *dev)
> >
> >  	if (dev_is_pci(dev))
> >  		ret = arm_smmu_init_pci_device(to_pci_dev(dev), group);
> > +	else if (dev_is_fsl_mc(dev))
> > +		ret = arm_smmu_init_fslmc_device(dev, group);
> >  	else
> >  		ret = arm_smmu_init_platform_device(dev, group);
> >
> > @@ -2102,6 +2140,11 @@ static int __init arm_smmu_init(void)
> >  	}
> >  #endif
> >
> > +#ifdef CONFIG_FSL_MC_BUS
> > +	if (!iommu_present(&fsl_mc_bus_type))
> > +		bus_set_iommu(&fsl_mc_bus_type, &arm_smmu_ops); #endif
> > +
> >  	return 0;
> >  }
> >
> >

-------------- next part --------------
An embedded message was scrubbed...
From: Nipun Gupta <nipun.gupta@nxp.com>
Subject: [PATCH v2] fsl-mc: add helper macro to determine if a device is of fsl_mc type
Date: Wed, 29 Jun 2016 17:14:39 +0000
Size: 9077
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160630/563688cd/attachment.mht>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
  2016-06-30 11:43         ` Nipun Gupta
@ 2016-06-30 14:14             ` Robin Murphy
  -1 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2016-06-30 14:14 UTC (permalink / raw)
  To: Nipun Gupta, will.deacon-5wv7dgnIgG8, Stuart Yoder,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan

On 30/06/16 12:43, Nipun Gupta wrote:
> 
> 
>> -----Original Message-----
>> From: Robin Murphy [mailto:robin.murphy-5wv7dgnIgG8@public.gmane.org]
>> Sent: Thursday, June 30, 2016 16:26
>> To: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>; will.deacon-5wv7dgnIgG8@public.gmane.org; Stuart Yoder
>> <stuart.yoder-3arQi8VN3Tc@public.gmane.org>; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linux-arm-
>> kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
>> Cc: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
>> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus
>> iommu group creation
>>
>> On 29/06/16 18:14, Nipun Gupta wrote:
>>> Added a header file fsl_mc_smmu.h to provide basic support of creating
>>> an IOMMU group for a fsl-mc type device and also provide helper macro
>>> to get the stream ID of fsl-mc tyoe device.
>>>
>>> Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
>>> Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
>>> ---
>>>  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45
>>> ++++++++++++++++++++++++++++
>>>  1 file changed, 45 insertions(+)
>>>  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>>
>>> diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>> b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>> new file mode 100644
>>> index 0000000..9dff5ba
>>> --- /dev/null
>>> +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>> @@ -0,0 +1,45 @@
>>> +/*
>>> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
>>> + * Author: Nipun Gupta <nipun.gupta-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
>>> + *
>>> + * This file is licensed under the terms of the GNU General Public
>>> + * License version 2. This program is licensed "as is" without any
>>> + * warranty of any kind, whether express or implied.
>>> + */
>>> +
>>> +#ifndef _FSL_MC_SMMU_H_
>>> +#define _FSL_MC_SMMU_H_
>>> +
>>> +#include <../drivers/staging/fsl-mc/include/mc.h>
>>> +
>>> +/* Macro to get the MC device ICID (Stream ID) */ #define
>>> +fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
>>
>> Is the the full 15-bit ICID from the MC's point of view, just the 7 bits that are
>> actually routed to the SMMU, or the actual stream ID seen by the SMMU? None
>> of those three are necessarily the same, and unless it's the third then I don't see
>> the point of patches adding incomplete code which isn't going to work.
> 
> Hi Robin,
> 
> It's the second one where just 7 bits are maintained in the 'fsl_mc_device--->icid' which is programmed in SMMU. Right, once the SMR masking support is there then only these patches would make more sense. 
> We have sent these patches to get some early comments and to have you guys well informed beforehand about the changes which we require in the SMMU driver specific to fsl-mc bus :).

Indeed, it's just kinda hard to review incomplete code, especially when
it's the parts which don't exist yet which are the most significant ;)

Either way, I'm deep in the middle of reworking SMMUv2 generic
bindings[1] based on the latest iteration of the core code and
iommu_fwspec[2], which removes the need for nearly all the bus-specific
business within the driver (it's getting too big to be 4.8 material now,
but I'll have something to post shortly). In that context, if the fsl-mc
driver could process an "iommu-map" property on the MC node to plumb the
ICID-to-stream-ID relationship into of_xlate, and inherit bus->iommu_ops
from its parent bus, there shouldn't be any need to directly touch the
SMMU driver at all.

Robin.

[1]:http://thread.gmane.org/gmane.linux.kernel.iommu/12454
[2]:http://thread.gmane.org/gmane.linux.kernel.iommu/14303

> 
> Thanks,
> Nipun
> 
>>
>>> +/* Macro to get the container device of a MC device */ #define
>>> +fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
>>> +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
>>> +
>>> +/* Macro to check if a device is a container device */ #define
>>> +is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
>>> +
>>> +static struct iommu_group *fslmc_device_group(struct device *dev) {
>>> +	struct device *cont_dev = fslmc_cont_dev(dev);
>>> +	struct iommu_group *group;
>>> +
>>> +	/* Container device is responsible for creating the iommu group */
>>> +	if (is_cont_dev(dev)) {
>>> +		group = iommu_group_alloc();
>>> +
>>> +		if (IS_ERR(group))
>>> +			return NULL;
>>> +	} else {
>>> +		get_device(cont_dev);
>>> +		group = iommu_group_get(cont_dev);
>>> +		put_device(cont_dev);
>>> +	}
>>> +
>>> +	return group;
>>> +}
>>
>> In isolation, though, this part seems perfectly reasonable.
>>
>> Robin.
>>
>>> +
>>> +#endif /* _FSL_MC_SMMU_H_ */
>>>
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
@ 2016-06-30 14:14             ` Robin Murphy
  0 siblings, 0 replies; 16+ messages in thread
From: Robin Murphy @ 2016-06-30 14:14 UTC (permalink / raw)
  To: linux-arm-kernel

On 30/06/16 12:43, Nipun Gupta wrote:
> 
> 
>> -----Original Message-----
>> From: Robin Murphy [mailto:robin.murphy at arm.com]
>> Sent: Thursday, June 30, 2016 16:26
>> To: Nipun Gupta <nipun.gupta@nxp.com>; will.deacon at arm.com; Stuart Yoder
>> <stuart.yoder@nxp.com>; iommu at lists.linux-foundation.org; linux-arm-
>> kernel at lists.infradead.org
>> Cc: Bharat Bhushan <bharat.bhushan@nxp.com>
>> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus
>> iommu group creation
>>
>> On 29/06/16 18:14, Nipun Gupta wrote:
>>> Added a header file fsl_mc_smmu.h to provide basic support of creating
>>> an IOMMU group for a fsl-mc type device and also provide helper macro
>>> to get the stream ID of fsl-mc tyoe device.
>>>
>>> Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
>>> Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
>>> ---
>>>  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45
>>> ++++++++++++++++++++++++++++
>>>  1 file changed, 45 insertions(+)
>>>  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>>
>>> diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>> b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>> new file mode 100644
>>> index 0000000..9dff5ba
>>> --- /dev/null
>>> +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
>>> @@ -0,0 +1,45 @@
>>> +/*
>>> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
>>> + * Author: Nipun Gupta <nipun.gupta@freescale.com>
>>> + *
>>> + * This file is licensed under the terms of the GNU General Public
>>> + * License version 2. This program is licensed "as is" without any
>>> + * warranty of any kind, whether express or implied.
>>> + */
>>> +
>>> +#ifndef _FSL_MC_SMMU_H_
>>> +#define _FSL_MC_SMMU_H_
>>> +
>>> +#include <../drivers/staging/fsl-mc/include/mc.h>
>>> +
>>> +/* Macro to get the MC device ICID (Stream ID) */ #define
>>> +fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
>>
>> Is the the full 15-bit ICID from the MC's point of view, just the 7 bits that are
>> actually routed to the SMMU, or the actual stream ID seen by the SMMU? None
>> of those three are necessarily the same, and unless it's the third then I don't see
>> the point of patches adding incomplete code which isn't going to work.
> 
> Hi Robin,
> 
> It's the second one where just 7 bits are maintained in the 'fsl_mc_device--->icid' which is programmed in SMMU. Right, once the SMR masking support is there then only these patches would make more sense. 
> We have sent these patches to get some early comments and to have you guys well informed beforehand about the changes which we require in the SMMU driver specific to fsl-mc bus :).

Indeed, it's just kinda hard to review incomplete code, especially when
it's the parts which don't exist yet which are the most significant ;)

Either way, I'm deep in the middle of reworking SMMUv2 generic
bindings[1] based on the latest iteration of the core code and
iommu_fwspec[2], which removes the need for nearly all the bus-specific
business within the driver (it's getting too big to be 4.8 material now,
but I'll have something to post shortly). In that context, if the fsl-mc
driver could process an "iommu-map" property on the MC node to plumb the
ICID-to-stream-ID relationship into of_xlate, and inherit bus->iommu_ops
from its parent bus, there shouldn't be any need to directly touch the
SMMU driver at all.

Robin.

[1]:http://thread.gmane.org/gmane.linux.kernel.iommu/12454
[2]:http://thread.gmane.org/gmane.linux.kernel.iommu/14303

> 
> Thanks,
> Nipun
> 
>>
>>> +/* Macro to get the container device of a MC device */ #define
>>> +fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
>>> +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
>>> +
>>> +/* Macro to check if a device is a container device */ #define
>>> +is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
>>> +
>>> +static struct iommu_group *fslmc_device_group(struct device *dev) {
>>> +	struct device *cont_dev = fslmc_cont_dev(dev);
>>> +	struct iommu_group *group;
>>> +
>>> +	/* Container device is responsible for creating the iommu group */
>>> +	if (is_cont_dev(dev)) {
>>> +		group = iommu_group_alloc();
>>> +
>>> +		if (IS_ERR(group))
>>> +			return NULL;
>>> +	} else {
>>> +		get_device(cont_dev);
>>> +		group = iommu_group_get(cont_dev);
>>> +		put_device(cont_dev);
>>> +	}
>>> +
>>> +	return group;
>>> +}
>>
>> In isolation, though, this part seems perfectly reasonable.
>>
>> Robin.
>>
>>> +
>>> +#endif /* _FSL_MC_SMMU_H_ */
>>>
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
  2016-06-30 14:14             ` Robin Murphy
@ 2016-07-01 15:11                 ` Nipun Gupta
  -1 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-07-01 15:11 UTC (permalink / raw)
  To: Robin Murphy, will.deacon-5wv7dgnIgG8, Stuart Yoder,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: Bharat Bhushan



> -----Original Message-----
> From: Robin Murphy [mailto:robin.murphy-5wv7dgnIgG8@public.gmane.org]
> Sent: Thursday, June 30, 2016 19:44
> To: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>; will.deacon-5wv7dgnIgG8@public.gmane.org; Stuart Yoder
> <stuart.yoder-3arQi8VN3Tc@public.gmane.org>; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linux-arm-
> kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> Cc: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus
> iommu group creation
> 
> On 30/06/16 12:43, Nipun Gupta wrote:
> >
> >
> >> -----Original Message-----
> >> From: Robin Murphy [mailto:robin.murphy-5wv7dgnIgG8@public.gmane.org]
> >> Sent: Thursday, June 30, 2016 16:26
> >> To: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>; will.deacon-5wv7dgnIgG8@public.gmane.org; Stuart
> >> Yoder <stuart.yoder-3arQi8VN3Tc@public.gmane.org>; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org;
> >> linux-arm- kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
> >> Cc: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> >> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide
> >> fsl-mc bus iommu group creation
> >>
> >> On 29/06/16 18:14, Nipun Gupta wrote:
> >>> Added a header file fsl_mc_smmu.h to provide basic support of
> >>> creating an IOMMU group for a fsl-mc type device and also provide
> >>> helper macro to get the stream ID of fsl-mc tyoe device.
> >>>
> >>> Signed-off-by: Nipun Gupta <nipun.gupta-3arQi8VN3Tc@public.gmane.org>
> >>> Signed-off-by: Bharat Bhushan <bharat.bhushan-3arQi8VN3Tc@public.gmane.org>
> >>> ---
> >>>  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45
> >>> ++++++++++++++++++++++++++++
> >>>  1 file changed, 45 insertions(+)
> >>>  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>>
> >>> diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>> b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>> new file mode 100644
> >>> index 0000000..9dff5ba
> >>> --- /dev/null
> >>> +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>> @@ -0,0 +1,45 @@
> >>> +/*
> >>> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> >>> + * Author: Nipun Gupta <nipun.gupta-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> >>> + *
> >>> + * This file is licensed under the terms of the GNU General Public
> >>> + * License version 2. This program is licensed "as is" without any
> >>> + * warranty of any kind, whether express or implied.
> >>> + */
> >>> +
> >>> +#ifndef _FSL_MC_SMMU_H_
> >>> +#define _FSL_MC_SMMU_H_
> >>> +
> >>> +#include <../drivers/staging/fsl-mc/include/mc.h>
> >>> +
> >>> +/* Macro to get the MC device ICID (Stream ID) */ #define
> >>> +fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
> >>
> >> Is the the full 15-bit ICID from the MC's point of view, just the 7
> >> bits that are actually routed to the SMMU, or the actual stream ID
> >> seen by the SMMU? None of those three are necessarily the same, and
> >> unless it's the third then I don't see the point of patches adding incomplete
> code which isn't going to work.
> >
> > Hi Robin,
> >
> > It's the second one where just 7 bits are maintained in the 'fsl_mc_device---
> >icid' which is programmed in SMMU. Right, once the SMR masking support is
> there then only these patches would make more sense.
> > We have sent these patches to get some early comments and to have you guys
> well informed beforehand about the changes which we require in the SMMU
> driver specific to fsl-mc bus :).
> 
> Indeed, it's just kinda hard to review incomplete code, especially when it's the
> parts which don't exist yet which are the most significant ;)
> 
> Either way, I'm deep in the middle of reworking SMMUv2 generic bindings[1]
> based on the latest iteration of the core code and iommu_fwspec[2], which
> removes the need for nearly all the bus-specific business within the driver (it's
> getting too big to be 4.8 material now, but I'll have something to post shortly).
> In that context, if the fsl-mc driver could process an "iommu-map" property on
> the MC node to plumb the ICID-to-stream-ID relationship into of_xlate, and
> inherit bus->iommu_ops from its parent bus, there shouldn't be any need to
> directly touch the SMMU driver at all.

Hi Robin,

One thing I would like to bring to your notice is that with our SoC the container devices gets dynamically created by MC (using linux command line). Once the container is created, the ICID is provided by MC to the devices.
Structure is somewhat the following:
							      		  ---- device 1 (ID 1)
				  ---- Container device 1 (ID 1)-----------	|---- device 2 (ID 1)
				|					  ---- device 3 (ID 1) ...
	MC bus/device------------	|---- Container device 2 (ID 2) ...
	(has a DT node)  	  ---- Container device 3 (ID 3) ...

Here the MC device node which is the SMMU master mode is present in the device tree, but the Container devices are created dynamically with ICID's provided to them by the MC (again at run-time).
A single iommu_group is required to be created per container, which will have the container device and all of its child devices added into that group.

On lines of your suggestion we can call the of_xlate callback of the MC device whenever the devices are created. This shall make API 'arm_smmu_init_fslmc_device' redundant from http://article.gmane.org/gmane.linux.kernel.iommu/14323 (patch 2/2).  Also looking at the your older patch-set for SMMU-v2 if we use of_xlate, I think for fsl-mc bus support there may be few changes required to facilitate addition of all the devices within the container into the single iommu_group & also setting up the 'dev->archdata.iommu' for the fsl-mc non-container devices.
I need to have a closer look at the iommu_fwspec[2] to see if these other changes required to support fsl-mc bus can also be minimized/removed.

We are eagerly waiting for your patches on SMMU-v2 for the new exciting stuff :).

Thanks,
Nipun
 
> 
> Robin.
> 
> [1]:http://thread.gmane.org/gmane.linux.kernel.iommu/12454
> [2]:http://thread.gmane.org/gmane.linux.kernel.iommu/14303
> 
> >
> > Thanks,
> > Nipun
> >
> >>
> >>> +/* Macro to get the container device of a MC device */ #define
> >>> +fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
> >>> +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
> >>> +
> >>> +/* Macro to check if a device is a container device */ #define
> >>> +is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
> >>> +
> >>> +static struct iommu_group *fslmc_device_group(struct device *dev) {
> >>> +	struct device *cont_dev = fslmc_cont_dev(dev);
> >>> +	struct iommu_group *group;
> >>> +
> >>> +	/* Container device is responsible for creating the iommu group */
> >>> +	if (is_cont_dev(dev)) {
> >>> +		group = iommu_group_alloc();
> >>> +
> >>> +		if (IS_ERR(group))
> >>> +			return NULL;
> >>> +	} else {
> >>> +		get_device(cont_dev);
> >>> +		group = iommu_group_get(cont_dev);
> >>> +		put_device(cont_dev);
> >>> +	}
> >>> +
> >>> +	return group;
> >>> +}
> >>
> >> In isolation, though, this part seems perfectly reasonable.
> >>
> >> Robin.
> >>
> >>> +
> >>> +#endif /* _FSL_MC_SMMU_H_ */
> >>>
> >

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation
@ 2016-07-01 15:11                 ` Nipun Gupta
  0 siblings, 0 replies; 16+ messages in thread
From: Nipun Gupta @ 2016-07-01 15:11 UTC (permalink / raw)
  To: linux-arm-kernel



> -----Original Message-----
> From: Robin Murphy [mailto:robin.murphy at arm.com]
> Sent: Thursday, June 30, 2016 19:44
> To: Nipun Gupta <nipun.gupta@nxp.com>; will.deacon at arm.com; Stuart Yoder
> <stuart.yoder@nxp.com>; iommu at lists.linux-foundation.org; linux-arm-
> kernel at lists.infradead.org
> Cc: Bharat Bhushan <bharat.bhushan@nxp.com>
> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus
> iommu group creation
> 
> On 30/06/16 12:43, Nipun Gupta wrote:
> >
> >
> >> -----Original Message-----
> >> From: Robin Murphy [mailto:robin.murphy at arm.com]
> >> Sent: Thursday, June 30, 2016 16:26
> >> To: Nipun Gupta <nipun.gupta@nxp.com>; will.deacon at arm.com; Stuart
> >> Yoder <stuart.yoder@nxp.com>; iommu at lists.linux-foundation.org;
> >> linux-arm- kernel at lists.infradead.org
> >> Cc: Bharat Bhushan <bharat.bhushan@nxp.com>
> >> Subject: Re: [RFC PATCH 1/2] fsl-mc: Added header file to provide
> >> fsl-mc bus iommu group creation
> >>
> >> On 29/06/16 18:14, Nipun Gupta wrote:
> >>> Added a header file fsl_mc_smmu.h to provide basic support of
> >>> creating an IOMMU group for a fsl-mc type device and also provide
> >>> helper macro to get the stream ID of fsl-mc tyoe device.
> >>>
> >>> Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com>
> >>> Signed-off-by: Bharat Bhushan <bharat.bhushan@nxp.com>
> >>> ---
> >>>  drivers/staging/fsl-mc/include/fsl_mc_smmu.h | 45
> >>> ++++++++++++++++++++++++++++
> >>>  1 file changed, 45 insertions(+)
> >>>  create mode 100644 drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>>
> >>> diff --git a/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>> b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>> new file mode 100644
> >>> index 0000000..9dff5ba
> >>> --- /dev/null
> >>> +++ b/drivers/staging/fsl-mc/include/fsl_mc_smmu.h
> >>> @@ -0,0 +1,45 @@
> >>> +/*
> >>> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> >>> + * Author: Nipun Gupta <nipun.gupta@freescale.com>
> >>> + *
> >>> + * This file is licensed under the terms of the GNU General Public
> >>> + * License version 2. This program is licensed "as is" without any
> >>> + * warranty of any kind, whether express or implied.
> >>> + */
> >>> +
> >>> +#ifndef _FSL_MC_SMMU_H_
> >>> +#define _FSL_MC_SMMU_H_
> >>> +
> >>> +#include <../drivers/staging/fsl-mc/include/mc.h>
> >>> +
> >>> +/* Macro to get the MC device ICID (Stream ID) */ #define
> >>> +fslmc_dev_streamid(_dev) (to_fsl_mc_device(_dev)->icid)
> >>
> >> Is the the full 15-bit ICID from the MC's point of view, just the 7
> >> bits that are actually routed to the SMMU, or the actual stream ID
> >> seen by the SMMU? None of those three are necessarily the same, and
> >> unless it's the third then I don't see the point of patches adding incomplete
> code which isn't going to work.
> >
> > Hi Robin,
> >
> > It's the second one where just 7 bits are maintained in the 'fsl_mc_device---
> >icid' which is programmed in SMMU. Right, once the SMR masking support is
> there then only these patches would make more sense.
> > We have sent these patches to get some early comments and to have you guys
> well informed beforehand about the changes which we require in the SMMU
> driver specific to fsl-mc bus :).
> 
> Indeed, it's just kinda hard to review incomplete code, especially when it's the
> parts which don't exist yet which are the most significant ;)
> 
> Either way, I'm deep in the middle of reworking SMMUv2 generic bindings[1]
> based on the latest iteration of the core code and iommu_fwspec[2], which
> removes the need for nearly all the bus-specific business within the driver (it's
> getting too big to be 4.8 material now, but I'll have something to post shortly).
> In that context, if the fsl-mc driver could process an "iommu-map" property on
> the MC node to plumb the ICID-to-stream-ID relationship into of_xlate, and
> inherit bus->iommu_ops from its parent bus, there shouldn't be any need to
> directly touch the SMMU driver at all.

Hi Robin,

One thing I would like to bring to your notice is that with our SoC the container devices gets dynamically created by MC (using linux command line). Once the container is created, the ICID is provided by MC to the devices.
Structure is somewhat the following:
							      		  ---- device 1 (ID 1)
				  ---- Container device 1 (ID 1)-----------	|---- device 2 (ID 1)
				|					  ---- device 3 (ID 1) ...
	MC bus/device------------	|---- Container device 2 (ID 2) ...
	(has a DT node)  	  ---- Container device 3 (ID 3) ...

Here the MC device node which is the SMMU master mode is present in the device tree, but the Container devices are created dynamically with ICID's provided to them by the MC (again at run-time).
A single iommu_group is required to be created per container, which will have the container device and all of its child devices added into that group.

On lines of your suggestion we can call the of_xlate callback of the MC device whenever the devices are created. This shall make API 'arm_smmu_init_fslmc_device' redundant from http://article.gmane.org/gmane.linux.kernel.iommu/14323 (patch 2/2).  Also looking at the your older patch-set for SMMU-v2 if we use of_xlate, I think for fsl-mc bus support there may be few changes required to facilitate addition of all the devices within the container into the single iommu_group & also setting up the 'dev->archdata.iommu' for the fsl-mc non-container devices.
I need to have a closer look at the iommu_fwspec[2] to see if these other changes required to support fsl-mc bus can also be minimized/removed.

We are eagerly waiting for your patches on SMMU-v2 for the new exciting stuff :).

Thanks,
Nipun
 
> 
> Robin.
> 
> [1]:http://thread.gmane.org/gmane.linux.kernel.iommu/12454
> [2]:http://thread.gmane.org/gmane.linux.kernel.iommu/14303
> 
> >
> > Thanks,
> > Nipun
> >
> >>
> >>> +/* Macro to get the container device of a MC device */ #define
> >>> +fslmc_cont_dev(_dev) ((to_fsl_mc_device(dev)->flags & \
> >>> +	FSL_MC_IS_DPRC) ? (_dev) : (_dev->parent))
> >>> +
> >>> +/* Macro to check if a device is a container device */ #define
> >>> +is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
> >>> +
> >>> +static struct iommu_group *fslmc_device_group(struct device *dev) {
> >>> +	struct device *cont_dev = fslmc_cont_dev(dev);
> >>> +	struct iommu_group *group;
> >>> +
> >>> +	/* Container device is responsible for creating the iommu group */
> >>> +	if (is_cont_dev(dev)) {
> >>> +		group = iommu_group_alloc();
> >>> +
> >>> +		if (IS_ERR(group))
> >>> +			return NULL;
> >>> +	} else {
> >>> +		get_device(cont_dev);
> >>> +		group = iommu_group_get(cont_dev);
> >>> +		put_device(cont_dev);
> >>> +	}
> >>> +
> >>> +	return group;
> >>> +}
> >>
> >> In isolation, though, this part seems perfectly reasonable.
> >>
> >> Robin.
> >>
> >>> +
> >>> +#endif /* _FSL_MC_SMMU_H_ */
> >>>
> >

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-07-01 15:11 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-29 17:14 [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation Nipun Gupta
2016-06-29 17:14 ` Nipun Gupta
     [not found] ` <1467220448-16764-1-git-send-email-nipun.gupta-3arQi8VN3Tc@public.gmane.org>
2016-06-29 17:14   ` [RFC PATCH 2/2] iommu/arm-smmu: Add support for the fsl-mc bus Nipun Gupta
2016-06-29 17:14     ` Nipun Gupta
     [not found]     ` <1467220448-16764-2-git-send-email-nipun.gupta-3arQi8VN3Tc@public.gmane.org>
2016-06-30 11:23       ` Robin Murphy
2016-06-30 11:23         ` Robin Murphy
     [not found]         ` <5775011C.60402-5wv7dgnIgG8@public.gmane.org>
2016-06-30 12:11           ` Nipun Gupta
2016-06-30 12:11             ` Nipun Gupta
2016-06-30 10:55   ` [RFC PATCH 1/2] fsl-mc: Added header file to provide fsl-mc bus iommu group creation Robin Murphy
2016-06-30 10:55     ` Robin Murphy
     [not found]     ` <5774FABE.5070707-5wv7dgnIgG8@public.gmane.org>
2016-06-30 11:43       ` Nipun Gupta
2016-06-30 11:43         ` Nipun Gupta
     [not found]         ` <HE1PR0401MB1866C1468D3B4733B437C79BE6240-B0v07Ae2tarOWAm+xAH2pY3W/0Ik+aLCnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2016-06-30 14:14           ` Robin Murphy
2016-06-30 14:14             ` Robin Murphy
     [not found]             ` <57752939.9010504-5wv7dgnIgG8@public.gmane.org>
2016-07-01 15:11               ` Nipun Gupta
2016-07-01 15:11                 ` Nipun Gupta

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.