Skip to content

Commit 3d5089c

Browse files
committed
of/address: Add support for 3 address cell bus
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/20230328-dt-address-helpers-v1-3-e2456c3e77ab@kernel.org Signed-off-by: Rob Herring <robh@kernel.org>
1 parent c75a794 commit 3d5089c

3 files changed

Lines changed: 87 additions & 2 deletions

File tree

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
{
@@ -344,6 +350,11 @@ static unsigned int of_bus_isa_get_flags(const __be32 *addr)
344350
return flags;
345351
}
346352

353+
static int of_bus_default_flags_match(struct device_node *np)
354+
{
355+
return of_bus_n_addr_cells(np) == 3;
356+
}
357+
347358
/*
348359
* Array of bus specific translators
349360
*/
@@ -373,6 +384,17 @@ static struct of_bus of_busses[] = {
373384
.has_flags = true,
374385
.get_flags = of_bus_isa_get_flags,
375386
},
387+
/* Default with flags cell */
388+
{
389+
.name = "default-flags",
390+
.addresses = "reg",
391+
.match = of_bus_default_flags_match,
392+
.count_cells = of_bus_default_count_cells,
393+
.map = of_bus_default_map,
394+
.translate = of_bus_default_translate,
395+
.has_flags = true,
396+
.get_flags = of_bus_default_flags_get_flags,
397+
},
376398
/* Default */
377399
{
378400
.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
@@ -1048,7 +1048,7 @@ static void __init of_unittest_bus_ranges(void)
10481048
"for_each_of_range wrong flags on node %pOF flags=%x (expected %x)\n",
10491049
np, range.flags, IORESOURCE_MEM);
10501050
if (!i) {
1051-
unittest(range.size == 0x40000000,
1051+
unittest(range.size == 0x50000000,
10521052
"for_each_of_range wrong size on node %pOF size=%llx\n",
10531053
np, range.size);
10541054
unittest(range.cpu_addr == 0x70000000,
@@ -1074,6 +1074,61 @@ static void __init of_unittest_bus_ranges(void)
10741074
of_node_put(np);
10751075
}
10761076

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

0 commit comments

Comments
 (0)