18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __SOUND_UTIL_MEM_H
38c2ecf20Sopenharmony_ci#define __SOUND_UTIL_MEM_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/mutex.h>
68c2ecf20Sopenharmony_ci/*
78c2ecf20Sopenharmony_ci *  Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  Generic memory management routines for soundcard memory allocation
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/*
138c2ecf20Sopenharmony_ci * memory block
148c2ecf20Sopenharmony_ci */
158c2ecf20Sopenharmony_cistruct snd_util_memblk {
168c2ecf20Sopenharmony_ci	unsigned int size;		/* size of this block */
178c2ecf20Sopenharmony_ci	unsigned int offset;		/* zero-offset of this block */
188c2ecf20Sopenharmony_ci	struct list_head list;		/* link */
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define snd_util_memblk_argptr(blk)	(void*)((char*)(blk) + sizeof(struct snd_util_memblk))
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * memory management information
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_cistruct snd_util_memhdr {
278c2ecf20Sopenharmony_ci	unsigned int size;		/* size of whole data */
288c2ecf20Sopenharmony_ci	struct list_head block;		/* block linked-list header */
298c2ecf20Sopenharmony_ci	int nblocks;			/* # of allocated blocks */
308c2ecf20Sopenharmony_ci	unsigned int used;		/* used memory size */
318c2ecf20Sopenharmony_ci	int block_extra_size;		/* extra data size of chunk */
328c2ecf20Sopenharmony_ci	struct mutex block_mutex;	/* lock */
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * prototypes
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cistruct snd_util_memhdr *snd_util_memhdr_new(int memsize);
398c2ecf20Sopenharmony_civoid snd_util_memhdr_free(struct snd_util_memhdr *hdr);
408c2ecf20Sopenharmony_cistruct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
418c2ecf20Sopenharmony_ciint snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
428c2ecf20Sopenharmony_ciint snd_util_mem_avail(struct snd_util_memhdr *hdr);
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* functions without mutex */
458c2ecf20Sopenharmony_cistruct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
468c2ecf20Sopenharmony_civoid __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
478c2ecf20Sopenharmony_cistruct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr,
488c2ecf20Sopenharmony_ci					      unsigned int units,
498c2ecf20Sopenharmony_ci					      struct list_head *prev);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#endif /* __SOUND_UTIL_MEM_H */
52