2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-07-23 20:55:18 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-10-02 11:12:32 +08:00
|
|
|
#ifdef CONFIG_SANDBOX
|
2020-05-11 01:40:05 +08:00
|
|
|
#include <log.h>
|
2018-10-02 11:12:32 +08:00
|
|
|
#include <os.h>
|
|
|
|
#endif
|
2014-07-23 20:55:18 +08:00
|
|
|
#include <dm.h>
|
2020-10-31 11:38:53 +08:00
|
|
|
#include <asm/global_data.h>
|
2019-09-04 18:31:26 +08:00
|
|
|
#include <dm/device.h>
|
2014-07-23 20:55:20 +08:00
|
|
|
#include <dm/device-internal.h>
|
2014-07-23 20:55:18 +08:00
|
|
|
#include <dm/test.h>
|
2015-01-25 23:27:01 +08:00
|
|
|
#include <dm/uclass-internal.h>
|
2014-07-23 20:55:18 +08:00
|
|
|
#include <dm/util.h>
|
2020-07-20 00:15:37 +08:00
|
|
|
#include <test/test.h>
|
2015-05-21 03:27:27 +08:00
|
|
|
#include <test/ut.h>
|
2014-07-23 20:55:18 +08:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/* Test that we can probe for children */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_children(struct unit_test_state *uts)
|
2014-07-23 20:55:18 +08:00
|
|
|
{
|
2020-09-11 16:13:35 +08:00
|
|
|
int num_devices = 9;
|
2014-07-23 20:55:18 +08:00
|
|
|
struct udevice *bus;
|
|
|
|
struct uclass *uc;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
|
|
|
|
ut_asserteq(num_devices, list_count_items(&uc->dev_head));
|
|
|
|
|
|
|
|
/* Probe the bus, which should yield 3 more devices */
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
num_devices += 3;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
|
|
|
|
ut_asserteq(num_devices, list_count_items(&uc->dev_head));
|
|
|
|
|
2015-05-21 03:27:27 +08:00
|
|
|
ut_assert(!dm_check_devices(uts, num_devices));
|
2014-07-23 20:55:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_bus_children, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-07-23 20:55:19 +08:00
|
|
|
|
|
|
|
/* Test our functions for accessing children */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_children_funcs(struct unit_test_state *uts)
|
2014-07-23 20:55:19 +08:00
|
|
|
{
|
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
|
|
|
|
/* device_get_child() */
|
|
|
|
ut_assertok(device_get_child(bus, 0, &dev));
|
|
|
|
ut_asserteq(-ENODEV, device_get_child(bus, 4, &dev));
|
|
|
|
ut_assertok(device_get_child_by_seq(bus, 5, &dev));
|
2020-12-20 01:40:10 +08:00
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
2014-07-23 20:55:19 +08:00
|
|
|
ut_asserteq_str("c-test@5", dev->name);
|
|
|
|
|
|
|
|
/* Device with sequence number 0 should be accessible */
|
2020-12-17 12:20:29 +08:00
|
|
|
ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, &dev));
|
|
|
|
ut_assertok(device_find_child_by_seq(bus, 0, &dev));
|
2020-12-20 01:40:10 +08:00
|
|
|
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
2020-12-17 12:20:29 +08:00
|
|
|
ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev));
|
2014-07-23 20:55:19 +08:00
|
|
|
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
|
2020-12-20 01:40:10 +08:00
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
2020-12-17 12:20:29 +08:00
|
|
|
ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev));
|
2014-07-23 20:55:19 +08:00
|
|
|
|
|
|
|
/* There is no device with sequence number 2 */
|
2020-12-17 12:20:29 +08:00
|
|
|
ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, &dev));
|
|
|
|
ut_asserteq(-ENODEV, device_find_child_by_seq(bus, 2, &dev));
|
2014-07-23 20:55:19 +08:00
|
|
|
ut_asserteq(-ENODEV, device_get_child_by_seq(bus, 2, &dev));
|
|
|
|
|
|
|
|
/* Looking for something that is not a child */
|
|
|
|
node = fdt_path_offset(blob, "/junk");
|
|
|
|
ut_asserteq(-ENODEV, device_find_child_by_of_offset(bus, node, &dev));
|
|
|
|
node = fdt_path_offset(blob, "/d-test");
|
|
|
|
ut_asserteq(-ENODEV, device_find_child_by_of_offset(bus, node, &dev));
|
|
|
|
|
2017-05-19 10:09:43 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_bus_children_funcs, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2017-05-19 10:09:43 +08:00
|
|
|
|
|
|
|
static int dm_test_bus_children_of_offset(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
const void *blob = gd->fdt_blob;
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
int node;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
2017-06-08 00:28:44 +08:00
|
|
|
ut_assertnonnull(bus);
|
2017-05-19 10:09:43 +08:00
|
|
|
|
2014-07-23 20:55:19 +08:00
|
|
|
/* Find a valid child */
|
|
|
|
node = fdt_path_offset(blob, "/some-bus/c-test@1");
|
2017-05-19 10:09:43 +08:00
|
|
|
ut_assert(node > 0);
|
2014-07-23 20:55:19 +08:00
|
|
|
ut_assertok(device_find_child_by_of_offset(bus, node, &dev));
|
2017-06-08 00:28:44 +08:00
|
|
|
ut_assertnonnull(dev);
|
2020-12-20 01:40:10 +08:00
|
|
|
ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED));
|
2014-07-23 20:55:19 +08:00
|
|
|
ut_assertok(device_get_child_by_of_offset(bus, node, &dev));
|
2017-06-08 00:28:44 +08:00
|
|
|
ut_assertnonnull(dev);
|
2020-12-20 01:40:10 +08:00
|
|
|
ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED);
|
2014-07-23 20:55:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-19 10:09:43 +08:00
|
|
|
DM_TEST(dm_test_bus_children_of_offset,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_FLAT_TREE);
|
2014-07-23 20:55:20 +08:00
|
|
|
|
2014-10-14 13:41:49 +08:00
|
|
|
/* Test that we can iterate through children */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_children_iterators(struct unit_test_state *uts)
|
2014-10-14 13:41:49 +08:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev, *child;
|
|
|
|
|
|
|
|
/* Walk through the children one by one */
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
ut_assertok(device_find_first_child(bus, &dev));
|
|
|
|
ut_asserteq_str("c-test@5", dev->name);
|
|
|
|
ut_assertok(device_find_next_child(&dev));
|
|
|
|
ut_asserteq_str("c-test@0", dev->name);
|
|
|
|
ut_assertok(device_find_next_child(&dev));
|
|
|
|
ut_asserteq_str("c-test@1", dev->name);
|
|
|
|
ut_assertok(device_find_next_child(&dev));
|
|
|
|
ut_asserteq_ptr(dev, NULL);
|
|
|
|
|
|
|
|
/* Move to the next child without using device_find_first_child() */
|
2020-12-17 12:20:29 +08:00
|
|
|
ut_assertok(device_find_child_by_seq(bus, 5, &dev));
|
2014-10-14 13:41:49 +08:00
|
|
|
ut_asserteq_str("c-test@5", dev->name);
|
|
|
|
ut_assertok(device_find_next_child(&dev));
|
|
|
|
ut_asserteq_str("c-test@0", dev->name);
|
|
|
|
|
|
|
|
/* Try a device with no children */
|
|
|
|
ut_assertok(device_find_first_child(dev, &child));
|
|
|
|
ut_asserteq_ptr(child, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_bus_children_iterators,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-10-14 13:41:49 +08:00
|
|
|
|
2014-07-23 20:55:20 +08:00
|
|
|
/* Test that the bus can store data about each child */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int test_bus_parent_data(struct unit_test_state *uts)
|
2014-07-23 20:55:20 +08:00
|
|
|
{
|
|
|
|
struct dm_test_parent_data *parent_data;
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
struct uclass *uc;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
|
|
|
|
/* Check that parent data is allocated */
|
2020-12-17 12:20:29 +08:00
|
|
|
ut_assertok(device_find_child_by_seq(bus, 0, &dev));
|
2015-09-29 13:32:01 +08:00
|
|
|
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
|
2014-07-23 20:55:20 +08:00
|
|
|
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
|
2015-09-29 13:32:01 +08:00
|
|
|
parent_data = dev_get_parent_priv(dev);
|
2014-07-23 20:55:20 +08:00
|
|
|
ut_assert(NULL != parent_data);
|
|
|
|
|
|
|
|
/* Check that it starts at 0 and goes away when device is removed */
|
|
|
|
parent_data->sum += 5;
|
|
|
|
ut_asserteq(5, parent_data->sum);
|
2017-03-20 19:51:48 +08:00
|
|
|
device_remove(dev, DM_REMOVE_NORMAL);
|
2015-09-29 13:32:01 +08:00
|
|
|
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
|
2014-07-23 20:55:20 +08:00
|
|
|
|
|
|
|
/* Check that we can do this twice */
|
|
|
|
ut_assertok(device_get_child_by_seq(bus, 0, &dev));
|
2015-09-29 13:32:01 +08:00
|
|
|
parent_data = dev_get_parent_priv(dev);
|
2014-07-23 20:55:20 +08:00
|
|
|
ut_assert(NULL != parent_data);
|
|
|
|
parent_data->sum += 5;
|
|
|
|
ut_asserteq(5, parent_data->sum);
|
|
|
|
|
|
|
|
/* Add parent data to all children */
|
|
|
|
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
|
|
|
|
value = 5;
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
/* Ignore these if they are not on this bus */
|
|
|
|
if (dev->parent != bus) {
|
2015-09-29 13:32:01 +08:00
|
|
|
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
|
2014-07-23 20:55:20 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ut_assertok(device_probe(dev));
|
2015-09-29 13:32:01 +08:00
|
|
|
parent_data = dev_get_parent_priv(dev);
|
2014-07-23 20:55:20 +08:00
|
|
|
|
|
|
|
parent_data->sum = value;
|
|
|
|
value += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check it is still there */
|
|
|
|
value = 5;
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
/* Ignore these if they are not on this bus */
|
|
|
|
if (dev->parent != bus)
|
|
|
|
continue;
|
2015-09-29 13:32:01 +08:00
|
|
|
parent_data = dev_get_parent_priv(dev);
|
2014-07-23 20:55:20 +08:00
|
|
|
|
|
|
|
ut_asserteq(value, parent_data->sum);
|
|
|
|
value += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-25 23:27:06 +08:00
|
|
|
/* Test that the bus can store data about each child */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_parent_data(struct unit_test_state *uts)
|
2015-01-25 23:27:06 +08:00
|
|
|
{
|
2015-05-21 03:27:27 +08:00
|
|
|
return test_bus_parent_data(uts);
|
2015-01-25 23:27:06 +08:00
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_bus_parent_data, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-07-23 20:55:21 +08:00
|
|
|
|
2015-01-25 23:27:06 +08:00
|
|
|
/* As above but the size is controlled by the uclass */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
|
2015-01-25 23:27:06 +08:00
|
|
|
{
|
2015-03-26 02:21:51 +08:00
|
|
|
struct driver *drv;
|
2015-01-25 23:27:06 +08:00
|
|
|
struct udevice *bus;
|
|
|
|
int size;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set the driver size to 0 so that the uclass size is used */
|
|
|
|
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
|
2015-03-26 02:21:51 +08:00
|
|
|
drv = (struct driver *)bus->driver;
|
2020-12-04 07:55:17 +08:00
|
|
|
size = drv->per_child_auto;
|
2018-10-02 11:12:32 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SANDBOX
|
|
|
|
os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
|
|
|
|
os_mprotect_allow(drv, sizeof(*drv));
|
|
|
|
#endif
|
2020-12-04 07:55:17 +08:00
|
|
|
bus->uclass->uc_drv->per_child_auto = size;
|
|
|
|
drv->per_child_auto = 0;
|
2015-05-21 03:27:27 +08:00
|
|
|
ret = test_bus_parent_data(uts);
|
2015-01-25 23:27:06 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-12-04 07:55:17 +08:00
|
|
|
bus->uclass->uc_drv->per_child_auto = 0;
|
|
|
|
drv->per_child_auto = size;
|
2015-01-25 23:27:06 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_bus_parent_data_uclass,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2015-01-25 23:27:06 +08:00
|
|
|
|
2014-07-23 20:55:21 +08:00
|
|
|
/* Test that the bus ops are called when a child is probed/removed */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_parent_ops(struct unit_test_state *uts)
|
2014-07-23 20:55:21 +08:00
|
|
|
{
|
|
|
|
struct dm_test_parent_data *parent_data;
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
struct uclass *uc;
|
|
|
|
|
2020-12-23 23:11:18 +08:00
|
|
|
testbus_get_clear_removed();
|
2014-07-23 20:55:21 +08:00
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
|
|
|
|
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
/* Ignore these if they are not on this bus */
|
|
|
|
if (dev->parent != bus)
|
|
|
|
continue;
|
2015-09-29 13:32:01 +08:00
|
|
|
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
|
2014-07-23 20:55:21 +08:00
|
|
|
|
|
|
|
ut_assertok(device_probe(dev));
|
2015-09-29 13:32:01 +08:00
|
|
|
parent_data = dev_get_parent_priv(dev);
|
2020-12-23 23:11:18 +08:00
|
|
|
ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag);
|
2014-07-23 20:55:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
/* Ignore these if they are not on this bus */
|
|
|
|
if (dev->parent != bus)
|
|
|
|
continue;
|
2015-09-29 13:32:01 +08:00
|
|
|
parent_data = dev_get_parent_priv(dev);
|
2020-12-23 23:11:18 +08:00
|
|
|
ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag);
|
2017-03-20 19:51:48 +08:00
|
|
|
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
|
2015-09-29 13:32:01 +08:00
|
|
|
ut_asserteq_ptr(NULL, dev_get_parent_priv(dev));
|
2020-12-23 23:11:18 +08:00
|
|
|
ut_asserteq_ptr(testbus_get_clear_removed(), dev);
|
2014-07-23 20:55:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_bus_parent_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2015-01-25 23:27:01 +08:00
|
|
|
|
2020-12-04 07:55:18 +08:00
|
|
|
static int test_bus_parent_plat(struct unit_test_state *uts)
|
2015-01-25 23:27:01 +08:00
|
|
|
{
|
2020-12-04 07:55:18 +08:00
|
|
|
struct dm_test_parent_plat *plat;
|
2015-01-25 23:27:01 +08:00
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
/* Check that the bus has no children */
|
|
|
|
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
device_find_first_child(bus, &dev);
|
|
|
|
ut_asserteq_ptr(NULL, dev);
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
|
|
|
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2015-01-25 23:27:01 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
/* Check that platform data is allocated */
|
2020-12-04 07:55:18 +08:00
|
|
|
plat = dev_get_parent_plat(dev);
|
2015-01-25 23:27:01 +08:00
|
|
|
ut_assert(plat != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that it is not affected by the device being
|
|
|
|
* probed/removed
|
|
|
|
*/
|
|
|
|
plat->count++;
|
|
|
|
ut_asserteq(1, plat->count);
|
|
|
|
device_probe(dev);
|
2017-03-20 19:51:48 +08:00
|
|
|
device_remove(dev, DM_REMOVE_NORMAL);
|
2015-01-25 23:27:01 +08:00
|
|
|
|
2020-12-04 07:55:18 +08:00
|
|
|
ut_asserteq_ptr(plat, dev_get_parent_plat(dev));
|
2015-01-25 23:27:01 +08:00
|
|
|
ut_asserteq(1, plat->count);
|
|
|
|
ut_assertok(device_probe(dev));
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2015-01-25 23:27:01 +08:00
|
|
|
|
|
|
|
/* Removing the bus should also have no effect (it is still bound) */
|
2017-03-20 19:51:48 +08:00
|
|
|
device_remove(bus, DM_REMOVE_NORMAL);
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2015-01-25 23:27:01 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
/* Check that platform data is allocated */
|
2020-12-04 07:55:18 +08:00
|
|
|
plat = dev_get_parent_plat(dev);
|
2015-01-25 23:27:01 +08:00
|
|
|
ut_assert(plat != NULL);
|
|
|
|
ut_asserteq(1, plat->count);
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2015-01-25 23:27:01 +08:00
|
|
|
|
|
|
|
/* Unbind all the children */
|
|
|
|
do {
|
|
|
|
device_find_first_child(bus, &dev);
|
|
|
|
if (dev)
|
|
|
|
device_unbind(dev);
|
|
|
|
} while (dev);
|
|
|
|
|
2020-12-04 07:55:18 +08:00
|
|
|
/* Now the child plat should be removed and re-added */
|
2015-01-25 23:27:01 +08:00
|
|
|
device_probe(bus);
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2015-01-25 23:27:01 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
/* Check that platform data is allocated */
|
2020-12-04 07:55:18 +08:00
|
|
|
plat = dev_get_parent_plat(dev);
|
2015-01-25 23:27:01 +08:00
|
|
|
ut_assert(plat != NULL);
|
|
|
|
ut_asserteq(0, plat->count);
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2015-01-25 23:27:01 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-25 23:27:02 +08:00
|
|
|
|
|
|
|
/* Test that the bus can store platform data about each child */
|
2020-12-04 07:55:18 +08:00
|
|
|
static int dm_test_bus_parent_plat(struct unit_test_state *uts)
|
2015-01-25 23:27:02 +08:00
|
|
|
{
|
2020-12-04 07:55:18 +08:00
|
|
|
return test_bus_parent_plat(uts);
|
2015-01-25 23:27:02 +08:00
|
|
|
}
|
2020-12-04 07:55:18 +08:00
|
|
|
DM_TEST(dm_test_bus_parent_plat, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2015-01-25 23:27:02 +08:00
|
|
|
|
|
|
|
/* As above but the size is controlled by the uclass */
|
2020-12-04 07:55:18 +08:00
|
|
|
static int dm_test_bus_parent_plat_uclass(struct unit_test_state *uts)
|
2015-01-25 23:27:02 +08:00
|
|
|
{
|
|
|
|
struct udevice *bus;
|
2015-03-26 02:21:51 +08:00
|
|
|
struct driver *drv;
|
2015-01-25 23:27:02 +08:00
|
|
|
int size;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set the driver size to 0 so that the uclass size is used */
|
|
|
|
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
|
2015-03-26 02:21:51 +08:00
|
|
|
drv = (struct driver *)bus->driver;
|
2020-12-04 07:55:18 +08:00
|
|
|
size = drv->per_child_plat_auto;
|
2018-10-02 11:12:32 +08:00
|
|
|
#ifdef CONFIG_SANDBOX
|
|
|
|
os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
|
|
|
|
os_mprotect_allow(drv, sizeof(*drv));
|
|
|
|
#endif
|
2020-12-04 07:55:18 +08:00
|
|
|
bus->uclass->uc_drv->per_child_plat_auto = size;
|
|
|
|
drv->per_child_plat_auto = 0;
|
|
|
|
ret = test_bus_parent_plat(uts);
|
2015-01-25 23:27:02 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-12-04 07:55:18 +08:00
|
|
|
bus->uclass->uc_drv->per_child_plat_auto = 0;
|
|
|
|
drv->per_child_plat_auto = size;
|
2015-01-25 23:27:02 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-12-04 07:55:18 +08:00
|
|
|
DM_TEST(dm_test_bus_parent_plat_uclass,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2015-01-25 23:27:03 +08:00
|
|
|
|
|
|
|
/* Test that the child post_bind method is called */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
|
2015-01-25 23:27:03 +08:00
|
|
|
{
|
2020-12-04 07:55:18 +08:00
|
|
|
struct dm_test_parent_plat *plat;
|
2015-01-25 23:27:03 +08:00
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2015-01-25 23:27:03 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
/* Check that platform data is allocated */
|
2020-12-04 07:55:18 +08:00
|
|
|
plat = dev_get_parent_plat(dev);
|
2015-01-25 23:27:03 +08:00
|
|
|
ut_assert(plat != NULL);
|
|
|
|
ut_asserteq(1, plat->bind_flag);
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2015-01-25 23:27:03 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_bus_child_post_bind, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2015-01-25 23:27:08 +08:00
|
|
|
|
|
|
|
/* Test that the child post_bind method is called */
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
|
2015-01-25 23:27:08 +08:00
|
|
|
{
|
2020-12-04 07:55:18 +08:00
|
|
|
struct dm_test_parent_plat *plat;
|
2015-01-25 23:27:08 +08:00
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2015-01-25 23:27:08 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
/* Check that platform data is allocated */
|
2020-12-04 07:55:18 +08:00
|
|
|
plat = dev_get_parent_plat(dev);
|
2015-01-25 23:27:08 +08:00
|
|
|
ut_assert(plat != NULL);
|
|
|
|
ut_asserteq(2, plat->uclass_bind_flag);
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2015-01-25 23:27:08 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_bus_child_post_bind_uclass,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2015-01-25 23:27:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test that the bus' uclass' child_pre_probe() is called before the
|
|
|
|
* device's probe() method
|
|
|
|
*/
|
2015-05-21 03:27:27 +08:00
|
|
|
static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts)
|
2015-01-25 23:27:10 +08:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See testfdt_drv_probe() which effectively checks that the uclass
|
|
|
|
* flag is set before that method is called
|
|
|
|
*/
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2015-01-25 23:27:10 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
struct dm_test_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
/* Check that things happened in the right order */
|
|
|
|
ut_asserteq_ptr(NULL, priv);
|
|
|
|
ut_assertok(device_probe(dev));
|
|
|
|
|
|
|
|
priv = dev_get_priv(dev);
|
|
|
|
ut_assert(priv != NULL);
|
|
|
|
ut_asserteq(1, priv->uclass_flag);
|
|
|
|
ut_asserteq(1, priv->uclass_total);
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2015-01-25 23:27:10 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_bus_child_pre_probe_uclass,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2018-10-15 17:20:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test that the bus' uclass' child_post_probe() is called after the
|
|
|
|
* device's probe() method
|
|
|
|
*/
|
|
|
|
static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See testfdt_drv_probe() which effectively initializes that
|
|
|
|
* the uclass postp flag is set to a value
|
|
|
|
*/
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
|
2019-09-04 18:31:26 +08:00
|
|
|
for (device_find_first_child(bus, &dev);
|
2018-10-15 17:20:58 +08:00
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
|
|
|
struct dm_test_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
/* Check that things happened in the right order */
|
|
|
|
ut_asserteq_ptr(NULL, priv);
|
|
|
|
ut_assertok(device_probe(dev));
|
|
|
|
|
|
|
|
priv = dev_get_priv(dev);
|
|
|
|
ut_assert(priv != NULL);
|
|
|
|
ut_asserteq(0, priv->uclass_postp);
|
|
|
|
}
|
2019-09-04 18:31:26 +08:00
|
|
|
ut_asserteq(3, device_get_child_count(bus));
|
2018-10-15 17:20:58 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_bus_child_post_probe_uclass,
|
2020-07-29 09:41:12 +08:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|