xref: /linux-6.15/include/linux/genalloc.h (revision 929f9727)
1f14f75b8SJes Sorensen /*
2f14f75b8SJes Sorensen  * Basic general purpose allocator for managing special purpose memory
3f14f75b8SJes Sorensen  * not managed by the regular kmalloc/kfree interface.
4f14f75b8SJes Sorensen  * Uses for this includes on-device special memory, uncached memory
5f14f75b8SJes Sorensen  * etc.
6f14f75b8SJes Sorensen  *
7f14f75b8SJes Sorensen  * This source code is licensed under the GNU General Public License,
8f14f75b8SJes Sorensen  * Version 2.  See the file COPYING for more details.
9f14f75b8SJes Sorensen  */
10f14f75b8SJes Sorensen 
11f14f75b8SJes Sorensen 
12f14f75b8SJes Sorensen /*
13*929f9727SDean Nelson  *  General purpose special memory pool descriptor.
14f14f75b8SJes Sorensen  */
15f14f75b8SJes Sorensen struct gen_pool {
16*929f9727SDean Nelson 	rwlock_t lock;
17*929f9727SDean Nelson 	struct list_head chunks;	/* list of chunks in this pool */
18*929f9727SDean Nelson 	int min_alloc_order;		/* minimum allocation order */
19f14f75b8SJes Sorensen };
20f14f75b8SJes Sorensen 
21*929f9727SDean Nelson /*
22*929f9727SDean Nelson  *  General purpose special memory pool chunk descriptor.
23*929f9727SDean Nelson  */
24*929f9727SDean Nelson struct gen_pool_chunk {
25*929f9727SDean Nelson 	spinlock_t lock;
26*929f9727SDean Nelson 	struct list_head next_chunk;	/* next chunk in pool */
27*929f9727SDean Nelson 	unsigned long start_addr;	/* starting address of memory chunk */
28*929f9727SDean Nelson 	unsigned long end_addr;		/* ending address of memory chunk */
29*929f9727SDean Nelson 	unsigned long bits[0];		/* bitmap for allocating memory chunk */
30*929f9727SDean Nelson };
31*929f9727SDean Nelson 
32*929f9727SDean Nelson extern struct gen_pool *gen_pool_create(int, int);
33*929f9727SDean Nelson extern int gen_pool_add(struct gen_pool *, unsigned long, size_t, int);
34*929f9727SDean Nelson extern unsigned long gen_pool_alloc(struct gen_pool *, size_t);
35*929f9727SDean Nelson extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
36