From nobody Sat Feb 7 08:58:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152967433609642.00539846843242; Fri, 22 Jun 2018 06:32:16 -0700 (PDT) Received: from localhost ([::1]:33918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWMAd-0006Vb-96 for importer@patchew.org; Fri, 22 Jun 2018 09:32:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWM1g-0007a9-LM for qemu-devel@nongnu.org; Fri, 22 Jun 2018 09:22:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWM1f-0004pq-9U for qemu-devel@nongnu.org; Fri, 22 Jun 2018 09:22:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34570 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fWM1c-0004lq-2G; Fri, 22 Jun 2018 09:22:52 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4F0C81A4EBE; Fri, 22 Jun 2018 13:22:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-106.ams2.redhat.com [10.36.117.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CB1A2026D6B; Fri, 22 Jun 2018 13:22:50 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, crosthwaite.peter@gmail.com, agraf@suse.de Date: Fri, 22 Jun 2018 15:22:43 +0200 Message-Id: <1529673765-16627-2-git-send-email-eric.auger@redhat.com> In-Reply-To: <1529673765-16627-1-git-send-email-eric.auger@redhat.com> References: <1529673765-16627-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 13:22:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 22 Jun 2018 13:22:51 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 1/3] device_tree: Add qemu_fdt_node_unit_path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This helper allows to retrieve the paths of nodes whose name match node-name or node-name@unit-address patterns. Signed-off-by: Eric Auger --- device_tree.c | 55 ++++++++++++++++++++++++++++++++++++++++= ++++ include/sysemu/device_tree.h | 16 +++++++++++++ 2 files changed, 71 insertions(+) diff --git a/device_tree.c b/device_tree.c index 52c3358..b5873f3 100644 --- a/device_tree.c +++ b/device_tree.c @@ -229,6 +229,61 @@ static int findnode_nofail(void *fdt, const char *node= _path) return offset; } =20 +char **qemu_fdt_node_unit_path(void *fdt, const char *name, Error **errp) +{ + char *prefix =3D g_strdup_printf("%s@", name); + unsigned int path_len =3D 16, n =3D 0; + GSList *path_list =3D NULL, *iter; + const char *iter_name; + int offset, len, ret; + char **path_array; + + offset =3D fdt_next_node(fdt, -1, NULL); + + while (offset >=3D 0) { + iter_name =3D fdt_get_name(fdt, offset, &len); + if (!iter_name) { + offset =3D len; + break; + } + if (!strcmp(iter_name, name) || g_str_has_prefix(iter_name, prefix= )) { + char *path; + + path =3D g_malloc(path_len); + while ((ret =3D fdt_get_path(fdt, offset, path, path_len)) + =3D=3D -FDT_ERR_NOSPACE) { + path_len +=3D 16; + path =3D g_realloc(path, path_len); + } + path_list =3D g_slist_prepend(path_list, path); + n++; + } + offset =3D fdt_next_node(fdt, offset, NULL); + } + g_free(prefix); + + if (offset < 0 && offset !=3D -FDT_ERR_NOTFOUND) { + error_setg(errp, "%s: abort parsing dt for %s node units: %s", + __func__, name, fdt_strerror(offset)); + for (iter =3D path_list; iter; iter =3D iter->next) { + g_free(iter->data); + } + g_slist_free(path_list); + return NULL; + } + + path_array =3D g_new(char *, n + 1); + path_array[n--] =3D NULL; + + for (iter =3D path_list; iter; iter =3D iter->next) { + path_array[n--] =3D iter->data; + } + + g_slist_free(path_list); + + return path_array; +} + char **qemu_fdt_node_path(void *fdt, const char *name, char *compat, Error **errp) { diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index e22e5be..c16fd69 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -43,6 +43,22 @@ void *load_device_tree_from_sysfs(void); char **qemu_fdt_node_path(void *fdt, const char *name, char *compat, Error **errp); =20 +/** + * qemu_fdt_node_unit_path: return the paths of nodes matching a given + * node-name, ie. node-name and node-name@unit-address + * @fdt: pointer to the dt blob + * @name: node name + * @errp: handle to an error object + * + * returns a newly allocated NULL-terminated array of node paths. + * Use g_strfreev() to free it. If one or more nodes were found, the + * array contains the path of each node and the last element equals to + * NULL. If there is no error but no matching node was found, the + * returned array contains a single element equal to NULL. If an error + * was encountered when parsing the blob, the function returns NULL + */ +char **qemu_fdt_node_unit_path(void *fdt, const char *name, Error **errp); + int qemu_fdt_setprop(void *fdt, const char *node_path, const char *property, const void *val, int size); int qemu_fdt_setprop_cell(void *fdt, const char *node_path, --=20 2.5.5