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