Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Digital Audio (PCM) 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/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/file.h> |
| 24 | #include <linux/slab.h> |
Jonathan Corbet | 2db9f0a | 2008-06-23 17:40:43 -0600 | [diff] [blame] | 25 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/time.h> |
Mark Gross | f011e2e | 2008-02-04 22:30:09 -0800 | [diff] [blame] | 27 | #include <linux/pm_qos_params.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/uio.h> |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 29 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <sound/core.h> |
| 31 | #include <sound/control.h> |
| 32 | #include <sound/info.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/pcm_params.h> |
| 35 | #include <sound/timer.h> |
| 36 | #include <sound/minors.h> |
| 37 | #include <asm/io.h> |
Takashi Iwai | 9fe17b5 | 2010-05-12 10:32:42 +0200 | [diff] [blame] | 38 | #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT) |
| 39 | #include <dma-coherence.h> |
| 40 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Compatibility |
| 44 | */ |
| 45 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 46 | struct snd_pcm_hw_params_old { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | unsigned int flags; |
| 48 | unsigned int masks[SNDRV_PCM_HW_PARAM_SUBFORMAT - |
| 49 | SNDRV_PCM_HW_PARAM_ACCESS + 1]; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 50 | struct snd_interval intervals[SNDRV_PCM_HW_PARAM_TICK_TIME - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS + 1]; |
| 52 | unsigned int rmask; |
| 53 | unsigned int cmask; |
| 54 | unsigned int info; |
| 55 | unsigned int msbits; |
| 56 | unsigned int rate_num; |
| 57 | unsigned int rate_den; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 58 | snd_pcm_uframes_t fifo_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | unsigned char reserved[64]; |
| 60 | }; |
| 61 | |
Takashi Iwai | 59d4858 | 2005-12-01 10:51:58 +0100 | [diff] [blame] | 62 | #ifdef CONFIG_SND_SUPPORT_OLD_API |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 63 | #define SNDRV_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct snd_pcm_hw_params_old) |
| 64 | #define SNDRV_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct snd_pcm_hw_params_old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 66 | static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, |
| 67 | struct snd_pcm_hw_params_old __user * _oparams); |
| 68 | static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, |
| 69 | struct snd_pcm_hw_params_old __user * _oparams); |
Takashi Iwai | 59d4858 | 2005-12-01 10:51:58 +0100 | [diff] [blame] | 70 | #endif |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 71 | static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * |
| 75 | */ |
| 76 | |
| 77 | DEFINE_RWLOCK(snd_pcm_link_rwlock); |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 78 | EXPORT_SYMBOL(snd_pcm_link_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 80 | static DECLARE_RWSEM(snd_pcm_link_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | static inline mm_segment_t snd_enter_user(void) |
| 83 | { |
| 84 | mm_segment_t fs = get_fs(); |
| 85 | set_fs(get_ds()); |
| 86 | return fs; |
| 87 | } |
| 88 | |
| 89 | static inline void snd_leave_user(mm_segment_t fs) |
| 90 | { |
| 91 | set_fs(fs); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 96 | int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 98 | struct snd_pcm_runtime *runtime; |
| 99 | struct snd_pcm *pcm = substream->pcm; |
| 100 | struct snd_pcm_str *pstr = substream->pstr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | memset(info, 0, sizeof(*info)); |
| 103 | info->card = pcm->card->number; |
| 104 | info->device = pcm->device; |
| 105 | info->stream = substream->stream; |
| 106 | info->subdevice = substream->number; |
| 107 | strlcpy(info->id, pcm->id, sizeof(info->id)); |
| 108 | strlcpy(info->name, pcm->name, sizeof(info->name)); |
| 109 | info->dev_class = pcm->dev_class; |
| 110 | info->dev_subclass = pcm->dev_subclass; |
| 111 | info->subdevices_count = pstr->substream_count; |
| 112 | info->subdevices_avail = pstr->substream_count - pstr->substream_opened; |
| 113 | strlcpy(info->subname, substream->name, sizeof(info->subname)); |
| 114 | runtime = substream->runtime; |
| 115 | /* AB: FIXME!!! This is definitely nonsense */ |
| 116 | if (runtime) { |
| 117 | info->sync = runtime->sync; |
| 118 | substream->ops->ioctl(substream, SNDRV_PCM_IOCTL1_INFO, info); |
| 119 | } |
| 120 | return 0; |
| 121 | } |
| 122 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 123 | int snd_pcm_info_user(struct snd_pcm_substream *substream, |
| 124 | struct snd_pcm_info __user * _info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 126 | struct snd_pcm_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int err; |
| 128 | |
| 129 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 130 | if (! info) |
| 131 | return -ENOMEM; |
| 132 | err = snd_pcm_info(substream, info); |
| 133 | if (err >= 0) { |
| 134 | if (copy_to_user(_info, info, sizeof(*info))) |
| 135 | err = -EFAULT; |
| 136 | } |
| 137 | kfree(info); |
| 138 | return err; |
| 139 | } |
| 140 | |
| 141 | #undef RULES_DEBUG |
| 142 | |
| 143 | #ifdef RULES_DEBUG |
| 144 | #define HW_PARAM(v) [SNDRV_PCM_HW_PARAM_##v] = #v |
Joe Perches | 47023ec | 2010-09-13 21:24:02 -0700 | [diff] [blame^] | 145 | static const char * const snd_pcm_hw_param_names[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | HW_PARAM(ACCESS), |
| 147 | HW_PARAM(FORMAT), |
| 148 | HW_PARAM(SUBFORMAT), |
| 149 | HW_PARAM(SAMPLE_BITS), |
| 150 | HW_PARAM(FRAME_BITS), |
| 151 | HW_PARAM(CHANNELS), |
| 152 | HW_PARAM(RATE), |
| 153 | HW_PARAM(PERIOD_TIME), |
| 154 | HW_PARAM(PERIOD_SIZE), |
| 155 | HW_PARAM(PERIOD_BYTES), |
| 156 | HW_PARAM(PERIODS), |
| 157 | HW_PARAM(BUFFER_TIME), |
| 158 | HW_PARAM(BUFFER_SIZE), |
| 159 | HW_PARAM(BUFFER_BYTES), |
| 160 | HW_PARAM(TICK_TIME), |
| 161 | }; |
| 162 | #endif |
| 163 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 164 | int snd_pcm_hw_refine(struct snd_pcm_substream *substream, |
| 165 | struct snd_pcm_hw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
| 167 | unsigned int k; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 168 | struct snd_pcm_hardware *hw; |
| 169 | struct snd_interval *i = NULL; |
| 170 | struct snd_mask *m = NULL; |
| 171 | struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | unsigned int rstamps[constrs->rules_num]; |
| 173 | unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1]; |
| 174 | unsigned int stamp = 2; |
| 175 | int changed, again; |
| 176 | |
| 177 | params->info = 0; |
| 178 | params->fifo_size = 0; |
| 179 | if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS)) |
| 180 | params->msbits = 0; |
| 181 | if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_RATE)) { |
| 182 | params->rate_num = 0; |
| 183 | params->rate_den = 0; |
| 184 | } |
| 185 | |
| 186 | for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) { |
| 187 | m = hw_param_mask(params, k); |
| 188 | if (snd_mask_empty(m)) |
| 189 | return -EINVAL; |
| 190 | if (!(params->rmask & (1 << k))) |
| 191 | continue; |
| 192 | #ifdef RULES_DEBUG |
Takashi Iwai | 006de267 | 2009-02-05 15:51:04 +0100 | [diff] [blame] | 193 | printk(KERN_DEBUG "%s = ", snd_pcm_hw_param_names[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | printk("%04x%04x%04x%04x -> ", m->bits[3], m->bits[2], m->bits[1], m->bits[0]); |
| 195 | #endif |
| 196 | changed = snd_mask_refine(m, constrs_mask(constrs, k)); |
| 197 | #ifdef RULES_DEBUG |
| 198 | printk("%04x%04x%04x%04x\n", m->bits[3], m->bits[2], m->bits[1], m->bits[0]); |
| 199 | #endif |
| 200 | if (changed) |
| 201 | params->cmask |= 1 << k; |
| 202 | if (changed < 0) |
| 203 | return changed; |
| 204 | } |
| 205 | |
| 206 | for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) { |
| 207 | i = hw_param_interval(params, k); |
| 208 | if (snd_interval_empty(i)) |
| 209 | return -EINVAL; |
| 210 | if (!(params->rmask & (1 << k))) |
| 211 | continue; |
| 212 | #ifdef RULES_DEBUG |
Takashi Iwai | 006de267 | 2009-02-05 15:51:04 +0100 | [diff] [blame] | 213 | printk(KERN_DEBUG "%s = ", snd_pcm_hw_param_names[k]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | if (i->empty) |
| 215 | printk("empty"); |
| 216 | else |
| 217 | printk("%c%u %u%c", |
| 218 | i->openmin ? '(' : '[', i->min, |
| 219 | i->max, i->openmax ? ')' : ']'); |
| 220 | printk(" -> "); |
| 221 | #endif |
| 222 | changed = snd_interval_refine(i, constrs_interval(constrs, k)); |
| 223 | #ifdef RULES_DEBUG |
| 224 | if (i->empty) |
| 225 | printk("empty\n"); |
| 226 | else |
| 227 | printk("%c%u %u%c\n", |
| 228 | i->openmin ? '(' : '[', i->min, |
| 229 | i->max, i->openmax ? ')' : ']'); |
| 230 | #endif |
| 231 | if (changed) |
| 232 | params->cmask |= 1 << k; |
| 233 | if (changed < 0) |
| 234 | return changed; |
| 235 | } |
| 236 | |
| 237 | for (k = 0; k < constrs->rules_num; k++) |
| 238 | rstamps[k] = 0; |
| 239 | for (k = 0; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) |
| 240 | vstamps[k] = (params->rmask & (1 << k)) ? 1 : 0; |
| 241 | do { |
| 242 | again = 0; |
| 243 | for (k = 0; k < constrs->rules_num; k++) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 244 | struct snd_pcm_hw_rule *r = &constrs->rules[k]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | unsigned int d; |
| 246 | int doit = 0; |
| 247 | if (r->cond && !(r->cond & params->flags)) |
| 248 | continue; |
| 249 | for (d = 0; r->deps[d] >= 0; d++) { |
| 250 | if (vstamps[r->deps[d]] > rstamps[k]) { |
| 251 | doit = 1; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | if (!doit) |
| 256 | continue; |
| 257 | #ifdef RULES_DEBUG |
Takashi Iwai | 006de267 | 2009-02-05 15:51:04 +0100 | [diff] [blame] | 258 | printk(KERN_DEBUG "Rule %d [%p]: ", k, r->func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | if (r->var >= 0) { |
| 260 | printk("%s = ", snd_pcm_hw_param_names[r->var]); |
| 261 | if (hw_is_mask(r->var)) { |
| 262 | m = hw_param_mask(params, r->var); |
| 263 | printk("%x", *m->bits); |
| 264 | } else { |
| 265 | i = hw_param_interval(params, r->var); |
| 266 | if (i->empty) |
| 267 | printk("empty"); |
| 268 | else |
| 269 | printk("%c%u %u%c", |
| 270 | i->openmin ? '(' : '[', i->min, |
| 271 | i->max, i->openmax ? ')' : ']'); |
| 272 | } |
| 273 | } |
| 274 | #endif |
| 275 | changed = r->func(params, r); |
| 276 | #ifdef RULES_DEBUG |
| 277 | if (r->var >= 0) { |
| 278 | printk(" -> "); |
| 279 | if (hw_is_mask(r->var)) |
| 280 | printk("%x", *m->bits); |
| 281 | else { |
| 282 | if (i->empty) |
| 283 | printk("empty"); |
| 284 | else |
| 285 | printk("%c%u %u%c", |
| 286 | i->openmin ? '(' : '[', i->min, |
| 287 | i->max, i->openmax ? ')' : ']'); |
| 288 | } |
| 289 | } |
| 290 | printk("\n"); |
| 291 | #endif |
| 292 | rstamps[k] = stamp; |
| 293 | if (changed && r->var >= 0) { |
| 294 | params->cmask |= (1 << r->var); |
| 295 | vstamps[r->var] = stamp; |
| 296 | again = 1; |
| 297 | } |
| 298 | if (changed < 0) |
| 299 | return changed; |
| 300 | stamp++; |
| 301 | } |
| 302 | } while (again); |
| 303 | if (!params->msbits) { |
| 304 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); |
| 305 | if (snd_interval_single(i)) |
| 306 | params->msbits = snd_interval_value(i); |
| 307 | } |
| 308 | |
| 309 | if (!params->rate_den) { |
| 310 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 311 | if (snd_interval_single(i)) { |
| 312 | params->rate_num = snd_interval_value(i); |
| 313 | params->rate_den = 1; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | hw = &substream->runtime->hw; |
| 318 | if (!params->info) |
Jaroslav Kysela | 8bea869 | 2009-04-27 09:44:40 +0200 | [diff] [blame] | 319 | params->info = hw->info & ~SNDRV_PCM_INFO_FIFO_IN_FRAMES; |
| 320 | if (!params->fifo_size) { |
Jaroslav Kysela | 3be522a | 2010-02-16 11:55:43 +0100 | [diff] [blame] | 321 | m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); |
| 322 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 323 | if (snd_mask_min(m) == snd_mask_max(m) && |
| 324 | snd_interval_min(i) == snd_interval_max(i)) { |
Jaroslav Kysela | 8bea869 | 2009-04-27 09:44:40 +0200 | [diff] [blame] | 325 | changed = substream->ops->ioctl(substream, |
| 326 | SNDRV_PCM_IOCTL1_FIFO_SIZE, params); |
Mariusz Kozlowski | 8bd9bca | 2009-06-21 20:26:59 +0200 | [diff] [blame] | 327 | if (changed < 0) |
Jaroslav Kysela | 8bea869 | 2009-04-27 09:44:40 +0200 | [diff] [blame] | 328 | return changed; |
| 329 | } |
| 330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | params->rmask = 0; |
| 332 | return 0; |
| 333 | } |
| 334 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 335 | EXPORT_SYMBOL(snd_pcm_hw_refine); |
| 336 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 337 | static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream, |
| 338 | struct snd_pcm_hw_params __user * _params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 340 | struct snd_pcm_hw_params *params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int err; |
| 342 | |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 343 | params = memdup_user(_params, sizeof(*params)); |
| 344 | if (IS_ERR(params)) |
| 345 | return PTR_ERR(params); |
| 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | err = snd_pcm_hw_refine(substream, params); |
| 348 | if (copy_to_user(_params, params, sizeof(*params))) { |
| 349 | if (!err) |
| 350 | err = -EFAULT; |
| 351 | } |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | kfree(params); |
| 354 | return err; |
| 355 | } |
| 356 | |
Takashi Iwai | 9442e69 | 2006-09-30 23:27:19 -0700 | [diff] [blame] | 357 | static int period_to_usecs(struct snd_pcm_runtime *runtime) |
| 358 | { |
| 359 | int usecs; |
| 360 | |
| 361 | if (! runtime->rate) |
| 362 | return -1; /* invalid */ |
| 363 | |
| 364 | /* take 75% of period time as the deadline */ |
| 365 | usecs = (750000 / runtime->rate) * runtime->period_size; |
| 366 | usecs += ((750000 % runtime->rate) * runtime->period_size) / |
| 367 | runtime->rate; |
| 368 | |
| 369 | return usecs; |
| 370 | } |
| 371 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 372 | static int snd_pcm_hw_params(struct snd_pcm_substream *substream, |
| 373 | struct snd_pcm_hw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 375 | struct snd_pcm_runtime *runtime; |
Takashi Iwai | 9442e69 | 2006-09-30 23:27:19 -0700 | [diff] [blame] | 376 | int err, usecs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | unsigned int bits; |
| 378 | snd_pcm_uframes_t frames; |
| 379 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 380 | if (PCM_RUNTIME_CHECK(substream)) |
| 381 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | snd_pcm_stream_lock_irq(substream); |
| 384 | switch (runtime->status->state) { |
| 385 | case SNDRV_PCM_STATE_OPEN: |
| 386 | case SNDRV_PCM_STATE_SETUP: |
| 387 | case SNDRV_PCM_STATE_PREPARED: |
| 388 | break; |
| 389 | default: |
| 390 | snd_pcm_stream_unlock_irq(substream); |
| 391 | return -EBADFD; |
| 392 | } |
| 393 | snd_pcm_stream_unlock_irq(substream); |
| 394 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) |
| 395 | if (!substream->oss.oss) |
| 396 | #endif |
Takashi Iwai | 9c323fc | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 397 | if (atomic_read(&substream->mmap_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return -EBADFD; |
| 399 | |
| 400 | params->rmask = ~0U; |
| 401 | err = snd_pcm_hw_refine(substream, params); |
| 402 | if (err < 0) |
| 403 | goto _error; |
| 404 | |
| 405 | err = snd_pcm_hw_params_choose(substream, params); |
| 406 | if (err < 0) |
| 407 | goto _error; |
| 408 | |
| 409 | if (substream->ops->hw_params != NULL) { |
| 410 | err = substream->ops->hw_params(substream, params); |
| 411 | if (err < 0) |
| 412 | goto _error; |
| 413 | } |
| 414 | |
| 415 | runtime->access = params_access(params); |
| 416 | runtime->format = params_format(params); |
| 417 | runtime->subformat = params_subformat(params); |
| 418 | runtime->channels = params_channels(params); |
| 419 | runtime->rate = params_rate(params); |
| 420 | runtime->period_size = params_period_size(params); |
| 421 | runtime->periods = params_periods(params); |
| 422 | runtime->buffer_size = params_buffer_size(params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | runtime->info = params->info; |
| 424 | runtime->rate_num = params->rate_num; |
| 425 | runtime->rate_den = params->rate_den; |
| 426 | |
| 427 | bits = snd_pcm_format_physical_width(runtime->format); |
| 428 | runtime->sample_bits = bits; |
| 429 | bits *= runtime->channels; |
| 430 | runtime->frame_bits = bits; |
| 431 | frames = 1; |
| 432 | while (bits % 8 != 0) { |
| 433 | bits *= 2; |
| 434 | frames *= 2; |
| 435 | } |
| 436 | runtime->byte_align = bits / 8; |
| 437 | runtime->min_align = frames; |
| 438 | |
| 439 | /* Default sw params */ |
| 440 | runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; |
| 441 | runtime->period_step = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | runtime->control->avail_min = runtime->period_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | runtime->start_threshold = 1; |
| 444 | runtime->stop_threshold = runtime->buffer_size; |
| 445 | runtime->silence_threshold = 0; |
| 446 | runtime->silence_size = 0; |
Clemens Ladisch | ead4046 | 2010-05-21 09:15:59 +0200 | [diff] [blame] | 447 | runtime->boundary = runtime->buffer_size; |
| 448 | while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) |
| 449 | runtime->boundary *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | snd_pcm_timer_resolution_change(substream); |
| 452 | runtime->status->state = SNDRV_PCM_STATE_SETUP; |
Takashi Iwai | 9442e69 | 2006-09-30 23:27:19 -0700 | [diff] [blame] | 453 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 454 | if (pm_qos_request_active(&substream->latency_pm_qos_req)) |
| 455 | pm_qos_remove_request(&substream->latency_pm_qos_req); |
Takashi Iwai | 9442e69 | 2006-09-30 23:27:19 -0700 | [diff] [blame] | 456 | if ((usecs = period_to_usecs(runtime)) >= 0) |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 457 | pm_qos_add_request(&substream->latency_pm_qos_req, |
| 458 | PM_QOS_CPU_DMA_LATENCY, usecs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return 0; |
| 460 | _error: |
| 461 | /* hardware might be unuseable from this time, |
| 462 | so we force application to retry to set |
| 463 | the correct hardware parameter settings */ |
| 464 | runtime->status->state = SNDRV_PCM_STATE_OPEN; |
| 465 | if (substream->ops->hw_free != NULL) |
| 466 | substream->ops->hw_free(substream); |
| 467 | return err; |
| 468 | } |
| 469 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 470 | static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream, |
| 471 | struct snd_pcm_hw_params __user * _params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 473 | struct snd_pcm_hw_params *params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | int err; |
| 475 | |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 476 | params = memdup_user(_params, sizeof(*params)); |
| 477 | if (IS_ERR(params)) |
| 478 | return PTR_ERR(params); |
| 479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | err = snd_pcm_hw_params(substream, params); |
| 481 | if (copy_to_user(_params, params, sizeof(*params))) { |
| 482 | if (!err) |
| 483 | err = -EFAULT; |
| 484 | } |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | kfree(params); |
| 487 | return err; |
| 488 | } |
| 489 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 490 | static int snd_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 492 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | int result = 0; |
| 494 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 495 | if (PCM_RUNTIME_CHECK(substream)) |
| 496 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | snd_pcm_stream_lock_irq(substream); |
| 499 | switch (runtime->status->state) { |
| 500 | case SNDRV_PCM_STATE_SETUP: |
| 501 | case SNDRV_PCM_STATE_PREPARED: |
| 502 | break; |
| 503 | default: |
| 504 | snd_pcm_stream_unlock_irq(substream); |
| 505 | return -EBADFD; |
| 506 | } |
| 507 | snd_pcm_stream_unlock_irq(substream); |
Takashi Iwai | 9c323fc | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 508 | if (atomic_read(&substream->mmap_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | return -EBADFD; |
| 510 | if (substream->ops->hw_free) |
| 511 | result = substream->ops->hw_free(substream); |
| 512 | runtime->status->state = SNDRV_PCM_STATE_OPEN; |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 513 | pm_qos_remove_request(&substream->latency_pm_qos_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | return result; |
| 515 | } |
| 516 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 517 | static int snd_pcm_sw_params(struct snd_pcm_substream *substream, |
| 518 | struct snd_pcm_sw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 520 | struct snd_pcm_runtime *runtime; |
Jaroslav Kysela | 1250932 | 2010-01-07 15:36:31 +0100 | [diff] [blame] | 521 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 523 | if (PCM_RUNTIME_CHECK(substream)) |
| 524 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | snd_pcm_stream_lock_irq(substream); |
| 527 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { |
| 528 | snd_pcm_stream_unlock_irq(substream); |
| 529 | return -EBADFD; |
| 530 | } |
| 531 | snd_pcm_stream_unlock_irq(substream); |
| 532 | |
| 533 | if (params->tstamp_mode > SNDRV_PCM_TSTAMP_LAST) |
| 534 | return -EINVAL; |
| 535 | if (params->avail_min == 0) |
| 536 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | if (params->silence_size >= runtime->boundary) { |
| 538 | if (params->silence_threshold != 0) |
| 539 | return -EINVAL; |
| 540 | } else { |
| 541 | if (params->silence_size > params->silence_threshold) |
| 542 | return -EINVAL; |
| 543 | if (params->silence_threshold > runtime->buffer_size) |
| 544 | return -EINVAL; |
| 545 | } |
Jaroslav Kysela | 1250932 | 2010-01-07 15:36:31 +0100 | [diff] [blame] | 546 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | snd_pcm_stream_lock_irq(substream); |
| 548 | runtime->tstamp_mode = params->tstamp_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | runtime->period_step = params->period_step; |
| 550 | runtime->control->avail_min = params->avail_min; |
| 551 | runtime->start_threshold = params->start_threshold; |
| 552 | runtime->stop_threshold = params->stop_threshold; |
| 553 | runtime->silence_threshold = params->silence_threshold; |
| 554 | runtime->silence_size = params->silence_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | params->boundary = runtime->boundary; |
| 556 | if (snd_pcm_running(substream)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 558 | runtime->silence_size > 0) |
| 559 | snd_pcm_playback_silence(substream, ULONG_MAX); |
Jaroslav Kysela | 1250932 | 2010-01-07 15:36:31 +0100 | [diff] [blame] | 560 | err = snd_pcm_update_state(substream, runtime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | snd_pcm_stream_unlock_irq(substream); |
Jaroslav Kysela | 1250932 | 2010-01-07 15:36:31 +0100 | [diff] [blame] | 563 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 566 | static int snd_pcm_sw_params_user(struct snd_pcm_substream *substream, |
| 567 | struct snd_pcm_sw_params __user * _params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 569 | struct snd_pcm_sw_params params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | int err; |
| 571 | if (copy_from_user(¶ms, _params, sizeof(params))) |
| 572 | return -EFAULT; |
| 573 | err = snd_pcm_sw_params(substream, ¶ms); |
| 574 | if (copy_to_user(_params, ¶ms, sizeof(params))) |
| 575 | return -EFAULT; |
| 576 | return err; |
| 577 | } |
| 578 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 579 | int snd_pcm_status(struct snd_pcm_substream *substream, |
| 580 | struct snd_pcm_status *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 582 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | snd_pcm_stream_lock_irq(substream); |
| 585 | status->state = runtime->status->state; |
| 586 | status->suspended_state = runtime->status->suspended_state; |
| 587 | if (status->state == SNDRV_PCM_STATE_OPEN) |
| 588 | goto _end; |
| 589 | status->trigger_tstamp = runtime->trigger_tstamp; |
Jaroslav Kysela | 8c12158 | 2008-01-11 08:45:08 +0100 | [diff] [blame] | 590 | if (snd_pcm_running(substream)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | snd_pcm_update_hw_ptr(substream); |
Jaroslav Kysela | 8c12158 | 2008-01-11 08:45:08 +0100 | [diff] [blame] | 592 | if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { |
| 593 | status->tstamp = runtime->status->tstamp; |
| 594 | goto _tstamp_end; |
| 595 | } |
| 596 | } |
Jaroslav Kysela | a713b58 | 2008-01-08 12:24:01 +0100 | [diff] [blame] | 597 | snd_pcm_gettime(runtime, &status->tstamp); |
Jaroslav Kysela | 8c12158 | 2008-01-11 08:45:08 +0100 | [diff] [blame] | 598 | _tstamp_end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | status->appl_ptr = runtime->control->appl_ptr; |
| 600 | status->hw_ptr = runtime->status->hw_ptr; |
| 601 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 602 | status->avail = snd_pcm_playback_avail(runtime); |
| 603 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING || |
Takashi Iwai | 4bbe1dd | 2008-10-13 03:07:14 +0200 | [diff] [blame] | 604 | runtime->status->state == SNDRV_PCM_STATE_DRAINING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | status->delay = runtime->buffer_size - status->avail; |
Takashi Iwai | 4bbe1dd | 2008-10-13 03:07:14 +0200 | [diff] [blame] | 606 | status->delay += runtime->delay; |
| 607 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | status->delay = 0; |
| 609 | } else { |
| 610 | status->avail = snd_pcm_capture_avail(runtime); |
| 611 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) |
Takashi Iwai | 4bbe1dd | 2008-10-13 03:07:14 +0200 | [diff] [blame] | 612 | status->delay = status->avail + runtime->delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | else |
| 614 | status->delay = 0; |
| 615 | } |
| 616 | status->avail_max = runtime->avail_max; |
| 617 | status->overrange = runtime->overrange; |
| 618 | runtime->avail_max = 0; |
| 619 | runtime->overrange = 0; |
| 620 | _end: |
| 621 | snd_pcm_stream_unlock_irq(substream); |
| 622 | return 0; |
| 623 | } |
| 624 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 625 | static int snd_pcm_status_user(struct snd_pcm_substream *substream, |
| 626 | struct snd_pcm_status __user * _status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 628 | struct snd_pcm_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | int res; |
| 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | memset(&status, 0, sizeof(status)); |
| 632 | res = snd_pcm_status(substream, &status); |
| 633 | if (res < 0) |
| 634 | return res; |
| 635 | if (copy_to_user(_status, &status, sizeof(status))) |
| 636 | return -EFAULT; |
| 637 | return 0; |
| 638 | } |
| 639 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 640 | static int snd_pcm_channel_info(struct snd_pcm_substream *substream, |
| 641 | struct snd_pcm_channel_info * info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 643 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | unsigned int channel; |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | channel = info->channel; |
| 647 | runtime = substream->runtime; |
| 648 | snd_pcm_stream_lock_irq(substream); |
| 649 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { |
| 650 | snd_pcm_stream_unlock_irq(substream); |
| 651 | return -EBADFD; |
| 652 | } |
| 653 | snd_pcm_stream_unlock_irq(substream); |
| 654 | if (channel >= runtime->channels) |
| 655 | return -EINVAL; |
| 656 | memset(info, 0, sizeof(*info)); |
| 657 | info->channel = channel; |
| 658 | return substream->ops->ioctl(substream, SNDRV_PCM_IOCTL1_CHANNEL_INFO, info); |
| 659 | } |
| 660 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 661 | static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, |
| 662 | struct snd_pcm_channel_info __user * _info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 664 | struct snd_pcm_channel_info info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | int res; |
| 666 | |
| 667 | if (copy_from_user(&info, _info, sizeof(info))) |
| 668 | return -EFAULT; |
| 669 | res = snd_pcm_channel_info(substream, &info); |
| 670 | if (res < 0) |
| 671 | return res; |
| 672 | if (copy_to_user(_info, &info, sizeof(info))) |
| 673 | return -EFAULT; |
| 674 | return 0; |
| 675 | } |
| 676 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 677 | static void snd_pcm_trigger_tstamp(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 679 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | if (runtime->trigger_master == NULL) |
| 681 | return; |
| 682 | if (runtime->trigger_master == substream) { |
Jaroslav Kysela | b751eef | 2007-12-13 10:19:42 +0100 | [diff] [blame] | 683 | snd_pcm_gettime(runtime, &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | } else { |
| 685 | snd_pcm_trigger_tstamp(runtime->trigger_master); |
| 686 | runtime->trigger_tstamp = runtime->trigger_master->runtime->trigger_tstamp; |
| 687 | } |
| 688 | runtime->trigger_master = NULL; |
| 689 | } |
| 690 | |
| 691 | struct action_ops { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 692 | int (*pre_action)(struct snd_pcm_substream *substream, int state); |
| 693 | int (*do_action)(struct snd_pcm_substream *substream, int state); |
| 694 | void (*undo_action)(struct snd_pcm_substream *substream, int state); |
| 695 | void (*post_action)(struct snd_pcm_substream *substream, int state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | }; |
| 697 | |
| 698 | /* |
| 699 | * this functions is core for handling of linked stream |
| 700 | * Note: the stream state might be changed also on failure |
| 701 | * Note2: call with calling stream lock + link lock |
| 702 | */ |
| 703 | static int snd_pcm_action_group(struct action_ops *ops, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 704 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | int state, int do_lock) |
| 706 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 707 | struct snd_pcm_substream *s = NULL; |
| 708 | struct snd_pcm_substream *s1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | int res = 0; |
| 710 | |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 711 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | if (do_lock && s != substream) |
Frederik Deweerdt | 208eee2 | 2007-04-05 16:57:41 +0200 | [diff] [blame] | 713 | spin_lock_nested(&s->self_group.lock, |
| 714 | SINGLE_DEPTH_NESTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | res = ops->pre_action(s, state); |
| 716 | if (res < 0) |
| 717 | goto _unlock; |
| 718 | } |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 719 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | res = ops->do_action(s, state); |
| 721 | if (res < 0) { |
| 722 | if (ops->undo_action) { |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 723 | snd_pcm_group_for_each_entry(s1, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | if (s1 == s) /* failed stream */ |
| 725 | break; |
| 726 | ops->undo_action(s1, state); |
| 727 | } |
| 728 | } |
| 729 | s = NULL; /* unlock all */ |
| 730 | goto _unlock; |
| 731 | } |
| 732 | } |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 733 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | ops->post_action(s, state); |
| 735 | } |
| 736 | _unlock: |
| 737 | if (do_lock) { |
| 738 | /* unlock streams */ |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 739 | snd_pcm_group_for_each_entry(s1, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | if (s1 != substream) |
| 741 | spin_unlock(&s1->self_group.lock); |
| 742 | if (s1 == s) /* end */ |
| 743 | break; |
| 744 | } |
| 745 | } |
| 746 | return res; |
| 747 | } |
| 748 | |
| 749 | /* |
| 750 | * Note: call with stream lock |
| 751 | */ |
| 752 | static int snd_pcm_action_single(struct action_ops *ops, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 753 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | int state) |
| 755 | { |
| 756 | int res; |
| 757 | |
| 758 | res = ops->pre_action(substream, state); |
| 759 | if (res < 0) |
| 760 | return res; |
| 761 | res = ops->do_action(substream, state); |
| 762 | if (res == 0) |
| 763 | ops->post_action(substream, state); |
| 764 | else if (ops->undo_action) |
| 765 | ops->undo_action(substream, state); |
| 766 | return res; |
| 767 | } |
| 768 | |
| 769 | /* |
| 770 | * Note: call with stream lock |
| 771 | */ |
| 772 | static int snd_pcm_action(struct action_ops *ops, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 773 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | int state) |
| 775 | { |
| 776 | int res; |
| 777 | |
| 778 | if (snd_pcm_stream_linked(substream)) { |
| 779 | if (!spin_trylock(&substream->group->lock)) { |
| 780 | spin_unlock(&substream->self_group.lock); |
| 781 | spin_lock(&substream->group->lock); |
| 782 | spin_lock(&substream->self_group.lock); |
| 783 | } |
| 784 | res = snd_pcm_action_group(ops, substream, state, 1); |
| 785 | spin_unlock(&substream->group->lock); |
| 786 | } else { |
| 787 | res = snd_pcm_action_single(ops, substream, state); |
| 788 | } |
| 789 | return res; |
| 790 | } |
| 791 | |
| 792 | /* |
| 793 | * Note: don't use any locks before |
| 794 | */ |
| 795 | static int snd_pcm_action_lock_irq(struct action_ops *ops, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 796 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | int state) |
| 798 | { |
| 799 | int res; |
| 800 | |
| 801 | read_lock_irq(&snd_pcm_link_rwlock); |
| 802 | if (snd_pcm_stream_linked(substream)) { |
| 803 | spin_lock(&substream->group->lock); |
| 804 | spin_lock(&substream->self_group.lock); |
| 805 | res = snd_pcm_action_group(ops, substream, state, 1); |
| 806 | spin_unlock(&substream->self_group.lock); |
| 807 | spin_unlock(&substream->group->lock); |
| 808 | } else { |
| 809 | spin_lock(&substream->self_group.lock); |
| 810 | res = snd_pcm_action_single(ops, substream, state); |
| 811 | spin_unlock(&substream->self_group.lock); |
| 812 | } |
| 813 | read_unlock_irq(&snd_pcm_link_rwlock); |
| 814 | return res; |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | */ |
| 819 | static int snd_pcm_action_nonatomic(struct action_ops *ops, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 820 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | int state) |
| 822 | { |
| 823 | int res; |
| 824 | |
| 825 | down_read(&snd_pcm_link_rwsem); |
| 826 | if (snd_pcm_stream_linked(substream)) |
| 827 | res = snd_pcm_action_group(ops, substream, state, 0); |
| 828 | else |
| 829 | res = snd_pcm_action_single(ops, substream, state); |
| 830 | up_read(&snd_pcm_link_rwsem); |
| 831 | return res; |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | * start callbacks |
| 836 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 837 | static int snd_pcm_pre_start(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 839 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | if (runtime->status->state != SNDRV_PCM_STATE_PREPARED) |
| 841 | return -EBADFD; |
| 842 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 843 | !snd_pcm_playback_data(substream)) |
| 844 | return -EPIPE; |
| 845 | runtime->trigger_master = substream; |
| 846 | return 0; |
| 847 | } |
| 848 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 849 | static int snd_pcm_do_start(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
| 851 | if (substream->runtime->trigger_master != substream) |
| 852 | return 0; |
| 853 | return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); |
| 854 | } |
| 855 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 856 | static void snd_pcm_undo_start(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | { |
| 858 | if (substream->runtime->trigger_master == substream) |
| 859 | substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); |
| 860 | } |
| 861 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 862 | static void snd_pcm_post_start(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 864 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | snd_pcm_trigger_tstamp(substream); |
Takashi Iwai | 6af3fb7 | 2009-05-27 10:49:26 +0200 | [diff] [blame] | 866 | runtime->hw_ptr_jiffies = jiffies; |
Jaroslav Kysela | bd76af0 | 2010-08-18 14:16:54 +0200 | [diff] [blame] | 867 | runtime->hw_ptr_buffer_jiffies = (runtime->buffer_size * HZ) / |
| 868 | runtime->rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | runtime->status->state = state; |
| 870 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 871 | runtime->silence_size > 0) |
| 872 | snd_pcm_playback_silence(substream, ULONG_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | if (substream->timer) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 874 | snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSTART, |
| 875 | &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static struct action_ops snd_pcm_action_start = { |
| 879 | .pre_action = snd_pcm_pre_start, |
| 880 | .do_action = snd_pcm_do_start, |
| 881 | .undo_action = snd_pcm_undo_start, |
| 882 | .post_action = snd_pcm_post_start |
| 883 | }; |
| 884 | |
| 885 | /** |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 886 | * snd_pcm_start - start all linked streams |
Takashi Iwai | df8db93 | 2005-09-07 13:38:19 +0200 | [diff] [blame] | 887 | * @substream: the PCM substream instance |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 889 | int snd_pcm_start(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 891 | return snd_pcm_action(&snd_pcm_action_start, substream, |
| 892 | SNDRV_PCM_STATE_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /* |
| 896 | * stop callbacks |
| 897 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 898 | static int snd_pcm_pre_stop(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 900 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 902 | return -EBADFD; |
| 903 | runtime->trigger_master = substream; |
| 904 | return 0; |
| 905 | } |
| 906 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 907 | static int snd_pcm_do_stop(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
| 909 | if (substream->runtime->trigger_master == substream && |
| 910 | snd_pcm_running(substream)) |
| 911 | substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); |
| 912 | return 0; /* unconditonally stop all substreams */ |
| 913 | } |
| 914 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 915 | static void snd_pcm_post_stop(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 917 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | if (runtime->status->state != state) { |
| 919 | snd_pcm_trigger_tstamp(substream); |
| 920 | if (substream->timer) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 921 | snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSTOP, |
| 922 | &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | runtime->status->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } |
| 925 | wake_up(&runtime->sleep); |
Jaroslav Kysela | c91a988 | 2010-01-21 10:32:15 +0100 | [diff] [blame] | 926 | wake_up(&runtime->tsleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | static struct action_ops snd_pcm_action_stop = { |
| 930 | .pre_action = snd_pcm_pre_stop, |
| 931 | .do_action = snd_pcm_do_stop, |
| 932 | .post_action = snd_pcm_post_stop |
| 933 | }; |
| 934 | |
| 935 | /** |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 936 | * snd_pcm_stop - try to stop all running streams in the substream group |
Takashi Iwai | df8db93 | 2005-09-07 13:38:19 +0200 | [diff] [blame] | 937 | * @substream: the PCM substream instance |
| 938 | * @state: PCM state after stopping the stream |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | * |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 940 | * The state of each stream is then changed to the given state unconditionally. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 942 | int snd_pcm_stop(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | { |
| 944 | return snd_pcm_action(&snd_pcm_action_stop, substream, state); |
| 945 | } |
| 946 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 947 | EXPORT_SYMBOL(snd_pcm_stop); |
| 948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | /** |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 950 | * snd_pcm_drain_done - stop the DMA only when the given stream is playback |
Takashi Iwai | df8db93 | 2005-09-07 13:38:19 +0200 | [diff] [blame] | 951 | * @substream: the PCM substream |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | * |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 953 | * After stopping, the state is changed to SETUP. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | * Unlike snd_pcm_stop(), this affects only the given stream. |
| 955 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 956 | int snd_pcm_drain_done(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 958 | return snd_pcm_action_single(&snd_pcm_action_stop, substream, |
| 959 | SNDRV_PCM_STATE_SETUP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* |
| 963 | * pause callbacks |
| 964 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 965 | static int snd_pcm_pre_pause(struct snd_pcm_substream *substream, int push) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 967 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | if (!(runtime->info & SNDRV_PCM_INFO_PAUSE)) |
| 969 | return -ENOSYS; |
| 970 | if (push) { |
| 971 | if (runtime->status->state != SNDRV_PCM_STATE_RUNNING) |
| 972 | return -EBADFD; |
| 973 | } else if (runtime->status->state != SNDRV_PCM_STATE_PAUSED) |
| 974 | return -EBADFD; |
| 975 | runtime->trigger_master = substream; |
| 976 | return 0; |
| 977 | } |
| 978 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 979 | static int snd_pcm_do_pause(struct snd_pcm_substream *substream, int push) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | { |
| 981 | if (substream->runtime->trigger_master != substream) |
| 982 | return 0; |
Jaroslav Kysela | 56385a1 | 2010-08-18 14:08:17 +0200 | [diff] [blame] | 983 | /* some drivers might use hw_ptr to recover from the pause - |
| 984 | update the hw_ptr now */ |
| 985 | if (push) |
| 986 | snd_pcm_update_hw_ptr(substream); |
Takashi Iwai | 6af3fb7 | 2009-05-27 10:49:26 +0200 | [diff] [blame] | 987 | /* The jiffies check in snd_pcm_update_hw_ptr*() is done by |
| 988 | * a delta betwen the current jiffies, this gives a large enough |
| 989 | * delta, effectively to skip the check once. |
| 990 | */ |
| 991 | substream->runtime->hw_ptr_jiffies = jiffies - HZ * 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | return substream->ops->trigger(substream, |
| 993 | push ? SNDRV_PCM_TRIGGER_PAUSE_PUSH : |
| 994 | SNDRV_PCM_TRIGGER_PAUSE_RELEASE); |
| 995 | } |
| 996 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 997 | static void snd_pcm_undo_pause(struct snd_pcm_substream *substream, int push) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | { |
| 999 | if (substream->runtime->trigger_master == substream) |
| 1000 | substream->ops->trigger(substream, |
| 1001 | push ? SNDRV_PCM_TRIGGER_PAUSE_RELEASE : |
| 1002 | SNDRV_PCM_TRIGGER_PAUSE_PUSH); |
| 1003 | } |
| 1004 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1005 | static void snd_pcm_post_pause(struct snd_pcm_substream *substream, int push) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1007 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | snd_pcm_trigger_tstamp(substream); |
| 1009 | if (push) { |
| 1010 | runtime->status->state = SNDRV_PCM_STATE_PAUSED; |
| 1011 | if (substream->timer) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1012 | snd_timer_notify(substream->timer, |
| 1013 | SNDRV_TIMER_EVENT_MPAUSE, |
| 1014 | &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | wake_up(&runtime->sleep); |
Jaroslav Kysela | c91a988 | 2010-01-21 10:32:15 +0100 | [diff] [blame] | 1016 | wake_up(&runtime->tsleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } else { |
| 1018 | runtime->status->state = SNDRV_PCM_STATE_RUNNING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | if (substream->timer) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1020 | snd_timer_notify(substream->timer, |
| 1021 | SNDRV_TIMER_EVENT_MCONTINUE, |
| 1022 | &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | static struct action_ops snd_pcm_action_pause = { |
| 1027 | .pre_action = snd_pcm_pre_pause, |
| 1028 | .do_action = snd_pcm_do_pause, |
| 1029 | .undo_action = snd_pcm_undo_pause, |
| 1030 | .post_action = snd_pcm_post_pause |
| 1031 | }; |
| 1032 | |
| 1033 | /* |
| 1034 | * Push/release the pause for all linked streams. |
| 1035 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1036 | static int snd_pcm_pause(struct snd_pcm_substream *substream, int push) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
| 1038 | return snd_pcm_action(&snd_pcm_action_pause, substream, push); |
| 1039 | } |
| 1040 | |
| 1041 | #ifdef CONFIG_PM |
| 1042 | /* suspend */ |
| 1043 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1044 | static int snd_pcm_pre_suspend(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1046 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) |
| 1048 | return -EBUSY; |
| 1049 | runtime->trigger_master = substream; |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1053 | static int snd_pcm_do_suspend(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1055 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | if (runtime->trigger_master != substream) |
| 1057 | return 0; |
| 1058 | if (! snd_pcm_running(substream)) |
| 1059 | return 0; |
| 1060 | substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); |
| 1061 | return 0; /* suspend unconditionally */ |
| 1062 | } |
| 1063 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1064 | static void snd_pcm_post_suspend(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1066 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | snd_pcm_trigger_tstamp(substream); |
| 1068 | if (substream->timer) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1069 | snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MSUSPEND, |
| 1070 | &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | runtime->status->suspended_state = runtime->status->state; |
| 1072 | runtime->status->state = SNDRV_PCM_STATE_SUSPENDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | wake_up(&runtime->sleep); |
Jaroslav Kysela | c91a988 | 2010-01-21 10:32:15 +0100 | [diff] [blame] | 1074 | wake_up(&runtime->tsleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static struct action_ops snd_pcm_action_suspend = { |
| 1078 | .pre_action = snd_pcm_pre_suspend, |
| 1079 | .do_action = snd_pcm_do_suspend, |
| 1080 | .post_action = snd_pcm_post_suspend |
| 1081 | }; |
| 1082 | |
| 1083 | /** |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 1084 | * snd_pcm_suspend - trigger SUSPEND to all linked streams |
Takashi Iwai | df8db93 | 2005-09-07 13:38:19 +0200 | [diff] [blame] | 1085 | * @substream: the PCM substream |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | * After this call, all streams are changed to SUSPENDED state. |
| 1088 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1089 | int snd_pcm_suspend(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
| 1091 | int err; |
| 1092 | unsigned long flags; |
| 1093 | |
Takashi Iwai | 603bf524 | 2005-11-17 15:59:14 +0100 | [diff] [blame] | 1094 | if (! substream) |
| 1095 | return 0; |
| 1096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | snd_pcm_stream_lock_irqsave(substream, flags); |
| 1098 | err = snd_pcm_action(&snd_pcm_action_suspend, substream, 0); |
| 1099 | snd_pcm_stream_unlock_irqrestore(substream, flags); |
| 1100 | return err; |
| 1101 | } |
| 1102 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 1103 | EXPORT_SYMBOL(snd_pcm_suspend); |
| 1104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | /** |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 1106 | * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm |
Takashi Iwai | df8db93 | 2005-09-07 13:38:19 +0200 | [diff] [blame] | 1107 | * @pcm: the PCM instance |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | * After this call, all streams are changed to SUSPENDED state. |
| 1110 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1111 | int snd_pcm_suspend_all(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1113 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | int stream, err = 0; |
| 1115 | |
Takashi Iwai | 603bf524 | 2005-11-17 15:59:14 +0100 | [diff] [blame] | 1116 | if (! pcm) |
| 1117 | return 0; |
| 1118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | for (stream = 0; stream < 2; stream++) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1120 | for (substream = pcm->streams[stream].substream; |
| 1121 | substream; substream = substream->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | /* FIXME: the open/close code should lock this as well */ |
| 1123 | if (substream->runtime == NULL) |
| 1124 | continue; |
| 1125 | err = snd_pcm_suspend(substream); |
| 1126 | if (err < 0 && err != -EBUSY) |
| 1127 | return err; |
| 1128 | } |
| 1129 | } |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 1133 | EXPORT_SYMBOL(snd_pcm_suspend_all); |
| 1134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | /* resume */ |
| 1136 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1137 | static int snd_pcm_pre_resume(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1139 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | if (!(runtime->info & SNDRV_PCM_INFO_RESUME)) |
| 1141 | return -ENOSYS; |
| 1142 | runtime->trigger_master = substream; |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1146 | static int snd_pcm_do_resume(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1148 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | if (runtime->trigger_master != substream) |
| 1150 | return 0; |
| 1151 | /* DMA not running previously? */ |
| 1152 | if (runtime->status->suspended_state != SNDRV_PCM_STATE_RUNNING && |
| 1153 | (runtime->status->suspended_state != SNDRV_PCM_STATE_DRAINING || |
| 1154 | substream->stream != SNDRV_PCM_STREAM_PLAYBACK)) |
| 1155 | return 0; |
| 1156 | return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME); |
| 1157 | } |
| 1158 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1159 | static void snd_pcm_undo_resume(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | { |
| 1161 | if (substream->runtime->trigger_master == substream && |
| 1162 | snd_pcm_running(substream)) |
| 1163 | substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); |
| 1164 | } |
| 1165 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1166 | static void snd_pcm_post_resume(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1168 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | snd_pcm_trigger_tstamp(substream); |
| 1170 | if (substream->timer) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1171 | snd_timer_notify(substream->timer, SNDRV_TIMER_EVENT_MRESUME, |
| 1172 | &runtime->trigger_tstamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | runtime->status->state = runtime->status->suspended_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | static struct action_ops snd_pcm_action_resume = { |
| 1177 | .pre_action = snd_pcm_pre_resume, |
| 1178 | .do_action = snd_pcm_do_resume, |
| 1179 | .undo_action = snd_pcm_undo_resume, |
| 1180 | .post_action = snd_pcm_post_resume |
| 1181 | }; |
| 1182 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1183 | static int snd_pcm_resume(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1185 | struct snd_card *card = substream->pcm->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | int res; |
| 1187 | |
| 1188 | snd_power_lock(card); |
Takashi Iwai | cbac4b0 | 2006-03-27 12:38:07 +0200 | [diff] [blame] | 1189 | if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0)) >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | res = snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, 0); |
| 1191 | snd_power_unlock(card); |
| 1192 | return res; |
| 1193 | } |
| 1194 | |
| 1195 | #else |
| 1196 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1197 | static int snd_pcm_resume(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | { |
| 1199 | return -ENOSYS; |
| 1200 | } |
| 1201 | |
| 1202 | #endif /* CONFIG_PM */ |
| 1203 | |
| 1204 | /* |
| 1205 | * xrun ioctl |
| 1206 | * |
| 1207 | * Change the RUNNING stream(s) to XRUN state. |
| 1208 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1209 | static int snd_pcm_xrun(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1211 | struct snd_card *card = substream->pcm->card; |
| 1212 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | int result; |
| 1214 | |
| 1215 | snd_power_lock(card); |
| 1216 | if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { |
Takashi Iwai | cbac4b0 | 2006-03-27 12:38:07 +0200 | [diff] [blame] | 1217 | result = snd_power_wait(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | if (result < 0) |
| 1219 | goto _unlock; |
| 1220 | } |
| 1221 | |
| 1222 | snd_pcm_stream_lock_irq(substream); |
| 1223 | switch (runtime->status->state) { |
| 1224 | case SNDRV_PCM_STATE_XRUN: |
| 1225 | result = 0; /* already there */ |
| 1226 | break; |
| 1227 | case SNDRV_PCM_STATE_RUNNING: |
| 1228 | result = snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); |
| 1229 | break; |
| 1230 | default: |
| 1231 | result = -EBADFD; |
| 1232 | } |
| 1233 | snd_pcm_stream_unlock_irq(substream); |
| 1234 | _unlock: |
| 1235 | snd_power_unlock(card); |
| 1236 | return result; |
| 1237 | } |
| 1238 | |
| 1239 | /* |
| 1240 | * reset ioctl |
| 1241 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1242 | static int snd_pcm_pre_reset(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1244 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | switch (runtime->status->state) { |
| 1246 | case SNDRV_PCM_STATE_RUNNING: |
| 1247 | case SNDRV_PCM_STATE_PREPARED: |
| 1248 | case SNDRV_PCM_STATE_PAUSED: |
| 1249 | case SNDRV_PCM_STATE_SUSPENDED: |
| 1250 | return 0; |
| 1251 | default: |
| 1252 | return -EBADFD; |
| 1253 | } |
| 1254 | } |
| 1255 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1256 | static int snd_pcm_do_reset(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1258 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | int err = substream->ops->ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL); |
| 1260 | if (err < 0) |
| 1261 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | runtime->hw_ptr_base = 0; |
Jaroslav Kysela | e763692 | 2010-01-26 17:08:24 +0100 | [diff] [blame] | 1263 | runtime->hw_ptr_interrupt = runtime->status->hw_ptr - |
| 1264 | runtime->status->hw_ptr % runtime->period_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | runtime->silence_start = runtime->status->hw_ptr; |
| 1266 | runtime->silence_filled = 0; |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1270 | static void snd_pcm_post_reset(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1272 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | runtime->control->appl_ptr = runtime->status->hw_ptr; |
| 1274 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && |
| 1275 | runtime->silence_size > 0) |
| 1276 | snd_pcm_playback_silence(substream, ULONG_MAX); |
| 1277 | } |
| 1278 | |
| 1279 | static struct action_ops snd_pcm_action_reset = { |
| 1280 | .pre_action = snd_pcm_pre_reset, |
| 1281 | .do_action = snd_pcm_do_reset, |
| 1282 | .post_action = snd_pcm_post_reset |
| 1283 | }; |
| 1284 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1285 | static int snd_pcm_reset(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | { |
| 1287 | return snd_pcm_action_nonatomic(&snd_pcm_action_reset, substream, 0); |
| 1288 | } |
| 1289 | |
| 1290 | /* |
| 1291 | * prepare ioctl |
| 1292 | */ |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1293 | /* we use the second argument for updating f_flags */ |
| 1294 | static int snd_pcm_pre_prepare(struct snd_pcm_substream *substream, |
| 1295 | int f_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1297 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | de1b8b9 | 2006-11-08 15:41:29 +0100 | [diff] [blame] | 1298 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN || |
| 1299 | runtime->status->state == SNDRV_PCM_STATE_DISCONNECTED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | return -EBADFD; |
| 1301 | if (snd_pcm_running(substream)) |
| 1302 | return -EBUSY; |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1303 | substream->f_flags = f_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | return 0; |
| 1305 | } |
| 1306 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1307 | static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | { |
| 1309 | int err; |
| 1310 | err = substream->ops->prepare(substream); |
| 1311 | if (err < 0) |
| 1312 | return err; |
| 1313 | return snd_pcm_do_reset(substream, 0); |
| 1314 | } |
| 1315 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1316 | static void snd_pcm_post_prepare(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1318 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | runtime->control->appl_ptr = runtime->status->hw_ptr; |
| 1320 | runtime->status->state = SNDRV_PCM_STATE_PREPARED; |
| 1321 | } |
| 1322 | |
| 1323 | static struct action_ops snd_pcm_action_prepare = { |
| 1324 | .pre_action = snd_pcm_pre_prepare, |
| 1325 | .do_action = snd_pcm_do_prepare, |
| 1326 | .post_action = snd_pcm_post_prepare |
| 1327 | }; |
| 1328 | |
| 1329 | /** |
Randy Dunlap | 1c85cc6 | 2008-10-15 14:38:40 -0700 | [diff] [blame] | 1330 | * snd_pcm_prepare - prepare the PCM substream to be triggerable |
Takashi Iwai | df8db93 | 2005-09-07 13:38:19 +0200 | [diff] [blame] | 1331 | * @substream: the PCM substream instance |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1332 | * @file: file to refer f_flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | */ |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1334 | static int snd_pcm_prepare(struct snd_pcm_substream *substream, |
| 1335 | struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | { |
| 1337 | int res; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1338 | struct snd_card *card = substream->pcm->card; |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1339 | int f_flags; |
| 1340 | |
| 1341 | if (file) |
| 1342 | f_flags = file->f_flags; |
| 1343 | else |
| 1344 | f_flags = substream->f_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
| 1346 | snd_power_lock(card); |
Takashi Iwai | cbac4b0 | 2006-03-27 12:38:07 +0200 | [diff] [blame] | 1347 | if ((res = snd_power_wait(card, SNDRV_CTL_POWER_D0)) >= 0) |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1348 | res = snd_pcm_action_nonatomic(&snd_pcm_action_prepare, |
| 1349 | substream, f_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | snd_power_unlock(card); |
| 1351 | return res; |
| 1352 | } |
| 1353 | |
| 1354 | /* |
| 1355 | * drain ioctl |
| 1356 | */ |
| 1357 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1358 | static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | substream->runtime->trigger_master = substream; |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1364 | static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1366 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 1368 | switch (runtime->status->state) { |
| 1369 | case SNDRV_PCM_STATE_PREPARED: |
| 1370 | /* start playback stream if possible */ |
| 1371 | if (! snd_pcm_playback_empty(substream)) { |
| 1372 | snd_pcm_do_start(substream, SNDRV_PCM_STATE_DRAINING); |
| 1373 | snd_pcm_post_start(substream, SNDRV_PCM_STATE_DRAINING); |
| 1374 | } |
| 1375 | break; |
| 1376 | case SNDRV_PCM_STATE_RUNNING: |
| 1377 | runtime->status->state = SNDRV_PCM_STATE_DRAINING; |
| 1378 | break; |
| 1379 | default: |
| 1380 | break; |
| 1381 | } |
| 1382 | } else { |
| 1383 | /* stop running stream */ |
| 1384 | if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) { |
Marcin Ślusarz | b05e578 | 2007-12-14 12:50:16 +0100 | [diff] [blame] | 1385 | int new_state = snd_pcm_capture_avail(runtime) > 0 ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | SNDRV_PCM_STATE_DRAINING : SNDRV_PCM_STATE_SETUP; |
Marcin Ślusarz | b05e578 | 2007-12-14 12:50:16 +0100 | [diff] [blame] | 1387 | snd_pcm_do_stop(substream, new_state); |
| 1388 | snd_pcm_post_stop(substream, new_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1394 | static void snd_pcm_post_drain_init(struct snd_pcm_substream *substream, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | { |
| 1396 | } |
| 1397 | |
| 1398 | static struct action_ops snd_pcm_action_drain_init = { |
| 1399 | .pre_action = snd_pcm_pre_drain_init, |
| 1400 | .do_action = snd_pcm_do_drain_init, |
| 1401 | .post_action = snd_pcm_post_drain_init |
| 1402 | }; |
| 1403 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1404 | static int snd_pcm_drop(struct snd_pcm_substream *substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
| 1406 | /* |
| 1407 | * Drain the stream(s). |
| 1408 | * When the substream is linked, sync until the draining of all playback streams |
| 1409 | * is finished. |
| 1410 | * After this call, all streams are supposed to be either SETUP or DRAINING |
| 1411 | * (capture only) state. |
| 1412 | */ |
Takashi Iwai | 4cdc115 | 2009-08-20 16:40:16 +0200 | [diff] [blame] | 1413 | static int snd_pcm_drain(struct snd_pcm_substream *substream, |
| 1414 | struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1416 | struct snd_card *card; |
| 1417 | struct snd_pcm_runtime *runtime; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 1418 | struct snd_pcm_substream *s; |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1419 | wait_queue_t wait; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | int result = 0; |
Takashi Iwai | 4cdc115 | 2009-08-20 16:40:16 +0200 | [diff] [blame] | 1421 | int nonblock = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | card = substream->pcm->card; |
| 1424 | runtime = substream->runtime; |
| 1425 | |
| 1426 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 1427 | return -EBADFD; |
| 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | snd_power_lock(card); |
| 1430 | if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { |
Takashi Iwai | cbac4b0 | 2006-03-27 12:38:07 +0200 | [diff] [blame] | 1431 | result = snd_power_wait(card, SNDRV_CTL_POWER_D0); |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1432 | if (result < 0) { |
| 1433 | snd_power_unlock(card); |
| 1434 | return result; |
| 1435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
Takashi Iwai | 4cdc115 | 2009-08-20 16:40:16 +0200 | [diff] [blame] | 1438 | if (file) { |
| 1439 | if (file->f_flags & O_NONBLOCK) |
| 1440 | nonblock = 1; |
| 1441 | } else if (substream->f_flags & O_NONBLOCK) |
| 1442 | nonblock = 1; |
| 1443 | |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1444 | down_read(&snd_pcm_link_rwsem); |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1445 | snd_pcm_stream_lock_irq(substream); |
| 1446 | /* resume pause */ |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1447 | if (runtime->status->state == SNDRV_PCM_STATE_PAUSED) |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1448 | snd_pcm_pause(substream, 0); |
| 1449 | |
| 1450 | /* pre-start/stop - all running streams are changed to DRAINING state */ |
| 1451 | result = snd_pcm_action(&snd_pcm_action_drain_init, substream, 0); |
Takashi Iwai | 4cdc115 | 2009-08-20 16:40:16 +0200 | [diff] [blame] | 1452 | if (result < 0) |
| 1453 | goto unlock; |
| 1454 | /* in non-blocking, we don't wait in ioctl but let caller poll */ |
| 1455 | if (nonblock) { |
| 1456 | result = -EAGAIN; |
| 1457 | goto unlock; |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | |
| 1460 | for (;;) { |
| 1461 | long tout; |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1462 | struct snd_pcm_runtime *to_check; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | if (signal_pending(current)) { |
| 1464 | result = -ERESTARTSYS; |
| 1465 | break; |
| 1466 | } |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1467 | /* find a substream to drain */ |
| 1468 | to_check = NULL; |
| 1469 | snd_pcm_group_for_each_entry(s, substream) { |
| 1470 | if (s->stream != SNDRV_PCM_STREAM_PLAYBACK) |
| 1471 | continue; |
| 1472 | runtime = s->runtime; |
| 1473 | if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) { |
| 1474 | to_check = runtime; |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1475 | break; |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1476 | } |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1477 | } |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1478 | if (!to_check) |
| 1479 | break; /* all drained */ |
| 1480 | init_waitqueue_entry(&wait, current); |
| 1481 | add_wait_queue(&to_check->sleep, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | set_current_state(TASK_INTERRUPTIBLE); |
| 1483 | snd_pcm_stream_unlock_irq(substream); |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1484 | up_read(&snd_pcm_link_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | snd_power_unlock(card); |
| 1486 | tout = schedule_timeout(10 * HZ); |
| 1487 | snd_power_lock(card); |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1488 | down_read(&snd_pcm_link_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | snd_pcm_stream_lock_irq(substream); |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1490 | remove_wait_queue(&to_check->sleep, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | if (tout == 0) { |
| 1492 | if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) |
| 1493 | result = -ESTRPIPE; |
| 1494 | else { |
| 1495 | snd_printd("playback drain error (DMA or IRQ trouble?)\n"); |
| 1496 | snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); |
| 1497 | result = -EIO; |
| 1498 | } |
| 1499 | break; |
| 1500 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | } |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1502 | |
Takashi Iwai | 4cdc115 | 2009-08-20 16:40:16 +0200 | [diff] [blame] | 1503 | unlock: |
Takashi Iwai | 21cb2a2 | 2005-05-31 14:35:31 +0200 | [diff] [blame] | 1504 | snd_pcm_stream_unlock_irq(substream); |
Takashi Iwai | d3a7dcf | 2009-09-17 18:46:26 +0200 | [diff] [blame] | 1505 | up_read(&snd_pcm_link_rwsem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | snd_power_unlock(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
| 1508 | return result; |
| 1509 | } |
| 1510 | |
| 1511 | /* |
| 1512 | * drop ioctl |
| 1513 | * |
| 1514 | * Immediately put all linked substreams into SETUP state. |
| 1515 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1516 | static int snd_pcm_drop(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1518 | struct snd_pcm_runtime *runtime; |
| 1519 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | int result = 0; |
| 1521 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1522 | if (PCM_RUNTIME_CHECK(substream)) |
| 1523 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | runtime = substream->runtime; |
| 1525 | card = substream->pcm->card; |
| 1526 | |
Takashi Iwai | de1b8b9 | 2006-11-08 15:41:29 +0100 | [diff] [blame] | 1527 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN || |
Takashi Iwai | 24e8fc4 | 2008-09-25 17:51:11 +0200 | [diff] [blame] | 1528 | runtime->status->state == SNDRV_PCM_STATE_DISCONNECTED || |
| 1529 | runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | return -EBADFD; |
| 1531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | snd_pcm_stream_lock_irq(substream); |
| 1533 | /* resume pause */ |
| 1534 | if (runtime->status->state == SNDRV_PCM_STATE_PAUSED) |
| 1535 | snd_pcm_pause(substream, 0); |
| 1536 | |
| 1537 | snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); |
| 1538 | /* runtime->control->appl_ptr = runtime->status->hw_ptr; */ |
| 1539 | snd_pcm_stream_unlock_irq(substream); |
Takashi Iwai | 24e8fc4 | 2008-09-25 17:51:11 +0200 | [diff] [blame] | 1540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | return result; |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | /* WARNING: Don't forget to fput back the file */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | static struct file *snd_pcm_file_fd(int fd) |
| 1547 | { |
| 1548 | struct file *file; |
| 1549 | struct inode *inode; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1550 | unsigned int minor; |
| 1551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | file = fget(fd); |
| 1553 | if (!file) |
| 1554 | return NULL; |
Josef Sipek | 7bc5632 | 2006-12-08 02:37:40 -0800 | [diff] [blame] | 1555 | inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | if (!S_ISCHR(inode->i_mode) || |
| 1557 | imajor(inode) != snd_major) { |
| 1558 | fput(file); |
| 1559 | return NULL; |
| 1560 | } |
| 1561 | minor = iminor(inode); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1562 | if (!snd_lookup_minor_data(minor, SNDRV_DEVICE_TYPE_PCM_PLAYBACK) && |
| 1563 | !snd_lookup_minor_data(minor, SNDRV_DEVICE_TYPE_PCM_CAPTURE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | fput(file); |
| 1565 | return NULL; |
| 1566 | } |
| 1567 | return file; |
| 1568 | } |
| 1569 | |
| 1570 | /* |
| 1571 | * PCM link handling |
| 1572 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1573 | static int snd_pcm_link(struct snd_pcm_substream *substream, int fd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | { |
| 1575 | int res = 0; |
| 1576 | struct file *file; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1577 | struct snd_pcm_file *pcm_file; |
| 1578 | struct snd_pcm_substream *substream1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
| 1580 | file = snd_pcm_file_fd(fd); |
| 1581 | if (!file) |
| 1582 | return -EBADFD; |
| 1583 | pcm_file = file->private_data; |
| 1584 | substream1 = pcm_file->substream; |
| 1585 | down_write(&snd_pcm_link_rwsem); |
| 1586 | write_lock_irq(&snd_pcm_link_rwlock); |
| 1587 | if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN || |
| 1588 | substream->runtime->status->state != substream1->runtime->status->state) { |
| 1589 | res = -EBADFD; |
| 1590 | goto _end; |
| 1591 | } |
| 1592 | if (snd_pcm_stream_linked(substream1)) { |
| 1593 | res = -EALREADY; |
| 1594 | goto _end; |
| 1595 | } |
| 1596 | if (!snd_pcm_stream_linked(substream)) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1597 | substream->group = kmalloc(sizeof(struct snd_pcm_group), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | if (substream->group == NULL) { |
| 1599 | res = -ENOMEM; |
| 1600 | goto _end; |
| 1601 | } |
| 1602 | spin_lock_init(&substream->group->lock); |
| 1603 | INIT_LIST_HEAD(&substream->group->substreams); |
| 1604 | list_add_tail(&substream->link_list, &substream->group->substreams); |
| 1605 | substream->group->count = 1; |
| 1606 | } |
| 1607 | list_add_tail(&substream1->link_list, &substream->group->substreams); |
| 1608 | substream->group->count++; |
| 1609 | substream1->group = substream->group; |
| 1610 | _end: |
| 1611 | write_unlock_irq(&snd_pcm_link_rwlock); |
| 1612 | up_write(&snd_pcm_link_rwsem); |
| 1613 | fput(file); |
| 1614 | return res; |
| 1615 | } |
| 1616 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1617 | static void relink_to_local(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | { |
| 1619 | substream->group = &substream->self_group; |
| 1620 | INIT_LIST_HEAD(&substream->self_group.substreams); |
| 1621 | list_add_tail(&substream->link_list, &substream->self_group.substreams); |
| 1622 | } |
| 1623 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1624 | static int snd_pcm_unlink(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | { |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 1626 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | int res = 0; |
| 1628 | |
| 1629 | down_write(&snd_pcm_link_rwsem); |
| 1630 | write_lock_irq(&snd_pcm_link_rwlock); |
| 1631 | if (!snd_pcm_stream_linked(substream)) { |
| 1632 | res = -EALREADY; |
| 1633 | goto _end; |
| 1634 | } |
| 1635 | list_del(&substream->link_list); |
| 1636 | substream->group->count--; |
| 1637 | if (substream->group->count == 1) { /* detach the last stream, too */ |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 1638 | snd_pcm_group_for_each_entry(s, substream) { |
| 1639 | relink_to_local(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | break; |
| 1641 | } |
| 1642 | kfree(substream->group); |
| 1643 | } |
| 1644 | relink_to_local(substream); |
| 1645 | _end: |
| 1646 | write_unlock_irq(&snd_pcm_link_rwlock); |
| 1647 | up_write(&snd_pcm_link_rwsem); |
| 1648 | return res; |
| 1649 | } |
| 1650 | |
| 1651 | /* |
| 1652 | * hw configurator |
| 1653 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1654 | static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params *params, |
| 1655 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1657 | struct snd_interval t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | snd_interval_mul(hw_param_interval_c(params, rule->deps[0]), |
| 1659 | hw_param_interval_c(params, rule->deps[1]), &t); |
| 1660 | return snd_interval_refine(hw_param_interval(params, rule->var), &t); |
| 1661 | } |
| 1662 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1663 | static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params *params, |
| 1664 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1666 | struct snd_interval t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | snd_interval_div(hw_param_interval_c(params, rule->deps[0]), |
| 1668 | hw_param_interval_c(params, rule->deps[1]), &t); |
| 1669 | return snd_interval_refine(hw_param_interval(params, rule->var), &t); |
| 1670 | } |
| 1671 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1672 | static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params *params, |
| 1673 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1675 | struct snd_interval t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | snd_interval_muldivk(hw_param_interval_c(params, rule->deps[0]), |
| 1677 | hw_param_interval_c(params, rule->deps[1]), |
| 1678 | (unsigned long) rule->private, &t); |
| 1679 | return snd_interval_refine(hw_param_interval(params, rule->var), &t); |
| 1680 | } |
| 1681 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1682 | static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params *params, |
| 1683 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1685 | struct snd_interval t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | snd_interval_mulkdiv(hw_param_interval_c(params, rule->deps[0]), |
| 1687 | (unsigned long) rule->private, |
| 1688 | hw_param_interval_c(params, rule->deps[1]), &t); |
| 1689 | return snd_interval_refine(hw_param_interval(params, rule->var), &t); |
| 1690 | } |
| 1691 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1692 | static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params *params, |
| 1693 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | { |
| 1695 | unsigned int k; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1696 | struct snd_interval *i = hw_param_interval(params, rule->deps[0]); |
| 1697 | struct snd_mask m; |
| 1698 | struct snd_mask *mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | snd_mask_any(&m); |
| 1700 | for (k = 0; k <= SNDRV_PCM_FORMAT_LAST; ++k) { |
| 1701 | int bits; |
| 1702 | if (! snd_mask_test(mask, k)) |
| 1703 | continue; |
| 1704 | bits = snd_pcm_format_physical_width(k); |
| 1705 | if (bits <= 0) |
| 1706 | continue; /* ignore invalid formats */ |
| 1707 | if ((unsigned)bits < i->min || (unsigned)bits > i->max) |
| 1708 | snd_mask_reset(&m, k); |
| 1709 | } |
| 1710 | return snd_mask_refine(mask, &m); |
| 1711 | } |
| 1712 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1713 | static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params *params, |
| 1714 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1716 | struct snd_interval t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | unsigned int k; |
| 1718 | t.min = UINT_MAX; |
| 1719 | t.max = 0; |
| 1720 | t.openmin = 0; |
| 1721 | t.openmax = 0; |
| 1722 | for (k = 0; k <= SNDRV_PCM_FORMAT_LAST; ++k) { |
| 1723 | int bits; |
| 1724 | if (! snd_mask_test(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), k)) |
| 1725 | continue; |
| 1726 | bits = snd_pcm_format_physical_width(k); |
| 1727 | if (bits <= 0) |
| 1728 | continue; /* ignore invalid formats */ |
| 1729 | if (t.min > (unsigned)bits) |
| 1730 | t.min = bits; |
| 1731 | if (t.max < (unsigned)bits) |
| 1732 | t.max = bits; |
| 1733 | } |
| 1734 | t.integer = 1; |
| 1735 | return snd_interval_refine(hw_param_interval(params, rule->var), &t); |
| 1736 | } |
| 1737 | |
| 1738 | #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12 |
| 1739 | #error "Change this table" |
| 1740 | #endif |
| 1741 | |
| 1742 | static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, |
| 1743 | 48000, 64000, 88200, 96000, 176400, 192000 }; |
| 1744 | |
Clemens Ladisch | 7653d55 | 2007-08-13 17:38:54 +0200 | [diff] [blame] | 1745 | const struct snd_pcm_hw_constraint_list snd_pcm_known_rates = { |
| 1746 | .count = ARRAY_SIZE(rates), |
| 1747 | .list = rates, |
| 1748 | }; |
| 1749 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1750 | static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params *params, |
| 1751 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1753 | struct snd_pcm_hardware *hw = rule->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | return snd_interval_list(hw_param_interval(params, rule->var), |
Clemens Ladisch | 7653d55 | 2007-08-13 17:38:54 +0200 | [diff] [blame] | 1755 | snd_pcm_known_rates.count, |
| 1756 | snd_pcm_known_rates.list, hw->rates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1759 | static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params *params, |
| 1760 | struct snd_pcm_hw_rule *rule) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1762 | struct snd_interval t; |
| 1763 | struct snd_pcm_substream *substream = rule->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | t.min = 0; |
| 1765 | t.max = substream->buffer_bytes_max; |
| 1766 | t.openmin = 0; |
| 1767 | t.openmax = 0; |
| 1768 | t.integer = 1; |
| 1769 | return snd_interval_refine(hw_param_interval(params, rule->var), &t); |
| 1770 | } |
| 1771 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1772 | int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1774 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1775 | struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | int k, err; |
| 1777 | |
| 1778 | for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) { |
| 1779 | snd_mask_any(constrs_mask(constrs, k)); |
| 1780 | } |
| 1781 | |
| 1782 | for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) { |
| 1783 | snd_interval_any(constrs_interval(constrs, k)); |
| 1784 | } |
| 1785 | |
| 1786 | snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_CHANNELS)); |
| 1787 | snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)); |
| 1788 | snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)); |
| 1789 | snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)); |
| 1790 | snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_FRAME_BITS)); |
| 1791 | |
| 1792 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, |
| 1793 | snd_pcm_hw_rule_format, NULL, |
| 1794 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); |
| 1795 | if (err < 0) |
| 1796 | return err; |
| 1797 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, |
| 1798 | snd_pcm_hw_rule_sample_bits, NULL, |
| 1799 | SNDRV_PCM_HW_PARAM_FORMAT, |
| 1800 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); |
| 1801 | if (err < 0) |
| 1802 | return err; |
| 1803 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, |
| 1804 | snd_pcm_hw_rule_div, NULL, |
| 1805 | SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 1806 | if (err < 0) |
| 1807 | return err; |
| 1808 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, |
| 1809 | snd_pcm_hw_rule_mul, NULL, |
| 1810 | SNDRV_PCM_HW_PARAM_SAMPLE_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 1811 | if (err < 0) |
| 1812 | return err; |
| 1813 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, |
| 1814 | snd_pcm_hw_rule_mulkdiv, (void*) 8, |
| 1815 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); |
| 1816 | if (err < 0) |
| 1817 | return err; |
| 1818 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, |
| 1819 | snd_pcm_hw_rule_mulkdiv, (void*) 8, |
| 1820 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1); |
| 1821 | if (err < 0) |
| 1822 | return err; |
| 1823 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 1824 | snd_pcm_hw_rule_div, NULL, |
| 1825 | SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); |
| 1826 | if (err < 0) |
| 1827 | return err; |
| 1828 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 1829 | snd_pcm_hw_rule_mulkdiv, (void*) 1000000, |
| 1830 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_PERIOD_TIME, -1); |
| 1831 | if (err < 0) |
| 1832 | return err; |
| 1833 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 1834 | snd_pcm_hw_rule_mulkdiv, (void*) 1000000, |
| 1835 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_BUFFER_TIME, -1); |
| 1836 | if (err < 0) |
| 1837 | return err; |
| 1838 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS, |
| 1839 | snd_pcm_hw_rule_div, NULL, |
| 1840 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); |
| 1841 | if (err < 0) |
| 1842 | return err; |
| 1843 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1844 | snd_pcm_hw_rule_div, NULL, |
| 1845 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_PERIODS, -1); |
| 1846 | if (err < 0) |
| 1847 | return err; |
| 1848 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1849 | snd_pcm_hw_rule_mulkdiv, (void*) 8, |
| 1850 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); |
| 1851 | if (err < 0) |
| 1852 | return err; |
| 1853 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 1854 | snd_pcm_hw_rule_muldivk, (void*) 1000000, |
| 1855 | SNDRV_PCM_HW_PARAM_PERIOD_TIME, SNDRV_PCM_HW_PARAM_RATE, -1); |
| 1856 | if (err < 0) |
| 1857 | return err; |
| 1858 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 1859 | snd_pcm_hw_rule_mul, NULL, |
| 1860 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_PERIODS, -1); |
| 1861 | if (err < 0) |
| 1862 | return err; |
| 1863 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 1864 | snd_pcm_hw_rule_mulkdiv, (void*) 8, |
| 1865 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); |
| 1866 | if (err < 0) |
| 1867 | return err; |
| 1868 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 1869 | snd_pcm_hw_rule_muldivk, (void*) 1000000, |
| 1870 | SNDRV_PCM_HW_PARAM_BUFFER_TIME, SNDRV_PCM_HW_PARAM_RATE, -1); |
| 1871 | if (err < 0) |
| 1872 | return err; |
| 1873 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 1874 | snd_pcm_hw_rule_muldivk, (void*) 8, |
| 1875 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); |
| 1876 | if (err < 0) |
| 1877 | return err; |
| 1878 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1879 | snd_pcm_hw_rule_muldivk, (void*) 8, |
| 1880 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); |
| 1881 | if (err < 0) |
| 1882 | return err; |
| 1883 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME, |
| 1884 | snd_pcm_hw_rule_mulkdiv, (void*) 1000000, |
| 1885 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_RATE, -1); |
| 1886 | if (err < 0) |
| 1887 | return err; |
| 1888 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME, |
| 1889 | snd_pcm_hw_rule_mulkdiv, (void*) 1000000, |
| 1890 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_RATE, -1); |
| 1891 | if (err < 0) |
| 1892 | return err; |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1896 | int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1898 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1899 | struct snd_pcm_hardware *hw = &runtime->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | int err; |
| 1901 | unsigned int mask = 0; |
| 1902 | |
| 1903 | if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) |
| 1904 | mask |= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED; |
| 1905 | if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) |
| 1906 | mask |= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED; |
| 1907 | if (hw->info & SNDRV_PCM_INFO_MMAP) { |
| 1908 | if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) |
| 1909 | mask |= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED; |
| 1910 | if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) |
| 1911 | mask |= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED; |
| 1912 | if (hw->info & SNDRV_PCM_INFO_COMPLEX) |
| 1913 | mask |= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX; |
| 1914 | } |
| 1915 | err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1916 | if (err < 0) |
| 1917 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
| 1919 | err = snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT, hw->formats); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1920 | if (err < 0) |
| 1921 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
| 1923 | err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT, 1 << SNDRV_PCM_SUBFORMAT_STD); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1924 | if (err < 0) |
| 1925 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
| 1927 | err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 1928 | hw->channels_min, hw->channels_max); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1929 | if (err < 0) |
| 1930 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
| 1932 | err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, |
| 1933 | hw->rate_min, hw->rate_max); |
Guennadi Liakhovetski | 8b90ca0 | 2009-12-24 01:17:46 +0100 | [diff] [blame] | 1934 | if (err < 0) |
| 1935 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | |
| 1937 | err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 1938 | hw->period_bytes_min, hw->period_bytes_max); |
Guennadi Liakhovetski | 8b90ca0 | 2009-12-24 01:17:46 +0100 | [diff] [blame] | 1939 | if (err < 0) |
| 1940 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | |
| 1942 | err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIODS, |
| 1943 | hw->periods_min, hw->periods_max); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1944 | if (err < 0) |
| 1945 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | |
| 1947 | err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1948 | hw->period_bytes_min, hw->buffer_bytes_max); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1949 | if (err < 0) |
| 1950 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | |
| 1952 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1953 | snd_pcm_hw_rule_buffer_bytes_max, substream, |
| 1954 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, -1); |
| 1955 | if (err < 0) |
| 1956 | return err; |
| 1957 | |
| 1958 | /* FIXME: remove */ |
| 1959 | if (runtime->dma_bytes) { |
| 1960 | err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, runtime->dma_bytes); |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 1961 | if (err < 0) |
| 1962 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | if (!(hw->rates & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))) { |
| 1966 | err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 1967 | snd_pcm_hw_rule_rate, hw, |
| 1968 | SNDRV_PCM_HW_PARAM_RATE, -1); |
| 1969 | if (err < 0) |
| 1970 | return err; |
| 1971 | } |
| 1972 | |
| 1973 | /* FIXME: this belong to lowlevel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
| 1975 | |
| 1976 | return 0; |
| 1977 | } |
| 1978 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 1979 | static void pcm_release_private(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | snd_pcm_unlink(substream); |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | void snd_pcm_release_substream(struct snd_pcm_substream *substream) |
| 1985 | { |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1986 | substream->ref_count--; |
| 1987 | if (substream->ref_count > 0) |
| 1988 | return; |
| 1989 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 1990 | snd_pcm_drop(substream); |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 1991 | if (substream->hw_opened) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | if (substream->ops->hw_free != NULL) |
| 1993 | substream->ops->hw_free(substream); |
| 1994 | substream->ops->close(substream); |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 1995 | substream->hw_opened = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | } |
Takashi Iwai | 1576274 | 2006-04-06 19:47:42 +0200 | [diff] [blame] | 1997 | if (substream->pcm_release) { |
| 1998 | substream->pcm_release(substream); |
| 1999 | substream->pcm_release = NULL; |
| 2000 | } |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2001 | snd_pcm_detach_substream(substream); |
| 2002 | } |
| 2003 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 2004 | EXPORT_SYMBOL(snd_pcm_release_substream); |
| 2005 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2006 | int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, |
| 2007 | struct file *file, |
| 2008 | struct snd_pcm_substream **rsubstream) |
| 2009 | { |
| 2010 | struct snd_pcm_substream *substream; |
| 2011 | int err; |
| 2012 | |
| 2013 | err = snd_pcm_attach_substream(pcm, stream, file, &substream); |
| 2014 | if (err < 0) |
| 2015 | return err; |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2016 | if (substream->ref_count > 1) { |
| 2017 | *rsubstream = substream; |
| 2018 | return 0; |
| 2019 | } |
| 2020 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2021 | err = snd_pcm_hw_constraints_init(substream); |
| 2022 | if (err < 0) { |
| 2023 | snd_printd("snd_pcm_hw_constraints_init failed\n"); |
| 2024 | goto error; |
| 2025 | } |
| 2026 | |
| 2027 | if ((err = substream->ops->open(substream)) < 0) |
| 2028 | goto error; |
| 2029 | |
| 2030 | substream->hw_opened = 1; |
| 2031 | |
| 2032 | err = snd_pcm_hw_constraints_complete(substream); |
| 2033 | if (err < 0) { |
| 2034 | snd_printd("snd_pcm_hw_constraints_complete failed\n"); |
| 2035 | goto error; |
| 2036 | } |
| 2037 | |
| 2038 | *rsubstream = substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | return 0; |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2040 | |
| 2041 | error: |
| 2042 | snd_pcm_release_substream(substream); |
| 2043 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 2046 | EXPORT_SYMBOL(snd_pcm_open_substream); |
| 2047 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | static int snd_pcm_open_file(struct file *file, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2049 | struct snd_pcm *pcm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | int stream, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2051 | struct snd_pcm_file **rpcm_file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2053 | struct snd_pcm_file *pcm_file; |
| 2054 | struct snd_pcm_substream *substream; |
| 2055 | struct snd_pcm_str *str; |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2056 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2058 | if (rpcm_file) |
| 2059 | *rpcm_file = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2061 | err = snd_pcm_open_substream(pcm, stream, file, &substream); |
| 2062 | if (err < 0) |
| 2063 | return err; |
| 2064 | |
Takashi Iwai | 548a648 | 2006-07-31 16:51:51 +0200 | [diff] [blame] | 2065 | pcm_file = kzalloc(sizeof(*pcm_file), GFP_KERNEL); |
| 2066 | if (pcm_file == NULL) { |
| 2067 | snd_pcm_release_substream(substream); |
| 2068 | return -ENOMEM; |
| 2069 | } |
| 2070 | pcm_file->substream = substream; |
| 2071 | if (substream->ref_count == 1) { |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2072 | str = substream->pstr; |
| 2073 | substream->file = pcm_file; |
| 2074 | substream->pcm_release = pcm_release_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | file->private_data = pcm_file; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2077 | if (rpcm_file) |
| 2078 | *rpcm_file = pcm_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | return 0; |
| 2080 | } |
| 2081 | |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 2082 | static int snd_pcm_playback_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2084 | struct snd_pcm *pcm; |
Takashi Iwai | 02f4865 | 2010-04-13 11:49:04 +0200 | [diff] [blame] | 2085 | int err = nonseekable_open(inode, file); |
| 2086 | if (err < 0) |
| 2087 | return err; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 2088 | pcm = snd_lookup_minor_data(iminor(inode), |
| 2089 | SNDRV_DEVICE_TYPE_PCM_PLAYBACK); |
| 2090 | return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK); |
| 2091 | } |
| 2092 | |
| 2093 | static int snd_pcm_capture_open(struct inode *inode, struct file *file) |
| 2094 | { |
| 2095 | struct snd_pcm *pcm; |
Takashi Iwai | 02f4865 | 2010-04-13 11:49:04 +0200 | [diff] [blame] | 2096 | int err = nonseekable_open(inode, file); |
| 2097 | if (err < 0) |
| 2098 | return err; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 2099 | pcm = snd_lookup_minor_data(iminor(inode), |
| 2100 | SNDRV_DEVICE_TYPE_PCM_CAPTURE); |
| 2101 | return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE); |
| 2102 | } |
| 2103 | |
| 2104 | static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) |
| 2105 | { |
| 2106 | int err; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2107 | struct snd_pcm_file *pcm_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | wait_queue_t wait; |
| 2109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | if (pcm == NULL) { |
| 2111 | err = -ENODEV; |
| 2112 | goto __error1; |
| 2113 | } |
| 2114 | err = snd_card_file_add(pcm->card, file); |
| 2115 | if (err < 0) |
| 2116 | goto __error1; |
| 2117 | if (!try_module_get(pcm->card->module)) { |
| 2118 | err = -EFAULT; |
| 2119 | goto __error2; |
| 2120 | } |
| 2121 | init_waitqueue_entry(&wait, current); |
| 2122 | add_wait_queue(&pcm->open_wait, &wait); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 2123 | mutex_lock(&pcm->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | while (1) { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 2125 | err = snd_pcm_open_file(file, pcm, stream, &pcm_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | if (err >= 0) |
| 2127 | break; |
| 2128 | if (err == -EAGAIN) { |
| 2129 | if (file->f_flags & O_NONBLOCK) { |
| 2130 | err = -EBUSY; |
| 2131 | break; |
| 2132 | } |
| 2133 | } else |
| 2134 | break; |
| 2135 | set_current_state(TASK_INTERRUPTIBLE); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 2136 | mutex_unlock(&pcm->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | schedule(); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 2138 | mutex_lock(&pcm->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | if (signal_pending(current)) { |
| 2140 | err = -ERESTARTSYS; |
| 2141 | break; |
| 2142 | } |
| 2143 | } |
| 2144 | remove_wait_queue(&pcm->open_wait, &wait); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 2145 | mutex_unlock(&pcm->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | if (err < 0) |
| 2147 | goto __error; |
| 2148 | return err; |
| 2149 | |
| 2150 | __error: |
| 2151 | module_put(pcm->card->module); |
| 2152 | __error2: |
| 2153 | snd_card_file_remove(pcm->card, file); |
| 2154 | __error1: |
| 2155 | return err; |
| 2156 | } |
| 2157 | |
| 2158 | static int snd_pcm_release(struct inode *inode, struct file *file) |
| 2159 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2160 | struct snd_pcm *pcm; |
| 2161 | struct snd_pcm_substream *substream; |
| 2162 | struct snd_pcm_file *pcm_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
| 2164 | pcm_file = file->private_data; |
| 2165 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2166 | if (snd_BUG_ON(!substream)) |
| 2167 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | pcm = substream->pcm; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 2169 | mutex_lock(&pcm->open_mutex); |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 2170 | snd_pcm_release_substream(substream); |
Takashi Iwai | 548a648 | 2006-07-31 16:51:51 +0200 | [diff] [blame] | 2171 | kfree(pcm_file); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 2172 | mutex_unlock(&pcm->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | wake_up(&pcm->open_wait); |
| 2174 | module_put(pcm->card->module); |
| 2175 | snd_card_file_remove(pcm->card, file); |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2179 | static snd_pcm_sframes_t snd_pcm_playback_rewind(struct snd_pcm_substream *substream, |
| 2180 | snd_pcm_uframes_t frames) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2182 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | snd_pcm_sframes_t appl_ptr; |
| 2184 | snd_pcm_sframes_t ret; |
| 2185 | snd_pcm_sframes_t hw_avail; |
| 2186 | |
| 2187 | if (frames == 0) |
| 2188 | return 0; |
| 2189 | |
| 2190 | snd_pcm_stream_lock_irq(substream); |
| 2191 | switch (runtime->status->state) { |
| 2192 | case SNDRV_PCM_STATE_PREPARED: |
| 2193 | break; |
| 2194 | case SNDRV_PCM_STATE_DRAINING: |
| 2195 | case SNDRV_PCM_STATE_RUNNING: |
| 2196 | if (snd_pcm_update_hw_ptr(substream) >= 0) |
| 2197 | break; |
| 2198 | /* Fall through */ |
| 2199 | case SNDRV_PCM_STATE_XRUN: |
| 2200 | ret = -EPIPE; |
| 2201 | goto __end; |
Lubomir Rintel | 5184040 | 2009-08-02 18:14:44 +0200 | [diff] [blame] | 2202 | case SNDRV_PCM_STATE_SUSPENDED: |
| 2203 | ret = -ESTRPIPE; |
| 2204 | goto __end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | default: |
| 2206 | ret = -EBADFD; |
| 2207 | goto __end; |
| 2208 | } |
| 2209 | |
| 2210 | hw_avail = snd_pcm_playback_hw_avail(runtime); |
| 2211 | if (hw_avail <= 0) { |
| 2212 | ret = 0; |
| 2213 | goto __end; |
| 2214 | } |
| 2215 | if (frames > (snd_pcm_uframes_t)hw_avail) |
| 2216 | frames = hw_avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | appl_ptr = runtime->control->appl_ptr - frames; |
| 2218 | if (appl_ptr < 0) |
| 2219 | appl_ptr += runtime->boundary; |
| 2220 | runtime->control->appl_ptr = appl_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | ret = frames; |
| 2222 | __end: |
| 2223 | snd_pcm_stream_unlock_irq(substream); |
| 2224 | return ret; |
| 2225 | } |
| 2226 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2227 | static snd_pcm_sframes_t snd_pcm_capture_rewind(struct snd_pcm_substream *substream, |
| 2228 | snd_pcm_uframes_t frames) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2230 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | snd_pcm_sframes_t appl_ptr; |
| 2232 | snd_pcm_sframes_t ret; |
| 2233 | snd_pcm_sframes_t hw_avail; |
| 2234 | |
| 2235 | if (frames == 0) |
| 2236 | return 0; |
| 2237 | |
| 2238 | snd_pcm_stream_lock_irq(substream); |
| 2239 | switch (runtime->status->state) { |
| 2240 | case SNDRV_PCM_STATE_PREPARED: |
| 2241 | case SNDRV_PCM_STATE_DRAINING: |
| 2242 | break; |
| 2243 | case SNDRV_PCM_STATE_RUNNING: |
| 2244 | if (snd_pcm_update_hw_ptr(substream) >= 0) |
| 2245 | break; |
| 2246 | /* Fall through */ |
| 2247 | case SNDRV_PCM_STATE_XRUN: |
| 2248 | ret = -EPIPE; |
| 2249 | goto __end; |
Lubomir Rintel | 5184040 | 2009-08-02 18:14:44 +0200 | [diff] [blame] | 2250 | case SNDRV_PCM_STATE_SUSPENDED: |
| 2251 | ret = -ESTRPIPE; |
| 2252 | goto __end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | default: |
| 2254 | ret = -EBADFD; |
| 2255 | goto __end; |
| 2256 | } |
| 2257 | |
| 2258 | hw_avail = snd_pcm_capture_hw_avail(runtime); |
| 2259 | if (hw_avail <= 0) { |
| 2260 | ret = 0; |
| 2261 | goto __end; |
| 2262 | } |
| 2263 | if (frames > (snd_pcm_uframes_t)hw_avail) |
| 2264 | frames = hw_avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | appl_ptr = runtime->control->appl_ptr - frames; |
| 2266 | if (appl_ptr < 0) |
| 2267 | appl_ptr += runtime->boundary; |
| 2268 | runtime->control->appl_ptr = appl_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | ret = frames; |
| 2270 | __end: |
| 2271 | snd_pcm_stream_unlock_irq(substream); |
| 2272 | return ret; |
| 2273 | } |
| 2274 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2275 | static snd_pcm_sframes_t snd_pcm_playback_forward(struct snd_pcm_substream *substream, |
| 2276 | snd_pcm_uframes_t frames) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2278 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | snd_pcm_sframes_t appl_ptr; |
| 2280 | snd_pcm_sframes_t ret; |
| 2281 | snd_pcm_sframes_t avail; |
| 2282 | |
| 2283 | if (frames == 0) |
| 2284 | return 0; |
| 2285 | |
| 2286 | snd_pcm_stream_lock_irq(substream); |
| 2287 | switch (runtime->status->state) { |
| 2288 | case SNDRV_PCM_STATE_PREPARED: |
| 2289 | case SNDRV_PCM_STATE_PAUSED: |
| 2290 | break; |
| 2291 | case SNDRV_PCM_STATE_DRAINING: |
| 2292 | case SNDRV_PCM_STATE_RUNNING: |
| 2293 | if (snd_pcm_update_hw_ptr(substream) >= 0) |
| 2294 | break; |
| 2295 | /* Fall through */ |
| 2296 | case SNDRV_PCM_STATE_XRUN: |
| 2297 | ret = -EPIPE; |
| 2298 | goto __end; |
Lubomir Rintel | 5184040 | 2009-08-02 18:14:44 +0200 | [diff] [blame] | 2299 | case SNDRV_PCM_STATE_SUSPENDED: |
| 2300 | ret = -ESTRPIPE; |
| 2301 | goto __end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | default: |
| 2303 | ret = -EBADFD; |
| 2304 | goto __end; |
| 2305 | } |
| 2306 | |
| 2307 | avail = snd_pcm_playback_avail(runtime); |
| 2308 | if (avail <= 0) { |
| 2309 | ret = 0; |
| 2310 | goto __end; |
| 2311 | } |
| 2312 | if (frames > (snd_pcm_uframes_t)avail) |
| 2313 | frames = avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | appl_ptr = runtime->control->appl_ptr + frames; |
| 2315 | if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) |
| 2316 | appl_ptr -= runtime->boundary; |
| 2317 | runtime->control->appl_ptr = appl_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | ret = frames; |
| 2319 | __end: |
| 2320 | snd_pcm_stream_unlock_irq(substream); |
| 2321 | return ret; |
| 2322 | } |
| 2323 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2324 | static snd_pcm_sframes_t snd_pcm_capture_forward(struct snd_pcm_substream *substream, |
| 2325 | snd_pcm_uframes_t frames) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2327 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | snd_pcm_sframes_t appl_ptr; |
| 2329 | snd_pcm_sframes_t ret; |
| 2330 | snd_pcm_sframes_t avail; |
| 2331 | |
| 2332 | if (frames == 0) |
| 2333 | return 0; |
| 2334 | |
| 2335 | snd_pcm_stream_lock_irq(substream); |
| 2336 | switch (runtime->status->state) { |
| 2337 | case SNDRV_PCM_STATE_PREPARED: |
| 2338 | case SNDRV_PCM_STATE_DRAINING: |
| 2339 | case SNDRV_PCM_STATE_PAUSED: |
| 2340 | break; |
| 2341 | case SNDRV_PCM_STATE_RUNNING: |
| 2342 | if (snd_pcm_update_hw_ptr(substream) >= 0) |
| 2343 | break; |
| 2344 | /* Fall through */ |
| 2345 | case SNDRV_PCM_STATE_XRUN: |
| 2346 | ret = -EPIPE; |
| 2347 | goto __end; |
Lubomir Rintel | 5184040 | 2009-08-02 18:14:44 +0200 | [diff] [blame] | 2348 | case SNDRV_PCM_STATE_SUSPENDED: |
| 2349 | ret = -ESTRPIPE; |
| 2350 | goto __end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | default: |
| 2352 | ret = -EBADFD; |
| 2353 | goto __end; |
| 2354 | } |
| 2355 | |
| 2356 | avail = snd_pcm_capture_avail(runtime); |
| 2357 | if (avail <= 0) { |
| 2358 | ret = 0; |
| 2359 | goto __end; |
| 2360 | } |
| 2361 | if (frames > (snd_pcm_uframes_t)avail) |
| 2362 | frames = avail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | appl_ptr = runtime->control->appl_ptr + frames; |
| 2364 | if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) |
| 2365 | appl_ptr -= runtime->boundary; |
| 2366 | runtime->control->appl_ptr = appl_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | ret = frames; |
| 2368 | __end: |
| 2369 | snd_pcm_stream_unlock_irq(substream); |
| 2370 | return ret; |
| 2371 | } |
| 2372 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2373 | static int snd_pcm_hwsync(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2375 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | int err; |
| 2377 | |
| 2378 | snd_pcm_stream_lock_irq(substream); |
| 2379 | switch (runtime->status->state) { |
| 2380 | case SNDRV_PCM_STATE_DRAINING: |
| 2381 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 2382 | goto __badfd; |
| 2383 | case SNDRV_PCM_STATE_RUNNING: |
| 2384 | if ((err = snd_pcm_update_hw_ptr(substream)) < 0) |
| 2385 | break; |
| 2386 | /* Fall through */ |
| 2387 | case SNDRV_PCM_STATE_PREPARED: |
| 2388 | case SNDRV_PCM_STATE_SUSPENDED: |
| 2389 | err = 0; |
| 2390 | break; |
| 2391 | case SNDRV_PCM_STATE_XRUN: |
| 2392 | err = -EPIPE; |
| 2393 | break; |
| 2394 | default: |
| 2395 | __badfd: |
| 2396 | err = -EBADFD; |
| 2397 | break; |
| 2398 | } |
| 2399 | snd_pcm_stream_unlock_irq(substream); |
| 2400 | return err; |
| 2401 | } |
| 2402 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2403 | static int snd_pcm_delay(struct snd_pcm_substream *substream, |
| 2404 | snd_pcm_sframes_t __user *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2406 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | int err; |
| 2408 | snd_pcm_sframes_t n = 0; |
| 2409 | |
| 2410 | snd_pcm_stream_lock_irq(substream); |
| 2411 | switch (runtime->status->state) { |
| 2412 | case SNDRV_PCM_STATE_DRAINING: |
| 2413 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 2414 | goto __badfd; |
| 2415 | case SNDRV_PCM_STATE_RUNNING: |
| 2416 | if ((err = snd_pcm_update_hw_ptr(substream)) < 0) |
| 2417 | break; |
| 2418 | /* Fall through */ |
| 2419 | case SNDRV_PCM_STATE_PREPARED: |
| 2420 | case SNDRV_PCM_STATE_SUSPENDED: |
| 2421 | err = 0; |
| 2422 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 2423 | n = snd_pcm_playback_hw_avail(runtime); |
| 2424 | else |
| 2425 | n = snd_pcm_capture_avail(runtime); |
Takashi Iwai | 4bbe1dd | 2008-10-13 03:07:14 +0200 | [diff] [blame] | 2426 | n += runtime->delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | break; |
| 2428 | case SNDRV_PCM_STATE_XRUN: |
| 2429 | err = -EPIPE; |
| 2430 | break; |
| 2431 | default: |
| 2432 | __badfd: |
| 2433 | err = -EBADFD; |
| 2434 | break; |
| 2435 | } |
| 2436 | snd_pcm_stream_unlock_irq(substream); |
| 2437 | if (!err) |
| 2438 | if (put_user(n, res)) |
| 2439 | err = -EFAULT; |
| 2440 | return err; |
| 2441 | } |
| 2442 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2443 | static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, |
| 2444 | struct snd_pcm_sync_ptr __user *_sync_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2446 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 2447 | struct snd_pcm_sync_ptr sync_ptr; |
| 2448 | volatile struct snd_pcm_mmap_status *status; |
| 2449 | volatile struct snd_pcm_mmap_control *control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | int err; |
| 2451 | |
| 2452 | memset(&sync_ptr, 0, sizeof(sync_ptr)); |
| 2453 | if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags))) |
| 2454 | return -EFAULT; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2455 | if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), sizeof(struct snd_pcm_mmap_control))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | return -EFAULT; |
| 2457 | status = runtime->status; |
| 2458 | control = runtime->control; |
| 2459 | if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) { |
| 2460 | err = snd_pcm_hwsync(substream); |
| 2461 | if (err < 0) |
| 2462 | return err; |
| 2463 | } |
| 2464 | snd_pcm_stream_lock_irq(substream); |
| 2465 | if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) |
| 2466 | control->appl_ptr = sync_ptr.c.control.appl_ptr; |
| 2467 | else |
| 2468 | sync_ptr.c.control.appl_ptr = control->appl_ptr; |
| 2469 | if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) |
| 2470 | control->avail_min = sync_ptr.c.control.avail_min; |
| 2471 | else |
| 2472 | sync_ptr.c.control.avail_min = control->avail_min; |
| 2473 | sync_ptr.s.status.state = status->state; |
| 2474 | sync_ptr.s.status.hw_ptr = status->hw_ptr; |
| 2475 | sync_ptr.s.status.tstamp = status->tstamp; |
| 2476 | sync_ptr.s.status.suspended_state = status->suspended_state; |
| 2477 | snd_pcm_stream_unlock_irq(substream); |
| 2478 | if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr))) |
| 2479 | return -EFAULT; |
| 2480 | return 0; |
| 2481 | } |
Jaroslav Kysela | b751eef | 2007-12-13 10:19:42 +0100 | [diff] [blame] | 2482 | |
| 2483 | static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) |
| 2484 | { |
| 2485 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 2486 | int arg; |
| 2487 | |
| 2488 | if (get_user(arg, _arg)) |
| 2489 | return -EFAULT; |
| 2490 | if (arg < 0 || arg > SNDRV_PCM_TSTAMP_TYPE_LAST) |
| 2491 | return -EINVAL; |
| 2492 | runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY; |
| 2493 | if (arg == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC) |
| 2494 | runtime->tstamp_type = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC; |
| 2495 | return 0; |
| 2496 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2498 | static int snd_pcm_common_ioctl1(struct file *file, |
| 2499 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | unsigned int cmd, void __user *arg) |
| 2501 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | switch (cmd) { |
| 2503 | case SNDRV_PCM_IOCTL_PVERSION: |
| 2504 | return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0; |
| 2505 | case SNDRV_PCM_IOCTL_INFO: |
| 2506 | return snd_pcm_info_user(substream, arg); |
Jaroslav Kysela | 28e9e47 | 2007-12-17 09:02:22 +0100 | [diff] [blame] | 2507 | case SNDRV_PCM_IOCTL_TSTAMP: /* just for compatibility */ |
| 2508 | return 0; |
Jaroslav Kysela | b751eef | 2007-12-13 10:19:42 +0100 | [diff] [blame] | 2509 | case SNDRV_PCM_IOCTL_TTSTAMP: |
| 2510 | return snd_pcm_tstamp(substream, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | case SNDRV_PCM_IOCTL_HW_REFINE: |
| 2512 | return snd_pcm_hw_refine_user(substream, arg); |
| 2513 | case SNDRV_PCM_IOCTL_HW_PARAMS: |
| 2514 | return snd_pcm_hw_params_user(substream, arg); |
| 2515 | case SNDRV_PCM_IOCTL_HW_FREE: |
| 2516 | return snd_pcm_hw_free(substream); |
| 2517 | case SNDRV_PCM_IOCTL_SW_PARAMS: |
| 2518 | return snd_pcm_sw_params_user(substream, arg); |
| 2519 | case SNDRV_PCM_IOCTL_STATUS: |
| 2520 | return snd_pcm_status_user(substream, arg); |
| 2521 | case SNDRV_PCM_IOCTL_CHANNEL_INFO: |
| 2522 | return snd_pcm_channel_info_user(substream, arg); |
| 2523 | case SNDRV_PCM_IOCTL_PREPARE: |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2524 | return snd_pcm_prepare(substream, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | case SNDRV_PCM_IOCTL_RESET: |
| 2526 | return snd_pcm_reset(substream); |
| 2527 | case SNDRV_PCM_IOCTL_START: |
| 2528 | return snd_pcm_action_lock_irq(&snd_pcm_action_start, substream, SNDRV_PCM_STATE_RUNNING); |
| 2529 | case SNDRV_PCM_IOCTL_LINK: |
| 2530 | return snd_pcm_link(substream, (int)(unsigned long) arg); |
| 2531 | case SNDRV_PCM_IOCTL_UNLINK: |
| 2532 | return snd_pcm_unlink(substream); |
| 2533 | case SNDRV_PCM_IOCTL_RESUME: |
| 2534 | return snd_pcm_resume(substream); |
| 2535 | case SNDRV_PCM_IOCTL_XRUN: |
| 2536 | return snd_pcm_xrun(substream); |
| 2537 | case SNDRV_PCM_IOCTL_HWSYNC: |
| 2538 | return snd_pcm_hwsync(substream); |
| 2539 | case SNDRV_PCM_IOCTL_DELAY: |
| 2540 | return snd_pcm_delay(substream, arg); |
| 2541 | case SNDRV_PCM_IOCTL_SYNC_PTR: |
| 2542 | return snd_pcm_sync_ptr(substream, arg); |
Takashi Iwai | 59d4858 | 2005-12-01 10:51:58 +0100 | [diff] [blame] | 2543 | #ifdef CONFIG_SND_SUPPORT_OLD_API |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | case SNDRV_PCM_IOCTL_HW_REFINE_OLD: |
| 2545 | return snd_pcm_hw_refine_old_user(substream, arg); |
| 2546 | case SNDRV_PCM_IOCTL_HW_PARAMS_OLD: |
| 2547 | return snd_pcm_hw_params_old_user(substream, arg); |
Takashi Iwai | 59d4858 | 2005-12-01 10:51:58 +0100 | [diff] [blame] | 2548 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | case SNDRV_PCM_IOCTL_DRAIN: |
Takashi Iwai | 4cdc115 | 2009-08-20 16:40:16 +0200 | [diff] [blame] | 2550 | return snd_pcm_drain(substream, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | case SNDRV_PCM_IOCTL_DROP: |
| 2552 | return snd_pcm_drop(substream); |
Takashi Iwai | e661d0d | 2006-02-21 14:14:50 +0100 | [diff] [blame] | 2553 | case SNDRV_PCM_IOCTL_PAUSE: |
| 2554 | { |
| 2555 | int res; |
| 2556 | snd_pcm_stream_lock_irq(substream); |
| 2557 | res = snd_pcm_pause(substream, (int)(unsigned long)arg); |
| 2558 | snd_pcm_stream_unlock_irq(substream); |
| 2559 | return res; |
| 2560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
| 2562 | snd_printd("unknown ioctl = 0x%x\n", cmd); |
| 2563 | return -ENOTTY; |
| 2564 | } |
| 2565 | |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2566 | static int snd_pcm_playback_ioctl1(struct file *file, |
| 2567 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | unsigned int cmd, void __user *arg) |
| 2569 | { |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2570 | if (snd_BUG_ON(!substream)) |
| 2571 | return -ENXIO; |
| 2572 | if (snd_BUG_ON(substream->stream != SNDRV_PCM_STREAM_PLAYBACK)) |
| 2573 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | switch (cmd) { |
| 2575 | case SNDRV_PCM_IOCTL_WRITEI_FRAMES: |
| 2576 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2577 | struct snd_xferi xferi; |
| 2578 | struct snd_xferi __user *_xferi = arg; |
| 2579 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | snd_pcm_sframes_t result; |
| 2581 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2582 | return -EBADFD; |
| 2583 | if (put_user(0, &_xferi->result)) |
| 2584 | return -EFAULT; |
| 2585 | if (copy_from_user(&xferi, _xferi, sizeof(xferi))) |
| 2586 | return -EFAULT; |
| 2587 | result = snd_pcm_lib_write(substream, xferi.buf, xferi.frames); |
| 2588 | __put_user(result, &_xferi->result); |
| 2589 | return result < 0 ? result : 0; |
| 2590 | } |
| 2591 | case SNDRV_PCM_IOCTL_WRITEN_FRAMES: |
| 2592 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2593 | struct snd_xfern xfern; |
| 2594 | struct snd_xfern __user *_xfern = arg; |
| 2595 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | void __user **bufs; |
| 2597 | snd_pcm_sframes_t result; |
| 2598 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2599 | return -EBADFD; |
| 2600 | if (runtime->channels > 128) |
| 2601 | return -EINVAL; |
| 2602 | if (put_user(0, &_xfern->result)) |
| 2603 | return -EFAULT; |
| 2604 | if (copy_from_user(&xfern, _xfern, sizeof(xfern))) |
| 2605 | return -EFAULT; |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 2606 | |
| 2607 | bufs = memdup_user(xfern.bufs, |
| 2608 | sizeof(void *) * runtime->channels); |
| 2609 | if (IS_ERR(bufs)) |
| 2610 | return PTR_ERR(bufs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | result = snd_pcm_lib_writev(substream, bufs, xfern.frames); |
| 2612 | kfree(bufs); |
| 2613 | __put_user(result, &_xfern->result); |
| 2614 | return result < 0 ? result : 0; |
| 2615 | } |
| 2616 | case SNDRV_PCM_IOCTL_REWIND: |
| 2617 | { |
| 2618 | snd_pcm_uframes_t frames; |
| 2619 | snd_pcm_uframes_t __user *_frames = arg; |
| 2620 | snd_pcm_sframes_t result; |
| 2621 | if (get_user(frames, _frames)) |
| 2622 | return -EFAULT; |
| 2623 | if (put_user(0, _frames)) |
| 2624 | return -EFAULT; |
| 2625 | result = snd_pcm_playback_rewind(substream, frames); |
| 2626 | __put_user(result, _frames); |
| 2627 | return result < 0 ? result : 0; |
| 2628 | } |
| 2629 | case SNDRV_PCM_IOCTL_FORWARD: |
| 2630 | { |
| 2631 | snd_pcm_uframes_t frames; |
| 2632 | snd_pcm_uframes_t __user *_frames = arg; |
| 2633 | snd_pcm_sframes_t result; |
| 2634 | if (get_user(frames, _frames)) |
| 2635 | return -EFAULT; |
| 2636 | if (put_user(0, _frames)) |
| 2637 | return -EFAULT; |
| 2638 | result = snd_pcm_playback_forward(substream, frames); |
| 2639 | __put_user(result, _frames); |
| 2640 | return result < 0 ? result : 0; |
| 2641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | } |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2643 | return snd_pcm_common_ioctl1(file, substream, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2646 | static int snd_pcm_capture_ioctl1(struct file *file, |
| 2647 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | unsigned int cmd, void __user *arg) |
| 2649 | { |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2650 | if (snd_BUG_ON(!substream)) |
| 2651 | return -ENXIO; |
| 2652 | if (snd_BUG_ON(substream->stream != SNDRV_PCM_STREAM_CAPTURE)) |
| 2653 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | switch (cmd) { |
| 2655 | case SNDRV_PCM_IOCTL_READI_FRAMES: |
| 2656 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2657 | struct snd_xferi xferi; |
| 2658 | struct snd_xferi __user *_xferi = arg; |
| 2659 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | snd_pcm_sframes_t result; |
| 2661 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2662 | return -EBADFD; |
| 2663 | if (put_user(0, &_xferi->result)) |
| 2664 | return -EFAULT; |
| 2665 | if (copy_from_user(&xferi, _xferi, sizeof(xferi))) |
| 2666 | return -EFAULT; |
| 2667 | result = snd_pcm_lib_read(substream, xferi.buf, xferi.frames); |
| 2668 | __put_user(result, &_xferi->result); |
| 2669 | return result < 0 ? result : 0; |
| 2670 | } |
| 2671 | case SNDRV_PCM_IOCTL_READN_FRAMES: |
| 2672 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2673 | struct snd_xfern xfern; |
| 2674 | struct snd_xfern __user *_xfern = arg; |
| 2675 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | void *bufs; |
| 2677 | snd_pcm_sframes_t result; |
| 2678 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2679 | return -EBADFD; |
| 2680 | if (runtime->channels > 128) |
| 2681 | return -EINVAL; |
| 2682 | if (put_user(0, &_xfern->result)) |
| 2683 | return -EFAULT; |
| 2684 | if (copy_from_user(&xfern, _xfern, sizeof(xfern))) |
| 2685 | return -EFAULT; |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 2686 | |
| 2687 | bufs = memdup_user(xfern.bufs, |
| 2688 | sizeof(void *) * runtime->channels); |
| 2689 | if (IS_ERR(bufs)) |
| 2690 | return PTR_ERR(bufs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | result = snd_pcm_lib_readv(substream, bufs, xfern.frames); |
| 2692 | kfree(bufs); |
| 2693 | __put_user(result, &_xfern->result); |
| 2694 | return result < 0 ? result : 0; |
| 2695 | } |
| 2696 | case SNDRV_PCM_IOCTL_REWIND: |
| 2697 | { |
| 2698 | snd_pcm_uframes_t frames; |
| 2699 | snd_pcm_uframes_t __user *_frames = arg; |
| 2700 | snd_pcm_sframes_t result; |
| 2701 | if (get_user(frames, _frames)) |
| 2702 | return -EFAULT; |
| 2703 | if (put_user(0, _frames)) |
| 2704 | return -EFAULT; |
| 2705 | result = snd_pcm_capture_rewind(substream, frames); |
| 2706 | __put_user(result, _frames); |
| 2707 | return result < 0 ? result : 0; |
| 2708 | } |
| 2709 | case SNDRV_PCM_IOCTL_FORWARD: |
| 2710 | { |
| 2711 | snd_pcm_uframes_t frames; |
| 2712 | snd_pcm_uframes_t __user *_frames = arg; |
| 2713 | snd_pcm_sframes_t result; |
| 2714 | if (get_user(frames, _frames)) |
| 2715 | return -EFAULT; |
| 2716 | if (put_user(0, _frames)) |
| 2717 | return -EFAULT; |
| 2718 | result = snd_pcm_capture_forward(substream, frames); |
| 2719 | __put_user(result, _frames); |
| 2720 | return result < 0 ? result : 0; |
| 2721 | } |
| 2722 | } |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2723 | return snd_pcm_common_ioctl1(file, substream, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2726 | static long snd_pcm_playback_ioctl(struct file *file, unsigned int cmd, |
| 2727 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2729 | struct snd_pcm_file *pcm_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | |
| 2731 | pcm_file = file->private_data; |
| 2732 | |
| 2733 | if (((cmd >> 8) & 0xff) != 'A') |
| 2734 | return -ENOTTY; |
| 2735 | |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2736 | return snd_pcm_playback_ioctl1(file, pcm_file->substream, cmd, |
| 2737 | (void __user *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2740 | static long snd_pcm_capture_ioctl(struct file *file, unsigned int cmd, |
| 2741 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2743 | struct snd_pcm_file *pcm_file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
| 2745 | pcm_file = file->private_data; |
| 2746 | |
| 2747 | if (((cmd >> 8) & 0xff) != 'A') |
| 2748 | return -ENOTTY; |
| 2749 | |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2750 | return snd_pcm_capture_ioctl1(file, pcm_file->substream, cmd, |
| 2751 | (void __user *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2754 | int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | unsigned int cmd, void *arg) |
| 2756 | { |
Takashi Iwai | bf1bbb5 | 2006-03-27 16:22:45 +0200 | [diff] [blame] | 2757 | mm_segment_t fs; |
| 2758 | int result; |
| 2759 | |
| 2760 | fs = snd_enter_user(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | switch (substream->stream) { |
| 2762 | case SNDRV_PCM_STREAM_PLAYBACK: |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2763 | result = snd_pcm_playback_ioctl1(NULL, substream, cmd, |
| 2764 | (void __user *)arg); |
Takashi Iwai | bf1bbb5 | 2006-03-27 16:22:45 +0200 | [diff] [blame] | 2765 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | case SNDRV_PCM_STREAM_CAPTURE: |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2767 | result = snd_pcm_capture_ioctl1(NULL, substream, cmd, |
| 2768 | (void __user *)arg); |
Takashi Iwai | bf1bbb5 | 2006-03-27 16:22:45 +0200 | [diff] [blame] | 2769 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | default: |
Takashi Iwai | bf1bbb5 | 2006-03-27 16:22:45 +0200 | [diff] [blame] | 2771 | result = -EINVAL; |
| 2772 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | } |
Takashi Iwai | bf1bbb5 | 2006-03-27 16:22:45 +0200 | [diff] [blame] | 2774 | snd_leave_user(fs); |
| 2775 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 2778 | EXPORT_SYMBOL(snd_pcm_kernel_ioctl); |
| 2779 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2780 | static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count, |
| 2781 | loff_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2783 | struct snd_pcm_file *pcm_file; |
| 2784 | struct snd_pcm_substream *substream; |
| 2785 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | snd_pcm_sframes_t result; |
| 2787 | |
| 2788 | pcm_file = file->private_data; |
| 2789 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2790 | if (PCM_RUNTIME_CHECK(substream)) |
| 2791 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | runtime = substream->runtime; |
| 2793 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2794 | return -EBADFD; |
| 2795 | if (!frame_aligned(runtime, count)) |
| 2796 | return -EINVAL; |
| 2797 | count = bytes_to_frames(runtime, count); |
| 2798 | result = snd_pcm_lib_read(substream, buf, count); |
| 2799 | if (result > 0) |
| 2800 | result = frames_to_bytes(runtime, result); |
| 2801 | return result; |
| 2802 | } |
| 2803 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2804 | static ssize_t snd_pcm_write(struct file *file, const char __user *buf, |
| 2805 | size_t count, loff_t * offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2807 | struct snd_pcm_file *pcm_file; |
| 2808 | struct snd_pcm_substream *substream; |
| 2809 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | snd_pcm_sframes_t result; |
| 2811 | |
| 2812 | pcm_file = file->private_data; |
| 2813 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2814 | if (PCM_RUNTIME_CHECK(substream)) |
| 2815 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | runtime = substream->runtime; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2817 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2818 | return -EBADFD; |
| 2819 | if (!frame_aligned(runtime, count)) |
| 2820 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | count = bytes_to_frames(runtime, count); |
| 2822 | result = snd_pcm_lib_write(substream, buf, count); |
| 2823 | if (result > 0) |
| 2824 | result = frames_to_bytes(runtime, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | return result; |
| 2826 | } |
| 2827 | |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2828 | static ssize_t snd_pcm_aio_read(struct kiocb *iocb, const struct iovec *iov, |
| 2829 | unsigned long nr_segs, loff_t pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | |
| 2831 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2832 | struct snd_pcm_file *pcm_file; |
| 2833 | struct snd_pcm_substream *substream; |
| 2834 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | snd_pcm_sframes_t result; |
| 2836 | unsigned long i; |
| 2837 | void __user **bufs; |
| 2838 | snd_pcm_uframes_t frames; |
| 2839 | |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2840 | pcm_file = iocb->ki_filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2842 | if (PCM_RUNTIME_CHECK(substream)) |
| 2843 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | runtime = substream->runtime; |
| 2845 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2846 | return -EBADFD; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2847 | if (nr_segs > 1024 || nr_segs != runtime->channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | return -EINVAL; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2849 | if (!frame_aligned(runtime, iov->iov_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | return -EINVAL; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2851 | frames = bytes_to_samples(runtime, iov->iov_len); |
| 2852 | bufs = kmalloc(sizeof(void *) * nr_segs, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | if (bufs == NULL) |
| 2854 | return -ENOMEM; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2855 | for (i = 0; i < nr_segs; ++i) |
| 2856 | bufs[i] = iov[i].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | result = snd_pcm_lib_readv(substream, bufs, frames); |
| 2858 | if (result > 0) |
| 2859 | result = frames_to_bytes(runtime, result); |
| 2860 | kfree(bufs); |
| 2861 | return result; |
| 2862 | } |
| 2863 | |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2864 | static ssize_t snd_pcm_aio_write(struct kiocb *iocb, const struct iovec *iov, |
| 2865 | unsigned long nr_segs, loff_t pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2867 | struct snd_pcm_file *pcm_file; |
| 2868 | struct snd_pcm_substream *substream; |
| 2869 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | snd_pcm_sframes_t result; |
| 2871 | unsigned long i; |
| 2872 | void __user **bufs; |
| 2873 | snd_pcm_uframes_t frames; |
| 2874 | |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2875 | pcm_file = iocb->ki_filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2877 | if (PCM_RUNTIME_CHECK(substream)) |
| 2878 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | runtime = substream->runtime; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2880 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 2881 | return -EBADFD; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2882 | if (nr_segs > 128 || nr_segs != runtime->channels || |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2883 | !frame_aligned(runtime, iov->iov_len)) |
| 2884 | return -EINVAL; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2885 | frames = bytes_to_samples(runtime, iov->iov_len); |
| 2886 | bufs = kmalloc(sizeof(void *) * nr_segs, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | if (bufs == NULL) |
| 2888 | return -ENOMEM; |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 2889 | for (i = 0; i < nr_segs; ++i) |
| 2890 | bufs[i] = iov[i].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | result = snd_pcm_lib_writev(substream, bufs, frames); |
| 2892 | if (result > 0) |
| 2893 | result = frames_to_bytes(runtime, result); |
| 2894 | kfree(bufs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | return result; |
| 2896 | } |
| 2897 | |
| 2898 | static unsigned int snd_pcm_playback_poll(struct file *file, poll_table * wait) |
| 2899 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2900 | struct snd_pcm_file *pcm_file; |
| 2901 | struct snd_pcm_substream *substream; |
| 2902 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | unsigned int mask; |
| 2904 | snd_pcm_uframes_t avail; |
| 2905 | |
| 2906 | pcm_file = file->private_data; |
| 2907 | |
| 2908 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2909 | if (PCM_RUNTIME_CHECK(substream)) |
| 2910 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | runtime = substream->runtime; |
| 2912 | |
| 2913 | poll_wait(file, &runtime->sleep, wait); |
| 2914 | |
| 2915 | snd_pcm_stream_lock_irq(substream); |
| 2916 | avail = snd_pcm_playback_avail(runtime); |
| 2917 | switch (runtime->status->state) { |
| 2918 | case SNDRV_PCM_STATE_RUNNING: |
| 2919 | case SNDRV_PCM_STATE_PREPARED: |
| 2920 | case SNDRV_PCM_STATE_PAUSED: |
| 2921 | if (avail >= runtime->control->avail_min) { |
| 2922 | mask = POLLOUT | POLLWRNORM; |
| 2923 | break; |
| 2924 | } |
| 2925 | /* Fall through */ |
| 2926 | case SNDRV_PCM_STATE_DRAINING: |
| 2927 | mask = 0; |
| 2928 | break; |
| 2929 | default: |
| 2930 | mask = POLLOUT | POLLWRNORM | POLLERR; |
| 2931 | break; |
| 2932 | } |
| 2933 | snd_pcm_stream_unlock_irq(substream); |
| 2934 | return mask; |
| 2935 | } |
| 2936 | |
| 2937 | static unsigned int snd_pcm_capture_poll(struct file *file, poll_table * wait) |
| 2938 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2939 | struct snd_pcm_file *pcm_file; |
| 2940 | struct snd_pcm_substream *substream; |
| 2941 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | unsigned int mask; |
| 2943 | snd_pcm_uframes_t avail; |
| 2944 | |
| 2945 | pcm_file = file->private_data; |
| 2946 | |
| 2947 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 2948 | if (PCM_RUNTIME_CHECK(substream)) |
| 2949 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | runtime = substream->runtime; |
| 2951 | |
| 2952 | poll_wait(file, &runtime->sleep, wait); |
| 2953 | |
| 2954 | snd_pcm_stream_lock_irq(substream); |
| 2955 | avail = snd_pcm_capture_avail(runtime); |
| 2956 | switch (runtime->status->state) { |
| 2957 | case SNDRV_PCM_STATE_RUNNING: |
| 2958 | case SNDRV_PCM_STATE_PREPARED: |
| 2959 | case SNDRV_PCM_STATE_PAUSED: |
| 2960 | if (avail >= runtime->control->avail_min) { |
| 2961 | mask = POLLIN | POLLRDNORM; |
| 2962 | break; |
| 2963 | } |
| 2964 | mask = 0; |
| 2965 | break; |
| 2966 | case SNDRV_PCM_STATE_DRAINING: |
| 2967 | if (avail > 0) { |
| 2968 | mask = POLLIN | POLLRDNORM; |
| 2969 | break; |
| 2970 | } |
| 2971 | /* Fall through */ |
| 2972 | default: |
| 2973 | mask = POLLIN | POLLRDNORM | POLLERR; |
| 2974 | break; |
| 2975 | } |
| 2976 | snd_pcm_stream_unlock_irq(substream); |
| 2977 | return mask; |
| 2978 | } |
| 2979 | |
| 2980 | /* |
| 2981 | * mmap support |
| 2982 | */ |
| 2983 | |
| 2984 | /* |
| 2985 | * Only on coherent architectures, we can mmap the status and the control records |
| 2986 | * for effcient data transfer. On others, we have to use HWSYNC ioctl... |
| 2987 | */ |
| 2988 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA) |
| 2989 | /* |
| 2990 | * mmap status record |
| 2991 | */ |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 2992 | static int snd_pcm_mmap_status_fault(struct vm_area_struct *area, |
| 2993 | struct vm_fault *vmf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 2995 | struct snd_pcm_substream *substream = area->vm_private_data; |
| 2996 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | |
| 2998 | if (substream == NULL) |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 2999 | return VM_FAULT_SIGBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | runtime = substream->runtime; |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3001 | vmf->page = virt_to_page(runtime->status); |
| 3002 | get_page(vmf->page); |
| 3003 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 3006 | static const struct vm_operations_struct snd_pcm_vm_ops_status = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | { |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3008 | .fault = snd_pcm_mmap_status_fault, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | }; |
| 3010 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3011 | static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | struct vm_area_struct *area) |
| 3013 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3014 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | long size; |
| 3016 | if (!(area->vm_flags & VM_READ)) |
| 3017 | return -EINVAL; |
| 3018 | runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | size = area->vm_end - area->vm_start; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3020 | if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | return -EINVAL; |
| 3022 | area->vm_ops = &snd_pcm_vm_ops_status; |
| 3023 | area->vm_private_data = substream; |
| 3024 | area->vm_flags |= VM_RESERVED; |
| 3025 | return 0; |
| 3026 | } |
| 3027 | |
| 3028 | /* |
| 3029 | * mmap control record |
| 3030 | */ |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3031 | static int snd_pcm_mmap_control_fault(struct vm_area_struct *area, |
| 3032 | struct vm_fault *vmf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3034 | struct snd_pcm_substream *substream = area->vm_private_data; |
| 3035 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | |
| 3037 | if (substream == NULL) |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3038 | return VM_FAULT_SIGBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | runtime = substream->runtime; |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3040 | vmf->page = virt_to_page(runtime->control); |
| 3041 | get_page(vmf->page); |
| 3042 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 3045 | static const struct vm_operations_struct snd_pcm_vm_ops_control = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | { |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3047 | .fault = snd_pcm_mmap_control_fault, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | }; |
| 3049 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3050 | static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | struct vm_area_struct *area) |
| 3052 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3053 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | long size; |
| 3055 | if (!(area->vm_flags & VM_READ)) |
| 3056 | return -EINVAL; |
| 3057 | runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | size = area->vm_end - area->vm_start; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3059 | if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | return -EINVAL; |
| 3061 | area->vm_ops = &snd_pcm_vm_ops_control; |
| 3062 | area->vm_private_data = substream; |
| 3063 | area->vm_flags |= VM_RESERVED; |
| 3064 | return 0; |
| 3065 | } |
| 3066 | #else /* ! coherent mmap */ |
| 3067 | /* |
| 3068 | * don't support mmap for status and control records. |
| 3069 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3070 | static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | struct vm_area_struct *area) |
| 3072 | { |
| 3073 | return -ENXIO; |
| 3074 | } |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3075 | static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | struct vm_area_struct *area) |
| 3077 | { |
| 3078 | return -ENXIO; |
| 3079 | } |
| 3080 | #endif /* coherent mmap */ |
| 3081 | |
Takashi Iwai | 9eb4a06 | 2009-11-26 12:43:39 +0100 | [diff] [blame] | 3082 | static inline struct page * |
| 3083 | snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs) |
| 3084 | { |
| 3085 | void *vaddr = substream->runtime->dma_area + ofs; |
Takashi Iwai | 66b6cfa | 2009-11-26 12:50:01 +0100 | [diff] [blame] | 3086 | #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT) |
| 3087 | if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) |
| 3088 | return virt_to_page(CAC_ADDR(vaddr)); |
| 3089 | #endif |
Takashi Iwai | 6985c88 | 2009-11-26 15:04:24 +0100 | [diff] [blame] | 3090 | #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE) |
| 3091 | if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) { |
| 3092 | dma_addr_t addr = substream->runtime->dma_addr + ofs; |
| 3093 | addr -= get_dma_offset(substream->dma_buffer.dev.dev); |
| 3094 | /* assume dma_handle set via pfn_to_phys() in |
| 3095 | * mm/dma-noncoherent.c |
| 3096 | */ |
| 3097 | return pfn_to_page(addr >> PAGE_SHIFT); |
| 3098 | } |
| 3099 | #endif |
Takashi Iwai | 9eb4a06 | 2009-11-26 12:43:39 +0100 | [diff] [blame] | 3100 | return virt_to_page(vaddr); |
| 3101 | } |
| 3102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | /* |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3104 | * fault callback for mmapping a RAM page |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | */ |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3106 | static int snd_pcm_mmap_data_fault(struct vm_area_struct *area, |
| 3107 | struct vm_fault *vmf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3109 | struct snd_pcm_substream *substream = area->vm_private_data; |
| 3110 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | unsigned long offset; |
| 3112 | struct page * page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | size_t dma_bytes; |
| 3114 | |
| 3115 | if (substream == NULL) |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3116 | return VM_FAULT_SIGBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | runtime = substream->runtime; |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3118 | offset = vmf->pgoff << PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | dma_bytes = PAGE_ALIGN(runtime->dma_bytes); |
| 3120 | if (offset > dma_bytes - PAGE_SIZE) |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3121 | return VM_FAULT_SIGBUS; |
Takashi Iwai | 9eb4a06 | 2009-11-26 12:43:39 +0100 | [diff] [blame] | 3122 | if (substream->ops->page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | page = substream->ops->page(substream, offset); |
Takashi Iwai | 9eb4a06 | 2009-11-26 12:43:39 +0100 | [diff] [blame] | 3124 | else |
| 3125 | page = snd_pcm_default_page_ops(substream, offset); |
| 3126 | if (!page) |
| 3127 | return VM_FAULT_SIGBUS; |
Nick Piggin | b581003 | 2005-10-29 18:16:12 -0700 | [diff] [blame] | 3128 | get_page(page); |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3129 | vmf->page = page; |
| 3130 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3133 | static const struct vm_operations_struct snd_pcm_vm_ops_data = { |
| 3134 | .open = snd_pcm_mmap_data_open, |
| 3135 | .close = snd_pcm_mmap_data_close, |
| 3136 | }; |
| 3137 | |
| 3138 | static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | .open = snd_pcm_mmap_data_open, |
| 3140 | .close = snd_pcm_mmap_data_close, |
Nick Piggin | 3ad5afc | 2007-12-13 16:15:00 +0100 | [diff] [blame] | 3141 | .fault = snd_pcm_mmap_data_fault, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | }; |
| 3143 | |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3144 | #ifndef ARCH_HAS_DMA_MMAP_COHERENT |
| 3145 | /* This should be defined / handled globally! */ |
| 3146 | #ifdef CONFIG_ARM |
| 3147 | #define ARCH_HAS_DMA_MMAP_COHERENT |
| 3148 | #endif |
| 3149 | #endif |
| 3150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | /* |
| 3152 | * mmap the DMA buffer on RAM |
| 3153 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3154 | static int snd_pcm_default_mmap(struct snd_pcm_substream *substream, |
| 3155 | struct vm_area_struct *area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | area->vm_flags |= VM_RESERVED; |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3158 | #ifdef ARCH_HAS_DMA_MMAP_COHERENT |
| 3159 | if (!substream->ops->page && |
| 3160 | substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV) |
| 3161 | return dma_mmap_coherent(substream->dma_buffer.dev.dev, |
| 3162 | area, |
| 3163 | substream->runtime->dma_area, |
| 3164 | substream->runtime->dma_addr, |
| 3165 | area->vm_end - area->vm_start); |
Takashi Iwai | 9fe17b5 | 2010-05-12 10:32:42 +0200 | [diff] [blame] | 3166 | #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT) |
| 3167 | if (substream->dma_buffer.dev.type == SNDRV_DMA_TYPE_DEV && |
| 3168 | !plat_device_is_coherent(substream->dma_buffer.dev.dev)) |
| 3169 | area->vm_page_prot = pgprot_noncached(area->vm_page_prot); |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3170 | #endif /* ARCH_HAS_DMA_MMAP_COHERENT */ |
| 3171 | /* mmap with fault handler */ |
| 3172 | area->vm_ops = &snd_pcm_vm_ops_data_fault; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | return 0; |
| 3174 | } |
| 3175 | |
| 3176 | /* |
| 3177 | * mmap the DMA buffer on I/O memory area |
| 3178 | */ |
| 3179 | #if SNDRV_PCM_INFO_MMAP_IOMEM |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3180 | int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, |
| 3181 | struct vm_area_struct *area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | { |
| 3183 | long size; |
| 3184 | unsigned long offset; |
| 3185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | area->vm_page_prot = pgprot_noncached(area->vm_page_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | area->vm_flags |= VM_IO; |
| 3188 | size = area->vm_end - area->vm_start; |
| 3189 | offset = area->vm_pgoff << PAGE_SHIFT; |
| 3190 | if (io_remap_pfn_range(area, area->vm_start, |
| 3191 | (substream->runtime->dma_addr + offset) >> PAGE_SHIFT, |
| 3192 | size, area->vm_page_prot)) |
| 3193 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | return 0; |
| 3195 | } |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 3196 | |
| 3197 | EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | #endif /* SNDRV_PCM_INFO_MMAP */ |
| 3199 | |
Takashi Iwai | c32d977 | 2010-01-18 14:58:57 +0100 | [diff] [blame] | 3200 | /* mmap callback with pgprot_noncached */ |
| 3201 | int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream *substream, |
| 3202 | struct vm_area_struct *area) |
| 3203 | { |
| 3204 | area->vm_page_prot = pgprot_noncached(area->vm_page_prot); |
| 3205 | return snd_pcm_default_mmap(substream, area); |
| 3206 | } |
| 3207 | EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached); |
| 3208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | /* |
| 3210 | * mmap DMA buffer |
| 3211 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3212 | int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | struct vm_area_struct *area) |
| 3214 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3215 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | long size; |
| 3217 | unsigned long offset; |
| 3218 | size_t dma_bytes; |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3219 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | |
| 3221 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 3222 | if (!(area->vm_flags & (VM_WRITE|VM_READ))) |
| 3223 | return -EINVAL; |
| 3224 | } else { |
| 3225 | if (!(area->vm_flags & VM_READ)) |
| 3226 | return -EINVAL; |
| 3227 | } |
| 3228 | runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) |
| 3230 | return -EBADFD; |
| 3231 | if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) |
| 3232 | return -ENXIO; |
| 3233 | if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || |
| 3234 | runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) |
| 3235 | return -EINVAL; |
| 3236 | size = area->vm_end - area->vm_start; |
| 3237 | offset = area->vm_pgoff << PAGE_SHIFT; |
| 3238 | dma_bytes = PAGE_ALIGN(runtime->dma_bytes); |
| 3239 | if ((size_t)size > dma_bytes) |
| 3240 | return -EINVAL; |
| 3241 | if (offset > dma_bytes - size) |
| 3242 | return -EINVAL; |
| 3243 | |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3244 | area->vm_ops = &snd_pcm_vm_ops_data; |
| 3245 | area->vm_private_data = substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | if (substream->ops->mmap) |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3247 | err = substream->ops->mmap(substream, area); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | else |
Takashi Iwai | 657b198 | 2009-11-26 12:40:21 +0100 | [diff] [blame] | 3249 | err = snd_pcm_default_mmap(substream, area); |
| 3250 | if (!err) |
| 3251 | atomic_inc(&substream->mmap_count); |
| 3252 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 3255 | EXPORT_SYMBOL(snd_pcm_mmap_data); |
| 3256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) |
| 3258 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3259 | struct snd_pcm_file * pcm_file; |
| 3260 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | unsigned long offset; |
| 3262 | |
| 3263 | pcm_file = file->private_data; |
| 3264 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 3265 | if (PCM_RUNTIME_CHECK(substream)) |
| 3266 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
| 3268 | offset = area->vm_pgoff << PAGE_SHIFT; |
| 3269 | switch (offset) { |
| 3270 | case SNDRV_PCM_MMAP_OFFSET_STATUS: |
Takashi Iwai | 548a648 | 2006-07-31 16:51:51 +0200 | [diff] [blame] | 3271 | if (pcm_file->no_compat_mmap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | return -ENXIO; |
| 3273 | return snd_pcm_mmap_status(substream, file, area); |
| 3274 | case SNDRV_PCM_MMAP_OFFSET_CONTROL: |
Takashi Iwai | 548a648 | 2006-07-31 16:51:51 +0200 | [diff] [blame] | 3275 | if (pcm_file->no_compat_mmap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | return -ENXIO; |
| 3277 | return snd_pcm_mmap_control(substream, file, area); |
| 3278 | default: |
| 3279 | return snd_pcm_mmap_data(substream, file, area); |
| 3280 | } |
| 3281 | return 0; |
| 3282 | } |
| 3283 | |
| 3284 | static int snd_pcm_fasync(int fd, struct file * file, int on) |
| 3285 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3286 | struct snd_pcm_file * pcm_file; |
| 3287 | struct snd_pcm_substream *substream; |
| 3288 | struct snd_pcm_runtime *runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | |
| 3290 | pcm_file = file->private_data; |
| 3291 | substream = pcm_file->substream; |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 3292 | if (PCM_RUNTIME_CHECK(substream)) |
Takashi Iwai | d05468b | 2010-04-07 18:29:46 +0200 | [diff] [blame] | 3293 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | runtime = substream->runtime; |
Takashi Iwai | d05468b | 2010-04-07 18:29:46 +0200 | [diff] [blame] | 3295 | return fasync_helper(fd, file, on, &runtime->fasync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | /* |
| 3299 | * ioctl32 compat |
| 3300 | */ |
| 3301 | #ifdef CONFIG_COMPAT |
| 3302 | #include "pcm_compat.c" |
| 3303 | #else |
| 3304 | #define snd_pcm_ioctl_compat NULL |
| 3305 | #endif |
| 3306 | |
| 3307 | /* |
| 3308 | * To be removed helpers to keep binary compatibility |
| 3309 | */ |
| 3310 | |
Takashi Iwai | 59d4858 | 2005-12-01 10:51:58 +0100 | [diff] [blame] | 3311 | #ifdef CONFIG_SND_SUPPORT_OLD_API |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5)) |
| 3313 | #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5)) |
| 3314 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3315 | static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params *params, |
| 3316 | struct snd_pcm_hw_params_old *oparams) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | { |
| 3318 | unsigned int i; |
| 3319 | |
| 3320 | memset(params, 0, sizeof(*params)); |
| 3321 | params->flags = oparams->flags; |
| 3322 | for (i = 0; i < ARRAY_SIZE(oparams->masks); i++) |
| 3323 | params->masks[i].bits[0] = oparams->masks[i]; |
| 3324 | memcpy(params->intervals, oparams->intervals, sizeof(oparams->intervals)); |
| 3325 | params->rmask = __OLD_TO_NEW_MASK(oparams->rmask); |
| 3326 | params->cmask = __OLD_TO_NEW_MASK(oparams->cmask); |
| 3327 | params->info = oparams->info; |
| 3328 | params->msbits = oparams->msbits; |
| 3329 | params->rate_num = oparams->rate_num; |
| 3330 | params->rate_den = oparams->rate_den; |
| 3331 | params->fifo_size = oparams->fifo_size; |
| 3332 | } |
| 3333 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3334 | static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old *oparams, |
| 3335 | struct snd_pcm_hw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | { |
| 3337 | unsigned int i; |
| 3338 | |
| 3339 | memset(oparams, 0, sizeof(*oparams)); |
| 3340 | oparams->flags = params->flags; |
| 3341 | for (i = 0; i < ARRAY_SIZE(oparams->masks); i++) |
| 3342 | oparams->masks[i] = params->masks[i].bits[0]; |
| 3343 | memcpy(oparams->intervals, params->intervals, sizeof(oparams->intervals)); |
| 3344 | oparams->rmask = __NEW_TO_OLD_MASK(params->rmask); |
| 3345 | oparams->cmask = __NEW_TO_OLD_MASK(params->cmask); |
| 3346 | oparams->info = params->info; |
| 3347 | oparams->msbits = params->msbits; |
| 3348 | oparams->rate_num = params->rate_num; |
| 3349 | oparams->rate_den = params->rate_den; |
| 3350 | oparams->fifo_size = params->fifo_size; |
| 3351 | } |
| 3352 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3353 | static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, |
| 3354 | struct snd_pcm_hw_params_old __user * _oparams) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3356 | struct snd_pcm_hw_params *params; |
| 3357 | struct snd_pcm_hw_params_old *oparams = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | int err; |
| 3359 | |
| 3360 | params = kmalloc(sizeof(*params), GFP_KERNEL); |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 3361 | if (!params) |
| 3362 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 3364 | oparams = memdup_user(_oparams, sizeof(*oparams)); |
| 3365 | if (IS_ERR(oparams)) { |
| 3366 | err = PTR_ERR(oparams); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | goto out; |
| 3368 | } |
| 3369 | snd_pcm_hw_convert_from_old_params(params, oparams); |
| 3370 | err = snd_pcm_hw_refine(substream, params); |
| 3371 | snd_pcm_hw_convert_to_old_params(oparams, params); |
| 3372 | if (copy_to_user(_oparams, oparams, sizeof(*oparams))) { |
| 3373 | if (!err) |
| 3374 | err = -EFAULT; |
| 3375 | } |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 3376 | |
| 3377 | kfree(oparams); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3378 | out: |
| 3379 | kfree(params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | return err; |
| 3381 | } |
| 3382 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3383 | static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, |
| 3384 | struct snd_pcm_hw_params_old __user * _oparams) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 3386 | struct snd_pcm_hw_params *params; |
| 3387 | struct snd_pcm_hw_params_old *oparams = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | int err; |
| 3389 | |
| 3390 | params = kmalloc(sizeof(*params), GFP_KERNEL); |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 3391 | if (!params) |
| 3392 | return -ENOMEM; |
| 3393 | |
| 3394 | oparams = memdup_user(_oparams, sizeof(*oparams)); |
| 3395 | if (IS_ERR(oparams)) { |
| 3396 | err = PTR_ERR(oparams); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | goto out; |
| 3398 | } |
| 3399 | snd_pcm_hw_convert_from_old_params(params, oparams); |
| 3400 | err = snd_pcm_hw_params(substream, params); |
| 3401 | snd_pcm_hw_convert_to_old_params(oparams, params); |
| 3402 | if (copy_to_user(_oparams, oparams, sizeof(*oparams))) { |
| 3403 | if (!err) |
| 3404 | err = -EFAULT; |
| 3405 | } |
Li Zefan | ef44a1e | 2009-04-10 09:43:08 +0800 | [diff] [blame] | 3406 | |
| 3407 | kfree(oparams); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | out: |
| 3409 | kfree(params); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | return err; |
| 3411 | } |
Takashi Iwai | 59d4858 | 2005-12-01 10:51:58 +0100 | [diff] [blame] | 3412 | #endif /* CONFIG_SND_SUPPORT_OLD_API */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | |
Cliff Cai | 7003609 | 2008-09-03 10:54:36 +0200 | [diff] [blame] | 3414 | #ifndef CONFIG_MMU |
Daniel Glöckner | 55c63bd | 2010-03-09 12:57:52 -0500 | [diff] [blame] | 3415 | static unsigned long snd_pcm_get_unmapped_area(struct file *file, |
| 3416 | unsigned long addr, |
| 3417 | unsigned long len, |
| 3418 | unsigned long pgoff, |
| 3419 | unsigned long flags) |
Cliff Cai | 7003609 | 2008-09-03 10:54:36 +0200 | [diff] [blame] | 3420 | { |
Daniel Glöckner | 55c63bd | 2010-03-09 12:57:52 -0500 | [diff] [blame] | 3421 | struct snd_pcm_file *pcm_file = file->private_data; |
| 3422 | struct snd_pcm_substream *substream = pcm_file->substream; |
| 3423 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 3424 | unsigned long offset = pgoff << PAGE_SHIFT; |
| 3425 | |
| 3426 | switch (offset) { |
| 3427 | case SNDRV_PCM_MMAP_OFFSET_STATUS: |
| 3428 | return (unsigned long)runtime->status; |
| 3429 | case SNDRV_PCM_MMAP_OFFSET_CONTROL: |
| 3430 | return (unsigned long)runtime->control; |
| 3431 | default: |
| 3432 | return (unsigned long)runtime->dma_area + offset; |
| 3433 | } |
Cliff Cai | 7003609 | 2008-09-03 10:54:36 +0200 | [diff] [blame] | 3434 | } |
| 3435 | #else |
Daniel Glöckner | 55c63bd | 2010-03-09 12:57:52 -0500 | [diff] [blame] | 3436 | # define snd_pcm_get_unmapped_area NULL |
Cliff Cai | 7003609 | 2008-09-03 10:54:36 +0200 | [diff] [blame] | 3437 | #endif |
| 3438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3439 | /* |
| 3440 | * Register section |
| 3441 | */ |
| 3442 | |
Arjan van de Ven | 9c2e08c | 2007-02-12 00:55:37 -0800 | [diff] [blame] | 3443 | const struct file_operations snd_pcm_f_ops[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | { |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 3445 | .owner = THIS_MODULE, |
| 3446 | .write = snd_pcm_write, |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 3447 | .aio_write = snd_pcm_aio_write, |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 3448 | .open = snd_pcm_playback_open, |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 3449 | .release = snd_pcm_release, |
Takashi Iwai | 02f4865 | 2010-04-13 11:49:04 +0200 | [diff] [blame] | 3450 | .llseek = no_llseek, |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 3451 | .poll = snd_pcm_playback_poll, |
| 3452 | .unlocked_ioctl = snd_pcm_playback_ioctl, |
| 3453 | .compat_ioctl = snd_pcm_ioctl_compat, |
| 3454 | .mmap = snd_pcm_mmap, |
| 3455 | .fasync = snd_pcm_fasync, |
Daniel Glöckner | 55c63bd | 2010-03-09 12:57:52 -0500 | [diff] [blame] | 3456 | .get_unmapped_area = snd_pcm_get_unmapped_area, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | }, |
| 3458 | { |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 3459 | .owner = THIS_MODULE, |
| 3460 | .read = snd_pcm_read, |
Badari Pulavarty | ee0b3e6 | 2006-09-30 23:28:47 -0700 | [diff] [blame] | 3461 | .aio_read = snd_pcm_aio_read, |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 3462 | .open = snd_pcm_capture_open, |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 3463 | .release = snd_pcm_release, |
Takashi Iwai | 02f4865 | 2010-04-13 11:49:04 +0200 | [diff] [blame] | 3464 | .llseek = no_llseek, |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 3465 | .poll = snd_pcm_capture_poll, |
| 3466 | .unlocked_ioctl = snd_pcm_capture_ioctl, |
| 3467 | .compat_ioctl = snd_pcm_ioctl_compat, |
| 3468 | .mmap = snd_pcm_mmap, |
| 3469 | .fasync = snd_pcm_fasync, |
Daniel Glöckner | 55c63bd | 2010-03-09 12:57:52 -0500 | [diff] [blame] | 3470 | .get_unmapped_area = snd_pcm_get_unmapped_area, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | } |
| 3472 | }; |