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: 11159975 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 3B3CC1800 for ; Wed, 25 Sep 2019 04:17:37 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 20C81217D9 for ; Wed, 25 Sep 2019 04:17:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20C81217D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCyj3-0000UC-JV; Wed, 25 Sep 2019 04:16:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCpJJ-0000GV-EJ for xen-devel@lists.xenproject.org; Tue, 24 Sep 2019 18:13:13 +0000 X-Inumbo-ID: f03d052a-def6-11e9-8628-bc764e2007e4 Received: from mx1.suse.de (unknown [195.135.220.15]) by localhost (Halon) with ESMTPS id f03d052a-def6-11e9-8628-bc764e2007e4; Tue, 24 Sep 2019 18:12:59 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 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 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 X-Mailman-Approved-At: Wed, 25 Sep 2019 04:16:20 +0000 Subject: [Xen-devel] [PATCH 06/11] of: address: use parent OF node in of_dma_get_range() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: f.fainelli@gmail.com, mbrugger@suse.com, wahrenst@gmx.net, james.quinlan@broadcom.com, robin.murphy@arm.com, Nicolas Saenz Julienne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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; }