Skip to content

Commit 46bcde9

Browse files
author
Christoph Hellwig
committed
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>
1 parent a602915 commit 46bcde9

3 files changed

Lines changed: 85 additions & 81 deletions

File tree

‎arch/sh/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ obj-$(CONFIG_DUMP_CODE) += disassemble.o
4545
obj-$(CONFIG_HIBERNATION) += swsusp.o
4646
obj-$(CONFIG_DWARF_UNWINDER) += dwarf.o
4747
obj-$(CONFIG_PERF_EVENTS) += perf_event.o perf_callchain.o
48-
obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o
48+
obj-$(CONFIG_DMA_NONCOHERENT) += dma-nommu.o dma-coherent.o
4949
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
5050

5151
ccflags-y := -Werror

‎arch/sh/kernel/dma-coherent.c‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
15+
void *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+
49+
void 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+
66+
void 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+
}

‎arch/sh/mm/consistent.c‎

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
/*
2-
* arch/sh/mm/consistent.c
3-
*
42
* Copyright (C) 2004 - 2007 Paul Mundt
53
*
6-
* Declared coherent memory functions based on arch/x86/kernel/pci-dma_32.c
7-
*
84
* This file is subject to the terms and conditions of the GNU General Public
95
* License. See the file "COPYING" in the main directory of this archive
106
* for more details.
@@ -13,83 +9,7 @@
139
#include <linux/init.h>
1410
#include <linux/platform_device.h>
1511
#include <linux/dma-mapping.h>
16-
#include <linux/dma-debug.h>
1712
#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-
23-
void *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-
57-
void 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-
74-
void 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-
}
9313

9414
static int __init memchunk_setup(char *str)
9515
{

0 commit comments

Comments
 (0)