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: 11159985 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 D82D114ED for ; Wed, 25 Sep 2019 04:17:39 +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 BEA2921848 for ; Wed, 25 Sep 2019 04:17:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEA2921848 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-0000TN-4t; Wed, 25 Sep 2019 04:16:25 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCpJJ-0000GQ-3q for xen-devel@lists.xenproject.org; Tue, 24 Sep 2019 18:13:13 +0000 X-Inumbo-ID: f3ee48b4-def6-11e9-9625-12813bfff9fa Received: from mx1.suse.de (unknown [195.135.220.15]) by localhost (Halon) with ESMTPS id f3ee48b4-def6-11e9-9625-12813bfff9fa; Tue, 24 Sep 2019 18:13:05 +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 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 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 X-Mailman-Approved-At: Wed, 25 Sep 2019 04:16:20 +0000 Subject: [Xen-devel] [PATCH 10/11] of: device: introduce of_dma_configure_parent() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: f.fainelli@gmail.com, mbrugger@suse.com, wahrenst@gmx.net, james.quinlan@broadcom.com, robin.murphy@arm.com, Nicolas Saenz Julienne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 */