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