2 * Digital Audio (PCM) abstract layer
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/file.h>
24 #include <linux/slab.h>
25 #include <linux/smp_lock.h>
26 #include <linux/time.h>
27 #include <linux/pm_qos_params.h>
28 #include <linux/uio.h>
29 #include <linux/dma-mapping.h>
30 #include <sound/core.h>
31 #include <sound/control.h>
32 #include <sound/info.h>
33 #include <sound/pcm.h>
34 #include <sound/pcm_params.h>
35 #include <sound/timer.h>
36 #include <sound/minors.h>
38 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
39 #include <dma-coherence.h>
46 struct snd_pcm_hw_params_old
{
48 unsigned int masks
[SNDRV_PCM_HW_PARAM_SUBFORMAT
-
49 SNDRV_PCM_HW_PARAM_ACCESS
+ 1];
50 struct snd_interval intervals
[SNDRV_PCM_HW_PARAM_TICK_TIME
-
51 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
+ 1];
56 unsigned int rate_num
;
57 unsigned int rate_den
;
58 snd_pcm_uframes_t fifo_size
;
59 unsigned char reserved
[64];
62 #ifdef CONFIG_SND_SUPPORT_OLD_API
63 #define SNDRV_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct snd_pcm_hw_params_old)
64 #define SNDRV_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct snd_pcm_hw_params_old)
66 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
67 struct snd_pcm_hw_params_old __user
* _oparams
);
68 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
69 struct snd_pcm_hw_params_old __user
* _oparams
);
71 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
);
77 DEFINE_RWLOCK(snd_pcm_link_rwlock
);
78 EXPORT_SYMBOL(snd_pcm_link_rwlock
);
80 static DECLARE_RWSEM(snd_pcm_link_rwsem
);
82 static inline mm_segment_t
snd_enter_user(void)
84 mm_segment_t fs
= get_fs();
89 static inline void snd_leave_user(mm_segment_t fs
)
96 int snd_pcm_info(struct snd_pcm_substream
*substream
, struct snd_pcm_info
*info
)
98 struct snd_pcm_runtime
*runtime
;
99 struct snd_pcm
*pcm
= substream
->pcm
;
100 struct snd_pcm_str
*pstr
= substream
->pstr
;
102 memset(info
, 0, sizeof(*info
));
103 info
->card
= pcm
->card
->number
;
104 info
->device
= pcm
->device
;
105 info
->stream
= substream
->stream
;
106 info
->subdevice
= substream
->number
;
107 strlcpy(info
->id
, pcm
->id
, sizeof(info
->id
));
108 strlcpy(info
->name
, pcm
->name
, sizeof(info
->name
));
109 info
->dev_class
= pcm
->dev_class
;
110 info
->dev_subclass
= pcm
->dev_subclass
;
111 info
->subdevices_count
= pstr
->substream_count
;
112 info
->subdevices_avail
= pstr
->substream_count
- pstr
->substream_opened
;
113 strlcpy(info
->subname
, substream
->name
, sizeof(info
->subname
));
114 runtime
= substream
->runtime
;
116 info
->sync
= runtime
->sync
;
117 substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_INFO
, info
);
122 int snd_pcm_info_user(struct snd_pcm_substream
*substream
,
123 struct snd_pcm_info __user
* _info
)
125 struct snd_pcm_info
*info
;
128 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
131 err
= snd_pcm_info(substream
, info
);
133 if (copy_to_user(_info
, info
, sizeof(*info
)))
143 #define HW_PARAM(v) [SNDRV_PCM_HW_PARAM_##v] = #v
144 char *snd_pcm_hw_param_names
[] = {
148 HW_PARAM(SAMPLE_BITS
),
149 HW_PARAM(FRAME_BITS
),
152 HW_PARAM(PERIOD_TIME
),
153 HW_PARAM(PERIOD_SIZE
),
154 HW_PARAM(PERIOD_BYTES
),
156 HW_PARAM(BUFFER_TIME
),
157 HW_PARAM(BUFFER_SIZE
),
158 HW_PARAM(BUFFER_BYTES
),
163 int snd_pcm_hw_refine(struct snd_pcm_substream
*substream
,
164 struct snd_pcm_hw_params
*params
)
167 struct snd_pcm_hardware
*hw
;
168 struct snd_interval
*i
= NULL
;
169 struct snd_mask
*m
= NULL
;
170 struct snd_pcm_hw_constraints
*constrs
= &substream
->runtime
->hw_constraints
;
171 unsigned int rstamps
[constrs
->rules_num
];
172 unsigned int vstamps
[SNDRV_PCM_HW_PARAM_LAST_INTERVAL
+ 1];
173 unsigned int stamp
= 2;
177 params
->fifo_size
= 0;
178 if (params
->rmask
& (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS
))
180 if (params
->rmask
& (1 << SNDRV_PCM_HW_PARAM_RATE
)) {
181 params
->rate_num
= 0;
182 params
->rate_den
= 0;
185 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
186 m
= hw_param_mask(params
, k
);
187 if (snd_mask_empty(m
))
189 if (!(params
->rmask
& (1 << k
)))
192 printk(KERN_DEBUG
"%s = ", snd_pcm_hw_param_names
[k
]);
193 printk("%04x%04x%04x%04x -> ", m
->bits
[3], m
->bits
[2], m
->bits
[1], m
->bits
[0]);
195 changed
= snd_mask_refine(m
, constrs_mask(constrs
, k
));
197 printk("%04x%04x%04x%04x\n", m
->bits
[3], m
->bits
[2], m
->bits
[1], m
->bits
[0]);
200 params
->cmask
|= 1 << k
;
205 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
206 i
= hw_param_interval(params
, k
);
207 if (snd_interval_empty(i
))
209 if (!(params
->rmask
& (1 << k
)))
212 printk(KERN_DEBUG
"%s = ", snd_pcm_hw_param_names
[k
]);
217 i
->openmin
? '(' : '[', i
->min
,
218 i
->max
, i
->openmax
? ')' : ']');
221 changed
= snd_interval_refine(i
, constrs_interval(constrs
, k
));
226 printk("%c%u %u%c\n",
227 i
->openmin
? '(' : '[', i
->min
,
228 i
->max
, i
->openmax
? ')' : ']');
231 params
->cmask
|= 1 << k
;
236 for (k
= 0; k
< constrs
->rules_num
; k
++)
238 for (k
= 0; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++)
239 vstamps
[k
] = (params
->rmask
& (1 << k
)) ? 1 : 0;
242 for (k
= 0; k
< constrs
->rules_num
; k
++) {
243 struct snd_pcm_hw_rule
*r
= &constrs
->rules
[k
];
246 if (r
->cond
&& !(r
->cond
& params
->flags
))
248 for (d
= 0; r
->deps
[d
] >= 0; d
++) {
249 if (vstamps
[r
->deps
[d
]] > rstamps
[k
]) {
257 printk(KERN_DEBUG
"Rule %d [%p]: ", k
, r
->func
);
259 printk("%s = ", snd_pcm_hw_param_names
[r
->var
]);
260 if (hw_is_mask(r
->var
)) {
261 m
= hw_param_mask(params
, r
->var
);
262 printk("%x", *m
->bits
);
264 i
= hw_param_interval(params
, r
->var
);
269 i
->openmin
? '(' : '[', i
->min
,
270 i
->max
, i
->openmax
? ')' : ']');
274 changed
= r
->func(params
, r
);
278 if (hw_is_mask(r
->var
))
279 printk("%x", *m
->bits
);
285 i
->openmin
? '(' : '[', i
->min
,
286 i
->max
, i
->openmax
? ')' : ']');
292 if (changed
&& r
->var
>= 0) {
293 params
->cmask
|= (1 << r
->var
);
294 vstamps
[r
->var
] = stamp
;
302 if (!params
->msbits
) {
303 i
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
);
304 if (snd_interval_single(i
))
305 params
->msbits
= snd_interval_value(i
);
308 if (!params
->rate_den
) {
309 i
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
310 if (snd_interval_single(i
)) {
311 params
->rate_num
= snd_interval_value(i
);
312 params
->rate_den
= 1;
316 hw
= &substream
->runtime
->hw
;
318 params
->info
= hw
->info
& ~SNDRV_PCM_INFO_FIFO_IN_FRAMES
;
319 if (!params
->fifo_size
) {
320 m
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
321 i
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
322 if (snd_mask_min(m
) == snd_mask_max(m
) &&
323 snd_interval_min(i
) == snd_interval_max(i
)) {
324 changed
= substream
->ops
->ioctl(substream
,
325 SNDRV_PCM_IOCTL1_FIFO_SIZE
, params
);
334 EXPORT_SYMBOL(snd_pcm_hw_refine
);
336 static int snd_pcm_hw_refine_user(struct snd_pcm_substream
*substream
,
337 struct snd_pcm_hw_params __user
* _params
)
339 struct snd_pcm_hw_params
*params
;
342 params
= memdup_user(_params
, sizeof(*params
));
344 return PTR_ERR(params
);
346 err
= snd_pcm_hw_refine(substream
, params
);
347 if (copy_to_user(_params
, params
, sizeof(*params
))) {
356 static int period_to_usecs(struct snd_pcm_runtime
*runtime
)
361 return -1; /* invalid */
363 /* take 75% of period time as the deadline */
364 usecs
= (750000 / runtime
->rate
) * runtime
->period_size
;
365 usecs
+= ((750000 % runtime
->rate
) * runtime
->period_size
) /
371 static int snd_pcm_hw_params(struct snd_pcm_substream
*substream
,
372 struct snd_pcm_hw_params
*params
)
374 struct snd_pcm_runtime
*runtime
;
377 snd_pcm_uframes_t frames
;
379 if (PCM_RUNTIME_CHECK(substream
))
381 runtime
= substream
->runtime
;
382 snd_pcm_stream_lock_irq(substream
);
383 switch (runtime
->status
->state
) {
384 case SNDRV_PCM_STATE_OPEN
:
385 case SNDRV_PCM_STATE_SETUP
:
386 case SNDRV_PCM_STATE_PREPARED
:
389 snd_pcm_stream_unlock_irq(substream
);
392 snd_pcm_stream_unlock_irq(substream
);
393 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
394 if (!substream
->oss
.oss
)
396 if (atomic_read(&substream
->mmap_count
))
400 err
= snd_pcm_hw_refine(substream
, params
);
404 err
= snd_pcm_hw_params_choose(substream
, params
);
408 if (substream
->ops
->hw_params
!= NULL
) {
409 err
= substream
->ops
->hw_params(substream
, params
);
414 runtime
->access
= params_access(params
);
415 runtime
->format
= params_format(params
);
416 runtime
->subformat
= params_subformat(params
);
417 runtime
->channels
= params_channels(params
);
418 runtime
->rate
= params_rate(params
);
419 runtime
->period_size
= params_period_size(params
);
420 runtime
->periods
= params_periods(params
);
421 runtime
->buffer_size
= params_buffer_size(params
);
422 runtime
->info
= params
->info
;
423 runtime
->rate_num
= params
->rate_num
;
424 runtime
->rate_den
= params
->rate_den
;
426 bits
= snd_pcm_format_physical_width(runtime
->format
);
427 runtime
->sample_bits
= bits
;
428 bits
*= runtime
->channels
;
429 runtime
->frame_bits
= bits
;
431 while (bits
% 8 != 0) {
435 runtime
->byte_align
= bits
/ 8;
436 runtime
->min_align
= frames
;
438 /* Default sw params */
439 runtime
->tstamp_mode
= SNDRV_PCM_TSTAMP_NONE
;
440 runtime
->period_step
= 1;
441 runtime
->control
->avail_min
= runtime
->period_size
;
442 runtime
->start_threshold
= 1;
443 runtime
->stop_threshold
= runtime
->buffer_size
;
444 runtime
->silence_threshold
= 0;
445 runtime
->silence_size
= 0;
446 runtime
->boundary
= runtime
->buffer_size
;
447 while (runtime
->boundary
* 2 <= LONG_MAX
- runtime
->buffer_size
)
448 runtime
->boundary
*= 2;
450 snd_pcm_timer_resolution_change(substream
);
451 runtime
->status
->state
= SNDRV_PCM_STATE_SETUP
;
453 if (pm_qos_request_active(&substream
->latency_pm_qos_req
))
454 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
455 if ((usecs
= period_to_usecs(runtime
)) >= 0)
456 pm_qos_add_request(&substream
->latency_pm_qos_req
,
457 PM_QOS_CPU_DMA_LATENCY
, usecs
);
460 /* hardware might be unuseable from this time,
461 so we force application to retry to set
462 the correct hardware parameter settings */
463 runtime
->status
->state
= SNDRV_PCM_STATE_OPEN
;
464 if (substream
->ops
->hw_free
!= NULL
)
465 substream
->ops
->hw_free(substream
);
469 static int snd_pcm_hw_params_user(struct snd_pcm_substream
*substream
,
470 struct snd_pcm_hw_params __user
* _params
)
472 struct snd_pcm_hw_params
*params
;
475 params
= memdup_user(_params
, sizeof(*params
));
477 return PTR_ERR(params
);
479 err
= snd_pcm_hw_params(substream
, params
);
480 if (copy_to_user(_params
, params
, sizeof(*params
))) {
489 static int snd_pcm_hw_free(struct snd_pcm_substream
*substream
)
491 struct snd_pcm_runtime
*runtime
;
494 if (PCM_RUNTIME_CHECK(substream
))
496 runtime
= substream
->runtime
;
497 snd_pcm_stream_lock_irq(substream
);
498 switch (runtime
->status
->state
) {
499 case SNDRV_PCM_STATE_SETUP
:
500 case SNDRV_PCM_STATE_PREPARED
:
503 snd_pcm_stream_unlock_irq(substream
);
506 snd_pcm_stream_unlock_irq(substream
);
507 if (atomic_read(&substream
->mmap_count
))
509 if (substream
->ops
->hw_free
)
510 result
= substream
->ops
->hw_free(substream
);
511 runtime
->status
->state
= SNDRV_PCM_STATE_OPEN
;
512 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
516 static int snd_pcm_sw_params(struct snd_pcm_substream
*substream
,
517 struct snd_pcm_sw_params
*params
)
519 struct snd_pcm_runtime
*runtime
;
522 if (PCM_RUNTIME_CHECK(substream
))
524 runtime
= substream
->runtime
;
525 snd_pcm_stream_lock_irq(substream
);
526 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
) {
527 snd_pcm_stream_unlock_irq(substream
);
530 snd_pcm_stream_unlock_irq(substream
);
532 if (params
->tstamp_mode
> SNDRV_PCM_TSTAMP_LAST
)
534 if (params
->avail_min
== 0)
536 if (params
->silence_size
>= runtime
->boundary
) {
537 if (params
->silence_threshold
!= 0)
540 if (params
->silence_size
> params
->silence_threshold
)
542 if (params
->silence_threshold
> runtime
->buffer_size
)
546 snd_pcm_stream_lock_irq(substream
);
547 runtime
->tstamp_mode
= params
->tstamp_mode
;
548 runtime
->period_step
= params
->period_step
;
549 runtime
->control
->avail_min
= params
->avail_min
;
550 runtime
->start_threshold
= params
->start_threshold
;
551 runtime
->stop_threshold
= params
->stop_threshold
;
552 runtime
->silence_threshold
= params
->silence_threshold
;
553 runtime
->silence_size
= params
->silence_size
;
554 params
->boundary
= runtime
->boundary
;
555 if (snd_pcm_running(substream
)) {
556 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
557 runtime
->silence_size
> 0)
558 snd_pcm_playback_silence(substream
, ULONG_MAX
);
559 err
= snd_pcm_update_state(substream
, runtime
);
561 snd_pcm_stream_unlock_irq(substream
);
565 static int snd_pcm_sw_params_user(struct snd_pcm_substream
*substream
,
566 struct snd_pcm_sw_params __user
* _params
)
568 struct snd_pcm_sw_params params
;
570 if (copy_from_user(¶ms
, _params
, sizeof(params
)))
572 err
= snd_pcm_sw_params(substream
, ¶ms
);
573 if (copy_to_user(_params
, ¶ms
, sizeof(params
)))
578 int snd_pcm_status(struct snd_pcm_substream
*substream
,
579 struct snd_pcm_status
*status
)
581 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
583 snd_pcm_stream_lock_irq(substream
);
584 status
->state
= runtime
->status
->state
;
585 status
->suspended_state
= runtime
->status
->suspended_state
;
586 if (status
->state
== SNDRV_PCM_STATE_OPEN
)
588 status
->trigger_tstamp
= runtime
->trigger_tstamp
;
589 if (snd_pcm_running(substream
)) {
590 snd_pcm_update_hw_ptr(substream
);
591 if (runtime
->tstamp_mode
== SNDRV_PCM_TSTAMP_ENABLE
) {
592 status
->tstamp
= runtime
->status
->tstamp
;
596 snd_pcm_gettime(runtime
, &status
->tstamp
);
598 status
->appl_ptr
= runtime
->control
->appl_ptr
;
599 status
->hw_ptr
= runtime
->status
->hw_ptr
;
600 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
601 status
->avail
= snd_pcm_playback_avail(runtime
);
602 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
||
603 runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
604 status
->delay
= runtime
->buffer_size
- status
->avail
;
605 status
->delay
+= runtime
->delay
;
609 status
->avail
= snd_pcm_capture_avail(runtime
);
610 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
)
611 status
->delay
= status
->avail
+ runtime
->delay
;
615 status
->avail_max
= runtime
->avail_max
;
616 status
->overrange
= runtime
->overrange
;
617 runtime
->avail_max
= 0;
618 runtime
->overrange
= 0;
620 snd_pcm_stream_unlock_irq(substream
);
624 static int snd_pcm_status_user(struct snd_pcm_substream
*substream
,
625 struct snd_pcm_status __user
* _status
)
627 struct snd_pcm_status status
;
630 memset(&status
, 0, sizeof(status
));
631 res
= snd_pcm_status(substream
, &status
);
634 if (copy_to_user(_status
, &status
, sizeof(status
)))
639 static int snd_pcm_channel_info(struct snd_pcm_substream
*substream
,
640 struct snd_pcm_channel_info
* info
)
642 struct snd_pcm_runtime
*runtime
;
643 unsigned int channel
;
645 channel
= info
->channel
;
646 runtime
= substream
->runtime
;
647 snd_pcm_stream_lock_irq(substream
);
648 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
) {
649 snd_pcm_stream_unlock_irq(substream
);
652 snd_pcm_stream_unlock_irq(substream
);
653 if (channel
>= runtime
->channels
)
655 memset(info
, 0, sizeof(*info
));
656 info
->channel
= channel
;
657 return substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_CHANNEL_INFO
, info
);
660 static int snd_pcm_channel_info_user(struct snd_pcm_substream
*substream
,
661 struct snd_pcm_channel_info __user
* _info
)
663 struct snd_pcm_channel_info info
;
666 if (copy_from_user(&info
, _info
, sizeof(info
)))
668 res
= snd_pcm_channel_info(substream
, &info
);
671 if (copy_to_user(_info
, &info
, sizeof(info
)))
676 static void snd_pcm_trigger_tstamp(struct snd_pcm_substream
*substream
)
678 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
679 if (runtime
->trigger_master
== NULL
)
681 if (runtime
->trigger_master
== substream
) {
682 snd_pcm_gettime(runtime
, &runtime
->trigger_tstamp
);
684 snd_pcm_trigger_tstamp(runtime
->trigger_master
);
685 runtime
->trigger_tstamp
= runtime
->trigger_master
->runtime
->trigger_tstamp
;
687 runtime
->trigger_master
= NULL
;
691 int (*pre_action
)(struct snd_pcm_substream
*substream
, int state
);
692 int (*do_action
)(struct snd_pcm_substream
*substream
, int state
);
693 void (*undo_action
)(struct snd_pcm_substream
*substream
, int state
);
694 void (*post_action
)(struct snd_pcm_substream
*substream
, int state
);
698 * this functions is core for handling of linked stream
699 * Note: the stream state might be changed also on failure
700 * Note2: call with calling stream lock + link lock
702 static int snd_pcm_action_group(struct action_ops
*ops
,
703 struct snd_pcm_substream
*substream
,
704 int state
, int do_lock
)
706 struct snd_pcm_substream
*s
= NULL
;
707 struct snd_pcm_substream
*s1
;
710 snd_pcm_group_for_each_entry(s
, substream
) {
711 if (do_lock
&& s
!= substream
)
712 spin_lock_nested(&s
->self_group
.lock
,
713 SINGLE_DEPTH_NESTING
);
714 res
= ops
->pre_action(s
, state
);
718 snd_pcm_group_for_each_entry(s
, substream
) {
719 res
= ops
->do_action(s
, state
);
721 if (ops
->undo_action
) {
722 snd_pcm_group_for_each_entry(s1
, substream
) {
723 if (s1
== s
) /* failed stream */
725 ops
->undo_action(s1
, state
);
728 s
= NULL
; /* unlock all */
732 snd_pcm_group_for_each_entry(s
, substream
) {
733 ops
->post_action(s
, state
);
738 snd_pcm_group_for_each_entry(s1
, substream
) {
740 spin_unlock(&s1
->self_group
.lock
);
741 if (s1
== s
) /* end */
749 * Note: call with stream lock
751 static int snd_pcm_action_single(struct action_ops
*ops
,
752 struct snd_pcm_substream
*substream
,
757 res
= ops
->pre_action(substream
, state
);
760 res
= ops
->do_action(substream
, state
);
762 ops
->post_action(substream
, state
);
763 else if (ops
->undo_action
)
764 ops
->undo_action(substream
, state
);
769 * Note: call with stream lock
771 static int snd_pcm_action(struct action_ops
*ops
,
772 struct snd_pcm_substream
*substream
,
777 if (snd_pcm_stream_linked(substream
)) {
778 if (!spin_trylock(&substream
->group
->lock
)) {
779 spin_unlock(&substream
->self_group
.lock
);
780 spin_lock(&substream
->group
->lock
);
781 spin_lock(&substream
->self_group
.lock
);
783 res
= snd_pcm_action_group(ops
, substream
, state
, 1);
784 spin_unlock(&substream
->group
->lock
);
786 res
= snd_pcm_action_single(ops
, substream
, state
);
792 * Note: don't use any locks before
794 static int snd_pcm_action_lock_irq(struct action_ops
*ops
,
795 struct snd_pcm_substream
*substream
,
800 read_lock_irq(&snd_pcm_link_rwlock
);
801 if (snd_pcm_stream_linked(substream
)) {
802 spin_lock(&substream
->group
->lock
);
803 spin_lock(&substream
->self_group
.lock
);
804 res
= snd_pcm_action_group(ops
, substream
, state
, 1);
805 spin_unlock(&substream
->self_group
.lock
);
806 spin_unlock(&substream
->group
->lock
);
808 spin_lock(&substream
->self_group
.lock
);
809 res
= snd_pcm_action_single(ops
, substream
, state
);
810 spin_unlock(&substream
->self_group
.lock
);
812 read_unlock_irq(&snd_pcm_link_rwlock
);
818 static int snd_pcm_action_nonatomic(struct action_ops
*ops
,
819 struct snd_pcm_substream
*substream
,
824 down_read(&snd_pcm_link_rwsem
);
825 if (snd_pcm_stream_linked(substream
))
826 res
= snd_pcm_action_group(ops
, substream
, state
, 0);
828 res
= snd_pcm_action_single(ops
, substream
, state
);
829 up_read(&snd_pcm_link_rwsem
);
836 static int snd_pcm_pre_start(struct snd_pcm_substream
*substream
, int state
)
838 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
839 if (runtime
->status
->state
!= SNDRV_PCM_STATE_PREPARED
)
841 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
842 !snd_pcm_playback_data(substream
))
844 runtime
->trigger_master
= substream
;
848 static int snd_pcm_do_start(struct snd_pcm_substream
*substream
, int state
)
850 if (substream
->runtime
->trigger_master
!= substream
)
852 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_START
);
855 static void snd_pcm_undo_start(struct snd_pcm_substream
*substream
, int state
)
857 if (substream
->runtime
->trigger_master
== substream
)
858 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
861 static void snd_pcm_post_start(struct snd_pcm_substream
*substream
, int state
)
863 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
864 snd_pcm_trigger_tstamp(substream
);
865 runtime
->hw_ptr_jiffies
= jiffies
;
866 runtime
->status
->state
= state
;
867 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
868 runtime
->silence_size
> 0)
869 snd_pcm_playback_silence(substream
, ULONG_MAX
);
870 if (substream
->timer
)
871 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTART
,
872 &runtime
->trigger_tstamp
);
875 static struct action_ops snd_pcm_action_start
= {
876 .pre_action
= snd_pcm_pre_start
,
877 .do_action
= snd_pcm_do_start
,
878 .undo_action
= snd_pcm_undo_start
,
879 .post_action
= snd_pcm_post_start
883 * snd_pcm_start - start all linked streams
884 * @substream: the PCM substream instance
886 int snd_pcm_start(struct snd_pcm_substream
*substream
)
888 return snd_pcm_action(&snd_pcm_action_start
, substream
,
889 SNDRV_PCM_STATE_RUNNING
);
895 static int snd_pcm_pre_stop(struct snd_pcm_substream
*substream
, int state
)
897 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
898 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
900 runtime
->trigger_master
= substream
;
904 static int snd_pcm_do_stop(struct snd_pcm_substream
*substream
, int state
)
906 if (substream
->runtime
->trigger_master
== substream
&&
907 snd_pcm_running(substream
))
908 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
909 return 0; /* unconditonally stop all substreams */
912 static void snd_pcm_post_stop(struct snd_pcm_substream
*substream
, int state
)
914 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
915 if (runtime
->status
->state
!= state
) {
916 snd_pcm_trigger_tstamp(substream
);
917 if (substream
->timer
)
918 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTOP
,
919 &runtime
->trigger_tstamp
);
920 runtime
->status
->state
= state
;
922 wake_up(&runtime
->sleep
);
923 wake_up(&runtime
->tsleep
);
926 static struct action_ops snd_pcm_action_stop
= {
927 .pre_action
= snd_pcm_pre_stop
,
928 .do_action
= snd_pcm_do_stop
,
929 .post_action
= snd_pcm_post_stop
933 * snd_pcm_stop - try to stop all running streams in the substream group
934 * @substream: the PCM substream instance
935 * @state: PCM state after stopping the stream
937 * The state of each stream is then changed to the given state unconditionally.
939 int snd_pcm_stop(struct snd_pcm_substream
*substream
, int state
)
941 return snd_pcm_action(&snd_pcm_action_stop
, substream
, state
);
944 EXPORT_SYMBOL(snd_pcm_stop
);
947 * snd_pcm_drain_done - stop the DMA only when the given stream is playback
948 * @substream: the PCM substream
950 * After stopping, the state is changed to SETUP.
951 * Unlike snd_pcm_stop(), this affects only the given stream.
953 int snd_pcm_drain_done(struct snd_pcm_substream
*substream
)
955 return snd_pcm_action_single(&snd_pcm_action_stop
, substream
,
956 SNDRV_PCM_STATE_SETUP
);
962 static int snd_pcm_pre_pause(struct snd_pcm_substream
*substream
, int push
)
964 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
965 if (!(runtime
->info
& SNDRV_PCM_INFO_PAUSE
))
968 if (runtime
->status
->state
!= SNDRV_PCM_STATE_RUNNING
)
970 } else if (runtime
->status
->state
!= SNDRV_PCM_STATE_PAUSED
)
972 runtime
->trigger_master
= substream
;
976 static int snd_pcm_do_pause(struct snd_pcm_substream
*substream
, int push
)
978 if (substream
->runtime
->trigger_master
!= substream
)
980 /* some drivers might use hw_ptr to recover from the pause -
981 update the hw_ptr now */
983 snd_pcm_update_hw_ptr(substream
);
984 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
985 * a delta betwen the current jiffies, this gives a large enough
986 * delta, effectively to skip the check once.
988 substream
->runtime
->hw_ptr_jiffies
= jiffies
- HZ
* 1000;
989 return substream
->ops
->trigger(substream
,
990 push
? SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
991 SNDRV_PCM_TRIGGER_PAUSE_RELEASE
);
994 static void snd_pcm_undo_pause(struct snd_pcm_substream
*substream
, int push
)
996 if (substream
->runtime
->trigger_master
== substream
)
997 substream
->ops
->trigger(substream
,
998 push
? SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
999 SNDRV_PCM_TRIGGER_PAUSE_PUSH
);
1002 static void snd_pcm_post_pause(struct snd_pcm_substream
*substream
, int push
)
1004 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1005 snd_pcm_trigger_tstamp(substream
);
1007 runtime
->status
->state
= SNDRV_PCM_STATE_PAUSED
;
1008 if (substream
->timer
)
1009 snd_timer_notify(substream
->timer
,
1010 SNDRV_TIMER_EVENT_MPAUSE
,
1011 &runtime
->trigger_tstamp
);
1012 wake_up(&runtime
->sleep
);
1013 wake_up(&runtime
->tsleep
);
1015 runtime
->status
->state
= SNDRV_PCM_STATE_RUNNING
;
1016 if (substream
->timer
)
1017 snd_timer_notify(substream
->timer
,
1018 SNDRV_TIMER_EVENT_MCONTINUE
,
1019 &runtime
->trigger_tstamp
);
1023 static struct action_ops snd_pcm_action_pause
= {
1024 .pre_action
= snd_pcm_pre_pause
,
1025 .do_action
= snd_pcm_do_pause
,
1026 .undo_action
= snd_pcm_undo_pause
,
1027 .post_action
= snd_pcm_post_pause
1031 * Push/release the pause for all linked streams.
1033 static int snd_pcm_pause(struct snd_pcm_substream
*substream
, int push
)
1035 return snd_pcm_action(&snd_pcm_action_pause
, substream
, push
);
1041 static int snd_pcm_pre_suspend(struct snd_pcm_substream
*substream
, int state
)
1043 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1044 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1046 runtime
->trigger_master
= substream
;
1050 static int snd_pcm_do_suspend(struct snd_pcm_substream
*substream
, int state
)
1052 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1053 if (runtime
->trigger_master
!= substream
)
1055 if (! snd_pcm_running(substream
))
1057 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1058 return 0; /* suspend unconditionally */
1061 static void snd_pcm_post_suspend(struct snd_pcm_substream
*substream
, int state
)
1063 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1064 snd_pcm_trigger_tstamp(substream
);
1065 if (substream
->timer
)
1066 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSUSPEND
,
1067 &runtime
->trigger_tstamp
);
1068 runtime
->status
->suspended_state
= runtime
->status
->state
;
1069 runtime
->status
->state
= SNDRV_PCM_STATE_SUSPENDED
;
1070 wake_up(&runtime
->sleep
);
1071 wake_up(&runtime
->tsleep
);
1074 static struct action_ops snd_pcm_action_suspend
= {
1075 .pre_action
= snd_pcm_pre_suspend
,
1076 .do_action
= snd_pcm_do_suspend
,
1077 .post_action
= snd_pcm_post_suspend
1081 * snd_pcm_suspend - trigger SUSPEND to all linked streams
1082 * @substream: the PCM substream
1084 * After this call, all streams are changed to SUSPENDED state.
1086 int snd_pcm_suspend(struct snd_pcm_substream
*substream
)
1089 unsigned long flags
;
1094 snd_pcm_stream_lock_irqsave(substream
, flags
);
1095 err
= snd_pcm_action(&snd_pcm_action_suspend
, substream
, 0);
1096 snd_pcm_stream_unlock_irqrestore(substream
, flags
);
1100 EXPORT_SYMBOL(snd_pcm_suspend
);
1103 * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm
1104 * @pcm: the PCM instance
1106 * After this call, all streams are changed to SUSPENDED state.
1108 int snd_pcm_suspend_all(struct snd_pcm
*pcm
)
1110 struct snd_pcm_substream
*substream
;
1111 int stream
, err
= 0;
1116 for (stream
= 0; stream
< 2; stream
++) {
1117 for (substream
= pcm
->streams
[stream
].substream
;
1118 substream
; substream
= substream
->next
) {
1119 if (substream
->runtime
== NULL
)
1121 err
= snd_pcm_suspend(substream
);
1122 if (err
< 0 && err
!= -EBUSY
)
1129 EXPORT_SYMBOL(snd_pcm_suspend_all
);
1133 static int snd_pcm_pre_resume(struct snd_pcm_substream
*substream
, int state
)
1135 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1136 if (!(runtime
->info
& SNDRV_PCM_INFO_RESUME
))
1138 runtime
->trigger_master
= substream
;
1142 static int snd_pcm_do_resume(struct snd_pcm_substream
*substream
, int state
)
1144 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1145 if (runtime
->trigger_master
!= substream
)
1147 /* DMA not running previously? */
1148 if (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_RUNNING
&&
1149 (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_DRAINING
||
1150 substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
1152 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_RESUME
);
1155 static void snd_pcm_undo_resume(struct snd_pcm_substream
*substream
, int state
)
1157 if (substream
->runtime
->trigger_master
== substream
&&
1158 snd_pcm_running(substream
))
1159 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1162 static void snd_pcm_post_resume(struct snd_pcm_substream
*substream
, int state
)
1164 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1165 snd_pcm_trigger_tstamp(substream
);
1166 if (substream
->timer
)
1167 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MRESUME
,
1168 &runtime
->trigger_tstamp
);
1169 runtime
->status
->state
= runtime
->status
->suspended_state
;
1172 static struct action_ops snd_pcm_action_resume
= {
1173 .pre_action
= snd_pcm_pre_resume
,
1174 .do_action
= snd_pcm_do_resume
,
1175 .undo_action
= snd_pcm_undo_resume
,
1176 .post_action
= snd_pcm_post_resume
1179 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1181 struct snd_card
*card
= substream
->pcm
->card
;
1184 snd_power_lock(card
);
1185 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1186 res
= snd_pcm_action_lock_irq(&snd_pcm_action_resume
, substream
, 0);
1187 snd_power_unlock(card
);
1193 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1198 #endif /* CONFIG_PM */
1203 * Change the RUNNING stream(s) to XRUN state.
1205 static int snd_pcm_xrun(struct snd_pcm_substream
*substream
)
1207 struct snd_card
*card
= substream
->pcm
->card
;
1208 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1211 snd_power_lock(card
);
1212 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1213 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1218 snd_pcm_stream_lock_irq(substream
);
1219 switch (runtime
->status
->state
) {
1220 case SNDRV_PCM_STATE_XRUN
:
1221 result
= 0; /* already there */
1223 case SNDRV_PCM_STATE_RUNNING
:
1224 result
= snd_pcm_stop(substream
, SNDRV_PCM_STATE_XRUN
);
1229 snd_pcm_stream_unlock_irq(substream
);
1231 snd_power_unlock(card
);
1238 static int snd_pcm_pre_reset(struct snd_pcm_substream
*substream
, int state
)
1240 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1241 switch (runtime
->status
->state
) {
1242 case SNDRV_PCM_STATE_RUNNING
:
1243 case SNDRV_PCM_STATE_PREPARED
:
1244 case SNDRV_PCM_STATE_PAUSED
:
1245 case SNDRV_PCM_STATE_SUSPENDED
:
1252 static int snd_pcm_do_reset(struct snd_pcm_substream
*substream
, int state
)
1254 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1255 int err
= substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_RESET
, NULL
);
1258 runtime
->hw_ptr_base
= 0;
1259 runtime
->hw_ptr_interrupt
= runtime
->status
->hw_ptr
-
1260 runtime
->status
->hw_ptr
% runtime
->period_size
;
1261 runtime
->silence_start
= runtime
->status
->hw_ptr
;
1262 runtime
->silence_filled
= 0;
1266 static void snd_pcm_post_reset(struct snd_pcm_substream
*substream
, int state
)
1268 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1269 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1270 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
1271 runtime
->silence_size
> 0)
1272 snd_pcm_playback_silence(substream
, ULONG_MAX
);
1275 static struct action_ops snd_pcm_action_reset
= {
1276 .pre_action
= snd_pcm_pre_reset
,
1277 .do_action
= snd_pcm_do_reset
,
1278 .post_action
= snd_pcm_post_reset
1281 static int snd_pcm_reset(struct snd_pcm_substream
*substream
)
1283 return snd_pcm_action_nonatomic(&snd_pcm_action_reset
, substream
, 0);
1289 /* we use the second argument for updating f_flags */
1290 static int snd_pcm_pre_prepare(struct snd_pcm_substream
*substream
,
1293 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1294 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1295 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
)
1297 if (snd_pcm_running(substream
))
1299 substream
->f_flags
= f_flags
;
1303 static int snd_pcm_do_prepare(struct snd_pcm_substream
*substream
, int state
)
1306 err
= substream
->ops
->prepare(substream
);
1309 return snd_pcm_do_reset(substream
, 0);
1312 static void snd_pcm_post_prepare(struct snd_pcm_substream
*substream
, int state
)
1314 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1315 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1316 runtime
->status
->state
= SNDRV_PCM_STATE_PREPARED
;
1319 static struct action_ops snd_pcm_action_prepare
= {
1320 .pre_action
= snd_pcm_pre_prepare
,
1321 .do_action
= snd_pcm_do_prepare
,
1322 .post_action
= snd_pcm_post_prepare
1326 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1327 * @substream: the PCM substream instance
1328 * @file: file to refer f_flags
1330 static int snd_pcm_prepare(struct snd_pcm_substream
*substream
,
1334 struct snd_card
*card
= substream
->pcm
->card
;
1338 f_flags
= file
->f_flags
;
1340 f_flags
= substream
->f_flags
;
1342 snd_power_lock(card
);
1343 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1344 res
= snd_pcm_action_nonatomic(&snd_pcm_action_prepare
,
1345 substream
, f_flags
);
1346 snd_power_unlock(card
);
1354 static int snd_pcm_pre_drain_init(struct snd_pcm_substream
*substream
, int state
)
1356 substream
->runtime
->trigger_master
= substream
;
1360 static int snd_pcm_do_drain_init(struct snd_pcm_substream
*substream
, int state
)
1362 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1363 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1364 switch (runtime
->status
->state
) {
1365 case SNDRV_PCM_STATE_PREPARED
:
1366 /* start playback stream if possible */
1367 if (! snd_pcm_playback_empty(substream
)) {
1368 snd_pcm_do_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1369 snd_pcm_post_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1372 case SNDRV_PCM_STATE_RUNNING
:
1373 runtime
->status
->state
= SNDRV_PCM_STATE_DRAINING
;
1379 /* stop running stream */
1380 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
) {
1381 int new_state
= snd_pcm_capture_avail(runtime
) > 0 ?
1382 SNDRV_PCM_STATE_DRAINING
: SNDRV_PCM_STATE_SETUP
;
1383 snd_pcm_do_stop(substream
, new_state
);
1384 snd_pcm_post_stop(substream
, new_state
);
1390 static void snd_pcm_post_drain_init(struct snd_pcm_substream
*substream
, int state
)
1394 static struct action_ops snd_pcm_action_drain_init
= {
1395 .pre_action
= snd_pcm_pre_drain_init
,
1396 .do_action
= snd_pcm_do_drain_init
,
1397 .post_action
= snd_pcm_post_drain_init
1400 static int snd_pcm_drop(struct snd_pcm_substream
*substream
);
1403 * Drain the stream(s).
1404 * When the substream is linked, sync until the draining of all playback streams
1406 * After this call, all streams are supposed to be either SETUP or DRAINING
1407 * (capture only) state.
1409 static int snd_pcm_drain(struct snd_pcm_substream
*substream
,
1412 struct snd_card
*card
;
1413 struct snd_pcm_runtime
*runtime
;
1414 struct snd_pcm_substream
*s
;
1419 card
= substream
->pcm
->card
;
1420 runtime
= substream
->runtime
;
1422 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
1425 snd_power_lock(card
);
1426 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1427 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1429 snd_power_unlock(card
);
1435 if (file
->f_flags
& O_NONBLOCK
)
1437 } else if (substream
->f_flags
& O_NONBLOCK
)
1440 down_read(&snd_pcm_link_rwsem
);
1441 snd_pcm_stream_lock_irq(substream
);
1443 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1444 snd_pcm_pause(substream
, 0);
1446 /* pre-start/stop - all running streams are changed to DRAINING state */
1447 result
= snd_pcm_action(&snd_pcm_action_drain_init
, substream
, 0);
1450 /* in non-blocking, we don't wait in ioctl but let caller poll */
1458 struct snd_pcm_runtime
*to_check
;
1459 if (signal_pending(current
)) {
1460 result
= -ERESTARTSYS
;
1463 /* find a substream to drain */
1465 snd_pcm_group_for_each_entry(s
, substream
) {
1466 if (s
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1468 runtime
= s
->runtime
;
1469 if (runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
1475 break; /* all drained */
1476 init_waitqueue_entry(&wait
, current
);
1477 add_wait_queue(&to_check
->sleep
, &wait
);
1478 set_current_state(TASK_INTERRUPTIBLE
);
1479 snd_pcm_stream_unlock_irq(substream
);
1480 up_read(&snd_pcm_link_rwsem
);
1481 snd_power_unlock(card
);
1482 tout
= schedule_timeout(10 * HZ
);
1483 snd_power_lock(card
);
1484 down_read(&snd_pcm_link_rwsem
);
1485 snd_pcm_stream_lock_irq(substream
);
1486 remove_wait_queue(&to_check
->sleep
, &wait
);
1488 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1491 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1492 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1500 snd_pcm_stream_unlock_irq(substream
);
1501 up_read(&snd_pcm_link_rwsem
);
1502 snd_power_unlock(card
);
1510 * Immediately put all linked substreams into SETUP state.
1512 static int snd_pcm_drop(struct snd_pcm_substream
*substream
)
1514 struct snd_pcm_runtime
*runtime
;
1515 struct snd_card
*card
;
1518 if (PCM_RUNTIME_CHECK(substream
))
1520 runtime
= substream
->runtime
;
1521 card
= substream
->pcm
->card
;
1523 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1524 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
||
1525 runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1528 snd_pcm_stream_lock_irq(substream
);
1530 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1531 snd_pcm_pause(substream
, 0);
1533 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1534 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */
1535 snd_pcm_stream_unlock_irq(substream
);
1541 /* WARNING: Don't forget to fput back the file */
1542 static struct file
*snd_pcm_file_fd(int fd
)
1545 struct inode
*inode
;
1551 inode
= file
->f_path
.dentry
->d_inode
;
1552 if (!S_ISCHR(inode
->i_mode
) ||
1553 imajor(inode
) != snd_major
) {
1557 minor
= iminor(inode
);
1558 if (!snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_PLAYBACK
) &&
1559 !snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_CAPTURE
)) {
1569 static int snd_pcm_link(struct snd_pcm_substream
*substream
, int fd
)
1573 struct snd_pcm_file
*pcm_file
;
1574 struct snd_pcm_substream
*substream1
;
1576 file
= snd_pcm_file_fd(fd
);
1579 pcm_file
= file
->private_data
;
1580 substream1
= pcm_file
->substream
;
1581 down_write(&snd_pcm_link_rwsem
);
1582 write_lock_irq(&snd_pcm_link_rwlock
);
1583 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1584 substream
->runtime
->status
->state
!= substream1
->runtime
->status
->state
) {
1588 if (snd_pcm_stream_linked(substream1
)) {
1592 if (!snd_pcm_stream_linked(substream
)) {
1593 substream
->group
= kmalloc(sizeof(struct snd_pcm_group
), GFP_ATOMIC
);
1594 if (substream
->group
== NULL
) {
1598 spin_lock_init(&substream
->group
->lock
);
1599 INIT_LIST_HEAD(&substream
->group
->substreams
);
1600 list_add_tail(&substream
->link_list
, &substream
->group
->substreams
);
1601 substream
->group
->count
= 1;
1603 list_add_tail(&substream1
->link_list
, &substream
->group
->substreams
);
1604 substream
->group
->count
++;
1605 substream1
->group
= substream
->group
;
1607 write_unlock_irq(&snd_pcm_link_rwlock
);
1608 up_write(&snd_pcm_link_rwsem
);
1613 static void relink_to_local(struct snd_pcm_substream
*substream
)
1615 substream
->group
= &substream
->self_group
;
1616 INIT_LIST_HEAD(&substream
->self_group
.substreams
);
1617 list_add_tail(&substream
->link_list
, &substream
->self_group
.substreams
);
1620 static int snd_pcm_unlink(struct snd_pcm_substream
*substream
)
1622 struct snd_pcm_substream
*s
;
1625 down_write(&snd_pcm_link_rwsem
);
1626 write_lock_irq(&snd_pcm_link_rwlock
);
1627 if (!snd_pcm_stream_linked(substream
)) {
1631 list_del(&substream
->link_list
);
1632 substream
->group
->count
--;
1633 if (substream
->group
->count
== 1) { /* detach the last stream, too */
1634 snd_pcm_group_for_each_entry(s
, substream
) {
1638 kfree(substream
->group
);
1640 relink_to_local(substream
);
1642 write_unlock_irq(&snd_pcm_link_rwlock
);
1643 up_write(&snd_pcm_link_rwsem
);
1650 static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params
*params
,
1651 struct snd_pcm_hw_rule
*rule
)
1653 struct snd_interval t
;
1654 snd_interval_mul(hw_param_interval_c(params
, rule
->deps
[0]),
1655 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1656 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1659 static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params
*params
,
1660 struct snd_pcm_hw_rule
*rule
)
1662 struct snd_interval t
;
1663 snd_interval_div(hw_param_interval_c(params
, rule
->deps
[0]),
1664 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1665 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1668 static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params
*params
,
1669 struct snd_pcm_hw_rule
*rule
)
1671 struct snd_interval t
;
1672 snd_interval_muldivk(hw_param_interval_c(params
, rule
->deps
[0]),
1673 hw_param_interval_c(params
, rule
->deps
[1]),
1674 (unsigned long) rule
->private, &t
);
1675 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1678 static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params
*params
,
1679 struct snd_pcm_hw_rule
*rule
)
1681 struct snd_interval t
;
1682 snd_interval_mulkdiv(hw_param_interval_c(params
, rule
->deps
[0]),
1683 (unsigned long) rule
->private,
1684 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1685 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1688 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params
*params
,
1689 struct snd_pcm_hw_rule
*rule
)
1692 struct snd_interval
*i
= hw_param_interval(params
, rule
->deps
[0]);
1694 struct snd_mask
*mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
1696 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1698 if (! snd_mask_test(mask
, k
))
1700 bits
= snd_pcm_format_physical_width(k
);
1702 continue; /* ignore invalid formats */
1703 if ((unsigned)bits
< i
->min
|| (unsigned)bits
> i
->max
)
1704 snd_mask_reset(&m
, k
);
1706 return snd_mask_refine(mask
, &m
);
1709 static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params
*params
,
1710 struct snd_pcm_hw_rule
*rule
)
1712 struct snd_interval t
;
1718 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1720 if (! snd_mask_test(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), k
))
1722 bits
= snd_pcm_format_physical_width(k
);
1724 continue; /* ignore invalid formats */
1725 if (t
.min
> (unsigned)bits
)
1727 if (t
.max
< (unsigned)bits
)
1731 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1734 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1735 #error "Change this table"
1738 static unsigned int rates
[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1739 48000, 64000, 88200, 96000, 176400, 192000 };
1741 const struct snd_pcm_hw_constraint_list snd_pcm_known_rates
= {
1742 .count
= ARRAY_SIZE(rates
),
1746 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params
*params
,
1747 struct snd_pcm_hw_rule
*rule
)
1749 struct snd_pcm_hardware
*hw
= rule
->private;
1750 return snd_interval_list(hw_param_interval(params
, rule
->var
),
1751 snd_pcm_known_rates
.count
,
1752 snd_pcm_known_rates
.list
, hw
->rates
);
1755 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params
*params
,
1756 struct snd_pcm_hw_rule
*rule
)
1758 struct snd_interval t
;
1759 struct snd_pcm_substream
*substream
= rule
->private;
1761 t
.max
= substream
->buffer_bytes_max
;
1765 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1768 int snd_pcm_hw_constraints_init(struct snd_pcm_substream
*substream
)
1770 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1771 struct snd_pcm_hw_constraints
*constrs
= &runtime
->hw_constraints
;
1774 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
1775 snd_mask_any(constrs_mask(constrs
, k
));
1778 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
1779 snd_interval_any(constrs_interval(constrs
, k
));
1782 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_CHANNELS
));
1783 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
));
1784 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
));
1785 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
));
1786 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_FRAME_BITS
));
1788 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FORMAT
,
1789 snd_pcm_hw_rule_format
, NULL
,
1790 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1793 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1794 snd_pcm_hw_rule_sample_bits
, NULL
,
1795 SNDRV_PCM_HW_PARAM_FORMAT
,
1796 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1799 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1800 snd_pcm_hw_rule_div
, NULL
,
1801 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1804 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1805 snd_pcm_hw_rule_mul
, NULL
,
1806 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1809 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1810 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1811 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1814 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1815 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1816 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, -1);
1819 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1820 snd_pcm_hw_rule_div
, NULL
,
1821 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1824 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1825 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1826 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_TIME
, -1);
1829 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1830 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1831 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
, -1);
1834 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
,
1835 snd_pcm_hw_rule_div
, NULL
,
1836 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1839 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1840 snd_pcm_hw_rule_div
, NULL
,
1841 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1844 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1845 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1846 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1849 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1850 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1851 SNDRV_PCM_HW_PARAM_PERIOD_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1854 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1855 snd_pcm_hw_rule_mul
, NULL
,
1856 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1859 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1860 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1861 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1864 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1865 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1866 SNDRV_PCM_HW_PARAM_BUFFER_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1869 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1870 snd_pcm_hw_rule_muldivk
, (void*) 8,
1871 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1874 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1875 snd_pcm_hw_rule_muldivk
, (void*) 8,
1876 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1879 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1880 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1881 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1884 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
1885 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1886 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1892 int snd_pcm_hw_constraints_complete(struct snd_pcm_substream
*substream
)
1894 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1895 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
1897 unsigned int mask
= 0;
1899 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1900 mask
|= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED
;
1901 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1902 mask
|= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
;
1903 if (hw
->info
& SNDRV_PCM_INFO_MMAP
) {
1904 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1905 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED
;
1906 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1907 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED
;
1908 if (hw
->info
& SNDRV_PCM_INFO_COMPLEX
)
1909 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX
;
1911 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_ACCESS
, mask
);
1915 err
= snd_pcm_hw_constraint_mask64(runtime
, SNDRV_PCM_HW_PARAM_FORMAT
, hw
->formats
);
1919 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_SUBFORMAT
, 1 << SNDRV_PCM_SUBFORMAT_STD
);
1923 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_CHANNELS
,
1924 hw
->channels_min
, hw
->channels_max
);
1928 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
1929 hw
->rate_min
, hw
->rate_max
);
1933 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1934 hw
->period_bytes_min
, hw
->period_bytes_max
);
1938 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
,
1939 hw
->periods_min
, hw
->periods_max
);
1943 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1944 hw
->period_bytes_min
, hw
->buffer_bytes_max
);
1948 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1949 snd_pcm_hw_rule_buffer_bytes_max
, substream
,
1950 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, -1);
1954 if (runtime
->dma_bytes
) {
1955 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 0, runtime
->dma_bytes
);
1960 if (!(hw
->rates
& (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_CONTINUOUS
))) {
1961 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1962 snd_pcm_hw_rule_rate
, hw
,
1963 SNDRV_PCM_HW_PARAM_RATE
, -1);
1968 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
1973 static void pcm_release_private(struct snd_pcm_substream
*substream
)
1975 snd_pcm_unlink(substream
);
1978 void snd_pcm_release_substream(struct snd_pcm_substream
*substream
)
1980 substream
->ref_count
--;
1981 if (substream
->ref_count
> 0)
1984 snd_pcm_drop(substream
);
1985 if (substream
->hw_opened
) {
1986 if (substream
->ops
->hw_free
!= NULL
)
1987 substream
->ops
->hw_free(substream
);
1988 substream
->ops
->close(substream
);
1989 substream
->hw_opened
= 0;
1991 if (pm_qos_request_active(&substream
->latency_pm_qos_req
))
1992 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
1993 if (substream
->pcm_release
) {
1994 substream
->pcm_release(substream
);
1995 substream
->pcm_release
= NULL
;
1997 snd_pcm_detach_substream(substream
);
2000 EXPORT_SYMBOL(snd_pcm_release_substream
);
2002 int snd_pcm_open_substream(struct snd_pcm
*pcm
, int stream
,
2004 struct snd_pcm_substream
**rsubstream
)
2006 struct snd_pcm_substream
*substream
;
2009 err
= snd_pcm_attach_substream(pcm
, stream
, file
, &substream
);
2012 if (substream
->ref_count
> 1) {
2013 *rsubstream
= substream
;
2017 err
= snd_pcm_hw_constraints_init(substream
);
2019 snd_printd("snd_pcm_hw_constraints_init failed\n");
2023 if ((err
= substream
->ops
->open(substream
)) < 0)
2026 substream
->hw_opened
= 1;
2028 err
= snd_pcm_hw_constraints_complete(substream
);
2030 snd_printd("snd_pcm_hw_constraints_complete failed\n");
2034 *rsubstream
= substream
;
2038 snd_pcm_release_substream(substream
);
2042 EXPORT_SYMBOL(snd_pcm_open_substream
);
2044 static int snd_pcm_open_file(struct file
*file
,
2045 struct snd_pcm
*pcm
,
2047 struct snd_pcm_file
**rpcm_file
)
2049 struct snd_pcm_file
*pcm_file
;
2050 struct snd_pcm_substream
*substream
;
2051 struct snd_pcm_str
*str
;
2057 err
= snd_pcm_open_substream(pcm
, stream
, file
, &substream
);
2061 pcm_file
= kzalloc(sizeof(*pcm_file
), GFP_KERNEL
);
2062 if (pcm_file
== NULL
) {
2063 snd_pcm_release_substream(substream
);
2066 pcm_file
->substream
= substream
;
2067 if (substream
->ref_count
== 1) {
2068 str
= substream
->pstr
;
2069 substream
->file
= pcm_file
;
2070 substream
->pcm_release
= pcm_release_private
;
2072 file
->private_data
= pcm_file
;
2074 *rpcm_file
= pcm_file
;
2078 static int snd_pcm_playback_open(struct inode
*inode
, struct file
*file
)
2080 struct snd_pcm
*pcm
;
2081 int err
= nonseekable_open(inode
, file
);
2084 pcm
= snd_lookup_minor_data(iminor(inode
),
2085 SNDRV_DEVICE_TYPE_PCM_PLAYBACK
);
2086 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_PLAYBACK
);
2089 static int snd_pcm_capture_open(struct inode
*inode
, struct file
*file
)
2091 struct snd_pcm
*pcm
;
2092 int err
= nonseekable_open(inode
, file
);
2095 pcm
= snd_lookup_minor_data(iminor(inode
),
2096 SNDRV_DEVICE_TYPE_PCM_CAPTURE
);
2097 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_CAPTURE
);
2100 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
)
2103 struct snd_pcm_file
*pcm_file
;
2110 err
= snd_card_file_add(pcm
->card
, file
);
2113 if (!try_module_get(pcm
->card
->module
)) {
2117 init_waitqueue_entry(&wait
, current
);
2118 add_wait_queue(&pcm
->open_wait
, &wait
);
2119 mutex_lock(&pcm
->open_mutex
);
2121 err
= snd_pcm_open_file(file
, pcm
, stream
, &pcm_file
);
2124 if (err
== -EAGAIN
) {
2125 if (file
->f_flags
& O_NONBLOCK
) {
2131 set_current_state(TASK_INTERRUPTIBLE
);
2132 mutex_unlock(&pcm
->open_mutex
);
2134 mutex_lock(&pcm
->open_mutex
);
2135 if (signal_pending(current
)) {
2140 remove_wait_queue(&pcm
->open_wait
, &wait
);
2141 mutex_unlock(&pcm
->open_mutex
);
2147 module_put(pcm
->card
->module
);
2149 snd_card_file_remove(pcm
->card
, file
);
2154 static int snd_pcm_release(struct inode
*inode
, struct file
*file
)
2156 struct snd_pcm
*pcm
;
2157 struct snd_pcm_substream
*substream
;
2158 struct snd_pcm_file
*pcm_file
;
2160 pcm_file
= file
->private_data
;
2161 substream
= pcm_file
->substream
;
2162 if (snd_BUG_ON(!substream
))
2164 pcm
= substream
->pcm
;
2165 mutex_lock(&pcm
->open_mutex
);
2166 snd_pcm_release_substream(substream
);
2168 mutex_unlock(&pcm
->open_mutex
);
2169 wake_up(&pcm
->open_wait
);
2170 module_put(pcm
->card
->module
);
2171 snd_card_file_remove(pcm
->card
, file
);
2175 static snd_pcm_sframes_t
snd_pcm_playback_rewind(struct snd_pcm_substream
*substream
,
2176 snd_pcm_uframes_t frames
)
2178 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2179 snd_pcm_sframes_t appl_ptr
;
2180 snd_pcm_sframes_t ret
;
2181 snd_pcm_sframes_t hw_avail
;
2186 snd_pcm_stream_lock_irq(substream
);
2187 switch (runtime
->status
->state
) {
2188 case SNDRV_PCM_STATE_PREPARED
:
2190 case SNDRV_PCM_STATE_DRAINING
:
2191 case SNDRV_PCM_STATE_RUNNING
:
2192 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2195 case SNDRV_PCM_STATE_XRUN
:
2198 case SNDRV_PCM_STATE_SUSPENDED
:
2206 hw_avail
= snd_pcm_playback_hw_avail(runtime
);
2207 if (hw_avail
<= 0) {
2211 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2213 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2215 appl_ptr
+= runtime
->boundary
;
2216 runtime
->control
->appl_ptr
= appl_ptr
;
2219 snd_pcm_stream_unlock_irq(substream
);
2223 static snd_pcm_sframes_t
snd_pcm_capture_rewind(struct snd_pcm_substream
*substream
,
2224 snd_pcm_uframes_t frames
)
2226 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2227 snd_pcm_sframes_t appl_ptr
;
2228 snd_pcm_sframes_t ret
;
2229 snd_pcm_sframes_t hw_avail
;
2234 snd_pcm_stream_lock_irq(substream
);
2235 switch (runtime
->status
->state
) {
2236 case SNDRV_PCM_STATE_PREPARED
:
2237 case SNDRV_PCM_STATE_DRAINING
:
2239 case SNDRV_PCM_STATE_RUNNING
:
2240 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2243 case SNDRV_PCM_STATE_XRUN
:
2246 case SNDRV_PCM_STATE_SUSPENDED
:
2254 hw_avail
= snd_pcm_capture_hw_avail(runtime
);
2255 if (hw_avail
<= 0) {
2259 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2261 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2263 appl_ptr
+= runtime
->boundary
;
2264 runtime
->control
->appl_ptr
= appl_ptr
;
2267 snd_pcm_stream_unlock_irq(substream
);
2271 static snd_pcm_sframes_t
snd_pcm_playback_forward(struct snd_pcm_substream
*substream
,
2272 snd_pcm_uframes_t frames
)
2274 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2275 snd_pcm_sframes_t appl_ptr
;
2276 snd_pcm_sframes_t ret
;
2277 snd_pcm_sframes_t avail
;
2282 snd_pcm_stream_lock_irq(substream
);
2283 switch (runtime
->status
->state
) {
2284 case SNDRV_PCM_STATE_PREPARED
:
2285 case SNDRV_PCM_STATE_PAUSED
:
2287 case SNDRV_PCM_STATE_DRAINING
:
2288 case SNDRV_PCM_STATE_RUNNING
:
2289 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2292 case SNDRV_PCM_STATE_XRUN
:
2295 case SNDRV_PCM_STATE_SUSPENDED
:
2303 avail
= snd_pcm_playback_avail(runtime
);
2308 if (frames
> (snd_pcm_uframes_t
)avail
)
2310 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2311 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2312 appl_ptr
-= runtime
->boundary
;
2313 runtime
->control
->appl_ptr
= appl_ptr
;
2316 snd_pcm_stream_unlock_irq(substream
);
2320 static snd_pcm_sframes_t
snd_pcm_capture_forward(struct snd_pcm_substream
*substream
,
2321 snd_pcm_uframes_t frames
)
2323 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2324 snd_pcm_sframes_t appl_ptr
;
2325 snd_pcm_sframes_t ret
;
2326 snd_pcm_sframes_t avail
;
2331 snd_pcm_stream_lock_irq(substream
);
2332 switch (runtime
->status
->state
) {
2333 case SNDRV_PCM_STATE_PREPARED
:
2334 case SNDRV_PCM_STATE_DRAINING
:
2335 case SNDRV_PCM_STATE_PAUSED
:
2337 case SNDRV_PCM_STATE_RUNNING
:
2338 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2341 case SNDRV_PCM_STATE_XRUN
:
2344 case SNDRV_PCM_STATE_SUSPENDED
:
2352 avail
= snd_pcm_capture_avail(runtime
);
2357 if (frames
> (snd_pcm_uframes_t
)avail
)
2359 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2360 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2361 appl_ptr
-= runtime
->boundary
;
2362 runtime
->control
->appl_ptr
= appl_ptr
;
2365 snd_pcm_stream_unlock_irq(substream
);
2369 static int snd_pcm_hwsync(struct snd_pcm_substream
*substream
)
2371 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2374 snd_pcm_stream_lock_irq(substream
);
2375 switch (runtime
->status
->state
) {
2376 case SNDRV_PCM_STATE_DRAINING
:
2377 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2379 case SNDRV_PCM_STATE_RUNNING
:
2380 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2383 case SNDRV_PCM_STATE_PREPARED
:
2384 case SNDRV_PCM_STATE_SUSPENDED
:
2387 case SNDRV_PCM_STATE_XRUN
:
2395 snd_pcm_stream_unlock_irq(substream
);
2399 static int snd_pcm_delay(struct snd_pcm_substream
*substream
,
2400 snd_pcm_sframes_t __user
*res
)
2402 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2404 snd_pcm_sframes_t n
= 0;
2406 snd_pcm_stream_lock_irq(substream
);
2407 switch (runtime
->status
->state
) {
2408 case SNDRV_PCM_STATE_DRAINING
:
2409 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2411 case SNDRV_PCM_STATE_RUNNING
:
2412 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2415 case SNDRV_PCM_STATE_PREPARED
:
2416 case SNDRV_PCM_STATE_SUSPENDED
:
2418 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2419 n
= snd_pcm_playback_hw_avail(runtime
);
2421 n
= snd_pcm_capture_avail(runtime
);
2422 n
+= runtime
->delay
;
2424 case SNDRV_PCM_STATE_XRUN
:
2432 snd_pcm_stream_unlock_irq(substream
);
2434 if (put_user(n
, res
))
2439 static int snd_pcm_sync_ptr(struct snd_pcm_substream
*substream
,
2440 struct snd_pcm_sync_ptr __user
*_sync_ptr
)
2442 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2443 struct snd_pcm_sync_ptr sync_ptr
;
2444 volatile struct snd_pcm_mmap_status
*status
;
2445 volatile struct snd_pcm_mmap_control
*control
;
2448 memset(&sync_ptr
, 0, sizeof(sync_ptr
));
2449 if (get_user(sync_ptr
.flags
, (unsigned __user
*)&(_sync_ptr
->flags
)))
2451 if (copy_from_user(&sync_ptr
.c
.control
, &(_sync_ptr
->c
.control
), sizeof(struct snd_pcm_mmap_control
)))
2453 status
= runtime
->status
;
2454 control
= runtime
->control
;
2455 if (sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
2456 err
= snd_pcm_hwsync(substream
);
2460 snd_pcm_stream_lock_irq(substream
);
2461 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_APPL
))
2462 control
->appl_ptr
= sync_ptr
.c
.control
.appl_ptr
;
2464 sync_ptr
.c
.control
.appl_ptr
= control
->appl_ptr
;
2465 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
2466 control
->avail_min
= sync_ptr
.c
.control
.avail_min
;
2468 sync_ptr
.c
.control
.avail_min
= control
->avail_min
;
2469 sync_ptr
.s
.status
.state
= status
->state
;
2470 sync_ptr
.s
.status
.hw_ptr
= status
->hw_ptr
;
2471 sync_ptr
.s
.status
.tstamp
= status
->tstamp
;
2472 sync_ptr
.s
.status
.suspended_state
= status
->suspended_state
;
2473 snd_pcm_stream_unlock_irq(substream
);
2474 if (copy_to_user(_sync_ptr
, &sync_ptr
, sizeof(sync_ptr
)))
2479 static int snd_pcm_tstamp(struct snd_pcm_substream
*substream
, int __user
*_arg
)
2481 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2484 if (get_user(arg
, _arg
))
2486 if (arg
< 0 || arg
> SNDRV_PCM_TSTAMP_TYPE_LAST
)
2488 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY
;
2489 if (arg
== SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
)
2490 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
;
2494 static int snd_pcm_common_ioctl1(struct file
*file
,
2495 struct snd_pcm_substream
*substream
,
2496 unsigned int cmd
, void __user
*arg
)
2499 case SNDRV_PCM_IOCTL_PVERSION
:
2500 return put_user(SNDRV_PCM_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2501 case SNDRV_PCM_IOCTL_INFO
:
2502 return snd_pcm_info_user(substream
, arg
);
2503 case SNDRV_PCM_IOCTL_TSTAMP
: /* just for compatibility */
2505 case SNDRV_PCM_IOCTL_TTSTAMP
:
2506 return snd_pcm_tstamp(substream
, arg
);
2507 case SNDRV_PCM_IOCTL_HW_REFINE
:
2508 return snd_pcm_hw_refine_user(substream
, arg
);
2509 case SNDRV_PCM_IOCTL_HW_PARAMS
:
2510 return snd_pcm_hw_params_user(substream
, arg
);
2511 case SNDRV_PCM_IOCTL_HW_FREE
:
2512 return snd_pcm_hw_free(substream
);
2513 case SNDRV_PCM_IOCTL_SW_PARAMS
:
2514 return snd_pcm_sw_params_user(substream
, arg
);
2515 case SNDRV_PCM_IOCTL_STATUS
:
2516 return snd_pcm_status_user(substream
, arg
);
2517 case SNDRV_PCM_IOCTL_CHANNEL_INFO
:
2518 return snd_pcm_channel_info_user(substream
, arg
);
2519 case SNDRV_PCM_IOCTL_PREPARE
:
2520 return snd_pcm_prepare(substream
, file
);
2521 case SNDRV_PCM_IOCTL_RESET
:
2522 return snd_pcm_reset(substream
);
2523 case SNDRV_PCM_IOCTL_START
:
2524 return snd_pcm_action_lock_irq(&snd_pcm_action_start
, substream
, SNDRV_PCM_STATE_RUNNING
);
2525 case SNDRV_PCM_IOCTL_LINK
:
2526 return snd_pcm_link(substream
, (int)(unsigned long) arg
);
2527 case SNDRV_PCM_IOCTL_UNLINK
:
2528 return snd_pcm_unlink(substream
);
2529 case SNDRV_PCM_IOCTL_RESUME
:
2530 return snd_pcm_resume(substream
);
2531 case SNDRV_PCM_IOCTL_XRUN
:
2532 return snd_pcm_xrun(substream
);
2533 case SNDRV_PCM_IOCTL_HWSYNC
:
2534 return snd_pcm_hwsync(substream
);
2535 case SNDRV_PCM_IOCTL_DELAY
:
2536 return snd_pcm_delay(substream
, arg
);
2537 case SNDRV_PCM_IOCTL_SYNC_PTR
:
2538 return snd_pcm_sync_ptr(substream
, arg
);
2539 #ifdef CONFIG_SND_SUPPORT_OLD_API
2540 case SNDRV_PCM_IOCTL_HW_REFINE_OLD
:
2541 return snd_pcm_hw_refine_old_user(substream
, arg
);
2542 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD
:
2543 return snd_pcm_hw_params_old_user(substream
, arg
);
2545 case SNDRV_PCM_IOCTL_DRAIN
:
2546 return snd_pcm_drain(substream
, file
);
2547 case SNDRV_PCM_IOCTL_DROP
:
2548 return snd_pcm_drop(substream
);
2549 case SNDRV_PCM_IOCTL_PAUSE
:
2552 snd_pcm_stream_lock_irq(substream
);
2553 res
= snd_pcm_pause(substream
, (int)(unsigned long)arg
);
2554 snd_pcm_stream_unlock_irq(substream
);
2558 snd_printd("unknown ioctl = 0x%x\n", cmd
);
2562 static int snd_pcm_playback_ioctl1(struct file
*file
,
2563 struct snd_pcm_substream
*substream
,
2564 unsigned int cmd
, void __user
*arg
)
2566 if (snd_BUG_ON(!substream
))
2568 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
2571 case SNDRV_PCM_IOCTL_WRITEI_FRAMES
:
2573 struct snd_xferi xferi
;
2574 struct snd_xferi __user
*_xferi
= arg
;
2575 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2576 snd_pcm_sframes_t result
;
2577 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2579 if (put_user(0, &_xferi
->result
))
2581 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2583 result
= snd_pcm_lib_write(substream
, xferi
.buf
, xferi
.frames
);
2584 __put_user(result
, &_xferi
->result
);
2585 return result
< 0 ? result
: 0;
2587 case SNDRV_PCM_IOCTL_WRITEN_FRAMES
:
2589 struct snd_xfern xfern
;
2590 struct snd_xfern __user
*_xfern
= arg
;
2591 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2593 snd_pcm_sframes_t result
;
2594 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2596 if (runtime
->channels
> 128)
2598 if (put_user(0, &_xfern
->result
))
2600 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2603 bufs
= memdup_user(xfern
.bufs
,
2604 sizeof(void *) * runtime
->channels
);
2606 return PTR_ERR(bufs
);
2607 result
= snd_pcm_lib_writev(substream
, bufs
, xfern
.frames
);
2609 __put_user(result
, &_xfern
->result
);
2610 return result
< 0 ? result
: 0;
2612 case SNDRV_PCM_IOCTL_REWIND
:
2614 snd_pcm_uframes_t frames
;
2615 snd_pcm_uframes_t __user
*_frames
= arg
;
2616 snd_pcm_sframes_t result
;
2617 if (get_user(frames
, _frames
))
2619 if (put_user(0, _frames
))
2621 result
= snd_pcm_playback_rewind(substream
, frames
);
2622 __put_user(result
, _frames
);
2623 return result
< 0 ? result
: 0;
2625 case SNDRV_PCM_IOCTL_FORWARD
:
2627 snd_pcm_uframes_t frames
;
2628 snd_pcm_uframes_t __user
*_frames
= arg
;
2629 snd_pcm_sframes_t result
;
2630 if (get_user(frames
, _frames
))
2632 if (put_user(0, _frames
))
2634 result
= snd_pcm_playback_forward(substream
, frames
);
2635 __put_user(result
, _frames
);
2636 return result
< 0 ? result
: 0;
2639 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2642 static int snd_pcm_capture_ioctl1(struct file
*file
,
2643 struct snd_pcm_substream
*substream
,
2644 unsigned int cmd
, void __user
*arg
)
2646 if (snd_BUG_ON(!substream
))
2648 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_CAPTURE
))
2651 case SNDRV_PCM_IOCTL_READI_FRAMES
:
2653 struct snd_xferi xferi
;
2654 struct snd_xferi __user
*_xferi
= arg
;
2655 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2656 snd_pcm_sframes_t result
;
2657 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2659 if (put_user(0, &_xferi
->result
))
2661 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2663 result
= snd_pcm_lib_read(substream
, xferi
.buf
, xferi
.frames
);
2664 __put_user(result
, &_xferi
->result
);
2665 return result
< 0 ? result
: 0;
2667 case SNDRV_PCM_IOCTL_READN_FRAMES
:
2669 struct snd_xfern xfern
;
2670 struct snd_xfern __user
*_xfern
= arg
;
2671 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2673 snd_pcm_sframes_t result
;
2674 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2676 if (runtime
->channels
> 128)
2678 if (put_user(0, &_xfern
->result
))
2680 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2683 bufs
= memdup_user(xfern
.bufs
,
2684 sizeof(void *) * runtime
->channels
);
2686 return PTR_ERR(bufs
);
2687 result
= snd_pcm_lib_readv(substream
, bufs
, xfern
.frames
);
2689 __put_user(result
, &_xfern
->result
);
2690 return result
< 0 ? result
: 0;
2692 case SNDRV_PCM_IOCTL_REWIND
:
2694 snd_pcm_uframes_t frames
;
2695 snd_pcm_uframes_t __user
*_frames
= arg
;
2696 snd_pcm_sframes_t result
;
2697 if (get_user(frames
, _frames
))
2699 if (put_user(0, _frames
))
2701 result
= snd_pcm_capture_rewind(substream
, frames
);
2702 __put_user(result
, _frames
);
2703 return result
< 0 ? result
: 0;
2705 case SNDRV_PCM_IOCTL_FORWARD
:
2707 snd_pcm_uframes_t frames
;
2708 snd_pcm_uframes_t __user
*_frames
= arg
;
2709 snd_pcm_sframes_t result
;
2710 if (get_user(frames
, _frames
))
2712 if (put_user(0, _frames
))
2714 result
= snd_pcm_capture_forward(substream
, frames
);
2715 __put_user(result
, _frames
);
2716 return result
< 0 ? result
: 0;
2719 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2722 static long snd_pcm_playback_ioctl(struct file
*file
, unsigned int cmd
,
2725 struct snd_pcm_file
*pcm_file
;
2727 pcm_file
= file
->private_data
;
2729 if (((cmd
>> 8) & 0xff) != 'A')
2732 return snd_pcm_playback_ioctl1(file
, pcm_file
->substream
, cmd
,
2733 (void __user
*)arg
);
2736 static long snd_pcm_capture_ioctl(struct file
*file
, unsigned int cmd
,
2739 struct snd_pcm_file
*pcm_file
;
2741 pcm_file
= file
->private_data
;
2743 if (((cmd
>> 8) & 0xff) != 'A')
2746 return snd_pcm_capture_ioctl1(file
, pcm_file
->substream
, cmd
,
2747 (void __user
*)arg
);
2750 int snd_pcm_kernel_ioctl(struct snd_pcm_substream
*substream
,
2751 unsigned int cmd
, void *arg
)
2756 fs
= snd_enter_user();
2757 switch (substream
->stream
) {
2758 case SNDRV_PCM_STREAM_PLAYBACK
:
2759 result
= snd_pcm_playback_ioctl1(NULL
, substream
, cmd
,
2760 (void __user
*)arg
);
2762 case SNDRV_PCM_STREAM_CAPTURE
:
2763 result
= snd_pcm_capture_ioctl1(NULL
, substream
, cmd
,
2764 (void __user
*)arg
);
2774 EXPORT_SYMBOL(snd_pcm_kernel_ioctl
);
2776 static ssize_t
snd_pcm_read(struct file
*file
, char __user
*buf
, size_t count
,
2779 struct snd_pcm_file
*pcm_file
;
2780 struct snd_pcm_substream
*substream
;
2781 struct snd_pcm_runtime
*runtime
;
2782 snd_pcm_sframes_t result
;
2784 pcm_file
= file
->private_data
;
2785 substream
= pcm_file
->substream
;
2786 if (PCM_RUNTIME_CHECK(substream
))
2788 runtime
= substream
->runtime
;
2789 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2791 if (!frame_aligned(runtime
, count
))
2793 count
= bytes_to_frames(runtime
, count
);
2794 result
= snd_pcm_lib_read(substream
, buf
, count
);
2796 result
= frames_to_bytes(runtime
, result
);
2800 static ssize_t
snd_pcm_write(struct file
*file
, const char __user
*buf
,
2801 size_t count
, loff_t
* offset
)
2803 struct snd_pcm_file
*pcm_file
;
2804 struct snd_pcm_substream
*substream
;
2805 struct snd_pcm_runtime
*runtime
;
2806 snd_pcm_sframes_t result
;
2808 pcm_file
= file
->private_data
;
2809 substream
= pcm_file
->substream
;
2810 if (PCM_RUNTIME_CHECK(substream
))
2812 runtime
= substream
->runtime
;
2813 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2815 if (!frame_aligned(runtime
, count
))
2817 count
= bytes_to_frames(runtime
, count
);
2818 result
= snd_pcm_lib_write(substream
, buf
, count
);
2820 result
= frames_to_bytes(runtime
, result
);
2824 static ssize_t
snd_pcm_aio_read(struct kiocb
*iocb
, const struct iovec
*iov
,
2825 unsigned long nr_segs
, loff_t pos
)
2828 struct snd_pcm_file
*pcm_file
;
2829 struct snd_pcm_substream
*substream
;
2830 struct snd_pcm_runtime
*runtime
;
2831 snd_pcm_sframes_t result
;
2834 snd_pcm_uframes_t frames
;
2836 pcm_file
= iocb
->ki_filp
->private_data
;
2837 substream
= pcm_file
->substream
;
2838 if (PCM_RUNTIME_CHECK(substream
))
2840 runtime
= substream
->runtime
;
2841 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2843 if (nr_segs
> 1024 || nr_segs
!= runtime
->channels
)
2845 if (!frame_aligned(runtime
, iov
->iov_len
))
2847 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2848 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2851 for (i
= 0; i
< nr_segs
; ++i
)
2852 bufs
[i
] = iov
[i
].iov_base
;
2853 result
= snd_pcm_lib_readv(substream
, bufs
, frames
);
2855 result
= frames_to_bytes(runtime
, result
);
2860 static ssize_t
snd_pcm_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
2861 unsigned long nr_segs
, loff_t pos
)
2863 struct snd_pcm_file
*pcm_file
;
2864 struct snd_pcm_substream
*substream
;
2865 struct snd_pcm_runtime
*runtime
;
2866 snd_pcm_sframes_t result
;
2869 snd_pcm_uframes_t frames
;
2871 pcm_file
= iocb
->ki_filp
->private_data
;
2872 substream
= pcm_file
->substream
;
2873 if (PCM_RUNTIME_CHECK(substream
))
2875 runtime
= substream
->runtime
;
2876 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2878 if (nr_segs
> 128 || nr_segs
!= runtime
->channels
||
2879 !frame_aligned(runtime
, iov
->iov_len
))
2881 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2882 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2885 for (i
= 0; i
< nr_segs
; ++i
)
2886 bufs
[i
] = iov
[i
].iov_base
;
2887 result
= snd_pcm_lib_writev(substream
, bufs
, frames
);
2889 result
= frames_to_bytes(runtime
, result
);
2894 static unsigned int snd_pcm_playback_poll(struct file
*file
, poll_table
* wait
)
2896 struct snd_pcm_file
*pcm_file
;
2897 struct snd_pcm_substream
*substream
;
2898 struct snd_pcm_runtime
*runtime
;
2900 snd_pcm_uframes_t avail
;
2902 pcm_file
= file
->private_data
;
2904 substream
= pcm_file
->substream
;
2905 if (PCM_RUNTIME_CHECK(substream
))
2907 runtime
= substream
->runtime
;
2909 poll_wait(file
, &runtime
->sleep
, wait
);
2911 snd_pcm_stream_lock_irq(substream
);
2912 avail
= snd_pcm_playback_avail(runtime
);
2913 switch (runtime
->status
->state
) {
2914 case SNDRV_PCM_STATE_RUNNING
:
2915 case SNDRV_PCM_STATE_PREPARED
:
2916 case SNDRV_PCM_STATE_PAUSED
:
2917 if (avail
>= runtime
->control
->avail_min
) {
2918 mask
= POLLOUT
| POLLWRNORM
;
2922 case SNDRV_PCM_STATE_DRAINING
:
2926 mask
= POLLOUT
| POLLWRNORM
| POLLERR
;
2929 snd_pcm_stream_unlock_irq(substream
);
2933 static unsigned int snd_pcm_capture_poll(struct file
*file
, poll_table
* wait
)
2935 struct snd_pcm_file
*pcm_file
;
2936 struct snd_pcm_substream
*substream
;
2937 struct snd_pcm_runtime
*runtime
;
2939 snd_pcm_uframes_t avail
;
2941 pcm_file
= file
->private_data
;
2943 substream
= pcm_file
->substream
;
2944 if (PCM_RUNTIME_CHECK(substream
))
2946 runtime
= substream
->runtime
;
2948 poll_wait(file
, &runtime
->sleep
, wait
);
2950 snd_pcm_stream_lock_irq(substream
);
2951 avail
= snd_pcm_capture_avail(runtime
);
2952 switch (runtime
->status
->state
) {
2953 case SNDRV_PCM_STATE_RUNNING
:
2954 case SNDRV_PCM_STATE_PREPARED
:
2955 case SNDRV_PCM_STATE_PAUSED
:
2956 if (avail
>= runtime
->control
->avail_min
) {
2957 mask
= POLLIN
| POLLRDNORM
;
2962 case SNDRV_PCM_STATE_DRAINING
:
2964 mask
= POLLIN
| POLLRDNORM
;
2969 mask
= POLLIN
| POLLRDNORM
| POLLERR
;
2972 snd_pcm_stream_unlock_irq(substream
);
2981 * Only on coherent architectures, we can mmap the status and the control records
2982 * for effcient data transfer. On others, we have to use HWSYNC ioctl...
2984 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
2986 * mmap status record
2988 static int snd_pcm_mmap_status_fault(struct vm_area_struct
*area
,
2989 struct vm_fault
*vmf
)
2991 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
2992 struct snd_pcm_runtime
*runtime
;
2994 if (substream
== NULL
)
2995 return VM_FAULT_SIGBUS
;
2996 runtime
= substream
->runtime
;
2997 vmf
->page
= virt_to_page(runtime
->status
);
2998 get_page(vmf
->page
);
3002 static const struct vm_operations_struct snd_pcm_vm_ops_status
=
3004 .fault
= snd_pcm_mmap_status_fault
,
3007 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3008 struct vm_area_struct
*area
)
3010 struct snd_pcm_runtime
*runtime
;
3012 if (!(area
->vm_flags
& VM_READ
))
3014 runtime
= substream
->runtime
;
3015 size
= area
->vm_end
- area
->vm_start
;
3016 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status
)))
3018 area
->vm_ops
= &snd_pcm_vm_ops_status
;
3019 area
->vm_private_data
= substream
;
3020 area
->vm_flags
|= VM_RESERVED
;
3025 * mmap control record
3027 static int snd_pcm_mmap_control_fault(struct vm_area_struct
*area
,
3028 struct vm_fault
*vmf
)
3030 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3031 struct snd_pcm_runtime
*runtime
;
3033 if (substream
== NULL
)
3034 return VM_FAULT_SIGBUS
;
3035 runtime
= substream
->runtime
;
3036 vmf
->page
= virt_to_page(runtime
->control
);
3037 get_page(vmf
->page
);
3041 static const struct vm_operations_struct snd_pcm_vm_ops_control
=
3043 .fault
= snd_pcm_mmap_control_fault
,
3046 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3047 struct vm_area_struct
*area
)
3049 struct snd_pcm_runtime
*runtime
;
3051 if (!(area
->vm_flags
& VM_READ
))
3053 runtime
= substream
->runtime
;
3054 size
= area
->vm_end
- area
->vm_start
;
3055 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control
)))
3057 area
->vm_ops
= &snd_pcm_vm_ops_control
;
3058 area
->vm_private_data
= substream
;
3059 area
->vm_flags
|= VM_RESERVED
;
3062 #else /* ! coherent mmap */
3064 * don't support mmap for status and control records.
3066 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3067 struct vm_area_struct
*area
)
3071 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3072 struct vm_area_struct
*area
)
3076 #endif /* coherent mmap */
3078 static inline struct page
*
3079 snd_pcm_default_page_ops(struct snd_pcm_substream
*substream
, unsigned long ofs
)
3081 void *vaddr
= substream
->runtime
->dma_area
+ ofs
;
3082 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3083 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3084 return virt_to_page(CAC_ADDR(vaddr
));
3086 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3087 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
) {
3088 dma_addr_t addr
= substream
->runtime
->dma_addr
+ ofs
;
3089 addr
-= get_dma_offset(substream
->dma_buffer
.dev
.dev
);
3090 /* assume dma_handle set via pfn_to_phys() in
3091 * mm/dma-noncoherent.c
3093 return pfn_to_page(addr
>> PAGE_SHIFT
);
3096 return virt_to_page(vaddr
);
3100 * fault callback for mmapping a RAM page
3102 static int snd_pcm_mmap_data_fault(struct vm_area_struct
*area
,
3103 struct vm_fault
*vmf
)
3105 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3106 struct snd_pcm_runtime
*runtime
;
3107 unsigned long offset
;
3111 if (substream
== NULL
)
3112 return VM_FAULT_SIGBUS
;
3113 runtime
= substream
->runtime
;
3114 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
3115 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3116 if (offset
> dma_bytes
- PAGE_SIZE
)
3117 return VM_FAULT_SIGBUS
;
3118 if (substream
->ops
->page
)
3119 page
= substream
->ops
->page(substream
, offset
);
3121 page
= snd_pcm_default_page_ops(substream
, offset
);
3123 return VM_FAULT_SIGBUS
;
3129 static const struct vm_operations_struct snd_pcm_vm_ops_data
= {
3130 .open
= snd_pcm_mmap_data_open
,
3131 .close
= snd_pcm_mmap_data_close
,
3134 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault
= {
3135 .open
= snd_pcm_mmap_data_open
,
3136 .close
= snd_pcm_mmap_data_close
,
3137 .fault
= snd_pcm_mmap_data_fault
,
3140 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3141 /* This should be defined / handled globally! */
3143 #define ARCH_HAS_DMA_MMAP_COHERENT
3148 * mmap the DMA buffer on RAM
3150 static int snd_pcm_default_mmap(struct snd_pcm_substream
*substream
,
3151 struct vm_area_struct
*area
)
3153 area
->vm_flags
|= VM_RESERVED
;
3154 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3155 if (!substream
->ops
->page
&&
3156 substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3157 return dma_mmap_coherent(substream
->dma_buffer
.dev
.dev
,
3159 substream
->runtime
->dma_area
,
3160 substream
->runtime
->dma_addr
,
3161 area
->vm_end
- area
->vm_start
);
3162 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3163 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
&&
3164 !plat_device_is_coherent(substream
->dma_buffer
.dev
.dev
))
3165 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3166 #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3167 /* mmap with fault handler */
3168 area
->vm_ops
= &snd_pcm_vm_ops_data_fault
;
3173 * mmap the DMA buffer on I/O memory area
3175 #if SNDRV_PCM_INFO_MMAP_IOMEM
3176 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream
*substream
,
3177 struct vm_area_struct
*area
)
3180 unsigned long offset
;
3182 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3183 area
->vm_flags
|= VM_IO
;
3184 size
= area
->vm_end
- area
->vm_start
;
3185 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3186 if (io_remap_pfn_range(area
, area
->vm_start
,
3187 (substream
->runtime
->dma_addr
+ offset
) >> PAGE_SHIFT
,
3188 size
, area
->vm_page_prot
))
3193 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem
);
3194 #endif /* SNDRV_PCM_INFO_MMAP */
3196 /* mmap callback with pgprot_noncached */
3197 int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream
*substream
,
3198 struct vm_area_struct
*area
)
3200 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3201 return snd_pcm_default_mmap(substream
, area
);
3203 EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached
);
3208 int snd_pcm_mmap_data(struct snd_pcm_substream
*substream
, struct file
*file
,
3209 struct vm_area_struct
*area
)
3211 struct snd_pcm_runtime
*runtime
;
3213 unsigned long offset
;
3217 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3218 if (!(area
->vm_flags
& (VM_WRITE
|VM_READ
)))
3221 if (!(area
->vm_flags
& VM_READ
))
3224 runtime
= substream
->runtime
;
3225 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
3227 if (!(runtime
->info
& SNDRV_PCM_INFO_MMAP
))
3229 if (runtime
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
||
3230 runtime
->access
== SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
)
3232 size
= area
->vm_end
- area
->vm_start
;
3233 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3234 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3235 if ((size_t)size
> dma_bytes
)
3237 if (offset
> dma_bytes
- size
)
3240 area
->vm_ops
= &snd_pcm_vm_ops_data
;
3241 area
->vm_private_data
= substream
;
3242 if (substream
->ops
->mmap
)
3243 err
= substream
->ops
->mmap(substream
, area
);
3245 err
= snd_pcm_default_mmap(substream
, area
);
3247 atomic_inc(&substream
->mmap_count
);
3251 EXPORT_SYMBOL(snd_pcm_mmap_data
);
3253 static int snd_pcm_mmap(struct file
*file
, struct vm_area_struct
*area
)
3255 struct snd_pcm_file
* pcm_file
;
3256 struct snd_pcm_substream
*substream
;
3257 unsigned long offset
;
3259 pcm_file
= file
->private_data
;
3260 substream
= pcm_file
->substream
;
3261 if (PCM_RUNTIME_CHECK(substream
))
3264 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3266 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3267 if (pcm_file
->no_compat_mmap
)
3269 return snd_pcm_mmap_status(substream
, file
, area
);
3270 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3271 if (pcm_file
->no_compat_mmap
)
3273 return snd_pcm_mmap_control(substream
, file
, area
);
3275 return snd_pcm_mmap_data(substream
, file
, area
);
3280 static int snd_pcm_fasync(int fd
, struct file
* file
, int on
)
3282 struct snd_pcm_file
* pcm_file
;
3283 struct snd_pcm_substream
*substream
;
3284 struct snd_pcm_runtime
*runtime
;
3286 pcm_file
= file
->private_data
;
3287 substream
= pcm_file
->substream
;
3288 if (PCM_RUNTIME_CHECK(substream
))
3290 runtime
= substream
->runtime
;
3291 return fasync_helper(fd
, file
, on
, &runtime
->fasync
);
3297 #ifdef CONFIG_COMPAT
3298 #include "pcm_compat.c"
3300 #define snd_pcm_ioctl_compat NULL
3304 * To be removed helpers to keep binary compatibility
3307 #ifdef CONFIG_SND_SUPPORT_OLD_API
3308 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3309 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3311 static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params
*params
,
3312 struct snd_pcm_hw_params_old
*oparams
)
3316 memset(params
, 0, sizeof(*params
));
3317 params
->flags
= oparams
->flags
;
3318 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3319 params
->masks
[i
].bits
[0] = oparams
->masks
[i
];
3320 memcpy(params
->intervals
, oparams
->intervals
, sizeof(oparams
->intervals
));
3321 params
->rmask
= __OLD_TO_NEW_MASK(oparams
->rmask
);
3322 params
->cmask
= __OLD_TO_NEW_MASK(oparams
->cmask
);
3323 params
->info
= oparams
->info
;
3324 params
->msbits
= oparams
->msbits
;
3325 params
->rate_num
= oparams
->rate_num
;
3326 params
->rate_den
= oparams
->rate_den
;
3327 params
->fifo_size
= oparams
->fifo_size
;
3330 static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old
*oparams
,
3331 struct snd_pcm_hw_params
*params
)
3335 memset(oparams
, 0, sizeof(*oparams
));
3336 oparams
->flags
= params
->flags
;
3337 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3338 oparams
->masks
[i
] = params
->masks
[i
].bits
[0];
3339 memcpy(oparams
->intervals
, params
->intervals
, sizeof(oparams
->intervals
));
3340 oparams
->rmask
= __NEW_TO_OLD_MASK(params
->rmask
);
3341 oparams
->cmask
= __NEW_TO_OLD_MASK(params
->cmask
);
3342 oparams
->info
= params
->info
;
3343 oparams
->msbits
= params
->msbits
;
3344 oparams
->rate_num
= params
->rate_num
;
3345 oparams
->rate_den
= params
->rate_den
;
3346 oparams
->fifo_size
= params
->fifo_size
;
3349 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
3350 struct snd_pcm_hw_params_old __user
* _oparams
)
3352 struct snd_pcm_hw_params
*params
;
3353 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3356 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3360 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3361 if (IS_ERR(oparams
)) {
3362 err
= PTR_ERR(oparams
);
3365 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3366 err
= snd_pcm_hw_refine(substream
, params
);
3367 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3368 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3379 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
3380 struct snd_pcm_hw_params_old __user
* _oparams
)
3382 struct snd_pcm_hw_params
*params
;
3383 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3386 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3390 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3391 if (IS_ERR(oparams
)) {
3392 err
= PTR_ERR(oparams
);
3395 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3396 err
= snd_pcm_hw_params(substream
, params
);
3397 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3398 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3408 #endif /* CONFIG_SND_SUPPORT_OLD_API */
3411 static unsigned long snd_pcm_get_unmapped_area(struct file
*file
,
3414 unsigned long pgoff
,
3415 unsigned long flags
)
3417 struct snd_pcm_file
*pcm_file
= file
->private_data
;
3418 struct snd_pcm_substream
*substream
= pcm_file
->substream
;
3419 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3420 unsigned long offset
= pgoff
<< PAGE_SHIFT
;
3423 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3424 return (unsigned long)runtime
->status
;
3425 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3426 return (unsigned long)runtime
->control
;
3428 return (unsigned long)runtime
->dma_area
+ offset
;
3432 # define snd_pcm_get_unmapped_area NULL
3439 const struct file_operations snd_pcm_f_ops
[2] = {
3441 .owner
= THIS_MODULE
,
3442 .write
= snd_pcm_write
,
3443 .aio_write
= snd_pcm_aio_write
,
3444 .open
= snd_pcm_playback_open
,
3445 .release
= snd_pcm_release
,
3446 .llseek
= no_llseek
,
3447 .poll
= snd_pcm_playback_poll
,
3448 .unlocked_ioctl
= snd_pcm_playback_ioctl
,
3449 .compat_ioctl
= snd_pcm_ioctl_compat
,
3450 .mmap
= snd_pcm_mmap
,
3451 .fasync
= snd_pcm_fasync
,
3452 .get_unmapped_area
= snd_pcm_get_unmapped_area
,
3455 .owner
= THIS_MODULE
,
3456 .read
= snd_pcm_read
,
3457 .aio_read
= snd_pcm_aio_read
,
3458 .open
= snd_pcm_capture_open
,
3459 .release
= snd_pcm_release
,
3460 .llseek
= no_llseek
,
3461 .poll
= snd_pcm_capture_poll
,
3462 .unlocked_ioctl
= snd_pcm_capture_ioctl
,
3463 .compat_ioctl
= snd_pcm_ioctl_compat
,
3464 .mmap
= snd_pcm_mmap
,
3465 .fasync
= snd_pcm_fasync
,
3466 .get_unmapped_area
= snd_pcm_get_unmapped_area
,