]> Git Repo - u-boot.git/blobdiff - test/dm/core.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[u-boot.git] / test / dm / core.c
index 6f380a574cf271da9aea69f3f98fe26c13f699b9..7f3f8d183bca4af336e60c32ad380e7d166f9d88 100644 (file)
@@ -11,6 +11,7 @@
 #include <fdtdec.h>
 #include <log.h>
 #include <malloc.h>
+#include <asm/global_data.h>
 #include <dm/device-internal.h>
 #include <dm/root.h>
 #include <dm/util.h>
@@ -43,35 +44,43 @@ static const struct dm_test_pdata test_pdata_pre_reloc = {
        .ping_add               = TEST_INTVAL_PRE_RELOC,
 };
 
-U_BOOT_DEVICE(dm_test_info1) = {
+U_BOOT_DRVINFO(dm_test_info1) = {
        .name = "test_drv",
-       .platdata = &test_pdata[0],
+       .plat = &test_pdata[0],
 };
 
-U_BOOT_DEVICE(dm_test_info2) = {
+U_BOOT_DRVINFO(dm_test_info2) = {
        .name = "test_drv",
-       .platdata = &test_pdata[1],
+       .plat = &test_pdata[1],
 };
 
-U_BOOT_DEVICE(dm_test_info3) = {
+U_BOOT_DRVINFO(dm_test_info3) = {
        .name = "test_drv",
-       .platdata = &test_pdata[2],
+       .plat = &test_pdata[2],
 };
 
 static struct driver_info driver_info_manual = {
        .name = "test_manual_drv",
-       .platdata = &test_pdata_manual,
+       .plat = &test_pdata_manual,
 };
 
 static struct driver_info driver_info_pre_reloc = {
        .name = "test_pre_reloc_drv",
-       .platdata = &test_pdata_pre_reloc,
+       .plat = &test_pdata_pre_reloc,
 };
 
 static struct driver_info driver_info_act_dma = {
        .name = "test_act_dma_drv",
 };
 
+static struct driver_info driver_info_vital_clk = {
+       .name = "test_vital_clk_drv",
+};
+
+static struct driver_info driver_info_act_dma_vital_clk = {
+       .name = "test_act_dma_vital_clk_drv",
+};
+
 void dm_leak_check_start(struct unit_test_state *uts)
 {
        uts->start = mallinfo();
@@ -105,25 +114,24 @@ int dm_leak_check_end(struct unit_test_state *uts)
        return 0;
 }
 
-/* Test that binding with platdata occurs correctly */
+/* Test that binding with plat occurs correctly */
 static int dm_test_autobind(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *dev;
 
        /*
         * We should have a single class (UCLASS_ROOT) and a single root
         * device with no children.
         */
-       ut_assert(dms->root);
-       ut_asserteq(1, list_count_items(&gd->uclass_root));
+       ut_assert(uts->root);
+       ut_asserteq(1, list_count_items(gd->uclass_root));
        ut_asserteq(0, list_count_items(&gd->dm_root->child_head));
        ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]);
 
-       ut_assertok(dm_scan_platdata(false));
+       ut_assertok(dm_scan_plat(false));
 
        /* We should have our test class now at least, plus more children */
-       ut_assert(1 < list_count_items(&gd->uclass_root));
+       ut_assert(1 < list_count_items(gd->uclass_root));
        ut_assert(0 < list_count_items(&gd->dm_root->child_head));
 
        /* Our 3 dm_test_infox children should be bound to the test uclass */
@@ -131,7 +139,7 @@ static int dm_test_autobind(struct unit_test_state *uts)
 
        /* No devices should be probed */
        list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node)
-               ut_assert(!(dev->flags & DM_FLAG_ACTIVATED));
+               ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
 
        /* Our test driver should have been bound 3 times */
        ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3);
@@ -140,7 +148,7 @@ static int dm_test_autobind(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_autobind, 0);
 
-/* Test that binding with uclass platdata allocation occurs correctly */
+/* Test that binding with uclass plat allocation occurs correctly */
 static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
 {
        struct dm_test_perdev_uc_pdata *uc_pdata;
@@ -152,16 +160,16 @@ static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
 
        /**
         * Test if test uclass driver requires allocation for the uclass
-        * platform data and then check the dev->uclass_platdata pointer.
+        * platform data and then check the dev->uclass_plat pointer.
         */
-       ut_assert(uc->uc_drv->per_device_platdata_auto_alloc_size);
+       ut_assert(uc->uc_drv->per_device_plat_auto);
 
        for (uclass_find_first_device(UCLASS_TEST, &dev);
             dev;
             uclass_find_next_device(&dev)) {
                ut_assertnonnull(dev);
 
-               uc_pdata = dev_get_uclass_platdata(dev);
+               uc_pdata = dev_get_uclass_plat(dev);
                ut_assert(uc_pdata);
        }
 
@@ -169,7 +177,21 @@ static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_autobind_uclass_pdata_alloc, UT_TESTF_SCAN_PDATA);
 
-/* Test that binding with uclass platdata setting occurs correctly */
+/* compare node names ignoring the unit address */
+static int dm_test_compare_node_name(struct unit_test_state *uts)
+{
+       ofnode node;
+
+       node = ofnode_path("/mmio-bus@0");
+       ut_assert(ofnode_valid(node));
+       ut_assert(ofnode_name_eq(node, "mmio-bus"));
+
+       return 0;
+}
+
+DM_TEST(dm_test_compare_node_name, UT_TESTF_SCAN_PDATA);
+
+/* Test that binding with uclass plat setting occurs correctly */
 static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
 {
        struct dm_test_perdev_uc_pdata *uc_pdata;
@@ -184,7 +206,7 @@ static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts)
             uclass_find_next_device(&dev)) {
                ut_assertnonnull(dev);
 
-               uc_pdata = dev_get_uclass_platdata(dev);
+               uc_pdata = dev_get_uclass_plat(dev);
                ut_assert(uc_pdata);
                ut_assert(uc_pdata->intval1 == TEST_UC_PDATA_INTVAL1);
                ut_assert(uc_pdata->intval2 == TEST_UC_PDATA_INTVAL2);
@@ -198,7 +220,6 @@ DM_TEST(dm_test_autobind_uclass_pdata_valid, UT_TESTF_SCAN_PDATA);
 /* Test that autoprobe finds all the expected devices */
 static int dm_test_autoprobe(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        int expected_base_add;
        struct udevice *dev;
        struct uclass *uc;
@@ -212,7 +233,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
        ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]);
 
        /* The root device should not be activated until needed */
-       ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
+       ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
 
        /*
         * We should be able to find the three test devices, and they should
@@ -222,17 +243,17 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
        for (i = 0; i < 3; i++) {
                ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
                ut_assert(dev);
-               ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
+               ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
                           "Driver %d/%s already activated", i, dev->name);
 
                /* This should activate it */
                ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev));
                ut_assert(dev);
-               ut_assert(dev->flags & DM_FLAG_ACTIVATED);
+               ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
 
                /* Activating a device should activate the root device */
                if (!i)
-                       ut_assert(dms->root->flags & DM_FLAG_ACTIVATED);
+                       ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
        }
 
        /*
@@ -255,7 +276,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
                ut_assert(priv);
                ut_asserteq(expected_base_add, priv->base_add);
 
-               pdata = dev->platdata;
+               pdata = dev_get_plat(dev);
                expected_base_add += pdata->ping_add;
        }
 
@@ -263,8 +284,8 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_autoprobe, UT_TESTF_SCAN_PDATA);
 
-/* Check that we see the correct platdata in each device */
-static int dm_test_platdata(struct unit_test_state *uts)
+/* Check that we see the correct plat in each device */
+static int dm_test_plat(struct unit_test_state *uts)
 {
        const struct dm_test_pdata *pdata;
        struct udevice *dev;
@@ -273,46 +294,54 @@ static int dm_test_platdata(struct unit_test_state *uts)
        for (i = 0; i < 3; i++) {
                ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
                ut_assert(dev);
-               pdata = dev->platdata;
+               pdata = dev_get_plat(dev);
                ut_assert(pdata->ping_add == test_pdata[i].ping_add);
        }
 
        return 0;
 }
-DM_TEST(dm_test_platdata, UT_TESTF_SCAN_PDATA);
+DM_TEST(dm_test_plat, UT_TESTF_SCAN_PDATA);
 
 /* Test that we can bind, probe, remove, unbind a driver */
 static int dm_test_lifecycle(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        int op_count[DM_TEST_OP_COUNT];
        struct udevice *dev, *test_dev;
+       int start_dev_count, start_uc_count;
+       int dev_count, uc_count;
        int pingret;
        int ret;
 
        memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
 
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+       dm_get_stats(&start_dev_count, &start_uc_count);
+
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
                                        &dev));
        ut_assert(dev);
        ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
                        == op_count[DM_TEST_OP_BIND] + 1);
-       ut_assert(!dev->priv);
+       ut_assert(!dev_get_priv(dev));
+
+       /* We should have one more device */
+       dm_get_stats(&dev_count, &uc_count);
+       ut_asserteq(start_dev_count + 1, dev_count);
+       ut_asserteq(start_uc_count, uc_count);
 
        /* Probe the device - it should fail allocating private data */
-       dms->force_fail_alloc = 1;
+       uts->force_fail_alloc = 1;
        ret = device_probe(dev);
        ut_assert(ret == -ENOMEM);
        ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
                        == op_count[DM_TEST_OP_PROBE] + 1);
-       ut_assert(!dev->priv);
+       ut_assert(!dev_get_priv(dev));
 
        /* Try again without the alloc failure */
-       dms->force_fail_alloc = 0;
+       uts->force_fail_alloc = 0;
        ut_assertok(device_probe(dev));
        ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE]
                        == op_count[DM_TEST_OP_PROBE] + 2);
-       ut_assert(dev->priv);
+       ut_assert(dev_get_priv(dev));
 
        /* This should be device 3 in the uclass */
        ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev));
@@ -333,6 +362,11 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
        ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_UNBIND]);
        ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_PRE_UNBIND]);
 
+       /* We should have one less device */
+       dm_get_stats(&dev_count, &uc_count);
+       ut_asserteq(start_dev_count, dev_count);
+       ut_asserteq(start_uc_count, uc_count);
+
        return 0;
 }
 DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
@@ -340,19 +374,18 @@ DM_TEST(dm_test_lifecycle, UT_TESTF_SCAN_PDATA | UT_TESTF_PROBE_TEST);
 /* Test that we can bind/unbind and the lists update correctly */
 static int dm_test_ordering(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *dev, *dev_penultimate, *dev_last, *test_dev;
        int pingret;
 
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
                                        &dev));
        ut_assert(dev);
 
        /* Bind two new devices (numbers 4 and 5) */
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
                                        &dev_penultimate));
        ut_assert(dev_penultimate);
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
                                        &dev_last));
        ut_assert(dev_last);
 
@@ -367,7 +400,7 @@ static int dm_test_ordering(struct unit_test_state *uts)
        ut_assert(dev_last == test_dev);
 
        /* Add back the original device 3, now in position 5 */
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
                                        &dev));
        ut_assert(dev);
 
@@ -400,10 +433,10 @@ int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
        int expected;
        int pingret;
 
-       /* Getting the child device should allocate platdata / priv */
+       /* Getting the child device should allocate plat / priv */
        ut_assertok(testfdt_ping(dev, 10, &pingret));
-       ut_assert(dev->priv);
-       ut_assert(dev->platdata);
+       ut_assert(dev_get_priv(dev));
+       ut_assert(dev_get_plat(dev));
 
        expected = 10 + base;
        ut_asserteq(expected, pingret);
@@ -414,7 +447,7 @@ int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
        ut_asserteq(expected, pingret);
 
        /* Now check the ping_total */
-       priv = dev->priv;
+       priv = dev_get_priv(dev);
        ut_asserteq(DM_TEST_START_TOTAL + 10 + 20 + base * 2,
                    priv->ping_total);
 
@@ -438,13 +471,13 @@ static int dm_test_operations(struct unit_test_state *uts)
 
                /*
                 * Get the 'reg' property, which tells us what the ping add
-                * should be. We don't use the platdata because we want
+                * should be. We don't use the plat because we want
                 * to test the code that sets that up (testfdt_drv_probe()).
                 */
                base = test_pdata[i].ping_add;
                debug("dev=%d, base=%d\n", i, base);
 
-               ut_assert(!dm_check_operations(uts, dev, base, dev->priv));
+               ut_assert(!dm_check_operations(uts, dev, base, dev_get_priv(dev)));
        }
 
        return 0;
@@ -460,13 +493,13 @@ static int dm_test_remove(struct unit_test_state *uts)
        for (i = 0; i < 3; i++) {
                ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev));
                ut_assert(dev);
-               ut_assertf(dev->flags & DM_FLAG_ACTIVATED,
+               ut_assertf(dev_get_flags(dev) & DM_FLAG_ACTIVATED,
                           "Driver %d/%s not activated", i, dev->name);
                ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
-               ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED),
+               ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED),
                           "Driver %d/%s should have deactivated", i,
                           dev->name);
-               ut_assert(!dev->priv);
+               ut_assert(!dev_get_priv(dev));
        }
 
        return 0;
@@ -479,23 +512,15 @@ static int dm_test_leak(struct unit_test_state *uts)
        int i;
 
        for (i = 0; i < 2; i++) {
-               struct udevice *dev;
                int ret;
-               int id;
 
                dm_leak_check_start(uts);
 
-               ut_assertok(dm_scan_platdata(false));
-               ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
+               ut_assertok(dm_scan_plat(false));
+               ut_assertok(dm_scan_fdt(false));
 
-               /* Scanning the uclass is enough to probe all the devices */
-               for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
-                       for (ret = uclass_first_device(UCLASS_TEST, &dev);
-                            dev;
-                            ret = uclass_next_device(&dev))
-                               ;
-                       ut_assertok(ret);
-               }
+               ret = uclass_probe_all(UCLASS_TEST);
+               ut_assertok(ret);
 
                ut_assertok(dm_leak_check_end(uts));
        }
@@ -507,17 +532,31 @@ DM_TEST(dm_test_leak, 0);
 /* Test uclass init/destroy methods */
 static int dm_test_uclass(struct unit_test_state *uts)
 {
+       int dev_count, uc_count;
        struct uclass *uc;
 
+       /* We should have just the root device and uclass */
+       dm_get_stats(&dev_count, &uc_count);
+       ut_asserteq(1, dev_count);
+       ut_asserteq(1, uc_count);
+
        ut_assertok(uclass_get(UCLASS_TEST, &uc));
        ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
        ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
-       ut_assert(uc->priv);
+       ut_assert(uclass_get_priv(uc));
+
+       dm_get_stats(&dev_count, &uc_count);
+       ut_asserteq(1, dev_count);
+       ut_asserteq(2, uc_count);
 
        ut_assertok(uclass_destroy(uc));
        ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]);
        ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_DESTROY]);
 
+       dm_get_stats(&dev_count, &uc_count);
+       ut_asserteq(1, dev_count);
+       ut_asserteq(1, uc_count);
+
        return 0;
 }
 DM_TEST(dm_test_uclass, 0);
@@ -532,7 +571,7 @@ DM_TEST(dm_test_uclass, 0);
  *             receive an incrementing value
  * @child:     If not NULL, then the child device pointers are written into
  *             this array.
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, -ve on error
  */
 static int create_children(struct unit_test_state *uts, struct udevice *parent,
                           int count, int key, struct udevice *child[])
@@ -547,7 +586,7 @@ static int create_children(struct unit_test_state *uts, struct udevice *parent,
                                                &driver_info_manual, &dev));
                pdata = calloc(1, sizeof(*pdata));
                pdata->ping_add = key + i;
-               dev->platdata = pdata;
+               dev_set_plat(dev, pdata);
                if (child)
                        child[i] = dev;
        }
@@ -559,7 +598,6 @@ static int create_children(struct unit_test_state *uts, struct udevice *parent,
 
 static int dm_test_children(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *top[NODE_COUNT];
        struct udevice *child[NODE_COUNT];
        struct udevice *grandchild[NODE_COUNT];
@@ -569,12 +607,12 @@ static int dm_test_children(struct unit_test_state *uts)
        int i;
 
        /* We don't care about the numbering for this test */
-       dms->skip_post_probe = 1;
+       uts->skip_post_probe = 1;
 
        ut_assert(NODE_COUNT > 5);
 
        /* First create 10 top-level children */
-       ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
+       ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top));
 
        /* Now a few have their own children */
        ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
@@ -607,10 +645,7 @@ static int dm_test_children(struct unit_test_state *uts)
        ut_asserteq(2 + NODE_COUNT, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
 
        /* Probe everything */
-       for (ret = uclass_first_device(UCLASS_TEST, &dev);
-            dev;
-            ret = uclass_next_device(&dev))
-               ;
+       ret = uclass_probe_all(UCLASS_TEST);
        ut_assertok(ret);
 
        ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
@@ -645,7 +680,6 @@ DM_TEST(dm_test_children, 0);
 
 static int dm_test_device_reparent(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *top[NODE_COUNT];
        struct udevice *child[NODE_COUNT];
        struct udevice *grandchild[NODE_COUNT];
@@ -655,12 +689,12 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
        int i;
 
        /* We don't care about the numbering for this test */
-       dms->skip_post_probe = 1;
+       uts->skip_post_probe = 1;
 
        ut_assert(NODE_COUNT > 5);
 
        /* First create 10 top-level children */
-       ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
+       ut_assertok(create_children(uts, uts->root, NODE_COUNT, 0, top));
 
        /* Now a few have their own children */
        ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL));
@@ -806,15 +840,14 @@ DM_TEST(dm_test_device_reparent, 0);
 /* Test that pre-relocation devices work as expected */
 static int dm_test_pre_reloc(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *dev;
 
        /* The normal driver should refuse to bind before relocation */
-       ut_asserteq(-EPERM, device_bind_by_name(dms->root, true,
+       ut_asserteq(-EPERM, device_bind_by_name(uts->root, true,
                                                &driver_info_manual, &dev));
 
        /* But this one is marked pre-reloc */
-       ut_assertok(device_bind_by_name(dms->root, true,
+       ut_assertok(device_bind_by_name(uts->root, true,
                                        &driver_info_pre_reloc, &dev));
 
        return 0;
@@ -827,10 +860,9 @@ DM_TEST(dm_test_pre_reloc, 0);
  */
 static int dm_test_remove_active_dma(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *dev;
 
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_act_dma,
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma,
                                        &dev));
        ut_assert(dev);
 
@@ -863,7 +895,7 @@ static int dm_test_remove_active_dma(struct unit_test_state *uts)
         * the active DMA remove call
         */
        ut_assertok(device_unbind(dev));
-       ut_assertok(device_bind_by_name(dms->root, false, &driver_info_manual,
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
                                        &dev));
        ut_assert(dev);
 
@@ -883,6 +915,91 @@ static int dm_test_remove_active_dma(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_remove_active_dma, 0);
 
+/* Test removal of 'vital' devices */
+static int dm_test_remove_vital(struct unit_test_state *uts)
+{
+       struct udevice *normal, *dma, *vital, *dma_vital;
+
+       /* Skip the behaviour in test_post_probe() */
+       uts->skip_post_probe = 1;
+
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_manual,
+                                       &normal));
+       ut_assertnonnull(normal);
+
+       ut_assertok(device_bind_by_name(uts->root, false, &driver_info_act_dma,
+                                       &dma));
+       ut_assertnonnull(dma);
+
+       ut_assertok(device_bind_by_name(uts->root, false,
+                                       &driver_info_vital_clk, &vital));
+       ut_assertnonnull(vital);
+
+       ut_assertok(device_bind_by_name(uts->root, false,
+                                       &driver_info_act_dma_vital_clk,
+                                       &dma_vital));
+       ut_assertnonnull(dma_vital);
+
+       /* Probe the devices */
+       ut_assertok(device_probe(normal));
+       ut_assertok(device_probe(dma));
+       ut_assertok(device_probe(vital));
+       ut_assertok(device_probe(dma_vital));
+
+       /* Check that devices are active right now */
+       ut_asserteq(true, device_active(normal));
+       ut_asserteq(true, device_active(dma));
+       ut_asserteq(true, device_active(vital));
+       ut_asserteq(true, device_active(dma_vital));
+
+       /* Remove active devices via selective remove flag */
+       dm_remove_devices_flags(DM_REMOVE_NON_VITAL | DM_REMOVE_ACTIVE_ALL);
+
+       /*
+        * Check that this only has an effect on the dma device, since two
+        * devices are vital and the third does not have active DMA
+        */
+       ut_asserteq(true, device_active(normal));
+       ut_asserteq(false, device_active(dma));
+       ut_asserteq(true, device_active(vital));
+       ut_asserteq(true, device_active(dma_vital));
+
+       /* Remove active devices via selective remove flag */
+       ut_assertok(device_probe(dma));
+       dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
+
+       /* This should have affected both active-dma devices */
+       ut_asserteq(true, device_active(normal));
+       ut_asserteq(false, device_active(dma));
+       ut_asserteq(true, device_active(vital));
+       ut_asserteq(false, device_active(dma_vital));
+
+       /* Remove non-vital devices */
+       ut_assertok(device_probe(dma));
+       ut_assertok(device_probe(dma_vital));
+       dm_remove_devices_flags(DM_REMOVE_NON_VITAL);
+
+       /* This should have affected only non-vital devices */
+       ut_asserteq(false, device_active(normal));
+       ut_asserteq(false, device_active(dma));
+       ut_asserteq(true, device_active(vital));
+       ut_asserteq(true, device_active(dma_vital));
+
+       /* Remove vital devices via normal remove flag */
+       ut_assertok(device_probe(normal));
+       ut_assertok(device_probe(dma));
+       dm_remove_devices_flags(DM_REMOVE_NORMAL);
+
+       /* Check that all devices are inactive right now */
+       ut_asserteq(false, device_active(normal));
+       ut_asserteq(false, device_active(dma));
+       ut_asserteq(false, device_active(vital));
+       ut_asserteq(false, device_active(dma_vital));
+
+       return 0;
+}
+DM_TEST(dm_test_remove_vital, 0);
+
 static int dm_test_uclass_before_ready(struct unit_test_state *uts)
 {
        struct uclass *uc;
@@ -894,6 +1011,7 @@ static int dm_test_uclass_before_ready(struct unit_test_state *uts)
        memset(&gd->uclass_root, '\0', sizeof(gd->uclass_root));
 
        ut_asserteq_ptr(NULL, uclass_find(UCLASS_TEST));
+       ut_asserteq(-EDEADLK, uclass_get(UCLASS_TEST, &uc));
 
        return 0;
 }
@@ -960,11 +1078,10 @@ static int dm_test_uclass_devices_get(struct unit_test_state *uts)
        struct udevice *dev;
        int ret;
 
-       for (ret = uclass_first_device(UCLASS_TEST, &dev);
+       for (ret = uclass_first_device_check(UCLASS_TEST, &dev);
             dev;
-            ret = uclass_next_device(&dev)) {
+            ret = uclass_next_device_check(&dev)) {
                ut_assert(!ret);
-               ut_assert(dev);
                ut_assert(device_active(dev));
        }
 
@@ -994,11 +1111,10 @@ static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts)
         * this will fail on checking condition: testdev == finddev, since the
         * uclass_get_device_by_name(), returns the first device by given name.
        */
-       for (ret = uclass_first_device(UCLASS_TEST_FDT, &testdev);
+       for (ret = uclass_first_device_check(UCLASS_TEST_FDT, &testdev);
             testdev;
-            ret = uclass_next_device(&testdev)) {
+            ret = uclass_next_device_check(&testdev)) {
                ut_assertok(ret);
-               ut_assert(testdev);
                ut_assert(device_active(testdev));
 
                findret = uclass_get_device_by_name(UCLASS_TEST_FDT,
@@ -1032,17 +1148,18 @@ static int dm_test_uclass_names(struct unit_test_state *uts)
        ut_asserteq_str("test", uclass_get_name(UCLASS_TEST));
        ut_asserteq(UCLASS_TEST, uclass_get_by_name("test"));
 
+       ut_asserteq(UCLASS_SPI, uclass_get_by_name("spi"));
+
        return 0;
 }
 DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA);
 
 static int dm_test_inactive_child(struct unit_test_state *uts)
 {
-       struct dm_test_state *dms = uts->priv;
        struct udevice *parent, *dev1, *dev2;
 
        /* Skip the behaviour in test_post_probe() */
-       dms->skip_post_probe = 1;
+       uts->skip_post_probe = 1;
 
        ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent));
 
@@ -1052,8 +1169,8 @@ static int dm_test_inactive_child(struct unit_test_state *uts)
         */
        ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
                                                        UCLASS_TEST, &dev1));
-       ut_assertok(device_bind_ofnode(parent, DM_GET_DRIVER(test_drv),
-                                      "test_child", 0, ofnode_null(), &dev1));
+       ut_assertok(device_bind(parent, DM_DRIVER_GET(test_drv),
+                               "test_child", 0, ofnode_null(), &dev1));
 
        ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST,
                                                     &dev2));
@@ -1066,3 +1183,173 @@ static int dm_test_inactive_child(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_inactive_child, UT_TESTF_SCAN_PDATA);
+
+/* Make sure all bound devices have a sequence number */
+static int dm_test_all_have_seq(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       struct uclass *uc;
+
+       list_for_each_entry(uc, gd->uclass_root, sibling_node) {
+               list_for_each_entry(dev, &uc->dev_head, uclass_node) {
+                       if (dev->seq_ == -1)
+                               printf("Device '%s' has no seq (%d)\n",
+                                      dev->name, dev->seq_);
+                       ut_assert(dev->seq_ != -1);
+               }
+       }
+
+       return 0;
+}
+DM_TEST(dm_test_all_have_seq, UT_TESTF_SCAN_PDATA);
+
+#if CONFIG_IS_ENABLED(DM_DMA)
+static int dm_test_dma_offset(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+       ofnode node;
+
+       /* Make sure the bus's dma-ranges aren't taken into account here */
+       node = ofnode_path("/mmio-bus@0");
+       ut_assert(ofnode_valid(node));
+       ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
+       ut_asserteq_64(0, dev->dma_offset);
+
+       /* Device behind a bus with dma-ranges */
+       node = ofnode_path("/mmio-bus@0/subnode@0");
+       ut_assert(ofnode_valid(node));
+       ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
+       ut_asserteq_64(-0x10000000ULL, dev->dma_offset);
+
+       /* This one has no dma-ranges */
+       node = ofnode_path("/mmio-bus@1");
+       ut_assert(ofnode_valid(node));
+       ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
+       node = ofnode_path("/mmio-bus@1/subnode@0");
+       ut_assert(ofnode_valid(node));
+       ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
+       ut_asserteq_64(0, dev->dma_offset);
+
+       return 0;
+}
+DM_TEST(dm_test_dma_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+#endif
+
+/* Test dm_get_stats() */
+static int dm_test_get_stats(struct unit_test_state *uts)
+{
+       int dev_count, uc_count;
+
+       dm_get_stats(&dev_count, &uc_count);
+       ut_assert(dev_count > 50);
+       ut_assert(uc_count > 30);
+
+       return 0;
+}
+DM_TEST(dm_test_get_stats, UT_TESTF_SCAN_FDT);
+
+/* Test uclass_find_device_by_name() */
+static int dm_test_uclass_find_device(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(uclass_find_device_by_name(UCLASS_I2C, "i2c@0", &dev));
+       ut_asserteq(-ENODEV,
+                   uclass_find_device_by_name(UCLASS_I2C, "i2c@0x", &dev));
+       ut_assertok(uclass_find_device_by_namelen(UCLASS_I2C, "i2c@0x", 5,
+                                                 &dev));
+
+       return 0;
+}
+DM_TEST(dm_test_uclass_find_device, UT_TESTF_SCAN_FDT);
+
+/* Test getting information about tags attached to devices */
+static int dm_test_dev_get_attach(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev));
+       ut_asserteq_str("a-test", dev->name);
+
+       ut_assertnonnull(dev_get_attach_ptr(dev, DM_TAG_PLAT));
+       ut_assertnonnull(dev_get_attach_ptr(dev, DM_TAG_PRIV));
+       ut_assertnull(dev_get_attach_ptr(dev, DM_TAG_UC_PRIV));
+       ut_assertnull(dev_get_attach_ptr(dev, DM_TAG_UC_PLAT));
+       ut_assertnull(dev_get_attach_ptr(dev, DM_TAG_PARENT_PLAT));
+       ut_assertnull(dev_get_attach_ptr(dev, DM_TAG_PARENT_PRIV));
+
+       ut_asserteq(sizeof(struct dm_test_pdata),
+                   dev_get_attach_size(dev, DM_TAG_PLAT));
+       ut_asserteq(sizeof(struct dm_test_priv),
+                   dev_get_attach_size(dev, DM_TAG_PRIV));
+       ut_asserteq(0, dev_get_attach_size(dev, DM_TAG_UC_PRIV));
+       ut_asserteq(0, dev_get_attach_size(dev, DM_TAG_UC_PLAT));
+       ut_asserteq(0, dev_get_attach_size(dev, DM_TAG_PARENT_PLAT));
+       ut_asserteq(0, dev_get_attach_size(dev, DM_TAG_PARENT_PRIV));
+
+       return 0;
+}
+DM_TEST(dm_test_dev_get_attach, UT_TESTF_SCAN_FDT);
+
+/* Test getting information about tags attached to bus devices */
+static int dm_test_dev_get_attach_bus(struct unit_test_state *uts)
+{
+       struct udevice *dev, *child;
+
+       ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &dev));
+       ut_asserteq_str("some-bus", dev->name);
+
+       ut_assertnonnull(dev_get_attach_ptr(dev, DM_TAG_PLAT));
+       ut_assertnonnull(dev_get_attach_ptr(dev, DM_TAG_PRIV));
+       ut_assertnonnull(dev_get_attach_ptr(dev, DM_TAG_UC_PRIV));
+       ut_assertnonnull(dev_get_attach_ptr(dev, DM_TAG_UC_PLAT));
+       ut_assertnull(dev_get_attach_ptr(dev, DM_TAG_PARENT_PLAT));
+       ut_assertnull(dev_get_attach_ptr(dev, DM_TAG_PARENT_PRIV));
+
+       ut_asserteq(sizeof(struct dm_test_pdata),
+                   dev_get_attach_size(dev, DM_TAG_PLAT));
+       ut_asserteq(sizeof(struct dm_test_priv),
+                   dev_get_attach_size(dev, DM_TAG_PRIV));
+       ut_asserteq(sizeof(struct dm_test_uclass_priv),
+                   dev_get_attach_size(dev, DM_TAG_UC_PRIV));
+       ut_asserteq(sizeof(struct dm_test_uclass_plat),
+                   dev_get_attach_size(dev, DM_TAG_UC_PLAT));
+       ut_asserteq(0, dev_get_attach_size(dev, DM_TAG_PARENT_PLAT));
+       ut_asserteq(0, dev_get_attach_size(dev, DM_TAG_PARENT_PRIV));
+
+       /* Now try the child of the bus */
+       ut_assertok(device_first_child_err(dev, &child));
+       ut_asserteq_str("c-test@5", child->name);
+
+       ut_assertnonnull(dev_get_attach_ptr(child, DM_TAG_PLAT));
+       ut_assertnonnull(dev_get_attach_ptr(child, DM_TAG_PRIV));
+       ut_assertnull(dev_get_attach_ptr(child, DM_TAG_UC_PRIV));
+       ut_assertnull(dev_get_attach_ptr(child, DM_TAG_UC_PLAT));
+       ut_assertnonnull(dev_get_attach_ptr(child, DM_TAG_PARENT_PLAT));
+       ut_assertnonnull(dev_get_attach_ptr(child, DM_TAG_PARENT_PRIV));
+
+       ut_asserteq(sizeof(struct dm_test_pdata),
+                   dev_get_attach_size(child, DM_TAG_PLAT));
+       ut_asserteq(sizeof(struct dm_test_priv),
+                   dev_get_attach_size(child, DM_TAG_PRIV));
+       ut_asserteq(0, dev_get_attach_size(child, DM_TAG_UC_PRIV));
+       ut_asserteq(0, dev_get_attach_size(child, DM_TAG_UC_PLAT));
+       ut_asserteq(sizeof(struct dm_test_parent_plat),
+                   dev_get_attach_size(child, DM_TAG_PARENT_PLAT));
+       ut_asserteq(sizeof(struct dm_test_parent_data),
+                   dev_get_attach_size(child, DM_TAG_PARENT_PRIV));
+
+       return 0;
+}
+DM_TEST(dm_test_dev_get_attach_bus, UT_TESTF_SCAN_FDT);
+
+/* Test getting information about tags attached to bus devices */
+static int dm_test_dev_get_mem(struct unit_test_state *uts)
+{
+       struct dm_stats stats;
+
+       dm_get_mem(&stats);
+
+       return 0;
+}
+DM_TEST(dm_test_dev_get_mem, UT_TESTF_SCAN_FDT);
This page took 0.057315 seconds and 4 git commands to generate.