So the parser can be used to parse range property of different bus types, such as 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@xxxxxxxxxxx> --- drivers/of/address.c | 15 +++++++++++---- include/linux/of_address.h | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 8eea3f6e29a4..250c91767648 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -702,6 +702,10 @@ static int parser_init(struct of_pci_range_parser *parser, parser->ns = of_bus_n_size_cells(node); parser->dma = !strcmp(name, "dma-ranges"); + parser->bus = of_match_bus(node); + if (!parser->bus) + return -ENOENT; + parser->range = of_get_property(node, name, &rlen); if (parser->range == NULL) return -ENOENT; @@ -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 bus_na = 0; if (!range) return NULL; @@ -739,8 +744,10 @@ 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); + parser->bus->count_cells(parser->node, &bus_na, NULL); + + if (parser->na == bus_na) + range->flags = parser->bus->get_flags(parser->range); else range->flags = 0; @@ -761,8 +768,8 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, u32 flags = 0; u64 pci_addr, cpu_addr, size; - if (parser->na == 3) - flags = of_bus_pci_get_flags(parser->range); + if (parser->na == bus_na) + flags = parser->bus->get_flags(parser->range); pci_addr = of_read_number(parser->range, na); if (parser->dma) cpu_addr = of_translate_dma_address(parser->node, diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 763022ed3456..3929b4637033 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; -- 2.28.0.rc1