From: Torsten Duwe <[email protected]>

In order to test whether device_get_dma_constraints() is now able to skip
device nodes without a DT association, temporarily remove those on 2 newly-
created nodes.

Signed-off-by: Torsten Duwe <[email protected]>

---

This test indeed makes a different whether the previous change is
applied or not, but *only* reliably for the non-flat-tree case (!?).
On the flat tree, it always fails after (reverse) applying it.

Either the previous patch is incomplete, or, more likely, the test
assumptions here are not all valid. Suggestions welcome (especially
how to create device nodes from a device tree without a reference to
their origin ;-)

---
 arch/sandbox/dts/test.dts |  9 +++++++++
 test/dm/phys2bus.c        | 25 ++++++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 0887de4333b..1d92e85c739 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -656,6 +656,15 @@
                subnode@0 {
                        compatible = "denx,u-boot-fdt-test";
                };
+               bus@7 {
+                       #address-cells = <1>;
+                       #size-cells = <1>;
+                       compatible = "denx,u-boot-test-bus";
+
+                       subnode@8 {
+                                 compatible = "denx,u-boot-fdt-test";
+                       };
+               };
        };
 
        mmio-bus@1 {
diff --git a/test/dm/phys2bus.c b/test/dm/phys2bus.c
index 67f33904943..858ed5410e2 100644
--- a/test/dm/phys2bus.c
+++ b/test/dm/phys2bus.c
@@ -15,7 +15,8 @@
 
 static int dm_test_phys_to_bus(struct unit_test_state *uts)
 {
-       struct udevice *dev;
+       struct udevice *dev, *pdev;
+       ofnode psave, nsave;
        ofnode node;
 
        node = ofnode_path("/mmio-bus@0");
@@ -31,6 +32,29 @@ static int dm_test_phys_to_bus(struct unit_test_state *uts)
        ut_asserteq_addr((void*)0x1003ffffULL, (void*)dev_phys_to_bus(dev, 
0x3ffff));
        ut_asserteq_addr((void*)0x3ffffULL, (void*)(ulong)dev_bus_to_phys(dev, 
0x1003ffff));
 
+#if CONFIG_IS_ENABLED(OF_REAL)
+       /* dma-ranges are on the grandparent bus node,
+        *  OF nodes neither here nor at parent
+        */
+       node = ofnode_path("/mmio-bus@0/bus@7");
+       ut_assert(ofnode_valid(node));
+       ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &pdev));
+
+       /* pretend the devices were discovered dynamically and have no OF node 
*/
+       psave = pdev->node_;
+       pdev->node_.np = NULL;
+       node = ofnode_path("/mmio-bus@0/bus@7/subnode@8");
+       ut_assert(ofnode_valid(node));
+       nsave = dev->node_;
+       dev->node_.np = NULL;
+       ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
+
+       ut_asserteq_addr((void *)0x1003ffffULL, (void *)dev_phys_to_bus(dev, 
0x3ffff));
+       ut_asserteq_addr((void *)0x3ffffULL, (void 
*)(ulong)dev_bus_to_phys(dev, 0x1003ffff));
+
+       pdev->node_ = psave;
+       dev->node_ = nsave;
+#endif
        return 0;
 }
 DM_TEST(dm_test_phys_to_bus, UTF_SCAN_PDATA | UTF_SCAN_FDT);
-- 
2.54.0

Reply via email to