aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-07-18 09:55:20 -0400
committerChristoph Hellwig <hch@lst.de>2018-08-02 07:54:15 -0400
commit46bcde94cd02283535cb719666399f1c4cfb8f22 (patch)
treefadc33231f3e6a67d572885d180af95aa54e4a6c
parenta602915f5d0d9eff96a1d85b6f81e4921b52edfe (diff)
sh: split arch/sh/mm/consistent.c
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 <hch@lst.de> Acked-by: Yoshinori Sato <ysato@users.sourceforge.jp>
-rw-r--r--arch/sh/kernel/Makefile2
-rw-r--r--arch/sh/kernel/dma-coherent.c84
-rw-r--r--arch/sh/mm/consistent.c80
3 files changed, 85 insertions, 81 deletions
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
45obj-$(CONFIG_HIBERNATION) += swsusp.o 45obj-$(CONFIG_HIBERNATION) += swsusp.o
46obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o 46obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o
47obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o 47obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o
48obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o 48obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o dma-coherent.o
49obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o 49obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
50 50
51ccflags-y := -Werror 51ccflags-y := -Werror
diff --git a/arch/sh/kernel/dma-coherent.c b/arch/sh/kernel/dma-coherent.c
new file mode 100644
index 000000000000..2518065d5d27
--- /dev/null
+++ b/arch/sh/kernel/dma-coherent.c
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2004 - 2007 Paul Mundt
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
8#include <linux/mm.h>
9#include <linux/init.h>
10#include <linux/dma-mapping.h>
11#include <linux/module.h>
12#include <asm/cacheflush.h>
13#include <asm/addrspace.h>
14
15void *dma_generic_alloc_coherent(struct device *dev, size_t size,
16 dma_addr_t *dma_handle, gfp_t gfp,
17 unsigned long attrs)
18{
19 void *ret, *ret_nocache;
20 int order = get_order(size);
21
22 gfp |= __GFP_ZERO;
23
24 ret = (void *)__get_free_pages(gfp, order);
25 if (!ret)
26 return NULL;
27
28 /*
29 * Pages from the page allocator may have data present in
30 * cache. So flush the cache before using uncached memory.
31 */
32 sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL);
33
34 ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size);
35 if (!ret_nocache) {
36 free_pages((unsigned long)ret, order);
37 return NULL;
38 }
39
40 split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order);
41
42 *dma_handle = virt_to_phys(ret);
43 if (!WARN_ON(!dev))
44 *dma_handle -= PFN_PHYS(dev->dma_pfn_offset);
45
46 return ret_nocache;
47}
48
49void dma_generic_free_coherent(struct device *dev, size_t size,
50 void *vaddr, dma_addr_t dma_handle,
51 unsigned long attrs)
52{
53 int order = get_order(size);
54 unsigned long pfn = (dma_handle >> PAGE_SHIFT);
55 int k;
56
57 if (!WARN_ON(!dev))
58 pfn += dev->dma_pfn_offset;
59
60 for (k = 0; k < (1 << order); k++)
61 __free_pages(pfn_to_page(pfn + k), 0);
62
63 iounmap(vaddr);
64}
65
66void sh_sync_dma_for_device(void *vaddr, size_t size,
67 enum dma_data_direction direction)
68{
69 void *addr = sh_cacheop_vaddr(vaddr);
70
71 switch (direction) {
72 case DMA_FROM_DEVICE: /* invalidate only */
73 __flush_invalidate_region(addr, size);
74 break;
75 case DMA_TO_DEVICE: /* writeback only */
76 __flush_wback_region(addr, size);
77 break;
78 case DMA_BIDIRECTIONAL: /* writeback and invalidate */
79 __flush_purge_region(addr, size);
80 break;
81 default:
82 BUG();
83 }
84}
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 @@
1/* 1/*
2 * arch/sh/mm/consistent.c
3 *
4 * Copyright (C) 2004 - 2007 Paul Mundt 2 * Copyright (C) 2004 - 2007 Paul Mundt
5 * 3 *
6 * Declared coherent memory functions based on arch/x86/kernel/pci-dma_32.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public 4 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
10 * for more details. 6 * for more details.
@@ -13,83 +9,7 @@
13#include <linux/init.h> 9#include <linux/init.h>
14#include <linux/platform_device.h> 10#include <linux/platform_device.h>
15#include <linux/dma-mapping.h> 11#include <linux/dma-mapping.h>
16#include <linux/dma-debug.h>
17#include <linux/io.h> 12#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/gfp.h>
20#include <asm/cacheflush.h>
21#include <asm/addrspace.h>
22
23void *dma_generic_alloc_coherent(struct device *dev, size_t size,
24 dma_addr_t *dma_handle, gfp_t gfp,
25 unsigned long attrs)
26{
27 void *ret, *ret_nocache;
28 int order = get_order(size);
29
30 gfp |= __GFP_ZERO;
31
32 ret = (void *)__get_free_pages(gfp, order);
33 if (!ret)
34 return NULL;
35
36 /*
37 * Pages from the page allocator may have data present in
38 * cache. So flush the cache before using uncached memory.
39 */
40 sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL);
41
42 ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size);
43 if (!ret_nocache) {
44 free_pages((unsigned long)ret, order);
45 return NULL;
46 }
47
48 split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order);
49
50 *dma_handle = virt_to_phys(ret);
51 if (!WARN_ON(!dev))
52 *dma_handle -= PFN_PHYS(dev->dma_pfn_offset);
53
54 return ret_nocache;
55}
56
57void dma_generic_free_coherent(struct device *dev, size_t size,
58 void *vaddr, dma_addr_t dma_handle,
59 unsigned long attrs)
60{
61 int order = get_order(size);
62 unsigned long pfn = dma_handle >> PAGE_SHIFT;
63 int k;
64
65 if (!WARN_ON(!dev))
66 pfn += dev->dma_pfn_offset;
67
68 for (k = 0; k < (1 << order); k++)
69 __free_pages(pfn_to_page(pfn + k), 0);
70
71 iounmap(vaddr);
72}
73
74void sh_sync_dma_for_device(void *vaddr, size_t size,
75 enum dma_data_direction direction)
76{
77 void *addr = sh_cacheop_vaddr(vaddr);
78
79 switch (direction) {
80 case DMA_FROM_DEVICE: /* invalidate only */
81 __flush_invalidate_region(addr, size);
82 break;
83 case DMA_TO_DEVICE: /* writeback only */
84 __flush_wback_region(addr, size);
85 break;
86 case DMA_BIDIRECTIONAL: /* writeback and invalidate */
87 __flush_purge_region(addr, size);
88 break;
89 default:
90 BUG();
91 }
92}
93 13
94static int __init memchunk_setup(char *str) 14static int __init memchunk_setup(char *str)
95{ 15{