From patchwork Fri Sep 27 00:24:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 174563 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp2787821ill; Thu, 26 Sep 2019 17:25:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAUClAnYZ9WdRO+/lrzkjxQX/WJpho9ptrj0tfN/yjyQSftWNfY/8IZ5RhnC/133KyUIud X-Received: by 2002:a17:906:24c8:: with SMTP id f8mr5561614ejb.119.1569543937415; Thu, 26 Sep 2019 17:25:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569543937; cv=none; d=google.com; s=arc-20160816; b=Qfmfr97A8s5VHTZLrQ+uW6essgwOR9vtR0EXo8RJfYcH4vHuSwcLx+W1BGonl3c1Eq r0HNlTkGUiYy671fXiCUnP1lwJj/O6m4Z9m9To8IttYxheBLuuIxbUcsySmy2U9QE786 2QPt+cGaLw0Ohr11uGvFaQLgDtZwgIlM2sb/NbsQcB4UmLFKPYh8NscrI8ehRSh5VtQB NfGuT9/Y6CO0UMWPSVCCeV7Bem+l9z7CT2RFx1LmDALg2bLCsE3MmMiywl3fJFz/TfHg CEU5RXmSWGQGqkcDrwDX+s/eUmmqdo18VnXcmudhyHxrZFuIei/lnYmCAUEkoJbbBFwl QRBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UKCh970cxpKTSE4xQt8EA5TvLAg6lDEOHEZjgVQOiEg=; b=vQ4cm64oWOkYPm5KFEInEj9GcjOkJJa9VhqhDfMZiiRJSAQz8sN6neg4jxqTzpjuxQ 3m9t8t1G5BrIqVe+0WrmgSrb2USmVL9hwjJqYotuXaIdQJmk6k0954jbd1i50dyVCCM/ NGO5LPnF7ptOyS1qRTzgsNhP5fgJGE4sSlpXKqbhqy9BwXNcLRhaJ6cEFvffVbbnhuKE LxEBAmguD14iKIgSFSWaNr1yFZr6gSmBZEML0r4CmF+gTriw3rdO34yKyiTdvLNVAbb+ rmPAxLUg/S5tX+wxEdkhn2xHr8UCM2d7Z7J7aqdB6p2dlHNwRJCd9u+u4Pq0V9yLfgLQ gWjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si565704edh.242.2019.09.26.17.25.35; Thu, 26 Sep 2019 17:25:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727502AbfI0AZf (ORCPT + 8 others); Thu, 26 Sep 2019 20:25:35 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:43244 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727901AbfI0AZK (ORCPT ); Thu, 26 Sep 2019 20:25:10 -0400 Received: by mail-oi1-f195.google.com with SMTP id t84so3722739oih.10; Thu, 26 Sep 2019 17:25:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UKCh970cxpKTSE4xQt8EA5TvLAg6lDEOHEZjgVQOiEg=; b=m5XwqiFEPWtXzRHdhcmEuQygNUQouhsLrY2JHWTLwtqq5PoobZbYBbU+pvp6Pv86T4 zKFmmaHDMIJdNrKNWILK2YLfjpagh6NpNpKk+geYxGfbyntI5DJ3lR57bAmQggJWaFNe fikGPltp5EMOy7riafYjMByhlXTfAqVaLKhMym5d84S2/CTBFDHvnVzTUjF4tG0SCMfO bTz5A6xsOi8EoYWqLJbOk/B47XR0KubRoCjwJfZtGVsznsBUcqtzuj/8q5H2DSvkcRsy zh9JTBZSoP8alAq8/dVcF6FumlTwfBSMsXi2SX9PLhowuI945KqN6mRMPxN629ktANF7 wJrg== X-Gm-Message-State: APjAAAW5ClND+nq5icmAYJQmaMe0cnWvML1G/wTJEQ1TferFYIMleKJp wvDrmcy+vbmlie1Iy0Z+i7RI+6w= X-Received: by 2002:a05:6808:316:: with SMTP id i22mr4935938oie.18.1569543908911; Thu, 26 Sep 2019 17:25:08 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id j11sm339866otk.80.2019.09.26.17.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:08 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Robin Murphy , Florian Fainelli , Stefan Wahren , Frank Rowand , Arnd Bergmann , Marek Vasut , Geert Uytterhoeven , Simon Horman , Lorenzo Pieralisi , Oza Pawandeep Subject: [PATCH 08/11] of: Factor out #{addr,size}-cells parsing Date: Thu, 26 Sep 2019 19:24:52 -0500 Message-Id: <20190927002455.13169-9-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190927002455.13169-1-robh@kernel.org> References: <20190927002455.13169-1-robh@kernel.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Robin Murphy In some cases such as PCI host controllers, we may have a "parent bus" which is an OF leaf node, but still need to correctly parse ranges from the point of view of that bus. For that, factor out variants of the "#addr-cells" and "#size-cells" parsers which do not assume they have a device node and thus immediately traverse upwards before reading the relevant property. Signed-off-by: Robin Murphy [robh: don't make of_bus_n_{addr,size}_cells() public] Signed-off-by: Rob Herring --- drivers/of/address.c | 2 ++ drivers/of/base.c | 32 ++++++++++++++++++++++---------- drivers/of/of_private.h | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-) -- 2.20.1 Reviewed-by: Geert Uytterhoeven diff --git a/drivers/of/address.c b/drivers/of/address.c index 3fd34f7ad772..887c0413f648 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -14,6 +14,8 @@ #include #include +#include "of_private.h" + /* Max address size we deal with */ #define OF_MAX_ADDR_CELLS 4 #define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS) diff --git a/drivers/of/base.c b/drivers/of/base.c index 55e7f5bb0549..12b2e9287117 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -86,34 +86,46 @@ 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_bus_n_addr_cells(struct device_node *np) { u32 cells; - do { - if (np->parent) - np = np->parent; + for (; np; np = np->parent) if (!of_property_read_u32(np, "#address-cells", &cells)) return cells; - } while (np->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_bus_n_addr_cells(np); +} EXPORT_SYMBOL(of_n_addr_cells); -int of_n_size_cells(struct device_node *np) +int of_bus_n_size_cells(struct device_node *np) { u32 cells; - do { - if (np->parent) - np = np->parent; + for (; np; np = np->parent) if (!of_property_read_u32(np, "#size-cells", &cells)) return cells; - } while (np->parent); + /* No #size-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_bus_n_size_cells(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 f8c58615c393..66294d29942a 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -158,6 +158,9 @@ extern void __of_sysfs_remove_bin_file(struct device_node *np, #define for_each_transaction_entry_reverse(_oft, _te) \ list_for_each_entry_reverse(_te, &(_oft)->te_list, node) +extern int of_bus_n_addr_cells(struct device_node *np); +extern int of_bus_n_size_cells(struct device_node *np); + #ifdef CONFIG_OF_ADDRESS extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size);