All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Tango PCIe host bridge MSI support + required API
@ 2017-08-29 14:19 ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:19 UTC (permalink / raw)
  To: Bjorn Helgaas, Marc Zyngier
  Cc: Mason, linux-pci, Thibaud Cornic, Liviu Dudau, Robin Murphy, Linux ARM

Bjorn, Marc,

This patch-set includes
	[PATCH v11] PCI: tango: Add MSI controller support
with the doorbell address parsed from DT instead of hard-coded
in the driver.

A wrapper to parse dma-ranges was added to drivers/of/address.c

A few drivers were converted to use the new wrapper.

Marc Gonzalez (3):
  of/pci: Add dma-ranges parsing support
  PCI: Use of_pci_dma_range_parser_init API
  PCI: tango: Add MSI controller support

 drivers/of/address.c             |  19 +++-
 drivers/pci/host/pci-ftpci100.c  |  20 +---
 drivers/pci/host/pci-rcar-gen2.c |  20 +---
 drivers/pci/host/pci-xgene.c     |  20 +---
 drivers/pci/host/pcie-iproc.c    |  20 +---
 drivers/pci/host/pcie-rcar.c     |  20 +---
 drivers/pci/host/pcie-tango.c    | 205 ++++++++++++++++++++++++++++++++++++++-
 include/linux/of_address.h       |  10 +-
 8 files changed, 232 insertions(+), 102 deletions(-)

-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 0/3] Tango PCIe host bridge MSI support + required API
@ 2017-08-29 14:19 ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:19 UTC (permalink / raw)
  To: linux-arm-kernel

Bjorn, Marc,

This patch-set includes
	[PATCH v11] PCI: tango: Add MSI controller support
with the doorbell address parsed from DT instead of hard-coded
in the driver.

A wrapper to parse dma-ranges was added to drivers/of/address.c

A few drivers were converted to use the new wrapper.

Marc Gonzalez (3):
  of/pci: Add dma-ranges parsing support
  PCI: Use of_pci_dma_range_parser_init API
  PCI: tango: Add MSI controller support

 drivers/of/address.c             |  19 +++-
 drivers/pci/host/pci-ftpci100.c  |  20 +---
 drivers/pci/host/pci-rcar-gen2.c |  20 +---
 drivers/pci/host/pci-xgene.c     |  20 +---
 drivers/pci/host/pcie-iproc.c    |  20 +---
 drivers/pci/host/pcie-rcar.c     |  20 +---
 drivers/pci/host/pcie-tango.c    | 205 ++++++++++++++++++++++++++++++++++++++-
 include/linux/of_address.h       |  10 +-
 8 files changed, 232 insertions(+), 102 deletions(-)

-- 
2.11.0

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

* [PATCH 1/3] of/pci: Add dma-ranges parsing support
  2017-08-29 14:19 ` Marc Gonzalez
  (?)
@ 2017-08-29 14:25   ` Marc Gonzalez
  -1 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:25 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand, Mark Rutland
  Cc: Bjorn Helgaas, Marc Zyngier, linux-pci, Linux ARM, Robin Murphy,
	Liviu Dudau, Thibaud Cornic, Mason, Andrew Murray,
	Thomas Petazzoni, Linus Walleij, Jason Cooper, DT

Several host bridge drivers duplicate of_pci_range_parser_init()
in order to parse their dma-ranges property.

Provide of_pci_dma_range_parser_init() for that use-case.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
 drivers/of/address.c       | 19 ++++++++++++++++---
 include/linux/of_address.h | 10 +++++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 580bbf6ca2b1..4cfd29e4ee1b 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -232,8 +232,8 @@ int of_pci_address_to_resource(struct device_node *dev, int bar,
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
 
-int of_pci_range_parser_init(struct of_pci_range_parser *parser,
-				struct device_node *node)
+static int parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node, const char *name)
 {
 	const int na = 3, ns = 2;
 	int rlen;
@@ -242,7 +242,7 @@ int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 	parser->pna = of_n_addr_cells(node);
 	parser->np = parser->pna + na + ns;
 
-	parser->range = of_get_property(node, "ranges", &rlen);
+	parser->range = of_get_property(node, name, &rlen);
 	if (parser->range == NULL)
 		return -ENOENT;
 
@@ -250,8 +250,21 @@ int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 
 	return 0;
 }
+
+int of_pci_range_parser_init(struct of_pci_range_parser *parser,
+				struct device_node *node)
+{
+	return parser_init(parser, node, "ranges");
+}
 EXPORT_SYMBOL_GPL(of_pci_range_parser_init);
 
+int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+				struct device_node *node)
+{
+	return parser_init(parser, node, "dma-ranges");
+}
+EXPORT_SYMBOL_GPL(of_pci_dma_range_parser_init);
+
 struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 						struct of_pci_range *range)
 {
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 37864734ca50..8beed2de98e9 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -49,6 +49,8 @@ extern const __be32 *of_get_address(struct device_node *dev, int index,
 
 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 			struct device_node *node);
+extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node);
 extern struct of_pci_range *of_pci_range_parser_one(
 					struct of_pci_range_parser *parser,
 					struct of_pci_range *range);
@@ -85,7 +87,13 @@ static inline const __be32 *of_get_address(struct device_node *dev, int index,
 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 			struct device_node *node)
 {
-	return -1;
+	return -ENOSYS;
+}
+
+static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node)
+{
+	return -ENOSYS;
 }
 
 static inline struct of_pci_range *of_pci_range_parser_one(
-- 
2.11.0

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

* [PATCH 1/3] of/pci: Add dma-ranges parsing support
@ 2017-08-29 14:25   ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:25 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand, Mark Rutland
  Cc: Thomas Petazzoni, DT, Jason Cooper, Mason, Marc Zyngier,
	linux-pci, Thibaud Cornic, Andrew Murray, Liviu Dudau,
	Bjorn Helgaas, Robin Murphy, Linus Walleij, Linux ARM

Several host bridge drivers duplicate of_pci_range_parser_init()
in order to parse their dma-ranges property.

Provide of_pci_dma_range_parser_init() for that use-case.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
 drivers/of/address.c       | 19 ++++++++++++++++---
 include/linux/of_address.h | 10 +++++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 580bbf6ca2b1..4cfd29e4ee1b 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -232,8 +232,8 @@ int of_pci_address_to_resource(struct device_node *dev, int bar,
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
 
-int of_pci_range_parser_init(struct of_pci_range_parser *parser,
-				struct device_node *node)
+static int parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node, const char *name)
 {
 	const int na = 3, ns = 2;
 	int rlen;
@@ -242,7 +242,7 @@ int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 	parser->pna = of_n_addr_cells(node);
 	parser->np = parser->pna + na + ns;
 
-	parser->range = of_get_property(node, "ranges", &rlen);
+	parser->range = of_get_property(node, name, &rlen);
 	if (parser->range == NULL)
 		return -ENOENT;
 
@@ -250,8 +250,21 @@ int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 
 	return 0;
 }
+
+int of_pci_range_parser_init(struct of_pci_range_parser *parser,
+				struct device_node *node)
+{
+	return parser_init(parser, node, "ranges");
+}
 EXPORT_SYMBOL_GPL(of_pci_range_parser_init);
 
+int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+				struct device_node *node)
+{
+	return parser_init(parser, node, "dma-ranges");
+}
+EXPORT_SYMBOL_GPL(of_pci_dma_range_parser_init);
+
 struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 						struct of_pci_range *range)
 {
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 37864734ca50..8beed2de98e9 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -49,6 +49,8 @@ extern const __be32 *of_get_address(struct device_node *dev, int index,
 
 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 			struct device_node *node);
+extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node);
 extern struct of_pci_range *of_pci_range_parser_one(
 					struct of_pci_range_parser *parser,
 					struct of_pci_range *range);
@@ -85,7 +87,13 @@ static inline const __be32 *of_get_address(struct device_node *dev, int index,
 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 			struct device_node *node)
 {
-	return -1;
+	return -ENOSYS;
+}
+
+static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node)
+{
+	return -ENOSYS;
 }
 
 static inline struct of_pci_range *of_pci_range_parser_one(
-- 
2.11.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 1/3] of/pci: Add dma-ranges parsing support
@ 2017-08-29 14:25   ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:25 UTC (permalink / raw)
  To: linux-arm-kernel

Several host bridge drivers duplicate of_pci_range_parser_init()
in order to parse their dma-ranges property.

Provide of_pci_dma_range_parser_init() for that use-case.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
 drivers/of/address.c       | 19 ++++++++++++++++---
 include/linux/of_address.h | 10 +++++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 580bbf6ca2b1..4cfd29e4ee1b 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -232,8 +232,8 @@ int of_pci_address_to_resource(struct device_node *dev, int bar,
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
 
-int of_pci_range_parser_init(struct of_pci_range_parser *parser,
-				struct device_node *node)
+static int parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node, const char *name)
 {
 	const int na = 3, ns = 2;
 	int rlen;
@@ -242,7 +242,7 @@ int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 	parser->pna = of_n_addr_cells(node);
 	parser->np = parser->pna + na + ns;
 
-	parser->range = of_get_property(node, "ranges", &rlen);
+	parser->range = of_get_property(node, name, &rlen);
 	if (parser->range == NULL)
 		return -ENOENT;
 
@@ -250,8 +250,21 @@ int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 
 	return 0;
 }
+
+int of_pci_range_parser_init(struct of_pci_range_parser *parser,
+				struct device_node *node)
+{
+	return parser_init(parser, node, "ranges");
+}
 EXPORT_SYMBOL_GPL(of_pci_range_parser_init);
 
+int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+				struct device_node *node)
+{
+	return parser_init(parser, node, "dma-ranges");
+}
+EXPORT_SYMBOL_GPL(of_pci_dma_range_parser_init);
+
 struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 						struct of_pci_range *range)
 {
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 37864734ca50..8beed2de98e9 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -49,6 +49,8 @@ extern const __be32 *of_get_address(struct device_node *dev, int index,
 
 extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 			struct device_node *node);
+extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node);
 extern struct of_pci_range *of_pci_range_parser_one(
 					struct of_pci_range_parser *parser,
 					struct of_pci_range *range);
@@ -85,7 +87,13 @@ static inline const __be32 *of_get_address(struct device_node *dev, int index,
 static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
 			struct device_node *node)
 {
-	return -1;
+	return -ENOSYS;
+}
+
+static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
+			struct device_node *node)
+{
+	return -ENOSYS;
 }
 
 static inline struct of_pci_range *of_pci_range_parser_one(
-- 
2.11.0

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

* [PATCH 2/3] PCI: Use of_pci_dma_range_parser_init API
  2017-08-29 14:19 ` Marc Gonzalez
@ 2017-08-29 14:27   ` Marc Gonzalez
  -1 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:27 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: linux-pci, Linux ARM, Robin Murphy, Liviu Dudau, Thibaud Cornic,
	Mason, Linus Walleij, Ray Jui, Simon Horman

Use the factorized implementation.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
 drivers/pci/host/pci-ftpci100.c  | 20 +-------------------
 drivers/pci/host/pci-rcar-gen2.c | 20 +-------------------
 drivers/pci/host/pci-xgene.c     | 20 +-------------------
 drivers/pci/host/pcie-iproc.c    | 20 +-------------------
 drivers/pci/host/pcie-rcar.c     | 20 +-------------------
 5 files changed, 5 insertions(+), 95 deletions(-)

diff --git a/drivers/pci/host/pci-ftpci100.c b/drivers/pci/host/pci-ftpci10=
0.c
index 5162dffc102b..12d78bba1bd3 100644
--- a/drivers/pci/host/pci-ftpci100.c
+++ b/drivers/pci/host/pci-ftpci100.c
@@ -370,24 +370,6 @@ static int faraday_pci_setup_cascaded_irq(struct farad=
ay_pci *p)
 =09return 0;
 }
=20
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-=09=09=09=09     struct device_node *node)
-{
-=09const int na =3D 3, ns =3D 2;
-=09int rlen;
-
-=09parser->node =3D node;
-=09parser->pna =3D of_n_addr_cells(node);
-=09parser->np =3D parser->pna + na + ns;
-
-=09parser->range =3D of_get_property(node, "dma-ranges", &rlen);
-=09if (!parser->range)
-=09=09return -ENOENT;
-=09parser->end =3D parser->range + rlen / sizeof(__be32);
-
-=09return 0;
-}
-
 static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 =09=09=09=09=09    struct device_node *np)
 {
@@ -402,7 +384,7 @@ static int faraday_pci_parse_map_dma_ranges(struct fara=
day_pci *p,
 =09int i =3D 0;
 =09u32 val;
=20
-=09if (pci_dma_range_parser_init(&parser, np)) {
+=09if (of_pci_dma_range_parser_init(&parser, np)) {
 =09=09dev_err(dev, "missing dma-ranges property\n");
 =09=09return -EINVAL;
 =09}
diff --git a/drivers/pci/host/pci-rcar-gen2.c b/drivers/pci/host/pci-rcar-g=
en2.c
index 6f879685fedd..e46de69f0380 100644
--- a/drivers/pci/host/pci-rcar-gen2.c
+++ b/drivers/pci/host/pci-rcar-gen2.c
@@ -293,24 +293,6 @@ static struct pci_ops rcar_pci_ops =3D {
 =09.write=09=3D pci_generic_config_write,
 };
=20
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-=09=09=09=09     struct device_node *node)
-{
-=09const int na =3D 3, ns =3D 2;
-=09int rlen;
-
-=09parser->node =3D node;
-=09parser->pna =3D of_n_addr_cells(node);
-=09parser->np =3D parser->pna + na + ns;
-
-=09parser->range =3D of_get_property(node, "dma-ranges", &rlen);
-=09if (!parser->range)
-=09=09return -ENOENT;
-
-=09parser->end =3D parser->range + rlen / sizeof(__be32);
-=09return 0;
-}
-
 static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
 =09=09=09=09=09 struct device_node *np)
 {
@@ -320,7 +302,7 @@ static int rcar_pci_parse_map_dma_ranges(struct rcar_pc=
i_priv *pci,
 =09int index =3D 0;
=20
 =09/* Failure to parse is ok as we fall back to defaults */
-=09if (pci_dma_range_parser_init(&parser, np))
+=09if (of_pci_dma_range_parser_init(&parser, np))
 =09=09return 0;
=20
 =09/* Get the dma-ranges from DT */
diff --git a/drivers/pci/host/pci-xgene.c b/drivers/pci/host/pci-xgene.c
index bd897479a215..f660513946d3 100644
--- a/drivers/pci/host/pci-xgene.c
+++ b/drivers/pci/host/pci-xgene.c
@@ -542,24 +542,6 @@ static void xgene_pcie_setup_ib_reg(struct xgene_pcie_=
port *port,
 =09xgene_pcie_setup_pims(port, pim_reg, pci_addr, ~(size - 1));
 }
=20
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-=09=09=09=09     struct device_node *node)
-{
-=09const int na =3D 3, ns =3D 2;
-=09int rlen;
-
-=09parser->node =3D node;
-=09parser->pna =3D of_n_addr_cells(node);
-=09parser->np =3D parser->pna + na + ns;
-
-=09parser->range =3D of_get_property(node, "dma-ranges", &rlen);
-=09if (!parser->range)
-=09=09return -ENOENT;
-=09parser->end =3D parser->range + rlen / sizeof(__be32);
-
-=09return 0;
-}
-
 static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
 {
 =09struct device_node *np =3D port->node;
@@ -568,7 +550,7 @@ static int xgene_pcie_parse_map_dma_ranges(struct xgene=
_pcie_port *port)
 =09struct device *dev =3D port->dev;
 =09u8 ib_reg_mask =3D 0;
=20
-=09if (pci_dma_range_parser_init(&parser, np)) {
+=09if (of_pci_dma_range_parser_init(&parser, np)) {
 =09=09dev_err(dev, "missing dma-ranges property\n");
 =09=09return -EINVAL;
 =09}
diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index c57486348856..aa4f6d519053 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -1000,24 +1000,6 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pc=
ie,
 =09return ret;
 }
=20
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-=09=09=09=09     struct device_node *node)
-{
-=09const int na =3D 3, ns =3D 2;
-=09int rlen;
-
-=09parser->node =3D node;
-=09parser->pna =3D of_n_addr_cells(node);
-=09parser->np =3D parser->pna + na + ns;
-
-=09parser->range =3D of_get_property(node, "dma-ranges", &rlen);
-=09if (!parser->range)
-=09=09return -ENOENT;
-
-=09parser->end =3D parser->range + rlen / sizeof(__be32);
-=09return 0;
-}
-
 static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie)
 {
 =09struct of_pci_range range;
@@ -1025,7 +1007,7 @@ static int iproc_pcie_map_dma_ranges(struct iproc_pci=
e *pcie)
 =09int ret;
=20
 =09/* Get the dma-ranges from DT */
-=09ret =3D pci_dma_range_parser_init(&parser, pcie->dev->of_node);
+=09ret =3D of_pci_dma_range_parser_init(&parser, pcie->dev->of_node);
 =09if (ret)
 =09=09return ret;
=20
diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 246d485b24c6..7975b10e21e8 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -1029,24 +1029,6 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie=
 *pcie,
 =09return 0;
 }
=20
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-=09=09=09=09     struct device_node *node)
-{
-=09const int na =3D 3, ns =3D 2;
-=09int rlen;
-
-=09parser->node =3D node;
-=09parser->pna =3D of_n_addr_cells(node);
-=09parser->np =3D parser->pna + na + ns;
-
-=09parser->range =3D of_get_property(node, "dma-ranges", &rlen);
-=09if (!parser->range)
-=09=09return -ENOENT;
-
-=09parser->end =3D parser->range + rlen / sizeof(__be32);
-=09return 0;
-}
-
 static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
 =09=09=09=09=09  struct device_node *np)
 {
@@ -1055,7 +1037,7 @@ static int rcar_pcie_parse_map_dma_ranges(struct rcar=
_pcie *pcie,
 =09int index =3D 0;
 =09int err;
=20
-=09if (pci_dma_range_parser_init(&parser, np))
+=09if (of_pci_dma_range_parser_init(&parser, np))
 =09=09return -EINVAL;
=20
 =09/* Get the dma-ranges from DT */
--=20
2.11.0

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

* [PATCH 2/3] PCI: Use of_pci_dma_range_parser_init API
@ 2017-08-29 14:27   ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:27 UTC (permalink / raw)
  To: linux-arm-kernel

Use the factorized implementation.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
 drivers/pci/host/pci-ftpci100.c  | 20 +-------------------
 drivers/pci/host/pci-rcar-gen2.c | 20 +-------------------
 drivers/pci/host/pci-xgene.c     | 20 +-------------------
 drivers/pci/host/pcie-iproc.c    | 20 +-------------------
 drivers/pci/host/pcie-rcar.c     | 20 +-------------------
 5 files changed, 5 insertions(+), 95 deletions(-)

diff --git a/drivers/pci/host/pci-ftpci100.c b/drivers/pci/host/pci-ftpci100.c
index 5162dffc102b..12d78bba1bd3 100644
--- a/drivers/pci/host/pci-ftpci100.c
+++ b/drivers/pci/host/pci-ftpci100.c
@@ -370,24 +370,6 @@ static int faraday_pci_setup_cascaded_irq(struct faraday_pci *p)
 	return 0;
 }
 
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-				     struct device_node *node)
-{
-	const int na = 3, ns = 2;
-	int rlen;
-
-	parser->node = node;
-	parser->pna = of_n_addr_cells(node);
-	parser->np = parser->pna + na + ns;
-
-	parser->range = of_get_property(node, "dma-ranges", &rlen);
-	if (!parser->range)
-		return -ENOENT;
-	parser->end = parser->range + rlen / sizeof(__be32);
-
-	return 0;
-}
-
 static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 					    struct device_node *np)
 {
@@ -402,7 +384,7 @@ static int faraday_pci_parse_map_dma_ranges(struct faraday_pci *p,
 	int i = 0;
 	u32 val;
 
-	if (pci_dma_range_parser_init(&parser, np)) {
+	if (of_pci_dma_range_parser_init(&parser, np)) {
 		dev_err(dev, "missing dma-ranges property\n");
 		return -EINVAL;
 	}
diff --git a/drivers/pci/host/pci-rcar-gen2.c b/drivers/pci/host/pci-rcar-gen2.c
index 6f879685fedd..e46de69f0380 100644
--- a/drivers/pci/host/pci-rcar-gen2.c
+++ b/drivers/pci/host/pci-rcar-gen2.c
@@ -293,24 +293,6 @@ static struct pci_ops rcar_pci_ops = {
 	.write	= pci_generic_config_write,
 };
 
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-				     struct device_node *node)
-{
-	const int na = 3, ns = 2;
-	int rlen;
-
-	parser->node = node;
-	parser->pna = of_n_addr_cells(node);
-	parser->np = parser->pna + na + ns;
-
-	parser->range = of_get_property(node, "dma-ranges", &rlen);
-	if (!parser->range)
-		return -ENOENT;
-
-	parser->end = parser->range + rlen / sizeof(__be32);
-	return 0;
-}
-
 static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
 					 struct device_node *np)
 {
@@ -320,7 +302,7 @@ static int rcar_pci_parse_map_dma_ranges(struct rcar_pci_priv *pci,
 	int index = 0;
 
 	/* Failure to parse is ok as we fall back to defaults */
-	if (pci_dma_range_parser_init(&parser, np))
+	if (of_pci_dma_range_parser_init(&parser, np))
 		return 0;
 
 	/* Get the dma-ranges from DT */
diff --git a/drivers/pci/host/pci-xgene.c b/drivers/pci/host/pci-xgene.c
index bd897479a215..f660513946d3 100644
--- a/drivers/pci/host/pci-xgene.c
+++ b/drivers/pci/host/pci-xgene.c
@@ -542,24 +542,6 @@ static void xgene_pcie_setup_ib_reg(struct xgene_pcie_port *port,
 	xgene_pcie_setup_pims(port, pim_reg, pci_addr, ~(size - 1));
 }
 
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-				     struct device_node *node)
-{
-	const int na = 3, ns = 2;
-	int rlen;
-
-	parser->node = node;
-	parser->pna = of_n_addr_cells(node);
-	parser->np = parser->pna + na + ns;
-
-	parser->range = of_get_property(node, "dma-ranges", &rlen);
-	if (!parser->range)
-		return -ENOENT;
-	parser->end = parser->range + rlen / sizeof(__be32);
-
-	return 0;
-}
-
 static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
 {
 	struct device_node *np = port->node;
@@ -568,7 +550,7 @@ static int xgene_pcie_parse_map_dma_ranges(struct xgene_pcie_port *port)
 	struct device *dev = port->dev;
 	u8 ib_reg_mask = 0;
 
-	if (pci_dma_range_parser_init(&parser, np)) {
+	if (of_pci_dma_range_parser_init(&parser, np)) {
 		dev_err(dev, "missing dma-ranges property\n");
 		return -EINVAL;
 	}
diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index c57486348856..aa4f6d519053 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -1000,24 +1000,6 @@ static int iproc_pcie_setup_ib(struct iproc_pcie *pcie,
 	return ret;
 }
 
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-				     struct device_node *node)
-{
-	const int na = 3, ns = 2;
-	int rlen;
-
-	parser->node = node;
-	parser->pna = of_n_addr_cells(node);
-	parser->np = parser->pna + na + ns;
-
-	parser->range = of_get_property(node, "dma-ranges", &rlen);
-	if (!parser->range)
-		return -ENOENT;
-
-	parser->end = parser->range + rlen / sizeof(__be32);
-	return 0;
-}
-
 static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie)
 {
 	struct of_pci_range range;
@@ -1025,7 +1007,7 @@ static int iproc_pcie_map_dma_ranges(struct iproc_pcie *pcie)
 	int ret;
 
 	/* Get the dma-ranges from DT */
-	ret = pci_dma_range_parser_init(&parser, pcie->dev->of_node);
+	ret = of_pci_dma_range_parser_init(&parser, pcie->dev->of_node);
 	if (ret)
 		return ret;
 
diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c
index 246d485b24c6..7975b10e21e8 100644
--- a/drivers/pci/host/pcie-rcar.c
+++ b/drivers/pci/host/pcie-rcar.c
@@ -1029,24 +1029,6 @@ static int rcar_pcie_inbound_ranges(struct rcar_pcie *pcie,
 	return 0;
 }
 
-static int pci_dma_range_parser_init(struct of_pci_range_parser *parser,
-				     struct device_node *node)
-{
-	const int na = 3, ns = 2;
-	int rlen;
-
-	parser->node = node;
-	parser->pna = of_n_addr_cells(node);
-	parser->np = parser->pna + na + ns;
-
-	parser->range = of_get_property(node, "dma-ranges", &rlen);
-	if (!parser->range)
-		return -ENOENT;
-
-	parser->end = parser->range + rlen / sizeof(__be32);
-	return 0;
-}
-
 static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
 					  struct device_node *np)
 {
@@ -1055,7 +1037,7 @@ static int rcar_pcie_parse_map_dma_ranges(struct rcar_pcie *pcie,
 	int index = 0;
 	int err;
 
-	if (pci_dma_range_parser_init(&parser, np))
+	if (of_pci_dma_range_parser_init(&parser, np))
 		return -EINVAL;
 
 	/* Get the dma-ranges from DT */
-- 
2.11.0

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

* [PATCH v11 3/3] PCI: tango: Add MSI controller support
  2017-08-29 14:19 ` Marc Gonzalez
@ 2017-08-29 14:32   ` Marc Gonzalez
  -1 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:32 UTC (permalink / raw)
  To: Bjorn Helgaas, Marc Zyngier
  Cc: linux-pci, Linux ARM, Robin Murphy, Liviu Dudau, Thibaud Cornic, Mason

The MSI controller in Tango supports 256 message-signaled interrupts
and a single doorbell address.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
Changes from v10 to v11
* Discover msi_doorbell in probe by parsing dma-ranges
---
 drivers/pci/host/pcie-tango.c | 205 ++++++++++++++++++++++++++++++++++++++=
+++-
 1 file changed, 202 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/host/pcie-tango.c b/drivers/pci/host/pcie-tango.c
index 6bbb81f06a53..e23f7383ac33 100644
--- a/drivers/pci/host/pcie-tango.c
+++ b/drivers/pci/host/pcie-tango.c
@@ -1,12 +1,172 @@
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
 #include <linux/pci-ecam.h>
 #include <linux/delay.h>
-#include <linux/of.h>
+#include <linux/msi.h>
+#include <linux/of_address.h>
+
+#define MSI_MAX=09=09=09256
=20
 #define SMP8759_MUX=09=090x48
 #define SMP8759_TEST_OUT=090x74
+#define SMP8759_DOORBELL=090x7c
+#define SMP8759_STATUS=09=090x80
+#define SMP8759_ENABLE=09=090xa0
=20
 struct tango_pcie {
-=09void __iomem *base;
+=09DECLARE_BITMAP(used_msi, MSI_MAX);
+=09u64=09=09=09msi_doorbell;
+=09spinlock_t=09=09used_msi_lock;
+=09void __iomem=09=09*base;
+=09struct irq_domain=09*dom;
+};
+
+static void tango_msi_isr(struct irq_desc *desc)
+{
+=09struct irq_chip *chip =3D irq_desc_get_chip(desc);
+=09struct tango_pcie *pcie =3D irq_desc_get_handler_data(desc);
+=09unsigned long status, base, virq, idx, pos =3D 0;
+
+=09chained_irq_enter(chip, desc);
+=09spin_lock(&pcie->used_msi_lock);
+
+=09while ((pos =3D find_next_bit(pcie->used_msi, MSI_MAX, pos)) < MSI_MAX)=
 {
+=09=09base =3D round_down(pos, 32);
+=09=09status =3D readl_relaxed(pcie->base + SMP8759_STATUS + base / 8);
+=09=09for_each_set_bit(idx, &status, 32) {
+=09=09=09virq =3D irq_find_mapping(pcie->dom, base + idx);
+=09=09=09generic_handle_irq(virq);
+=09=09}
+=09=09pos =3D base + 32;
+=09}
+
+=09spin_unlock(&pcie->used_msi_lock);
+=09chained_irq_exit(chip, desc);
+}
+
+static void tango_ack(struct irq_data *d)
+{
+=09struct tango_pcie *pcie =3D d->chip_data;
+=09u32 offset =3D (d->hwirq / 32) * 4;
+=09u32 bit =3D BIT(d->hwirq % 32);
+
+=09writel_relaxed(bit, pcie->base + SMP8759_STATUS + offset);
+}
+
+static void update_msi_enable(struct irq_data *d, bool unmask)
+{
+=09unsigned long flags;
+=09struct tango_pcie *pcie =3D d->chip_data;
+=09u32 offset =3D (d->hwirq / 32) * 4;
+=09u32 bit =3D BIT(d->hwirq % 32);
+=09u32 val;
+
+=09spin_lock_irqsave(&pcie->used_msi_lock, flags);
+=09val =3D readl_relaxed(pcie->base + SMP8759_ENABLE + offset);
+=09val =3D unmask ? val | bit : val & ~bit;
+=09writel_relaxed(val, pcie->base + SMP8759_ENABLE + offset);
+=09spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+}
+
+static void tango_mask(struct irq_data *d)
+{
+=09update_msi_enable(d, false);
+}
+
+static void tango_unmask(struct irq_data *d)
+{
+=09update_msi_enable(d, true);
+}
+
+static int tango_set_affinity(struct irq_data *d, const struct cpumask *ma=
sk,
+=09=09=09      bool force)
+{
+=09return -EINVAL;
+}
+
+static void tango_compose_msi_msg(struct irq_data *d, struct msi_msg *msg)
+{
+=09struct tango_pcie *pcie =3D d->chip_data;
+=09msg->address_lo =3D lower_32_bits(pcie->msi_doorbell);
+=09msg->address_hi =3D upper_32_bits(pcie->msi_doorbell);
+=09msg->data =3D d->hwirq;
+}
+
+static struct irq_chip tango_chip =3D {
+=09.irq_ack=09=09=3D tango_ack,
+=09.irq_mask=09=09=3D tango_mask,
+=09.irq_unmask=09=09=3D tango_unmask,
+=09.irq_set_affinity=09=3D tango_set_affinity,
+=09.irq_compose_msi_msg=09=3D tango_compose_msi_msg,
+};
+
+static void msi_ack(struct irq_data *d)
+{
+=09irq_chip_ack_parent(d);
+}
+
+static void msi_mask(struct irq_data *d)
+{
+=09pci_msi_mask_irq(d);
+=09irq_chip_mask_parent(d);
+}
+
+static void msi_unmask(struct irq_data *d)
+{
+=09pci_msi_unmask_irq(d);
+=09irq_chip_unmask_parent(d);
+}
+
+static struct irq_chip msi_chip =3D {
+=09.name =3D "MSI",
+=09.irq_ack =3D msi_ack,
+=09.irq_mask =3D msi_mask,
+=09.irq_unmask =3D msi_unmask,
+};
+
+static struct msi_domain_info msi_dom_info =3D {
+=09.flags=09=3D MSI_FLAG_PCI_MSIX
+=09=09| MSI_FLAG_USE_DEF_DOM_OPS
+=09=09| MSI_FLAG_USE_DEF_CHIP_OPS,
+=09.chip=09=3D &msi_chip,
+};
+
+static int tango_irq_domain_alloc(struct irq_domain *dom, unsigned int vir=
q,
+=09=09=09=09  unsigned int nr_irqs, void *args)
+{
+=09struct tango_pcie *pcie =3D dom->host_data;
+=09unsigned long flags;
+=09int pos;
+
+=09spin_lock_irqsave(&pcie->used_msi_lock, flags);
+=09pos =3D find_first_zero_bit(pcie->used_msi, MSI_MAX);
+=09if (pos >=3D MSI_MAX) {
+=09=09spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+=09=09return -ENOSPC;
+=09}
+=09__set_bit(pos, pcie->used_msi);
+=09spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+=09irq_domain_set_info(dom, virq, pos, &tango_chip,
+=09=09=09pcie, handle_edge_irq, NULL, NULL);
+
+=09return 0;
+}
+
+static void tango_irq_domain_free(struct irq_domain *dom, unsigned int vir=
q,
+=09=09=09=09  unsigned int nr_irqs)
+{
+=09unsigned long flags;
+=09struct irq_data *d =3D irq_domain_get_irq_data(dom, virq);
+=09struct tango_pcie *pcie =3D d->chip_data;
+
+=09spin_lock_irqsave(&pcie->used_msi_lock, flags);
+=09__clear_bit(d->hwirq, pcie->used_msi);
+=09spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+}
+
+static const struct irq_domain_ops dom_ops =3D {
+=09.alloc=09=3D tango_irq_domain_alloc,
+=09.free=09=3D tango_irq_domain_free,
 };
=20
 static int smp8759_config_read(struct pci_bus *bus, unsigned int devfn,
@@ -76,7 +236,11 @@ static int tango_pcie_probe(struct platform_device *pde=
v)
 =09struct device *dev =3D &pdev->dev;
 =09struct tango_pcie *pcie;
 =09struct resource *res;
-=09int ret;
+=09struct fwnode_handle *fwnode =3D of_node_to_fwnode(dev->of_node);
+=09struct irq_domain *msi_dom, *irq_dom;
+=09struct of_pci_range_parser parser;
+=09struct of_pci_range range;
+=09int virq, offset;
=20
 =09dev_warn(dev, "simultaneous PCI config and MMIO accesses may cause data=
 corruption\n");
 =09add_taint(TAINT_CRAP, LOCKDEP_STILL_OK);
@@ -95,6 +259,41 @@ static int tango_pcie_probe(struct platform_device *pde=
v)
 =09if (!tango_pcie_link_up(pcie))
 =09=09return -ENODEV;
=20
+=09if (of_pci_dma_range_parser_init(&parser, dev->of_node) < 0)
+=09=09return -ENOENT;
+
+=09if (of_pci_range_parser_one(&parser, &range) =3D=3D NULL)
+=09=09return -ENOENT;
+
+=09range.pci_addr +=3D range.size;
+=09pcie->msi_doorbell =3D range.pci_addr + res->start + SMP8759_DOORBELL;
+
+=09for (offset =3D 0; offset < MSI_MAX / 8; offset +=3D 4)
+=09=09writel_relaxed(0, pcie->base + SMP8759_ENABLE + offset);
+
+=09virq =3D platform_get_irq(pdev, 1);
+=09if (virq <=3D 0) {
+=09=09dev_err(dev, "Failed to map IRQ\n");
+=09=09return -ENXIO;
+=09}
+
+=09irq_dom =3D irq_domain_create_linear(fwnode, MSI_MAX, &dom_ops, pcie);
+=09if (!irq_dom) {
+=09=09dev_err(dev, "Failed to create IRQ domain\n");
+=09=09return -ENOMEM;
+=09}
+
+=09msi_dom =3D pci_msi_create_irq_domain(fwnode, &msi_dom_info, irq_dom);
+=09if (!msi_dom) {
+=09=09dev_err(dev, "Failed to create MSI domain\n");
+=09=09irq_domain_remove(irq_dom);
+=09=09return -ENOMEM;
+=09}
+
+=09pcie->dom =3D irq_dom;
+=09spin_lock_init(&pcie->used_msi_lock);
+=09irq_set_chained_handler_and_data(virq, tango_msi_isr, pcie);
+
 =09return pci_host_common_probe(pdev, &smp8759_ecam_ops);
 }
=20
--=20
2.11.0

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

* [PATCH v11 3/3] PCI: tango: Add MSI controller support
@ 2017-08-29 14:32   ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-08-29 14:32 UTC (permalink / raw)
  To: linux-arm-kernel

The MSI controller in Tango supports 256 message-signaled interrupts
and a single doorbell address.

Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
---
Changes from v10 to v11
* Discover msi_doorbell in probe by parsing dma-ranges
---
 drivers/pci/host/pcie-tango.c | 205 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 202 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/host/pcie-tango.c b/drivers/pci/host/pcie-tango.c
index 6bbb81f06a53..e23f7383ac33 100644
--- a/drivers/pci/host/pcie-tango.c
+++ b/drivers/pci/host/pcie-tango.c
@@ -1,12 +1,172 @@
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
 #include <linux/pci-ecam.h>
 #include <linux/delay.h>
-#include <linux/of.h>
+#include <linux/msi.h>
+#include <linux/of_address.h>
+
+#define MSI_MAX			256
 
 #define SMP8759_MUX		0x48
 #define SMP8759_TEST_OUT	0x74
+#define SMP8759_DOORBELL	0x7c
+#define SMP8759_STATUS		0x80
+#define SMP8759_ENABLE		0xa0
 
 struct tango_pcie {
-	void __iomem *base;
+	DECLARE_BITMAP(used_msi, MSI_MAX);
+	u64			msi_doorbell;
+	spinlock_t		used_msi_lock;
+	void __iomem		*base;
+	struct irq_domain	*dom;
+};
+
+static void tango_msi_isr(struct irq_desc *desc)
+{
+	struct irq_chip *chip = irq_desc_get_chip(desc);
+	struct tango_pcie *pcie = irq_desc_get_handler_data(desc);
+	unsigned long status, base, virq, idx, pos = 0;
+
+	chained_irq_enter(chip, desc);
+	spin_lock(&pcie->used_msi_lock);
+
+	while ((pos = find_next_bit(pcie->used_msi, MSI_MAX, pos)) < MSI_MAX) {
+		base = round_down(pos, 32);
+		status = readl_relaxed(pcie->base + SMP8759_STATUS + base / 8);
+		for_each_set_bit(idx, &status, 32) {
+			virq = irq_find_mapping(pcie->dom, base + idx);
+			generic_handle_irq(virq);
+		}
+		pos = base + 32;
+	}
+
+	spin_unlock(&pcie->used_msi_lock);
+	chained_irq_exit(chip, desc);
+}
+
+static void tango_ack(struct irq_data *d)
+{
+	struct tango_pcie *pcie = d->chip_data;
+	u32 offset = (d->hwirq / 32) * 4;
+	u32 bit = BIT(d->hwirq % 32);
+
+	writel_relaxed(bit, pcie->base + SMP8759_STATUS + offset);
+}
+
+static void update_msi_enable(struct irq_data *d, bool unmask)
+{
+	unsigned long flags;
+	struct tango_pcie *pcie = d->chip_data;
+	u32 offset = (d->hwirq / 32) * 4;
+	u32 bit = BIT(d->hwirq % 32);
+	u32 val;
+
+	spin_lock_irqsave(&pcie->used_msi_lock, flags);
+	val = readl_relaxed(pcie->base + SMP8759_ENABLE + offset);
+	val = unmask ? val | bit : val & ~bit;
+	writel_relaxed(val, pcie->base + SMP8759_ENABLE + offset);
+	spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+}
+
+static void tango_mask(struct irq_data *d)
+{
+	update_msi_enable(d, false);
+}
+
+static void tango_unmask(struct irq_data *d)
+{
+	update_msi_enable(d, true);
+}
+
+static int tango_set_affinity(struct irq_data *d, const struct cpumask *mask,
+			      bool force)
+{
+	return -EINVAL;
+}
+
+static void tango_compose_msi_msg(struct irq_data *d, struct msi_msg *msg)
+{
+	struct tango_pcie *pcie = d->chip_data;
+	msg->address_lo = lower_32_bits(pcie->msi_doorbell);
+	msg->address_hi = upper_32_bits(pcie->msi_doorbell);
+	msg->data = d->hwirq;
+}
+
+static struct irq_chip tango_chip = {
+	.irq_ack		= tango_ack,
+	.irq_mask		= tango_mask,
+	.irq_unmask		= tango_unmask,
+	.irq_set_affinity	= tango_set_affinity,
+	.irq_compose_msi_msg	= tango_compose_msi_msg,
+};
+
+static void msi_ack(struct irq_data *d)
+{
+	irq_chip_ack_parent(d);
+}
+
+static void msi_mask(struct irq_data *d)
+{
+	pci_msi_mask_irq(d);
+	irq_chip_mask_parent(d);
+}
+
+static void msi_unmask(struct irq_data *d)
+{
+	pci_msi_unmask_irq(d);
+	irq_chip_unmask_parent(d);
+}
+
+static struct irq_chip msi_chip = {
+	.name = "MSI",
+	.irq_ack = msi_ack,
+	.irq_mask = msi_mask,
+	.irq_unmask = msi_unmask,
+};
+
+static struct msi_domain_info msi_dom_info = {
+	.flags	= MSI_FLAG_PCI_MSIX
+		| MSI_FLAG_USE_DEF_DOM_OPS
+		| MSI_FLAG_USE_DEF_CHIP_OPS,
+	.chip	= &msi_chip,
+};
+
+static int tango_irq_domain_alloc(struct irq_domain *dom, unsigned int virq,
+				  unsigned int nr_irqs, void *args)
+{
+	struct tango_pcie *pcie = dom->host_data;
+	unsigned long flags;
+	int pos;
+
+	spin_lock_irqsave(&pcie->used_msi_lock, flags);
+	pos = find_first_zero_bit(pcie->used_msi, MSI_MAX);
+	if (pos >= MSI_MAX) {
+		spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+		return -ENOSPC;
+	}
+	__set_bit(pos, pcie->used_msi);
+	spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+	irq_domain_set_info(dom, virq, pos, &tango_chip,
+			pcie, handle_edge_irq, NULL, NULL);
+
+	return 0;
+}
+
+static void tango_irq_domain_free(struct irq_domain *dom, unsigned int virq,
+				  unsigned int nr_irqs)
+{
+	unsigned long flags;
+	struct irq_data *d = irq_domain_get_irq_data(dom, virq);
+	struct tango_pcie *pcie = d->chip_data;
+
+	spin_lock_irqsave(&pcie->used_msi_lock, flags);
+	__clear_bit(d->hwirq, pcie->used_msi);
+	spin_unlock_irqrestore(&pcie->used_msi_lock, flags);
+}
+
+static const struct irq_domain_ops dom_ops = {
+	.alloc	= tango_irq_domain_alloc,
+	.free	= tango_irq_domain_free,
 };
 
 static int smp8759_config_read(struct pci_bus *bus, unsigned int devfn,
@@ -76,7 +236,11 @@ static int tango_pcie_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct tango_pcie *pcie;
 	struct resource *res;
-	int ret;
+	struct fwnode_handle *fwnode = of_node_to_fwnode(dev->of_node);
+	struct irq_domain *msi_dom, *irq_dom;
+	struct of_pci_range_parser parser;
+	struct of_pci_range range;
+	int virq, offset;
 
 	dev_warn(dev, "simultaneous PCI config and MMIO accesses may cause data corruption\n");
 	add_taint(TAINT_CRAP, LOCKDEP_STILL_OK);
@@ -95,6 +259,41 @@ static int tango_pcie_probe(struct platform_device *pdev)
 	if (!tango_pcie_link_up(pcie))
 		return -ENODEV;
 
+	if (of_pci_dma_range_parser_init(&parser, dev->of_node) < 0)
+		return -ENOENT;
+
+	if (of_pci_range_parser_one(&parser, &range) == NULL)
+		return -ENOENT;
+
+	range.pci_addr += range.size;
+	pcie->msi_doorbell = range.pci_addr + res->start + SMP8759_DOORBELL;
+
+	for (offset = 0; offset < MSI_MAX / 8; offset += 4)
+		writel_relaxed(0, pcie->base + SMP8759_ENABLE + offset);
+
+	virq = platform_get_irq(pdev, 1);
+	if (virq <= 0) {
+		dev_err(dev, "Failed to map IRQ\n");
+		return -ENXIO;
+	}
+
+	irq_dom = irq_domain_create_linear(fwnode, MSI_MAX, &dom_ops, pcie);
+	if (!irq_dom) {
+		dev_err(dev, "Failed to create IRQ domain\n");
+		return -ENOMEM;
+	}
+
+	msi_dom = pci_msi_create_irq_domain(fwnode, &msi_dom_info, irq_dom);
+	if (!msi_dom) {
+		dev_err(dev, "Failed to create MSI domain\n");
+		irq_domain_remove(irq_dom);
+		return -ENOMEM;
+	}
+
+	pcie->dom = irq_dom;
+	spin_lock_init(&pcie->used_msi_lock);
+	irq_set_chained_handler_and_data(virq, tango_msi_isr, pcie);
+
 	return pci_host_common_probe(pdev, &smp8759_ecam_ops);
 }
 
-- 
2.11.0

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

* Re: [PATCH 1/3] of/pci: Add dma-ranges parsing support
  2017-08-29 14:25   ` Marc Gonzalez
@ 2017-08-31 11:55     ` Linus Walleij
  -1 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2017-08-31 11:55 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Rob Herring, Frank Rowand, Mark Rutland, Bjorn Helgaas,
	Marc Zyngier, linux-pci, Linux ARM, Robin Murphy, Liviu Dudau,
	Thibaud Cornic, Mason, Andrew Murray, Thomas Petazzoni,
	Jason Cooper, DT

On Tue, Aug 29, 2017 at 4:25 PM, Marc Gonzalez
<marc_gonzalez@sigmadesigns.com> wrote:

> Several host bridge drivers duplicate of_pci_range_parser_init()
> in order to parse their dma-ranges property.
>
> Provide of_pci_dma_range_parser_init() for that use-case.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Looks good to me.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* [PATCH 1/3] of/pci: Add dma-ranges parsing support
@ 2017-08-31 11:55     ` Linus Walleij
  0 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2017-08-31 11:55 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 29, 2017 at 4:25 PM, Marc Gonzalez
<marc_gonzalez@sigmadesigns.com> wrote:

> Several host bridge drivers duplicate of_pci_range_parser_init()
> in order to parse their dma-ranges property.
>
> Provide of_pci_dma_range_parser_init() for that use-case.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Looks good to me.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 2/3] PCI: Use of_pci_dma_range_parser_init API
  2017-08-29 14:27   ` Marc Gonzalez
@ 2017-08-31 13:53     ` Linus Walleij
  -1 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2017-08-31 13:53 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Bjorn Helgaas, linux-pci, Linux ARM, Robin Murphy, Liviu Dudau,
	Thibaud Cornic, Mason, Ray Jui, Simon Horman

On Tue, Aug 29, 2017 at 4:27 PM, Marc Gonzalez
<marc_gonzalez@sigmadesigns.com> wrote:

> Use the factorized implementation.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Looks like a real nice factorization.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* [PATCH 2/3] PCI: Use of_pci_dma_range_parser_init API
@ 2017-08-31 13:53     ` Linus Walleij
  0 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2017-08-31 13:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 29, 2017 at 4:27 PM, Marc Gonzalez
<marc_gonzalez@sigmadesigns.com> wrote:

> Use the factorized implementation.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>

Looks like a real nice factorization.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 1/3] of/pci: Add dma-ranges parsing support
  2017-08-29 14:25   ` Marc Gonzalez
@ 2017-09-01 18:27     ` Rob Herring
  -1 siblings, 0 replies; 17+ messages in thread
From: Rob Herring @ 2017-09-01 18:27 UTC (permalink / raw)
  To: Marc Gonzalez
  Cc: Frank Rowand, Mark Rutland, Thomas Petazzoni, DT, Jason Cooper,
	Mason, Marc Zyngier, linux-pci, Thibaud Cornic, Andrew Murray,
	Liviu Dudau, Bjorn Helgaas, Robin Murphy, Linus Walleij,
	Linux ARM

On Tue, Aug 29, 2017 at 9:25 AM, Marc Gonzalez
<marc_gonzalez@sigmadesigns.com> wrote:
> Several host bridge drivers duplicate of_pci_range_parser_init()
> in order to parse their dma-ranges property.
>
> Provide of_pci_dma_range_parser_init() for that use-case.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> ---
>  drivers/of/address.c       | 19 ++++++++++++++++---
>  include/linux/of_address.h | 10 +++++++++-
>  2 files changed, 25 insertions(+), 4 deletions(-)

Reviewed-by: Rob Herring <robh@kernel.org>

I'm assuming this will go thru the PCI tree.

Rob

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

* [PATCH 1/3] of/pci: Add dma-ranges parsing support
@ 2017-09-01 18:27     ` Rob Herring
  0 siblings, 0 replies; 17+ messages in thread
From: Rob Herring @ 2017-09-01 18:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 29, 2017 at 9:25 AM, Marc Gonzalez
<marc_gonzalez@sigmadesigns.com> wrote:
> Several host bridge drivers duplicate of_pci_range_parser_init()
> in order to parse their dma-ranges property.
>
> Provide of_pci_dma_range_parser_init() for that use-case.
>
> Signed-off-by: Marc Gonzalez <marc_gonzalez@sigmadesigns.com>
> ---
>  drivers/of/address.c       | 19 ++++++++++++++++---
>  include/linux/of_address.h | 10 +++++++++-
>  2 files changed, 25 insertions(+), 4 deletions(-)

Reviewed-by: Rob Herring <robh@kernel.org>

I'm assuming this will go thru the PCI tree.

Rob

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

* Re: [PATCH 0/3] Tango PCIe host bridge MSI support + required API
  2017-08-29 14:19 ` Marc Gonzalez
@ 2017-09-13  7:57   ` Marc Gonzalez
  -1 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-09-13  7:57 UTC (permalink / raw)
  To: Bjorn Helgaas, Marc Zyngier
  Cc: Mason, linux-pci, Thibaud Cornic, Liviu Dudau, Robin Murphy, Linux ARM

On 29/08/2017 16:19, Marc Gonzalez wrote:

> Bjorn, Marc Z,
> 
> This patch-set includes:
>
> o [PATCH v11] PCI: tango: Add MSI controller support
> with the doorbell address parsed from DT instead of hard-coded
> in the driver.
> 
> o A wrapper to parse dma-ranges was added to drivers/of/address.c
> 
> o A few drivers were converted to use the new wrapper
> 
> Marc Gonzalez (3):
>    of/pci: Add dma-ranges parsing support
>    PCI: Use of_pci_dma_range_parser_init API
>    PCI: tango: Add MSI controller support
> 
>   drivers/of/address.c             |  19 +++-
>   drivers/pci/host/pci-ftpci100.c  |  20 +---
>   drivers/pci/host/pci-rcar-gen2.c |  20 +---
>   drivers/pci/host/pci-xgene.c     |  20 +---
>   drivers/pci/host/pcie-iproc.c    |  20 +---
>   drivers/pci/host/pcie-rcar.c     |  20 +---
>   drivers/pci/host/pcie-tango.c    | 205 ++++++++++++++++++++++++++++++++++++++-
>   include/linux/of_address.h       |  10 +-
>   8 files changed, 232 insertions(+), 102 deletions(-)

What's the word on this patch series?

Marc Z, Robin: is the computation of pcie->msi_doorbell alright?
(Is u64 the correct type for a PCI address?)

Should the first two patches be squashed together, in case reverting
is required?

Regards.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 0/3] Tango PCIe host bridge MSI support + required API
@ 2017-09-13  7:57   ` Marc Gonzalez
  0 siblings, 0 replies; 17+ messages in thread
From: Marc Gonzalez @ 2017-09-13  7:57 UTC (permalink / raw)
  To: linux-arm-kernel

On 29/08/2017 16:19, Marc Gonzalez wrote:

> Bjorn, Marc Z,
> 
> This patch-set includes:
>
> o [PATCH v11] PCI: tango: Add MSI controller support
> with the doorbell address parsed from DT instead of hard-coded
> in the driver.
> 
> o A wrapper to parse dma-ranges was added to drivers/of/address.c
> 
> o A few drivers were converted to use the new wrapper
> 
> Marc Gonzalez (3):
>    of/pci: Add dma-ranges parsing support
>    PCI: Use of_pci_dma_range_parser_init API
>    PCI: tango: Add MSI controller support
> 
>   drivers/of/address.c             |  19 +++-
>   drivers/pci/host/pci-ftpci100.c  |  20 +---
>   drivers/pci/host/pci-rcar-gen2.c |  20 +---
>   drivers/pci/host/pci-xgene.c     |  20 +---
>   drivers/pci/host/pcie-iproc.c    |  20 +---
>   drivers/pci/host/pcie-rcar.c     |  20 +---
>   drivers/pci/host/pcie-tango.c    | 205 ++++++++++++++++++++++++++++++++++++++-
>   include/linux/of_address.h       |  10 +-
>   8 files changed, 232 insertions(+), 102 deletions(-)

What's the word on this patch series?

Marc Z, Robin: is the computation of pcie->msi_doorbell alright?
(Is u64 the correct type for a PCI address?)

Should the first two patches be squashed together, in case reverting
is required?

Regards.

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

end of thread, other threads:[~2017-09-13  7:57 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-29 14:19 [PATCH 0/3] Tango PCIe host bridge MSI support + required API Marc Gonzalez
2017-08-29 14:19 ` Marc Gonzalez
2017-08-29 14:25 ` [PATCH 1/3] of/pci: Add dma-ranges parsing support Marc Gonzalez
2017-08-29 14:25   ` Marc Gonzalez
2017-08-29 14:25   ` Marc Gonzalez
2017-08-31 11:55   ` Linus Walleij
2017-08-31 11:55     ` Linus Walleij
2017-09-01 18:27   ` Rob Herring
2017-09-01 18:27     ` Rob Herring
2017-08-29 14:27 ` [PATCH 2/3] PCI: Use of_pci_dma_range_parser_init API Marc Gonzalez
2017-08-29 14:27   ` Marc Gonzalez
2017-08-31 13:53   ` Linus Walleij
2017-08-31 13:53     ` Linus Walleij
2017-08-29 14:32 ` [PATCH v11 3/3] PCI: tango: Add MSI controller support Marc Gonzalez
2017-08-29 14:32   ` Marc Gonzalez
2017-09-13  7:57 ` [PATCH 0/3] Tango PCIe host bridge MSI support + required API Marc Gonzalez
2017-09-13  7:57   ` Marc Gonzalez

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.