blob: b6494517ef32e72210272b96dcb4fc97538889a7 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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
20struct 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 Crouse8c78b132011-05-26 10:27:47 -060026 unsigned int id;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027};
28
29struct alloc {
30 struct rb_node rb_node;
31 void *vaddr;
32 unsigned long paddr;
33 struct mem_pool *mpool;
34 unsigned long len;
Jordan Crouse8c78b132011-05-26 10:27:47 -060035 void *caller;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036};
37
38struct mem_pool *initialize_memory_pool(unsigned long start,
39 unsigned long size, int mem_type);
40
41void *allocate_contiguous_memory(unsigned long size,
42 int mem_type, unsigned long align, int cached);
43
Jordan Crouse8c78b132011-05-26 10:27:47 -060044unsigned long _allocate_contiguous_memory_nomap(unsigned long size,
45 int mem_type, unsigned long align, void *caller);
46
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070047unsigned long allocate_contiguous_memory_nomap(unsigned long size,
48 int mem_type, unsigned long align);
49
50void free_contiguous_memory(void *addr);
51void free_contiguous_memory_by_paddr(unsigned long paddr);
52
53unsigned long memory_pool_node_paddr(void *vaddr);
54
55unsigned long memory_pool_node_len(void *vaddr);
56
57int memory_pool_init(void);
58#endif /* _LINUX_MEMALLOC_H */