util_mem.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __SOUND_UTIL_MEM_H
  3. #define __SOUND_UTIL_MEM_H
  4. #include <linux/mutex.h>
  5. /*
  6. * Copyright (C) 2000 Takashi Iwai <[email protected]>
  7. *
  8. * Generic memory management routines for soundcard memory allocation
  9. */
  10. /*
  11. * memory block
  12. */
  13. struct snd_util_memblk {
  14. unsigned int size; /* size of this block */
  15. unsigned int offset; /* zero-offset of this block */
  16. struct list_head list; /* link */
  17. };
  18. #define snd_util_memblk_argptr(blk) (void*)((char*)(blk) + sizeof(struct snd_util_memblk))
  19. /*
  20. * memory management information
  21. */
  22. struct snd_util_memhdr {
  23. unsigned int size; /* size of whole data */
  24. struct list_head block; /* block linked-list header */
  25. int nblocks; /* # of allocated blocks */
  26. unsigned int used; /* used memory size */
  27. int block_extra_size; /* extra data size of chunk */
  28. struct mutex block_mutex; /* lock */
  29. };
  30. /*
  31. * prototypes
  32. */
  33. struct snd_util_memhdr *snd_util_memhdr_new(int memsize);
  34. void snd_util_memhdr_free(struct snd_util_memhdr *hdr);
  35. struct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
  36. int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
  37. int snd_util_mem_avail(struct snd_util_memhdr *hdr);
  38. /* functions without mutex */
  39. struct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
  40. void __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
  41. struct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr,
  42. unsigned int units,
  43. struct list_head *prev);
  44. #endif /* __SOUND_UTIL_MEM_H */