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/time.h>
26 #include <linux/pm_qos_params.h>
27 #include <linux/uio.h>
28 #include <linux/dma-mapping.h>
29 #include <sound/core.h>
30 #include <sound/control.h>
31 #include <sound/info.h>
32 #include <sound/pcm.h>
33 #include <sound/pcm_params.h>
34 #include <sound/timer.h>
35 #include <sound/minors.h>
37 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
38 #include <dma-coherence.h>
45 struct snd_pcm_hw_params_old
{
47 unsigned int masks
[SNDRV_PCM_HW_PARAM_SUBFORMAT
-
48 SNDRV_PCM_HW_PARAM_ACCESS
+ 1];
49 struct snd_interval intervals
[SNDRV_PCM_HW_PARAM_TICK_TIME
-
50 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
+ 1];
55 unsigned int rate_num
;
56 unsigned int rate_den
;
57 snd_pcm_uframes_t fifo_size
;
58 unsigned char reserved
[64];
61 #ifdef CONFIG_SND_SUPPORT_OLD_API
62 #define SNDRV_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct snd_pcm_hw_params_old)
63 #define SNDRV_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct snd_pcm_hw_params_old)
65 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
66 struct snd_pcm_hw_params_old __user
* _oparams
);
67 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
68 struct snd_pcm_hw_params_old __user
* _oparams
);
70 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
);
76 DEFINE_RWLOCK(snd_pcm_link_rwlock
);
77 EXPORT_SYMBOL(snd_pcm_link_rwlock
);
79 static DECLARE_RWSEM(snd_pcm_link_rwsem
);
81 static inline mm_segment_t
snd_enter_user(void)
83 mm_segment_t fs
= get_fs();
88 static inline void snd_leave_user(mm_segment_t fs
)
95 int snd_pcm_info(struct snd_pcm_substream
*substream
, struct snd_pcm_info
*info
)
97 struct snd_pcm_runtime
*runtime
;
98 struct snd_pcm
*pcm
= substream
->pcm
;
99 struct snd_pcm_str
*pstr
= substream
->pstr
;
101 memset(info
, 0, sizeof(*info
));
102 info
->card
= pcm
->card
->number
;
103 info
->device
= pcm
->device
;
104 info
->stream
= substream
->stream
;
105 info
->subdevice
= substream
->number
;
106 strlcpy(info
->id
, pcm
->id
, sizeof(info
->id
));
107 strlcpy(info
->name
, pcm
->name
, sizeof(info
->name
));
108 info
->dev_class
= pcm
->dev_class
;
109 info
->dev_subclass
= pcm
->dev_subclass
;
110 info
->subdevices_count
= pstr
->substream_count
;
111 info
->subdevices_avail
= pstr
->substream_count
- pstr
->substream_opened
;
112 strlcpy(info
->subname
, substream
->name
, sizeof(info
->subname
));
113 runtime
= substream
->runtime
;
114 /* AB: FIXME!!! This is definitely nonsense */
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 static const char * const 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
->hw_ptr_buffer_jiffies
= (runtime
->buffer_size
* HZ
) /
868 runtime
->status
->state
= state
;
869 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
870 runtime
->silence_size
> 0)
871 snd_pcm_playback_silence(substream
, ULONG_MAX
);
872 if (substream
->timer
)
873 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTART
,
874 &runtime
->trigger_tstamp
);
877 static struct action_ops snd_pcm_action_start
= {
878 .pre_action
= snd_pcm_pre_start
,
879 .do_action
= snd_pcm_do_start
,
880 .undo_action
= snd_pcm_undo_start
,
881 .post_action
= snd_pcm_post_start
885 * snd_pcm_start - start all linked streams
886 * @substream: the PCM substream instance
888 int snd_pcm_start(struct snd_pcm_substream
*substream
)
890 return snd_pcm_action(&snd_pcm_action_start
, substream
,
891 SNDRV_PCM_STATE_RUNNING
);
897 static int snd_pcm_pre_stop(struct snd_pcm_substream
*substream
, int state
)
899 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
900 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
902 runtime
->trigger_master
= substream
;
906 static int snd_pcm_do_stop(struct snd_pcm_substream
*substream
, int state
)
908 if (substream
->runtime
->trigger_master
== substream
&&
909 snd_pcm_running(substream
))
910 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
911 return 0; /* unconditonally stop all substreams */
914 static void snd_pcm_post_stop(struct snd_pcm_substream
*substream
, int state
)
916 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
917 if (runtime
->status
->state
!= state
) {
918 snd_pcm_trigger_tstamp(substream
);
919 if (substream
->timer
)
920 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTOP
,
921 &runtime
->trigger_tstamp
);
922 runtime
->status
->state
= state
;
924 wake_up(&runtime
->sleep
);
925 wake_up(&runtime
->tsleep
);
928 static struct action_ops snd_pcm_action_stop
= {
929 .pre_action
= snd_pcm_pre_stop
,
930 .do_action
= snd_pcm_do_stop
,
931 .post_action
= snd_pcm_post_stop
935 * snd_pcm_stop - try to stop all running streams in the substream group
936 * @substream: the PCM substream instance
937 * @state: PCM state after stopping the stream
939 * The state of each stream is then changed to the given state unconditionally.
941 int snd_pcm_stop(struct snd_pcm_substream
*substream
, int state
)
943 return snd_pcm_action(&snd_pcm_action_stop
, substream
, state
);
946 EXPORT_SYMBOL(snd_pcm_stop
);
949 * snd_pcm_drain_done - stop the DMA only when the given stream is playback
950 * @substream: the PCM substream
952 * After stopping, the state is changed to SETUP.
953 * Unlike snd_pcm_stop(), this affects only the given stream.
955 int snd_pcm_drain_done(struct snd_pcm_substream
*substream
)
957 return snd_pcm_action_single(&snd_pcm_action_stop
, substream
,
958 SNDRV_PCM_STATE_SETUP
);
964 static int snd_pcm_pre_pause(struct snd_pcm_substream
*substream
, int push
)
966 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
967 if (!(runtime
->info
& SNDRV_PCM_INFO_PAUSE
))
970 if (runtime
->status
->state
!= SNDRV_PCM_STATE_RUNNING
)
972 } else if (runtime
->status
->state
!= SNDRV_PCM_STATE_PAUSED
)
974 runtime
->trigger_master
= substream
;
978 static int snd_pcm_do_pause(struct snd_pcm_substream
*substream
, int push
)
980 if (substream
->runtime
->trigger_master
!= substream
)
982 /* some drivers might use hw_ptr to recover from the pause -
983 update the hw_ptr now */
985 snd_pcm_update_hw_ptr(substream
);
986 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
987 * a delta betwen the current jiffies, this gives a large enough
988 * delta, effectively to skip the check once.
990 substream
->runtime
->hw_ptr_jiffies
= jiffies
- HZ
* 1000;
991 return substream
->ops
->trigger(substream
,
992 push
? SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
993 SNDRV_PCM_TRIGGER_PAUSE_RELEASE
);
996 static void snd_pcm_undo_pause(struct snd_pcm_substream
*substream
, int push
)
998 if (substream
->runtime
->trigger_master
== substream
)
999 substream
->ops
->trigger(substream
,
1000 push
? SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1001 SNDRV_PCM_TRIGGER_PAUSE_PUSH
);
1004 static void snd_pcm_post_pause(struct snd_pcm_substream
*substream
, int push
)
1006 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1007 snd_pcm_trigger_tstamp(substream
);
1009 runtime
->status
->state
= SNDRV_PCM_STATE_PAUSED
;
1010 if (substream
->timer
)
1011 snd_timer_notify(substream
->timer
,
1012 SNDRV_TIMER_EVENT_MPAUSE
,
1013 &runtime
->trigger_tstamp
);
1014 wake_up(&runtime
->sleep
);
1015 wake_up(&runtime
->tsleep
);
1017 runtime
->status
->state
= SNDRV_PCM_STATE_RUNNING
;
1018 if (substream
->timer
)
1019 snd_timer_notify(substream
->timer
,
1020 SNDRV_TIMER_EVENT_MCONTINUE
,
1021 &runtime
->trigger_tstamp
);
1025 static struct action_ops snd_pcm_action_pause
= {
1026 .pre_action
= snd_pcm_pre_pause
,
1027 .do_action
= snd_pcm_do_pause
,
1028 .undo_action
= snd_pcm_undo_pause
,
1029 .post_action
= snd_pcm_post_pause
1033 * Push/release the pause for all linked streams.
1035 static int snd_pcm_pause(struct snd_pcm_substream
*substream
, int push
)
1037 return snd_pcm_action(&snd_pcm_action_pause
, substream
, push
);
1043 static int snd_pcm_pre_suspend(struct snd_pcm_substream
*substream
, int state
)
1045 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1046 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1048 runtime
->trigger_master
= substream
;
1052 static int snd_pcm_do_suspend(struct snd_pcm_substream
*substream
, int state
)
1054 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1055 if (runtime
->trigger_master
!= substream
)
1057 if (! snd_pcm_running(substream
))
1059 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1060 return 0; /* suspend unconditionally */
1063 static void snd_pcm_post_suspend(struct snd_pcm_substream
*substream
, int state
)
1065 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1066 snd_pcm_trigger_tstamp(substream
);
1067 if (substream
->timer
)
1068 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSUSPEND
,
1069 &runtime
->trigger_tstamp
);
1070 runtime
->status
->suspended_state
= runtime
->status
->state
;
1071 runtime
->status
->state
= SNDRV_PCM_STATE_SUSPENDED
;
1072 wake_up(&runtime
->sleep
);
1073 wake_up(&runtime
->tsleep
);
1076 static struct action_ops snd_pcm_action_suspend
= {
1077 .pre_action
= snd_pcm_pre_suspend
,
1078 .do_action
= snd_pcm_do_suspend
,
1079 .post_action
= snd_pcm_post_suspend
1083 * snd_pcm_suspend - trigger SUSPEND to all linked streams
1084 * @substream: the PCM substream
1086 * After this call, all streams are changed to SUSPENDED state.
1088 int snd_pcm_suspend(struct snd_pcm_substream
*substream
)
1091 unsigned long flags
;
1096 snd_pcm_stream_lock_irqsave(substream
, flags
);
1097 err
= snd_pcm_action(&snd_pcm_action_suspend
, substream
, 0);
1098 snd_pcm_stream_unlock_irqrestore(substream
, flags
);
1102 EXPORT_SYMBOL(snd_pcm_suspend
);
1105 * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm
1106 * @pcm: the PCM instance
1108 * After this call, all streams are changed to SUSPENDED state.
1110 int snd_pcm_suspend_all(struct snd_pcm
*pcm
)
1112 struct snd_pcm_substream
*substream
;
1113 int stream
, err
= 0;
1118 for (stream
= 0; stream
< 2; stream
++) {
1119 for (substream
= pcm
->streams
[stream
].substream
;
1120 substream
; substream
= substream
->next
) {
1121 /* FIXME: the open/close code should lock this as well */
1122 if (substream
->runtime
== NULL
)
1124 err
= snd_pcm_suspend(substream
);
1125 if (err
< 0 && err
!= -EBUSY
)
1132 EXPORT_SYMBOL(snd_pcm_suspend_all
);
1136 static int snd_pcm_pre_resume(struct snd_pcm_substream
*substream
, int state
)
1138 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1139 if (!(runtime
->info
& SNDRV_PCM_INFO_RESUME
))
1141 runtime
->trigger_master
= substream
;
1145 static int snd_pcm_do_resume(struct snd_pcm_substream
*substream
, int state
)
1147 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1148 if (runtime
->trigger_master
!= substream
)
1150 /* DMA not running previously? */
1151 if (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_RUNNING
&&
1152 (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_DRAINING
||
1153 substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
1155 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_RESUME
);
1158 static void snd_pcm_undo_resume(struct snd_pcm_substream
*substream
, int state
)
1160 if (substream
->runtime
->trigger_master
== substream
&&
1161 snd_pcm_running(substream
))
1162 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1165 static void snd_pcm_post_resume(struct snd_pcm_substream
*substream
, int state
)
1167 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1168 snd_pcm_trigger_tstamp(substream
);
1169 if (substream
->timer
)
1170 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MRESUME
,
1171 &runtime
->trigger_tstamp
);
1172 runtime
->status
->state
= runtime
->status
->suspended_state
;
1175 static struct action_ops snd_pcm_action_resume
= {
1176 .pre_action
= snd_pcm_pre_resume
,
1177 .do_action
= snd_pcm_do_resume
,
1178 .undo_action
= snd_pcm_undo_resume
,
1179 .post_action
= snd_pcm_post_resume
1182 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1184 struct snd_card
*card
= substream
->pcm
->card
;
1187 snd_power_lock(card
);
1188 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1189 res
= snd_pcm_action_lock_irq(&snd_pcm_action_resume
, substream
, 0);
1190 snd_power_unlock(card
);
1196 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1201 #endif /* CONFIG_PM */
1206 * Change the RUNNING stream(s) to XRUN state.
1208 static int snd_pcm_xrun(struct snd_pcm_substream
*substream
)
1210 struct snd_card
*card
= substream
->pcm
->card
;
1211 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1214 snd_power_lock(card
);
1215 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1216 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1221 snd_pcm_stream_lock_irq(substream
);
1222 switch (runtime
->status
->state
) {
1223 case SNDRV_PCM_STATE_XRUN
:
1224 result
= 0; /* already there */
1226 case SNDRV_PCM_STATE_RUNNING
:
1227 result
= snd_pcm_stop(substream
, SNDRV_PCM_STATE_XRUN
);
1232 snd_pcm_stream_unlock_irq(substream
);
1234 snd_power_unlock(card
);
1241 static int snd_pcm_pre_reset(struct snd_pcm_substream
*substream
, int state
)
1243 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1244 switch (runtime
->status
->state
) {
1245 case SNDRV_PCM_STATE_RUNNING
:
1246 case SNDRV_PCM_STATE_PREPARED
:
1247 case SNDRV_PCM_STATE_PAUSED
:
1248 case SNDRV_PCM_STATE_SUSPENDED
:
1255 static int snd_pcm_do_reset(struct snd_pcm_substream
*substream
, int state
)
1257 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1258 int err
= substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_RESET
, NULL
);
1261 runtime
->hw_ptr_base
= 0;
1262 runtime
->hw_ptr_interrupt
= runtime
->status
->hw_ptr
-
1263 runtime
->status
->hw_ptr
% runtime
->period_size
;
1264 runtime
->silence_start
= runtime
->status
->hw_ptr
;
1265 runtime
->silence_filled
= 0;
1269 static void snd_pcm_post_reset(struct snd_pcm_substream
*substream
, int state
)
1271 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1272 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1273 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
1274 runtime
->silence_size
> 0)
1275 snd_pcm_playback_silence(substream
, ULONG_MAX
);
1278 static struct action_ops snd_pcm_action_reset
= {
1279 .pre_action
= snd_pcm_pre_reset
,
1280 .do_action
= snd_pcm_do_reset
,
1281 .post_action
= snd_pcm_post_reset
1284 static int snd_pcm_reset(struct snd_pcm_substream
*substream
)
1286 return snd_pcm_action_nonatomic(&snd_pcm_action_reset
, substream
, 0);
1292 /* we use the second argument for updating f_flags */
1293 static int snd_pcm_pre_prepare(struct snd_pcm_substream
*substream
,
1296 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1297 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1298 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
)
1300 if (snd_pcm_running(substream
))
1302 substream
->f_flags
= f_flags
;
1306 static int snd_pcm_do_prepare(struct snd_pcm_substream
*substream
, int state
)
1309 err
= substream
->ops
->prepare(substream
);
1312 return snd_pcm_do_reset(substream
, 0);
1315 static void snd_pcm_post_prepare(struct snd_pcm_substream
*substream
, int state
)
1317 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1318 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1319 runtime
->status
->state
= SNDRV_PCM_STATE_PREPARED
;
1322 static struct action_ops snd_pcm_action_prepare
= {
1323 .pre_action
= snd_pcm_pre_prepare
,
1324 .do_action
= snd_pcm_do_prepare
,
1325 .post_action
= snd_pcm_post_prepare
1329 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1330 * @substream: the PCM substream instance
1331 * @file: file to refer f_flags
1333 static int snd_pcm_prepare(struct snd_pcm_substream
*substream
,
1337 struct snd_card
*card
= substream
->pcm
->card
;
1341 f_flags
= file
->f_flags
;
1343 f_flags
= substream
->f_flags
;
1345 snd_power_lock(card
);
1346 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1347 res
= snd_pcm_action_nonatomic(&snd_pcm_action_prepare
,
1348 substream
, f_flags
);
1349 snd_power_unlock(card
);
1357 static int snd_pcm_pre_drain_init(struct snd_pcm_substream
*substream
, int state
)
1359 substream
->runtime
->trigger_master
= substream
;
1363 static int snd_pcm_do_drain_init(struct snd_pcm_substream
*substream
, int state
)
1365 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1366 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1367 switch (runtime
->status
->state
) {
1368 case SNDRV_PCM_STATE_PREPARED
:
1369 /* start playback stream if possible */
1370 if (! snd_pcm_playback_empty(substream
)) {
1371 snd_pcm_do_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1372 snd_pcm_post_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1375 case SNDRV_PCM_STATE_RUNNING
:
1376 runtime
->status
->state
= SNDRV_PCM_STATE_DRAINING
;
1382 /* stop running stream */
1383 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
) {
1384 int new_state
= snd_pcm_capture_avail(runtime
) > 0 ?
1385 SNDRV_PCM_STATE_DRAINING
: SNDRV_PCM_STATE_SETUP
;
1386 snd_pcm_do_stop(substream
, new_state
);
1387 snd_pcm_post_stop(substream
, new_state
);
1393 static void snd_pcm_post_drain_init(struct snd_pcm_substream
*substream
, int state
)
1397 static struct action_ops snd_pcm_action_drain_init
= {
1398 .pre_action
= snd_pcm_pre_drain_init
,
1399 .do_action
= snd_pcm_do_drain_init
,
1400 .post_action
= snd_pcm_post_drain_init
1403 static int snd_pcm_drop(struct snd_pcm_substream
*substream
);
1406 * Drain the stream(s).
1407 * When the substream is linked, sync until the draining of all playback streams
1409 * After this call, all streams are supposed to be either SETUP or DRAINING
1410 * (capture only) state.
1412 static int snd_pcm_drain(struct snd_pcm_substream
*substream
,
1415 struct snd_card
*card
;
1416 struct snd_pcm_runtime
*runtime
;
1417 struct snd_pcm_substream
*s
;
1422 card
= substream
->pcm
->card
;
1423 runtime
= substream
->runtime
;
1425 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
1428 snd_power_lock(card
);
1429 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1430 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1432 snd_power_unlock(card
);
1438 if (file
->f_flags
& O_NONBLOCK
)
1440 } else if (substream
->f_flags
& O_NONBLOCK
)
1443 down_read(&snd_pcm_link_rwsem
);
1444 snd_pcm_stream_lock_irq(substream
);
1446 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1447 snd_pcm_pause(substream
, 0);
1449 /* pre-start/stop - all running streams are changed to DRAINING state */
1450 result
= snd_pcm_action(&snd_pcm_action_drain_init
, substream
, 0);
1453 /* in non-blocking, we don't wait in ioctl but let caller poll */
1461 struct snd_pcm_runtime
*to_check
;
1462 if (signal_pending(current
)) {
1463 result
= -ERESTARTSYS
;
1466 /* find a substream to drain */
1468 snd_pcm_group_for_each_entry(s
, substream
) {
1469 if (s
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1471 runtime
= s
->runtime
;
1472 if (runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
1478 break; /* all drained */
1479 init_waitqueue_entry(&wait
, current
);
1480 add_wait_queue(&to_check
->sleep
, &wait
);
1481 set_current_state(TASK_INTERRUPTIBLE
);
1482 snd_pcm_stream_unlock_irq(substream
);
1483 up_read(&snd_pcm_link_rwsem
);
1484 snd_power_unlock(card
);
1485 tout
= schedule_timeout(10 * HZ
);
1486 snd_power_lock(card
);
1487 down_read(&snd_pcm_link_rwsem
);
1488 snd_pcm_stream_lock_irq(substream
);
1489 remove_wait_queue(&to_check
->sleep
, &wait
);
1491 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1494 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1495 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1503 snd_pcm_stream_unlock_irq(substream
);
1504 up_read(&snd_pcm_link_rwsem
);
1505 snd_power_unlock(card
);
1513 * Immediately put all linked substreams into SETUP state.
1515 static int snd_pcm_drop(struct snd_pcm_substream
*substream
)
1517 struct snd_pcm_runtime
*runtime
;
1518 struct snd_card
*card
;
1521 if (PCM_RUNTIME_CHECK(substream
))
1523 runtime
= substream
->runtime
;
1524 card
= substream
->pcm
->card
;
1526 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1527 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
||
1528 runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1531 snd_pcm_stream_lock_irq(substream
);
1533 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1534 snd_pcm_pause(substream
, 0);
1536 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1537 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */
1538 snd_pcm_stream_unlock_irq(substream
);
1544 /* WARNING: Don't forget to fput back the file */
1545 static struct file
*snd_pcm_file_fd(int fd
)
1548 struct inode
*inode
;
1554 inode
= file
->f_path
.dentry
->d_inode
;
1555 if (!S_ISCHR(inode
->i_mode
) ||
1556 imajor(inode
) != snd_major
) {
1560 minor
= iminor(inode
);
1561 if (!snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_PLAYBACK
) &&
1562 !snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_CAPTURE
)) {
1572 static int snd_pcm_link(struct snd_pcm_substream
*substream
, int fd
)
1576 struct snd_pcm_file
*pcm_file
;
1577 struct snd_pcm_substream
*substream1
;
1579 file
= snd_pcm_file_fd(fd
);
1582 pcm_file
= file
->private_data
;
1583 substream1
= pcm_file
->substream
;
1584 down_write(&snd_pcm_link_rwsem
);
1585 write_lock_irq(&snd_pcm_link_rwlock
);
1586 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1587 substream
->runtime
->status
->state
!= substream1
->runtime
->status
->state
) {
1591 if (snd_pcm_stream_linked(substream1
)) {
1595 if (!snd_pcm_stream_linked(substream
)) {
1596 substream
->group
= kmalloc(sizeof(struct snd_pcm_group
), GFP_ATOMIC
);
1597 if (substream
->group
== NULL
) {
1601 spin_lock_init(&substream
->group
->lock
);
1602 INIT_LIST_HEAD(&substream
->group
->substreams
);
1603 list_add_tail(&substream
->link_list
, &substream
->group
->substreams
);
1604 substream
->group
->count
= 1;
1606 list_add_tail(&substream1
->link_list
, &substream
->group
->substreams
);
1607 substream
->group
->count
++;
1608 substream1
->group
= substream
->group
;
1610 write_unlock_irq(&snd_pcm_link_rwlock
);
1611 up_write(&snd_pcm_link_rwsem
);
1616 static void relink_to_local(struct snd_pcm_substream
*substream
)
1618 substream
->group
= &substream
->self_group
;
1619 INIT_LIST_HEAD(&substream
->self_group
.substreams
);
1620 list_add_tail(&substream
->link_list
, &substream
->self_group
.substreams
);
1623 static int snd_pcm_unlink(struct snd_pcm_substream
*substream
)
1625 struct snd_pcm_substream
*s
;
1628 down_write(&snd_pcm_link_rwsem
);
1629 write_lock_irq(&snd_pcm_link_rwlock
);
1630 if (!snd_pcm_stream_linked(substream
)) {
1634 list_del(&substream
->link_list
);
1635 substream
->group
->count
--;
1636 if (substream
->group
->count
== 1) { /* detach the last stream, too */
1637 snd_pcm_group_for_each_entry(s
, substream
) {
1641 kfree(substream
->group
);
1643 relink_to_local(substream
);
1645 write_unlock_irq(&snd_pcm_link_rwlock
);
1646 up_write(&snd_pcm_link_rwsem
);
1653 static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params
*params
,
1654 struct snd_pcm_hw_rule
*rule
)
1656 struct snd_interval t
;
1657 snd_interval_mul(hw_param_interval_c(params
, rule
->deps
[0]),
1658 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1659 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1662 static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params
*params
,
1663 struct snd_pcm_hw_rule
*rule
)
1665 struct snd_interval t
;
1666 snd_interval_div(hw_param_interval_c(params
, rule
->deps
[0]),
1667 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1668 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1671 static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params
*params
,
1672 struct snd_pcm_hw_rule
*rule
)
1674 struct snd_interval t
;
1675 snd_interval_muldivk(hw_param_interval_c(params
, rule
->deps
[0]),
1676 hw_param_interval_c(params
, rule
->deps
[1]),
1677 (unsigned long) rule
->private, &t
);
1678 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1681 static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params
*params
,
1682 struct snd_pcm_hw_rule
*rule
)
1684 struct snd_interval t
;
1685 snd_interval_mulkdiv(hw_param_interval_c(params
, rule
->deps
[0]),
1686 (unsigned long) rule
->private,
1687 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1688 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1691 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params
*params
,
1692 struct snd_pcm_hw_rule
*rule
)
1695 struct snd_interval
*i
= hw_param_interval(params
, rule
->deps
[0]);
1697 struct snd_mask
*mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
1699 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1701 if (! snd_mask_test(mask
, k
))
1703 bits
= snd_pcm_format_physical_width(k
);
1705 continue; /* ignore invalid formats */
1706 if ((unsigned)bits
< i
->min
|| (unsigned)bits
> i
->max
)
1707 snd_mask_reset(&m
, k
);
1709 return snd_mask_refine(mask
, &m
);
1712 static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params
*params
,
1713 struct snd_pcm_hw_rule
*rule
)
1715 struct snd_interval t
;
1721 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1723 if (! snd_mask_test(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), k
))
1725 bits
= snd_pcm_format_physical_width(k
);
1727 continue; /* ignore invalid formats */
1728 if (t
.min
> (unsigned)bits
)
1730 if (t
.max
< (unsigned)bits
)
1734 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1737 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1738 #error "Change this table"
1741 static unsigned int rates
[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1742 48000, 64000, 88200, 96000, 176400, 192000 };
1744 const struct snd_pcm_hw_constraint_list snd_pcm_known_rates
= {
1745 .count
= ARRAY_SIZE(rates
),
1749 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params
*params
,
1750 struct snd_pcm_hw_rule
*rule
)
1752 struct snd_pcm_hardware
*hw
= rule
->private;
1753 return snd_interval_list(hw_param_interval(params
, rule
->var
),
1754 snd_pcm_known_rates
.count
,
1755 snd_pcm_known_rates
.list
, hw
->rates
);
1758 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params
*params
,
1759 struct snd_pcm_hw_rule
*rule
)
1761 struct snd_interval t
;
1762 struct snd_pcm_substream
*substream
= rule
->private;
1764 t
.max
= substream
->buffer_bytes_max
;
1768 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1771 int snd_pcm_hw_constraints_init(struct snd_pcm_substream
*substream
)
1773 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1774 struct snd_pcm_hw_constraints
*constrs
= &runtime
->hw_constraints
;
1777 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
1778 snd_mask_any(constrs_mask(constrs
, k
));
1781 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
1782 snd_interval_any(constrs_interval(constrs
, k
));
1785 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_CHANNELS
));
1786 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
));
1787 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
));
1788 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
));
1789 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_FRAME_BITS
));
1791 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FORMAT
,
1792 snd_pcm_hw_rule_format
, NULL
,
1793 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1796 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1797 snd_pcm_hw_rule_sample_bits
, NULL
,
1798 SNDRV_PCM_HW_PARAM_FORMAT
,
1799 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1802 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1803 snd_pcm_hw_rule_div
, NULL
,
1804 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1807 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1808 snd_pcm_hw_rule_mul
, NULL
,
1809 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1812 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1813 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1814 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1817 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1818 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1819 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, -1);
1822 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1823 snd_pcm_hw_rule_div
, NULL
,
1824 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1827 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1828 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1829 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_TIME
, -1);
1832 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1833 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1834 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
, -1);
1837 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
,
1838 snd_pcm_hw_rule_div
, NULL
,
1839 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1842 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1843 snd_pcm_hw_rule_div
, NULL
,
1844 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1847 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1848 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1849 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1852 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1853 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1854 SNDRV_PCM_HW_PARAM_PERIOD_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1857 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1858 snd_pcm_hw_rule_mul
, NULL
,
1859 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1862 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1863 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1864 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1867 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1868 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1869 SNDRV_PCM_HW_PARAM_BUFFER_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1872 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1873 snd_pcm_hw_rule_muldivk
, (void*) 8,
1874 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1877 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1878 snd_pcm_hw_rule_muldivk
, (void*) 8,
1879 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1882 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1883 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1884 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1887 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
1888 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1889 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1895 int snd_pcm_hw_constraints_complete(struct snd_pcm_substream
*substream
)
1897 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1898 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
1900 unsigned int mask
= 0;
1902 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1903 mask
|= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED
;
1904 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1905 mask
|= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
;
1906 if (hw
->info
& SNDRV_PCM_INFO_MMAP
) {
1907 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1908 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED
;
1909 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1910 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED
;
1911 if (hw
->info
& SNDRV_PCM_INFO_COMPLEX
)
1912 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX
;
1914 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_ACCESS
, mask
);
1918 err
= snd_pcm_hw_constraint_mask64(runtime
, SNDRV_PCM_HW_PARAM_FORMAT
, hw
->formats
);
1922 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_SUBFORMAT
, 1 << SNDRV_PCM_SUBFORMAT_STD
);
1926 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_CHANNELS
,
1927 hw
->channels_min
, hw
->channels_max
);
1931 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
1932 hw
->rate_min
, hw
->rate_max
);
1936 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1937 hw
->period_bytes_min
, hw
->period_bytes_max
);
1941 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
,
1942 hw
->periods_min
, hw
->periods_max
);
1946 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1947 hw
->period_bytes_min
, hw
->buffer_bytes_max
);
1951 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1952 snd_pcm_hw_rule_buffer_bytes_max
, substream
,
1953 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, -1);
1958 if (runtime
->dma_bytes
) {
1959 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 0, runtime
->dma_bytes
);
1964 if (!(hw
->rates
& (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_CONTINUOUS
))) {
1965 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1966 snd_pcm_hw_rule_rate
, hw
,
1967 SNDRV_PCM_HW_PARAM_RATE
, -1);
1972 /* FIXME: this belong to lowlevel */
1973 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
1978 static void pcm_release_private(struct snd_pcm_substream
*substream
)
1980 snd_pcm_unlink(substream
);
1983 void snd_pcm_release_substream(struct snd_pcm_substream
*substream
)
1985 substream
->ref_count
--;
1986 if (substream
->ref_count
> 0)
1989 snd_pcm_drop(substream
);
1990 if (substream
->hw_opened
) {
1991 if (substream
->ops
->hw_free
!= NULL
)
1992 substream
->ops
->hw_free(substream
);
1993 substream
->ops
->close(substream
);
1994 substream
->hw_opened
= 0;
1996 if (pm_qos_request_active(&substream
->latency_pm_qos_req
))
1997 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
1998 if (substream
->pcm_release
) {
1999 substream
->pcm_release(substream
);
2000 substream
->pcm_release
= NULL
;
2002 snd_pcm_detach_substream(substream
);
2005 EXPORT_SYMBOL(snd_pcm_release_substream
);
2007 int snd_pcm_open_substream(struct snd_pcm
*pcm
, int stream
,
2009 struct snd_pcm_substream
**rsubstream
)
2011 struct snd_pcm_substream
*substream
;
2014 err
= snd_pcm_attach_substream(pcm
, stream
, file
, &substream
);
2017 if (substream
->ref_count
> 1) {
2018 *rsubstream
= substream
;
2022 err
= snd_pcm_hw_constraints_init(substream
);
2024 snd_printd("snd_pcm_hw_constraints_init failed\n");
2028 if ((err
= substream
->ops
->open(substream
)) < 0)
2031 substream
->hw_opened
= 1;
2033 err
= snd_pcm_hw_constraints_complete(substream
);
2035 snd_printd("snd_pcm_hw_constraints_complete failed\n");
2039 *rsubstream
= substream
;
2043 snd_pcm_release_substream(substream
);
2047 EXPORT_SYMBOL(snd_pcm_open_substream
);
2049 static int snd_pcm_open_file(struct file
*file
,
2050 struct snd_pcm
*pcm
,
2052 struct snd_pcm_file
**rpcm_file
)
2054 struct snd_pcm_file
*pcm_file
;
2055 struct snd_pcm_substream
*substream
;
2056 struct snd_pcm_str
*str
;
2062 err
= snd_pcm_open_substream(pcm
, stream
, file
, &substream
);
2066 pcm_file
= kzalloc(sizeof(*pcm_file
), GFP_KERNEL
);
2067 if (pcm_file
== NULL
) {
2068 snd_pcm_release_substream(substream
);
2071 pcm_file
->substream
= substream
;
2072 if (substream
->ref_count
== 1) {
2073 str
= substream
->pstr
;
2074 substream
->file
= pcm_file
;
2075 substream
->pcm_release
= pcm_release_private
;
2077 file
->private_data
= pcm_file
;
2079 *rpcm_file
= pcm_file
;
2083 static int snd_pcm_playback_open(struct inode
*inode
, struct file
*file
)
2085 struct snd_pcm
*pcm
;
2086 int err
= nonseekable_open(inode
, file
);
2089 pcm
= snd_lookup_minor_data(iminor(inode
),
2090 SNDRV_DEVICE_TYPE_PCM_PLAYBACK
);
2091 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_PLAYBACK
);
2094 static int snd_pcm_capture_open(struct inode
*inode
, struct file
*file
)
2096 struct snd_pcm
*pcm
;
2097 int err
= nonseekable_open(inode
, file
);
2100 pcm
= snd_lookup_minor_data(iminor(inode
),
2101 SNDRV_DEVICE_TYPE_PCM_CAPTURE
);
2102 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_CAPTURE
);
2105 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
)
2108 struct snd_pcm_file
*pcm_file
;
2115 err
= snd_card_file_add(pcm
->card
, file
);
2118 if (!try_module_get(pcm
->card
->module
)) {
2122 init_waitqueue_entry(&wait
, current
);
2123 add_wait_queue(&pcm
->open_wait
, &wait
);
2124 mutex_lock(&pcm
->open_mutex
);
2126 err
= snd_pcm_open_file(file
, pcm
, stream
, &pcm_file
);
2129 if (err
== -EAGAIN
) {
2130 if (file
->f_flags
& O_NONBLOCK
) {
2136 set_current_state(TASK_INTERRUPTIBLE
);
2137 mutex_unlock(&pcm
->open_mutex
);
2139 mutex_lock(&pcm
->open_mutex
);
2140 if (signal_pending(current
)) {
2145 remove_wait_queue(&pcm
->open_wait
, &wait
);
2146 mutex_unlock(&pcm
->open_mutex
);
2152 module_put(pcm
->card
->module
);
2154 snd_card_file_remove(pcm
->card
, file
);
2159 static int snd_pcm_release(struct inode
*inode
, struct file
*file
)
2161 struct snd_pcm
*pcm
;
2162 struct snd_pcm_substream
*substream
;
2163 struct snd_pcm_file
*pcm_file
;
2165 pcm_file
= file
->private_data
;
2166 substream
= pcm_file
->substream
;
2167 if (snd_BUG_ON(!substream
))
2169 pcm
= substream
->pcm
;
2170 mutex_lock(&pcm
->open_mutex
);
2171 snd_pcm_release_substream(substream
);
2173 mutex_unlock(&pcm
->open_mutex
);
2174 wake_up(&pcm
->open_wait
);
2175 module_put(pcm
->card
->module
);
2176 snd_card_file_remove(pcm
->card
, file
);
2180 static snd_pcm_sframes_t
snd_pcm_playback_rewind(struct snd_pcm_substream
*substream
,
2181 snd_pcm_uframes_t frames
)
2183 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2184 snd_pcm_sframes_t appl_ptr
;
2185 snd_pcm_sframes_t ret
;
2186 snd_pcm_sframes_t hw_avail
;
2191 snd_pcm_stream_lock_irq(substream
);
2192 switch (runtime
->status
->state
) {
2193 case SNDRV_PCM_STATE_PREPARED
:
2195 case SNDRV_PCM_STATE_DRAINING
:
2196 case SNDRV_PCM_STATE_RUNNING
:
2197 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2200 case SNDRV_PCM_STATE_XRUN
:
2203 case SNDRV_PCM_STATE_SUSPENDED
:
2211 hw_avail
= snd_pcm_playback_hw_avail(runtime
);
2212 if (hw_avail
<= 0) {
2216 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2218 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2220 appl_ptr
+= runtime
->boundary
;
2221 runtime
->control
->appl_ptr
= appl_ptr
;
2224 snd_pcm_stream_unlock_irq(substream
);
2228 static snd_pcm_sframes_t
snd_pcm_capture_rewind(struct snd_pcm_substream
*substream
,
2229 snd_pcm_uframes_t frames
)
2231 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2232 snd_pcm_sframes_t appl_ptr
;
2233 snd_pcm_sframes_t ret
;
2234 snd_pcm_sframes_t hw_avail
;
2239 snd_pcm_stream_lock_irq(substream
);
2240 switch (runtime
->status
->state
) {
2241 case SNDRV_PCM_STATE_PREPARED
:
2242 case SNDRV_PCM_STATE_DRAINING
:
2244 case SNDRV_PCM_STATE_RUNNING
:
2245 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2248 case SNDRV_PCM_STATE_XRUN
:
2251 case SNDRV_PCM_STATE_SUSPENDED
:
2259 hw_avail
= snd_pcm_capture_hw_avail(runtime
);
2260 if (hw_avail
<= 0) {
2264 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2266 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2268 appl_ptr
+= runtime
->boundary
;
2269 runtime
->control
->appl_ptr
= appl_ptr
;
2272 snd_pcm_stream_unlock_irq(substream
);
2276 static snd_pcm_sframes_t
snd_pcm_playback_forward(struct snd_pcm_substream
*substream
,
2277 snd_pcm_uframes_t frames
)
2279 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2280 snd_pcm_sframes_t appl_ptr
;
2281 snd_pcm_sframes_t ret
;
2282 snd_pcm_sframes_t avail
;
2287 snd_pcm_stream_lock_irq(substream
);
2288 switch (runtime
->status
->state
) {
2289 case SNDRV_PCM_STATE_PREPARED
:
2290 case SNDRV_PCM_STATE_PAUSED
:
2292 case SNDRV_PCM_STATE_DRAINING
:
2293 case SNDRV_PCM_STATE_RUNNING
:
2294 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2297 case SNDRV_PCM_STATE_XRUN
:
2300 case SNDRV_PCM_STATE_SUSPENDED
:
2308 avail
= snd_pcm_playback_avail(runtime
);
2313 if (frames
> (snd_pcm_uframes_t
)avail
)
2315 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2316 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2317 appl_ptr
-= runtime
->boundary
;
2318 runtime
->control
->appl_ptr
= appl_ptr
;
2321 snd_pcm_stream_unlock_irq(substream
);
2325 static snd_pcm_sframes_t
snd_pcm_capture_forward(struct snd_pcm_substream
*substream
,
2326 snd_pcm_uframes_t frames
)
2328 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2329 snd_pcm_sframes_t appl_ptr
;
2330 snd_pcm_sframes_t ret
;
2331 snd_pcm_sframes_t avail
;
2336 snd_pcm_stream_lock_irq(substream
);
2337 switch (runtime
->status
->state
) {
2338 case SNDRV_PCM_STATE_PREPARED
:
2339 case SNDRV_PCM_STATE_DRAINING
:
2340 case SNDRV_PCM_STATE_PAUSED
:
2342 case SNDRV_PCM_STATE_RUNNING
:
2343 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2346 case SNDRV_PCM_STATE_XRUN
:
2349 case SNDRV_PCM_STATE_SUSPENDED
:
2357 avail
= snd_pcm_capture_avail(runtime
);
2362 if (frames
> (snd_pcm_uframes_t
)avail
)
2364 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2365 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2366 appl_ptr
-= runtime
->boundary
;
2367 runtime
->control
->appl_ptr
= appl_ptr
;
2370 snd_pcm_stream_unlock_irq(substream
);
2374 static int snd_pcm_hwsync(struct snd_pcm_substream
*substream
)
2376 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2379 snd_pcm_stream_lock_irq(substream
);
2380 switch (runtime
->status
->state
) {
2381 case SNDRV_PCM_STATE_DRAINING
:
2382 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2384 case SNDRV_PCM_STATE_RUNNING
:
2385 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2388 case SNDRV_PCM_STATE_PREPARED
:
2389 case SNDRV_PCM_STATE_SUSPENDED
:
2392 case SNDRV_PCM_STATE_XRUN
:
2400 snd_pcm_stream_unlock_irq(substream
);
2404 static int snd_pcm_delay(struct snd_pcm_substream
*substream
,
2405 snd_pcm_sframes_t __user
*res
)
2407 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2409 snd_pcm_sframes_t n
= 0;
2411 snd_pcm_stream_lock_irq(substream
);
2412 switch (runtime
->status
->state
) {
2413 case SNDRV_PCM_STATE_DRAINING
:
2414 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2416 case SNDRV_PCM_STATE_RUNNING
:
2417 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2420 case SNDRV_PCM_STATE_PREPARED
:
2421 case SNDRV_PCM_STATE_SUSPENDED
:
2423 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2424 n
= snd_pcm_playback_hw_avail(runtime
);
2426 n
= snd_pcm_capture_avail(runtime
);
2427 n
+= runtime
->delay
;
2429 case SNDRV_PCM_STATE_XRUN
:
2437 snd_pcm_stream_unlock_irq(substream
);
2439 if (put_user(n
, res
))
2444 static int snd_pcm_sync_ptr(struct snd_pcm_substream
*substream
,
2445 struct snd_pcm_sync_ptr __user
*_sync_ptr
)
2447 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2448 struct snd_pcm_sync_ptr sync_ptr
;
2449 volatile struct snd_pcm_mmap_status
*status
;
2450 volatile struct snd_pcm_mmap_control
*control
;
2453 memset(&sync_ptr
, 0, sizeof(sync_ptr
));
2454 if (get_user(sync_ptr
.flags
, (unsigned __user
*)&(_sync_ptr
->flags
)))
2456 if (copy_from_user(&sync_ptr
.c
.control
, &(_sync_ptr
->c
.control
), sizeof(struct snd_pcm_mmap_control
)))
2458 status
= runtime
->status
;
2459 control
= runtime
->control
;
2460 if (sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
2461 err
= snd_pcm_hwsync(substream
);
2465 snd_pcm_stream_lock_irq(substream
);
2466 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_APPL
))
2467 control
->appl_ptr
= sync_ptr
.c
.control
.appl_ptr
;
2469 sync_ptr
.c
.control
.appl_ptr
= control
->appl_ptr
;
2470 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
2471 control
->avail_min
= sync_ptr
.c
.control
.avail_min
;
2473 sync_ptr
.c
.control
.avail_min
= control
->avail_min
;
2474 sync_ptr
.s
.status
.state
= status
->state
;
2475 sync_ptr
.s
.status
.hw_ptr
= status
->hw_ptr
;
2476 sync_ptr
.s
.status
.tstamp
= status
->tstamp
;
2477 sync_ptr
.s
.status
.suspended_state
= status
->suspended_state
;
2478 snd_pcm_stream_unlock_irq(substream
);
2479 if (copy_to_user(_sync_ptr
, &sync_ptr
, sizeof(sync_ptr
)))
2484 static int snd_pcm_tstamp(struct snd_pcm_substream
*substream
, int __user
*_arg
)
2486 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2489 if (get_user(arg
, _arg
))
2491 if (arg
< 0 || arg
> SNDRV_PCM_TSTAMP_TYPE_LAST
)
2493 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY
;
2494 if (arg
== SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
)
2495 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
;
2499 static int snd_pcm_common_ioctl1(struct file
*file
,
2500 struct snd_pcm_substream
*substream
,
2501 unsigned int cmd
, void __user
*arg
)
2504 case SNDRV_PCM_IOCTL_PVERSION
:
2505 return put_user(SNDRV_PCM_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2506 case SNDRV_PCM_IOCTL_INFO
:
2507 return snd_pcm_info_user(substream
, arg
);
2508 case SNDRV_PCM_IOCTL_TSTAMP
: /* just for compatibility */
2510 case SNDRV_PCM_IOCTL_TTSTAMP
:
2511 return snd_pcm_tstamp(substream
, arg
);
2512 case SNDRV_PCM_IOCTL_HW_REFINE
:
2513 return snd_pcm_hw_refine_user(substream
, arg
);
2514 case SNDRV_PCM_IOCTL_HW_PARAMS
:
2515 return snd_pcm_hw_params_user(substream
, arg
);
2516 case SNDRV_PCM_IOCTL_HW_FREE
:
2517 return snd_pcm_hw_free(substream
);
2518 case SNDRV_PCM_IOCTL_SW_PARAMS
:
2519 return snd_pcm_sw_params_user(substream
, arg
);
2520 case SNDRV_PCM_IOCTL_STATUS
:
2521 return snd_pcm_status_user(substream
, arg
);
2522 case SNDRV_PCM_IOCTL_CHANNEL_INFO
:
2523 return snd_pcm_channel_info_user(substream
, arg
);
2524 case SNDRV_PCM_IOCTL_PREPARE
:
2525 return snd_pcm_prepare(substream
, file
);
2526 case SNDRV_PCM_IOCTL_RESET
:
2527 return snd_pcm_reset(substream
);
2528 case SNDRV_PCM_IOCTL_START
:
2529 return snd_pcm_action_lock_irq(&snd_pcm_action_start
, substream
, SNDRV_PCM_STATE_RUNNING
);
2530 case SNDRV_PCM_IOCTL_LINK
:
2531 return snd_pcm_link(substream
, (int)(unsigned long) arg
);
2532 case SNDRV_PCM_IOCTL_UNLINK
:
2533 return snd_pcm_unlink(substream
);
2534 case SNDRV_PCM_IOCTL_RESUME
:
2535 return snd_pcm_resume(substream
);
2536 case SNDRV_PCM_IOCTL_XRUN
:
2537 return snd_pcm_xrun(substream
);
2538 case SNDRV_PCM_IOCTL_HWSYNC
:
2539 return snd_pcm_hwsync(substream
);
2540 case SNDRV_PCM_IOCTL_DELAY
:
2541 return snd_pcm_delay(substream
, arg
);
2542 case SNDRV_PCM_IOCTL_SYNC_PTR
:
2543 return snd_pcm_sync_ptr(substream
, arg
);
2544 #ifdef CONFIG_SND_SUPPORT_OLD_API
2545 case SNDRV_PCM_IOCTL_HW_REFINE_OLD
:
2546 return snd_pcm_hw_refine_old_user(substream
, arg
);
2547 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD
:
2548 return snd_pcm_hw_params_old_user(substream
, arg
);
2550 case SNDRV_PCM_IOCTL_DRAIN
:
2551 return snd_pcm_drain(substream
, file
);
2552 case SNDRV_PCM_IOCTL_DROP
:
2553 return snd_pcm_drop(substream
);
2554 case SNDRV_PCM_IOCTL_PAUSE
:
2557 snd_pcm_stream_lock_irq(substream
);
2558 res
= snd_pcm_pause(substream
, (int)(unsigned long)arg
);
2559 snd_pcm_stream_unlock_irq(substream
);
2563 snd_printd("unknown ioctl = 0x%x\n", cmd
);
2567 static int snd_pcm_playback_ioctl1(struct file
*file
,
2568 struct snd_pcm_substream
*substream
,
2569 unsigned int cmd
, void __user
*arg
)
2571 if (snd_BUG_ON(!substream
))
2573 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
2576 case SNDRV_PCM_IOCTL_WRITEI_FRAMES
:
2578 struct snd_xferi xferi
;
2579 struct snd_xferi __user
*_xferi
= arg
;
2580 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2581 snd_pcm_sframes_t result
;
2582 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2584 if (put_user(0, &_xferi
->result
))
2586 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2588 result
= snd_pcm_lib_write(substream
, xferi
.buf
, xferi
.frames
);
2589 __put_user(result
, &_xferi
->result
);
2590 return result
< 0 ? result
: 0;
2592 case SNDRV_PCM_IOCTL_WRITEN_FRAMES
:
2594 struct snd_xfern xfern
;
2595 struct snd_xfern __user
*_xfern
= arg
;
2596 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2598 snd_pcm_sframes_t result
;
2599 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2601 if (runtime
->channels
> 128)
2603 if (put_user(0, &_xfern
->result
))
2605 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2608 bufs
= memdup_user(xfern
.bufs
,
2609 sizeof(void *) * runtime
->channels
);
2611 return PTR_ERR(bufs
);
2612 result
= snd_pcm_lib_writev(substream
, bufs
, xfern
.frames
);
2614 __put_user(result
, &_xfern
->result
);
2615 return result
< 0 ? result
: 0;
2617 case SNDRV_PCM_IOCTL_REWIND
:
2619 snd_pcm_uframes_t frames
;
2620 snd_pcm_uframes_t __user
*_frames
= arg
;
2621 snd_pcm_sframes_t result
;
2622 if (get_user(frames
, _frames
))
2624 if (put_user(0, _frames
))
2626 result
= snd_pcm_playback_rewind(substream
, frames
);
2627 __put_user(result
, _frames
);
2628 return result
< 0 ? result
: 0;
2630 case SNDRV_PCM_IOCTL_FORWARD
:
2632 snd_pcm_uframes_t frames
;
2633 snd_pcm_uframes_t __user
*_frames
= arg
;
2634 snd_pcm_sframes_t result
;
2635 if (get_user(frames
, _frames
))
2637 if (put_user(0, _frames
))
2639 result
= snd_pcm_playback_forward(substream
, frames
);
2640 __put_user(result
, _frames
);
2641 return result
< 0 ? result
: 0;
2644 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2647 static int snd_pcm_capture_ioctl1(struct file
*file
,
2648 struct snd_pcm_substream
*substream
,
2649 unsigned int cmd
, void __user
*arg
)
2651 if (snd_BUG_ON(!substream
))
2653 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_CAPTURE
))
2656 case SNDRV_PCM_IOCTL_READI_FRAMES
:
2658 struct snd_xferi xferi
;
2659 struct snd_xferi __user
*_xferi
= arg
;
2660 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2661 snd_pcm_sframes_t result
;
2662 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2664 if (put_user(0, &_xferi
->result
))
2666 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2668 result
= snd_pcm_lib_read(substream
, xferi
.buf
, xferi
.frames
);
2669 __put_user(result
, &_xferi
->result
);
2670 return result
< 0 ? result
: 0;
2672 case SNDRV_PCM_IOCTL_READN_FRAMES
:
2674 struct snd_xfern xfern
;
2675 struct snd_xfern __user
*_xfern
= arg
;
2676 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2678 snd_pcm_sframes_t result
;
2679 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2681 if (runtime
->channels
> 128)
2683 if (put_user(0, &_xfern
->result
))
2685 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2688 bufs
= memdup_user(xfern
.bufs
,
2689 sizeof(void *) * runtime
->channels
);
2691 return PTR_ERR(bufs
);
2692 result
= snd_pcm_lib_readv(substream
, bufs
, xfern
.frames
);
2694 __put_user(result
, &_xfern
->result
);
2695 return result
< 0 ? result
: 0;
2697 case SNDRV_PCM_IOCTL_REWIND
:
2699 snd_pcm_uframes_t frames
;
2700 snd_pcm_uframes_t __user
*_frames
= arg
;
2701 snd_pcm_sframes_t result
;
2702 if (get_user(frames
, _frames
))
2704 if (put_user(0, _frames
))
2706 result
= snd_pcm_capture_rewind(substream
, frames
);
2707 __put_user(result
, _frames
);
2708 return result
< 0 ? result
: 0;
2710 case SNDRV_PCM_IOCTL_FORWARD
:
2712 snd_pcm_uframes_t frames
;
2713 snd_pcm_uframes_t __user
*_frames
= arg
;
2714 snd_pcm_sframes_t result
;
2715 if (get_user(frames
, _frames
))
2717 if (put_user(0, _frames
))
2719 result
= snd_pcm_capture_forward(substream
, frames
);
2720 __put_user(result
, _frames
);
2721 return result
< 0 ? result
: 0;
2724 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2727 static long snd_pcm_playback_ioctl(struct file
*file
, unsigned int cmd
,
2730 struct snd_pcm_file
*pcm_file
;
2732 pcm_file
= file
->private_data
;
2734 if (((cmd
>> 8) & 0xff) != 'A')
2737 return snd_pcm_playback_ioctl1(file
, pcm_file
->substream
, cmd
,
2738 (void __user
*)arg
);
2741 static long snd_pcm_capture_ioctl(struct file
*file
, unsigned int cmd
,
2744 struct snd_pcm_file
*pcm_file
;
2746 pcm_file
= file
->private_data
;
2748 if (((cmd
>> 8) & 0xff) != 'A')
2751 return snd_pcm_capture_ioctl1(file
, pcm_file
->substream
, cmd
,
2752 (void __user
*)arg
);
2755 int snd_pcm_kernel_ioctl(struct snd_pcm_substream
*substream
,
2756 unsigned int cmd
, void *arg
)
2761 fs
= snd_enter_user();
2762 switch (substream
->stream
) {
2763 case SNDRV_PCM_STREAM_PLAYBACK
:
2764 result
= snd_pcm_playback_ioctl1(NULL
, substream
, cmd
,
2765 (void __user
*)arg
);
2767 case SNDRV_PCM_STREAM_CAPTURE
:
2768 result
= snd_pcm_capture_ioctl1(NULL
, substream
, cmd
,
2769 (void __user
*)arg
);
2779 EXPORT_SYMBOL(snd_pcm_kernel_ioctl
);
2781 static ssize_t
snd_pcm_read(struct file
*file
, char __user
*buf
, size_t count
,
2784 struct snd_pcm_file
*pcm_file
;
2785 struct snd_pcm_substream
*substream
;
2786 struct snd_pcm_runtime
*runtime
;
2787 snd_pcm_sframes_t result
;
2789 pcm_file
= file
->private_data
;
2790 substream
= pcm_file
->substream
;
2791 if (PCM_RUNTIME_CHECK(substream
))
2793 runtime
= substream
->runtime
;
2794 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2796 if (!frame_aligned(runtime
, count
))
2798 count
= bytes_to_frames(runtime
, count
);
2799 result
= snd_pcm_lib_read(substream
, buf
, count
);
2801 result
= frames_to_bytes(runtime
, result
);
2805 static ssize_t
snd_pcm_write(struct file
*file
, const char __user
*buf
,
2806 size_t count
, loff_t
* offset
)
2808 struct snd_pcm_file
*pcm_file
;
2809 struct snd_pcm_substream
*substream
;
2810 struct snd_pcm_runtime
*runtime
;
2811 snd_pcm_sframes_t result
;
2813 pcm_file
= file
->private_data
;
2814 substream
= pcm_file
->substream
;
2815 if (PCM_RUNTIME_CHECK(substream
))
2817 runtime
= substream
->runtime
;
2818 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2820 if (!frame_aligned(runtime
, count
))
2822 count
= bytes_to_frames(runtime
, count
);
2823 result
= snd_pcm_lib_write(substream
, buf
, count
);
2825 result
= frames_to_bytes(runtime
, result
);
2829 static ssize_t
snd_pcm_aio_read(struct kiocb
*iocb
, const struct iovec
*iov
,
2830 unsigned long nr_segs
, loff_t pos
)
2833 struct snd_pcm_file
*pcm_file
;
2834 struct snd_pcm_substream
*substream
;
2835 struct snd_pcm_runtime
*runtime
;
2836 snd_pcm_sframes_t result
;
2839 snd_pcm_uframes_t frames
;
2841 pcm_file
= iocb
->ki_filp
->private_data
;
2842 substream
= pcm_file
->substream
;
2843 if (PCM_RUNTIME_CHECK(substream
))
2845 runtime
= substream
->runtime
;
2846 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2848 if (nr_segs
> 1024 || nr_segs
!= runtime
->channels
)
2850 if (!frame_aligned(runtime
, iov
->iov_len
))
2852 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2853 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2856 for (i
= 0; i
< nr_segs
; ++i
)
2857 bufs
[i
] = iov
[i
].iov_base
;
2858 result
= snd_pcm_lib_readv(substream
, bufs
, frames
);
2860 result
= frames_to_bytes(runtime
, result
);
2865 static ssize_t
snd_pcm_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
2866 unsigned long nr_segs
, loff_t pos
)
2868 struct snd_pcm_file
*pcm_file
;
2869 struct snd_pcm_substream
*substream
;
2870 struct snd_pcm_runtime
*runtime
;
2871 snd_pcm_sframes_t result
;
2874 snd_pcm_uframes_t frames
;
2876 pcm_file
= iocb
->ki_filp
->private_data
;
2877 substream
= pcm_file
->substream
;
2878 if (PCM_RUNTIME_CHECK(substream
))
2880 runtime
= substream
->runtime
;
2881 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2883 if (nr_segs
> 128 || nr_segs
!= runtime
->channels
||
2884 !frame_aligned(runtime
, iov
->iov_len
))
2886 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2887 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2890 for (i
= 0; i
< nr_segs
; ++i
)
2891 bufs
[i
] = iov
[i
].iov_base
;
2892 result
= snd_pcm_lib_writev(substream
, bufs
, frames
);
2894 result
= frames_to_bytes(runtime
, result
);
2899 static unsigned int snd_pcm_playback_poll(struct file
*file
, poll_table
* wait
)
2901 struct snd_pcm_file
*pcm_file
;
2902 struct snd_pcm_substream
*substream
;
2903 struct snd_pcm_runtime
*runtime
;
2905 snd_pcm_uframes_t avail
;
2907 pcm_file
= file
->private_data
;
2909 substream
= pcm_file
->substream
;
2910 if (PCM_RUNTIME_CHECK(substream
))
2912 runtime
= substream
->runtime
;
2914 poll_wait(file
, &runtime
->sleep
, wait
);
2916 snd_pcm_stream_lock_irq(substream
);
2917 avail
= snd_pcm_playback_avail(runtime
);
2918 switch (runtime
->status
->state
) {
2919 case SNDRV_PCM_STATE_RUNNING
:
2920 case SNDRV_PCM_STATE_PREPARED
:
2921 case SNDRV_PCM_STATE_PAUSED
:
2922 if (avail
>= runtime
->control
->avail_min
) {
2923 mask
= POLLOUT
| POLLWRNORM
;
2927 case SNDRV_PCM_STATE_DRAINING
:
2931 mask
= POLLOUT
| POLLWRNORM
| POLLERR
;
2934 snd_pcm_stream_unlock_irq(substream
);
2938 static unsigned int snd_pcm_capture_poll(struct file
*file
, poll_table
* wait
)
2940 struct snd_pcm_file
*pcm_file
;
2941 struct snd_pcm_substream
*substream
;
2942 struct snd_pcm_runtime
*runtime
;
2944 snd_pcm_uframes_t avail
;
2946 pcm_file
= file
->private_data
;
2948 substream
= pcm_file
->substream
;
2949 if (PCM_RUNTIME_CHECK(substream
))
2951 runtime
= substream
->runtime
;
2953 poll_wait(file
, &runtime
->sleep
, wait
);
2955 snd_pcm_stream_lock_irq(substream
);
2956 avail
= snd_pcm_capture_avail(runtime
);
2957 switch (runtime
->status
->state
) {
2958 case SNDRV_PCM_STATE_RUNNING
:
2959 case SNDRV_PCM_STATE_PREPARED
:
2960 case SNDRV_PCM_STATE_PAUSED
:
2961 if (avail
>= runtime
->control
->avail_min
) {
2962 mask
= POLLIN
| POLLRDNORM
;
2967 case SNDRV_PCM_STATE_DRAINING
:
2969 mask
= POLLIN
| POLLRDNORM
;
2974 mask
= POLLIN
| POLLRDNORM
| POLLERR
;
2977 snd_pcm_stream_unlock_irq(substream
);
2986 * Only on coherent architectures, we can mmap the status and the control records
2987 * for effcient data transfer. On others, we have to use HWSYNC ioctl...
2989 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
2991 * mmap status record
2993 static int snd_pcm_mmap_status_fault(struct vm_area_struct
*area
,
2994 struct vm_fault
*vmf
)
2996 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
2997 struct snd_pcm_runtime
*runtime
;
2999 if (substream
== NULL
)
3000 return VM_FAULT_SIGBUS
;
3001 runtime
= substream
->runtime
;
3002 vmf
->page
= virt_to_page(runtime
->status
);
3003 get_page(vmf
->page
);
3007 static const struct vm_operations_struct snd_pcm_vm_ops_status
=
3009 .fault
= snd_pcm_mmap_status_fault
,
3012 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3013 struct vm_area_struct
*area
)
3015 struct snd_pcm_runtime
*runtime
;
3017 if (!(area
->vm_flags
& VM_READ
))
3019 runtime
= substream
->runtime
;
3020 size
= area
->vm_end
- area
->vm_start
;
3021 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status
)))
3023 area
->vm_ops
= &snd_pcm_vm_ops_status
;
3024 area
->vm_private_data
= substream
;
3025 area
->vm_flags
|= VM_RESERVED
;
3030 * mmap control record
3032 static int snd_pcm_mmap_control_fault(struct vm_area_struct
*area
,
3033 struct vm_fault
*vmf
)
3035 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3036 struct snd_pcm_runtime
*runtime
;
3038 if (substream
== NULL
)
3039 return VM_FAULT_SIGBUS
;
3040 runtime
= substream
->runtime
;
3041 vmf
->page
= virt_to_page(runtime
->control
);
3042 get_page(vmf
->page
);
3046 static const struct vm_operations_struct snd_pcm_vm_ops_control
=
3048 .fault
= snd_pcm_mmap_control_fault
,
3051 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3052 struct vm_area_struct
*area
)
3054 struct snd_pcm_runtime
*runtime
;
3056 if (!(area
->vm_flags
& VM_READ
))
3058 runtime
= substream
->runtime
;
3059 size
= area
->vm_end
- area
->vm_start
;
3060 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control
)))
3062 area
->vm_ops
= &snd_pcm_vm_ops_control
;
3063 area
->vm_private_data
= substream
;
3064 area
->vm_flags
|= VM_RESERVED
;
3067 #else /* ! coherent mmap */
3069 * don't support mmap for status and control records.
3071 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3072 struct vm_area_struct
*area
)
3076 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3077 struct vm_area_struct
*area
)
3081 #endif /* coherent mmap */
3083 static inline struct page
*
3084 snd_pcm_default_page_ops(struct snd_pcm_substream
*substream
, unsigned long ofs
)
3086 void *vaddr
= substream
->runtime
->dma_area
+ ofs
;
3087 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3088 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3089 return virt_to_page(CAC_ADDR(vaddr
));
3091 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3092 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
) {
3093 dma_addr_t addr
= substream
->runtime
->dma_addr
+ ofs
;
3094 addr
-= get_dma_offset(substream
->dma_buffer
.dev
.dev
);
3095 /* assume dma_handle set via pfn_to_phys() in
3096 * mm/dma-noncoherent.c
3098 return pfn_to_page(addr
>> PAGE_SHIFT
);
3101 return virt_to_page(vaddr
);
3105 * fault callback for mmapping a RAM page
3107 static int snd_pcm_mmap_data_fault(struct vm_area_struct
*area
,
3108 struct vm_fault
*vmf
)
3110 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3111 struct snd_pcm_runtime
*runtime
;
3112 unsigned long offset
;
3116 if (substream
== NULL
)
3117 return VM_FAULT_SIGBUS
;
3118 runtime
= substream
->runtime
;
3119 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
3120 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3121 if (offset
> dma_bytes
- PAGE_SIZE
)
3122 return VM_FAULT_SIGBUS
;
3123 if (substream
->ops
->page
)
3124 page
= substream
->ops
->page(substream
, offset
);
3126 page
= snd_pcm_default_page_ops(substream
, offset
);
3128 return VM_FAULT_SIGBUS
;
3134 static const struct vm_operations_struct snd_pcm_vm_ops_data
= {
3135 .open
= snd_pcm_mmap_data_open
,
3136 .close
= snd_pcm_mmap_data_close
,
3139 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault
= {
3140 .open
= snd_pcm_mmap_data_open
,
3141 .close
= snd_pcm_mmap_data_close
,
3142 .fault
= snd_pcm_mmap_data_fault
,
3145 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3146 /* This should be defined / handled globally! */
3148 #define ARCH_HAS_DMA_MMAP_COHERENT
3153 * mmap the DMA buffer on RAM
3155 static int snd_pcm_default_mmap(struct snd_pcm_substream
*substream
,
3156 struct vm_area_struct
*area
)
3158 area
->vm_flags
|= VM_RESERVED
;
3159 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3160 if (!substream
->ops
->page
&&
3161 substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3162 return dma_mmap_coherent(substream
->dma_buffer
.dev
.dev
,
3164 substream
->runtime
->dma_area
,
3165 substream
->runtime
->dma_addr
,
3166 area
->vm_end
- area
->vm_start
);
3167 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3168 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
&&
3169 !plat_device_is_coherent(substream
->dma_buffer
.dev
.dev
))
3170 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3171 #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3172 /* mmap with fault handler */
3173 area
->vm_ops
= &snd_pcm_vm_ops_data_fault
;
3178 * mmap the DMA buffer on I/O memory area
3180 #if SNDRV_PCM_INFO_MMAP_IOMEM
3181 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream
*substream
,
3182 struct vm_area_struct
*area
)
3185 unsigned long offset
;
3187 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3188 area
->vm_flags
|= VM_IO
;
3189 size
= area
->vm_end
- area
->vm_start
;
3190 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3191 if (io_remap_pfn_range(area
, area
->vm_start
,
3192 (substream
->runtime
->dma_addr
+ offset
) >> PAGE_SHIFT
,
3193 size
, area
->vm_page_prot
))
3198 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem
);
3199 #endif /* SNDRV_PCM_INFO_MMAP */
3201 /* mmap callback with pgprot_noncached */
3202 int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream
*substream
,
3203 struct vm_area_struct
*area
)
3205 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3206 return snd_pcm_default_mmap(substream
, area
);
3208 EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached
);
3213 int snd_pcm_mmap_data(struct snd_pcm_substream
*substream
, struct file
*file
,
3214 struct vm_area_struct
*area
)
3216 struct snd_pcm_runtime
*runtime
;
3218 unsigned long offset
;
3222 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3223 if (!(area
->vm_flags
& (VM_WRITE
|VM_READ
)))
3226 if (!(area
->vm_flags
& VM_READ
))
3229 runtime
= substream
->runtime
;
3230 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
3232 if (!(runtime
->info
& SNDRV_PCM_INFO_MMAP
))
3234 if (runtime
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
||
3235 runtime
->access
== SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
)
3237 size
= area
->vm_end
- area
->vm_start
;
3238 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3239 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3240 if ((size_t)size
> dma_bytes
)
3242 if (offset
> dma_bytes
- size
)
3245 area
->vm_ops
= &snd_pcm_vm_ops_data
;
3246 area
->vm_private_data
= substream
;
3247 if (substream
->ops
->mmap
)
3248 err
= substream
->ops
->mmap(substream
, area
);
3250 err
= snd_pcm_default_mmap(substream
, area
);
3252 atomic_inc(&substream
->mmap_count
);
3256 EXPORT_SYMBOL(snd_pcm_mmap_data
);
3258 static int snd_pcm_mmap(struct file
*file
, struct vm_area_struct
*area
)
3260 struct snd_pcm_file
* pcm_file
;
3261 struct snd_pcm_substream
*substream
;
3262 unsigned long offset
;
3264 pcm_file
= file
->private_data
;
3265 substream
= pcm_file
->substream
;
3266 if (PCM_RUNTIME_CHECK(substream
))
3269 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3271 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3272 if (pcm_file
->no_compat_mmap
)
3274 return snd_pcm_mmap_status(substream
, file
, area
);
3275 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3276 if (pcm_file
->no_compat_mmap
)
3278 return snd_pcm_mmap_control(substream
, file
, area
);
3280 return snd_pcm_mmap_data(substream
, file
, area
);
3285 static int snd_pcm_fasync(int fd
, struct file
* file
, int on
)
3287 struct snd_pcm_file
* pcm_file
;
3288 struct snd_pcm_substream
*substream
;
3289 struct snd_pcm_runtime
*runtime
;
3291 pcm_file
= file
->private_data
;
3292 substream
= pcm_file
->substream
;
3293 if (PCM_RUNTIME_CHECK(substream
))
3295 runtime
= substream
->runtime
;
3296 return fasync_helper(fd
, file
, on
, &runtime
->fasync
);
3302 #ifdef CONFIG_COMPAT
3303 #include "pcm_compat.c"
3305 #define snd_pcm_ioctl_compat NULL
3309 * To be removed helpers to keep binary compatibility
3312 #ifdef CONFIG_SND_SUPPORT_OLD_API
3313 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3314 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3316 static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params
*params
,
3317 struct snd_pcm_hw_params_old
*oparams
)
3321 memset(params
, 0, sizeof(*params
));
3322 params
->flags
= oparams
->flags
;
3323 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3324 params
->masks
[i
].bits
[0] = oparams
->masks
[i
];
3325 memcpy(params
->intervals
, oparams
->intervals
, sizeof(oparams
->intervals
));
3326 params
->rmask
= __OLD_TO_NEW_MASK(oparams
->rmask
);
3327 params
->cmask
= __OLD_TO_NEW_MASK(oparams
->cmask
);
3328 params
->info
= oparams
->info
;
3329 params
->msbits
= oparams
->msbits
;
3330 params
->rate_num
= oparams
->rate_num
;
3331 params
->rate_den
= oparams
->rate_den
;
3332 params
->fifo_size
= oparams
->fifo_size
;
3335 static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old
*oparams
,
3336 struct snd_pcm_hw_params
*params
)
3340 memset(oparams
, 0, sizeof(*oparams
));
3341 oparams
->flags
= params
->flags
;
3342 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3343 oparams
->masks
[i
] = params
->masks
[i
].bits
[0];
3344 memcpy(oparams
->intervals
, params
->intervals
, sizeof(oparams
->intervals
));
3345 oparams
->rmask
= __NEW_TO_OLD_MASK(params
->rmask
);
3346 oparams
->cmask
= __NEW_TO_OLD_MASK(params
->cmask
);
3347 oparams
->info
= params
->info
;
3348 oparams
->msbits
= params
->msbits
;
3349 oparams
->rate_num
= params
->rate_num
;
3350 oparams
->rate_den
= params
->rate_den
;
3351 oparams
->fifo_size
= params
->fifo_size
;
3354 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
3355 struct snd_pcm_hw_params_old __user
* _oparams
)
3357 struct snd_pcm_hw_params
*params
;
3358 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3361 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3365 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3366 if (IS_ERR(oparams
)) {
3367 err
= PTR_ERR(oparams
);
3370 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3371 err
= snd_pcm_hw_refine(substream
, params
);
3372 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3373 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3384 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
3385 struct snd_pcm_hw_params_old __user
* _oparams
)
3387 struct snd_pcm_hw_params
*params
;
3388 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3391 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3395 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3396 if (IS_ERR(oparams
)) {
3397 err
= PTR_ERR(oparams
);
3400 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3401 err
= snd_pcm_hw_params(substream
, params
);
3402 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3403 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3413 #endif /* CONFIG_SND_SUPPORT_OLD_API */
3416 static unsigned long snd_pcm_get_unmapped_area(struct file
*file
,
3419 unsigned long pgoff
,
3420 unsigned long flags
)
3422 struct snd_pcm_file
*pcm_file
= file
->private_data
;
3423 struct snd_pcm_substream
*substream
= pcm_file
->substream
;
3424 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3425 unsigned long offset
= pgoff
<< PAGE_SHIFT
;
3428 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3429 return (unsigned long)runtime
->status
;
3430 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3431 return (unsigned long)runtime
->control
;
3433 return (unsigned long)runtime
->dma_area
+ offset
;
3437 # define snd_pcm_get_unmapped_area NULL
3444 const struct file_operations snd_pcm_f_ops
[2] = {
3446 .owner
= THIS_MODULE
,
3447 .write
= snd_pcm_write
,
3448 .aio_write
= snd_pcm_aio_write
,
3449 .open
= snd_pcm_playback_open
,
3450 .release
= snd_pcm_release
,
3451 .llseek
= no_llseek
,
3452 .poll
= snd_pcm_playback_poll
,
3453 .unlocked_ioctl
= snd_pcm_playback_ioctl
,
3454 .compat_ioctl
= snd_pcm_ioctl_compat
,
3455 .mmap
= snd_pcm_mmap
,
3456 .fasync
= snd_pcm_fasync
,
3457 .get_unmapped_area
= snd_pcm_get_unmapped_area
,
3460 .owner
= THIS_MODULE
,
3461 .read
= snd_pcm_read
,
3462 .aio_read
= snd_pcm_aio_read
,
3463 .open
= snd_pcm_capture_open
,
3464 .release
= snd_pcm_release
,
3465 .llseek
= no_llseek
,
3466 .poll
= snd_pcm_capture_poll
,
3467 .unlocked_ioctl
= snd_pcm_capture_ioctl
,
3468 .compat_ioctl
= snd_pcm_ioctl_compat
,
3469 .mmap
= snd_pcm_mmap
,
3470 .fasync
= snd_pcm_fasync
,
3471 .get_unmapped_area
= snd_pcm_get_unmapped_area
,