From patchwork Wed Jan 11 18:31:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Yushchenko X-Patchwork-Id: 9511011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 32F426075C for ; Wed, 11 Jan 2017 18:32:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1973128662 for ; Wed, 11 Jan 2017 18:32:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E5C328667; Wed, 11 Jan 2017 18:32:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B145428662 for ; Wed, 11 Jan 2017 18:32:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cRNhg-0002cA-1E; Wed, 11 Jan 2017 18:32:56 +0000 Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cRNhR-0002Gp-Rs for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2017 18:32:44 +0000 Received: by mail-lf0-x22e.google.com with SMTP id v186so88425988lfa.1 for ; Wed, 11 Jan 2017 10:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DsmrLQTYacTBB218+YKtMvjS3EcC+45BYBgx6QuX0Bo=; b=YriAQesX1D7UqB2/hu4swdy3MEYeKiaNw8OzpMGBi7BzEHKfMW/m4pytMmM+JldF9L mCcyYLrweP/smQ+N0nRL9l3qPEMguFlnucI4egpmua+rgtnHySn6fFC6YRAb8ZJhvRtf +xqAhmYH69zov7zaIpwCJFknQKn9ucfJRs4V0h8koR5MlllnckA8cD8BuS31ixhyPfsQ qwmJ6m5Em70xqXJz2s8NEdb/6n364QOggRRHWBCLEdO6uI5G8AsTVFcZXUkNWJVZCVil nv3j6IDP5ohudDIcGG1aDzLscUKzPJsh9mr17ShZS0oYq2kQIioB0gO+tiUJOC8xW+e5 qNRQ== 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; bh=DsmrLQTYacTBB218+YKtMvjS3EcC+45BYBgx6QuX0Bo=; b=D8ldOaY0lDaiUN14Q9zEiQXiXo8/7hKFBeidH0IVs1xUeTx/aMx6UC9ZXMwFd4L6BQ l7R/9zpCGGMVdFnieQJE8958wLTCHoFCWg2DmPncqimPNVHQI7Vbe6z1ZLDeN3lN37n1 X97lLqbpVMxF+LXqWXykdkWs27AqMOzlg7RyG+XyqHYmzMakkefAa02vr6fKQPlozcRR MsSZbn1ZAbfkRe4frIqUXOIGNzJxJvG626dUxafEx/4qShlKuHH1BiqUPhVm+CzhANb7 EmIoslfZtwEOrR8hdcS8F1b28QQDGq8xKcLQqZCLZohgMGBzafFm6Ox5OG3PIHbWSJNB CnLA== X-Gm-Message-State: AIkVDXLjOMekVDgRMz9XhSYtY+nfvdk+NlVt/o8z5FzTofMZi+KuaTRyrzq086YD1ow++Q== X-Received: by 10.25.234.216 with SMTP id y85mr3412287lfi.35.1484159539746; Wed, 11 Jan 2017 10:32:19 -0800 (PST) Received: from hugenb.home (nikaet.starlink.ru. [94.141.168.29]) by smtp.gmail.com with ESMTPSA id s20sm361640lfe.41.2017.01.11.10.32.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 10:32:18 -0800 (PST) From: Nikita Yushchenko To: Robin Murphy , Will Deacon , Arnd Bergmann Subject: [PATCH 1/2] dma-mapping: let arch know origin of dma range passed to arch_setup_dma_ops() Date: Wed, 11 Jan 2017 21:31:51 +0300 Message-Id: <1484159512-28515-2-git-send-email-nikita.yoush@cogentembedded.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1484159512-28515-1-git-send-email-nikita.yoush@cogentembedded.com> References: <1484159512-28515-1-git-send-email-nikita.yoush@cogentembedded.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170111_103242_269789_0CCEA914 X-CRM114-Status: GOOD ( 17.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nikita Yushchenko , fkan@apm.com, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Simon Horman , Bjorn Helgaas , Artemi Ivanov , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP There are cases when device is capable of wide DMA mask (and driver issues corresponding dma_set_mask() call), but bus device sits on can't support wide address. Example: NVMe device behind PCIe controller sitting on 32-bit SoC bus. To support such case, architecture needs information about such limitations. Such information can originate from dma-ranges property in device tree, and is passed to architecture via arch_setup_dma_ops() call. Problem is that in wide majority of cases, no dma range is defined. E.g. ACPI has no means to define it. Thus default range (usually full 32-bit range, i.e. 4G starting at zero address) is passed instead. If architecture enforce this range, all setups currently using wide DMA addresses without explicitly defining support for that via device tree will break. This is bad, especially for ACPI based platforms. To avoid that, this patch adds additional boolean argument to arch_setup_dma_ops() to show if range originates from authorative source and thus should be enforced, or is just a guess and should be handled as such. Signed-off-by: Nikita Yushchenko --- arch/arm/include/asm/dma-mapping.h | 1 + arch/arm/mm/dma-mapping.c | 3 ++- arch/arm64/include/asm/dma-mapping.h | 3 ++- arch/arm64/mm/dma-mapping.c | 3 ++- arch/mips/include/asm/dma-mapping.h | 3 ++- drivers/acpi/scan.c | 2 +- drivers/iommu/rockchip-iommu.c | 2 +- drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 2 +- drivers/of/device.c | 5 ++++- drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 2 +- 10 files changed, 17 insertions(+), 9 deletions(-) diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index bf02dbd..2a3863e 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -117,6 +117,7 @@ static inline unsigned long dma_max_pfn(struct device *dev) #define arch_setup_dma_ops arch_setup_dma_ops extern void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, + bool enforce_range, const struct iommu_ops *iommu, bool coherent); #define arch_teardown_dma_ops arch_teardown_dma_ops diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index ab77100..b8b11f8 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -2380,7 +2380,8 @@ static struct dma_map_ops *arm_get_dma_map_ops(bool coherent) } void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - const struct iommu_ops *iommu, bool coherent) + bool enforce_range, const struct iommu_ops *iommu, + bool coherent) { struct dma_map_ops *dma_ops; diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h index ccea82c..ae1c23f 100644 --- a/arch/arm64/include/asm/dma-mapping.h +++ b/arch/arm64/include/asm/dma-mapping.h @@ -48,7 +48,8 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev) } void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - const struct iommu_ops *iommu, bool coherent); + bool enforce_range, const struct iommu_ops *iommu, + bool coherent); #define arch_setup_dma_ops arch_setup_dma_ops #ifdef CONFIG_IOMMU_DMA diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index e040827..ea295f1 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -953,7 +953,8 @@ static void __iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, #endif /* CONFIG_IOMMU_DMA */ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - const struct iommu_ops *iommu, bool coherent) + bool enforce_range, const struct iommu_ops *iommu, + bool coherent) { if (!dev->archdata.dma_ops) dev->archdata.dma_ops = &swiotlb_dma_ops; diff --git a/arch/mips/include/asm/dma-mapping.h b/arch/mips/include/asm/dma-mapping.h index 7aa71b9..6af4d87 100644 --- a/arch/mips/include/asm/dma-mapping.h +++ b/arch/mips/include/asm/dma-mapping.h @@ -34,7 +34,8 @@ extern void dma_cache_sync(struct device *dev, void *vaddr, size_t size, #define arch_setup_dma_ops arch_setup_dma_ops static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, - u64 size, const struct iommu_ops *iommu, + u64 size, bool enforce_range, + const struct iommu_ops *iommu, bool coherent) { #ifdef CONFIG_DMA_PERDEV_COHERENT diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1926918..dea17a5 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1385,7 +1385,7 @@ void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) * Assume dma valid range starts at 0 and covers the whole * coherent_dma_mask. */ - arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu, + arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, false, iommu, attr == DEV_DMA_COHERENT); } EXPORT_SYMBOL_GPL(acpi_dma_configure); diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 9afcbf7..0995ab3 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1096,7 +1096,7 @@ static int rk_iommu_domain_probe(struct platform_device *pdev) return -ENOMEM; /* Set dma_ops for dev, otherwise it would be dummy_dma_ops */ - arch_setup_dma_ops(dev, 0, DMA_BIT_MASK(32), NULL, false); + arch_setup_dma_ops(dev, 0, DMA_BIT_MASK(32), false, NULL, false); dma_set_max_seg_size(dev, DMA_BIT_MASK(32)); dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index c9b7ad6..19f70d8 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -2533,7 +2533,7 @@ static int dpaa_eth_probe(struct platform_device *pdev) priv->buf_layout[TX].priv_data_size = DPAA_TX_PRIV_DATA_SIZE; /* Tx */ /* device used for DMA mapping */ - arch_setup_dma_ops(dev, 0, 0, NULL, false); + arch_setup_dma_ops(dev, 0, 0, false, NULL, false); err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(40)); if (err) { dev_err(dev, "dma_coerce_mask_and_coherent() failed\n"); diff --git a/drivers/of/device.c b/drivers/of/device.c index fd5cfad..1cc2115 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -89,6 +89,7 @@ void of_dma_configure(struct device *dev, struct device_node *np) bool coherent; unsigned long offset; const struct iommu_ops *iommu; + bool enforce_range = false; /* * Set default coherent_dma_mask to 32 bit. Drivers are expected to @@ -126,6 +127,8 @@ void of_dma_configure(struct device *dev, struct device_node *np) return; } dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset); + + enforce_range = true; } dev->dma_pfn_offset = offset; @@ -147,7 +150,7 @@ void of_dma_configure(struct device *dev, struct device_node *np) dev_dbg(dev, "device is%sbehind an iommu\n", iommu ? " " : " not "); - arch_setup_dma_ops(dev, dma_addr, size, iommu, coherent); + arch_setup_dma_ops(dev, dma_addr, size, enforce_range, iommu, coherent); } EXPORT_SYMBOL_GPL(of_dma_configure); diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c index 5ac373c..480b644 100644 --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c @@ -540,7 +540,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc, /* Objects are coherent, unless 'no shareability' flag set. */ if (!(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY)) - arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true); + arch_setup_dma_ops(&mc_dev->dev, 0, 0, false, NULL, true); /* * The device-specific probe callback will get invoked by device_add()