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 /* The jiffies check in snd_pcm_update_hw_ptr*() is done by
982 * a delta betwen the current jiffies, this gives a large enough
983 * delta, effectively to skip the check once.
985 substream
->runtime
->hw_ptr_jiffies
= jiffies
- HZ
* 1000;
986 return substream
->ops
->trigger(substream
,
987 push
? SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
988 SNDRV_PCM_TRIGGER_PAUSE_RELEASE
);
991 static void snd_pcm_undo_pause(struct snd_pcm_substream
*substream
, int push
)
993 if (substream
->runtime
->trigger_master
== substream
)
994 substream
->ops
->trigger(substream
,
995 push
? SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
996 SNDRV_PCM_TRIGGER_PAUSE_PUSH
);
999 static void snd_pcm_post_pause(struct snd_pcm_substream
*substream
, int push
)
1001 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1002 snd_pcm_trigger_tstamp(substream
);
1004 runtime
->status
->state
= SNDRV_PCM_STATE_PAUSED
;
1005 if (substream
->timer
)
1006 snd_timer_notify(substream
->timer
,
1007 SNDRV_TIMER_EVENT_MPAUSE
,
1008 &runtime
->trigger_tstamp
);
1009 wake_up(&runtime
->sleep
);
1010 wake_up(&runtime
->tsleep
);
1012 runtime
->status
->state
= SNDRV_PCM_STATE_RUNNING
;
1013 if (substream
->timer
)
1014 snd_timer_notify(substream
->timer
,
1015 SNDRV_TIMER_EVENT_MCONTINUE
,
1016 &runtime
->trigger_tstamp
);
1020 static struct action_ops snd_pcm_action_pause
= {
1021 .pre_action
= snd_pcm_pre_pause
,
1022 .do_action
= snd_pcm_do_pause
,
1023 .undo_action
= snd_pcm_undo_pause
,
1024 .post_action
= snd_pcm_post_pause
1028 * Push/release the pause for all linked streams.
1030 static int snd_pcm_pause(struct snd_pcm_substream
*substream
, int push
)
1032 return snd_pcm_action(&snd_pcm_action_pause
, substream
, push
);
1038 static int snd_pcm_pre_suspend(struct snd_pcm_substream
*substream
, int state
)
1040 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1041 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1043 runtime
->trigger_master
= substream
;
1047 static int snd_pcm_do_suspend(struct snd_pcm_substream
*substream
, int state
)
1049 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1050 if (runtime
->trigger_master
!= substream
)
1052 if (! snd_pcm_running(substream
))
1054 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1055 return 0; /* suspend unconditionally */
1058 static void snd_pcm_post_suspend(struct snd_pcm_substream
*substream
, int state
)
1060 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1061 snd_pcm_trigger_tstamp(substream
);
1062 if (substream
->timer
)
1063 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MSUSPEND
,
1064 &runtime
->trigger_tstamp
);
1065 runtime
->status
->suspended_state
= runtime
->status
->state
;
1066 runtime
->status
->state
= SNDRV_PCM_STATE_SUSPENDED
;
1067 wake_up(&runtime
->sleep
);
1068 wake_up(&runtime
->tsleep
);
1071 static struct action_ops snd_pcm_action_suspend
= {
1072 .pre_action
= snd_pcm_pre_suspend
,
1073 .do_action
= snd_pcm_do_suspend
,
1074 .post_action
= snd_pcm_post_suspend
1078 * snd_pcm_suspend - trigger SUSPEND to all linked streams
1079 * @substream: the PCM substream
1081 * After this call, all streams are changed to SUSPENDED state.
1083 int snd_pcm_suspend(struct snd_pcm_substream
*substream
)
1086 unsigned long flags
;
1091 snd_pcm_stream_lock_irqsave(substream
, flags
);
1092 err
= snd_pcm_action(&snd_pcm_action_suspend
, substream
, 0);
1093 snd_pcm_stream_unlock_irqrestore(substream
, flags
);
1097 EXPORT_SYMBOL(snd_pcm_suspend
);
1100 * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm
1101 * @pcm: the PCM instance
1103 * After this call, all streams are changed to SUSPENDED state.
1105 int snd_pcm_suspend_all(struct snd_pcm
*pcm
)
1107 struct snd_pcm_substream
*substream
;
1108 int stream
, err
= 0;
1113 for (stream
= 0; stream
< 2; stream
++) {
1114 for (substream
= pcm
->streams
[stream
].substream
;
1115 substream
; substream
= substream
->next
) {
1116 /* FIXME: the open/close code should lock this as well */
1117 if (substream
->runtime
== NULL
)
1119 err
= snd_pcm_suspend(substream
);
1120 if (err
< 0 && err
!= -EBUSY
)
1127 EXPORT_SYMBOL(snd_pcm_suspend_all
);
1131 static int snd_pcm_pre_resume(struct snd_pcm_substream
*substream
, int state
)
1133 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1134 if (!(runtime
->info
& SNDRV_PCM_INFO_RESUME
))
1136 runtime
->trigger_master
= substream
;
1140 static int snd_pcm_do_resume(struct snd_pcm_substream
*substream
, int state
)
1142 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1143 if (runtime
->trigger_master
!= substream
)
1145 /* DMA not running previously? */
1146 if (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_RUNNING
&&
1147 (runtime
->status
->suspended_state
!= SNDRV_PCM_STATE_DRAINING
||
1148 substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
1150 return substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_RESUME
);
1153 static void snd_pcm_undo_resume(struct snd_pcm_substream
*substream
, int state
)
1155 if (substream
->runtime
->trigger_master
== substream
&&
1156 snd_pcm_running(substream
))
1157 substream
->ops
->trigger(substream
, SNDRV_PCM_TRIGGER_SUSPEND
);
1160 static void snd_pcm_post_resume(struct snd_pcm_substream
*substream
, int state
)
1162 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1163 snd_pcm_trigger_tstamp(substream
);
1164 if (substream
->timer
)
1165 snd_timer_notify(substream
->timer
, SNDRV_TIMER_EVENT_MRESUME
,
1166 &runtime
->trigger_tstamp
);
1167 runtime
->status
->state
= runtime
->status
->suspended_state
;
1170 static struct action_ops snd_pcm_action_resume
= {
1171 .pre_action
= snd_pcm_pre_resume
,
1172 .do_action
= snd_pcm_do_resume
,
1173 .undo_action
= snd_pcm_undo_resume
,
1174 .post_action
= snd_pcm_post_resume
1177 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1179 struct snd_card
*card
= substream
->pcm
->card
;
1182 snd_power_lock(card
);
1183 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1184 res
= snd_pcm_action_lock_irq(&snd_pcm_action_resume
, substream
, 0);
1185 snd_power_unlock(card
);
1191 static int snd_pcm_resume(struct snd_pcm_substream
*substream
)
1196 #endif /* CONFIG_PM */
1201 * Change the RUNNING stream(s) to XRUN state.
1203 static int snd_pcm_xrun(struct snd_pcm_substream
*substream
)
1205 struct snd_card
*card
= substream
->pcm
->card
;
1206 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1209 snd_power_lock(card
);
1210 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1211 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1216 snd_pcm_stream_lock_irq(substream
);
1217 switch (runtime
->status
->state
) {
1218 case SNDRV_PCM_STATE_XRUN
:
1219 result
= 0; /* already there */
1221 case SNDRV_PCM_STATE_RUNNING
:
1222 result
= snd_pcm_stop(substream
, SNDRV_PCM_STATE_XRUN
);
1227 snd_pcm_stream_unlock_irq(substream
);
1229 snd_power_unlock(card
);
1236 static int snd_pcm_pre_reset(struct snd_pcm_substream
*substream
, int state
)
1238 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1239 switch (runtime
->status
->state
) {
1240 case SNDRV_PCM_STATE_RUNNING
:
1241 case SNDRV_PCM_STATE_PREPARED
:
1242 case SNDRV_PCM_STATE_PAUSED
:
1243 case SNDRV_PCM_STATE_SUSPENDED
:
1250 static int snd_pcm_do_reset(struct snd_pcm_substream
*substream
, int state
)
1252 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1253 int err
= substream
->ops
->ioctl(substream
, SNDRV_PCM_IOCTL1_RESET
, NULL
);
1256 runtime
->hw_ptr_base
= 0;
1257 runtime
->hw_ptr_interrupt
= runtime
->status
->hw_ptr
-
1258 runtime
->status
->hw_ptr
% runtime
->period_size
;
1259 runtime
->silence_start
= runtime
->status
->hw_ptr
;
1260 runtime
->silence_filled
= 0;
1264 static void snd_pcm_post_reset(struct snd_pcm_substream
*substream
, int state
)
1266 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1267 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1268 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
&&
1269 runtime
->silence_size
> 0)
1270 snd_pcm_playback_silence(substream
, ULONG_MAX
);
1273 static struct action_ops snd_pcm_action_reset
= {
1274 .pre_action
= snd_pcm_pre_reset
,
1275 .do_action
= snd_pcm_do_reset
,
1276 .post_action
= snd_pcm_post_reset
1279 static int snd_pcm_reset(struct snd_pcm_substream
*substream
)
1281 return snd_pcm_action_nonatomic(&snd_pcm_action_reset
, substream
, 0);
1287 /* we use the second argument for updating f_flags */
1288 static int snd_pcm_pre_prepare(struct snd_pcm_substream
*substream
,
1291 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1292 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1293 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
)
1295 if (snd_pcm_running(substream
))
1297 substream
->f_flags
= f_flags
;
1301 static int snd_pcm_do_prepare(struct snd_pcm_substream
*substream
, int state
)
1304 err
= substream
->ops
->prepare(substream
);
1307 return snd_pcm_do_reset(substream
, 0);
1310 static void snd_pcm_post_prepare(struct snd_pcm_substream
*substream
, int state
)
1312 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1313 runtime
->control
->appl_ptr
= runtime
->status
->hw_ptr
;
1314 runtime
->status
->state
= SNDRV_PCM_STATE_PREPARED
;
1317 static struct action_ops snd_pcm_action_prepare
= {
1318 .pre_action
= snd_pcm_pre_prepare
,
1319 .do_action
= snd_pcm_do_prepare
,
1320 .post_action
= snd_pcm_post_prepare
1324 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1325 * @substream: the PCM substream instance
1326 * @file: file to refer f_flags
1328 static int snd_pcm_prepare(struct snd_pcm_substream
*substream
,
1332 struct snd_card
*card
= substream
->pcm
->card
;
1336 f_flags
= file
->f_flags
;
1338 f_flags
= substream
->f_flags
;
1340 snd_power_lock(card
);
1341 if ((res
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
)) >= 0)
1342 res
= snd_pcm_action_nonatomic(&snd_pcm_action_prepare
,
1343 substream
, f_flags
);
1344 snd_power_unlock(card
);
1352 static int snd_pcm_pre_drain_init(struct snd_pcm_substream
*substream
, int state
)
1354 substream
->runtime
->trigger_master
= substream
;
1358 static int snd_pcm_do_drain_init(struct snd_pcm_substream
*substream
, int state
)
1360 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1361 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1362 switch (runtime
->status
->state
) {
1363 case SNDRV_PCM_STATE_PREPARED
:
1364 /* start playback stream if possible */
1365 if (! snd_pcm_playback_empty(substream
)) {
1366 snd_pcm_do_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1367 snd_pcm_post_start(substream
, SNDRV_PCM_STATE_DRAINING
);
1370 case SNDRV_PCM_STATE_RUNNING
:
1371 runtime
->status
->state
= SNDRV_PCM_STATE_DRAINING
;
1377 /* stop running stream */
1378 if (runtime
->status
->state
== SNDRV_PCM_STATE_RUNNING
) {
1379 int new_state
= snd_pcm_capture_avail(runtime
) > 0 ?
1380 SNDRV_PCM_STATE_DRAINING
: SNDRV_PCM_STATE_SETUP
;
1381 snd_pcm_do_stop(substream
, new_state
);
1382 snd_pcm_post_stop(substream
, new_state
);
1388 static void snd_pcm_post_drain_init(struct snd_pcm_substream
*substream
, int state
)
1392 static struct action_ops snd_pcm_action_drain_init
= {
1393 .pre_action
= snd_pcm_pre_drain_init
,
1394 .do_action
= snd_pcm_do_drain_init
,
1395 .post_action
= snd_pcm_post_drain_init
1398 static int snd_pcm_drop(struct snd_pcm_substream
*substream
);
1401 * Drain the stream(s).
1402 * When the substream is linked, sync until the draining of all playback streams
1404 * After this call, all streams are supposed to be either SETUP or DRAINING
1405 * (capture only) state.
1407 static int snd_pcm_drain(struct snd_pcm_substream
*substream
,
1410 struct snd_card
*card
;
1411 struct snd_pcm_runtime
*runtime
;
1412 struct snd_pcm_substream
*s
;
1417 card
= substream
->pcm
->card
;
1418 runtime
= substream
->runtime
;
1420 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
1423 snd_power_lock(card
);
1424 if (runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
) {
1425 result
= snd_power_wait(card
, SNDRV_CTL_POWER_D0
);
1427 snd_power_unlock(card
);
1433 if (file
->f_flags
& O_NONBLOCK
)
1435 } else if (substream
->f_flags
& O_NONBLOCK
)
1438 down_read(&snd_pcm_link_rwsem
);
1439 snd_pcm_stream_lock_irq(substream
);
1441 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1442 snd_pcm_pause(substream
, 0);
1444 /* pre-start/stop - all running streams are changed to DRAINING state */
1445 result
= snd_pcm_action(&snd_pcm_action_drain_init
, substream
, 0);
1448 /* in non-blocking, we don't wait in ioctl but let caller poll */
1456 struct snd_pcm_runtime
*to_check
;
1457 if (signal_pending(current
)) {
1458 result
= -ERESTARTSYS
;
1461 /* find a substream to drain */
1463 snd_pcm_group_for_each_entry(s
, substream
) {
1464 if (s
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
)
1466 runtime
= s
->runtime
;
1467 if (runtime
->status
->state
== SNDRV_PCM_STATE_DRAINING
) {
1473 break; /* all drained */
1474 init_waitqueue_entry(&wait
, current
);
1475 add_wait_queue(&to_check
->sleep
, &wait
);
1476 set_current_state(TASK_INTERRUPTIBLE
);
1477 snd_pcm_stream_unlock_irq(substream
);
1478 up_read(&snd_pcm_link_rwsem
);
1479 snd_power_unlock(card
);
1480 tout
= schedule_timeout(10 * HZ
);
1481 snd_power_lock(card
);
1482 down_read(&snd_pcm_link_rwsem
);
1483 snd_pcm_stream_lock_irq(substream
);
1484 remove_wait_queue(&to_check
->sleep
, &wait
);
1486 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1489 snd_printd("playback drain error (DMA or IRQ trouble?)\n");
1490 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1498 snd_pcm_stream_unlock_irq(substream
);
1499 up_read(&snd_pcm_link_rwsem
);
1500 snd_power_unlock(card
);
1508 * Immediately put all linked substreams into SETUP state.
1510 static int snd_pcm_drop(struct snd_pcm_substream
*substream
)
1512 struct snd_pcm_runtime
*runtime
;
1513 struct snd_card
*card
;
1516 if (PCM_RUNTIME_CHECK(substream
))
1518 runtime
= substream
->runtime
;
1519 card
= substream
->pcm
->card
;
1521 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1522 runtime
->status
->state
== SNDRV_PCM_STATE_DISCONNECTED
||
1523 runtime
->status
->state
== SNDRV_PCM_STATE_SUSPENDED
)
1526 snd_pcm_stream_lock_irq(substream
);
1528 if (runtime
->status
->state
== SNDRV_PCM_STATE_PAUSED
)
1529 snd_pcm_pause(substream
, 0);
1531 snd_pcm_stop(substream
, SNDRV_PCM_STATE_SETUP
);
1532 /* runtime->control->appl_ptr = runtime->status->hw_ptr; */
1533 snd_pcm_stream_unlock_irq(substream
);
1539 /* WARNING: Don't forget to fput back the file */
1540 static struct file
*snd_pcm_file_fd(int fd
)
1543 struct inode
*inode
;
1549 inode
= file
->f_path
.dentry
->d_inode
;
1550 if (!S_ISCHR(inode
->i_mode
) ||
1551 imajor(inode
) != snd_major
) {
1555 minor
= iminor(inode
);
1556 if (!snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_PLAYBACK
) &&
1557 !snd_lookup_minor_data(minor
, SNDRV_DEVICE_TYPE_PCM_CAPTURE
)) {
1567 static int snd_pcm_link(struct snd_pcm_substream
*substream
, int fd
)
1571 struct snd_pcm_file
*pcm_file
;
1572 struct snd_pcm_substream
*substream1
;
1574 file
= snd_pcm_file_fd(fd
);
1577 pcm_file
= file
->private_data
;
1578 substream1
= pcm_file
->substream
;
1579 down_write(&snd_pcm_link_rwsem
);
1580 write_lock_irq(&snd_pcm_link_rwlock
);
1581 if (substream
->runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
||
1582 substream
->runtime
->status
->state
!= substream1
->runtime
->status
->state
) {
1586 if (snd_pcm_stream_linked(substream1
)) {
1590 if (!snd_pcm_stream_linked(substream
)) {
1591 substream
->group
= kmalloc(sizeof(struct snd_pcm_group
), GFP_ATOMIC
);
1592 if (substream
->group
== NULL
) {
1596 spin_lock_init(&substream
->group
->lock
);
1597 INIT_LIST_HEAD(&substream
->group
->substreams
);
1598 list_add_tail(&substream
->link_list
, &substream
->group
->substreams
);
1599 substream
->group
->count
= 1;
1601 list_add_tail(&substream1
->link_list
, &substream
->group
->substreams
);
1602 substream
->group
->count
++;
1603 substream1
->group
= substream
->group
;
1605 write_unlock_irq(&snd_pcm_link_rwlock
);
1606 up_write(&snd_pcm_link_rwsem
);
1611 static void relink_to_local(struct snd_pcm_substream
*substream
)
1613 substream
->group
= &substream
->self_group
;
1614 INIT_LIST_HEAD(&substream
->self_group
.substreams
);
1615 list_add_tail(&substream
->link_list
, &substream
->self_group
.substreams
);
1618 static int snd_pcm_unlink(struct snd_pcm_substream
*substream
)
1620 struct snd_pcm_substream
*s
;
1623 down_write(&snd_pcm_link_rwsem
);
1624 write_lock_irq(&snd_pcm_link_rwlock
);
1625 if (!snd_pcm_stream_linked(substream
)) {
1629 list_del(&substream
->link_list
);
1630 substream
->group
->count
--;
1631 if (substream
->group
->count
== 1) { /* detach the last stream, too */
1632 snd_pcm_group_for_each_entry(s
, substream
) {
1636 kfree(substream
->group
);
1638 relink_to_local(substream
);
1640 write_unlock_irq(&snd_pcm_link_rwlock
);
1641 up_write(&snd_pcm_link_rwsem
);
1648 static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params
*params
,
1649 struct snd_pcm_hw_rule
*rule
)
1651 struct snd_interval t
;
1652 snd_interval_mul(hw_param_interval_c(params
, rule
->deps
[0]),
1653 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1654 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1657 static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params
*params
,
1658 struct snd_pcm_hw_rule
*rule
)
1660 struct snd_interval t
;
1661 snd_interval_div(hw_param_interval_c(params
, rule
->deps
[0]),
1662 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1663 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1666 static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params
*params
,
1667 struct snd_pcm_hw_rule
*rule
)
1669 struct snd_interval t
;
1670 snd_interval_muldivk(hw_param_interval_c(params
, rule
->deps
[0]),
1671 hw_param_interval_c(params
, rule
->deps
[1]),
1672 (unsigned long) rule
->private, &t
);
1673 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1676 static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params
*params
,
1677 struct snd_pcm_hw_rule
*rule
)
1679 struct snd_interval t
;
1680 snd_interval_mulkdiv(hw_param_interval_c(params
, rule
->deps
[0]),
1681 (unsigned long) rule
->private,
1682 hw_param_interval_c(params
, rule
->deps
[1]), &t
);
1683 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1686 static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params
*params
,
1687 struct snd_pcm_hw_rule
*rule
)
1690 struct snd_interval
*i
= hw_param_interval(params
, rule
->deps
[0]);
1692 struct snd_mask
*mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
1694 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1696 if (! snd_mask_test(mask
, k
))
1698 bits
= snd_pcm_format_physical_width(k
);
1700 continue; /* ignore invalid formats */
1701 if ((unsigned)bits
< i
->min
|| (unsigned)bits
> i
->max
)
1702 snd_mask_reset(&m
, k
);
1704 return snd_mask_refine(mask
, &m
);
1707 static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params
*params
,
1708 struct snd_pcm_hw_rule
*rule
)
1710 struct snd_interval t
;
1716 for (k
= 0; k
<= SNDRV_PCM_FORMAT_LAST
; ++k
) {
1718 if (! snd_mask_test(hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
), k
))
1720 bits
= snd_pcm_format_physical_width(k
);
1722 continue; /* ignore invalid formats */
1723 if (t
.min
> (unsigned)bits
)
1725 if (t
.max
< (unsigned)bits
)
1729 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1732 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1733 #error "Change this table"
1736 static unsigned int rates
[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1737 48000, 64000, 88200, 96000, 176400, 192000 };
1739 const struct snd_pcm_hw_constraint_list snd_pcm_known_rates
= {
1740 .count
= ARRAY_SIZE(rates
),
1744 static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params
*params
,
1745 struct snd_pcm_hw_rule
*rule
)
1747 struct snd_pcm_hardware
*hw
= rule
->private;
1748 return snd_interval_list(hw_param_interval(params
, rule
->var
),
1749 snd_pcm_known_rates
.count
,
1750 snd_pcm_known_rates
.list
, hw
->rates
);
1753 static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params
*params
,
1754 struct snd_pcm_hw_rule
*rule
)
1756 struct snd_interval t
;
1757 struct snd_pcm_substream
*substream
= rule
->private;
1759 t
.max
= substream
->buffer_bytes_max
;
1763 return snd_interval_refine(hw_param_interval(params
, rule
->var
), &t
);
1766 int snd_pcm_hw_constraints_init(struct snd_pcm_substream
*substream
)
1768 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1769 struct snd_pcm_hw_constraints
*constrs
= &runtime
->hw_constraints
;
1772 for (k
= SNDRV_PCM_HW_PARAM_FIRST_MASK
; k
<= SNDRV_PCM_HW_PARAM_LAST_MASK
; k
++) {
1773 snd_mask_any(constrs_mask(constrs
, k
));
1776 for (k
= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
; k
<= SNDRV_PCM_HW_PARAM_LAST_INTERVAL
; k
++) {
1777 snd_interval_any(constrs_interval(constrs
, k
));
1780 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_CHANNELS
));
1781 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
));
1782 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
));
1783 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
));
1784 snd_interval_setinteger(constrs_interval(constrs
, SNDRV_PCM_HW_PARAM_FRAME_BITS
));
1786 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FORMAT
,
1787 snd_pcm_hw_rule_format
, NULL
,
1788 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1791 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1792 snd_pcm_hw_rule_sample_bits
, NULL
,
1793 SNDRV_PCM_HW_PARAM_FORMAT
,
1794 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1797 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1798 snd_pcm_hw_rule_div
, NULL
,
1799 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1802 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1803 snd_pcm_hw_rule_mul
, NULL
,
1804 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
1807 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1808 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1809 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1812 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS
,
1813 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1814 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, -1);
1817 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1818 snd_pcm_hw_rule_div
, NULL
,
1819 SNDRV_PCM_HW_PARAM_FRAME_BITS
, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
, -1);
1822 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1823 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1824 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_TIME
, -1);
1827 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1828 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1829 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_BUFFER_TIME
, -1);
1832 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIODS
,
1833 snd_pcm_hw_rule_div
, NULL
,
1834 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, -1);
1837 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1838 snd_pcm_hw_rule_div
, NULL
,
1839 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1842 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1843 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1844 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1847 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
,
1848 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1849 SNDRV_PCM_HW_PARAM_PERIOD_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1852 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1853 snd_pcm_hw_rule_mul
, NULL
,
1854 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_PERIODS
, -1);
1857 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1858 snd_pcm_hw_rule_mulkdiv
, (void*) 8,
1859 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1862 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
1863 snd_pcm_hw_rule_muldivk
, (void*) 1000000,
1864 SNDRV_PCM_HW_PARAM_BUFFER_TIME
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1867 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1868 snd_pcm_hw_rule_muldivk
, (void*) 8,
1869 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1872 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1873 snd_pcm_hw_rule_muldivk
, (void*) 8,
1874 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_FRAME_BITS
, -1);
1877 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME
,
1878 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1879 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1882 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME
,
1883 snd_pcm_hw_rule_mulkdiv
, (void*) 1000000,
1884 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
, SNDRV_PCM_HW_PARAM_RATE
, -1);
1890 int snd_pcm_hw_constraints_complete(struct snd_pcm_substream
*substream
)
1892 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1893 struct snd_pcm_hardware
*hw
= &runtime
->hw
;
1895 unsigned int mask
= 0;
1897 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1898 mask
|= 1 << SNDRV_PCM_ACCESS_RW_INTERLEAVED
;
1899 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1900 mask
|= 1 << SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
;
1901 if (hw
->info
& SNDRV_PCM_INFO_MMAP
) {
1902 if (hw
->info
& SNDRV_PCM_INFO_INTERLEAVED
)
1903 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_INTERLEAVED
;
1904 if (hw
->info
& SNDRV_PCM_INFO_NONINTERLEAVED
)
1905 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED
;
1906 if (hw
->info
& SNDRV_PCM_INFO_COMPLEX
)
1907 mask
|= 1 << SNDRV_PCM_ACCESS_MMAP_COMPLEX
;
1909 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_ACCESS
, mask
);
1913 err
= snd_pcm_hw_constraint_mask64(runtime
, SNDRV_PCM_HW_PARAM_FORMAT
, hw
->formats
);
1917 err
= snd_pcm_hw_constraint_mask(runtime
, SNDRV_PCM_HW_PARAM_SUBFORMAT
, 1 << SNDRV_PCM_SUBFORMAT_STD
);
1921 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_CHANNELS
,
1922 hw
->channels_min
, hw
->channels_max
);
1926 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_RATE
,
1927 hw
->rate_min
, hw
->rate_max
);
1931 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1932 hw
->period_bytes_min
, hw
->period_bytes_max
);
1936 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_PERIODS
,
1937 hw
->periods_min
, hw
->periods_max
);
1941 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1942 hw
->period_bytes_min
, hw
->buffer_bytes_max
);
1946 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1947 snd_pcm_hw_rule_buffer_bytes_max
, substream
,
1948 SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, -1);
1953 if (runtime
->dma_bytes
) {
1954 err
= snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
, 0, runtime
->dma_bytes
);
1959 if (!(hw
->rates
& (SNDRV_PCM_RATE_KNOT
| SNDRV_PCM_RATE_CONTINUOUS
))) {
1960 err
= snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1961 snd_pcm_hw_rule_rate
, hw
,
1962 SNDRV_PCM_HW_PARAM_RATE
, -1);
1967 /* FIXME: this belong to lowlevel */
1968 snd_pcm_hw_constraint_integer(runtime
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
1973 static void pcm_release_private(struct snd_pcm_substream
*substream
)
1975 snd_pcm_unlink(substream
);
1978 void snd_pcm_release_substream(struct snd_pcm_substream
*substream
)
1980 substream
->ref_count
--;
1981 if (substream
->ref_count
> 0)
1984 snd_pcm_drop(substream
);
1985 if (substream
->hw_opened
) {
1986 if (substream
->ops
->hw_free
!= NULL
)
1987 substream
->ops
->hw_free(substream
);
1988 substream
->ops
->close(substream
);
1989 substream
->hw_opened
= 0;
1991 if (substream
->pcm_release
) {
1992 substream
->pcm_release(substream
);
1993 substream
->pcm_release
= NULL
;
1995 snd_pcm_detach_substream(substream
);
1998 EXPORT_SYMBOL(snd_pcm_release_substream
);
2000 int snd_pcm_open_substream(struct snd_pcm
*pcm
, int stream
,
2002 struct snd_pcm_substream
**rsubstream
)
2004 struct snd_pcm_substream
*substream
;
2007 err
= snd_pcm_attach_substream(pcm
, stream
, file
, &substream
);
2010 if (substream
->ref_count
> 1) {
2011 *rsubstream
= substream
;
2015 err
= snd_pcm_hw_constraints_init(substream
);
2017 snd_printd("snd_pcm_hw_constraints_init failed\n");
2021 if ((err
= substream
->ops
->open(substream
)) < 0)
2024 substream
->hw_opened
= 1;
2026 err
= snd_pcm_hw_constraints_complete(substream
);
2028 snd_printd("snd_pcm_hw_constraints_complete failed\n");
2032 *rsubstream
= substream
;
2036 snd_pcm_release_substream(substream
);
2040 EXPORT_SYMBOL(snd_pcm_open_substream
);
2042 static int snd_pcm_open_file(struct file
*file
,
2043 struct snd_pcm
*pcm
,
2045 struct snd_pcm_file
**rpcm_file
)
2047 struct snd_pcm_file
*pcm_file
;
2048 struct snd_pcm_substream
*substream
;
2049 struct snd_pcm_str
*str
;
2055 err
= snd_pcm_open_substream(pcm
, stream
, file
, &substream
);
2059 pcm_file
= kzalloc(sizeof(*pcm_file
), GFP_KERNEL
);
2060 if (pcm_file
== NULL
) {
2061 snd_pcm_release_substream(substream
);
2064 pcm_file
->substream
= substream
;
2065 if (substream
->ref_count
== 1) {
2066 str
= substream
->pstr
;
2067 substream
->file
= pcm_file
;
2068 substream
->pcm_release
= pcm_release_private
;
2070 file
->private_data
= pcm_file
;
2072 *rpcm_file
= pcm_file
;
2076 static int snd_pcm_playback_open(struct inode
*inode
, struct file
*file
)
2078 struct snd_pcm
*pcm
;
2079 int err
= nonseekable_open(inode
, file
);
2082 pcm
= snd_lookup_minor_data(iminor(inode
),
2083 SNDRV_DEVICE_TYPE_PCM_PLAYBACK
);
2084 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_PLAYBACK
);
2087 static int snd_pcm_capture_open(struct inode
*inode
, struct file
*file
)
2089 struct snd_pcm
*pcm
;
2090 int err
= nonseekable_open(inode
, file
);
2093 pcm
= snd_lookup_minor_data(iminor(inode
),
2094 SNDRV_DEVICE_TYPE_PCM_CAPTURE
);
2095 return snd_pcm_open(file
, pcm
, SNDRV_PCM_STREAM_CAPTURE
);
2098 static int snd_pcm_open(struct file
*file
, struct snd_pcm
*pcm
, int stream
)
2101 struct snd_pcm_file
*pcm_file
;
2108 err
= snd_card_file_add(pcm
->card
, file
);
2111 if (!try_module_get(pcm
->card
->module
)) {
2115 init_waitqueue_entry(&wait
, current
);
2116 add_wait_queue(&pcm
->open_wait
, &wait
);
2117 mutex_lock(&pcm
->open_mutex
);
2119 err
= snd_pcm_open_file(file
, pcm
, stream
, &pcm_file
);
2122 if (err
== -EAGAIN
) {
2123 if (file
->f_flags
& O_NONBLOCK
) {
2129 set_current_state(TASK_INTERRUPTIBLE
);
2130 mutex_unlock(&pcm
->open_mutex
);
2132 mutex_lock(&pcm
->open_mutex
);
2133 if (signal_pending(current
)) {
2138 remove_wait_queue(&pcm
->open_wait
, &wait
);
2139 mutex_unlock(&pcm
->open_mutex
);
2145 module_put(pcm
->card
->module
);
2147 snd_card_file_remove(pcm
->card
, file
);
2152 static int snd_pcm_release(struct inode
*inode
, struct file
*file
)
2154 struct snd_pcm
*pcm
;
2155 struct snd_pcm_substream
*substream
;
2156 struct snd_pcm_file
*pcm_file
;
2158 pcm_file
= file
->private_data
;
2159 substream
= pcm_file
->substream
;
2160 if (snd_BUG_ON(!substream
))
2162 pcm
= substream
->pcm
;
2163 mutex_lock(&pcm
->open_mutex
);
2164 snd_pcm_release_substream(substream
);
2166 mutex_unlock(&pcm
->open_mutex
);
2167 wake_up(&pcm
->open_wait
);
2168 module_put(pcm
->card
->module
);
2169 snd_card_file_remove(pcm
->card
, file
);
2173 static snd_pcm_sframes_t
snd_pcm_playback_rewind(struct snd_pcm_substream
*substream
,
2174 snd_pcm_uframes_t frames
)
2176 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2177 snd_pcm_sframes_t appl_ptr
;
2178 snd_pcm_sframes_t ret
;
2179 snd_pcm_sframes_t hw_avail
;
2184 snd_pcm_stream_lock_irq(substream
);
2185 switch (runtime
->status
->state
) {
2186 case SNDRV_PCM_STATE_PREPARED
:
2188 case SNDRV_PCM_STATE_DRAINING
:
2189 case SNDRV_PCM_STATE_RUNNING
:
2190 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2193 case SNDRV_PCM_STATE_XRUN
:
2196 case SNDRV_PCM_STATE_SUSPENDED
:
2204 hw_avail
= snd_pcm_playback_hw_avail(runtime
);
2205 if (hw_avail
<= 0) {
2209 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2211 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2213 appl_ptr
+= runtime
->boundary
;
2214 runtime
->control
->appl_ptr
= appl_ptr
;
2217 snd_pcm_stream_unlock_irq(substream
);
2221 static snd_pcm_sframes_t
snd_pcm_capture_rewind(struct snd_pcm_substream
*substream
,
2222 snd_pcm_uframes_t frames
)
2224 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2225 snd_pcm_sframes_t appl_ptr
;
2226 snd_pcm_sframes_t ret
;
2227 snd_pcm_sframes_t hw_avail
;
2232 snd_pcm_stream_lock_irq(substream
);
2233 switch (runtime
->status
->state
) {
2234 case SNDRV_PCM_STATE_PREPARED
:
2235 case SNDRV_PCM_STATE_DRAINING
:
2237 case SNDRV_PCM_STATE_RUNNING
:
2238 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2241 case SNDRV_PCM_STATE_XRUN
:
2244 case SNDRV_PCM_STATE_SUSPENDED
:
2252 hw_avail
= snd_pcm_capture_hw_avail(runtime
);
2253 if (hw_avail
<= 0) {
2257 if (frames
> (snd_pcm_uframes_t
)hw_avail
)
2259 appl_ptr
= runtime
->control
->appl_ptr
- frames
;
2261 appl_ptr
+= runtime
->boundary
;
2262 runtime
->control
->appl_ptr
= appl_ptr
;
2265 snd_pcm_stream_unlock_irq(substream
);
2269 static snd_pcm_sframes_t
snd_pcm_playback_forward(struct snd_pcm_substream
*substream
,
2270 snd_pcm_uframes_t frames
)
2272 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2273 snd_pcm_sframes_t appl_ptr
;
2274 snd_pcm_sframes_t ret
;
2275 snd_pcm_sframes_t avail
;
2280 snd_pcm_stream_lock_irq(substream
);
2281 switch (runtime
->status
->state
) {
2282 case SNDRV_PCM_STATE_PREPARED
:
2283 case SNDRV_PCM_STATE_PAUSED
:
2285 case SNDRV_PCM_STATE_DRAINING
:
2286 case SNDRV_PCM_STATE_RUNNING
:
2287 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2290 case SNDRV_PCM_STATE_XRUN
:
2293 case SNDRV_PCM_STATE_SUSPENDED
:
2301 avail
= snd_pcm_playback_avail(runtime
);
2306 if (frames
> (snd_pcm_uframes_t
)avail
)
2308 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2309 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2310 appl_ptr
-= runtime
->boundary
;
2311 runtime
->control
->appl_ptr
= appl_ptr
;
2314 snd_pcm_stream_unlock_irq(substream
);
2318 static snd_pcm_sframes_t
snd_pcm_capture_forward(struct snd_pcm_substream
*substream
,
2319 snd_pcm_uframes_t frames
)
2321 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2322 snd_pcm_sframes_t appl_ptr
;
2323 snd_pcm_sframes_t ret
;
2324 snd_pcm_sframes_t avail
;
2329 snd_pcm_stream_lock_irq(substream
);
2330 switch (runtime
->status
->state
) {
2331 case SNDRV_PCM_STATE_PREPARED
:
2332 case SNDRV_PCM_STATE_DRAINING
:
2333 case SNDRV_PCM_STATE_PAUSED
:
2335 case SNDRV_PCM_STATE_RUNNING
:
2336 if (snd_pcm_update_hw_ptr(substream
) >= 0)
2339 case SNDRV_PCM_STATE_XRUN
:
2342 case SNDRV_PCM_STATE_SUSPENDED
:
2350 avail
= snd_pcm_capture_avail(runtime
);
2355 if (frames
> (snd_pcm_uframes_t
)avail
)
2357 appl_ptr
= runtime
->control
->appl_ptr
+ frames
;
2358 if (appl_ptr
>= (snd_pcm_sframes_t
)runtime
->boundary
)
2359 appl_ptr
-= runtime
->boundary
;
2360 runtime
->control
->appl_ptr
= appl_ptr
;
2363 snd_pcm_stream_unlock_irq(substream
);
2367 static int snd_pcm_hwsync(struct snd_pcm_substream
*substream
)
2369 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2372 snd_pcm_stream_lock_irq(substream
);
2373 switch (runtime
->status
->state
) {
2374 case SNDRV_PCM_STATE_DRAINING
:
2375 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2377 case SNDRV_PCM_STATE_RUNNING
:
2378 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2381 case SNDRV_PCM_STATE_PREPARED
:
2382 case SNDRV_PCM_STATE_SUSPENDED
:
2385 case SNDRV_PCM_STATE_XRUN
:
2393 snd_pcm_stream_unlock_irq(substream
);
2397 static int snd_pcm_delay(struct snd_pcm_substream
*substream
,
2398 snd_pcm_sframes_t __user
*res
)
2400 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2402 snd_pcm_sframes_t n
= 0;
2404 snd_pcm_stream_lock_irq(substream
);
2405 switch (runtime
->status
->state
) {
2406 case SNDRV_PCM_STATE_DRAINING
:
2407 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
2409 case SNDRV_PCM_STATE_RUNNING
:
2410 if ((err
= snd_pcm_update_hw_ptr(substream
)) < 0)
2413 case SNDRV_PCM_STATE_PREPARED
:
2414 case SNDRV_PCM_STATE_SUSPENDED
:
2416 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
2417 n
= snd_pcm_playback_hw_avail(runtime
);
2419 n
= snd_pcm_capture_avail(runtime
);
2420 n
+= runtime
->delay
;
2422 case SNDRV_PCM_STATE_XRUN
:
2430 snd_pcm_stream_unlock_irq(substream
);
2432 if (put_user(n
, res
))
2437 static int snd_pcm_sync_ptr(struct snd_pcm_substream
*substream
,
2438 struct snd_pcm_sync_ptr __user
*_sync_ptr
)
2440 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2441 struct snd_pcm_sync_ptr sync_ptr
;
2442 volatile struct snd_pcm_mmap_status
*status
;
2443 volatile struct snd_pcm_mmap_control
*control
;
2446 memset(&sync_ptr
, 0, sizeof(sync_ptr
));
2447 if (get_user(sync_ptr
.flags
, (unsigned __user
*)&(_sync_ptr
->flags
)))
2449 if (copy_from_user(&sync_ptr
.c
.control
, &(_sync_ptr
->c
.control
), sizeof(struct snd_pcm_mmap_control
)))
2451 status
= runtime
->status
;
2452 control
= runtime
->control
;
2453 if (sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_HWSYNC
) {
2454 err
= snd_pcm_hwsync(substream
);
2458 snd_pcm_stream_lock_irq(substream
);
2459 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_APPL
))
2460 control
->appl_ptr
= sync_ptr
.c
.control
.appl_ptr
;
2462 sync_ptr
.c
.control
.appl_ptr
= control
->appl_ptr
;
2463 if (!(sync_ptr
.flags
& SNDRV_PCM_SYNC_PTR_AVAIL_MIN
))
2464 control
->avail_min
= sync_ptr
.c
.control
.avail_min
;
2466 sync_ptr
.c
.control
.avail_min
= control
->avail_min
;
2467 sync_ptr
.s
.status
.state
= status
->state
;
2468 sync_ptr
.s
.status
.hw_ptr
= status
->hw_ptr
;
2469 sync_ptr
.s
.status
.tstamp
= status
->tstamp
;
2470 sync_ptr
.s
.status
.suspended_state
= status
->suspended_state
;
2471 snd_pcm_stream_unlock_irq(substream
);
2472 if (copy_to_user(_sync_ptr
, &sync_ptr
, sizeof(sync_ptr
)))
2477 static int snd_pcm_tstamp(struct snd_pcm_substream
*substream
, int __user
*_arg
)
2479 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2482 if (get_user(arg
, _arg
))
2484 if (arg
< 0 || arg
> SNDRV_PCM_TSTAMP_TYPE_LAST
)
2486 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY
;
2487 if (arg
== SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
)
2488 runtime
->tstamp_type
= SNDRV_PCM_TSTAMP_TYPE_MONOTONIC
;
2492 static int snd_pcm_common_ioctl1(struct file
*file
,
2493 struct snd_pcm_substream
*substream
,
2494 unsigned int cmd
, void __user
*arg
)
2497 case SNDRV_PCM_IOCTL_PVERSION
:
2498 return put_user(SNDRV_PCM_VERSION
, (int __user
*)arg
) ? -EFAULT
: 0;
2499 case SNDRV_PCM_IOCTL_INFO
:
2500 return snd_pcm_info_user(substream
, arg
);
2501 case SNDRV_PCM_IOCTL_TSTAMP
: /* just for compatibility */
2503 case SNDRV_PCM_IOCTL_TTSTAMP
:
2504 return snd_pcm_tstamp(substream
, arg
);
2505 case SNDRV_PCM_IOCTL_HW_REFINE
:
2506 return snd_pcm_hw_refine_user(substream
, arg
);
2507 case SNDRV_PCM_IOCTL_HW_PARAMS
:
2508 return snd_pcm_hw_params_user(substream
, arg
);
2509 case SNDRV_PCM_IOCTL_HW_FREE
:
2510 return snd_pcm_hw_free(substream
);
2511 case SNDRV_PCM_IOCTL_SW_PARAMS
:
2512 return snd_pcm_sw_params_user(substream
, arg
);
2513 case SNDRV_PCM_IOCTL_STATUS
:
2514 return snd_pcm_status_user(substream
, arg
);
2515 case SNDRV_PCM_IOCTL_CHANNEL_INFO
:
2516 return snd_pcm_channel_info_user(substream
, arg
);
2517 case SNDRV_PCM_IOCTL_PREPARE
:
2518 return snd_pcm_prepare(substream
, file
);
2519 case SNDRV_PCM_IOCTL_RESET
:
2520 return snd_pcm_reset(substream
);
2521 case SNDRV_PCM_IOCTL_START
:
2522 return snd_pcm_action_lock_irq(&snd_pcm_action_start
, substream
, SNDRV_PCM_STATE_RUNNING
);
2523 case SNDRV_PCM_IOCTL_LINK
:
2524 return snd_pcm_link(substream
, (int)(unsigned long) arg
);
2525 case SNDRV_PCM_IOCTL_UNLINK
:
2526 return snd_pcm_unlink(substream
);
2527 case SNDRV_PCM_IOCTL_RESUME
:
2528 return snd_pcm_resume(substream
);
2529 case SNDRV_PCM_IOCTL_XRUN
:
2530 return snd_pcm_xrun(substream
);
2531 case SNDRV_PCM_IOCTL_HWSYNC
:
2532 return snd_pcm_hwsync(substream
);
2533 case SNDRV_PCM_IOCTL_DELAY
:
2534 return snd_pcm_delay(substream
, arg
);
2535 case SNDRV_PCM_IOCTL_SYNC_PTR
:
2536 return snd_pcm_sync_ptr(substream
, arg
);
2537 #ifdef CONFIG_SND_SUPPORT_OLD_API
2538 case SNDRV_PCM_IOCTL_HW_REFINE_OLD
:
2539 return snd_pcm_hw_refine_old_user(substream
, arg
);
2540 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD
:
2541 return snd_pcm_hw_params_old_user(substream
, arg
);
2543 case SNDRV_PCM_IOCTL_DRAIN
:
2544 return snd_pcm_drain(substream
, file
);
2545 case SNDRV_PCM_IOCTL_DROP
:
2546 return snd_pcm_drop(substream
);
2547 case SNDRV_PCM_IOCTL_PAUSE
:
2550 snd_pcm_stream_lock_irq(substream
);
2551 res
= snd_pcm_pause(substream
, (int)(unsigned long)arg
);
2552 snd_pcm_stream_unlock_irq(substream
);
2556 snd_printd("unknown ioctl = 0x%x\n", cmd
);
2560 static int snd_pcm_playback_ioctl1(struct file
*file
,
2561 struct snd_pcm_substream
*substream
,
2562 unsigned int cmd
, void __user
*arg
)
2564 if (snd_BUG_ON(!substream
))
2566 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_PLAYBACK
))
2569 case SNDRV_PCM_IOCTL_WRITEI_FRAMES
:
2571 struct snd_xferi xferi
;
2572 struct snd_xferi __user
*_xferi
= arg
;
2573 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2574 snd_pcm_sframes_t result
;
2575 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2577 if (put_user(0, &_xferi
->result
))
2579 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2581 result
= snd_pcm_lib_write(substream
, xferi
.buf
, xferi
.frames
);
2582 __put_user(result
, &_xferi
->result
);
2583 return result
< 0 ? result
: 0;
2585 case SNDRV_PCM_IOCTL_WRITEN_FRAMES
:
2587 struct snd_xfern xfern
;
2588 struct snd_xfern __user
*_xfern
= arg
;
2589 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2591 snd_pcm_sframes_t result
;
2592 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2594 if (runtime
->channels
> 128)
2596 if (put_user(0, &_xfern
->result
))
2598 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2601 bufs
= memdup_user(xfern
.bufs
,
2602 sizeof(void *) * runtime
->channels
);
2604 return PTR_ERR(bufs
);
2605 result
= snd_pcm_lib_writev(substream
, bufs
, xfern
.frames
);
2607 __put_user(result
, &_xfern
->result
);
2608 return result
< 0 ? result
: 0;
2610 case SNDRV_PCM_IOCTL_REWIND
:
2612 snd_pcm_uframes_t frames
;
2613 snd_pcm_uframes_t __user
*_frames
= arg
;
2614 snd_pcm_sframes_t result
;
2615 if (get_user(frames
, _frames
))
2617 if (put_user(0, _frames
))
2619 result
= snd_pcm_playback_rewind(substream
, frames
);
2620 __put_user(result
, _frames
);
2621 return result
< 0 ? result
: 0;
2623 case SNDRV_PCM_IOCTL_FORWARD
:
2625 snd_pcm_uframes_t frames
;
2626 snd_pcm_uframes_t __user
*_frames
= arg
;
2627 snd_pcm_sframes_t result
;
2628 if (get_user(frames
, _frames
))
2630 if (put_user(0, _frames
))
2632 result
= snd_pcm_playback_forward(substream
, frames
);
2633 __put_user(result
, _frames
);
2634 return result
< 0 ? result
: 0;
2637 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2640 static int snd_pcm_capture_ioctl1(struct file
*file
,
2641 struct snd_pcm_substream
*substream
,
2642 unsigned int cmd
, void __user
*arg
)
2644 if (snd_BUG_ON(!substream
))
2646 if (snd_BUG_ON(substream
->stream
!= SNDRV_PCM_STREAM_CAPTURE
))
2649 case SNDRV_PCM_IOCTL_READI_FRAMES
:
2651 struct snd_xferi xferi
;
2652 struct snd_xferi __user
*_xferi
= arg
;
2653 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2654 snd_pcm_sframes_t result
;
2655 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2657 if (put_user(0, &_xferi
->result
))
2659 if (copy_from_user(&xferi
, _xferi
, sizeof(xferi
)))
2661 result
= snd_pcm_lib_read(substream
, xferi
.buf
, xferi
.frames
);
2662 __put_user(result
, &_xferi
->result
);
2663 return result
< 0 ? result
: 0;
2665 case SNDRV_PCM_IOCTL_READN_FRAMES
:
2667 struct snd_xfern xfern
;
2668 struct snd_xfern __user
*_xfern
= arg
;
2669 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
2671 snd_pcm_sframes_t result
;
2672 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2674 if (runtime
->channels
> 128)
2676 if (put_user(0, &_xfern
->result
))
2678 if (copy_from_user(&xfern
, _xfern
, sizeof(xfern
)))
2681 bufs
= memdup_user(xfern
.bufs
,
2682 sizeof(void *) * runtime
->channels
);
2684 return PTR_ERR(bufs
);
2685 result
= snd_pcm_lib_readv(substream
, bufs
, xfern
.frames
);
2687 __put_user(result
, &_xfern
->result
);
2688 return result
< 0 ? result
: 0;
2690 case SNDRV_PCM_IOCTL_REWIND
:
2692 snd_pcm_uframes_t frames
;
2693 snd_pcm_uframes_t __user
*_frames
= arg
;
2694 snd_pcm_sframes_t result
;
2695 if (get_user(frames
, _frames
))
2697 if (put_user(0, _frames
))
2699 result
= snd_pcm_capture_rewind(substream
, frames
);
2700 __put_user(result
, _frames
);
2701 return result
< 0 ? result
: 0;
2703 case SNDRV_PCM_IOCTL_FORWARD
:
2705 snd_pcm_uframes_t frames
;
2706 snd_pcm_uframes_t __user
*_frames
= arg
;
2707 snd_pcm_sframes_t result
;
2708 if (get_user(frames
, _frames
))
2710 if (put_user(0, _frames
))
2712 result
= snd_pcm_capture_forward(substream
, frames
);
2713 __put_user(result
, _frames
);
2714 return result
< 0 ? result
: 0;
2717 return snd_pcm_common_ioctl1(file
, substream
, cmd
, arg
);
2720 static long snd_pcm_playback_ioctl(struct file
*file
, unsigned int cmd
,
2723 struct snd_pcm_file
*pcm_file
;
2725 pcm_file
= file
->private_data
;
2727 if (((cmd
>> 8) & 0xff) != 'A')
2730 return snd_pcm_playback_ioctl1(file
, pcm_file
->substream
, cmd
,
2731 (void __user
*)arg
);
2734 static long snd_pcm_capture_ioctl(struct file
*file
, unsigned int cmd
,
2737 struct snd_pcm_file
*pcm_file
;
2739 pcm_file
= file
->private_data
;
2741 if (((cmd
>> 8) & 0xff) != 'A')
2744 return snd_pcm_capture_ioctl1(file
, pcm_file
->substream
, cmd
,
2745 (void __user
*)arg
);
2748 int snd_pcm_kernel_ioctl(struct snd_pcm_substream
*substream
,
2749 unsigned int cmd
, void *arg
)
2754 fs
= snd_enter_user();
2755 switch (substream
->stream
) {
2756 case SNDRV_PCM_STREAM_PLAYBACK
:
2757 result
= snd_pcm_playback_ioctl1(NULL
, substream
, cmd
,
2758 (void __user
*)arg
);
2760 case SNDRV_PCM_STREAM_CAPTURE
:
2761 result
= snd_pcm_capture_ioctl1(NULL
, substream
, cmd
,
2762 (void __user
*)arg
);
2772 EXPORT_SYMBOL(snd_pcm_kernel_ioctl
);
2774 static ssize_t
snd_pcm_read(struct file
*file
, char __user
*buf
, size_t count
,
2777 struct snd_pcm_file
*pcm_file
;
2778 struct snd_pcm_substream
*substream
;
2779 struct snd_pcm_runtime
*runtime
;
2780 snd_pcm_sframes_t result
;
2782 pcm_file
= file
->private_data
;
2783 substream
= pcm_file
->substream
;
2784 if (PCM_RUNTIME_CHECK(substream
))
2786 runtime
= substream
->runtime
;
2787 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2789 if (!frame_aligned(runtime
, count
))
2791 count
= bytes_to_frames(runtime
, count
);
2792 result
= snd_pcm_lib_read(substream
, buf
, count
);
2794 result
= frames_to_bytes(runtime
, result
);
2798 static ssize_t
snd_pcm_write(struct file
*file
, const char __user
*buf
,
2799 size_t count
, loff_t
* offset
)
2801 struct snd_pcm_file
*pcm_file
;
2802 struct snd_pcm_substream
*substream
;
2803 struct snd_pcm_runtime
*runtime
;
2804 snd_pcm_sframes_t result
;
2806 pcm_file
= file
->private_data
;
2807 substream
= pcm_file
->substream
;
2808 if (PCM_RUNTIME_CHECK(substream
))
2810 runtime
= substream
->runtime
;
2811 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2813 if (!frame_aligned(runtime
, count
))
2815 count
= bytes_to_frames(runtime
, count
);
2816 result
= snd_pcm_lib_write(substream
, buf
, count
);
2818 result
= frames_to_bytes(runtime
, result
);
2822 static ssize_t
snd_pcm_aio_read(struct kiocb
*iocb
, const struct iovec
*iov
,
2823 unsigned long nr_segs
, loff_t pos
)
2826 struct snd_pcm_file
*pcm_file
;
2827 struct snd_pcm_substream
*substream
;
2828 struct snd_pcm_runtime
*runtime
;
2829 snd_pcm_sframes_t result
;
2832 snd_pcm_uframes_t frames
;
2834 pcm_file
= iocb
->ki_filp
->private_data
;
2835 substream
= pcm_file
->substream
;
2836 if (PCM_RUNTIME_CHECK(substream
))
2838 runtime
= substream
->runtime
;
2839 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2841 if (nr_segs
> 1024 || nr_segs
!= runtime
->channels
)
2843 if (!frame_aligned(runtime
, iov
->iov_len
))
2845 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2846 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2849 for (i
= 0; i
< nr_segs
; ++i
)
2850 bufs
[i
] = iov
[i
].iov_base
;
2851 result
= snd_pcm_lib_readv(substream
, bufs
, frames
);
2853 result
= frames_to_bytes(runtime
, result
);
2858 static ssize_t
snd_pcm_aio_write(struct kiocb
*iocb
, const struct iovec
*iov
,
2859 unsigned long nr_segs
, loff_t pos
)
2861 struct snd_pcm_file
*pcm_file
;
2862 struct snd_pcm_substream
*substream
;
2863 struct snd_pcm_runtime
*runtime
;
2864 snd_pcm_sframes_t result
;
2867 snd_pcm_uframes_t frames
;
2869 pcm_file
= iocb
->ki_filp
->private_data
;
2870 substream
= pcm_file
->substream
;
2871 if (PCM_RUNTIME_CHECK(substream
))
2873 runtime
= substream
->runtime
;
2874 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
2876 if (nr_segs
> 128 || nr_segs
!= runtime
->channels
||
2877 !frame_aligned(runtime
, iov
->iov_len
))
2879 frames
= bytes_to_samples(runtime
, iov
->iov_len
);
2880 bufs
= kmalloc(sizeof(void *) * nr_segs
, GFP_KERNEL
);
2883 for (i
= 0; i
< nr_segs
; ++i
)
2884 bufs
[i
] = iov
[i
].iov_base
;
2885 result
= snd_pcm_lib_writev(substream
, bufs
, frames
);
2887 result
= frames_to_bytes(runtime
, result
);
2892 static unsigned int snd_pcm_playback_poll(struct file
*file
, poll_table
* wait
)
2894 struct snd_pcm_file
*pcm_file
;
2895 struct snd_pcm_substream
*substream
;
2896 struct snd_pcm_runtime
*runtime
;
2898 snd_pcm_uframes_t avail
;
2900 pcm_file
= file
->private_data
;
2902 substream
= pcm_file
->substream
;
2903 if (PCM_RUNTIME_CHECK(substream
))
2905 runtime
= substream
->runtime
;
2907 poll_wait(file
, &runtime
->sleep
, wait
);
2909 snd_pcm_stream_lock_irq(substream
);
2910 avail
= snd_pcm_playback_avail(runtime
);
2911 switch (runtime
->status
->state
) {
2912 case SNDRV_PCM_STATE_RUNNING
:
2913 case SNDRV_PCM_STATE_PREPARED
:
2914 case SNDRV_PCM_STATE_PAUSED
:
2915 if (avail
>= runtime
->control
->avail_min
) {
2916 mask
= POLLOUT
| POLLWRNORM
;
2920 case SNDRV_PCM_STATE_DRAINING
:
2924 mask
= POLLOUT
| POLLWRNORM
| POLLERR
;
2927 snd_pcm_stream_unlock_irq(substream
);
2931 static unsigned int snd_pcm_capture_poll(struct file
*file
, poll_table
* wait
)
2933 struct snd_pcm_file
*pcm_file
;
2934 struct snd_pcm_substream
*substream
;
2935 struct snd_pcm_runtime
*runtime
;
2937 snd_pcm_uframes_t avail
;
2939 pcm_file
= file
->private_data
;
2941 substream
= pcm_file
->substream
;
2942 if (PCM_RUNTIME_CHECK(substream
))
2944 runtime
= substream
->runtime
;
2946 poll_wait(file
, &runtime
->sleep
, wait
);
2948 snd_pcm_stream_lock_irq(substream
);
2949 avail
= snd_pcm_capture_avail(runtime
);
2950 switch (runtime
->status
->state
) {
2951 case SNDRV_PCM_STATE_RUNNING
:
2952 case SNDRV_PCM_STATE_PREPARED
:
2953 case SNDRV_PCM_STATE_PAUSED
:
2954 if (avail
>= runtime
->control
->avail_min
) {
2955 mask
= POLLIN
| POLLRDNORM
;
2960 case SNDRV_PCM_STATE_DRAINING
:
2962 mask
= POLLIN
| POLLRDNORM
;
2967 mask
= POLLIN
| POLLRDNORM
| POLLERR
;
2970 snd_pcm_stream_unlock_irq(substream
);
2979 * Only on coherent architectures, we can mmap the status and the control records
2980 * for effcient data transfer. On others, we have to use HWSYNC ioctl...
2982 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
2984 * mmap status record
2986 static int snd_pcm_mmap_status_fault(struct vm_area_struct
*area
,
2987 struct vm_fault
*vmf
)
2989 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
2990 struct snd_pcm_runtime
*runtime
;
2992 if (substream
== NULL
)
2993 return VM_FAULT_SIGBUS
;
2994 runtime
= substream
->runtime
;
2995 vmf
->page
= virt_to_page(runtime
->status
);
2996 get_page(vmf
->page
);
3000 static const struct vm_operations_struct snd_pcm_vm_ops_status
=
3002 .fault
= snd_pcm_mmap_status_fault
,
3005 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3006 struct vm_area_struct
*area
)
3008 struct snd_pcm_runtime
*runtime
;
3010 if (!(area
->vm_flags
& VM_READ
))
3012 runtime
= substream
->runtime
;
3013 size
= area
->vm_end
- area
->vm_start
;
3014 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status
)))
3016 area
->vm_ops
= &snd_pcm_vm_ops_status
;
3017 area
->vm_private_data
= substream
;
3018 area
->vm_flags
|= VM_RESERVED
;
3023 * mmap control record
3025 static int snd_pcm_mmap_control_fault(struct vm_area_struct
*area
,
3026 struct vm_fault
*vmf
)
3028 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3029 struct snd_pcm_runtime
*runtime
;
3031 if (substream
== NULL
)
3032 return VM_FAULT_SIGBUS
;
3033 runtime
= substream
->runtime
;
3034 vmf
->page
= virt_to_page(runtime
->control
);
3035 get_page(vmf
->page
);
3039 static const struct vm_operations_struct snd_pcm_vm_ops_control
=
3041 .fault
= snd_pcm_mmap_control_fault
,
3044 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3045 struct vm_area_struct
*area
)
3047 struct snd_pcm_runtime
*runtime
;
3049 if (!(area
->vm_flags
& VM_READ
))
3051 runtime
= substream
->runtime
;
3052 size
= area
->vm_end
- area
->vm_start
;
3053 if (size
!= PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control
)))
3055 area
->vm_ops
= &snd_pcm_vm_ops_control
;
3056 area
->vm_private_data
= substream
;
3057 area
->vm_flags
|= VM_RESERVED
;
3060 #else /* ! coherent mmap */
3062 * don't support mmap for status and control records.
3064 static int snd_pcm_mmap_status(struct snd_pcm_substream
*substream
, struct file
*file
,
3065 struct vm_area_struct
*area
)
3069 static int snd_pcm_mmap_control(struct snd_pcm_substream
*substream
, struct file
*file
,
3070 struct vm_area_struct
*area
)
3074 #endif /* coherent mmap */
3076 static inline struct page
*
3077 snd_pcm_default_page_ops(struct snd_pcm_substream
*substream
, unsigned long ofs
)
3079 void *vaddr
= substream
->runtime
->dma_area
+ ofs
;
3080 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3081 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3082 return virt_to_page(CAC_ADDR(vaddr
));
3084 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3085 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
) {
3086 dma_addr_t addr
= substream
->runtime
->dma_addr
+ ofs
;
3087 addr
-= get_dma_offset(substream
->dma_buffer
.dev
.dev
);
3088 /* assume dma_handle set via pfn_to_phys() in
3089 * mm/dma-noncoherent.c
3091 return pfn_to_page(addr
>> PAGE_SHIFT
);
3094 return virt_to_page(vaddr
);
3098 * fault callback for mmapping a RAM page
3100 static int snd_pcm_mmap_data_fault(struct vm_area_struct
*area
,
3101 struct vm_fault
*vmf
)
3103 struct snd_pcm_substream
*substream
= area
->vm_private_data
;
3104 struct snd_pcm_runtime
*runtime
;
3105 unsigned long offset
;
3109 if (substream
== NULL
)
3110 return VM_FAULT_SIGBUS
;
3111 runtime
= substream
->runtime
;
3112 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
3113 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3114 if (offset
> dma_bytes
- PAGE_SIZE
)
3115 return VM_FAULT_SIGBUS
;
3116 if (substream
->ops
->page
)
3117 page
= substream
->ops
->page(substream
, offset
);
3119 page
= snd_pcm_default_page_ops(substream
, offset
);
3121 return VM_FAULT_SIGBUS
;
3127 static const struct vm_operations_struct snd_pcm_vm_ops_data
= {
3128 .open
= snd_pcm_mmap_data_open
,
3129 .close
= snd_pcm_mmap_data_close
,
3132 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault
= {
3133 .open
= snd_pcm_mmap_data_open
,
3134 .close
= snd_pcm_mmap_data_close
,
3135 .fault
= snd_pcm_mmap_data_fault
,
3138 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3139 /* This should be defined / handled globally! */
3141 #define ARCH_HAS_DMA_MMAP_COHERENT
3146 * mmap the DMA buffer on RAM
3148 static int snd_pcm_default_mmap(struct snd_pcm_substream
*substream
,
3149 struct vm_area_struct
*area
)
3151 area
->vm_flags
|= VM_RESERVED
;
3152 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3153 if (!substream
->ops
->page
&&
3154 substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
)
3155 return dma_mmap_coherent(substream
->dma_buffer
.dev
.dev
,
3157 substream
->runtime
->dma_area
,
3158 substream
->runtime
->dma_addr
,
3159 area
->vm_end
- area
->vm_start
);
3160 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3161 if (substream
->dma_buffer
.dev
.type
== SNDRV_DMA_TYPE_DEV
&&
3162 !plat_device_is_coherent(substream
->dma_buffer
.dev
.dev
))
3163 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3164 #endif /* ARCH_HAS_DMA_MMAP_COHERENT */
3165 /* mmap with fault handler */
3166 area
->vm_ops
= &snd_pcm_vm_ops_data_fault
;
3171 * mmap the DMA buffer on I/O memory area
3173 #if SNDRV_PCM_INFO_MMAP_IOMEM
3174 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream
*substream
,
3175 struct vm_area_struct
*area
)
3178 unsigned long offset
;
3180 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3181 area
->vm_flags
|= VM_IO
;
3182 size
= area
->vm_end
- area
->vm_start
;
3183 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3184 if (io_remap_pfn_range(area
, area
->vm_start
,
3185 (substream
->runtime
->dma_addr
+ offset
) >> PAGE_SHIFT
,
3186 size
, area
->vm_page_prot
))
3191 EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem
);
3192 #endif /* SNDRV_PCM_INFO_MMAP */
3194 /* mmap callback with pgprot_noncached */
3195 int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream
*substream
,
3196 struct vm_area_struct
*area
)
3198 area
->vm_page_prot
= pgprot_noncached(area
->vm_page_prot
);
3199 return snd_pcm_default_mmap(substream
, area
);
3201 EXPORT_SYMBOL(snd_pcm_lib_mmap_noncached
);
3206 int snd_pcm_mmap_data(struct snd_pcm_substream
*substream
, struct file
*file
,
3207 struct vm_area_struct
*area
)
3209 struct snd_pcm_runtime
*runtime
;
3211 unsigned long offset
;
3215 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
3216 if (!(area
->vm_flags
& (VM_WRITE
|VM_READ
)))
3219 if (!(area
->vm_flags
& VM_READ
))
3222 runtime
= substream
->runtime
;
3223 if (runtime
->status
->state
== SNDRV_PCM_STATE_OPEN
)
3225 if (!(runtime
->info
& SNDRV_PCM_INFO_MMAP
))
3227 if (runtime
->access
== SNDRV_PCM_ACCESS_RW_INTERLEAVED
||
3228 runtime
->access
== SNDRV_PCM_ACCESS_RW_NONINTERLEAVED
)
3230 size
= area
->vm_end
- area
->vm_start
;
3231 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3232 dma_bytes
= PAGE_ALIGN(runtime
->dma_bytes
);
3233 if ((size_t)size
> dma_bytes
)
3235 if (offset
> dma_bytes
- size
)
3238 area
->vm_ops
= &snd_pcm_vm_ops_data
;
3239 area
->vm_private_data
= substream
;
3240 if (substream
->ops
->mmap
)
3241 err
= substream
->ops
->mmap(substream
, area
);
3243 err
= snd_pcm_default_mmap(substream
, area
);
3245 atomic_inc(&substream
->mmap_count
);
3249 EXPORT_SYMBOL(snd_pcm_mmap_data
);
3251 static int snd_pcm_mmap(struct file
*file
, struct vm_area_struct
*area
)
3253 struct snd_pcm_file
* pcm_file
;
3254 struct snd_pcm_substream
*substream
;
3255 unsigned long offset
;
3257 pcm_file
= file
->private_data
;
3258 substream
= pcm_file
->substream
;
3259 if (PCM_RUNTIME_CHECK(substream
))
3262 offset
= area
->vm_pgoff
<< PAGE_SHIFT
;
3264 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3265 if (pcm_file
->no_compat_mmap
)
3267 return snd_pcm_mmap_status(substream
, file
, area
);
3268 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3269 if (pcm_file
->no_compat_mmap
)
3271 return snd_pcm_mmap_control(substream
, file
, area
);
3273 return snd_pcm_mmap_data(substream
, file
, area
);
3278 static int snd_pcm_fasync(int fd
, struct file
* file
, int on
)
3280 struct snd_pcm_file
* pcm_file
;
3281 struct snd_pcm_substream
*substream
;
3282 struct snd_pcm_runtime
*runtime
;
3284 pcm_file
= file
->private_data
;
3285 substream
= pcm_file
->substream
;
3286 if (PCM_RUNTIME_CHECK(substream
))
3288 runtime
= substream
->runtime
;
3289 return fasync_helper(fd
, file
, on
, &runtime
->fasync
);
3295 #ifdef CONFIG_COMPAT
3296 #include "pcm_compat.c"
3298 #define snd_pcm_ioctl_compat NULL
3302 * To be removed helpers to keep binary compatibility
3305 #ifdef CONFIG_SND_SUPPORT_OLD_API
3306 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3307 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3309 static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params
*params
,
3310 struct snd_pcm_hw_params_old
*oparams
)
3314 memset(params
, 0, sizeof(*params
));
3315 params
->flags
= oparams
->flags
;
3316 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3317 params
->masks
[i
].bits
[0] = oparams
->masks
[i
];
3318 memcpy(params
->intervals
, oparams
->intervals
, sizeof(oparams
->intervals
));
3319 params
->rmask
= __OLD_TO_NEW_MASK(oparams
->rmask
);
3320 params
->cmask
= __OLD_TO_NEW_MASK(oparams
->cmask
);
3321 params
->info
= oparams
->info
;
3322 params
->msbits
= oparams
->msbits
;
3323 params
->rate_num
= oparams
->rate_num
;
3324 params
->rate_den
= oparams
->rate_den
;
3325 params
->fifo_size
= oparams
->fifo_size
;
3328 static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old
*oparams
,
3329 struct snd_pcm_hw_params
*params
)
3333 memset(oparams
, 0, sizeof(*oparams
));
3334 oparams
->flags
= params
->flags
;
3335 for (i
= 0; i
< ARRAY_SIZE(oparams
->masks
); i
++)
3336 oparams
->masks
[i
] = params
->masks
[i
].bits
[0];
3337 memcpy(oparams
->intervals
, params
->intervals
, sizeof(oparams
->intervals
));
3338 oparams
->rmask
= __NEW_TO_OLD_MASK(params
->rmask
);
3339 oparams
->cmask
= __NEW_TO_OLD_MASK(params
->cmask
);
3340 oparams
->info
= params
->info
;
3341 oparams
->msbits
= params
->msbits
;
3342 oparams
->rate_num
= params
->rate_num
;
3343 oparams
->rate_den
= params
->rate_den
;
3344 oparams
->fifo_size
= params
->fifo_size
;
3347 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream
*substream
,
3348 struct snd_pcm_hw_params_old __user
* _oparams
)
3350 struct snd_pcm_hw_params
*params
;
3351 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3354 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3358 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3359 if (IS_ERR(oparams
)) {
3360 err
= PTR_ERR(oparams
);
3363 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3364 err
= snd_pcm_hw_refine(substream
, params
);
3365 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3366 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3377 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream
*substream
,
3378 struct snd_pcm_hw_params_old __user
* _oparams
)
3380 struct snd_pcm_hw_params
*params
;
3381 struct snd_pcm_hw_params_old
*oparams
= NULL
;
3384 params
= kmalloc(sizeof(*params
), GFP_KERNEL
);
3388 oparams
= memdup_user(_oparams
, sizeof(*oparams
));
3389 if (IS_ERR(oparams
)) {
3390 err
= PTR_ERR(oparams
);
3393 snd_pcm_hw_convert_from_old_params(params
, oparams
);
3394 err
= snd_pcm_hw_params(substream
, params
);
3395 snd_pcm_hw_convert_to_old_params(oparams
, params
);
3396 if (copy_to_user(_oparams
, oparams
, sizeof(*oparams
))) {
3406 #endif /* CONFIG_SND_SUPPORT_OLD_API */
3409 static unsigned long snd_pcm_get_unmapped_area(struct file
*file
,
3412 unsigned long pgoff
,
3413 unsigned long flags
)
3415 struct snd_pcm_file
*pcm_file
= file
->private_data
;
3416 struct snd_pcm_substream
*substream
= pcm_file
->substream
;
3417 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
3418 unsigned long offset
= pgoff
<< PAGE_SHIFT
;
3421 case SNDRV_PCM_MMAP_OFFSET_STATUS
:
3422 return (unsigned long)runtime
->status
;
3423 case SNDRV_PCM_MMAP_OFFSET_CONTROL
:
3424 return (unsigned long)runtime
->control
;
3426 return (unsigned long)runtime
->dma_area
+ offset
;
3430 # define snd_pcm_get_unmapped_area NULL
3437 const struct file_operations snd_pcm_f_ops
[2] = {
3439 .owner
= THIS_MODULE
,
3440 .write
= snd_pcm_write
,
3441 .aio_write
= snd_pcm_aio_write
,
3442 .open
= snd_pcm_playback_open
,
3443 .release
= snd_pcm_release
,
3444 .llseek
= no_llseek
,
3445 .poll
= snd_pcm_playback_poll
,
3446 .unlocked_ioctl
= snd_pcm_playback_ioctl
,
3447 .compat_ioctl
= snd_pcm_ioctl_compat
,
3448 .mmap
= snd_pcm_mmap
,
3449 .fasync
= snd_pcm_fasync
,
3450 .get_unmapped_area
= snd_pcm_get_unmapped_area
,
3453 .owner
= THIS_MODULE
,
3454 .read
= snd_pcm_read
,
3455 .aio_read
= snd_pcm_aio_read
,
3456 .open
= snd_pcm_capture_open
,
3457 .release
= snd_pcm_release
,
3458 .llseek
= no_llseek
,
3459 .poll
= snd_pcm_capture_poll
,
3460 .unlocked_ioctl
= snd_pcm_capture_ioctl
,
3461 .compat_ioctl
= snd_pcm_ioctl_compat
,
3462 .mmap
= snd_pcm_mmap
,
3463 .fasync
= snd_pcm_fasync
,
3464 .get_unmapped_area
= snd_pcm_get_unmapped_area
,