/*1* ALSA sequencer Memory Manager2* Copyright (c) 1998 by Frank van de Pol <[email protected]>3*4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*19*/20#ifndef __SND_SEQ_MEMORYMGR_H21#define __SND_SEQ_MEMORYMGR_H2223#include <sound/seq_kernel.h>24#include <linux/poll.h>2526struct snd_info_buffer;2728/* container for sequencer event (internal use) */29struct snd_seq_event_cell {30struct snd_seq_event event;31struct snd_seq_pool *pool; /* used pool */32struct snd_seq_event_cell *next; /* next cell */33};3435/* design note: the pool is a contiguous block of memory, if we dynamicly36want to add additional cells to the pool be better store this in another37pool as we need to know the base address of the pool when releasing38memory. */3940struct snd_seq_pool {41struct snd_seq_event_cell *ptr; /* pointer to first event chunk */42struct snd_seq_event_cell *free; /* pointer to the head of the free list */4344int total_elements; /* pool size actually allocated */45atomic_t counter; /* cells free */4647int size; /* pool size to be allocated */48int room; /* watermark for sleep/wakeup */4950int closing;5152/* statistics */53int max_used;54int event_alloc_nopool;55int event_alloc_failures;56int event_alloc_success;5758/* Write locking */59wait_queue_head_t output_sleep;6061/* Pool lock */62spinlock_t lock;63};6465void snd_seq_cell_free(struct snd_seq_event_cell *cell);6667int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,68struct snd_seq_event_cell **cellp, int nonblock, struct file *file);6970/* return number of unused (free) cells */71static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)72{73return pool ? pool->total_elements - atomic_read(&pool->counter) : 0;74}7576/* return total number of allocated cells */77static inline int snd_seq_total_cells(struct snd_seq_pool *pool)78{79return pool ? pool->total_elements : 0;80}8182/* init pool - allocate events */83int snd_seq_pool_init(struct snd_seq_pool *pool);8485/* done pool - free events */86int snd_seq_pool_done(struct snd_seq_pool *pool);8788/* create pool */89struct snd_seq_pool *snd_seq_pool_new(int poolsize);9091/* remove pool */92int snd_seq_pool_delete(struct snd_seq_pool **pool);9394/* init memory */95int snd_sequencer_memory_init(void);9697/* release event memory */98void snd_sequencer_memory_done(void);99100/* polling */101int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, poll_table *wait);102103void snd_seq_info_pool(struct snd_info_buffer *buffer,104struct snd_seq_pool *pool, char *space);105106#endif107108109