Skip to content

Commit 1a75e81

Browse files
Andrea della Portarobherring
authored andcommitted
of/unittest: Add empty dma-ranges address translation tests
Intermediate DT PCI nodes dynamically generated by enabling CONFIG_PCI_DYNAMIC_OF_NODES have empty dma-ranges property. PCI address specifiers have 3 cells and when dma-ranges is missing or empty, of_translate_one() is currently dropping the flag portion of PCI addresses which are subnodes of the aforementioned ones, failing the translation. Add new tests covering this case. With this test, we get 1 new failure which is fixed in subsequent commit: FAIL of_unittest_pci_empty_dma_ranges():1245 for_each_of_pci_range wrong CPU addr (ffffffffffffffff) on node /testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0 Signed-off-by: Andrea della Porta <andrea.porta@suse.com> Link: https://lore.kernel.org/r/08f8fee4fdc0379240fda2f4a0e6f11ebf9647a8.1732441813.git.andrea.porta@suse.com Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent bc7acc0 commit 1a75e81

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
device_type = "pci";
115115
ranges = <0x82000000 0 0xe8000000 0 0xe8000000 0 0x7f00000>,
116116
<0x81000000 0 0x00000000 0 0xefff0000 0 0x0010000>;
117+
dma-ranges = <0x43000000 0x10 0x00 0x00 0x00 0x00 0x10000000>;
117118
reg = <0x00000000 0xd1070000 0x20000>;
118119

119120
pci@0,0 {
@@ -142,6 +143,7 @@
142143
#size-cells = <0x01>;
143144
ranges = <0xa0000000 0 0 0 0x2000000>,
144145
<0xb0000000 1 0 0 0x1000000>;
146+
dma-ranges = <0xc0000000 0x43000000 0x10 0x00 0x10000000>;
145147

146148
dev@e0000000 {
147149
reg = <0xa0001000 0x1000>,

drivers/of/unittest.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,44 @@ static void __init of_unittest_pci_dma_ranges(void)
12131213
of_node_put(np);
12141214
}
12151215

1216+
static void __init of_unittest_pci_empty_dma_ranges(void)
1217+
{
1218+
struct device_node *np;
1219+
struct of_pci_range range;
1220+
struct of_pci_range_parser parser;
1221+
1222+
if (!IS_ENABLED(CONFIG_PCI))
1223+
return;
1224+
1225+
np = of_find_node_by_path("/testcase-data/address-tests2/pcie@d1070000/pci@0,0/dev@0,0/local-bus@0");
1226+
if (!np) {
1227+
pr_err("missing testcase data\n");
1228+
return;
1229+
}
1230+
1231+
if (of_pci_dma_range_parser_init(&parser, np)) {
1232+
pr_err("missing dma-ranges property\n");
1233+
return;
1234+
}
1235+
1236+
/*
1237+
* Get the dma-ranges from the device tree
1238+
*/
1239+
for_each_of_pci_range(&parser, &range) {
1240+
unittest(range.size == 0x10000000,
1241+
"for_each_of_pci_range wrong size on node %pOF size=%llx\n",
1242+
np, range.size);
1243+
unittest(range.cpu_addr == 0x00000000,
1244+
"for_each_of_pci_range wrong CPU addr (%llx) on node %pOF",
1245+
range.cpu_addr, np);
1246+
unittest(range.pci_addr == 0xc0000000,
1247+
"for_each_of_pci_range wrong DMA addr (%llx) on node %pOF",
1248+
range.pci_addr, np);
1249+
}
1250+
1251+
of_node_put(np);
1252+
}
1253+
12161254
static void __init of_unittest_bus_ranges(void)
12171255
{
12181256
struct device_node *np;
@@ -4272,6 +4310,7 @@ static int __init of_unittest(void)
42724310
of_unittest_dma_get_max_cpu_address();
42734311
of_unittest_parse_dma_ranges();
42744312
of_unittest_pci_dma_ranges();
4313+
of_unittest_pci_empty_dma_ranges();
42754314
of_unittest_bus_ranges();
42764315
of_unittest_bus_3cell_ranges();
42774316
of_unittest_reg();

0 commit comments

Comments
 (0)