dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / sound / core / timer.c
blobef850a99d64a81b993bb0680158060ed8b2dcc48
1 /*
2 * Timers abstract layer
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
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.
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.
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
22 #include <linux/delay.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/time.h>
26 #include <linux/mutex.h>
27 #include <linux/device.h>
28 #include <linux/module.h>
29 #include <linux/string.h>
30 #include <sound/core.h>
31 #include <sound/timer.h>
32 #include <sound/control.h>
33 #include <sound/info.h>
34 #include <sound/minors.h>
35 #include <sound/initval.h>
36 #include <linux/kmod.h>
38 #if IS_ENABLED(CONFIG_SND_HRTIMER)
39 #define DEFAULT_TIMER_LIMIT 4
40 #elif IS_ENABLED(CONFIG_SND_RTCTIMER)
41 #define DEFAULT_TIMER_LIMIT 2
42 #else
43 #define DEFAULT_TIMER_LIMIT 1
44 #endif
46 static int timer_limit = DEFAULT_TIMER_LIMIT;
47 static int timer_tstamp_monotonic = 1;
48 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>");
49 MODULE_DESCRIPTION("ALSA timer interface");
50 MODULE_LICENSE("GPL");
51 module_param(timer_limit, int, 0444);
52 MODULE_PARM_DESC(timer_limit, "Maximum global timers in system.");
53 module_param(timer_tstamp_monotonic, int, 0444);
54 MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default).");
56 MODULE_ALIAS_CHARDEV(CONFIG_SND_MAJOR, SNDRV_MINOR_TIMER);
57 MODULE_ALIAS("devname:snd/timer");
59 struct snd_timer_user {
60 struct snd_timer_instance *timeri;
61 int tread; /* enhanced read with timestamps and events */
62 unsigned long ticks;
63 unsigned long overrun;
64 int qhead;
65 int qtail;
66 int qused;
67 int queue_size;
68 bool disconnected;
69 struct snd_timer_read *queue;
70 struct snd_timer_tread *tqueue;
71 spinlock_t qlock;
72 unsigned long last_resolution;
73 unsigned int filter;
74 struct timespec tstamp; /* trigger tstamp */
75 wait_queue_head_t qchange_sleep;
76 struct fasync_struct *fasync;
77 struct mutex ioctl_lock;
80 /* list of timers */
81 static LIST_HEAD(snd_timer_list);
83 /* list of slave instances */
84 static LIST_HEAD(snd_timer_slave_list);
86 /* lock for slave active lists */
87 static DEFINE_SPINLOCK(slave_active_lock);
89 static DEFINE_MUTEX(register_mutex);
91 static int snd_timer_free(struct snd_timer *timer);
92 static int snd_timer_dev_free(struct snd_device *device);
93 static int snd_timer_dev_register(struct snd_device *device);
94 static int snd_timer_dev_disconnect(struct snd_device *device);
96 static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left);
99 * create a timer instance with the given owner string.
100 * when timer is not NULL, increments the module counter
102 static struct snd_timer_instance *snd_timer_instance_new(char *owner,
103 struct snd_timer *timer)
105 struct snd_timer_instance *timeri;
106 timeri = kzalloc(sizeof(*timeri), GFP_KERNEL);
107 if (timeri == NULL)
108 return NULL;
109 timeri->owner = kstrdup(owner, GFP_KERNEL);
110 if (! timeri->owner) {
111 kfree(timeri);
112 return NULL;
114 INIT_LIST_HEAD(&timeri->open_list);
115 INIT_LIST_HEAD(&timeri->active_list);
116 INIT_LIST_HEAD(&timeri->ack_list);
117 INIT_LIST_HEAD(&timeri->slave_list_head);
118 INIT_LIST_HEAD(&timeri->slave_active_head);
120 timeri->timer = timer;
121 if (timer && !try_module_get(timer->module)) {
122 kfree(timeri->owner);
123 kfree(timeri);
124 return NULL;
127 return timeri;
131 * find a timer instance from the given timer id
133 static struct snd_timer *snd_timer_find(struct snd_timer_id *tid)
135 struct snd_timer *timer = NULL;
137 list_for_each_entry(timer, &snd_timer_list, device_list) {
138 if (timer->tmr_class != tid->dev_class)
139 continue;
140 if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD ||
141 timer->tmr_class == SNDRV_TIMER_CLASS_PCM) &&
142 (timer->card == NULL ||
143 timer->card->number != tid->card))
144 continue;
145 if (timer->tmr_device != tid->device)
146 continue;
147 if (timer->tmr_subdevice != tid->subdevice)
148 continue;
149 return timer;
151 return NULL;
154 #ifdef CONFIG_MODULES
156 static void snd_timer_request(struct snd_timer_id *tid)
158 switch (tid->dev_class) {
159 case SNDRV_TIMER_CLASS_GLOBAL:
160 if (tid->device < timer_limit)
161 request_module("snd-timer-%i", tid->device);
162 break;
163 case SNDRV_TIMER_CLASS_CARD:
164 case SNDRV_TIMER_CLASS_PCM:
165 if (tid->card < snd_ecards_limit)
166 request_module("snd-card-%i", tid->card);
167 break;
168 default:
169 break;
173 #endif
176 * look for a master instance matching with the slave id of the given slave.
177 * when found, relink the open_link of the slave.
179 * call this with register_mutex down.
181 static void snd_timer_check_slave(struct snd_timer_instance *slave)
183 struct snd_timer *timer;
184 struct snd_timer_instance *master;
186 /* FIXME: it's really dumb to look up all entries.. */
187 list_for_each_entry(timer, &snd_timer_list, device_list) {
188 list_for_each_entry(master, &timer->open_list_head, open_list) {
189 if (slave->slave_class == master->slave_class &&
190 slave->slave_id == master->slave_id) {
191 list_move_tail(&slave->open_list,
192 &master->slave_list_head);
193 spin_lock_irq(&slave_active_lock);
194 slave->master = master;
195 slave->timer = master->timer;
196 spin_unlock_irq(&slave_active_lock);
197 return;
204 * look for slave instances matching with the slave id of the given master.
205 * when found, relink the open_link of slaves.
207 * call this with register_mutex down.
209 static void snd_timer_check_master(struct snd_timer_instance *master)
211 struct snd_timer_instance *slave, *tmp;
213 /* check all pending slaves */
214 list_for_each_entry_safe(slave, tmp, &snd_timer_slave_list, open_list) {
215 if (slave->slave_class == master->slave_class &&
216 slave->slave_id == master->slave_id) {
217 list_move_tail(&slave->open_list, &master->slave_list_head);
218 spin_lock_irq(&slave_active_lock);
219 spin_lock(&master->timer->lock);
220 slave->master = master;
221 slave->timer = master->timer;
222 if (slave->flags & SNDRV_TIMER_IFLG_RUNNING)
223 list_add_tail(&slave->active_list,
224 &master->slave_active_head);
225 spin_unlock(&master->timer->lock);
226 spin_unlock_irq(&slave_active_lock);
232 * open a timer instance
233 * when opening a master, the slave id must be here given.
235 int snd_timer_open(struct snd_timer_instance **ti,
236 char *owner, struct snd_timer_id *tid,
237 unsigned int slave_id)
239 struct snd_timer *timer;
240 struct snd_timer_instance *timeri = NULL;
242 if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) {
243 /* open a slave instance */
244 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
245 tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) {
246 pr_debug("ALSA: timer: invalid slave class %i\n",
247 tid->dev_sclass);
248 return -EINVAL;
250 mutex_lock(&register_mutex);
251 timeri = snd_timer_instance_new(owner, NULL);
252 if (!timeri) {
253 mutex_unlock(&register_mutex);
254 return -ENOMEM;
256 timeri->slave_class = tid->dev_sclass;
257 timeri->slave_id = tid->device;
258 timeri->flags |= SNDRV_TIMER_IFLG_SLAVE;
259 list_add_tail(&timeri->open_list, &snd_timer_slave_list);
260 snd_timer_check_slave(timeri);
261 mutex_unlock(&register_mutex);
262 *ti = timeri;
263 return 0;
266 /* open a master instance */
267 mutex_lock(&register_mutex);
268 timer = snd_timer_find(tid);
269 #ifdef CONFIG_MODULES
270 if (!timer) {
271 mutex_unlock(&register_mutex);
272 snd_timer_request(tid);
273 mutex_lock(&register_mutex);
274 timer = snd_timer_find(tid);
276 #endif
277 if (!timer) {
278 mutex_unlock(&register_mutex);
279 return -ENODEV;
281 if (!list_empty(&timer->open_list_head)) {
282 timeri = list_entry(timer->open_list_head.next,
283 struct snd_timer_instance, open_list);
284 if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
285 mutex_unlock(&register_mutex);
286 return -EBUSY;
289 timeri = snd_timer_instance_new(owner, timer);
290 if (!timeri) {
291 mutex_unlock(&register_mutex);
292 return -ENOMEM;
294 /* take a card refcount for safe disconnection */
295 if (timer->card)
296 get_device(&timer->card->card_dev);
297 timeri->slave_class = tid->dev_sclass;
298 timeri->slave_id = slave_id;
300 if (list_empty(&timer->open_list_head) && timer->hw.open) {
301 int err = timer->hw.open(timer);
302 if (err) {
303 kfree(timeri->owner);
304 kfree(timeri);
306 if (timer->card)
307 put_device(&timer->card->card_dev);
308 module_put(timer->module);
309 mutex_unlock(&register_mutex);
310 return err;
314 list_add_tail(&timeri->open_list, &timer->open_list_head);
315 snd_timer_check_master(timeri);
316 mutex_unlock(&register_mutex);
317 *ti = timeri;
318 return 0;
322 * close a timer instance
324 int snd_timer_close(struct snd_timer_instance *timeri)
326 struct snd_timer *timer = NULL;
327 struct snd_timer_instance *slave, *tmp;
329 if (snd_BUG_ON(!timeri))
330 return -ENXIO;
332 /* force to stop the timer */
333 snd_timer_stop(timeri);
335 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
336 /* wait, until the active callback is finished */
337 spin_lock_irq(&slave_active_lock);
338 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) {
339 spin_unlock_irq(&slave_active_lock);
340 udelay(10);
341 spin_lock_irq(&slave_active_lock);
343 spin_unlock_irq(&slave_active_lock);
344 mutex_lock(&register_mutex);
345 list_del(&timeri->open_list);
346 mutex_unlock(&register_mutex);
347 } else {
348 timer = timeri->timer;
349 if (snd_BUG_ON(!timer))
350 goto out;
351 /* wait, until the active callback is finished */
352 spin_lock_irq(&timer->lock);
353 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) {
354 spin_unlock_irq(&timer->lock);
355 udelay(10);
356 spin_lock_irq(&timer->lock);
358 spin_unlock_irq(&timer->lock);
359 mutex_lock(&register_mutex);
360 list_del(&timeri->open_list);
361 if (list_empty(&timer->open_list_head) &&
362 timer->hw.close)
363 timer->hw.close(timer);
364 /* remove slave links */
365 spin_lock_irq(&slave_active_lock);
366 spin_lock(&timer->lock);
367 list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head,
368 open_list) {
369 list_move_tail(&slave->open_list, &snd_timer_slave_list);
370 slave->master = NULL;
371 slave->timer = NULL;
372 list_del_init(&slave->ack_list);
373 list_del_init(&slave->active_list);
375 spin_unlock(&timer->lock);
376 spin_unlock_irq(&slave_active_lock);
377 /* release a card refcount for safe disconnection */
378 if (timer->card)
379 put_device(&timer->card->card_dev);
380 mutex_unlock(&register_mutex);
382 out:
383 if (timeri->private_free)
384 timeri->private_free(timeri);
385 kfree(timeri->owner);
386 kfree(timeri);
387 if (timer)
388 module_put(timer->module);
389 return 0;
392 unsigned long snd_timer_resolution(struct snd_timer_instance *timeri)
394 struct snd_timer * timer;
396 if (timeri == NULL)
397 return 0;
398 if ((timer = timeri->timer) != NULL) {
399 if (timer->hw.c_resolution)
400 return timer->hw.c_resolution(timer);
401 return timer->hw.resolution;
403 return 0;
406 static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
408 struct snd_timer *timer;
409 unsigned long resolution = 0;
410 struct snd_timer_instance *ts;
411 struct timespec tstamp;
413 if (timer_tstamp_monotonic)
414 ktime_get_ts(&tstamp);
415 else
416 getnstimeofday(&tstamp);
417 if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START ||
418 event > SNDRV_TIMER_EVENT_PAUSE))
419 return;
420 if (event == SNDRV_TIMER_EVENT_START ||
421 event == SNDRV_TIMER_EVENT_CONTINUE)
422 resolution = snd_timer_resolution(ti);
423 if (ti->ccallback)
424 ti->ccallback(ti, event, &tstamp, resolution);
425 if (ti->flags & SNDRV_TIMER_IFLG_SLAVE)
426 return;
427 timer = ti->timer;
428 if (timer == NULL)
429 return;
430 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
431 return;
432 list_for_each_entry(ts, &ti->slave_active_head, active_list)
433 if (ts->ccallback)
434 ts->ccallback(ts, event + 100, &tstamp, resolution);
437 /* start/continue a master timer */
438 static int snd_timer_start1(struct snd_timer_instance *timeri,
439 bool start, unsigned long ticks)
441 struct snd_timer *timer;
442 int result;
443 unsigned long flags;
445 timer = timeri->timer;
446 if (!timer)
447 return -EINVAL;
449 spin_lock_irqsave(&timer->lock, flags);
450 if (timer->card && timer->card->shutdown) {
451 result = -ENODEV;
452 goto unlock;
454 if (timeri->flags & (SNDRV_TIMER_IFLG_RUNNING |
455 SNDRV_TIMER_IFLG_START)) {
456 result = -EBUSY;
457 goto unlock;
460 if (start)
461 timeri->ticks = timeri->cticks = ticks;
462 else if (!timeri->cticks)
463 timeri->cticks = 1;
464 timeri->pticks = 0;
466 list_move_tail(&timeri->active_list, &timer->active_list_head);
467 if (timer->running) {
468 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
469 goto __start_now;
470 timer->flags |= SNDRV_TIMER_FLG_RESCHED;
471 timeri->flags |= SNDRV_TIMER_IFLG_START;
472 result = 1; /* delayed start */
473 } else {
474 if (start)
475 timer->sticks = ticks;
476 timer->hw.start(timer);
477 __start_now:
478 timer->running++;
479 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
480 result = 0;
482 snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START :
483 SNDRV_TIMER_EVENT_CONTINUE);
484 unlock:
485 spin_unlock_irqrestore(&timer->lock, flags);
486 return result;
489 /* start/continue a slave timer */
490 static int snd_timer_start_slave(struct snd_timer_instance *timeri,
491 bool start)
493 unsigned long flags;
495 spin_lock_irqsave(&slave_active_lock, flags);
496 if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) {
497 spin_unlock_irqrestore(&slave_active_lock, flags);
498 return -EBUSY;
500 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
501 if (timeri->master && timeri->timer) {
502 spin_lock(&timeri->timer->lock);
503 list_add_tail(&timeri->active_list,
504 &timeri->master->slave_active_head);
505 snd_timer_notify1(timeri, start ? SNDRV_TIMER_EVENT_START :
506 SNDRV_TIMER_EVENT_CONTINUE);
507 spin_unlock(&timeri->timer->lock);
509 spin_unlock_irqrestore(&slave_active_lock, flags);
510 return 1; /* delayed start */
513 /* stop/pause a master timer */
514 static int snd_timer_stop1(struct snd_timer_instance *timeri, bool stop)
516 struct snd_timer *timer;
517 int result = 0;
518 unsigned long flags;
520 timer = timeri->timer;
521 if (!timer)
522 return -EINVAL;
523 spin_lock_irqsave(&timer->lock, flags);
524 if (!(timeri->flags & (SNDRV_TIMER_IFLG_RUNNING |
525 SNDRV_TIMER_IFLG_START))) {
526 result = -EBUSY;
527 goto unlock;
529 list_del_init(&timeri->ack_list);
530 list_del_init(&timeri->active_list);
531 if (timer->card && timer->card->shutdown)
532 goto unlock;
533 if (stop) {
534 timeri->cticks = timeri->ticks;
535 timeri->pticks = 0;
537 if ((timeri->flags & SNDRV_TIMER_IFLG_RUNNING) &&
538 !(--timer->running)) {
539 timer->hw.stop(timer);
540 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) {
541 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED;
542 snd_timer_reschedule(timer, 0);
543 if (timer->flags & SNDRV_TIMER_FLG_CHANGE) {
544 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE;
545 timer->hw.start(timer);
549 timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START);
550 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP :
551 SNDRV_TIMER_EVENT_PAUSE);
552 unlock:
553 spin_unlock_irqrestore(&timer->lock, flags);
554 return result;
557 /* stop/pause a slave timer */
558 static int snd_timer_stop_slave(struct snd_timer_instance *timeri, bool stop)
560 unsigned long flags;
562 spin_lock_irqsave(&slave_active_lock, flags);
563 if (!(timeri->flags & SNDRV_TIMER_IFLG_RUNNING)) {
564 spin_unlock_irqrestore(&slave_active_lock, flags);
565 return -EBUSY;
567 timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
568 if (timeri->timer) {
569 spin_lock(&timeri->timer->lock);
570 list_del_init(&timeri->ack_list);
571 list_del_init(&timeri->active_list);
572 snd_timer_notify1(timeri, stop ? SNDRV_TIMER_EVENT_STOP :
573 SNDRV_TIMER_EVENT_PAUSE);
574 spin_unlock(&timeri->timer->lock);
576 spin_unlock_irqrestore(&slave_active_lock, flags);
577 return 0;
581 * start the timer instance
583 int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks)
585 if (timeri == NULL || ticks < 1)
586 return -EINVAL;
587 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE)
588 return snd_timer_start_slave(timeri, true);
589 else
590 return snd_timer_start1(timeri, true, ticks);
594 * stop the timer instance.
596 * do not call this from the timer callback!
598 int snd_timer_stop(struct snd_timer_instance *timeri)
600 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE)
601 return snd_timer_stop_slave(timeri, true);
602 else
603 return snd_timer_stop1(timeri, true);
607 * start again.. the tick is kept.
609 int snd_timer_continue(struct snd_timer_instance *timeri)
611 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE)
612 return snd_timer_start_slave(timeri, false);
613 else
614 return snd_timer_start1(timeri, false, 0);
618 * pause.. remember the ticks left
620 int snd_timer_pause(struct snd_timer_instance * timeri)
622 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE)
623 return snd_timer_stop_slave(timeri, false);
624 else
625 return snd_timer_stop1(timeri, false);
629 * reschedule the timer
631 * start pending instances and check the scheduling ticks.
632 * when the scheduling ticks is changed set CHANGE flag to reprogram the timer.
634 static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left)
636 struct snd_timer_instance *ti;
637 unsigned long ticks = ~0UL;
639 list_for_each_entry(ti, &timer->active_list_head, active_list) {
640 if (ti->flags & SNDRV_TIMER_IFLG_START) {
641 ti->flags &= ~SNDRV_TIMER_IFLG_START;
642 ti->flags |= SNDRV_TIMER_IFLG_RUNNING;
643 timer->running++;
645 if (ti->flags & SNDRV_TIMER_IFLG_RUNNING) {
646 if (ticks > ti->cticks)
647 ticks = ti->cticks;
650 if (ticks == ~0UL) {
651 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED;
652 return;
654 if (ticks > timer->hw.ticks)
655 ticks = timer->hw.ticks;
656 if (ticks_left != ticks)
657 timer->flags |= SNDRV_TIMER_FLG_CHANGE;
658 timer->sticks = ticks;
662 * timer tasklet
665 static void snd_timer_tasklet(unsigned long arg)
667 struct snd_timer *timer = (struct snd_timer *) arg;
668 struct snd_timer_instance *ti;
669 struct list_head *p;
670 unsigned long resolution, ticks;
671 unsigned long flags;
673 if (timer->card && timer->card->shutdown)
674 return;
676 spin_lock_irqsave(&timer->lock, flags);
677 /* now process all callbacks */
678 while (!list_empty(&timer->sack_list_head)) {
679 p = timer->sack_list_head.next; /* get first item */
680 ti = list_entry(p, struct snd_timer_instance, ack_list);
682 /* remove from ack_list and make empty */
683 list_del_init(p);
685 ticks = ti->pticks;
686 ti->pticks = 0;
687 resolution = ti->resolution;
689 ti->flags |= SNDRV_TIMER_IFLG_CALLBACK;
690 spin_unlock(&timer->lock);
691 if (ti->callback)
692 ti->callback(ti, resolution, ticks);
693 spin_lock(&timer->lock);
694 ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK;
696 spin_unlock_irqrestore(&timer->lock, flags);
700 * timer interrupt
702 * ticks_left is usually equal to timer->sticks.
705 void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
707 struct snd_timer_instance *ti, *ts, *tmp;
708 unsigned long resolution, ticks;
709 struct list_head *p, *ack_list_head;
710 unsigned long flags;
711 int use_tasklet = 0;
713 if (timer == NULL)
714 return;
716 if (timer->card && timer->card->shutdown)
717 return;
719 spin_lock_irqsave(&timer->lock, flags);
721 /* remember the current resolution */
722 if (timer->hw.c_resolution)
723 resolution = timer->hw.c_resolution(timer);
724 else
725 resolution = timer->hw.resolution;
727 /* loop for all active instances
728 * Here we cannot use list_for_each_entry because the active_list of a
729 * processed instance is relinked to done_list_head before the callback
730 * is called.
732 list_for_each_entry_safe(ti, tmp, &timer->active_list_head,
733 active_list) {
734 if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING))
735 continue;
736 ti->pticks += ticks_left;
737 ti->resolution = resolution;
738 if (ti->cticks < ticks_left)
739 ti->cticks = 0;
740 else
741 ti->cticks -= ticks_left;
742 if (ti->cticks) /* not expired */
743 continue;
744 if (ti->flags & SNDRV_TIMER_IFLG_AUTO) {
745 ti->cticks = ti->ticks;
746 } else {
747 ti->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
748 --timer->running;
749 list_del_init(&ti->active_list);
751 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) ||
752 (ti->flags & SNDRV_TIMER_IFLG_FAST))
753 ack_list_head = &timer->ack_list_head;
754 else
755 ack_list_head = &timer->sack_list_head;
756 if (list_empty(&ti->ack_list))
757 list_add_tail(&ti->ack_list, ack_list_head);
758 list_for_each_entry(ts, &ti->slave_active_head, active_list) {
759 ts->pticks = ti->pticks;
760 ts->resolution = resolution;
761 if (list_empty(&ts->ack_list))
762 list_add_tail(&ts->ack_list, ack_list_head);
765 if (timer->flags & SNDRV_TIMER_FLG_RESCHED)
766 snd_timer_reschedule(timer, timer->sticks);
767 if (timer->running) {
768 if (timer->hw.flags & SNDRV_TIMER_HW_STOP) {
769 timer->hw.stop(timer);
770 timer->flags |= SNDRV_TIMER_FLG_CHANGE;
772 if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) ||
773 (timer->flags & SNDRV_TIMER_FLG_CHANGE)) {
774 /* restart timer */
775 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE;
776 timer->hw.start(timer);
778 } else {
779 timer->hw.stop(timer);
782 /* now process all fast callbacks */
783 while (!list_empty(&timer->ack_list_head)) {
784 p = timer->ack_list_head.next; /* get first item */
785 ti = list_entry(p, struct snd_timer_instance, ack_list);
787 /* remove from ack_list and make empty */
788 list_del_init(p);
790 ticks = ti->pticks;
791 ti->pticks = 0;
793 ti->flags |= SNDRV_TIMER_IFLG_CALLBACK;
794 spin_unlock(&timer->lock);
795 if (ti->callback)
796 ti->callback(ti, resolution, ticks);
797 spin_lock(&timer->lock);
798 ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK;
801 /* do we have any slow callbacks? */
802 use_tasklet = !list_empty(&timer->sack_list_head);
803 spin_unlock_irqrestore(&timer->lock, flags);
805 if (use_tasklet)
806 tasklet_schedule(&timer->task_queue);
813 int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
814 struct snd_timer **rtimer)
816 struct snd_timer *timer;
817 int err;
818 static struct snd_device_ops ops = {
819 .dev_free = snd_timer_dev_free,
820 .dev_register = snd_timer_dev_register,
821 .dev_disconnect = snd_timer_dev_disconnect,
824 if (snd_BUG_ON(!tid))
825 return -EINVAL;
826 if (rtimer)
827 *rtimer = NULL;
828 timer = kzalloc(sizeof(*timer), GFP_KERNEL);
829 if (!timer)
830 return -ENOMEM;
831 timer->tmr_class = tid->dev_class;
832 timer->card = card;
833 timer->tmr_device = tid->device;
834 timer->tmr_subdevice = tid->subdevice;
835 if (id)
836 strlcpy(timer->id, id, sizeof(timer->id));
837 timer->sticks = 1;
838 INIT_LIST_HEAD(&timer->device_list);
839 INIT_LIST_HEAD(&timer->open_list_head);
840 INIT_LIST_HEAD(&timer->active_list_head);
841 INIT_LIST_HEAD(&timer->ack_list_head);
842 INIT_LIST_HEAD(&timer->sack_list_head);
843 spin_lock_init(&timer->lock);
844 tasklet_init(&timer->task_queue, snd_timer_tasklet,
845 (unsigned long)timer);
846 if (card != NULL) {
847 timer->module = card->module;
848 err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops);
849 if (err < 0) {
850 snd_timer_free(timer);
851 return err;
854 if (rtimer)
855 *rtimer = timer;
856 return 0;
859 static int snd_timer_free(struct snd_timer *timer)
861 if (!timer)
862 return 0;
864 mutex_lock(&register_mutex);
865 if (! list_empty(&timer->open_list_head)) {
866 struct list_head *p, *n;
867 struct snd_timer_instance *ti;
868 pr_warn("ALSA: timer %p is busy?\n", timer);
869 list_for_each_safe(p, n, &timer->open_list_head) {
870 list_del_init(p);
871 ti = list_entry(p, struct snd_timer_instance, open_list);
872 ti->timer = NULL;
875 list_del(&timer->device_list);
876 mutex_unlock(&register_mutex);
878 if (timer->private_free)
879 timer->private_free(timer);
880 kfree(timer);
881 return 0;
884 static int snd_timer_dev_free(struct snd_device *device)
886 struct snd_timer *timer = device->device_data;
887 return snd_timer_free(timer);
890 static int snd_timer_dev_register(struct snd_device *dev)
892 struct snd_timer *timer = dev->device_data;
893 struct snd_timer *timer1;
895 if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop))
896 return -ENXIO;
897 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) &&
898 !timer->hw.resolution && timer->hw.c_resolution == NULL)
899 return -EINVAL;
901 mutex_lock(&register_mutex);
902 list_for_each_entry(timer1, &snd_timer_list, device_list) {
903 if (timer1->tmr_class > timer->tmr_class)
904 break;
905 if (timer1->tmr_class < timer->tmr_class)
906 continue;
907 if (timer1->card && timer->card) {
908 if (timer1->card->number > timer->card->number)
909 break;
910 if (timer1->card->number < timer->card->number)
911 continue;
913 if (timer1->tmr_device > timer->tmr_device)
914 break;
915 if (timer1->tmr_device < timer->tmr_device)
916 continue;
917 if (timer1->tmr_subdevice > timer->tmr_subdevice)
918 break;
919 if (timer1->tmr_subdevice < timer->tmr_subdevice)
920 continue;
921 /* conflicts.. */
922 mutex_unlock(&register_mutex);
923 return -EBUSY;
925 list_add_tail(&timer->device_list, &timer1->device_list);
926 mutex_unlock(&register_mutex);
927 return 0;
930 /* just for reference in snd_timer_dev_disconnect() below */
931 static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
932 int event, struct timespec *tstamp,
933 unsigned long resolution);
935 static int snd_timer_dev_disconnect(struct snd_device *device)
937 struct snd_timer *timer = device->device_data;
938 struct snd_timer_instance *ti;
940 mutex_lock(&register_mutex);
941 list_del_init(&timer->device_list);
942 /* wake up pending sleepers */
943 list_for_each_entry(ti, &timer->open_list_head, open_list) {
944 /* FIXME: better to have a ti.disconnect() op */
945 if (ti->ccallback == snd_timer_user_ccallback) {
946 struct snd_timer_user *tu = ti->callback_data;
948 tu->disconnected = true;
949 wake_up(&tu->qchange_sleep);
952 mutex_unlock(&register_mutex);
953 return 0;
956 void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp)
958 unsigned long flags;
959 unsigned long resolution = 0;
960 struct snd_timer_instance *ti, *ts;
962 if (timer->card && timer->card->shutdown)
963 return;
964 if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE))
965 return;
966 if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_MSTART ||
967 event > SNDRV_TIMER_EVENT_MRESUME))
968 return;
969 spin_lock_irqsave(&timer->lock, flags);
970 if (event == SNDRV_TIMER_EVENT_MSTART ||
971 event == SNDRV_TIMER_EVENT_MCONTINUE ||
972 event == SNDRV_TIMER_EVENT_MRESUME) {
973 if (timer->hw.c_resolution)
974 resolution = timer->hw.c_resolution(timer);
975 else
976 resolution = timer->hw.resolution;
978 list_for_each_entry(ti, &timer->active_list_head, active_list) {
979 if (ti->ccallback)
980 ti->ccallback(ti, event, tstamp, resolution);
981 list_for_each_entry(ts, &ti->slave_active_head, active_list)
982 if (ts->ccallback)
983 ts->ccallback(ts, event, tstamp, resolution);
985 spin_unlock_irqrestore(&timer->lock, flags);
989 * exported functions for global timers
991 int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer)
993 struct snd_timer_id tid;
995 tid.dev_class = SNDRV_TIMER_CLASS_GLOBAL;
996 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
997 tid.card = -1;
998 tid.device = device;
999 tid.subdevice = 0;
1000 return snd_timer_new(NULL, id, &tid, rtimer);
1003 int snd_timer_global_free(struct snd_timer *timer)
1005 return snd_timer_free(timer);
1008 int snd_timer_global_register(struct snd_timer *timer)
1010 struct snd_device dev;
1012 memset(&dev, 0, sizeof(dev));
1013 dev.device_data = timer;
1014 return snd_timer_dev_register(&dev);
1018 * System timer
1021 struct snd_timer_system_private {
1022 struct timer_list tlist;
1023 unsigned long last_expires;
1024 unsigned long last_jiffies;
1025 unsigned long correction;
1028 static void snd_timer_s_function(unsigned long data)
1030 struct snd_timer *timer = (struct snd_timer *)data;
1031 struct snd_timer_system_private *priv = timer->private_data;
1032 unsigned long jiff = jiffies;
1033 if (time_after(jiff, priv->last_expires))
1034 priv->correction += (long)jiff - (long)priv->last_expires;
1035 snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies);
1038 static int snd_timer_s_start(struct snd_timer * timer)
1040 struct snd_timer_system_private *priv;
1041 unsigned long njiff;
1043 priv = (struct snd_timer_system_private *) timer->private_data;
1044 njiff = (priv->last_jiffies = jiffies);
1045 if (priv->correction > timer->sticks - 1) {
1046 priv->correction -= timer->sticks - 1;
1047 njiff++;
1048 } else {
1049 njiff += timer->sticks - priv->correction;
1050 priv->correction = 0;
1052 priv->last_expires = njiff;
1053 mod_timer(&priv->tlist, njiff);
1054 return 0;
1057 static int snd_timer_s_stop(struct snd_timer * timer)
1059 struct snd_timer_system_private *priv;
1060 unsigned long jiff;
1062 priv = (struct snd_timer_system_private *) timer->private_data;
1063 del_timer(&priv->tlist);
1064 jiff = jiffies;
1065 if (time_before(jiff, priv->last_expires))
1066 timer->sticks = priv->last_expires - jiff;
1067 else
1068 timer->sticks = 1;
1069 priv->correction = 0;
1070 return 0;
1073 static struct snd_timer_hardware snd_timer_system =
1075 .flags = SNDRV_TIMER_HW_FIRST | SNDRV_TIMER_HW_TASKLET,
1076 .resolution = 1000000000L / HZ,
1077 .ticks = 10000000L,
1078 .start = snd_timer_s_start,
1079 .stop = snd_timer_s_stop
1082 static void snd_timer_free_system(struct snd_timer *timer)
1084 kfree(timer->private_data);
1087 static int snd_timer_register_system(void)
1089 struct snd_timer *timer;
1090 struct snd_timer_system_private *priv;
1091 int err;
1093 err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer);
1094 if (err < 0)
1095 return err;
1096 strcpy(timer->name, "system timer");
1097 timer->hw = snd_timer_system;
1098 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1099 if (priv == NULL) {
1100 snd_timer_free(timer);
1101 return -ENOMEM;
1103 setup_timer(&priv->tlist, snd_timer_s_function, (unsigned long) timer);
1104 timer->private_data = priv;
1105 timer->private_free = snd_timer_free_system;
1106 return snd_timer_global_register(timer);
1109 #ifdef CONFIG_SND_PROC_FS
1111 * Info interface
1114 static void snd_timer_proc_read(struct snd_info_entry *entry,
1115 struct snd_info_buffer *buffer)
1117 struct snd_timer *timer;
1118 struct snd_timer_instance *ti;
1120 mutex_lock(&register_mutex);
1121 list_for_each_entry(timer, &snd_timer_list, device_list) {
1122 if (timer->card && timer->card->shutdown)
1123 continue;
1124 switch (timer->tmr_class) {
1125 case SNDRV_TIMER_CLASS_GLOBAL:
1126 snd_iprintf(buffer, "G%i: ", timer->tmr_device);
1127 break;
1128 case SNDRV_TIMER_CLASS_CARD:
1129 snd_iprintf(buffer, "C%i-%i: ",
1130 timer->card->number, timer->tmr_device);
1131 break;
1132 case SNDRV_TIMER_CLASS_PCM:
1133 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number,
1134 timer->tmr_device, timer->tmr_subdevice);
1135 break;
1136 default:
1137 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class,
1138 timer->card ? timer->card->number : -1,
1139 timer->tmr_device, timer->tmr_subdevice);
1141 snd_iprintf(buffer, "%s :", timer->name);
1142 if (timer->hw.resolution)
1143 snd_iprintf(buffer, " %lu.%03luus (%lu ticks)",
1144 timer->hw.resolution / 1000,
1145 timer->hw.resolution % 1000,
1146 timer->hw.ticks);
1147 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
1148 snd_iprintf(buffer, " SLAVE");
1149 snd_iprintf(buffer, "\n");
1150 list_for_each_entry(ti, &timer->open_list_head, open_list)
1151 snd_iprintf(buffer, " Client %s : %s\n",
1152 ti->owner ? ti->owner : "unknown",
1153 ti->flags & (SNDRV_TIMER_IFLG_START |
1154 SNDRV_TIMER_IFLG_RUNNING)
1155 ? "running" : "stopped");
1157 mutex_unlock(&register_mutex);
1160 static struct snd_info_entry *snd_timer_proc_entry;
1162 static void __init snd_timer_proc_init(void)
1164 struct snd_info_entry *entry;
1166 entry = snd_info_create_module_entry(THIS_MODULE, "timers", NULL);
1167 if (entry != NULL) {
1168 entry->c.text.read = snd_timer_proc_read;
1169 if (snd_info_register(entry) < 0) {
1170 snd_info_free_entry(entry);
1171 entry = NULL;
1174 snd_timer_proc_entry = entry;
1177 static void __exit snd_timer_proc_done(void)
1179 snd_info_free_entry(snd_timer_proc_entry);
1181 #else /* !CONFIG_SND_PROC_FS */
1182 #define snd_timer_proc_init()
1183 #define snd_timer_proc_done()
1184 #endif
1187 * USER SPACE interface
1190 static void snd_timer_user_interrupt(struct snd_timer_instance *timeri,
1191 unsigned long resolution,
1192 unsigned long ticks)
1194 struct snd_timer_user *tu = timeri->callback_data;
1195 struct snd_timer_read *r;
1196 int prev;
1198 spin_lock(&tu->qlock);
1199 if (tu->qused > 0) {
1200 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1;
1201 r = &tu->queue[prev];
1202 if (r->resolution == resolution) {
1203 r->ticks += ticks;
1204 goto __wake;
1207 if (tu->qused >= tu->queue_size) {
1208 tu->overrun++;
1209 } else {
1210 r = &tu->queue[tu->qtail++];
1211 tu->qtail %= tu->queue_size;
1212 r->resolution = resolution;
1213 r->ticks = ticks;
1214 tu->qused++;
1216 __wake:
1217 spin_unlock(&tu->qlock);
1218 kill_fasync(&tu->fasync, SIGIO, POLL_IN);
1219 wake_up(&tu->qchange_sleep);
1222 static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu,
1223 struct snd_timer_tread *tread)
1225 if (tu->qused >= tu->queue_size) {
1226 tu->overrun++;
1227 } else {
1228 memcpy(&tu->tqueue[tu->qtail++], tread, sizeof(*tread));
1229 tu->qtail %= tu->queue_size;
1230 tu->qused++;
1234 static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
1235 int event,
1236 struct timespec *tstamp,
1237 unsigned long resolution)
1239 struct snd_timer_user *tu = timeri->callback_data;
1240 struct snd_timer_tread r1;
1241 unsigned long flags;
1243 if (event >= SNDRV_TIMER_EVENT_START &&
1244 event <= SNDRV_TIMER_EVENT_PAUSE)
1245 tu->tstamp = *tstamp;
1246 if ((tu->filter & (1 << event)) == 0 || !tu->tread)
1247 return;
1248 memset(&r1, 0, sizeof(r1));
1249 r1.event = event;
1250 r1.tstamp = *tstamp;
1251 r1.val = resolution;
1252 spin_lock_irqsave(&tu->qlock, flags);
1253 snd_timer_user_append_to_tqueue(tu, &r1);
1254 spin_unlock_irqrestore(&tu->qlock, flags);
1255 kill_fasync(&tu->fasync, SIGIO, POLL_IN);
1256 wake_up(&tu->qchange_sleep);
1259 static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
1260 unsigned long resolution,
1261 unsigned long ticks)
1263 struct snd_timer_user *tu = timeri->callback_data;
1264 struct snd_timer_tread *r, r1;
1265 struct timespec tstamp;
1266 int prev, append = 0;
1268 memset(&tstamp, 0, sizeof(tstamp));
1269 spin_lock(&tu->qlock);
1270 if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) |
1271 (1 << SNDRV_TIMER_EVENT_TICK))) == 0) {
1272 spin_unlock(&tu->qlock);
1273 return;
1275 if (tu->last_resolution != resolution || ticks > 0) {
1276 if (timer_tstamp_monotonic)
1277 ktime_get_ts(&tstamp);
1278 else
1279 getnstimeofday(&tstamp);
1281 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) &&
1282 tu->last_resolution != resolution) {
1283 memset(&r1, 0, sizeof(r1));
1284 r1.event = SNDRV_TIMER_EVENT_RESOLUTION;
1285 r1.tstamp = tstamp;
1286 r1.val = resolution;
1287 snd_timer_user_append_to_tqueue(tu, &r1);
1288 tu->last_resolution = resolution;
1289 append++;
1291 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0)
1292 goto __wake;
1293 if (ticks == 0)
1294 goto __wake;
1295 if (tu->qused > 0) {
1296 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1;
1297 r = &tu->tqueue[prev];
1298 if (r->event == SNDRV_TIMER_EVENT_TICK) {
1299 r->tstamp = tstamp;
1300 r->val += ticks;
1301 append++;
1302 goto __wake;
1305 r1.event = SNDRV_TIMER_EVENT_TICK;
1306 r1.tstamp = tstamp;
1307 r1.val = ticks;
1308 snd_timer_user_append_to_tqueue(tu, &r1);
1309 append++;
1310 __wake:
1311 spin_unlock(&tu->qlock);
1312 if (append == 0)
1313 return;
1314 kill_fasync(&tu->fasync, SIGIO, POLL_IN);
1315 wake_up(&tu->qchange_sleep);
1318 static int snd_timer_user_open(struct inode *inode, struct file *file)
1320 struct snd_timer_user *tu;
1321 int err;
1323 err = nonseekable_open(inode, file);
1324 if (err < 0)
1325 return err;
1327 tu = kzalloc(sizeof(*tu), GFP_KERNEL);
1328 if (tu == NULL)
1329 return -ENOMEM;
1330 spin_lock_init(&tu->qlock);
1331 init_waitqueue_head(&tu->qchange_sleep);
1332 mutex_init(&tu->ioctl_lock);
1333 tu->ticks = 1;
1334 tu->queue_size = 128;
1335 tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read),
1336 GFP_KERNEL);
1337 if (tu->queue == NULL) {
1338 kfree(tu);
1339 return -ENOMEM;
1341 file->private_data = tu;
1342 return 0;
1345 static int snd_timer_user_release(struct inode *inode, struct file *file)
1347 struct snd_timer_user *tu;
1349 if (file->private_data) {
1350 tu = file->private_data;
1351 file->private_data = NULL;
1352 mutex_lock(&tu->ioctl_lock);
1353 if (tu->timeri)
1354 snd_timer_close(tu->timeri);
1355 mutex_unlock(&tu->ioctl_lock);
1356 kfree(tu->queue);
1357 kfree(tu->tqueue);
1358 kfree(tu);
1360 return 0;
1363 static void snd_timer_user_zero_id(struct snd_timer_id *id)
1365 id->dev_class = SNDRV_TIMER_CLASS_NONE;
1366 id->dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1367 id->card = -1;
1368 id->device = -1;
1369 id->subdevice = -1;
1372 static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *timer)
1374 id->dev_class = timer->tmr_class;
1375 id->dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1376 id->card = timer->card ? timer->card->number : -1;
1377 id->device = timer->tmr_device;
1378 id->subdevice = timer->tmr_subdevice;
1381 static int snd_timer_user_next_device(struct snd_timer_id __user *_tid)
1383 struct snd_timer_id id;
1384 struct snd_timer *timer;
1385 struct list_head *p;
1387 if (copy_from_user(&id, _tid, sizeof(id)))
1388 return -EFAULT;
1389 mutex_lock(&register_mutex);
1390 if (id.dev_class < 0) { /* first item */
1391 if (list_empty(&snd_timer_list))
1392 snd_timer_user_zero_id(&id);
1393 else {
1394 timer = list_entry(snd_timer_list.next,
1395 struct snd_timer, device_list);
1396 snd_timer_user_copy_id(&id, timer);
1398 } else {
1399 switch (id.dev_class) {
1400 case SNDRV_TIMER_CLASS_GLOBAL:
1401 id.device = id.device < 0 ? 0 : id.device + 1;
1402 list_for_each(p, &snd_timer_list) {
1403 timer = list_entry(p, struct snd_timer, device_list);
1404 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) {
1405 snd_timer_user_copy_id(&id, timer);
1406 break;
1408 if (timer->tmr_device >= id.device) {
1409 snd_timer_user_copy_id(&id, timer);
1410 break;
1413 if (p == &snd_timer_list)
1414 snd_timer_user_zero_id(&id);
1415 break;
1416 case SNDRV_TIMER_CLASS_CARD:
1417 case SNDRV_TIMER_CLASS_PCM:
1418 if (id.card < 0) {
1419 id.card = 0;
1420 } else {
1421 if (id.card < 0) {
1422 id.card = 0;
1423 } else {
1424 if (id.device < 0) {
1425 id.device = 0;
1426 } else {
1427 if (id.subdevice < 0) {
1428 id.subdevice = 0;
1429 } else {
1430 id.subdevice++;
1435 list_for_each(p, &snd_timer_list) {
1436 timer = list_entry(p, struct snd_timer, device_list);
1437 if (timer->tmr_class > id.dev_class) {
1438 snd_timer_user_copy_id(&id, timer);
1439 break;
1441 if (timer->tmr_class < id.dev_class)
1442 continue;
1443 if (timer->card->number > id.card) {
1444 snd_timer_user_copy_id(&id, timer);
1445 break;
1447 if (timer->card->number < id.card)
1448 continue;
1449 if (timer->tmr_device > id.device) {
1450 snd_timer_user_copy_id(&id, timer);
1451 break;
1453 if (timer->tmr_device < id.device)
1454 continue;
1455 if (timer->tmr_subdevice > id.subdevice) {
1456 snd_timer_user_copy_id(&id, timer);
1457 break;
1459 if (timer->tmr_subdevice < id.subdevice)
1460 continue;
1461 snd_timer_user_copy_id(&id, timer);
1462 break;
1464 if (p == &snd_timer_list)
1465 snd_timer_user_zero_id(&id);
1466 break;
1467 default:
1468 snd_timer_user_zero_id(&id);
1471 mutex_unlock(&register_mutex);
1472 if (copy_to_user(_tid, &id, sizeof(*_tid)))
1473 return -EFAULT;
1474 return 0;
1477 static int snd_timer_user_ginfo(struct file *file,
1478 struct snd_timer_ginfo __user *_ginfo)
1480 struct snd_timer_ginfo *ginfo;
1481 struct snd_timer_id tid;
1482 struct snd_timer *t;
1483 struct list_head *p;
1484 int err = 0;
1486 ginfo = memdup_user(_ginfo, sizeof(*ginfo));
1487 if (IS_ERR(ginfo))
1488 return PTR_ERR(ginfo);
1490 tid = ginfo->tid;
1491 memset(ginfo, 0, sizeof(*ginfo));
1492 ginfo->tid = tid;
1493 mutex_lock(&register_mutex);
1494 t = snd_timer_find(&tid);
1495 if (t != NULL) {
1496 ginfo->card = t->card ? t->card->number : -1;
1497 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
1498 ginfo->flags |= SNDRV_TIMER_FLG_SLAVE;
1499 strlcpy(ginfo->id, t->id, sizeof(ginfo->id));
1500 strlcpy(ginfo->name, t->name, sizeof(ginfo->name));
1501 ginfo->resolution = t->hw.resolution;
1502 if (t->hw.resolution_min > 0) {
1503 ginfo->resolution_min = t->hw.resolution_min;
1504 ginfo->resolution_max = t->hw.resolution_max;
1506 list_for_each(p, &t->open_list_head) {
1507 ginfo->clients++;
1509 } else {
1510 err = -ENODEV;
1512 mutex_unlock(&register_mutex);
1513 if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo)))
1514 err = -EFAULT;
1515 kfree(ginfo);
1516 return err;
1519 static int snd_timer_user_gparams(struct file *file,
1520 struct snd_timer_gparams __user *_gparams)
1522 struct snd_timer_gparams gparams;
1523 struct snd_timer *t;
1524 int err;
1526 if (copy_from_user(&gparams, _gparams, sizeof(gparams)))
1527 return -EFAULT;
1528 mutex_lock(&register_mutex);
1529 t = snd_timer_find(&gparams.tid);
1530 if (!t) {
1531 err = -ENODEV;
1532 goto _error;
1534 if (!list_empty(&t->open_list_head)) {
1535 err = -EBUSY;
1536 goto _error;
1538 if (!t->hw.set_period) {
1539 err = -ENOSYS;
1540 goto _error;
1542 err = t->hw.set_period(t, gparams.period_num, gparams.period_den);
1543 _error:
1544 mutex_unlock(&register_mutex);
1545 return err;
1548 static int snd_timer_user_gstatus(struct file *file,
1549 struct snd_timer_gstatus __user *_gstatus)
1551 struct snd_timer_gstatus gstatus;
1552 struct snd_timer_id tid;
1553 struct snd_timer *t;
1554 int err = 0;
1556 if (copy_from_user(&gstatus, _gstatus, sizeof(gstatus)))
1557 return -EFAULT;
1558 tid = gstatus.tid;
1559 memset(&gstatus, 0, sizeof(gstatus));
1560 gstatus.tid = tid;
1561 mutex_lock(&register_mutex);
1562 t = snd_timer_find(&tid);
1563 if (t != NULL) {
1564 if (t->hw.c_resolution)
1565 gstatus.resolution = t->hw.c_resolution(t);
1566 else
1567 gstatus.resolution = t->hw.resolution;
1568 if (t->hw.precise_resolution) {
1569 t->hw.precise_resolution(t, &gstatus.resolution_num,
1570 &gstatus.resolution_den);
1571 } else {
1572 gstatus.resolution_num = gstatus.resolution;
1573 gstatus.resolution_den = 1000000000uL;
1575 } else {
1576 err = -ENODEV;
1578 mutex_unlock(&register_mutex);
1579 if (err >= 0 && copy_to_user(_gstatus, &gstatus, sizeof(gstatus)))
1580 err = -EFAULT;
1581 return err;
1584 static int snd_timer_user_tselect(struct file *file,
1585 struct snd_timer_select __user *_tselect)
1587 struct snd_timer_user *tu;
1588 struct snd_timer_select tselect;
1589 char str[32];
1590 int err = 0;
1592 tu = file->private_data;
1593 if (tu->timeri) {
1594 snd_timer_close(tu->timeri);
1595 tu->timeri = NULL;
1597 if (copy_from_user(&tselect, _tselect, sizeof(tselect))) {
1598 err = -EFAULT;
1599 goto __err;
1601 sprintf(str, "application %i", current->pid);
1602 if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE)
1603 tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION;
1604 err = snd_timer_open(&tu->timeri, str, &tselect.id, current->pid);
1605 if (err < 0)
1606 goto __err;
1608 tu->qhead = tu->qtail = tu->qused = 0;
1609 kfree(tu->queue);
1610 tu->queue = NULL;
1611 kfree(tu->tqueue);
1612 tu->tqueue = NULL;
1613 if (tu->tread) {
1614 tu->tqueue = kmalloc(tu->queue_size * sizeof(struct snd_timer_tread),
1615 GFP_KERNEL);
1616 if (tu->tqueue == NULL)
1617 err = -ENOMEM;
1618 } else {
1619 tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read),
1620 GFP_KERNEL);
1621 if (tu->queue == NULL)
1622 err = -ENOMEM;
1625 if (err < 0) {
1626 snd_timer_close(tu->timeri);
1627 tu->timeri = NULL;
1628 } else {
1629 tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST;
1630 tu->timeri->callback = tu->tread
1631 ? snd_timer_user_tinterrupt : snd_timer_user_interrupt;
1632 tu->timeri->ccallback = snd_timer_user_ccallback;
1633 tu->timeri->callback_data = (void *)tu;
1636 __err:
1637 return err;
1640 static int snd_timer_user_info(struct file *file,
1641 struct snd_timer_info __user *_info)
1643 struct snd_timer_user *tu;
1644 struct snd_timer_info *info;
1645 struct snd_timer *t;
1646 int err = 0;
1648 tu = file->private_data;
1649 if (!tu->timeri)
1650 return -EBADFD;
1651 t = tu->timeri->timer;
1652 if (!t)
1653 return -EBADFD;
1655 info = kzalloc(sizeof(*info), GFP_KERNEL);
1656 if (! info)
1657 return -ENOMEM;
1658 info->card = t->card ? t->card->number : -1;
1659 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
1660 info->flags |= SNDRV_TIMER_FLG_SLAVE;
1661 strlcpy(info->id, t->id, sizeof(info->id));
1662 strlcpy(info->name, t->name, sizeof(info->name));
1663 info->resolution = t->hw.resolution;
1664 if (copy_to_user(_info, info, sizeof(*_info)))
1665 err = -EFAULT;
1666 kfree(info);
1667 return err;
1670 static int snd_timer_user_params(struct file *file,
1671 struct snd_timer_params __user *_params)
1673 struct snd_timer_user *tu;
1674 struct snd_timer_params params;
1675 struct snd_timer *t;
1676 struct snd_timer_read *tr;
1677 struct snd_timer_tread *ttr;
1678 int err;
1680 tu = file->private_data;
1681 if (!tu->timeri)
1682 return -EBADFD;
1683 t = tu->timeri->timer;
1684 if (!t)
1685 return -EBADFD;
1686 if (copy_from_user(&params, _params, sizeof(params)))
1687 return -EFAULT;
1688 if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE)) {
1689 u64 resolution;
1691 if (params.ticks < 1) {
1692 err = -EINVAL;
1693 goto _end;
1696 /* Don't allow resolution less than 1ms */
1697 resolution = snd_timer_resolution(tu->timeri);
1698 resolution *= params.ticks;
1699 if (resolution < 1000000) {
1700 err = -EINVAL;
1701 goto _end;
1704 if (params.queue_size > 0 &&
1705 (params.queue_size < 32 || params.queue_size > 1024)) {
1706 err = -EINVAL;
1707 goto _end;
1709 if (params.filter & ~((1<<SNDRV_TIMER_EVENT_RESOLUTION)|
1710 (1<<SNDRV_TIMER_EVENT_TICK)|
1711 (1<<SNDRV_TIMER_EVENT_START)|
1712 (1<<SNDRV_TIMER_EVENT_STOP)|
1713 (1<<SNDRV_TIMER_EVENT_CONTINUE)|
1714 (1<<SNDRV_TIMER_EVENT_PAUSE)|
1715 (1<<SNDRV_TIMER_EVENT_SUSPEND)|
1716 (1<<SNDRV_TIMER_EVENT_RESUME)|
1717 (1<<SNDRV_TIMER_EVENT_MSTART)|
1718 (1<<SNDRV_TIMER_EVENT_MSTOP)|
1719 (1<<SNDRV_TIMER_EVENT_MCONTINUE)|
1720 (1<<SNDRV_TIMER_EVENT_MPAUSE)|
1721 (1<<SNDRV_TIMER_EVENT_MSUSPEND)|
1722 (1<<SNDRV_TIMER_EVENT_MRESUME))) {
1723 err = -EINVAL;
1724 goto _end;
1726 snd_timer_stop(tu->timeri);
1727 spin_lock_irq(&t->lock);
1728 tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO|
1729 SNDRV_TIMER_IFLG_EXCLUSIVE|
1730 SNDRV_TIMER_IFLG_EARLY_EVENT);
1731 if (params.flags & SNDRV_TIMER_PSFLG_AUTO)
1732 tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO;
1733 if (params.flags & SNDRV_TIMER_PSFLG_EXCLUSIVE)
1734 tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE;
1735 if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT)
1736 tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT;
1737 spin_unlock_irq(&t->lock);
1738 if (params.queue_size > 0 &&
1739 (unsigned int)tu->queue_size != params.queue_size) {
1740 if (tu->tread) {
1741 ttr = kmalloc(params.queue_size * sizeof(*ttr),
1742 GFP_KERNEL);
1743 if (ttr) {
1744 kfree(tu->tqueue);
1745 tu->queue_size = params.queue_size;
1746 tu->tqueue = ttr;
1748 } else {
1749 tr = kmalloc(params.queue_size * sizeof(*tr),
1750 GFP_KERNEL);
1751 if (tr) {
1752 kfree(tu->queue);
1753 tu->queue_size = params.queue_size;
1754 tu->queue = tr;
1758 tu->qhead = tu->qtail = tu->qused = 0;
1759 if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) {
1760 if (tu->tread) {
1761 struct snd_timer_tread tread;
1762 memset(&tread, 0, sizeof(tread));
1763 tread.event = SNDRV_TIMER_EVENT_EARLY;
1764 tread.tstamp.tv_sec = 0;
1765 tread.tstamp.tv_nsec = 0;
1766 tread.val = 0;
1767 snd_timer_user_append_to_tqueue(tu, &tread);
1768 } else {
1769 struct snd_timer_read *r = &tu->queue[0];
1770 r->resolution = 0;
1771 r->ticks = 0;
1772 tu->qused++;
1773 tu->qtail++;
1776 tu->filter = params.filter;
1777 tu->ticks = params.ticks;
1778 err = 0;
1779 _end:
1780 if (copy_to_user(_params, &params, sizeof(params)))
1781 return -EFAULT;
1782 return err;
1785 static int snd_timer_user_status(struct file *file,
1786 struct snd_timer_status __user *_status)
1788 struct snd_timer_user *tu;
1789 struct snd_timer_status status;
1791 tu = file->private_data;
1792 if (!tu->timeri)
1793 return -EBADFD;
1794 memset(&status, 0, sizeof(status));
1795 status.tstamp = tu->tstamp;
1796 status.resolution = snd_timer_resolution(tu->timeri);
1797 status.lost = tu->timeri->lost;
1798 status.overrun = tu->overrun;
1799 spin_lock_irq(&tu->qlock);
1800 status.queue = tu->qused;
1801 spin_unlock_irq(&tu->qlock);
1802 if (copy_to_user(_status, &status, sizeof(status)))
1803 return -EFAULT;
1804 return 0;
1807 static int snd_timer_user_start(struct file *file)
1809 int err;
1810 struct snd_timer_user *tu;
1812 tu = file->private_data;
1813 if (!tu->timeri)
1814 return -EBADFD;
1815 snd_timer_stop(tu->timeri);
1816 tu->timeri->lost = 0;
1817 tu->last_resolution = 0;
1818 return (err = snd_timer_start(tu->timeri, tu->ticks)) < 0 ? err : 0;
1821 static int snd_timer_user_stop(struct file *file)
1823 int err;
1824 struct snd_timer_user *tu;
1826 tu = file->private_data;
1827 if (!tu->timeri)
1828 return -EBADFD;
1829 return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0;
1832 static int snd_timer_user_continue(struct file *file)
1834 int err;
1835 struct snd_timer_user *tu;
1837 tu = file->private_data;
1838 if (!tu->timeri)
1839 return -EBADFD;
1840 tu->timeri->lost = 0;
1841 return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0;
1844 static int snd_timer_user_pause(struct file *file)
1846 int err;
1847 struct snd_timer_user *tu;
1849 tu = file->private_data;
1850 if (!tu->timeri)
1851 return -EBADFD;
1852 return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0;
1855 enum {
1856 SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20),
1857 SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21),
1858 SNDRV_TIMER_IOCTL_CONTINUE_OLD = _IO('T', 0x22),
1859 SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23),
1862 static long __snd_timer_user_ioctl(struct file *file, unsigned int cmd,
1863 unsigned long arg)
1865 struct snd_timer_user *tu;
1866 void __user *argp = (void __user *)arg;
1867 int __user *p = argp;
1869 tu = file->private_data;
1870 switch (cmd) {
1871 case SNDRV_TIMER_IOCTL_PVERSION:
1872 return put_user(SNDRV_TIMER_VERSION, p) ? -EFAULT : 0;
1873 case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
1874 return snd_timer_user_next_device(argp);
1875 case SNDRV_TIMER_IOCTL_TREAD:
1877 int xarg;
1879 if (tu->timeri) /* too late */
1880 return -EBUSY;
1881 if (get_user(xarg, p))
1882 return -EFAULT;
1883 tu->tread = xarg ? 1 : 0;
1884 return 0;
1886 case SNDRV_TIMER_IOCTL_GINFO:
1887 return snd_timer_user_ginfo(file, argp);
1888 case SNDRV_TIMER_IOCTL_GPARAMS:
1889 return snd_timer_user_gparams(file, argp);
1890 case SNDRV_TIMER_IOCTL_GSTATUS:
1891 return snd_timer_user_gstatus(file, argp);
1892 case SNDRV_TIMER_IOCTL_SELECT:
1893 return snd_timer_user_tselect(file, argp);
1894 case SNDRV_TIMER_IOCTL_INFO:
1895 return snd_timer_user_info(file, argp);
1896 case SNDRV_TIMER_IOCTL_PARAMS:
1897 return snd_timer_user_params(file, argp);
1898 case SNDRV_TIMER_IOCTL_STATUS:
1899 return snd_timer_user_status(file, argp);
1900 case SNDRV_TIMER_IOCTL_START:
1901 case SNDRV_TIMER_IOCTL_START_OLD:
1902 return snd_timer_user_start(file);
1903 case SNDRV_TIMER_IOCTL_STOP:
1904 case SNDRV_TIMER_IOCTL_STOP_OLD:
1905 return snd_timer_user_stop(file);
1906 case SNDRV_TIMER_IOCTL_CONTINUE:
1907 case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
1908 return snd_timer_user_continue(file);
1909 case SNDRV_TIMER_IOCTL_PAUSE:
1910 case SNDRV_TIMER_IOCTL_PAUSE_OLD:
1911 return snd_timer_user_pause(file);
1913 return -ENOTTY;
1916 static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
1917 unsigned long arg)
1919 struct snd_timer_user *tu = file->private_data;
1920 long ret;
1922 mutex_lock(&tu->ioctl_lock);
1923 ret = __snd_timer_user_ioctl(file, cmd, arg);
1924 mutex_unlock(&tu->ioctl_lock);
1925 return ret;
1928 static int snd_timer_user_fasync(int fd, struct file * file, int on)
1930 struct snd_timer_user *tu;
1932 tu = file->private_data;
1933 return fasync_helper(fd, file, on, &tu->fasync);
1936 static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
1937 size_t count, loff_t *offset)
1939 struct snd_timer_user *tu;
1940 long result = 0, unit;
1941 int qhead;
1942 int err = 0;
1944 tu = file->private_data;
1945 unit = tu->tread ? sizeof(struct snd_timer_tread) : sizeof(struct snd_timer_read);
1946 mutex_lock(&tu->ioctl_lock);
1947 spin_lock_irq(&tu->qlock);
1948 while ((long)count - result >= unit) {
1949 while (!tu->qused) {
1950 wait_queue_t wait;
1952 if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
1953 err = -EAGAIN;
1954 goto _error;
1957 set_current_state(TASK_INTERRUPTIBLE);
1958 init_waitqueue_entry(&wait, current);
1959 add_wait_queue(&tu->qchange_sleep, &wait);
1961 spin_unlock_irq(&tu->qlock);
1962 mutex_unlock(&tu->ioctl_lock);
1963 schedule();
1964 mutex_lock(&tu->ioctl_lock);
1965 spin_lock_irq(&tu->qlock);
1967 remove_wait_queue(&tu->qchange_sleep, &wait);
1969 if (tu->disconnected) {
1970 err = -ENODEV;
1971 goto _error;
1973 if (signal_pending(current)) {
1974 err = -ERESTARTSYS;
1975 goto _error;
1979 qhead = tu->qhead++;
1980 tu->qhead %= tu->queue_size;
1981 tu->qused--;
1982 spin_unlock_irq(&tu->qlock);
1984 if (tu->tread) {
1985 if (copy_to_user(buffer, &tu->tqueue[qhead],
1986 sizeof(struct snd_timer_tread)))
1987 err = -EFAULT;
1988 } else {
1989 if (copy_to_user(buffer, &tu->queue[qhead],
1990 sizeof(struct snd_timer_read)))
1991 err = -EFAULT;
1994 spin_lock_irq(&tu->qlock);
1995 if (err < 0)
1996 goto _error;
1997 result += unit;
1998 buffer += unit;
2000 _error:
2001 spin_unlock_irq(&tu->qlock);
2002 mutex_unlock(&tu->ioctl_lock);
2003 return result > 0 ? result : err;
2006 static unsigned int snd_timer_user_poll(struct file *file, poll_table * wait)
2008 unsigned int mask;
2009 struct snd_timer_user *tu;
2011 tu = file->private_data;
2013 poll_wait(file, &tu->qchange_sleep, wait);
2015 mask = 0;
2016 if (tu->qused)
2017 mask |= POLLIN | POLLRDNORM;
2018 if (tu->disconnected)
2019 mask |= POLLERR;
2021 return mask;
2024 #ifdef CONFIG_COMPAT
2025 #include "timer_compat.c"
2026 #else
2027 #define snd_timer_user_ioctl_compat NULL
2028 #endif
2030 static const struct file_operations snd_timer_f_ops =
2032 .owner = THIS_MODULE,
2033 .read = snd_timer_user_read,
2034 .open = snd_timer_user_open,
2035 .release = snd_timer_user_release,
2036 .llseek = no_llseek,
2037 .poll = snd_timer_user_poll,
2038 .unlocked_ioctl = snd_timer_user_ioctl,
2039 .compat_ioctl = snd_timer_user_ioctl_compat,
2040 .fasync = snd_timer_user_fasync,
2043 /* unregister the system timer */
2044 static void snd_timer_free_all(void)
2046 struct snd_timer *timer, *n;
2048 list_for_each_entry_safe(timer, n, &snd_timer_list, device_list)
2049 snd_timer_free(timer);
2052 static struct device timer_dev;
2055 * ENTRY functions
2058 static int __init alsa_timer_init(void)
2060 int err;
2062 snd_device_initialize(&timer_dev, NULL);
2063 dev_set_name(&timer_dev, "timer");
2065 #ifdef SNDRV_OSS_INFO_DEV_TIMERS
2066 snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1,
2067 "system timer");
2068 #endif
2070 err = snd_timer_register_system();
2071 if (err < 0) {
2072 pr_err("ALSA: unable to register system timer (%i)\n", err);
2073 put_device(&timer_dev);
2074 return err;
2077 err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0,
2078 &snd_timer_f_ops, NULL, &timer_dev);
2079 if (err < 0) {
2080 pr_err("ALSA: unable to register timer device (%i)\n", err);
2081 snd_timer_free_all();
2082 put_device(&timer_dev);
2083 return err;
2086 snd_timer_proc_init();
2087 return 0;
2090 static void __exit alsa_timer_exit(void)
2092 snd_unregister_device(&timer_dev);
2093 snd_timer_free_all();
2094 put_device(&timer_dev);
2095 snd_timer_proc_done();
2096 #ifdef SNDRV_OSS_INFO_DEV_TIMERS
2097 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1);
2098 #endif
2101 module_init(alsa_timer_init)
2102 module_exit(alsa_timer_exit)
2104 EXPORT_SYMBOL(snd_timer_open);
2105 EXPORT_SYMBOL(snd_timer_close);
2106 EXPORT_SYMBOL(snd_timer_resolution);
2107 EXPORT_SYMBOL(snd_timer_start);
2108 EXPORT_SYMBOL(snd_timer_stop);
2109 EXPORT_SYMBOL(snd_timer_continue);
2110 EXPORT_SYMBOL(snd_timer_pause);
2111 EXPORT_SYMBOL(snd_timer_new);
2112 EXPORT_SYMBOL(snd_timer_notify);
2113 EXPORT_SYMBOL(snd_timer_global_new);
2114 EXPORT_SYMBOL(snd_timer_global_free);
2115 EXPORT_SYMBOL(snd_timer_global_register);
2116 EXPORT_SYMBOL(snd_timer_interrupt);