From patchwork Mon Oct 12 16:48:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 54806 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id E0DFE23001 for ; Mon, 12 Oct 2015 16:49:01 +0000 (UTC) Received: by lbbpc3 with SMTP id pc3sf18024207lbb.2 for ; Mon, 12 Oct 2015 09:49:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=zv2kvrM4C5rT5utzRoPvslUOAy8uLVNUqqr5QCAFfQM=; b=Ohbuc2hFDN5doqcejcrOwKNJikPRraKfmHzsCxWHk83jIfeurjJ7eNm1ppC5+0TN9C /0afLDiLFOfs6n7s9mu2225hraMX6C/lm4xdXxzUB/vcyDIOgKpOvKayP/6hADN1uAmC ZEoG8nGzWGOczBAAnAMeK55vSZI36NZHe7JyLxyKgrZWLlmoJs7Np+9c+T7LSDevm6Vl rIdmRwuCVHZ2Q14Rk/p5ZdTUdiR89Y04UJzkM7cAu0wHhYQQnsWK1VlKuii6EAZhznht RKvdIl3KX6DooYLH1AvGKIsMbXwrToDFXbgfP9wLxkSHKZE32ESgWCh9G5Tkux3thqw3 FXYw== X-Gm-Message-State: ALoCoQnNu7ELDKLS98Mx1lNPyydCVe+PMnUFIktE0wjzCn7OlEbd18b8L7ftD8FgQxny6CASQImc X-Received: by 10.112.147.7 with SMTP id tg7mr5918627lbb.16.1444668540901; Mon, 12 Oct 2015 09:49:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.42.209 with SMTP id q200ls583724lfq.72.gmail; Mon, 12 Oct 2015 09:49:00 -0700 (PDT) X-Received: by 10.25.18.77 with SMTP id h74mr5109178lfi.7.1444668540766; Mon, 12 Oct 2015 09:49:00 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id wb7si8126100lbb.41.2015.10.12.09.49.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:49:00 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbbck17 with SMTP id ck17so28791274lbb.1 for ; Mon, 12 Oct 2015 09:49:00 -0700 (PDT) X-Received: by 10.25.38.9 with SMTP id m9mr8396689lfm.112.1444668540644; Mon, 12 Oct 2015 09:49:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1650572lbq; Mon, 12 Oct 2015 09:48:59 -0700 (PDT) X-Received: by 10.180.230.197 with SMTP id ta5mr14899869wic.26.1444668537130; Mon, 12 Oct 2015 09:48:57 -0700 (PDT) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com. [209.85.212.180]) by mx.google.com with ESMTPS id e11si2103036wik.98.2015.10.12.09.48.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2015 09:48:57 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.180 as permitted sender) client-ip=209.85.212.180; Received: by wicgb1 with SMTP id gb1so156534219wic.1 for ; Mon, 12 Oct 2015 09:48:57 -0700 (PDT) X-Received: by 10.194.78.34 with SMTP id y2mr31333143wjw.91.1444668536952; Mon, 12 Oct 2015 09:48:56 -0700 (PDT) Received: from localhost.localdomain.home (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id xt1sm20805130wjb.32.2015.10.12.09.48.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Oct 2015 09:48:55 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com Cc: patches@linaro.org, christoffer.dall@linaro.org, pbonzini@redhat.com, b.reynal@virtualopensystems.com, suravee.suthikulpanit@amd.com, thomas.lendacky@amd.com Subject: [RFC 3/6] device_tree: introduce qemu_fdt_node_path Date: Mon, 12 Oct 2015 16:48:40 +0000 Message-Id: <1444668523-2252-4-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444668523-2252-1-git-send-email-eric.auger@linaro.org> References: <1444668523-2252-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This new helper routine returns the node path of a device referred to by its name and compat string. Signed-off-by: Eric Auger --- device_tree.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/sysemu/device_tree.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/device_tree.c b/device_tree.c index 58a5329..f184e3c 100644 --- a/device_tree.c +++ b/device_tree.c @@ -171,6 +171,46 @@ static int findnode_nofail(void *fdt, const char *node_path) return offset; } +/** + * qemu_fdt_node_path + * + * return the node path of a device, referred to by its node name + * and its compat string + * fdt: pointer to the dt blob + * name: name of the device + * compat: compatibility string of the device + * + * returns the node path + */ +int qemu_fdt_node_path(void *fdt, const char *name, char *compat, + char **node_path) +{ + int offset = 0, len; + const char *iter_name; + char path[256]; + int ret; + + *node_path = NULL; + while (1) { + offset = fdt_node_offset_by_compatible(fdt, offset, compat); + if (offset == -FDT_ERR_NOTFOUND) { + break; + } + iter_name = fdt_get_name(fdt, offset, &len); + if (!strncmp(iter_name, name, len)) { + goto found; + } + } + 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,