]> Git Repo - u-boot.git/blobdiff - test/dm/core.c
test: Add DM_DMA to be disabled
[u-boot.git] / test / dm / core.c
index 1f5ca570dc7a9f511680c466ae0055d55970188e..0492698997c19721a92e1c236db86e2dfe9ce751 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>
@@ -72,6 +73,14 @@ 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();
@@ -108,14 +117,13 @@ int dm_leak_check_end(struct unit_test_state *uts)
 /* 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_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]);
@@ -198,7 +206,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 +219,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(dev_get_flags(dms->root) & 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
@@ -232,7 +239,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts)
 
                /* Activating a device should activate the root device */
                if (!i)
-                       ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED);
+                       ut_assert(dev_get_flags(uts->root) & DM_FLAG_ACTIVATED);
        }
 
        /*
@@ -284,7 +291,6 @@ 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 pingret;
@@ -292,7 +298,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
 
        memcpy(op_count, dm_testdrv_op_count, sizeof(op_count));
 
-       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);
        ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND]
@@ -300,7 +306,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
        ut_assert(!dev_get_priv(dev));
 
        /* 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]
@@ -308,7 +314,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts)
        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);
@@ -340,19 +346,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 +372,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);
 
@@ -559,7 +564,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 +573,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));
@@ -645,7 +649,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 +658,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 +809,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 +829,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 +864,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 +884,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;
@@ -1038,11 +1124,10 @@ 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));
 
@@ -1085,3 +1170,35 @@ static int dm_test_all_have_seq(struct unit_test_state *uts)
        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
This page took 0.039911 seconds and 4 git commands to generate.