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