util_mem.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef __SOUND_UTIL_MEM_H
  2. #define __SOUND_UTIL_MEM_H
  3. #include <linux/mutex.h>
  4. /*
  5. * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
  6. *
  7. * Generic memory management routines for soundcard memory allocation
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /*
  24. * memory block
  25. */
  26. struct snd_util_memblk {
  27. unsigned int size; /* size of this block */
  28. unsigned int offset; /* zero-offset of this block */
  29. struct list_head list; /* link */
  30. };
  31. #define snd_util_memblk_argptr(blk) (void*)((char*)(blk) + sizeof(struct snd_util_memblk))
  32. /*
  33. * memory management information
  34. */
  35. struct snd_util_memhdr {
  36. unsigned int size; /* size of whole data */
  37. struct list_head block; /* block linked-list header */
  38. int nblocks; /* # of allocated blocks */
  39. unsigned int used; /* used memory size */
  40. int block_extra_size; /* extra data size of chunk */
  41. struct mutex block_mutex; /* lock */
  42. };
  43. /*
  44. * prototypes
  45. */
  46. struct snd_util_memhdr *snd_util_memhdr_new(int memsize);
  47. void snd_util_memhdr_free(struct snd_util_memhdr *hdr);
  48. struct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
  49. int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
  50. int snd_util_mem_avail(struct snd_util_memhdr *hdr);
  51. /* functions without mutex */
  52. struct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
  53. void __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
  54. struct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr,
  55. unsigned int units,
  56. struct list_head *prev);
  57. #endif /* __SOUND_UTIL_MEM_H */