Skip to content

Commit 2f96593

Browse files
FlyGoattsbogend
authored andcommitted
of_address: Add bus type match for pci ranges parser
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 <[email protected]> Reviewed-by: Rob Herring <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent aa35a5e commit 2f96593

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

drivers/of/address.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct of_bus {
4949
u64 (*map)(__be32 *addr, const __be32 *range,
5050
int na, int ns, int pna);
5151
int (*translate)(__be32 *addr, u64 offset, int na);
52+
bool has_flags;
5253
unsigned int (*get_flags)(const __be32 *addr);
5354
};
5455

@@ -364,6 +365,7 @@ static struct of_bus of_busses[] = {
364365
.count_cells = of_bus_pci_count_cells,
365366
.map = of_bus_pci_map,
366367
.translate = of_bus_pci_translate,
368+
.has_flags = true,
367369
.get_flags = of_bus_pci_get_flags,
368370
},
369371
#endif /* CONFIG_PCI */
@@ -375,6 +377,7 @@ static struct of_bus of_busses[] = {
375377
.count_cells = of_bus_isa_count_cells,
376378
.map = of_bus_isa_map,
377379
.translate = of_bus_isa_translate,
380+
.has_flags = true,
378381
.get_flags = of_bus_isa_get_flags,
379382
},
380383
/* Default */
@@ -698,9 +701,10 @@ static int parser_init(struct of_pci_range_parser *parser,
698701

699702
parser->node = node;
700703
parser->pna = of_n_addr_cells(node);
701-
parser->na = of_bus_n_addr_cells(node);
702-
parser->ns = of_bus_n_size_cells(node);
703704
parser->dma = !strcmp(name, "dma-ranges");
705+
parser->bus = of_match_bus(node);
706+
707+
parser->bus->count_cells(parser->node, &parser->na, &parser->ns);
704708

705709
parser->range = of_get_property(node, name, &rlen);
706710
if (parser->range == NULL)
@@ -732,19 +736,21 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
732736
int na = parser->na;
733737
int ns = parser->ns;
734738
int np = parser->pna + na + ns;
739+
int busflag_na = 0;
735740

736741
if (!range)
737742
return NULL;
738743

739744
if (!parser->range || parser->range + np > parser->end)
740745
return NULL;
741746

742-
if (parser->na == 3)
743-
range->flags = of_bus_pci_get_flags(parser->range);
744-
else
745-
range->flags = 0;
747+
range->flags = parser->bus->get_flags(parser->range);
748+
749+
/* A extra cell for resource flags */
750+
if (parser->bus->has_flags)
751+
busflag_na = 1;
746752

747-
range->pci_addr = of_read_number(parser->range, na);
753+
range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
748754

749755
if (parser->dma)
750756
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,
759765
/* Now consume following elements while they are contiguous */
760766
while (parser->range + np <= parser->end) {
761767
u32 flags = 0;
762-
u64 pci_addr, cpu_addr, size;
768+
u64 bus_addr, cpu_addr, size;
763769

764-
if (parser->na == 3)
765-
flags = of_bus_pci_get_flags(parser->range);
766-
pci_addr = of_read_number(parser->range, na);
770+
flags = parser->bus->get_flags(parser->range);
771+
bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
767772
if (parser->dma)
768773
cpu_addr = of_translate_dma_address(parser->node,
769774
parser->range + na);
@@ -774,7 +779,7 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
774779

775780
if (flags != range->flags)
776781
break;
777-
if (pci_addr != range->pci_addr + range->size ||
782+
if (bus_addr != range->bus_addr + range->size ||
778783
cpu_addr != range->cpu_addr + range->size)
779784
break;
780785

include/linux/of_address.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
#include <linux/of.h>
77
#include <linux/io.h>
88

9+
struct of_bus;
10+
911
struct of_pci_range_parser {
1012
struct device_node *node;
13+
struct of_bus *bus;
1114
const __be32 *range;
1215
const __be32 *end;
1316
int na;
@@ -119,6 +122,7 @@ static inline void __iomem *of_iomap(struct device_node *device, int index)
119122
return NULL;
120123
}
121124
#endif
125+
#define of_range_parser_init of_pci_range_parser_init
122126

123127
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
124128
extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,

0 commit comments

Comments
 (0)