Commit de7cf917 authored by Christoph Hellwig's avatar Christoph Hellwig

dma-mapping: add new {alloc,free}_noncoherent dma_map_ops methods

This will allow IOMMU drivers to allocate non-contigous memory and
return a vmapped virtual address.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent efa70f2f
...@@ -74,6 +74,11 @@ struct dma_map_ops { ...@@ -74,6 +74,11 @@ struct dma_map_ops {
gfp_t gfp); gfp_t gfp);
void (*free_pages)(struct device *dev, size_t size, struct page *vaddr, void (*free_pages)(struct device *dev, size_t size, struct page *vaddr,
dma_addr_t dma_handle, enum dma_data_direction dir); dma_addr_t dma_handle, enum dma_data_direction dir);
void* (*alloc_noncoherent)(struct device *dev, size_t size,
dma_addr_t *dma_handle, enum dma_data_direction dir,
gfp_t gfp);
void (*free_noncoherent)(struct device *dev, size_t size, void *vaddr,
dma_addr_t dma_handle, enum dma_data_direction dir);
int (*mmap)(struct device *, struct vm_area_struct *, int (*mmap)(struct device *, struct vm_area_struct *,
void *, dma_addr_t, size_t, void *, dma_addr_t, size_t,
unsigned long attrs); unsigned long attrs);
......
...@@ -513,19 +513,40 @@ EXPORT_SYMBOL_GPL(dma_free_pages); ...@@ -513,19 +513,40 @@ EXPORT_SYMBOL_GPL(dma_free_pages);
void *dma_alloc_noncoherent(struct device *dev, size_t size, void *dma_alloc_noncoherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp) dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp)
{ {
const struct dma_map_ops *ops = get_dma_ops(dev);
void *vaddr;
if (!ops || !ops->alloc_noncoherent) {
struct page *page; struct page *page;
page = dma_alloc_pages(dev, size, dma_handle, dir, gfp); page = dma_alloc_pages(dev, size, dma_handle, dir, gfp);
if (!page) if (!page)
return NULL; return NULL;
return page_address(page); return page_address(page);
}
size = PAGE_ALIGN(size);
vaddr = ops->alloc_noncoherent(dev, size, dma_handle, dir, gfp);
if (vaddr)
debug_dma_map_page(dev, virt_to_page(vaddr), 0, size, dir,
*dma_handle);
return vaddr;
} }
EXPORT_SYMBOL_GPL(dma_alloc_noncoherent); EXPORT_SYMBOL_GPL(dma_alloc_noncoherent);
void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr, void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
dma_addr_t dma_handle, enum dma_data_direction dir) dma_addr_t dma_handle, enum dma_data_direction dir)
{ {
const struct dma_map_ops *ops = get_dma_ops(dev);
if (!ops || !ops->free_noncoherent) {
dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir); dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir);
return;
}
size = PAGE_ALIGN(size);
debug_dma_unmap_page(dev, dma_handle, size, dir);
ops->free_noncoherent(dev, size, vaddr, dma_handle, dir);
} }
EXPORT_SYMBOL_GPL(dma_free_noncoherent); EXPORT_SYMBOL_GPL(dma_free_noncoherent);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment