blob: 3bc7dd7394bf01557506df46747326c3937ea922 [file] [log] [blame]
Jes Sorensenf14f75b2005-06-21 17:15:02 -07001/*
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 Sorensenf14f75b2005-06-21 17:15:02 -07007 * 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-VILLARD6aae6e02011-05-24 17:13:33 -070011#ifndef __GENALLOC_H__
12#define __GENALLOC_H__
Jes Sorensenf14f75b2005-06-21 17:15:02 -070013
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070014struct gen_pool;
Dean Nelson929f9722006-06-23 02:03:21 -070015
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070016struct gen_pool *__must_check gen_pool_create(unsigned order, int nid);
17
18void gen_pool_destroy(struct gen_pool *pool);
19
20unsigned long __must_check
21gen_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 */
32static inline unsigned long __must_check
33gen_pool_alloc(struct gen_pool *pool, size_t size)
34{
35 return gen_pool_alloc_aligned(pool, size, 0);
36}
37
38void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size);
39
Jean-Christophe PLAGNIOL-VILLARD3c8f3702011-05-24 17:13:34 -070040extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long);
41extern 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 Huntsman3f2bc4d2011-08-16 17:27:22 -070055static inline int __must_check gen_pool_add(struct gen_pool *pool, unsigned long addr,
Jean-Christophe PLAGNIOL-VILLARD3c8f3702011-05-24 17:13:34 -070056 size_t size, int nid)
57{
58 return gen_pool_add_virt(pool, addr, -1, size, nid);
59}
Jean-Christophe PLAGNIOL-VILLARD6aae6e02011-05-24 17:13:33 -070060#endif /* __GENALLOC_H__ */