blob: 3abe306c394af95c8dbdb99475f7829a17efc33c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Clemens Ladischfea952e2011-02-14 11:00:47 +010027struct snd_info_buffer;
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029/* container for sequencer event (internal use) */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010030struct snd_seq_event_cell {
31 struct snd_seq_event event;
32 struct snd_seq_pool *pool; /* used pool */
33 struct snd_seq_event_cell *next; /* next cell */
34};
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Andreas Mohrd6e05ed2006-06-26 18:35:02 +020036/* design note: the pool is a contiguous block of memory, if we dynamicly
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 want to add additional cells to the pool be better store this in another
38 pool as we need to know the base address of the pool when releasing
39 memory. */
40
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010041struct snd_seq_pool {
42 struct snd_seq_event_cell *ptr; /* pointer to first event chunk */
43 struct snd_seq_event_cell *free; /* pointer to the head of the free list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 int total_elements; /* pool size actually allocated */
46 atomic_t counter; /* cells free */
47
48 int size; /* pool size to be allocated */
49 int room; /* watermark for sleep/wakeup */
50
51 int closing;
52
53 /* statistics */
54 int max_used;
55 int event_alloc_nopool;
56 int event_alloc_failures;
57 int event_alloc_success;
58
59 /* Write locking */
60 wait_queue_head_t output_sleep;
61
62 /* Pool lock */
63 spinlock_t lock;
64};
65
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010066void snd_seq_cell_free(struct snd_seq_event_cell *cell);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010068int snd_seq_event_dup(struct snd_seq_pool *pool, struct snd_seq_event *event,
Takashi Iwaiec001162018-03-05 22:06:09 +010069 struct snd_seq_event_cell **cellp, int nonblock,
70 struct file *file, struct mutex *mutexp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/* return number of unused (free) cells */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010073static inline int snd_seq_unused_cells(struct snd_seq_pool *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 return pool ? pool->total_elements - atomic_read(&pool->counter) : 0;
76}
77
78/* return total number of allocated cells */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010079static inline int snd_seq_total_cells(struct snd_seq_pool *pool)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 return pool ? pool->total_elements : 0;
82}
83
84/* init pool - allocate events */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010085int snd_seq_pool_init(struct snd_seq_pool *pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87/* done pool - free events */
Takashi Iwaica799522017-03-21 13:56:04 +010088void snd_seq_pool_mark_closing(struct snd_seq_pool *pool);
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010089int snd_seq_pool_done(struct snd_seq_pool *pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/* create pool */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010092struct snd_seq_pool *snd_seq_pool_new(int poolsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94/* remove pool */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +010095int snd_seq_pool_delete(struct snd_seq_pool **pool);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97/* init memory */
98int snd_sequencer_memory_init(void);
99
100/* release event memory */
101void snd_sequencer_memory_done(void);
102
103/* polling */
Takashi Iwaic7e0b5b2005-11-17 14:04:02 +0100104int snd_seq_pool_poll_wait(struct snd_seq_pool *pool, struct file *file, poll_table *wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Clemens Ladischfea952e2011-02-14 11:00:47 +0100106void snd_seq_info_pool(struct snd_info_buffer *buffer,
107 struct snd_seq_pool *pool, char *space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#endif