From patchwork Tue Sep 24 18:12:32 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: 11159307 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 BCAAB1668 for ; Tue, 24 Sep 2019 18:12:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9A69C214DA for ; Tue, 24 Sep 2019 18:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407960AbfIXSMy (ORCPT ); Tue, 24 Sep 2019 14:12:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:43932 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2393831AbfIXSMx (ORCPT ); Tue, 24 Sep 2019 14:12:53 -0400 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 3AA7DAEF1; Tue, 24 Sep 2019 18:12:51 +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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 01/11] of: address: clean-up unused variable in of_dma_get_range() Date: Tue, 24 Sep 2019 20:12:32 +0200 Message-Id: <20190924181244.7159-2-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 'len' in of_dma_get_range() is used to check the 'dma-ranges' property length. After the fact, some calculations are run on the variable to be then left unused. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/address.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 978427a9d5e6..0f898756199d 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -922,7 +922,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz { struct device_node *node = of_node_get(np); const __be32 *ranges = NULL; - int len, naddr, nsize, pna; + int naddr, nsize, pna; int ret = 0; u64 dmaaddr; @@ -931,6 +931,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz while (1) { struct device_node *parent; + int len; naddr = of_n_addr_cells(node); nsize = of_n_size_cells(node); @@ -962,8 +963,6 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz goto out; } - len /= sizeof(u32); - pna = of_n_addr_cells(node); /* dma-ranges format: 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: 11159409 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 6E11D912 for ; Tue, 24 Sep 2019 18:14:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55319214AF for ; Tue, 24 Sep 2019 18:14:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725882AbfIXSOC (ORCPT ); Tue, 24 Sep 2019 14:14:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:43988 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388114AbfIXSMz (ORCPT ); Tue, 24 Sep 2019 14:12:55 -0400 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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 02/11] of: base: introduce __of_n_*_cells_parent() 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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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); From patchwork Tue Sep 24 18:12:34 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: 11159405 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 6D37D1668 for ; Tue, 24 Sep 2019 18:14:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 55C9F21850 for ; Tue, 24 Sep 2019 18:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439673AbfIXSM6 (ORCPT ); Tue, 24 Sep 2019 14:12:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:44010 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2393831AbfIXSM4 (ORCPT ); Tue, 24 Sep 2019 14:12:56 -0400 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 E4980AEF8; Tue, 24 Sep 2019 18:12:53 +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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 03/11] of: address: use parent DT node in bus->count_cells() Date: Tue, 24 Sep 2019 20:12:34 +0200 Message-Id: <20190924181244.7159-4-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The function provides the cell sizes for a specific bus type. Instead of passing it the device DT node sitting on top of that bus we directly pass its parent which is the actual node the function will start looking from. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/address.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 0f898756199d..9c1e638fa8ea 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) @@ -42,7 +44,7 @@ struct of_bus { const char *name; const char *addresses; int (*match)(struct device_node *parent); - void (*count_cells)(struct device_node *child, + void (*count_cells)(struct device_node *parent, int *addrc, int *sizec); u64 (*map)(__be32 *addr, const __be32 *range, int na, int ns, int pna); @@ -54,13 +56,13 @@ struct of_bus { * Default translator (generic bus) */ -static void of_bus_default_count_cells(struct device_node *dev, +static void of_bus_default_count_cells(struct device_node *parent, int *addrc, int *sizec) { if (addrc) - *addrc = of_n_addr_cells(dev); + *addrc = __of_n_addr_cells_parent(parent); if (sizec) - *sizec = of_n_size_cells(dev); + *sizec = __of_n_size_cells_parent(parent); } static u64 of_bus_default_map(__be32 *addr, const __be32 *range, @@ -192,7 +194,7 @@ const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, of_node_put(parent); return NULL; } - bus->count_cells(dev, &na, &ns); + bus->count_cells(parent, &na, &ns); of_node_put(parent); if (!OF_CHECK_ADDR_COUNT(na)) return NULL; @@ -592,7 +594,7 @@ static u64 __of_translate_address(struct device_node *dev, bus = of_match_bus(parent); /* Count address cells & copy address locally */ - bus->count_cells(dev, &na, &ns); + bus->count_cells(parent, &na, &ns); if (!OF_CHECK_COUNTS(na, ns)) { pr_debug("Bad cell count for %pOF\n", dev); goto bail; @@ -634,7 +636,7 @@ static u64 __of_translate_address(struct device_node *dev, /* Get new parent bus and counts */ pbus = of_match_bus(parent); - pbus->count_cells(dev, &pna, &pns); + pbus->count_cells(parent, &pna, &pns); if (!OF_CHECK_COUNTS(pna, pns)) { pr_err("Bad cell count for %pOF\n", dev); break; @@ -726,7 +728,7 @@ const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, if (parent == NULL) return NULL; bus = of_match_bus(parent); - bus->count_cells(dev, &na, &ns); + bus->count_cells(parent, &na, &ns); of_node_put(parent); if (!OF_CHECK_ADDR_COUNT(na)) return NULL; From patchwork Tue Sep 24 18:12:35 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: 11159399 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 648DC912 for ; Tue, 24 Sep 2019 18:14:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B96D21655 for ; Tue, 24 Sep 2019 18:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439708AbfIXSM6 (ORCPT ); Tue, 24 Sep 2019 14:12:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:44036 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2439610AbfIXSM6 (ORCPT ); Tue, 24 Sep 2019 14:12:58 -0400 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 3CDFFABBD; Tue, 24 Sep 2019 18:12:55 +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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 04/11] of: address: introduce of_translate_dma_address_parent() Date: Tue, 24 Sep 2019 20:12:35 +0200 Message-Id: <20190924181244.7159-5-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Some devices might not have a DT node of their own, but might still need to translate DMA addresses based on their bus DT node. Update of_translate_dma_address() to only depend on the parent DT node. Rename it to of_translate_dma_address_parent(). The later will be still available as a wrapper around the new function. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/address.c | 60 ++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 9c1e638fa8ea..c9eb4ebcc2e9 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -570,33 +570,32 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus, * device that had registered logical PIO mapping, and the return code is * relative to that node. */ -static u64 __of_translate_address(struct device_node *dev, - struct device_node *(*get_parent)(const struct device_node *), - const __be32 *in_addr, const char *rprop, - struct device_node **host) +static u64 __of_translate_address_parent(struct device_node *parent, + struct device_node *(*get_parent) + (const struct device_node *), + const __be32 *in_addr, + const char *rprop, + struct device_node **host) { - struct device_node *parent = NULL; + struct device_node *dev = NULL; struct of_bus *bus, *pbus; __be32 addr[OF_MAX_ADDR_CELLS]; int na, ns, pna, pns; u64 result = OF_BAD_ADDR; - pr_debug("** translation for device %pOF **\n", dev); - - /* Increase refcount at current level */ - of_node_get(dev); - *host = NULL; - /* Get parent & match bus type */ - parent = get_parent(dev); - if (parent == NULL) + + if (!parent) goto bail; + + /* Increase refcount at current level and match bus type */ + of_node_get(parent); bus = of_match_bus(parent); /* Count address cells & copy address locally */ bus->count_cells(parent, &na, &ns); if (!OF_CHECK_COUNTS(na, ns)) { - pr_debug("Bad cell count for %pOF\n", dev); + pr_debug("Bad cell count for %pOF\n", parent); goto bail; } memcpy(addr, in_addr, na * 4); @@ -610,9 +609,8 @@ static u64 __of_translate_address(struct device_node *dev, struct logic_pio_hwaddr *iorange; /* Switch to parent bus */ - of_node_put(dev); dev = parent; - parent = get_parent(dev); + parent = get_parent(parent); /* If root, we have finished */ if (parent == NULL) { @@ -650,6 +648,8 @@ static u64 __of_translate_address(struct device_node *dev, break; /* Complete the move up one level */ + of_node_put(dev); + dev = parent; na = pna; ns = pns; bus = pbus; @@ -668,8 +668,10 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr) struct device_node *host; u64 ret; - ret = __of_translate_address(dev, of_get_parent, - in_addr, "ranges", &host); + pr_debug("** translation for device %pOF **\n", dev); + + ret = __of_translate_address_parent(dev->parent, of_get_parent, + in_addr, "ranges", &host); if (host) { of_node_put(host); return OF_BAD_ADDR; @@ -697,14 +699,14 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np) return of_node_get(args.np); } -u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) +static u64 of_translate_dma_address_parent(struct device_node *parent, + const __be32 *in_addr) { struct device_node *host; u64 ret; - ret = __of_translate_address(dev, __of_get_dma_parent, - in_addr, "dma-ranges", &host); - + ret = __of_translate_address_parent(parent, __of_get_dma_parent, in_addr, + "dma-ranges", &host); if (host) { of_node_put(host); return OF_BAD_ADDR; @@ -712,6 +714,14 @@ u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) return ret; } + +u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) +{ + pr_debug("** translation for device %pOF **\n", dev); + + return of_translate_dma_address_parent(__of_get_dma_parent(dev->parent), + in_addr); +} EXPORT_SYMBOL(of_translate_dma_address); const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, @@ -759,8 +769,10 @@ static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr, unsigned long port; struct device_node *host; - taddr = __of_translate_address(dev, of_get_parent, - in_addr, "ranges", &host); + pr_debug("** translation for device %pOF **\n", dev); + + taddr = __of_translate_address_parent(dev->parent, of_get_parent, + in_addr, "ranges", &host); if (host) { /* host-specific port access */ port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size); From patchwork Tue Sep 24 18:12:36 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: 11159391 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 412E914ED for ; Tue, 24 Sep 2019 18:13:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2960E21841 for ; Tue, 24 Sep 2019 18:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730382AbfIXSNs (ORCPT ); Tue, 24 Sep 2019 14:13:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:44010 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2439657AbfIXSM7 (ORCPT ); Tue, 24 Sep 2019 14:12:59 -0400 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 D66E4AE78; Tue, 24 Sep 2019 18:12:56 +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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 05/11] of: expose __of_get_dma_parent() to OF subsystem Date: Tue, 24 Sep 2019 20:12:36 +0200 Message-Id: <20190924181244.7159-6-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The function was only available locally to of/address.c, make it available to the OF subsystem. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/address.c | 18 ------------------ drivers/of/base.c | 25 +++++++++++++++++++++++++ drivers/of/of_private.h | 2 ++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index c9eb4ebcc2e9..53666063e938 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -681,24 +681,6 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr) } EXPORT_SYMBOL(of_translate_address); -static struct device_node *__of_get_dma_parent(const struct device_node *np) -{ - struct of_phandle_args args; - int ret, index; - - index = of_property_match_string(np, "interconnect-names", "dma-mem"); - if (index < 0) - return of_get_parent(np); - - ret = of_parse_phandle_with_args(np, "interconnects", - "#interconnect-cells", - index, &args); - if (ret < 0) - return of_get_parent(np); - - return of_node_get(args.np); -} - static u64 of_translate_dma_address_parent(struct device_node *parent, const __be32 *in_addr) { diff --git a/drivers/of/base.c b/drivers/of/base.c index 94f83051910c..ec161e6b5222 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -716,6 +716,31 @@ struct device_node *of_get_parent(const struct device_node *node) } EXPORT_SYMBOL(of_get_parent); +/** + * __of_get_dma_parent - Get a node's dma parent if any + * @node: Node to get dma parent + * + * Returns a node pointer with refcount incremented, use + * of_node_put() on it when done. + */ +struct device_node *__of_get_dma_parent(const struct device_node *np) +{ + struct of_phandle_args args; + int ret, index; + + index = of_property_match_string(np, "interconnect-names", "dma-mem"); + if (index < 0) + return of_get_parent(np); + + ret = of_parse_phandle_with_args(np, "interconnects", + "#interconnect-cells", + index, &args); + if (ret < 0) + return of_get_parent(np); + + return of_node_get(args.np); +} + /** * of_get_next_parent - Iterate to a node's parent * @node: Node to get parent of diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index b528304be244..63bb16cc454c 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -42,6 +42,8 @@ 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); +struct device_node *__of_get_dma_parent(const struct device_node *np); + #if defined(CONFIG_OF_DYNAMIC) extern int of_property_notify(int action, struct device_node *np, struct property *prop, struct property *old_prop); From patchwork Tue Sep 24 18:12:37 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: 11159377 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 232C11668 for ; Tue, 24 Sep 2019 18:13:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A5E3214DA for ; Tue, 24 Sep 2019 18:13:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439741AbfIXSNC (ORCPT ); Tue, 24 Sep 2019 14:13:02 -0400 Received: from mx2.suse.de ([195.135.220.15]:44098 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2439705AbfIXSNB (ORCPT ); Tue, 24 Sep 2019 14:13:01 -0400 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 376C8AC93; Tue, 24 Sep 2019 18:12:58 +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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 06/11] of: address: use parent OF node in of_dma_get_range() Date: Tue, 24 Sep 2019 20:12:37 +0200 Message-Id: <20190924181244.7159-7-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Some devices don't have their own OF node, and are stuck passing their bus node. Adapt the function for this use case. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/address.c | 33 +++++++++++++++------------------ drivers/of/device.c | 3 ++- include/linux/of_address.h | 8 ++++---- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 53666063e938..b7b864b0ac75 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -914,30 +914,21 @@ EXPORT_SYMBOL(of_io_request_and_map); * It returns -ENODEV if "dma-ranges" property was not found * for this device in DT. */ -int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size) +int of_dma_get_range(struct device_node *parent, u64 *dma_addr, + u64 *paddr, u64 *size) { - struct device_node *node = of_node_get(np); + struct device_node *node = of_node_get(parent); const __be32 *ranges = NULL; int naddr, nsize, pna; int ret = 0; u64 dmaaddr; - if (!node) - return -EINVAL; - while (1) { - struct device_node *parent; + struct device_node *tmp; int len; - 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; + naddr = __of_n_addr_cells_parent(node); + nsize = __of_n_size_cells_parent(node); ranges = of_get_property(node, "dma-ranges", &len); @@ -951,10 +942,16 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz */ if (!ranges) break; + + tmp = __of_get_dma_parent(node); + of_node_put(node); + node = tmp; + if (!node) + break; } if (!ranges) { - pr_debug("no dma-ranges found for node(%pOF)\n", np); + pr_debug("no dma-ranges found for node(%pOF)\n", node); ret = -ENODEV; goto out; } @@ -967,10 +964,10 @@ 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_parent(parent, ranges); if (*paddr == OF_BAD_ADDR) { pr_err("translation of DMA address(%pad) to CPU address failed node(%pOF)\n", - dma_addr, np); + dma_addr, parent); ret = -EINVAL; goto out; } diff --git a/drivers/of/device.c b/drivers/of/device.c index da8158392010..267b509df517 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -95,7 +95,8 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma) const struct iommu_ops *iommu; u64 mask; - ret = of_dma_get_range(np, &dma_addr, &paddr, &size); + ret = of_dma_get_range(__of_get_dma_parent(np), &dma_addr, + &paddr, &size); if (ret < 0) { /* * For legacy reasons, we have to assume some devices need diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 30e40fb6936b..aa1ce0cb59a1 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -55,8 +55,8 @@ 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 int of_dma_get_range(struct device_node *parent, 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, @@ -104,8 +104,8 @@ 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) +static inline int of_dma_get_range(struct device_node *parent, u64 *dma_addr, + u64 *paddr, u64 *size) { return -ENODEV; } From patchwork Tue Sep 24 18:12:38 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: 11159375 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 77323912 for ; Tue, 24 Sep 2019 18:13:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5EB6D21783 for ; Tue, 24 Sep 2019 18:13:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436694AbfIXSNg (ORCPT ); Tue, 24 Sep 2019 14:13:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:44010 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2505058AbfIXSNC (ORCPT ); Tue, 24 Sep 2019 14:13:02 -0400 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 D4F0DAF03; Tue, 24 Sep 2019 18:12:59 +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, Shawn Guo , Li Yang Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne , Mark Rutland Subject: [PATCH 07/11] dts: arm64: layerscape: add dma-ranges property to qoric-mc node Date: Tue, 24 Sep 2019 20:12:38 +0200 Message-Id: <20190924181244.7159-8-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org qoriq-mc's dpmacs DMA configuration is inherited from their parent node, which acts a bus in this regard. So far it maked all devices as dma-coherent but no dma-ranges recommendation is made. The truth is that the underlying interconnect has DMA constraints, so add an empty dma-ranges in qoriq-mc's node in order for DT's DMA configuration code to get the DMA constraints from it. Signed-off-by: Nicolas Saenz Julienne --- arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi | 1 + arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi | 1 + arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi index c676d0771762..f0d0b6145b72 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-ls1088a.dtsi @@ -698,6 +698,7 @@ <0x00000000 0x08340000 0 0x40000>; /* MC control reg */ msi-parent = <&its>; iommu-map = <0 &smmu 0 0>; /* This is fixed-up by u-boot */ + dma-ranges; dma-coherent; #address-cells = <3>; #size-cells = <1>; diff --git a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi index 7a0be8eaa84a..fd6036b7865c 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi @@ -340,6 +340,7 @@ <0x00000000 0x08340000 0 0x40000>; /* MC control reg */ msi-parent = <&its>; iommu-map = <0 &smmu 0 0>; /* This is fixed-up by u-boot */ + dma-ranges; dma-coherent; #address-cells = <3>; #size-cells = <1>; diff --git a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi index 408e0ecdce6a..3735bb139cb2 100644 --- a/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi @@ -868,6 +868,7 @@ msi-parent = <&its>; /* iommu-map property is fixed up by u-boot */ iommu-map = <0 &smmu 0 0>; + dma-ranges; dma-coherent; #address-cells = <3>; #size-cells = <1>; From patchwork Tue Sep 24 18:12:39 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: 11159357 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 B84D6912 for ; Tue, 24 Sep 2019 18:13:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 94426214DA for ; Tue, 24 Sep 2019 18:13:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439786AbfIXSNE (ORCPT ); Tue, 24 Sep 2019 14:13:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:44168 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2439739AbfIXSNE (ORCPT ); Tue, 24 Sep 2019 14:13:04 -0400 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 4A5C4ABBD; Tue, 24 Sep 2019 18:13:01 +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, Shawn Guo , Li Yang Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne , Mark Rutland Subject: [PATCH 08/11] dts: arm64: layerscape: add dma-ranges property to pcie nodes Date: Tue, 24 Sep 2019 20:12:39 +0200 Message-Id: <20190924181244.7159-9-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The bus behind the board's PCIe core has DMA addressing limitations. Add an empty 'dma-ranges' property on all PCIe bus descriptions to inform the OF core that a translation is due further down the line. Signed-off-by: Nicolas Saenz Julienne --- arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi index fd6036b7865c..2c41cfc66bb9 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi +++ b/arch/arm64/boot/dts/freescale/fsl-ls208xa.dtsi @@ -640,6 +640,7 @@ #size-cells = <2>; device_type = "pci"; dma-coherent; + dma-ranges; num-viewport = <6>; bus-range = <0x0 0xff>; msi-parent = <&its>; @@ -661,6 +662,7 @@ #size-cells = <2>; device_type = "pci"; dma-coherent; + dma-ranges; num-viewport = <6>; bus-range = <0x0 0xff>; msi-parent = <&its>; @@ -682,6 +684,7 @@ #size-cells = <2>; device_type = "pci"; dma-coherent; + dma-ranges; num-viewport = <256>; bus-range = <0x0 0xff>; msi-parent = <&its>; @@ -703,6 +706,7 @@ #size-cells = <2>; device_type = "pci"; dma-coherent; + dma-ranges; num-viewport = <6>; bus-range = <0x0 0xff>; msi-parent = <&its>; From patchwork Tue Sep 24 18:12:40 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: 11159351 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 DF5EC912 for ; Tue, 24 Sep 2019 18:13:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C71B921848 for ; Tue, 24 Sep 2019 18:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393831AbfIXSNF (ORCPT ); Tue, 24 Sep 2019 14:13:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:44098 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2439771AbfIXSNE (ORCPT ); Tue, 24 Sep 2019 14:13:04 -0400 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 93C9FAEF1; Tue, 24 Sep 2019 18:13:02 +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 Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 09/11] of: device: remove comment in of_dma_configure() Date: Tue, 24 Sep 2019 20:12:40 +0200 Message-Id: <20190924181244.7159-10-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org It's not longer advised to use notifiers in order to setup custom DMA ops. Signed-off-by: Nicolas Saenz Julienne --- drivers/of/device.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 267b509df517..018c52688546 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -81,10 +81,6 @@ int of_device_add(struct platform_device *ofdev) * * Try to get devices's DMA configuration from DT and update it * accordingly. - * - * If platform code needs to use its own special DMA configuration, it - * 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) { From patchwork Tue Sep 24 18:12:41 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: 11159325 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 00BDD912 for ; Tue, 24 Sep 2019 18:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC3F521BE5 for ; Tue, 24 Sep 2019 18:13:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505097AbfIXSNO (ORCPT ); Tue, 24 Sep 2019 14:13:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:44168 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2505076AbfIXSNH (ORCPT ); Tue, 24 Sep 2019 14:13:07 -0400 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 67856AC93; Tue, 24 Sep 2019 18:13:04 +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, Stuart Yoder , Laurentiu Tudor , Thierry Reding , Bjorn Helgaas Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne Subject: [PATCH 10/11] of: device: introduce of_dma_configure_parent() Date: Tue, 24 Sep 2019 20:12:41 +0200 Message-Id: <20190924181244.7159-11-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Devices not represented in DT, placed behind a bus that autodetects them, pass of_dma_configure() their bus' DT node. This misses that bus' 'dma-ranges' property as the function's implementation expects the DT node to be one of a device. Create of_dma_configure_parent() which takes the given DT node as the device's underlying bus and parses it accordingly. Signed-off-by: Nicolas Saenz Julienne --- drivers/bus/fsl-mc/fsl-mc-bus.c | 2 +- drivers/gpu/host1x/bus.c | 2 +- drivers/of/device.c | 30 ++++++++++++++++++++++++++++-- drivers/pci/pci-driver.c | 3 ++- include/linux/of_device.h | 13 ++++++++++--- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c index 5c9bf2e06552..217e64119497 100644 --- a/drivers/bus/fsl-mc/fsl-mc-bus.c +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c @@ -134,7 +134,7 @@ static int fsl_mc_dma_configure(struct device *dev) while (dev_is_fsl_mc(dma_dev)) dma_dev = dma_dev->parent; - return of_dma_configure(dev, dma_dev->of_node, 0); + return of_dma_configure_parent(dev, dma_dev->of_node, false); } static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c index 742aa9ff21b8..2fdc04383a60 100644 --- a/drivers/gpu/host1x/bus.c +++ b/drivers/gpu/host1x/bus.c @@ -442,7 +442,7 @@ static int host1x_device_add(struct host1x *host1x, device->dev.bus = &host1x_bus_type; device->dev.parent = host1x->dev; - of_dma_configure(&device->dev, host1x->dev->of_node, true); + of_dma_configure_parent(&device->dev, host1x->dev->of_node, true); device->dev.dma_parms = &device->dma_parms; dma_set_max_seg_size(&device->dev, SZ_4M); diff --git a/drivers/of/device.c b/drivers/of/device.c index 018c52688546..1d0b1127d05e 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -83,6 +83,31 @@ int of_device_add(struct platform_device *ofdev) * accordingly. */ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma) +{ + struct device_node *dma_parent; + int ret; + + dma_parent = __of_get_dma_parent(np); + ret = of_dma_configure_parent(dev, dma_parent, force_dma); + of_node_put(dma_parent); + + return ret; +} +EXPORT_SYMBOL_GPL(of_dma_configure); + +/** + * of_dma_configure_parent - Setup DMA configuration based on a parent bus' + * DT node + * @dev: Device to apply DMA configuration + * @parent: Parent bus device node + * @force_dma: Whether device is to be set up by of_dma_configure() even if + * DMA capability is not explicitly described by firmware. + * + * Try to get devices's DMA configuration from parent bus' DT and update it + * accordingly. + */ +int of_dma_configure_parent(struct device *dev, struct device_node *parent, + bool force_dma) { u64 dma_addr, paddr, size = 0; int ret; @@ -91,8 +116,9 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma) const struct iommu_ops *iommu; u64 mask; - ret = of_dma_get_range(__of_get_dma_parent(np), &dma_addr, - &paddr, &size); + dev_dbg(dev, "starting at %pOF\n", parent); + + ret = of_dma_get_range(parent, &dma_addr, &paddr, &size); if (ret < 0) { /* * For legacy reasons, we have to assume some devices need diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index a8124e47bf6e..25073d68a0f6 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -1628,7 +1628,8 @@ static int pci_dma_configure(struct device *dev) if (IS_ENABLED(CONFIG_OF) && bridge->parent && bridge->parent->of_node) { - ret = of_dma_configure(dev, bridge->parent->of_node, true); + ret = of_dma_configure_parent(dev, bridge->parent->of_node, + true); } else if (has_acpi_companion(bridge)) { struct acpi_device *adev = to_acpi_device_node(bridge->fwnode); diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 8d31e39dd564..8f319b8c9deb 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -55,9 +55,9 @@ static inline struct device_node *of_cpu_device_node_get(int cpu) return of_node_get(cpu_dev->of_node); } -int of_dma_configure(struct device *dev, - struct device_node *np, - bool force_dma); +int of_dma_configure(struct device *dev, struct devce_node *np, bool force_dma); +int of_dma_configure_parent(struct device *dev, struct device_node *parent, + bool force_dma); #else /* CONFIG_OF */ static inline int of_driver_match_device(struct device *dev, @@ -112,6 +112,13 @@ static inline int of_dma_configure(struct device *dev, { return 0; } + +static inline int of_dma_configure_parent(struct device *dev, + struct device_node *parent, + bool force_dma) +{ + return 0; +} #endif /* CONFIG_OF */ #endif /* _LINUX_OF_DEVICE_H */ From patchwork Tue Sep 24 18:12:42 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: 11159337 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 F0BB2912 for ; Tue, 24 Sep 2019 18:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF06D21655 for ; Tue, 24 Sep 2019 18:13:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2632839AbfIXSNQ (ORCPT ); Tue, 24 Sep 2019 14:13:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:44314 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2409758AbfIXSNP (ORCPT ); Tue, 24 Sep 2019 14:13:15 -0400 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 71267ABBD; Tue, 24 Sep 2019 18:13:11 +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, Greg Kroah-Hartman , "Rafael J. Wysocki" , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Sinan Kaya , Andy Gross , Lucas Stach , Russell King , Christian Gmeiner , Maxime Ripard , Chen-Yu Tsai , Oleksandr Andrushchenko , Thierry Reding , Stanimir Varbanov , Kyungmin Park , Kamil Debski , Jeongtae Park , Andrzej Hajda , Boris Ostrovsky , Juergen Gross , Stefano Stabellini Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com, james.quinlan@broadcom.com, wahrenst@gmx.net, Nicolas Saenz Julienne , Vinod Koul , Dan Williams , David Airlie , Daniel Vetter , Rob Clark , Sean Paul , Mauro Carvalho Chehab , freedreno@lists.freedesktop.org Subject: [PATCH 11/11] of: simplify of_dma_config()'s arguments Date: Tue, 24 Sep 2019 20:12:42 +0200 Message-Id: <20190924181244.7159-12-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 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The widespread use case for of_dma_config() highlights a redundant argument. Most callers provide both 'dev' and 'dev->of_node'. The rest of users use it to copy some device's DMA configuration into a device not represented in DT. In order to simplify the common use case, and make code a little more explicit, create of_dma_config_copy() which will take another device's DT node as an argument and simplify of_dma_config() by removing one of it's redundant arguments. Signed-off-by: Nicolas Saenz Julienne --- drivers/base/platform.c | 2 +- drivers/bcma/main.c | 2 +- drivers/dma/qcom/hidma_mgmt.c | 2 +- drivers/gpu/drm/etnaviv/etnaviv_drv.c | 2 +- drivers/gpu/drm/msm/adreno/a6xx_gmu.c | 2 +- drivers/gpu/drm/sun4i/sun4i_backend.c | 2 +- drivers/gpu/drm/xen/xen_drm_front.c | 2 +- drivers/gpu/host1x/bus.c | 2 +- drivers/media/platform/qcom/venus/firmware.c | 2 +- drivers/media/platform/s5p-mfc/s5p_mfc.c | 2 +- drivers/of/device.c | 30 ++++++++++++++++++-- drivers/xen/gntdev.c | 2 +- include/linux/of_device.h | 12 ++++++-- 13 files changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index b6c6c7d97d5b..4e252028aee9 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1221,7 +1221,7 @@ int platform_dma_configure(struct device *dev) int ret = 0; if (dev->of_node) { - ret = of_dma_configure(dev, dev->of_node, true); + ret = of_dma_configure(dev, true); } else if (has_acpi_companion(dev)) { attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode)); ret = acpi_dma_configure(dev, attr); diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c index 6535614a7dc1..4c7e8b35525c 100644 --- a/drivers/bcma/main.c +++ b/drivers/bcma/main.c @@ -207,7 +207,7 @@ static void bcma_of_fill_device(struct device *parent, core->irq = bcma_of_get_irq(parent, core, 0); - of_dma_configure(&core->dev, node, false); + of_dma_configure(&core->dev, false); } unsigned int bcma_core_irq(struct bcma_device *core, int num) diff --git a/drivers/dma/qcom/hidma_mgmt.c b/drivers/dma/qcom/hidma_mgmt.c index 806ca02c52d7..4ea901537902 100644 --- a/drivers/dma/qcom/hidma_mgmt.c +++ b/drivers/dma/qcom/hidma_mgmt.c @@ -388,7 +388,7 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np) goto out; } new_pdev->dev.of_node = child; - of_dma_configure(&new_pdev->dev, child, true); + of_dma_configure(&new_pdev->dev, true); /* * It is assumed that calling of_msi_configure is safe on * platforms with or without MSI support. diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c index 1f9c01be40d7..1375f41593ef 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c @@ -706,7 +706,7 @@ static int __init etnaviv_init(void) * device as the GPU we found. This assumes that all Vivante * GPUs in the system share the same DMA constraints. */ - of_dma_configure(&pdev->dev, np, true); + of_dma_configure_copy(&pdev->dev, np, true); ret = platform_device_add(pdev); if (ret) { diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c index 85f14feafdec..825fcdc72bd9 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c @@ -1268,7 +1268,7 @@ int a6xx_gmu_init(struct a6xx_gpu *a6xx_gpu, struct device_node *node) gmu->dev = &pdev->dev; - of_dma_configure(gmu->dev, node, true); + of_dma_configure(gmu->dev, true); /* Fow now, don't do anything fancy until we get our feet under us */ gmu->idle_level = GMU_IDLE_STATE_ACTIVE; diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index 4e29f4fe4a05..97dd5d31e38d 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -802,7 +802,7 @@ static int sun4i_backend_bind(struct device *dev, struct device *master, * for us, and DRM doesn't do per-device allocation either, so * we would need to fix DRM first... */ - ret = of_dma_configure(drm->dev, dev->of_node, true); + ret = of_dma_configure_copy(drm->dev, dev->of_node, true); if (ret) return ret; } else { diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c index ba1828acd8c9..fa0bfd6517fa 100644 --- a/drivers/gpu/drm/xen/xen_drm_front.c +++ b/drivers/gpu/drm/xen/xen_drm_front.c @@ -726,7 +726,7 @@ static int xen_drv_probe(struct xenbus_device *xb_dev, * node to set default DMA ops. */ dev->coherent_dma_mask = DMA_BIT_MASK(32); - ret = of_dma_configure(dev, NULL, true); + ret = of_dma_configure(dev, true); if (ret < 0) { DRM_ERROR("Cannot setup DMA ops, ret %d", ret); return ret; diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c index 2fdc04383a60..4eb531906e4a 100644 --- a/drivers/gpu/host1x/bus.c +++ b/drivers/gpu/host1x/bus.c @@ -337,7 +337,7 @@ static int host1x_device_uevent(struct device *dev, static int host1x_dma_configure(struct device *dev) { - return of_dma_configure(dev, dev->of_node, true); + return of_dma_configure(dev, true); } static const struct dev_pm_ops host1x_device_pm_ops = { diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c index d3d1748a7ef6..82f433218d99 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -238,7 +238,7 @@ int venus_firmware_init(struct venus_core *core) pdev->dev.of_node = np; - ret = of_dma_configure(&pdev->dev, np, true); + ret = of_dma_configure(&pdev->dev, true); if (ret) { dev_err(core->dev, "dma configure fail\n"); goto err_unregister; diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c index b776f83e395e..ad33e7a655aa 100644 --- a/drivers/media/platform/s5p-mfc/s5p_mfc.c +++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c @@ -1095,7 +1095,7 @@ static struct device *s5p_mfc_alloc_memdev(struct device *dev, * to be treated as valid DMA masters we need a bit of a hack to force * them to inherit the MFC node's DMA configuration. */ - of_dma_configure(child, dev->of_node, true); + of_dma_configure_copy(child, dev->of_node, true); if (device_add(child) == 0) { ret = of_reserved_mem_device_init_by_idx(child, dev->of_node, diff --git a/drivers/of/device.c b/drivers/of/device.c index 1d0b1127d05e..66726a2499d3 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -75,19 +75,18 @@ 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 * @force_dma: Whether device is to be set up by of_dma_configure() even if * DMA capability is not explicitly described by firmware. * * Try to get devices's DMA configuration from DT and update it * accordingly. */ -int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma) +int of_dma_configure(struct device *dev, bool force_dma) { struct device_node *dma_parent; int ret; - dma_parent = __of_get_dma_parent(np); + dma_parent = __of_get_dma_parent(dev->of_node); ret = of_dma_configure_parent(dev, dma_parent, force_dma); of_node_put(dma_parent); @@ -95,6 +94,31 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma) } EXPORT_SYMBOL_GPL(of_dma_configure); +/** + * of_dma_configure_copy - Setup DMA configuration based on another device's DT + * node + * @dev: Device to apply DMA configuration + * @np: Device node to copy the configuration from + * @force_dma: Whether device is to be set up by of_dma_configure() even if + * DMA capability is not explicitly described by firmware. + * + * Try to get devices's DMA configuration from DT and update it + * accordingly. + */ +int of_dma_configure_copy(struct device *dev, struct device_node *np, + bool force_dma) +{ + struct device_node *dma_parent; + int ret; + + dma_parent = __of_get_dma_parent(np); + ret = of_dma_configure_parent(dev, dma_parent, force_dma); + of_node_put(dma_parent); + + return ret; +} +EXPORT_SYMBOL_GPL(of_dma_configure_copy); + /** * of_dma_configure_parent - Setup DMA configuration based on a parent bus' * DT node diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index a446a7221e13..115e39f9f67a 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c @@ -632,7 +632,7 @@ static int gntdev_open(struct inode *inode, struct file *flip) * Fix this by calling of_dma_configure() with a NULL node to set * default DMA ops. */ - of_dma_configure(priv->dma_dev, NULL, true); + of_dma_configure(priv->dma_dev, true); #endif pr_debug("priv %p\n", priv); diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 8f319b8c9deb..b05a86fd35a4 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -55,7 +55,9 @@ static inline struct device_node *of_cpu_device_node_get(int cpu) return of_node_get(cpu_dev->of_node); } -int of_dma_configure(struct device *dev, struct devce_node *np, bool force_dma); +int of_dma_configure(struct device *dev, bool force_dma); +int of_dma_configure_copy(struct device *dev, struct device_node *np, + bool force_dma); int of_dma_configure_parent(struct device *dev, struct device_node *parent, bool force_dma); #else /* CONFIG_OF */ @@ -107,12 +109,18 @@ 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, bool force_dma) { return 0; } +static inline int of_dma_configure_copy(struct device *dev, + struct device_node *np, + bool force_dma) +{ + return 0; +} + static inline int of_dma_configure_parent(struct device *dev, struct device_node *parent, bool force_dma)