summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/core/device.c3
-rw-r--r--drivers/core/root.c8
-rw-r--r--include/dm/device.h8
3 files changed, 17 insertions, 2 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index b7ce8544140..3ab2583df38 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -1186,7 +1186,8 @@ int dev_enable_by_path(const char *path)
static struct udevice_rt *dev_get_rt(const struct udevice *dev)
{
struct udevice *base = ll_entry_start(struct udevice, udevice);
- int idx = dev - base;
+ uint each_size = dm_udevice_size();
+ int idx = ((void *)dev - (void *)base) / each_size;
struct udevice_rt *urt = gd_dm_udevice_rt() + idx;
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 86b3884fc67..e09c12f4d6e 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -136,12 +136,18 @@ static int dm_setup_inst(void)
if (CONFIG_IS_ENABLED(OF_PLATDATA_RT)) {
struct udevice_rt *urt;
+ void *start, *end;
+ int each_size;
void *base;
int n_ents;
uint size;
/* Allocate the udevice_rt table */
- n_ents = ll_entry_count(struct udevice, udevice);
+ each_size = dm_udevice_size();
+ start = ll_entry_start(struct udevice, udevice);
+ end = ll_entry_end(struct udevice, udevice);
+ size = end - start;
+ n_ents = size / each_size;
urt = calloc(n_ents, sizeof(struct udevice_rt));
if (!urt)
return log_msg_ret("urt", -ENOMEM);
diff --git a/include/dm/device.h b/include/dm/device.h
index 3d8961f9ac6..e0f86f5df9f 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -192,6 +192,14 @@ struct udevice {
#endif
};
+static inline int dm_udevice_size(void)
+{
+ if (CONFIG_IS_ENABLED(OF_PLATDATA_RT))
+ return ALIGN(sizeof(struct udevice), CONFIG_LINKER_LIST_ALIGN);
+
+ return sizeof(struct udevice);
+}
+
/**
* struct udevice_rt - runtime information set up by U-Boot
*