Lines Matching +full:signal +full:- +full:guard
1 // SPDX-License-Identifier: GPL-2.0-or-later
15 #include <linux/sched/signal.h>
93 s32 tstamp_sec; /* Timestamp - last update */
105 s64 tstamp_sec; /* Timestamp - last update */
116 /* Internal data structure for keeping the state of the userspace-driven timer */
157 timeri->owner = kstrdup(owner, GFP_KERNEL); in snd_timer_instance_new()
158 if (! timeri->owner) { in snd_timer_instance_new()
162 INIT_LIST_HEAD(&timeri->open_list); in snd_timer_instance_new()
163 INIT_LIST_HEAD(&timeri->active_list); in snd_timer_instance_new()
164 INIT_LIST_HEAD(&timeri->ack_list); in snd_timer_instance_new()
165 INIT_LIST_HEAD(&timeri->slave_list_head); in snd_timer_instance_new()
166 INIT_LIST_HEAD(&timeri->slave_active_head); in snd_timer_instance_new()
175 if (timeri->private_free) in snd_timer_instance_free()
176 timeri->private_free(timeri); in snd_timer_instance_free()
177 kfree(timeri->owner); in snd_timer_instance_free()
191 if (timer->tmr_class != tid->dev_class) in snd_timer_find()
193 if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD || in snd_timer_find()
194 timer->tmr_class == SNDRV_TIMER_CLASS_PCM) && in snd_timer_find()
195 (timer->card == NULL || in snd_timer_find()
196 timer->card->number != tid->card)) in snd_timer_find()
198 if (timer->tmr_device != tid->device) in snd_timer_find()
200 if (timer->tmr_subdevice != tid->subdevice) in snd_timer_find()
211 switch (tid->dev_class) { in snd_timer_request()
213 if (tid->device < timer_limit) in snd_timer_request()
214 request_module("snd-timer-%i", tid->device); in snd_timer_request()
218 if (tid->card < snd_ecards_limit) in snd_timer_request()
219 request_module("snd-card-%i", tid->card); in snd_timer_request()
232 if (slave->slave_class != master->slave_class || in check_matching_master_slave()
233 slave->slave_id != master->slave_id) in check_matching_master_slave()
235 if (master->timer->num_instances >= master->timer->max_instances) in check_matching_master_slave()
236 return -EBUSY; in check_matching_master_slave()
237 list_move_tail(&slave->open_list, &master->slave_list_head); in check_matching_master_slave()
238 master->timer->num_instances++; in check_matching_master_slave()
239 guard(spinlock_irq)(&slave_active_lock); in check_matching_master_slave()
240 guard(spinlock)(&master->timer->lock); in check_matching_master_slave()
241 slave->master = master; in check_matching_master_slave()
242 slave->timer = master->timer; in check_matching_master_slave()
243 if (slave->flags & SNDRV_TIMER_IFLG_RUNNING) in check_matching_master_slave()
244 list_add_tail(&slave->active_list, &master->slave_active_head); in check_matching_master_slave()
262 list_for_each_entry(master, &timer->open_list_head, open_list) { in snd_timer_check_slave()
308 if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) { in snd_timer_open()
310 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE || in snd_timer_open()
311 tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) { in snd_timer_open()
313 tid->dev_sclass); in snd_timer_open()
314 err = -EINVAL; in snd_timer_open()
318 err = -EBUSY; in snd_timer_open()
321 timeri->slave_class = tid->dev_sclass; in snd_timer_open()
322 timeri->slave_id = tid->device; in snd_timer_open()
323 timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; in snd_timer_open()
324 list_add_tail(&timeri->open_list, &snd_timer_slave_list); in snd_timer_open()
341 err = -ENODEV; in snd_timer_open()
344 if (!list_empty(&timer->open_list_head)) { in snd_timer_open()
346 list_entry(timer->open_list_head.next, in snd_timer_open()
348 if (t->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) { in snd_timer_open()
349 err = -EBUSY; in snd_timer_open()
353 if (timer->num_instances >= timer->max_instances) { in snd_timer_open()
354 err = -EBUSY; in snd_timer_open()
357 if (!try_module_get(timer->module)) { in snd_timer_open()
358 err = -EBUSY; in snd_timer_open()
362 if (timer->card) { in snd_timer_open()
363 get_device(&timer->card->card_dev); in snd_timer_open()
364 card_dev_to_put = &timer->card->card_dev; in snd_timer_open()
367 if (list_empty(&timer->open_list_head) && timer->hw.open) { in snd_timer_open()
368 err = timer->hw.open(timer); in snd_timer_open()
370 module_put(timer->module); in snd_timer_open()
375 timeri->timer = timer; in snd_timer_open()
376 timeri->slave_class = tid->dev_sclass; in snd_timer_open()
377 timeri->slave_id = slave_id; in snd_timer_open()
379 list_add_tail(&timeri->open_list, &timer->open_list_head); in snd_timer_open()
380 timer->num_instances++; in snd_timer_open()
401 guard(spinlock_irq)(&slave_active_lock); in remove_slave_links()
402 guard(spinlock)(&timer->lock); in remove_slave_links()
403 timeri->timer = NULL; in remove_slave_links()
404 list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head, open_list) { in remove_slave_links()
405 list_move_tail(&slave->open_list, &snd_timer_slave_list); in remove_slave_links()
406 timer->num_instances--; in remove_slave_links()
407 slave->master = NULL; in remove_slave_links()
408 slave->timer = NULL; in remove_slave_links()
409 list_del_init(&slave->ack_list); in remove_slave_links()
410 list_del_init(&slave->active_list); in remove_slave_links()
421 struct snd_timer *timer = timeri->timer; in snd_timer_close_locked()
424 guard(spinlock_irq)(&timer->lock); in snd_timer_close_locked()
425 timeri->flags |= SNDRV_TIMER_IFLG_DEAD; in snd_timer_close_locked()
428 if (!list_empty(&timeri->open_list)) { in snd_timer_close_locked()
429 list_del_init(&timeri->open_list); in snd_timer_close_locked()
430 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_close_locked()
431 num_slaves--; in snd_timer_close_locked()
438 timer->num_instances--; in snd_timer_close_locked()
440 spin_lock_irq(&timer->lock); in snd_timer_close_locked()
441 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) { in snd_timer_close_locked()
442 spin_unlock_irq(&timer->lock); in snd_timer_close_locked()
444 spin_lock_irq(&timer->lock); in snd_timer_close_locked()
446 spin_unlock_irq(&timer->lock); in snd_timer_close_locked()
451 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_close_locked()
456 if (list_empty(&timer->open_list_head) && timer->hw.close) in snd_timer_close_locked()
457 timer->hw.close(timer); in snd_timer_close_locked()
459 if (timer->card) in snd_timer_close_locked()
460 *card_devp_to_put = &timer->card->card_dev; in snd_timer_close_locked()
461 module_put(timer->module); in snd_timer_close_locked()
485 if (timer->hw.c_resolution) in snd_timer_hw_resolution()
486 return timer->hw.c_resolution(timer); in snd_timer_hw_resolution()
488 return timer->hw.resolution; in snd_timer_hw_resolution()
498 timer = timeri->timer; in snd_timer_resolution()
500 guard(spinlock_irqsave)(&timer->lock); in snd_timer_resolution()
509 struct snd_timer *timer = ti->timer; in snd_timer_notify1()
525 if (ti->ccallback) in snd_timer_notify1()
526 ti->ccallback(ti, event, &tstamp, resolution); in snd_timer_notify1()
527 if (ti->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_notify1()
531 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_notify1()
534 list_for_each_entry(ts, &ti->slave_active_head, active_list) in snd_timer_notify1()
535 if (ts->ccallback) in snd_timer_notify1()
536 ts->ccallback(ts, event, &tstamp, resolution); in snd_timer_notify1()
546 timer = timeri->timer; in snd_timer_start1()
548 return -EINVAL; in snd_timer_start1()
550 guard(spinlock_irqsave)(&timer->lock); in snd_timer_start1()
551 if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) in snd_timer_start1()
552 return -EINVAL; in snd_timer_start1()
553 if (timer->card && timer->card->shutdown) in snd_timer_start1()
554 return -ENODEV; in snd_timer_start1()
555 if (timeri->flags & (SNDRV_TIMER_IFLG_RUNNING | in snd_timer_start1()
557 return -EBUSY; in snd_timer_start1()
562 if (start && !(timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) { in snd_timer_start1()
564 return -EINVAL; in snd_timer_start1()
568 timeri->ticks = timeri->cticks = ticks; in snd_timer_start1()
569 else if (!timeri->cticks) in snd_timer_start1()
570 timeri->cticks = 1; in snd_timer_start1()
571 timeri->pticks = 0; in snd_timer_start1()
573 list_move_tail(&timeri->active_list, &timer->active_list_head); in snd_timer_start1()
574 if (timer->running) { in snd_timer_start1()
575 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_start1()
577 timer->flags |= SNDRV_TIMER_FLG_RESCHED; in snd_timer_start1()
578 timeri->flags |= SNDRV_TIMER_IFLG_START; in snd_timer_start1()
582 timer->sticks = ticks; in snd_timer_start1()
583 timer->hw.start(timer); in snd_timer_start1()
585 timer->running++; in snd_timer_start1()
586 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; in snd_timer_start1()
598 guard(spinlock_irqsave)(&slave_active_lock); in snd_timer_start_slave()
599 if (timeri->flags & SNDRV_TIMER_IFLG_DEAD) in snd_timer_start_slave()
600 return -EINVAL; in snd_timer_start_slave()
601 if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) in snd_timer_start_slave()
602 return -EBUSY; in snd_timer_start_slave()
603 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; in snd_timer_start_slave()
604 if (timeri->master && timeri->timer) { in snd_timer_start_slave()
605 guard(spinlock)(&timeri->timer->lock); in snd_timer_start_slave()
606 list_add_tail(&timeri->active_list, in snd_timer_start_slave()
607 &timeri->master->slave_active_head); in snd_timer_start_slave()
619 timer = timeri->timer; in snd_timer_stop1()
621 return -EINVAL; in snd_timer_stop1()
622 guard(spinlock_irqsave)(&timer->lock); in snd_timer_stop1()
623 list_del_init(&timeri->ack_list); in snd_timer_stop1()
624 list_del_init(&timeri->active_list); in snd_timer_stop1()
625 if (!(timeri->flags & (SNDRV_TIMER_IFLG_RUNNING | in snd_timer_stop1()
627 return -EBUSY; in snd_timer_stop1()
628 if (timer->card && timer->card->shutdown) in snd_timer_stop1()
631 timeri->cticks = timeri->ticks; in snd_timer_stop1()
632 timeri->pticks = 0; in snd_timer_stop1()
634 if ((timeri->flags & SNDRV_TIMER_IFLG_RUNNING) && in snd_timer_stop1()
635 !(--timer->running)) { in snd_timer_stop1()
636 timer->hw.stop(timer); in snd_timer_stop1()
637 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) { in snd_timer_stop1()
638 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; in snd_timer_stop1()
640 if (timer->flags & SNDRV_TIMER_FLG_CHANGE) { in snd_timer_stop1()
641 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; in snd_timer_stop1()
642 timer->hw.start(timer); in snd_timer_stop1()
646 timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START); in snd_timer_stop1()
648 timeri->flags &= ~SNDRV_TIMER_IFLG_PAUSED; in snd_timer_stop1()
650 timeri->flags |= SNDRV_TIMER_IFLG_PAUSED; in snd_timer_stop1()
661 guard(spinlock_irqsave)(&slave_active_lock); in snd_timer_stop_slave()
662 running = timeri->flags & SNDRV_TIMER_IFLG_RUNNING; in snd_timer_stop_slave()
663 timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING; in snd_timer_stop_slave()
664 if (timeri->timer) { in snd_timer_stop_slave()
665 guard(spinlock)(&timeri->timer->lock); in snd_timer_stop_slave()
666 list_del_init(&timeri->ack_list); in snd_timer_stop_slave()
667 list_del_init(&timeri->active_list); in snd_timer_stop_slave()
672 return running ? 0 : -EBUSY; in snd_timer_stop_slave()
681 return -EINVAL; in snd_timer_start()
682 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_start()
696 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_stop()
709 if (!(timeri->flags & SNDRV_TIMER_IFLG_PAUSED)) in snd_timer_continue()
710 return -EINVAL; in snd_timer_continue()
712 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_continue()
724 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) in snd_timer_pause()
742 list_for_each_entry(ti, &timer->active_list_head, active_list) { in snd_timer_reschedule()
743 if (ti->flags & SNDRV_TIMER_IFLG_START) { in snd_timer_reschedule()
744 ti->flags &= ~SNDRV_TIMER_IFLG_START; in snd_timer_reschedule()
745 ti->flags |= SNDRV_TIMER_IFLG_RUNNING; in snd_timer_reschedule()
746 timer->running++; in snd_timer_reschedule()
748 if (ti->flags & SNDRV_TIMER_IFLG_RUNNING) { in snd_timer_reschedule()
749 if (ticks > ti->cticks) in snd_timer_reschedule()
750 ticks = ti->cticks; in snd_timer_reschedule()
754 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; in snd_timer_reschedule()
757 if (ticks > timer->hw.ticks) in snd_timer_reschedule()
758 ticks = timer->hw.ticks; in snd_timer_reschedule()
760 timer->flags |= SNDRV_TIMER_FLG_CHANGE; in snd_timer_reschedule()
761 timer->sticks = ticks; in snd_timer_reschedule()
776 list_del_init(&ti->ack_list); in snd_timer_process_callbacks()
778 if (!(ti->flags & SNDRV_TIMER_IFLG_DEAD)) { in snd_timer_process_callbacks()
779 ticks = ti->pticks; in snd_timer_process_callbacks()
780 ti->pticks = 0; in snd_timer_process_callbacks()
781 resolution = ti->resolution; in snd_timer_process_callbacks()
782 ti->flags |= SNDRV_TIMER_IFLG_CALLBACK; in snd_timer_process_callbacks()
783 spin_unlock(&timer->lock); in snd_timer_process_callbacks()
784 if (ti->callback) in snd_timer_process_callbacks()
785 ti->callback(ti, resolution, ticks); in snd_timer_process_callbacks()
786 spin_lock(&timer->lock); in snd_timer_process_callbacks()
787 ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK; in snd_timer_process_callbacks()
796 guard(spinlock_irqsave)(&timer->lock); in snd_timer_clear_callbacks()
798 list_del_init(head->next); in snd_timer_clear_callbacks()
809 if (timer->card && timer->card->shutdown) { in snd_timer_work()
810 snd_timer_clear_callbacks(timer, &timer->sack_list_head); in snd_timer_work()
814 guard(spinlock_irqsave)(&timer->lock); in snd_timer_work()
815 snd_timer_process_callbacks(timer, &timer->sack_list_head); in snd_timer_work()
821 * ticks_left is usually equal to timer->sticks.
833 if (timer->card && timer->card->shutdown) { in snd_timer_interrupt()
834 snd_timer_clear_callbacks(timer, &timer->ack_list_head); in snd_timer_interrupt()
838 guard(spinlock_irqsave)(&timer->lock); in snd_timer_interrupt()
848 list_for_each_entry_safe(ti, tmp, &timer->active_list_head, in snd_timer_interrupt()
850 if (ti->flags & SNDRV_TIMER_IFLG_DEAD) in snd_timer_interrupt()
852 if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING)) in snd_timer_interrupt()
854 ti->pticks += ticks_left; in snd_timer_interrupt()
855 ti->resolution = resolution; in snd_timer_interrupt()
856 if (ti->cticks < ticks_left) in snd_timer_interrupt()
857 ti->cticks = 0; in snd_timer_interrupt()
859 ti->cticks -= ticks_left; in snd_timer_interrupt()
860 if (ti->cticks) /* not expired */ in snd_timer_interrupt()
862 if (ti->flags & SNDRV_TIMER_IFLG_AUTO) { in snd_timer_interrupt()
863 ti->cticks = ti->ticks; in snd_timer_interrupt()
865 ti->flags &= ~SNDRV_TIMER_IFLG_RUNNING; in snd_timer_interrupt()
866 --timer->running; in snd_timer_interrupt()
867 list_del_init(&ti->active_list); in snd_timer_interrupt()
869 if ((timer->hw.flags & SNDRV_TIMER_HW_WORK) || in snd_timer_interrupt()
870 (ti->flags & SNDRV_TIMER_IFLG_FAST)) in snd_timer_interrupt()
871 ack_list_head = &timer->ack_list_head; in snd_timer_interrupt()
873 ack_list_head = &timer->sack_list_head; in snd_timer_interrupt()
874 if (list_empty(&ti->ack_list)) in snd_timer_interrupt()
875 list_add_tail(&ti->ack_list, ack_list_head); in snd_timer_interrupt()
876 list_for_each_entry(ts, &ti->slave_active_head, active_list) { in snd_timer_interrupt()
877 ts->pticks = ti->pticks; in snd_timer_interrupt()
878 ts->resolution = resolution; in snd_timer_interrupt()
879 if (list_empty(&ts->ack_list)) in snd_timer_interrupt()
880 list_add_tail(&ts->ack_list, ack_list_head); in snd_timer_interrupt()
883 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) in snd_timer_interrupt()
884 snd_timer_reschedule(timer, timer->sticks); in snd_timer_interrupt()
885 if (timer->running) { in snd_timer_interrupt()
886 if (timer->hw.flags & SNDRV_TIMER_HW_STOP) { in snd_timer_interrupt()
887 timer->hw.stop(timer); in snd_timer_interrupt()
888 timer->flags |= SNDRV_TIMER_FLG_CHANGE; in snd_timer_interrupt()
890 if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) || in snd_timer_interrupt()
891 (timer->flags & SNDRV_TIMER_FLG_CHANGE)) { in snd_timer_interrupt()
893 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; in snd_timer_interrupt()
894 timer->hw.start(timer); in snd_timer_interrupt()
897 timer->hw.stop(timer); in snd_timer_interrupt()
901 snd_timer_process_callbacks(timer, &timer->ack_list_head); in snd_timer_interrupt()
904 if (!list_empty(&timer->sack_list_head)) in snd_timer_interrupt()
905 queue_work(system_highpri_wq, &timer->task_work); in snd_timer_interrupt()
925 return -EINVAL; in snd_timer_new()
926 if (tid->dev_class == SNDRV_TIMER_CLASS_CARD || in snd_timer_new()
927 tid->dev_class == SNDRV_TIMER_CLASS_PCM) { in snd_timer_new()
929 return -EINVAL; in snd_timer_new()
935 return -ENOMEM; in snd_timer_new()
936 timer->tmr_class = tid->dev_class; in snd_timer_new()
937 timer->card = card; in snd_timer_new()
938 timer->tmr_device = tid->device; in snd_timer_new()
939 timer->tmr_subdevice = tid->subdevice; in snd_timer_new()
941 strscpy(timer->id, id, sizeof(timer->id)); in snd_timer_new()
942 timer->sticks = 1; in snd_timer_new()
943 INIT_LIST_HEAD(&timer->device_list); in snd_timer_new()
944 INIT_LIST_HEAD(&timer->open_list_head); in snd_timer_new()
945 INIT_LIST_HEAD(&timer->active_list_head); in snd_timer_new()
946 INIT_LIST_HEAD(&timer->ack_list_head); in snd_timer_new()
947 INIT_LIST_HEAD(&timer->sack_list_head); in snd_timer_new()
948 spin_lock_init(&timer->lock); in snd_timer_new()
949 INIT_WORK(&timer->task_work, snd_timer_work); in snd_timer_new()
950 timer->max_instances = 1000; /* default limit per timer */ in snd_timer_new()
952 timer->module = card->module; in snd_timer_new()
970 guard(mutex)(®ister_mutex); in snd_timer_free()
971 if (! list_empty(&timer->open_list_head)) { in snd_timer_free()
975 list_for_each_safe(p, n, &timer->open_list_head) { in snd_timer_free()
978 ti->timer = NULL; in snd_timer_free()
981 list_del(&timer->device_list); in snd_timer_free()
983 if (timer->private_free) in snd_timer_free()
984 timer->private_free(timer); in snd_timer_free()
991 struct snd_timer *timer = device->device_data; in snd_timer_dev_free()
997 struct snd_timer *timer = dev->device_data; in snd_timer_dev_register()
1000 if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop)) in snd_timer_dev_register()
1001 return -ENXIO; in snd_timer_dev_register()
1002 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && in snd_timer_dev_register()
1003 !timer->hw.resolution && timer->hw.c_resolution == NULL) in snd_timer_dev_register()
1004 return -EINVAL; in snd_timer_dev_register()
1006 guard(mutex)(®ister_mutex); in snd_timer_dev_register()
1008 if (timer1->tmr_class > timer->tmr_class) in snd_timer_dev_register()
1010 if (timer1->tmr_class < timer->tmr_class) in snd_timer_dev_register()
1012 if (timer1->card && timer->card) { in snd_timer_dev_register()
1013 if (timer1->card->number > timer->card->number) in snd_timer_dev_register()
1015 if (timer1->card->number < timer->card->number) in snd_timer_dev_register()
1018 if (timer1->tmr_device > timer->tmr_device) in snd_timer_dev_register()
1020 if (timer1->tmr_device < timer->tmr_device) in snd_timer_dev_register()
1022 if (timer1->tmr_subdevice > timer->tmr_subdevice) in snd_timer_dev_register()
1024 if (timer1->tmr_subdevice < timer->tmr_subdevice) in snd_timer_dev_register()
1027 return -EBUSY; in snd_timer_dev_register()
1029 list_add_tail(&timer->device_list, &timer1->device_list); in snd_timer_dev_register()
1035 struct snd_timer *timer = device->device_data; in snd_timer_dev_disconnect()
1038 guard(mutex)(®ister_mutex); in snd_timer_dev_disconnect()
1039 list_del_init(&timer->device_list); in snd_timer_dev_disconnect()
1041 list_for_each_entry(ti, &timer->open_list_head, open_list) { in snd_timer_dev_disconnect()
1042 if (ti->disconnect) in snd_timer_dev_disconnect()
1043 ti->disconnect(ti); in snd_timer_dev_disconnect()
1053 if (timer->card && timer->card->shutdown) in snd_timer_notify()
1055 if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) in snd_timer_notify()
1060 guard(spinlock_irqsave)(&timer->lock); in snd_timer_notify()
1065 list_for_each_entry(ti, &timer->active_list_head, active_list) { in snd_timer_notify()
1066 if (ti->ccallback) in snd_timer_notify()
1067 ti->ccallback(ti, event, tstamp, resolution); in snd_timer_notify()
1068 list_for_each_entry(ts, &ti->slave_active_head, active_list) in snd_timer_notify()
1069 if (ts->ccallback) in snd_timer_notify()
1070 ts->ccallback(ts, event, tstamp, resolution); in snd_timer_notify()
1084 tid.card = -1; in snd_timer_global_new()
1123 struct snd_timer *timer = priv->snd_timer; in snd_timer_s_function()
1125 if (time_after(jiff, priv->last_expires)) in snd_timer_s_function()
1126 priv->correction += (long)jiff - (long)priv->last_expires; in snd_timer_s_function()
1127 snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies); in snd_timer_s_function()
1135 priv = (struct snd_timer_system_private *) timer->private_data; in snd_timer_s_start()
1136 njiff = (priv->last_jiffies = jiffies); in snd_timer_s_start()
1137 if (priv->correction > timer->sticks - 1) { in snd_timer_s_start()
1138 priv->correction -= timer->sticks - 1; in snd_timer_s_start()
1141 njiff += timer->sticks - priv->correction; in snd_timer_s_start()
1142 priv->correction = 0; in snd_timer_s_start()
1144 priv->last_expires = njiff; in snd_timer_s_start()
1145 mod_timer(&priv->tlist, njiff); in snd_timer_s_start()
1154 priv = (struct snd_timer_system_private *) timer->private_data; in snd_timer_s_stop()
1155 del_timer(&priv->tlist); in snd_timer_s_stop()
1157 if (time_before(jiff, priv->last_expires)) in snd_timer_s_stop()
1158 timer->sticks = priv->last_expires - jiff; in snd_timer_s_stop()
1160 timer->sticks = 1; in snd_timer_s_stop()
1161 priv->correction = 0; in snd_timer_s_stop()
1169 priv = (struct snd_timer_system_private *)timer->private_data; in snd_timer_s_close()
1170 del_timer_sync(&priv->tlist); in snd_timer_s_close()
1186 kfree(timer->private_data); in snd_timer_free_system()
1198 strcpy(timer->name, "system timer"); in snd_timer_register_system()
1199 timer->hw = snd_timer_system; in snd_timer_register_system()
1203 return -ENOMEM; in snd_timer_register_system()
1205 priv->snd_timer = timer; in snd_timer_register_system()
1206 timer_setup(&priv->tlist, snd_timer_s_function, 0); in snd_timer_register_system()
1207 timer->private_data = priv; in snd_timer_register_system()
1208 timer->private_free = snd_timer_free_system; in snd_timer_register_system()
1224 guard(mutex)(®ister_mutex); in snd_timer_proc_read()
1226 if (timer->card && timer->card->shutdown) in snd_timer_proc_read()
1228 switch (timer->tmr_class) { in snd_timer_proc_read()
1230 snd_iprintf(buffer, "G%i: ", timer->tmr_device); in snd_timer_proc_read()
1233 snd_iprintf(buffer, "C%i-%i: ", in snd_timer_proc_read()
1234 timer->card->number, timer->tmr_device); in snd_timer_proc_read()
1237 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, in snd_timer_proc_read()
1238 timer->tmr_device, timer->tmr_subdevice); in snd_timer_proc_read()
1241 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class, in snd_timer_proc_read()
1242 timer->card ? timer->card->number : -1, in snd_timer_proc_read()
1243 timer->tmr_device, timer->tmr_subdevice); in snd_timer_proc_read()
1245 snd_iprintf(buffer, "%s :", timer->name); in snd_timer_proc_read()
1246 scoped_guard(spinlock_irq, &timer->lock) in snd_timer_proc_read()
1252 timer->hw.ticks); in snd_timer_proc_read()
1253 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_proc_read()
1256 list_for_each_entry(ti, &timer->open_list_head, open_list) in snd_timer_proc_read()
1258 ti->owner ? ti->owner : "unknown", in snd_timer_proc_read()
1259 (ti->flags & (SNDRV_TIMER_IFLG_START | in snd_timer_proc_read()
1273 entry->c.text.read = snd_timer_proc_read; in snd_timer_proc_init()
1299 struct snd_timer_user *tu = timeri->callback_data; in snd_timer_user_interrupt()
1303 guard(spinlock)(&tu->qlock); in snd_timer_user_interrupt()
1304 if (tu->qused > 0) { in snd_timer_user_interrupt()
1305 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; in snd_timer_user_interrupt()
1306 r = &tu->queue[prev]; in snd_timer_user_interrupt()
1307 if (r->resolution == resolution) { in snd_timer_user_interrupt()
1308 r->ticks += ticks; in snd_timer_user_interrupt()
1312 if (tu->qused >= tu->queue_size) { in snd_timer_user_interrupt()
1313 tu->overrun++; in snd_timer_user_interrupt()
1315 r = &tu->queue[tu->qtail++]; in snd_timer_user_interrupt()
1316 tu->qtail %= tu->queue_size; in snd_timer_user_interrupt()
1317 r->resolution = resolution; in snd_timer_user_interrupt()
1318 r->ticks = ticks; in snd_timer_user_interrupt()
1319 tu->qused++; in snd_timer_user_interrupt()
1322 snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); in snd_timer_user_interrupt()
1323 wake_up(&tu->qchange_sleep); in snd_timer_user_interrupt()
1329 if (tu->qused >= tu->queue_size) { in snd_timer_user_append_to_tqueue()
1330 tu->overrun++; in snd_timer_user_append_to_tqueue()
1332 memcpy(&tu->tqueue[tu->qtail++], tread, sizeof(*tread)); in snd_timer_user_append_to_tqueue()
1333 tu->qtail %= tu->queue_size; in snd_timer_user_append_to_tqueue()
1334 tu->qused++; in snd_timer_user_append_to_tqueue()
1343 struct snd_timer_user *tu = timeri->callback_data; in snd_timer_user_ccallback()
1348 tu->tstamp = *tstamp; in snd_timer_user_ccallback()
1349 if ((tu->filter & (1 << event)) == 0 || !tu->tread) in snd_timer_user_ccallback()
1353 r1.tstamp_sec = tstamp->tv_sec; in snd_timer_user_ccallback()
1354 r1.tstamp_nsec = tstamp->tv_nsec; in snd_timer_user_ccallback()
1356 scoped_guard(spinlock_irqsave, &tu->qlock) in snd_timer_user_ccallback()
1358 snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); in snd_timer_user_ccallback()
1359 wake_up(&tu->qchange_sleep); in snd_timer_user_ccallback()
1364 struct snd_timer_user *tu = timeri->callback_data; in snd_timer_user_disconnect()
1366 tu->disconnected = true; in snd_timer_user_disconnect()
1367 wake_up(&tu->qchange_sleep); in snd_timer_user_disconnect()
1374 struct snd_timer_user *tu = timeri->callback_data; in snd_timer_user_tinterrupt()
1381 scoped_guard(spinlock, &tu->qlock) { in snd_timer_user_tinterrupt()
1382 if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) | in snd_timer_user_tinterrupt()
1385 if (tu->last_resolution != resolution || ticks > 0) { in snd_timer_user_tinterrupt()
1391 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) && in snd_timer_user_tinterrupt()
1392 tu->last_resolution != resolution) { in snd_timer_user_tinterrupt()
1398 tu->last_resolution = resolution; in snd_timer_user_tinterrupt()
1401 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0) in snd_timer_user_tinterrupt()
1405 if (tu->qused > 0) { in snd_timer_user_tinterrupt()
1406 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1; in snd_timer_user_tinterrupt()
1407 r = &tu->tqueue[prev]; in snd_timer_user_tinterrupt()
1408 if (r->event == SNDRV_TIMER_EVENT_TICK) { in snd_timer_user_tinterrupt()
1409 r->tstamp_sec = tstamp.tv_sec; in snd_timer_user_tinterrupt()
1410 r->tstamp_nsec = tstamp.tv_nsec; in snd_timer_user_tinterrupt()
1411 r->val += ticks; in snd_timer_user_tinterrupt()
1425 snd_kill_fasync(tu->fasync, SIGIO, POLL_IN); in snd_timer_user_tinterrupt()
1426 wake_up(&tu->qchange_sleep); in snd_timer_user_tinterrupt()
1434 if (tu->tread) { in realloc_user_queue()
1437 return -ENOMEM; in realloc_user_queue()
1441 return -ENOMEM; in realloc_user_queue()
1444 guard(spinlock_irq)(&tu->qlock); in realloc_user_queue()
1445 kfree(tu->queue); in realloc_user_queue()
1446 kfree(tu->tqueue); in realloc_user_queue()
1447 tu->queue_size = size; in realloc_user_queue()
1448 tu->queue = queue; in realloc_user_queue()
1449 tu->tqueue = tqueue; in realloc_user_queue()
1450 tu->qhead = tu->qtail = tu->qused = 0; in realloc_user_queue()
1466 return -ENOMEM; in snd_timer_user_open()
1467 spin_lock_init(&tu->qlock); in snd_timer_user_open()
1468 init_waitqueue_head(&tu->qchange_sleep); in snd_timer_user_open()
1469 mutex_init(&tu->ioctl_lock); in snd_timer_user_open()
1470 tu->ticks = 1; in snd_timer_user_open()
1473 return -ENOMEM; in snd_timer_user_open()
1475 file->private_data = tu; in snd_timer_user_open()
1483 if (file->private_data) { in snd_timer_user_release()
1484 tu = file->private_data; in snd_timer_user_release()
1485 file->private_data = NULL; in snd_timer_user_release()
1486 scoped_guard(mutex, &tu->ioctl_lock) { in snd_timer_user_release()
1487 if (tu->timeri) { in snd_timer_user_release()
1488 snd_timer_close(tu->timeri); in snd_timer_user_release()
1489 snd_timer_instance_free(tu->timeri); in snd_timer_user_release()
1492 snd_fasync_free(tu->fasync); in snd_timer_user_release()
1493 kfree(tu->queue); in snd_timer_user_release()
1494 kfree(tu->tqueue); in snd_timer_user_release()
1502 id->dev_class = SNDRV_TIMER_CLASS_NONE; in snd_timer_user_zero_id()
1503 id->dev_sclass = SNDRV_TIMER_SCLASS_NONE; in snd_timer_user_zero_id()
1504 id->card = -1; in snd_timer_user_zero_id()
1505 id->device = -1; in snd_timer_user_zero_id()
1506 id->subdevice = -1; in snd_timer_user_zero_id()
1511 id->dev_class = timer->tmr_class; in snd_timer_user_copy_id()
1512 id->dev_sclass = SNDRV_TIMER_SCLASS_NONE; in snd_timer_user_copy_id()
1513 id->card = timer->card ? timer->card->number : -1; in snd_timer_user_copy_id()
1514 id->device = timer->tmr_device; in snd_timer_user_copy_id()
1515 id->subdevice = timer->tmr_subdevice; in snd_timer_user_copy_id()
1525 return -EFAULT; in snd_timer_user_next_device()
1526 guard(mutex)(®ister_mutex); in snd_timer_user_next_device()
1541 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) { in snd_timer_user_next_device()
1545 if (timer->tmr_device >= id.device) { in snd_timer_user_next_device()
1569 if (timer->tmr_class > id.dev_class) { in snd_timer_user_next_device()
1573 if (timer->tmr_class < id.dev_class) in snd_timer_user_next_device()
1575 if (timer->card->number > id.card) { in snd_timer_user_next_device()
1579 if (timer->card->number < id.card) in snd_timer_user_next_device()
1581 if (timer->tmr_device > id.device) { in snd_timer_user_next_device()
1585 if (timer->tmr_device < id.device) in snd_timer_user_next_device()
1587 if (timer->tmr_subdevice > id.subdevice) { in snd_timer_user_next_device()
1591 if (timer->tmr_subdevice < id.subdevice) in snd_timer_user_next_device()
1604 return -EFAULT; in snd_timer_user_next_device()
1620 tid = ginfo->tid; in snd_timer_user_ginfo()
1622 ginfo->tid = tid; in snd_timer_user_ginfo()
1623 guard(mutex)(®ister_mutex); in snd_timer_user_ginfo()
1626 return -ENODEV; in snd_timer_user_ginfo()
1627 ginfo->card = t->card ? t->card->number : -1; in snd_timer_user_ginfo()
1628 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_user_ginfo()
1629 ginfo->flags |= SNDRV_TIMER_FLG_SLAVE; in snd_timer_user_ginfo()
1630 strscpy(ginfo->id, t->id, sizeof(ginfo->id)); in snd_timer_user_ginfo()
1631 strscpy(ginfo->name, t->name, sizeof(ginfo->name)); in snd_timer_user_ginfo()
1632 scoped_guard(spinlock_irq, &t->lock) in snd_timer_user_ginfo()
1633 ginfo->resolution = snd_timer_hw_resolution(t); in snd_timer_user_ginfo()
1634 if (t->hw.resolution_min > 0) { in snd_timer_user_ginfo()
1635 ginfo->resolution_min = t->hw.resolution_min; in snd_timer_user_ginfo()
1636 ginfo->resolution_max = t->hw.resolution_max; in snd_timer_user_ginfo()
1638 list_for_each(p, &t->open_list_head) { in snd_timer_user_ginfo()
1639 ginfo->clients++; in snd_timer_user_ginfo()
1642 return -EFAULT; in snd_timer_user_ginfo()
1650 guard(mutex)(®ister_mutex); in timer_set_gparams()
1651 t = snd_timer_find(&gparams->tid); in timer_set_gparams()
1653 return -ENODEV; in timer_set_gparams()
1654 if (!list_empty(&t->open_list_head)) in timer_set_gparams()
1655 return -EBUSY; in timer_set_gparams()
1656 if (!t->hw.set_period) in timer_set_gparams()
1657 return -ENOSYS; in timer_set_gparams()
1658 return t->hw.set_period(t, gparams->period_num, gparams->period_den); in timer_set_gparams()
1667 return -EFAULT; in snd_timer_user_gparams()
1680 return -EFAULT; in snd_timer_user_gstatus()
1684 guard(mutex)(®ister_mutex); in snd_timer_user_gstatus()
1687 guard(spinlock_irq)(&t->lock); in snd_timer_user_gstatus()
1689 if (t->hw.precise_resolution) { in snd_timer_user_gstatus()
1690 t->hw.precise_resolution(t, &gstatus.resolution_num, in snd_timer_user_gstatus()
1697 err = -ENODEV; in snd_timer_user_gstatus()
1700 err = -EFAULT; in snd_timer_user_gstatus()
1712 tu = file->private_data; in snd_timer_user_tselect()
1713 if (tu->timeri) { in snd_timer_user_tselect()
1714 snd_timer_close(tu->timeri); in snd_timer_user_tselect()
1715 snd_timer_instance_free(tu->timeri); in snd_timer_user_tselect()
1716 tu->timeri = NULL; in snd_timer_user_tselect()
1719 err = -EFAULT; in snd_timer_user_tselect()
1722 sprintf(str, "application %i", current->pid); in snd_timer_user_tselect()
1725 tu->timeri = snd_timer_instance_new(str); in snd_timer_user_tselect()
1726 if (!tu->timeri) { in snd_timer_user_tselect()
1727 err = -ENOMEM; in snd_timer_user_tselect()
1731 tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST; in snd_timer_user_tselect()
1732 tu->timeri->callback = tu->tread in snd_timer_user_tselect()
1734 tu->timeri->ccallback = snd_timer_user_ccallback; in snd_timer_user_tselect()
1735 tu->timeri->callback_data = (void *)tu; in snd_timer_user_tselect()
1736 tu->timeri->disconnect = snd_timer_user_disconnect; in snd_timer_user_tselect()
1738 err = snd_timer_open(tu->timeri, &tselect.id, current->pid); in snd_timer_user_tselect()
1740 snd_timer_instance_free(tu->timeri); in snd_timer_user_tselect()
1741 tu->timeri = NULL; in snd_timer_user_tselect()
1755 tu = file->private_data; in snd_timer_user_info()
1756 if (!tu->timeri) in snd_timer_user_info()
1757 return -EBADFD; in snd_timer_user_info()
1758 t = tu->timeri->timer; in snd_timer_user_info()
1760 return -EBADFD; in snd_timer_user_info()
1764 return -ENOMEM; in snd_timer_user_info()
1765 info->card = t->card ? t->card->number : -1; in snd_timer_user_info()
1766 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_user_info()
1767 info->flags |= SNDRV_TIMER_FLG_SLAVE; in snd_timer_user_info()
1768 strscpy(info->id, t->id, sizeof(info->id)); in snd_timer_user_info()
1769 strscpy(info->name, t->name, sizeof(info->name)); in snd_timer_user_info()
1770 scoped_guard(spinlock_irq, &t->lock) in snd_timer_user_info()
1771 info->resolution = snd_timer_hw_resolution(t); in snd_timer_user_info()
1773 return -EFAULT; in snd_timer_user_info()
1785 tu = file->private_data; in snd_timer_user_params()
1786 if (!tu->timeri) in snd_timer_user_params()
1787 return -EBADFD; in snd_timer_user_params()
1788 t = tu->timeri->timer; in snd_timer_user_params()
1790 return -EBADFD; in snd_timer_user_params()
1792 return -EFAULT; in snd_timer_user_params()
1793 if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE)) { in snd_timer_user_params()
1797 err = -EINVAL; in snd_timer_user_params()
1802 resolution = snd_timer_resolution(tu->timeri); in snd_timer_user_params()
1805 err = -EINVAL; in snd_timer_user_params()
1811 err = -EINVAL; in snd_timer_user_params()
1828 err = -EINVAL; in snd_timer_user_params()
1831 snd_timer_stop(tu->timeri); in snd_timer_user_params()
1832 scoped_guard(spinlock_irq, &t->lock) { in snd_timer_user_params()
1833 tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO| in snd_timer_user_params()
1837 tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO; in snd_timer_user_params()
1839 tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE; in snd_timer_user_params()
1841 tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT; in snd_timer_user_params()
1844 (unsigned int)tu->queue_size != params.queue_size) { in snd_timer_user_params()
1849 scoped_guard(spinlock_irq, &tu->qlock) { in snd_timer_user_params()
1850 tu->qhead = tu->qtail = tu->qused = 0; in snd_timer_user_params()
1851 if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) { in snd_timer_user_params()
1852 if (tu->tread) { in snd_timer_user_params()
1862 struct snd_timer_read *r = &tu->queue[0]; in snd_timer_user_params()
1864 r->resolution = 0; in snd_timer_user_params()
1865 r->ticks = 0; in snd_timer_user_params()
1866 tu->qused++; in snd_timer_user_params()
1867 tu->qtail++; in snd_timer_user_params()
1870 tu->filter = params.filter; in snd_timer_user_params()
1871 tu->ticks = params.ticks; in snd_timer_user_params()
1876 return -EFAULT; in snd_timer_user_params()
1886 tu = file->private_data; in snd_timer_user_status32()
1887 if (!tu->timeri) in snd_timer_user_status32()
1888 return -EBADFD; in snd_timer_user_status32()
1890 status.tstamp_sec = tu->tstamp.tv_sec; in snd_timer_user_status32()
1891 status.tstamp_nsec = tu->tstamp.tv_nsec; in snd_timer_user_status32()
1892 status.resolution = snd_timer_resolution(tu->timeri); in snd_timer_user_status32()
1893 status.lost = tu->timeri->lost; in snd_timer_user_status32()
1894 status.overrun = tu->overrun; in snd_timer_user_status32()
1895 scoped_guard(spinlock_irq, &tu->qlock) in snd_timer_user_status32()
1896 status.queue = tu->qused; in snd_timer_user_status32()
1898 return -EFAULT; in snd_timer_user_status32()
1908 tu = file->private_data; in snd_timer_user_status64()
1909 if (!tu->timeri) in snd_timer_user_status64()
1910 return -EBADFD; in snd_timer_user_status64()
1912 status.tstamp_sec = tu->tstamp.tv_sec; in snd_timer_user_status64()
1913 status.tstamp_nsec = tu->tstamp.tv_nsec; in snd_timer_user_status64()
1914 status.resolution = snd_timer_resolution(tu->timeri); in snd_timer_user_status64()
1915 status.lost = tu->timeri->lost; in snd_timer_user_status64()
1916 status.overrun = tu->overrun; in snd_timer_user_status64()
1917 scoped_guard(spinlock_irq, &tu->qlock) in snd_timer_user_status64()
1918 status.queue = tu->qused; in snd_timer_user_status64()
1920 return -EFAULT; in snd_timer_user_status64()
1929 tu = file->private_data; in snd_timer_user_start()
1930 if (!tu->timeri) in snd_timer_user_start()
1931 return -EBADFD; in snd_timer_user_start()
1932 snd_timer_stop(tu->timeri); in snd_timer_user_start()
1933 tu->timeri->lost = 0; in snd_timer_user_start()
1934 tu->last_resolution = 0; in snd_timer_user_start()
1935 err = snd_timer_start(tu->timeri, tu->ticks); in snd_timer_user_start()
1946 tu = file->private_data; in snd_timer_user_stop()
1947 if (!tu->timeri) in snd_timer_user_stop()
1948 return -EBADFD; in snd_timer_user_stop()
1949 err = snd_timer_stop(tu->timeri); in snd_timer_user_stop()
1960 tu = file->private_data; in snd_timer_user_continue()
1961 if (!tu->timeri) in snd_timer_user_continue()
1962 return -EBADFD; in snd_timer_user_continue()
1964 if (!(tu->timeri->flags & SNDRV_TIMER_IFLG_PAUSED)) in snd_timer_user_continue()
1966 tu->timeri->lost = 0; in snd_timer_user_continue()
1967 err = snd_timer_continue(tu->timeri); in snd_timer_user_continue()
1978 tu = file->private_data; in snd_timer_user_pause()
1979 if (!tu->timeri) in snd_timer_user_pause()
1980 return -EBADFD; in snd_timer_user_pause()
1981 err = snd_timer_pause(tu->timeri); in snd_timer_user_pause()
1993 if (tu->timeri) /* too late */ in snd_timer_user_tread()
1994 return -EBUSY; in snd_timer_user_tread()
1996 return -EFAULT; in snd_timer_user_tread()
1998 old_tread = tu->tread; in snd_timer_user_tread()
2001 tu->tread = TREAD_FORMAT_NONE; in snd_timer_user_tread()
2004 tu->tread = TREAD_FORMAT_TIME64; in snd_timer_user_tread()
2006 tu->tread = TREAD_FORMAT_TIME32; in snd_timer_user_tread()
2008 if (tu->tread != old_tread && in snd_timer_user_tread()
2009 realloc_user_queue(tu, tu->queue_size) < 0) { in snd_timer_user_tread()
2010 tu->tread = old_tread; in snd_timer_user_tread()
2011 return -ENOMEM; in snd_timer_user_tread()
2026 * Since userspace-driven timers are passed to userspace, we need to have an identifier
2033 int timer_id = utimer->id; in snd_utimer_put_id()
2041 return ida_alloc_max(&snd_utimer_ids, SNDRV_UTIMERS_MAX_COUNT - 1, GFP_KERNEL); in snd_utimer_take_id()
2046 snd_timer_free(utimer->timer); in snd_utimer_free()
2048 kfree(utimer->name); in snd_utimer_free()
2054 struct snd_utimer *utimer = (struct snd_utimer *)file->private_data; in snd_utimer_release()
2062 struct snd_utimer *utimer = (struct snd_utimer *)file->private_data; in snd_utimer_trigger()
2064 snd_timer_interrupt(utimer->timer, utimer->timer->sticks); in snd_utimer_trigger()
2075 return -ENOTTY; in snd_utimer_ioctl()
2121 if (!utimer_info || utimer_info->resolution == 0) in snd_utimer_create()
2122 return -EINVAL; in snd_utimer_create()
2126 return -ENOMEM; in snd_utimer_create()
2135 utimer->name = kasprintf(GFP_KERNEL, "snd-utimer%d", utimer_id); in snd_utimer_create()
2136 if (!utimer->name) { in snd_utimer_create()
2137 err = -ENOMEM; in snd_utimer_create()
2141 utimer->id = utimer_id; in snd_utimer_create()
2145 tid.card = -1; in snd_utimer_create()
2149 err = snd_timer_new(NULL, utimer->name, &tid, &timer); in snd_utimer_create()
2151 pr_err("Can't create userspace-driven timer\n"); in snd_utimer_create()
2155 timer->module = THIS_MODULE; in snd_utimer_create()
2156 timer->hw = timer_hw; in snd_utimer_create()
2157 timer->hw.resolution = utimer_info->resolution; in snd_utimer_create()
2158 timer->hw.ticks = 1; in snd_utimer_create()
2159 timer->max_instances = MAX_SLAVE_INSTANCES; in snd_utimer_create()
2161 utimer->timer = timer; in snd_utimer_create()
2165 pr_err("Can't register a userspace-driven timer\n"); in snd_utimer_create()
2175 kfree(utimer->name); in snd_utimer_create()
2199 utimer_info->id = utimer->id; in snd_utimer_ioctl_create()
2201 timer_fd = anon_inode_getfd(utimer->name, &snd_utimer_fops, utimer, O_RDWR | O_CLOEXEC); in snd_utimer_ioctl_create()
2207 utimer_info->fd = timer_fd; in snd_utimer_ioctl_create()
2219 return -EFAULT; in snd_utimer_ioctl_create()
2230 return -ENOTTY; in snd_utimer_ioctl_create()
2242 tu = file->private_data; in __snd_timer_user_ioctl()
2245 return put_user(SNDRV_TIMER_VERSION, p) ? -EFAULT : 0; in __snd_timer_user_ioctl()
2282 return -ENOTTY; in __snd_timer_user_ioctl()
2288 struct snd_timer_user *tu = file->private_data; in snd_timer_user_ioctl()
2290 guard(mutex)(&tu->ioctl_lock); in snd_timer_user_ioctl()
2298 tu = file->private_data; in snd_timer_user_fasync()
2299 return snd_fasync_helper(fd, file, on, &tu->fasync); in snd_timer_user_fasync()
2312 tu = file->private_data; in snd_timer_user_read()
2313 switch (tu->tread) { in snd_timer_user_read()
2325 return -ENOTSUPP; in snd_timer_user_read()
2328 mutex_lock(&tu->ioctl_lock); in snd_timer_user_read()
2329 spin_lock_irq(&tu->qlock); in snd_timer_user_read()
2330 while ((long)count - result >= unit) { in snd_timer_user_read()
2331 while (!tu->qused) { in snd_timer_user_read()
2334 if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) { in snd_timer_user_read()
2335 err = -EAGAIN; in snd_timer_user_read()
2341 add_wait_queue(&tu->qchange_sleep, &wait); in snd_timer_user_read()
2343 spin_unlock_irq(&tu->qlock); in snd_timer_user_read()
2344 mutex_unlock(&tu->ioctl_lock); in snd_timer_user_read()
2346 mutex_lock(&tu->ioctl_lock); in snd_timer_user_read()
2347 spin_lock_irq(&tu->qlock); in snd_timer_user_read()
2349 remove_wait_queue(&tu->qchange_sleep, &wait); in snd_timer_user_read()
2351 if (tu->disconnected) { in snd_timer_user_read()
2352 err = -ENODEV; in snd_timer_user_read()
2356 err = -ERESTARTSYS; in snd_timer_user_read()
2361 qhead = tu->qhead++; in snd_timer_user_read()
2362 tu->qhead %= tu->queue_size; in snd_timer_user_read()
2363 tu->qused--; in snd_timer_user_read()
2364 spin_unlock_irq(&tu->qlock); in snd_timer_user_read()
2366 tread = &tu->tqueue[qhead]; in snd_timer_user_read()
2368 switch (tu->tread) { in snd_timer_user_read()
2372 err = -EFAULT; in snd_timer_user_read()
2377 .event = tread->event, in snd_timer_user_read()
2378 .tstamp_sec = tread->tstamp_sec, in snd_timer_user_read()
2379 .tstamp_nsec = tread->tstamp_nsec, in snd_timer_user_read()
2380 .val = tread->val, in snd_timer_user_read()
2384 err = -EFAULT; in snd_timer_user_read()
2387 if (copy_to_user(buffer, &tu->queue[qhead], in snd_timer_user_read()
2389 err = -EFAULT; in snd_timer_user_read()
2392 err = -ENOTSUPP; in snd_timer_user_read()
2396 spin_lock_irq(&tu->qlock); in snd_timer_user_read()
2403 spin_unlock_irq(&tu->qlock); in snd_timer_user_read()
2404 mutex_unlock(&tu->ioctl_lock); in snd_timer_user_read()
2413 tu = file->private_data; in snd_timer_user_poll()
2415 poll_wait(file, &tu->qchange_sleep, wait); in snd_timer_user_poll()
2418 guard(spinlock_irq)(&tu->qlock); in snd_timer_user_poll()
2419 if (tu->qused) in snd_timer_user_poll()
2421 if (tu->disconnected) in snd_timer_user_poll()
2470 snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1, in alsa_timer_init()
2503 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1); in alsa_timer_exit()