2 * ALSA sequencer Client Manager
3 * Copyright (c) 1998-2001 by Frank van de Pol <fvdpol@coil.demon.nl>
4 * Jaroslav Kysela <perex@suse.cz>
5 * Takashi Iwai <tiwai@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/smp_lock.h>
27 #include <linux/slab.h>
28 #include <sound/core.h>
29 #include <sound/minors.h>
30 #include <linux/kmod.h>
32 #include <sound/seq_kernel.h>
33 #include "seq_clientmgr.h"
34 #include "seq_memory.h"
35 #include "seq_queue.h"
36 #include "seq_timer.h"
38 #include "seq_system.h"
39 #include <sound/seq_device.h>
41 #include <linux/compat.h>
46 * this module handles the connections of userland and kernel clients
50 #define SNDRV_SEQ_LFLG_INPUT 0x0001
51 #define SNDRV_SEQ_LFLG_OUTPUT 0x0002
52 #define SNDRV_SEQ_LFLG_OPEN (SNDRV_SEQ_LFLG_INPUT|SNDRV_SEQ_LFLG_OUTPUT)
54 static DEFINE_SPINLOCK(clients_lock
);
55 static DECLARE_MUTEX(register_mutex
);
60 static char clienttablock
[SNDRV_SEQ_MAX_CLIENTS
];
61 static struct snd_seq_client
*clienttab
[SNDRV_SEQ_MAX_CLIENTS
];
62 static struct snd_seq_usage client_usage
;
67 static int bounce_error_event(struct snd_seq_client
*client
,
68 struct snd_seq_event
*event
,
69 int err
, int atomic
, int hop
);
70 static int snd_seq_deliver_single_event(struct snd_seq_client
*client
,
71 struct snd_seq_event
*event
,
72 int filter
, int atomic
, int hop
);
77 static inline mm_segment_t
snd_enter_user(void)
79 mm_segment_t fs
= get_fs();
84 static inline void snd_leave_user(mm_segment_t fs
)
91 static inline unsigned short snd_seq_file_flags(struct file
*file
)
93 switch (file
->f_mode
& (FMODE_READ
| FMODE_WRITE
)) {
95 return SNDRV_SEQ_LFLG_OUTPUT
;
97 return SNDRV_SEQ_LFLG_INPUT
;
99 return SNDRV_SEQ_LFLG_OPEN
;
103 static inline int snd_seq_write_pool_allocated(struct snd_seq_client
*client
)
105 return snd_seq_total_cells(client
->pool
) > 0;
108 /* return pointer to client structure for specified id */
109 static struct snd_seq_client
*clientptr(int clientid
)
111 if (clientid
< 0 || clientid
>= SNDRV_SEQ_MAX_CLIENTS
) {
112 snd_printd("Seq: oops. Trying to get pointer to client %d\n",
116 return clienttab
[clientid
];
119 extern int seq_client_load
[];
121 struct snd_seq_client
*snd_seq_client_use_ptr(int clientid
)
124 struct snd_seq_client
*client
;
126 if (clientid
< 0 || clientid
>= SNDRV_SEQ_MAX_CLIENTS
) {
127 snd_printd("Seq: oops. Trying to get pointer to client %d\n",
131 spin_lock_irqsave(&clients_lock
, flags
);
132 client
= clientptr(clientid
);
135 if (clienttablock
[clientid
]) {
136 spin_unlock_irqrestore(&clients_lock
, flags
);
139 spin_unlock_irqrestore(&clients_lock
, flags
);
141 if (!in_interrupt() && current
->fs
->root
) {
142 static char client_requested
[64];
143 static char card_requested
[SNDRV_CARDS
];
147 if (! client_requested
[clientid
] && current
->fs
->root
) {
148 client_requested
[clientid
] = 1;
149 for (idx
= 0; idx
< 64; idx
++) {
150 if (seq_client_load
[idx
] < 0)
152 if (seq_client_load
[idx
] == clientid
) {
153 request_module("snd-seq-client-%i",
159 } else if (clientid
>= 64 && clientid
< 128) {
160 int card
= (clientid
- 64) / 4;
161 if (card
< snd_ecards_limit
) {
162 if (! card_requested
[card
]) {
163 card_requested
[card
] = 1;
164 snd_request_card(card
);
166 snd_seq_device_load_drivers();
169 spin_lock_irqsave(&clients_lock
, flags
);
170 client
= clientptr(clientid
);
173 spin_unlock_irqrestore(&clients_lock
, flags
);
179 snd_use_lock_use(&client
->use_lock
);
180 spin_unlock_irqrestore(&clients_lock
, flags
);
184 static void usage_alloc(struct snd_seq_usage
*res
, int num
)
187 if (res
->cur
> res
->peak
)
188 res
->peak
= res
->cur
;
191 static void usage_free(struct snd_seq_usage
*res
, int num
)
196 /* initialise data structures */
197 int __init
client_init_data(void)
199 /* zap out the client table */
200 memset(&clienttablock
, 0, sizeof(clienttablock
));
201 memset(&clienttab
, 0, sizeof(clienttab
));
206 static struct snd_seq_client
*seq_create_client1(int client_index
, int poolsize
)
210 struct snd_seq_client
*client
;
212 /* init client data */
213 client
= kzalloc(sizeof(*client
), GFP_KERNEL
);
216 client
->pool
= snd_seq_pool_new(poolsize
);
217 if (client
->pool
== NULL
) {
221 client
->type
= NO_CLIENT
;
222 snd_use_lock_init(&client
->use_lock
);
223 rwlock_init(&client
->ports_lock
);
224 init_MUTEX(&client
->ports_mutex
);
225 INIT_LIST_HEAD(&client
->ports_list_head
);
227 /* find free slot in the client table */
228 spin_lock_irqsave(&clients_lock
, flags
);
229 if (client_index
< 0) {
230 for (c
= 128; c
< SNDRV_SEQ_MAX_CLIENTS
; c
++) {
231 if (clienttab
[c
] || clienttablock
[c
])
233 clienttab
[client
->number
= c
] = client
;
234 spin_unlock_irqrestore(&clients_lock
, flags
);
238 if (clienttab
[client_index
] == NULL
&& !clienttablock
[client_index
]) {
239 clienttab
[client
->number
= client_index
] = client
;
240 spin_unlock_irqrestore(&clients_lock
, flags
);
244 spin_unlock_irqrestore(&clients_lock
, flags
);
245 snd_seq_pool_delete(&client
->pool
);
247 return NULL
; /* no free slot found or busy, return failure code */
251 static int seq_free_client1(struct snd_seq_client
*client
)
255 snd_assert(client
!= NULL
, return -EINVAL
);
256 snd_seq_delete_all_ports(client
);
257 snd_seq_queue_client_leave(client
->number
);
258 spin_lock_irqsave(&clients_lock
, flags
);
259 clienttablock
[client
->number
] = 1;
260 clienttab
[client
->number
] = NULL
;
261 spin_unlock_irqrestore(&clients_lock
, flags
);
262 snd_use_lock_sync(&client
->use_lock
);
263 snd_seq_queue_client_termination(client
->number
);
265 snd_seq_pool_delete(&client
->pool
);
266 spin_lock_irqsave(&clients_lock
, flags
);
267 clienttablock
[client
->number
] = 0;
268 spin_unlock_irqrestore(&clients_lock
, flags
);
273 static void seq_free_client(struct snd_seq_client
* client
)
275 down(®ister_mutex
);
276 switch (client
->type
) {
278 snd_printk(KERN_WARNING
"Seq: Trying to free unused client %d\n",
283 seq_free_client1(client
);
284 usage_free(&client_usage
, 1);
288 snd_printk(KERN_ERR
"Seq: Trying to free client %d with undefined type = %d\n",
289 client
->number
, client
->type
);
293 snd_seq_system_client_ev_client_exit(client
->number
);
298 /* -------------------------------------------------------- */
300 /* create a user client */
301 static int snd_seq_open(struct inode
*inode
, struct file
*file
)
303 int c
, mode
; /* client id */
304 struct snd_seq_client
*client
;
305 struct snd_seq_user_client
*user
;
307 if (down_interruptible(®ister_mutex
))
309 client
= seq_create_client1(-1, SNDRV_SEQ_DEFAULT_EVENTS
);
310 if (client
== NULL
) {
312 return -ENOMEM
; /* failure code */
315 mode
= snd_seq_file_flags(file
);
316 if (mode
& SNDRV_SEQ_LFLG_INPUT
)
317 client
->accept_input
= 1;
318 if (mode
& SNDRV_SEQ_LFLG_OUTPUT
)
319 client
->accept_output
= 1;
321 user
= &client
->data
.user
;
323 user
->fifo_pool_size
= 0;
325 if (mode
& SNDRV_SEQ_LFLG_INPUT
) {
326 user
->fifo_pool_size
= SNDRV_SEQ_DEFAULT_CLIENT_EVENTS
;
327 user
->fifo
= snd_seq_fifo_new(user
->fifo_pool_size
);
328 if (user
->fifo
== NULL
) {
329 seq_free_client1(client
);
336 usage_alloc(&client_usage
, 1);
337 client
->type
= USER_CLIENT
;
341 file
->private_data
= client
;
343 /* fill client data */
345 sprintf(client
->name
, "Client-%d", c
);
347 /* make others aware this new client */
348 snd_seq_system_client_ev_client_start(c
);
353 /* delete a user client */
354 static int snd_seq_release(struct inode
*inode
, struct file
*file
)
356 struct snd_seq_client
*client
= file
->private_data
;
359 seq_free_client(client
);
360 if (client
->data
.user
.fifo
)
361 snd_seq_fifo_delete(&client
->data
.user
.fifo
);
369 /* handle client read() */
370 /* possible error values:
371 * -ENXIO invalid client or file open mode
372 * -ENOSPC FIFO overflow (the flag is cleared after this error report)
373 * -EINVAL no enough user-space buffer to write the whole event
374 * -EFAULT seg. fault during copy to user space
376 static ssize_t
snd_seq_read(struct file
*file
, char __user
*buf
, size_t count
,
379 struct snd_seq_client
*client
= file
->private_data
;
380 struct snd_seq_fifo
*fifo
;
383 struct snd_seq_event_cell
*cell
;
385 if (!(snd_seq_file_flags(file
) & SNDRV_SEQ_LFLG_INPUT
))
388 if (!access_ok(VERIFY_WRITE
, buf
, count
))
391 /* check client structures are in place */
392 snd_assert(client
!= NULL
, return -ENXIO
);
394 if (!client
->accept_input
|| (fifo
= client
->data
.user
.fifo
) == NULL
)
397 if (atomic_read(&fifo
->overflow
) > 0) {
398 /* buffer overflow is detected */
399 snd_seq_fifo_clear(fifo
);
400 /* return error code */
406 snd_seq_fifo_lock(fifo
);
408 /* while data available in queue */
409 while (count
>= sizeof(struct snd_seq_event
)) {
412 nonblock
= (file
->f_flags
& O_NONBLOCK
) || result
> 0;
413 if ((err
= snd_seq_fifo_cell_out(fifo
, &cell
, nonblock
)) < 0) {
416 if (snd_seq_ev_is_variable(&cell
->event
)) {
417 struct snd_seq_event tmpev
;
419 tmpev
.data
.ext
.len
&= ~SNDRV_SEQ_EXT_MASK
;
420 if (copy_to_user(buf
, &tmpev
, sizeof(struct snd_seq_event
))) {
424 count
-= sizeof(struct snd_seq_event
);
425 buf
+= sizeof(struct snd_seq_event
);
426 err
= snd_seq_expand_var_event(&cell
->event
, count
,
427 (char __force
*)buf
, 0,
428 sizeof(struct snd_seq_event
));
435 if (copy_to_user(buf
, &cell
->event
, sizeof(struct snd_seq_event
))) {
439 count
-= sizeof(struct snd_seq_event
);
440 buf
+= sizeof(struct snd_seq_event
);
442 snd_seq_cell_free(cell
);
443 cell
= NULL
; /* to be sure */
444 result
+= sizeof(struct snd_seq_event
);
449 snd_seq_fifo_cell_putback(fifo
, cell
);
450 if (err
== -EAGAIN
&& result
> 0)
453 snd_seq_fifo_unlock(fifo
);
455 return (err
< 0) ? err
: result
;
460 * check access permission to the port
462 static int check_port_perm(struct snd_seq_client_port
*port
, unsigned int flags
)
464 if ((port
->capability
& flags
) != flags
)
470 * check if the destination client is available, and return the pointer
471 * if filter is non-zero, client filter bitmap is tested.
473 static struct snd_seq_client
*get_event_dest_client(struct snd_seq_event
*event
,
476 struct snd_seq_client
*dest
;
478 dest
= snd_seq_client_use_ptr(event
->dest
.client
);
481 if (! dest
->accept_input
)
483 if ((dest
->filter
& SNDRV_SEQ_FILTER_USE_EVENT
) &&
484 ! test_bit(event
->type
, dest
->event_filter
))
486 if (filter
&& !(dest
->filter
& filter
))
489 return dest
; /* ok - accessible */
491 snd_seq_client_unlock(dest
);
497 * Return the error event.
499 * If the receiver client is a user client, the original event is
500 * encapsulated in SNDRV_SEQ_EVENT_BOUNCE as variable length event. If
501 * the original event is also variable length, the external data is
502 * copied after the event record.
503 * If the receiver client is a kernel client, the original event is
504 * quoted in SNDRV_SEQ_EVENT_KERNEL_ERROR, since this requires no extra
507 static int bounce_error_event(struct snd_seq_client
*client
,
508 struct snd_seq_event
*event
,
509 int err
, int atomic
, int hop
)
511 struct snd_seq_event bounce_ev
;
514 if (client
== NULL
||
515 ! (client
->filter
& SNDRV_SEQ_FILTER_BOUNCE
) ||
516 ! client
->accept_input
)
517 return 0; /* ignored */
519 /* set up quoted error */
520 memset(&bounce_ev
, 0, sizeof(bounce_ev
));
521 bounce_ev
.type
= SNDRV_SEQ_EVENT_KERNEL_ERROR
;
522 bounce_ev
.flags
= SNDRV_SEQ_EVENT_LENGTH_FIXED
;
523 bounce_ev
.queue
= SNDRV_SEQ_QUEUE_DIRECT
;
524 bounce_ev
.source
.client
= SNDRV_SEQ_CLIENT_SYSTEM
;
525 bounce_ev
.source
.port
= SNDRV_SEQ_PORT_SYSTEM_ANNOUNCE
;
526 bounce_ev
.dest
.client
= client
->number
;
527 bounce_ev
.dest
.port
= event
->source
.port
;
528 bounce_ev
.data
.quote
.origin
= event
->dest
;
529 bounce_ev
.data
.quote
.event
= event
;
530 bounce_ev
.data
.quote
.value
= -err
; /* use positive value */
531 result
= snd_seq_deliver_single_event(NULL
, &bounce_ev
, 0, atomic
, hop
+ 1);
533 client
->event_lost
++;
542 * rewrite the time-stamp of the event record with the curren time
543 * of the given queue.
544 * return non-zero if updated.
546 static int update_timestamp_of_queue(struct snd_seq_event
*event
,
547 int queue
, int real_time
)
549 struct snd_seq_queue
*q
;
554 event
->queue
= queue
;
555 event
->flags
&= ~SNDRV_SEQ_TIME_STAMP_MASK
;
557 event
->time
.time
= snd_seq_timer_get_cur_time(q
->timer
);
558 event
->flags
|= SNDRV_SEQ_TIME_STAMP_REAL
;
560 event
->time
.tick
= snd_seq_timer_get_cur_tick(q
->timer
);
561 event
->flags
|= SNDRV_SEQ_TIME_STAMP_TICK
;
569 * deliver an event to the specified destination.
570 * if filter is non-zero, client filter bitmap is tested.
572 * RETURN VALUE: 0 : if succeeded
575 static int snd_seq_deliver_single_event(struct snd_seq_client
*client
,
576 struct snd_seq_event
*event
,
577 int filter
, int atomic
, int hop
)
579 struct snd_seq_client
*dest
= NULL
;
580 struct snd_seq_client_port
*dest_port
= NULL
;
581 int result
= -ENOENT
;
584 direct
= snd_seq_ev_is_direct(event
);
586 dest
= get_event_dest_client(event
, filter
);
589 dest_port
= snd_seq_port_use_ptr(dest
, event
->dest
.port
);
590 if (dest_port
== NULL
)
593 /* check permission */
594 if (! check_port_perm(dest_port
, SNDRV_SEQ_PORT_CAP_WRITE
)) {
599 if (dest_port
->timestamping
)
600 update_timestamp_of_queue(event
, dest_port
->time_queue
,
601 dest_port
->time_real
);
603 switch (dest
->type
) {
605 if (dest
->data
.user
.fifo
)
606 result
= snd_seq_fifo_event_in(dest
->data
.user
.fifo
, event
);
610 if (dest_port
->event_input
== NULL
)
612 result
= dest_port
->event_input(event
, direct
,
613 dest_port
->private_data
,
622 snd_seq_port_unlock(dest_port
);
624 snd_seq_client_unlock(dest
);
626 if (result
< 0 && !direct
) {
627 result
= bounce_error_event(client
, event
, result
, atomic
, hop
);
634 * send the event to all subscribers:
636 static int deliver_to_subscribers(struct snd_seq_client
*client
,
637 struct snd_seq_event
*event
,
640 struct snd_seq_subscribers
*subs
;
641 int err
= 0, num_ev
= 0;
642 struct snd_seq_event event_saved
;
643 struct snd_seq_client_port
*src_port
;
645 struct snd_seq_port_subs_info
*grp
;
647 src_port
= snd_seq_port_use_ptr(client
, event
->source
.port
);
648 if (src_port
== NULL
)
649 return -EINVAL
; /* invalid source port */
650 /* save original event record */
651 event_saved
= *event
;
652 grp
= &src_port
->c_src
;
656 read_lock(&grp
->list_lock
);
658 down_read(&grp
->list_mutex
);
659 list_for_each(p
, &grp
->list_head
) {
660 subs
= list_entry(p
, struct snd_seq_subscribers
, src_list
);
661 event
->dest
= subs
->info
.dest
;
662 if (subs
->info
.flags
& SNDRV_SEQ_PORT_SUBS_TIMESTAMP
)
663 /* convert time according to flag with subscription */
664 update_timestamp_of_queue(event
, subs
->info
.queue
,
665 subs
->info
.flags
& SNDRV_SEQ_PORT_SUBS_TIME_REAL
);
666 err
= snd_seq_deliver_single_event(client
, event
,
671 /* restore original event record */
672 *event
= event_saved
;
675 read_unlock(&grp
->list_lock
);
677 up_read(&grp
->list_mutex
);
678 *event
= event_saved
; /* restore */
679 snd_seq_port_unlock(src_port
);
680 return (err
< 0) ? err
: num_ev
;
684 #ifdef SUPPORT_BROADCAST
686 * broadcast to all ports:
688 static int port_broadcast_event(struct snd_seq_client
*client
,
689 struct snd_seq_event
*event
,
692 int num_ev
= 0, err
= 0;
693 struct snd_seq_client
*dest_client
;
696 dest_client
= get_event_dest_client(event
, SNDRV_SEQ_FILTER_BROADCAST
);
697 if (dest_client
== NULL
)
698 return 0; /* no matching destination */
700 read_lock(&dest_client
->ports_lock
);
701 list_for_each(p
, &dest_client
->ports_list_head
) {
702 struct snd_seq_client_port
*port
= list_entry(p
, struct snd_seq_client_port
, list
);
703 event
->dest
.port
= port
->addr
.port
;
704 /* pass NULL as source client to avoid error bounce */
705 err
= snd_seq_deliver_single_event(NULL
, event
,
706 SNDRV_SEQ_FILTER_BROADCAST
,
712 read_unlock(&dest_client
->ports_lock
);
713 snd_seq_client_unlock(dest_client
);
714 event
->dest
.port
= SNDRV_SEQ_ADDRESS_BROADCAST
; /* restore */
715 return (err
< 0) ? err
: num_ev
;
719 * send the event to all clients:
720 * if destination port is also ADDRESS_BROADCAST, deliver to all ports.
722 static int broadcast_event(struct snd_seq_client
*client
,
723 struct snd_seq_event
*event
, int atomic
, int hop
)
725 int err
= 0, num_ev
= 0;
727 struct snd_seq_addr addr
;
729 addr
= event
->dest
; /* save */
731 for (dest
= 0; dest
< SNDRV_SEQ_MAX_CLIENTS
; dest
++) {
732 /* don't send to itself */
733 if (dest
== client
->number
)
735 event
->dest
.client
= dest
;
736 event
->dest
.port
= addr
.port
;
737 if (addr
.port
== SNDRV_SEQ_ADDRESS_BROADCAST
)
738 err
= port_broadcast_event(client
, event
, atomic
, hop
);
740 /* pass NULL as source client to avoid error bounce */
741 err
= snd_seq_deliver_single_event(NULL
, event
,
742 SNDRV_SEQ_FILTER_BROADCAST
,
748 event
->dest
= addr
; /* restore */
749 return (err
< 0) ? err
: num_ev
;
753 /* multicast - not supported yet */
754 static int multicast_event(struct snd_seq_client
*client
, struct snd_seq_event
*event
,
757 snd_printd("seq: multicast not supported yet.\n");
758 return 0; /* ignored */
760 #endif /* SUPPORT_BROADCAST */
763 /* deliver an event to the destination port(s).
764 * if the event is to subscribers or broadcast, the event is dispatched
765 * to multiple targets.
767 * RETURN VALUE: n > 0 : the number of delivered events.
768 * n == 0 : the event was not passed to any client.
769 * n < 0 : error - event was not processed.
771 static int snd_seq_deliver_event(struct snd_seq_client
*client
, struct snd_seq_event
*event
,
777 if (hop
>= SNDRV_SEQ_MAX_HOPS
) {
778 snd_printd("too long delivery path (%d:%d->%d:%d)\n",
779 event
->source
.client
, event
->source
.port
,
780 event
->dest
.client
, event
->dest
.port
);
784 if (event
->queue
== SNDRV_SEQ_ADDRESS_SUBSCRIBERS
||
785 event
->dest
.client
== SNDRV_SEQ_ADDRESS_SUBSCRIBERS
)
786 result
= deliver_to_subscribers(client
, event
, atomic
, hop
);
787 #ifdef SUPPORT_BROADCAST
788 else if (event
->queue
== SNDRV_SEQ_ADDRESS_BROADCAST
||
789 event
->dest
.client
== SNDRV_SEQ_ADDRESS_BROADCAST
)
790 result
= broadcast_event(client
, event
, atomic
, hop
);
791 else if (event
->dest
.client
>= SNDRV_SEQ_MAX_CLIENTS
)
792 result
= multicast_event(client
, event
, atomic
, hop
);
793 else if (event
->dest
.port
== SNDRV_SEQ_ADDRESS_BROADCAST
)
794 result
= port_broadcast_event(client
, event
, atomic
, hop
);
797 result
= snd_seq_deliver_single_event(client
, event
, 0, atomic
, hop
);
803 * dispatch an event cell:
804 * This function is called only from queue check routines in timer
805 * interrupts or after enqueued.
806 * The event cell shall be released or re-queued in this function.
808 * RETURN VALUE: n > 0 : the number of delivered events.
809 * n == 0 : the event was not passed to any client.
810 * n < 0 : error - event was not processed.
812 int snd_seq_dispatch_event(struct snd_seq_event_cell
*cell
, int atomic
, int hop
)
814 struct snd_seq_client
*client
;
817 snd_assert(cell
!= NULL
, return -EINVAL
);
819 client
= snd_seq_client_use_ptr(cell
->event
.source
.client
);
820 if (client
== NULL
) {
821 snd_seq_cell_free(cell
); /* release this cell */
825 if (cell
->event
.type
== SNDRV_SEQ_EVENT_NOTE
) {
827 * the event cell is re-used as a NOTE-OFF event and
830 struct snd_seq_event tmpev
, *ev
;
832 /* reserve this event to enqueue note-off later */
834 tmpev
.type
= SNDRV_SEQ_EVENT_NOTEON
;
835 result
= snd_seq_deliver_event(client
, &tmpev
, atomic
, hop
);
838 * This was originally a note event. We now re-use the
839 * cell for the note-off event.
843 ev
->type
= SNDRV_SEQ_EVENT_NOTEOFF
;
844 ev
->flags
|= SNDRV_SEQ_PRIORITY_HIGH
;
846 /* add the duration time */
847 switch (ev
->flags
& SNDRV_SEQ_TIME_STAMP_MASK
) {
848 case SNDRV_SEQ_TIME_STAMP_TICK
:
849 ev
->time
.tick
+= ev
->data
.note
.duration
;
851 case SNDRV_SEQ_TIME_STAMP_REAL
:
852 /* unit for duration is ms */
853 ev
->time
.time
.tv_nsec
+= 1000000 * (ev
->data
.note
.duration
% 1000);
854 ev
->time
.time
.tv_sec
+= ev
->data
.note
.duration
/ 1000 +
855 ev
->time
.time
.tv_nsec
/ 1000000000;
856 ev
->time
.time
.tv_nsec
%= 1000000000;
859 ev
->data
.note
.velocity
= ev
->data
.note
.off_velocity
;
861 /* Now queue this cell as the note off event */
862 if (snd_seq_enqueue_event(cell
, atomic
, hop
) < 0)
863 snd_seq_cell_free(cell
); /* release this cell */
867 * event cell is freed after processing the event
870 result
= snd_seq_deliver_event(client
, &cell
->event
, atomic
, hop
);
871 snd_seq_cell_free(cell
);
874 snd_seq_client_unlock(client
);
879 /* Allocate a cell from client pool and enqueue it to queue:
880 * if pool is empty and blocking is TRUE, sleep until a new cell is
883 static int snd_seq_client_enqueue_event(struct snd_seq_client
*client
,
884 struct snd_seq_event
*event
,
885 struct file
*file
, int blocking
,
888 struct snd_seq_event_cell
*cell
;
891 /* special queue values - force direct passing */
892 if (event
->queue
== SNDRV_SEQ_ADDRESS_SUBSCRIBERS
) {
893 event
->dest
.client
= SNDRV_SEQ_ADDRESS_SUBSCRIBERS
;
894 event
->queue
= SNDRV_SEQ_QUEUE_DIRECT
;
896 #ifdef SUPPORT_BROADCAST
897 if (event
->queue
== SNDRV_SEQ_ADDRESS_BROADCAST
) {
898 event
->dest
.client
= SNDRV_SEQ_ADDRESS_BROADCAST
;
899 event
->queue
= SNDRV_SEQ_QUEUE_DIRECT
;
902 if (event
->dest
.client
== SNDRV_SEQ_ADDRESS_SUBSCRIBERS
) {
903 /* check presence of source port */
904 struct snd_seq_client_port
*src_port
= snd_seq_port_use_ptr(client
, event
->source
.port
);
905 if (src_port
== NULL
)
907 snd_seq_port_unlock(src_port
);
910 /* direct event processing without enqueued */
911 if (snd_seq_ev_is_direct(event
)) {
912 if (event
->type
== SNDRV_SEQ_EVENT_NOTE
)
913 return -EINVAL
; /* this event must be enqueued! */
914 return snd_seq_deliver_event(client
, event
, atomic
, hop
);
917 /* Not direct, normal queuing */
918 if (snd_seq_queue_is_used(event
->queue
, client
->number
) <= 0)
919 return -EINVAL
; /* invalid queue */
920 if (! snd_seq_write_pool_allocated(client
))
921 return -ENXIO
; /* queue is not allocated */
923 /* allocate an event cell */
924 err
= snd_seq_event_dup(client
->pool
, event
, &cell
, !blocking
|| atomic
, file
);
928 /* we got a cell. enqueue it. */
929 if ((err
= snd_seq_enqueue_event(cell
, atomic
, hop
)) < 0) {
930 snd_seq_cell_free(cell
);
939 * check validity of event type and data length.
940 * return non-zero if invalid.
942 static int check_event_type_and_length(struct snd_seq_event
*ev
)
944 switch (snd_seq_ev_length_type(ev
)) {
945 case SNDRV_SEQ_EVENT_LENGTH_FIXED
:
946 if (snd_seq_ev_is_variable_type(ev
))
949 case SNDRV_SEQ_EVENT_LENGTH_VARIABLE
:
950 if (! snd_seq_ev_is_variable_type(ev
) ||
951 (ev
->data
.ext
.len
& ~SNDRV_SEQ_EXT_MASK
) >= SNDRV_SEQ_MAX_EVENT_LEN
)
954 case SNDRV_SEQ_EVENT_LENGTH_VARUSR
:
955 if (! snd_seq_ev_is_instr_type(ev
) ||
956 ! snd_seq_ev_is_direct(ev
))
965 /* possible error values:
966 * -ENXIO invalid client or file open mode
967 * -ENOMEM malloc failed
968 * -EFAULT seg. fault during copy from user space
969 * -EINVAL invalid event
970 * -EAGAIN no space in output pool
971 * -EINTR interrupts while sleep
972 * -EMLINK too many hops
973 * others depends on return value from driver callback
975 static ssize_t
snd_seq_write(struct file
*file
, const char __user
*buf
,
976 size_t count
, loff_t
*offset
)
978 struct snd_seq_client
*client
= file
->private_data
;
979 int written
= 0, len
;
981 struct snd_seq_event event
;
983 if (!(snd_seq_file_flags(file
) & SNDRV_SEQ_LFLG_OUTPUT
))
986 /* check client structures are in place */
987 snd_assert(client
!= NULL
, return -ENXIO
);
989 if (!client
->accept_output
|| client
->pool
== NULL
)
992 /* allocate the pool now if the pool is not allocated yet */
993 if (client
->pool
->size
> 0 && !snd_seq_write_pool_allocated(client
)) {
994 if (snd_seq_pool_init(client
->pool
) < 0)
998 /* only process whole events */
999 while (count
>= sizeof(struct snd_seq_event
)) {
1000 /* Read in the event header from the user */
1001 len
= sizeof(event
);
1002 if (copy_from_user(&event
, buf
, len
)) {
1006 event
.source
.client
= client
->number
; /* fill in client number */
1007 /* Check for extension data length */
1008 if (check_event_type_and_length(&event
)) {
1013 /* check for special events */
1014 if (event
.type
== SNDRV_SEQ_EVENT_NONE
)
1016 else if (snd_seq_ev_is_reserved(&event
)) {
1021 if (snd_seq_ev_is_variable(&event
)) {
1022 int extlen
= event
.data
.ext
.len
& ~SNDRV_SEQ_EXT_MASK
;
1023 if ((size_t)(extlen
+ len
) > count
) {
1024 /* back out, will get an error this time or next */
1028 /* set user space pointer */
1029 event
.data
.ext
.len
= extlen
| SNDRV_SEQ_EXT_USRPTR
;
1030 event
.data
.ext
.ptr
= (char __force
*)buf
1031 + sizeof(struct snd_seq_event
);
1032 len
+= extlen
; /* increment data length */
1034 #ifdef CONFIG_COMPAT
1035 if (client
->convert32
&& snd_seq_ev_is_varusr(&event
)) {
1036 void *ptr
= compat_ptr(event
.data
.raw32
.d
[1]);
1037 event
.data
.ext
.ptr
= ptr
;
1042 /* ok, enqueue it */
1043 err
= snd_seq_client_enqueue_event(client
, &event
, file
,
1044 !(file
->f_flags
& O_NONBLOCK
),
1050 /* Update pointers and counts */
1056 return written
? written
: err
;
1063 static unsigned int snd_seq_poll(struct file
*file
, poll_table
* wait
)
1065 struct snd_seq_client
*client
= file
->private_data
;
1066 unsigned int mask
= 0;
1068 /* check client structures are in place */
1069 snd_assert(client
!= NULL
, return -ENXIO
);
1071 if ((snd_seq_file_flags(file
) & SNDRV_SEQ_LFLG_INPUT
) &&
1072 client
->data
.user
.fifo
) {
1074 /* check if data is available in the outqueue */
1075 if (snd_seq_fifo_poll_wait(client
->data
.user
.fifo
, file
, wait
))
1076 mask
|= POLLIN
| POLLRDNORM
;
1079 if (snd_seq_file_flags(file
) & SNDRV_SEQ_LFLG_OUTPUT
) {
1081 /* check if data is available in the pool */
1082 if (!snd_seq_write_pool_allocated(client
) ||
1083 snd_seq_pool_poll_wait(client
->pool
, file
, wait
))
1084 mask
|= POLLOUT
| POLLWRNORM
;
1091 /*-----------------------------------------------------*/
1094 /* SYSTEM_INFO ioctl() */
1095 static int snd_seq_ioctl_system_info(struct snd_seq_client
*client
, void __user
*arg
)
1097 struct snd_seq_system_info info
;
1099 memset(&info
, 0, sizeof(info
));
1100 /* fill the info fields */
1101 info
.queues
= SNDRV_SEQ_MAX_QUEUES
;
1102 info
.clients
= SNDRV_SEQ_MAX_CLIENTS
;
1103 info
.ports
= 256; /* fixed limit */
1104 info
.channels
= 256; /* fixed limit */
1105 info
.cur_clients
= client_usage
.cur
;
1106 info
.cur_queues
= snd_seq_queue_get_cur_queues();
1108 if (copy_to_user(arg
, &info
, sizeof(info
)))
1114 /* RUNNING_MODE ioctl() */
1115 static int snd_seq_ioctl_running_mode(struct snd_seq_client
*client
, void __user
*arg
)
1117 struct snd_seq_running_info info
;
1118 struct snd_seq_client
*cptr
;
1121 if (copy_from_user(&info
, arg
, sizeof(info
)))
1124 /* requested client number */
1125 cptr
= snd_seq_client_use_ptr(info
.client
);
1127 return -ENOENT
; /* don't change !!! */
1129 #ifdef SNDRV_BIG_ENDIAN
1130 if (! info
.big_endian
) {
1135 if (info
.big_endian
) {
1141 if (info
.cpu_mode
> sizeof(long)) {
1145 cptr
->convert32
= (info
.cpu_mode
< sizeof(long));
1147 snd_seq_client_unlock(cptr
);
1151 /* CLIENT_INFO ioctl() */
1152 static void get_client_info(struct snd_seq_client
*cptr
,
1153 struct snd_seq_client_info
*info
)
1155 info
->client
= cptr
->number
;
1157 /* fill the info fields */
1158 info
->type
= cptr
->type
;
1159 strcpy(info
->name
, cptr
->name
);
1160 info
->filter
= cptr
->filter
;
1161 info
->event_lost
= cptr
->event_lost
;
1162 memcpy(info
->event_filter
, cptr
->event_filter
, 32);
1163 info
->num_ports
= cptr
->num_ports
;
1164 memset(info
->reserved
, 0, sizeof(info
->reserved
));
1167 static int snd_seq_ioctl_get_client_info(struct snd_seq_client
*client
,
1170 struct snd_seq_client
*cptr
;
1171 struct snd_seq_client_info client_info
;
1173 if (copy_from_user(&client_info
, arg
, sizeof(client_info
)))
1176 /* requested client number */
1177 cptr
= snd_seq_client_use_ptr(client_info
.client
);
1179 return -ENOENT
; /* don't change !!! */
1181 get_client_info(cptr
, &client_info
);
1182 snd_seq_client_unlock(cptr
);
1184 if (copy_to_user(arg
, &client_info
, sizeof(client_info
)))
1190 /* CLIENT_INFO ioctl() */
1191 static int snd_seq_ioctl_set_client_info(struct snd_seq_client
*client
,
1194 struct snd_seq_client_info client_info
;
1196 if (copy_from_user(&client_info
, arg
, sizeof(client_info
)))
1199 /* it is not allowed to set the info fields for an another client */
1200 if (client
->number
!= client_info
.client
)
1202 /* also client type must be set now */
1203 if (client
->type
!= client_info
.type
)
1206 /* fill the info fields */
1207 if (client_info
.name
[0])
1208 strlcpy(client
->name
, client_info
.name
, sizeof(client
->name
));
1210 client
->filter
= client_info
.filter
;
1211 client
->event_lost
= client_info
.event_lost
;
1212 memcpy(client
->event_filter
, client_info
.event_filter
, 32);
1219 * CREATE PORT ioctl()
1221 static int snd_seq_ioctl_create_port(struct snd_seq_client
*client
,
1224 struct snd_seq_client_port
*port
;
1225 struct snd_seq_port_info info
;
1226 struct snd_seq_port_callback
*callback
;
1228 if (copy_from_user(&info
, arg
, sizeof(info
)))
1231 /* it is not allowed to create the port for an another client */
1232 if (info
.addr
.client
!= client
->number
)
1235 port
= snd_seq_create_port(client
, (info
.flags
& SNDRV_SEQ_PORT_FLG_GIVEN_PORT
) ? info
.addr
.port
: -1);
1239 if (client
->type
== USER_CLIENT
&& info
.kernel
) {
1240 snd_seq_delete_port(client
, port
->addr
.port
);
1243 if (client
->type
== KERNEL_CLIENT
) {
1244 if ((callback
= info
.kernel
) != NULL
) {
1245 if (callback
->owner
)
1246 port
->owner
= callback
->owner
;
1247 port
->private_data
= callback
->private_data
;
1248 port
->private_free
= callback
->private_free
;
1249 port
->callback_all
= callback
->callback_all
;
1250 port
->event_input
= callback
->event_input
;
1251 port
->c_src
.open
= callback
->subscribe
;
1252 port
->c_src
.close
= callback
->unsubscribe
;
1253 port
->c_dest
.open
= callback
->use
;
1254 port
->c_dest
.close
= callback
->unuse
;
1258 info
.addr
= port
->addr
;
1260 snd_seq_set_port_info(port
, &info
);
1261 snd_seq_system_client_ev_port_start(port
->addr
.client
, port
->addr
.port
);
1263 if (copy_to_user(arg
, &info
, sizeof(info
)))
1270 * DELETE PORT ioctl()
1272 static int snd_seq_ioctl_delete_port(struct snd_seq_client
*client
,
1275 struct snd_seq_port_info info
;
1278 /* set passed parameters */
1279 if (copy_from_user(&info
, arg
, sizeof(info
)))
1282 /* it is not allowed to remove the port for an another client */
1283 if (info
.addr
.client
!= client
->number
)
1286 err
= snd_seq_delete_port(client
, info
.addr
.port
);
1288 snd_seq_system_client_ev_port_exit(client
->number
, info
.addr
.port
);
1294 * GET_PORT_INFO ioctl() (on any client)
1296 static int snd_seq_ioctl_get_port_info(struct snd_seq_client
*client
,
1299 struct snd_seq_client
*cptr
;
1300 struct snd_seq_client_port
*port
;
1301 struct snd_seq_port_info info
;
1303 if (copy_from_user(&info
, arg
, sizeof(info
)))
1305 cptr
= snd_seq_client_use_ptr(info
.addr
.client
);
1309 port
= snd_seq_port_use_ptr(cptr
, info
.addr
.port
);
1311 snd_seq_client_unlock(cptr
);
1312 return -ENOENT
; /* don't change */
1316 snd_seq_get_port_info(port
, &info
);
1317 snd_seq_port_unlock(port
);
1318 snd_seq_client_unlock(cptr
);
1320 if (copy_to_user(arg
, &info
, sizeof(info
)))
1327 * SET_PORT_INFO ioctl() (only ports on this/own client)
1329 static int snd_seq_ioctl_set_port_info(struct snd_seq_client
*client
,
1332 struct snd_seq_client_port
*port
;
1333 struct snd_seq_port_info info
;
1335 if (copy_from_user(&info
, arg
, sizeof(info
)))
1338 if (info
.addr
.client
!= client
->number
) /* only set our own ports ! */
1340 port
= snd_seq_port_use_ptr(client
, info
.addr
.port
);
1342 snd_seq_set_port_info(port
, &info
);
1343 snd_seq_port_unlock(port
);
1350 * port subscription (connection)
1352 #define PERM_RD (SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ)
1353 #define PERM_WR (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_SUBS_WRITE)
1355 static int check_subscription_permission(struct snd_seq_client
*client
,
1356 struct snd_seq_client_port
*sport
,
1357 struct snd_seq_client_port
*dport
,
1358 struct snd_seq_port_subscribe
*subs
)
1360 if (client
->number
!= subs
->sender
.client
&&
1361 client
->number
!= subs
->dest
.client
) {
1362 /* connection by third client - check export permission */
1363 if (check_port_perm(sport
, SNDRV_SEQ_PORT_CAP_NO_EXPORT
))
1365 if (check_port_perm(dport
, SNDRV_SEQ_PORT_CAP_NO_EXPORT
))
1369 /* check read permission */
1370 /* if sender or receiver is the subscribing client itself,
1371 * no permission check is necessary
1373 if (client
->number
!= subs
->sender
.client
) {
1374 if (! check_port_perm(sport
, PERM_RD
))
1377 /* check write permission */
1378 if (client
->number
!= subs
->dest
.client
) {
1379 if (! check_port_perm(dport
, PERM_WR
))
1386 * send an subscription notify event to user client:
1387 * client must be user client.
1389 int snd_seq_client_notify_subscription(int client
, int port
,
1390 struct snd_seq_port_subscribe
*info
,
1393 struct snd_seq_event event
;
1395 memset(&event
, 0, sizeof(event
));
1396 event
.type
= evtype
;
1397 event
.data
.connect
.dest
= info
->dest
;
1398 event
.data
.connect
.sender
= info
->sender
;
1400 return snd_seq_system_notify(client
, port
, &event
); /* non-atomic */
1405 * add to port's subscription list IOCTL interface
1407 static int snd_seq_ioctl_subscribe_port(struct snd_seq_client
*client
,
1410 int result
= -EINVAL
;
1411 struct snd_seq_client
*receiver
= NULL
, *sender
= NULL
;
1412 struct snd_seq_client_port
*sport
= NULL
, *dport
= NULL
;
1413 struct snd_seq_port_subscribe subs
;
1415 if (copy_from_user(&subs
, arg
, sizeof(subs
)))
1418 if ((receiver
= snd_seq_client_use_ptr(subs
.dest
.client
)) == NULL
)
1420 if ((sender
= snd_seq_client_use_ptr(subs
.sender
.client
)) == NULL
)
1422 if ((sport
= snd_seq_port_use_ptr(sender
, subs
.sender
.port
)) == NULL
)
1424 if ((dport
= snd_seq_port_use_ptr(receiver
, subs
.dest
.port
)) == NULL
)
1427 result
= check_subscription_permission(client
, sport
, dport
, &subs
);
1432 result
= snd_seq_port_connect(client
, sender
, sport
, receiver
, dport
, &subs
);
1433 if (! result
) /* broadcast announce */
1434 snd_seq_client_notify_subscription(SNDRV_SEQ_ADDRESS_SUBSCRIBERS
, 0,
1435 &subs
, SNDRV_SEQ_EVENT_PORT_SUBSCRIBED
);
1438 snd_seq_port_unlock(sport
);
1440 snd_seq_port_unlock(dport
);
1442 snd_seq_client_unlock(sender
);
1444 snd_seq_client_unlock(receiver
);
1450 * remove from port's subscription list
1452 static int snd_seq_ioctl_unsubscribe_port(struct snd_seq_client
*client
,
1455 int result
= -ENXIO
;
1456 struct snd_seq_client
*receiver
= NULL
, *sender
= NULL
;
1457 struct snd_seq_client_port
*sport
= NULL
, *dport
= NULL
;
1458 struct snd_seq_port_subscribe subs
;
1460 if (copy_from_user(&subs
, arg
, sizeof(subs
)))
1463 if ((receiver
= snd_seq_client_use_ptr(subs
.dest
.client
)) == NULL
)
1465 if ((sender
= snd_seq_client_use_ptr(subs
.sender
.client
)) == NULL
)
1467 if ((sport
= snd_seq_port_use_ptr(sender
, subs
.sender
.port
)) == NULL
)
1469 if ((dport
= snd_seq_port_use_ptr(receiver
, subs
.dest
.port
)) == NULL
)
1472 result
= check_subscription_permission(client
, sport
, dport
, &subs
);
1476 result
= snd_seq_port_disconnect(client
, sender
, sport
, receiver
, dport
, &subs
);
1477 if (! result
) /* broadcast announce */
1478 snd_seq_client_notify_subscription(SNDRV_SEQ_ADDRESS_SUBSCRIBERS
, 0,
1479 &subs
, SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED
);
1482 snd_seq_port_unlock(sport
);
1484 snd_seq_port_unlock(dport
);
1486 snd_seq_client_unlock(sender
);
1488 snd_seq_client_unlock(receiver
);
1493 /* CREATE_QUEUE ioctl() */
1494 static int snd_seq_ioctl_create_queue(struct snd_seq_client
*client
,
1497 struct snd_seq_queue_info info
;
1499 struct snd_seq_queue
*q
;
1501 if (copy_from_user(&info
, arg
, sizeof(info
)))
1504 result
= snd_seq_queue_alloc(client
->number
, info
.locked
, info
.flags
);
1508 q
= queueptr(result
);
1512 info
.queue
= q
->queue
;
1513 info
.locked
= q
->locked
;
1514 info
.owner
= q
->owner
;
1516 /* set queue name */
1518 snprintf(info
.name
, sizeof(info
.name
), "Queue-%d", q
->queue
);
1519 strlcpy(q
->name
, info
.name
, sizeof(q
->name
));
1522 if (copy_to_user(arg
, &info
, sizeof(info
)))
1528 /* DELETE_QUEUE ioctl() */
1529 static int snd_seq_ioctl_delete_queue(struct snd_seq_client
*client
,
1532 struct snd_seq_queue_info info
;
1534 if (copy_from_user(&info
, arg
, sizeof(info
)))
1537 return snd_seq_queue_delete(client
->number
, info
.queue
);
1540 /* GET_QUEUE_INFO ioctl() */
1541 static int snd_seq_ioctl_get_queue_info(struct snd_seq_client
*client
,
1544 struct snd_seq_queue_info info
;
1545 struct snd_seq_queue
*q
;
1547 if (copy_from_user(&info
, arg
, sizeof(info
)))
1550 q
= queueptr(info
.queue
);
1554 memset(&info
, 0, sizeof(info
));
1555 info
.queue
= q
->queue
;
1556 info
.owner
= q
->owner
;
1557 info
.locked
= q
->locked
;
1558 strlcpy(info
.name
, q
->name
, sizeof(info
.name
));
1561 if (copy_to_user(arg
, &info
, sizeof(info
)))
1567 /* SET_QUEUE_INFO ioctl() */
1568 static int snd_seq_ioctl_set_queue_info(struct snd_seq_client
*client
,
1571 struct snd_seq_queue_info info
;
1572 struct snd_seq_queue
*q
;
1574 if (copy_from_user(&info
, arg
, sizeof(info
)))
1577 if (info
.owner
!= client
->number
)
1580 /* change owner/locked permission */
1581 if (snd_seq_queue_check_access(info
.queue
, client
->number
)) {
1582 if (snd_seq_queue_set_owner(info
.queue
, client
->number
, info
.locked
) < 0)
1585 snd_seq_queue_use(info
.queue
, client
->number
, 1);
1590 q
= queueptr(info
.queue
);
1593 if (q
->owner
!= client
->number
) {
1597 strlcpy(q
->name
, info
.name
, sizeof(q
->name
));
1603 /* GET_NAMED_QUEUE ioctl() */
1604 static int snd_seq_ioctl_get_named_queue(struct snd_seq_client
*client
, void __user
*arg
)
1606 struct snd_seq_queue_info info
;
1607 struct snd_seq_queue
*q
;
1609 if (copy_from_user(&info
, arg
, sizeof(info
)))
1612 q
= snd_seq_queue_find_name(info
.name
);
1615 info
.queue
= q
->queue
;
1616 info
.owner
= q
->owner
;
1617 info
.locked
= q
->locked
;
1620 if (copy_to_user(arg
, &info
, sizeof(info
)))
1626 /* GET_QUEUE_STATUS ioctl() */
1627 static int snd_seq_ioctl_get_queue_status(struct snd_seq_client
*client
,
1630 struct snd_seq_queue_status status
;
1631 struct snd_seq_queue
*queue
;
1632 struct snd_seq_timer
*tmr
;
1634 if (copy_from_user(&status
, arg
, sizeof(status
)))
1637 queue
= queueptr(status
.queue
);
1640 memset(&status
, 0, sizeof(status
));
1641 status
.queue
= queue
->queue
;
1644 status
.events
= queue
->tickq
->cells
+ queue
->timeq
->cells
;
1646 status
.time
= snd_seq_timer_get_cur_time(tmr
);
1647 status
.tick
= snd_seq_timer_get_cur_tick(tmr
);
1649 status
.running
= tmr
->running
;
1651 status
.flags
= queue
->flags
;
1654 if (copy_to_user(arg
, &status
, sizeof(status
)))
1660 /* GET_QUEUE_TEMPO ioctl() */
1661 static int snd_seq_ioctl_get_queue_tempo(struct snd_seq_client
*client
,
1664 struct snd_seq_queue_tempo tempo
;
1665 struct snd_seq_queue
*queue
;
1666 struct snd_seq_timer
*tmr
;
1668 if (copy_from_user(&tempo
, arg
, sizeof(tempo
)))
1671 queue
= queueptr(tempo
.queue
);
1674 memset(&tempo
, 0, sizeof(tempo
));
1675 tempo
.queue
= queue
->queue
;
1679 tempo
.tempo
= tmr
->tempo
;
1680 tempo
.ppq
= tmr
->ppq
;
1681 tempo
.skew_value
= tmr
->skew
;
1682 tempo
.skew_base
= tmr
->skew_base
;
1685 if (copy_to_user(arg
, &tempo
, sizeof(tempo
)))
1691 /* SET_QUEUE_TEMPO ioctl() */
1692 int snd_seq_set_queue_tempo(int client
, struct snd_seq_queue_tempo
*tempo
)
1694 if (!snd_seq_queue_check_access(tempo
->queue
, client
))
1696 return snd_seq_queue_timer_set_tempo(tempo
->queue
, client
, tempo
);
1699 static int snd_seq_ioctl_set_queue_tempo(struct snd_seq_client
*client
,
1703 struct snd_seq_queue_tempo tempo
;
1705 if (copy_from_user(&tempo
, arg
, sizeof(tempo
)))
1708 result
= snd_seq_set_queue_tempo(client
->number
, &tempo
);
1709 return result
< 0 ? result
: 0;
1713 /* GET_QUEUE_TIMER ioctl() */
1714 static int snd_seq_ioctl_get_queue_timer(struct snd_seq_client
*client
,
1717 struct snd_seq_queue_timer timer
;
1718 struct snd_seq_queue
*queue
;
1719 struct snd_seq_timer
*tmr
;
1721 if (copy_from_user(&timer
, arg
, sizeof(timer
)))
1724 queue
= queueptr(timer
.queue
);
1728 if (down_interruptible(&queue
->timer_mutex
)) {
1730 return -ERESTARTSYS
;
1733 memset(&timer
, 0, sizeof(timer
));
1734 timer
.queue
= queue
->queue
;
1736 timer
.type
= tmr
->type
;
1737 if (tmr
->type
== SNDRV_SEQ_TIMER_ALSA
) {
1738 timer
.u
.alsa
.id
= tmr
->alsa_id
;
1739 timer
.u
.alsa
.resolution
= tmr
->preferred_resolution
;
1741 up(&queue
->timer_mutex
);
1744 if (copy_to_user(arg
, &timer
, sizeof(timer
)))
1750 /* SET_QUEUE_TIMER ioctl() */
1751 static int snd_seq_ioctl_set_queue_timer(struct snd_seq_client
*client
,
1755 struct snd_seq_queue_timer timer
;
1757 if (copy_from_user(&timer
, arg
, sizeof(timer
)))
1760 if (timer
.type
!= SNDRV_SEQ_TIMER_ALSA
)
1763 if (snd_seq_queue_check_access(timer
.queue
, client
->number
)) {
1764 struct snd_seq_queue
*q
;
1765 struct snd_seq_timer
*tmr
;
1767 q
= queueptr(timer
.queue
);
1770 if (down_interruptible(&q
->timer_mutex
)) {
1772 return -ERESTARTSYS
;
1775 snd_seq_queue_timer_close(timer
.queue
);
1776 tmr
->type
= timer
.type
;
1777 if (tmr
->type
== SNDRV_SEQ_TIMER_ALSA
) {
1778 tmr
->alsa_id
= timer
.u
.alsa
.id
;
1779 tmr
->preferred_resolution
= timer
.u
.alsa
.resolution
;
1781 result
= snd_seq_queue_timer_open(timer
.queue
);
1782 up(&q
->timer_mutex
);
1792 /* GET_QUEUE_CLIENT ioctl() */
1793 static int snd_seq_ioctl_get_queue_client(struct snd_seq_client
*client
,
1796 struct snd_seq_queue_client info
;
1799 if (copy_from_user(&info
, arg
, sizeof(info
)))
1802 used
= snd_seq_queue_is_used(info
.queue
, client
->number
);
1806 info
.client
= client
->number
;
1808 if (copy_to_user(arg
, &info
, sizeof(info
)))
1814 /* SET_QUEUE_CLIENT ioctl() */
1815 static int snd_seq_ioctl_set_queue_client(struct snd_seq_client
*client
,
1819 struct snd_seq_queue_client info
;
1821 if (copy_from_user(&info
, arg
, sizeof(info
)))
1824 if (info
.used
>= 0) {
1825 err
= snd_seq_queue_use(info
.queue
, client
->number
, info
.used
);
1830 return snd_seq_ioctl_get_queue_client(client
, arg
);
1834 /* GET_CLIENT_POOL ioctl() */
1835 static int snd_seq_ioctl_get_client_pool(struct snd_seq_client
*client
,
1838 struct snd_seq_client_pool info
;
1839 struct snd_seq_client
*cptr
;
1841 if (copy_from_user(&info
, arg
, sizeof(info
)))
1844 cptr
= snd_seq_client_use_ptr(info
.client
);
1847 memset(&info
, 0, sizeof(info
));
1848 info
.output_pool
= cptr
->pool
->size
;
1849 info
.output_room
= cptr
->pool
->room
;
1850 info
.output_free
= info
.output_pool
;
1852 info
.output_free
= snd_seq_unused_cells(cptr
->pool
);
1853 if (cptr
->type
== USER_CLIENT
) {
1854 info
.input_pool
= cptr
->data
.user
.fifo_pool_size
;
1855 info
.input_free
= info
.input_pool
;
1856 if (cptr
->data
.user
.fifo
)
1857 info
.input_free
= snd_seq_unused_cells(cptr
->data
.user
.fifo
->pool
);
1859 info
.input_pool
= 0;
1860 info
.input_free
= 0;
1862 snd_seq_client_unlock(cptr
);
1864 if (copy_to_user(arg
, &info
, sizeof(info
)))
1869 /* SET_CLIENT_POOL ioctl() */
1870 static int snd_seq_ioctl_set_client_pool(struct snd_seq_client
*client
,
1873 struct snd_seq_client_pool info
;
1876 if (copy_from_user(&info
, arg
, sizeof(info
)))
1879 if (client
->number
!= info
.client
)
1880 return -EINVAL
; /* can't change other clients */
1882 if (info
.output_pool
>= 1 && info
.output_pool
<= SNDRV_SEQ_MAX_EVENTS
&&
1883 (! snd_seq_write_pool_allocated(client
) ||
1884 info
.output_pool
!= client
->pool
->size
)) {
1885 if (snd_seq_write_pool_allocated(client
)) {
1886 /* remove all existing cells */
1887 snd_seq_queue_client_leave_cells(client
->number
);
1888 snd_seq_pool_done(client
->pool
);
1890 client
->pool
->size
= info
.output_pool
;
1891 rc
= snd_seq_pool_init(client
->pool
);
1895 if (client
->type
== USER_CLIENT
&& client
->data
.user
.fifo
!= NULL
&&
1896 info
.input_pool
>= 1 &&
1897 info
.input_pool
<= SNDRV_SEQ_MAX_CLIENT_EVENTS
&&
1898 info
.input_pool
!= client
->data
.user
.fifo_pool_size
) {
1899 /* change pool size */
1900 rc
= snd_seq_fifo_resize(client
->data
.user
.fifo
, info
.input_pool
);
1903 client
->data
.user
.fifo_pool_size
= info
.input_pool
;
1905 if (info
.output_room
>= 1 &&
1906 info
.output_room
<= client
->pool
->size
) {
1907 client
->pool
->room
= info
.output_room
;
1910 return snd_seq_ioctl_get_client_pool(client
, arg
);
1914 /* REMOVE_EVENTS ioctl() */
1915 static int snd_seq_ioctl_remove_events(struct snd_seq_client
*client
,
1918 struct snd_seq_remove_events info
;
1920 if (copy_from_user(&info
, arg
, sizeof(info
)))
1924 * Input mostly not implemented XXX.
1926 if (info
.remove_mode
& SNDRV_SEQ_REMOVE_INPUT
) {
1928 * No restrictions so for a user client we can clear
1931 if (client
->type
== USER_CLIENT
)
1932 snd_seq_fifo_clear(client
->data
.user
.fifo
);
1935 if (info
.remove_mode
& SNDRV_SEQ_REMOVE_OUTPUT
)
1936 snd_seq_queue_remove_cells(client
->number
, &info
);
1943 * get subscription info
1945 static int snd_seq_ioctl_get_subscription(struct snd_seq_client
*client
,
1949 struct snd_seq_client
*sender
= NULL
;
1950 struct snd_seq_client_port
*sport
= NULL
;
1951 struct snd_seq_port_subscribe subs
;
1952 struct snd_seq_subscribers
*p
;
1954 if (copy_from_user(&subs
, arg
, sizeof(subs
)))
1958 if ((sender
= snd_seq_client_use_ptr(subs
.sender
.client
)) == NULL
)
1960 if ((sport
= snd_seq_port_use_ptr(sender
, subs
.sender
.port
)) == NULL
)
1962 p
= snd_seq_port_get_subscription(&sport
->c_src
, &subs
.dest
);
1971 snd_seq_port_unlock(sport
);
1973 snd_seq_client_unlock(sender
);
1975 if (copy_to_user(arg
, &subs
, sizeof(subs
)))
1983 * get subscription info - check only its presence
1985 static int snd_seq_ioctl_query_subs(struct snd_seq_client
*client
,
1988 int result
= -ENXIO
;
1989 struct snd_seq_client
*cptr
= NULL
;
1990 struct snd_seq_client_port
*port
= NULL
;
1991 struct snd_seq_query_subs subs
;
1992 struct snd_seq_port_subs_info
*group
;
1993 struct list_head
*p
;
1996 if (copy_from_user(&subs
, arg
, sizeof(subs
)))
1999 if ((cptr
= snd_seq_client_use_ptr(subs
.root
.client
)) == NULL
)
2001 if ((port
= snd_seq_port_use_ptr(cptr
, subs
.root
.port
)) == NULL
)
2004 switch (subs
.type
) {
2005 case SNDRV_SEQ_QUERY_SUBS_READ
:
2006 group
= &port
->c_src
;
2008 case SNDRV_SEQ_QUERY_SUBS_WRITE
:
2009 group
= &port
->c_dest
;
2015 down_read(&group
->list_mutex
);
2016 /* search for the subscriber */
2017 subs
.num_subs
= group
->count
;
2020 list_for_each(p
, &group
->list_head
) {
2021 if (i
++ == subs
.index
) {
2023 struct snd_seq_subscribers
*s
;
2024 if (subs
.type
== SNDRV_SEQ_QUERY_SUBS_READ
) {
2025 s
= list_entry(p
, struct snd_seq_subscribers
, src_list
);
2026 subs
.addr
= s
->info
.dest
;
2028 s
= list_entry(p
, struct snd_seq_subscribers
, dest_list
);
2029 subs
.addr
= s
->info
.sender
;
2031 subs
.flags
= s
->info
.flags
;
2032 subs
.queue
= s
->info
.queue
;
2037 up_read(&group
->list_mutex
);
2041 snd_seq_port_unlock(port
);
2043 snd_seq_client_unlock(cptr
);
2045 if (copy_to_user(arg
, &subs
, sizeof(subs
)))
2055 static int snd_seq_ioctl_query_next_client(struct snd_seq_client
*client
,
2058 struct snd_seq_client
*cptr
= NULL
;
2059 struct snd_seq_client_info info
;
2061 if (copy_from_user(&info
, arg
, sizeof(info
)))
2064 /* search for next client */
2066 if (info
.client
< 0)
2068 for (; info
.client
< SNDRV_SEQ_MAX_CLIENTS
; info
.client
++) {
2069 cptr
= snd_seq_client_use_ptr(info
.client
);
2076 get_client_info(cptr
, &info
);
2077 snd_seq_client_unlock(cptr
);
2079 if (copy_to_user(arg
, &info
, sizeof(info
)))
2087 static int snd_seq_ioctl_query_next_port(struct snd_seq_client
*client
,
2090 struct snd_seq_client
*cptr
;
2091 struct snd_seq_client_port
*port
= NULL
;
2092 struct snd_seq_port_info info
;
2094 if (copy_from_user(&info
, arg
, sizeof(info
)))
2096 cptr
= snd_seq_client_use_ptr(info
.addr
.client
);
2100 /* search for next port */
2102 port
= snd_seq_port_query_nearest(cptr
, &info
);
2104 snd_seq_client_unlock(cptr
);
2109 info
.addr
= port
->addr
;
2110 snd_seq_get_port_info(port
, &info
);
2111 snd_seq_port_unlock(port
);
2112 snd_seq_client_unlock(cptr
);
2114 if (copy_to_user(arg
, &info
, sizeof(info
)))
2119 /* -------------------------------------------------------- */
2121 static struct seq_ioctl_table
{
2123 int (*func
)(struct snd_seq_client
*client
, void __user
* arg
);
2124 } ioctl_tables
[] = {
2125 { SNDRV_SEQ_IOCTL_SYSTEM_INFO
, snd_seq_ioctl_system_info
},
2126 { SNDRV_SEQ_IOCTL_RUNNING_MODE
, snd_seq_ioctl_running_mode
},
2127 { SNDRV_SEQ_IOCTL_GET_CLIENT_INFO
, snd_seq_ioctl_get_client_info
},
2128 { SNDRV_SEQ_IOCTL_SET_CLIENT_INFO
, snd_seq_ioctl_set_client_info
},
2129 { SNDRV_SEQ_IOCTL_CREATE_PORT
, snd_seq_ioctl_create_port
},
2130 { SNDRV_SEQ_IOCTL_DELETE_PORT
, snd_seq_ioctl_delete_port
},
2131 { SNDRV_SEQ_IOCTL_GET_PORT_INFO
, snd_seq_ioctl_get_port_info
},
2132 { SNDRV_SEQ_IOCTL_SET_PORT_INFO
, snd_seq_ioctl_set_port_info
},
2133 { SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT
, snd_seq_ioctl_subscribe_port
},
2134 { SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT
, snd_seq_ioctl_unsubscribe_port
},
2135 { SNDRV_SEQ_IOCTL_CREATE_QUEUE
, snd_seq_ioctl_create_queue
},
2136 { SNDRV_SEQ_IOCTL_DELETE_QUEUE
, snd_seq_ioctl_delete_queue
},
2137 { SNDRV_SEQ_IOCTL_GET_QUEUE_INFO
, snd_seq_ioctl_get_queue_info
},
2138 { SNDRV_SEQ_IOCTL_SET_QUEUE_INFO
, snd_seq_ioctl_set_queue_info
},
2139 { SNDRV_SEQ_IOCTL_GET_NAMED_QUEUE
, snd_seq_ioctl_get_named_queue
},
2140 { SNDRV_SEQ_IOCTL_GET_QUEUE_STATUS
, snd_seq_ioctl_get_queue_status
},
2141 { SNDRV_SEQ_IOCTL_GET_QUEUE_TEMPO
, snd_seq_ioctl_get_queue_tempo
},
2142 { SNDRV_SEQ_IOCTL_SET_QUEUE_TEMPO
, snd_seq_ioctl_set_queue_tempo
},
2143 { SNDRV_SEQ_IOCTL_GET_QUEUE_TIMER
, snd_seq_ioctl_get_queue_timer
},
2144 { SNDRV_SEQ_IOCTL_SET_QUEUE_TIMER
, snd_seq_ioctl_set_queue_timer
},
2145 { SNDRV_SEQ_IOCTL_GET_QUEUE_CLIENT
, snd_seq_ioctl_get_queue_client
},
2146 { SNDRV_SEQ_IOCTL_SET_QUEUE_CLIENT
, snd_seq_ioctl_set_queue_client
},
2147 { SNDRV_SEQ_IOCTL_GET_CLIENT_POOL
, snd_seq_ioctl_get_client_pool
},
2148 { SNDRV_SEQ_IOCTL_SET_CLIENT_POOL
, snd_seq_ioctl_set_client_pool
},
2149 { SNDRV_SEQ_IOCTL_GET_SUBSCRIPTION
, snd_seq_ioctl_get_subscription
},
2150 { SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT
, snd_seq_ioctl_query_next_client
},
2151 { SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT
, snd_seq_ioctl_query_next_port
},
2152 { SNDRV_SEQ_IOCTL_REMOVE_EVENTS
, snd_seq_ioctl_remove_events
},
2153 { SNDRV_SEQ_IOCTL_QUERY_SUBS
, snd_seq_ioctl_query_subs
},
2157 static int snd_seq_do_ioctl(struct snd_seq_client
*client
, unsigned int cmd
,
2160 struct seq_ioctl_table
*p
;
2163 case SNDRV_SEQ_IOCTL_PVERSION
:
2164 /* return sequencer version number */
2165 return put_user(SNDRV_SEQ_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2166 case SNDRV_SEQ_IOCTL_CLIENT_ID
:
2167 /* return the id of this client */
2168 return put_user(client
->number
, (int __user
*)arg
) ? -EFAULT
: 0;
2173 for (p
= ioctl_tables
; p
->cmd
; p
++) {
2175 return p
->func(client
, arg
);
2177 snd_printd("seq unknown ioctl() 0x%x (type='%c', number=0x%2x)\n",
2178 cmd
, _IOC_TYPE(cmd
), _IOC_NR(cmd
));
2183 static long snd_seq_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2185 struct snd_seq_client
*client
= file
->private_data
;
2187 snd_assert(client
!= NULL
, return -ENXIO
);
2189 return snd_seq_do_ioctl(client
, cmd
, (void __user
*) arg
);
2192 #ifdef CONFIG_COMPAT
2193 #include "seq_compat.c"
2195 #define snd_seq_ioctl_compat NULL
2198 /* -------------------------------------------------------- */
2201 /* exported to kernel modules */
2202 int snd_seq_create_kernel_client(struct snd_card
*card
, int client_index
,
2203 struct snd_seq_client_callback
*callback
)
2205 struct snd_seq_client
*client
;
2207 snd_assert(! in_interrupt(), return -EBUSY
);
2209 if (callback
== NULL
)
2211 if (card
&& client_index
> 3)
2213 if (card
== NULL
&& client_index
> 63)
2216 client_index
+= 64 + (card
->number
<< 2);
2218 if (down_interruptible(®ister_mutex
))
2219 return -ERESTARTSYS
;
2220 /* empty write queue as default */
2221 client
= seq_create_client1(client_index
, 0);
2222 if (client
== NULL
) {
2223 up(®ister_mutex
);
2224 return -EBUSY
; /* failure code */
2226 usage_alloc(&client_usage
, 1);
2228 client
->accept_input
= callback
->allow_output
;
2229 client
->accept_output
= callback
->allow_input
;
2231 /* fill client data */
2232 client
->data
.kernel
.card
= card
;
2233 client
->data
.kernel
.private_data
= callback
->private_data
;
2234 sprintf(client
->name
, "Client-%d", client
->number
);
2236 client
->type
= KERNEL_CLIENT
;
2237 up(®ister_mutex
);
2239 /* make others aware this new client */
2240 snd_seq_system_client_ev_client_start(client
->number
);
2242 /* return client number to caller */
2243 return client
->number
;
2246 /* exported to kernel modules */
2247 int snd_seq_delete_kernel_client(int client
)
2249 struct snd_seq_client
*ptr
;
2251 snd_assert(! in_interrupt(), return -EBUSY
);
2253 ptr
= clientptr(client
);
2257 seq_free_client(ptr
);
2263 /* skeleton to enqueue event, called from snd_seq_kernel_client_enqueue
2264 * and snd_seq_kernel_client_enqueue_blocking
2266 static int kernel_client_enqueue(int client
, struct snd_seq_event
*ev
,
2267 struct file
*file
, int blocking
,
2268 int atomic
, int hop
)
2270 struct snd_seq_client
*cptr
;
2273 snd_assert(ev
!= NULL
, return -EINVAL
);
2275 if (ev
->type
== SNDRV_SEQ_EVENT_NONE
)
2276 return 0; /* ignore this */
2277 if (ev
->type
== SNDRV_SEQ_EVENT_KERNEL_ERROR
)
2278 return -EINVAL
; /* quoted events can't be enqueued */
2280 /* fill in client number */
2281 ev
->source
.client
= client
;
2283 if (check_event_type_and_length(ev
))
2286 cptr
= snd_seq_client_use_ptr(client
);
2290 if (! cptr
->accept_output
)
2293 result
= snd_seq_client_enqueue_event(cptr
, ev
, file
, blocking
, atomic
, hop
);
2295 snd_seq_client_unlock(cptr
);
2300 * exported, called by kernel clients to enqueue events (w/o blocking)
2302 * RETURN VALUE: zero if succeed, negative if error
2304 int snd_seq_kernel_client_enqueue(int client
, struct snd_seq_event
* ev
,
2305 int atomic
, int hop
)
2307 return kernel_client_enqueue(client
, ev
, NULL
, 0, atomic
, hop
);
2311 * exported, called by kernel clients to enqueue events (with blocking)
2313 * RETURN VALUE: zero if succeed, negative if error
2315 int snd_seq_kernel_client_enqueue_blocking(int client
, struct snd_seq_event
* ev
,
2317 int atomic
, int hop
)
2319 return kernel_client_enqueue(client
, ev
, file
, 1, atomic
, hop
);
2324 * exported, called by kernel clients to dispatch events directly to other
2325 * clients, bypassing the queues. Event time-stamp will be updated.
2327 * RETURN VALUE: negative = delivery failed,
2328 * zero, or positive: the number of delivered events
2330 int snd_seq_kernel_client_dispatch(int client
, struct snd_seq_event
* ev
,
2331 int atomic
, int hop
)
2333 struct snd_seq_client
*cptr
;
2336 snd_assert(ev
!= NULL
, return -EINVAL
);
2338 /* fill in client number */
2339 ev
->queue
= SNDRV_SEQ_QUEUE_DIRECT
;
2340 ev
->source
.client
= client
;
2342 if (check_event_type_and_length(ev
))
2345 cptr
= snd_seq_client_use_ptr(client
);
2349 if (!cptr
->accept_output
)
2352 result
= snd_seq_deliver_event(cptr
, ev
, atomic
, hop
);
2354 snd_seq_client_unlock(cptr
);
2360 * exported, called by kernel clients to perform same functions as with
2363 int snd_seq_kernel_client_ctl(int clientid
, unsigned int cmd
, void *arg
)
2365 struct snd_seq_client
*client
;
2369 client
= clientptr(clientid
);
2372 fs
= snd_enter_user();
2373 result
= snd_seq_do_ioctl(client
, cmd
, (void __user
*)arg
);
2379 /* exported (for OSS emulator) */
2380 int snd_seq_kernel_client_write_poll(int clientid
, struct file
*file
, poll_table
*wait
)
2382 struct snd_seq_client
*client
;
2384 client
= clientptr(clientid
);
2388 if (! snd_seq_write_pool_allocated(client
))
2390 if (snd_seq_pool_poll_wait(client
->pool
, file
, wait
))
2395 /*---------------------------------------------------------------------------*/
2400 static void snd_seq_info_dump_subscribers(struct snd_info_buffer
*buffer
,
2401 struct snd_seq_port_subs_info
*group
,
2402 int is_src
, char *msg
)
2404 struct list_head
*p
;
2405 struct snd_seq_subscribers
*s
;
2408 down_read(&group
->list_mutex
);
2409 if (list_empty(&group
->list_head
)) {
2410 up_read(&group
->list_mutex
);
2413 snd_iprintf(buffer
, msg
);
2414 list_for_each(p
, &group
->list_head
) {
2416 s
= list_entry(p
, struct snd_seq_subscribers
, src_list
);
2418 s
= list_entry(p
, struct snd_seq_subscribers
, dest_list
);
2420 snd_iprintf(buffer
, ", ");
2421 snd_iprintf(buffer
, "%d:%d",
2422 is_src
? s
->info
.dest
.client
: s
->info
.sender
.client
,
2423 is_src
? s
->info
.dest
.port
: s
->info
.sender
.port
);
2424 if (s
->info
.flags
& SNDRV_SEQ_PORT_SUBS_TIMESTAMP
)
2425 snd_iprintf(buffer
, "[%c:%d]", ((s
->info
.flags
& SNDRV_SEQ_PORT_SUBS_TIME_REAL
) ? 'r' : 't'), s
->info
.queue
);
2426 if (group
->exclusive
)
2427 snd_iprintf(buffer
, "[ex]");
2429 up_read(&group
->list_mutex
);
2430 snd_iprintf(buffer
, "\n");
2433 #define FLAG_PERM_RD(perm) ((perm) & SNDRV_SEQ_PORT_CAP_READ ? ((perm) & SNDRV_SEQ_PORT_CAP_SUBS_READ ? 'R' : 'r') : '-')
2434 #define FLAG_PERM_WR(perm) ((perm) & SNDRV_SEQ_PORT_CAP_WRITE ? ((perm) & SNDRV_SEQ_PORT_CAP_SUBS_WRITE ? 'W' : 'w') : '-')
2435 #define FLAG_PERM_EX(perm) ((perm) & SNDRV_SEQ_PORT_CAP_NO_EXPORT ? '-' : 'e')
2437 #define FLAG_PERM_DUPLEX(perm) ((perm) & SNDRV_SEQ_PORT_CAP_DUPLEX ? 'X' : '-')
2439 static void snd_seq_info_dump_ports(struct snd_info_buffer
*buffer
,
2440 struct snd_seq_client
*client
)
2442 struct list_head
*l
;
2444 down(&client
->ports_mutex
);
2445 list_for_each(l
, &client
->ports_list_head
) {
2446 struct snd_seq_client_port
*p
= list_entry(l
, struct snd_seq_client_port
, list
);
2447 snd_iprintf(buffer
, " Port %3d : \"%s\" (%c%c%c%c)\n",
2448 p
->addr
.port
, p
->name
,
2449 FLAG_PERM_RD(p
->capability
),
2450 FLAG_PERM_WR(p
->capability
),
2451 FLAG_PERM_EX(p
->capability
),
2452 FLAG_PERM_DUPLEX(p
->capability
));
2453 snd_seq_info_dump_subscribers(buffer
, &p
->c_src
, 1, " Connecting To: ");
2454 snd_seq_info_dump_subscribers(buffer
, &p
->c_dest
, 0, " Connected From: ");
2456 up(&client
->ports_mutex
);
2460 void snd_seq_info_pool(struct snd_info_buffer
*buffer
,
2461 struct snd_seq_pool
*pool
, char *space
);
2463 /* exported to seq_info.c */
2464 void snd_seq_info_clients_read(struct snd_info_entry
*entry
,
2465 struct snd_info_buffer
*buffer
)
2468 struct snd_seq_client
*client
;
2470 snd_iprintf(buffer
, "Client info\n");
2471 snd_iprintf(buffer
, " cur clients : %d\n", client_usage
.cur
);
2472 snd_iprintf(buffer
, " peak clients : %d\n", client_usage
.peak
);
2473 snd_iprintf(buffer
, " max clients : %d\n", SNDRV_SEQ_MAX_CLIENTS
);
2474 snd_iprintf(buffer
, "\n");
2476 /* list the client table */
2477 for (c
= 0; c
< SNDRV_SEQ_MAX_CLIENTS
; c
++) {
2478 client
= snd_seq_client_use_ptr(c
);
2481 if (client
->type
== NO_CLIENT
) {
2482 snd_seq_client_unlock(client
);
2486 snd_iprintf(buffer
, "Client %3d : \"%s\" [%s]\n",
2488 client
->type
== USER_CLIENT
? "User" : "Kernel");
2489 snd_seq_info_dump_ports(buffer
, client
);
2490 if (snd_seq_write_pool_allocated(client
)) {
2491 snd_iprintf(buffer
, " Output pool :\n");
2492 snd_seq_info_pool(buffer
, client
->pool
, " ");
2494 if (client
->type
== USER_CLIENT
&& client
->data
.user
.fifo
&&
2495 client
->data
.user
.fifo
->pool
) {
2496 snd_iprintf(buffer
, " Input pool :\n");
2497 snd_seq_info_pool(buffer
, client
->data
.user
.fifo
->pool
, " ");
2499 snd_seq_client_unlock(client
);
2504 /*---------------------------------------------------------------------------*/
2511 static struct file_operations snd_seq_f_ops
=
2513 .owner
= THIS_MODULE
,
2514 .read
= snd_seq_read
,
2515 .write
= snd_seq_write
,
2516 .open
= snd_seq_open
,
2517 .release
= snd_seq_release
,
2518 .poll
= snd_seq_poll
,
2519 .unlocked_ioctl
= snd_seq_ioctl
,
2520 .compat_ioctl
= snd_seq_ioctl_compat
,
2524 * register sequencer device
2526 int __init
snd_sequencer_device_init(void)
2530 if (down_interruptible(®ister_mutex
))
2531 return -ERESTARTSYS
;
2533 if ((err
= snd_register_device(SNDRV_DEVICE_TYPE_SEQUENCER
, NULL
, 0,
2534 &snd_seq_f_ops
, NULL
, "seq")) < 0) {
2535 up(®ister_mutex
);
2539 up(®ister_mutex
);
2547 * unregister sequencer device
2549 void __exit
snd_sequencer_device_done(void)
2551 snd_unregister_device(SNDRV_DEVICE_TYPE_SEQUENCER
, NULL
, 0);