Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __SOUND_UTIL_MEM_H
0003 #define __SOUND_UTIL_MEM_H
0004 
0005 #include <linux/mutex.h>
0006 /*
0007  *  Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
0008  *
0009  *  Generic memory management routines for soundcard memory allocation
0010  */
0011 
0012 /*
0013  * memory block
0014  */
0015 struct snd_util_memblk {
0016     unsigned int size;      /* size of this block */
0017     unsigned int offset;        /* zero-offset of this block */
0018     struct list_head list;      /* link */
0019 };
0020 
0021 #define snd_util_memblk_argptr(blk) (void*)((char*)(blk) + sizeof(struct snd_util_memblk))
0022 
0023 /*
0024  * memory management information
0025  */
0026 struct snd_util_memhdr {
0027     unsigned int size;      /* size of whole data */
0028     struct list_head block;     /* block linked-list header */
0029     int nblocks;            /* # of allocated blocks */
0030     unsigned int used;      /* used memory size */
0031     int block_extra_size;       /* extra data size of chunk */
0032     struct mutex block_mutex;   /* lock */
0033 };
0034 
0035 /*
0036  * prototypes
0037  */
0038 struct snd_util_memhdr *snd_util_memhdr_new(int memsize);
0039 void snd_util_memhdr_free(struct snd_util_memhdr *hdr);
0040 struct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
0041 int snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
0042 int snd_util_mem_avail(struct snd_util_memhdr *hdr);
0043 
0044 /* functions without mutex */
0045 struct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
0046 void __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
0047 struct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr,
0048                           unsigned int units,
0049                           struct list_head *prev);
0050 
0051 #endif /* __SOUND_UTIL_MEM_H */