aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/genalloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/genalloc.h')
-rw-r--r--include/linux/genalloc.h59
1 files changed, 50 insertions, 9 deletions
diff --git a/include/linux/genalloc.h b/include/linux/genalloc.h
index dd0a452373e7..205f62b8d291 100644
--- a/include/linux/genalloc.h
+++ b/include/linux/genalloc.h
@@ -1,3 +1,4 @@
1/* SPDX-License-Identifier: GPL-2.0-only */
1/* 2/*
2 * Basic general purpose allocator for managing special purpose 3 * Basic general purpose allocator for managing special purpose
3 * memory, for example, memory that is not managed by the regular 4 * memory, for example, memory that is not managed by the regular
@@ -21,9 +22,6 @@
21 * the allocator can NOT be used in NMI handler. So code uses the 22 * the allocator can NOT be used in NMI handler. So code uses the
22 * allocator in NMI handler should depend on 23 * allocator in NMI handler should depend on
23 * CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG. 24 * CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG.
24 *
25 * This source code is licensed under the GNU General Public License,
26 * Version 2. See the file COPYING for more details.
27 */ 25 */
28 26
29 27
@@ -75,6 +73,7 @@ struct gen_pool_chunk {
75 struct list_head next_chunk; /* next chunk in pool */ 73 struct list_head next_chunk; /* next chunk in pool */
76 atomic_long_t avail; 74 atomic_long_t avail;
77 phys_addr_t phys_addr; /* physical starting address of memory chunk */ 75 phys_addr_t phys_addr; /* physical starting address of memory chunk */
76 void *owner; /* private data to retrieve at alloc time */
78 unsigned long start_addr; /* start address of memory chunk */ 77 unsigned long start_addr; /* start address of memory chunk */
79 unsigned long end_addr; /* end address of memory chunk (inclusive) */ 78 unsigned long end_addr; /* end address of memory chunk (inclusive) */
80 unsigned long bits[0]; /* bitmap for allocating memory chunk */ 79 unsigned long bits[0]; /* bitmap for allocating memory chunk */
@@ -96,8 +95,15 @@ struct genpool_data_fixed {
96 95
97extern struct gen_pool *gen_pool_create(int, int); 96extern struct gen_pool *gen_pool_create(int, int);
98extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long); 97extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long);
99extern int gen_pool_add_virt(struct gen_pool *, unsigned long, phys_addr_t, 98extern int gen_pool_add_owner(struct gen_pool *, unsigned long, phys_addr_t,
100 size_t, int); 99 size_t, int, void *);
100
101static inline int gen_pool_add_virt(struct gen_pool *pool, unsigned long addr,
102 phys_addr_t phys, size_t size, int nid)
103{
104 return gen_pool_add_owner(pool, addr, phys, size, nid, NULL);
105}
106
101/** 107/**
102 * gen_pool_add - add a new chunk of special memory to the pool 108 * gen_pool_add - add a new chunk of special memory to the pool
103 * @pool: pool to add new memory chunk to 109 * @pool: pool to add new memory chunk to
@@ -116,12 +122,47 @@ static inline int gen_pool_add(struct gen_pool *pool, unsigned long addr,
116 return gen_pool_add_virt(pool, addr, -1, size, nid); 122 return gen_pool_add_virt(pool, addr, -1, size, nid);
117} 123}
118extern void gen_pool_destroy(struct gen_pool *); 124extern void gen_pool_destroy(struct gen_pool *);
119extern unsigned long gen_pool_alloc(struct gen_pool *, size_t); 125unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
120extern unsigned long gen_pool_alloc_algo(struct gen_pool *, size_t, 126 genpool_algo_t algo, void *data, void **owner);
121 genpool_algo_t algo, void *data); 127
128static inline unsigned long gen_pool_alloc_owner(struct gen_pool *pool,
129 size_t size, void **owner)
130{
131 return gen_pool_alloc_algo_owner(pool, size, pool->algo, pool->data,
132 owner);
133}
134
135static inline unsigned long gen_pool_alloc_algo(struct gen_pool *pool,
136 size_t size, genpool_algo_t algo, void *data)
137{
138 return gen_pool_alloc_algo_owner(pool, size, algo, data, NULL);
139}
140
141/**
142 * gen_pool_alloc - allocate special memory from the pool
143 * @pool: pool to allocate from
144 * @size: number of bytes to allocate from the pool
145 *
146 * Allocate the requested number of bytes from the specified pool.
147 * Uses the pool allocation function (with first-fit algorithm by default).
148 * Can not be used in NMI handler on architectures without
149 * NMI-safe cmpxchg implementation.
150 */
151static inline unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
152{
153 return gen_pool_alloc_algo(pool, size, pool->algo, pool->data);
154}
155
122extern void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, 156extern void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size,
123 dma_addr_t *dma); 157 dma_addr_t *dma);
124extern void gen_pool_free(struct gen_pool *, unsigned long, size_t); 158extern void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr,
159 size_t size, void **owner);
160static inline void gen_pool_free(struct gen_pool *pool, unsigned long addr,
161 size_t size)
162{
163 gen_pool_free_owner(pool, addr, size, NULL);
164}
165
125extern void gen_pool_for_each_chunk(struct gen_pool *, 166extern void gen_pool_for_each_chunk(struct gen_pool *,
126 void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *); 167 void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);
127extern size_t gen_pool_avail(struct gen_pool *); 168extern size_t gen_pool_avail(struct gen_pool *);