23 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/time.h>
28 #include <linux/uio.h>
38 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
39 #include <dma-coherence.h>
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)
71 static int snd_pcm_open(
struct file *
file,
struct snd_pcm *pcm,
int stream);
102 memset(info, 0,
sizeof(*info));
144 #define HW_PARAM(v) [SNDRV_PCM_HW_PARAM_##v] = #v
145 static const char *
const snd_pcm_hw_param_names[] = {
150 HW_PARAM(FRAME_BITS),
153 HW_PARAM(PERIOD_TIME),
155 HW_PARAM(PERIOD_BYTES),
157 HW_PARAM(BUFFER_TIME),
159 HW_PARAM(BUFFER_BYTES),
172 unsigned int rstamps[constrs->
rules_num];
174 unsigned int stamp = 2;
187 m = hw_param_mask(params, k);
188 if (snd_mask_empty(m))
190 if (!(params->
rmask & (1 << k)))
196 changed = snd_mask_refine(m, constrs_mask(constrs, k));
207 i = hw_param_interval(params, k);
208 if (snd_interval_empty(i))
210 if (!(params->
rmask & (1 << k)))
240 vstamps[k] = (params->
rmask & (1 << k)) ? 1 : 0;
243 for (k = 0; k < constrs->
rules_num; k++) {
249 for (d = 0; r->
deps[
d] >= 0; d++) {
250 if (vstamps[r->
deps[d]] > rstamps[k]) {
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);
265 i = hw_param_interval(params, r->
var);
275 changed = r->
func(params, r);
279 if (hw_is_mask(r->
var))
293 if (changed && r->
var >= 0) {
305 if (snd_interval_single(i))
306 params->
msbits = snd_interval_value(i);
311 if (snd_interval_single(i)) {
312 params->
rate_num = snd_interval_value(i);
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,
345 return PTR_ERR(params);
374 snd_pcm_stream_lock_irq(substream);
377 snd_pcm_stream_unlock_irq(substream);
391 snd_pcm_stream_lock_irq(substream);
392 switch (runtime->
status->state) {
398 snd_pcm_stream_unlock_irq(substream);
401 snd_pcm_stream_unlock_irq(substream);
402 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
403 if (!substream->oss.oss)
417 if (substream->
ops->hw_params !=
NULL) {
418 err = substream->
ops->hw_params(substream, params);
443 while (bits % 8 != 0) {
467 if ((usecs = period_to_usecs(runtime)) >= 0)
476 if (substream->
ops->hw_free !=
NULL)
477 substream->
ops->hw_free(substream);
489 return PTR_ERR(params);
509 snd_pcm_stream_lock_irq(substream);
510 switch (runtime->
status->state) {
515 snd_pcm_stream_unlock_irq(substream);
518 snd_pcm_stream_unlock_irq(substream);
521 if (substream->
ops->hw_free)
522 result = substream->
ops->hw_free(substream);
537 snd_pcm_stream_lock_irq(substream);
539 snd_pcm_stream_unlock_irq(substream);
542 snd_pcm_stream_unlock_irq(substream);
558 snd_pcm_stream_lock_irq(substream);
567 if (snd_pcm_running(substream)) {
573 snd_pcm_stream_unlock_irq(substream);
595 snd_pcm_stream_lock_irq(substream);
601 if (snd_pcm_running(substream)) {
608 snd_pcm_gettime(runtime, &status->
tstamp);
613 status->
avail = snd_pcm_playback_avail(runtime);
621 status->
avail = snd_pcm_capture_avail(runtime);
632 snd_pcm_stream_unlock_irq(substream);
659 snd_pcm_stream_lock_irq(substream);
661 snd_pcm_stream_unlock_irq(substream);
664 snd_pcm_stream_unlock_irq(substream);
667 memset(info, 0,
sizeof(*info));
716 int state,
int do_lock)
723 if (do_lock && s != substream)
763 static int snd_pcm_action_single(
struct action_ops *ops,
783 static int snd_pcm_action(
struct action_ops *ops,
789 if (snd_pcm_stream_linked(substream)) {
790 if (!spin_trylock(&substream->
group->lock)) {
792 spin_lock(&substream->
group->lock);
795 res = snd_pcm_action_group(ops, substream, state, 1);
796 spin_unlock(&substream->
group->lock);
798 res = snd_pcm_action_single(ops, substream, state);
806 static int snd_pcm_action_lock_irq(
struct action_ops *ops,
813 if (snd_pcm_stream_linked(substream)) {
814 spin_lock(&substream->
group->lock);
816 res = snd_pcm_action_group(ops, substream, state, 1);
818 spin_unlock(&substream->
group->lock);
821 res = snd_pcm_action_single(ops, substream, state);
830 static int snd_pcm_action_nonatomic(
struct action_ops *ops,
837 if (snd_pcm_stream_linked(substream))
838 res = snd_pcm_action_group(ops, substream, state, 0);
840 res = snd_pcm_action_single(ops, substream, state);
854 !snd_pcm_playback_data(substream))
862 if (substream->
runtime->trigger_master != substream)
869 if (substream->
runtime->trigger_master == substream)
876 snd_pcm_trigger_tstamp(substream);
880 runtime->
status->state = state;
884 if (substream->
timer)
889 static struct action_ops snd_pcm_action_start = {
890 .pre_action = snd_pcm_pre_start,
891 .do_action = snd_pcm_do_start,
892 .undo_action = snd_pcm_undo_start,
893 .post_action = snd_pcm_post_start
902 return snd_pcm_action(&snd_pcm_action_start, substream,
920 if (substream->
runtime->trigger_master == substream &&
921 snd_pcm_running(substream))
929 if (runtime->
status->state != state) {
930 snd_pcm_trigger_tstamp(substream);
931 if (substream->
timer)
940 static struct action_ops snd_pcm_action_stop = {
941 .pre_action = snd_pcm_pre_stop,
942 .do_action = snd_pcm_do_stop,
943 .post_action = snd_pcm_post_stop
955 return snd_pcm_action(&snd_pcm_action_stop, substream, state);
969 return snd_pcm_action_single(&snd_pcm_action_stop, substream,
992 if (substream->
runtime->trigger_master != substream)
1003 return substream->
ops->trigger(substream,
1010 if (substream->
runtime->trigger_master == substream)
1011 substream->
ops->trigger(substream,
1019 snd_pcm_trigger_tstamp(substream);
1022 if (substream->
timer)
1030 if (substream->
timer)
1037 static struct action_ops snd_pcm_action_pause = {
1038 .pre_action = snd_pcm_pre_pause,
1039 .do_action = snd_pcm_do_pause,
1040 .undo_action = snd_pcm_undo_pause,
1041 .post_action = snd_pcm_post_pause
1049 return snd_pcm_action(&snd_pcm_action_pause, substream, push);
1069 if (! snd_pcm_running(substream))
1075 static void snd_pcm_post_suspend(
struct snd_pcm_substream *substream,
int state)
1078 snd_pcm_trigger_tstamp(substream);
1079 if (substream->
timer)
1082 runtime->
status->suspended_state = runtime->
status->state;
1088 static struct action_ops snd_pcm_action_suspend = {
1090 .do_action = snd_pcm_do_suspend,
1091 .post_action = snd_pcm_post_suspend
1103 unsigned long flags;
1109 err = snd_pcm_action(&snd_pcm_action_suspend, substream, 0);
1122 int snd_pcm_suspend_all(
struct snd_pcm *pcm)
1130 for (stream = 0; stream < 2; stream++) {
1131 for (substream = pcm->
streams[stream].substream;
1132 substream; substream = substream->
next) {
1136 err = snd_pcm_suspend(substream);
1137 if (err < 0 && err != -
EBUSY)
1172 if (substream->
runtime->trigger_master == substream &&
1173 snd_pcm_running(substream))
1180 snd_pcm_trigger_tstamp(substream);
1181 if (substream->
timer)
1184 runtime->
status->state = runtime->
status->suspended_state;
1187 static struct action_ops snd_pcm_action_resume = {
1189 .do_action = snd_pcm_do_resume,
1190 .undo_action = snd_pcm_undo_resume,
1191 .post_action = snd_pcm_post_resume
1201 res = snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, 0);
1233 snd_pcm_stream_lock_irq(substream);
1234 switch (runtime->
status->state) {
1244 snd_pcm_stream_unlock_irq(substream);
1256 switch (runtime->
status->state) {
1290 static struct action_ops snd_pcm_action_reset = {
1291 .pre_action = snd_pcm_pre_reset,
1292 .do_action = snd_pcm_do_reset,
1293 .post_action = snd_pcm_post_reset
1298 return snd_pcm_action_nonatomic(&snd_pcm_action_reset, substream, 0);
1312 if (snd_pcm_running(substream))
1321 err = substream->
ops->prepare(substream);
1324 return snd_pcm_do_reset(substream, 0);
1327 static void snd_pcm_post_prepare(
struct snd_pcm_substream *substream,
int state)
1334 static struct action_ops snd_pcm_action_prepare = {
1335 .pre_action = snd_pcm_pre_prepare,
1336 .do_action = snd_pcm_do_prepare,
1337 .post_action = snd_pcm_post_prepare
1359 res = snd_pcm_action_nonatomic(&snd_pcm_action_prepare,
1360 substream, f_flags);
1369 static int snd_pcm_pre_drain_init(
struct snd_pcm_substream *substream,
int state)
1372 switch (runtime->
status->state) {
1382 static int snd_pcm_do_drain_init(
struct snd_pcm_substream *substream,
int state)
1386 switch (runtime->
status->state) {
1389 if (! snd_pcm_playback_empty(substream)) {
1406 int new_state = snd_pcm_capture_avail(runtime) > 0 ?
1408 snd_pcm_do_stop(substream, new_state);
1409 snd_pcm_post_stop(substream, new_state);
1415 static void snd_pcm_post_drain_init(
struct snd_pcm_substream *substream,
int state)
1419 static struct action_ops snd_pcm_action_drain_init = {
1420 .pre_action = snd_pcm_pre_drain_init,
1421 .do_action = snd_pcm_do_drain_init,
1422 .post_action = snd_pcm_post_drain_init
1444 card = substream->
pcm->card;
1466 snd_pcm_stream_lock_irq(substream);
1469 snd_pcm_pause(substream, 0);
1472 result = snd_pcm_action(&snd_pcm_action_drain_init, substream, 0);
1484 if (signal_pending(
current)) {
1501 init_waitqueue_entry(&wait,
current);
1503 snd_pcm_stream_unlock_irq(substream);
1510 if (runtime->
rate) {
1512 tout =
max(t, tout);
1519 snd_pcm_stream_lock_irq(substream);
1529 snd_printd(
"playback drain error (DMA or IRQ trouble?)\n");
1538 snd_pcm_stream_unlock_irq(substream);
1564 snd_pcm_stream_lock_irq(substream);
1567 snd_pcm_pause(substream, 0);
1571 snd_pcm_stream_unlock_irq(substream);
1578 static struct file *snd_pcm_file_fd(
int fd,
int *fput_needed)
1587 inode = file->
f_path.dentry->d_inode;
1590 fput_light(file, *fput_needed);
1593 minor = iminor(inode);
1596 fput_light(file, *fput_needed);
1614 file = snd_pcm_file_fd(fd, &fput_needed);
1627 substream->
runtime->status->state != substream1->
runtime->status->state) {
1631 if (snd_pcm_stream_linked(substream1)) {
1635 if (!snd_pcm_stream_linked(substream)) {
1638 INIT_LIST_HEAD(&substream->
group->substreams);
1640 substream->
group->count = 1;
1643 substream->
group->count++;
1650 fput_light(file, fput_needed);
1659 INIT_LIST_HEAD(&substream->
self_group.substreams);
1670 if (!snd_pcm_stream_linked(substream)) {
1675 substream->
group->count--;
1676 if (substream->
group->count == 1) {
1683 relink_to_local(substream);
1698 hw_param_interval_c(params, rule->
deps[1]), &
t);
1707 hw_param_interval_c(params, rule->
deps[1]), &
t);
1716 hw_param_interval_c(params, rule->
deps[1]),
1717 (
unsigned long) rule->
private, &
t);
1726 (
unsigned long) rule->
private,
1727 hw_param_interval_c(params, rule->
deps[1]), &
t);
1741 if (! snd_mask_test(mask, k))
1746 if ((
unsigned)bits < i->
min || (
unsigned)bits > i->
max)
1747 snd_mask_reset(&
m, k);
1749 return snd_mask_refine(mask, &
m);
1768 if (
t.min > (
unsigned)bits)
1770 if (
t.max < (
unsigned)bits)
1777 #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
1778 #error "Change this table"
1781 static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
1782 48000, 64000, 88200, 96000, 176400, 192000 };
1794 snd_pcm_known_rates.
count,
1818 snd_mask_any(constrs_mask(constrs, k));
1822 snd_interval_any(constrs_interval(constrs, k));
1832 snd_pcm_hw_rule_format,
NULL,
1837 snd_pcm_hw_rule_sample_bits,
NULL,
1843 snd_pcm_hw_rule_div,
NULL,
1848 snd_pcm_hw_rule_mul,
NULL,
1853 snd_pcm_hw_rule_mulkdiv, (
void*) 8,
1858 snd_pcm_hw_rule_mulkdiv, (
void*) 8,
1863 snd_pcm_hw_rule_div,
NULL,
1868 snd_pcm_hw_rule_mulkdiv, (
void*) 1000000,
1873 snd_pcm_hw_rule_mulkdiv, (
void*) 1000000,
1878 snd_pcm_hw_rule_div,
NULL,
1883 snd_pcm_hw_rule_div,
NULL,
1888 snd_pcm_hw_rule_mulkdiv, (
void*) 8,
1893 snd_pcm_hw_rule_muldivk, (
void*) 1000000,
1898 snd_pcm_hw_rule_mul,
NULL,
1903 snd_pcm_hw_rule_mulkdiv, (
void*) 8,
1908 snd_pcm_hw_rule_muldivk, (
void*) 1000000,
1913 snd_pcm_hw_rule_muldivk, (
void*) 8,
1918 snd_pcm_hw_rule_muldivk, (
void*) 8,
1923 snd_pcm_hw_rule_mulkdiv, (
void*) 1000000,
1928 snd_pcm_hw_rule_mulkdiv, (
void*) 1000000,
1940 unsigned int mask = 0;
1992 snd_pcm_hw_rule_buffer_bytes_max, substream,
2006 snd_pcm_hw_rule_rate, hw,
2020 snd_pcm_unlink(substream);
2029 snd_pcm_drop(substream);
2031 if (substream->
ops->hw_free !=
NULL)
2032 substream->
ops->hw_free(substream);
2033 substream->
ops->close(substream);
2058 *rsubstream = substream;
2064 snd_printd(
"snd_pcm_hw_constraints_init failed\n");
2068 if ((err = substream->
ops->open(substream)) < 0)
2075 snd_printd(
"snd_pcm_hw_constraints_complete failed\n");
2079 *rsubstream = substream;
2089 static int snd_pcm_open_file(
struct file *file,
2101 pcm_file = kzalloc(
sizeof(*pcm_file),
GFP_KERNEL);
2102 if (pcm_file ==
NULL) {
2108 substream->
file = pcm_file;
2116 static int snd_pcm_playback_open(
struct inode *inode,
struct file *file)
2130 static int snd_pcm_capture_open(
struct inode *inode,
struct file *file)
2144 static int snd_pcm_open(
struct file *file,
struct snd_pcm *pcm,
int stream)
2156 if (!try_module_get(pcm->
card->module)) {
2160 init_waitqueue_entry(&wait,
current);
2164 err = snd_pcm_open_file(file, pcm, stream);
2178 if (pcm->
card->shutdown) {
2182 if (signal_pending(
current)) {
2194 module_put(pcm->
card->module);
2201 static int snd_pcm_release(
struct inode *inode,
struct file *file)
2211 pcm = substream->
pcm;
2217 module_put(pcm->
card->module);
2233 snd_pcm_stream_lock_irq(substream);
2234 switch (runtime->
status->state) {
2253 hw_avail = snd_pcm_playback_hw_avail(runtime);
2254 if (hw_avail <= 0) {
2260 appl_ptr = runtime->
control->appl_ptr - frames;
2266 snd_pcm_stream_unlock_irq(substream);
2281 snd_pcm_stream_lock_irq(substream);
2282 switch (runtime->
status->state) {
2301 hw_avail = snd_pcm_capture_hw_avail(runtime);
2302 if (hw_avail <= 0) {
2308 appl_ptr = runtime->
control->appl_ptr - frames;
2314 snd_pcm_stream_unlock_irq(substream);
2329 snd_pcm_stream_lock_irq(substream);
2330 switch (runtime->
status->state) {
2350 avail = snd_pcm_playback_avail(runtime);
2357 appl_ptr = runtime->
control->appl_ptr + frames;
2363 snd_pcm_stream_unlock_irq(substream);
2378 snd_pcm_stream_lock_irq(substream);
2379 switch (runtime->
status->state) {
2399 avail = snd_pcm_capture_avail(runtime);
2406 appl_ptr = runtime->
control->appl_ptr + frames;
2412 snd_pcm_stream_unlock_irq(substream);
2421 snd_pcm_stream_lock_irq(substream);
2422 switch (runtime->
status->state) {
2442 snd_pcm_stream_unlock_irq(substream);
2453 snd_pcm_stream_lock_irq(substream);
2454 switch (runtime->
status->state) {
2466 n = snd_pcm_playback_hw_avail(runtime);
2468 n = snd_pcm_capture_avail(runtime);
2469 n += runtime->
delay;
2479 snd_pcm_stream_unlock_irq(substream);
2495 memset(&sync_ptr, 0,
sizeof(sync_ptr));
2496 if (
get_user(sync_ptr.flags, (
unsigned __user *)&(_sync_ptr->flags)))
2500 status = runtime->
status;
2503 err = snd_pcm_hwsync(substream);
2507 snd_pcm_stream_lock_irq(substream);
2509 control->
appl_ptr = sync_ptr.c.control.appl_ptr;
2511 sync_ptr.c.control.appl_ptr = control->
appl_ptr;
2513 control->
avail_min = sync_ptr.c.control.avail_min;
2515 sync_ptr.c.control.avail_min = control->
avail_min;
2516 sync_ptr.s.status.state = status->
state;
2517 sync_ptr.s.status.hw_ptr = status->
hw_ptr;
2518 sync_ptr.s.status.tstamp = status->
tstamp;
2520 snd_pcm_stream_unlock_irq(substream);
2521 if (
copy_to_user(_sync_ptr, &sync_ptr,
sizeof(sync_ptr)))
2526 static int snd_pcm_tstamp(
struct snd_pcm_substream *substream,
int __user *_arg)
2541 static int snd_pcm_common_ioctl1(
struct file *file,
2543 unsigned int cmd,
void __user *arg)
2553 return snd_pcm_tstamp(substream, arg);
2555 return snd_pcm_hw_refine_user(substream, arg);
2557 return snd_pcm_hw_params_user(substream, arg);
2559 return snd_pcm_hw_free(substream);
2561 return snd_pcm_sw_params_user(substream, arg);
2563 return snd_pcm_status_user(substream, arg);
2565 return snd_pcm_channel_info_user(substream, arg);
2567 return snd_pcm_prepare(substream, file);
2569 return snd_pcm_reset(substream);
2573 return snd_pcm_link(substream, (
int)(
unsigned long) arg);
2575 return snd_pcm_unlink(substream);
2577 return snd_pcm_resume(substream);
2579 return snd_pcm_xrun(substream);
2581 return snd_pcm_hwsync(substream);
2583 return snd_pcm_delay(substream, arg);
2586 #ifdef CONFIG_SND_SUPPORT_OLD_API
2587 case SNDRV_PCM_IOCTL_HW_REFINE_OLD:
2588 return snd_pcm_hw_refine_old_user(substream, arg);
2589 case SNDRV_PCM_IOCTL_HW_PARAMS_OLD:
2590 return snd_pcm_hw_params_old_user(substream, arg);
2593 return snd_pcm_drain(substream, file);
2595 return snd_pcm_drop(substream);
2599 snd_pcm_stream_lock_irq(substream);
2600 res = snd_pcm_pause(substream, (
int)(
unsigned long)arg);
2601 snd_pcm_stream_unlock_irq(substream);
2609 static int snd_pcm_playback_ioctl1(
struct file *file,
2611 unsigned int cmd,
void __user *arg)
2632 return result < 0 ? result : 0;
2651 sizeof(
void *) * runtime->
channels);
2653 return PTR_ERR(bufs);
2657 return result < 0 ? result : 0;
2668 result = snd_pcm_playback_rewind(substream, frames);
2670 return result < 0 ? result : 0;
2681 result = snd_pcm_playback_forward(substream, frames);
2683 return result < 0 ? result : 0;
2686 return snd_pcm_common_ioctl1(file, substream, cmd, arg);
2689 static int snd_pcm_capture_ioctl1(
struct file *file,
2691 unsigned int cmd,
void __user *arg)
2712 return result < 0 ? result : 0;
2731 sizeof(
void *) * runtime->
channels);
2733 return PTR_ERR(bufs);
2737 return result < 0 ? result : 0;
2748 result = snd_pcm_capture_rewind(substream, frames);
2750 return result < 0 ? result : 0;
2761 result = snd_pcm_capture_forward(substream, frames);
2763 return result < 0 ? result : 0;
2766 return snd_pcm_common_ioctl1(file, substream, cmd, arg);
2769 static long snd_pcm_playback_ioctl(
struct file *file,
unsigned int cmd,
2776 if (((cmd >> 8) & 0xff) !=
'A')
2779 return snd_pcm_playback_ioctl1(file, pcm_file->
substream, cmd,
2780 (
void __user *)arg);
2783 static long snd_pcm_capture_ioctl(
struct file *file,
unsigned int cmd,
2790 if (((cmd >> 8) & 0xff) !=
'A')
2793 return snd_pcm_capture_ioctl1(file, pcm_file->
substream, cmd,
2794 (
void __user *)arg);
2798 unsigned int cmd,
void *arg)
2803 fs = snd_enter_user();
2804 switch (substream->
stream) {
2806 result = snd_pcm_playback_ioctl1(
NULL, substream, cmd,
2810 result = snd_pcm_capture_ioctl1(
NULL, substream, cmd,
2823 static ssize_t snd_pcm_read(
struct file *file,
char __user *
buf,
size_t count,
2838 if (!frame_aligned(runtime, count))
2840 count = bytes_to_frames(runtime, count);
2843 result = frames_to_bytes(runtime, result);
2847 static ssize_t snd_pcm_write(
struct file *file,
const char __user *buf,
2848 size_t count, loff_t * offset)
2862 if (!frame_aligned(runtime, count))
2864 count = bytes_to_frames(runtime, count);
2867 result = frames_to_bytes(runtime, result);
2872 unsigned long nr_segs, loff_t
pos)
2883 pcm_file = iocb->
ki_filp->private_data;
2890 if (nr_segs > 1024 || nr_segs != runtime->
channels)
2892 if (!frame_aligned(runtime, iov->
iov_len))
2894 frames = bytes_to_samples(runtime, iov->
iov_len);
2898 for (i = 0; i < nr_segs; ++
i)
2899 bufs[i] = iov[i].iov_base;
2902 result = frames_to_bytes(runtime, result);
2908 unsigned long nr_segs, loff_t pos)
2918 pcm_file = iocb->
ki_filp->private_data;
2925 if (nr_segs > 128 || nr_segs != runtime->
channels ||
2926 !frame_aligned(runtime, iov->
iov_len))
2928 frames = bytes_to_samples(runtime, iov->
iov_len);
2932 for (i = 0; i < nr_segs; ++
i)
2933 bufs[i] = iov[i].iov_base;
2936 result = frames_to_bytes(runtime, result);
2941 static unsigned int snd_pcm_playback_poll(
struct file *file,
poll_table * wait)
2956 poll_wait(file, &runtime->
sleep, wait);
2958 snd_pcm_stream_lock_irq(substream);
2959 avail = snd_pcm_playback_avail(runtime);
2960 switch (runtime->
status->state) {
2964 if (avail >= runtime->
control->avail_min) {
2976 snd_pcm_stream_unlock_irq(substream);
2980 static unsigned int snd_pcm_capture_poll(
struct file *file,
poll_table * wait)
2995 poll_wait(file, &runtime->
sleep, wait);
2997 snd_pcm_stream_lock_irq(substream);
2998 avail = snd_pcm_capture_avail(runtime);
2999 switch (runtime->
status->state) {
3003 if (avail >= runtime->
control->avail_min) {
3019 snd_pcm_stream_unlock_irq(substream);
3031 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
3035 static int snd_pcm_mmap_status_fault(
struct vm_area_struct *area,
3036 struct vm_fault *vmf)
3041 if (substream ==
NULL)
3042 return VM_FAULT_SIGBUS;
3045 get_page(vmf->page);
3049 static const struct vm_operations_struct snd_pcm_vm_ops_status =
3051 .fault = snd_pcm_mmap_status_fault,
3063 area->
vm_ops = &snd_pcm_vm_ops_status;
3065 area->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3072 static int snd_pcm_mmap_control_fault(
struct vm_area_struct *area,
3073 struct vm_fault *vmf)
3078 if (substream ==
NULL)
3079 return VM_FAULT_SIGBUS;
3082 get_page(vmf->page);
3086 static const struct vm_operations_struct snd_pcm_vm_ops_control =
3088 .fault = snd_pcm_mmap_control_fault,
3100 area->
vm_ops = &snd_pcm_vm_ops_control;
3102 area->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3121 static inline struct page *
3122 snd_pcm_default_page_ops(
struct snd_pcm_substream *substream,
unsigned long ofs)
3125 #if defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3129 #if defined(CONFIG_PPC32) && defined(CONFIG_NOT_COHERENT_CACHE)
3132 addr -= get_dma_offset(substream->
dma_buffer.dev.dev);
3146 struct vm_fault *vmf)
3154 if (substream ==
NULL)
3155 return VM_FAULT_SIGBUS;
3160 return VM_FAULT_SIGBUS;
3161 if (substream->
ops->page)
3162 page = substream->
ops->page(substream, offset);
3164 page = snd_pcm_default_page_ops(substream, offset);
3166 return VM_FAULT_SIGBUS;
3172 static const struct vm_operations_struct snd_pcm_vm_ops_data = {
3173 .open = snd_pcm_mmap_data_open,
3174 .close = snd_pcm_mmap_data_close,
3177 static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = {
3178 .open = snd_pcm_mmap_data_open,
3179 .close = snd_pcm_mmap_data_close,
3180 .fault = snd_pcm_mmap_data_fault,
3183 #ifndef ARCH_HAS_DMA_MMAP_COHERENT
3186 #define ARCH_HAS_DMA_MMAP_COHERENT
3196 area->
vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3197 #ifdef ARCH_HAS_DMA_MMAP_COHERENT
3198 if (!substream->
ops->page &&
3205 #elif defined(CONFIG_MIPS) && defined(CONFIG_DMA_NONCOHERENT)
3207 !plat_device_is_coherent(substream->
dma_buffer.dev.dev))
3211 area->
vm_ops = &snd_pcm_vm_ops_data_fault;
3219 #if SNDRV_PCM_INFO_MMAP_IOMEM
3253 if (!(area->
vm_flags & (VM_WRITE|VM_READ)))
3270 if ((
size_t)size > dma_bytes)
3272 if (offset > dma_bytes - size)
3275 area->
vm_ops = &snd_pcm_vm_ops_data;
3277 if (substream->
ops->mmap)
3278 err = substream->
ops->mmap(substream, area);
3288 static int snd_pcm_mmap(
struct file *file,
struct vm_area_struct *area)
3315 static int snd_pcm_fasync(
int fd,
struct file * file,
int on)
3332 #ifdef CONFIG_COMPAT
3335 #define snd_pcm_ioctl_compat NULL
3342 #ifdef CONFIG_SND_SUPPORT_OLD_API
3343 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
3344 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
3346 static void snd_pcm_hw_convert_from_old_params(
struct snd_pcm_hw_params *params,
3351 memset(params, 0,
sizeof(*params));
3354 params->
masks[i].bits[0] = oparams->
masks[i];
3356 params->
rmask = __OLD_TO_NEW_MASK(oparams->
rmask);
3357 params->
cmask = __OLD_TO_NEW_MASK(oparams->
cmask);
3370 memset(oparams, 0,
sizeof(*oparams));
3373 oparams->
masks[i] = params->
masks[i].bits[0];
3375 oparams->
rmask = __NEW_TO_OLD_MASK(params->
rmask);
3376 oparams->
cmask = __NEW_TO_OLD_MASK(params->
cmask);
3395 oparams =
memdup_user(_oparams,
sizeof(*oparams));
3396 if (IS_ERR(oparams)) {
3397 err = PTR_ERR(oparams);
3400 snd_pcm_hw_convert_from_old_params(params, oparams);
3402 snd_pcm_hw_convert_to_old_params(oparams, params);
3403 if (
copy_to_user(_oparams, oparams,
sizeof(*oparams))) {
3425 oparams =
memdup_user(_oparams,
sizeof(*oparams));
3426 if (IS_ERR(oparams)) {
3427 err = PTR_ERR(oparams);
3430 snd_pcm_hw_convert_from_old_params(params, oparams);
3432 snd_pcm_hw_convert_to_old_params(oparams, params);
3433 if (
copy_to_user(_oparams, oparams,
sizeof(*oparams))) {
3446 static unsigned long snd_pcm_get_unmapped_area(
struct file *file,
3449 unsigned long pgoff,
3450 unsigned long flags)
3459 return (
unsigned long)runtime->
status;
3461 return (
unsigned long)runtime->
control;
3467 # define snd_pcm_get_unmapped_area NULL
3477 .write = snd_pcm_write,
3478 .aio_write = snd_pcm_aio_write,
3479 .open = snd_pcm_playback_open,
3480 .release = snd_pcm_release,
3482 .poll = snd_pcm_playback_poll,
3483 .unlocked_ioctl = snd_pcm_playback_ioctl,
3485 .mmap = snd_pcm_mmap,
3486 .fasync = snd_pcm_fasync,
3487 .get_unmapped_area = snd_pcm_get_unmapped_area,
3491 .read = snd_pcm_read,
3492 .aio_read = snd_pcm_aio_read,
3493 .open = snd_pcm_capture_open,
3494 .release = snd_pcm_release,
3496 .poll = snd_pcm_capture_poll,
3497 .unlocked_ioctl = snd_pcm_capture_ioctl,
3499 .mmap = snd_pcm_mmap,
3500 .fasync = snd_pcm_fasync,
3501 .get_unmapped_area = snd_pcm_get_unmapped_area,