Skip to content

Commit b816265

Browse files
kkudielkabjorn-helgaas
authored andcommitted
PCI: mvebu: Fix use of for_each_of_range() iterator
5da3d94 ("PCI: mvebu: Use for_each_of_range() iterator for parsing "ranges"") simplified code by using the for_each_of_range() iterator, but it broke PCI enumeration on Turris Omnia (and probably other mvebu targets). Issue #1: To determine range.flags, of_pci_range_parser_one() uses bus->get_flags(), which resolves to of_bus_pci_get_flags(), which already returns an IORESOURCE bit field, and NOT the original flags from the "ranges" resource. Then mvebu_get_tgt_attr() attempts the very same conversion again. Remove the misinterpretation of range.flags in mvebu_get_tgt_attr(), to restore the intended behavior. Issue #2: The driver needs target and attributes, which are encoded in the raw address values of the "/soc/pcie/ranges" resource. According to of_pci_range_parser_one(), the raw values are stored in range.bus_addr and range.parent_bus_addr, respectively. range.cpu_addr is a translated version of range.parent_bus_addr, and not relevant here. Use the correct range structure member, to extract target and attributes. This restores the intended behavior. Fixes: 5da3d94 ("PCI: mvebu: Use for_each_of_range() iterator for parsing "ranges"") Reported-by: Jan Palus <[email protected]> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=220479 Signed-off-by: Klaus Kudielka <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Tested-by: Tony Dinh <[email protected]> Tested-by: Jan Palus <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 8f5ae30 commit b816265

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

drivers/pci/controller/pci-mvebu.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,12 +1168,6 @@ static void __iomem *mvebu_pcie_map_registers(struct platform_device *pdev,
11681168
return devm_ioremap_resource(&pdev->dev, &port->regs);
11691169
}
11701170

1171-
#define DT_FLAGS_TO_TYPE(flags) (((flags) >> 24) & 0x03)
1172-
#define DT_TYPE_IO 0x1
1173-
#define DT_TYPE_MEM32 0x2
1174-
#define DT_CPUADDR_TO_TARGET(cpuaddr) (((cpuaddr) >> 56) & 0xFF)
1175-
#define DT_CPUADDR_TO_ATTR(cpuaddr) (((cpuaddr) >> 48) & 0xFF)
1176-
11771171
static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
11781172
unsigned long type,
11791173
unsigned int *tgt,
@@ -1189,19 +1183,12 @@ static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
11891183
return -EINVAL;
11901184

11911185
for_each_of_range(&parser, &range) {
1192-
unsigned long rtype;
11931186
u32 slot = upper_32_bits(range.bus_addr);
11941187

1195-
if (DT_FLAGS_TO_TYPE(range.flags) == DT_TYPE_IO)
1196-
rtype = IORESOURCE_IO;
1197-
else if (DT_FLAGS_TO_TYPE(range.flags) == DT_TYPE_MEM32)
1198-
rtype = IORESOURCE_MEM;
1199-
else
1200-
continue;
1201-
1202-
if (slot == PCI_SLOT(devfn) && type == rtype) {
1203-
*tgt = DT_CPUADDR_TO_TARGET(range.cpu_addr);
1204-
*attr = DT_CPUADDR_TO_ATTR(range.cpu_addr);
1188+
if (slot == PCI_SLOT(devfn) &&
1189+
type == (range.flags & IORESOURCE_TYPE_BITS)) {
1190+
*tgt = (range.parent_bus_addr >> 56) & 0xFF;
1191+
*attr = (range.parent_bus_addr >> 48) & 0xFF;
12051192
return 0;
12061193
}
12071194
}

0 commit comments

Comments
 (0)