Skip to content

Commit 5da3d94

Browse files
robherringMani-Sadhasivam
authored andcommitted
PCI: mvebu: Use for_each_of_range() iterator for parsing "ranges"
The mvebu "ranges" is a bit unusual with its own encoding of addresses, but it's still just normal "ranges" as far as parsing is concerned. Convert mvebu_get_tgt_attr() to use the for_each_of_range() iterator instead of open coding the parsing. Signed-off-by: Rob Herring (Arm) <[email protected]> Signed-off-by: Manivannan Sadhasivam <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 0af2f6b commit 5da3d94

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

drivers/pci/controller/pci-mvebu.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,37 +1179,29 @@ static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
11791179
unsigned int *tgt,
11801180
unsigned int *attr)
11811181
{
1182-
const int na = 3, ns = 2;
1183-
const __be32 *range;
1184-
int rlen, nranges, rangesz, pna, i;
1182+
struct of_range range;
1183+
struct of_range_parser parser;
11851184

11861185
*tgt = -1;
11871186
*attr = -1;
11881187

1189-
range = of_get_property(np, "ranges", &rlen);
1190-
if (!range)
1188+
if (of_pci_range_parser_init(&parser, np))
11911189
return -EINVAL;
11921190

1193-
pna = of_n_addr_cells(np);
1194-
rangesz = pna + na + ns;
1195-
nranges = rlen / sizeof(__be32) / rangesz;
1196-
1197-
for (i = 0; i < nranges; i++, range += rangesz) {
1198-
u32 flags = of_read_number(range, 1);
1199-
u32 slot = of_read_number(range + 1, 1);
1200-
u64 cpuaddr = of_read_number(range + na, pna);
1191+
for_each_of_range(&parser, &range) {
12011192
unsigned long rtype;
1193+
u32 slot = upper_32_bits(range.bus_addr);
12021194

1203-
if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_IO)
1195+
if (DT_FLAGS_TO_TYPE(range.flags) == DT_TYPE_IO)
12041196
rtype = IORESOURCE_IO;
1205-
else if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_MEM32)
1197+
else if (DT_FLAGS_TO_TYPE(range.flags) == DT_TYPE_MEM32)
12061198
rtype = IORESOURCE_MEM;
12071199
else
12081200
continue;
12091201

12101202
if (slot == PCI_SLOT(devfn) && type == rtype) {
1211-
*tgt = DT_CPUADDR_TO_TARGET(cpuaddr);
1212-
*attr = DT_CPUADDR_TO_ATTR(cpuaddr);
1203+
*tgt = DT_CPUADDR_TO_TARGET(range.cpu_addr);
1204+
*attr = DT_CPUADDR_TO_ATTR(range.cpu_addr);
12131205
return 0;
12141206
}
12151207
}

0 commit comments

Comments
 (0)