mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-17 10:18:38 +00:00
00606d7e39
Driver model currently only operates after relocation is complete. In this state U-Boot typically has a small amount of memory available. In adding support for driver model prior to relocation we must try to use as little memory as possible. In addition, on some machines the memory has not be inited and/or the CPU is not running at full speed or the data cache is off. These can reduce execution performance, so the less initialisation that is done before relocation the better. An immediately-obvious improvement is to only initialise drivers which are actually going to be used before relocation. On many boards the only such driver is a serial UART, so this provides a very large potential benefit. Allow drivers to mark themselves as 'pre-reloc' which means that they will be initialised prior to relocation. This can be done either with a driver flag or with a 'dm,pre-reloc' device tree property. To support this, the various dm scanning function now take a 'pre_reloc_only' parameter which indicates that only drivers marked pre-reloc should be bound. Signed-off-by: Simon Glass <sjg@chromium.org>
157 lines
3.2 KiB
C
157 lines
3.2 KiB
C
/*
|
|
* Copyright (c) 2013 Google, Inc
|
|
*
|
|
* (C) Copyright 2012
|
|
* Pavel Herrmann <morpheus.ibis@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <errno.h>
|
|
#include <malloc.h>
|
|
#include <dm/test.h>
|
|
#include <dm/ut.h>
|
|
#include <asm/io.h>
|
|
|
|
int dm_testdrv_op_count[DM_TEST_OP_COUNT];
|
|
static struct dm_test_state *dms = &global_test_state;
|
|
|
|
static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
|
|
{
|
|
const struct dm_test_pdata *pdata = dev_get_platdata(dev);
|
|
struct dm_test_priv *priv = dev_get_priv(dev);
|
|
|
|
*pingret = pingval + pdata->ping_add;
|
|
priv->ping_total += *pingret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct test_ops test_ops = {
|
|
.ping = testdrv_ping,
|
|
};
|
|
|
|
static int test_bind(struct udevice *dev)
|
|
{
|
|
/* Private data should not be allocated */
|
|
ut_assert(!dev_get_priv(dev));
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_BIND]++;
|
|
return 0;
|
|
}
|
|
|
|
static int test_probe(struct udevice *dev)
|
|
{
|
|
struct dm_test_priv *priv = dev_get_priv(dev);
|
|
|
|
/* Private data should be allocated */
|
|
ut_assert(priv);
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
|
|
priv->ping_total += DM_TEST_START_TOTAL;
|
|
return 0;
|
|
}
|
|
|
|
static int test_remove(struct udevice *dev)
|
|
{
|
|
/* Private data should still be allocated */
|
|
ut_assert(dev_get_priv(dev));
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
|
|
return 0;
|
|
}
|
|
|
|
static int test_unbind(struct udevice *dev)
|
|
{
|
|
/* Private data should not be allocated */
|
|
ut_assert(!dev->priv);
|
|
|
|
dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
|
|
return 0;
|
|
}
|
|
|
|
U_BOOT_DRIVER(test_drv) = {
|
|
.name = "test_drv",
|
|
.id = UCLASS_TEST,
|
|
.ops = &test_ops,
|
|
.bind = test_bind,
|
|
.probe = test_probe,
|
|
.remove = test_remove,
|
|
.unbind = test_unbind,
|
|
.priv_auto_alloc_size = sizeof(struct dm_test_priv),
|
|
};
|
|
|
|
U_BOOT_DRIVER(test2_drv) = {
|
|
.name = "test2_drv",
|
|
.id = UCLASS_TEST,
|
|
.ops = &test_ops,
|
|
.bind = test_bind,
|
|
.probe = test_probe,
|
|
.remove = test_remove,
|
|
.unbind = test_unbind,
|
|
.priv_auto_alloc_size = sizeof(struct dm_test_priv),
|
|
};
|
|
|
|
static int test_manual_drv_ping(struct udevice *dev, int pingval, int *pingret)
|
|
{
|
|
*pingret = pingval + 2;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct test_ops test_manual_ops = {
|
|
.ping = test_manual_drv_ping,
|
|
};
|
|
|
|
static int test_manual_bind(struct udevice *dev)
|
|
{
|
|
dm_testdrv_op_count[DM_TEST_OP_BIND]++;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int test_manual_probe(struct udevice *dev)
|
|
{
|
|
dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
|
|
if (!dms->force_fail_alloc)
|
|
dev->priv = calloc(1, sizeof(struct dm_test_priv));
|
|
if (!dev->priv)
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int test_manual_remove(struct udevice *dev)
|
|
{
|
|
dm_testdrv_op_count[DM_TEST_OP_REMOVE]++;
|
|
return 0;
|
|
}
|
|
|
|
static int test_manual_unbind(struct udevice *dev)
|
|
{
|
|
dm_testdrv_op_count[DM_TEST_OP_UNBIND]++;
|
|
return 0;
|
|
}
|
|
|
|
U_BOOT_DRIVER(test_manual_drv) = {
|
|
.name = "test_manual_drv",
|
|
.id = UCLASS_TEST,
|
|
.ops = &test_manual_ops,
|
|
.bind = test_manual_bind,
|
|
.probe = test_manual_probe,
|
|
.remove = test_manual_remove,
|
|
.unbind = test_manual_unbind,
|
|
};
|
|
|
|
U_BOOT_DRIVER(test_pre_reloc_drv) = {
|
|
.name = "test_pre_reloc_drv",
|
|
.id = UCLASS_TEST,
|
|
.ops = &test_manual_ops,
|
|
.bind = test_manual_bind,
|
|
.probe = test_manual_probe,
|
|
.remove = test_manual_remove,
|
|
.unbind = test_manual_unbind,
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
};
|