From patchwork Tue Feb 18 18:41:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11389275 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 43A33930 for ; Tue, 18 Feb 2020 18:41:52 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 21F8E21D56 for ; Tue, 18 Feb 2020 18:41:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Fx+n/kIR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21F8E21D56 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Jw8JfdMthnvg5W5RPQKxaikkMzmmDB0xtoPWc4BjRU0=; b=Fx+n/kIRM562Qs HtIDjBE/c/KN8C8ZQBlyQOHJA/3O5iqn+DCnIYf/WPGsy7tyLc1fzrJJ8LYbfVO6eS/9exy4Iitzm GQbpaQG7/R5qQvoUIujZUiyzYLWWWeK6s2EnkDoYcRQ9HaEhYBauCvHglup5337BAMa0Fz4J8lh/E aR4auP+pK8v5kh5N8jR/Sr6o8BiS85z6VWyZ+HdtTlWQicwnIuPdRO6Zt2baST/fYUfqlBEgjGnuT NAmAGjcmAOjslID2Lxgdb5TAgowNLgSB9x6gQOXlYLyjVLIyRM7tp9P6qGEK5oH5uvZNlWZude2Qh lkbx2Dk9vUJkMdB18Asg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j47oa-0002r6-C0; Tue, 18 Feb 2020 18:41:48 +0000 Received: from [199.255.44.128] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j47oW-0002jH-ED; Tue, 18 Feb 2020 18:41:47 +0000 From: Christoph Hellwig To: Russell King Subject: [PATCH 1/3] ARM/dma-mapping: remove get_coherent_dma_mask Date: Tue, 18 Feb 2020 10:41:01 -0800 Message-Id: <20200218184103.35932-2-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200218184103.35932-1-hch@lst.de> References: <20200218184103.35932-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Peter Ujfalusi , iommu@lists.linux-foundation.org, Robin Murphy , linux-arm-kernel@lists.infradead.org, Roger Quadros Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The core DMA code already checks for valid DMA masks earlier on, and doesn't allow NULL struct device pointers. Remove the now not required checks. Signed-off-by: Christoph Hellwig --- arch/arm/mm/dma-mapping.c | 41 ++++----------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 9414d72f664b..72ddc3d0f5eb 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -219,7 +219,7 @@ const struct dma_map_ops arm_coherent_dma_ops = { }; EXPORT_SYMBOL(arm_coherent_dma_ops); -static int __dma_supported(struct device *dev, u64 mask, bool warn) +static int __dma_supported(struct device *dev, u64 mask) { unsigned long max_dma_pfn = min(max_pfn - 1, arm_dma_pfn_limit); @@ -227,41 +227,11 @@ static int __dma_supported(struct device *dev, u64 mask, bool warn) * Translate the device's DMA mask to a PFN limit. This * PFN number includes the page which we can DMA to. */ - if (dma_to_pfn(dev, mask) < max_dma_pfn) { - if (warn) - dev_warn(dev, "Coherent DMA mask %#llx (pfn %#lx-%#lx) covers a smaller range of system memory than the DMA zone pfn 0x0-%#lx\n", - mask, - dma_to_pfn(dev, 0), dma_to_pfn(dev, mask) + 1, - max_dma_pfn + 1); + if (dma_to_pfn(dev, mask) < max_dma_pfn) return 0; - } - return 1; } -static u64 get_coherent_dma_mask(struct device *dev) -{ - u64 mask = (u64)DMA_BIT_MASK(32); - - if (dev) { - mask = dev->coherent_dma_mask; - - /* - * Sanity check the DMA mask - it must be non-zero, and - * must be able to be satisfied by a DMA allocation. - */ - if (mask == 0) { - dev_warn(dev, "coherent DMA mask is unset\n"); - return 0; - } - - if (!__dma_supported(dev, mask, true)) - return 0; - } - - return mask; -} - static void __dma_clear_buffer(struct page *page, size_t size, int coherent_flag) { /* @@ -688,7 +658,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp, pgprot_t prot, bool is_coherent, unsigned long attrs, const void *caller) { - u64 mask = get_coherent_dma_mask(dev); + u64 mask = dev->coherent_dma_mask; struct page *page = NULL; void *addr; bool allowblock, cma; @@ -712,9 +682,6 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, } #endif - if (!mask) - return NULL; - buf = kzalloc(sizeof(*buf), gfp & ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM)); if (!buf) @@ -1095,7 +1062,7 @@ void arm_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, */ int arm_dma_supported(struct device *dev, u64 mask) { - return __dma_supported(dev, mask, false); + return __dma_supported(dev, mask); } static const struct dma_map_ops *arm_get_dma_map_ops(bool coherent) From patchwork Tue Feb 18 18:41:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11389277 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 C138C13A4 for ; Tue, 18 Feb 2020 18:42:07 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 9FB3321D56 for ; Tue, 18 Feb 2020 18:42:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UZlglxzQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FB3321D56 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lOtJaMIs7MmvQUHyuk80MrWcw68NLw9gZQnDiYyLxnE=; b=UZlglxzQE3J+DX ADwqkD+94FjWf6A+wU10B7szkcDA/6jBxhRe2EA0k8mNhKKeRsuDAAWa0PcR/NMbgHqHVSfhrXxg3 Wv6icZY377E9ZLNDTFuF/kijwIke2TZTi6WnwxMEyGkwr07tuUYgy4yqe2Yvk/lfrRAiRvqqXWKuG 4UCjlcxiL9gP7QdB/ZmuvISimOCccUltvAe1OXmLQMXYCS/6K2yNU4JZaQtPqAp2zRWop6Bgi0Fe3 Hw4N9h38tSUA97eXwF1qr59jJfk0iWKFjJyO8pCQjUYKSrAE15H/bv57PwhOGNz0V/3RWT4a9t+NQ Bu9SRY4ZMl0z72zqjwdA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j47oo-00034e-C1; Tue, 18 Feb 2020 18:42:02 +0000 Received: from [199.255.44.128] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j47oh-0002xO-K7; Tue, 18 Feb 2020 18:41:55 +0000 From: Christoph Hellwig To: Russell King Subject: [PATCH 2/3] ARM/dma-mapping: take the bus limit into account in __dma_alloc Date: Tue, 18 Feb 2020 10:41:02 -0800 Message-Id: <20200218184103.35932-3-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200218184103.35932-1-hch@lst.de> References: <20200218184103.35932-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Peter Ujfalusi , iommu@lists.linux-foundation.org, Robin Murphy , linux-arm-kernel@lists.infradead.org, Roger Quadros Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The DMA coherent allocator needs to take bus limits into account for picking the zone that the memory is allocated from. Reported-by: Roger Quadros Signed-off-by: Christoph Hellwig Tested-by: Peter Ujfalusi Tested-by: Roger Quadros --- arch/arm/mm/dma-mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 72ddc3d0f5eb..87aba505554a 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -658,7 +658,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp, pgprot_t prot, bool is_coherent, unsigned long attrs, const void *caller) { - u64 mask = dev->coherent_dma_mask; + u64 mask = min_not_zero(dev->coherent_dma_mask, dev->bus_dma_limit); struct page *page = NULL; void *addr; bool allowblock, cma; From patchwork Tue Feb 18 18:41:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 11389279 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 E8DF013A4 for ; Tue, 18 Feb 2020 18:42:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 C768124125 for ; Tue, 18 Feb 2020 18:42:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="um24azcE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C768124125 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QYl1Uj9AAnz6Ue2XY7Bw+nJpjIaFSdAC2mcNcMtAIBY=; b=um24azcEu0ukkL 8lUYIdaqsyroZ4W/gxnDrSzahzdoOfMq0jugGxyxeVvgTMQbM0uPjgoYkF/cvWgIUG7UL4TtrYfys LKudwzG5oEXVm4bs2d1YRR2USmf8iOdOFygvYf7b3Rl3aMrH8OFyEPyIDp0FFA2nRSksTFogC+1K4 3Y0m4JMGezd5AckyNayhptWjAPVYOduWSaM3SGj4swTFDtfpCGiTFMIRf8TnA6oRxAY34ZRT9Kaon RQp7fuuenoKLyGMe90DqGWUEK0M/QJbU5vTIhgf7T3zdqCoOBwgwfS5beI7uBCD8y4lb9lheoL5/3 +eTevMg1reyq2uKic7rw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1j47p0-0003Fs-RS; Tue, 18 Feb 2020 18:42:14 +0000 Received: from [199.255.44.128] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1j47ou-000390-KX; Tue, 18 Feb 2020 18:42:08 +0000 From: Christoph Hellwig To: Russell King Subject: [PATCH 3/3] ARM/dma-mapping: merge __dma_supported into arm_dma_supported Date: Tue, 18 Feb 2020 10:41:03 -0800 Message-Id: <20200218184103.35932-4-hch@lst.de> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200218184103.35932-1-hch@lst.de> References: <20200218184103.35932-1-hch@lst.de> MIME-Version: 1.0 X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, Peter Ujfalusi , iommu@lists.linux-foundation.org, Robin Murphy , linux-arm-kernel@lists.infradead.org, Roger Quadros Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Merge __dma_supported into its only caller, and move the resulting function so that it doesn't need a forward declaration. Also mark it static as there are no callers outside of dma-mapping.c. Signed-off-by: Christoph Hellwig --- arch/arm/include/asm/dma-iommu.h | 2 -- arch/arm/mm/dma-mapping.c | 41 +++++++++++++------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h index 772f48ef84b7..86405cc81385 100644 --- a/arch/arm/include/asm/dma-iommu.h +++ b/arch/arm/include/asm/dma-iommu.h @@ -33,7 +33,5 @@ int arm_iommu_attach_device(struct device *dev, struct dma_iommu_mapping *mapping); void arm_iommu_detach_device(struct device *dev); -int arm_dma_supported(struct device *dev, u64 mask); - #endif /* __KERNEL__ */ #endif diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 87aba505554a..8a8949174b1c 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -179,6 +179,23 @@ static void arm_dma_sync_single_for_device(struct device *dev, __dma_page_cpu_to_dev(page, offset, size, dir); } +/* + * Return whether the given device DMA address mask can be supported + * properly. For example, if your device can only drive the low 24-bits + * during bus mastering, then you would pass 0x00ffffff as the mask + * to this function. + */ +static int arm_dma_supported(struct device *dev, u64 mask) +{ + unsigned long max_dma_pfn = min(max_pfn - 1, arm_dma_pfn_limit); + + /* + * Translate the device's DMA mask to a PFN limit. This + * PFN number includes the page which we can DMA to. + */ + return dma_to_pfn(dev, mask) >= max_dma_pfn; +} + const struct dma_map_ops arm_dma_ops = { .alloc = arm_dma_alloc, .free = arm_dma_free, @@ -219,19 +236,6 @@ const struct dma_map_ops arm_coherent_dma_ops = { }; EXPORT_SYMBOL(arm_coherent_dma_ops); -static int __dma_supported(struct device *dev, u64 mask) -{ - unsigned long max_dma_pfn = min(max_pfn - 1, arm_dma_pfn_limit); - - /* - * Translate the device's DMA mask to a PFN limit. This - * PFN number includes the page which we can DMA to. - */ - if (dma_to_pfn(dev, mask) < max_dma_pfn) - return 0; - return 1; -} - static void __dma_clear_buffer(struct page *page, size_t size, int coherent_flag) { /* @@ -1054,17 +1058,6 @@ void arm_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, dir); } -/* - * Return whether the given device DMA address mask can be supported - * properly. For example, if your device can only drive the low 24-bits - * during bus mastering, then you would pass 0x00ffffff as the mask - * to this function. - */ -int arm_dma_supported(struct device *dev, u64 mask) -{ - return __dma_supported(dev, mask); -} - static const struct dma_map_ops *arm_get_dma_map_ops(bool coherent) { /*