2 * Dynamic DMA mapping support.
4 * We never have any address translations to worry about, so this
8 #include <linux/types.h>
11 #include <linux/device.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/export.h>
14 #include <asm/cacheflush.h>
16 void *dma_alloc_coherent(struct device
*dev
, size_t size
,
17 dma_addr_t
*dma_handle
, gfp_t gfp
)
20 /* ignore region specifiers */
21 gfp
&= ~(__GFP_DMA
| __GFP_HIGHMEM
);
23 if (dev
== NULL
|| (*dev
->dma_mask
< 0xffffffff))
25 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
29 *dma_handle
= virt_to_phys(ret
);
34 void dma_free_coherent(struct device
*dev
, size_t size
,
35 void *vaddr
, dma_addr_t dma_handle
)
37 free_pages((unsigned long)vaddr
, get_order(size
));
40 void dma_sync_single_for_device(struct device
*dev
, dma_addr_t handle
,
41 size_t size
, enum dma_data_direction dir
)
45 flush_dcache_range(handle
, size
);
48 /* Should be clear already */
51 if (printk_ratelimit())
52 printk("dma_sync_single_for_device: unsupported dir %u\n", dir
);
57 EXPORT_SYMBOL(dma_sync_single_for_device
);
58 dma_addr_t
dma_map_single(struct device
*dev
, void *addr
, size_t size
,
59 enum dma_data_direction dir
)
61 dma_addr_t handle
= virt_to_phys(addr
);
62 flush_dcache_range(handle
, size
);
65 EXPORT_SYMBOL(dma_map_single
);
67 dma_addr_t
dma_map_page(struct device
*dev
, struct page
*page
,
68 unsigned long offset
, size_t size
,
69 enum dma_data_direction dir
)
71 dma_addr_t handle
= page_to_phys(page
) + offset
;
72 dma_sync_single_for_device(dev
, handle
, size
, dir
);
75 EXPORT_SYMBOL(dma_map_page
);