From owner-svn-src-all@freebsd.org Tue Feb 9 03:35:42 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 561BBAA29C9; Tue, 9 Feb 2016 03:35:42 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 192FF1A41; Tue, 9 Feb 2016 03:35:42 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u193Zfef052910; Tue, 9 Feb 2016 03:35:41 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u193Zf05052908; Tue, 9 Feb 2016 03:35:41 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201602090335.u193Zf05052908@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Tue, 9 Feb 2016 03:35:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r295424 - head/sys/dev/ofw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Feb 2016 03:35:42 -0000 Author: adrian Date: Tue Feb 9 03:35:40 2016 New Revision: 295424 URL: https://svnweb.freebsd.org/changeset/base/295424 Log: Teach ofw_bus_parse_xref_list_alloc to be able to return the length of the parsed list. Currently, there is no easy way to know in advance how many entries a list parsed by ofw_bus_parse_xref_list_alloc() in sys/dev/ofw/ofw_bus_subr.c has. This patch: * teaches the existing function about handling idx == -1 and returning how big the set is; then renames it as _internal; * create a new function that asserts idx != -1, so the old API is maintained; * add a new function that returns just the list length. Submitted by: Stanislav Galabov Differential Revision: https://reviews.freebsd.org/D5043 Modified: head/sys/dev/ofw/ofw_bus_subr.c head/sys/dev/ofw/ofw_bus_subr.h Modified: head/sys/dev/ofw/ofw_bus_subr.c ============================================================================== --- head/sys/dev/ofw/ofw_bus_subr.c Tue Feb 9 01:42:51 2016 (r295423) +++ head/sys/dev/ofw/ofw_bus_subr.c Tue Feb 9 03:35:40 2016 (r295424) @@ -629,13 +629,16 @@ ofw_bus_find_child_device_by_phandle(dev * 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 (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 } 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 Modified: head/sys/dev/ofw/ofw_bus_subr.h ============================================================================== --- head/sys/dev/ofw/ofw_bus_subr.h Tue Feb 9 01:42:51 2016 (r295423) +++ head/sys/dev/ofw/ofw_bus_subr.h Tue Feb 9 03:35:40 2016 (r295424) @@ -118,6 +118,8 @@ device_t ofw_bus_find_child_device_by_ph 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,