blob: 8097949f879f4ab007b054fd2031013b704a29c8 [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;
Laura Abbottda6b9612013-04-09 10:48:22 -070023 phys_addr_t paddr;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024 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;
Laura Abbottda6b9612013-04-09 10:48:22 -070031 /*
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 Huntsman3f2bc4d2011-08-16 17:27:22 -070038 struct mem_pool *mpool;
39 unsigned long len;
Jordan Crouse8c78b132011-05-26 10:27:47 -060040 void *caller;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041};
42
Laura Abbottda6b9612013-04-09 10:48:22 -070043struct mem_pool *initialize_memory_pool(phys_addr_t start,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044 unsigned long size, int mem_type);
45
46void *allocate_contiguous_memory(unsigned long size,
47 int mem_type, unsigned long align, int cached);
48
Laura Abbottda6b9612013-04-09 10:48:22 -070049phys_addr_t _allocate_contiguous_memory_nomap(unsigned long size,
Jordan Crouse8c78b132011-05-26 10:27:47 -060050 int mem_type, unsigned long align, void *caller);
51
Laura Abbottda6b9612013-04-09 10:48:22 -070052phys_addr_t allocate_contiguous_memory_nomap(unsigned long size,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053 int mem_type, unsigned long align);
54
55void free_contiguous_memory(void *addr);
Laura Abbottda6b9612013-04-09 10:48:22 -070056void free_contiguous_memory_by_paddr(phys_addr_t paddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
Laura Abbottda6b9612013-04-09 10:48:22 -070058phys_addr_t memory_pool_node_paddr(void *vaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059
60unsigned long memory_pool_node_len(void *vaddr);
61
62int memory_pool_init(void);
63#endif /* _LINUX_MEMALLOC_H */