Path: blob/master/arch/blackfin/include/asm/dma-mapping.h
15126 views
/*1* Copyright 2004-2009 Analog Devices Inc.2*3* Licensed under the GPL-2 or later.4*/56#ifndef _BLACKFIN_DMA_MAPPING_H7#define _BLACKFIN_DMA_MAPPING_H89#include <asm/cacheflush.h>10struct scatterlist;1112void *dma_alloc_coherent(struct device *dev, size_t size,13dma_addr_t *dma_handle, gfp_t gfp);14void dma_free_coherent(struct device *dev, size_t size, void *vaddr,15dma_addr_t dma_handle);1617/*18* Now for the API extensions over the pci_ one19*/20#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)21#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)22#define dma_supported(d, m) (1)2324static inline int25dma_set_mask(struct device *dev, u64 dma_mask)26{27if (!dev->dma_mask || !dma_supported(dev, dma_mask))28return -EIO;2930*dev->dma_mask = dma_mask;3132return 0;33}3435static inline int36dma_mapping_error(struct device *dev, dma_addr_t dma_addr)37{38return 0;39}4041extern void42__dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir);43static inline void44__dma_sync_inline(dma_addr_t addr, size_t size, enum dma_data_direction dir)45{46switch (dir) {47case DMA_NONE:48BUG();49case DMA_TO_DEVICE: /* writeback only */50flush_dcache_range(addr, addr + size);51break;52case DMA_FROM_DEVICE: /* invalidate only */53case DMA_BIDIRECTIONAL: /* flush and invalidate */54/* Blackfin has no dedicated invalidate (it includes a flush) */55invalidate_dcache_range(addr, addr + size);56break;57}58}59static inline void60_dma_sync(dma_addr_t addr, size_t size, enum dma_data_direction dir)61{62if (__builtin_constant_p(dir))63__dma_sync_inline(addr, size, dir);64else65__dma_sync(addr, size, dir);66}6768static inline dma_addr_t69dma_map_single(struct device *dev, void *ptr, size_t size,70enum dma_data_direction dir)71{72_dma_sync((dma_addr_t)ptr, size, dir);73return (dma_addr_t) ptr;74}7576static inline dma_addr_t77dma_map_page(struct device *dev, struct page *page,78unsigned long offset, size_t size,79enum dma_data_direction dir)80{81return dma_map_single(dev, page_address(page) + offset, size, dir);82}8384static inline void85dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,86enum dma_data_direction dir)87{88BUG_ON(!valid_dma_direction(dir));89}9091static inline void92dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,93enum dma_data_direction dir)94{95dma_unmap_single(dev, dma_addr, size, dir);96}9798extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,99enum dma_data_direction dir);100101static inline void102dma_unmap_sg(struct device *dev, struct scatterlist *sg,103int nhwentries, enum dma_data_direction dir)104{105BUG_ON(!valid_dma_direction(dir));106}107108static inline void109dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t handle,110unsigned long offset, size_t size,111enum dma_data_direction dir)112{113BUG_ON(!valid_dma_direction(dir));114}115116static inline void117dma_sync_single_range_for_device(struct device *dev, dma_addr_t handle,118unsigned long offset, size_t size,119enum dma_data_direction dir)120{121_dma_sync(handle + offset, size, dir);122}123124static inline void125dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle, size_t size,126enum dma_data_direction dir)127{128dma_sync_single_range_for_cpu(dev, handle, 0, size, dir);129}130131static inline void132dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,133enum dma_data_direction dir)134{135dma_sync_single_range_for_device(dev, handle, 0, size, dir);136}137138static inline void139dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents,140enum dma_data_direction dir)141{142BUG_ON(!valid_dma_direction(dir));143}144145extern void146dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,147int nents, enum dma_data_direction dir);148149static inline void150dma_cache_sync(struct device *dev, void *vaddr, size_t size,151enum dma_data_direction dir)152{153_dma_sync((dma_addr_t)vaddr, size, dir);154}155156#endif /* _BLACKFIN_DMA_MAPPING_H */157158159