From patchwork Wed Apr 8 09:35:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 1267831 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=default header.b=HtuyqIqK; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xzfq1LH3z9sRN for ; Wed, 8 Apr 2020 19:36:02 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 63EDE81918; Wed, 8 Apr 2020 11:35:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="HtuyqIqK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 29D8981901; Wed, 8 Apr 2020 11:35:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2DE0981834 for ; Wed, 8 Apr 2020 11:35:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matthias.bgg@kernel.org Received: from ziggy.de (unknown [213.195.113.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 53C7920768; Wed, 8 Apr 2020 09:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586338538; bh=dgjhNbd00YdF4JBAsmC+o6Fy7mh0CeLk6nyVwjF9krQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HtuyqIqKzl9XrazkTzw0IhfkaiI6BMlZeunkceS5KeaSiH8Ddj30Fft5UwCc0FupZ hLkd1eiVsL3cY73mpxKJfRb5IQxECjGQtHkyZgVk04pEXykjfknqygqzRYg5+ifidU F/6apA+GioMMtAd/N8syxOGQi+MPhuBux1Yeo0h0= From: matthias.bgg@kernel.org To: matthias.bgg@kernel.org, Simon Glass , u-boot@lists.denx.de, Robin.Randhawa@ARM.com Cc: giulio.benetti@benettiengineering.com, treding@nvidia.com, Matthias Brugger Subject: [PATCH 1/2] libfdt: Make fdt_cells function accessible Date: Wed, 8 Apr 2020 11:35:27 +0200 Message-Id: <20200408093528.24276-2-matthias.bgg@kernel.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200408093528.24276-1-matthias.bgg@kernel.org> References: <20200408093528.24276-1-matthias.bgg@kernel.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean From: Matthias Brugger For reading address-cells and size-cells, the libfdt only provides functions which do not return in case the node does not provide the property. For traversing the DT to find the parent node which provides this property we will need to know that. Make fdt_cells accessible from outside of libfdt so that we can detect not present size- and address-cells properties in a node. Signed-off-by: Matthias Brugger --- scripts/dtc/libfdt/fdt_addresses.c | 2 +- scripts/dtc/libfdt/libfdt.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/dtc/libfdt/fdt_addresses.c b/scripts/dtc/libfdt/fdt_addresses.c index 9a82cd0ba2..ead9460e95 100644 --- a/scripts/dtc/libfdt/fdt_addresses.c +++ b/scripts/dtc/libfdt/fdt_addresses.c @@ -11,7 +11,7 @@ #include "libfdt_internal.h" -static int fdt_cells(const void *fdt, int nodeoffset, const char *name) +int fdt_cells(const void *fdt, int nodeoffset, const char *name) { const fdt32_t *c; uint32_t val; diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h index fa63fffe28..b0eca12491 100644 --- a/scripts/dtc/libfdt/libfdt.h +++ b/scripts/dtc/libfdt/libfdt.h @@ -1121,6 +1121,8 @@ const char *fdt_stringlist_get(const void *fdt, int nodeoffset, */ #define FDT_MAX_NCELLS 4 +int fdt_cells(const void *fdt, int nodeoffset, const char *name); + /** * fdt_address_cells - retrieve address size for a bus represented in the tree * @fdt: pointer to the device tree blob From patchwork Wed Apr 8 09:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 1267833 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=default header.b=DTL1AtIf; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xzfy2jJCz9sRN for ; Wed, 8 Apr 2020 19:36:10 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 67CA781981; Wed, 8 Apr 2020 11:35:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="DTL1AtIf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D557B8191A; Wed, 8 Apr 2020 11:35:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 814AC8188A for ; Wed, 8 Apr 2020 11:35:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matthias.bgg@kernel.org Received: from ziggy.de (unknown [213.195.113.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A71E520753; Wed, 8 Apr 2020 09:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586338540; bh=J9Nj5wiVTpwXWLKDGJ7t9m4jgDptE0e57sJuxoTOwXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTL1AtIfZubWHz7Vok46RfnOhfyfi+KF9VtUQIPZmnj9l4XP9yoAoWyzmDEqc/yrP 8rv1YzIcF0lc+iXY5CENMANGzxjc84nD632Kw6He8XmCcCp3p0RAJ9Fc3zDlHltFl6 koUzDbNdUibIRr0ldsq2b1KJtPv0eEeU0XtaNsXE= From: matthias.bgg@kernel.org To: matthias.bgg@kernel.org, Simon Glass , u-boot@lists.denx.de, Robin.Randhawa@ARM.com Cc: giulio.benetti@benettiengineering.com, treding@nvidia.com, Matthias Brugger Subject: [PATCH 2/2] dm: core: Walk the tree to find address- and size-cells properties Date: Wed, 8 Apr 2020 11:35:28 +0200 Message-Id: <20200408093528.24276-3-matthias.bgg@kernel.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200408093528.24276-1-matthias.bgg@kernel.org> References: <20200408093528.24276-1-matthias.bgg@kernel.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean From: Matthias Brugger Walk the tree when reading size-cells or address-cells properties. Reported-by: Robin Randhawa Signed-off-by: Matthias Brugger Reviewed-by: Simon Glass --- drivers/core/ofnode.c | 8 ++++---- include/dm/ofnode.h | 36 ++++++++++++++++++++++++++++++++++++ include/dm/read.h | 6 ++---- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 96a5dd20bd..5f23826b70 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -697,16 +697,16 @@ int ofnode_read_addr_cells(ofnode node) { if (ofnode_is_np(node)) return of_n_addr_cells(ofnode_to_np(node)); - else /* NOTE: this call should walk up the parent stack */ - return fdt_address_cells(gd->fdt_blob, ofnode_to_offset(node)); + else + return __ofnode_read_address_cells(node); } int ofnode_read_size_cells(ofnode node) { if (ofnode_is_np(node)) return of_n_size_cells(ofnode_to_np(node)); - else /* NOTE: this call should walk up the parent stack */ - return fdt_size_cells(gd->fdt_blob, ofnode_to_offset(node)); + else + return __ofnode_read_size_cells(node); } int ofnode_read_simple_addr_cells(ofnode node) diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index b5a50e8849..c6b768763d 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -660,6 +660,24 @@ int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device); */ int ofnode_read_addr_cells(ofnode node); +static inline int __ofnode_read_address_cells(ofnode node) +{ + /* NOTE: this call walks up the parent stack */ + int val = -FDT_ERR_NOTFOUND; + ofnode nd = node; + + while (val == -FDT_ERR_NOTFOUND) { + val = fdt_cells(gd->fdt_blob, ofnode_to_offset(nd), + "#address-cells"); + nd = ofnode_get_parent(nd); + } + + if (val == -FDT_ERR_NOTFOUND) + return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; + else + return val; +} + /** * ofnode_read_size_cells() - Get the number of size cells for a node * @@ -671,6 +689,24 @@ int ofnode_read_addr_cells(ofnode node); */ int ofnode_read_size_cells(ofnode node); +static inline int __ofnode_read_size_cells(ofnode node) +{ + /* NOTE: this call walks up the parent stack */ + int val = -FDT_ERR_NOTFOUND; + ofnode nd = node; + + while (val == -FDT_ERR_NOTFOUND) { + val = fdt_cells(gd->fdt_blob, ofnode_to_offset(nd), + "#size-cells"); + nd = ofnode_get_parent(nd); + } + + if (val == -FDT_ERR_NOTFOUND) + return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; + else + return val; +} + /** * ofnode_read_simple_addr_cells() - Get the address cells property in a node * diff --git a/include/dm/read.h b/include/dm/read.h index da8c7f25e7..0302c7bffb 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -789,14 +789,12 @@ static inline int dev_count_phandle_with_args(const struct udevice *dev, static inline int dev_read_addr_cells(const struct udevice *dev) { - /* NOTE: this call should walk up the parent stack */ - return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); + return __ofnode_read_address_cells(dev_ofnode(dev)); } static inline int dev_read_size_cells(const struct udevice *dev) { - /* NOTE: this call should walk up the parent stack */ - return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); + return __ofnode_read_size_cells(dev_ofnode(dev)); } static inline int dev_read_simple_addr_cells(const struct udevice *dev)