genalloc.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Basic general purpose allocator for managing special purpose memory
  3. * not managed by the regular kmalloc/kfree interface.
  4. * Uses for this includes on-device special memory, uncached memory
  5. * etc.
  6. *
  7. * This code is based on the buddy allocator found in the sym53c8xx_2
  8. * driver, adapted for general purpose use.
  9. *
  10. * This source code is licensed under the GNU General Public License,
  11. * Version 2. See the file COPYING for more details.
  12. */
  13. #include <linux/spinlock.h>
  14. #define ALLOC_MIN_SHIFT 5 /* 32 bytes minimum */
  15. /*
  16. * Link between free memory chunks of a given size.
  17. */
  18. struct gen_pool_link {
  19. struct gen_pool_link *next;
  20. };
  21. /*
  22. * Memory pool descriptor.
  23. */
  24. struct gen_pool {
  25. spinlock_t lock;
  26. unsigned long (*get_new_chunk)(struct gen_pool *);
  27. struct gen_pool *next;
  28. struct gen_pool_link *h;
  29. unsigned long private;
  30. int max_chunk_shift;
  31. };
  32. unsigned long gen_pool_alloc(struct gen_pool *poolp, int size);
  33. void gen_pool_free(struct gen_pool *mp, unsigned long ptr, int size);
  34. struct gen_pool *gen_pool_create(int nr_chunks, int max_chunk_shift,
  35. unsigned long (*fp)(struct gen_pool *),
  36. unsigned long data);