memory_alloc.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (c) 2011, The Linux Foundation. All rights reserved.
  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. #ifndef _LINUX_MEMALLOC_H
  13. #define _LINUX_MEMALLOC_H
  14. #include <linux/mutex.h>
  15. #include <linux/genalloc.h>
  16. #include <linux/rbtree.h>
  17. struct mem_pool {
  18. struct mutex pool_mutex;
  19. struct gen_pool *gpool;
  20. phys_addr_t paddr;
  21. unsigned long size;
  22. unsigned long free;
  23. unsigned int id;
  24. };
  25. struct alloc {
  26. struct rb_node rb_node;
  27. /*
  28. * The physical address may be used for lookup in the tree so the
  29. * 'virtual address' needs to be able to accomodate larger physical
  30. * addresses.
  31. */
  32. phys_addr_t vaddr;
  33. phys_addr_t paddr;
  34. struct mem_pool *mpool;
  35. unsigned long len;
  36. void *caller;
  37. };
  38. struct mem_pool *initialize_memory_pool(phys_addr_t start,
  39. unsigned long size, int mem_type);
  40. void *allocate_contiguous_memory(unsigned long size,
  41. int mem_type, unsigned long align, int cached);
  42. phys_addr_t _allocate_contiguous_memory_nomap(unsigned long size,
  43. int mem_type, unsigned long align, void *caller);
  44. phys_addr_t allocate_contiguous_memory_nomap(unsigned long size,
  45. int mem_type, unsigned long align);
  46. void free_contiguous_memory(void *addr);
  47. void free_contiguous_memory_by_paddr(phys_addr_t paddr);
  48. phys_addr_t memory_pool_node_paddr(void *vaddr);
  49. unsigned long memory_pool_node_len(void *vaddr);
  50. int memory_pool_init(void);
  51. #endif /* _LINUX_MEMALLOC_H */