Linux Audio

Check our new training course

Loading...
v5.4
 1/* SPDX-License-Identifier: GPL-2.0-or-later */
 2/*
 3 *   ALSA sequencer Queue handling
 4 *   Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 5 */
 6#ifndef __SND_SEQ_QUEUE_H
 7#define __SND_SEQ_QUEUE_H
 8
 9#include "seq_memory.h"
10#include "seq_prioq.h"
11#include "seq_timer.h"
12#include "seq_lock.h"
13#include <linux/interrupt.h>
14#include <linux/list.h>
15#include <linux/bitops.h>
16
17#define SEQ_QUEUE_NO_OWNER (-1)
18
19struct snd_seq_queue {
20	int queue;		/* queue number */
21
22	char name[64];		/* name of this queue */
23
24	struct snd_seq_prioq	*tickq;		/* midi tick event queue */
25	struct snd_seq_prioq	*timeq;		/* real-time event queue */	
26	
27	struct snd_seq_timer *timer;	/* time keeper for this queue */
28	int	owner;		/* client that 'owns' the timer */
29	unsigned int	locked:1,	/* timer is only accesibble by owner if set */
30		klocked:1,	/* kernel lock (after START) */	
31		check_again:1,
32		check_blocked:1;
33
34	unsigned int flags;		/* status flags */
35	unsigned int info_flags;	/* info for sync */
36
37	spinlock_t owner_lock;
38	spinlock_t check_lock;
39
40	/* clients which uses this queue (bitmap) */
41	DECLARE_BITMAP(clients_bitmap, SNDRV_SEQ_MAX_CLIENTS);
42	unsigned int clients;	/* users of this queue */
43	struct mutex timer_mutex;
44
45	snd_use_lock_t use_lock;
46};
47
48
49/* get the number of current queues */
50int snd_seq_queue_get_cur_queues(void);
51
 
 
 
52/* delete queues */ 
53void snd_seq_queues_delete(void);
54
55
56/* create new queue (constructor) */
57struct snd_seq_queue *snd_seq_queue_alloc(int client, int locked, unsigned int flags);
58
59/* delete queue (destructor) */
60int snd_seq_queue_delete(int client, int queueid);
61
62/* notification that client has left the system */
63void snd_seq_queue_client_termination(int client);
64
65/* final stage */
66void snd_seq_queue_client_leave(int client);
67
68/* enqueue a event received from one the clients */
69int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop);
70
71/* Remove events */
72void snd_seq_queue_client_leave_cells(int client);
73void snd_seq_queue_remove_cells(int client, struct snd_seq_remove_events *info);
74
75/* return pointer to queue structure for specified id */
76struct snd_seq_queue *queueptr(int queueid);
77/* unlock */
78#define queuefree(q) snd_use_lock_free(&(q)->use_lock)
79
80/* return the (first) queue matching with the specified name */
81struct snd_seq_queue *snd_seq_queue_find_name(char *name);
82
83/* check single queue and dispatch events */
84void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop);
85
86/* access to queue's parameters */
87int snd_seq_queue_check_access(int queueid, int client);
88int snd_seq_queue_timer_set_tempo(int queueid, int client, struct snd_seq_queue_tempo *info);
89int snd_seq_queue_set_owner(int queueid, int client, int locked);
90int snd_seq_queue_set_locked(int queueid, int client, int locked);
91int snd_seq_queue_timer_open(int queueid);
92int snd_seq_queue_timer_close(int queueid);
93int snd_seq_queue_use(int queueid, int client, int use);
94int snd_seq_queue_is_used(int queueid, int client);
95
96int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
98#endif
v4.17
 
  1/*
  2 *   ALSA sequencer Queue handling
  3 *   Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
  4 *
  5 *   This program is free software; you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation; either version 2 of the License, or
  8 *   (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 of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with this program; if not, write to the Free Software
 17 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 18 *
 19 */
 20#ifndef __SND_SEQ_QUEUE_H
 21#define __SND_SEQ_QUEUE_H
 22
 23#include "seq_memory.h"
 24#include "seq_prioq.h"
 25#include "seq_timer.h"
 26#include "seq_lock.h"
 27#include <linux/interrupt.h>
 28#include <linux/list.h>
 29#include <linux/bitops.h>
 30
 31#define SEQ_QUEUE_NO_OWNER (-1)
 32
 33struct snd_seq_queue {
 34	int queue;		/* queue number */
 35
 36	char name[64];		/* name of this queue */
 37
 38	struct snd_seq_prioq	*tickq;		/* midi tick event queue */
 39	struct snd_seq_prioq	*timeq;		/* real-time event queue */	
 40	
 41	struct snd_seq_timer *timer;	/* time keeper for this queue */
 42	int	owner;		/* client that 'owns' the timer */
 43	unsigned int	locked:1,	/* timer is only accesibble by owner if set */
 44		klocked:1,	/* kernel lock (after START) */	
 45		check_again:1,
 46		check_blocked:1;
 47
 48	unsigned int flags;		/* status flags */
 49	unsigned int info_flags;	/* info for sync */
 50
 51	spinlock_t owner_lock;
 52	spinlock_t check_lock;
 53
 54	/* clients which uses this queue (bitmap) */
 55	DECLARE_BITMAP(clients_bitmap, SNDRV_SEQ_MAX_CLIENTS);
 56	unsigned int clients;	/* users of this queue */
 57	struct mutex timer_mutex;
 58
 59	snd_use_lock_t use_lock;
 60};
 61
 62
 63/* get the number of current queues */
 64int snd_seq_queue_get_cur_queues(void);
 65
 66/* init queues structure */
 67int snd_seq_queues_init(void);
 68
 69/* delete queues */ 
 70void snd_seq_queues_delete(void);
 71
 72
 73/* create new queue (constructor) */
 74struct snd_seq_queue *snd_seq_queue_alloc(int client, int locked, unsigned int flags);
 75
 76/* delete queue (destructor) */
 77int snd_seq_queue_delete(int client, int queueid);
 78
 79/* notification that client has left the system */
 80void snd_seq_queue_client_termination(int client);
 81
 82/* final stage */
 83void snd_seq_queue_client_leave(int client);
 84
 85/* enqueue a event received from one the clients */
 86int snd_seq_enqueue_event(struct snd_seq_event_cell *cell, int atomic, int hop);
 87
 88/* Remove events */
 89void snd_seq_queue_client_leave_cells(int client);
 90void snd_seq_queue_remove_cells(int client, struct snd_seq_remove_events *info);
 91
 92/* return pointer to queue structure for specified id */
 93struct snd_seq_queue *queueptr(int queueid);
 94/* unlock */
 95#define queuefree(q) snd_use_lock_free(&(q)->use_lock)
 96
 97/* return the (first) queue matching with the specified name */
 98struct snd_seq_queue *snd_seq_queue_find_name(char *name);
 99
100/* check single queue and dispatch events */
101void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop);
102
103/* access to queue's parameters */
104int snd_seq_queue_check_access(int queueid, int client);
105int snd_seq_queue_timer_set_tempo(int queueid, int client, struct snd_seq_queue_tempo *info);
106int snd_seq_queue_set_owner(int queueid, int client, int locked);
107int snd_seq_queue_set_locked(int queueid, int client, int locked);
108int snd_seq_queue_timer_open(int queueid);
109int snd_seq_queue_timer_close(int queueid);
110int snd_seq_queue_use(int queueid, int client, int use);
111int snd_seq_queue_is_used(int queueid, int client);
112
113int snd_seq_control_queue(struct snd_seq_event *ev, int atomic, int hop);
114
115/*
116 * 64bit division - for sync stuff..
117 */
118#if defined(i386) || defined(i486)
119
120#define udiv_qrnnd(q, r, n1, n0, d) \
121  __asm__ ("divl %4"		\
122	   : "=a" ((u32)(q)),	\
123	     "=d" ((u32)(r))	\
124	   : "0" ((u32)(n0)),	\
125	     "1" ((u32)(n1)),	\
126	     "rm" ((u32)(d)))
127
128#define u64_div(x,y,q) do {u32 __tmp; udiv_qrnnd(q, __tmp, (x)>>32, x, y);} while (0)
129#define u64_mod(x,y,r) do {u32 __tmp; udiv_qrnnd(__tmp, q, (x)>>32, x, y);} while (0)
130#define u64_divmod(x,y,q,r) udiv_qrnnd(q, r, (x)>>32, x, y)
131
132#else
133#define u64_div(x,y,q)	((q) = (u32)((u64)(x) / (u64)(y)))
134#define u64_mod(x,y,r)	((r) = (u32)((u64)(x) % (u64)(y)))
135#define u64_divmod(x,y,q,r) (u64_div(x,y,q), u64_mod(x,y,r))
136#endif
137
138
139#endif