From 0de1b07406d709c3951dbb1a69ca196d80bd516d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:02 -0700 Subject: dm: core: Add a livetree function to check node status Add a way to find out if a node is enabled or not, based on its 'status' property. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ced7f6ffb25..ee8c44a71ec 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -345,6 +345,17 @@ const char *ofnode_read_string(ofnode node, const char *propname); */ int ofnode_read_u32_array(ofnode node, const char *propname, u32 *out_values, size_t sz); +/** + * ofnode_is_enabled() - Checks whether a node is enabled. + * This looks for a 'status' property. If this exists, then returns true if + * the status is 'okay' and false otherwise. If there is no status property, + * it returns true on the assumption that anything mentioned should be enabled + * by default. + * + * @node: node to examine + * @return false (not enabled) or true (enabled) + */ +bool ofnode_is_enabled(ofnode node); /** * ofnode_read_bool() - read a boolean value from a property -- cgit v1.3.1 From d0c20ce6bcb9af3d70ed6ada618607ca1099e811 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:07 -0700 Subject: dm: core: Add an ofnode function to get the devicetree root This is needed in at least one place. Avoid the conditional code in root.c by adding this inline function. Signed-off-by: Simon Glass --- drivers/core/root.c | 8 ++------ include/dm/ofnode.h | 12 ++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'include/dm/ofnode.h') diff --git a/drivers/core/root.c b/drivers/core/root.c index 5f10d7a39c7..9ee65504e6e 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -147,12 +147,8 @@ int dm_init(bool of_live) ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST); if (ret) return ret; -#if CONFIG_IS_ENABLED(OF_CONTROL) - if (CONFIG_IS_ENABLED(OF_LIVE) && of_live) - DM_ROOT_NON_CONST->node = np_to_ofnode(gd_of_root()); - else - DM_ROOT_NON_CONST->node = offset_to_ofnode(0); -#endif + if (CONFIG_IS_ENABLED(OF_CONTROL)) + DM_ROOT_NON_CONST->node = ofnode_root(); ret = device_probe(DM_ROOT_NON_CONST); if (ret) return ret; diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ee8c44a71ec..53f04ac91d0 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -218,6 +218,18 @@ static inline ofnode ofnode_null(void) return node; } +static inline ofnode ofnode_root(void) +{ + ofnode node; + + if (of_live_active()) + node.np = gd_of_root(); + else + node.of_offset = 0; + + return node; +} + /** * ofnode_read_u32() - Read a 32-bit integer from a property * -- cgit v1.3.1 From ec1add1e51affd4aacc308dc37439ea13dc1b70e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 16 Dec 2020 17:25:06 -0700 Subject: dm: core: Inline a few ofnode functions in SPL A recent change to unify the flattree/livetree code introduced a small size increase in SPL on some boards. For example SPL code size for px30-core-ctouch2-px30 increased by 40 bytes. To address this we can take advantage of the fact that some of the ofnode functions are only called a few times in SPL, so it is worth inlining them. Add new Kconfig options to control this. These functions are not inlined for U-Boot proper, since this increases code size. Fixes: 2ebea5eaebf ("dm: core: Combine the flattree and livetree binding code") Signed-off-by: Simon Glass --- drivers/core/Kconfig | 16 +++++++++++++++ drivers/core/ofnode.c | 2 ++ include/dm/ofnode.h | 56 +++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 63 insertions(+), 11 deletions(-) (limited to 'include/dm/ofnode.h') diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig index ffae6f9795f..65a503e76d1 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -113,6 +113,22 @@ config SPL_DM_SEQ_ALIAS numbered devices (e.g. serial0 = &serial0). This feature can be disabled if it is not required, to save code space in SPL. +config SPL_DM_INLINE_OFNODE + bool "Inline some ofnode functions which are seldom used in SPL" + depends on SPL_DM + default y + help + This applies to several ofnode functions (see ofnode.h) which are + seldom used. Inlining them can help reduce code size. + +config TPL_DM_INLINE_OFNODE + bool "Inline some ofnode functions which are seldom used in TPL" + depends on TPL_DM + default y + help + This applies to several ofnode functions (see ofnode.h) which are + seldom used. Inlining them can help reduce code size. + config REGMAP bool "Support register maps" depends on DM diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 87072094f32..2a6e43ddc6b 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -226,6 +226,7 @@ int ofnode_read_u32_array(ofnode node, const char *propname, } } +#if !CONFIG_IS_ENABLED(DM_INLINE_OFNODE) bool ofnode_is_enabled(ofnode node) { if (ofnode_is_np(node)) { @@ -255,6 +256,7 @@ ofnode ofnode_next_subnode(ofnode node) return offset_to_ofnode( fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node))); } +#endif /* !DM_INLINE_OFNODE */ ofnode ofnode_get_parent(ofnode node) { diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 53f04ac91d0..5b088650d3b 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -10,6 +10,7 @@ /* TODO(sjg@chromium.org): Drop fdtdec.h include */ #include #include +#include #include /* Enable checks to protect against invalid calls */ @@ -357,17 +358,6 @@ const char *ofnode_read_string(ofnode node, const char *propname); */ int ofnode_read_u32_array(ofnode node, const char *propname, u32 *out_values, size_t sz); -/** - * ofnode_is_enabled() - Checks whether a node is enabled. - * This looks for a 'status' property. If this exists, then returns true if - * the status is 'okay' and false otherwise. If there is no status property, - * it returns true on the assumption that anything mentioned should be enabled - * by default. - * - * @node: node to examine - * @return false (not enabled) or true (enabled) - */ -bool ofnode_is_enabled(ofnode node); /** * ofnode_read_bool() - read a boolean value from a property @@ -388,6 +378,49 @@ bool ofnode_read_bool(ofnode node, const char *propname); */ ofnode ofnode_find_subnode(ofnode node, const char *subnode_name); +#if CONFIG_IS_ENABLED(DM_INLINE_OFNODE) +static inline bool ofnode_is_enabled(ofnode node) +{ + if (ofnode_is_np(node)) { + return of_device_is_available(ofnode_to_np(node)); + } else { + return fdtdec_get_is_enabled(gd->fdt_blob, + ofnode_to_offset(node)); + } +} + +static inline ofnode ofnode_first_subnode(ofnode node) +{ + assert(ofnode_valid(node)); + if (ofnode_is_np(node)) + return np_to_ofnode(node.np->child); + + return offset_to_ofnode( + fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node))); +} + +static inline ofnode ofnode_next_subnode(ofnode node) +{ + assert(ofnode_valid(node)); + if (ofnode_is_np(node)) + return np_to_ofnode(node.np->sibling); + + return offset_to_ofnode( + fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node))); +} +#else +/** + * ofnode_is_enabled() - Checks whether a node is enabled. + * This looks for a 'status' property. If this exists, then returns true if + * the status is 'okay' and false otherwise. If there is no status property, + * it returns true on the assumption that anything mentioned should be enabled + * by default. + * + * @node: node to examine + * @return false (not enabled) or true (enabled) + */ +bool ofnode_is_enabled(ofnode node); + /** * ofnode_first_subnode() - find the first subnode of a parent node * @@ -405,6 +438,7 @@ ofnode ofnode_first_subnode(ofnode node); * has no more siblings) */ ofnode ofnode_next_subnode(ofnode node); +#endif /* DM_INLINE_OFNODE */ /** * ofnode_get_parent() - get the ofnode's parent (enclosing ofnode) -- cgit v1.3.1