[2.6 patch] make ocfs2_find_entry_el() static
[pv_ops_mirror.git] / arch / sh / mm / consistent.c
blobe220c29a3c00cf03fab0da8c4dd329160269d577
1 /*
2 * arch/sh/mm/consistent.c
4 * Copyright (C) 2004 Paul Mundt
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10 #include <linux/mm.h>
11 #include <linux/dma-mapping.h>
12 #include <asm/cacheflush.h>
13 #include <asm/addrspace.h>
14 #include <asm/io.h>
16 void *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *handle)
18 struct page *page, *end, *free;
19 void *ret;
20 int order;
22 size = PAGE_ALIGN(size);
23 order = get_order(size);
25 page = alloc_pages(gfp, order);
26 if (!page)
27 return NULL;
28 split_page(page, order);
30 ret = page_address(page);
31 memset(ret, 0, size);
32 *handle = virt_to_phys(ret);
35 * We must flush the cache before we pass it on to the device
37 __flush_purge_region(ret, size);
39 page = virt_to_page(ret);
40 free = page + (size >> PAGE_SHIFT);
41 end = page + (1 << order);
43 while (++page < end) {
44 /* Free any unused pages */
45 if (page >= free) {
46 __free_page(page);
50 return P2SEGADDR(ret);
53 void consistent_free(void *vaddr, size_t size)
55 unsigned long addr = P1SEGADDR((unsigned long)vaddr);
56 struct page *page=virt_to_page(addr);
57 int num_pages=(size+PAGE_SIZE-1) >> PAGE_SHIFT;
58 int i;
60 for(i=0;i<num_pages;i++) {
61 __free_page((page+i));
65 void consistent_sync(void *vaddr, size_t size, int direction)
67 void * p1addr = (void*) P1SEGADDR((unsigned long)vaddr);
69 switch (direction) {
70 case DMA_FROM_DEVICE: /* invalidate only */
71 __flush_invalidate_region(p1addr, size);
72 break;
73 case DMA_TO_DEVICE: /* writeback only */
74 __flush_wback_region(p1addr, size);
75 break;
76 case DMA_BIDIRECTIONAL: /* writeback and invalidate */
77 __flush_purge_region(p1addr, size);
78 break;
79 default:
80 BUG();
84 EXPORT_SYMBOL(consistent_alloc);
85 EXPORT_SYMBOL(consistent_free);
86 EXPORT_SYMBOL(consistent_sync);