From: Simon Glass Date: Fri, 19 May 2017 02:09:04 +0000 (-0600) Subject: dm: core: Implement live tree 'read' functions X-Git-Tag: v2017.07-rc1~154 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=47a0fd3bad3858ae2f58bc3b3368e16ed20f394c;p=u-boot dm: core: Implement live tree 'read' functions When the live tree is supported some functions need to change a little. Add an implementation which is used when not inlining these functions. Signed-off-by: Simon Glass --- diff --git a/drivers/core/Makefile b/drivers/core/Makefile index d74b065a07..435cf98ae1 100644 --- a/drivers/core/Makefile +++ b/drivers/core/Makefile @@ -12,4 +12,7 @@ obj-$(CONFIG_DM) += dump.o obj-$(CONFIG_$(SPL_)REGMAP) += regmap.o obj-$(CONFIG_$(SPL_)SYSCON) += syscon-uclass.o obj-$(CONFIG_OF_LIVE) += of_access.o of_addr.o +ifndef CONFIG_DM_DEV_READ_INLINE +obj-$(CONFIG_OF_CONTROL) += read.o +endif obj-$(CONFIG_OF_CONTROL) += of_extra.o ofnode.o diff --git a/drivers/core/read.c b/drivers/core/read.c new file mode 100644 index 0000000000..3131e5379c --- /dev/null +++ b/drivers/core/read.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2017 Google, Inc + * Written by Simon Glass + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +int dev_read_u32_default(struct udevice *dev, const char *propname, int def) +{ + return ofnode_read_u32_default(dev_ofnode(dev), propname, def); +} + +const char *dev_read_string(struct udevice *dev, const char *propname) +{ + return ofnode_read_string(dev_ofnode(dev), propname); +} + +bool dev_read_bool(struct udevice *dev, const char *propname) +{ + return ofnode_read_bool(dev_ofnode(dev), propname); +} + +ofnode dev_read_subnode(struct udevice *dev, const char *subnode_name) +{ + return ofnode_find_subnode(dev_ofnode(dev), subnode_name); +} + +ofnode dev_read_first_subnode(struct udevice *dev) +{ + return ofnode_first_subnode(dev_ofnode(dev)); +} + +ofnode dev_read_next_subnode(ofnode node) +{ + return ofnode_next_subnode(node); +} + +int dev_read_size(struct udevice *dev, const char *propname) +{ + return ofnode_read_size(dev_ofnode(dev), propname); +} + +fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) +{ + if (ofnode_is_np(dev_ofnode(dev))) + return ofnode_get_addr_index(dev_ofnode(dev), index); + else + return devfdt_get_addr_index(dev, index); +} + +fdt_addr_t dev_read_addr(struct udevice *dev) +{ + return dev_read_addr_index(dev, 0); +} + +fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *property, + fdt_size_t *sizep) +{ + return ofnode_get_addr_size(dev_ofnode(dev), property, sizep); +} + +const char *dev_read_name(struct udevice *dev) +{ + return ofnode_get_name(dev_ofnode(dev)); +} + +int dev_read_stringlist_search(struct udevice *dev, const char *property, + const char *string) +{ + return ofnode_stringlist_search(dev_ofnode(dev), property, string); +} + +int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, + const char *cells_name, int cell_count, + int index, + struct ofnode_phandle_args *out_args) +{ + return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, + cells_name, cell_count, index, + out_args); +} + +int dev_read_addr_cells(struct udevice *dev) +{ + return ofnode_read_addr_cells(dev_ofnode(dev)); +} + +int dev_read_size_cells(struct udevice *dev) +{ + return ofnode_read_size_cells(dev_ofnode(dev)); +} + +int dev_read_phandle(struct udevice *dev) +{ + ofnode node = dev_ofnode(dev); + + if (ofnode_is_np(node)) + return ofnode_to_np(node)->phandle; + else + return fdt_get_phandle(gd->fdt_blob, ofnode_to_offset(node)); +} + +const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp) +{ + return ofnode_read_prop(dev_ofnode(dev), propname, lenp); +} + +int dev_read_alias_seq(struct udevice *dev, int *devnump) +{ + ofnode node = dev_ofnode(dev); + const char *uc_name = dev->uclass->uc_drv->name; + int ret; + + if (ofnode_is_np(node)) { + ret = of_alias_get_id(ofnode_to_np(node), uc_name); + if (ret >= 0) + *devnump = ret; + } else { + ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name, + ofnode_to_offset(node), devnump); + } + + return ret; +} + +int dev_read_u32_array(struct udevice *dev, const char *propname, + u32 *out_values, size_t sz) +{ + return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); +} + +const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, + size_t sz) +{ + return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); +} diff --git a/include/dm/read.h b/include/dm/read.h index 4ce2bc2d6e..8c9846eaf2 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -42,13 +42,16 @@ static inline bool dev_of_valid(struct udevice *dev) return ofnode_valid(dev_ofnode(dev)); } -#ifdef CONFIG_DM_DEV_READ_INLINE - -static inline int dev_read_u32_default(struct udevice *dev, - const char *propname, int def) -{ - return ofnode_read_u32_default(dev_ofnode(dev), propname, def); -} +#ifndef CONFIG_DM_DEV_READ_INLINE +/** + * dev_read_u32_default() - read a 32-bit integer from a device's DT property + * + * @dev: device to read DT property from + * @propname: name of the property to read from + * @def: default value to return if the property has no value + * @return property value, or @def if not found + */ +int dev_read_u32_default(struct udevice *dev, const char *propname, int def); /** * dev_read_string() - Read a string from a device's DT property @@ -57,11 +60,7 @@ static inline int dev_read_u32_default(struct udevice *dev, * @propname: name of the property to read * @return string from property value, or NULL if there is no such property */ -static inline const char *dev_read_string(struct udevice *dev, - const char *propname) -{ - return ofnode_read_string(dev_ofnode(dev), propname); -} +const char *dev_read_string(struct udevice *dev, const char *propname); /** * dev_read_bool() - read a boolean value from a device's DT property @@ -70,10 +69,7 @@ static inline const char *dev_read_string(struct udevice *dev, * @propname: name of property to read * @return true if property is present (meaning true), false if not present */ -static inline bool dev_read_bool(struct udevice *dev, const char *propname) -{ - return ofnode_read_bool(dev_ofnode(dev), propname); -} +bool dev_read_bool(struct udevice *dev, const char *propname); /** * dev_read_subnode() - find a named subnode of a device @@ -83,11 +79,7 @@ static inline bool dev_read_bool(struct udevice *dev, const char *propname) * @return reference to subnode (which can be invalid if there is no such * subnode) */ -static inline ofnode dev_read_subnode(struct udevice *dev, - const char *subbnode_name) -{ - return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); -} +ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); /** * dev_read_size() - read the size of a property @@ -96,10 +88,7 @@ static inline ofnode dev_read_subnode(struct udevice *dev, * @propname: property to check * @return size of property if present, or -EINVAL if not */ -static inline int dev_read_size(struct udevice *dev, const char *propname) -{ - return ofnode_read_size(dev_ofnode(dev), propname); -} +int dev_read_size(struct udevice *dev, const char *propname); /** * dev_read_addr_index() - Get the indexed reg property of a device @@ -110,10 +99,7 @@ static inline int dev_read_size(struct udevice *dev, const char *propname) * * @return address or FDT_ADDR_T_NONE if not found */ -static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) -{ - return devfdt_get_addr_index(dev, index); -} +fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); /** * dev_read_addr() - Get the reg property of a device @@ -122,10 +108,7 @@ static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) * * @return address or FDT_ADDR_T_NONE if not found */ -static inline fdt_addr_t dev_read_addr(struct udevice *dev) -{ - return devfdt_get_addr(dev); -} +fdt_addr_t dev_read_addr(struct udevice *dev); /** * dev_read_addr_size() - get address and size from a device property @@ -138,12 +121,8 @@ static inline fdt_addr_t dev_read_addr(struct udevice *dev) * @sizep: place to put size value (on success) * @return address value, or FDT_ADDR_T_NONE on error */ -static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, - const char *propname, - fdt_size_t *sizep) -{ - return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); -} +fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, + fdt_size_t *sizep); /** * dev_read_name() - get the name of a device's node @@ -151,10 +130,7 @@ static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, * @node: valid node to look up * @return name of node */ -static inline const char *dev_read_name(struct udevice *dev) -{ - return ofnode_get_name(dev_ofnode(dev)); -} +const char *dev_read_name(struct udevice *dev); /** * dev_read_stringlist_search() - find string in a string list and return index @@ -174,12 +150,8 @@ static inline const char *dev_read_name(struct udevice *dev) * -ENODATA if the property is not found * -EINVAL on some other error */ -static inline int dev_read_stringlist_search(struct udevice *dev, - const char *propname, - const char *string) -{ - return ofnode_stringlist_search(dev_ofnode(dev), propname, string); -} +int dev_read_stringlist_search(struct udevice *dev, const char *property, + const char *string); /** * dev_read_phandle_with_args() - Find a node pointed by phandle in a list @@ -219,14 +191,10 @@ static inline int dev_read_stringlist_search(struct udevice *dev, * @cells_name could not be found, the arguments were truncated or there * were too many arguments. */ -static inline int dev_read_phandle_with_args(struct udevice *dev, - const char *list_name, const char *cells_name, int cell_count, - int index, struct ofnode_phandle_args *out_args) -{ - return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, - cells_name, cell_count, index, - out_args); -} +int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, + const char *cells_name, int cell_count, + int index, + struct ofnode_phandle_args *out_args); /** * dev_read_addr_cells() - Get the number of address cells for a device's node @@ -237,10 +205,7 @@ static inline int dev_read_phandle_with_args(struct udevice *dev, * @dev: devioe to check * @return number of address cells this node uses */ -static inline int dev_read_addr_cells(struct udevice *dev) -{ - return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); -} +int dev_read_addr_cells(struct udevice *dev); /** * dev_read_size_cells() - Get the number of size cells for a device's node @@ -251,10 +216,7 @@ static inline int dev_read_addr_cells(struct udevice *dev) * @dev: devioe to check * @return number of size cells this node uses */ -static inline int dev_read_size_cells(struct udevice *dev) -{ - return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); -} +int dev_read_size_cells(struct udevice *dev); /** * dev_read_phandle() - Get the phandle from a device @@ -262,10 +224,7 @@ static inline int dev_read_size_cells(struct udevice *dev) * @dev: device to check * @return phandle (1 or greater), or 0 if no phandle or other error */ -static inline int dev_read_phandle(struct udevice *dev) -{ - return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); -} +int dev_read_phandle(struct udevice *dev); /** * dev_read_prop()- - read a property from a device's node @@ -275,11 +234,7 @@ static inline int dev_read_phandle(struct udevice *dev) * @lenp: place to put length on success * @return pointer to property, or NULL if not found */ -static inline const u32 *dev_read_prop(struct udevice *dev, - const char *propname, int *lenp) -{ - return ofnode_read_prop(dev_ofnode(dev), propname, lenp); -} +const u32 *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); /** * dev_read_alias_seq() - Get the alias sequence number of a node @@ -292,11 +247,7 @@ static inline const u32 *dev_read_prop(struct udevice *dev, * @devnump: set to the sequence number if one is found * @return 0 if a sequence was found, -ve if not */ -static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) -{ - return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, - dev_of_offset(dev), devnump); -} +int dev_read_alias_seq(struct udevice *dev, int *devnump); /** * dev_read_u32_array() - Find and read an array of 32 bit integers @@ -314,11 +265,8 @@ static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) * property does not have a value, and -EOVERFLOW if the property data isn't * large enough. */ -static inline int dev_read_u32_array(struct udevice *dev, const char *propname, - u32 *out_values, size_t sz) -{ - return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); -} +int dev_read_u32_array(struct udevice *dev, const char *propname, + u32 *out_values, size_t sz); /** * dev_read_first_subnode() - find the first subnode of a device's node @@ -327,10 +275,7 @@ static inline int dev_read_u32_array(struct udevice *dev, const char *propname, * @return reference to the first subnode (which can be invalid if the device's * node has no subnodes) */ -static inline ofnode dev_read_first_subnode(struct udevice *dev) -{ - return ofnode_first_subnode(dev_ofnode(dev)); -} +ofnode dev_read_first_subnode(struct udevice *dev); /** * ofnode_next_subnode() - find the next sibling of a subnode @@ -339,10 +284,7 @@ static inline ofnode dev_read_first_subnode(struct udevice *dev) * @return reference to the next subnode (which can be invalid if the node * has no more siblings) */ -static inline ofnode dev_read_next_subnode(ofnode node) -{ - return ofnode_next_subnode(node); -} +ofnode dev_read_next_subnode(ofnode node); /** * dev_read_u8_array_ptr() - find an 8-bit array @@ -358,6 +300,120 @@ static inline ofnode dev_read_next_subnode(ofnode node) * @return pointer to byte array if found, or NULL if the property is not * found or there is not enough data */ +const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, + size_t sz); + +#else /* CONFIG_DM_DEV_READ_INLINE is enabled */ + +static inline int dev_read_u32_default(struct udevice *dev, + const char *propname, int def) +{ + return ofnode_read_u32_default(dev_ofnode(dev), propname, def); +} + +static inline const char *dev_read_string(struct udevice *dev, + const char *propname) +{ + return ofnode_read_string(dev_ofnode(dev), propname); +} + +static inline bool dev_read_bool(struct udevice *dev, const char *propname) +{ + return ofnode_read_bool(dev_ofnode(dev), propname); +} + +static inline ofnode dev_read_subnode(struct udevice *dev, + const char *subbnode_name) +{ + return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); +} + +static inline int dev_read_size(struct udevice *dev, const char *propname) +{ + return ofnode_read_size(dev_ofnode(dev), propname); +} + +static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) +{ + return devfdt_get_addr_index(dev, index); +} + +static inline fdt_addr_t dev_read_addr(struct udevice *dev) +{ + return devfdt_get_addr(dev); +} + +static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, + const char *propname, + fdt_size_t *sizep) +{ + return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); +} + +static inline const char *dev_read_name(struct udevice *dev) +{ + return ofnode_get_name(dev_ofnode(dev)); +} + +static inline int dev_read_stringlist_search(struct udevice *dev, + const char *propname, + const char *string) +{ + return ofnode_stringlist_search(dev_ofnode(dev), propname, string); +} + +static inline int dev_read_phandle_with_args(struct udevice *dev, + const char *list_name, const char *cells_name, int cell_count, + int index, struct ofnode_phandle_args *out_args) +{ + return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, + cells_name, cell_count, index, + out_args); +} + +static inline int dev_read_addr_cells(struct udevice *dev) +{ + return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); +} + +static inline int dev_read_size_cells(struct udevice *dev) +{ + return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); +} + +static inline int dev_read_phandle(struct udevice *dev) +{ + return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); +} + +static inline const u32 *dev_read_prop(struct udevice *dev, + const char *propname, int *lenp) +{ + return ofnode_read_prop(dev_ofnode(dev), propname, lenp); +} + +static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) +{ + return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, + dev_of_offset(dev), devnump); +} + +static inline int dev_read_u32_array(struct udevice *dev, const char *propname, + u32 *out_values, size_t sz) +{ + return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); +} + +static inline ofnode dev_read_first_subnode(struct udevice *dev) +{ + return ofnode_first_subnode(dev_ofnode(dev)); +} + +static inline ofnode dev_read_next_subnode(ofnode node) +{ + return ofnode_next_subnode(node); +} + static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, size_t sz) {