summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/board_r.c19
-rw-r--r--drivers/core/Makefile2
-rw-r--r--drivers/core/root.c27
-rw-r--r--include/asm-generic/global_data.h13
-rw-r--r--include/dm/of.h9
-rw-r--r--test/dm/test-main.c16
6 files changed, 37 insertions, 49 deletions
diff --git a/common/board_r.c b/common/board_r.c
index b9217b2e27..0829622d0d 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -296,20 +296,21 @@ static int initr_noncached(void)
}
#endif
-#ifdef CONFIG_OF_LIVE
static int initr_of_live(void)
{
- int ret;
+ if (CONFIG_IS_ENABLED(OF_LIVE)) {
+ int ret;
- bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
- ret = of_live_build(gd->fdt_blob, (struct device_node **)&gd->of_root);
- bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
- if (ret)
- return ret;
+ bootstage_start(BOOTSTAGE_ID_ACCUM_OF_LIVE, "of_live");
+ ret = of_live_build(gd->fdt_blob,
+ (struct device_node **)gd_of_root_ptr());
+ bootstage_accum(BOOTSTAGE_ID_ACCUM_OF_LIVE);
+ if (ret)
+ return ret;
+ }
return 0;
}
-#endif
#ifdef CONFIG_DM
static int initr_dm(void)
@@ -713,9 +714,7 @@ static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_SYS_NONCACHED_MEMORY
initr_noncached,
#endif
-#ifdef CONFIG_OF_LIVE
initr_of_live,
-#endif
#ifdef CONFIG_DM
initr_dm,
#endif
diff --git a/drivers/core/Makefile b/drivers/core/Makefile
index 10f4bece33..5edd4e4135 100644
--- a/drivers/core/Makefile
+++ b/drivers/core/Makefile
@@ -11,7 +11,7 @@ obj-$(CONFIG_SIMPLE_PM_BUS) += simple-pm-bus.o
obj-$(CONFIG_DM) += dump.o
obj-$(CONFIG_$(SPL_TPL_)REGMAP) += regmap.o
obj-$(CONFIG_$(SPL_TPL_)SYSCON) += syscon-uclass.o
-obj-$(CONFIG_OF_LIVE) += of_access.o of_addr.o
+obj-$(CONFIG_$(SPL_)OF_LIVE) += of_access.o of_addr.o
ifndef CONFIG_DM_DEV_READ_INLINE
obj-$(CONFIG_OF_CONTROL) += read.o
endif
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 0726be6b79..de23161cff 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -61,7 +61,7 @@ void fix_drivers(void)
for (entry = drv; entry != drv + n_ents; entry++) {
if (entry->of_match)
entry->of_match = (const struct udevice_id *)
- ((u32)entry->of_match + gd->reloc_off);
+ ((ulong)entry->of_match + gd->reloc_off);
if (entry->bind)
entry->bind += gd->reloc_off;
if (entry->probe)
@@ -151,11 +151,9 @@ int dm_init(bool of_live)
if (ret)
return ret;
#if CONFIG_IS_ENABLED(OF_CONTROL)
-# if CONFIG_IS_ENABLED(OF_LIVE)
- if (of_live)
- DM_ROOT_NON_CONST->node = np_to_ofnode(gd->of_root);
+ if (CONFIG_IS_ENABLED(OF_LIVE) && of_live)
+ DM_ROOT_NON_CONST->node = np_to_ofnode(gd_of_root());
else
-#endif
DM_ROOT_NON_CONST->node = offset_to_ofnode(0);
#endif
ret = device_probe(DM_ROOT_NON_CONST);
@@ -196,7 +194,7 @@ int dm_scan_platdata(bool pre_reloc_only)
return ret;
}
-#if CONFIG_IS_ENABLED(OF_LIVE)
+#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
static int dm_scan_fdt_live(struct udevice *parent,
const struct device_node *node_parent,
bool pre_reloc_only)
@@ -223,9 +221,7 @@ static int dm_scan_fdt_live(struct udevice *parent,
return ret;
}
-#endif /* CONFIG_IS_ENABLED(OF_LIVE) */
-#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
/**
* dm_scan_fdt_node() - Scan the device tree and bind drivers for a node
*
@@ -272,24 +268,20 @@ int dm_scan_fdt_dev(struct udevice *dev)
if (!dev_of_valid(dev))
return 0;
-#if CONFIG_IS_ENABLED(OF_LIVE)
if (of_live_active())
return dm_scan_fdt_live(dev, dev_np(dev),
gd->flags & GD_FLG_RELOC ? false : true);
- else
-#endif
+
return dm_scan_fdt_node(dev, gd->fdt_blob, dev_of_offset(dev),
gd->flags & GD_FLG_RELOC ? false : true);
}
int dm_scan_fdt(const void *blob, bool pre_reloc_only)
{
-#if CONFIG_IS_ENABLED(OF_LIVE)
if (of_live_active())
- return dm_scan_fdt_live(gd->dm_root, gd->of_root,
+ return dm_scan_fdt_live(gd->dm_root, gd_of_root(),
pre_reloc_only);
- else
-#endif
+
return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
}
@@ -302,10 +294,9 @@ static int dm_scan_fdt_ofnode_path(const void *blob, const char *path,
if (!ofnode_valid(node))
return 0;
-#if CONFIG_IS_ENABLED(OF_LIVE)
if (of_live_active())
return dm_scan_fdt_live(gd->dm_root, node.np, pre_reloc_only);
-#endif
+
return dm_scan_fdt_node(gd->dm_root, blob, node.of_offset,
pre_reloc_only);
}
@@ -352,7 +343,7 @@ int dm_init_and_scan(bool pre_reloc_only)
dm_populate_phandle_data();
#endif
- ret = dm_init(IS_ENABLED(CONFIG_OF_LIVE));
+ ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE));
if (ret) {
debug("dm_init() failed: %d\n", ret);
return ret;
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 0157af1aa4..cadfc05dd7 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -211,7 +211,7 @@ struct global_data {
* @fdt_size: space reserved for relocated device space
*/
unsigned long fdt_size;
-#ifdef CONFIG_OF_LIVE
+#if CONFIG_IS_ENABLED(OF_LIVE)
/**
* @of_root: root node of the live tree
*/
@@ -427,6 +427,17 @@ struct global_data {
#define gd_board_type() 0
#endif
+/* These macros help avoid #ifdefs in the code */
+#if CONFIG_IS_ENABLED(OF_LIVE)
+#define gd_of_root() gd->of_root
+#define gd_of_root_ptr() &gd->of_root
+#define gd_set_of_root(_root) gd->of_root = (_root)
+#else
+#define gd_of_root() NULL
+#define gd_of_root_ptr() NULL
+#define gd_set_of_root(_root)
+#endif
+
/**
* enum gd_flags - global data flags
*
diff --git a/include/dm/of.h b/include/dm/of.h
index 6bef73b441..5cb6f44a6c 100644
--- a/include/dm/of.h
+++ b/include/dm/of.h
@@ -90,17 +90,10 @@ DECLARE_GLOBAL_DATA_PTR;
*
* @returns true if livetree is active, false it not
*/
-#ifdef CONFIG_OF_LIVE
static inline bool of_live_active(void)
{
- return gd->of_root != NULL;
+ return gd_of_root() != NULL;
}
-#else
-static inline bool of_live_active(void)
-{
- return false;
-}
-#endif
#define OF_BAD_ADDR ((u64)-1)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 38b7b1481a..995988723a 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -33,10 +33,8 @@ static int dm_test_init(struct unit_test_state *uts, bool of_live)
memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
state_reset_for_test(state_get_current());
-#ifdef CONFIG_OF_LIVE
/* Determine whether to make the live tree available */
- gd->of_root = of_live ? uts->of_root : NULL;
-#endif
+ gd_set_of_root(of_live ? uts->of_root : NULL);
ut_assertok(dm_init(of_live));
dms->root = dm_root();
@@ -152,9 +150,7 @@ static int dm_test_main(const char *test_name)
printf("Running %d driver model tests\n", n_ents);
found = 0;
-#ifdef CONFIG_OF_LIVE
- uts->of_root = gd->of_root;
-#endif
+ uts->of_root = gd_of_root();
for (test = tests; test < tests + n_ents; test++) {
const char *name = test->name;
int runs;
@@ -167,7 +163,7 @@ static int dm_test_main(const char *test_name)
/* Run with the live tree if possible */
runs = 0;
- if (IS_ENABLED(CONFIG_OF_LIVE)) {
+ if (CONFIG_IS_ENABLED(OF_LIVE)) {
if (!(test->flags & UT_TESTF_FLAT_TREE)) {
ut_assertok(dm_do_test(uts, test, true));
runs++;
@@ -192,11 +188,9 @@ static int dm_test_main(const char *test_name)
printf("Failures: %d\n", uts->fail_count);
/* Put everything back to normal so that sandbox works as expected */
-#ifdef CONFIG_OF_LIVE
- gd->of_root = uts->of_root;
-#endif
+ gd_set_of_root(uts->of_root);
gd->dm_root = NULL;
- ut_assertok(dm_init(IS_ENABLED(CONFIG_OF_LIVE)));
+ ut_assertok(dm_init(CONFIG_IS_ENABLED(OF_LIVE)));
dm_scan_platdata(false);
dm_scan_fdt(gd->fdt_blob, false);