From patchwork Fri Dec 29 08:18:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10136871 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 8DBA36037D for ; Fri, 29 Dec 2017 08:48:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B9AA2D348 for ; Fri, 29 Dec 2017 08:48:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 705702DC38; Fri, 29 Dec 2017 08:48:06 +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.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 04AFB2D348 for ; Fri, 29 Dec 2017 08:48:06 +0000 (UTC) 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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=sVibg2J5C/RlHaF2VlUGRt+jVnv7vjDRPlxsbS+AVOs=; b=L5zIfCXHOGm/kJdNqMinktIwZE utY+Z9ZphvsgMMhF03Zg9fmoQ2ZKBNkpvPd6w6JaoSSm3xGVz/8TdXOLTkCWhWcPtbASHRkbvG8MU XID62ov4DMzWx7umLgTJ7Vc0/ERnGIclj8kX0N0SZWeC4ea6OR9CBcBgyXn6gbMQTLg2evZu7HRyA JbRHntOop+IwEYS2TW7Sk7NSI76aeOD3oLtwenL4shEFg/c16ttTMXSb+cJCJ5rIcmAzEzSfs+A8E eFFfN4qSgo0weKhZkda9AW8vFgK1RUPHy9Q3QRTYvmWN5y99MWlQZjYHf45/0vc8IipqPWazL1W8s 7NgTb9OQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eUqKf-00076H-JF; Fri, 29 Dec 2017 08:48:01 +0000 Received: from 77.117.237.29.wireless.dyn.drei.com ([77.117.237.29] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1eUpvO-0002dp-Uf; Fri, 29 Dec 2017 08:21:55 +0000 From: Christoph Hellwig To: iommu@lists.linux-foundation.org Subject: [PATCH 36/67] x86: remove dma_alloc_coherent_mask Date: Fri, 29 Dec 2017 09:18:40 +0100 Message-Id: <20171229081911.2802-37-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171229081911.2802-1-hch@lst.de> References: <20171229081911.2802-1-hch@lst.de> 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: linux-mips@linux-mips.org, linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, Guan Xuetao , linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, linux-c6x-dev@linux-c6x.org, linux-hexagon@vger.kernel.org, x86@kernel.org, linux-snps-arc@lists.infradead.org, adi-buildroot-devel@lists.sourceforge.net, linux-m68k@lists.linux-m68k.org, patches@groups.riscv.org, linux-metag@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Michal Simek , linux-parisc@vger.kernel.org, linux-cris-kernel@axis.com, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.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 These days all devices (including the ISA fallback device) have a coherent DMA mask set, so remove the workaround. Signed-off-by: Christoph Hellwig --- arch/x86/include/asm/dma-mapping.h | 18 ++---------------- arch/x86/kernel/pci-dma.c | 10 ++++------ arch/x86/mm/mem_encrypt.c | 4 +--- drivers/xen/swiotlb-xen.c | 16 +--------------- 4 files changed, 8 insertions(+), 40 deletions(-) diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h index 6277c83c0eb1..545bf3721bc0 100644 --- a/arch/x86/include/asm/dma-mapping.h +++ b/arch/x86/include/asm/dma-mapping.h @@ -44,26 +44,12 @@ extern void dma_generic_free_coherent(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_addr, unsigned long attrs); -static inline unsigned long dma_alloc_coherent_mask(struct device *dev, - gfp_t gfp) -{ - unsigned long dma_mask = 0; - - dma_mask = dev->coherent_dma_mask; - if (!dma_mask) - dma_mask = (gfp & GFP_DMA) ? DMA_BIT_MASK(24) : DMA_BIT_MASK(32); - - return dma_mask; -} - static inline gfp_t dma_alloc_coherent_gfp_flags(struct device *dev, gfp_t gfp) { - unsigned long dma_mask = dma_alloc_coherent_mask(dev, gfp); - - if (dma_mask <= DMA_BIT_MASK(24)) + if (dev->coherent_dma_mask <= DMA_BIT_MASK(24)) gfp |= GFP_DMA; #ifdef CONFIG_X86_64 - if (dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA)) + if (dev->coherent_dma_mask <= DMA_BIT_MASK(32) && !(gfp & GFP_DMA)) gfp |= GFP_DMA32; #endif return gfp; diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c index df7ab02f959f..b59820872ec7 100644 --- a/arch/x86/kernel/pci-dma.c +++ b/arch/x86/kernel/pci-dma.c @@ -80,13 +80,10 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr, gfp_t flag, unsigned long attrs) { - unsigned long dma_mask; struct page *page; unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; dma_addr_t addr; - dma_mask = dma_alloc_coherent_mask(dev, flag); - again: page = NULL; /* CMA can be used only in the context which permits sleeping */ @@ -95,7 +92,7 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, flag); if (page) { addr = phys_to_dma(dev, page_to_phys(page)); - if (addr + size > dma_mask) { + if (addr + size > dev->coherent_dma_mask) { dma_release_from_contiguous(dev, page, count); page = NULL; } @@ -108,10 +105,11 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size, return NULL; addr = phys_to_dma(dev, page_to_phys(page)); - if (addr + size > dma_mask) { + if (addr + size > dev->coherent_dma_mask) { __free_pages(page, get_order(size)); - if (dma_mask < DMA_BIT_MASK(32) && !(flag & GFP_DMA)) { + if (dev->coherent_dma_mask < DMA_BIT_MASK(32) && + !(flag & GFP_DMA)) { flag = (flag & ~GFP_DMA32) | GFP_DMA; goto again; } diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c index 764b916ef7da..479586b8ca9b 100644 --- a/arch/x86/mm/mem_encrypt.c +++ b/arch/x86/mm/mem_encrypt.c @@ -203,12 +203,10 @@ void __init sme_early_init(void) static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { - unsigned long dma_mask; unsigned int order; struct page *page; void *vaddr = NULL; - dma_mask = dma_alloc_coherent_mask(dev, gfp); order = get_order(size); /* @@ -226,7 +224,7 @@ static void *sev_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, * mask with it already cleared. */ addr = __sme_clr(phys_to_dma(dev, page_to_phys(page))); - if ((addr + size) > dma_mask) { + if ((addr + size) > dev->coherent_dma_mask) { __free_pages(page, get_order(size)); } else { vaddr = page_address(page); diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 5bb72d3f8337..e1c60899fdbc 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -53,20 +53,6 @@ * API. */ -#ifndef CONFIG_X86 -static unsigned long dma_alloc_coherent_mask(struct device *dev, - gfp_t gfp) -{ - unsigned long dma_mask = 0; - - dma_mask = dev->coherent_dma_mask; - if (!dma_mask) - dma_mask = (gfp & GFP_DMA) ? DMA_BIT_MASK(24) : DMA_BIT_MASK(32); - - return dma_mask; -} -#endif - #define XEN_SWIOTLB_ERROR_CODE (~(dma_addr_t)0x0) static char *xen_io_tlb_start, *xen_io_tlb_end; @@ -328,7 +314,7 @@ xen_swiotlb_alloc_coherent(struct device *hwdev, size_t size, return ret; if (hwdev && hwdev->coherent_dma_mask) - dma_mask = dma_alloc_coherent_mask(hwdev, flags); + dma_mask = hwdev->coherent_dma_mask; /* At this point dma_handle is the physical address, next we are * going to set it to the machine address.