Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef __SOUND_UTIL_MEM_H |
| 3 | #define __SOUND_UTIL_MEM_H |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 4 | |
| 5 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | /* |
| 7 | * Copyright (C) 2000 Takashi Iwai <tiwai@suse.de> |
| 8 | * |
| 9 | * Generic memory management routines for soundcard memory allocation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | /* |
| 13 | * memory block |
| 14 | */ |
| 15 | struct snd_util_memblk { |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 16 | unsigned int size; /* size of this block */ |
| 17 | unsigned int offset; /* zero-offset of this block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | struct list_head list; /* link */ |
| 19 | }; |
| 20 | |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 21 | #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] | 22 | |
| 23 | /* |
| 24 | * memory management information |
| 25 | */ |
| 26 | struct snd_util_memhdr { |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 27 | unsigned int size; /* size of whole data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | struct list_head block; /* block linked-list header */ |
| 29 | int nblocks; /* # of allocated blocks */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 30 | unsigned int used; /* used memory size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | int block_extra_size; /* extra data size of chunk */ |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 32 | struct mutex block_mutex; /* lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /* |
| 36 | * prototypes |
| 37 | */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 38 | struct snd_util_memhdr *snd_util_memhdr_new(int memsize); |
| 39 | void snd_util_memhdr_free(struct snd_util_memhdr *hdr); |
| 40 | struct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size); |
| 41 | int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk); |
| 42 | int snd_util_mem_avail(struct snd_util_memhdr *hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* functions without mutex */ |
Takashi Iwai | 03da312 | 2005-11-17 14:24:47 +0100 | [diff] [blame] | 45 | struct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size); |
| 46 | void __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk); |
| 47 | struct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr, |
| 48 | unsigned int units, |
| 49 | struct list_head *prev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #endif /* __SOUND_UTIL_MEM_H */ |