Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1674867imm; Thu, 19 Jul 2018 06:06:22 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe4/ySz56mTtQ2M5NpyffpphPVB9hvdR1pgWo3DiVUFjQqXcRs2Cgc+rKMBDYhgE91KFemj X-Received: by 2002:a63:9a52:: with SMTP id e18-v6mr9836627pgo.188.1532005582380; Thu, 19 Jul 2018 06:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532005582; cv=none; d=google.com; s=arc-20160816; b=Jmu2wX4l/jQx/sZKuMUHZmWIetyk/ewDHONeH05i0MnB0zFn66W63nyQoPx/VzcY3d tL/jMtB9Uq7B2EOwoytPw9Ow476xm7ILPlvkLOu221IFoVZmy4w+aFhu9mhBO4wQLlJC YEPVPurnOW1CaVXujbRDzMJsEArtTzN7jPnBecNOOHciwEIiYYPheMG26k1gdBLnT4o0 msSsi8nV9y+rxEo9I9FxqTx7VLt5ECPfZi3I1NiErsCG1bVRb7X0UbyF+ZSo91TgZcaJ 4aLuDMoiYF5QbUqCnoYUfjnXBf9UJvjVeOGSk2wJfdZmTj2rw4E+oV6kQQf04Zy8nPND dh9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fcIoKHXpQ3Eb2RjJzX+DDQxonfkOHwxNCNG9+jfOyvo=; b=iPw7p7gYzsKrG8nVSGrBGtS4XjY3QSklNYiKBKIKHTpTfvWl2LDkj9Qnp1q1clpLGq 9/jLPgccVs1DcVXbO+SFwUhkJTzqj5B0uzWyZnrnAIn0Ks/fNHf2lUo5UiIbGwkxAODG RBs1FNKbx24I/o3a7OXxyIlpEAFMrFuTmls9awVRejXMO6o87cjvufWnpz+5nh6t5Cj1 vNzz8o62lsJJ8mRZU+2K63for+WIr3O8dfJLkEk96QeqxUcysteiYBTDgnB9R5lwjTdw bgRe0eH3ywBxlkAKaimUqXN8z/369xrffK24Y2X+e6TgekSlsVmmZKCrlT5ovZ64fvnZ 5osw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="VdS/axdQ"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q28-v6si5938151pgm.362.2018.07.19.06.06.07; Thu, 19 Jul 2018 06:06:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="VdS/axdQ"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731717AbeGSNsb (ORCPT + 99 others); Thu, 19 Jul 2018 09:48:31 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:38822 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731645AbeGSNsa (ORCPT ); Thu, 19 Jul 2018 09:48:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fcIoKHXpQ3Eb2RjJzX+DDQxonfkOHwxNCNG9+jfOyvo=; b=VdS/axdQ7O++yZwO0kGBOaXjb QcKFHW+uglpzPd8u2d21qddECb+gni9v75TKsAoZTJ9zDPyZaB5aWPS+GgB2V/fNrhEetcGOC/OYp ilMyKZVC+TqLb5KS8GVxuiHfm6SPvKUNzh4ezdxuq/KKc2cHlXJR02u7/0mXeydjcGwbS1mlHo5In eaSmTYmjniET8n5TXwh4QP3jCak4qwYqARyssaABaCROScwHfIf488UgxPvVuHLkJ7fNRT/uyNzlu DFbieSSFlznGBqG4Y7tlxZUk3piY+irvM7vx1/GGwkb4ZL/ue8DktSeg9Zi1SX5OonUwPholENRA1 2pWoOJz8w==; Received: from [96.72.186.57] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fg8cR-0001gl-5I; Thu, 19 Jul 2018 13:05:19 +0000 From: Christoph Hellwig To: Yoshinori Sato , Rich Felker Cc: Jacopo Mondi , Thomas Petazzoni , linux-sh@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] sh: split arch/sh/mm/consistent.c Date: Thu, 19 Jul 2018 06:05:15 -0700 Message-Id: <20180719130516.1989-5-hch@lst.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180719130516.1989-1-hch@lst.de> References: <20180719130516.1989-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Half of the file just contains platform device memory setup code which is required for all builds, and half contains helpers for dma coherent allocation, which is only needed if CONFIG_DMA_NONCOHERENT is enabled. Signed-off-by: Christoph Hellwig --- arch/sh/kernel/Makefile | 2 +- arch/sh/kernel/dma-coherent.c | 85 +++++++++++++++++++++++++++++++++++ arch/sh/mm/consistent.c | 80 --------------------------------- 3 files changed, 86 insertions(+), 81 deletions(-) create mode 100644 arch/sh/kernel/dma-coherent.c diff --git a/arch/sh/kernel/Makefile b/arch/sh/kernel/Makefile index cb5f1bfb52de..d5ddb64bfffe 100644 --- a/arch/sh/kernel/Makefile +++ b/arch/sh/kernel/Makefile @@ -45,7 +45,7 @@ obj-$(CONFIG_DUMP_CODE) += disassemble.o obj-$(CONFIG_HIBERNATION) += swsusp.o obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o -obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o +obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o dma-coherent.o obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o ccflags-y := -Werror diff --git a/arch/sh/kernel/dma-coherent.c b/arch/sh/kernel/dma-coherent.c new file mode 100644 index 000000000000..0e7720b5d495 --- /dev/null +++ b/arch/sh/kernel/dma-coherent.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2004 - 2007 Paul Mundt + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + */ +#include +#include +#include +#include +#include +#include + +void *dma_generic_alloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, + unsigned long attrs) +{ + void *ret, *ret_nocache; + int order = get_order(size); + + gfp |= __GFP_ZERO; + + ret = (void *)__get_free_pages(gfp, order); + if (!ret) + return NULL; + + /* + * Pages from the page allocator may have data present in + * cache. So flush the cache before using uncached memory. + */ + sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL); + + ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size); + if (!ret_nocache) { + free_pages((unsigned long)ret, order); + return NULL; + } + + split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order); + + *dma_handle = virt_to_phys(ret); + if (!WARN_ON(!dev)) + *dma_handle - PFN_PHYS(dev->dma_pfn_offset); + + return ret_nocache; +} + +void dma_generic_free_coherent(struct device *dev, size_t size, + void *vaddr, dma_addr_t dma_handle, + unsigned long attrs) +{ + int order = get_order(size); + unsigned long pfn = (dma_handle >> PAGE_SHIFT); + int k; + + if (!WARN_ON(!dev)) + pfn + dev->dma_pfn_offset; + + for (k = 0; k < (1 << order); k++) + __free_pages(pfn_to_page(pfn + k), 0); + + iounmap(vaddr); +} + +void sh_sync_dma_for_device(void *vaddr, size_t size, + enum dma_data_direction direction) +{ + void *addr = sh_cacheop_vaddr(vaddr); + + switch (direction) { + case DMA_FROM_DEVICE: /* invalidate only */ + __flush_invalidate_region(addr, size); + break; + case DMA_TO_DEVICE: /* writeback only */ + __flush_wback_region(addr, size); + break; + case DMA_BIDIRECTIONAL: /* writeback and invalidate */ + __flush_purge_region(addr, size); + break; + default: + BUG(); + } +} +EXPORT_SYMBOL(sh_sync_dma_for_device); diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c index 1622ae6b9dbd..792f36129062 100644 --- a/arch/sh/mm/consistent.c +++ b/arch/sh/mm/consistent.c @@ -1,10 +1,6 @@ /* - * arch/sh/mm/consistent.c - * * Copyright (C) 2004 - 2007 Paul Mundt * - * Declared coherent memory functions based on arch/x86/kernel/pci-dma_32.c - * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. @@ -13,83 +9,7 @@ #include #include #include -#include #include -#include -#include -#include -#include - -void *dma_generic_alloc_coherent(struct device *dev, size_t size, - dma_addr_t *dma_handle, gfp_t gfp, - unsigned long attrs) -{ - void *ret, *ret_nocache; - int order = get_order(size); - - gfp |= __GFP_ZERO; - - ret = (void *)__get_free_pages(gfp, order); - if (!ret) - return NULL; - - /* - * Pages from the page allocator may have data present in - * cache. So flush the cache before using uncached memory. - */ - sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL); - - ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size); - if (!ret_nocache) { - free_pages((unsigned long)ret, order); - return NULL; - } - - split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order); - - *dma_handle = virt_to_phys(ret); - if (!WARN_ON(!dev)) - *dma_handle -= PFN_PHYS(dev->dma_pfn_offset); - - return ret_nocache; -} - -void dma_generic_free_coherent(struct device *dev, size_t size, - void *vaddr, dma_addr_t dma_handle, - unsigned long attrs) -{ - int order = get_order(size); - unsigned long pfn = dma_handle >> PAGE_SHIFT; - int k; - - if (!WARN_ON(!dev)) - pfn += dev->dma_pfn_offset; - - for (k = 0; k < (1 << order); k++) - __free_pages(pfn_to_page(pfn + k), 0); - - iounmap(vaddr); -} - -void sh_sync_dma_for_device(void *vaddr, size_t size, - enum dma_data_direction direction) -{ - void *addr = sh_cacheop_vaddr(vaddr); - - switch (direction) { - case DMA_FROM_DEVICE: /* invalidate only */ - __flush_invalidate_region(addr, size); - break; - case DMA_TO_DEVICE: /* writeback only */ - __flush_wback_region(addr, size); - break; - case DMA_BIDIRECTIONAL: /* writeback and invalidate */ - __flush_purge_region(addr, size); - break; - default: - BUG(); - } -} static int __init memchunk_setup(char *str) { -- 2.18.0