From patchwork Wed Jan 6 15:13:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 563968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7FB5614029E for ; Thu, 7 Jan 2016 02:14:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=aYK1z+Go; dkim-atps=neutral Received: from localhost ([::1]:54685 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGpmy-0000wU-4K for incoming@patchwork.ozlabs.org; Wed, 06 Jan 2016 10:14:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGpmJ-0008EY-6c for qemu-devel@nongnu.org; Wed, 06 Jan 2016 10:13:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGpmI-0005tZ-3C for qemu-devel@nongnu.org; Wed, 06 Jan 2016 10:13:35 -0500 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGpmH-0005tN-Td for qemu-devel@nongnu.org; Wed, 06 Jan 2016 10:13:34 -0500 Received: by mail-wm0-x22f.google.com with SMTP id f206so79945385wmf.0 for ; Wed, 06 Jan 2016 07:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kV6N27qiuswlag2H1s2evzjNV+nHFfWWVrGZ4zJiJ3s=; b=aYK1z+GomKrm2mQW5BlGtrgEtuTvwcahyCxw6SwazbPCqnczYXciu83Zf9ZgfNJDZN yjbfRxTbDSDT+Dn/+ExabwueENMX3oTDQnZ086aHGB/TqBl5G7gHBmFSDEy2l5kZV1ho cJyMGm+EDENEmfI3i35Loj0daQWQNvDAC3pKM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kV6N27qiuswlag2H1s2evzjNV+nHFfWWVrGZ4zJiJ3s=; b=ioSzu6aZsVzsMmL1BKu837CIMxJnaOyuCscXPphaF5dZR8UMnxAQDo9BAgm1DcQu/o GbaeDh/9J8UwxC0mnzUhGWrj42sY9Kp6wmKFlQcT9s1rxh+SqQ1LRXLjhr0/SuC3HB+K 5+iOZa85mOg5j3ApvviKT27wCC8Vlkerg+lR16DvkfiYqMZc7GWUsDqKxUxCZqGvDpVa Fzz8KK2nJ1vm3vLs8HrHpceUXyF9TdQlPXwKSfWhD5FvK3Vl1XIxQNrwF9jQdgVcWmBA vjeJ0hazQSyio9b7KtsAmXP/dgCNjBpCDffBLtRnw8rtojtbs8RB4Jq/xrTWWSwUZmrD lYhg== X-Gm-Message-State: ALoCoQm2KBZSQW5bC/i5E/hcVwUgDi1VCzp5jrGr9HUc/Zgk3zG3Ro8h97pnOqDTaL08cMUruiwDjzoUHRPObd/cZU5ce3JTdQ== X-Received: by 10.28.210.143 with SMTP id j137mr10546921wmg.13.1452093213441; Wed, 06 Jan 2016 07:13:33 -0800 (PST) Received: from new-host-6.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id df10sm81858826wjb.44.2016.01.06.07.13.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jan 2016 07:13:31 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, david@gibson.dropbear.id.au, alex.williamson@redhat.com Date: Wed, 6 Jan 2016 15:13:21 +0000 Message-Id: <1452093205-30167-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452093205-30167-1-git-send-email-eric.auger@linaro.org> References: <1452093205-30167-1-git-send-email-eric.auger@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f Cc: thomas.lendacky@amd.com, thuth@redhat.com, b.reynal@virtualopensystems.com, patches@linaro.org, crosthwaitepeter@gmail.com, suravee.suthikulpanit@amd.com, pbonzini@redhat.com, alex.bennee@linaro.org, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v2 3/7] device_tree: introduce qemu_fdt_node_path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This new helper routine returns the node path of a device referred to by its node name and compat string. Signed-off-by: Eric Auger --- v1 -> v2: - move doc comment in header file - do not use a fixed size buffer - break on errors in while loop - use strcmp instead of strncmp RFC -> v1: - improve error handling according to Alex' comments --- device_tree.c | 37 +++++++++++++++++++++++++++++++++++++ include/sysemu/device_tree.h | 14 ++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/device_tree.c b/device_tree.c index b262c2d..8441e01 100644 --- a/device_tree.c +++ b/device_tree.c @@ -231,6 +231,43 @@ static int findnode_nofail(void *fdt, const char *node_path) return offset; } +int qemu_fdt_node_path(void *fdt, const char *name, char *compat, + char **node_path) +{ + int offset, len, ret; + const char *iter_name; + unsigned int path_len = 16; + char *path; + + *node_path = NULL; + offset = fdt_node_offset_by_compatible(fdt, -1, compat); + + while (offset >= 0) { + iter_name = fdt_get_name(fdt, offset, &len); + if (!iter_name) { + offset = len; + break; + } + if (!strcmp(iter_name, name)) { + goto found; + } + offset = fdt_node_offset_by_compatible(fdt, offset, compat); + } + return offset; + +found: + path = g_malloc(path_len); + while ((ret = fdt_get_path(fdt, offset, path, path_len)) + == -FDT_ERR_NOSPACE) { + path_len += 16; + path = g_realloc(path, path_len); + } + if (!ret) { + *node_path = path; + } + return ret; +} + int qemu_fdt_setprop(void *fdt, const char *node_path, const char *property, const void *val, int size) { diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index fdf25a4..269cb1c 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -20,6 +20,20 @@ void *load_device_tree(const char *filename_path, int *sizep); void *load_device_tree_from_sysfs(void); #endif +/** + * qemu_fdt_node_path: return the node path of a device, given its + * node name and its compat string + * @fdt: pointer to the dt blob + * @name: device node name + * @compat: compatibility string of the device + * @node_path: returned node path + * + * upon success, the path is output at node_path address + * returns 0 on success, < 0 on failure + */ +int qemu_fdt_node_path(void *fdt, const char *name, char *compat, + char **node_path); + 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,