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 char *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
->status
->state
= state
;
868 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
869 runtime
->silence_size
> 0)
870 snd_pcm_playback_silence(substream
, ULONG_MAX
);
871 if (substream
->timer
)
872 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTART
,
873 &runtime
->trigger_tstamp
);
876 static struct action_ops snd_pcm_action_start
= {
877 .pre_action
= snd_pcm_pre_start
,
878 .do_action
= snd_pcm_do_start
,
879 .undo_action
= snd_pcm_undo_start
,
880 .post_action
= snd_pcm_post_start
884 * snd_pcm_start - start all linked streams
885 * @substream: the PCM substream instance
887 int snd_pcm_start(struct snd_pcm_substream
*substream
)
889 return snd_pcm_action(&snd_pcm_action_start
, substream
,
890 SNDRV_PCM_STATE_RUNNING
);
896 static int snd_pcm_pre_stop(struct snd_pcm_substream
*substream
, int state
)
898 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
899 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
901 runtime
->trigger_master
= substream
;
905 static int snd_pcm_do_stop(struct snd_pcm_substream
*substream
, int state
)
907 if (substream
->runtime
->trigger_master
== substream
&&
908 snd_pcm_running(substream
))
909 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
910 return 0; /* unconditonally stop all substreams */
913 static void snd_pcm_post_stop(struct snd_pcm_substream
*substream
, int state
)
915 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
916 if (runtime
->status
->state
!= state
) {
917 snd_pcm_trigger_tstamp(substream
);
918 if (substream
->timer
)
919 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTOP
,
920 &runtime
->trigger_tstamp
);
921 runtime
->status
->state
= state
;
923 wake_up(&runtime
->sleep
);
924 wake_up(&runtime
->tsleep
);
927 static struct action_ops snd_pcm_action_stop
= {
928 .pre_action
= snd_pcm_pre_stop
,
929 .do_action
= snd_pcm_do_stop
,
930 .post_action
= snd_pcm_post_stop
934 * snd_pcm_stop - try to stop all running streams in the substream group
935 * @substream: the PCM substream instance
936 * @state: PCM state after stopping the stream
938 * The state of each stream is then changed to the given state unconditionally.
940 int snd_pcm_stop(struct snd_pcm_substream
*substream
, int state
)
942 return snd_pcm_action(&snd_pcm_action_stop
, substream
, state
);
945 EXPORT_SYMBOL(snd_pcm_stop
);
948 * snd_pcm_drain_done - stop the DMA only when the given stream is playback
949 * @substream: the PCM substream
951 * After stopping, the state is changed to SETUP.
952 * Unlike snd_pcm_stop(), this affects only the given stream.
954 int snd_pcm_drain_done(struct snd_pcm_substream
*substream
)
956 return snd_pcm_action_single(&snd_pcm_action_stop
, substream
,
957 SNDRV_PCM_STATE_SETUP
);
963 static int snd_pcm_pre_pause(struct snd_pcm_substream
*substream
, int push
)
965 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
966 if (!(runtime
->info
& SNDRV_PCM_INFO_PAUSE
))
969 if (runtime
->status
->state
!= SNDRV_PCM_STATE_RUNNING
)
971 } else if (runtime
->status
->state
!= SNDRV_PCM_STATE_PAUSED
)
973 runtime
->trigger_master
= substream
;
977 static int snd_pcm_do_pause(struct snd_pcm_substream
*substream
, int push
)
979 if (substream
->runtime
->trigger_master
!= substream
)
981 /* some drivers might use hw_ptr to recover from the pause -
982 update the hw_ptr now */
984 snd_pcm_update_hw_ptr(substream
);
985 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
986 * a delta betwen the current jiffies, this gives a large enough
987 * delta, effectively to skip the check once.
989 substream
->runtime
->hw_ptr_jiffies
= jiffies
- HZ
* 1000;
990 return substream
->ops
->trigger(substream
,
991 push
? SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
992 SNDRV_PCM_TRIGGER_PAUSE_RELEASE
);
995 static void snd_pcm_undo_pause(struct snd_pcm_substream
*substream
, int push
)
997 if (substream
->runtime
->trigger_master
== substream
)
998 substream
->ops
->trigger(substream
,
999 push
? SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1000 SNDRV_PCM_TRIGGER_PAUSE_PUSH
);
1003 static void snd_pcm_post_pause(struct snd_pcm_substream
*substream
, int push
)
1005 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1006 snd_pcm_trigger_tstamp(substream
);
1008 runtime
->status
->state
= SNDRV_PCM_STATE_PAUSED
;
1009 if (substream
->timer
)
1010 snd_timer_notify(substream
->timer
,
1011 SNDRV_TIMER_EVENT_MPAUSE
,
1012 &runtime
->trigger_tstamp
);
1013 wake_up(&runtime
->sleep
);
1014 wake_up(&runtime
->tsleep
);
1016 runtime
->status
->state
= SNDRV_PCM_STATE_RUNNING
;
1017 if (substream
->timer
)
1018 snd_timer_notify(substream
->timer
,
1019 SNDRV_TIMER_EVENT_MCONTINUE
,
1020 &runtime
->trigger_tstamp
);
1024 static struct action_ops snd_pcm_action_pause
= {
1025 .pre_action
= snd_pcm_pre_pause
,
1026 .do_action
= snd_pcm_do_pause
,
1027 .undo_action
= snd_pcm_undo_pause
,
1028 .post_action
= snd_pcm_post_pause
1032 * Push/release the pause for all linked streams.
1034 static int snd_pcm_pause(struct snd_pcm_substream
*substream
, int push
)
1036 return snd_pcm_action(&snd_pcm_action_pause
, substream
, push
);
1042 static int snd_pcm_pre_suspend(struct snd_pcm_substream
*substream
, int state
)
1044 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1045 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1047 runtime
->trigger_master
= substream
;
1051 static int snd_pcm_do_suspend(struct snd_pcm_substream
*substream
, int state
)
1053 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1054 if (runtime
->trigger_master
!= substream
)
1056 if (! snd_pcm_running(substream
))
1058 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1059 return 0; /* suspend unconditionally */
1062 static void snd_pcm_post_suspend(struct snd_pcm_substream
*substream
, int state
)
1064 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1065 snd_pcm_trigger_tstamp(substream
);
1066 if (substream
->timer
)
1067 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSUSPEND
,
1068 &runtime
->trigger_tstamp
);
1069 runtime
->status
->suspended_state
= runtime
->status
->state
;
1070 runtime
->status
->state
= SNDRV_PCM_STATE_SUSPENDED
;
1071 wake_up(&runtime
->sleep
);
1072 wake_up(&runtime
->tsleep
);
1075 static struct action_ops snd_pcm_action_suspend
= {
1076 .pre_action
= snd_pcm_pre_suspend
,
1077 .do_action
= snd_pcm_do_suspend
,
1078 .post_action
= snd_pcm_post_suspend
1082 * snd_pcm_suspend - trigger SUSPEND to all linked streams
1083 * @substream: the PCM substream
1085 * After this call, all streams are changed to SUSPENDED state.
1087 int snd_pcm_suspend(struct snd_pcm_substream
*substream
)
1090 unsigned long flags
;
1095 snd_pcm_stream_lock_irqsave(substream
, flags
);
1096 err
= snd_pcm_action(&snd_pcm_action_suspend
, substream
, 0);
1097 snd_pcm_stream_unlock_irqrestore(substream
, flags
);
1101 EXPORT_SYMBOL(snd_pcm_suspend
);
1104 * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm
1105 * @pcm: the PCM instance
1107 * After this call, all streams are changed to SUSPENDED state.
1109 int snd_pcm_suspend_all(struct snd_pcm
*pcm
)
1111 struct snd_pcm_substream
*substream
;
1112 int stream
, err
= 0;
1117 for (stream
= 0; stream
< 2; stream
++) {
1118 for (substream
= pcm
->streams
[stream
].substream
;
1119 substream
; substream
= substream
->next
) {
1120 /* FIXME: the open/close code should lock this as well */
1121 if (substream
->runtime
== NULL
)
1123 err
= snd_pcm_suspend(substream
);
1124 if (err
< 0 && err
!= -EBUSY
)
1131 EXPORT_SYMBOL(snd_pcm_suspend_all
);
1135 static int snd_pcm_pre_resume(struct snd_pcm_substream
*substream
, int state
)
1137 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1138 if (!(runtime
->info
& SNDRV_PCM_INFO_RESUME
))
1140 runtime
->trigger_master
= substream
;
1144 static int snd_pcm_do_resume(struct snd_pcm_substream
*substream
, int state
)
1146 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1147 if (runtime
->trigger_master
!= substream
)
1149 /* DMA not running previously? */
1150 if (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_RUNNING
&&
1151 (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_DRAINING
||
1152 substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
1154 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_RESUME
);
1157 static void snd_pcm_undo_resume(struct snd_pcm_substream
*substream
, int state
)
1159 if (substream
->runtime
->trigger_master
== substream
&&
1160 snd_pcm_running(substream
))
1161 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1164 static void snd_pcm_post_resume(struct snd_pcm_substream
*substream
, int state
)
1166 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1167 snd_pcm_trigger_tstamp(substream
);
1168 if (substream
->timer
)
1169 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MRESUME
,
1170 &runtime
->trigger_tstamp
);
1171 runtime
->status
->state
= runtime
->status
->suspended_state
;
1174 static struct action_ops snd_pcm_action_resume
= {
1175 .pre_action
= snd_pcm_pre_resume
,
1176 .do_action
= snd_pcm_do_resume
,
1177 .undo_action
= snd_pcm_undo_resume
,
1178 .post_action
= snd_pcm_post_resume
1181 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1183 struct snd_card
*card
= substream
->pcm
->card
;
1186 snd_power_lock(card
);
1187 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1188 res
= snd_pcm_action_lock_irq(&snd_pcm_action_resume
, substream
, 0);
1189 snd_power_unlock(card
);
1195 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1200 #endif /* CONFIG_PM */
1205 * Change the RUNNING stream(s) to XRUN state.
1207 static int snd_pcm_xrun(struct snd_pcm_substream
*substream
)
1209 struct snd_card
*card
= substream
->pcm
->card
;
1210 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1213 snd_power_lock(card
);
1214 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1215 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1220 snd_pcm_stream_lock_irq(substream
);
1221 switch (runtime
->status
->state
) {
1222 case SNDRV_PCM_STATE_XRUN
:
1223 result
= 0; /* already there */
1225 case SNDRV_PCM_STATE_RUNNING
:
1226 result
= snd_pcm_stop(substream
, SNDRV_PCM_STATE_XRUN
);
1231 snd_pcm_stream_unlock_irq(substream
);
1233 snd_power_unlock(card
);
1240 static int snd_pcm_pre_reset(struct snd_pcm_substream
*substream
, int state
)
1242 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1243 switch (runtime
->status
->state
) {
1244 case SNDRV_PCM_STATE_RUNNING
:
1245 case SNDRV_PCM_STATE_PREPARED
:
1246 case SNDRV_PCM_STATE_PAUSED
:
1247 case SNDRV_PCM_STATE_SUSPENDED
:
1254 static int snd_pcm_do_reset(struct snd_pcm_substream
*substream
, int state
)
1256 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1257 int err
= substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_RESET
, NULL
);
1260 runtime
->hw_ptr_base
= 0;
1261 runtime
->hw_ptr_interrupt
= runtime
->status
->hw_ptr
-
1262 runtime
->status
->hw_ptr
% runtime
->period_size
;
1263 runtime
->silence_start
= runtime
->status
->hw_ptr
;
1264 runtime
->silence_filled
= 0;
1268 static void snd_pcm_post_reset(struct snd_pcm_substream
*substream
, int state
)
1270 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1271 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1272 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
1273 runtime
->silence_size
> 0)
1274 snd_pcm_playback_silence(substream
, ULONG_MAX
);
1277 static struct action_ops snd_pcm_action_reset
= {
1278 .pre_action
= snd_pcm_pre_reset
,
1279 .do_action
= snd_pcm_do_reset
,
1280 .post_action
= snd_pcm_post_reset
1283 static int snd_pcm_reset(struct snd_pcm_substream
*substream
)
1285 return snd_pcm_action_nonatomic(&snd_pcm_action_reset
, substream
, 0);
1291 /* we use the second argument for updating f_flags */
1292 static int snd_pcm_pre_prepare(struct snd_pcm_substream
*substream
,
1295 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1296 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1297 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
)
1299 if (snd_pcm_running(substream
))
1301 substream
->f_flags
= f_flags
;
1305 static int snd_pcm_do_prepare(struct snd_pcm_substream
*substream
, int state
)
1308 err
= substream
->ops
->prepare(substream
);
1311 return snd_pcm_do_reset(substream
, 0);
1314 static void snd_pcm_post_prepare(struct snd_pcm_substream
*substream
, int state
)
1316 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1317 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1318 runtime
->status
->state
= SNDRV_PCM_STATE_PREPARED
;
1321 static struct action_ops snd_pcm_action_prepare
= {
1322 .pre_action
= snd_pcm_pre_prepare
,
1323 .do_action
= snd_pcm_do_prepare
,
1324 .post_action
= snd_pcm_post_prepare
1328 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1329 * @substream: the PCM substream instance
1330 * @file: file to refer f_flags
1332 static int snd_pcm_prepare(struct snd_pcm_substream
*substream
,
1336 struct snd_card
*card
= substream
->pcm
->card
;
1340 f_flags
= file
->f_flags
;
1342 f_flags
= substream
->f_flags
;
1344 snd_power_lock(card
);
1345 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1346 res
= snd_pcm_action_nonatomic(&snd_pcm_action_prepare
,
1347 substream
, f_flags
);
1348 snd_power_unlock(card
);
1356 static int snd_pcm_pre_drain_init(struct snd_pcm_substream
*substream
, int state
)
1358 substream
->runtime
->trigger_master
= substream
;
1362 static int snd_pcm_do_drain_init(struct snd_pcm_substream
*substream
, int state
)
1364 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1365 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1366 switch (runtime
->status
->state
) {
1367 case SNDRV_PCM_STATE_PREPARED
:
1368 /* start playback stream if possible */
1369 if (! snd_pcm_playback_empty(substream
)) {
1370 snd_pcm_do_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1371 snd_pcm_post_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1374 case SNDRV_PCM_STATE_RUNNING
:
1375 runtime
->status
->state
= SNDRV_PCM_STATE_DRAINING
;
1381 /* stop running stream */
1382 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
) {
1383 int new_state
= snd_pcm_capture_avail(runtime
) > 0 ?
1384 SNDRV_PCM_STATE_DRAINING
: SNDRV_PCM_STATE_SETUP
;
1385 snd_pcm_do_stop(substream
, new_state
);
1386 snd_pcm_post_stop(substream
, new_state
);
1392 static void snd_pcm_post_drain_init(struct snd_pcm_substream
*substream
, int state
)
1396 static struct action_ops snd_pcm_action_drain_init
= {
1397 .pre_action
= snd_pcm_pre_drain_init
,
1398 .do_action
= snd_pcm_do_drain_init
,
1399 .post_action
= snd_pcm_post_drain_init
1402 static int snd_pcm_drop(struct snd_pcm_substream
*substream
);
1405 * Drain the stream(s).
1406 * When the substream is linked, sync until the draining of all playback streams
1408 * After this call, all streams are supposed to be either SETUP or DRAINING
1409 * (capture only) state.
1411 static int snd_pcm_drain(struct snd_pcm_substream
*substream
,
1414 struct snd_card
*card
;
1415 struct snd_pcm_runtime
*runtime
;
1416 struct snd_pcm_substream
*s
;
1421 card
= substream
->pcm
->card
;
1422 runtime
= substream
->runtime
;
1424 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
1427 snd_power_lock(card
);
1428 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1429 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1431 snd_power_unlock(card
);
1437 if (file
->f_flags
& O_NONBLOCK
)
1439 } else if (substream
->f_flags
& O_NONBLOCK
)
1442 down_read(&snd_pcm_link_rwsem
);
1443 snd_pcm_stream_lock_irq(substream
);
1445 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1446 snd_pcm_pause(substream
, 0);
1448 /* pre-start/stop - all running streams are changed to DRAINING state */
1449 result
= snd_pcm_action(&snd_pcm_action_drain_init
, substream
, 0);
1452 /* in non-blocking, we don't wait in ioctl but let caller poll */
1460 struct snd_pcm_runtime
*to_check
;
1461 if (signal_pending(current
)) {
1462 result
= -ERESTARTSYS
;
1465 /* find a substream to drain */
1467 snd_pcm_group_for_each_entry(s
, substream
) {
1468 if (s
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1470 runtime
= s
->runtime
;
1471 if (runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
1477 break; /* all drained */
1478 init_waitqueue_entry(&wait
, current
);
1479 add_wait_queue(&to_check
->sleep
, &wait
);
1480 set_current_state(TASK_INTERRUPTIBLE
);
1481 snd_pcm_stream_unlock_irq(substream
);
1482 up_read(&snd_pcm_link_rwsem
);
1483 snd_power_unlock(card
);
1484 tout
= schedule_timeout(10 * HZ
);
1485 snd_power_lock(card
);
1486 down_read(&snd_pcm_link_rwsem
);
1487 snd_pcm_stream_lock_irq(substream
);
1488 remove_wait_queue(&to_check
->sleep
, &wait
);
1490 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1493 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1494 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1502 snd_pcm_stream_unlock_irq(substream
);
1503 up_read(&snd_pcm_link_rwsem
);
1504 snd_power_unlock(card
);
1512 * Immediately put all linked substreams into SETUP state.
1514 static int snd_pcm_drop(struct snd_pcm_substream
*substream
)
1516 struct snd_pcm_runtime
*runtime
;
1517 struct snd_card
*card
;
1520 if (PCM_RUNTIME_CHECK(substream
))
1522 runtime
= substream
->runtime
;
1523 card
= substream
->pcm
->card
;
1525 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1526 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
||
1527 runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1530 snd_pcm_stream_lock_irq(substream
);
1532 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1533 snd_pcm_pause(substream
, 0);
1535 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1536 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */
1537 snd_pcm_stream_unlock_irq(substream
);
1543 /* WARNING: Don't forget to fput back the file */
1544 static struct file
*snd_pcm_file_fd(int fd
)
1547 struct inode
*inode
;
1553 inode
= file
->f_path
.dentry
->d_inode
;
1554 if (!S_ISCHR(inode
->i_mode
) ||
1555 imajor(inode
) != snd_major
) {
1559 minor
= iminor(inode
);
1560 if (!snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_PLAYBACK
) &&
1561 !snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_CAPTURE
)) {
1571 static int snd_pcm_link(struct snd_pcm_substream
*substream
, int fd
)
1575 struct snd_pcm_file
*pcm_file
;
1576 struct snd_pcm_substream
*substream1
;
1578 file
= snd_pcm_file_fd(fd
);
1581 pcm_file
= file
->private_data
;
1582 substream1
= pcm_file
->substream
;
1583 down_write(&snd_pcm_link_rwsem
);
1584 write_lock_irq(&snd_pcm_link_rwlock
);
1585 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1586 substream
->runtime
->status
->state
!= substream1
->runtime
->status
->state
) {
1590 if (snd_pcm_stream_linked(substream1
)) {
1594 if (!snd_pcm_stream_linked(substream
)) {
1595 substream
->group
= kmalloc(sizeof(struct snd_pcm_group
), GFP_ATOMIC
);
1596 if (substream
->group
== NULL
) {
1600 spin_lock_init(&substream
->group
->lock
);
1601 INIT_LIST_HEAD(&substream
->group
->substreams
);
1602 list_add_tail(&substream
->link_list
, &substream
->group
->substreams
);
1603 substream
->group
->count
= 1;
1605 list_add_tail(&substream1
->link_list
, &substream
->group
->substreams
);
1606 substream
->group
->count
++;
1607 substream1
->group
= substream
->group
;
1609 write_unlock_irq(&snd_pcm_link_rwlock
);
1610 up_write(&snd_pcm_link_rwsem
);
1615 static void relink_to_local(struct snd_pcm_substream
*substream
)
1617 substream
->group
= &substream
->self_group
;
1618 INIT_LIST_HEAD(&substream
->self_group
.substreams
);
1619 list_add_tail(&substream
->link_list
, &substream
->self_group
.substreams
);
1622 static int snd_pcm_unlink(struct snd_pcm_substream
*substream
)
1624 struct snd_pcm_substream
*s
;
1627 down_write(&snd_pcm_link_rwsem
);
1628 write_lock_irq(&snd_pcm_link_rwlock
);
1629 if (!snd_pcm_stream_linked(substream
)) {
1633 list_del(&substream
->link_list
);
1634 substream
->group
->count
--;
1635 if (substream
->group
->count
== 1) { /* detach the last stream, too */
1636 snd_pcm_group_for_each_entry(s
, substream
) {
1640 kfree(substream
->group
);
1642 relink_to_local(substream
);
1644 write_unlock_irq(&snd_pcm_link_rwlock
);
1645 up_write(&snd_pcm_link_rwsem
);
1652 static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params
*params
,
1653 struct snd_pcm_hw_rule
*rule
)
1655 struct snd_interval t
;
1656 snd_interval_mul(hw_param_interval_c(params
, rule
->deps
[0]),
1657 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1658 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1661 static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params
*params
,
1662 struct snd_pcm_hw_rule
*rule
)
1664 struct snd_interval t
;
1665 snd_interval_div(hw_param_interval_c(params
, rule
->deps
[0]),
1666 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1667 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1670 static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params
*params
,
1671 struct snd_pcm_hw_rule
*rule
)
1673 struct snd_interval t
;
1674 snd_interval_muldivk(hw_param_interval_c(params
, rule
->deps
[0]),
1675 hw_param_interval_c(params
, rule
->deps
[1]),
1676 (unsigned long) rule
->private, &t
);
1677 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1680 static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params
*params
,
1681 struct snd_pcm_hw_rule
*rule
)
1683 struct snd_interval t
;
1684 snd_interval_mulkdiv(hw_param_interval_c(params
, rule
->deps
[0]),
1685 (unsigned long) rule
->private,
1686 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1687 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1690 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params
*params
,
1691 struct snd_pcm_hw_rule
*rule
)
1694 struct snd_interval
*i
= hw_param_interval(params
, rule
->deps
[0]);
1696 struct snd_mask
*mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
1698 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1700 if (! snd_mask_test(mask
, k
))
1702 bits
= snd_pcm_format_physical_width(k
);
1704 continue; /* ignore invalid formats */
1705 if ((unsigned)bits
< i
->min
|| (unsigned)bits
> i
->max
)
1706 snd_mask_reset(&m
, k
);
1708 return snd_mask_refine(mask
, &m
);
1711 static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params
*params
,
1712 struct snd_pcm_hw_rule
*rule
)
1714 struct snd_interval t
;
1720 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1722 if (! snd_mask_test(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), k
))
1724 bits
= snd_pcm_format_physical_width(k
);
1726 continue; /* ignore invalid formats */
1727 if (t
.min
> (unsigned)bits
)
1729 if (t
.max
< (unsigned)bits
)
1733 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1736 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1737 #error "Change this table"
1740 static unsigned int rates
[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1741 48000, 64000, 88200, 96000, 176400, 192000 };
1743 const struct snd_pcm_hw_constraint_list snd_pcm_known_rates
= {
1744 .count
= ARRAY_SIZE(rates
),
1748 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params
*params
,
1749 struct snd_pcm_hw_rule
*rule
)
1751 struct snd_pcm_hardware
*hw
= rule
->private;
1752 return snd_interval_list(hw_param_interval(params
, rule
->var
),
1753 snd_pcm_known_rates
.count
,
1754 snd_pcm_known_rates
.list
, hw
->rates
);
1757 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params
*params
,
1758 struct snd_pcm_hw_rule
*rule
)
1760 struct snd_interval t
;
1761 struct snd_pcm_substream
*substream
= rule
->private;
1763 t
.max
= substream
->buffer_bytes_max
;
1767 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1770 int snd_pcm_hw_constraints_init(struct snd_pcm_substream
*substream
)
1772 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1773 struct snd_pcm_hw_constraints
*constrs
= &runtime
->hw_constraints
;
1776 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
1777 snd_mask_any(constrs_mask(constrs
, k
));
1780 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
1781 snd_interval_any(constrs_interval(constrs
, k
));
1784 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_CHANNELS
));
1785 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
));
1786 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
));
1787 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
));
1788 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_FRAME_BITS
));
1790 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FORMAT
,
1791 snd_pcm_hw_rule_format
, NULL
,
1792 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1795 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1796 snd_pcm_hw_rule_sample_bits
, NULL
,
1797 SNDRV_PCM_HW_PARAM_FORMAT
,
1798 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1801 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1802 snd_pcm_hw_rule_div
, NULL
,
1803 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1806 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1807 snd_pcm_hw_rule_mul
, NULL
,
1808 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1811 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1812 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1813 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1816 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1817 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1818 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, -1);
1821 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1822 snd_pcm_hw_rule_div
, NULL
,
1823 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1826 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1827 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1828 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_TIME
, -1);
1831 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1832 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1833 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
, -1);
1836 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
,
1837 snd_pcm_hw_rule_div
, NULL
,
1838 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1841 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1842 snd_pcm_hw_rule_div
, NULL
,
1843 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1846 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1847 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1848 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1851 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1852 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1853 SNDRV_PCM_HW_PARAM_PERIOD_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1856 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1857 snd_pcm_hw_rule_mul
, NULL
,
1858 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1861 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1862 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1863 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1866 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1867 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1868 SNDRV_PCM_HW_PARAM_BUFFER_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1871 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1872 snd_pcm_hw_rule_muldivk
, (void*) 8,
1873 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1876 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1877 snd_pcm_hw_rule_muldivk
, (void*) 8,
1878 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1881 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1882 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1883 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1886 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
1887 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1888 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1894 int snd_pcm_hw_constraints_complete(struct snd_pcm_substream
*substream
)
1896 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1897 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
1899 unsigned int mask
= 0;
1901 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1902 mask
|= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED
;
1903 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1904 mask
|= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
;
1905 if (hw
->info
& SNDRV_PCM_INFO_MMAP
) {
1906 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1907 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED
;
1908 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1909 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED
;
1910 if (hw
->info
& SNDRV_PCM_INFO_COMPLEX
)
1911 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX
;
1913 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_ACCESS
, mask
);
1917 err
= snd_pcm_hw_constraint_mask64(runtime
, SNDRV_PCM_HW_PARAM_FORMAT
, hw
->formats
);
1921 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_SUBFORMAT
, 1 << SNDRV_PCM_SUBFORMAT_STD
);
1925 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_CHANNELS
,
1926 hw
->channels_min
, hw
->channels_max
);
1930 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
1931 hw
->rate_min
, hw
->rate_max
);
1935 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1936 hw
->period_bytes_min
, hw
->period_bytes_max
);
1940 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
,
1941 hw
->periods_min
, hw
->periods_max
);
1945 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1946 hw
->period_bytes_min
, hw
->buffer_bytes_max
);
1950 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1951 snd_pcm_hw_rule_buffer_bytes_max
, substream
,
1952 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, -1);
1957 if (runtime
->dma_bytes
) {
1958 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 0, runtime
->dma_bytes
);
1963 if (!(hw
->rates
& (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_CONTINUOUS
))) {
1964 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1965 snd_pcm_hw_rule_rate
, hw
,
1966 SNDRV_PCM_HW_PARAM_RATE
, -1);
1971 /* FIXME: this belong to lowlevel */
1972 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
1977 static void pcm_release_private(struct snd_pcm_substream
*substream
)
1979 snd_pcm_unlink(substream
);
1982 void snd_pcm_release_substream(struct snd_pcm_substream
*substream
)
1984 substream
->ref_count
--;
1985 if (substream
->ref_count
> 0)
1988 snd_pcm_drop(substream
);
1989 if (substream
->hw_opened
) {
1990 if (substream
->ops
->hw_free
!= NULL
)
1991 substream
->ops
->hw_free(substream
);
1992 substream
->ops
->close(substream
);
1993 substream
->hw_opened
= 0;
1995 if (pm_qos_request_active(&substream
->latency_pm_qos_req
))
1996 pm_qos_remove_request(&substream
->latency_pm_qos_req
);
1997 if (substream
->pcm_release
) {
1998 substream
->pcm_release(substream
);
1999 substream
->pcm_release
= NULL
;
2001 snd_pcm_detach_substream(substream
);
2004 EXPORT_SYMBOL(snd_pcm_release_substream
);
2006 int snd_pcm_open_substream(struct snd_pcm
*pcm
, int stream
,
2008 struct snd_pcm_substream
**rsubstream
)
2010 struct snd_pcm_substream
*substream
;
2013 err
= snd_pcm_attach_substream(pcm
, stream
, file
, &substream
);
2016 if (substream
->ref_count
> 1) {
2017 *rsubstream
= substream
;
2021 err
= snd_pcm_hw_constraints_init(substream
);
2023 snd_printd("snd_pcm_hw_constraints_init failed\n");
2027 if ((err
= substream
->ops
->open(substream
)) < 0)
2030 substream
->hw_opened
= 1;
2032 err
= snd_pcm_hw_constraints_complete(substream
);
2034 snd_printd("snd_pcm_hw_constraints_complete failed\n");
2038 *rsubstream
= substream
;
2042 snd_pcm_release_substream(substream
);
2046 EXPORT_SYMBOL(snd_pcm_open_substream
);
2048 static int snd_pcm_open_file(struct file
*file
,
2049 struct snd_pcm
*pcm
,
2051 struct snd_pcm_file
**rpcm_file
)
2053 struct snd_pcm_file
*pcm_file
;
2054 struct snd_pcm_substream
*substream
;
2055 struct snd_pcm_str
*str
;
2061 err
= snd_pcm_open_substream(pcm
, stream
, file
, &substream
);
2065 pcm_file
= kzalloc(sizeof(*pcm_file
), GFP_KERNEL
);
2066 if (pcm_file
== NULL
) {
2067 snd_pcm_release_substream(substream
);
2070 pcm_file
->substream
= substream
;
2071 if (substream
->ref_count
== 1) {
2072 str
= substream
->pstr
;
2073 substream
->file
= pcm_file
;
2074 substream
->pcm_release
= pcm_release_private
;
2076 file
->private_data
= pcm_file
;
2078 *rpcm_file
= pcm_file
;
2082 static int snd_pcm_playback_open(struct inode
*inode
, struct file
*file
)
2084 struct snd_pcm
*pcm
;
2085 int err
= nonseekable_open(inode
, file
);
2088 pcm
= snd_lookup_minor_data(iminor(inode
),
2089 SNDRV_DEVICE_TYPE_PCM_PLAYBACK
);
2090 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_PLAYBACK
);
2093 static int snd_pcm_capture_open(struct inode
*inode
, struct file
*file
)
2095 struct snd_pcm
*pcm
;
2096 int err
= nonseekable_open(inode
, file
);
2099 pcm
= snd_lookup_minor_data(iminor(inode
),
2100 SNDRV_DEVICE_TYPE_PCM_CAPTURE
);
2101 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_CAPTURE
);
2104 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
)
2107 struct snd_pcm_file
*pcm_file
;
2114 err
= snd_card_file_add(pcm
->card
, file
);
2117 if (!try_module_get(pcm
->card
->module
)) {
2121 init_waitqueue_entry(&wait
, current
);
2122 add_wait_queue(&pcm
->open_wait
, &wait
);
2123 mutex_lock(&pcm
->open_mutex
);
2125 err
= snd_pcm_open_file(file
, pcm
, stream
, &pcm_file
);
2128 if (err
== -EAGAIN
) {
2129 if (file
->f_flags
& O_NONBLOCK
) {
2135 set_current_state(TASK_INTERRUPTIBLE
);
2136 mutex_unlock(&pcm
->open_mutex
);
2138 mutex_lock(&pcm
->open_mutex
);
2139 if (signal_pending(current
)) {
2144 remove_wait_queue(&pcm
->open_wait
, &wait
);
2145 mutex_unlock(&pcm
->open_mutex
);
2151 module_put(pcm
->card
->module
);
2153 snd_card_file_remove(pcm
->card
, file
);
2158 static int snd_pcm_release(struct inode
*inode
, struct file
*file
)
2160 struct snd_pcm
*pcm
;
2161 struct snd_pcm_substream
*substream
;
2162 struct snd_pcm_file
*pcm_file
;
2164 pcm_file
= file
->private_data
;
2165 substream
= pcm_file
->substream
;
2166 if (snd_BUG_ON(!substream
))
2168 pcm
= substream
->pcm
;
2169 mutex_lock(&pcm
->open_mutex
);
2170 snd_pcm_release_substream(substream
);
2172 mutex_unlock(&pcm
->open_mutex
);
2173 wake_up(&pcm
->open_wait
);
2174 module_put(pcm
->card
->module
);
2175 snd_card_file_remove(pcm
->card
, file
);
2179 static snd_pcm_sframes_t
snd_pcm_playback_rewind(struct snd_pcm_substream
*substream
,
2180 snd_pcm_uframes_t frames
)
2182 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2183 snd_pcm_sframes_t appl_ptr
;
2184 snd_pcm_sframes_t ret
;
2185 snd_pcm_sframes_t hw_avail
;
2190 snd_pcm_stream_lock_irq(substream
);
2191 switch (runtime
->status
->state
) {
2192 case SNDRV_PCM_STATE_PREPARED
:
2194 case SNDRV_PCM_STATE_DRAINING
:
2195 case SNDRV_PCM_STATE_RUNNING
:
2196 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2199 case SNDRV_PCM_STATE_XRUN
:
2202 case SNDRV_PCM_STATE_SUSPENDED
:
2210 hw_avail
= snd_pcm_playback_hw_avail(runtime
);
2211 if (hw_avail
<= 0) {
2215 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2217 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2219 appl_ptr
+= runtime
->boundary
;
2220 runtime
->control
->appl_ptr
= appl_ptr
;
2223 snd_pcm_stream_unlock_irq(substream
);
2227 static snd_pcm_sframes_t
snd_pcm_capture_rewind(struct snd_pcm_substream
*substream
,
2228 snd_pcm_uframes_t frames
)
2230 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2231 snd_pcm_sframes_t appl_ptr
;
2232 snd_pcm_sframes_t ret
;
2233 snd_pcm_sframes_t hw_avail
;
2238 snd_pcm_stream_lock_irq(substream
);
2239 switch (runtime
->status
->state
) {
2240 case SNDRV_PCM_STATE_PREPARED
:
2241 case SNDRV_PCM_STATE_DRAINING
:
2243 case SNDRV_PCM_STATE_RUNNING
:
2244 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2247 case SNDRV_PCM_STATE_XRUN
:
2250 case SNDRV_PCM_STATE_SUSPENDED
:
2258 hw_avail
= snd_pcm_capture_hw_avail(runtime
);
2259 if (hw_avail
<= 0) {
2263 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2265 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2267 appl_ptr
+= runtime
->boundary
;
2268 runtime
->control
->appl_ptr
= appl_ptr
;
2271 snd_pcm_stream_unlock_irq(substream
);
2275 static snd_pcm_sframes_t
snd_pcm_playback_forward(struct snd_pcm_substream
*substream
,
2276 snd_pcm_uframes_t frames
)
2278 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2279 snd_pcm_sframes_t appl_ptr
;
2280 snd_pcm_sframes_t ret
;
2281 snd_pcm_sframes_t avail
;
2286 snd_pcm_stream_lock_irq(substream
);
2287 switch (runtime
->status
->state
) {
2288 case SNDRV_PCM_STATE_PREPARED
:
2289 case SNDRV_PCM_STATE_PAUSED
:
2291 case SNDRV_PCM_STATE_DRAINING
:
2292 case SNDRV_PCM_STATE_RUNNING
:
2293 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2296 case SNDRV_PCM_STATE_XRUN
:
2299 case SNDRV_PCM_STATE_SUSPENDED
:
2307 avail
= snd_pcm_playback_avail(runtime
);
2312 if (frames
> (snd_pcm_uframes_t
)avail
)
2314 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2315 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2316 appl_ptr
-= runtime
->boundary
;
2317 runtime
->control
->appl_ptr
= appl_ptr
;
2320 snd_pcm_stream_unlock_irq(substream
);
2324 static snd_pcm_sframes_t
snd_pcm_capture_forward(struct snd_pcm_substream
*substream
,
2325 snd_pcm_uframes_t frames
)
2327 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2328 snd_pcm_sframes_t appl_ptr
;
2329 snd_pcm_sframes_t ret
;
2330 snd_pcm_sframes_t avail
;
2335 snd_pcm_stream_lock_irq(substream
);
2336 switch (runtime
->status
->state
) {
2337 case SNDRV_PCM_STATE_PREPARED
:
2338 case SNDRV_PCM_STATE_DRAINING
:
2339 case SNDRV_PCM_STATE_PAUSED
:
2341 case SNDRV_PCM_STATE_RUNNING
:
2342 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2345 case SNDRV_PCM_STATE_XRUN
:
2348 case SNDRV_PCM_STATE_SUSPENDED
:
2356 avail
= snd_pcm_capture_avail(runtime
);
2361 if (frames
> (snd_pcm_uframes_t
)avail
)
2363 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2364 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2365 appl_ptr
-= runtime
->boundary
;
2366 runtime
->control
->appl_ptr
= appl_ptr
;
2369 snd_pcm_stream_unlock_irq(substream
);
2373 static int snd_pcm_hwsync(struct snd_pcm_substream
*substream
)
2375 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2378 snd_pcm_stream_lock_irq(substream
);
2379 switch (runtime
->status
->state
) {
2380 case SNDRV_PCM_STATE_DRAINING
:
2381 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2383 case SNDRV_PCM_STATE_RUNNING
:
2384 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2387 case SNDRV_PCM_STATE_PREPARED
:
2388 case SNDRV_PCM_STATE_SUSPENDED
:
2391 case SNDRV_PCM_STATE_XRUN
:
2399 snd_pcm_stream_unlock_irq(substream
);
2403 static int snd_pcm_delay(struct snd_pcm_substream
*substream
,
2404 snd_pcm_sframes_t __user
*res
)
2406 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2408 snd_pcm_sframes_t n
= 0;
2410 snd_pcm_stream_lock_irq(substream
);
2411 switch (runtime
->status
->state
) {
2412 case SNDRV_PCM_STATE_DRAINING
:
2413 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2415 case SNDRV_PCM_STATE_RUNNING
:
2416 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2419 case SNDRV_PCM_STATE_PREPARED
:
2420 case SNDRV_PCM_STATE_SUSPENDED
:
2422 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2423 n
= snd_pcm_playback_hw_avail(runtime
);
2425 n
= snd_pcm_capture_avail(runtime
);
2426 n
+= runtime
->delay
;
2428 case SNDRV_PCM_STATE_XRUN
:
2436 snd_pcm_stream_unlock_irq(substream
);
2438 if (put_user(n
, res
))
2443 static int snd_pcm_sync_ptr(struct snd_pcm_substream
*substream
,
2444 struct snd_pcm_sync_ptr __user
*_sync_ptr
)
2446 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2447 struct snd_pcm_sync_ptr sync_ptr
;
2448 volatile struct snd_pcm_mmap_status
*status
;
2449 volatile struct snd_pcm_mmap_control
*control
;
2452 memset(&sync_ptr
, 0, sizeof(sync_ptr
));
2453 if (get_user(sync_ptr
.flags
, (unsigned __user
*)&(_sync_ptr
->flags
)))
2455 if (copy_from_user(&sync_ptr
.c
.control
, &(_sync_ptr
->c
.control
), sizeof(struct snd_pcm_mmap_control
)))
2457 status
= runtime
->status
;
2458 control
= runtime
->control
;
2459 if (sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
2460 err
= snd_pcm_hwsync(substream
);
2464 snd_pcm_stream_lock_irq(substream
);
2465 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_APPL
))
2466 control
->appl_ptr
= sync_ptr
.c
.control
.appl_ptr
;
2468 sync_ptr
.c
.control
.appl_ptr
= control
->appl_ptr
;
2469 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
2470 control
->avail_min
= sync_ptr
.c
.control
.avail_min
;
2472 sync_ptr
.c
.control
.avail_min
= control
->avail_min
;
2473 sync_ptr
.s
.status
.state
= status
->state
;
2474 sync_ptr
.s
.status
.hw_ptr
= status
->hw_ptr
;
2475 sync_ptr
.s
.status
.tstamp
= status
->tstamp
;
2476 sync_ptr
.s
.status
.suspended_state
= status
->suspended_state
;
2477 snd_pcm_stream_unlock_irq(substream
);
2478 if (copy_to_user(_sync_ptr
, &sync_ptr
, sizeof(sync_ptr
)))
2483 static int snd_pcm_tstamp(struct snd_pcm_substream
*substream
, int __user
*_arg
)
2485 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2488 if (get_user(arg
, _arg
))
2490 if (arg
< 0 || arg
> SNDRV_PCM_TSTAMP_TYPE_LAST
)
2492 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY
;
2493 if (arg
== SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
)
2494 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
;
2498 static int snd_pcm_common_ioctl1(struct file
*file
,
2499 struct snd_pcm_substream
*substream
,
2500 unsigned int cmd
, void __user
*arg
)
2503 case SNDRV_PCM_IOCTL_PVERSION
:
2504 return put_user(SNDRV_PCM_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2505 case SNDRV_PCM_IOCTL_INFO
:
2506 return snd_pcm_info_user(substream
, arg
);
2507 case SNDRV_PCM_IOCTL_TSTAMP
: /* just for compatibility */
2509 case SNDRV_PCM_IOCTL_TTSTAMP
:
2510 return snd_pcm_tstamp(substream
, arg
);
2511 case SNDRV_PCM_IOCTL_HW_REFINE
:
2512 return snd_pcm_hw_refine_user(substream
, arg
);
2513 case SNDRV_PCM_IOCTL_HW_PARAMS
:
2514 return snd_pcm_hw_params_user(substream
, arg
);
2515 case SNDRV_PCM_IOCTL_HW_FREE
:
2516 return snd_pcm_hw_free(substream
);
2517 case SNDRV_PCM_IOCTL_SW_PARAMS
:
2518 return snd_pcm_sw_params_user(substream
, arg
);
2519 case SNDRV_PCM_IOCTL_STATUS
:
2520 return snd_pcm_status_user(substream
, arg
);
2521 case SNDRV_PCM_IOCTL_CHANNEL_INFO
:
2522 return snd_pcm_channel_info_user(substream
, arg
);
2523 case SNDRV_PCM_IOCTL_PREPARE
:
2524 return snd_pcm_prepare(substream
, file
);
2525 case SNDRV_PCM_IOCTL_RESET
:
2526 return snd_pcm_reset(substream
);
2527 case SNDRV_PCM_IOCTL_START
:
2528 return snd_pcm_action_lock_irq(&snd_pcm_action_start
, substream
, SNDRV_PCM_STATE_RUNNING
);
2529 case SNDRV_PCM_IOCTL_LINK
:
2530 return snd_pcm_link(substream
, (int)(unsigned long) arg
);
2531 case SNDRV_PCM_IOCTL_UNLINK
:
2532 return snd_pcm_unlink(substream
);
2533 case SNDRV_PCM_IOCTL_RESUME
:
2534 return snd_pcm_resume(substream
);
2535 case SNDRV_PCM_IOCTL_XRUN
:
2536 return snd_pcm_xrun(substream
);
2537 case SNDRV_PCM_IOCTL_HWSYNC
:
2538 return snd_pcm_hwsync(substream
);
2539 case SNDRV_PCM_IOCTL_DELAY
:
2540 return snd_pcm_delay(substream
, arg
);
2541 case SNDRV_PCM_IOCTL_SYNC_PTR
:
2542 return snd_pcm_sync_ptr(substream
, arg
);
2543 #ifdef CONFIG_SND_SUPPORT_OLD_API
2544 case SNDRV_PCM_IOCTL_HW_REFINE_OLD
:
2545 return snd_pcm_hw_refine_old_user(substream
, arg
);
2546 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD
:
2547 return snd_pcm_hw_params_old_user(substream
, arg
);
2549 case SNDRV_PCM_IOCTL_DRAIN
:
2550 return snd_pcm_drain(substream
, file
);
2551 case SNDRV_PCM_IOCTL_DROP
:
2552 return snd_pcm_drop(substream
);
2553 case SNDRV_PCM_IOCTL_PAUSE
:
2556 snd_pcm_stream_lock_irq(substream
);
2557 res
= snd_pcm_pause(substream
, (int)(unsigned long)arg
);
2558 snd_pcm_stream_unlock_irq(substream
);
2562 snd_printd("unknown ioctl = 0x%x\n", cmd
);
2566 static int snd_pcm_playback_ioctl1(struct file
*file
,
2567 struct snd_pcm_substream
*substream
,
2568 unsigned int cmd
, void __user
*arg
)
2570 if (snd_BUG_ON(!substream
))
2572 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
2575 case SNDRV_PCM_IOCTL_WRITEI_FRAMES
:
2577 struct snd_xferi xferi
;
2578 struct snd_xferi __user
*_xferi
= arg
;
2579 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2580 snd_pcm_sframes_t result
;
2581 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2583 if (put_user(0, &_xferi
->result
))
2585 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2587 result
= snd_pcm_lib_write(substream
, xferi
.buf
, xferi
.frames
);
2588 __put_user(result
, &_xferi
->result
);
2589 return result
< 0 ? result
: 0;
2591 case SNDRV_PCM_IOCTL_WRITEN_FRAMES
:
2593 struct snd_xfern xfern
;
2594 struct snd_xfern __user
*_xfern
= arg
;
2595 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2597 snd_pcm_sframes_t result
;
2598 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2600 if (runtime
->channels
> 128)
2602 if (put_user(0, &_xfern
->result
))
2604 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2607 bufs
= memdup_user(xfern
.bufs
,
2608 sizeof(void *) * runtime
->channels
);
2610 return PTR_ERR(bufs
);
2611 result
= snd_pcm_lib_writev(substream
, bufs
, xfern
.frames
);
2613 __put_user(result
, &_xfern
->result
);
2614 return result
< 0 ? result
: 0;
2616 case SNDRV_PCM_IOCTL_REWIND
:
2618 snd_pcm_uframes_t frames
;
2619 snd_pcm_uframes_t __user
*_frames
= arg
;
2620 snd_pcm_sframes_t result
;
2621 if (get_user(frames
, _frames
))
2623 if (put_user(0, _frames
))
2625 result
= snd_pcm_playback_rewind(substream
, frames
);
2626 __put_user(result
, _frames
);
2627 return result
< 0 ? result
: 0;
2629 case SNDRV_PCM_IOCTL_FORWARD
:
2631 snd_pcm_uframes_t frames
;
2632 snd_pcm_uframes_t __user
*_frames
= arg
;
2633 snd_pcm_sframes_t result
;
2634 if (get_user(frames
, _frames
))
2636 if (put_user(0, _frames
))
2638 result
= snd_pcm_playback_forward(substream
, frames
);
2639 __put_user(result
, _frames
);
2640 return result
< 0 ? result
: 0;
2643 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2646 static int snd_pcm_capture_ioctl1(struct file
*file
,
2647 struct snd_pcm_substream
*substream
,
2648 unsigned int cmd
, void __user
*arg
)
2650 if (snd_BUG_ON(!substream
))
2652 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_CAPTURE
))
2655 case SNDRV_PCM_IOCTL_READI_FRAMES
:
2657 struct snd_xferi xferi
;
2658 struct snd_xferi __user
*_xferi
= arg
;
2659 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2660 snd_pcm_sframes_t result
;
2661 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2663 if (put_user(0, &_xferi
->result
))
2665 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2667 result
= snd_pcm_lib_read(substream
, xferi
.buf
, xferi
.frames
);
2668 __put_user(result
, &_xferi
->result
);
2669 return result
< 0 ? result
: 0;
2671 case SNDRV_PCM_IOCTL_READN_FRAMES
:
2673 struct snd_xfern xfern
;
2674 struct snd_xfern __user
*_xfern
= arg
;
2675 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2677 snd_pcm_sframes_t result
;
2678 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2680 if (runtime
->channels
> 128)
2682 if (put_user(0, &_xfern
->result
))
2684 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2687 bufs
= memdup_user(xfern
.bufs
,
2688 sizeof(void *) * runtime
->channels
);
2690 return PTR_ERR(bufs
);
2691 result
= snd_pcm_lib_readv(substream
, bufs
, xfern
.frames
);
2693 __put_user(result
, &_xfern
->result
);
2694 return result
< 0 ? result
: 0;
2696 case SNDRV_PCM_IOCTL_REWIND
:
2698 snd_pcm_uframes_t frames
;
2699 snd_pcm_uframes_t __user
*_frames
= arg
;
2700 snd_pcm_sframes_t result
;
2701 if (get_user(frames
, _frames
))
2703 if (put_user(0, _frames
))
2705 result
= snd_pcm_capture_rewind(substream
, frames
);
2706 __put_user(result
, _frames
);
2707 return result
< 0 ? result
: 0;
2709 case SNDRV_PCM_IOCTL_FORWARD
:
2711 snd_pcm_uframes_t frames
;
2712 snd_pcm_uframes_t __user
*_frames
= arg
;
2713 snd_pcm_sframes_t result
;
2714 if (get_user(frames
, _frames
))
2716 if (put_user(0, _frames
))
2718 result
= snd_pcm_capture_forward(substream
, frames
);
2719 __put_user(result
, _frames
);
2720 return result
< 0 ? result
: 0;
2723 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2726 static long snd_pcm_playback_ioctl(struct file
*file
, unsigned int cmd
,
2729 struct snd_pcm_file
*pcm_file
;
2731 pcm_file
= file
->private_data
;
2733 if (((cmd
>> 8) & 0xff) != 'A')
2736 return snd_pcm_playback_ioctl1(file
, pcm_file
->substream
, cmd
,
2737 (void __user
*)arg
);
2740 static long snd_pcm_capture_ioctl(struct file
*file
, unsigned int cmd
,
2743 struct snd_pcm_file
*pcm_file
;
2745 pcm_file
= file
->private_data
;
2747 if (((cmd
>> 8) & 0xff) != 'A')
2750 return snd_pcm_capture_ioctl1(file
, pcm_file
->substream
, cmd
,
2751 (void __user
*)arg
);
2754 int snd_pcm_kernel_ioctl(struct snd_pcm_substream
*substream
,
2755 unsigned int cmd
, void *arg
)
2760 fs
= snd_enter_user();
2761 switch (substream
->stream
) {
2762 case SNDRV_PCM_STREAM_PLAYBACK
:
2763 result
= snd_pcm_playback_ioctl1(NULL
, substream
, cmd
,
2764 (void __user
*)arg
);
2766 case SNDRV_PCM_STREAM_CAPTURE
:
2767 result
= snd_pcm_capture_ioctl1(NULL
, substream
, cmd
,
2768 (void __user
*)arg
);
2778 EXPORT_SYMBOL(snd_pcm_kernel_ioctl
);
2780 static ssize_t
snd_pcm_read(struct file
*file
, char __user
*buf
, size_t count
,
2783 struct snd_pcm_file
*pcm_file
;
2784 struct snd_pcm_substream
*substream
;
2785 struct snd_pcm_runtime
*runtime
;
2786 snd_pcm_sframes_t result
;
2788 pcm_file
= file
->private_data
;
2789 substream
= pcm_file
->substream
;
2790 if (PCM_RUNTIME_CHECK(substream
))
2792 runtime
= substream
->runtime
;
2793 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2795 if (!frame_aligned(runtime
, count
))
2797 count
= bytes_to_frames(runtime
, count
);
2798 result
= snd_pcm_lib_read(substream
, buf
, count
);
2800 result
= frames_to_bytes(runtime
, result
);
2804 static ssize_t
snd_pcm_write(struct file
*file
, const char __user
*buf
,
2805 size_t count
, loff_t
* offset
)
2807 struct snd_pcm_file
*pcm_file
;
2808 struct snd_pcm_substream
*substream
;
2809 struct snd_pcm_runtime
*runtime
;
2810 snd_pcm_sframes_t result
;
2812 pcm_file
= file
->private_data
;
2813 substream
= pcm_file
->substream
;
2814 if (PCM_RUNTIME_CHECK(substream
))
2816 runtime
= substream
->runtime
;
2817 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2819 if (!frame_aligned(runtime
, count
))
2821 count
= bytes_to_frames(runtime
, count
);
2822 result
= snd_pcm_lib_write(substream
, buf
, count
);
2824 result
= frames_to_bytes(runtime
, result
);
2828 static ssize_t
snd_pcm_aio_read(struct kiocb
*iocb
, const struct iovec
*iov
,
2829 unsigned long nr_segs
, loff_t pos
)
2832 struct snd_pcm_file
*pcm_file
;
2833 struct snd_pcm_substream
*substream
;
2834 struct snd_pcm_runtime
*runtime
;
2835 snd_pcm_sframes_t result
;
2838 snd_pcm_uframes_t frames
;
2840 pcm_file
= iocb
->ki_filp
->private_data
;
2841 substream
= pcm_file
->substream
;
2842 if (PCM_RUNTIME_CHECK(substream
))
2844 runtime
= substream
->runtime
;
2845 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2847 if (nr_segs
> 1024 || nr_segs
!= runtime
->channels
)
2849 if (!frame_aligned(runtime
, iov
->iov_len
))
2851 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2852 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2855 for (i
= 0; i
< nr_segs
; ++i
)
2856 bufs
[i
] = iov
[i
].iov_base
;
2857 result
= snd_pcm_lib_readv(substream
, bufs
, frames
);
2859 result
= frames_to_bytes(runtime
, result
);
2864 static ssize_t
snd_pcm_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
2865 unsigned long nr_segs
, loff_t pos
)
2867 struct snd_pcm_file
*pcm_file
;
2868 struct snd_pcm_substream
*substream
;
2869 struct snd_pcm_runtime
*runtime
;
2870 snd_pcm_sframes_t result
;
2873 snd_pcm_uframes_t frames
;
2875 pcm_file
= iocb
->ki_filp
->private_data
;
2876 substream
= pcm_file
->substream
;
2877 if (PCM_RUNTIME_CHECK(substream
))
2879 runtime
= substream
->runtime
;
2880 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2882 if (nr_segs
> 128 || nr_segs
!= runtime
->channels
||
2883 !frame_aligned(runtime
, iov
->iov_len
))
2885 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2886 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2889 for (i
= 0; i
< nr_segs
; ++i
)
2890 bufs
[i
] = iov
[i
].iov_base
;
2891 result
= snd_pcm_lib_writev(substream
, bufs
, frames
);
2893 result
= frames_to_bytes(runtime
, result
);
2898 static unsigned int snd_pcm_playback_poll(struct file
*file
, poll_table
* wait
)
2900 struct snd_pcm_file
*pcm_file
;
2901 struct snd_pcm_substream
*substream
;
2902 struct snd_pcm_runtime
*runtime
;
2904 snd_pcm_uframes_t avail
;
2906 pcm_file
= file
->private_data
;
2908 substream
= pcm_file
->substream
;
2909 if (PCM_RUNTIME_CHECK(substream
))
2911 runtime
= substream
->runtime
;
2913 poll_wait(file
, &runtime
->sleep
, wait
);
2915 snd_pcm_stream_lock_irq(substream
);
2916 avail
= snd_pcm_playback_avail(runtime
);
2917 switch (runtime
->status
->state
) {
2918 case SNDRV_PCM_STATE_RUNNING
:
2919 case SNDRV_PCM_STATE_PREPARED
:
2920 case SNDRV_PCM_STATE_PAUSED
:
2921 if (avail
>= runtime
->control
->avail_min
) {
2922 mask
= POLLOUT
| POLLWRNORM
;
2926 case SNDRV_PCM_STATE_DRAINING
:
2930 mask
= POLLOUT
| POLLWRNORM
| POLLERR
;
2933 snd_pcm_stream_unlock_irq(substream
);
2937 static unsigned int snd_pcm_capture_poll(struct file
*file
, poll_table
* wait
)
2939 struct snd_pcm_file
*pcm_file
;
2940 struct snd_pcm_substream
*substream
;
2941 struct snd_pcm_runtime
*runtime
;
2943 snd_pcm_uframes_t avail
;
2945 pcm_file
= file
->private_data
;
2947 substream
= pcm_file
->substream
;
2948 if (PCM_RUNTIME_CHECK(substream
))
2950 runtime
= substream
->runtime
;
2952 poll_wait(file
, &runtime
->sleep
, wait
);
2954 snd_pcm_stream_lock_irq(substream
);
2955 avail
= snd_pcm_capture_avail(runtime
);
2956 switch (runtime
->status
->state
) {
2957 case SNDRV_PCM_STATE_RUNNING
:
2958 case SNDRV_PCM_STATE_PREPARED
:
2959 case SNDRV_PCM_STATE_PAUSED
:
2960 if (avail
>= runtime
->control
->avail_min
) {
2961 mask
= POLLIN
| POLLRDNORM
;
2966 case SNDRV_PCM_STATE_DRAINING
:
2968 mask
= POLLIN
| POLLRDNORM
;
2973 mask
= POLLIN
| POLLRDNORM
| POLLERR
;
2976 snd_pcm_stream_unlock_irq(substream
);
2985 * Only on coherent architectures, we can mmap the status and the control records
2986 * for effcient data transfer. On others, we have to use HWSYNC ioctl...
2988 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
2990 * mmap status record
2992 static int snd_pcm_mmap_status_fault(struct vm_area_struct
*area
,
2993 struct vm_fault
*vmf
)
2995 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
2996 struct snd_pcm_runtime
*runtime
;
2998 if (substream
== NULL
)
2999 return VM_FAULT_SIGBUS
;
3000 runtime
= substream
->runtime
;
3001 vmf
->page
= virt_to_page(runtime
->status
);
3002 get_page(vmf
->page
);
3006 static const struct vm_operations_struct snd_pcm_vm_ops_status
=
3008 .fault
= snd_pcm_mmap_status_fault
,
3011 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3012 struct vm_area_struct
*area
)
3014 struct snd_pcm_runtime
*runtime
;
3016 if (!(area
->vm_flags
& VM_READ
))
3018 runtime
= substream
->runtime
;
3019 size
= area
->vm_end
- area
->vm_start
;
3020 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status
)))
3022 area
->vm_ops
= &snd_pcm_vm_ops_status
;
3023 area
->vm_private_data
= substream
;
3024 area
->vm_flags
|= VM_RESERVED
;
3029 * mmap control record
3031 static int snd_pcm_mmap_control_fault(struct vm_area_struct
*area
,
3032 struct vm_fault
*vmf
)
3034 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3035 struct snd_pcm_runtime
*runtime
;
3037 if (substream
== NULL
)
3038 return VM_FAULT_SIGBUS
;
3039 runtime
= substream
->runtime
;
3040 vmf
->page
= virt_to_page(runtime
->control
);
3041 get_page(vmf
->page
);
3045 static const struct vm_operations_struct snd_pcm_vm_ops_control
=
3047 .fault
= snd_pcm_mmap_control_fault
,
3050 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3051 struct vm_area_struct
*area
)
3053 struct snd_pcm_runtime
*runtime
;
3055 if (!(area
->vm_flags
& VM_READ
))
3057 runtime
= substream
->runtime
;
3058 size
= area
->vm_end
- area
->vm_start
;
3059 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control
)))
3061 area
->vm_ops
= &snd_pcm_vm_ops_control
;
3062 area
->vm_private_data
= substream
;
3063 area
->vm_flags
|= VM_RESERVED
;
3066 #else /* ! coherent mmap */
3068 * don't support mmap for status and control records.
3070 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3071 struct vm_area_struct
*area
)
3075 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3076 struct vm_area_struct
*area
)
3080 #endif /* coherent mmap */
3082 static inline struct page
*
3083 snd_pcm_default_page_ops(struct snd_pcm_substream
*substream
, unsigned long ofs
)
3085 void *vaddr
= substream
->runtime
->dma_area
+ ofs
;
3086 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3087 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3088 return virt_to_page(CAC_ADDR(vaddr
));
3090 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3091 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
) {
3092 dma_addr_t addr
= substream
->runtime
->dma_addr
+ ofs
;
3093 addr
-= get_dma_offset(substream
->dma_buffer
.dev
.dev
);
3094 /* assume dma_handle set via pfn_to_phys() in
3095 * mm/dma-noncoherent.c
3097 return pfn_to_page(addr
>> PAGE_SHIFT
);
3100 return virt_to_page(vaddr
);
3104 * fault callback for mmapping a RAM page
3106 static int snd_pcm_mmap_data_fault(struct vm_area_struct
*area
,
3107 struct vm_fault
*vmf
)
3109 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3110 struct snd_pcm_runtime
*runtime
;
3111 unsigned long offset
;
3115 if (substream
== NULL
)
3116 return VM_FAULT_SIGBUS
;
3117 runtime
= substream
->runtime
;
3118 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
3119 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3120 if (offset
> dma_bytes
- PAGE_SIZE
)
3121 return VM_FAULT_SIGBUS
;
3122 if (substream
->ops
->page
)
3123 page
= substream
->ops
->page(substream
, offset
);
3125 page
= snd_pcm_default_page_ops(substream
, offset
);
3127 return VM_FAULT_SIGBUS
;
3133 static const struct vm_operations_struct snd_pcm_vm_ops_data
= {
3134 .open
= snd_pcm_mmap_data_open
,
3135 .close
= snd_pcm_mmap_data_close
,
3138 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault
= {
3139 .open
= snd_pcm_mmap_data_open
,
3140 .close
= snd_pcm_mmap_data_close
,
3141 .fault
= snd_pcm_mmap_data_fault
,
3144 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3145 /* This should be defined / handled globally! */
3147 #define ARCH_HAS_DMA_MMAP_COHERENT
3152 * mmap the DMA buffer on RAM
3154 static int snd_pcm_default_mmap(struct snd_pcm_substream
*substream
,
3155 struct vm_area_struct
*area
)
3157 area
->vm_flags
|= VM_RESERVED
;
3158 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3159 if (!substream
->ops
->page
&&
3160 substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3161 return dma_mmap_coherent(substream
->dma_buffer
.dev
.dev
,
3163 substream
->runtime
->dma_area
,
3164 substream
->runtime
->dma_addr
,
3165 area
->vm_end
- area
->vm_start
);
3166 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3167 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
&&
3168 !plat_device_is_coherent(substream
->dma_buffer
.dev
.dev
))
3169 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3170 #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3171 /* mmap with fault handler */
3172 area
->vm_ops
= &snd_pcm_vm_ops_data_fault
;
3177 * mmap the DMA buffer on I/O memory area
3179 #if SNDRV_PCM_INFO_MMAP_IOMEM
3180 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream
*substream
,
3181 struct vm_area_struct
*area
)
3184 unsigned long offset
;
3186 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3187 area
->vm_flags
|= VM_IO
;
3188 size
= area
->vm_end
- area
->vm_start
;
3189 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3190 if (io_remap_pfn_range(area
, area
->vm_start
,
3191 (substream
->runtime
->dma_addr
+ offset
) >> PAGE_SHIFT
,
3192 size
, area
->vm_page_prot
))
3197 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem
);
3198 #endif /* SNDRV_PCM_INFO_MMAP */
3200 /* mmap callback with pgprot_noncached */
3201 int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream
*substream
,
3202 struct vm_area_struct
*area
)
3204 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3205 return snd_pcm_default_mmap(substream
, area
);
3207 EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached
);
3212 int snd_pcm_mmap_data(struct snd_pcm_substream
*substream
, struct file
*file
,
3213 struct vm_area_struct
*area
)
3215 struct snd_pcm_runtime
*runtime
;
3217 unsigned long offset
;
3221 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3222 if (!(area
->vm_flags
& (VM_WRITE
|VM_READ
)))
3225 if (!(area
->vm_flags
& VM_READ
))
3228 runtime
= substream
->runtime
;
3229 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
3231 if (!(runtime
->info
& SNDRV_PCM_INFO_MMAP
))
3233 if (runtime
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
||
3234 runtime
->access
== SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
)
3236 size
= area
->vm_end
- area
->vm_start
;
3237 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3238 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3239 if ((size_t)size
> dma_bytes
)
3241 if (offset
> dma_bytes
- size
)
3244 area
->vm_ops
= &snd_pcm_vm_ops_data
;
3245 area
->vm_private_data
= substream
;
3246 if (substream
->ops
->mmap
)
3247 err
= substream
->ops
->mmap(substream
, area
);
3249 err
= snd_pcm_default_mmap(substream
, area
);
3251 atomic_inc(&substream
->mmap_count
);
3255 EXPORT_SYMBOL(snd_pcm_mmap_data
);
3257 static int snd_pcm_mmap(struct file
*file
, struct vm_area_struct
*area
)
3259 struct snd_pcm_file
* pcm_file
;
3260 struct snd_pcm_substream
*substream
;
3261 unsigned long offset
;
3263 pcm_file
= file
->private_data
;
3264 substream
= pcm_file
->substream
;
3265 if (PCM_RUNTIME_CHECK(substream
))
3268 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3270 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3271 if (pcm_file
->no_compat_mmap
)
3273 return snd_pcm_mmap_status(substream
, file
, area
);
3274 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3275 if (pcm_file
->no_compat_mmap
)
3277 return snd_pcm_mmap_control(substream
, file
, area
);
3279 return snd_pcm_mmap_data(substream
, file
, area
);
3284 static int snd_pcm_fasync(int fd
, struct file
* file
, int on
)
3286 struct snd_pcm_file
* pcm_file
;
3287 struct snd_pcm_substream
*substream
;
3288 struct snd_pcm_runtime
*runtime
;
3290 pcm_file
= file
->private_data
;
3291 substream
= pcm_file
->substream
;
3292 if (PCM_RUNTIME_CHECK(substream
))
3294 runtime
= substream
->runtime
;
3295 return fasync_helper(fd
, file
, on
, &runtime
->fasync
);
3301 #ifdef CONFIG_COMPAT
3302 #include "pcm_compat.c"
3304 #define snd_pcm_ioctl_compat NULL
3308 * To be removed helpers to keep binary compatibility
3311 #ifdef CONFIG_SND_SUPPORT_OLD_API
3312 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3313 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3315 static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params
*params
,
3316 struct snd_pcm_hw_params_old
*oparams
)
3320 memset(params
, 0, sizeof(*params
));
3321 params
->flags
= oparams
->flags
;
3322 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3323 params
->masks
[i
].bits
[0] = oparams
->masks
[i
];
3324 memcpy(params
->intervals
, oparams
->intervals
, sizeof(oparams
->intervals
));
3325 params
->rmask
= __OLD_TO_NEW_MASK(oparams
->rmask
);
3326 params
->cmask
= __OLD_TO_NEW_MASK(oparams
->cmask
);
3327 params
->info
= oparams
->info
;
3328 params
->msbits
= oparams
->msbits
;
3329 params
->rate_num
= oparams
->rate_num
;
3330 params
->rate_den
= oparams
->rate_den
;
3331 params
->fifo_size
= oparams
->fifo_size
;
3334 static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old
*oparams
,
3335 struct snd_pcm_hw_params
*params
)
3339 memset(oparams
, 0, sizeof(*oparams
));
3340 oparams
->flags
= params
->flags
;
3341 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3342 oparams
->masks
[i
] = params
->masks
[i
].bits
[0];
3343 memcpy(oparams
->intervals
, params
->intervals
, sizeof(oparams
->intervals
));
3344 oparams
->rmask
= __NEW_TO_OLD_MASK(params
->rmask
);
3345 oparams
->cmask
= __NEW_TO_OLD_MASK(params
->cmask
);
3346 oparams
->info
= params
->info
;
3347 oparams
->msbits
= params
->msbits
;
3348 oparams
->rate_num
= params
->rate_num
;
3349 oparams
->rate_den
= params
->rate_den
;
3350 oparams
->fifo_size
= params
->fifo_size
;
3353 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
3354 struct snd_pcm_hw_params_old __user
* _oparams
)
3356 struct snd_pcm_hw_params
*params
;
3357 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3360 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3364 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3365 if (IS_ERR(oparams
)) {
3366 err
= PTR_ERR(oparams
);
3369 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3370 err
= snd_pcm_hw_refine(substream
, params
);
3371 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3372 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3383 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
3384 struct snd_pcm_hw_params_old __user
* _oparams
)
3386 struct snd_pcm_hw_params
*params
;
3387 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3390 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3394 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3395 if (IS_ERR(oparams
)) {
3396 err
= PTR_ERR(oparams
);
3399 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3400 err
= snd_pcm_hw_params(substream
, params
);
3401 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3402 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3412 #endif /* CONFIG_SND_SUPPORT_OLD_API */
3415 static unsigned long snd_pcm_get_unmapped_area(struct file
*file
,
3418 unsigned long pgoff
,
3419 unsigned long flags
)
3421 struct snd_pcm_file
*pcm_file
= file
->private_data
;
3422 struct snd_pcm_substream
*substream
= pcm_file
->substream
;
3423 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3424 unsigned long offset
= pgoff
<< PAGE_SHIFT
;
3427 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3428 return (unsigned long)runtime
->status
;
3429 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3430 return (unsigned long)runtime
->control
;
3432 return (unsigned long)runtime
->dma_area
+ offset
;
3436 # define snd_pcm_get_unmapped_area NULL
3443 const struct file_operations snd_pcm_f_ops
[2] = {
3445 .owner
= THIS_MODULE
,
3446 .write
= snd_pcm_write
,
3447 .aio_write
= snd_pcm_aio_write
,
3448 .open
= snd_pcm_playback_open
,
3449 .release
= snd_pcm_release
,
3450 .llseek
= no_llseek
,
3451 .poll
= snd_pcm_playback_poll
,
3452 .unlocked_ioctl
= snd_pcm_playback_ioctl
,
3453 .compat_ioctl
= snd_pcm_ioctl_compat
,
3454 .mmap
= snd_pcm_mmap
,
3455 .fasync
= snd_pcm_fasync
,
3456 .get_unmapped_area
= snd_pcm_get_unmapped_area
,
3459 .owner
= THIS_MODULE
,
3460 .read
= snd_pcm_read
,
3461 .aio_read
= snd_pcm_aio_read
,
3462 .open
= snd_pcm_capture_open
,
3463 .release
= snd_pcm_release
,
3464 .llseek
= no_llseek
,
3465 .poll
= snd_pcm_capture_poll
,
3466 .unlocked_ioctl
= snd_pcm_capture_ioctl
,
3467 .compat_ioctl
= snd_pcm_ioctl_compat
,
3468 .mmap
= snd_pcm_mmap
,
3469 .fasync
= snd_pcm_fasync
,
3470 .get_unmapped_area
= snd_pcm_get_unmapped_area
,