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