From patchwork Fri Sep 27 00:24:45 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: 11163563 X-Patchwork-Delegate: bhelgaas@google.com 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 9DCE414E5 for ; Fri, 27 Sep 2019 00:25:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C02620872 for ; Fri, 27 Sep 2019 00:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543950; bh=XiCTN29M9zpR9Gh2trmKYTPFx1Q5Bw5bm3kUcLU+ZgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=n3wZfdCZ1Dxtn5u6jhqVE8TdS+lJZx8gCMpYKIsLvMX3rGyZ1NMYW20kZ2WBAEDa5 wJo1Gd8JhZW+nUJIGxCj1jEK5M1rHlFExBb6k8DxINC6OjuW0SIsF6lBOJtOwTcXxI viPeZHBTHJ0IZL9WztmAuR7JEfN5POSqCFYJwNbE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbfI0AZB (ORCPT ); Thu, 26 Sep 2019 20:25:01 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:37191 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbfI0AZB (ORCPT ); Thu, 26 Sep 2019 20:25:01 -0400 Received: by mail-oi1-f196.google.com with SMTP id i16so3740969oie.4; Thu, 26 Sep 2019 17:24:59 -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=+w5IFIxhvLU+cAIOScJHHta0qaO4ZGZGm/wE8/ycgf8=; b=rJ8xxO+z4dT24fHthj0h9FrKmRoSWdet4bq92MPGKa+ydQYYgVLoe7mdZd8dyq+8+d tpItjzCHc4IUOVsZyAr0s4p5tG/m7dHfxeFTlJE42VohqtpDUSqVrFM5SU27t2x1rCPu VhEqOWjEgdDCRIN/EfxTa5ZSsje4P+1x3xronJL8ySpCVYvuZwjW8VIPAlDyv4IlIYTp OXZ6k9wS0cvWFxREoaNQHUVQFc3159Arqhzw6GHC4FeYsXR8DbEYec6YG4nWvO0ayO6h 0BT8XuMPkFfXBNEG73Asw82dCTVSmiNmdtvrBLsBYauEtd01IoJ6Sl+ACszkAXNXKckA cVKg== X-Gm-Message-State: APjAAAVx7jCk15PkIOrhr68qO9a00tFgXL4yFStxNgtcoeF38qxelt4O pnH46U4UNj4Wz7ONpVhXOtVitDI= X-Google-Smtp-Source: APXvYqz440W6O64cgvCu2OYrAyaV4fHohe2E6X1Kaj+k2yyGSBSVQGkq2l9TDw1R1g0urlwMQ3JhwA== X-Received: by 2002:aca:c0d6:: with SMTP id q205mr4827563oif.81.1569543898837; Thu, 26 Sep 2019 17:24:58 -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.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:24:58 -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 01/11] of: Remove unused of_find_matching_node_by_address() Date: Thu, 26 Sep 2019 19:24:45 -0500 Message-Id: <20190927002455.13169-2-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org of_find_matching_node_by_address() is unused, so remove it. Cc: Robin Murphy Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven Reviewed-by: Christoph Hellwig --- drivers/of/address.c | 19 ------------------- include/linux/of_address.h | 12 ------------ 2 files changed, 31 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 978427a9d5e6..0c3cf515c510 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -826,25 +826,6 @@ int of_address_to_resource(struct device_node *dev, int index, } EXPORT_SYMBOL_GPL(of_address_to_resource); -struct device_node *of_find_matching_node_by_address(struct device_node *from, - const struct of_device_id *matches, - u64 base_address) -{ - struct device_node *dn = of_find_matching_node(from, matches); - struct resource res; - - while (dn) { - if (!of_address_to_resource(dn, 0, &res) && - res.start == base_address) - return dn; - - dn = of_find_matching_node(dn, matches); - } - - return NULL; -} - - /** * of_iomap - Maps the memory mapped IO for a given device_node * @device: the device whose io range will be mapped diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 30e40fb6936b..e317f375374a 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -33,10 +33,6 @@ extern u64 of_translate_dma_address(struct device_node *dev, extern u64 of_translate_address(struct device_node *np, const __be32 *addr); extern int of_address_to_resource(struct device_node *dev, int index, struct resource *r); -extern struct device_node *of_find_matching_node_by_address( - struct device_node *from, - const struct of_device_id *matches, - u64 base_address); extern void __iomem *of_iomap(struct device_node *device, int index); void __iomem *of_io_request_and_map(struct device_node *device, int index, const char *name); @@ -71,14 +67,6 @@ static inline u64 of_translate_address(struct device_node *np, return OF_BAD_ADDR; } -static inline struct device_node *of_find_matching_node_by_address( - struct device_node *from, - const struct of_device_id *matches, - u64 base_address) -{ - return NULL; -} - static inline const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, unsigned int *flags) { From patchwork Fri Sep 27 00:24:46 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: 11163561 X-Patchwork-Delegate: bhelgaas@google.com 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 6EF3614E5 for ; Fri, 27 Sep 2019 00:25:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4DC3E20872 for ; Fri, 27 Sep 2019 00:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543949; bh=o+I7s02TcoZpTHqx/C2Q9bnm5GWdX+6+g/oMvUM0ou4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=GGh5rYa8j+Mm4fnqRgC8tkIOjR7AGSiINLotFmTMy2eV2bNPuR4P/0F4puImtmn+z 8qc6AhwZTiMj9OTNEhTV+eAc1y/5cuE4NG37a5AW11FdE539TKWatybDyoBo4cgtcP 6SBfpdSN/PxODSxBNwIc0dfDRSHWKOjaVNMiM5IY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727323AbfI0AZC (ORCPT ); Thu, 26 Sep 2019 20:25:02 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:36434 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726664AbfI0AZB (ORCPT ); Thu, 26 Sep 2019 20:25:01 -0400 Received: by mail-oi1-f193.google.com with SMTP id k20so3749633oih.3; Thu, 26 Sep 2019 17:25:01 -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=bFnIODxLI07lEZcLoD/U0DfHP6ZA4NBNR5sSatiO5f0=; b=Tmp8sZoJpBkcnHybmmcyW9scGfrjYcXWPKB3fPk7Z1CEjJmIqYcSfkIsjsbi8XF242 5+5D+I4vbRglrv6ibY+memPOOUuReLDH68qtGiqob8jld5UT6enlWGY7c8YSrBWs7JHh K2qd7x+E6n5pVBId6aLpjk1EAPbM0PPHgzxdRlh89WeQRP4Wym3avv77ZZwon0ZFZJiJ 9ATxEUHxn1Slt0SG5xU0tV97eeyY1cuSyypQNqq7FTMqgB7cvS0myTWqCfU7SkLp/c/Y p2fyQ8FKB6nQzDbfMUxndD2+zTGoo++aK+RKnH4mLSkCnKnSZlNA520nc6IKhsYQMUc+ dXcg== X-Gm-Message-State: APjAAAU2mSG9Sg7lJ9s8NL6OxVH7j1f0dUuAC0kanzh2ydCARKMpAwFZ I7Ap0zcQjk/1VbfjyXpiYFgm9/w= X-Google-Smtp-Source: APXvYqwWVfPVt77YLh4Gv2K4ppvWZ2WTrZfJ1ydtavZRgfmvlui1t3teRXd2GNnOw0HXgwd3DJ7LBA== X-Received: by 2002:aca:3ed7:: with SMTP id l206mr4922395oia.25.1569543900588; Thu, 26 Sep 2019 17:25:00 -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.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:24:59 -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 02/11] of: Make of_dma_get_range() private Date: Thu, 26 Sep 2019 19:24:46 -0500 Message-Id: <20190927002455.13169-3-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org of_dma_get_range() is only used within the DT core code, so remove the export and move the header declaration to the private header. Cc: Robin Murphy Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven Reviewed-by: Christoph Hellwig --- drivers/of/address.c | 1 - drivers/of/of_private.h | 11 +++++++++++ include/linux/of_address.h | 8 -------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 0c3cf515c510..8e354d12fb04 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -972,7 +972,6 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz return ret; } -EXPORT_SYMBOL_GPL(of_dma_get_range); /** * of_dma_is_coherent - Check if device is coherent diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 24786818e32e..f8c58615c393 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -158,4 +158,15 @@ 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) +#ifdef CONFIG_OF_ADDRESS +extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, + u64 *paddr, u64 *size); +#else +static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr, + u64 *paddr, u64 *size) +{ + return -ENODEV; +} +#endif + #endif /* _LINUX_OF_PRIVATE_H */ diff --git a/include/linux/of_address.h b/include/linux/of_address.h index e317f375374a..ddda3936039c 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -51,8 +51,6 @@ extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser, extern struct of_pci_range *of_pci_range_parser_one( struct of_pci_range_parser *parser, struct of_pci_range *range); -extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, - u64 *paddr, u64 *size); extern bool of_dma_is_coherent(struct device_node *np); #else /* CONFIG_OF_ADDRESS */ static inline void __iomem *of_io_request_and_map(struct device_node *device, @@ -92,12 +90,6 @@ static inline struct of_pci_range *of_pci_range_parser_one( return NULL; } -static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr, - u64 *paddr, u64 *size) -{ - return -ENODEV; -} - static inline bool of_dma_is_coherent(struct device_node *np) { return false; From patchwork Fri Sep 27 00:24:47 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: 11163559 X-Patchwork-Delegate: bhelgaas@google.com 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 5CD0713B1 for ; Fri, 27 Sep 2019 00:25:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39AAB217F4 for ; Fri, 27 Sep 2019 00:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543945; bh=riRAkZ8l8hFPE7m70G3+0gIIIDl90zbB9gBE+44Yftk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=ZehAjBW9wHTP6l9F0uV+8P+q2XZaCeNoB9oVn49xm7t2fBauX3J9YEyujpQoqWtkH fgueW1M1deeB9oX1CS4xnwYRRGZd7LjifDp98g4zF3GOhggaHtHubQII8VM6Ny1bSN s9CdICv1Izt6VhqxmNjx8vfQ6jTDi+CcM98bFrRE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727592AbfI0AZD (ORCPT ); Thu, 26 Sep 2019 20:25:03 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:32868 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbfI0AZD (ORCPT ); Thu, 26 Sep 2019 20:25:03 -0400 Received: by mail-ot1-f65.google.com with SMTP id o9so6809otl.0; Thu, 26 Sep 2019 17:25:02 -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=JkoxCwhnPe0SFeKySMCtF/hXJiLiKDyHZ2P8cGCAjJ4=; b=Z2umiizmy2F46GCtFv/rEpEMlzwFe4iMjl99d8mFPgLtZElqsGJ3hLucgRPEPlM/Z3 sipX8quj6lthD2Yi1H62hcOvO/jLTw3mxdzleNGnGPSFKqCJR3jVUbmei+wd3BfjNdBr xyUs11VC1J7lhUQMP1WVJHLwhHKpcy25xBoSudrRPfwGCxzg9Z3nUcrzCtbKrfXso1hw S68umZSleNs/xnYUq6t0+xGS68xMexG2COiBY2Fvz4iv6bz8tB5OZvL9RPrFyFDAT9jW Q9Hj5MHynHYAhAo3iU1Bcgb4xR9yYBVZZlv6e1p2WPxbGa82if6Aiw269/+nRhNmkN7t FIpQ== X-Gm-Message-State: APjAAAWydiRvx8Li8EBnz0Q1XTNfTznFEQ1HbWnGcWSjU760Vwli/6cT sxgOEyX3oQQd1ZR8OtdcCjhkkSM= X-Google-Smtp-Source: APXvYqxZR3T1urKVEgD2urD3ZJXLbAOnRlRfEvJiEt8IQGqUlVsJBTO9efMTTpeSgg0sC4mgieqBMg== X-Received: by 2002:a9d:4e0b:: with SMTP id p11mr1184024otf.280.1569543901894; Thu, 26 Sep 2019 17:25:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:01 -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 03/11] of: address: Report of_dma_get_range() errors meaningfully Date: Thu, 26 Sep 2019 19:24:47 -0500 Message-Id: <20190927002455.13169-4-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Robin Murphy If we failed to translate a DMA address, at least show the offending address rather than the uninitialised contents of the destination argument. Signed-off-by: Robin Murphy Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven Reviewed-by: Christoph Hellwig --- drivers/of/address.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 8e354d12fb04..53d2656c2269 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -955,8 +955,8 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz dmaaddr = of_read_number(ranges, naddr); *paddr = of_translate_dma_address(np, ranges); if (*paddr == OF_BAD_ADDR) { - pr_err("translation of DMA address(%pad) to CPU address failed node(%pOF)\n", - dma_addr, np); + pr_err("translation of DMA address(%llx) to CPU address failed node(%pOF)\n", + dmaaddr, np); ret = -EINVAL; goto out; } From patchwork Fri Sep 27 00:24:48 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: 11163555 X-Patchwork-Delegate: bhelgaas@google.com 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 D6E3B14E5 for ; Fri, 27 Sep 2019 00:25:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB6A420835 for ; Fri, 27 Sep 2019 00:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543943; bh=g9Em8w3tSjrn7vXBNuyNK9kHuhLpk6I/HXQKSsMdcnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kFAwyZ6zH7CRUyl1Gh1zhyMvcDaMgscZLIccNJBKRTNl833b3fxH0AXInI4Y2AxbI JPXrdmpEHd1yKh4jcu9hiKC0oRKcCiAii2UuH5nIYAitat04yfIcNADr4gS1hMvlaL FVk5fzf27NgppVNFRqRkJr7jEHQkyaLtKDtIEy44= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727775AbfI0AZG (ORCPT ); Thu, 26 Sep 2019 20:25:06 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:42539 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbfI0AZG (ORCPT ); Thu, 26 Sep 2019 20:25:06 -0400 Received: by mail-oi1-f194.google.com with SMTP id i185so3713856oif.9; Thu, 26 Sep 2019 17:25:04 -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=80wnyFMJy45OToJ2Qn6gUBxEzekXteJX990/5YkKFnw=; b=DuBvgH3/DdWz5nwPfeHrshqEdOV7Fq/nE4r/ReqI0VnM63P6OD3ZH+2X4gZgIrH+m6 yHSiiKbsSPqJYNpqEHsv3FK/ubzztuox3axKh/F+Fetj1BjFsm2Er3TUhq3hYtEQbb8f j2EX5Lq0VQMVASmGEOGXUv/ywQpqyT6eK11pTLIl3pDw0LPC5Yl3MRv3+oFnTxj0W4e8 l1X6W17BuJpMjV9q+JFDF7xs3beBdM6GINlHywG50tgeMc6NztLzPzmyQ1YvAPFehPnm pmBvDNB6/IDSz/TLhewSyUSxH4R2a1Xptyo5X/uN3XnyEbP/Co+kxt3yawTaZ1VPO+Gl Zf9Q== X-Gm-Message-State: APjAAAVhUD4868Pd9ZPgrfenRdTyghBh9Oa5QhKw/l/ssHqTDQlztxe4 gjy6U0sqekPbEoDvVy9V7p/ghCk= X-Google-Smtp-Source: APXvYqxz/X9nzzW8lZv2efDM6lGTA/yrwcSDDcujHOurhrkdl9XLDCRUqcE4TxLsZ4JMtZCq7n2nhA== X-Received: by 2002:aca:703:: with SMTP id 3mr4647438oih.118.1569543903216; Thu, 26 Sep 2019 17:25:03 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:02 -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 04/11] of/unittest: Add dma-ranges address translation tests Date: Thu, 26 Sep 2019 19:24:48 -0500 Message-Id: <20190927002455.13169-5-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The functions for parsing 'dma-ranges' ranges are buggy and fail to handle several conditions. Add new tests for of_dma_get_range() and for_each_of_pci_range(). With this test, we get 5 new failures which are fixed in subsequent commits: OF: translation of DMA address(0) to CPU address failed node(/testcase-data/address-tests/device@70000000) FAIL of_unittest_dma_ranges_one():798 of_dma_get_range failed on node /testcase-data/address-tests/device@70000000 rc=-22 OF: translation of DMA address(10000000) to CPU address failed node(/testcase-data/address-tests/bus@80000000/device@1000) FAIL of_unittest_dma_ranges_one():798 of_dma_get_range failed on node /testcase-data/address-tests/bus@80000000/device@1000 rc=-22 OF: translation of DMA address(0) to CPU address failed node(/testcase-data/address-tests/pci@90000000) FAIL of_unittest_dma_ranges_one():798 of_dma_get_range failed on node /testcase-data/address-tests/pci@90000000 rc=-22 FAIL of_unittest_pci_dma_ranges():851 for_each_of_pci_range wrong CPU addr (d0000000) on node /testcase-data/address-tests/pci@90000000 FAIL of_unittest_pci_dma_ranges():861 for_each_of_pci_range wrong CPU addr (ffffffffffffffff) on node /testcase-data/address-tests/pci@90000000 Cc: Robin Murphy Signed-off-by: Rob Herring --- drivers/of/unittest-data/testcases.dts | 1 + drivers/of/unittest-data/tests-address.dtsi | 48 +++++++++++ drivers/of/unittest.c | 92 +++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 drivers/of/unittest-data/tests-address.dtsi diff --git a/drivers/of/unittest-data/testcases.dts b/drivers/of/unittest-data/testcases.dts index 55fe0ee20109..a85b5e1c381a 100644 --- a/drivers/of/unittest-data/testcases.dts +++ b/drivers/of/unittest-data/testcases.dts @@ -15,5 +15,6 @@ #include "tests-phandle.dtsi" #include "tests-interrupts.dtsi" #include "tests-match.dtsi" +#include "tests-address.dtsi" #include "tests-platform.dtsi" #include "tests-overlay.dtsi" diff --git a/drivers/of/unittest-data/tests-address.dtsi b/drivers/of/unittest-data/tests-address.dtsi new file mode 100644 index 000000000000..3fe5d3987beb --- /dev/null +++ b/drivers/of/unittest-data/tests-address.dtsi @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 + +/ { + #address-cells = <1>; + #size-cells = <1>; + + testcase-data { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + address-tests { + #address-cells = <1>; + #size-cells = <1>; + /* ranges here is to make sure we don't use it for + * dma-ranges translation */ + ranges = <0x70000000 0x70000000 0x40000000>, + <0x00000000 0xd0000000 0x20000000>; + dma-ranges = <0x0 0x20000000 0x40000000>; + + device@70000000 { + reg = <0x70000000 0x1000>; + }; + + bus@80000000 { + #address-cells = <1>; + #size-cells = <1>; + ranges = <0x0 0x80000000 0x100000>; + dma-ranges = <0x10000000 0x0 0x40000000>; + + device@1000 { + reg = <0x1000 0x1000>; + }; + }; + + pci@90000000 { + device_type = "pci"; + #address-cells = <3>; + #size-cells = <2>; + reg = <0x90000000 0x1000>; + ranges = <0x42000000 0x0 0x40000000 0x40000000 0x0 0x10000000>; + dma-ranges = <0x42000000 0x0 0x80000000 0x00000000 0x0 0x10000000>, + <0x42000000 0x0 0xc0000000 0x20000000 0x0 0x10000000>; + }; + + }; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e6b175370f2e..3969075194c5 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -779,6 +780,95 @@ static void __init of_unittest_changeset(void) #endif } +static void __init of_unittest_dma_ranges_one(const char *path, + u64 expect_dma_addr, u64 expect_paddr, u64 expect_size) +{ + struct device_node *np; + u64 dma_addr, paddr, size; + int rc; + + np = of_find_node_by_path(path); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + rc = of_dma_get_range(np, &dma_addr, &paddr, &size); + + unittest(!rc, "of_dma_get_range failed on node %pOF rc=%i\n", np, rc); + if (!rc) { + unittest(size == expect_size, + "of_dma_get_range wrong size on node %pOF size=%llx\n", np, size); + unittest(paddr == expect_paddr, + "of_dma_get_range wrong phys addr (%llx) on node %pOF", paddr, np); + unittest(dma_addr == expect_dma_addr, + "of_dma_get_range wrong DMA addr (%llx) on node %pOF", dma_addr, np); + } + of_node_put(np); +} + +static void __init of_unittest_parse_dma_ranges(void) +{ + of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000", + 0x0, 0x20000000, 0x40000000); + of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000", + 0x10000000, 0x20000000, 0x40000000); + of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000", + 0x80000000, 0x20000000, 0x10000000); +} + +static void __init of_unittest_pci_dma_ranges(void) +{ + struct device_node *np; + struct of_pci_range range; + struct of_pci_range_parser parser; + int i = 0; + + if (!IS_ENABLED(CONFIG_PCI)) + return; + + np = of_find_node_by_path("/testcase-data/address-tests/pci@90000000"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + if (of_pci_dma_range_parser_init(&parser, np)) { + pr_err("missing dma-ranges property\n"); + return; + } + + /* + * Get the dma-ranges from the device tree + */ + for_each_of_pci_range(&parser, &range) { + if (!i) { + unittest(range.size == 0x10000000, + "for_each_of_pci_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0x20000000, + "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.pci_addr == 0x80000000, + "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF", + range.pci_addr, np); + } else { + unittest(range.size == 0x10000000, + "for_each_of_pci_range wrong size on node %pOF size=%llx\n", + np, range.size); + unittest(range.cpu_addr == 0x40000000, + "for_each_of_pci_range wrong CPU addr (%llx) on node %pOF", + range.cpu_addr, np); + unittest(range.pci_addr == 0xc0000000, + "for_each_of_pci_range wrong DMA addr (%llx) on node %pOF", + range.pci_addr, np); + } + i++; + } + + of_node_put(np); +} + static void __init of_unittest_parse_interrupts(void) { struct device_node *np; @@ -2552,6 +2642,8 @@ static int __init of_unittest(void) of_unittest_changeset(); of_unittest_parse_interrupts(); of_unittest_parse_interrupts_extended(); + of_unittest_parse_dma_ranges(); + of_unittest_pci_dma_ranges(); of_unittest_match_node(); of_unittest_platform_populate(); of_unittest_overlay(); From patchwork Fri Sep 27 00:24:49 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: 11163557 X-Patchwork-Delegate: bhelgaas@google.com 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 A7E4314E5 for ; Fri, 27 Sep 2019 00:25:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85C18217F4 for ; Fri, 27 Sep 2019 00:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543944; bh=eqboXYYEr1L5MwwNkv+KGk8gZLgSNHFZESSGK+6zWrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Qhh92VSd/NbDJ597VggKtBhH8YWhEVO3fu+ZGRxJK553uz4htek/yiH1QYhjq7QAz Y6CVtAiZdg/0G9iZR9rMBoGAN6gIYDsQPH5e8mSogE0uiMj1Km5KIMNuLvGsZqZxTR t+gVzj/mCp0tx7LmUJaVH/+gdKuSGtCu/jwr/OHU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727707AbfI0AZG (ORCPT ); Thu, 26 Sep 2019 20:25:06 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:40575 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727682AbfI0AZF (ORCPT ); Thu, 26 Sep 2019 20:25:05 -0400 Received: by mail-oi1-f195.google.com with SMTP id k9so3726634oib.7; Thu, 26 Sep 2019 17:25:05 -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=/FdaUd4Foou3uzALlTE4nuHwXAnVOybAVTlMM/NfMxM=; b=MWof7LvYsCAN8OEjOTq0UogPE5mr2Nw/a5/2+XNVhQQ1p4gBJhJFekeCHLO0zbfXbI ajIJX8wi+NBFVaWA6DnPoW1X2B8RkbQ4fJAeWGvxaZQW0M7qWQ5sVJtbikqgs65Nj5xe LP6hfOVbPmjuUGzy4VF9qimsU04Fp/A9E6b9vlZUD2lNNb9gu16dHzUoq+nQxL8WbqbZ Mq7bQ6sX/O1iPVLDTmfkwQrZXspFgWURIAWRyNHLOfjcy69/xlkU4SLaToGmlA41Sh2C Gd/NcYHFwFA4WFKJYwG7JunSyx/ullo11nQHPCXsHY2rUqTw5YTgbUxmneS7h14gXmqc CdQw== X-Gm-Message-State: APjAAAWuZlaWQZ510DQMXW77zAVbnaC75LNjWR0JFpQzQT1MgEkqG635 hjnei1f3UaK4WmLvz6bR+K/Tjz4= X-Google-Smtp-Source: APXvYqxes6fLBSO8a/NFYc1ZhLQ2DJ3dk3ZrSbyT+sGdDBiq/Yncolj5jjG+yPBb+Q9ycO7s7d945A== X-Received: by 2002:aca:fdc9:: with SMTP id b192mr4641000oii.50.1569543904799; Thu, 26 Sep 2019 17:25:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:04 -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 05/11] of: Ratify of_dma_configure() interface Date: Thu, 26 Sep 2019 19:24:49 -0500 Message-Id: <20190927002455.13169-6-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Robin Murphy For various DMA masters not directly represented in DT, we pass the OF node of their parent or bridge device as the master_np argument to of_dma_configure(), such that they can inherit the appropriate DMA configuration from whatever is described there. This creates an ambiguity for properties which are not valid for a device itself but only for its parent bus, since we don't know whether to start looking for those at master_np or master_np->parent. Fortunately, the de-facto interface since the prototype change in 1f5c69aa51f9 ("of: Move of_dma_configure() to device.c to help re-use") is pretty clear-cut: either master_np is redundant with dev->of_node, or dev->of_node is NULL and master_np is already the relevant parent. Let's formally ratify that so we can start relying on it. Signed-off-by: Robin Murphy Signed-off-by: Rob Herring --- drivers/of/device.c | 12 ++++++++++-- include/linux/of_device.h | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index da8158392010..a45261e21144 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -75,7 +75,8 @@ int of_device_add(struct platform_device *ofdev) /** * of_dma_configure - Setup DMA configuration * @dev: Device to apply DMA configuration - * @np: Pointer to OF node having DMA configuration + * @parent: OF node of parent device having DMA configuration, if + * @dev->of_node is NULL (ignored otherwise) * @force_dma: Whether device is to be set up by of_dma_configure() even if * DMA capability is not explicitly described by firmware. * @@ -86,15 +87,22 @@ int of_device_add(struct platform_device *ofdev) * can use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE events * to fix up DMA configuration. */ -int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma) +int of_dma_configure(struct device *dev, struct device_node *parent, bool force_dma) { u64 dma_addr, paddr, size = 0; int ret; bool coherent; unsigned long offset; const struct iommu_ops *iommu; + struct device_node *np; u64 mask; + np = dev->of_node; + if (!np) + np = parent; + if (!np) + return -ENODEV; + ret = of_dma_get_range(np, &dma_addr, &paddr, &size); if (ret < 0) { /* diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 8d31e39dd564..a4fe418e57f6 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -56,7 +56,7 @@ static inline struct device_node *of_cpu_device_node_get(int cpu) } int of_dma_configure(struct device *dev, - struct device_node *np, + struct device_node *parent, bool force_dma); #else /* CONFIG_OF */ @@ -107,7 +107,7 @@ static inline struct device_node *of_cpu_device_node_get(int cpu) } static inline int of_dma_configure(struct device *dev, - struct device_node *np, + struct device_node *parent, bool force_dma) { return 0; From patchwork Fri Sep 27 00:24:50 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: 11163553 X-Patchwork-Delegate: bhelgaas@google.com 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 73C9A13B1 for ; Fri, 27 Sep 2019 00:25:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 52B9C20872 for ; Fri, 27 Sep 2019 00:25:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543941; bh=CVVhYXn3jmsV2VMLYSZbofFoPr26FJDeYI9Zg8HIPUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=B2mQFGKQIa5j+Hjtke72Po7WLMgn01tmAiXRsCBK27eMrBcQztpyO4VJaV98Omlfj dFC8/y6ygfXXdAXLkMyInZOADL08lAaiIo+arVZRVACEYsAljxpUVHKnP3jKCGoOQW D8HrMDo5Dowd0wFR6k3ainjxMAlAnASey69bO/4g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727828AbfI0AZI (ORCPT ); Thu, 26 Sep 2019 20:25:08 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:38700 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbfI0AZH (ORCPT ); Thu, 26 Sep 2019 20:25:07 -0400 Received: by mail-oi1-f196.google.com with SMTP id m16so3747036oic.5; Thu, 26 Sep 2019 17:25:06 -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=+Kwduh2L3Q3wglxQRQFNc0vVRF7aZPumhA9/VlLU+NE=; b=mjhcUDE8XUiETIYkOZkncJVwXFfDn3+5OtMOKkMygQtL0EMH6+dzILudd6EoFv4LRt NFOVho6exq84wuyEEwcJayqJJ6hzsSz6HAQK1rgWBpW1V52UgdUZe3AHwUtVGOGK73Y+ aw0vdIsvkAPuEyEvBkTE3pZmOdTDD7jIw35WNmM9Bx/iLhYrfQCtF7sZ0k7O4VdRjGbC LV4eBoFPJeKw4wt+FWwOuntgjxUqw9mhdypHpHS2W5oyE5EoT2EUSW7YqLecLlAfMsWl lD+3oBlaBBxy4s1L0rVECGMI0c5BFFOXhHwwxeKXX0kWFzxrj9kvJ9bT72PyFp6Uf5fX UN/A== X-Gm-Message-State: APjAAAW8KwnBEzAcWpKg7+K+BIwbrJgcq/hMxW7G8FI6SvMK3qn+OlK/ 0U7Iss5M88wxi5UOZ4txzZdhKvY= X-Google-Smtp-Source: APXvYqwZ4lR/YWP5vXy1ugIkWQ7hYP0e0FO8/TUE1SqXSQM+108Okq4ee9Kd9IvMs2n7+cX5zbFRVg== X-Received: by 2002:aca:540a:: with SMTP id i10mr4633085oib.108.1569543906002; Thu, 26 Sep 2019 17:25:06 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:05 -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 06/11] of/address: Introduce of_get_next_dma_parent() helper Date: Thu, 26 Sep 2019 19:24:50 -0500 Message-Id: <20190927002455.13169-7-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Robin Murphy Add of_get_next_dma_parent() helper which is similar to __of_get_dma_parent(), but can be used in iterators and decrements the ref count on the prior parent. Signed-off-by: Robin Murphy Signed-off-by: Rob Herring Reviewed-by: Geert Uytterhoeven --- drivers/of/address.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index 53d2656c2269..e9188c82fdae 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -695,6 +695,16 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np) return of_node_get(args.np); } +static struct device_node *of_get_next_dma_parent(struct device_node *np) +{ + struct device_node *parent; + + parent = __of_get_dma_parent(np); + of_node_put(np); + + return parent; +} + u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) { struct device_node *host; From patchwork Fri Sep 27 00:24:51 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: 11163551 X-Patchwork-Delegate: bhelgaas@google.com 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 A10C513B1 for ; Fri, 27 Sep 2019 00:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7794421928 for ; Fri, 27 Sep 2019 00:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543939; bh=TW56rIG2SiRPy1ax8TLIYREnvHKrp/VdmZ3Xn8dfBOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sZ72mHZ5lffM8RhWsui5+YKdKB6rbMa1rjy8Yh6jyVIlHUHtn+nbLuM1El+ThhsZI ydFkuEtVZKEyM5tpiiB+ipGcZPJFBauiHbW3SJSJ8EbGo22Su7zd9ZrNW7752CoqL4 b/e9ADUoxd1nCJEE+qTfTPEAJpIhUxFXau8/WTZM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727898AbfI0AZJ (ORCPT ); Thu, 26 Sep 2019 20:25:09 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:38700 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727862AbfI0AZI (ORCPT ); Thu, 26 Sep 2019 20:25:08 -0400 Received: by mail-oi1-f195.google.com with SMTP id m16so3747063oic.5; Thu, 26 Sep 2019 17:25:08 -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=2eJmO98TJvWjef7NL2xv0z4jdHs/rDOAySInsQ51HYo=; b=qvhDAxBAoQbm3dv5rQzxbn/qYzKGe8M9Q8bRLb1NFqcCmGIreODiyDFEQhX9QBXu03 k8mnioCWIxWn3N1Hponxx0o49k3m1IPao1UKyYUYcmUkdGJG6oUsErr6jkg4DRTSDk+B YSy+hiPm2eqiuoF2QEbEE1KkAhixZKy1F1c17IH8/1Bz023JjY8lQlGqzME+PMUzxUqu 2ZkOXfhu1cRGDXMCwB116cyUuYcm358yoBv8vQp/OSBeqE/PTLcl6slgqWghwTaOjOSW bT3p2KGcxoscq01EMRp1Yzig/pS+Gc72JiOO0u38A9NQgBBcdd0n5UkiBc/j8hn7gq3x Qolg== X-Gm-Message-State: APjAAAWfW33ukipWuz5cmvm3nBsPPsoXjTYni3uUE7tnrUo+nnW/hDg6 8cwV4MwoyfhtI2iRk7Z8m+N3sOA= X-Google-Smtp-Source: APXvYqymF9L96mPxVpqSA9nOQNOKKwoPIHBbCEwP0jWqbUfs1Sl2A8wDMIuZP/zjDv51L0/QcKzRIQ== X-Received: by 2002:aca:4890:: with SMTP id v138mr5031090oia.57.1569543907590; Thu, 26 Sep 2019 17:25:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:07 -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 07/11] of: address: Follow DMA parent for "dma-coherent" Date: Thu, 26 Sep 2019 19:24:51 -0500 Message-Id: <20190927002455.13169-8-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Robin Murphy Much like for address translation, when checking for DMA coherence we should be sure to walk up the DMA hierarchy, rather than the MMIO one, now that we can accommodate them being different. Signed-off-by: Robin Murphy Signed-off-by: Rob Herring --- drivers/of/address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index e9188c82fdae..3fd34f7ad772 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -999,7 +999,7 @@ bool of_dma_is_coherent(struct device_node *np) of_node_put(node); return true; } - node = of_get_next_parent(node); + node = of_get_next_dma_parent(node); } of_node_put(node); return false; 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: 11163549 X-Patchwork-Delegate: bhelgaas@google.com 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 4CF1B14E5 for ; Fri, 27 Sep 2019 00:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BBC5214D9 for ; Fri, 27 Sep 2019 00:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543939; bh=J7sWdxRgrOR09Y/rcYcUVrJ5/VoRuKBI2nIdBcq4qpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lsOh/BE0aS+o9cfaWXcczOQzpBpZzGZlokDDE2srLlYZevtP/7lkkkgDfPNs1J8jM hNshVlxleHA+rQlIpUuoJgYtvQpFGwLgC9nx492Xp/p2P7RZB+S2oroOrDH+6i/GRj QJslUpiVI5FxkO3r4Jl7yZWHQh+eEZKez6up7RNg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728426AbfI0AZf (ORCPT ); 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-Google-Smtp-Source: APXvYqy1CQ/pJ4u81ZjOTBygjp0HyvnzRjfsumqlZMQhMMHtdm91xx5NicQ33wJ1JMQxCbhI++4dWg== 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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@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 Reviewed-by: Geert Uytterhoeven --- drivers/of/address.c | 2 ++ drivers/of/base.c | 32 ++++++++++++++++++++++---------- drivers/of/of_private.h | 3 +++ 3 files changed, 27 insertions(+), 10 deletions(-) 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); From patchwork Fri Sep 27 00:24:53 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: 11163545 X-Patchwork-Delegate: bhelgaas@google.com 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 DC17113B1 for ; Fri, 27 Sep 2019 00:25:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BABBA214D9 for ; Fri, 27 Sep 2019 00:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543930; bh=p3HmVGXM7DdgD58As3jzBMAl/M661nD3DvZcbuQJWsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=IbN1reKiFvooEN/VmsjCH+NHecXREMfnXwf7JWzLeE05AJbU7n6cErxIGwuY9uYb+ rqVXl5cATPJmugHxBa7kU1GKhin6zkwiVfKxZ9NsUDApZF3MV+TsDOXQJlQ0LPSuk9 ICLl8ETr/WwcSUaAeRVsuk7cRhCcJ4eGNFfKnm5U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727999AbfI0AZ3 (ORCPT ); Thu, 26 Sep 2019 20:25:29 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:40639 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbfI0AZL (ORCPT ); Thu, 26 Sep 2019 20:25:11 -0400 Received: by mail-ot1-f65.google.com with SMTP id y39so772543ota.7; Thu, 26 Sep 2019 17:25:10 -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=+t0HPsSboHAO+BoQ/6wZRtvX50rdRybsdCc4k/BGGOU=; b=Y2hs8wibHQWRr9khsCPMVE7x/hYmz8VyFMKZ7nsDW7EIqQ7FLtWyycylbMydY2OFwx Pdys6HOTJedGiOWVIt1qrvcRZniQPMhkminsdr3hZF0IOJ09Tc42bo7be1VJn0Co5eUX pWRbgyP/b4IUJWS92vjTzh0ubYwn/c4EN87ALJWhSeAFKTYV1rPEEBhDZkFCigjCAKLq BxApUizG0eaTvxc8xGbRKee0L5Xb0b7rZbcag6mWLMIY9O7fSZBw4m00kNdJ9pgOAIOD PvtYZE3xsca4YaRzP5yQh2XBW74ebhCI9kq5c55PPAfg5fo0kc4QaqjrMBqikEZsk0Te BT7A== X-Gm-Message-State: APjAAAWMH2ouL60j8rvfksR3DOLTw5q4EsclXPIgapS167oZhIn2X4um pm6eqnyUsRrgBl1uV3nvNv22SCY= X-Google-Smtp-Source: APXvYqwlqui2UKuMtp8r6la4AcjByFeStlouN8pLtfIFhhyhtZVP8xij2Q0PurThyDu0Z4XEh1j7IQ== X-Received: by 2002:a05:6830:4a5:: with SMTP id l5mr991746otd.150.1569543910071; Thu, 26 Sep 2019 17:25:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:09 -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 09/11] of: Make of_dma_get_range() work on bus nodes Date: Thu, 26 Sep 2019 19:24:53 -0500 Message-Id: <20190927002455.13169-10-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Robin Murphy Since the "dma-ranges" property is only valid for a node representing a bus, of_dma_get_range() currently assumes the node passed in is a leaf representing a device, and starts the walk from its parent. In cases like PCI host controllers on typical FDT systems, however, where the PCI endpoints are probed dynamically the initial leaf node represents the 'bus' itself, and this logic means we fail to consider any "dma-ranges" describing the host bridge itself. Rework the logic such that of_dma_get_range() works correctly starting from a bus node containing "dma-ranges". Signed-off-by: Robin Murphy [robh: Allow for the bus child node to still be passed in] Signed-off-by: Rob Herring --- drivers/of/address.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 887c0413f648..e918001c7798 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -922,18 +922,9 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz if (!node) return -EINVAL; - while (1) { - struct device_node *parent; - - naddr = of_n_addr_cells(node); - nsize = of_n_size_cells(node); - - parent = __of_get_dma_parent(node); - of_node_put(node); - - node = parent; - if (!node) - break; + while (node) { + naddr = of_bus_n_addr_cells(node); + nsize = of_bus_n_size_cells(node); ranges = of_get_property(node, "dma-ranges", &len); @@ -941,12 +932,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz if (ranges && len > 0) break; - /* - * At least empty ranges has to be defined for parent node if - * DMA is supported - */ - if (!ranges) - break; + node = of_get_next_dma_parent(node); } if (!ranges) { @@ -965,7 +951,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz * size : nsize cells */ dmaaddr = of_read_number(ranges, naddr); - *paddr = of_translate_dma_address(np, ranges); + *paddr = of_translate_dma_address(node, ranges + naddr); if (*paddr == OF_BAD_ADDR) { pr_err("translation of DMA address(%llx) to CPU address failed node(%pOF)\n", dmaaddr, np); From patchwork Fri Sep 27 00:24:54 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: 11163541 X-Patchwork-Delegate: bhelgaas@google.com 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 3F6391800 for ; Fri, 27 Sep 2019 00:25:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EF43208C3 for ; Fri, 27 Sep 2019 00:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543918; bh=6qoA07OIW8RH23zhkZZfOhsC7wpaGKGZRjf9OKHFSyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=A91WWNeybuvbSZMRJhds9yI2e2q3yOXDuhJ5NAecniWLu6bWxbMlcu2IdrNsCUoKA E0pnhKsPnIcaISXRfieU5ju6NolCvu3kVLXIQm6szgJmkZ8krnZJX22v3exzIg8Fn8 8A5YiVWbafjP8TjRfnILIF3kXzUetE6TLQAo+99o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728075AbfI0AZP (ORCPT ); Thu, 26 Sep 2019 20:25:15 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:45140 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727999AbfI0AZO (ORCPT ); Thu, 26 Sep 2019 20:25:14 -0400 Received: by mail-ot1-f68.google.com with SMTP id 41so745907oti.12; Thu, 26 Sep 2019 17:25:12 -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=JSIM/mVNAQUFTI8poYL0tbeVsabT6n06A8LUKfKixqE=; b=UwbwatXpaojKG2T+EF0sCiKPxLZzbRNJCRU/1l4Hdor8K7puYEzz/EjhB7MA6hB/Vb ReCpYSa12FvcLXDltZ458bNPHiGhEJ60H7BzzDWz7/VbBISP0kKMDqtaHQDL+CYjSnEx CfG1OhLDFNtj0XErLDT8KuDFudbktd1zwRaDwS7TwRsaJKMaVxXlgBFdCCQ+gFUwxUIX a2EcA1dMw8jmt8OkSkfgzLGNfUfyiidQRMFzXg7aCORwIRV5ynfL1byMsDfSLwbgffJg PrZqSH7tRcNwks6UQx+iWY6mmluHTHmJH3dsilME2nj3vR+wx56WlNOuSMP8eHRpNux/ sE0g== X-Gm-Message-State: APjAAAUy1TlVx2uo3KNBAj+rUIhzBoC3oIn7MeXs57P+5B3928O1fBYU /kG3dRY49RfZzU4+92MeJMfS6Xs= X-Google-Smtp-Source: APXvYqz+gt7zD0g7DVclnrzC6AFnTepOJfcgHAqg8BRkcLS/bgxsfuL2h2LiMFlwEq9ILoaJHvmz+w== X-Received: by 2002:a9d:6d0a:: with SMTP id o10mr991391otp.221.1569543911563; Thu, 26 Sep 2019 17:25:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:11 -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 10/11] of/address: Translate 'dma-ranges' for parent nodes missing 'dma-ranges' Date: Thu, 26 Sep 2019 19:24:54 -0500 Message-Id: <20190927002455.13169-11-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 'dma-ranges' frequently exists without parent nodes having 'dma-ranges'. While this is an error for 'ranges', this is fine because DMA capable devices always have a translatable DMA address. Also, with no 'dma-ranges' at all, the assumption is that DMA addresses are 1:1 with no restrictions unless perhaps the device itself has implicit restrictions. Cc: Robin Murphy Signed-off-by: Rob Herring --- drivers/of/address.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index e918001c7798..5b835d332709 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -519,9 +519,13 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus, * * As far as we know, this damage only exists on Apple machines, so * This code is only enabled on powerpc. --gcl + * + * This quirk also applies for 'dma-ranges' which frequently exist in + * child nodes without 'dma-ranges' in the parent nodes. --RobH */ ranges = of_get_property(parent, rprop, &rlen); - if (ranges == NULL && !of_empty_ranges_quirk(parent)) { + if (ranges == NULL && !of_empty_ranges_quirk(parent) && + strcmp(rprop, "dma-ranges")) { pr_debug("no ranges; cannot translate\n"); return 1; } From patchwork Fri Sep 27 00:24:55 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: 11163539 X-Patchwork-Delegate: bhelgaas@google.com 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 1D8E214E5 for ; Fri, 27 Sep 2019 00:25:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6E4020835 for ; Fri, 27 Sep 2019 00:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569543918; bh=9/NP/wZv/cipKjgXcy8j3h5UkUORhxltJpAOwhHW56Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NZlMclsaj8G9PoXOE92Yq9Guuau527kdzMjMyh7eE3oq63P8QYw2ml8pi7Vhv0bew dPzCEl3qtb1cUuoGq2XidEXYZSD3W+dF2YP2unk3CwFgvvSbw7u31sooRBve+J4GJg xDrNA+m7Yb+7TvuZjJrxdIYC9Y2EaPnQMYUhjCTo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728036AbfI0AZP (ORCPT ); Thu, 26 Sep 2019 20:25:15 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:33271 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728003AbfI0AZO (ORCPT ); Thu, 26 Sep 2019 20:25:14 -0400 Received: by mail-oi1-f195.google.com with SMTP id e18so3767601oii.0; Thu, 26 Sep 2019 17:25:13 -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=KvE1OjQp2Eo5TOhHCna2F9pDoURrQBiIlsatoh/ojtA=; b=KqYGlp4pnmNRkjgrtDJgECRHf1rpz2lNXLgnDrdZTmWoQOC+25/QKZtUkGcGBZ2MuG +1x0fm1hlBsfW5UNwdciNVoIxhvFoLj0slGnorylKWqjR960G+fgqUfylYBaBtnLrEK8 BvA59sYp08yFmC61qmHiujPvI4aGdJVivsF9vnZVGiqLtWYG3zATyAsQwn8JPze4b1hS 4tKA94mxv/Vvpk32tlwmP1JpQnKx5PpNRlnHP5/TnMfxIaHNZ4RaOqo0JBU8AdntxtTn hNXqTSnwdep+F+QLxG4vFvSPHt3XQerAcY+9zpnPZ84CFKIdzhyQPDxSXGViljO2oB6b 85aQ== X-Gm-Message-State: APjAAAXIHkETXzCMwxGJlQpNnmK+FX7+eCBnqF/zKARK2svJyUm2/YtN QPEXH1JaPw0RNhjzMgz3OPEqBrs= X-Google-Smtp-Source: APXvYqymzzkGngPSfklXZDXctIqAbqktZ7y7sWXPpqKuwMptW/o1ke/+OGivC0alJNA1OSSWMEbpfg== X-Received: by 2002:a05:6808:b0d:: with SMTP id s13mr4936115oij.52.1569543912890; Thu, 26 Sep 2019 17:25:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 17:25:12 -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 11/11] of/address: Fix of_pci_range_parser_one translation of DMA addresses Date: Thu, 26 Sep 2019 19:24:55 -0500 Message-Id: <20190927002455.13169-12-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: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org of_pci_range_parser_one() has a bug when parsing dma-ranges. When it translates the parent address (aka cpu address in the code), 'ranges' is always being used. This happens to work because most users are just 1:1 translation. Cc: Robin Murphy Signed-off-by: Rob Herring --- drivers/of/address.c | 15 ++++++++++++--- include/linux/of_address.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 5b835d332709..54011a355b81 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -243,6 +243,7 @@ static int parser_init(struct of_pci_range_parser *parser, parser->node = node; parser->pna = of_n_addr_cells(node); parser->np = parser->pna + na + ns; + parser->dma = !strcmp(name, "dma-ranges"); parser->range = of_get_property(node, name, &rlen); if (parser->range == NULL) @@ -281,7 +282,11 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, range->pci_space = be32_to_cpup(parser->range); range->flags = of_bus_pci_get_flags(parser->range); range->pci_addr = of_read_number(parser->range + 1, ns); - range->cpu_addr = of_translate_address(parser->node, + if (parser->dma) + range->cpu_addr = of_translate_dma_address(parser->node, + parser->range + na); + else + range->cpu_addr = of_translate_address(parser->node, parser->range + na); range->size = of_read_number(parser->range + parser->pna + na, ns); @@ -294,8 +299,12 @@ struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser, flags = of_bus_pci_get_flags(parser->range); pci_addr = of_read_number(parser->range + 1, ns); - cpu_addr = of_translate_address(parser->node, - parser->range + na); + if (parser->dma) + cpu_addr = of_translate_dma_address(parser->node, + parser->range + na); + else + cpu_addr = of_translate_address(parser->node, + parser->range + na); size = of_read_number(parser->range + parser->pna + na, ns); if (flags != range->flags) diff --git a/include/linux/of_address.h b/include/linux/of_address.h index ddda3936039c..eac7ab109df4 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -12,6 +12,7 @@ struct of_pci_range_parser { const __be32 *end; int np; int pna; + bool dma; }; struct of_pci_range {