]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Timers abstract layer | |
3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | |
4 | * | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #include <sound/driver.h> | |
23 | #include <linux/delay.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/smp_lock.h> | |
26 | #include <linux/slab.h> | |
27 | #include <linux/time.h> | |
28 | #include <linux/moduleparam.h> | |
543537bd | 29 | #include <linux/string.h> |
1da177e4 LT |
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> | |
37 | #ifdef CONFIG_KERNELD | |
38 | #include <linux/kerneld.h> | |
39 | #endif | |
40 | ||
41 | #if defined(CONFIG_SND_HPET) || defined(CONFIG_SND_HPET_MODULE) | |
42 | #define DEFAULT_TIMER_LIMIT 3 | |
43 | #elif defined(CONFIG_SND_RTCTIMER) || defined(CONFIG_SND_RTCTIMER_MODULE) | |
44 | #define DEFAULT_TIMER_LIMIT 2 | |
45 | #else | |
46 | #define DEFAULT_TIMER_LIMIT 1 | |
47 | #endif | |
48 | ||
49 | static int timer_limit = DEFAULT_TIMER_LIMIT; | |
50 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Takashi Iwai <tiwai@suse.de>"); | |
51 | MODULE_DESCRIPTION("ALSA timer interface"); | |
52 | MODULE_LICENSE("GPL"); | |
53 | module_param(timer_limit, int, 0444); | |
54 | MODULE_PARM_DESC(timer_limit, "Maximum global timers in system."); | |
55 | ||
53d2f744 TI |
56 | struct snd_timer_user { |
57 | struct snd_timer_instance *timeri; | |
6b172a85 | 58 | int tread; /* enhanced read with timestamps and events */ |
1da177e4 LT |
59 | unsigned long ticks; |
60 | unsigned long overrun; | |
61 | int qhead; | |
62 | int qtail; | |
63 | int qused; | |
64 | int queue_size; | |
53d2f744 TI |
65 | struct snd_timer_read *queue; |
66 | struct snd_timer_tread *tqueue; | |
1da177e4 LT |
67 | spinlock_t qlock; |
68 | unsigned long last_resolution; | |
69 | unsigned int filter; | |
70 | struct timespec tstamp; /* trigger tstamp */ | |
71 | wait_queue_head_t qchange_sleep; | |
72 | struct fasync_struct *fasync; | |
c1935b4d | 73 | struct semaphore tread_sem; |
53d2f744 | 74 | }; |
1da177e4 LT |
75 | |
76 | /* list of timers */ | |
77 | static LIST_HEAD(snd_timer_list); | |
78 | ||
79 | /* list of slave instances */ | |
80 | static LIST_HEAD(snd_timer_slave_list); | |
81 | ||
82 | /* lock for slave active lists */ | |
83 | static DEFINE_SPINLOCK(slave_active_lock); | |
84 | ||
85 | static DECLARE_MUTEX(register_mutex); | |
86 | ||
53d2f744 TI |
87 | static int snd_timer_free(struct snd_timer *timer); |
88 | static int snd_timer_dev_free(struct snd_device *device); | |
89 | static int snd_timer_dev_register(struct snd_device *device); | |
90 | static int snd_timer_dev_unregister(struct snd_device *device); | |
1da177e4 | 91 | |
53d2f744 | 92 | static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left); |
1da177e4 LT |
93 | |
94 | /* | |
95 | * create a timer instance with the given owner string. | |
96 | * when timer is not NULL, increments the module counter | |
97 | */ | |
53d2f744 TI |
98 | static struct snd_timer_instance *snd_timer_instance_new(char *owner, |
99 | struct snd_timer *timer) | |
1da177e4 | 100 | { |
53d2f744 | 101 | struct snd_timer_instance *timeri; |
ca2c0966 | 102 | timeri = kzalloc(sizeof(*timeri), GFP_KERNEL); |
1da177e4 LT |
103 | if (timeri == NULL) |
104 | return NULL; | |
543537bd | 105 | timeri->owner = kstrdup(owner, GFP_KERNEL); |
1da177e4 LT |
106 | if (! timeri->owner) { |
107 | kfree(timeri); | |
108 | return NULL; | |
109 | } | |
110 | INIT_LIST_HEAD(&timeri->open_list); | |
111 | INIT_LIST_HEAD(&timeri->active_list); | |
112 | INIT_LIST_HEAD(&timeri->ack_list); | |
113 | INIT_LIST_HEAD(&timeri->slave_list_head); | |
114 | INIT_LIST_HEAD(&timeri->slave_active_head); | |
115 | ||
116 | timeri->timer = timer; | |
de24214d | 117 | if (timer && !try_module_get(timer->module)) { |
1da177e4 LT |
118 | kfree(timeri->owner); |
119 | kfree(timeri); | |
120 | return NULL; | |
121 | } | |
122 | ||
123 | return timeri; | |
124 | } | |
125 | ||
126 | /* | |
127 | * find a timer instance from the given timer id | |
128 | */ | |
53d2f744 | 129 | static struct snd_timer *snd_timer_find(struct snd_timer_id *tid) |
1da177e4 | 130 | { |
53d2f744 | 131 | struct snd_timer *timer = NULL; |
1da177e4 LT |
132 | struct list_head *p; |
133 | ||
134 | list_for_each(p, &snd_timer_list) { | |
53d2f744 | 135 | timer = list_entry(p, struct snd_timer, device_list); |
1da177e4 LT |
136 | |
137 | if (timer->tmr_class != tid->dev_class) | |
138 | continue; | |
139 | if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD || | |
140 | timer->tmr_class == SNDRV_TIMER_CLASS_PCM) && | |
141 | (timer->card == NULL || | |
142 | timer->card->number != tid->card)) | |
143 | continue; | |
144 | if (timer->tmr_device != tid->device) | |
145 | continue; | |
146 | if (timer->tmr_subdevice != tid->subdevice) | |
147 | continue; | |
148 | return timer; | |
149 | } | |
150 | return NULL; | |
151 | } | |
152 | ||
153 | #ifdef CONFIG_KMOD | |
154 | ||
53d2f744 | 155 | static void snd_timer_request(struct snd_timer_id *tid) |
1da177e4 LT |
156 | { |
157 | if (! current->fs->root) | |
158 | return; | |
159 | switch (tid->dev_class) { | |
160 | case SNDRV_TIMER_CLASS_GLOBAL: | |
161 | if (tid->device < timer_limit) | |
162 | request_module("snd-timer-%i", tid->device); | |
163 | break; | |
164 | case SNDRV_TIMER_CLASS_CARD: | |
165 | case SNDRV_TIMER_CLASS_PCM: | |
166 | if (tid->card < snd_ecards_limit) | |
167 | request_module("snd-card-%i", tid->card); | |
168 | break; | |
169 | default: | |
170 | break; | |
171 | } | |
172 | } | |
173 | ||
174 | #endif | |
175 | ||
176 | /* | |
177 | * look for a master instance matching with the slave id of the given slave. | |
178 | * when found, relink the open_link of the slave. | |
179 | * | |
180 | * call this with register_mutex down. | |
181 | */ | |
53d2f744 | 182 | static void snd_timer_check_slave(struct snd_timer_instance *slave) |
1da177e4 | 183 | { |
53d2f744 TI |
184 | struct snd_timer *timer; |
185 | struct snd_timer_instance *master; | |
1da177e4 LT |
186 | struct list_head *p, *q; |
187 | ||
188 | /* FIXME: it's really dumb to look up all entries.. */ | |
189 | list_for_each(p, &snd_timer_list) { | |
53d2f744 | 190 | timer = list_entry(p, struct snd_timer, device_list); |
1da177e4 | 191 | list_for_each(q, &timer->open_list_head) { |
53d2f744 | 192 | master = list_entry(q, struct snd_timer_instance, open_list); |
1da177e4 LT |
193 | if (slave->slave_class == master->slave_class && |
194 | slave->slave_id == master->slave_id) { | |
195 | list_del(&slave->open_list); | |
6b172a85 CL |
196 | list_add_tail(&slave->open_list, |
197 | &master->slave_list_head); | |
1da177e4 LT |
198 | spin_lock_irq(&slave_active_lock); |
199 | slave->master = master; | |
200 | slave->timer = master->timer; | |
201 | spin_unlock_irq(&slave_active_lock); | |
202 | return; | |
203 | } | |
204 | } | |
205 | } | |
206 | } | |
207 | ||
208 | /* | |
209 | * look for slave instances matching with the slave id of the given master. | |
210 | * when found, relink the open_link of slaves. | |
211 | * | |
212 | * call this with register_mutex down. | |
213 | */ | |
53d2f744 | 214 | static void snd_timer_check_master(struct snd_timer_instance *master) |
1da177e4 | 215 | { |
53d2f744 | 216 | struct snd_timer_instance *slave; |
1da177e4 LT |
217 | struct list_head *p, *n; |
218 | ||
219 | /* check all pending slaves */ | |
220 | list_for_each_safe(p, n, &snd_timer_slave_list) { | |
53d2f744 | 221 | slave = list_entry(p, struct snd_timer_instance, open_list); |
1da177e4 LT |
222 | if (slave->slave_class == master->slave_class && |
223 | slave->slave_id == master->slave_id) { | |
224 | list_del(p); | |
225 | list_add_tail(p, &master->slave_list_head); | |
226 | spin_lock_irq(&slave_active_lock); | |
227 | slave->master = master; | |
228 | slave->timer = master->timer; | |
229 | if (slave->flags & SNDRV_TIMER_IFLG_RUNNING) | |
6b172a85 CL |
230 | list_add_tail(&slave->active_list, |
231 | &master->slave_active_head); | |
1da177e4 LT |
232 | spin_unlock_irq(&slave_active_lock); |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | /* | |
238 | * open a timer instance | |
239 | * when opening a master, the slave id must be here given. | |
240 | */ | |
53d2f744 TI |
241 | int snd_timer_open(struct snd_timer_instance **ti, |
242 | char *owner, struct snd_timer_id *tid, | |
1da177e4 LT |
243 | unsigned int slave_id) |
244 | { | |
53d2f744 TI |
245 | struct snd_timer *timer; |
246 | struct snd_timer_instance *timeri = NULL; | |
6b172a85 | 247 | |
1da177e4 LT |
248 | if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) { |
249 | /* open a slave instance */ | |
250 | if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE || | |
251 | tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) { | |
252 | snd_printd("invalid slave class %i\n", tid->dev_sclass); | |
253 | return -EINVAL; | |
254 | } | |
255 | down(®ister_mutex); | |
256 | timeri = snd_timer_instance_new(owner, NULL); | |
2fd43d11 CL |
257 | if (!timeri) { |
258 | up(®ister_mutex); | |
259 | return -ENOMEM; | |
260 | } | |
1da177e4 LT |
261 | timeri->slave_class = tid->dev_sclass; |
262 | timeri->slave_id = tid->device; | |
263 | timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; | |
264 | list_add_tail(&timeri->open_list, &snd_timer_slave_list); | |
265 | snd_timer_check_slave(timeri); | |
266 | up(®ister_mutex); | |
267 | *ti = timeri; | |
268 | return 0; | |
269 | } | |
270 | ||
271 | /* open a master instance */ | |
272 | down(®ister_mutex); | |
273 | timer = snd_timer_find(tid); | |
274 | #ifdef CONFIG_KMOD | |
275 | if (timer == NULL) { | |
276 | up(®ister_mutex); | |
277 | snd_timer_request(tid); | |
278 | down(®ister_mutex); | |
279 | timer = snd_timer_find(tid); | |
280 | } | |
281 | #endif | |
2fd43d11 | 282 | if (!timer) { |
1da177e4 LT |
283 | up(®ister_mutex); |
284 | return -ENODEV; | |
285 | } | |
2fd43d11 CL |
286 | if (!list_empty(&timer->open_list_head)) { |
287 | timeri = list_entry(timer->open_list_head.next, | |
53d2f744 | 288 | struct snd_timer_instance, open_list); |
2fd43d11 CL |
289 | if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) { |
290 | up(®ister_mutex); | |
291 | return -EBUSY; | |
292 | } | |
293 | } | |
294 | timeri = snd_timer_instance_new(owner, timer); | |
295 | if (!timeri) { | |
296 | up(®ister_mutex); | |
297 | return -ENOMEM; | |
298 | } | |
299 | timeri->slave_class = tid->dev_sclass; | |
300 | timeri->slave_id = slave_id; | |
301 | if (list_empty(&timer->open_list_head) && timer->hw.open) | |
302 | timer->hw.open(timer); | |
303 | list_add_tail(&timeri->open_list, &timer->open_list_head); | |
304 | snd_timer_check_master(timeri); | |
1da177e4 LT |
305 | up(®ister_mutex); |
306 | *ti = timeri; | |
307 | return 0; | |
308 | } | |
309 | ||
53d2f744 TI |
310 | static int _snd_timer_stop(struct snd_timer_instance *timeri, |
311 | int keep_flag, int event); | |
1da177e4 LT |
312 | |
313 | /* | |
314 | * close a timer instance | |
315 | */ | |
53d2f744 | 316 | int snd_timer_close(struct snd_timer_instance *timeri) |
1da177e4 | 317 | { |
53d2f744 | 318 | struct snd_timer *timer = NULL; |
1da177e4 | 319 | struct list_head *p, *n; |
53d2f744 | 320 | struct snd_timer_instance *slave; |
1da177e4 LT |
321 | |
322 | snd_assert(timeri != NULL, return -ENXIO); | |
323 | ||
324 | /* force to stop the timer */ | |
325 | snd_timer_stop(timeri); | |
326 | ||
327 | if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) { | |
328 | /* wait, until the active callback is finished */ | |
329 | spin_lock_irq(&slave_active_lock); | |
330 | while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) { | |
331 | spin_unlock_irq(&slave_active_lock); | |
332 | udelay(10); | |
333 | spin_lock_irq(&slave_active_lock); | |
334 | } | |
335 | spin_unlock_irq(&slave_active_lock); | |
336 | down(®ister_mutex); | |
337 | list_del(&timeri->open_list); | |
338 | up(®ister_mutex); | |
339 | } else { | |
340 | timer = timeri->timer; | |
341 | /* wait, until the active callback is finished */ | |
342 | spin_lock_irq(&timer->lock); | |
343 | while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) { | |
344 | spin_unlock_irq(&timer->lock); | |
345 | udelay(10); | |
346 | spin_lock_irq(&timer->lock); | |
347 | } | |
348 | spin_unlock_irq(&timer->lock); | |
349 | down(®ister_mutex); | |
350 | list_del(&timeri->open_list); | |
6b172a85 CL |
351 | if (timer && list_empty(&timer->open_list_head) && |
352 | timer->hw.close) | |
1da177e4 LT |
353 | timer->hw.close(timer); |
354 | /* remove slave links */ | |
355 | list_for_each_safe(p, n, &timeri->slave_list_head) { | |
53d2f744 | 356 | slave = list_entry(p, struct snd_timer_instance, open_list); |
1da177e4 LT |
357 | spin_lock_irq(&slave_active_lock); |
358 | _snd_timer_stop(slave, 1, SNDRV_TIMER_EVENT_RESOLUTION); | |
359 | list_del(p); | |
360 | list_add_tail(p, &snd_timer_slave_list); | |
361 | slave->master = NULL; | |
362 | slave->timer = NULL; | |
363 | spin_unlock_irq(&slave_active_lock); | |
364 | } | |
365 | up(®ister_mutex); | |
366 | } | |
367 | if (timeri->private_free) | |
368 | timeri->private_free(timeri); | |
369 | kfree(timeri->owner); | |
370 | kfree(timeri); | |
de24214d CL |
371 | if (timer) |
372 | module_put(timer->module); | |
1da177e4 LT |
373 | return 0; |
374 | } | |
375 | ||
53d2f744 | 376 | unsigned long snd_timer_resolution(struct snd_timer_instance *timeri) |
1da177e4 | 377 | { |
53d2f744 | 378 | struct snd_timer * timer; |
1da177e4 LT |
379 | |
380 | if (timeri == NULL) | |
381 | return 0; | |
382 | if ((timer = timeri->timer) != NULL) { | |
383 | if (timer->hw.c_resolution) | |
384 | return timer->hw.c_resolution(timer); | |
385 | return timer->hw.resolution; | |
386 | } | |
387 | return 0; | |
388 | } | |
389 | ||
53d2f744 | 390 | static void snd_timer_notify1(struct snd_timer_instance *ti, int event) |
1da177e4 | 391 | { |
53d2f744 | 392 | struct snd_timer *timer; |
1da177e4 LT |
393 | unsigned long flags; |
394 | unsigned long resolution = 0; | |
53d2f744 | 395 | struct snd_timer_instance *ts; |
1da177e4 LT |
396 | struct list_head *n; |
397 | struct timespec tstamp; | |
398 | ||
07799e75 | 399 | getnstimeofday(&tstamp); |
6b172a85 CL |
400 | snd_assert(event >= SNDRV_TIMER_EVENT_START && |
401 | event <= SNDRV_TIMER_EVENT_PAUSE, return); | |
402 | if (event == SNDRV_TIMER_EVENT_START || | |
403 | event == SNDRV_TIMER_EVENT_CONTINUE) | |
1da177e4 LT |
404 | resolution = snd_timer_resolution(ti); |
405 | if (ti->ccallback) | |
406 | ti->ccallback(ti, SNDRV_TIMER_EVENT_START, &tstamp, resolution); | |
407 | if (ti->flags & SNDRV_TIMER_IFLG_SLAVE) | |
408 | return; | |
409 | timer = ti->timer; | |
410 | if (timer == NULL) | |
411 | return; | |
412 | if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) | |
413 | return; | |
414 | spin_lock_irqsave(&timer->lock, flags); | |
415 | list_for_each(n, &ti->slave_active_head) { | |
53d2f744 | 416 | ts = list_entry(n, struct snd_timer_instance, active_list); |
1da177e4 LT |
417 | if (ts->ccallback) |
418 | ts->ccallback(ti, event + 100, &tstamp, resolution); | |
419 | } | |
420 | spin_unlock_irqrestore(&timer->lock, flags); | |
421 | } | |
422 | ||
53d2f744 | 423 | static int snd_timer_start1(struct snd_timer *timer, struct snd_timer_instance *timeri, |
6b172a85 | 424 | unsigned long sticks) |
1da177e4 LT |
425 | { |
426 | list_del(&timeri->active_list); | |
427 | list_add_tail(&timeri->active_list, &timer->active_list_head); | |
428 | if (timer->running) { | |
429 | if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) | |
430 | goto __start_now; | |
431 | timer->flags |= SNDRV_TIMER_FLG_RESCHED; | |
432 | timeri->flags |= SNDRV_TIMER_IFLG_START; | |
433 | return 1; /* delayed start */ | |
434 | } else { | |
435 | timer->sticks = sticks; | |
436 | timer->hw.start(timer); | |
437 | __start_now: | |
438 | timer->running++; | |
439 | timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; | |
440 | return 0; | |
441 | } | |
442 | } | |
443 | ||
53d2f744 | 444 | static int snd_timer_start_slave(struct snd_timer_instance *timeri) |
1da177e4 LT |
445 | { |
446 | unsigned long flags; | |
447 | ||
448 | spin_lock_irqsave(&slave_active_lock, flags); | |
449 | timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; | |
450 | if (timeri->master) | |
6b172a85 CL |
451 | list_add_tail(&timeri->active_list, |
452 | &timeri->master->slave_active_head); | |
1da177e4 LT |
453 | spin_unlock_irqrestore(&slave_active_lock, flags); |
454 | return 1; /* delayed start */ | |
455 | } | |
456 | ||
457 | /* | |
458 | * start the timer instance | |
6b172a85 | 459 | */ |
53d2f744 | 460 | int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks) |
1da177e4 | 461 | { |
53d2f744 | 462 | struct snd_timer *timer; |
1da177e4 LT |
463 | int result = -EINVAL; |
464 | unsigned long flags; | |
465 | ||
466 | if (timeri == NULL || ticks < 1) | |
467 | return -EINVAL; | |
468 | if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) { | |
469 | result = snd_timer_start_slave(timeri); | |
470 | snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START); | |
471 | return result; | |
472 | } | |
473 | timer = timeri->timer; | |
474 | if (timer == NULL) | |
475 | return -EINVAL; | |
476 | spin_lock_irqsave(&timer->lock, flags); | |
477 | timeri->ticks = timeri->cticks = ticks; | |
478 | timeri->pticks = 0; | |
479 | result = snd_timer_start1(timer, timeri, ticks); | |
480 | spin_unlock_irqrestore(&timer->lock, flags); | |
481 | snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START); | |
482 | return result; | |
483 | } | |
484 | ||
53d2f744 TI |
485 | static int _snd_timer_stop(struct snd_timer_instance * timeri, |
486 | int keep_flag, int event) | |
1da177e4 | 487 | { |
53d2f744 | 488 | struct snd_timer *timer; |
1da177e4 LT |
489 | unsigned long flags; |
490 | ||
491 | snd_assert(timeri != NULL, return -ENXIO); | |
492 | ||
493 | if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) { | |
494 | if (!keep_flag) { | |
495 | spin_lock_irqsave(&slave_active_lock, flags); | |
496 | timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING; | |
497 | spin_unlock_irqrestore(&slave_active_lock, flags); | |
498 | } | |
499 | goto __end; | |
500 | } | |
501 | timer = timeri->timer; | |
502 | if (!timer) | |
503 | return -EINVAL; | |
504 | spin_lock_irqsave(&timer->lock, flags); | |
505 | list_del_init(&timeri->ack_list); | |
506 | list_del_init(&timeri->active_list); | |
507 | if ((timeri->flags & SNDRV_TIMER_IFLG_RUNNING) && | |
508 | !(--timer->running)) { | |
509 | timer->hw.stop(timer); | |
510 | if (timer->flags & SNDRV_TIMER_FLG_RESCHED) { | |
511 | timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; | |
512 | snd_timer_reschedule(timer, 0); | |
513 | if (timer->flags & SNDRV_TIMER_FLG_CHANGE) { | |
514 | timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; | |
515 | timer->hw.start(timer); | |
516 | } | |
517 | } | |
518 | } | |
519 | if (!keep_flag) | |
6b172a85 CL |
520 | timeri->flags &= |
521 | ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START); | |
1da177e4 LT |
522 | spin_unlock_irqrestore(&timer->lock, flags); |
523 | __end: | |
524 | if (event != SNDRV_TIMER_EVENT_RESOLUTION) | |
525 | snd_timer_notify1(timeri, event); | |
526 | return 0; | |
527 | } | |
528 | ||
529 | /* | |
530 | * stop the timer instance. | |
531 | * | |
532 | * do not call this from the timer callback! | |
533 | */ | |
53d2f744 | 534 | int snd_timer_stop(struct snd_timer_instance *timeri) |
1da177e4 | 535 | { |
53d2f744 | 536 | struct snd_timer *timer; |
1da177e4 LT |
537 | unsigned long flags; |
538 | int err; | |
539 | ||
540 | err = _snd_timer_stop(timeri, 0, SNDRV_TIMER_EVENT_STOP); | |
541 | if (err < 0) | |
542 | return err; | |
543 | timer = timeri->timer; | |
544 | spin_lock_irqsave(&timer->lock, flags); | |
545 | timeri->cticks = timeri->ticks; | |
546 | timeri->pticks = 0; | |
547 | spin_unlock_irqrestore(&timer->lock, flags); | |
548 | return 0; | |
549 | } | |
550 | ||
551 | /* | |
552 | * start again.. the tick is kept. | |
553 | */ | |
53d2f744 | 554 | int snd_timer_continue(struct snd_timer_instance *timeri) |
1da177e4 | 555 | { |
53d2f744 | 556 | struct snd_timer *timer; |
1da177e4 LT |
557 | int result = -EINVAL; |
558 | unsigned long flags; | |
559 | ||
560 | if (timeri == NULL) | |
561 | return result; | |
562 | if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) | |
563 | return snd_timer_start_slave(timeri); | |
564 | timer = timeri->timer; | |
565 | if (! timer) | |
566 | return -EINVAL; | |
567 | spin_lock_irqsave(&timer->lock, flags); | |
568 | if (!timeri->cticks) | |
569 | timeri->cticks = 1; | |
570 | timeri->pticks = 0; | |
571 | result = snd_timer_start1(timer, timeri, timer->sticks); | |
572 | spin_unlock_irqrestore(&timer->lock, flags); | |
573 | snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_CONTINUE); | |
574 | return result; | |
575 | } | |
576 | ||
577 | /* | |
578 | * pause.. remember the ticks left | |
579 | */ | |
53d2f744 | 580 | int snd_timer_pause(struct snd_timer_instance * timeri) |
1da177e4 LT |
581 | { |
582 | return _snd_timer_stop(timeri, 0, SNDRV_TIMER_EVENT_PAUSE); | |
583 | } | |
584 | ||
585 | /* | |
586 | * reschedule the timer | |
587 | * | |
588 | * start pending instances and check the scheduling ticks. | |
589 | * when the scheduling ticks is changed set CHANGE flag to reprogram the timer. | |
590 | */ | |
53d2f744 | 591 | static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left) |
1da177e4 | 592 | { |
53d2f744 | 593 | struct snd_timer_instance *ti; |
1da177e4 LT |
594 | unsigned long ticks = ~0UL; |
595 | struct list_head *p; | |
596 | ||
597 | list_for_each(p, &timer->active_list_head) { | |
53d2f744 | 598 | ti = list_entry(p, struct snd_timer_instance, active_list); |
1da177e4 LT |
599 | if (ti->flags & SNDRV_TIMER_IFLG_START) { |
600 | ti->flags &= ~SNDRV_TIMER_IFLG_START; | |
601 | ti->flags |= SNDRV_TIMER_IFLG_RUNNING; | |
602 | timer->running++; | |
603 | } | |
604 | if (ti->flags & SNDRV_TIMER_IFLG_RUNNING) { | |
605 | if (ticks > ti->cticks) | |
606 | ticks = ti->cticks; | |
607 | } | |
608 | } | |
609 | if (ticks == ~0UL) { | |
610 | timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; | |
611 | return; | |
612 | } | |
613 | if (ticks > timer->hw.ticks) | |
614 | ticks = timer->hw.ticks; | |
615 | if (ticks_left != ticks) | |
616 | timer->flags |= SNDRV_TIMER_FLG_CHANGE; | |
617 | timer->sticks = ticks; | |
618 | } | |
619 | ||
620 | /* | |
621 | * timer tasklet | |
622 | * | |
623 | */ | |
624 | static void snd_timer_tasklet(unsigned long arg) | |
625 | { | |
53d2f744 TI |
626 | struct snd_timer *timer = (struct snd_timer *) arg; |
627 | struct snd_timer_instance *ti; | |
1da177e4 LT |
628 | struct list_head *p; |
629 | unsigned long resolution, ticks; | |
630 | ||
631 | spin_lock(&timer->lock); | |
632 | /* now process all callbacks */ | |
633 | while (!list_empty(&timer->sack_list_head)) { | |
634 | p = timer->sack_list_head.next; /* get first item */ | |
53d2f744 | 635 | ti = list_entry(p, struct snd_timer_instance, ack_list); |
1da177e4 LT |
636 | |
637 | /* remove from ack_list and make empty */ | |
638 | list_del_init(p); | |
6b172a85 | 639 | |
1da177e4 LT |
640 | ticks = ti->pticks; |
641 | ti->pticks = 0; | |
642 | resolution = ti->resolution; | |
643 | ||
644 | ti->flags |= SNDRV_TIMER_IFLG_CALLBACK; | |
645 | spin_unlock(&timer->lock); | |
646 | if (ti->callback) | |
647 | ti->callback(ti, resolution, ticks); | |
648 | spin_lock(&timer->lock); | |
649 | ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK; | |
650 | } | |
651 | spin_unlock(&timer->lock); | |
652 | } | |
653 | ||
654 | /* | |
655 | * timer interrupt | |
656 | * | |
657 | * ticks_left is usually equal to timer->sticks. | |
658 | * | |
659 | */ | |
53d2f744 | 660 | void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) |
1da177e4 | 661 | { |
53d2f744 | 662 | struct snd_timer_instance *ti, *ts; |
1da177e4 | 663 | unsigned long resolution, ticks; |
6b172a85 | 664 | struct list_head *p, *q, *n, *ack_list_head; |
1da177e4 LT |
665 | int use_tasklet = 0; |
666 | ||
667 | if (timer == NULL) | |
668 | return; | |
669 | ||
670 | spin_lock(&timer->lock); | |
671 | ||
672 | /* remember the current resolution */ | |
673 | if (timer->hw.c_resolution) | |
674 | resolution = timer->hw.c_resolution(timer); | |
675 | else | |
676 | resolution = timer->hw.resolution; | |
677 | ||
678 | /* loop for all active instances | |
6b172a85 CL |
679 | * Here we cannot use list_for_each because the active_list of a |
680 | * processed instance is relinked to done_list_head before the callback | |
681 | * is called. | |
1da177e4 LT |
682 | */ |
683 | list_for_each_safe(p, n, &timer->active_list_head) { | |
53d2f744 | 684 | ti = list_entry(p, struct snd_timer_instance, active_list); |
1da177e4 LT |
685 | if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING)) |
686 | continue; | |
687 | ti->pticks += ticks_left; | |
688 | ti->resolution = resolution; | |
689 | if (ti->cticks < ticks_left) | |
690 | ti->cticks = 0; | |
691 | else | |
692 | ti->cticks -= ticks_left; | |
693 | if (ti->cticks) /* not expired */ | |
694 | continue; | |
695 | if (ti->flags & SNDRV_TIMER_IFLG_AUTO) { | |
696 | ti->cticks = ti->ticks; | |
697 | } else { | |
698 | ti->flags &= ~SNDRV_TIMER_IFLG_RUNNING; | |
699 | if (--timer->running) | |
700 | list_del(p); | |
701 | } | |
6b172a85 CL |
702 | if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) || |
703 | (ti->flags & SNDRV_TIMER_IFLG_FAST)) | |
704 | ack_list_head = &timer->ack_list_head; | |
705 | else | |
706 | ack_list_head = &timer->sack_list_head; | |
707 | if (list_empty(&ti->ack_list)) | |
708 | list_add_tail(&ti->ack_list, ack_list_head); | |
1da177e4 | 709 | list_for_each(q, &ti->slave_active_head) { |
53d2f744 | 710 | ts = list_entry(q, struct snd_timer_instance, active_list); |
1da177e4 LT |
711 | ts->pticks = ti->pticks; |
712 | ts->resolution = resolution; | |
6b172a85 CL |
713 | if (list_empty(&ts->ack_list)) |
714 | list_add_tail(&ts->ack_list, ack_list_head); | |
1da177e4 LT |
715 | } |
716 | } | |
717 | if (timer->flags & SNDRV_TIMER_FLG_RESCHED) | |
718 | snd_timer_reschedule(timer, ticks_left); | |
719 | if (timer->running) { | |
720 | if (timer->hw.flags & SNDRV_TIMER_HW_STOP) { | |
721 | timer->hw.stop(timer); | |
722 | timer->flags |= SNDRV_TIMER_FLG_CHANGE; | |
723 | } | |
724 | if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) || | |
725 | (timer->flags & SNDRV_TIMER_FLG_CHANGE)) { | |
726 | /* restart timer */ | |
727 | timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; | |
728 | timer->hw.start(timer); | |
729 | } | |
730 | } else { | |
731 | timer->hw.stop(timer); | |
732 | } | |
733 | ||
734 | /* now process all fast callbacks */ | |
735 | while (!list_empty(&timer->ack_list_head)) { | |
736 | p = timer->ack_list_head.next; /* get first item */ | |
53d2f744 | 737 | ti = list_entry(p, struct snd_timer_instance, ack_list); |
6b172a85 | 738 | |
1da177e4 LT |
739 | /* remove from ack_list and make empty */ |
740 | list_del_init(p); | |
6b172a85 | 741 | |
1da177e4 LT |
742 | ticks = ti->pticks; |
743 | ti->pticks = 0; | |
744 | ||
745 | ti->flags |= SNDRV_TIMER_IFLG_CALLBACK; | |
746 | spin_unlock(&timer->lock); | |
747 | if (ti->callback) | |
748 | ti->callback(ti, resolution, ticks); | |
749 | spin_lock(&timer->lock); | |
750 | ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK; | |
751 | } | |
752 | ||
753 | /* do we have any slow callbacks? */ | |
754 | use_tasklet = !list_empty(&timer->sack_list_head); | |
755 | spin_unlock(&timer->lock); | |
756 | ||
757 | if (use_tasklet) | |
758 | tasklet_hi_schedule(&timer->task_queue); | |
759 | } | |
760 | ||
761 | /* | |
762 | ||
763 | */ | |
764 | ||
53d2f744 TI |
765 | int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, |
766 | struct snd_timer **rtimer) | |
1da177e4 | 767 | { |
53d2f744 | 768 | struct snd_timer *timer; |
1da177e4 | 769 | int err; |
53d2f744 | 770 | static struct snd_device_ops ops = { |
1da177e4 LT |
771 | .dev_free = snd_timer_dev_free, |
772 | .dev_register = snd_timer_dev_register, | |
773 | .dev_unregister = snd_timer_dev_unregister | |
774 | }; | |
775 | ||
776 | snd_assert(tid != NULL, return -EINVAL); | |
777 | snd_assert(rtimer != NULL, return -EINVAL); | |
778 | *rtimer = NULL; | |
ca2c0966 | 779 | timer = kzalloc(sizeof(*timer), GFP_KERNEL); |
73e77ba0 TI |
780 | if (timer == NULL) { |
781 | snd_printk(KERN_ERR "timer: cannot allocate\n"); | |
1da177e4 | 782 | return -ENOMEM; |
73e77ba0 | 783 | } |
1da177e4 LT |
784 | timer->tmr_class = tid->dev_class; |
785 | timer->card = card; | |
786 | timer->tmr_device = tid->device; | |
787 | timer->tmr_subdevice = tid->subdevice; | |
788 | if (id) | |
789 | strlcpy(timer->id, id, sizeof(timer->id)); | |
790 | INIT_LIST_HEAD(&timer->device_list); | |
791 | INIT_LIST_HEAD(&timer->open_list_head); | |
792 | INIT_LIST_HEAD(&timer->active_list_head); | |
793 | INIT_LIST_HEAD(&timer->ack_list_head); | |
794 | INIT_LIST_HEAD(&timer->sack_list_head); | |
795 | spin_lock_init(&timer->lock); | |
6b172a85 CL |
796 | tasklet_init(&timer->task_queue, snd_timer_tasklet, |
797 | (unsigned long)timer); | |
1da177e4 | 798 | if (card != NULL) { |
de24214d | 799 | timer->module = card->module; |
6b172a85 CL |
800 | err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops); |
801 | if (err < 0) { | |
1da177e4 LT |
802 | snd_timer_free(timer); |
803 | return err; | |
804 | } | |
805 | } | |
806 | *rtimer = timer; | |
807 | return 0; | |
808 | } | |
809 | ||
53d2f744 | 810 | static int snd_timer_free(struct snd_timer *timer) |
1da177e4 LT |
811 | { |
812 | snd_assert(timer != NULL, return -ENXIO); | |
813 | if (timer->private_free) | |
814 | timer->private_free(timer); | |
815 | kfree(timer); | |
816 | return 0; | |
817 | } | |
818 | ||
53d2f744 | 819 | static int snd_timer_dev_free(struct snd_device *device) |
1da177e4 | 820 | { |
53d2f744 | 821 | struct snd_timer *timer = device->device_data; |
1da177e4 LT |
822 | return snd_timer_free(timer); |
823 | } | |
824 | ||
53d2f744 | 825 | static int snd_timer_dev_register(struct snd_device *dev) |
1da177e4 | 826 | { |
53d2f744 TI |
827 | struct snd_timer *timer = dev->device_data; |
828 | struct snd_timer *timer1; | |
1da177e4 LT |
829 | struct list_head *p; |
830 | ||
6b172a85 CL |
831 | snd_assert(timer != NULL && timer->hw.start != NULL && |
832 | timer->hw.stop != NULL, return -ENXIO); | |
1da177e4 LT |
833 | if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && |
834 | !timer->hw.resolution && timer->hw.c_resolution == NULL) | |
835 | return -EINVAL; | |
836 | ||
837 | down(®ister_mutex); | |
838 | list_for_each(p, &snd_timer_list) { | |
53d2f744 | 839 | timer1 = list_entry(p, struct snd_timer, device_list); |
1da177e4 LT |
840 | if (timer1->tmr_class > timer->tmr_class) |
841 | break; | |
842 | if (timer1->tmr_class < timer->tmr_class) | |
843 | continue; | |
844 | if (timer1->card && timer->card) { | |
845 | if (timer1->card->number > timer->card->number) | |
846 | break; | |
847 | if (timer1->card->number < timer->card->number) | |
848 | continue; | |
849 | } | |
850 | if (timer1->tmr_device > timer->tmr_device) | |
851 | break; | |
852 | if (timer1->tmr_device < timer->tmr_device) | |
853 | continue; | |
854 | if (timer1->tmr_subdevice > timer->tmr_subdevice) | |
855 | break; | |
856 | if (timer1->tmr_subdevice < timer->tmr_subdevice) | |
857 | continue; | |
858 | /* conflicts.. */ | |
859 | up(®ister_mutex); | |
860 | return -EBUSY; | |
861 | } | |
862 | list_add_tail(&timer->device_list, p); | |
863 | up(®ister_mutex); | |
864 | return 0; | |
865 | } | |
866 | ||
53d2f744 | 867 | static int snd_timer_unregister(struct snd_timer *timer) |
1da177e4 LT |
868 | { |
869 | struct list_head *p, *n; | |
53d2f744 | 870 | struct snd_timer_instance *ti; |
1da177e4 LT |
871 | |
872 | snd_assert(timer != NULL, return -ENXIO); | |
873 | down(®ister_mutex); | |
874 | if (! list_empty(&timer->open_list_head)) { | |
875 | snd_printk(KERN_WARNING "timer 0x%lx is busy?\n", (long)timer); | |
876 | list_for_each_safe(p, n, &timer->open_list_head) { | |
877 | list_del_init(p); | |
53d2f744 | 878 | ti = list_entry(p, struct snd_timer_instance, open_list); |
1da177e4 LT |
879 | ti->timer = NULL; |
880 | } | |
881 | } | |
882 | list_del(&timer->device_list); | |
883 | up(®ister_mutex); | |
884 | return snd_timer_free(timer); | |
885 | } | |
886 | ||
53d2f744 | 887 | static int snd_timer_dev_unregister(struct snd_device *device) |
1da177e4 | 888 | { |
53d2f744 | 889 | struct snd_timer *timer = device->device_data; |
1da177e4 LT |
890 | return snd_timer_unregister(timer); |
891 | } | |
892 | ||
53d2f744 | 893 | void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp) |
1da177e4 LT |
894 | { |
895 | unsigned long flags; | |
896 | unsigned long resolution = 0; | |
53d2f744 | 897 | struct snd_timer_instance *ti, *ts; |
1da177e4 LT |
898 | struct list_head *p, *n; |
899 | ||
7c22f1aa TI |
900 | if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) |
901 | return; | |
6b172a85 CL |
902 | snd_assert(event >= SNDRV_TIMER_EVENT_MSTART && |
903 | event <= SNDRV_TIMER_EVENT_MRESUME, return); | |
1da177e4 | 904 | spin_lock_irqsave(&timer->lock, flags); |
a501dfa3 JK |
905 | if (event == SNDRV_TIMER_EVENT_MSTART || |
906 | event == SNDRV_TIMER_EVENT_MCONTINUE || | |
907 | event == SNDRV_TIMER_EVENT_MRESUME) { | |
1da177e4 LT |
908 | if (timer->hw.c_resolution) |
909 | resolution = timer->hw.c_resolution(timer); | |
910 | else | |
911 | resolution = timer->hw.resolution; | |
912 | } | |
913 | list_for_each(p, &timer->active_list_head) { | |
53d2f744 | 914 | ti = list_entry(p, struct snd_timer_instance, active_list); |
1da177e4 LT |
915 | if (ti->ccallback) |
916 | ti->ccallback(ti, event, tstamp, resolution); | |
917 | list_for_each(n, &ti->slave_active_head) { | |
53d2f744 | 918 | ts = list_entry(n, struct snd_timer_instance, active_list); |
1da177e4 LT |
919 | if (ts->ccallback) |
920 | ts->ccallback(ts, event, tstamp, resolution); | |
921 | } | |
922 | } | |
923 | spin_unlock_irqrestore(&timer->lock, flags); | |
924 | } | |
925 | ||
926 | /* | |
927 | * exported functions for global timers | |
928 | */ | |
53d2f744 | 929 | int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer) |
1da177e4 | 930 | { |
53d2f744 | 931 | struct snd_timer_id tid; |
6b172a85 | 932 | |
1da177e4 LT |
933 | tid.dev_class = SNDRV_TIMER_CLASS_GLOBAL; |
934 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; | |
935 | tid.card = -1; | |
936 | tid.device = device; | |
937 | tid.subdevice = 0; | |
938 | return snd_timer_new(NULL, id, &tid, rtimer); | |
939 | } | |
940 | ||
53d2f744 | 941 | int snd_timer_global_free(struct snd_timer *timer) |
1da177e4 LT |
942 | { |
943 | return snd_timer_free(timer); | |
944 | } | |
945 | ||
53d2f744 | 946 | int snd_timer_global_register(struct snd_timer *timer) |
1da177e4 | 947 | { |
53d2f744 | 948 | struct snd_device dev; |
1da177e4 LT |
949 | |
950 | memset(&dev, 0, sizeof(dev)); | |
951 | dev.device_data = timer; | |
952 | return snd_timer_dev_register(&dev); | |
953 | } | |
954 | ||
53d2f744 | 955 | int snd_timer_global_unregister(struct snd_timer *timer) |
1da177e4 LT |
956 | { |
957 | return snd_timer_unregister(timer); | |
958 | } | |
959 | ||
6b172a85 | 960 | /* |
1da177e4 LT |
961 | * System timer |
962 | */ | |
963 | ||
964 | struct snd_timer_system_private { | |
965 | struct timer_list tlist; | |
966 | struct timer * timer; | |
967 | unsigned long last_expires; | |
968 | unsigned long last_jiffies; | |
969 | unsigned long correction; | |
970 | }; | |
971 | ||
1da177e4 LT |
972 | static void snd_timer_s_function(unsigned long data) |
973 | { | |
53d2f744 | 974 | struct snd_timer *timer = (struct snd_timer *)data; |
1da177e4 LT |
975 | struct snd_timer_system_private *priv = timer->private_data; |
976 | unsigned long jiff = jiffies; | |
977 | if (time_after(jiff, priv->last_expires)) | |
978 | priv->correction = (long)jiff - (long)priv->last_expires; | |
979 | snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies); | |
980 | } | |
981 | ||
53d2f744 | 982 | static int snd_timer_s_start(struct snd_timer * timer) |
1da177e4 LT |
983 | { |
984 | struct snd_timer_system_private *priv; | |
985 | unsigned long njiff; | |
986 | ||
987 | priv = (struct snd_timer_system_private *) timer->private_data; | |
988 | njiff = (priv->last_jiffies = jiffies); | |
989 | if (priv->correction > timer->sticks - 1) { | |
990 | priv->correction -= timer->sticks - 1; | |
991 | njiff++; | |
992 | } else { | |
993 | njiff += timer->sticks - priv->correction; | |
994 | priv->correction -= timer->sticks; | |
995 | } | |
996 | priv->last_expires = priv->tlist.expires = njiff; | |
997 | add_timer(&priv->tlist); | |
998 | return 0; | |
999 | } | |
1000 | ||
53d2f744 | 1001 | static int snd_timer_s_stop(struct snd_timer * timer) |
1da177e4 LT |
1002 | { |
1003 | struct snd_timer_system_private *priv; | |
1004 | unsigned long jiff; | |
1005 | ||
1006 | priv = (struct snd_timer_system_private *) timer->private_data; | |
1007 | del_timer(&priv->tlist); | |
1008 | jiff = jiffies; | |
1009 | if (time_before(jiff, priv->last_expires)) | |
1010 | timer->sticks = priv->last_expires - jiff; | |
1011 | else | |
1012 | timer->sticks = 1; | |
1013 | return 0; | |
1014 | } | |
1015 | ||
53d2f744 | 1016 | static struct snd_timer_hardware snd_timer_system = |
1da177e4 LT |
1017 | { |
1018 | .flags = SNDRV_TIMER_HW_FIRST | SNDRV_TIMER_HW_TASKLET, | |
1019 | .resolution = 1000000000L / HZ, | |
1020 | .ticks = 10000000L, | |
1021 | .start = snd_timer_s_start, | |
1022 | .stop = snd_timer_s_stop | |
1023 | }; | |
1024 | ||
53d2f744 | 1025 | static void snd_timer_free_system(struct snd_timer *timer) |
1da177e4 LT |
1026 | { |
1027 | kfree(timer->private_data); | |
1028 | } | |
1029 | ||
1030 | static int snd_timer_register_system(void) | |
1031 | { | |
53d2f744 | 1032 | struct snd_timer *timer; |
1da177e4 LT |
1033 | struct snd_timer_system_private *priv; |
1034 | int err; | |
1035 | ||
6b172a85 CL |
1036 | err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer); |
1037 | if (err < 0) | |
1da177e4 LT |
1038 | return err; |
1039 | strcpy(timer->name, "system timer"); | |
1040 | timer->hw = snd_timer_system; | |
ca2c0966 | 1041 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
1da177e4 LT |
1042 | if (priv == NULL) { |
1043 | snd_timer_free(timer); | |
1044 | return -ENOMEM; | |
1045 | } | |
1046 | init_timer(&priv->tlist); | |
1047 | priv->tlist.function = snd_timer_s_function; | |
1048 | priv->tlist.data = (unsigned long) timer; | |
1049 | timer->private_data = priv; | |
1050 | timer->private_free = snd_timer_free_system; | |
1051 | return snd_timer_global_register(timer); | |
1052 | } | |
1053 | ||
1054 | /* | |
1055 | * Info interface | |
1056 | */ | |
1057 | ||
53d2f744 TI |
1058 | static void snd_timer_proc_read(struct snd_info_entry *entry, |
1059 | struct snd_info_buffer *buffer) | |
1da177e4 LT |
1060 | { |
1061 | unsigned long flags; | |
53d2f744 TI |
1062 | struct snd_timer *timer; |
1063 | struct snd_timer_instance *ti; | |
1da177e4 LT |
1064 | struct list_head *p, *q; |
1065 | ||
1066 | down(®ister_mutex); | |
1067 | list_for_each(p, &snd_timer_list) { | |
53d2f744 | 1068 | timer = list_entry(p, struct snd_timer, device_list); |
1da177e4 LT |
1069 | switch (timer->tmr_class) { |
1070 | case SNDRV_TIMER_CLASS_GLOBAL: | |
1071 | snd_iprintf(buffer, "G%i: ", timer->tmr_device); | |
1072 | break; | |
1073 | case SNDRV_TIMER_CLASS_CARD: | |
6b172a85 CL |
1074 | snd_iprintf(buffer, "C%i-%i: ", |
1075 | timer->card->number, timer->tmr_device); | |
1da177e4 LT |
1076 | break; |
1077 | case SNDRV_TIMER_CLASS_PCM: | |
6b172a85 CL |
1078 | snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, |
1079 | timer->tmr_device, timer->tmr_subdevice); | |
1da177e4 LT |
1080 | break; |
1081 | default: | |
6b172a85 CL |
1082 | snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class, |
1083 | timer->card ? timer->card->number : -1, | |
1084 | timer->tmr_device, timer->tmr_subdevice); | |
1da177e4 LT |
1085 | } |
1086 | snd_iprintf(buffer, "%s :", timer->name); | |
1087 | if (timer->hw.resolution) | |
6b172a85 CL |
1088 | snd_iprintf(buffer, " %lu.%03luus (%lu ticks)", |
1089 | timer->hw.resolution / 1000, | |
1090 | timer->hw.resolution % 1000, | |
1091 | timer->hw.ticks); | |
1da177e4 LT |
1092 | if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) |
1093 | snd_iprintf(buffer, " SLAVE"); | |
1094 | snd_iprintf(buffer, "\n"); | |
1095 | spin_lock_irqsave(&timer->lock, flags); | |
1096 | list_for_each(q, &timer->open_list_head) { | |
53d2f744 | 1097 | ti = list_entry(q, struct snd_timer_instance, open_list); |
6b172a85 CL |
1098 | snd_iprintf(buffer, " Client %s : %s\n", |
1099 | ti->owner ? ti->owner : "unknown", | |
1100 | ti->flags & (SNDRV_TIMER_IFLG_START | | |
1101 | SNDRV_TIMER_IFLG_RUNNING) | |
1102 | ? "running" : "stopped"); | |
1da177e4 LT |
1103 | } |
1104 | spin_unlock_irqrestore(&timer->lock, flags); | |
1105 | } | |
1106 | up(®ister_mutex); | |
1107 | } | |
1108 | ||
1109 | /* | |
1110 | * USER SPACE interface | |
1111 | */ | |
1112 | ||
53d2f744 | 1113 | static void snd_timer_user_interrupt(struct snd_timer_instance *timeri, |
1da177e4 LT |
1114 | unsigned long resolution, |
1115 | unsigned long ticks) | |
1116 | { | |
53d2f744 TI |
1117 | struct snd_timer_user *tu = timeri->callback_data; |
1118 | struct snd_timer_read *r; | |
1da177e4 | 1119 | int prev; |
6b172a85 | 1120 | |
1da177e4 LT |
1121 | spin_lock(&tu->qlock); |
1122 | if (tu->qused > 0) { | |
1123 | prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; | |
1124 | r = &tu->queue[prev]; | |
1125 | if (r->resolution == resolution) { | |
1126 | r->ticks += ticks; | |
1127 | goto __wake; | |
1128 | } | |
1129 | } | |
1130 | if (tu->qused >= tu->queue_size) { | |
1131 | tu->overrun++; | |
1132 | } else { | |
1133 | r = &tu->queue[tu->qtail++]; | |
1134 | tu->qtail %= tu->queue_size; | |
1135 | r->resolution = resolution; | |
1136 | r->ticks = ticks; | |
1137 | tu->qused++; | |
1138 | } | |
1139 | __wake: | |
1140 | spin_unlock(&tu->qlock); | |
1141 | kill_fasync(&tu->fasync, SIGIO, POLL_IN); | |
1142 | wake_up(&tu->qchange_sleep); | |
1143 | } | |
1144 | ||
53d2f744 TI |
1145 | static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu, |
1146 | struct snd_timer_tread *tread) | |
1da177e4 LT |
1147 | { |
1148 | if (tu->qused >= tu->queue_size) { | |
1149 | tu->overrun++; | |
1150 | } else { | |
1151 | memcpy(&tu->tqueue[tu->qtail++], tread, sizeof(*tread)); | |
1152 | tu->qtail %= tu->queue_size; | |
1153 | tu->qused++; | |
1154 | } | |
1155 | } | |
1156 | ||
53d2f744 TI |
1157 | static void snd_timer_user_ccallback(struct snd_timer_instance *timeri, |
1158 | int event, | |
1da177e4 LT |
1159 | struct timespec *tstamp, |
1160 | unsigned long resolution) | |
1161 | { | |
53d2f744 TI |
1162 | struct snd_timer_user *tu = timeri->callback_data; |
1163 | struct snd_timer_tread r1; | |
1da177e4 | 1164 | |
6b172a85 CL |
1165 | if (event >= SNDRV_TIMER_EVENT_START && |
1166 | event <= SNDRV_TIMER_EVENT_PAUSE) | |
1da177e4 LT |
1167 | tu->tstamp = *tstamp; |
1168 | if ((tu->filter & (1 << event)) == 0 || !tu->tread) | |
1169 | return; | |
1170 | r1.event = event; | |
1171 | r1.tstamp = *tstamp; | |
1172 | r1.val = resolution; | |
1173 | spin_lock(&tu->qlock); | |
1174 | snd_timer_user_append_to_tqueue(tu, &r1); | |
1175 | spin_unlock(&tu->qlock); | |
1176 | kill_fasync(&tu->fasync, SIGIO, POLL_IN); | |
1177 | wake_up(&tu->qchange_sleep); | |
1178 | } | |
1179 | ||
53d2f744 | 1180 | static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri, |
1da177e4 LT |
1181 | unsigned long resolution, |
1182 | unsigned long ticks) | |
1183 | { | |
53d2f744 TI |
1184 | struct snd_timer_user *tu = timeri->callback_data; |
1185 | struct snd_timer_tread *r, r1; | |
1da177e4 LT |
1186 | struct timespec tstamp; |
1187 | int prev, append = 0; | |
1188 | ||
07799e75 | 1189 | memset(&tstamp, 0, sizeof(tstamp)); |
1da177e4 | 1190 | spin_lock(&tu->qlock); |
6b172a85 CL |
1191 | if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) | |
1192 | (1 << SNDRV_TIMER_EVENT_TICK))) == 0) { | |
1da177e4 LT |
1193 | spin_unlock(&tu->qlock); |
1194 | return; | |
1195 | } | |
1196 | if (tu->last_resolution != resolution || ticks > 0) | |
07799e75 | 1197 | getnstimeofday(&tstamp); |
6b172a85 CL |
1198 | if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && |
1199 | tu->last_resolution != resolution) { | |
1da177e4 LT |
1200 | r1.event = SNDRV_TIMER_EVENT_RESOLUTION; |
1201 | r1.tstamp = tstamp; | |
1202 | r1.val = resolution; | |
1203 | snd_timer_user_append_to_tqueue(tu, &r1); | |
1204 | tu->last_resolution = resolution; | |
1205 | append++; | |
1206 | } | |
1207 | if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0) | |
1208 | goto __wake; | |
1209 | if (ticks == 0) | |
1210 | goto __wake; | |
1211 | if (tu->qused > 0) { | |
1212 | prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; | |
1213 | r = &tu->tqueue[prev]; | |
1214 | if (r->event == SNDRV_TIMER_EVENT_TICK) { | |
1215 | r->tstamp = tstamp; | |
1216 | r->val += ticks; | |
1217 | append++; | |
1218 | goto __wake; | |
1219 | } | |
1220 | } | |
1221 | r1.event = SNDRV_TIMER_EVENT_TICK; | |
1222 | r1.tstamp = tstamp; | |
1223 | r1.val = ticks; | |
1224 | snd_timer_user_append_to_tqueue(tu, &r1); | |
1225 | append++; | |
1226 | __wake: | |
1227 | spin_unlock(&tu->qlock); | |
1228 | if (append == 0) | |
1229 | return; | |
1230 | kill_fasync(&tu->fasync, SIGIO, POLL_IN); | |
1231 | wake_up(&tu->qchange_sleep); | |
1232 | } | |
1233 | ||
1234 | static int snd_timer_user_open(struct inode *inode, struct file *file) | |
1235 | { | |
53d2f744 | 1236 | struct snd_timer_user *tu; |
6b172a85 | 1237 | |
ca2c0966 | 1238 | tu = kzalloc(sizeof(*tu), GFP_KERNEL); |
1da177e4 LT |
1239 | if (tu == NULL) |
1240 | return -ENOMEM; | |
1241 | spin_lock_init(&tu->qlock); | |
1242 | init_waitqueue_head(&tu->qchange_sleep); | |
c1935b4d | 1243 | init_MUTEX(&tu->tread_sem); |
1da177e4 LT |
1244 | tu->ticks = 1; |
1245 | tu->queue_size = 128; | |
53d2f744 | 1246 | tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read), |
6b172a85 | 1247 | GFP_KERNEL); |
1da177e4 LT |
1248 | if (tu->queue == NULL) { |
1249 | kfree(tu); | |
1250 | return -ENOMEM; | |
1251 | } | |
1252 | file->private_data = tu; | |
1253 | return 0; | |
1254 | } | |
1255 | ||
1256 | static int snd_timer_user_release(struct inode *inode, struct file *file) | |
1257 | { | |
53d2f744 | 1258 | struct snd_timer_user *tu; |
1da177e4 LT |
1259 | |
1260 | if (file->private_data) { | |
1261 | tu = file->private_data; | |
1262 | file->private_data = NULL; | |
1263 | fasync_helper(-1, file, 0, &tu->fasync); | |
1264 | if (tu->timeri) | |
1265 | snd_timer_close(tu->timeri); | |
1266 | kfree(tu->queue); | |
1267 | kfree(tu->tqueue); | |
1268 | kfree(tu); | |
1269 | } | |
1270 | return 0; | |
1271 | } | |
1272 | ||
53d2f744 | 1273 | static void snd_timer_user_zero_id(struct snd_timer_id *id) |
1da177e4 LT |
1274 | { |
1275 | id->dev_class = SNDRV_TIMER_CLASS_NONE; | |
1276 | id->dev_sclass = SNDRV_TIMER_SCLASS_NONE; | |
1277 | id->card = -1; | |
1278 | id->device = -1; | |
1279 | id->subdevice = -1; | |
1280 | } | |
1281 | ||
53d2f744 | 1282 | static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *timer) |
1da177e4 LT |
1283 | { |
1284 | id->dev_class = timer->tmr_class; | |
1285 | id->dev_sclass = SNDRV_TIMER_SCLASS_NONE; | |
1286 | id->card = timer->card ? timer->card->number : -1; | |
1287 | id->device = timer->tmr_device; | |
1288 | id->subdevice = timer->tmr_subdevice; | |
1289 | } | |
1290 | ||
53d2f744 | 1291 | static int snd_timer_user_next_device(struct snd_timer_id __user *_tid) |
1da177e4 | 1292 | { |
53d2f744 TI |
1293 | struct snd_timer_id id; |
1294 | struct snd_timer *timer; | |
1da177e4 | 1295 | struct list_head *p; |
6b172a85 | 1296 | |
1da177e4 LT |
1297 | if (copy_from_user(&id, _tid, sizeof(id))) |
1298 | return -EFAULT; | |
1299 | down(®ister_mutex); | |
1300 | if (id.dev_class < 0) { /* first item */ | |
1301 | if (list_empty(&snd_timer_list)) | |
1302 | snd_timer_user_zero_id(&id); | |
1303 | else { | |
9dfba380 | 1304 | timer = list_entry(snd_timer_list.next, |
53d2f744 | 1305 | struct snd_timer, device_list); |
1da177e4 LT |
1306 | snd_timer_user_copy_id(&id, timer); |
1307 | } | |
1308 | } else { | |
1309 | switch (id.dev_class) { | |
1310 | case SNDRV_TIMER_CLASS_GLOBAL: | |
1311 | id.device = id.device < 0 ? 0 : id.device + 1; | |
1312 | list_for_each(p, &snd_timer_list) { | |
53d2f744 | 1313 | timer = list_entry(p, struct snd_timer, device_list); |
1da177e4 LT |
1314 | if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) { |
1315 | snd_timer_user_copy_id(&id, timer); | |
1316 | break; | |
1317 | } | |
1318 | if (timer->tmr_device >= id.device) { | |
1319 | snd_timer_user_copy_id(&id, timer); | |
1320 | break; | |
1321 | } | |
1322 | } | |
1323 | if (p == &snd_timer_list) | |
1324 | snd_timer_user_zero_id(&id); | |
1325 | break; | |
1326 | case SNDRV_TIMER_CLASS_CARD: | |
1327 | case SNDRV_TIMER_CLASS_PCM: | |
1328 | if (id.card < 0) { | |
1329 | id.card = 0; | |
1330 | } else { | |
1331 | if (id.card < 0) { | |
1332 | id.card = 0; | |
1333 | } else { | |
1334 | if (id.device < 0) { | |
1335 | id.device = 0; | |
1336 | } else { | |
6b172a85 CL |
1337 | if (id.subdevice < 0) { |
1338 | id.subdevice = 0; | |
1339 | } else { | |
1340 | id.subdevice++; | |
1341 | } | |
1da177e4 LT |
1342 | } |
1343 | } | |
1344 | } | |
1345 | list_for_each(p, &snd_timer_list) { | |
53d2f744 | 1346 | timer = list_entry(p, struct snd_timer, device_list); |
1da177e4 LT |
1347 | if (timer->tmr_class > id.dev_class) { |
1348 | snd_timer_user_copy_id(&id, timer); | |
1349 | break; | |
1350 | } | |
1351 | if (timer->tmr_class < id.dev_class) | |
1352 | continue; | |
1353 | if (timer->card->number > id.card) { | |
1354 | snd_timer_user_copy_id(&id, timer); | |
1355 | break; | |
1356 | } | |
1357 | if (timer->card->number < id.card) | |
1358 | continue; | |
1359 | if (timer->tmr_device > id.device) { | |
1360 | snd_timer_user_copy_id(&id, timer); | |
1361 | break; | |
1362 | } | |
1363 | if (timer->tmr_device < id.device) | |
1364 | continue; | |
1365 | if (timer->tmr_subdevice > id.subdevice) { | |
1366 | snd_timer_user_copy_id(&id, timer); | |
1367 | break; | |
1368 | } | |
1369 | if (timer->tmr_subdevice < id.subdevice) | |
1370 | continue; | |
1371 | snd_timer_user_copy_id(&id, timer); | |
1372 | break; | |
1373 | } | |
1374 | if (p == &snd_timer_list) | |
1375 | snd_timer_user_zero_id(&id); | |
1376 | break; | |
1377 | default: | |
1378 | snd_timer_user_zero_id(&id); | |
1379 | } | |
1380 | } | |
1381 | up(®ister_mutex); | |
1382 | if (copy_to_user(_tid, &id, sizeof(*_tid))) | |
1383 | return -EFAULT; | |
1384 | return 0; | |
6b172a85 | 1385 | } |
1da177e4 | 1386 | |
6b172a85 | 1387 | static int snd_timer_user_ginfo(struct file *file, |
53d2f744 | 1388 | struct snd_timer_ginfo __user *_ginfo) |
1da177e4 | 1389 | { |
53d2f744 TI |
1390 | struct snd_timer_ginfo *ginfo; |
1391 | struct snd_timer_id tid; | |
1392 | struct snd_timer *t; | |
1da177e4 LT |
1393 | struct list_head *p; |
1394 | int err = 0; | |
1395 | ||
1396 | ginfo = kmalloc(sizeof(*ginfo), GFP_KERNEL); | |
1397 | if (! ginfo) | |
1398 | return -ENOMEM; | |
1399 | if (copy_from_user(ginfo, _ginfo, sizeof(*ginfo))) { | |
1400 | kfree(ginfo); | |
1401 | return -EFAULT; | |
1402 | } | |
1403 | tid = ginfo->tid; | |
1404 | memset(ginfo, 0, sizeof(*ginfo)); | |
1405 | ginfo->tid = tid; | |
1406 | down(®ister_mutex); | |
1407 | t = snd_timer_find(&tid); | |
1408 | if (t != NULL) { | |
1409 | ginfo->card = t->card ? t->card->number : -1; | |
1410 | if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) | |
1411 | ginfo->flags |= SNDRV_TIMER_FLG_SLAVE; | |
1412 | strlcpy(ginfo->id, t->id, sizeof(ginfo->id)); | |
1413 | strlcpy(ginfo->name, t->name, sizeof(ginfo->name)); | |
1414 | ginfo->resolution = t->hw.resolution; | |
1415 | if (t->hw.resolution_min > 0) { | |
1416 | ginfo->resolution_min = t->hw.resolution_min; | |
1417 | ginfo->resolution_max = t->hw.resolution_max; | |
1418 | } | |
1419 | list_for_each(p, &t->open_list_head) { | |
1420 | ginfo->clients++; | |
1421 | } | |
1422 | } else { | |
1423 | err = -ENODEV; | |
1424 | } | |
1425 | up(®ister_mutex); | |
1426 | if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo))) | |
1427 | err = -EFAULT; | |
1428 | kfree(ginfo); | |
1429 | return err; | |
1430 | } | |
1431 | ||
6b172a85 | 1432 | static int snd_timer_user_gparams(struct file *file, |
53d2f744 | 1433 | struct snd_timer_gparams __user *_gparams) |
1da177e4 | 1434 | { |
53d2f744 TI |
1435 | struct snd_timer_gparams gparams; |
1436 | struct snd_timer *t; | |
1da177e4 LT |
1437 | int err; |
1438 | ||
1439 | if (copy_from_user(&gparams, _gparams, sizeof(gparams))) | |
1440 | return -EFAULT; | |
1441 | down(®ister_mutex); | |
1442 | t = snd_timer_find(&gparams.tid); | |
6b172a85 | 1443 | if (!t) { |
1da177e4 | 1444 | err = -ENODEV; |
6b172a85 CL |
1445 | goto _error; |
1446 | } | |
1447 | if (!list_empty(&t->open_list_head)) { | |
1448 | err = -EBUSY; | |
1449 | goto _error; | |
1450 | } | |
1451 | if (!t->hw.set_period) { | |
1452 | err = -ENOSYS; | |
1453 | goto _error; | |
1da177e4 | 1454 | } |
6b172a85 CL |
1455 | err = t->hw.set_period(t, gparams.period_num, gparams.period_den); |
1456 | _error: | |
1da177e4 LT |
1457 | up(®ister_mutex); |
1458 | return err; | |
1459 | } | |
1460 | ||
6b172a85 | 1461 | static int snd_timer_user_gstatus(struct file *file, |
53d2f744 | 1462 | struct snd_timer_gstatus __user *_gstatus) |
1da177e4 | 1463 | { |
53d2f744 TI |
1464 | struct snd_timer_gstatus gstatus; |
1465 | struct snd_timer_id tid; | |
1466 | struct snd_timer *t; | |
1da177e4 LT |
1467 | int err = 0; |
1468 | ||
1469 | if (copy_from_user(&gstatus, _gstatus, sizeof(gstatus))) | |
1470 | return -EFAULT; | |
1471 | tid = gstatus.tid; | |
1472 | memset(&gstatus, 0, sizeof(gstatus)); | |
1473 | gstatus.tid = tid; | |
1474 | down(®ister_mutex); | |
1475 | t = snd_timer_find(&tid); | |
1476 | if (t != NULL) { | |
1477 | if (t->hw.c_resolution) | |
1478 | gstatus.resolution = t->hw.c_resolution(t); | |
1479 | else | |
1480 | gstatus.resolution = t->hw.resolution; | |
1481 | if (t->hw.precise_resolution) { | |
6b172a85 CL |
1482 | t->hw.precise_resolution(t, &gstatus.resolution_num, |
1483 | &gstatus.resolution_den); | |
1da177e4 LT |
1484 | } else { |
1485 | gstatus.resolution_num = gstatus.resolution; | |
1486 | gstatus.resolution_den = 1000000000uL; | |
1487 | } | |
1488 | } else { | |
1489 | err = -ENODEV; | |
1490 | } | |
1491 | up(®ister_mutex); | |
1492 | if (err >= 0 && copy_to_user(_gstatus, &gstatus, sizeof(gstatus))) | |
1493 | err = -EFAULT; | |
1494 | return err; | |
1495 | } | |
1496 | ||
6b172a85 | 1497 | static int snd_timer_user_tselect(struct file *file, |
53d2f744 | 1498 | struct snd_timer_select __user *_tselect) |
1da177e4 | 1499 | { |
53d2f744 TI |
1500 | struct snd_timer_user *tu; |
1501 | struct snd_timer_select tselect; | |
1da177e4 | 1502 | char str[32]; |
c1935b4d | 1503 | int err = 0; |
6b172a85 | 1504 | |
1da177e4 | 1505 | tu = file->private_data; |
c1935b4d JK |
1506 | down(&tu->tread_sem); |
1507 | if (tu->timeri) { | |
1da177e4 | 1508 | snd_timer_close(tu->timeri); |
c1935b4d JK |
1509 | tu->timeri = NULL; |
1510 | } | |
1511 | if (copy_from_user(&tselect, _tselect, sizeof(tselect))) { | |
1512 | err = -EFAULT; | |
1513 | goto __err; | |
1514 | } | |
1da177e4 LT |
1515 | sprintf(str, "application %i", current->pid); |
1516 | if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE) | |
1517 | tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION; | |
6b172a85 CL |
1518 | err = snd_timer_open(&tu->timeri, str, &tselect.id, current->pid); |
1519 | if (err < 0) | |
c1935b4d | 1520 | goto __err; |
1da177e4 | 1521 | |
4d572776 JJ |
1522 | kfree(tu->queue); |
1523 | tu->queue = NULL; | |
1524 | kfree(tu->tqueue); | |
1525 | tu->tqueue = NULL; | |
1da177e4 | 1526 | if (tu->tread) { |
53d2f744 | 1527 | tu->tqueue = kmalloc(tu->queue_size * sizeof(struct snd_timer_tread), |
6b172a85 | 1528 | GFP_KERNEL); |
c1935b4d JK |
1529 | if (tu->tqueue == NULL) |
1530 | err = -ENOMEM; | |
1da177e4 | 1531 | } else { |
53d2f744 | 1532 | tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read), |
6b172a85 | 1533 | GFP_KERNEL); |
c1935b4d JK |
1534 | if (tu->queue == NULL) |
1535 | err = -ENOMEM; | |
1da177e4 | 1536 | } |
6b172a85 | 1537 | |
c1935b4d JK |
1538 | if (err < 0) { |
1539 | snd_timer_close(tu->timeri); | |
1540 | tu->timeri = NULL; | |
1541 | } else { | |
1542 | tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST; | |
6b172a85 CL |
1543 | tu->timeri->callback = tu->tread |
1544 | ? snd_timer_user_tinterrupt : snd_timer_user_interrupt; | |
c1935b4d JK |
1545 | tu->timeri->ccallback = snd_timer_user_ccallback; |
1546 | tu->timeri->callback_data = (void *)tu; | |
1547 | } | |
1548 | ||
1549 | __err: | |
1550 | up(&tu->tread_sem); | |
1551 | return err; | |
1da177e4 LT |
1552 | } |
1553 | ||
6b172a85 | 1554 | static int snd_timer_user_info(struct file *file, |
53d2f744 | 1555 | struct snd_timer_info __user *_info) |
1da177e4 | 1556 | { |
53d2f744 TI |
1557 | struct snd_timer_user *tu; |
1558 | struct snd_timer_info *info; | |
1559 | struct snd_timer *t; | |
1da177e4 LT |
1560 | int err = 0; |
1561 | ||
1562 | tu = file->private_data; | |
1563 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
1564 | t = tu->timeri->timer; | |
1565 | snd_assert(t != NULL, return -ENXIO); | |
1566 | ||
ca2c0966 | 1567 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
1da177e4 LT |
1568 | if (! info) |
1569 | return -ENOMEM; | |
1570 | info->card = t->card ? t->card->number : -1; | |
1571 | if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) | |
1572 | info->flags |= SNDRV_TIMER_FLG_SLAVE; | |
1573 | strlcpy(info->id, t->id, sizeof(info->id)); | |
1574 | strlcpy(info->name, t->name, sizeof(info->name)); | |
1575 | info->resolution = t->hw.resolution; | |
1576 | if (copy_to_user(_info, info, sizeof(*_info))) | |
1577 | err = -EFAULT; | |
1578 | kfree(info); | |
1579 | return err; | |
1580 | } | |
1581 | ||
6b172a85 | 1582 | static int snd_timer_user_params(struct file *file, |
53d2f744 | 1583 | struct snd_timer_params __user *_params) |
1da177e4 | 1584 | { |
53d2f744 TI |
1585 | struct snd_timer_user *tu; |
1586 | struct snd_timer_params params; | |
1587 | struct snd_timer *t; | |
1588 | struct snd_timer_read *tr; | |
1589 | struct snd_timer_tread *ttr; | |
1da177e4 | 1590 | int err; |
6b172a85 | 1591 | |
1da177e4 LT |
1592 | tu = file->private_data; |
1593 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
1594 | t = tu->timeri->timer; | |
1595 | snd_assert(t != NULL, return -ENXIO); | |
1596 | if (copy_from_user(¶ms, _params, sizeof(params))) | |
1597 | return -EFAULT; | |
1598 | if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE) && params.ticks < 1) { | |
1599 | err = -EINVAL; | |
1600 | goto _end; | |
1601 | } | |
6b172a85 CL |
1602 | if (params.queue_size > 0 && |
1603 | (params.queue_size < 32 || params.queue_size > 1024)) { | |
1da177e4 LT |
1604 | err = -EINVAL; |
1605 | goto _end; | |
1606 | } | |
1607 | if (params.filter & ~((1<<SNDRV_TIMER_EVENT_RESOLUTION)| | |
1608 | (1<<SNDRV_TIMER_EVENT_TICK)| | |
1609 | (1<<SNDRV_TIMER_EVENT_START)| | |
1610 | (1<<SNDRV_TIMER_EVENT_STOP)| | |
1611 | (1<<SNDRV_TIMER_EVENT_CONTINUE)| | |
1612 | (1<<SNDRV_TIMER_EVENT_PAUSE)| | |
a501dfa3 JK |
1613 | (1<<SNDRV_TIMER_EVENT_SUSPEND)| |
1614 | (1<<SNDRV_TIMER_EVENT_RESUME)| | |
1da177e4 LT |
1615 | (1<<SNDRV_TIMER_EVENT_MSTART)| |
1616 | (1<<SNDRV_TIMER_EVENT_MSTOP)| | |
1617 | (1<<SNDRV_TIMER_EVENT_MCONTINUE)| | |
65d11d95 JK |
1618 | (1<<SNDRV_TIMER_EVENT_MPAUSE)| |
1619 | (1<<SNDRV_TIMER_EVENT_MSUSPEND)| | |
a501dfa3 | 1620 | (1<<SNDRV_TIMER_EVENT_MRESUME))) { |
1da177e4 LT |
1621 | err = -EINVAL; |
1622 | goto _end; | |
1623 | } | |
1624 | snd_timer_stop(tu->timeri); | |
1625 | spin_lock_irq(&t->lock); | |
1626 | tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO| | |
1627 | SNDRV_TIMER_IFLG_EXCLUSIVE| | |
1628 | SNDRV_TIMER_IFLG_EARLY_EVENT); | |
1629 | if (params.flags & SNDRV_TIMER_PSFLG_AUTO) | |
1630 | tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO; | |
1631 | if (params.flags & SNDRV_TIMER_PSFLG_EXCLUSIVE) | |
1632 | tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE; | |
1633 | if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT) | |
1634 | tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT; | |
1635 | spin_unlock_irq(&t->lock); | |
6b172a85 CL |
1636 | if (params.queue_size > 0 && |
1637 | (unsigned int)tu->queue_size != params.queue_size) { | |
1da177e4 | 1638 | if (tu->tread) { |
6b172a85 CL |
1639 | ttr = kmalloc(params.queue_size * sizeof(*ttr), |
1640 | GFP_KERNEL); | |
1da177e4 LT |
1641 | if (ttr) { |
1642 | kfree(tu->tqueue); | |
1643 | tu->queue_size = params.queue_size; | |
1644 | tu->tqueue = ttr; | |
1645 | } | |
1646 | } else { | |
6b172a85 CL |
1647 | tr = kmalloc(params.queue_size * sizeof(*tr), |
1648 | GFP_KERNEL); | |
1da177e4 LT |
1649 | if (tr) { |
1650 | kfree(tu->queue); | |
1651 | tu->queue_size = params.queue_size; | |
1652 | tu->queue = tr; | |
1653 | } | |
1654 | } | |
1655 | } | |
1656 | tu->qhead = tu->qtail = tu->qused = 0; | |
1657 | if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { | |
1658 | if (tu->tread) { | |
53d2f744 | 1659 | struct snd_timer_tread tread; |
1da177e4 LT |
1660 | tread.event = SNDRV_TIMER_EVENT_EARLY; |
1661 | tread.tstamp.tv_sec = 0; | |
1662 | tread.tstamp.tv_nsec = 0; | |
1663 | tread.val = 0; | |
1664 | snd_timer_user_append_to_tqueue(tu, &tread); | |
1665 | } else { | |
53d2f744 | 1666 | struct snd_timer_read *r = &tu->queue[0]; |
1da177e4 LT |
1667 | r->resolution = 0; |
1668 | r->ticks = 0; | |
1669 | tu->qused++; | |
1670 | tu->qtail++; | |
1671 | } | |
1da177e4 LT |
1672 | } |
1673 | tu->filter = params.filter; | |
1674 | tu->ticks = params.ticks; | |
1675 | err = 0; | |
1676 | _end: | |
1677 | if (copy_to_user(_params, ¶ms, sizeof(params))) | |
1678 | return -EFAULT; | |
1679 | return err; | |
1680 | } | |
1681 | ||
6b172a85 | 1682 | static int snd_timer_user_status(struct file *file, |
53d2f744 | 1683 | struct snd_timer_status __user *_status) |
1da177e4 | 1684 | { |
53d2f744 TI |
1685 | struct snd_timer_user *tu; |
1686 | struct snd_timer_status status; | |
6b172a85 | 1687 | |
1da177e4 LT |
1688 | tu = file->private_data; |
1689 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
1690 | memset(&status, 0, sizeof(status)); | |
1691 | status.tstamp = tu->tstamp; | |
1692 | status.resolution = snd_timer_resolution(tu->timeri); | |
1693 | status.lost = tu->timeri->lost; | |
1694 | status.overrun = tu->overrun; | |
1695 | spin_lock_irq(&tu->qlock); | |
1696 | status.queue = tu->qused; | |
1697 | spin_unlock_irq(&tu->qlock); | |
1698 | if (copy_to_user(_status, &status, sizeof(status))) | |
1699 | return -EFAULT; | |
1700 | return 0; | |
1701 | } | |
1702 | ||
1703 | static int snd_timer_user_start(struct file *file) | |
1704 | { | |
1705 | int err; | |
53d2f744 | 1706 | struct snd_timer_user *tu; |
6b172a85 | 1707 | |
1da177e4 LT |
1708 | tu = file->private_data; |
1709 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
1710 | snd_timer_stop(tu->timeri); | |
1711 | tu->timeri->lost = 0; | |
1712 | tu->last_resolution = 0; | |
1713 | return (err = snd_timer_start(tu->timeri, tu->ticks)) < 0 ? err : 0; | |
1714 | } | |
1715 | ||
1716 | static int snd_timer_user_stop(struct file *file) | |
1717 | { | |
1718 | int err; | |
53d2f744 | 1719 | struct snd_timer_user *tu; |
6b172a85 | 1720 | |
1da177e4 LT |
1721 | tu = file->private_data; |
1722 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
1723 | return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0; | |
1724 | } | |
1725 | ||
1726 | static int snd_timer_user_continue(struct file *file) | |
1727 | { | |
1728 | int err; | |
53d2f744 | 1729 | struct snd_timer_user *tu; |
6b172a85 | 1730 | |
1da177e4 LT |
1731 | tu = file->private_data; |
1732 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
1733 | tu->timeri->lost = 0; | |
1734 | return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0; | |
1735 | } | |
1736 | ||
15790a6b TI |
1737 | static int snd_timer_user_pause(struct file *file) |
1738 | { | |
1739 | int err; | |
53d2f744 | 1740 | struct snd_timer_user *tu; |
6b172a85 | 1741 | |
15790a6b TI |
1742 | tu = file->private_data; |
1743 | snd_assert(tu->timeri != NULL, return -ENXIO); | |
d138b445 | 1744 | return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0; |
15790a6b TI |
1745 | } |
1746 | ||
8c50b37c TI |
1747 | enum { |
1748 | SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20), | |
1749 | SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21), | |
1750 | SNDRV_TIMER_IOCTL_CONTINUE_OLD = _IO('T', 0x22), | |
1751 | SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23), | |
1752 | }; | |
1753 | ||
6b172a85 CL |
1754 | static long snd_timer_user_ioctl(struct file *file, unsigned int cmd, |
1755 | unsigned long arg) | |
1da177e4 | 1756 | { |
53d2f744 | 1757 | struct snd_timer_user *tu; |
1da177e4 LT |
1758 | void __user *argp = (void __user *)arg; |
1759 | int __user *p = argp; | |
6b172a85 | 1760 | |
1da177e4 LT |
1761 | tu = file->private_data; |
1762 | switch (cmd) { | |
1763 | case SNDRV_TIMER_IOCTL_PVERSION: | |
1764 | return put_user(SNDRV_TIMER_VERSION, p) ? -EFAULT : 0; | |
1765 | case SNDRV_TIMER_IOCTL_NEXT_DEVICE: | |
1766 | return snd_timer_user_next_device(argp); | |
1767 | case SNDRV_TIMER_IOCTL_TREAD: | |
1768 | { | |
1769 | int xarg; | |
6b172a85 | 1770 | |
c1935b4d JK |
1771 | down(&tu->tread_sem); |
1772 | if (tu->timeri) { /* too late */ | |
1773 | up(&tu->tread_sem); | |
1da177e4 | 1774 | return -EBUSY; |
c1935b4d JK |
1775 | } |
1776 | if (get_user(xarg, p)) { | |
1777 | up(&tu->tread_sem); | |
1da177e4 | 1778 | return -EFAULT; |
c1935b4d | 1779 | } |
1da177e4 | 1780 | tu->tread = xarg ? 1 : 0; |
c1935b4d | 1781 | up(&tu->tread_sem); |
1da177e4 LT |
1782 | return 0; |
1783 | } | |
1784 | case SNDRV_TIMER_IOCTL_GINFO: | |
1785 | return snd_timer_user_ginfo(file, argp); | |
1786 | case SNDRV_TIMER_IOCTL_GPARAMS: | |
1787 | return snd_timer_user_gparams(file, argp); | |
1788 | case SNDRV_TIMER_IOCTL_GSTATUS: | |
1789 | return snd_timer_user_gstatus(file, argp); | |
1790 | case SNDRV_TIMER_IOCTL_SELECT: | |
1791 | return snd_timer_user_tselect(file, argp); | |
1792 | case SNDRV_TIMER_IOCTL_INFO: | |
1793 | return snd_timer_user_info(file, argp); | |
1794 | case SNDRV_TIMER_IOCTL_PARAMS: | |
1795 | return snd_timer_user_params(file, argp); | |
1796 | case SNDRV_TIMER_IOCTL_STATUS: | |
1797 | return snd_timer_user_status(file, argp); | |
1798 | case SNDRV_TIMER_IOCTL_START: | |
8c50b37c | 1799 | case SNDRV_TIMER_IOCTL_START_OLD: |
1da177e4 LT |
1800 | return snd_timer_user_start(file); |
1801 | case SNDRV_TIMER_IOCTL_STOP: | |
8c50b37c | 1802 | case SNDRV_TIMER_IOCTL_STOP_OLD: |
1da177e4 LT |
1803 | return snd_timer_user_stop(file); |
1804 | case SNDRV_TIMER_IOCTL_CONTINUE: | |
8c50b37c | 1805 | case SNDRV_TIMER_IOCTL_CONTINUE_OLD: |
1da177e4 | 1806 | return snd_timer_user_continue(file); |
15790a6b | 1807 | case SNDRV_TIMER_IOCTL_PAUSE: |
8c50b37c | 1808 | case SNDRV_TIMER_IOCTL_PAUSE_OLD: |
15790a6b | 1809 | return snd_timer_user_pause(file); |
1da177e4 LT |
1810 | } |
1811 | return -ENOTTY; | |
1812 | } | |
1813 | ||
1814 | static int snd_timer_user_fasync(int fd, struct file * file, int on) | |
1815 | { | |
53d2f744 | 1816 | struct snd_timer_user *tu; |
1da177e4 | 1817 | int err; |
6b172a85 | 1818 | |
1da177e4 LT |
1819 | tu = file->private_data; |
1820 | err = fasync_helper(fd, file, on, &tu->fasync); | |
1821 | if (err < 0) | |
1822 | return err; | |
1823 | return 0; | |
1824 | } | |
1825 | ||
6b172a85 CL |
1826 | static ssize_t snd_timer_user_read(struct file *file, char __user *buffer, |
1827 | size_t count, loff_t *offset) | |
1da177e4 | 1828 | { |
53d2f744 | 1829 | struct snd_timer_user *tu; |
1da177e4 LT |
1830 | long result = 0, unit; |
1831 | int err = 0; | |
6b172a85 | 1832 | |
1da177e4 | 1833 | tu = file->private_data; |
53d2f744 | 1834 | unit = tu->tread ? sizeof(struct snd_timer_tread) : sizeof(struct snd_timer_read); |
1da177e4 LT |
1835 | spin_lock_irq(&tu->qlock); |
1836 | while ((long)count - result >= unit) { | |
1837 | while (!tu->qused) { | |
1838 | wait_queue_t wait; | |
1839 | ||
1840 | if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) { | |
1841 | err = -EAGAIN; | |
1842 | break; | |
1843 | } | |
1844 | ||
1845 | set_current_state(TASK_INTERRUPTIBLE); | |
1846 | init_waitqueue_entry(&wait, current); | |
1847 | add_wait_queue(&tu->qchange_sleep, &wait); | |
1848 | ||
1849 | spin_unlock_irq(&tu->qlock); | |
1850 | schedule(); | |
1851 | spin_lock_irq(&tu->qlock); | |
1852 | ||
1853 | remove_wait_queue(&tu->qchange_sleep, &wait); | |
1854 | ||
1855 | if (signal_pending(current)) { | |
1856 | err = -ERESTARTSYS; | |
1857 | break; | |
1858 | } | |
1859 | } | |
1860 | ||
1861 | spin_unlock_irq(&tu->qlock); | |
1862 | if (err < 0) | |
1863 | goto _error; | |
1864 | ||
1865 | if (tu->tread) { | |
6b172a85 | 1866 | if (copy_to_user(buffer, &tu->tqueue[tu->qhead++], |
53d2f744 | 1867 | sizeof(struct snd_timer_tread))) { |
1da177e4 LT |
1868 | err = -EFAULT; |
1869 | goto _error; | |
1870 | } | |
1871 | } else { | |
6b172a85 | 1872 | if (copy_to_user(buffer, &tu->queue[tu->qhead++], |
53d2f744 | 1873 | sizeof(struct snd_timer_read))) { |
1da177e4 LT |
1874 | err = -EFAULT; |
1875 | goto _error; | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | tu->qhead %= tu->queue_size; | |
1880 | ||
1881 | result += unit; | |
1882 | buffer += unit; | |
1883 | ||
1884 | spin_lock_irq(&tu->qlock); | |
1885 | tu->qused--; | |
1886 | } | |
1887 | spin_unlock_irq(&tu->qlock); | |
1888 | _error: | |
1889 | return result > 0 ? result : err; | |
1890 | } | |
1891 | ||
1892 | static unsigned int snd_timer_user_poll(struct file *file, poll_table * wait) | |
1893 | { | |
1894 | unsigned int mask; | |
53d2f744 | 1895 | struct snd_timer_user *tu; |
1da177e4 LT |
1896 | |
1897 | tu = file->private_data; | |
1898 | ||
1899 | poll_wait(file, &tu->qchange_sleep, wait); | |
6b172a85 | 1900 | |
1da177e4 LT |
1901 | mask = 0; |
1902 | if (tu->qused) | |
1903 | mask |= POLLIN | POLLRDNORM; | |
1904 | ||
1905 | return mask; | |
1906 | } | |
1907 | ||
1908 | #ifdef CONFIG_COMPAT | |
1909 | #include "timer_compat.c" | |
1910 | #else | |
1911 | #define snd_timer_user_ioctl_compat NULL | |
1912 | #endif | |
1913 | ||
1914 | static struct file_operations snd_timer_f_ops = | |
1915 | { | |
1916 | .owner = THIS_MODULE, | |
1917 | .read = snd_timer_user_read, | |
1918 | .open = snd_timer_user_open, | |
1919 | .release = snd_timer_user_release, | |
1920 | .poll = snd_timer_user_poll, | |
1921 | .unlocked_ioctl = snd_timer_user_ioctl, | |
1922 | .compat_ioctl = snd_timer_user_ioctl_compat, | |
1923 | .fasync = snd_timer_user_fasync, | |
1924 | }; | |
1925 | ||
53d2f744 | 1926 | static struct snd_minor snd_timer_reg = |
1da177e4 LT |
1927 | { |
1928 | .comment = "timer", | |
1929 | .f_ops = &snd_timer_f_ops, | |
1930 | }; | |
1931 | ||
1932 | /* | |
1933 | * ENTRY functions | |
1934 | */ | |
1935 | ||
53d2f744 | 1936 | static struct snd_info_entry *snd_timer_proc_entry = NULL; |
1da177e4 LT |
1937 | |
1938 | static int __init alsa_timer_init(void) | |
1939 | { | |
1940 | int err; | |
53d2f744 | 1941 | struct snd_info_entry *entry; |
1da177e4 LT |
1942 | |
1943 | #ifdef SNDRV_OSS_INFO_DEV_TIMERS | |
6b172a85 CL |
1944 | snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1, |
1945 | "system timer"); | |
1da177e4 | 1946 | #endif |
6b172a85 CL |
1947 | entry = snd_info_create_module_entry(THIS_MODULE, "timers", NULL); |
1948 | if (entry != NULL) { | |
1da177e4 LT |
1949 | entry->c.text.read_size = SNDRV_TIMER_DEVICES * 128; |
1950 | entry->c.text.read = snd_timer_proc_read; | |
1951 | if (snd_info_register(entry) < 0) { | |
1952 | snd_info_free_entry(entry); | |
1953 | entry = NULL; | |
1954 | } | |
1955 | } | |
1956 | snd_timer_proc_entry = entry; | |
1957 | if ((err = snd_timer_register_system()) < 0) | |
6b172a85 CL |
1958 | snd_printk(KERN_ERR "unable to register system timer (%i)\n", |
1959 | err); | |
1da177e4 LT |
1960 | if ((err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, |
1961 | NULL, 0, &snd_timer_reg, "timer"))<0) | |
6b172a85 CL |
1962 | snd_printk(KERN_ERR "unable to register timer device (%i)\n", |
1963 | err); | |
1da177e4 LT |
1964 | return 0; |
1965 | } | |
1966 | ||
1967 | static void __exit alsa_timer_exit(void) | |
1968 | { | |
1969 | struct list_head *p, *n; | |
1970 | ||
1971 | snd_unregister_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0); | |
1972 | /* unregister the system timer */ | |
1973 | list_for_each_safe(p, n, &snd_timer_list) { | |
53d2f744 | 1974 | struct snd_timer *timer = list_entry(p, struct snd_timer, device_list); |
1da177e4 LT |
1975 | snd_timer_unregister(timer); |
1976 | } | |
1977 | if (snd_timer_proc_entry) { | |
1978 | snd_info_unregister(snd_timer_proc_entry); | |
1979 | snd_timer_proc_entry = NULL; | |
1980 | } | |
1981 | #ifdef SNDRV_OSS_INFO_DEV_TIMERS | |
1982 | snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1); | |
1983 | #endif | |
1984 | } | |
1985 | ||
1986 | module_init(alsa_timer_init) | |
1987 | module_exit(alsa_timer_exit) | |
1988 | ||
1989 | EXPORT_SYMBOL(snd_timer_open); | |
1990 | EXPORT_SYMBOL(snd_timer_close); | |
1991 | EXPORT_SYMBOL(snd_timer_resolution); | |
1992 | EXPORT_SYMBOL(snd_timer_start); | |
1993 | EXPORT_SYMBOL(snd_timer_stop); | |
1994 | EXPORT_SYMBOL(snd_timer_continue); | |
1995 | EXPORT_SYMBOL(snd_timer_pause); | |
1996 | EXPORT_SYMBOL(snd_timer_new); | |
1997 | EXPORT_SYMBOL(snd_timer_notify); | |
1998 | EXPORT_SYMBOL(snd_timer_global_new); | |
1999 | EXPORT_SYMBOL(snd_timer_global_free); | |
2000 | EXPORT_SYMBOL(snd_timer_global_register); | |
2001 | EXPORT_SYMBOL(snd_timer_global_unregister); | |
2002 | EXPORT_SYMBOL(snd_timer_interrupt); |