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
;
115 /* AB: FIXME!!! This is definitely nonsense */
117 info
->sync
= runtime
->sync
;
118 substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_INFO
, info
);
123 int snd_pcm_info_user(struct snd_pcm_substream
*substream
,
124 struct snd_pcm_info __user
* _info
)
126 struct snd_pcm_info
*info
;
129 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
132 err
= snd_pcm_info(substream
, info
);
134 if (copy_to_user(_info
, info
, sizeof(*info
)))
144 #define HW_PARAM(v) [SNDRV_PCM_HW_PARAM_##v] = #v
145 static const char * const snd_pcm_hw_param_names
[] = {
149 HW_PARAM(SAMPLE_BITS
),
150 HW_PARAM(FRAME_BITS
),
153 HW_PARAM(PERIOD_TIME
),
154 HW_PARAM(PERIOD_SIZE
),
155 HW_PARAM(PERIOD_BYTES
),
157 HW_PARAM(BUFFER_TIME
),
158 HW_PARAM(BUFFER_SIZE
),
159 HW_PARAM(BUFFER_BYTES
),
164 int snd_pcm_hw_refine(struct snd_pcm_substream
*substream
,
165 struct snd_pcm_hw_params
*params
)
168 struct snd_pcm_hardware
*hw
;
169 struct snd_interval
*i
= NULL
;
170 struct snd_mask
*m
= NULL
;
171 struct snd_pcm_hw_constraints
*constrs
= &substream
->runtime
->hw_constraints
;
172 unsigned int rstamps
[constrs
->rules_num
];
173 unsigned int vstamps
[SNDRV_PCM_HW_PARAM_LAST_INTERVAL
+ 1];
174 unsigned int stamp
= 2;
178 params
->fifo_size
= 0;
179 if (params
->rmask
& (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS
))
181 if (params
->rmask
& (1 << SNDRV_PCM_HW_PARAM_RATE
)) {
182 params
->rate_num
= 0;
183 params
->rate_den
= 0;
186 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
187 m
= hw_param_mask(params
, k
);
188 if (snd_mask_empty(m
))
190 if (!(params
->rmask
& (1 << k
)))
193 printk(KERN_DEBUG
"%s = ", snd_pcm_hw_param_names
[k
]);
194 printk("%04x%04x%04x%04x -> ", m
->bits
[3], m
->bits
[2], m
->bits
[1], m
->bits
[0]);
196 changed
= snd_mask_refine(m
, constrs_mask(constrs
, k
));
198 printk("%04x%04x%04x%04x\n", m
->bits
[3], m
->bits
[2], m
->bits
[1], m
->bits
[0]);
201 params
->cmask
|= 1 << k
;
206 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
207 i
= hw_param_interval(params
, k
);
208 if (snd_interval_empty(i
))
210 if (!(params
->rmask
& (1 << k
)))
213 printk(KERN_DEBUG
"%s = ", snd_pcm_hw_param_names
[k
]);
218 i
->openmin
? '(' : '[', i
->min
,
219 i
->max
, i
->openmax
? ')' : ']');
222 changed
= snd_interval_refine(i
, constrs_interval(constrs
, k
));
227 printk("%c%u %u%c\n",
228 i
->openmin
? '(' : '[', i
->min
,
229 i
->max
, i
->openmax
? ')' : ']');
232 params
->cmask
|= 1 << k
;
237 for (k
= 0; k
< constrs
->rules_num
; k
++)
239 for (k
= 0; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++)
240 vstamps
[k
] = (params
->rmask
& (1 << k
)) ? 1 : 0;
243 for (k
= 0; k
< constrs
->rules_num
; k
++) {
244 struct snd_pcm_hw_rule
*r
= &constrs
->rules
[k
];
247 if (r
->cond
&& !(r
->cond
& params
->flags
))
249 for (d
= 0; r
->deps
[d
] >= 0; d
++) {
250 if (vstamps
[r
->deps
[d
]] > rstamps
[k
]) {
258 printk(KERN_DEBUG
"Rule %d [%p]: ", k
, r
->func
);
260 printk("%s = ", snd_pcm_hw_param_names
[r
->var
]);
261 if (hw_is_mask(r
->var
)) {
262 m
= hw_param_mask(params
, r
->var
);
263 printk("%x", *m
->bits
);
265 i
= hw_param_interval(params
, r
->var
);
270 i
->openmin
? '(' : '[', i
->min
,
271 i
->max
, i
->openmax
? ')' : ']');
275 changed
= r
->func(params
, r
);
279 if (hw_is_mask(r
->var
))
280 printk("%x", *m
->bits
);
286 i
->openmin
? '(' : '[', i
->min
,
287 i
->max
, i
->openmax
? ')' : ']');
293 if (changed
&& r
->var
>= 0) {
294 params
->cmask
|= (1 << r
->var
);
295 vstamps
[r
->var
] = stamp
;
303 if (!params
->msbits
) {
304 i
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
);
305 if (snd_interval_single(i
))
306 params
->msbits
= snd_interval_value(i
);
309 if (!params
->rate_den
) {
310 i
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
311 if (snd_interval_single(i
)) {
312 params
->rate_num
= snd_interval_value(i
);
313 params
->rate_den
= 1;
317 hw
= &substream
->runtime
->hw
;
319 params
->info
= hw
->info
& ~SNDRV_PCM_INFO_FIFO_IN_FRAMES
;
320 if (!params
->fifo_size
) {
321 m
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
322 i
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
323 if (snd_mask_min(m
) == snd_mask_max(m
) &&
324 snd_interval_min(i
) == snd_interval_max(i
)) {
325 changed
= substream
->ops
->ioctl(substream
,
326 SNDRV_PCM_IOCTL1_FIFO_SIZE
, params
);
335 EXPORT_SYMBOL(snd_pcm_hw_refine
);
337 static int snd_pcm_hw_refine_user(struct snd_pcm_substream
*substream
,
338 struct snd_pcm_hw_params __user
* _params
)
340 struct snd_pcm_hw_params
*params
;
343 params
= memdup_user(_params
, sizeof(*params
));
345 return PTR_ERR(params
);
347 err
= snd_pcm_hw_refine(substream
, params
);
348 if (copy_to_user(_params
, params
, sizeof(*params
))) {
357 static int period_to_usecs(struct snd_pcm_runtime
*runtime
)
362 return -1; /* invalid */
364 /* take 75% of period time as the deadline */
365 usecs
= (750000 / runtime
->rate
) * runtime
->period_size
;
366 usecs
+= ((750000 % runtime
->rate
) * runtime
->period_size
) /
372 static int snd_pcm_hw_params(struct snd_pcm_substream
*substream
,
373 struct snd_pcm_hw_params
*params
)
375 struct snd_pcm_runtime
*runtime
;
378 snd_pcm_uframes_t frames
;
380 if (PCM_RUNTIME_CHECK(substream
))
382 runtime
= substream
->runtime
;
383 snd_pcm_stream_lock_irq(substream
);
384 switch (runtime
->status
->state
) {
385 case SNDRV_PCM_STATE_OPEN
:
386 case SNDRV_PCM_STATE_SETUP
:
387 case SNDRV_PCM_STATE_PREPARED
:
390 snd_pcm_stream_unlock_irq(substream
);
393 snd_pcm_stream_unlock_irq(substream
);
394 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
395 if (!substream
->oss
.oss
)
397 if (atomic_read(&substream
->mmap_count
))
401 err
= snd_pcm_hw_refine(substream
, params
);
405 err
= snd_pcm_hw_params_choose(substream
, params
);
409 if (substream
->ops
->hw_params
!= NULL
) {
410 err
= substream
->ops
->hw_params(substream
, params
);
415 runtime
->access
= params_access(params
);
416 runtime
->format
= params_format(params
);
417 runtime
->subformat
= params_subformat(params
);
418 runtime
->channels
= params_channels(params
);
419 runtime
->rate
= params_rate(params
);
420 runtime
->period_size
= params_period_size(params
);
421 runtime
->periods
= params_periods(params
);
422 runtime
->buffer_size
= params_buffer_size(params
);
423 runtime
->info
= params
->info
;
424 runtime
->rate_num
= params
->rate_num
;
425 runtime
->rate_den
= params
->rate_den
;
427 bits
= snd_pcm_format_physical_width(runtime
->format
);
428 runtime
->sample_bits
= bits
;
429 bits
*= runtime
->channels
;
430 runtime
->frame_bits
= bits
;
432 while (bits
% 8 != 0) {
436 runtime
->byte_align
= bits
/ 8;
437 runtime
->min_align
= frames
;
439 /* Default sw params */
440 runtime
->tstamp_mode
= SNDRV_PCM_TSTAMP_NONE
;
441 runtime
->period_step
= 1;
442 runtime
->control
->avail_min
= runtime
->period_size
;
443 runtime
->start_threshold
= 1;
444 runtime
->stop_threshold
= runtime
->buffer_size
;
445 runtime
->silence_threshold
= 0;
446 runtime
->silence_size
= 0;
447 runtime
->boundary
= runtime
->buffer_size
;
448 while (runtime
->boundary
* 2 <= LONG_MAX
- runtime
->buffer_size
)
449 runtime
->boundary
*= 2;
451 snd_pcm_timer_resolution_change(substream
);
452 runtime
->status
->state
= SNDRV_PCM_STATE_SETUP
;
454 if (pm_qos_request_active(&substream
->latency_pm_qos_req
))
455 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
456 if ((usecs
= period_to_usecs(runtime
)) >= 0)
457 pm_qos_add_request(&substream
->latency_pm_qos_req
,
458 PM_QOS_CPU_DMA_LATENCY
, usecs
);
461 /* hardware might be unuseable from this time,
462 so we force application to retry to set
463 the correct hardware parameter settings */
464 runtime
->status
->state
= SNDRV_PCM_STATE_OPEN
;
465 if (substream
->ops
->hw_free
!= NULL
)
466 substream
->ops
->hw_free(substream
);
470 static int snd_pcm_hw_params_user(struct snd_pcm_substream
*substream
,
471 struct snd_pcm_hw_params __user
* _params
)
473 struct snd_pcm_hw_params
*params
;
476 params
= memdup_user(_params
, sizeof(*params
));
478 return PTR_ERR(params
);
480 err
= snd_pcm_hw_params(substream
, params
);
481 if (copy_to_user(_params
, params
, sizeof(*params
))) {
490 static int snd_pcm_hw_free(struct snd_pcm_substream
*substream
)
492 struct snd_pcm_runtime
*runtime
;
495 if (PCM_RUNTIME_CHECK(substream
))
497 runtime
= substream
->runtime
;
498 snd_pcm_stream_lock_irq(substream
);
499 switch (runtime
->status
->state
) {
500 case SNDRV_PCM_STATE_SETUP
:
501 case SNDRV_PCM_STATE_PREPARED
:
504 snd_pcm_stream_unlock_irq(substream
);
507 snd_pcm_stream_unlock_irq(substream
);
508 if (atomic_read(&substream
->mmap_count
))
510 if (substream
->ops
->hw_free
)
511 result
= substream
->ops
->hw_free(substream
);
512 runtime
->status
->state
= SNDRV_PCM_STATE_OPEN
;
513 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
517 static int snd_pcm_sw_params(struct snd_pcm_substream
*substream
,
518 struct snd_pcm_sw_params
*params
)
520 struct snd_pcm_runtime
*runtime
;
523 if (PCM_RUNTIME_CHECK(substream
))
525 runtime
= substream
->runtime
;
526 snd_pcm_stream_lock_irq(substream
);
527 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
) {
528 snd_pcm_stream_unlock_irq(substream
);
531 snd_pcm_stream_unlock_irq(substream
);
533 if (params
->tstamp_mode
> SNDRV_PCM_TSTAMP_LAST
)
535 if (params
->avail_min
== 0)
537 if (params
->silence_size
>= runtime
->boundary
) {
538 if (params
->silence_threshold
!= 0)
541 if (params
->silence_size
> params
->silence_threshold
)
543 if (params
->silence_threshold
> runtime
->buffer_size
)
547 snd_pcm_stream_lock_irq(substream
);
548 runtime
->tstamp_mode
= params
->tstamp_mode
;
549 runtime
->period_step
= params
->period_step
;
550 runtime
->control
->avail_min
= params
->avail_min
;
551 runtime
->start_threshold
= params
->start_threshold
;
552 runtime
->stop_threshold
= params
->stop_threshold
;
553 runtime
->silence_threshold
= params
->silence_threshold
;
554 runtime
->silence_size
= params
->silence_size
;
555 params
->boundary
= runtime
->boundary
;
556 if (snd_pcm_running(substream
)) {
557 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
558 runtime
->silence_size
> 0)
559 snd_pcm_playback_silence(substream
, ULONG_MAX
);
560 err
= snd_pcm_update_state(substream
, runtime
);
562 snd_pcm_stream_unlock_irq(substream
);
566 static int snd_pcm_sw_params_user(struct snd_pcm_substream
*substream
,
567 struct snd_pcm_sw_params __user
* _params
)
569 struct snd_pcm_sw_params params
;
571 if (copy_from_user(¶ms
, _params
, sizeof(params
)))
573 err
= snd_pcm_sw_params(substream
, ¶ms
);
574 if (copy_to_user(_params
, ¶ms
, sizeof(params
)))
579 int snd_pcm_status(struct snd_pcm_substream
*substream
,
580 struct snd_pcm_status
*status
)
582 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
584 snd_pcm_stream_lock_irq(substream
);
585 status
->state
= runtime
->status
->state
;
586 status
->suspended_state
= runtime
->status
->suspended_state
;
587 if (status
->state
== SNDRV_PCM_STATE_OPEN
)
589 status
->trigger_tstamp
= runtime
->trigger_tstamp
;
590 if (snd_pcm_running(substream
)) {
591 snd_pcm_update_hw_ptr(substream
);
592 if (runtime
->tstamp_mode
== SNDRV_PCM_TSTAMP_ENABLE
) {
593 status
->tstamp
= runtime
->status
->tstamp
;
597 snd_pcm_gettime(runtime
, &status
->tstamp
);
599 status
->appl_ptr
= runtime
->control
->appl_ptr
;
600 status
->hw_ptr
= runtime
->status
->hw_ptr
;
601 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
602 status
->avail
= snd_pcm_playback_avail(runtime
);
603 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
||
604 runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
605 status
->delay
= runtime
->buffer_size
- status
->avail
;
606 status
->delay
+= runtime
->delay
;
610 status
->avail
= snd_pcm_capture_avail(runtime
);
611 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
)
612 status
->delay
= status
->avail
+ runtime
->delay
;
616 status
->avail_max
= runtime
->avail_max
;
617 status
->overrange
= runtime
->overrange
;
618 runtime
->avail_max
= 0;
619 runtime
->overrange
= 0;
621 snd_pcm_stream_unlock_irq(substream
);
625 static int snd_pcm_status_user(struct snd_pcm_substream
*substream
,
626 struct snd_pcm_status __user
* _status
)
628 struct snd_pcm_status status
;
631 memset(&status
, 0, sizeof(status
));
632 res
= snd_pcm_status(substream
, &status
);
635 if (copy_to_user(_status
, &status
, sizeof(status
)))
640 static int snd_pcm_channel_info(struct snd_pcm_substream
*substream
,
641 struct snd_pcm_channel_info
* info
)
643 struct snd_pcm_runtime
*runtime
;
644 unsigned int channel
;
646 channel
= info
->channel
;
647 runtime
= substream
->runtime
;
648 snd_pcm_stream_lock_irq(substream
);
649 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
) {
650 snd_pcm_stream_unlock_irq(substream
);
653 snd_pcm_stream_unlock_irq(substream
);
654 if (channel
>= runtime
->channels
)
656 memset(info
, 0, sizeof(*info
));
657 info
->channel
= channel
;
658 return substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_CHANNEL_INFO
, info
);
661 static int snd_pcm_channel_info_user(struct snd_pcm_substream
*substream
,
662 struct snd_pcm_channel_info __user
* _info
)
664 struct snd_pcm_channel_info info
;
667 if (copy_from_user(&info
, _info
, sizeof(info
)))
669 res
= snd_pcm_channel_info(substream
, &info
);
672 if (copy_to_user(_info
, &info
, sizeof(info
)))
677 static void snd_pcm_trigger_tstamp(struct snd_pcm_substream
*substream
)
679 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
680 if (runtime
->trigger_master
== NULL
)
682 if (runtime
->trigger_master
== substream
) {
683 snd_pcm_gettime(runtime
, &runtime
->trigger_tstamp
);
685 snd_pcm_trigger_tstamp(runtime
->trigger_master
);
686 runtime
->trigger_tstamp
= runtime
->trigger_master
->runtime
->trigger_tstamp
;
688 runtime
->trigger_master
= NULL
;
692 int (*pre_action
)(struct snd_pcm_substream
*substream
, int state
);
693 int (*do_action
)(struct snd_pcm_substream
*substream
, int state
);
694 void (*undo_action
)(struct snd_pcm_substream
*substream
, int state
);
695 void (*post_action
)(struct snd_pcm_substream
*substream
, int state
);
699 * this functions is core for handling of linked stream
700 * Note: the stream state might be changed also on failure
701 * Note2: call with calling stream lock + link lock
703 static int snd_pcm_action_group(struct action_ops
*ops
,
704 struct snd_pcm_substream
*substream
,
705 int state
, int do_lock
)
707 struct snd_pcm_substream
*s
= NULL
;
708 struct snd_pcm_substream
*s1
;
711 snd_pcm_group_for_each_entry(s
, substream
) {
712 if (do_lock
&& s
!= substream
)
713 spin_lock_nested(&s
->self_group
.lock
,
714 SINGLE_DEPTH_NESTING
);
715 res
= ops
->pre_action(s
, state
);
719 snd_pcm_group_for_each_entry(s
, substream
) {
720 res
= ops
->do_action(s
, state
);
722 if (ops
->undo_action
) {
723 snd_pcm_group_for_each_entry(s1
, substream
) {
724 if (s1
== s
) /* failed stream */
726 ops
->undo_action(s1
, state
);
729 s
= NULL
; /* unlock all */
733 snd_pcm_group_for_each_entry(s
, substream
) {
734 ops
->post_action(s
, state
);
739 snd_pcm_group_for_each_entry(s1
, substream
) {
741 spin_unlock(&s1
->self_group
.lock
);
742 if (s1
== s
) /* end */
750 * Note: call with stream lock
752 static int snd_pcm_action_single(struct action_ops
*ops
,
753 struct snd_pcm_substream
*substream
,
758 res
= ops
->pre_action(substream
, state
);
761 res
= ops
->do_action(substream
, state
);
763 ops
->post_action(substream
, state
);
764 else if (ops
->undo_action
)
765 ops
->undo_action(substream
, state
);
770 * Note: call with stream lock
772 static int snd_pcm_action(struct action_ops
*ops
,
773 struct snd_pcm_substream
*substream
,
778 if (snd_pcm_stream_linked(substream
)) {
779 if (!spin_trylock(&substream
->group
->lock
)) {
780 spin_unlock(&substream
->self_group
.lock
);
781 spin_lock(&substream
->group
->lock
);
782 spin_lock(&substream
->self_group
.lock
);
784 res
= snd_pcm_action_group(ops
, substream
, state
, 1);
785 spin_unlock(&substream
->group
->lock
);
787 res
= snd_pcm_action_single(ops
, substream
, state
);
793 * Note: don't use any locks before
795 static int snd_pcm_action_lock_irq(struct action_ops
*ops
,
796 struct snd_pcm_substream
*substream
,
801 read_lock_irq(&snd_pcm_link_rwlock
);
802 if (snd_pcm_stream_linked(substream
)) {
803 spin_lock(&substream
->group
->lock
);
804 spin_lock(&substream
->self_group
.lock
);
805 res
= snd_pcm_action_group(ops
, substream
, state
, 1);
806 spin_unlock(&substream
->self_group
.lock
);
807 spin_unlock(&substream
->group
->lock
);
809 spin_lock(&substream
->self_group
.lock
);
810 res
= snd_pcm_action_single(ops
, substream
, state
);
811 spin_unlock(&substream
->self_group
.lock
);
813 read_unlock_irq(&snd_pcm_link_rwlock
);
819 static int snd_pcm_action_nonatomic(struct action_ops
*ops
,
820 struct snd_pcm_substream
*substream
,
825 down_read(&snd_pcm_link_rwsem
);
826 if (snd_pcm_stream_linked(substream
))
827 res
= snd_pcm_action_group(ops
, substream
, state
, 0);
829 res
= snd_pcm_action_single(ops
, substream
, state
);
830 up_read(&snd_pcm_link_rwsem
);
837 static int snd_pcm_pre_start(struct snd_pcm_substream
*substream
, int state
)
839 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
840 if (runtime
->status
->state
!= SNDRV_PCM_STATE_PREPARED
)
842 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
843 !snd_pcm_playback_data(substream
))
845 runtime
->trigger_master
= substream
;
849 static int snd_pcm_do_start(struct snd_pcm_substream
*substream
, int state
)
851 if (substream
->runtime
->trigger_master
!= substream
)
853 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_START
);
856 static void snd_pcm_undo_start(struct snd_pcm_substream
*substream
, int state
)
858 if (substream
->runtime
->trigger_master
== substream
)
859 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
862 static void snd_pcm_post_start(struct snd_pcm_substream
*substream
, int state
)
864 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
865 snd_pcm_trigger_tstamp(substream
);
866 runtime
->hw_ptr_jiffies
= jiffies
;
867 runtime
->hw_ptr_buffer_jiffies
= (runtime
->buffer_size
* HZ
) /
869 runtime
->status
->state
= state
;
870 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
871 runtime
->silence_size
> 0)
872 snd_pcm_playback_silence(substream
, ULONG_MAX
);
873 if (substream
->timer
)
874 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTART
,
875 &runtime
->trigger_tstamp
);
878 static struct action_ops snd_pcm_action_start
= {
879 .pre_action
= snd_pcm_pre_start
,
880 .do_action
= snd_pcm_do_start
,
881 .undo_action
= snd_pcm_undo_start
,
882 .post_action
= snd_pcm_post_start
886 * snd_pcm_start - start all linked streams
887 * @substream: the PCM substream instance
889 int snd_pcm_start(struct snd_pcm_substream
*substream
)
891 return snd_pcm_action(&snd_pcm_action_start
, substream
,
892 SNDRV_PCM_STATE_RUNNING
);
898 static int snd_pcm_pre_stop(struct snd_pcm_substream
*substream
, int state
)
900 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
901 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
903 runtime
->trigger_master
= substream
;
907 static int snd_pcm_do_stop(struct snd_pcm_substream
*substream
, int state
)
909 if (substream
->runtime
->trigger_master
== substream
&&
910 snd_pcm_running(substream
))
911 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
912 return 0; /* unconditonally stop all substreams */
915 static void snd_pcm_post_stop(struct snd_pcm_substream
*substream
, int state
)
917 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
918 if (runtime
->status
->state
!= state
) {
919 snd_pcm_trigger_tstamp(substream
);
920 if (substream
->timer
)
921 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTOP
,
922 &runtime
->trigger_tstamp
);
923 runtime
->status
->state
= state
;
925 wake_up(&runtime
->sleep
);
926 wake_up(&runtime
->tsleep
);
929 static struct action_ops snd_pcm_action_stop
= {
930 .pre_action
= snd_pcm_pre_stop
,
931 .do_action
= snd_pcm_do_stop
,
932 .post_action
= snd_pcm_post_stop
936 * snd_pcm_stop - try to stop all running streams in the substream group
937 * @substream: the PCM substream instance
938 * @state: PCM state after stopping the stream
940 * The state of each stream is then changed to the given state unconditionally.
942 int snd_pcm_stop(struct snd_pcm_substream
*substream
, int state
)
944 return snd_pcm_action(&snd_pcm_action_stop
, substream
, state
);
947 EXPORT_SYMBOL(snd_pcm_stop
);
950 * snd_pcm_drain_done - stop the DMA only when the given stream is playback
951 * @substream: the PCM substream
953 * After stopping, the state is changed to SETUP.
954 * Unlike snd_pcm_stop(), this affects only the given stream.
956 int snd_pcm_drain_done(struct snd_pcm_substream
*substream
)
958 return snd_pcm_action_single(&snd_pcm_action_stop
, substream
,
959 SNDRV_PCM_STATE_SETUP
);
965 static int snd_pcm_pre_pause(struct snd_pcm_substream
*substream
, int push
)
967 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
968 if (!(runtime
->info
& SNDRV_PCM_INFO_PAUSE
))
971 if (runtime
->status
->state
!= SNDRV_PCM_STATE_RUNNING
)
973 } else if (runtime
->status
->state
!= SNDRV_PCM_STATE_PAUSED
)
975 runtime
->trigger_master
= substream
;
979 static int snd_pcm_do_pause(struct snd_pcm_substream
*substream
, int push
)
981 if (substream
->runtime
->trigger_master
!= substream
)
983 /* some drivers might use hw_ptr to recover from the pause -
984 update the hw_ptr now */
986 snd_pcm_update_hw_ptr(substream
);
987 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
988 * a delta betwen the current jiffies, this gives a large enough
989 * delta, effectively to skip the check once.
991 substream
->runtime
->hw_ptr_jiffies
= jiffies
- HZ
* 1000;
992 return substream
->ops
->trigger(substream
,
993 push
? SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
994 SNDRV_PCM_TRIGGER_PAUSE_RELEASE
);
997 static void snd_pcm_undo_pause(struct snd_pcm_substream
*substream
, int push
)
999 if (substream
->runtime
->trigger_master
== substream
)
1000 substream
->ops
->trigger(substream
,
1001 push
? SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1002 SNDRV_PCM_TRIGGER_PAUSE_PUSH
);
1005 static void snd_pcm_post_pause(struct snd_pcm_substream
*substream
, int push
)
1007 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1008 snd_pcm_trigger_tstamp(substream
);
1010 runtime
->status
->state
= SNDRV_PCM_STATE_PAUSED
;
1011 if (substream
->timer
)
1012 snd_timer_notify(substream
->timer
,
1013 SNDRV_TIMER_EVENT_MPAUSE
,
1014 &runtime
->trigger_tstamp
);
1015 wake_up(&runtime
->sleep
);
1016 wake_up(&runtime
->tsleep
);
1018 runtime
->status
->state
= SNDRV_PCM_STATE_RUNNING
;
1019 if (substream
->timer
)
1020 snd_timer_notify(substream
->timer
,
1021 SNDRV_TIMER_EVENT_MCONTINUE
,
1022 &runtime
->trigger_tstamp
);
1026 static struct action_ops snd_pcm_action_pause
= {
1027 .pre_action
= snd_pcm_pre_pause
,
1028 .do_action
= snd_pcm_do_pause
,
1029 .undo_action
= snd_pcm_undo_pause
,
1030 .post_action
= snd_pcm_post_pause
1034 * Push/release the pause for all linked streams.
1036 static int snd_pcm_pause(struct snd_pcm_substream
*substream
, int push
)
1038 return snd_pcm_action(&snd_pcm_action_pause
, substream
, push
);
1044 static int snd_pcm_pre_suspend(struct snd_pcm_substream
*substream
, int state
)
1046 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1047 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1049 runtime
->trigger_master
= substream
;
1053 static int snd_pcm_do_suspend(struct snd_pcm_substream
*substream
, int state
)
1055 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1056 if (runtime
->trigger_master
!= substream
)
1058 if (! snd_pcm_running(substream
))
1060 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1061 return 0; /* suspend unconditionally */
1064 static void snd_pcm_post_suspend(struct snd_pcm_substream
*substream
, int state
)
1066 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1067 snd_pcm_trigger_tstamp(substream
);
1068 if (substream
->timer
)
1069 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSUSPEND
,
1070 &runtime
->trigger_tstamp
);
1071 runtime
->status
->suspended_state
= runtime
->status
->state
;
1072 runtime
->status
->state
= SNDRV_PCM_STATE_SUSPENDED
;
1073 wake_up(&runtime
->sleep
);
1074 wake_up(&runtime
->tsleep
);
1077 static struct action_ops snd_pcm_action_suspend
= {
1078 .pre_action
= snd_pcm_pre_suspend
,
1079 .do_action
= snd_pcm_do_suspend
,
1080 .post_action
= snd_pcm_post_suspend
1084 * snd_pcm_suspend - trigger SUSPEND to all linked streams
1085 * @substream: the PCM substream
1087 * After this call, all streams are changed to SUSPENDED state.
1089 int snd_pcm_suspend(struct snd_pcm_substream
*substream
)
1092 unsigned long flags
;
1097 snd_pcm_stream_lock_irqsave(substream
, flags
);
1098 err
= snd_pcm_action(&snd_pcm_action_suspend
, substream
, 0);
1099 snd_pcm_stream_unlock_irqrestore(substream
, flags
);
1103 EXPORT_SYMBOL(snd_pcm_suspend
);
1106 * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm
1107 * @pcm: the PCM instance
1109 * After this call, all streams are changed to SUSPENDED state.
1111 int snd_pcm_suspend_all(struct snd_pcm
*pcm
)
1113 struct snd_pcm_substream
*substream
;
1114 int stream
, err
= 0;
1119 for (stream
= 0; stream
< 2; stream
++) {
1120 for (substream
= pcm
->streams
[stream
].substream
;
1121 substream
; substream
= substream
->next
) {
1122 /* FIXME: the open/close code should lock this as well */
1123 if (substream
->runtime
== NULL
)
1125 err
= snd_pcm_suspend(substream
);
1126 if (err
< 0 && err
!= -EBUSY
)
1133 EXPORT_SYMBOL(snd_pcm_suspend_all
);
1137 static int snd_pcm_pre_resume(struct snd_pcm_substream
*substream
, int state
)
1139 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1140 if (!(runtime
->info
& SNDRV_PCM_INFO_RESUME
))
1142 runtime
->trigger_master
= substream
;
1146 static int snd_pcm_do_resume(struct snd_pcm_substream
*substream
, int state
)
1148 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1149 if (runtime
->trigger_master
!= substream
)
1151 /* DMA not running previously? */
1152 if (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_RUNNING
&&
1153 (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_DRAINING
||
1154 substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
1156 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_RESUME
);
1159 static void snd_pcm_undo_resume(struct snd_pcm_substream
*substream
, int state
)
1161 if (substream
->runtime
->trigger_master
== substream
&&
1162 snd_pcm_running(substream
))
1163 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1166 static void snd_pcm_post_resume(struct snd_pcm_substream
*substream
, int state
)
1168 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1169 snd_pcm_trigger_tstamp(substream
);
1170 if (substream
->timer
)
1171 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MRESUME
,
1172 &runtime
->trigger_tstamp
);
1173 runtime
->status
->state
= runtime
->status
->suspended_state
;
1176 static struct action_ops snd_pcm_action_resume
= {
1177 .pre_action
= snd_pcm_pre_resume
,
1178 .do_action
= snd_pcm_do_resume
,
1179 .undo_action
= snd_pcm_undo_resume
,
1180 .post_action
= snd_pcm_post_resume
1183 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1185 struct snd_card
*card
= substream
->pcm
->card
;
1188 snd_power_lock(card
);
1189 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1190 res
= snd_pcm_action_lock_irq(&snd_pcm_action_resume
, substream
, 0);
1191 snd_power_unlock(card
);
1197 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1202 #endif /* CONFIG_PM */
1207 * Change the RUNNING stream(s) to XRUN state.
1209 static int snd_pcm_xrun(struct snd_pcm_substream
*substream
)
1211 struct snd_card
*card
= substream
->pcm
->card
;
1212 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1215 snd_power_lock(card
);
1216 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1217 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1222 snd_pcm_stream_lock_irq(substream
);
1223 switch (runtime
->status
->state
) {
1224 case SNDRV_PCM_STATE_XRUN
:
1225 result
= 0; /* already there */
1227 case SNDRV_PCM_STATE_RUNNING
:
1228 result
= snd_pcm_stop(substream
, SNDRV_PCM_STATE_XRUN
);
1233 snd_pcm_stream_unlock_irq(substream
);
1235 snd_power_unlock(card
);
1242 static int snd_pcm_pre_reset(struct snd_pcm_substream
*substream
, int state
)
1244 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1245 switch (runtime
->status
->state
) {
1246 case SNDRV_PCM_STATE_RUNNING
:
1247 case SNDRV_PCM_STATE_PREPARED
:
1248 case SNDRV_PCM_STATE_PAUSED
:
1249 case SNDRV_PCM_STATE_SUSPENDED
:
1256 static int snd_pcm_do_reset(struct snd_pcm_substream
*substream
, int state
)
1258 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1259 int err
= substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_RESET
, NULL
);
1262 runtime
->hw_ptr_base
= 0;
1263 runtime
->hw_ptr_interrupt
= runtime
->status
->hw_ptr
-
1264 runtime
->status
->hw_ptr
% runtime
->period_size
;
1265 runtime
->silence_start
= runtime
->status
->hw_ptr
;
1266 runtime
->silence_filled
= 0;
1270 static void snd_pcm_post_reset(struct snd_pcm_substream
*substream
, int state
)
1272 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1273 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1274 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
1275 runtime
->silence_size
> 0)
1276 snd_pcm_playback_silence(substream
, ULONG_MAX
);
1279 static struct action_ops snd_pcm_action_reset
= {
1280 .pre_action
= snd_pcm_pre_reset
,
1281 .do_action
= snd_pcm_do_reset
,
1282 .post_action
= snd_pcm_post_reset
1285 static int snd_pcm_reset(struct snd_pcm_substream
*substream
)
1287 return snd_pcm_action_nonatomic(&snd_pcm_action_reset
, substream
, 0);
1293 /* we use the second argument for updating f_flags */
1294 static int snd_pcm_pre_prepare(struct snd_pcm_substream
*substream
,
1297 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1298 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1299 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
)
1301 if (snd_pcm_running(substream
))
1303 substream
->f_flags
= f_flags
;
1307 static int snd_pcm_do_prepare(struct snd_pcm_substream
*substream
, int state
)
1310 err
= substream
->ops
->prepare(substream
);
1313 return snd_pcm_do_reset(substream
, 0);
1316 static void snd_pcm_post_prepare(struct snd_pcm_substream
*substream
, int state
)
1318 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1319 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1320 runtime
->status
->state
= SNDRV_PCM_STATE_PREPARED
;
1323 static struct action_ops snd_pcm_action_prepare
= {
1324 .pre_action
= snd_pcm_pre_prepare
,
1325 .do_action
= snd_pcm_do_prepare
,
1326 .post_action
= snd_pcm_post_prepare
1330 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1331 * @substream: the PCM substream instance
1332 * @file: file to refer f_flags
1334 static int snd_pcm_prepare(struct snd_pcm_substream
*substream
,
1338 struct snd_card
*card
= substream
->pcm
->card
;
1342 f_flags
= file
->f_flags
;
1344 f_flags
= substream
->f_flags
;
1346 snd_power_lock(card
);
1347 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1348 res
= snd_pcm_action_nonatomic(&snd_pcm_action_prepare
,
1349 substream
, f_flags
);
1350 snd_power_unlock(card
);
1358 static int snd_pcm_pre_drain_init(struct snd_pcm_substream
*substream
, int state
)
1360 substream
->runtime
->trigger_master
= substream
;
1364 static int snd_pcm_do_drain_init(struct snd_pcm_substream
*substream
, int state
)
1366 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1367 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1368 switch (runtime
->status
->state
) {
1369 case SNDRV_PCM_STATE_PREPARED
:
1370 /* start playback stream if possible */
1371 if (! snd_pcm_playback_empty(substream
)) {
1372 snd_pcm_do_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1373 snd_pcm_post_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1376 case SNDRV_PCM_STATE_RUNNING
:
1377 runtime
->status
->state
= SNDRV_PCM_STATE_DRAINING
;
1383 /* stop running stream */
1384 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
) {
1385 int new_state
= snd_pcm_capture_avail(runtime
) > 0 ?
1386 SNDRV_PCM_STATE_DRAINING
: SNDRV_PCM_STATE_SETUP
;
1387 snd_pcm_do_stop(substream
, new_state
);
1388 snd_pcm_post_stop(substream
, new_state
);
1394 static void snd_pcm_post_drain_init(struct snd_pcm_substream
*substream
, int state
)
1398 static struct action_ops snd_pcm_action_drain_init
= {
1399 .pre_action
= snd_pcm_pre_drain_init
,
1400 .do_action
= snd_pcm_do_drain_init
,
1401 .post_action
= snd_pcm_post_drain_init
1404 static int snd_pcm_drop(struct snd_pcm_substream
*substream
);
1407 * Drain the stream(s).
1408 * When the substream is linked, sync until the draining of all playback streams
1410 * After this call, all streams are supposed to be either SETUP or DRAINING
1411 * (capture only) state.
1413 static int snd_pcm_drain(struct snd_pcm_substream
*substream
,
1416 struct snd_card
*card
;
1417 struct snd_pcm_runtime
*runtime
;
1418 struct snd_pcm_substream
*s
;
1423 card
= substream
->pcm
->card
;
1424 runtime
= substream
->runtime
;
1426 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
1429 snd_power_lock(card
);
1430 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1431 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1433 snd_power_unlock(card
);
1439 if (file
->f_flags
& O_NONBLOCK
)
1441 } else if (substream
->f_flags
& O_NONBLOCK
)
1444 down_read(&snd_pcm_link_rwsem
);
1445 snd_pcm_stream_lock_irq(substream
);
1447 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1448 snd_pcm_pause(substream
, 0);
1450 /* pre-start/stop - all running streams are changed to DRAINING state */
1451 result
= snd_pcm_action(&snd_pcm_action_drain_init
, substream
, 0);
1454 /* in non-blocking, we don't wait in ioctl but let caller poll */
1462 struct snd_pcm_runtime
*to_check
;
1463 if (signal_pending(current
)) {
1464 result
= -ERESTARTSYS
;
1467 /* find a substream to drain */
1469 snd_pcm_group_for_each_entry(s
, substream
) {
1470 if (s
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1472 runtime
= s
->runtime
;
1473 if (runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
1479 break; /* all drained */
1480 init_waitqueue_entry(&wait
, current
);
1481 add_wait_queue(&to_check
->sleep
, &wait
);
1482 set_current_state(TASK_INTERRUPTIBLE
);
1483 snd_pcm_stream_unlock_irq(substream
);
1484 up_read(&snd_pcm_link_rwsem
);
1485 snd_power_unlock(card
);
1486 tout
= schedule_timeout(10 * HZ
);
1487 snd_power_lock(card
);
1488 down_read(&snd_pcm_link_rwsem
);
1489 snd_pcm_stream_lock_irq(substream
);
1490 remove_wait_queue(&to_check
->sleep
, &wait
);
1492 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1495 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1496 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1504 snd_pcm_stream_unlock_irq(substream
);
1505 up_read(&snd_pcm_link_rwsem
);
1506 snd_power_unlock(card
);
1514 * Immediately put all linked substreams into SETUP state.
1516 static int snd_pcm_drop(struct snd_pcm_substream
*substream
)
1518 struct snd_pcm_runtime
*runtime
;
1519 struct snd_card
*card
;
1522 if (PCM_RUNTIME_CHECK(substream
))
1524 runtime
= substream
->runtime
;
1525 card
= substream
->pcm
->card
;
1527 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1528 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
||
1529 runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1532 snd_pcm_stream_lock_irq(substream
);
1534 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1535 snd_pcm_pause(substream
, 0);
1537 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1538 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */
1539 snd_pcm_stream_unlock_irq(substream
);
1545 /* WARNING: Don't forget to fput back the file */
1546 static struct file
*snd_pcm_file_fd(int fd
)
1549 struct inode
*inode
;
1555 inode
= file
->f_path
.dentry
->d_inode
;
1556 if (!S_ISCHR(inode
->i_mode
) ||
1557 imajor(inode
) != snd_major
) {
1561 minor
= iminor(inode
);
1562 if (!snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_PLAYBACK
) &&
1563 !snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_CAPTURE
)) {
1573 static int snd_pcm_link(struct snd_pcm_substream
*substream
, int fd
)
1577 struct snd_pcm_file
*pcm_file
;
1578 struct snd_pcm_substream
*substream1
;
1580 file
= snd_pcm_file_fd(fd
);
1583 pcm_file
= file
->private_data
;
1584 substream1
= pcm_file
->substream
;
1585 down_write(&snd_pcm_link_rwsem
);
1586 write_lock_irq(&snd_pcm_link_rwlock
);
1587 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1588 substream
->runtime
->status
->state
!= substream1
->runtime
->status
->state
) {
1592 if (snd_pcm_stream_linked(substream1
)) {
1596 if (!snd_pcm_stream_linked(substream
)) {
1597 substream
->group
= kmalloc(sizeof(struct snd_pcm_group
), GFP_ATOMIC
);
1598 if (substream
->group
== NULL
) {
1602 spin_lock_init(&substream
->group
->lock
);
1603 INIT_LIST_HEAD(&substream
->group
->substreams
);
1604 list_add_tail(&substream
->link_list
, &substream
->group
->substreams
);
1605 substream
->group
->count
= 1;
1607 list_add_tail(&substream1
->link_list
, &substream
->group
->substreams
);
1608 substream
->group
->count
++;
1609 substream1
->group
= substream
->group
;
1611 write_unlock_irq(&snd_pcm_link_rwlock
);
1612 up_write(&snd_pcm_link_rwsem
);
1617 static void relink_to_local(struct snd_pcm_substream
*substream
)
1619 substream
->group
= &substream
->self_group
;
1620 INIT_LIST_HEAD(&substream
->self_group
.substreams
);
1621 list_add_tail(&substream
->link_list
, &substream
->self_group
.substreams
);
1624 static int snd_pcm_unlink(struct snd_pcm_substream
*substream
)
1626 struct snd_pcm_substream
*s
;
1629 down_write(&snd_pcm_link_rwsem
);
1630 write_lock_irq(&snd_pcm_link_rwlock
);
1631 if (!snd_pcm_stream_linked(substream
)) {
1635 list_del(&substream
->link_list
);
1636 substream
->group
->count
--;
1637 if (substream
->group
->count
== 1) { /* detach the last stream, too */
1638 snd_pcm_group_for_each_entry(s
, substream
) {
1642 kfree(substream
->group
);
1644 relink_to_local(substream
);
1646 write_unlock_irq(&snd_pcm_link_rwlock
);
1647 up_write(&snd_pcm_link_rwsem
);
1654 static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params
*params
,
1655 struct snd_pcm_hw_rule
*rule
)
1657 struct snd_interval t
;
1658 snd_interval_mul(hw_param_interval_c(params
, rule
->deps
[0]),
1659 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1660 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1663 static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params
*params
,
1664 struct snd_pcm_hw_rule
*rule
)
1666 struct snd_interval t
;
1667 snd_interval_div(hw_param_interval_c(params
, rule
->deps
[0]),
1668 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1669 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1672 static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params
*params
,
1673 struct snd_pcm_hw_rule
*rule
)
1675 struct snd_interval t
;
1676 snd_interval_muldivk(hw_param_interval_c(params
, rule
->deps
[0]),
1677 hw_param_interval_c(params
, rule
->deps
[1]),
1678 (unsigned long) rule
->private, &t
);
1679 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1682 static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params
*params
,
1683 struct snd_pcm_hw_rule
*rule
)
1685 struct snd_interval t
;
1686 snd_interval_mulkdiv(hw_param_interval_c(params
, rule
->deps
[0]),
1687 (unsigned long) rule
->private,
1688 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1689 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1692 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params
*params
,
1693 struct snd_pcm_hw_rule
*rule
)
1696 struct snd_interval
*i
= hw_param_interval(params
, rule
->deps
[0]);
1698 struct snd_mask
*mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
1700 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1702 if (! snd_mask_test(mask
, k
))
1704 bits
= snd_pcm_format_physical_width(k
);
1706 continue; /* ignore invalid formats */
1707 if ((unsigned)bits
< i
->min
|| (unsigned)bits
> i
->max
)
1708 snd_mask_reset(&m
, k
);
1710 return snd_mask_refine(mask
, &m
);
1713 static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params
*params
,
1714 struct snd_pcm_hw_rule
*rule
)
1716 struct snd_interval t
;
1722 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1724 if (! snd_mask_test(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), k
))
1726 bits
= snd_pcm_format_physical_width(k
);
1728 continue; /* ignore invalid formats */
1729 if (t
.min
> (unsigned)bits
)
1731 if (t
.max
< (unsigned)bits
)
1735 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1738 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1739 #error "Change this table"
1742 static unsigned int rates
[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1743 48000, 64000, 88200, 96000, 176400, 192000 };
1745 const struct snd_pcm_hw_constraint_list snd_pcm_known_rates
= {
1746 .count
= ARRAY_SIZE(rates
),
1750 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params
*params
,
1751 struct snd_pcm_hw_rule
*rule
)
1753 struct snd_pcm_hardware
*hw
= rule
->private;
1754 return snd_interval_list(hw_param_interval(params
, rule
->var
),
1755 snd_pcm_known_rates
.count
,
1756 snd_pcm_known_rates
.list
, hw
->rates
);
1759 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params
*params
,
1760 struct snd_pcm_hw_rule
*rule
)
1762 struct snd_interval t
;
1763 struct snd_pcm_substream
*substream
= rule
->private;
1765 t
.max
= substream
->buffer_bytes_max
;
1769 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1772 int snd_pcm_hw_constraints_init(struct snd_pcm_substream
*substream
)
1774 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1775 struct snd_pcm_hw_constraints
*constrs
= &runtime
->hw_constraints
;
1778 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
1779 snd_mask_any(constrs_mask(constrs
, k
));
1782 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
1783 snd_interval_any(constrs_interval(constrs
, k
));
1786 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_CHANNELS
));
1787 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
));
1788 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
));
1789 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
));
1790 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_FRAME_BITS
));
1792 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FORMAT
,
1793 snd_pcm_hw_rule_format
, NULL
,
1794 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1797 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1798 snd_pcm_hw_rule_sample_bits
, NULL
,
1799 SNDRV_PCM_HW_PARAM_FORMAT
,
1800 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1803 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1804 snd_pcm_hw_rule_div
, NULL
,
1805 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1808 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1809 snd_pcm_hw_rule_mul
, NULL
,
1810 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1813 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1814 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1815 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1818 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1819 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1820 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, -1);
1823 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1824 snd_pcm_hw_rule_div
, NULL
,
1825 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1828 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1829 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1830 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_TIME
, -1);
1833 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1834 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1835 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
, -1);
1838 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
,
1839 snd_pcm_hw_rule_div
, NULL
,
1840 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1843 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1844 snd_pcm_hw_rule_div
, NULL
,
1845 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1848 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1849 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1850 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1853 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1854 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1855 SNDRV_PCM_HW_PARAM_PERIOD_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1858 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1859 snd_pcm_hw_rule_mul
, NULL
,
1860 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1863 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1864 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1865 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1868 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1869 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1870 SNDRV_PCM_HW_PARAM_BUFFER_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1873 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1874 snd_pcm_hw_rule_muldivk
, (void*) 8,
1875 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1878 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1879 snd_pcm_hw_rule_muldivk
, (void*) 8,
1880 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1883 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1884 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1885 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1888 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
1889 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1890 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1896 int snd_pcm_hw_constraints_complete(struct snd_pcm_substream
*substream
)
1898 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1899 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
1901 unsigned int mask
= 0;
1903 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1904 mask
|= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED
;
1905 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1906 mask
|= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
;
1907 if (hw
->info
& SNDRV_PCM_INFO_MMAP
) {
1908 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1909 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED
;
1910 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1911 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED
;
1912 if (hw
->info
& SNDRV_PCM_INFO_COMPLEX
)
1913 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX
;
1915 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_ACCESS
, mask
);
1919 err
= snd_pcm_hw_constraint_mask64(runtime
, SNDRV_PCM_HW_PARAM_FORMAT
, hw
->formats
);
1923 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_SUBFORMAT
, 1 << SNDRV_PCM_SUBFORMAT_STD
);
1927 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_CHANNELS
,
1928 hw
->channels_min
, hw
->channels_max
);
1932 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
1933 hw
->rate_min
, hw
->rate_max
);
1937 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1938 hw
->period_bytes_min
, hw
->period_bytes_max
);
1942 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
,
1943 hw
->periods_min
, hw
->periods_max
);
1947 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1948 hw
->period_bytes_min
, hw
->buffer_bytes_max
);
1952 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1953 snd_pcm_hw_rule_buffer_bytes_max
, substream
,
1954 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, -1);
1959 if (runtime
->dma_bytes
) {
1960 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 0, runtime
->dma_bytes
);
1965 if (!(hw
->rates
& (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_CONTINUOUS
))) {
1966 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1967 snd_pcm_hw_rule_rate
, hw
,
1968 SNDRV_PCM_HW_PARAM_RATE
, -1);
1973 /* FIXME: this belong to lowlevel */
1974 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
1979 static void pcm_release_private(struct snd_pcm_substream
*substream
)
1981 snd_pcm_unlink(substream
);
1984 void snd_pcm_release_substream(struct snd_pcm_substream
*substream
)
1986 substream
->ref_count
--;
1987 if (substream
->ref_count
> 0)
1990 snd_pcm_drop(substream
);
1991 if (substream
->hw_opened
) {
1992 if (substream
->ops
->hw_free
!= NULL
)
1993 substream
->ops
->hw_free(substream
);
1994 substream
->ops
->close(substream
);
1995 substream
->hw_opened
= 0;
1997 if (pm_qos_request_active(&substream
->latency_pm_qos_req
))
1998 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
1999 if (substream
->pcm_release
) {
2000 substream
->pcm_release(substream
);
2001 substream
->pcm_release
= NULL
;
2003 snd_pcm_detach_substream(substream
);
2006 EXPORT_SYMBOL(snd_pcm_release_substream
);
2008 int snd_pcm_open_substream(struct snd_pcm
*pcm
, int stream
,
2010 struct snd_pcm_substream
**rsubstream
)
2012 struct snd_pcm_substream
*substream
;
2015 err
= snd_pcm_attach_substream(pcm
, stream
, file
, &substream
);
2018 if (substream
->ref_count
> 1) {
2019 *rsubstream
= substream
;
2023 err
= snd_pcm_hw_constraints_init(substream
);
2025 snd_printd("snd_pcm_hw_constraints_init failed\n");
2029 if ((err
= substream
->ops
->open(substream
)) < 0)
2032 substream
->hw_opened
= 1;
2034 err
= snd_pcm_hw_constraints_complete(substream
);
2036 snd_printd("snd_pcm_hw_constraints_complete failed\n");
2040 *rsubstream
= substream
;
2044 snd_pcm_release_substream(substream
);
2048 EXPORT_SYMBOL(snd_pcm_open_substream
);
2050 static int snd_pcm_open_file(struct file
*file
,
2051 struct snd_pcm
*pcm
,
2053 struct snd_pcm_file
**rpcm_file
)
2055 struct snd_pcm_file
*pcm_file
;
2056 struct snd_pcm_substream
*substream
;
2057 struct snd_pcm_str
*str
;
2063 err
= snd_pcm_open_substream(pcm
, stream
, file
, &substream
);
2067 pcm_file
= kzalloc(sizeof(*pcm_file
), GFP_KERNEL
);
2068 if (pcm_file
== NULL
) {
2069 snd_pcm_release_substream(substream
);
2072 pcm_file
->substream
= substream
;
2073 if (substream
->ref_count
== 1) {
2074 str
= substream
->pstr
;
2075 substream
->file
= pcm_file
;
2076 substream
->pcm_release
= pcm_release_private
;
2078 file
->private_data
= pcm_file
;
2080 *rpcm_file
= pcm_file
;
2084 static int snd_pcm_playback_open(struct inode
*inode
, struct file
*file
)
2086 struct snd_pcm
*pcm
;
2087 int err
= nonseekable_open(inode
, file
);
2090 pcm
= snd_lookup_minor_data(iminor(inode
),
2091 SNDRV_DEVICE_TYPE_PCM_PLAYBACK
);
2092 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_PLAYBACK
);
2095 static int snd_pcm_capture_open(struct inode
*inode
, struct file
*file
)
2097 struct snd_pcm
*pcm
;
2098 int err
= nonseekable_open(inode
, file
);
2101 pcm
= snd_lookup_minor_data(iminor(inode
),
2102 SNDRV_DEVICE_TYPE_PCM_CAPTURE
);
2103 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_CAPTURE
);
2106 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
)
2109 struct snd_pcm_file
*pcm_file
;
2116 err
= snd_card_file_add(pcm
->card
, file
);
2119 if (!try_module_get(pcm
->card
->module
)) {
2123 init_waitqueue_entry(&wait
, current
);
2124 add_wait_queue(&pcm
->open_wait
, &wait
);
2125 mutex_lock(&pcm
->open_mutex
);
2127 err
= snd_pcm_open_file(file
, pcm
, stream
, &pcm_file
);
2130 if (err
== -EAGAIN
) {
2131 if (file
->f_flags
& O_NONBLOCK
) {
2137 set_current_state(TASK_INTERRUPTIBLE
);
2138 mutex_unlock(&pcm
->open_mutex
);
2140 mutex_lock(&pcm
->open_mutex
);
2141 if (signal_pending(current
)) {
2146 remove_wait_queue(&pcm
->open_wait
, &wait
);
2147 mutex_unlock(&pcm
->open_mutex
);
2153 module_put(pcm
->card
->module
);
2155 snd_card_file_remove(pcm
->card
, file
);
2160 static int snd_pcm_release(struct inode
*inode
, struct file
*file
)
2162 struct snd_pcm
*pcm
;
2163 struct snd_pcm_substream
*substream
;
2164 struct snd_pcm_file
*pcm_file
;
2166 pcm_file
= file
->private_data
;
2167 substream
= pcm_file
->substream
;
2168 if (snd_BUG_ON(!substream
))
2170 pcm
= substream
->pcm
;
2171 mutex_lock(&pcm
->open_mutex
);
2172 snd_pcm_release_substream(substream
);
2174 mutex_unlock(&pcm
->open_mutex
);
2175 wake_up(&pcm
->open_wait
);
2176 module_put(pcm
->card
->module
);
2177 snd_card_file_remove(pcm
->card
, file
);
2181 static snd_pcm_sframes_t
snd_pcm_playback_rewind(struct snd_pcm_substream
*substream
,
2182 snd_pcm_uframes_t frames
)
2184 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2185 snd_pcm_sframes_t appl_ptr
;
2186 snd_pcm_sframes_t ret
;
2187 snd_pcm_sframes_t hw_avail
;
2192 snd_pcm_stream_lock_irq(substream
);
2193 switch (runtime
->status
->state
) {
2194 case SNDRV_PCM_STATE_PREPARED
:
2196 case SNDRV_PCM_STATE_DRAINING
:
2197 case SNDRV_PCM_STATE_RUNNING
:
2198 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2201 case SNDRV_PCM_STATE_XRUN
:
2204 case SNDRV_PCM_STATE_SUSPENDED
:
2212 hw_avail
= snd_pcm_playback_hw_avail(runtime
);
2213 if (hw_avail
<= 0) {
2217 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2219 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2221 appl_ptr
+= runtime
->boundary
;
2222 runtime
->control
->appl_ptr
= appl_ptr
;
2225 snd_pcm_stream_unlock_irq(substream
);
2229 static snd_pcm_sframes_t
snd_pcm_capture_rewind(struct snd_pcm_substream
*substream
,
2230 snd_pcm_uframes_t frames
)
2232 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2233 snd_pcm_sframes_t appl_ptr
;
2234 snd_pcm_sframes_t ret
;
2235 snd_pcm_sframes_t hw_avail
;
2240 snd_pcm_stream_lock_irq(substream
);
2241 switch (runtime
->status
->state
) {
2242 case SNDRV_PCM_STATE_PREPARED
:
2243 case SNDRV_PCM_STATE_DRAINING
:
2245 case SNDRV_PCM_STATE_RUNNING
:
2246 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2249 case SNDRV_PCM_STATE_XRUN
:
2252 case SNDRV_PCM_STATE_SUSPENDED
:
2260 hw_avail
= snd_pcm_capture_hw_avail(runtime
);
2261 if (hw_avail
<= 0) {
2265 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2267 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2269 appl_ptr
+= runtime
->boundary
;
2270 runtime
->control
->appl_ptr
= appl_ptr
;
2273 snd_pcm_stream_unlock_irq(substream
);
2277 static snd_pcm_sframes_t
snd_pcm_playback_forward(struct snd_pcm_substream
*substream
,
2278 snd_pcm_uframes_t frames
)
2280 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2281 snd_pcm_sframes_t appl_ptr
;
2282 snd_pcm_sframes_t ret
;
2283 snd_pcm_sframes_t avail
;
2288 snd_pcm_stream_lock_irq(substream
);
2289 switch (runtime
->status
->state
) {
2290 case SNDRV_PCM_STATE_PREPARED
:
2291 case SNDRV_PCM_STATE_PAUSED
:
2293 case SNDRV_PCM_STATE_DRAINING
:
2294 case SNDRV_PCM_STATE_RUNNING
:
2295 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2298 case SNDRV_PCM_STATE_XRUN
:
2301 case SNDRV_PCM_STATE_SUSPENDED
:
2309 avail
= snd_pcm_playback_avail(runtime
);
2314 if (frames
> (snd_pcm_uframes_t
)avail
)
2316 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2317 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2318 appl_ptr
-= runtime
->boundary
;
2319 runtime
->control
->appl_ptr
= appl_ptr
;
2322 snd_pcm_stream_unlock_irq(substream
);
2326 static snd_pcm_sframes_t
snd_pcm_capture_forward(struct snd_pcm_substream
*substream
,
2327 snd_pcm_uframes_t frames
)
2329 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2330 snd_pcm_sframes_t appl_ptr
;
2331 snd_pcm_sframes_t ret
;
2332 snd_pcm_sframes_t avail
;
2337 snd_pcm_stream_lock_irq(substream
);
2338 switch (runtime
->status
->state
) {
2339 case SNDRV_PCM_STATE_PREPARED
:
2340 case SNDRV_PCM_STATE_DRAINING
:
2341 case SNDRV_PCM_STATE_PAUSED
:
2343 case SNDRV_PCM_STATE_RUNNING
:
2344 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2347 case SNDRV_PCM_STATE_XRUN
:
2350 case SNDRV_PCM_STATE_SUSPENDED
:
2358 avail
= snd_pcm_capture_avail(runtime
);
2363 if (frames
> (snd_pcm_uframes_t
)avail
)
2365 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2366 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2367 appl_ptr
-= runtime
->boundary
;
2368 runtime
->control
->appl_ptr
= appl_ptr
;
2371 snd_pcm_stream_unlock_irq(substream
);
2375 static int snd_pcm_hwsync(struct snd_pcm_substream
*substream
)
2377 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2380 snd_pcm_stream_lock_irq(substream
);
2381 switch (runtime
->status
->state
) {
2382 case SNDRV_PCM_STATE_DRAINING
:
2383 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2385 case SNDRV_PCM_STATE_RUNNING
:
2386 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2389 case SNDRV_PCM_STATE_PREPARED
:
2390 case SNDRV_PCM_STATE_SUSPENDED
:
2393 case SNDRV_PCM_STATE_XRUN
:
2401 snd_pcm_stream_unlock_irq(substream
);
2405 static int snd_pcm_delay(struct snd_pcm_substream
*substream
,
2406 snd_pcm_sframes_t __user
*res
)
2408 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2410 snd_pcm_sframes_t n
= 0;
2412 snd_pcm_stream_lock_irq(substream
);
2413 switch (runtime
->status
->state
) {
2414 case SNDRV_PCM_STATE_DRAINING
:
2415 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2417 case SNDRV_PCM_STATE_RUNNING
:
2418 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2421 case SNDRV_PCM_STATE_PREPARED
:
2422 case SNDRV_PCM_STATE_SUSPENDED
:
2424 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2425 n
= snd_pcm_playback_hw_avail(runtime
);
2427 n
= snd_pcm_capture_avail(runtime
);
2428 n
+= runtime
->delay
;
2430 case SNDRV_PCM_STATE_XRUN
:
2438 snd_pcm_stream_unlock_irq(substream
);
2440 if (put_user(n
, res
))
2445 static int snd_pcm_sync_ptr(struct snd_pcm_substream
*substream
,
2446 struct snd_pcm_sync_ptr __user
*_sync_ptr
)
2448 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2449 struct snd_pcm_sync_ptr sync_ptr
;
2450 volatile struct snd_pcm_mmap_status
*status
;
2451 volatile struct snd_pcm_mmap_control
*control
;
2454 memset(&sync_ptr
, 0, sizeof(sync_ptr
));
2455 if (get_user(sync_ptr
.flags
, (unsigned __user
*)&(_sync_ptr
->flags
)))
2457 if (copy_from_user(&sync_ptr
.c
.control
, &(_sync_ptr
->c
.control
), sizeof(struct snd_pcm_mmap_control
)))
2459 status
= runtime
->status
;
2460 control
= runtime
->control
;
2461 if (sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
2462 err
= snd_pcm_hwsync(substream
);
2466 snd_pcm_stream_lock_irq(substream
);
2467 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_APPL
))
2468 control
->appl_ptr
= sync_ptr
.c
.control
.appl_ptr
;
2470 sync_ptr
.c
.control
.appl_ptr
= control
->appl_ptr
;
2471 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
2472 control
->avail_min
= sync_ptr
.c
.control
.avail_min
;
2474 sync_ptr
.c
.control
.avail_min
= control
->avail_min
;
2475 sync_ptr
.s
.status
.state
= status
->state
;
2476 sync_ptr
.s
.status
.hw_ptr
= status
->hw_ptr
;
2477 sync_ptr
.s
.status
.tstamp
= status
->tstamp
;
2478 sync_ptr
.s
.status
.suspended_state
= status
->suspended_state
;
2479 snd_pcm_stream_unlock_irq(substream
);
2480 if (copy_to_user(_sync_ptr
, &sync_ptr
, sizeof(sync_ptr
)))
2485 static int snd_pcm_tstamp(struct snd_pcm_substream
*substream
, int __user
*_arg
)
2487 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2490 if (get_user(arg
, _arg
))
2492 if (arg
< 0 || arg
> SNDRV_PCM_TSTAMP_TYPE_LAST
)
2494 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY
;
2495 if (arg
== SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
)
2496 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
;
2500 static int snd_pcm_common_ioctl1(struct file
*file
,
2501 struct snd_pcm_substream
*substream
,
2502 unsigned int cmd
, void __user
*arg
)
2505 case SNDRV_PCM_IOCTL_PVERSION
:
2506 return put_user(SNDRV_PCM_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2507 case SNDRV_PCM_IOCTL_INFO
:
2508 return snd_pcm_info_user(substream
, arg
);
2509 case SNDRV_PCM_IOCTL_TSTAMP
: /* just for compatibility */
2511 case SNDRV_PCM_IOCTL_TTSTAMP
:
2512 return snd_pcm_tstamp(substream
, arg
);
2513 case SNDRV_PCM_IOCTL_HW_REFINE
:
2514 return snd_pcm_hw_refine_user(substream
, arg
);
2515 case SNDRV_PCM_IOCTL_HW_PARAMS
:
2516 return snd_pcm_hw_params_user(substream
, arg
);
2517 case SNDRV_PCM_IOCTL_HW_FREE
:
2518 return snd_pcm_hw_free(substream
);
2519 case SNDRV_PCM_IOCTL_SW_PARAMS
:
2520 return snd_pcm_sw_params_user(substream
, arg
);
2521 case SNDRV_PCM_IOCTL_STATUS
:
2522 return snd_pcm_status_user(substream
, arg
);
2523 case SNDRV_PCM_IOCTL_CHANNEL_INFO
:
2524 return snd_pcm_channel_info_user(substream
, arg
);
2525 case SNDRV_PCM_IOCTL_PREPARE
:
2526 return snd_pcm_prepare(substream
, file
);
2527 case SNDRV_PCM_IOCTL_RESET
:
2528 return snd_pcm_reset(substream
);
2529 case SNDRV_PCM_IOCTL_START
:
2530 return snd_pcm_action_lock_irq(&snd_pcm_action_start
, substream
, SNDRV_PCM_STATE_RUNNING
);
2531 case SNDRV_PCM_IOCTL_LINK
:
2532 return snd_pcm_link(substream
, (int)(unsigned long) arg
);
2533 case SNDRV_PCM_IOCTL_UNLINK
:
2534 return snd_pcm_unlink(substream
);
2535 case SNDRV_PCM_IOCTL_RESUME
:
2536 return snd_pcm_resume(substream
);
2537 case SNDRV_PCM_IOCTL_XRUN
:
2538 return snd_pcm_xrun(substream
);
2539 case SNDRV_PCM_IOCTL_HWSYNC
:
2540 return snd_pcm_hwsync(substream
);
2541 case SNDRV_PCM_IOCTL_DELAY
:
2542 return snd_pcm_delay(substream
, arg
);
2543 case SNDRV_PCM_IOCTL_SYNC_PTR
:
2544 return snd_pcm_sync_ptr(substream
, arg
);
2545 #ifdef CONFIG_SND_SUPPORT_OLD_API
2546 case SNDRV_PCM_IOCTL_HW_REFINE_OLD
:
2547 return snd_pcm_hw_refine_old_user(substream
, arg
);
2548 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD
:
2549 return snd_pcm_hw_params_old_user(substream
, arg
);
2551 case SNDRV_PCM_IOCTL_DRAIN
:
2552 return snd_pcm_drain(substream
, file
);
2553 case SNDRV_PCM_IOCTL_DROP
:
2554 return snd_pcm_drop(substream
);
2555 case SNDRV_PCM_IOCTL_PAUSE
:
2558 snd_pcm_stream_lock_irq(substream
);
2559 res
= snd_pcm_pause(substream
, (int)(unsigned long)arg
);
2560 snd_pcm_stream_unlock_irq(substream
);
2564 snd_printd("unknown ioctl = 0x%x\n", cmd
);
2568 static int snd_pcm_playback_ioctl1(struct file
*file
,
2569 struct snd_pcm_substream
*substream
,
2570 unsigned int cmd
, void __user
*arg
)
2572 if (snd_BUG_ON(!substream
))
2574 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
2577 case SNDRV_PCM_IOCTL_WRITEI_FRAMES
:
2579 struct snd_xferi xferi
;
2580 struct snd_xferi __user
*_xferi
= arg
;
2581 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2582 snd_pcm_sframes_t result
;
2583 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2585 if (put_user(0, &_xferi
->result
))
2587 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2589 result
= snd_pcm_lib_write(substream
, xferi
.buf
, xferi
.frames
);
2590 __put_user(result
, &_xferi
->result
);
2591 return result
< 0 ? result
: 0;
2593 case SNDRV_PCM_IOCTL_WRITEN_FRAMES
:
2595 struct snd_xfern xfern
;
2596 struct snd_xfern __user
*_xfern
= arg
;
2597 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2599 snd_pcm_sframes_t result
;
2600 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2602 if (runtime
->channels
> 128)
2604 if (put_user(0, &_xfern
->result
))
2606 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2609 bufs
= memdup_user(xfern
.bufs
,
2610 sizeof(void *) * runtime
->channels
);
2612 return PTR_ERR(bufs
);
2613 result
= snd_pcm_lib_writev(substream
, bufs
, xfern
.frames
);
2615 __put_user(result
, &_xfern
->result
);
2616 return result
< 0 ? result
: 0;
2618 case SNDRV_PCM_IOCTL_REWIND
:
2620 snd_pcm_uframes_t frames
;
2621 snd_pcm_uframes_t __user
*_frames
= arg
;
2622 snd_pcm_sframes_t result
;
2623 if (get_user(frames
, _frames
))
2625 if (put_user(0, _frames
))
2627 result
= snd_pcm_playback_rewind(substream
, frames
);
2628 __put_user(result
, _frames
);
2629 return result
< 0 ? result
: 0;
2631 case SNDRV_PCM_IOCTL_FORWARD
:
2633 snd_pcm_uframes_t frames
;
2634 snd_pcm_uframes_t __user
*_frames
= arg
;
2635 snd_pcm_sframes_t result
;
2636 if (get_user(frames
, _frames
))
2638 if (put_user(0, _frames
))
2640 result
= snd_pcm_playback_forward(substream
, frames
);
2641 __put_user(result
, _frames
);
2642 return result
< 0 ? result
: 0;
2645 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2648 static int snd_pcm_capture_ioctl1(struct file
*file
,
2649 struct snd_pcm_substream
*substream
,
2650 unsigned int cmd
, void __user
*arg
)
2652 if (snd_BUG_ON(!substream
))
2654 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_CAPTURE
))
2657 case SNDRV_PCM_IOCTL_READI_FRAMES
:
2659 struct snd_xferi xferi
;
2660 struct snd_xferi __user
*_xferi
= arg
;
2661 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2662 snd_pcm_sframes_t result
;
2663 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2665 if (put_user(0, &_xferi
->result
))
2667 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2669 result
= snd_pcm_lib_read(substream
, xferi
.buf
, xferi
.frames
);
2670 __put_user(result
, &_xferi
->result
);
2671 return result
< 0 ? result
: 0;
2673 case SNDRV_PCM_IOCTL_READN_FRAMES
:
2675 struct snd_xfern xfern
;
2676 struct snd_xfern __user
*_xfern
= arg
;
2677 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2679 snd_pcm_sframes_t result
;
2680 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2682 if (runtime
->channels
> 128)
2684 if (put_user(0, &_xfern
->result
))
2686 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2689 bufs
= memdup_user(xfern
.bufs
,
2690 sizeof(void *) * runtime
->channels
);
2692 return PTR_ERR(bufs
);
2693 result
= snd_pcm_lib_readv(substream
, bufs
, xfern
.frames
);
2695 __put_user(result
, &_xfern
->result
);
2696 return result
< 0 ? result
: 0;
2698 case SNDRV_PCM_IOCTL_REWIND
:
2700 snd_pcm_uframes_t frames
;
2701 snd_pcm_uframes_t __user
*_frames
= arg
;
2702 snd_pcm_sframes_t result
;
2703 if (get_user(frames
, _frames
))
2705 if (put_user(0, _frames
))
2707 result
= snd_pcm_capture_rewind(substream
, frames
);
2708 __put_user(result
, _frames
);
2709 return result
< 0 ? result
: 0;
2711 case SNDRV_PCM_IOCTL_FORWARD
:
2713 snd_pcm_uframes_t frames
;
2714 snd_pcm_uframes_t __user
*_frames
= arg
;
2715 snd_pcm_sframes_t result
;
2716 if (get_user(frames
, _frames
))
2718 if (put_user(0, _frames
))
2720 result
= snd_pcm_capture_forward(substream
, frames
);
2721 __put_user(result
, _frames
);
2722 return result
< 0 ? result
: 0;
2725 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2728 static long snd_pcm_playback_ioctl(struct file
*file
, unsigned int cmd
,
2731 struct snd_pcm_file
*pcm_file
;
2733 pcm_file
= file
->private_data
;
2735 if (((cmd
>> 8) & 0xff) != 'A')
2738 return snd_pcm_playback_ioctl1(file
, pcm_file
->substream
, cmd
,
2739 (void __user
*)arg
);
2742 static long snd_pcm_capture_ioctl(struct file
*file
, unsigned int cmd
,
2745 struct snd_pcm_file
*pcm_file
;
2747 pcm_file
= file
->private_data
;
2749 if (((cmd
>> 8) & 0xff) != 'A')
2752 return snd_pcm_capture_ioctl1(file
, pcm_file
->substream
, cmd
,
2753 (void __user
*)arg
);
2756 int snd_pcm_kernel_ioctl(struct snd_pcm_substream
*substream
,
2757 unsigned int cmd
, void *arg
)
2762 fs
= snd_enter_user();
2763 switch (substream
->stream
) {
2764 case SNDRV_PCM_STREAM_PLAYBACK
:
2765 result
= snd_pcm_playback_ioctl1(NULL
, substream
, cmd
,
2766 (void __user
*)arg
);
2768 case SNDRV_PCM_STREAM_CAPTURE
:
2769 result
= snd_pcm_capture_ioctl1(NULL
, substream
, cmd
,
2770 (void __user
*)arg
);
2780 EXPORT_SYMBOL(snd_pcm_kernel_ioctl
);
2782 static ssize_t
snd_pcm_read(struct file
*file
, char __user
*buf
, size_t count
,
2785 struct snd_pcm_file
*pcm_file
;
2786 struct snd_pcm_substream
*substream
;
2787 struct snd_pcm_runtime
*runtime
;
2788 snd_pcm_sframes_t result
;
2790 pcm_file
= file
->private_data
;
2791 substream
= pcm_file
->substream
;
2792 if (PCM_RUNTIME_CHECK(substream
))
2794 runtime
= substream
->runtime
;
2795 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2797 if (!frame_aligned(runtime
, count
))
2799 count
= bytes_to_frames(runtime
, count
);
2800 result
= snd_pcm_lib_read(substream
, buf
, count
);
2802 result
= frames_to_bytes(runtime
, result
);
2806 static ssize_t
snd_pcm_write(struct file
*file
, const char __user
*buf
,
2807 size_t count
, loff_t
* offset
)
2809 struct snd_pcm_file
*pcm_file
;
2810 struct snd_pcm_substream
*substream
;
2811 struct snd_pcm_runtime
*runtime
;
2812 snd_pcm_sframes_t result
;
2814 pcm_file
= file
->private_data
;
2815 substream
= pcm_file
->substream
;
2816 if (PCM_RUNTIME_CHECK(substream
))
2818 runtime
= substream
->runtime
;
2819 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2821 if (!frame_aligned(runtime
, count
))
2823 count
= bytes_to_frames(runtime
, count
);
2824 result
= snd_pcm_lib_write(substream
, buf
, count
);
2826 result
= frames_to_bytes(runtime
, result
);
2830 static ssize_t
snd_pcm_aio_read(struct kiocb
*iocb
, const struct iovec
*iov
,
2831 unsigned long nr_segs
, loff_t pos
)
2834 struct snd_pcm_file
*pcm_file
;
2835 struct snd_pcm_substream
*substream
;
2836 struct snd_pcm_runtime
*runtime
;
2837 snd_pcm_sframes_t result
;
2840 snd_pcm_uframes_t frames
;
2842 pcm_file
= iocb
->ki_filp
->private_data
;
2843 substream
= pcm_file
->substream
;
2844 if (PCM_RUNTIME_CHECK(substream
))
2846 runtime
= substream
->runtime
;
2847 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2849 if (nr_segs
> 1024 || nr_segs
!= runtime
->channels
)
2851 if (!frame_aligned(runtime
, iov
->iov_len
))
2853 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2854 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2857 for (i
= 0; i
< nr_segs
; ++i
)
2858 bufs
[i
] = iov
[i
].iov_base
;
2859 result
= snd_pcm_lib_readv(substream
, bufs
, frames
);
2861 result
= frames_to_bytes(runtime
, result
);
2866 static ssize_t
snd_pcm_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
2867 unsigned long nr_segs
, loff_t pos
)
2869 struct snd_pcm_file
*pcm_file
;
2870 struct snd_pcm_substream
*substream
;
2871 struct snd_pcm_runtime
*runtime
;
2872 snd_pcm_sframes_t result
;
2875 snd_pcm_uframes_t frames
;
2877 pcm_file
= iocb
->ki_filp
->private_data
;
2878 substream
= pcm_file
->substream
;
2879 if (PCM_RUNTIME_CHECK(substream
))
2881 runtime
= substream
->runtime
;
2882 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2884 if (nr_segs
> 128 || nr_segs
!= runtime
->channels
||
2885 !frame_aligned(runtime
, iov
->iov_len
))
2887 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2888 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2891 for (i
= 0; i
< nr_segs
; ++i
)
2892 bufs
[i
] = iov
[i
].iov_base
;
2893 result
= snd_pcm_lib_writev(substream
, bufs
, frames
);
2895 result
= frames_to_bytes(runtime
, result
);
2900 static unsigned int snd_pcm_playback_poll(struct file
*file
, poll_table
* wait
)
2902 struct snd_pcm_file
*pcm_file
;
2903 struct snd_pcm_substream
*substream
;
2904 struct snd_pcm_runtime
*runtime
;
2906 snd_pcm_uframes_t avail
;
2908 pcm_file
= file
->private_data
;
2910 substream
= pcm_file
->substream
;
2911 if (PCM_RUNTIME_CHECK(substream
))
2913 runtime
= substream
->runtime
;
2915 poll_wait(file
, &runtime
->sleep
, wait
);
2917 snd_pcm_stream_lock_irq(substream
);
2918 avail
= snd_pcm_playback_avail(runtime
);
2919 switch (runtime
->status
->state
) {
2920 case SNDRV_PCM_STATE_RUNNING
:
2921 case SNDRV_PCM_STATE_PREPARED
:
2922 case SNDRV_PCM_STATE_PAUSED
:
2923 if (avail
>= runtime
->control
->avail_min
) {
2924 mask
= POLLOUT
| POLLWRNORM
;
2928 case SNDRV_PCM_STATE_DRAINING
:
2932 mask
= POLLOUT
| POLLWRNORM
| POLLERR
;
2935 snd_pcm_stream_unlock_irq(substream
);
2939 static unsigned int snd_pcm_capture_poll(struct file
*file
, poll_table
* wait
)
2941 struct snd_pcm_file
*pcm_file
;
2942 struct snd_pcm_substream
*substream
;
2943 struct snd_pcm_runtime
*runtime
;
2945 snd_pcm_uframes_t avail
;
2947 pcm_file
= file
->private_data
;
2949 substream
= pcm_file
->substream
;
2950 if (PCM_RUNTIME_CHECK(substream
))
2952 runtime
= substream
->runtime
;
2954 poll_wait(file
, &runtime
->sleep
, wait
);
2956 snd_pcm_stream_lock_irq(substream
);
2957 avail
= snd_pcm_capture_avail(runtime
);
2958 switch (runtime
->status
->state
) {
2959 case SNDRV_PCM_STATE_RUNNING
:
2960 case SNDRV_PCM_STATE_PREPARED
:
2961 case SNDRV_PCM_STATE_PAUSED
:
2962 if (avail
>= runtime
->control
->avail_min
) {
2963 mask
= POLLIN
| POLLRDNORM
;
2968 case SNDRV_PCM_STATE_DRAINING
:
2970 mask
= POLLIN
| POLLRDNORM
;
2975 mask
= POLLIN
| POLLRDNORM
| POLLERR
;
2978 snd_pcm_stream_unlock_irq(substream
);
2987 * Only on coherent architectures, we can mmap the status and the control records
2988 * for effcient data transfer. On others, we have to use HWSYNC ioctl...
2990 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
2992 * mmap status record
2994 static int snd_pcm_mmap_status_fault(struct vm_area_struct
*area
,
2995 struct vm_fault
*vmf
)
2997 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
2998 struct snd_pcm_runtime
*runtime
;
3000 if (substream
== NULL
)
3001 return VM_FAULT_SIGBUS
;
3002 runtime
= substream
->runtime
;
3003 vmf
->page
= virt_to_page(runtime
->status
);
3004 get_page(vmf
->page
);
3008 static const struct vm_operations_struct snd_pcm_vm_ops_status
=
3010 .fault
= snd_pcm_mmap_status_fault
,
3013 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3014 struct vm_area_struct
*area
)
3016 struct snd_pcm_runtime
*runtime
;
3018 if (!(area
->vm_flags
& VM_READ
))
3020 runtime
= substream
->runtime
;
3021 size
= area
->vm_end
- area
->vm_start
;
3022 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status
)))
3024 area
->vm_ops
= &snd_pcm_vm_ops_status
;
3025 area
->vm_private_data
= substream
;
3026 area
->vm_flags
|= VM_RESERVED
;
3031 * mmap control record
3033 static int snd_pcm_mmap_control_fault(struct vm_area_struct
*area
,
3034 struct vm_fault
*vmf
)
3036 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3037 struct snd_pcm_runtime
*runtime
;
3039 if (substream
== NULL
)
3040 return VM_FAULT_SIGBUS
;
3041 runtime
= substream
->runtime
;
3042 vmf
->page
= virt_to_page(runtime
->control
);
3043 get_page(vmf
->page
);
3047 static const struct vm_operations_struct snd_pcm_vm_ops_control
=
3049 .fault
= snd_pcm_mmap_control_fault
,
3052 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3053 struct vm_area_struct
*area
)
3055 struct snd_pcm_runtime
*runtime
;
3057 if (!(area
->vm_flags
& VM_READ
))
3059 runtime
= substream
->runtime
;
3060 size
= area
->vm_end
- area
->vm_start
;
3061 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control
)))
3063 area
->vm_ops
= &snd_pcm_vm_ops_control
;
3064 area
->vm_private_data
= substream
;
3065 area
->vm_flags
|= VM_RESERVED
;
3068 #else /* ! coherent mmap */
3070 * don't support mmap for status and control records.
3072 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3073 struct vm_area_struct
*area
)
3077 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3078 struct vm_area_struct
*area
)
3082 #endif /* coherent mmap */
3084 static inline struct page
*
3085 snd_pcm_default_page_ops(struct snd_pcm_substream
*substream
, unsigned long ofs
)
3087 void *vaddr
= substream
->runtime
->dma_area
+ ofs
;
3088 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3089 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3090 return virt_to_page(CAC_ADDR(vaddr
));
3092 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3093 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
) {
3094 dma_addr_t addr
= substream
->runtime
->dma_addr
+ ofs
;
3095 addr
-= get_dma_offset(substream
->dma_buffer
.dev
.dev
);
3096 /* assume dma_handle set via pfn_to_phys() in
3097 * mm/dma-noncoherent.c
3099 return pfn_to_page(addr
>> PAGE_SHIFT
);
3102 return virt_to_page(vaddr
);
3106 * fault callback for mmapping a RAM page
3108 static int snd_pcm_mmap_data_fault(struct vm_area_struct
*area
,
3109 struct vm_fault
*vmf
)
3111 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3112 struct snd_pcm_runtime
*runtime
;
3113 unsigned long offset
;
3117 if (substream
== NULL
)
3118 return VM_FAULT_SIGBUS
;
3119 runtime
= substream
->runtime
;
3120 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
3121 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3122 if (offset
> dma_bytes
- PAGE_SIZE
)
3123 return VM_FAULT_SIGBUS
;
3124 if (substream
->ops
->page
)
3125 page
= substream
->ops
->page(substream
, offset
);
3127 page
= snd_pcm_default_page_ops(substream
, offset
);
3129 return VM_FAULT_SIGBUS
;
3135 static const struct vm_operations_struct snd_pcm_vm_ops_data
= {
3136 .open
= snd_pcm_mmap_data_open
,
3137 .close
= snd_pcm_mmap_data_close
,
3140 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault
= {
3141 .open
= snd_pcm_mmap_data_open
,
3142 .close
= snd_pcm_mmap_data_close
,
3143 .fault
= snd_pcm_mmap_data_fault
,
3146 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3147 /* This should be defined / handled globally! */
3149 #define ARCH_HAS_DMA_MMAP_COHERENT
3154 * mmap the DMA buffer on RAM
3156 static int snd_pcm_default_mmap(struct snd_pcm_substream
*substream
,
3157 struct vm_area_struct
*area
)
3159 area
->vm_flags
|= VM_RESERVED
;
3160 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3161 if (!substream
->ops
->page
&&
3162 substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3163 return dma_mmap_coherent(substream
->dma_buffer
.dev
.dev
,
3165 substream
->runtime
->dma_area
,
3166 substream
->runtime
->dma_addr
,
3167 area
->vm_end
- area
->vm_start
);
3168 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3169 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
&&
3170 !plat_device_is_coherent(substream
->dma_buffer
.dev
.dev
))
3171 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3172 #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3173 /* mmap with fault handler */
3174 area
->vm_ops
= &snd_pcm_vm_ops_data_fault
;
3179 * mmap the DMA buffer on I/O memory area
3181 #if SNDRV_PCM_INFO_MMAP_IOMEM
3182 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream
*substream
,
3183 struct vm_area_struct
*area
)
3186 unsigned long offset
;
3188 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3189 area
->vm_flags
|= VM_IO
;
3190 size
= area
->vm_end
- area
->vm_start
;
3191 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3192 if (io_remap_pfn_range(area
, area
->vm_start
,
3193 (substream
->runtime
->dma_addr
+ offset
) >> PAGE_SHIFT
,
3194 size
, area
->vm_page_prot
))
3199 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem
);
3200 #endif /* SNDRV_PCM_INFO_MMAP */
3202 /* mmap callback with pgprot_noncached */
3203 int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream
*substream
,
3204 struct vm_area_struct
*area
)
3206 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3207 return snd_pcm_default_mmap(substream
, area
);
3209 EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached
);
3214 int snd_pcm_mmap_data(struct snd_pcm_substream
*substream
, struct file
*file
,
3215 struct vm_area_struct
*area
)
3217 struct snd_pcm_runtime
*runtime
;
3219 unsigned long offset
;
3223 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3224 if (!(area
->vm_flags
& (VM_WRITE
|VM_READ
)))
3227 if (!(area
->vm_flags
& VM_READ
))
3230 runtime
= substream
->runtime
;
3231 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
3233 if (!(runtime
->info
& SNDRV_PCM_INFO_MMAP
))
3235 if (runtime
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
||
3236 runtime
->access
== SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
)
3238 size
= area
->vm_end
- area
->vm_start
;
3239 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3240 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3241 if ((size_t)size
> dma_bytes
)
3243 if (offset
> dma_bytes
- size
)
3246 area
->vm_ops
= &snd_pcm_vm_ops_data
;
3247 area
->vm_private_data
= substream
;
3248 if (substream
->ops
->mmap
)
3249 err
= substream
->ops
->mmap(substream
, area
);
3251 err
= snd_pcm_default_mmap(substream
, area
);
3253 atomic_inc(&substream
->mmap_count
);
3257 EXPORT_SYMBOL(snd_pcm_mmap_data
);
3259 static int snd_pcm_mmap(struct file
*file
, struct vm_area_struct
*area
)
3261 struct snd_pcm_file
* pcm_file
;
3262 struct snd_pcm_substream
*substream
;
3263 unsigned long offset
;
3265 pcm_file
= file
->private_data
;
3266 substream
= pcm_file
->substream
;
3267 if (PCM_RUNTIME_CHECK(substream
))
3270 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3272 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3273 if (pcm_file
->no_compat_mmap
)
3275 return snd_pcm_mmap_status(substream
, file
, area
);
3276 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3277 if (pcm_file
->no_compat_mmap
)
3279 return snd_pcm_mmap_control(substream
, file
, area
);
3281 return snd_pcm_mmap_data(substream
, file
, area
);
3286 static int snd_pcm_fasync(int fd
, struct file
* file
, int on
)
3288 struct snd_pcm_file
* pcm_file
;
3289 struct snd_pcm_substream
*substream
;
3290 struct snd_pcm_runtime
*runtime
;
3292 pcm_file
= file
->private_data
;
3293 substream
= pcm_file
->substream
;
3294 if (PCM_RUNTIME_CHECK(substream
))
3296 runtime
= substream
->runtime
;
3297 return fasync_helper(fd
, file
, on
, &runtime
->fasync
);
3303 #ifdef CONFIG_COMPAT
3304 #include "pcm_compat.c"
3306 #define snd_pcm_ioctl_compat NULL
3310 * To be removed helpers to keep binary compatibility
3313 #ifdef CONFIG_SND_SUPPORT_OLD_API
3314 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3315 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3317 static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params
*params
,
3318 struct snd_pcm_hw_params_old
*oparams
)
3322 memset(params
, 0, sizeof(*params
));
3323 params
->flags
= oparams
->flags
;
3324 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3325 params
->masks
[i
].bits
[0] = oparams
->masks
[i
];
3326 memcpy(params
->intervals
, oparams
->intervals
, sizeof(oparams
->intervals
));
3327 params
->rmask
= __OLD_TO_NEW_MASK(oparams
->rmask
);
3328 params
->cmask
= __OLD_TO_NEW_MASK(oparams
->cmask
);
3329 params
->info
= oparams
->info
;
3330 params
->msbits
= oparams
->msbits
;
3331 params
->rate_num
= oparams
->rate_num
;
3332 params
->rate_den
= oparams
->rate_den
;
3333 params
->fifo_size
= oparams
->fifo_size
;
3336 static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old
*oparams
,
3337 struct snd_pcm_hw_params
*params
)
3341 memset(oparams
, 0, sizeof(*oparams
));
3342 oparams
->flags
= params
->flags
;
3343 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3344 oparams
->masks
[i
] = params
->masks
[i
].bits
[0];
3345 memcpy(oparams
->intervals
, params
->intervals
, sizeof(oparams
->intervals
));
3346 oparams
->rmask
= __NEW_TO_OLD_MASK(params
->rmask
);
3347 oparams
->cmask
= __NEW_TO_OLD_MASK(params
->cmask
);
3348 oparams
->info
= params
->info
;
3349 oparams
->msbits
= params
->msbits
;
3350 oparams
->rate_num
= params
->rate_num
;
3351 oparams
->rate_den
= params
->rate_den
;
3352 oparams
->fifo_size
= params
->fifo_size
;
3355 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
3356 struct snd_pcm_hw_params_old __user
* _oparams
)
3358 struct snd_pcm_hw_params
*params
;
3359 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3362 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3366 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3367 if (IS_ERR(oparams
)) {
3368 err
= PTR_ERR(oparams
);
3371 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3372 err
= snd_pcm_hw_refine(substream
, params
);
3373 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3374 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3385 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
3386 struct snd_pcm_hw_params_old __user
* _oparams
)
3388 struct snd_pcm_hw_params
*params
;
3389 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3392 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3396 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3397 if (IS_ERR(oparams
)) {
3398 err
= PTR_ERR(oparams
);
3401 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3402 err
= snd_pcm_hw_params(substream
, params
);
3403 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3404 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3414 #endif /* CONFIG_SND_SUPPORT_OLD_API */
3417 static unsigned long snd_pcm_get_unmapped_area(struct file
*file
,
3420 unsigned long pgoff
,
3421 unsigned long flags
)
3423 struct snd_pcm_file
*pcm_file
= file
->private_data
;
3424 struct snd_pcm_substream
*substream
= pcm_file
->substream
;
3425 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3426 unsigned long offset
= pgoff
<< PAGE_SHIFT
;
3429 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3430 return (unsigned long)runtime
->status
;
3431 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3432 return (unsigned long)runtime
->control
;
3434 return (unsigned long)runtime
->dma_area
+ offset
;
3438 # define snd_pcm_get_unmapped_area NULL
3445 const struct file_operations snd_pcm_f_ops
[2] = {
3447 .owner
= THIS_MODULE
,
3448 .write
= snd_pcm_write
,
3449 .aio_write
= snd_pcm_aio_write
,
3450 .open
= snd_pcm_playback_open
,
3451 .release
= snd_pcm_release
,
3452 .llseek
= no_llseek
,
3453 .poll
= snd_pcm_playback_poll
,
3454 .unlocked_ioctl
= snd_pcm_playback_ioctl
,
3455 .compat_ioctl
= snd_pcm_ioctl_compat
,
3456 .mmap
= snd_pcm_mmap
,
3457 .fasync
= snd_pcm_fasync
,
3458 .get_unmapped_area
= snd_pcm_get_unmapped_area
,
3461 .owner
= THIS_MODULE
,
3462 .read
= snd_pcm_read
,
3463 .aio_read
= snd_pcm_aio_read
,
3464 .open
= snd_pcm_capture_open
,
3465 .release
= snd_pcm_release
,
3466 .llseek
= no_llseek
,
3467 .poll
= snd_pcm_capture_poll
,
3468 .unlocked_ioctl
= snd_pcm_capture_ioctl
,
3469 .compat_ioctl
= snd_pcm_ioctl_compat
,
3470 .mmap
= snd_pcm_mmap
,
3471 .fasync
= snd_pcm_fasync
,
3472 .get_unmapped_area
= snd_pcm_get_unmapped_area
,