1/*
2 * include/linux/dmapool.h
3 *
4 * Allocation pools for DMAable (coherent) memory.
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#ifndef LINUX_DMAPOOL_H
12#define LINUX_DMAPOOL_H
13
14#include <linux/nodemask_types.h>
15#include <linux/scatterlist.h>
16#include <asm/io.h>
17
18struct device;
19
20#ifdef CONFIG_HAS_DMA
21
22struct dma_pool *dma_pool_create_node(const char *name, struct device *dev,
23 size_t size, size_t align, size_t boundary, int node);
24
25void dma_pool_destroy(struct dma_pool *pool);
26
27void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
28 dma_addr_t *handle);
29void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t addr);
30
31/*
32 * Managed DMA pool
33 */
34struct dma_pool *dmam_pool_create(const char *name, struct device *dev,
35 size_t size, size_t align, size_t allocation);
36void dmam_pool_destroy(struct dma_pool *pool);
37
38#else /* !CONFIG_HAS_DMA */
39static inline struct dma_pool *dma_pool_create_node(const char *name,
40 struct device *dev, size_t size, size_t align, size_t boundary,
41 int node)
42{
43 return NULL;
44}
45static inline void dma_pool_destroy(struct dma_pool *pool) { }
46static inline void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
47 dma_addr_t *handle) { return NULL; }
48static inline void dma_pool_free(struct dma_pool *pool, void *vaddr,
49 dma_addr_t addr) { }
50static inline struct dma_pool *dmam_pool_create(const char *name,
51 struct device *dev, size_t size, size_t align, size_t allocation)
52{ return NULL; }
53static inline void dmam_pool_destroy(struct dma_pool *pool) { }
54#endif /* !CONFIG_HAS_DMA */
55
56static inline struct dma_pool *dma_pool_create(const char *name,
57 struct device *dev, size_t size, size_t align, size_t boundary)
58{
59 return dma_pool_create_node(name, dev, size, align, boundary,
60 NUMA_NO_NODE);
61}
62
63/**
64 * dma_pool_zalloc - Get a zero-initialized block of DMA coherent memory.
65 * @pool: dma pool that will produce the block
66 * @mem_flags: GFP_* bitmask
67 * @handle: pointer to dma address of block
68 *
69 * Same as dma_pool_alloc(), but the returned memory is zeroed.
70 */
71static inline void *dma_pool_zalloc(struct dma_pool *pool, gfp_t mem_flags,
72 dma_addr_t *handle)
73{
74 return dma_pool_alloc(pool, mem_flags: mem_flags | __GFP_ZERO, handle);
75}
76
77#endif
78
79