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; |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 23 | phys_addr_t paddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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; |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 31 | /* |
| 32 | * The physical address may be used for lookup in the tree so the |
| 33 | * 'virtual address' needs to be able to accomodate larger physical |
| 34 | * addresses. |
| 35 | */ |
| 36 | phys_addr_t vaddr; |
| 37 | phys_addr_t paddr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | struct mem_pool *mpool; |
| 39 | unsigned long len; |
Jordan Crouse | 8c78b13 | 2011-05-26 10:27:47 -0600 | [diff] [blame] | 40 | void *caller; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 43 | struct mem_pool *initialize_memory_pool(phys_addr_t start, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | unsigned long size, int mem_type); |
| 45 | |
| 46 | void *allocate_contiguous_memory(unsigned long size, |
| 47 | int mem_type, unsigned long align, int cached); |
| 48 | |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 49 | phys_addr_t _allocate_contiguous_memory_nomap(unsigned long size, |
Jordan Crouse | 8c78b13 | 2011-05-26 10:27:47 -0600 | [diff] [blame] | 50 | int mem_type, unsigned long align, void *caller); |
| 51 | |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 52 | phys_addr_t allocate_contiguous_memory_nomap(unsigned long size, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | int mem_type, unsigned long align); |
| 54 | |
| 55 | void free_contiguous_memory(void *addr); |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 56 | void free_contiguous_memory_by_paddr(phys_addr_t paddr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 57 | |
Laura Abbott | da6b961 | 2013-04-09 10:48:22 -0700 | [diff] [blame] | 58 | phys_addr_t memory_pool_node_paddr(void *vaddr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | |
| 60 | unsigned long memory_pool_node_len(void *vaddr); |
| 61 | |
| 62 | int memory_pool_init(void); |
| 63 | #endif /* _LINUX_MEMALLOC_H */ |