Skip to content

Commit

Permalink
lib: backport memory_alloc from cafs 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
drewis authored and cayniarb committed Feb 19, 2012
1 parent f3747d8 commit 89ca98f
Show file tree
Hide file tree
Showing 3 changed files with 485 additions and 1 deletion.
58 changes: 58 additions & 0 deletions include/linux/memory_alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/

#ifndef _LINUX_MEMALLOC_H
#define _LINUX_MEMALLOC_H

#include <linux/mutex.h>
#include <linux/genalloc.h>
#include <linux/rbtree.h>

struct mem_pool {
struct mutex pool_mutex;
struct gen_pool *gpool;
unsigned long paddr;
unsigned long size;
unsigned long free;
unsigned int id;
};

struct alloc {
struct rb_node rb_node;
void *vaddr;
unsigned long paddr;
struct mem_pool *mpool;
unsigned long len;
void *caller;
};

struct mem_pool *initialize_memory_pool(unsigned long start,
unsigned long size, int mem_type);

void *allocate_contiguous_memory(unsigned long size,
int mem_type, unsigned long align, int cached);

unsigned long _allocate_contiguous_memory_nomap(unsigned long size,
int mem_type, unsigned long align, void *caller);

unsigned long allocate_contiguous_memory_nomap(unsigned long size,
int mem_type, unsigned long align);

void free_contiguous_memory(void *addr);
void free_contiguous_memory_by_paddr(unsigned long paddr);

unsigned long memory_pool_node_paddr(void *vaddr);

unsigned long memory_pool_node_len(void *vaddr);

int memory_pool_init(void);
#endif /* _LINUX_MEMALLOC_H */
3 changes: 2 additions & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
idr.o int_sqrt.o extable.o prio_tree.o \
sha1.o irq_regs.o reciprocal_div.o argv_split.o \
proportions.o prio_heap.o ratelimit.o show_mem.o \
is_single_threaded.o plist.o decompress.o
is_single_threaded.o plist.o decompress.o \
memory_alloc.o

lib-$(CONFIG_MMU) += ioremap.o
lib-$(CONFIG_SMP) += cpumask.o
Expand Down
Loading

0 comments on commit 89ca98f

Please sign in to comment.