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 (substream
->latency_pm_qos_req
) {
455 pm_qos_remove_request(substream
->latency_pm_qos_req
);
456 substream
->latency_pm_qos_req
= NULL
;
458 if ((usecs
= period_to_usecs(runtime
)) >= 0)
459 substream
->latency_pm_qos_req
= pm_qos_add_request(
460 PM_QOS_CPU_DMA_LATENCY
, usecs
);
463 /* hardware might be unuseable from this time,
464 so we force application to retry to set
465 the correct hardware parameter settings */
466 runtime
->status
->state
= SNDRV_PCM_STATE_OPEN
;
467 if (substream
->ops
->hw_free
!= NULL
)
468 substream
->ops
->hw_free(substream
);
472 static int snd_pcm_hw_params_user(struct snd_pcm_substream
*substream
,
473 struct snd_pcm_hw_params __user
* _params
)
475 struct snd_pcm_hw_params
*params
;
478 params
= memdup_user(_params
, sizeof(*params
));
480 return PTR_ERR(params
);
482 err
= snd_pcm_hw_params(substream
, params
);
483 if (copy_to_user(_params
, params
, sizeof(*params
))) {
492 static int snd_pcm_hw_free(struct snd_pcm_substream
*substream
)
494 struct snd_pcm_runtime
*runtime
;
497 if (PCM_RUNTIME_CHECK(substream
))
499 runtime
= substream
->runtime
;
500 snd_pcm_stream_lock_irq(substream
);
501 switch (runtime
->status
->state
) {
502 case SNDRV_PCM_STATE_SETUP
:
503 case SNDRV_PCM_STATE_PREPARED
:
506 snd_pcm_stream_unlock_irq(substream
);
509 snd_pcm_stream_unlock_irq(substream
);
510 if (atomic_read(&substream
->mmap_count
))
512 if (substream
->ops
->hw_free
)
513 result
= substream
->ops
->hw_free(substream
);
514 runtime
->status
->state
= SNDRV_PCM_STATE_OPEN
;
515 pm_qos_remove_request(substream
->latency_pm_qos_req
);
516 substream
->latency_pm_qos_req
= NULL
;
520 static int snd_pcm_sw_params(struct snd_pcm_substream
*substream
,
521 struct snd_pcm_sw_params
*params
)
523 struct snd_pcm_runtime
*runtime
;
526 if (PCM_RUNTIME_CHECK(substream
))
528 runtime
= substream
->runtime
;
529 snd_pcm_stream_lock_irq(substream
);
530 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
) {
531 snd_pcm_stream_unlock_irq(substream
);
534 snd_pcm_stream_unlock_irq(substream
);
536 if (params
->tstamp_mode
> SNDRV_PCM_TSTAMP_LAST
)
538 if (params
->avail_min
== 0)
540 if (params
->silence_size
>= runtime
->boundary
) {
541 if (params
->silence_threshold
!= 0)
544 if (params
->silence_size
> params
->silence_threshold
)
546 if (params
->silence_threshold
> runtime
->buffer_size
)
550 snd_pcm_stream_lock_irq(substream
);
551 runtime
->tstamp_mode
= params
->tstamp_mode
;
552 runtime
->period_step
= params
->period_step
;
553 runtime
->control
->avail_min
= params
->avail_min
;
554 runtime
->start_threshold
= params
->start_threshold
;
555 runtime
->stop_threshold
= params
->stop_threshold
;
556 runtime
->silence_threshold
= params
->silence_threshold
;
557 runtime
->silence_size
= params
->silence_size
;
558 params
->boundary
= runtime
->boundary
;
559 if (snd_pcm_running(substream
)) {
560 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
561 runtime
->silence_size
> 0)
562 snd_pcm_playback_silence(substream
, ULONG_MAX
);
563 err
= snd_pcm_update_state(substream
, runtime
);
565 snd_pcm_stream_unlock_irq(substream
);
569 static int snd_pcm_sw_params_user(struct snd_pcm_substream
*substream
,
570 struct snd_pcm_sw_params __user
* _params
)
572 struct snd_pcm_sw_params params
;
574 if (copy_from_user(¶ms
, _params
, sizeof(params
)))
576 err
= snd_pcm_sw_params(substream
, ¶ms
);
577 if (copy_to_user(_params
, ¶ms
, sizeof(params
)))
582 int snd_pcm_status(struct snd_pcm_substream
*substream
,
583 struct snd_pcm_status
*status
)
585 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
587 snd_pcm_stream_lock_irq(substream
);
588 status
->state
= runtime
->status
->state
;
589 status
->suspended_state
= runtime
->status
->suspended_state
;
590 if (status
->state
== SNDRV_PCM_STATE_OPEN
)
592 status
->trigger_tstamp
= runtime
->trigger_tstamp
;
593 if (snd_pcm_running(substream
)) {
594 snd_pcm_update_hw_ptr(substream
);
595 if (runtime
->tstamp_mode
== SNDRV_PCM_TSTAMP_ENABLE
) {
596 status
->tstamp
= runtime
->status
->tstamp
;
600 snd_pcm_gettime(runtime
, &status
->tstamp
);
602 status
->appl_ptr
= runtime
->control
->appl_ptr
;
603 status
->hw_ptr
= runtime
->status
->hw_ptr
;
604 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
605 status
->avail
= snd_pcm_playback_avail(runtime
);
606 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
||
607 runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
608 status
->delay
= runtime
->buffer_size
- status
->avail
;
609 status
->delay
+= runtime
->delay
;
613 status
->avail
= snd_pcm_capture_avail(runtime
);
614 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
)
615 status
->delay
= status
->avail
+ runtime
->delay
;
619 status
->avail_max
= runtime
->avail_max
;
620 status
->overrange
= runtime
->overrange
;
621 runtime
->avail_max
= 0;
622 runtime
->overrange
= 0;
624 snd_pcm_stream_unlock_irq(substream
);
628 static int snd_pcm_status_user(struct snd_pcm_substream
*substream
,
629 struct snd_pcm_status __user
* _status
)
631 struct snd_pcm_status status
;
634 memset(&status
, 0, sizeof(status
));
635 res
= snd_pcm_status(substream
, &status
);
638 if (copy_to_user(_status
, &status
, sizeof(status
)))
643 static int snd_pcm_channel_info(struct snd_pcm_substream
*substream
,
644 struct snd_pcm_channel_info
* info
)
646 struct snd_pcm_runtime
*runtime
;
647 unsigned int channel
;
649 channel
= info
->channel
;
650 runtime
= substream
->runtime
;
651 snd_pcm_stream_lock_irq(substream
);
652 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
) {
653 snd_pcm_stream_unlock_irq(substream
);
656 snd_pcm_stream_unlock_irq(substream
);
657 if (channel
>= runtime
->channels
)
659 memset(info
, 0, sizeof(*info
));
660 info
->channel
= channel
;
661 return substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_CHANNEL_INFO
, info
);
664 static int snd_pcm_channel_info_user(struct snd_pcm_substream
*substream
,
665 struct snd_pcm_channel_info __user
* _info
)
667 struct snd_pcm_channel_info info
;
670 if (copy_from_user(&info
, _info
, sizeof(info
)))
672 res
= snd_pcm_channel_info(substream
, &info
);
675 if (copy_to_user(_info
, &info
, sizeof(info
)))
680 static void snd_pcm_trigger_tstamp(struct snd_pcm_substream
*substream
)
682 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
683 if (runtime
->trigger_master
== NULL
)
685 if (runtime
->trigger_master
== substream
) {
686 snd_pcm_gettime(runtime
, &runtime
->trigger_tstamp
);
688 snd_pcm_trigger_tstamp(runtime
->trigger_master
);
689 runtime
->trigger_tstamp
= runtime
->trigger_master
->runtime
->trigger_tstamp
;
691 runtime
->trigger_master
= NULL
;
695 int (*pre_action
)(struct snd_pcm_substream
*substream
, int state
);
696 int (*do_action
)(struct snd_pcm_substream
*substream
, int state
);
697 void (*undo_action
)(struct snd_pcm_substream
*substream
, int state
);
698 void (*post_action
)(struct snd_pcm_substream
*substream
, int state
);
702 * this functions is core for handling of linked stream
703 * Note: the stream state might be changed also on failure
704 * Note2: call with calling stream lock + link lock
706 static int snd_pcm_action_group(struct action_ops
*ops
,
707 struct snd_pcm_substream
*substream
,
708 int state
, int do_lock
)
710 struct snd_pcm_substream
*s
= NULL
;
711 struct snd_pcm_substream
*s1
;
714 snd_pcm_group_for_each_entry(s
, substream
) {
715 if (do_lock
&& s
!= substream
)
716 spin_lock_nested(&s
->self_group
.lock
,
717 SINGLE_DEPTH_NESTING
);
718 res
= ops
->pre_action(s
, state
);
722 snd_pcm_group_for_each_entry(s
, substream
) {
723 res
= ops
->do_action(s
, state
);
725 if (ops
->undo_action
) {
726 snd_pcm_group_for_each_entry(s1
, substream
) {
727 if (s1
== s
) /* failed stream */
729 ops
->undo_action(s1
, state
);
732 s
= NULL
; /* unlock all */
736 snd_pcm_group_for_each_entry(s
, substream
) {
737 ops
->post_action(s
, state
);
742 snd_pcm_group_for_each_entry(s1
, substream
) {
744 spin_unlock(&s1
->self_group
.lock
);
745 if (s1
== s
) /* end */
753 * Note: call with stream lock
755 static int snd_pcm_action_single(struct action_ops
*ops
,
756 struct snd_pcm_substream
*substream
,
761 res
= ops
->pre_action(substream
, state
);
764 res
= ops
->do_action(substream
, state
);
766 ops
->post_action(substream
, state
);
767 else if (ops
->undo_action
)
768 ops
->undo_action(substream
, state
);
773 * Note: call with stream lock
775 static int snd_pcm_action(struct action_ops
*ops
,
776 struct snd_pcm_substream
*substream
,
781 if (snd_pcm_stream_linked(substream
)) {
782 if (!spin_trylock(&substream
->group
->lock
)) {
783 spin_unlock(&substream
->self_group
.lock
);
784 spin_lock(&substream
->group
->lock
);
785 spin_lock(&substream
->self_group
.lock
);
787 res
= snd_pcm_action_group(ops
, substream
, state
, 1);
788 spin_unlock(&substream
->group
->lock
);
790 res
= snd_pcm_action_single(ops
, substream
, state
);
796 * Note: don't use any locks before
798 static int snd_pcm_action_lock_irq(struct action_ops
*ops
,
799 struct snd_pcm_substream
*substream
,
804 read_lock_irq(&snd_pcm_link_rwlock
);
805 if (snd_pcm_stream_linked(substream
)) {
806 spin_lock(&substream
->group
->lock
);
807 spin_lock(&substream
->self_group
.lock
);
808 res
= snd_pcm_action_group(ops
, substream
, state
, 1);
809 spin_unlock(&substream
->self_group
.lock
);
810 spin_unlock(&substream
->group
->lock
);
812 spin_lock(&substream
->self_group
.lock
);
813 res
= snd_pcm_action_single(ops
, substream
, state
);
814 spin_unlock(&substream
->self_group
.lock
);
816 read_unlock_irq(&snd_pcm_link_rwlock
);
822 static int snd_pcm_action_nonatomic(struct action_ops
*ops
,
823 struct snd_pcm_substream
*substream
,
828 down_read(&snd_pcm_link_rwsem
);
829 if (snd_pcm_stream_linked(substream
))
830 res
= snd_pcm_action_group(ops
, substream
, state
, 0);
832 res
= snd_pcm_action_single(ops
, substream
, state
);
833 up_read(&snd_pcm_link_rwsem
);
840 static int snd_pcm_pre_start(struct snd_pcm_substream
*substream
, int state
)
842 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
843 if (runtime
->status
->state
!= SNDRV_PCM_STATE_PREPARED
)
845 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
846 !snd_pcm_playback_data(substream
))
848 runtime
->trigger_master
= substream
;
852 static int snd_pcm_do_start(struct snd_pcm_substream
*substream
, int state
)
854 if (substream
->runtime
->trigger_master
!= substream
)
856 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_START
);
859 static void snd_pcm_undo_start(struct snd_pcm_substream
*substream
, int state
)
861 if (substream
->runtime
->trigger_master
== substream
)
862 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
865 static void snd_pcm_post_start(struct snd_pcm_substream
*substream
, int state
)
867 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
868 snd_pcm_trigger_tstamp(substream
);
869 runtime
->hw_ptr_jiffies
= jiffies
;
870 runtime
->status
->state
= state
;
871 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
872 runtime
->silence_size
> 0)
873 snd_pcm_playback_silence(substream
, ULONG_MAX
);
874 if (substream
->timer
)
875 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTART
,
876 &runtime
->trigger_tstamp
);
879 static struct action_ops snd_pcm_action_start
= {
880 .pre_action
= snd_pcm_pre_start
,
881 .do_action
= snd_pcm_do_start
,
882 .undo_action
= snd_pcm_undo_start
,
883 .post_action
= snd_pcm_post_start
887 * snd_pcm_start - start all linked streams
888 * @substream: the PCM substream instance
890 int snd_pcm_start(struct snd_pcm_substream
*substream
)
892 return snd_pcm_action(&snd_pcm_action_start
, substream
,
893 SNDRV_PCM_STATE_RUNNING
);
899 static int snd_pcm_pre_stop(struct snd_pcm_substream
*substream
, int state
)
901 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
902 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
904 runtime
->trigger_master
= substream
;
908 static int snd_pcm_do_stop(struct snd_pcm_substream
*substream
, int state
)
910 if (substream
->runtime
->trigger_master
== substream
&&
911 snd_pcm_running(substream
))
912 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_STOP
);
913 return 0; /* unconditonally stop all substreams */
916 static void snd_pcm_post_stop(struct snd_pcm_substream
*substream
, int state
)
918 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
919 if (runtime
->status
->state
!= state
) {
920 snd_pcm_trigger_tstamp(substream
);
921 if (substream
->timer
)
922 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSTOP
,
923 &runtime
->trigger_tstamp
);
924 runtime
->status
->state
= state
;
926 wake_up(&runtime
->sleep
);
927 wake_up(&runtime
->tsleep
);
930 static struct action_ops snd_pcm_action_stop
= {
931 .pre_action
= snd_pcm_pre_stop
,
932 .do_action
= snd_pcm_do_stop
,
933 .post_action
= snd_pcm_post_stop
937 * snd_pcm_stop - try to stop all running streams in the substream group
938 * @substream: the PCM substream instance
939 * @state: PCM state after stopping the stream
941 * The state of each stream is then changed to the given state unconditionally.
943 int snd_pcm_stop(struct snd_pcm_substream
*substream
, int state
)
945 return snd_pcm_action(&snd_pcm_action_stop
, substream
, state
);
948 EXPORT_SYMBOL(snd_pcm_stop
);
951 * snd_pcm_drain_done - stop the DMA only when the given stream is playback
952 * @substream: the PCM substream
954 * After stopping, the state is changed to SETUP.
955 * Unlike snd_pcm_stop(), this affects only the given stream.
957 int snd_pcm_drain_done(struct snd_pcm_substream
*substream
)
959 return snd_pcm_action_single(&snd_pcm_action_stop
, substream
,
960 SNDRV_PCM_STATE_SETUP
);
966 static int snd_pcm_pre_pause(struct snd_pcm_substream
*substream
, int push
)
968 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
969 if (!(runtime
->info
& SNDRV_PCM_INFO_PAUSE
))
972 if (runtime
->status
->state
!= SNDRV_PCM_STATE_RUNNING
)
974 } else if (runtime
->status
->state
!= SNDRV_PCM_STATE_PAUSED
)
976 runtime
->trigger_master
= substream
;
980 static int snd_pcm_do_pause(struct snd_pcm_substream
*substream
, int push
)
982 if (substream
->runtime
->trigger_master
!= substream
)
984 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
985 * a delta betwen the current jiffies, this gives a large enough
986 * delta, effectively to skip the check once.
988 substream
->runtime
->hw_ptr_jiffies
= jiffies
- HZ
* 1000;
989 return substream
->ops
->trigger(substream
,
990 push
? SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
991 SNDRV_PCM_TRIGGER_PAUSE_RELEASE
);
994 static void snd_pcm_undo_pause(struct snd_pcm_substream
*substream
, int push
)
996 if (substream
->runtime
->trigger_master
== substream
)
997 substream
->ops
->trigger(substream
,
998 push
? SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
999 SNDRV_PCM_TRIGGER_PAUSE_PUSH
);
1002 static void snd_pcm_post_pause(struct snd_pcm_substream
*substream
, int push
)
1004 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1005 snd_pcm_trigger_tstamp(substream
);
1007 runtime
->status
->state
= SNDRV_PCM_STATE_PAUSED
;
1008 if (substream
->timer
)
1009 snd_timer_notify(substream
->timer
,
1010 SNDRV_TIMER_EVENT_MPAUSE
,
1011 &runtime
->trigger_tstamp
);
1012 wake_up(&runtime
->sleep
);
1013 wake_up(&runtime
->tsleep
);
1015 runtime
->status
->state
= SNDRV_PCM_STATE_RUNNING
;
1016 if (substream
->timer
)
1017 snd_timer_notify(substream
->timer
,
1018 SNDRV_TIMER_EVENT_MCONTINUE
,
1019 &runtime
->trigger_tstamp
);
1023 static struct action_ops snd_pcm_action_pause
= {
1024 .pre_action
= snd_pcm_pre_pause
,
1025 .do_action
= snd_pcm_do_pause
,
1026 .undo_action
= snd_pcm_undo_pause
,
1027 .post_action
= snd_pcm_post_pause
1031 * Push/release the pause for all linked streams.
1033 static int snd_pcm_pause(struct snd_pcm_substream
*substream
, int push
)
1035 return snd_pcm_action(&snd_pcm_action_pause
, substream
, push
);
1041 static int snd_pcm_pre_suspend(struct snd_pcm_substream
*substream
, int state
)
1043 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1044 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1046 runtime
->trigger_master
= substream
;
1050 static int snd_pcm_do_suspend(struct snd_pcm_substream
*substream
, int state
)
1052 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1053 if (runtime
->trigger_master
!= substream
)
1055 if (! snd_pcm_running(substream
))
1057 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1058 return 0; /* suspend unconditionally */
1061 static void snd_pcm_post_suspend(struct snd_pcm_substream
*substream
, int state
)
1063 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1064 snd_pcm_trigger_tstamp(substream
);
1065 if (substream
->timer
)
1066 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSUSPEND
,
1067 &runtime
->trigger_tstamp
);
1068 runtime
->status
->suspended_state
= runtime
->status
->state
;
1069 runtime
->status
->state
= SNDRV_PCM_STATE_SUSPENDED
;
1070 wake_up(&runtime
->sleep
);
1071 wake_up(&runtime
->tsleep
);
1074 static struct action_ops snd_pcm_action_suspend
= {
1075 .pre_action
= snd_pcm_pre_suspend
,
1076 .do_action
= snd_pcm_do_suspend
,
1077 .post_action
= snd_pcm_post_suspend
1081 * snd_pcm_suspend - trigger SUSPEND to all linked streams
1082 * @substream: the PCM substream
1084 * After this call, all streams are changed to SUSPENDED state.
1086 int snd_pcm_suspend(struct snd_pcm_substream
*substream
)
1089 unsigned long flags
;
1094 snd_pcm_stream_lock_irqsave(substream
, flags
);
1095 err
= snd_pcm_action(&snd_pcm_action_suspend
, substream
, 0);
1096 snd_pcm_stream_unlock_irqrestore(substream
, flags
);
1100 EXPORT_SYMBOL(snd_pcm_suspend
);
1103 * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm
1104 * @pcm: the PCM instance
1106 * After this call, all streams are changed to SUSPENDED state.
1108 int snd_pcm_suspend_all(struct snd_pcm
*pcm
)
1110 struct snd_pcm_substream
*substream
;
1111 int stream
, err
= 0;
1116 for (stream
= 0; stream
< 2; stream
++) {
1117 for (substream
= pcm
->streams
[stream
].substream
;
1118 substream
; substream
= substream
->next
) {
1119 /* FIXME: the open/close code should lock this as well */
1120 if (substream
->runtime
== NULL
)
1122 err
= snd_pcm_suspend(substream
);
1123 if (err
< 0 && err
!= -EBUSY
)
1130 EXPORT_SYMBOL(snd_pcm_suspend_all
);
1134 static int snd_pcm_pre_resume(struct snd_pcm_substream
*substream
, int state
)
1136 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1137 if (!(runtime
->info
& SNDRV_PCM_INFO_RESUME
))
1139 runtime
->trigger_master
= substream
;
1143 static int snd_pcm_do_resume(struct snd_pcm_substream
*substream
, int state
)
1145 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1146 if (runtime
->trigger_master
!= substream
)
1148 /* DMA not running previously? */
1149 if (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_RUNNING
&&
1150 (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_DRAINING
||
1151 substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
1153 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_RESUME
);
1156 static void snd_pcm_undo_resume(struct snd_pcm_substream
*substream
, int state
)
1158 if (substream
->runtime
->trigger_master
== substream
&&
1159 snd_pcm_running(substream
))
1160 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1163 static void snd_pcm_post_resume(struct snd_pcm_substream
*substream
, int state
)
1165 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1166 snd_pcm_trigger_tstamp(substream
);
1167 if (substream
->timer
)
1168 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MRESUME
,
1169 &runtime
->trigger_tstamp
);
1170 runtime
->status
->state
= runtime
->status
->suspended_state
;
1173 static struct action_ops snd_pcm_action_resume
= {
1174 .pre_action
= snd_pcm_pre_resume
,
1175 .do_action
= snd_pcm_do_resume
,
1176 .undo_action
= snd_pcm_undo_resume
,
1177 .post_action
= snd_pcm_post_resume
1180 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1182 struct snd_card
*card
= substream
->pcm
->card
;
1185 snd_power_lock(card
);
1186 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1187 res
= snd_pcm_action_lock_irq(&snd_pcm_action_resume
, substream
, 0);
1188 snd_power_unlock(card
);
1194 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1199 #endif /* CONFIG_PM */
1204 * Change the RUNNING stream(s) to XRUN state.
1206 static int snd_pcm_xrun(struct snd_pcm_substream
*substream
)
1208 struct snd_card
*card
= substream
->pcm
->card
;
1209 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1212 snd_power_lock(card
);
1213 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1214 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1219 snd_pcm_stream_lock_irq(substream
);
1220 switch (runtime
->status
->state
) {
1221 case SNDRV_PCM_STATE_XRUN
:
1222 result
= 0; /* already there */
1224 case SNDRV_PCM_STATE_RUNNING
:
1225 result
= snd_pcm_stop(substream
, SNDRV_PCM_STATE_XRUN
);
1230 snd_pcm_stream_unlock_irq(substream
);
1232 snd_power_unlock(card
);
1239 static int snd_pcm_pre_reset(struct snd_pcm_substream
*substream
, int state
)
1241 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1242 switch (runtime
->status
->state
) {
1243 case SNDRV_PCM_STATE_RUNNING
:
1244 case SNDRV_PCM_STATE_PREPARED
:
1245 case SNDRV_PCM_STATE_PAUSED
:
1246 case SNDRV_PCM_STATE_SUSPENDED
:
1253 static int snd_pcm_do_reset(struct snd_pcm_substream
*substream
, int state
)
1255 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1256 int err
= substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_RESET
, NULL
);
1259 runtime
->hw_ptr_base
= 0;
1260 runtime
->hw_ptr_interrupt
= runtime
->status
->hw_ptr
-
1261 runtime
->status
->hw_ptr
% runtime
->period_size
;
1262 runtime
->silence_start
= runtime
->status
->hw_ptr
;
1263 runtime
->silence_filled
= 0;
1267 static void snd_pcm_post_reset(struct snd_pcm_substream
*substream
, int state
)
1269 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1270 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1271 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
1272 runtime
->silence_size
> 0)
1273 snd_pcm_playback_silence(substream
, ULONG_MAX
);
1276 static struct action_ops snd_pcm_action_reset
= {
1277 .pre_action
= snd_pcm_pre_reset
,
1278 .do_action
= snd_pcm_do_reset
,
1279 .post_action
= snd_pcm_post_reset
1282 static int snd_pcm_reset(struct snd_pcm_substream
*substream
)
1284 return snd_pcm_action_nonatomic(&snd_pcm_action_reset
, substream
, 0);
1290 /* we use the second argument for updating f_flags */
1291 static int snd_pcm_pre_prepare(struct snd_pcm_substream
*substream
,
1294 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1295 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1296 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
)
1298 if (snd_pcm_running(substream
))
1300 substream
->f_flags
= f_flags
;
1304 static int snd_pcm_do_prepare(struct snd_pcm_substream
*substream
, int state
)
1307 err
= substream
->ops
->prepare(substream
);
1310 return snd_pcm_do_reset(substream
, 0);
1313 static void snd_pcm_post_prepare(struct snd_pcm_substream
*substream
, int state
)
1315 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1316 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1317 runtime
->status
->state
= SNDRV_PCM_STATE_PREPARED
;
1320 static struct action_ops snd_pcm_action_prepare
= {
1321 .pre_action
= snd_pcm_pre_prepare
,
1322 .do_action
= snd_pcm_do_prepare
,
1323 .post_action
= snd_pcm_post_prepare
1327 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1328 * @substream: the PCM substream instance
1329 * @file: file to refer f_flags
1331 static int snd_pcm_prepare(struct snd_pcm_substream
*substream
,
1335 struct snd_card
*card
= substream
->pcm
->card
;
1339 f_flags
= file
->f_flags
;
1341 f_flags
= substream
->f_flags
;
1343 snd_power_lock(card
);
1344 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1345 res
= snd_pcm_action_nonatomic(&snd_pcm_action_prepare
,
1346 substream
, f_flags
);
1347 snd_power_unlock(card
);
1355 static int snd_pcm_pre_drain_init(struct snd_pcm_substream
*substream
, int state
)
1357 substream
->runtime
->trigger_master
= substream
;
1361 static int snd_pcm_do_drain_init(struct snd_pcm_substream
*substream
, int state
)
1363 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1364 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1365 switch (runtime
->status
->state
) {
1366 case SNDRV_PCM_STATE_PREPARED
:
1367 /* start playback stream if possible */
1368 if (! snd_pcm_playback_empty(substream
)) {
1369 snd_pcm_do_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1370 snd_pcm_post_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1373 case SNDRV_PCM_STATE_RUNNING
:
1374 runtime
->status
->state
= SNDRV_PCM_STATE_DRAINING
;
1380 /* stop running stream */
1381 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
) {
1382 int new_state
= snd_pcm_capture_avail(runtime
) > 0 ?
1383 SNDRV_PCM_STATE_DRAINING
: SNDRV_PCM_STATE_SETUP
;
1384 snd_pcm_do_stop(substream
, new_state
);
1385 snd_pcm_post_stop(substream
, new_state
);
1391 static void snd_pcm_post_drain_init(struct snd_pcm_substream
*substream
, int state
)
1395 static struct action_ops snd_pcm_action_drain_init
= {
1396 .pre_action
= snd_pcm_pre_drain_init
,
1397 .do_action
= snd_pcm_do_drain_init
,
1398 .post_action
= snd_pcm_post_drain_init
1401 static int snd_pcm_drop(struct snd_pcm_substream
*substream
);
1404 * Drain the stream(s).
1405 * When the substream is linked, sync until the draining of all playback streams
1407 * After this call, all streams are supposed to be either SETUP or DRAINING
1408 * (capture only) state.
1410 static int snd_pcm_drain(struct snd_pcm_substream
*substream
,
1413 struct snd_card
*card
;
1414 struct snd_pcm_runtime
*runtime
;
1415 struct snd_pcm_substream
*s
;
1420 card
= substream
->pcm
->card
;
1421 runtime
= substream
->runtime
;
1423 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
1426 snd_power_lock(card
);
1427 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1428 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1430 snd_power_unlock(card
);
1436 if (file
->f_flags
& O_NONBLOCK
)
1438 } else if (substream
->f_flags
& O_NONBLOCK
)
1441 down_read(&snd_pcm_link_rwsem
);
1442 snd_pcm_stream_lock_irq(substream
);
1444 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1445 snd_pcm_pause(substream
, 0);
1447 /* pre-start/stop - all running streams are changed to DRAINING state */
1448 result
= snd_pcm_action(&snd_pcm_action_drain_init
, substream
, 0);
1451 /* in non-blocking, we don't wait in ioctl but let caller poll */
1459 struct snd_pcm_runtime
*to_check
;
1460 if (signal_pending(current
)) {
1461 result
= -ERESTARTSYS
;
1464 /* find a substream to drain */
1466 snd_pcm_group_for_each_entry(s
, substream
) {
1467 if (s
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1469 runtime
= s
->runtime
;
1470 if (runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
1476 break; /* all drained */
1477 init_waitqueue_entry(&wait
, current
);
1478 add_wait_queue(&to_check
->sleep
, &wait
);
1479 set_current_state(TASK_INTERRUPTIBLE
);
1480 snd_pcm_stream_unlock_irq(substream
);
1481 up_read(&snd_pcm_link_rwsem
);
1482 snd_power_unlock(card
);
1483 tout
= schedule_timeout(10 * HZ
);
1484 snd_power_lock(card
);
1485 down_read(&snd_pcm_link_rwsem
);
1486 snd_pcm_stream_lock_irq(substream
);
1487 remove_wait_queue(&to_check
->sleep
, &wait
);
1489 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1492 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1493 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1501 snd_pcm_stream_unlock_irq(substream
);
1502 up_read(&snd_pcm_link_rwsem
);
1503 snd_power_unlock(card
);
1511 * Immediately put all linked substreams into SETUP state.
1513 static int snd_pcm_drop(struct snd_pcm_substream
*substream
)
1515 struct snd_pcm_runtime
*runtime
;
1516 struct snd_card
*card
;
1519 if (PCM_RUNTIME_CHECK(substream
))
1521 runtime
= substream
->runtime
;
1522 card
= substream
->pcm
->card
;
1524 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1525 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
||
1526 runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1529 snd_pcm_stream_lock_irq(substream
);
1531 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1532 snd_pcm_pause(substream
, 0);
1534 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1535 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */
1536 snd_pcm_stream_unlock_irq(substream
);
1542 /* WARNING: Don't forget to fput back the file */
1543 static struct file
*snd_pcm_file_fd(int fd
)
1546 struct inode
*inode
;
1552 inode
= file
->f_path
.dentry
->d_inode
;
1553 if (!S_ISCHR(inode
->i_mode
) ||
1554 imajor(inode
) != snd_major
) {
1558 minor
= iminor(inode
);
1559 if (!snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_PLAYBACK
) &&
1560 !snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_CAPTURE
)) {
1570 static int snd_pcm_link(struct snd_pcm_substream
*substream
, int fd
)
1574 struct snd_pcm_file
*pcm_file
;
1575 struct snd_pcm_substream
*substream1
;
1577 file
= snd_pcm_file_fd(fd
);
1580 pcm_file
= file
->private_data
;
1581 substream1
= pcm_file
->substream
;
1582 down_write(&snd_pcm_link_rwsem
);
1583 write_lock_irq(&snd_pcm_link_rwlock
);
1584 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1585 substream
->runtime
->status
->state
!= substream1
->runtime
->status
->state
) {
1589 if (snd_pcm_stream_linked(substream1
)) {
1593 if (!snd_pcm_stream_linked(substream
)) {
1594 substream
->group
= kmalloc(sizeof(struct snd_pcm_group
), GFP_ATOMIC
);
1595 if (substream
->group
== NULL
) {
1599 spin_lock_init(&substream
->group
->lock
);
1600 INIT_LIST_HEAD(&substream
->group
->substreams
);
1601 list_add_tail(&substream
->link_list
, &substream
->group
->substreams
);
1602 substream
->group
->count
= 1;
1604 list_add_tail(&substream1
->link_list
, &substream
->group
->substreams
);
1605 substream
->group
->count
++;
1606 substream1
->group
= substream
->group
;
1608 write_unlock_irq(&snd_pcm_link_rwlock
);
1609 up_write(&snd_pcm_link_rwsem
);
1614 static void relink_to_local(struct snd_pcm_substream
*substream
)
1616 substream
->group
= &substream
->self_group
;
1617 INIT_LIST_HEAD(&substream
->self_group
.substreams
);
1618 list_add_tail(&substream
->link_list
, &substream
->self_group
.substreams
);
1621 static int snd_pcm_unlink(struct snd_pcm_substream
*substream
)
1623 struct snd_pcm_substream
*s
;
1626 down_write(&snd_pcm_link_rwsem
);
1627 write_lock_irq(&snd_pcm_link_rwlock
);
1628 if (!snd_pcm_stream_linked(substream
)) {
1632 list_del(&substream
->link_list
);
1633 substream
->group
->count
--;
1634 if (substream
->group
->count
== 1) { /* detach the last stream, too */
1635 snd_pcm_group_for_each_entry(s
, substream
) {
1639 kfree(substream
->group
);
1641 relink_to_local(substream
);
1643 write_unlock_irq(&snd_pcm_link_rwlock
);
1644 up_write(&snd_pcm_link_rwsem
);
1651 static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params
*params
,
1652 struct snd_pcm_hw_rule
*rule
)
1654 struct snd_interval t
;
1655 snd_interval_mul(hw_param_interval_c(params
, rule
->deps
[0]),
1656 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1657 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1660 static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params
*params
,
1661 struct snd_pcm_hw_rule
*rule
)
1663 struct snd_interval t
;
1664 snd_interval_div(hw_param_interval_c(params
, rule
->deps
[0]),
1665 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1666 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1669 static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params
*params
,
1670 struct snd_pcm_hw_rule
*rule
)
1672 struct snd_interval t
;
1673 snd_interval_muldivk(hw_param_interval_c(params
, rule
->deps
[0]),
1674 hw_param_interval_c(params
, rule
->deps
[1]),
1675 (unsigned long) rule
->private, &t
);
1676 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1679 static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params
*params
,
1680 struct snd_pcm_hw_rule
*rule
)
1682 struct snd_interval t
;
1683 snd_interval_mulkdiv(hw_param_interval_c(params
, rule
->deps
[0]),
1684 (unsigned long) rule
->private,
1685 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1686 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1689 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params
*params
,
1690 struct snd_pcm_hw_rule
*rule
)
1693 struct snd_interval
*i
= hw_param_interval(params
, rule
->deps
[0]);
1695 struct snd_mask
*mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
1697 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1699 if (! snd_mask_test(mask
, k
))
1701 bits
= snd_pcm_format_physical_width(k
);
1703 continue; /* ignore invalid formats */
1704 if ((unsigned)bits
< i
->min
|| (unsigned)bits
> i
->max
)
1705 snd_mask_reset(&m
, k
);
1707 return snd_mask_refine(mask
, &m
);
1710 static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params
*params
,
1711 struct snd_pcm_hw_rule
*rule
)
1713 struct snd_interval t
;
1719 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1721 if (! snd_mask_test(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), k
))
1723 bits
= snd_pcm_format_physical_width(k
);
1725 continue; /* ignore invalid formats */
1726 if (t
.min
> (unsigned)bits
)
1728 if (t
.max
< (unsigned)bits
)
1732 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1735 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1736 #error "Change this table"
1739 static unsigned int rates
[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1740 48000, 64000, 88200, 96000, 176400, 192000 };
1742 const struct snd_pcm_hw_constraint_list snd_pcm_known_rates
= {
1743 .count
= ARRAY_SIZE(rates
),
1747 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params
*params
,
1748 struct snd_pcm_hw_rule
*rule
)
1750 struct snd_pcm_hardware
*hw
= rule
->private;
1751 return snd_interval_list(hw_param_interval(params
, rule
->var
),
1752 snd_pcm_known_rates
.count
,
1753 snd_pcm_known_rates
.list
, hw
->rates
);
1756 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params
*params
,
1757 struct snd_pcm_hw_rule
*rule
)
1759 struct snd_interval t
;
1760 struct snd_pcm_substream
*substream
= rule
->private;
1762 t
.max
= substream
->buffer_bytes_max
;
1766 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1769 int snd_pcm_hw_constraints_init(struct snd_pcm_substream
*substream
)
1771 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1772 struct snd_pcm_hw_constraints
*constrs
= &runtime
->hw_constraints
;
1775 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
1776 snd_mask_any(constrs_mask(constrs
, k
));
1779 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
1780 snd_interval_any(constrs_interval(constrs
, k
));
1783 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_CHANNELS
));
1784 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
));
1785 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
));
1786 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
));
1787 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_FRAME_BITS
));
1789 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FORMAT
,
1790 snd_pcm_hw_rule_format
, NULL
,
1791 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1794 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1795 snd_pcm_hw_rule_sample_bits
, NULL
,
1796 SNDRV_PCM_HW_PARAM_FORMAT
,
1797 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1800 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1801 snd_pcm_hw_rule_div
, NULL
,
1802 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1805 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1806 snd_pcm_hw_rule_mul
, NULL
,
1807 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1810 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1811 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1812 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1815 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1816 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1817 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, -1);
1820 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1821 snd_pcm_hw_rule_div
, NULL
,
1822 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1825 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1826 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1827 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_TIME
, -1);
1830 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1831 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1832 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
, -1);
1835 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
,
1836 snd_pcm_hw_rule_div
, NULL
,
1837 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1840 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1841 snd_pcm_hw_rule_div
, NULL
,
1842 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1845 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1846 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1847 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1850 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1851 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1852 SNDRV_PCM_HW_PARAM_PERIOD_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1855 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1856 snd_pcm_hw_rule_mul
, NULL
,
1857 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1860 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1861 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1862 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1865 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1866 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1867 SNDRV_PCM_HW_PARAM_BUFFER_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1870 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1871 snd_pcm_hw_rule_muldivk
, (void*) 8,
1872 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1875 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1876 snd_pcm_hw_rule_muldivk
, (void*) 8,
1877 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1880 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1881 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1882 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1885 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
1886 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1887 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1893 int snd_pcm_hw_constraints_complete(struct snd_pcm_substream
*substream
)
1895 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1896 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
1898 unsigned int mask
= 0;
1900 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1901 mask
|= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED
;
1902 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1903 mask
|= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
;
1904 if (hw
->info
& SNDRV_PCM_INFO_MMAP
) {
1905 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1906 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED
;
1907 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1908 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED
;
1909 if (hw
->info
& SNDRV_PCM_INFO_COMPLEX
)
1910 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX
;
1912 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_ACCESS
, mask
);
1916 err
= snd_pcm_hw_constraint_mask64(runtime
, SNDRV_PCM_HW_PARAM_FORMAT
, hw
->formats
);
1920 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_SUBFORMAT
, 1 << SNDRV_PCM_SUBFORMAT_STD
);
1924 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_CHANNELS
,
1925 hw
->channels_min
, hw
->channels_max
);
1929 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
1930 hw
->rate_min
, hw
->rate_max
);
1934 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1935 hw
->period_bytes_min
, hw
->period_bytes_max
);
1939 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
,
1940 hw
->periods_min
, hw
->periods_max
);
1944 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1945 hw
->period_bytes_min
, hw
->buffer_bytes_max
);
1949 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1950 snd_pcm_hw_rule_buffer_bytes_max
, substream
,
1951 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, -1);
1956 if (runtime
->dma_bytes
) {
1957 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 0, runtime
->dma_bytes
);
1962 if (!(hw
->rates
& (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_CONTINUOUS
))) {
1963 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1964 snd_pcm_hw_rule_rate
, hw
,
1965 SNDRV_PCM_HW_PARAM_RATE
, -1);
1970 /* FIXME: this belong to lowlevel */
1971 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
1976 static void pcm_release_private(struct snd_pcm_substream
*substream
)
1978 snd_pcm_unlink(substream
);
1981 void snd_pcm_release_substream(struct snd_pcm_substream
*substream
)
1983 substream
->ref_count
--;
1984 if (substream
->ref_count
> 0)
1987 snd_pcm_drop(substream
);
1988 if (substream
->hw_opened
) {
1989 if (substream
->ops
->hw_free
!= NULL
)
1990 substream
->ops
->hw_free(substream
);
1991 substream
->ops
->close(substream
);
1992 substream
->hw_opened
= 0;
1994 if (substream
->pcm_release
) {
1995 substream
->pcm_release(substream
);
1996 substream
->pcm_release
= NULL
;
1998 snd_pcm_detach_substream(substream
);
2001 EXPORT_SYMBOL(snd_pcm_release_substream
);
2003 int snd_pcm_open_substream(struct snd_pcm
*pcm
, int stream
,
2005 struct snd_pcm_substream
**rsubstream
)
2007 struct snd_pcm_substream
*substream
;
2010 err
= snd_pcm_attach_substream(pcm
, stream
, file
, &substream
);
2013 if (substream
->ref_count
> 1) {
2014 *rsubstream
= substream
;
2018 err
= snd_pcm_hw_constraints_init(substream
);
2020 snd_printd("snd_pcm_hw_constraints_init failed\n");
2024 if ((err
= substream
->ops
->open(substream
)) < 0)
2027 substream
->hw_opened
= 1;
2029 err
= snd_pcm_hw_constraints_complete(substream
);
2031 snd_printd("snd_pcm_hw_constraints_complete failed\n");
2035 *rsubstream
= substream
;
2039 snd_pcm_release_substream(substream
);
2043 EXPORT_SYMBOL(snd_pcm_open_substream
);
2045 static int snd_pcm_open_file(struct file
*file
,
2046 struct snd_pcm
*pcm
,
2048 struct snd_pcm_file
**rpcm_file
)
2050 struct snd_pcm_file
*pcm_file
;
2051 struct snd_pcm_substream
*substream
;
2052 struct snd_pcm_str
*str
;
2058 err
= snd_pcm_open_substream(pcm
, stream
, file
, &substream
);
2062 pcm_file
= kzalloc(sizeof(*pcm_file
), GFP_KERNEL
);
2063 if (pcm_file
== NULL
) {
2064 snd_pcm_release_substream(substream
);
2067 pcm_file
->substream
= substream
;
2068 if (substream
->ref_count
== 1) {
2069 str
= substream
->pstr
;
2070 substream
->file
= pcm_file
;
2071 substream
->pcm_release
= pcm_release_private
;
2073 file
->private_data
= pcm_file
;
2075 *rpcm_file
= pcm_file
;
2079 static int snd_pcm_playback_open(struct inode
*inode
, struct file
*file
)
2081 struct snd_pcm
*pcm
;
2082 int err
= nonseekable_open(inode
, file
);
2085 pcm
= snd_lookup_minor_data(iminor(inode
),
2086 SNDRV_DEVICE_TYPE_PCM_PLAYBACK
);
2087 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_PLAYBACK
);
2090 static int snd_pcm_capture_open(struct inode
*inode
, struct file
*file
)
2092 struct snd_pcm
*pcm
;
2093 int err
= nonseekable_open(inode
, file
);
2096 pcm
= snd_lookup_minor_data(iminor(inode
),
2097 SNDRV_DEVICE_TYPE_PCM_CAPTURE
);
2098 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_CAPTURE
);
2101 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
)
2104 struct snd_pcm_file
*pcm_file
;
2111 err
= snd_card_file_add(pcm
->card
, file
);
2114 if (!try_module_get(pcm
->card
->module
)) {
2118 init_waitqueue_entry(&wait
, current
);
2119 add_wait_queue(&pcm
->open_wait
, &wait
);
2120 mutex_lock(&pcm
->open_mutex
);
2122 err
= snd_pcm_open_file(file
, pcm
, stream
, &pcm_file
);
2125 if (err
== -EAGAIN
) {
2126 if (file
->f_flags
& O_NONBLOCK
) {
2132 set_current_state(TASK_INTERRUPTIBLE
);
2133 mutex_unlock(&pcm
->open_mutex
);
2135 mutex_lock(&pcm
->open_mutex
);
2136 if (signal_pending(current
)) {
2141 remove_wait_queue(&pcm
->open_wait
, &wait
);
2142 mutex_unlock(&pcm
->open_mutex
);
2148 module_put(pcm
->card
->module
);
2150 snd_card_file_remove(pcm
->card
, file
);
2155 static int snd_pcm_release(struct inode
*inode
, struct file
*file
)
2157 struct snd_pcm
*pcm
;
2158 struct snd_pcm_substream
*substream
;
2159 struct snd_pcm_file
*pcm_file
;
2161 pcm_file
= file
->private_data
;
2162 substream
= pcm_file
->substream
;
2163 if (snd_BUG_ON(!substream
))
2165 pcm
= substream
->pcm
;
2166 mutex_lock(&pcm
->open_mutex
);
2167 snd_pcm_release_substream(substream
);
2169 mutex_unlock(&pcm
->open_mutex
);
2170 wake_up(&pcm
->open_wait
);
2171 module_put(pcm
->card
->module
);
2172 snd_card_file_remove(pcm
->card
, file
);
2176 static snd_pcm_sframes_t
snd_pcm_playback_rewind(struct snd_pcm_substream
*substream
,
2177 snd_pcm_uframes_t frames
)
2179 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2180 snd_pcm_sframes_t appl_ptr
;
2181 snd_pcm_sframes_t ret
;
2182 snd_pcm_sframes_t hw_avail
;
2187 snd_pcm_stream_lock_irq(substream
);
2188 switch (runtime
->status
->state
) {
2189 case SNDRV_PCM_STATE_PREPARED
:
2191 case SNDRV_PCM_STATE_DRAINING
:
2192 case SNDRV_PCM_STATE_RUNNING
:
2193 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2196 case SNDRV_PCM_STATE_XRUN
:
2199 case SNDRV_PCM_STATE_SUSPENDED
:
2207 hw_avail
= snd_pcm_playback_hw_avail(runtime
);
2208 if (hw_avail
<= 0) {
2212 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2214 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2216 appl_ptr
+= runtime
->boundary
;
2217 runtime
->control
->appl_ptr
= appl_ptr
;
2220 snd_pcm_stream_unlock_irq(substream
);
2224 static snd_pcm_sframes_t
snd_pcm_capture_rewind(struct snd_pcm_substream
*substream
,
2225 snd_pcm_uframes_t frames
)
2227 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2228 snd_pcm_sframes_t appl_ptr
;
2229 snd_pcm_sframes_t ret
;
2230 snd_pcm_sframes_t hw_avail
;
2235 snd_pcm_stream_lock_irq(substream
);
2236 switch (runtime
->status
->state
) {
2237 case SNDRV_PCM_STATE_PREPARED
:
2238 case SNDRV_PCM_STATE_DRAINING
:
2240 case SNDRV_PCM_STATE_RUNNING
:
2241 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2244 case SNDRV_PCM_STATE_XRUN
:
2247 case SNDRV_PCM_STATE_SUSPENDED
:
2255 hw_avail
= snd_pcm_capture_hw_avail(runtime
);
2256 if (hw_avail
<= 0) {
2260 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2262 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2264 appl_ptr
+= runtime
->boundary
;
2265 runtime
->control
->appl_ptr
= appl_ptr
;
2268 snd_pcm_stream_unlock_irq(substream
);
2272 static snd_pcm_sframes_t
snd_pcm_playback_forward(struct snd_pcm_substream
*substream
,
2273 snd_pcm_uframes_t frames
)
2275 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2276 snd_pcm_sframes_t appl_ptr
;
2277 snd_pcm_sframes_t ret
;
2278 snd_pcm_sframes_t avail
;
2283 snd_pcm_stream_lock_irq(substream
);
2284 switch (runtime
->status
->state
) {
2285 case SNDRV_PCM_STATE_PREPARED
:
2286 case SNDRV_PCM_STATE_PAUSED
:
2288 case SNDRV_PCM_STATE_DRAINING
:
2289 case SNDRV_PCM_STATE_RUNNING
:
2290 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2293 case SNDRV_PCM_STATE_XRUN
:
2296 case SNDRV_PCM_STATE_SUSPENDED
:
2304 avail
= snd_pcm_playback_avail(runtime
);
2309 if (frames
> (snd_pcm_uframes_t
)avail
)
2311 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2312 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2313 appl_ptr
-= runtime
->boundary
;
2314 runtime
->control
->appl_ptr
= appl_ptr
;
2317 snd_pcm_stream_unlock_irq(substream
);
2321 static snd_pcm_sframes_t
snd_pcm_capture_forward(struct snd_pcm_substream
*substream
,
2322 snd_pcm_uframes_t frames
)
2324 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2325 snd_pcm_sframes_t appl_ptr
;
2326 snd_pcm_sframes_t ret
;
2327 snd_pcm_sframes_t avail
;
2332 snd_pcm_stream_lock_irq(substream
);
2333 switch (runtime
->status
->state
) {
2334 case SNDRV_PCM_STATE_PREPARED
:
2335 case SNDRV_PCM_STATE_DRAINING
:
2336 case SNDRV_PCM_STATE_PAUSED
:
2338 case SNDRV_PCM_STATE_RUNNING
:
2339 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2342 case SNDRV_PCM_STATE_XRUN
:
2345 case SNDRV_PCM_STATE_SUSPENDED
:
2353 avail
= snd_pcm_capture_avail(runtime
);
2358 if (frames
> (snd_pcm_uframes_t
)avail
)
2360 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2361 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2362 appl_ptr
-= runtime
->boundary
;
2363 runtime
->control
->appl_ptr
= appl_ptr
;
2366 snd_pcm_stream_unlock_irq(substream
);
2370 static int snd_pcm_hwsync(struct snd_pcm_substream
*substream
)
2372 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2375 snd_pcm_stream_lock_irq(substream
);
2376 switch (runtime
->status
->state
) {
2377 case SNDRV_PCM_STATE_DRAINING
:
2378 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2380 case SNDRV_PCM_STATE_RUNNING
:
2381 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2384 case SNDRV_PCM_STATE_PREPARED
:
2385 case SNDRV_PCM_STATE_SUSPENDED
:
2388 case SNDRV_PCM_STATE_XRUN
:
2396 snd_pcm_stream_unlock_irq(substream
);
2400 static int snd_pcm_delay(struct snd_pcm_substream
*substream
,
2401 snd_pcm_sframes_t __user
*res
)
2403 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2405 snd_pcm_sframes_t n
= 0;
2407 snd_pcm_stream_lock_irq(substream
);
2408 switch (runtime
->status
->state
) {
2409 case SNDRV_PCM_STATE_DRAINING
:
2410 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2412 case SNDRV_PCM_STATE_RUNNING
:
2413 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2416 case SNDRV_PCM_STATE_PREPARED
:
2417 case SNDRV_PCM_STATE_SUSPENDED
:
2419 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2420 n
= snd_pcm_playback_hw_avail(runtime
);
2422 n
= snd_pcm_capture_avail(runtime
);
2423 n
+= runtime
->delay
;
2425 case SNDRV_PCM_STATE_XRUN
:
2433 snd_pcm_stream_unlock_irq(substream
);
2435 if (put_user(n
, res
))
2440 static int snd_pcm_sync_ptr(struct snd_pcm_substream
*substream
,
2441 struct snd_pcm_sync_ptr __user
*_sync_ptr
)
2443 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2444 struct snd_pcm_sync_ptr sync_ptr
;
2445 volatile struct snd_pcm_mmap_status
*status
;
2446 volatile struct snd_pcm_mmap_control
*control
;
2449 memset(&sync_ptr
, 0, sizeof(sync_ptr
));
2450 if (get_user(sync_ptr
.flags
, (unsigned __user
*)&(_sync_ptr
->flags
)))
2452 if (copy_from_user(&sync_ptr
.c
.control
, &(_sync_ptr
->c
.control
), sizeof(struct snd_pcm_mmap_control
)))
2454 status
= runtime
->status
;
2455 control
= runtime
->control
;
2456 if (sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
2457 err
= snd_pcm_hwsync(substream
);
2461 snd_pcm_stream_lock_irq(substream
);
2462 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_APPL
))
2463 control
->appl_ptr
= sync_ptr
.c
.control
.appl_ptr
;
2465 sync_ptr
.c
.control
.appl_ptr
= control
->appl_ptr
;
2466 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
2467 control
->avail_min
= sync_ptr
.c
.control
.avail_min
;
2469 sync_ptr
.c
.control
.avail_min
= control
->avail_min
;
2470 sync_ptr
.s
.status
.state
= status
->state
;
2471 sync_ptr
.s
.status
.hw_ptr
= status
->hw_ptr
;
2472 sync_ptr
.s
.status
.tstamp
= status
->tstamp
;
2473 sync_ptr
.s
.status
.suspended_state
= status
->suspended_state
;
2474 snd_pcm_stream_unlock_irq(substream
);
2475 if (copy_to_user(_sync_ptr
, &sync_ptr
, sizeof(sync_ptr
)))
2480 static int snd_pcm_tstamp(struct snd_pcm_substream
*substream
, int __user
*_arg
)
2482 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2485 if (get_user(arg
, _arg
))
2487 if (arg
< 0 || arg
> SNDRV_PCM_TSTAMP_TYPE_LAST
)
2489 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY
;
2490 if (arg
== SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
)
2491 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
;
2495 static int snd_pcm_common_ioctl1(struct file
*file
,
2496 struct snd_pcm_substream
*substream
,
2497 unsigned int cmd
, void __user
*arg
)
2500 case SNDRV_PCM_IOCTL_PVERSION
:
2501 return put_user(SNDRV_PCM_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2502 case SNDRV_PCM_IOCTL_INFO
:
2503 return snd_pcm_info_user(substream
, arg
);
2504 case SNDRV_PCM_IOCTL_TSTAMP
: /* just for compatibility */
2506 case SNDRV_PCM_IOCTL_TTSTAMP
:
2507 return snd_pcm_tstamp(substream
, arg
);
2508 case SNDRV_PCM_IOCTL_HW_REFINE
:
2509 return snd_pcm_hw_refine_user(substream
, arg
);
2510 case SNDRV_PCM_IOCTL_HW_PARAMS
:
2511 return snd_pcm_hw_params_user(substream
, arg
);
2512 case SNDRV_PCM_IOCTL_HW_FREE
:
2513 return snd_pcm_hw_free(substream
);
2514 case SNDRV_PCM_IOCTL_SW_PARAMS
:
2515 return snd_pcm_sw_params_user(substream
, arg
);
2516 case SNDRV_PCM_IOCTL_STATUS
:
2517 return snd_pcm_status_user(substream
, arg
);
2518 case SNDRV_PCM_IOCTL_CHANNEL_INFO
:
2519 return snd_pcm_channel_info_user(substream
, arg
);
2520 case SNDRV_PCM_IOCTL_PREPARE
:
2521 return snd_pcm_prepare(substream
, file
);
2522 case SNDRV_PCM_IOCTL_RESET
:
2523 return snd_pcm_reset(substream
);
2524 case SNDRV_PCM_IOCTL_START
:
2525 return snd_pcm_action_lock_irq(&snd_pcm_action_start
, substream
, SNDRV_PCM_STATE_RUNNING
);
2526 case SNDRV_PCM_IOCTL_LINK
:
2527 return snd_pcm_link(substream
, (int)(unsigned long) arg
);
2528 case SNDRV_PCM_IOCTL_UNLINK
:
2529 return snd_pcm_unlink(substream
);
2530 case SNDRV_PCM_IOCTL_RESUME
:
2531 return snd_pcm_resume(substream
);
2532 case SNDRV_PCM_IOCTL_XRUN
:
2533 return snd_pcm_xrun(substream
);
2534 case SNDRV_PCM_IOCTL_HWSYNC
:
2535 return snd_pcm_hwsync(substream
);
2536 case SNDRV_PCM_IOCTL_DELAY
:
2537 return snd_pcm_delay(substream
, arg
);
2538 case SNDRV_PCM_IOCTL_SYNC_PTR
:
2539 return snd_pcm_sync_ptr(substream
, arg
);
2540 #ifdef CONFIG_SND_SUPPORT_OLD_API
2541 case SNDRV_PCM_IOCTL_HW_REFINE_OLD
:
2542 return snd_pcm_hw_refine_old_user(substream
, arg
);
2543 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD
:
2544 return snd_pcm_hw_params_old_user(substream
, arg
);
2546 case SNDRV_PCM_IOCTL_DRAIN
:
2547 return snd_pcm_drain(substream
, file
);
2548 case SNDRV_PCM_IOCTL_DROP
:
2549 return snd_pcm_drop(substream
);
2550 case SNDRV_PCM_IOCTL_PAUSE
:
2553 snd_pcm_stream_lock_irq(substream
);
2554 res
= snd_pcm_pause(substream
, (int)(unsigned long)arg
);
2555 snd_pcm_stream_unlock_irq(substream
);
2559 snd_printd("unknown ioctl = 0x%x\n", cmd
);
2563 static int snd_pcm_playback_ioctl1(struct file
*file
,
2564 struct snd_pcm_substream
*substream
,
2565 unsigned int cmd
, void __user
*arg
)
2567 if (snd_BUG_ON(!substream
))
2569 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
2572 case SNDRV_PCM_IOCTL_WRITEI_FRAMES
:
2574 struct snd_xferi xferi
;
2575 struct snd_xferi __user
*_xferi
= arg
;
2576 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2577 snd_pcm_sframes_t result
;
2578 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2580 if (put_user(0, &_xferi
->result
))
2582 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2584 result
= snd_pcm_lib_write(substream
, xferi
.buf
, xferi
.frames
);
2585 __put_user(result
, &_xferi
->result
);
2586 return result
< 0 ? result
: 0;
2588 case SNDRV_PCM_IOCTL_WRITEN_FRAMES
:
2590 struct snd_xfern xfern
;
2591 struct snd_xfern __user
*_xfern
= arg
;
2592 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2594 snd_pcm_sframes_t result
;
2595 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2597 if (runtime
->channels
> 128)
2599 if (put_user(0, &_xfern
->result
))
2601 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2604 bufs
= memdup_user(xfern
.bufs
,
2605 sizeof(void *) * runtime
->channels
);
2607 return PTR_ERR(bufs
);
2608 result
= snd_pcm_lib_writev(substream
, bufs
, xfern
.frames
);
2610 __put_user(result
, &_xfern
->result
);
2611 return result
< 0 ? result
: 0;
2613 case SNDRV_PCM_IOCTL_REWIND
:
2615 snd_pcm_uframes_t frames
;
2616 snd_pcm_uframes_t __user
*_frames
= arg
;
2617 snd_pcm_sframes_t result
;
2618 if (get_user(frames
, _frames
))
2620 if (put_user(0, _frames
))
2622 result
= snd_pcm_playback_rewind(substream
, frames
);
2623 __put_user(result
, _frames
);
2624 return result
< 0 ? result
: 0;
2626 case SNDRV_PCM_IOCTL_FORWARD
:
2628 snd_pcm_uframes_t frames
;
2629 snd_pcm_uframes_t __user
*_frames
= arg
;
2630 snd_pcm_sframes_t result
;
2631 if (get_user(frames
, _frames
))
2633 if (put_user(0, _frames
))
2635 result
= snd_pcm_playback_forward(substream
, frames
);
2636 __put_user(result
, _frames
);
2637 return result
< 0 ? result
: 0;
2640 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2643 static int snd_pcm_capture_ioctl1(struct file
*file
,
2644 struct snd_pcm_substream
*substream
,
2645 unsigned int cmd
, void __user
*arg
)
2647 if (snd_BUG_ON(!substream
))
2649 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_CAPTURE
))
2652 case SNDRV_PCM_IOCTL_READI_FRAMES
:
2654 struct snd_xferi xferi
;
2655 struct snd_xferi __user
*_xferi
= arg
;
2656 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2657 snd_pcm_sframes_t result
;
2658 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2660 if (put_user(0, &_xferi
->result
))
2662 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2664 result
= snd_pcm_lib_read(substream
, xferi
.buf
, xferi
.frames
);
2665 __put_user(result
, &_xferi
->result
);
2666 return result
< 0 ? result
: 0;
2668 case SNDRV_PCM_IOCTL_READN_FRAMES
:
2670 struct snd_xfern xfern
;
2671 struct snd_xfern __user
*_xfern
= arg
;
2672 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2674 snd_pcm_sframes_t result
;
2675 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2677 if (runtime
->channels
> 128)
2679 if (put_user(0, &_xfern
->result
))
2681 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2684 bufs
= memdup_user(xfern
.bufs
,
2685 sizeof(void *) * runtime
->channels
);
2687 return PTR_ERR(bufs
);
2688 result
= snd_pcm_lib_readv(substream
, bufs
, xfern
.frames
);
2690 __put_user(result
, &_xfern
->result
);
2691 return result
< 0 ? result
: 0;
2693 case SNDRV_PCM_IOCTL_REWIND
:
2695 snd_pcm_uframes_t frames
;
2696 snd_pcm_uframes_t __user
*_frames
= arg
;
2697 snd_pcm_sframes_t result
;
2698 if (get_user(frames
, _frames
))
2700 if (put_user(0, _frames
))
2702 result
= snd_pcm_capture_rewind(substream
, frames
);
2703 __put_user(result
, _frames
);
2704 return result
< 0 ? result
: 0;
2706 case SNDRV_PCM_IOCTL_FORWARD
:
2708 snd_pcm_uframes_t frames
;
2709 snd_pcm_uframes_t __user
*_frames
= arg
;
2710 snd_pcm_sframes_t result
;
2711 if (get_user(frames
, _frames
))
2713 if (put_user(0, _frames
))
2715 result
= snd_pcm_capture_forward(substream
, frames
);
2716 __put_user(result
, _frames
);
2717 return result
< 0 ? result
: 0;
2720 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2723 static long snd_pcm_playback_ioctl(struct file
*file
, unsigned int cmd
,
2726 struct snd_pcm_file
*pcm_file
;
2728 pcm_file
= file
->private_data
;
2730 if (((cmd
>> 8) & 0xff) != 'A')
2733 return snd_pcm_playback_ioctl1(file
, pcm_file
->substream
, cmd
,
2734 (void __user
*)arg
);
2737 static long snd_pcm_capture_ioctl(struct file
*file
, unsigned int cmd
,
2740 struct snd_pcm_file
*pcm_file
;
2742 pcm_file
= file
->private_data
;
2744 if (((cmd
>> 8) & 0xff) != 'A')
2747 return snd_pcm_capture_ioctl1(file
, pcm_file
->substream
, cmd
,
2748 (void __user
*)arg
);
2751 int snd_pcm_kernel_ioctl(struct snd_pcm_substream
*substream
,
2752 unsigned int cmd
, void *arg
)
2757 fs
= snd_enter_user();
2758 switch (substream
->stream
) {
2759 case SNDRV_PCM_STREAM_PLAYBACK
:
2760 result
= snd_pcm_playback_ioctl1(NULL
, substream
, cmd
,
2761 (void __user
*)arg
);
2763 case SNDRV_PCM_STREAM_CAPTURE
:
2764 result
= snd_pcm_capture_ioctl1(NULL
, substream
, cmd
,
2765 (void __user
*)arg
);
2775 EXPORT_SYMBOL(snd_pcm_kernel_ioctl
);
2777 static ssize_t
snd_pcm_read(struct file
*file
, char __user
*buf
, size_t count
,
2780 struct snd_pcm_file
*pcm_file
;
2781 struct snd_pcm_substream
*substream
;
2782 struct snd_pcm_runtime
*runtime
;
2783 snd_pcm_sframes_t result
;
2785 pcm_file
= file
->private_data
;
2786 substream
= pcm_file
->substream
;
2787 if (PCM_RUNTIME_CHECK(substream
))
2789 runtime
= substream
->runtime
;
2790 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2792 if (!frame_aligned(runtime
, count
))
2794 count
= bytes_to_frames(runtime
, count
);
2795 result
= snd_pcm_lib_read(substream
, buf
, count
);
2797 result
= frames_to_bytes(runtime
, result
);
2801 static ssize_t
snd_pcm_write(struct file
*file
, const char __user
*buf
,
2802 size_t count
, loff_t
* offset
)
2804 struct snd_pcm_file
*pcm_file
;
2805 struct snd_pcm_substream
*substream
;
2806 struct snd_pcm_runtime
*runtime
;
2807 snd_pcm_sframes_t result
;
2809 pcm_file
= file
->private_data
;
2810 substream
= pcm_file
->substream
;
2811 if (PCM_RUNTIME_CHECK(substream
))
2813 runtime
= substream
->runtime
;
2814 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2816 if (!frame_aligned(runtime
, count
))
2818 count
= bytes_to_frames(runtime
, count
);
2819 result
= snd_pcm_lib_write(substream
, buf
, count
);
2821 result
= frames_to_bytes(runtime
, result
);
2825 static ssize_t
snd_pcm_aio_read(struct kiocb
*iocb
, const struct iovec
*iov
,
2826 unsigned long nr_segs
, loff_t pos
)
2829 struct snd_pcm_file
*pcm_file
;
2830 struct snd_pcm_substream
*substream
;
2831 struct snd_pcm_runtime
*runtime
;
2832 snd_pcm_sframes_t result
;
2835 snd_pcm_uframes_t frames
;
2837 pcm_file
= iocb
->ki_filp
->private_data
;
2838 substream
= pcm_file
->substream
;
2839 if (PCM_RUNTIME_CHECK(substream
))
2841 runtime
= substream
->runtime
;
2842 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2844 if (nr_segs
> 1024 || nr_segs
!= runtime
->channels
)
2846 if (!frame_aligned(runtime
, iov
->iov_len
))
2848 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2849 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2852 for (i
= 0; i
< nr_segs
; ++i
)
2853 bufs
[i
] = iov
[i
].iov_base
;
2854 result
= snd_pcm_lib_readv(substream
, bufs
, frames
);
2856 result
= frames_to_bytes(runtime
, result
);
2861 static ssize_t
snd_pcm_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
2862 unsigned long nr_segs
, loff_t pos
)
2864 struct snd_pcm_file
*pcm_file
;
2865 struct snd_pcm_substream
*substream
;
2866 struct snd_pcm_runtime
*runtime
;
2867 snd_pcm_sframes_t result
;
2870 snd_pcm_uframes_t frames
;
2872 pcm_file
= iocb
->ki_filp
->private_data
;
2873 substream
= pcm_file
->substream
;
2874 if (PCM_RUNTIME_CHECK(substream
))
2876 runtime
= substream
->runtime
;
2877 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2879 if (nr_segs
> 128 || nr_segs
!= runtime
->channels
||
2880 !frame_aligned(runtime
, iov
->iov_len
))
2882 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2883 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2886 for (i
= 0; i
< nr_segs
; ++i
)
2887 bufs
[i
] = iov
[i
].iov_base
;
2888 result
= snd_pcm_lib_writev(substream
, bufs
, frames
);
2890 result
= frames_to_bytes(runtime
, result
);
2895 static unsigned int snd_pcm_playback_poll(struct file
*file
, poll_table
* wait
)
2897 struct snd_pcm_file
*pcm_file
;
2898 struct snd_pcm_substream
*substream
;
2899 struct snd_pcm_runtime
*runtime
;
2901 snd_pcm_uframes_t avail
;
2903 pcm_file
= file
->private_data
;
2905 substream
= pcm_file
->substream
;
2906 if (PCM_RUNTIME_CHECK(substream
))
2908 runtime
= substream
->runtime
;
2910 poll_wait(file
, &runtime
->sleep
, wait
);
2912 snd_pcm_stream_lock_irq(substream
);
2913 avail
= snd_pcm_playback_avail(runtime
);
2914 switch (runtime
->status
->state
) {
2915 case SNDRV_PCM_STATE_RUNNING
:
2916 case SNDRV_PCM_STATE_PREPARED
:
2917 case SNDRV_PCM_STATE_PAUSED
:
2918 if (avail
>= runtime
->control
->avail_min
) {
2919 mask
= POLLOUT
| POLLWRNORM
;
2923 case SNDRV_PCM_STATE_DRAINING
:
2927 mask
= POLLOUT
| POLLWRNORM
| POLLERR
;
2930 snd_pcm_stream_unlock_irq(substream
);
2934 static unsigned int snd_pcm_capture_poll(struct file
*file
, poll_table
* wait
)
2936 struct snd_pcm_file
*pcm_file
;
2937 struct snd_pcm_substream
*substream
;
2938 struct snd_pcm_runtime
*runtime
;
2940 snd_pcm_uframes_t avail
;
2942 pcm_file
= file
->private_data
;
2944 substream
= pcm_file
->substream
;
2945 if (PCM_RUNTIME_CHECK(substream
))
2947 runtime
= substream
->runtime
;
2949 poll_wait(file
, &runtime
->sleep
, wait
);
2951 snd_pcm_stream_lock_irq(substream
);
2952 avail
= snd_pcm_capture_avail(runtime
);
2953 switch (runtime
->status
->state
) {
2954 case SNDRV_PCM_STATE_RUNNING
:
2955 case SNDRV_PCM_STATE_PREPARED
:
2956 case SNDRV_PCM_STATE_PAUSED
:
2957 if (avail
>= runtime
->control
->avail_min
) {
2958 mask
= POLLIN
| POLLRDNORM
;
2963 case SNDRV_PCM_STATE_DRAINING
:
2965 mask
= POLLIN
| POLLRDNORM
;
2970 mask
= POLLIN
| POLLRDNORM
| POLLERR
;
2973 snd_pcm_stream_unlock_irq(substream
);
2982 * Only on coherent architectures, we can mmap the status and the control records
2983 * for effcient data transfer. On others, we have to use HWSYNC ioctl...
2985 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
2987 * mmap status record
2989 static int snd_pcm_mmap_status_fault(struct vm_area_struct
*area
,
2990 struct vm_fault
*vmf
)
2992 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
2993 struct snd_pcm_runtime
*runtime
;
2995 if (substream
== NULL
)
2996 return VM_FAULT_SIGBUS
;
2997 runtime
= substream
->runtime
;
2998 vmf
->page
= virt_to_page(runtime
->status
);
2999 get_page(vmf
->page
);
3003 static const struct vm_operations_struct snd_pcm_vm_ops_status
=
3005 .fault
= snd_pcm_mmap_status_fault
,
3008 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3009 struct vm_area_struct
*area
)
3011 struct snd_pcm_runtime
*runtime
;
3013 if (!(area
->vm_flags
& VM_READ
))
3015 runtime
= substream
->runtime
;
3016 size
= area
->vm_end
- area
->vm_start
;
3017 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status
)))
3019 area
->vm_ops
= &snd_pcm_vm_ops_status
;
3020 area
->vm_private_data
= substream
;
3021 area
->vm_flags
|= VM_RESERVED
;
3026 * mmap control record
3028 static int snd_pcm_mmap_control_fault(struct vm_area_struct
*area
,
3029 struct vm_fault
*vmf
)
3031 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3032 struct snd_pcm_runtime
*runtime
;
3034 if (substream
== NULL
)
3035 return VM_FAULT_SIGBUS
;
3036 runtime
= substream
->runtime
;
3037 vmf
->page
= virt_to_page(runtime
->control
);
3038 get_page(vmf
->page
);
3042 static const struct vm_operations_struct snd_pcm_vm_ops_control
=
3044 .fault
= snd_pcm_mmap_control_fault
,
3047 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3048 struct vm_area_struct
*area
)
3050 struct snd_pcm_runtime
*runtime
;
3052 if (!(area
->vm_flags
& VM_READ
))
3054 runtime
= substream
->runtime
;
3055 size
= area
->vm_end
- area
->vm_start
;
3056 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control
)))
3058 area
->vm_ops
= &snd_pcm_vm_ops_control
;
3059 area
->vm_private_data
= substream
;
3060 area
->vm_flags
|= VM_RESERVED
;
3063 #else /* ! coherent mmap */
3065 * don't support mmap for status and control records.
3067 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3068 struct vm_area_struct
*area
)
3072 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3073 struct vm_area_struct
*area
)
3077 #endif /* coherent mmap */
3079 static inline struct page
*
3080 snd_pcm_default_page_ops(struct snd_pcm_substream
*substream
, unsigned long ofs
)
3082 void *vaddr
= substream
->runtime
->dma_area
+ ofs
;
3083 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3084 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3085 return virt_to_page(CAC_ADDR(vaddr
));
3087 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3088 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
) {
3089 dma_addr_t addr
= substream
->runtime
->dma_addr
+ ofs
;
3090 addr
-= get_dma_offset(substream
->dma_buffer
.dev
.dev
);
3091 /* assume dma_handle set via pfn_to_phys() in
3092 * mm/dma-noncoherent.c
3094 return pfn_to_page(addr
>> PAGE_SHIFT
);
3097 return virt_to_page(vaddr
);
3101 * fault callback for mmapping a RAM page
3103 static int snd_pcm_mmap_data_fault(struct vm_area_struct
*area
,
3104 struct vm_fault
*vmf
)
3106 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3107 struct snd_pcm_runtime
*runtime
;
3108 unsigned long offset
;
3112 if (substream
== NULL
)
3113 return VM_FAULT_SIGBUS
;
3114 runtime
= substream
->runtime
;
3115 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
3116 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3117 if (offset
> dma_bytes
- PAGE_SIZE
)
3118 return VM_FAULT_SIGBUS
;
3119 if (substream
->ops
->page
)
3120 page
= substream
->ops
->page(substream
, offset
);
3122 page
= snd_pcm_default_page_ops(substream
, offset
);
3124 return VM_FAULT_SIGBUS
;
3130 static const struct vm_operations_struct snd_pcm_vm_ops_data
= {
3131 .open
= snd_pcm_mmap_data_open
,
3132 .close
= snd_pcm_mmap_data_close
,
3135 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault
= {
3136 .open
= snd_pcm_mmap_data_open
,
3137 .close
= snd_pcm_mmap_data_close
,
3138 .fault
= snd_pcm_mmap_data_fault
,
3141 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3142 /* This should be defined / handled globally! */
3144 #define ARCH_HAS_DMA_MMAP_COHERENT
3149 * mmap the DMA buffer on RAM
3151 static int snd_pcm_default_mmap(struct snd_pcm_substream
*substream
,
3152 struct vm_area_struct
*area
)
3154 area
->vm_flags
|= VM_RESERVED
;
3155 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3156 if (!substream
->ops
->page
&&
3157 substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3158 return dma_mmap_coherent(substream
->dma_buffer
.dev
.dev
,
3160 substream
->runtime
->dma_area
,
3161 substream
->runtime
->dma_addr
,
3162 area
->vm_end
- area
->vm_start
);
3163 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3164 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
&&
3165 !plat_device_is_coherent(substream
->dma_buffer
.dev
.dev
))
3166 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3167 #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3168 /* mmap with fault handler */
3169 area
->vm_ops
= &snd_pcm_vm_ops_data_fault
;
3174 * mmap the DMA buffer on I/O memory area
3176 #if SNDRV_PCM_INFO_MMAP_IOMEM
3177 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream
*substream
,
3178 struct vm_area_struct
*area
)
3181 unsigned long offset
;
3183 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3184 area
->vm_flags
|= VM_IO
;
3185 size
= area
->vm_end
- area
->vm_start
;
3186 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3187 if (io_remap_pfn_range(area
, area
->vm_start
,
3188 (substream
->runtime
->dma_addr
+ offset
) >> PAGE_SHIFT
,
3189 size
, area
->vm_page_prot
))
3194 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem
);
3195 #endif /* SNDRV_PCM_INFO_MMAP */
3197 /* mmap callback with pgprot_noncached */
3198 int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream
*substream
,
3199 struct vm_area_struct
*area
)
3201 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3202 return snd_pcm_default_mmap(substream
, area
);
3204 EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached
);
3209 int snd_pcm_mmap_data(struct snd_pcm_substream
*substream
, struct file
*file
,
3210 struct vm_area_struct
*area
)
3212 struct snd_pcm_runtime
*runtime
;
3214 unsigned long offset
;
3218 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3219 if (!(area
->vm_flags
& (VM_WRITE
|VM_READ
)))
3222 if (!(area
->vm_flags
& VM_READ
))
3225 runtime
= substream
->runtime
;
3226 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
3228 if (!(runtime
->info
& SNDRV_PCM_INFO_MMAP
))
3230 if (runtime
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
||
3231 runtime
->access
== SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
)
3233 size
= area
->vm_end
- area
->vm_start
;
3234 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3235 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3236 if ((size_t)size
> dma_bytes
)
3238 if (offset
> dma_bytes
- size
)
3241 area
->vm_ops
= &snd_pcm_vm_ops_data
;
3242 area
->vm_private_data
= substream
;
3243 if (substream
->ops
->mmap
)
3244 err
= substream
->ops
->mmap(substream
, area
);
3246 err
= snd_pcm_default_mmap(substream
, area
);
3248 atomic_inc(&substream
->mmap_count
);
3252 EXPORT_SYMBOL(snd_pcm_mmap_data
);
3254 static int snd_pcm_mmap(struct file
*file
, struct vm_area_struct
*area
)
3256 struct snd_pcm_file
* pcm_file
;
3257 struct snd_pcm_substream
*substream
;
3258 unsigned long offset
;
3260 pcm_file
= file
->private_data
;
3261 substream
= pcm_file
->substream
;
3262 if (PCM_RUNTIME_CHECK(substream
))
3265 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3267 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3268 if (pcm_file
->no_compat_mmap
)
3270 return snd_pcm_mmap_status(substream
, file
, area
);
3271 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3272 if (pcm_file
->no_compat_mmap
)
3274 return snd_pcm_mmap_control(substream
, file
, area
);
3276 return snd_pcm_mmap_data(substream
, file
, area
);
3281 static int snd_pcm_fasync(int fd
, struct file
* file
, int on
)
3283 struct snd_pcm_file
* pcm_file
;
3284 struct snd_pcm_substream
*substream
;
3285 struct snd_pcm_runtime
*runtime
;
3287 pcm_file
= file
->private_data
;
3288 substream
= pcm_file
->substream
;
3289 if (PCM_RUNTIME_CHECK(substream
))
3291 runtime
= substream
->runtime
;
3292 return fasync_helper(fd
, file
, on
, &runtime
->fasync
);
3298 #ifdef CONFIG_COMPAT
3299 #include "pcm_compat.c"
3301 #define snd_pcm_ioctl_compat NULL
3305 * To be removed helpers to keep binary compatibility
3308 #ifdef CONFIG_SND_SUPPORT_OLD_API
3309 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3310 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3312 static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params
*params
,
3313 struct snd_pcm_hw_params_old
*oparams
)
3317 memset(params
, 0, sizeof(*params
));
3318 params
->flags
= oparams
->flags
;
3319 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3320 params
->masks
[i
].bits
[0] = oparams
->masks
[i
];
3321 memcpy(params
->intervals
, oparams
->intervals
, sizeof(oparams
->intervals
));
3322 params
->rmask
= __OLD_TO_NEW_MASK(oparams
->rmask
);
3323 params
->cmask
= __OLD_TO_NEW_MASK(oparams
->cmask
);
3324 params
->info
= oparams
->info
;
3325 params
->msbits
= oparams
->msbits
;
3326 params
->rate_num
= oparams
->rate_num
;
3327 params
->rate_den
= oparams
->rate_den
;
3328 params
->fifo_size
= oparams
->fifo_size
;
3331 static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old
*oparams
,
3332 struct snd_pcm_hw_params
*params
)
3336 memset(oparams
, 0, sizeof(*oparams
));
3337 oparams
->flags
= params
->flags
;
3338 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3339 oparams
->masks
[i
] = params
->masks
[i
].bits
[0];
3340 memcpy(oparams
->intervals
, params
->intervals
, sizeof(oparams
->intervals
));
3341 oparams
->rmask
= __NEW_TO_OLD_MASK(params
->rmask
);
3342 oparams
->cmask
= __NEW_TO_OLD_MASK(params
->cmask
);
3343 oparams
->info
= params
->info
;
3344 oparams
->msbits
= params
->msbits
;
3345 oparams
->rate_num
= params
->rate_num
;
3346 oparams
->rate_den
= params
->rate_den
;
3347 oparams
->fifo_size
= params
->fifo_size
;
3350 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
3351 struct snd_pcm_hw_params_old __user
* _oparams
)
3353 struct snd_pcm_hw_params
*params
;
3354 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3357 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3361 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3362 if (IS_ERR(oparams
)) {
3363 err
= PTR_ERR(oparams
);
3366 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3367 err
= snd_pcm_hw_refine(substream
, params
);
3368 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3369 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3380 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
3381 struct snd_pcm_hw_params_old __user
* _oparams
)
3383 struct snd_pcm_hw_params
*params
;
3384 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3387 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3391 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3392 if (IS_ERR(oparams
)) {
3393 err
= PTR_ERR(oparams
);
3396 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3397 err
= snd_pcm_hw_params(substream
, params
);
3398 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3399 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3409 #endif /* CONFIG_SND_SUPPORT_OLD_API */
3412 static unsigned long snd_pcm_get_unmapped_area(struct file
*file
,
3415 unsigned long pgoff
,
3416 unsigned long flags
)
3418 struct snd_pcm_file
*pcm_file
= file
->private_data
;
3419 struct snd_pcm_substream
*substream
= pcm_file
->substream
;
3420 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3421 unsigned long offset
= pgoff
<< PAGE_SHIFT
;
3424 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3425 return (unsigned long)runtime
->status
;
3426 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3427 return (unsigned long)runtime
->control
;
3429 return (unsigned long)runtime
->dma_area
+ offset
;
3433 # define snd_pcm_get_unmapped_area NULL
3440 const struct file_operations snd_pcm_f_ops
[2] = {
3442 .owner
= THIS_MODULE
,
3443 .write
= snd_pcm_write
,
3444 .aio_write
= snd_pcm_aio_write
,
3445 .open
= snd_pcm_playback_open
,
3446 .release
= snd_pcm_release
,
3447 .llseek
= no_llseek
,
3448 .poll
= snd_pcm_playback_poll
,
3449 .unlocked_ioctl
= snd_pcm_playback_ioctl
,
3450 .compat_ioctl
= snd_pcm_ioctl_compat
,
3451 .mmap
= snd_pcm_mmap
,
3452 .fasync
= snd_pcm_fasync
,
3453 .get_unmapped_area
= snd_pcm_get_unmapped_area
,
3456 .owner
= THIS_MODULE
,
3457 .read
= snd_pcm_read
,
3458 .aio_read
= snd_pcm_aio_read
,
3459 .open
= snd_pcm_capture_open
,
3460 .release
= snd_pcm_release
,
3461 .llseek
= no_llseek
,
3462 .poll
= snd_pcm_capture_poll
,
3463 .unlocked_ioctl
= snd_pcm_capture_ioctl
,
3464 .compat_ioctl
= snd_pcm_ioctl_compat
,
3465 .mmap
= snd_pcm_mmap
,
3466 .fasync
= snd_pcm_fasync
,
3467 .get_unmapped_area
= snd_pcm_get_unmapped_area
,