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