Skip to content

Commit 46dfdb0

Browse files
robherringgregkh
authored andcommitted
of/address: Add support for 3 address cell bus
[ Upstream commit 3d5089c4263d3594dc055e0f9c5cb990505cdd64 ] There's a few custom bus bindings (e.g. fsl,qoriq-mc) which use a 3 cell format with custom flags in the high cell. We can match these buses as a fallback if we didn't match on PCI bus which is the only standard bus binding with 3 address cells. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring <[email protected]> Stable-dep-of: 7f05e20b989a ("of: address: Preserve the flags portion on 1:1 dma-ranges mapping") Signed-off-by: Sasha Levin <[email protected]>
1 parent 57e3220 commit 46dfdb0

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

drivers/of/address.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ static int of_bus_default_translate(__be32 *addr, u64 offset, int na)
9595
return 0;
9696
}
9797

98+
static unsigned int of_bus_default_flags_get_flags(const __be32 *addr)
99+
{
100+
return of_read_number(addr, 1);
101+
}
102+
98103
static unsigned int of_bus_default_get_flags(const __be32 *addr)
99104
{
100105
return IORESOURCE_MEM;
101106
}
102107

108+
103109
#ifdef CONFIG_PCI
104110
static unsigned int of_bus_pci_get_flags(const __be32 *addr)
105111
{
@@ -319,6 +325,11 @@ static unsigned int of_bus_isa_get_flags(const __be32 *addr)
319325
return flags;
320326
}
321327

328+
static int of_bus_default_flags_match(struct device_node *np)
329+
{
330+
return of_bus_n_addr_cells(np) == 3;
331+
}
332+
322333
/*
323334
* Array of bus specific translators
324335
*/
@@ -348,6 +359,17 @@ static struct of_bus of_busses[] = {
348359
.has_flags = true,
349360
.get_flags = of_bus_isa_get_flags,
350361
},
362+
/* Default with flags cell */
363+
{
364+
.name = "default-flags",
365+
.addresses = "reg",
366+
.match = of_bus_default_flags_match,
367+
.count_cells = of_bus_default_count_cells,
368+
.map = of_bus_default_map,
369+
.translate = of_bus_default_translate,
370+
.has_flags = true,
371+
.get_flags = of_bus_default_flags_get_flags,
372+
},
351373
/* Default */
352374
{
353375
.name = "default",

drivers/of/unittest-data/tests-address.dtsi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#size-cells = <1>;
1515
/* ranges here is to make sure we don't use it for
1616
* dma-ranges translation */
17-
ranges = <0x70000000 0x70000000 0x40000000>,
17+
ranges = <0x70000000 0x70000000 0x50000000>,
1818
<0x00000000 0xd0000000 0x20000000>;
1919
dma-ranges = <0x0 0x20000000 0x40000000>;
2020

@@ -43,6 +43,13 @@
4343
<0x42000000 0x0 0xc0000000 0x20000000 0x0 0x10000000>;
4444
};
4545

46+
bus@a0000000 {
47+
#address-cells = <3>;
48+
#size-cells = <2>;
49+
ranges = <0xf00baa 0x0 0x0 0xa0000000 0x0 0x100000>,
50+
<0xf00bee 0x1 0x0 0xb0000000 0x0 0x200000>;
51+
};
52+
4653
};
4754
};
4855
};

drivers/of/unittest.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ static void __init of_unittest_bus_ranges(void)
10451045
"for_each_of_range wrong flags on node %pOF flags=%x (expected %x)\n",
10461046
np, range.flags, IORESOURCE_MEM);
10471047
if (!i) {
1048-
unittest(range.size == 0x40000000,
1048+
unittest(range.size == 0x50000000,
10491049
"for_each_of_range wrong size on node %pOF size=%llx\n",
10501050
np, range.size);
10511051
unittest(range.cpu_addr == 0x70000000,
@@ -1071,6 +1071,61 @@ static void __init of_unittest_bus_ranges(void)
10711071
of_node_put(np);
10721072
}
10731073

1074+
static void __init of_unittest_bus_3cell_ranges(void)
1075+
{
1076+
struct device_node *np;
1077+
struct of_range range;
1078+
struct of_range_parser parser;
1079+
int i = 0;
1080+
1081+
np = of_find_node_by_path("/testcase-data/address-tests/bus@a0000000");
1082+
if (!np) {
1083+
pr_err("missing testcase data\n");
1084+
return;
1085+
}
1086+
1087+
if (of_range_parser_init(&parser, np)) {
1088+
pr_err("missing ranges property\n");
1089+
return;
1090+
}
1091+
1092+
/*
1093+
* Get the "ranges" from the device tree
1094+
*/
1095+
for_each_of_range(&parser, &range) {
1096+
if (!i) {
1097+
unittest(range.flags == 0xf00baa,
1098+
"for_each_of_range wrong flags on node %pOF flags=%x\n",
1099+
np, range.flags);
1100+
unittest(range.size == 0x100000,
1101+
"for_each_of_range wrong size on node %pOF size=%llx\n",
1102+
np, range.size);
1103+
unittest(range.cpu_addr == 0xa0000000,
1104+
"for_each_of_range wrong CPU addr (%llx) on node %pOF",
1105+
range.cpu_addr, np);
1106+
unittest(range.bus_addr == 0x0,
1107+
"for_each_of_range wrong bus addr (%llx) on node %pOF",
1108+
range.pci_addr, np);
1109+
} else {
1110+
unittest(range.flags == 0xf00bee,
1111+
"for_each_of_range wrong flags on node %pOF flags=%x\n",
1112+
np, range.flags);
1113+
unittest(range.size == 0x200000,
1114+
"for_each_of_range wrong size on node %pOF size=%llx\n",
1115+
np, range.size);
1116+
unittest(range.cpu_addr == 0xb0000000,
1117+
"for_each_of_range wrong CPU addr (%llx) on node %pOF",
1118+
range.cpu_addr, np);
1119+
unittest(range.bus_addr == 0x100000000,
1120+
"for_each_of_range wrong bus addr (%llx) on node %pOF",
1121+
range.pci_addr, np);
1122+
}
1123+
i++;
1124+
}
1125+
1126+
of_node_put(np);
1127+
}
1128+
10741129
static void __init of_unittest_parse_interrupts(void)
10751130
{
10761131
struct device_node *np;
@@ -3574,6 +3629,7 @@ static int __init of_unittest(void)
35743629
of_unittest_parse_dma_ranges();
35753630
of_unittest_pci_dma_ranges();
35763631
of_unittest_bus_ranges();
3632+
of_unittest_bus_3cell_ranges();
35773633
of_unittest_match_node();
35783634
of_unittest_platform_populate();
35793635
of_unittest_overlay();

0 commit comments

Comments
 (0)