162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef __SOUND_UTIL_MEM_H
362306a36Sopenharmony_ci#define __SOUND_UTIL_MEM_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/mutex.h>
662306a36Sopenharmony_ci/*
762306a36Sopenharmony_ci *  Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci *  Generic memory management routines for soundcard memory allocation
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/*
1362306a36Sopenharmony_ci * memory block
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_cistruct snd_util_memblk {
1662306a36Sopenharmony_ci	unsigned int size;		/* size of this block */
1762306a36Sopenharmony_ci	unsigned int offset;		/* zero-offset of this block */
1862306a36Sopenharmony_ci	struct list_head list;		/* link */
1962306a36Sopenharmony_ci};
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define snd_util_memblk_argptr(blk)	(void*)((char*)(blk) + sizeof(struct snd_util_memblk))
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*
2462306a36Sopenharmony_ci * memory management information
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_cistruct snd_util_memhdr {
2762306a36Sopenharmony_ci	unsigned int size;		/* size of whole data */
2862306a36Sopenharmony_ci	struct list_head block;		/* block linked-list header */
2962306a36Sopenharmony_ci	int nblocks;			/* # of allocated blocks */
3062306a36Sopenharmony_ci	unsigned int used;		/* used memory size */
3162306a36Sopenharmony_ci	int block_extra_size;		/* extra data size of chunk */
3262306a36Sopenharmony_ci	struct mutex block_mutex;	/* lock */
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/*
3662306a36Sopenharmony_ci * prototypes
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_cistruct snd_util_memhdr *snd_util_memhdr_new(int memsize);
3962306a36Sopenharmony_civoid snd_util_memhdr_free(struct snd_util_memhdr *hdr);
4062306a36Sopenharmony_cistruct snd_util_memblk *snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
4162306a36Sopenharmony_ciint snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
4262306a36Sopenharmony_ciint snd_util_mem_avail(struct snd_util_memhdr *hdr);
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/* functions without mutex */
4562306a36Sopenharmony_cistruct snd_util_memblk *__snd_util_mem_alloc(struct snd_util_memhdr *hdr, int size);
4662306a36Sopenharmony_civoid __snd_util_mem_free(struct snd_util_memhdr *hdr, struct snd_util_memblk *blk);
4762306a36Sopenharmony_cistruct snd_util_memblk *__snd_util_memblk_new(struct snd_util_memhdr *hdr,
4862306a36Sopenharmony_ci					      unsigned int units,
4962306a36Sopenharmony_ci					      struct list_head *prev);
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#endif /* __SOUND_UTIL_MEM_H */
52