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