}
int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
- struct driver_info *info, struct udevice **devp)
+ const struct driver_info *info, struct udevice **devp)
{
struct driver *drv;
uint platdata_size = 0;
platdata_size, devp);
if (ret)
return ret;
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
- info->dev = *devp;
-#endif
return ret;
}
int device_get_by_driver_info(const struct driver_info *info,
struct udevice **devp)
{
+ struct driver_info *info_base =
+ ll_entry_start(struct driver_info, driver_info);
+ int idx = info - info_base;
+ struct driver_rt *drt = gd_dm_driver_rt() + idx;
struct udevice *dev;
- dev = info->dev;
+ dev = drt->dev;
*devp = NULL;
return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
struct driver_info *info =
ll_entry_start(struct driver_info, driver_info);
const int n_ents = ll_entry_count(struct driver_info, driver_info);
- struct driver_info *entry;
- struct udevice *dev;
int result = 0;
- int ret;
+ uint idx;
+
+ for (idx = 0; idx < n_ents; idx++) {
+ const struct driver_info *entry = info + idx;
+ struct driver_rt *drt = gd_dm_driver_rt() + idx;
+ struct udevice *dev;
+ int ret;
- for (entry = info; entry != info + n_ents; entry++) {
ret = device_bind_by_name(parent, pre_reloc_only, entry, &dev);
- if (ret && ret != -EPERM) {
+ if (!ret) {
+ if (CONFIG_IS_ENABLED(OF_PLATDATA))
+ drt->dev = dev;
+ } else if (ret != -EPERM) {
dm_warn("No match for driver '%s'\n", entry->name);
if (!result || ret != -ENOENT)
result = ret;
{
int ret;
+ if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
+ struct driver_rt *dyn;
+ int n_ents;
+
+ n_ents = ll_entry_count(struct driver_info, driver_info);
+ dyn = calloc(n_ents, sizeof(struct driver_rt));
+ if (!dyn)
+ return -ENOMEM;
+ gd_set_dm_driver_rt(dyn);
+ }
+
ret = lists_bind_drivers(DM_ROOT_NON_CONST, pre_reloc_only);
if (ret == -ENOENT) {
dm_warn("Some drivers were not found\n");
#include <membuff.h>
#include <linux/list.h>
+struct driver_rt;
+
typedef struct global_data gd_t;
/**
* @uclass_root: head of core tree
*/
struct list_head uclass_root;
+# if CONFIG_IS_ENABLED(OF_PLATDATA)
+ /** Dynamic info about the driver */
+ struct driver_rt *dm_driver_rt;
+# endif
#endif
#ifdef CONFIG_TIMER
/**
#define gd_set_of_root(_root)
#endif
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+#define gd_set_dm_driver_rt(dyn) gd->dm_driver_rt = dyn
+#define gd_dm_driver_rt() gd->dm_driver_rt
+#else
+#define gd_set_dm_driver_rt(dyn)
+#define gd_dm_driver_rt() NULL
+#endif
+
/**
* enum gd_flags - global data flags
*
* @return 0 if OK, -ve on error
*/
int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
- struct driver_info *info, struct udevice **devp);
+ const struct driver_info *info, struct udevice **devp);
/**
* device_reparent: reparent the device to a new parent
* @name: Driver name
* @platdata: Driver-specific platform data
* @platdata_size: Size of platform data structure
- * @dev: Device created from this structure data
*/
struct driver_info {
const char *name;
const void *platdata;
#if CONFIG_IS_ENABLED(OF_PLATDATA)
uint platdata_size;
- struct udevice *dev;
#endif
};
+/**
+ * driver_rt - runtime information set up by U-Boot
+ *
+ * There is one of these for every driver_info in the linker list, indexed by
+ * the driver_info idx value.
+ *
+ * @dev: Device created from this idx
+ */
+struct driver_rt {
+ struct udevice *dev;
+};
+
/**
* NOTE: Avoid using these except in extreme circumstances, where device tree
* is not feasible (e.g. serial driver in SPL where <8KB of SRAM is
/* If not the root device, find the entry that caused it to be bound */
if (parent->parent) {
- const struct driver_info *info =
- ll_entry_start(struct driver_info, driver_info);
const int n_ents =
ll_entry_count(struct driver_info, driver_info);
- const struct driver_info *entry;
int idx = -1;
+ int i;
- for (entry = info; entry != info + n_ents; entry++) {
- if (entry->dev == parent) {
- idx = entry - info;
+ for (i = 0; i < n_ents; i++) {
+ const struct driver_rt *drt = gd_dm_driver_rt() + i;
+
+ if (drt->dev == parent) {
+ idx = i;
found[idx] = true;
break;
}
/* Make sure that the driver entries without devices have no ->dev */
for (i = 0; i < n_ents; i++) {
+ const struct driver_rt *drt = gd_dm_driver_rt() + i;
const struct driver_info *entry = info + i;
struct udevice *dev;
if (found[i]) {
/* Make sure we can find it */
- ut_assertnonnull(entry->dev);
+ ut_assertnonnull(drt->dev);
ut_assertok(device_get_by_driver_info(entry, &dev));
- ut_asserteq_ptr(dev, entry->dev);
+ ut_asserteq_ptr(dev, drt->dev);
} else {
- ut_assertnull(entry->dev);
+ ut_assertnull(drt->dev);
ut_asserteq(-ENOENT,
device_get_by_driver_info(entry, &dev));
}