From patchwork Tue Sep 24 18:12:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 11159965 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 558F814ED for ; Wed, 25 Sep 2019 04:17:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BFCE2075D for ; Wed, 25 Sep 2019 04:17:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BFCE2075D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCyj2-0000RU-0X; Wed, 25 Sep 2019 04:16:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCpJ9-0000FG-DE for xen-devel@lists.xenproject.org; Tue, 24 Sep 2019 18:13:03 +0000 X-Inumbo-ID: ece94744-def6-11e9-b588-bc764e2007e4 Received: from mx1.suse.de (unknown [195.135.220.15]) by localhost (Halon) with ESMTPS id ece94744-def6-11e9-b588-bc764e2007e4; Tue, 24 Sep 2019 18:12:53 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A1202AF03; Tue, 24 Sep 2019 18:12:52 +0000 (UTC) From: Nicolas Saenz Julienne To: robh+dt@kernel.org, devicetree@vger.kernel.org, frowand.list@gmail.com, linux-arm-kernel@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, xen-devel@lists.xenproject.org, linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org Date: Tue, 24 Sep 2019 20:12:33 +0200 Message-Id: <20190924181244.7159-3-nsaenzjulienne@suse.de> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190924181244.7159-1-nsaenzjulienne@suse.de> References: <20190924181244.7159-1-nsaenzjulienne@suse.de> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 25 Sep 2019 04:16:20 +0000 Subject: [Xen-devel] [PATCH 02/11] of: base: introduce __of_n_*_cells_parent() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: f.fainelli@gmail.com, mbrugger@suse.com, wahrenst@gmx.net, james.quinlan@broadcom.com, robin.murphy@arm.com, Nicolas Saenz Julienne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Master PCI devices might not appear in the device tree, yet they still need to get the underlying cells properties in order to calculate the bus DMA constraints. This conflicts with of_n_*_cells() as it's designed under the assumption it'll receive a device OF node. Create __of_n_*_cells_parent() in order to deal with this limitation. For now, it'll only be available privately to OF code. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/base.c | 44 +++++++++++++++++++++++++++++------------ drivers/of/of_private.h | 3 +++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 1d667eb730e1..94f83051910c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -86,34 +86,52 @@ static bool __of_node_is_type(const struct device_node *np, const char *type) return np && match && type && !strcmp(match, type); } -int of_n_addr_cells(struct device_node *np) +int __of_n_addr_cells_parent(struct device_node *parent) { u32 cells; - do { - if (np->parent) - np = np->parent; - if (!of_property_read_u32(np, "#address-cells", &cells)) + while (parent) { + if (!of_property_read_u32(parent, "#address-cells", &cells)) return cells; - } while (np->parent); + + parent = parent->parent; + } + /* No #address-cells property for the root node */ return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; } + +int of_n_addr_cells(struct device_node *np) +{ + if (np->parent) + np = np->parent; + + return __of_n_addr_cells_parent(np); +} EXPORT_SYMBOL(of_n_addr_cells); -int of_n_size_cells(struct device_node *np) +int __of_n_size_cells_parent(struct device_node *parent) { u32 cells; - do { - if (np->parent) - np = np->parent; - if (!of_property_read_u32(np, "#size-cells", &cells)) + while (parent) { + if (!of_property_read_u32(parent, "#size-cells", &cells)) return cells; - } while (np->parent); - /* No #size-cells property for the root node */ + + parent = parent->parent; + } + + /* No #address-cells property for the root node */ return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; } + +int of_n_size_cells(struct device_node *np) +{ + if (np->parent) + np = np->parent; + + return __of_n_size_cells_parent(np); +} EXPORT_SYMBOL(of_n_size_cells); #ifdef CONFIG_NUMA diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 24786818e32e..b528304be244 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -39,6 +39,9 @@ extern struct mutex of_mutex; extern struct list_head aliases_lookup; extern struct kset *of_kset; +int __of_n_addr_cells_parent(struct device_node *parent); +int __of_n_size_cells_parent(struct device_node *parent); + #if defined(CONFIG_OF_DYNAMIC) extern int of_property_notify(int action, struct device_node *np, struct property *prop, struct property *old_prop);