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
11 #include <linux/dma-mapping.h>
14 void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle)
16 struct page *page, *end, *free;
20 size = PAGE_ALIGN(size);
21 order = get_order(size);
23 page = alloc_pages(gfp, order);
27 ret = (void *)P2SEGADDR(page_to_bus(page));
30 * We must flush the cache before we pass it on to the device
32 dma_cache_wback_inv(ret, size);
34 *handle = (unsigned long)ret;
36 free = page + (size >> PAGE_SHIFT);
37 end = page + (1 << order);
40 set_page_count(page, 1);
42 } while (size -= PAGE_SIZE);
45 * Free any unused pages
48 set_page_count(page, 1);
56 void consistent_free(void *vaddr, size_t size)
58 unsigned long addr = P1SEGADDR((unsigned long)vaddr);
60 free_pages(addr, get_order(size));
63 void consistent_sync(void *vaddr, size_t size, int direction)
66 case DMA_FROM_DEVICE: /* invalidate only */
67 dma_cache_inv(vaddr, size);
69 case DMA_TO_DEVICE: /* writeback only */
70 dma_cache_wback(vaddr, size);
72 case DMA_BIDIRECTIONAL: /* writeback and invalidate */
73 dma_cache_wback_inv(vaddr, size);