blob: 69944bbb5445fb9476af87e40e5e2285b6e21733 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __SOUND_UTIL_MEM_H
2#define __SOUND_UTIL_MEM_H
3/*
4 * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
5 *
6 * Generic memory management routines for soundcard memory allocation
7 *
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.
12 *
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.
17 *
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
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24 * memory block
25 */
26struct snd_util_memblk {
Takashi Iwai03da3122005-11-17 14:24:47 +010027 unsigned int size; /* size of this block */
28 unsigned int offset; /* zero-offset of this block */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 struct list_head list; /* link */
30};
31
Takashi Iwai03da3122005-11-17 14:24:47 +010032#define snd_util_memblk_argptr(blk) (void*)((char*)(blk) + sizeof(struct snd_util_memblk))
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/*
35 * memory management information
36 */
37struct snd_util_memhdr {
Takashi Iwai03da3122005-11-17 14:24:47 +010038 unsigned int size; /* size of whole data */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 struct list_head block; /* block linked-list header */
40 int nblocks; /* # of allocated blocks */
Takashi Iwai03da3122005-11-17 14:24:47 +010041 unsigned int used; /* used memory size */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 int block_extra_size; /* extra data size of chunk */
43 struct semaphore block_mutex; /* lock */
44};
45
46/*
47 * prototypes
48 */
Takashi Iwai03da3122005-11-17 14:24:47 +010049struct snd_util_memhdr *snd_util_memhdr_new(int memsize);
50void snd_util_memhdr_free(struct snd_util_memhdr *hdr);
51struct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
52int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
53int snd_util_mem_avail(struct snd_util_memhdr *hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* functions without mutex */
Takashi Iwai03da3122005-11-17 14:24:47 +010056struct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
57void __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
58struct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr,
59 unsigned int units,
60 struct list_head *prev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62#endif /* __SOUND_UTIL_MEM_H */