Changeset View
Changeset View
Standalone View
Standalone View
head/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | void (*sync_sg_for_device)(struct device *dev, struct scatterlist *sg, | ||||
int nents, enum dma_data_direction dir); | int nents, enum dma_data_direction dir); | ||||
int (*mapping_error)(struct device *dev, dma_addr_t dma_addr); | int (*mapping_error)(struct device *dev, dma_addr_t dma_addr); | ||||
int (*dma_supported)(struct device *dev, u64 mask); | int (*dma_supported)(struct device *dev, u64 mask); | ||||
int is_phys; | int is_phys; | ||||
}; | }; | ||||
#define DMA_BIT_MASK(n) ((2ULL << ((n) - 1)) - 1ULL) | #define DMA_BIT_MASK(n) ((2ULL << ((n) - 1)) - 1ULL) | ||||
int linux_dma_tag_init(struct device *dev, u64 mask); | |||||
void *linux_dma_alloc_coherent(struct device *dev, size_t size, | |||||
dma_addr_t *dma_handle, gfp_t flag); | |||||
dma_addr_t linux_dma_map_phys(struct device *dev, vm_paddr_t phys, size_t len); | |||||
void linux_dma_unmap(struct device *dev, dma_addr_t dma_addr, size_t size); | |||||
int linux_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, | |||||
int nents, enum dma_data_direction dir, struct dma_attrs *attrs); | |||||
void linux_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, | |||||
int nents, enum dma_data_direction dir, struct dma_attrs *attrs); | |||||
static inline int | static inline int | ||||
dma_supported(struct device *dev, u64 mask) | dma_supported(struct device *dev, u64 mask) | ||||
{ | { | ||||
/* XXX busdma takes care of this elsewhere. */ | /* XXX busdma takes care of this elsewhere. */ | ||||
return (1); | return (1); | ||||
} | } | ||||
static inline int | static inline int | ||||
dma_set_mask(struct device *dev, u64 dma_mask) | dma_set_mask(struct device *dev, u64 dma_mask) | ||||
{ | { | ||||
if (!dev->dma_mask || !dma_supported(dev, dma_mask)) | if (!dev->dma_priv || !dma_supported(dev, dma_mask)) | ||||
return -EIO; | return -EIO; | ||||
*dev->dma_mask = dma_mask; | return (linux_dma_tag_init(dev, dma_mask)); | ||||
return (0); | |||||
} | } | ||||
static inline int | static inline int | ||||
dma_set_coherent_mask(struct device *dev, u64 mask) | dma_set_coherent_mask(struct device *dev, u64 mask) | ||||
{ | { | ||||
if (!dma_supported(dev, mask)) | if (!dma_supported(dev, mask)) | ||||
return -EIO; | return -EIO; | ||||
Show All 11 Lines | if (r == 0) | ||||
dma_set_coherent_mask(dev, mask); | dma_set_coherent_mask(dev, mask); | ||||
return (r); | return (r); | ||||
} | } | ||||
static inline void * | static inline void * | ||||
dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, | dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, | ||||
gfp_t flag) | gfp_t flag) | ||||
{ | { | ||||
vm_paddr_t high; | return (linux_dma_alloc_coherent(dev, size, dma_handle, flag)); | ||||
size_t align; | |||||
void *mem; | |||||
if (dev != NULL && dev->dma_mask) | |||||
high = *dev->dma_mask; | |||||
else if (flag & GFP_DMA32) | |||||
high = BUS_SPACE_MAXADDR_32BIT; | |||||
else | |||||
high = BUS_SPACE_MAXADDR; | |||||
align = PAGE_SIZE << get_order(size); | |||||
mem = (void *)kmem_alloc_contig(size, flag, 0, high, align, 0, | |||||
VM_MEMATTR_DEFAULT); | |||||
if (mem) | |||||
*dma_handle = vtophys(mem); | |||||
else | |||||
*dma_handle = 0; | |||||
return (mem); | |||||
} | } | ||||
static inline void * | static inline void * | ||||
dma_zalloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, | dma_zalloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, | ||||
gfp_t flag) | gfp_t flag) | ||||
{ | { | ||||
return (dma_alloc_coherent(dev, size, dma_handle, flag | __GFP_ZERO)); | return (dma_alloc_coherent(dev, size, dma_handle, flag | __GFP_ZERO)); | ||||
} | } | ||||
static inline void | static inline void | ||||
dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, | dma_free_coherent(struct device *dev, size_t size, void *cpu_addr, | ||||
dma_addr_t dma_handle) | dma_addr_t dma_addr) | ||||
{ | { | ||||
linux_dma_unmap(dev, dma_addr, size); | |||||
kmem_free((vm_offset_t)cpu_addr, size); | kmem_free((vm_offset_t)cpu_addr, size); | ||||
} | } | ||||
/* XXX This only works with no iommu. */ | |||||
static inline dma_addr_t | static inline dma_addr_t | ||||
dma_map_single_attrs(struct device *dev, void *ptr, size_t size, | dma_map_single_attrs(struct device *dev, void *ptr, size_t size, | ||||
enum dma_data_direction dir, struct dma_attrs *attrs) | enum dma_data_direction dir, struct dma_attrs *attrs) | ||||
{ | { | ||||
return vtophys(ptr); | return (linux_dma_map_phys(dev, vtophys(ptr), size)); | ||||
} | } | ||||
static inline void | static inline void | ||||
dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, size_t size, | dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr, size_t size, | ||||
enum dma_data_direction dir, struct dma_attrs *attrs) | enum dma_data_direction dir, struct dma_attrs *attrs) | ||||
{ | { | ||||
linux_dma_unmap(dev, dma_addr, size); | |||||
} | } | ||||
static inline dma_addr_t | static inline dma_addr_t | ||||
dma_map_page_attrs(struct device *dev, struct page *page, size_t offset, | dma_map_page_attrs(struct device *dev, struct page *page, size_t offset, | ||||
size_t size, enum dma_data_direction dir, unsigned long attrs) | size_t size, enum dma_data_direction dir, unsigned long attrs) | ||||
{ | { | ||||
return (VM_PAGE_TO_PHYS(page) + offset); | return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size)); | ||||
} | } | ||||
static inline int | static inline int | ||||
dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents, | dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl, int nents, | ||||
enum dma_data_direction dir, struct dma_attrs *attrs) | enum dma_data_direction dir, struct dma_attrs *attrs) | ||||
{ | { | ||||
struct scatterlist *sg; | |||||
int i; | |||||
for_each_sg(sgl, sg, nents, i) | return (linux_dma_map_sg_attrs(dev, sgl, nents, dir, attrs)); | ||||
sg_dma_address(sg) = sg_phys(sg); | |||||
return (nents); | |||||
} | } | ||||
static inline void | static inline void | ||||
dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, int nents, | dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg, int nents, | ||||
enum dma_data_direction dir, struct dma_attrs *attrs) | enum dma_data_direction dir, struct dma_attrs *attrs) | ||||
{ | { | ||||
linux_dma_unmap_sg_attrs(dev, sg, nents, dir, attrs); | |||||
} | } | ||||
static inline dma_addr_t | static inline dma_addr_t | ||||
dma_map_page(struct device *dev, struct page *page, | dma_map_page(struct device *dev, struct page *page, | ||||
unsigned long offset, size_t size, enum dma_data_direction direction) | unsigned long offset, size_t size, enum dma_data_direction direction) | ||||
{ | { | ||||
return VM_PAGE_TO_PHYS(page) + offset; | return (linux_dma_map_phys(dev, VM_PAGE_TO_PHYS(page) + offset, size)); | ||||
} | } | ||||
static inline void | static inline void | ||||
dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, | dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, | ||||
enum dma_data_direction direction) | enum dma_data_direction direction) | ||||
{ | { | ||||
linux_dma_unmap(dev, dma_address, size); | |||||
} | } | ||||
static inline void | static inline void | ||||
dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, | dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, | ||||
enum dma_data_direction direction) | enum dma_data_direction direction) | ||||
{ | { | ||||
} | } | ||||
Show All 33 Lines | dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle, | ||||
unsigned long offset, size_t size, int direction) | unsigned long offset, size_t size, int direction) | ||||
{ | { | ||||
} | } | ||||
static inline int | static inline int | ||||
dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | dma_mapping_error(struct device *dev, dma_addr_t dma_addr) | ||||
{ | { | ||||
return (0); | return (dma_addr == 0); | ||||
} | } | ||||
static inline unsigned int dma_set_max_seg_size(struct device *dev, | static inline unsigned int dma_set_max_seg_size(struct device *dev, | ||||
unsigned int size) | unsigned int size) | ||||
{ | { | ||||
return (0); | return (0); | ||||
} | } | ||||
Show All 17 Lines |