From patchwork Thu Dec 17 12:29:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 58586 Delivered-To: patches@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp332338lbb; Thu, 17 Dec 2015 04:29:30 -0800 (PST) X-Received: by 10.194.24.70 with SMTP id s6mr56269216wjf.74.1450355370003; Thu, 17 Dec 2015 04:29:30 -0800 (PST) Return-Path: Received: from mail-wm0-x22c.google.com (mail-wm0-x22c.google.com. [2a00:1450:400c:c09::22c]) by mx.google.com with ESMTPS id y187si3685683wme.46.2015.12.17.04.29.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Dec 2015 04:29:29 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) client-ip=2a00:1450:400c:c09::22c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::22c as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-wm0-x22c.google.com with SMTP id l126so19120187wml.0 for ; Thu, 17 Dec 2015 04:29:29 -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=kSnDYid2GjeWiV0jEytZCl9gK4KHbHYbiVcmEBQ4bmA=; b=LO6S5gV+D2hoKzwFFoVqZGbstde8VZHSBOuk9kF9SoqcaaRi5NriUYiwl+enYa/D3x REkVcrRvTyJaq6MdsAFtBs/1YKoYvanHMu8kf6fOjFKcrt9Had5+XWFe8jvbcQB2IesG 5JGiuYNWkGGfpfFM8WzHuFFmXhIzOq0ZOv2KY= 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=kSnDYid2GjeWiV0jEytZCl9gK4KHbHYbiVcmEBQ4bmA=; b=KdHOjVozSpnyr8687/dToxevB8/sYnrmxspNk3OXr75lQuGnScMUjYpvjsgTg0SLsN tcKhsGjz6KmyxYu4xvbt7WelzRIV4OJZkWvZrLecZtjF4V38Wz+MSxO09ThswFlNRtsA dSaMVyq4AgAHE07B4F8OoBecAFpgTa2gbrEOQ1O/sH7LMcLOnOZmqjrN5rpBlrzKa1nL snaH1xxyCYrL/dNz98IJZ/2x5x6/twr+PVLzaxz7vKIS2550wuNsdMlEXMDkafgcuH24 s6CQ1B63hyq1Kc/vdRj+bIZiEw0YyP8VgI0/uVduY4NHln+/wKzvMaJqMZTXM3TGxwR9 tEyQ== X-Gm-Message-State: ALoCoQkJy9elujS+52qRpHN5VbmZEScUmFbR2I5af6CKEtXLZrqFXe5Zkq3zzj3dwdJYt6b/96UXWWNL5YnPXzhYH3WX7E6Urg== X-Received: by 10.28.182.11 with SMTP id g11mr4048885wmf.42.1450355369803; Thu, 17 Dec 2015 04:29:29 -0800 (PST) Return-Path: Received: from new-host-17.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id bh6sm10313963wjb.0.2015.12.17.04.29.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Dec 2015 04:29:28 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, peter.maydell@linaro.org, david@gibson.dropbear.id.au, alex.williamson@redhat.com Cc: alex.bennee@linaro.org, thuth@redhat.com, crosthwaitepeter@gmail.com, patches@linaro.org, christoffer.dall@linaro.org, pbonzini@redhat.com, b.reynal@virtualopensystems.com, suravee.suthikulpanit@amd.com, thomas.lendacky@amd.com Subject: [PATCH 3/6] device_tree: introduce qemu_fdt_node_path Date: Thu, 17 Dec 2015 12:29:24 +0000 Message-Id: <1450355367-14818-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450355367-14818-1-git-send-email-eric.auger@linaro.org> References: <1450355367-14818-1-git-send-email-eric.auger@linaro.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 --- RFC -> v1: - improve error handling according to Alex' comments --- device_tree.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/sysemu/device_tree.h | 3 +++ 2 files changed, 48 insertions(+) -- 1.9.1 diff --git a/device_tree.c b/device_tree.c index e556a99..b5d7e0b 100644 --- a/device_tree.c +++ b/device_tree.c @@ -233,6 +233,51 @@ static int findnode_nofail(void *fdt, const char *node_path) return offset; } +/** + * 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 + * + * 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 offset, len, ret; + const char *iter_name; + char path[256]; + + *node_path = NULL; + offset = fdt_node_offset_by_compatible(fdt, -1, compat); + while (offset != -FDT_ERR_NOTFOUND) { + if (offset < 0) { + continue; + } + iter_name = fdt_get_name(fdt, offset, &len); + if (!iter_name) { + continue; + } + + if (!strncmp(iter_name, name, len)) { + goto found; + } + offset = fdt_node_offset_by_compatible(fdt, offset, compat); + } + return offset; + +found: + ret = fdt_get_path(fdt, offset, path, 256); + if (!ret) { + *node_path = g_strdup(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 307e53d..f9e6e6e 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -18,6 +18,9 @@ void *create_device_tree(int *sizep); void *load_device_tree(const char *filename_path, int *sizep); void *load_device_tree_from_sysfs(void); +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,