Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALSA sequencer Memory Manager |
| 3 | * Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl> |
| 4 | * |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | #ifndef __SND_SEQ_MEMORYMGR_H |
| 22 | #define __SND_SEQ_MEMORYMGR_H |
| 23 | |
| 24 | #include <sound/seq_kernel.h> |
| 25 | #include <linux/poll.h> |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | /* container for sequencer event (internal use) */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 28 | struct snd_seq_event_cell { |
| 29 | struct snd_seq_event event; |
| 30 | struct snd_seq_pool *pool; /* used pool */ |
| 31 | struct snd_seq_event_cell *next; /* next cell */ |
| 32 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 34 | /* design note: the pool is a contiguous block of memory, if we dynamicly |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | want to add additional cells to the pool be better store this in another |
| 36 | pool as we need to know the base address of the pool when releasing |
| 37 | memory. */ |
| 38 | |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 39 | struct snd_seq_pool { |
| 40 | struct snd_seq_event_cell *ptr; /* pointer to first event chunk */ |
| 41 | struct snd_seq_event_cell *free; /* pointer to the head of the free list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | int total_elements; /* pool size actually allocated */ |
| 44 | atomic_t counter; /* cells free */ |
| 45 | |
| 46 | int size; /* pool size to be allocated */ |
| 47 | int room; /* watermark for sleep/wakeup */ |
| 48 | |
| 49 | int closing; |
| 50 | |
| 51 | /* statistics */ |
| 52 | int max_used; |
| 53 | int event_alloc_nopool; |
| 54 | int event_alloc_failures; |
| 55 | int event_alloc_success; |
| 56 | |
| 57 | /* Write locking */ |
| 58 | wait_queue_head_t output_sleep; |
| 59 | |
| 60 | /* Pool lock */ |
| 61 | spinlock_t lock; |
| 62 | }; |
| 63 | |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 64 | void snd_seq_cell_free(struct snd_seq_event_cell *cell); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 66 | int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event, |
| 67 | struct snd_seq_event_cell **cellp, int nonblock, struct file *file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* return number of unused (free) cells */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 70 | static inline int snd_seq_unused_cells(struct snd_seq_pool *pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | return pool ? pool->total_elements - atomic_read(&pool->counter) : 0; |
| 73 | } |
| 74 | |
| 75 | /* return total number of allocated cells */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 76 | static inline int snd_seq_total_cells(struct snd_seq_pool *pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | return pool ? pool->total_elements : 0; |
| 79 | } |
| 80 | |
| 81 | /* init pool - allocate events */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 82 | int snd_seq_pool_init(struct snd_seq_pool *pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | /* done pool - free events */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 85 | int snd_seq_pool_done(struct snd_seq_pool *pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | /* create pool */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 88 | struct snd_seq_pool *snd_seq_pool_new(int poolsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* remove pool */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 91 | int snd_seq_pool_delete(struct snd_seq_pool **pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* init memory */ |
| 94 | int snd_sequencer_memory_init(void); |
| 95 | |
| 96 | /* release event memory */ |
| 97 | void snd_sequencer_memory_done(void); |
| 98 | |
| 99 | /* polling */ |
Takashi Iwai | c7e0b5b | 2005-11-17 14:04:02 +0100 | [diff] [blame] | 100 | int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, poll_table *wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | |
| 103 | #endif |