[Skiboot] [PATCH 1/2] device: add dt_find_by_name_addr

Vasant Hegde hegdevasant at linux.vnet.ibm.com
Thu Apr 6 14:54:45 AEST 2017


On 04/06/2017 09:31 AM, Oliver O'Halloran wrote:
> Adds two helper functions that allow device nodes to be found via
> their name and unit address. One will take an integer address and
> format it to a hex string while the other looks up the unit based
> a user supplied string. This is handy in a few places inside the
> HDAT parser.
>
> Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
> ---
>  core/device.c          | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  core/test/run-device.c |  1 +
>  include/device.h       |  5 +++++
>  3 files changed, 56 insertions(+)
>
> diff --git a/core/device.c b/core/device.c
> index 76c2f8481b9f..f3ee63fbc423 100644
> --- a/core/device.c
> +++ b/core/device.c
> @@ -21,6 +21,7 @@
>  #include <libfdt/libfdt_internal.h>
>  #include <ccan/str/str.h>
>  #include <ccan/endian/endian.h>
> +#include <inttypes.h>
>
>  /* Used to give unique handles. */
>  u32 last_phandle = 0;
> @@ -155,6 +156,55 @@ struct dt_node *dt_new(struct dt_node *parent, const char *name)
>  	return new;
>  }
>
> +/*
> + * low level variant, we export this because there are "weird" address
> + * formats, such as LPC/ISA bus addresses which have a letter to identify
> + * which bus space the address is inside of.
> + */
> +struct dt_node *__dt_find_by_name_addr(struct dt_node *parent, const char *name,
> +	const char *addr)
> +{
> +	struct dt_node *node;
> +
> +	if (list_empty(&parent->children))
> +		return NULL;
> +
> +	dt_for_each_child(parent, node) {
> +		const char *unit = get_unitname(node);
> +		int len;
> +
> +		if (!unit)
> +			continue;
> +
> +		/* match the name */
> +		len = (int) (unit - node->name) - 1;
> +		if (strncmp(node->name, name, len))
> +			continue;
> +
> +		/* match the unit */
> +		if (strcmp(unit, addr) == 0)
> +			return node;
> +	}
> +
> +	dt_for_each_child(parent, node) {
> +		struct dt_node *ret = __dt_find_by_name_addr(node, name, addr);

You can reuse variable 'node' instead of creating one more here. Otherwise patch 
looks good.

Reviewed-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>

-Vasant



More information about the Skiboot mailing list