| Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011, The Linux Foundation. All rights reserved. | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 |  * | 
 | 3 |  * This program is free software; you can redistribute it and/or modify | 
 | 4 |  * it under the terms of the GNU General Public License version 2 and | 
 | 5 |  * only version 2 as published by the Free Software Foundation. | 
 | 6 |  * | 
 | 7 |  * This program is distributed in the hope that it will be useful, | 
 | 8 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 9 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 10 |  * GNU General Public License for more details. | 
 | 11 |  */ | 
 | 12 |  | 
 | 13 | #ifndef _LINUX_MEMALLOC_H | 
 | 14 | #define	_LINUX_MEMALLOC_H | 
 | 15 |  | 
 | 16 | #include <linux/mutex.h> | 
 | 17 | #include <linux/genalloc.h> | 
 | 18 | #include <linux/rbtree.h> | 
 | 19 |  | 
 | 20 | struct mem_pool { | 
 | 21 | 	struct mutex pool_mutex; | 
 | 22 | 	struct gen_pool *gpool; | 
 | 23 | 	unsigned long paddr; | 
 | 24 | 	unsigned long size; | 
 | 25 | 	unsigned long free; | 
| Jordan Crouse | 8c78b13 | 2011-05-26 10:27:47 -0600 | [diff] [blame] | 26 | 	unsigned int id; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | }; | 
 | 28 |  | 
 | 29 | struct alloc { | 
 | 30 | 	struct rb_node rb_node; | 
 | 31 | 	void *vaddr; | 
 | 32 | 	unsigned long paddr; | 
 | 33 | 	struct mem_pool *mpool; | 
 | 34 | 	unsigned long len; | 
| Jordan Crouse | 8c78b13 | 2011-05-26 10:27:47 -0600 | [diff] [blame] | 35 | 	void *caller; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | }; | 
 | 37 |  | 
 | 38 | struct mem_pool *initialize_memory_pool(unsigned long start, | 
 | 39 | 	unsigned long size, int mem_type); | 
 | 40 |  | 
 | 41 | void *allocate_contiguous_memory(unsigned long size, | 
 | 42 | 	int mem_type, unsigned long align, int cached); | 
 | 43 |  | 
| Jordan Crouse | 8c78b13 | 2011-05-26 10:27:47 -0600 | [diff] [blame] | 44 | unsigned long _allocate_contiguous_memory_nomap(unsigned long size, | 
 | 45 | 	int mem_type, unsigned long align, void *caller); | 
 | 46 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 47 | unsigned long allocate_contiguous_memory_nomap(unsigned long size, | 
 | 48 | 	int mem_type, unsigned long align); | 
 | 49 |  | 
 | 50 | void free_contiguous_memory(void *addr); | 
 | 51 | void free_contiguous_memory_by_paddr(unsigned long paddr); | 
 | 52 |  | 
 | 53 | unsigned long memory_pool_node_paddr(void *vaddr); | 
 | 54 |  | 
 | 55 | unsigned long memory_pool_node_len(void *vaddr); | 
 | 56 |  | 
 | 57 | int memory_pool_init(void); | 
 | 58 | #endif	/* _LINUX_MEMALLOC_H */ |