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 <asm/cacheflush.h>
15 void *dma_alloc_coherent(struct device
*dev
, size_t size
,
16 dma_addr_t
*dma_handle
, gfp_t gfp
)
19 /* ignore region specifiers */
20 gfp
&= ~(__GFP_DMA
| __GFP_HIGHMEM
);
22 if (dev
== NULL
|| (*dev
->dma_mask
< 0xffffffff))
24 ret
= (void *)__get_free_pages(gfp
, get_order(size
));
28 *dma_handle
= virt_to_phys(ret
);
33 void dma_free_coherent(struct device
*dev
, size_t size
,
34 void *vaddr
, dma_addr_t dma_handle
)
36 free_pages((unsigned long)vaddr
, get_order(size
));
39 void dma_sync_single_for_device(struct device
*dev
, dma_addr_t handle
,
40 size_t size
, enum dma_data_direction dir
)
44 flush_dcache_range(handle
, size
);
47 /* Should be clear already */
50 if (printk_ratelimit())
51 printk("dma_sync_single_for_device: unsupported dir %u\n", dir
);
56 EXPORT_SYMBOL(dma_sync_single_for_device
);
57 dma_addr_t
dma_map_single(struct device
*dev
, void *addr
, size_t size
,
58 enum dma_data_direction dir
)
60 dma_addr_t handle
= virt_to_phys(addr
);
61 flush_dcache_range(handle
, size
);
64 EXPORT_SYMBOL(dma_map_single
);
66 dma_addr_t
dma_map_page(struct device
*dev
, struct page
*page
,
67 unsigned long offset
, size_t size
,
68 enum dma_data_direction dir
)
70 dma_addr_t handle
= page_to_phys(page
) + offset
;
71 dma_sync_single_for_device(dev
, handle
, size
, dir
);
74 EXPORT_SYMBOL(dma_map_page
);