diff mbox series

[v3,1/5] of_address: Add bus type match for pci ranges parser

Message ID 20200725014529.1143208-2-jiaxun.yang@flygoat.com
State Not Applicable, archived
Headers show
Series MIPS: Loongson64: Process ISA Node in DeviceTree | expand

Checks

Context Check Description
robh/checkpatch success

Commit Message

Jiaxun Yang July 25, 2020, 1:45 a.m. UTC
So the parser can be used to parse range property of ISA bus.

As they're all using PCI-like method of range property, there is no need
start a new parser.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

--
v2: Drop useless check, fix some na for bus_addr
	add define of of_range_parser_init according to
	Rob's suggestion.
v3: Abstract out has_flags. simplify define.
---
 drivers/of/address.c       | 29 +++++++++++++++++------------
 include/linux/of_address.h |  4 ++++
 2 files changed, 21 insertions(+), 12 deletions(-)

Comments

Rob Herring July 27, 2020, 5:50 p.m. UTC | #1
On Fri, Jul 24, 2020 at 7:45 PM Jiaxun Yang <jiaxun.yang@flygoat.com> wrote:
>
> So the parser can be used to parse range property of ISA bus.
>
> As they're all using PCI-like method of range property, there is no need
> start a new parser.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
>
> --
> v2: Drop useless check, fix some na for bus_addr
>         add define of of_range_parser_init according to
>         Rob's suggestion.
> v3: Abstract out has_flags. simplify define.
> ---
>  drivers/of/address.c       | 29 +++++++++++++++++------------
>  include/linux/of_address.h |  4 ++++
>  2 files changed, 21 insertions(+), 12 deletions(-)

Reviewed-by: Rob Herring <robh@kernel.org>
Thomas Bogendoerfer July 28, 2020, 8:33 a.m. UTC | #2
On Mon, Jul 27, 2020 at 11:50:14AM -0600, Rob Herring wrote:
> On Fri, Jul 24, 2020 at 7:45 PM Jiaxun Yang <jiaxun.yang@flygoat.com> wrote:
> >
> > So the parser can be used to parse range property of ISA bus.
> >
> > As they're all using PCI-like method of range property, there is no need
> > start a new parser.
> >
> > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> >
> > --
> > v2: Drop useless check, fix some na for bus_addr
> >         add define of of_range_parser_init according to
> >         Rob's suggestion.
> > v3: Abstract out has_flags. simplify define.
> > ---
> >  drivers/of/address.c       | 29 +++++++++++++++++------------
> >  include/linux/of_address.h |  4 ++++
> >  2 files changed, 21 insertions(+), 12 deletions(-)
> 
> Reviewed-by: Rob Herring <robh@kernel.org>

Rob, are you ok with merging this via the mips-next tree ?

Thomas.
Rob Herring July 28, 2020, 1:46 p.m. UTC | #3
On Tue, Jul 28, 2020 at 2:39 AM Thomas Bogendoerfer
<tsbogend@alpha.franken.de> wrote:
>
> On Mon, Jul 27, 2020 at 11:50:14AM -0600, Rob Herring wrote:
> > On Fri, Jul 24, 2020 at 7:45 PM Jiaxun Yang <jiaxun.yang@flygoat.com> wrote:
> > >
> > > So the parser can be used to parse range property of ISA bus.
> > >
> > > As they're all using PCI-like method of range property, there is no need
> > > start a new parser.
> > >
> > > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> > >
> > > --
> > > v2: Drop useless check, fix some na for bus_addr
> > >         add define of of_range_parser_init according to
> > >         Rob's suggestion.
> > > v3: Abstract out has_flags. simplify define.
> > > ---
> > >  drivers/of/address.c       | 29 +++++++++++++++++------------
> > >  include/linux/of_address.h |  4 ++++
> > >  2 files changed, 21 insertions(+), 12 deletions(-)
> >
> > Reviewed-by: Rob Herring <robh@kernel.org>
>
> Rob, are you ok with merging this via the mips-next tree ?

That's my expectation hence the Reviewed-by.

Rob
diff mbox series

Patch

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 8eea3f6e29a4..813936d419ad 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -49,6 +49,7 @@  struct of_bus {
 	u64		(*map)(__be32 *addr, const __be32 *range,
 				int na, int ns, int pna);
 	int		(*translate)(__be32 *addr, u64 offset, int na);
+	bool	has_flags;
 	unsigned int	(*get_flags)(const __be32 *addr);
 };
 
@@ -364,6 +365,7 @@  static struct of_bus of_busses[] = {
 		.count_cells = of_bus_pci_count_cells,
 		.map = of_bus_pci_map,
 		.translate = of_bus_pci_translate,
+		.has_flags = true,
 		.get_flags = of_bus_pci_get_flags,
 	},
 #endif /* CONFIG_PCI */
@@ -375,6 +377,7 @@  static struct of_bus of_busses[] = {
 		.count_cells = of_bus_isa_count_cells,
 		.map = of_bus_isa_map,
 		.translate = of_bus_isa_translate,
+		.has_flags = true,
 		.get_flags = of_bus_isa_get_flags,
 	},
 	/* Default */
@@ -698,9 +701,10 @@  static int parser_init(struct of_pci_range_parser *parser,
 
 	parser->node = node;
 	parser->pna = of_n_addr_cells(node);
-	parser->na = of_bus_n_addr_cells(node);
-	parser->ns = of_bus_n_size_cells(node);
 	parser->dma = !strcmp(name, "dma-ranges");
+	parser->bus = of_match_bus(node);
+
+	parser->bus->count_cells(parser->node, &parser->na, &parser->ns);
 
 	parser->range = of_get_property(node, name, &rlen);
 	if (parser->range == NULL)
@@ -732,6 +736,7 @@  struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 	int na = parser->na;
 	int ns = parser->ns;
 	int np = parser->pna + na + ns;
+	int busflag_na = 0;
 
 	if (!range)
 		return NULL;
@@ -739,12 +744,13 @@  struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 	if (!parser->range || parser->range + np > parser->end)
 		return NULL;
 
-	if (parser->na == 3)
-		range->flags = of_bus_pci_get_flags(parser->range);
-	else
-		range->flags = 0;
+	range->flags = parser->bus->get_flags(parser->range);
+
+	/* A extra cell for resource flags */
+	if (parser->bus->has_flags)
+		busflag_na = 1;
 
-	range->pci_addr = of_read_number(parser->range, na);
+	range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
 
 	if (parser->dma)
 		range->cpu_addr = of_translate_dma_address(parser->node,
@@ -759,11 +765,10 @@  struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 	/* Now consume following elements while they are contiguous */
 	while (parser->range + np <= parser->end) {
 		u32 flags = 0;
-		u64 pci_addr, cpu_addr, size;
+		u64 bus_addr, cpu_addr, size;
 
-		if (parser->na == 3)
-			flags = of_bus_pci_get_flags(parser->range);
-		pci_addr = of_read_number(parser->range, na);
+		flags = parser->bus->get_flags(parser->range);
+		bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
 		if (parser->dma)
 			cpu_addr = of_translate_dma_address(parser->node,
 					parser->range + na);
@@ -774,7 +779,7 @@  struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
 
 		if (flags != range->flags)
 			break;
-		if (pci_addr != range->pci_addr + range->size ||
+		if (bus_addr != range->bus_addr + range->size ||
 		    cpu_addr != range->cpu_addr + range->size)
 			break;
 
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 763022ed3456..88bc943405cd 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -6,8 +6,11 @@ 
 #include <linux/of.h>
 #include <linux/io.h>
 
+struct of_bus;
+
 struct of_pci_range_parser {
 	struct device_node *node;
+	struct of_bus *bus;
 	const __be32 *range;
 	const __be32 *end;
 	int na;
@@ -119,6 +122,7 @@  static inline void __iomem *of_iomap(struct device_node *device, int index)
 	return NULL;
 }
 #endif
+#define of_range_parser_init of_pci_range_parser_init
 
 #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
 extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,