Skip to content

Commit d7076f0

Browse files
author
Christoph Hellwig
committed
dma-mapping: implement dmam_alloc_coherent using dmam_alloc_attrs
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>
1 parent 2e05ea5 commit d7076f0

2 files changed

Lines changed: 13 additions & 46 deletions

File tree

‎include/linux/dma-mapping.h‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,21 +677,20 @@ dma_mark_declared_memory_occupied(struct device *dev,
677677
* Managed DMA API
678678
*/
679679
#ifdef CONFIG_HAS_DMA
680-
extern void *dmam_alloc_coherent(struct device *dev, size_t size,
681-
dma_addr_t *dma_handle, gfp_t gfp);
680+
extern void *dmam_alloc_attrs(struct device *dev, size_t size,
681+
dma_addr_t *dma_handle, gfp_t gfp,
682+
unsigned long attrs);
682683
extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
683684
dma_addr_t dma_handle);
684685
#else /* !CONFIG_HAS_DMA */
685-
static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
686-
dma_addr_t *dma_handle, gfp_t gfp)
686+
static inline void *dmam_alloc_attrs(struct device *dev, size_t size,
687+
dma_addr_t *dma_handle, gfp_t gfp,
688+
unsigned long attrs)
687689
{ return NULL; }
688690
static inline void dmam_free_coherent(struct device *dev, size_t size,
689691
void *vaddr, dma_addr_t dma_handle) { }
690692
#endif /* !CONFIG_HAS_DMA */
691693

692-
extern void *dmam_alloc_attrs(struct device *dev, size_t size,
693-
dma_addr_t *dma_handle, gfp_t gfp,
694-
unsigned long attrs);
695694
#ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
696695
extern int dmam_declare_coherent_memory(struct device *dev,
697696
phys_addr_t phys_addr,
@@ -711,6 +710,13 @@ static inline void dmam_release_declared_memory(struct device *dev)
711710
}
712711
#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
713712

713+
static inline void *dmam_alloc_coherent(struct device *dev, size_t size,
714+
dma_addr_t *dma_handle, gfp_t gfp)
715+
{
716+
return dmam_alloc_attrs(dev, size, dma_handle, gfp,
717+
(gfp & __GFP_NOWARN) ? DMA_ATTR_NO_WARN : 0);
718+
}
719+
714720
static inline void *dma_alloc_wc(struct device *dev, size_t size,
715721
dma_addr_t *dma_addr, gfp_t gfp)
716722
{

‎kernel/dma/mapping.c‎

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,6 @@ static int dmam_match(struct device *dev, void *res, void *match_data)
4545
return 0;
4646
}
4747

48-
/**
49-
* dmam_alloc_coherent - Managed dma_alloc_coherent()
50-
* @dev: Device to allocate coherent memory for
51-
* @size: Size of allocation
52-
* @dma_handle: Out argument for allocated DMA handle
53-
* @gfp: Allocation flags
54-
*
55-
* Managed dma_alloc_coherent(). Memory allocated using this function
56-
* will be automatically released on driver detach.
57-
*
58-
* RETURNS:
59-
* Pointer to allocated memory on success, NULL on failure.
60-
*/
61-
void *dmam_alloc_coherent(struct device *dev, size_t size,
62-
dma_addr_t *dma_handle, gfp_t gfp)
63-
{
64-
struct dma_devres *dr;
65-
void *vaddr;
66-
67-
dr = devres_alloc(dmam_release, sizeof(*dr), gfp);
68-
if (!dr)
69-
return NULL;
70-
71-
vaddr = dma_alloc_coherent(dev, size, dma_handle, gfp);
72-
if (!vaddr) {
73-
devres_free(dr);
74-
return NULL;
75-
}
76-
77-
dr->vaddr = vaddr;
78-
dr->dma_handle = *dma_handle;
79-
dr->size = size;
80-
81-
devres_add(dev, dr);
82-
83-
return vaddr;
84-
}
85-
EXPORT_SYMBOL(dmam_alloc_coherent);
86-
8748
/**
8849
* dmam_free_coherent - Managed dma_free_coherent()
8950
* @dev: Device to free coherent memory for

0 commit comments

Comments
 (0)