Skip to content

Commit

Permalink
dma-mapping: implement dmam_alloc_coherent using dmam_alloc_attrs
Browse files Browse the repository at this point in the history
dmam_alloc_coherent is just the default no-flags case of
dmam_alloc_attrs, so take advantage of this similar to the non-managed
version.

Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Christoph Hellwig committed Jan 4, 2019
1 parent 2e05ea5 commit d7076f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
20 changes: 13 additions & 7 deletions include/linux/dma-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,20 @@ dma_mark_declared_memory_occupied(struct device *dev,
* Managed DMA API
*/
#ifdef CONFIG_HAS_DMA
extern void *dmam_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp);
extern void *dmam_alloc_attrs(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp,
unsigned long attrs);
extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
dma_addr_t dma_handle);
#else /* !CONFIG_HAS_DMA */
static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp)
static inline void *dmam_alloc_attrs(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp,
unsigned long attrs)
{ return NULL; }
static inline void dmam_free_coherent(struct device *dev, size_t size,
void *vaddr, dma_addr_t dma_handle) { }
#endif /* !CONFIG_HAS_DMA */

extern void *dmam_alloc_attrs(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp,
unsigned long attrs);
#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
extern int dmam_declare_coherent_memory(struct device *dev,
phys_addr_t phys_addr,
Expand All @@ -711,6 +710,13 @@ static inline void dmam_release_declared_memory(struct device *dev)
}
#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */

static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp)
{
return dmam_alloc_attrs(dev, size, dma_handle, gfp,
(gfp & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0);
}

static inline void *dma_alloc_wc(struct device *dev, size_t size,
dma_addr_t *dma_addr, gfp_t gfp)
{
Expand Down
39 changes: 0 additions & 39 deletions kernel/dma/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,6 @@ static int dmam_match(struct device *dev, void *res, void *match_data)
return 0;
}

/**
* dmam_alloc_coherent - Managed dma_alloc_coherent()
* @dev: Device to allocate coherent memory for
* @size: Size of allocation
* @dma_handle: Out argument for allocated DMA handle
* @gfp: Allocation flags
*
* Managed dma_alloc_coherent(). Memory allocated using this function
* will be automatically released on driver detach.
*
* RETURNS:
* Pointer to allocated memory on success, NULL on failure.
*/
void *dmam_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t gfp)
{
struct dma_devres *dr;
void *vaddr;

dr = devres_alloc(dmam_release, sizeof(*dr), gfp);
if (!dr)
return NULL;

vaddr = dma_alloc_coherent(dev, size, dma_handle, gfp);
if (!vaddr) {
devres_free(dr);
return NULL;
}

dr->vaddr = vaddr;
dr->dma_handle = *dma_handle;
dr->size = size;

devres_add(dev, dr);

return vaddr;
}
EXPORT_SYMBOL(dmam_alloc_coherent);

/**
* dmam_free_coherent - Managed dma_free_coherent()
* @dev: Device to free coherent memory for
Expand Down

0 comments on commit d7076f0

Please sign in to comment.