Skip to contentSkip to conversation

of/irq: provide more wrappers for !CONFIG_OF

PATCH In review Arnd Bergmann 4 participants 6 messages Jun 3, 2014 – Jun 4, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 of/irq: provide more wrappers for !CONFIG_OF

The pci-rcar driver is enabled for compile tests, and this has now shown that the driver cannot build without CONFIG_OF, following the inclusion of f8f2fe7355fb "PCI: rcar: Use new OF interrupt mapping when possible":

drivers/built-in.o: In function `rcar_pci_map_irq':
:(.text+0x1cc7c): undefined reference to `of_irq_parse_and_map_pci'
pci/host/pcie-rcar.c: In function 'pci_dma_range_parser_init':
pci/host/pcie-rcar.c:875:2: error: implicit declaration of function 'of_n_addr_cells' [-Werror=implicit-function-declaration]

As pointed out by Ben Dooks and Geert Uytterhoeven, this is actually supposed to build fine, which we can achieve if we make the declaration of of_irq_parse_and_map_pci conditional on CONFIG_OF and provide an empty inline function otherwise, as we do for a lot of other of interfaces.

This lets us build the rcar_pci driver again without CONFIG_OF for build testing. All platforms using this driver select OF, so this doesn't change anything for the users.

Cc Rob Herring <[email protected]>
Cc Grant Likely <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Magnus Damm <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ben Dooks <[email protected]>

----

This replaces "[PATCH v2] of/irq: provide int of_irq_parse_and_map_pci wrapper", since now the same driver requires additional interfaces. We still want to be able to build the driver with CONFIG_OF disabled, but now we need three functions instead of just one.

Rob, Grant, can you apply this as a bug fix, or provide comments?

include/linux/of.h +3 -0
index 196b34c..7c29e6c 100644
@@ -511,6 +511,9 @@ static inline struct device_node *of_get_cpu_node(int cpu,
 	return NULL;
 }
 
+static inline int of_n_addr_cells(struct device_node *np) { return 0; }
+static inline int of_n_size_cells(struct device_node *np) { return 0; }
+
 static inline int of_property_read_u64(const struct device_node *np,
 				       const char *propname, u64 *out_value)
 {
include/linux/of_pci.h +33 -3
index 1a1f5ff..dde3a4a 100644
@@ -6,14 +6,44 @@
 
 struct pci_dev;
 struct of_phandle_args;
-int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq);
-int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
-
 struct device_node;
+
+#ifdef CONFIG_OF
+int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq);
 struct device_node *of_pci_find_child_device(struct device_node *parent,
 					     unsigned int devfn);
 int of_pci_get_devfn(struct device_node *np);
+int of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin);
 int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
+#else
+static inline int of_irq_parse_pci(const struct pci_dev *pdev, struct of_phandle_args *out_irq)
+{
+	return 0;
+}
+
+static inline struct device_node *of_pci_find_child_device(struct device_node *parent,
+					     unsigned int devfn)
+{
+	return NULL;
+}
+
+static inline int of_pci_get_devfn(struct device_node *np)
+{
+	return -EINVAL;
+}
+
+static inline int
+of_irq_parse_and_map_pci(const struct pci_dev *dev, u8 slot, u8 pin)
+{
+	return 0;
+}
+
+static inline int
+of_pci_parse_bus_range(struct device_node *node, struct resource *res)
+{
+	return -EINVAL;
+}
+#endif
 
 #if defined(CONFIG_OF) && defined(CONFIG_PCI_MSI)
 int of_pci_msi_chip_add(struct msi_chip *chip);
#1 lore raw
Quoted 45 lines · Arnd Bergmann

The pci-rcar driver is enabled for compile tests, and this has now shown that the driver cannot build without CONFIG_OF, following the inclusion of f8f2fe7355fb "PCI: rcar: Use new OF interrupt mapping when possible":

drivers/built-in.o: In function `rcar_pci_map_irq':
:(.text+0x1cc7c): undefined reference to `of_irq_parse_and_map_pci'
pci/host/pcie-rcar.c: In function 'pci_dma_range_parser_init':
pci/host/pcie-rcar.c:875:2: error: implicit declaration of function 'of_n_addr_cells' [-Werror=implicit-function-declaration]

As pointed out by Ben Dooks and Geert Uytterhoeven, this is actually supposed to build fine, which we can achieve if we make the declaration of of_irq_parse_and_map_pci conditional on CONFIG_OF and provide an empty inline function otherwise, as we do for a lot of other of interfaces.

This lets us build the rcar_pci driver again without CONFIG_OF for build testing. All platforms using this driver select OF, so this doesn't change anything for the users.

Cc Rob Herring <[email protected]>
Cc Grant Likely <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Magnus Damm <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ben Dooks <[email protected]>

----

This replaces "[PATCH v2] of/irq: provide int of_irq_parse_and_map_pci wrapper", since now the same driver requires additional interfaces. We still want to be able to build the driver with CONFIG_OF disabled, but now we need three functions instead of just one.

Rob, Grant, can you apply this as a bug fix, or provide comments?

include/linux/of.h +0 -0
index 196b34c..7c29e6c 100644

include/linux/of.h static inline struct device_node *of_get_cpu_node(int cpu, · line 515

Quoted 5 lines
include/linux/of.h +2 -0
@@ -511,6 +511,9 @@ static inline struct device_node *of_get_cpu_node(int cpu,
        return NULL;
 }
 
+static inline int of_n_addr_cells(struct device_node *np) { return 0; }
+static inline int of_n_size_cells(struct device_node *np) { return 0; }

I'm fine with the rest, but I think these should always be used within some higher level function.

I can't seem to find where this is used by rcar. BTW, why does rcar pci DT support fail to have any ranges property?

Looking at one use in mvebu pci only confirms my position. An of_for_each_ranges helper would be useful in that case.

Rob

#2 lore raw
Quoted 8 lines · On Tuesday 03 June 2014 10:40:34 Rob Herring wrote:
Quoted 8 lines
include/linux/of.h +0 -0
index 196b34c..7c29e6c 100644
@@ -511,6 +511,9 @@ static inline struct device_node *of_get_cpu_node(int cpu,
        return NULL;
 }
 
Quoted 5 lines

include/linux/of.h static inline struct device_node *of_get_cpu_node(int cpu, · line 515

Quoted 2 lines
include/linux/of.h +2 -0
+static inline int of_n_addr_cells(struct device_node *np) { return 0; }
+static inline int of_n_size_cells(struct device_node *np) { return 0; }

I'm fine with the rest, but I think these should always be used within some higher level function.

Can you apply the rest already?

Quoted 5 lines

I can't seem to find where this is used by rcar. BTW, why does rcar pci DT support fail to have any ranges property?

Looking at one use in mvebu pci only confirms my position. An of_for_each_ranges helper would be useful in that case.

It's currently in the pci-next, the code using this looks like

+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)
+{

+       struct of_pci_range range;
+       struct of_pci_range_parser parser;
+       int index = 0;
+       int err;

+
+ if (pci_dma_range_parser_init(&parser, np))
+ return -EINVAL;
+
+ /* Get the dma-ranges from DT */
+ for_each_of_pci_range(&parser, &range) {
+ u64 end = range.cpu_addr + range.size - 1;
+ dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
+ range.flags, range.cpu_addr, end, range.pci_addr);
+
+ err = rcar_pcie_inbound_ranges(pcie, &range, &index);
+ if (err)
+ return err;
+ }
+
+ return 0;
+}

Should the first function just be moved into of-pci.c?

Arnd

#3 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · On Tuesday 03 June 2014 10:40:34 Rob Herring wrote:
Quoted 8 lines
include/linux/of.h +0 -0
index 196b34c..7c29e6c 100644
@@ -511,6 +511,9 @@ static inline struct device_node *of_get_cpu_node(int cpu,
        return NULL;
 }
 
Quoted 7 lines
Quoted 5 lines

include/linux/of.h static inline struct device_node *of_get_cpu_node(int cpu, · line 515

Quoted 2 lines
include/linux/of.h +2 -0
+static inline int of_n_addr_cells(struct device_node *np) { return 0; }
+static inline int of_n_size_cells(struct device_node *np) { return 0; }

I'm fine with the rest, but I think these should always be used within some higher level function.

Can you apply the rest already?

Yes, sure.

Quoted 52 lines
Quoted 6 lines

I can't seem to find where this is used by rcar. BTW, why does rcar pci DT support fail to have any ranges property?

Looking at one use in mvebu pci only confirms my position. An of_for_each_ranges helper would be useful in that case.

It's currently in the pci-next, the code using this looks like

(quoted diff) +42 -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)
+{
+       struct of_pci_range range;
+       struct of_pci_range_parser parser;
+       int index = 0;
+       int err;
+
+       if (pci_dma_range_parser_init(&parser, np))
+               return -EINVAL;
+
+       /* Get the dma-ranges from DT */
+       for_each_of_pci_range(&parser, &range) {
+               u64 end = range.cpu_addr + range.size - 1;
+               dev_dbg(pcie->dev, "0x%08x 0x%016llx..0x%016llx -> 0x%016llx\n",
+                       range.flags, range.cpu_addr, end, range.pci_addr);
+
+               err = rcar_pcie_inbound_ranges(pcie, &range, &index);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
Quoted 1 line

Should the first function just be moved into of-pci.c?

Yes, and probably some refactoring with the "ranges" version of it too.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Rob Herring
Quoted 49 lines · Rob Herring
Quoted 48 lines · Arnd Bergmann

The pci-rcar driver is enabled for compile tests, and this has now shown that the driver cannot build without CONFIG_OF, following the inclusion of f8f2fe7355fb "PCI: rcar: Use new OF interrupt mapping when possible":

drivers/built-in.o: In function `rcar_pci_map_irq':
:(.text+0x1cc7c): undefined reference to `of_irq_parse_and_map_pci'
pci/host/pcie-rcar.c: In function 'pci_dma_range_parser_init':
pci/host/pcie-rcar.c:875:2: error: implicit declaration of function 'of_n_addr_cells' [-Werror=implicit-function-declaration]

As pointed out by Ben Dooks and Geert Uytterhoeven, this is actually supposed to build fine, which we can achieve if we make the declaration of of_irq_parse_and_map_pci conditional on CONFIG_OF and provide an empty inline function otherwise, as we do for a lot of other of interfaces.

This lets us build the rcar_pci driver again without CONFIG_OF for build testing. All platforms using this driver select OF, so this doesn't change anything for the users.

Cc Rob Herring <[email protected]>
Cc Grant Likely <[email protected]>
Cc Lucas Stach <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Magnus Damm <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Ben Dooks <[email protected]>

----

This replaces "[PATCH v2] of/irq: provide int of_irq_parse_and_map_pci wrapper", since now the same driver requires additional interfaces. We still want to be able to build the driver with CONFIG_OF disabled, but now we need three functions instead of just one.

Rob, Grant, can you apply this as a bug fix, or provide comments?

include/linux/of.h +0 -0
index 196b34c..7c29e6c 100644
@@ -511,6 +511,9 @@ static inline struct device_node *of_get_cpu_node(int cpu,
        return NULL;
 }
 
Quoted 8 lines

include/linux/of.h static inline struct device_node *of_get_cpu_node(int cpu, · line 515

Quoted 2 lines
include/linux/of.h +2 -0
+static inline int of_n_addr_cells(struct device_node *np) { return 0; }
+static inline int of_n_size_cells(struct device_node *np) { return 0; }

I'm fine with the rest, but I think these should always be used within some higher level function.

I can't seem to find where this is used by rcar. BTW, why does rcar pci DT support fail to have any ranges property?

I think the driver provides all the necessary PCI information internally as it started off as a platform-driver.

Signature · 2 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius
#5 lore raw
Quoted 23 lines · On Wednesday 04 June 2014 10:58:15 Ben Dooks wrote:
Quoted 22 lines · Rob Herring
Quoted 12 lines · Arnd Bergmann

This replaces "[PATCH v2] of/irq: provide int of_irq_parse_and_map_pci wrapper", since now the same driver requires additional interfaces. We still want to be able to build the driver with CONFIG_OF disabled, but now we need three functions instead of just one.

Rob, Grant, can you apply this as a bug fix, or provide comments?

include/linux/of.h +0 -0
index 196b34c..7c29e6c 100644

include/linux/of.h static inline struct device_node *of_get_cpu_node(int cpu, · line 515

Quoted 5 lines
include/linux/of.h +2 -0
@@ -511,6 +511,9 @@ static inline struct device_node *of_get_cpu_node(int cpu,
        return NULL;
 }
 
+static inline int of_n_addr_cells(struct device_node *np) { return 0; }
+static inline int of_n_size_cells(struct device_node *np) { return 0; }

I'm fine with the rest, but I think these should always be used within some higher level function.

Quoted 5 lines
Quoted 2 lines

I can't seem to find where this is used by rcar. BTW, why does rcar pci DT support fail to have any ranges property?

I think the driver provides all the necessary PCI information internally as it started off as a platform-driver.

Actually it gets the memory resource from the 'reg' property instead of parsing the 'ranges' property, which of course is not compliant with the generic PCI binding.

It also sets up an I/O resource that is located at the same location as the memory resource, which is just a bug but might be used to work around problems of the PCI core when no I/O resource is present.

I think that should be fixed.

I also see that the ranges parser in the pcie-rcar driver still gets I/O space wrong, we should probably move that to a common range parser once the arm64 pci implementation is in place and we can share more of the common helpers.

Arnd