diff options
author | Adrian Chadd <adrian@FreeBSD.org> | 2016-02-09 03:35:40 +0000 |
---|---|---|
committer | Adrian Chadd <adrian@FreeBSD.org> | 2016-02-09 03:35:40 +0000 |
commit | 91ef8da010fb8edf25b66d89994c0889ca15fb47 (patch) | |
tree | d1e44bc0be615e93d4037f32aebdfb5e0b6b5175 /sys | |
parent | 78a38b8f05f9dbb70ca12e0223ef52984f3aa65f (diff) | |
download | src-test2-91ef8da010fb8edf25b66d89994c0889ca15fb47.tar.gz src-test2-91ef8da010fb8edf25b66d89994c0889ca15fb47.zip |
Notes
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ofw/ofw_bus_subr.c | 59 | ||||
-rw-r--r-- | sys/dev/ofw/ofw_bus_subr.h | 2 |
2 files changed, 57 insertions, 4 deletions
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index dafaaedb8ae0..653f04c8c8bf 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -629,13 +629,16 @@ ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node) * node - consumers device node * list_name - name of parsed list - "clocks" * cells_name - name of size property - "#clock-cells" + * idx - the index of the requested list entry, or, if -1, an indication + * to return the number of entries in the parsed list. * Output arguments: * producer - handle of producer - * ncells - number of cells in result + * ncells - number of cells in result or the number of items in the list when + * idx == -1. * cells - array of decoded cells */ -int -ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, +static int +ofw_bus_parse_xref_list_internal(phandle_t node, const char *list_name, const char *cells_name, int idx, phandle_t *producer, int *ncells, pcell_t **cells) { @@ -649,7 +652,7 @@ ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, (void **)&elems); if (nelems <= 0) return (ENOENT); - rv = ENOENT; + rv = (idx == -1) ? 0 : ENOENT; for (i = 0, cnt = 0; i < nelems; i += pcells, cnt++) { pnode = elems[i++]; if (OF_getencprop(OF_node_from_xref(pnode), @@ -678,10 +681,58 @@ ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, } if (elems != NULL) free(elems, M_OFWPROP); + if (idx == -1 && rv == 0) + *ncells = cnt; return (rv); } /* + * Parse property that contain list of xrefs and values + * (like standard "clocks" and "resets" properties) + * Input arguments: + * node - consumers device node + * list_name - name of parsed list - "clocks" + * cells_name - name of size property - "#clock-cells" + * idx - the index of the requested list entry (>= 0) + * Output arguments: + * producer - handle of producer + * ncells - number of cells in result + * cells - array of decoded cells + */ +int +ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, + const char *cells_name, int idx, phandle_t *producer, int *ncells, + pcell_t **cells) +{ + + KASSERT(idx >= 0, + ("ofw_bus_parse_xref_list_alloc: negative index supplied")); + + return (ofw_bus_parse_xref_list_internal(node, list_name, cells_name, + idx, producer, ncells, cells)); +} + +/* + * Parse property that contain list of xrefs and values + * (like standard "clocks" and "resets" properties) + * and determine the number of items in the list + * Input arguments: + * node - consumers device node + * list_name - name of parsed list - "clocks" + * cells_name - name of size property - "#clock-cells" + * Output arguments: + * count - number of items in list + */ +int +ofw_bus_parse_xref_list_get_length(phandle_t node, const char *list_name, + const char *cells_name, int *count) +{ + + return (ofw_bus_parse_xref_list_internal(node, list_name, cells_name, + -1, NULL, count, NULL)); +} + +/* * Find index of string in string list property (case sensitive). */ int diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h index 7c4df3377768..b79539701281 100644 --- a/sys/dev/ofw/ofw_bus_subr.h +++ b/sys/dev/ofw/ofw_bus_subr.h @@ -118,6 +118,8 @@ device_t ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node); int ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, const char *cells_name, int idx, phandle_t *producer, int *ncells, pcell_t **cells); +int ofw_bus_parse_xref_list_get_length(phandle_t node, const char *list_name, + const char *cells_name, int *count); int ofw_bus_find_string_index(phandle_t node, const char *list_name, const char *name, int *idx); int ofw_bus_string_list_to_array(phandle_t node, const char *list_name, |