Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Basic general purpose allocator for managing special purpose memory |
| 3 | * not managed by the regular kmalloc/kfree interface. |
| 4 | * Uses for this includes on-device special memory, uncached memory |
| 5 | * etc. |
| 6 | * |
Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 7 | * This source code is licensed under the GNU General Public License, |
| 8 | * Version 2. See the file COPYING for more details. |
| 9 | */ |
| 10 | |
Jean-Christophe PLAGNIOL-VILLARD | 6aae6e0 | 2011-05-24 17:13:33 -0700 | [diff] [blame] | 11 | #ifndef __GENALLOC_H__ |
| 12 | #define __GENALLOC_H__ |
Jes Sorensen | f14f75b | 2005-06-21 17:15:02 -0700 | [diff] [blame] | 13 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 14 | struct gen_pool; |
Dean Nelson | 929f972 | 2006-06-23 02:03:21 -0700 | [diff] [blame] | 15 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 16 | struct gen_pool *__must_check gen_pool_create(unsigned order, int nid); |
| 17 | |
| 18 | void gen_pool_destroy(struct gen_pool *pool); |
| 19 | |
| 20 | unsigned long __must_check |
| 21 | gen_pool_alloc_aligned(struct gen_pool *pool, size_t size, |
| 22 | unsigned alignment_order); |
| 23 | |
| 24 | /** |
| 25 | * gen_pool_alloc() - allocate special memory from the pool |
| 26 | * @pool: Pool to allocate from. |
| 27 | * @size: Number of bytes to allocate from the pool. |
| 28 | * |
| 29 | * Allocate the requested number of bytes from the specified pool. |
| 30 | * Uses a first-fit algorithm. |
| 31 | */ |
| 32 | static inline unsigned long __must_check |
| 33 | gen_pool_alloc(struct gen_pool *pool, size_t size) |
| 34 | { |
| 35 | return gen_pool_alloc_aligned(pool, size, 0); |
| 36 | } |
| 37 | |
| 38 | void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size); |
| 39 | |
Jean-Christophe PLAGNIOL-VILLARD | 3c8f370 | 2011-05-24 17:13:34 -0700 | [diff] [blame] | 40 | extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long); |
| 41 | extern int gen_pool_add_virt(struct gen_pool *, unsigned long, phys_addr_t, |
| 42 | size_t, int); |
| 43 | /** |
| 44 | * gen_pool_add - add a new chunk of special memory to the pool |
| 45 | * @pool: pool to add new memory chunk to |
| 46 | * @addr: starting address of memory chunk to add to pool |
| 47 | * @size: size in bytes of the memory chunk to add to pool |
| 48 | * @nid: node id of the node the chunk structure and bitmap should be |
| 49 | * allocated on, or -1 |
| 50 | * |
| 51 | * Add a new chunk of special memory to the specified pool. |
| 52 | * |
| 53 | * Returns 0 on success or a -ve errno on failure. |
| 54 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 55 | static inline int __must_check gen_pool_add(struct gen_pool *pool, unsigned long addr, |
Jean-Christophe PLAGNIOL-VILLARD | 3c8f370 | 2011-05-24 17:13:34 -0700 | [diff] [blame] | 56 | size_t size, int nid) |
| 57 | { |
| 58 | return gen_pool_add_virt(pool, addr, -1, size, nid); |
| 59 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6aae6e0 | 2011-05-24 17:13:33 -0700 | [diff] [blame] | 60 | #endif /* __GENALLOC_H__ */ |