Lines Matching refs:substream

36 #define trace_hw_mask_param(substream, type, index, prev, curr)
37 #define trace_hw_interval_param(substream, type, index, prev, curr)
64 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
66 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
102 * @substream: PCM substream
105 * flag of the given substream. This also takes the global link rw lock
108 void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
110 snd_pcm_group_lock(&substream->self_group, substream->pcm->nonatomic);
116 * @substream: PCM substream
120 void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
122 snd_pcm_group_unlock(&substream->self_group, substream->pcm->nonatomic);
128 * @substream: PCM substream
134 void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
136 snd_pcm_group_lock_irq(&substream->self_group,
137 substream->pcm->nonatomic);
141 static void snd_pcm_stream_lock_nested(struct snd_pcm_substream *substream)
143 struct snd_pcm_group *group = &substream->self_group;
145 if (substream->pcm->nonatomic)
153 * @substream: PCM substream
157 void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
159 snd_pcm_group_unlock_irq(&substream->self_group,
160 substream->pcm->nonatomic);
164 unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream)
167 if (substream->pcm->nonatomic)
168 mutex_lock(&substream->self_group.mutex);
170 spin_lock_irqsave(&substream->self_group.lock, flags);
175 unsigned long _snd_pcm_stream_lock_irqsave_nested(struct snd_pcm_substream *substream)
178 if (substream->pcm->nonatomic)
179 mutex_lock_nested(&substream->self_group.mutex,
182 spin_lock_irqsave_nested(&substream->self_group.lock, flags,
190 * @substream: PCM substream
195 void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
198 if (substream->pcm->nonatomic)
199 mutex_unlock(&substream->self_group.mutex);
201 spin_unlock_irqrestore(&substream->self_group.lock, flags);
206 static int snd_pcm_ops_ioctl(struct snd_pcm_substream *substream,
209 if (substream->ops->ioctl)
210 return substream->ops->ioctl(substream, cmd, arg);
212 return snd_pcm_lib_ioctl(substream, cmd, arg);
215 int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info)
217 struct snd_pcm *pcm = substream->pcm;
218 struct snd_pcm_str *pstr = substream->pstr;
223 info->stream = substream->stream;
224 info->subdevice = substream->number;
231 strscpy(info->subname, substream->name, sizeof(info->subname));
236 int snd_pcm_info_user(struct snd_pcm_substream *substream,
245 err = snd_pcm_info(substream, info);
256 static bool hw_support_mmap(struct snd_pcm_substream *substream)
260 if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP))
263 if (substream->ops->mmap || substream->ops->page)
266 dmabuf = snd_pcm_get_dma_buf(substream);
268 dmabuf = &substream->dma_buffer;
283 static int constrain_mask_params(struct snd_pcm_substream *substream,
287 &substream->runtime->hw_constraints;
312 trace_hw_mask_param(substream, k, 0, &old_mask, m);
319 static int constrain_interval_params(struct snd_pcm_substream *substream,
323 &substream->runtime->hw_constraints;
348 trace_hw_interval_param(substream, k, 0, &old_interval, i);
355 static int constrain_params_by_rules(struct snd_pcm_substream *substream,
359 &substream->runtime->hw_constraints;
447 trace_hw_mask_param(substream, r->var,
452 trace_hw_interval_param(substream, r->var,
472 static int fixup_unreferenced_params(struct snd_pcm_substream *substream,
519 err = snd_pcm_ops_ioctl(substream,
528 params->info = substream->runtime->hw.info;
531 if (!hw_support_mmap(substream))
539 int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
553 err = constrain_mask_params(substream, params);
557 err = constrain_interval_params(substream, params);
561 err = constrain_params_by_rules(substream, params);
571 static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream,
581 err = snd_pcm_hw_refine(substream, params);
585 err = fixup_unreferenced_params(substream, params);
609 static void snd_pcm_set_state(struct snd_pcm_substream *substream,
612 guard(pcm_stream_lock_irq)(substream);
613 if (substream->runtime->state != SNDRV_PCM_STATE_DISCONNECTED)
614 __snd_pcm_set_state(substream->runtime, state);
617 static inline void snd_pcm_timer_notify(struct snd_pcm_substream *substream,
621 if (substream->timer)
622 snd_timer_notify(substream->timer, event,
623 &substream->runtime->trigger_tstamp);
627 void snd_pcm_sync_stop(struct snd_pcm_substream *substream, bool sync_irq)
629 if (substream->runtime && substream->runtime->stop_operating) {
630 substream->runtime->stop_operating = false;
631 if (substream->ops && substream->ops->sync_stop)
632 substream->ops->sync_stop(substream);
633 else if (sync_irq && substream->pcm->card->sync_irq > 0)
634 synchronize_irq(substream->pcm->card->sync_irq);
721 #define is_oss_stream(substream) ((substream)->oss.oss)
723 #define is_oss_stream(substream) false
726 static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
734 if (PCM_RUNTIME_CHECK(substream))
736 runtime = substream->runtime;
740 scoped_guard(pcm_stream_lock_irq, substream) {
745 if (!is_oss_stream(substream) &&
746 atomic_read(&substream->mmap_count))
757 snd_pcm_sync_stop(substream, true);
760 err = snd_pcm_hw_refine(substream, params);
764 err = snd_pcm_hw_params_choose(substream, params);
768 err = fixup_unreferenced_params(substream, params);
772 if (substream->managed_buffer_alloc) {
773 err = snd_pcm_lib_malloc_pages(substream,
780 if (substream->ops->hw_params != NULL) {
781 err = substream->ops->hw_params(substream, params);
826 if (runtime->dma_area && !substream->ops->copy) {
834 snd_pcm_timer_resolution_change(substream);
835 snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP);
837 if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req))
838 cpu_latency_qos_remove_request(&substream->latency_pm_qos_req);
841 cpu_latency_qos_add_request(&substream->latency_pm_qos_req,
850 snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN);
851 if (substream->ops->hw_free != NULL)
852 substream->ops->hw_free(substream);
853 if (substream->managed_buffer_alloc)
854 snd_pcm_lib_free_pages(substream);
861 static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream,
871 err = snd_pcm_hw_params(substream, params);
880 static int do_hw_free(struct snd_pcm_substream *substream)
884 snd_pcm_sync_stop(substream, true);
885 if (substream->ops->hw_free)
886 result = substream->ops->hw_free(substream);
887 if (substream->managed_buffer_alloc)
888 snd_pcm_lib_free_pages(substream);
892 static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
897 if (PCM_RUNTIME_CHECK(substream))
899 runtime = substream->runtime;
903 scoped_guard(pcm_stream_lock_irq, substream) {
907 if (atomic_read(&substream->mmap_count))
917 result = do_hw_free(substream);
918 snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN);
919 cpu_latency_qos_remove_request(&substream->latency_pm_qos_req);
925 static int snd_pcm_sw_params(struct snd_pcm_substream *substream,
931 if (PCM_RUNTIME_CHECK(substream))
933 runtime = substream->runtime;
934 scoped_guard(pcm_stream_lock_irq, substream) {
957 scoped_guard(pcm_stream_lock_irq, substream) {
968 if (snd_pcm_running(substream)) {
969 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
971 snd_pcm_playback_silence(substream, ULONG_MAX);
972 err = snd_pcm_update_state(substream, runtime);
978 static int snd_pcm_sw_params_user(struct snd_pcm_substream *substream,
985 err = snd_pcm_sw_params(substream, &params);
992 snd_pcm_calc_delay(struct snd_pcm_substream *substream)
996 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
997 delay = snd_pcm_playback_hw_avail(substream->runtime);
999 delay = snd_pcm_capture_avail(substream->runtime);
1000 return delay + substream->runtime->delay;
1003 int snd_pcm_status64(struct snd_pcm_substream *substream,
1006 struct snd_pcm_runtime *runtime = substream->runtime;
1008 guard(pcm_stream_lock_irq)(substream);
1032 if (snd_pcm_running(substream)) {
1033 snd_pcm_update_hw_ptr(substream);
1067 status->avail = snd_pcm_avail(substream);
1068 status->delay = snd_pcm_running(substream) ?
1069 snd_pcm_calc_delay(substream) : 0;
1077 static int snd_pcm_status_user64(struct snd_pcm_substream *substream,
1093 res = snd_pcm_status64(substream, &status);
1101 static int snd_pcm_status_user32(struct snd_pcm_substream *substream,
1119 res = snd_pcm_status64(substream, &status64);
1150 static int snd_pcm_channel_info(struct snd_pcm_substream *substream,
1157 runtime = substream->runtime;
1158 scoped_guard(pcm_stream_lock_irq, substream) {
1166 return snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_CHANNEL_INFO, info);
1169 static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream,
1177 res = snd_pcm_channel_info(substream, &info);
1185 static void snd_pcm_trigger_tstamp(struct snd_pcm_substream *substream)
1187 struct snd_pcm_runtime *runtime = substream->runtime;
1190 if (runtime->trigger_master == substream) {
1203 int (*pre_action)(struct snd_pcm_substream *substream,
1205 int (*do_action)(struct snd_pcm_substream *substream,
1207 void (*undo_action)(struct snd_pcm_substream *substream,
1209 void (*post_action)(struct snd_pcm_substream *substream,
1219 struct snd_pcm_substream *substream,
1227 snd_pcm_group_for_each_entry(s, substream) {
1228 if (s != substream) {
1241 snd_pcm_group_for_each_entry(s, substream) {
1245 snd_pcm_group_for_each_entry(s1, substream) {
1255 snd_pcm_group_for_each_entry(s, substream) {
1260 snd_pcm_group_for_each_entry(s1, substream) {
1261 if (s1 != substream) {
1279 struct snd_pcm_substream *substream,
1284 res = ops->pre_action(substream, state);
1287 res = ops->do_action(substream, state);
1289 ops->post_action(substream, state);
1291 ops->undo_action(substream, state);
1295 static void snd_pcm_group_assign(struct snd_pcm_substream *substream,
1298 substream->group = new_group;
1299 list_move(&substream->link_list, &new_group->substreams);
1307 struct snd_pcm_substream *substream)
1314 snd_pcm_group_unlock(group, substream->pcm->nonatomic);
1324 snd_pcm_stream_group_ref(struct snd_pcm_substream *substream)
1326 bool nonatomic = substream->pcm->nonatomic;
1331 if (!snd_pcm_stream_linked(substream))
1333 group = substream->group;
1343 snd_pcm_stream_unlock(substream);
1345 snd_pcm_stream_lock(substream);
1348 if (substream->group == group)
1351 snd_pcm_group_unref(group, substream);
1360 struct snd_pcm_substream *substream,
1366 group = snd_pcm_stream_group_ref(substream);
1368 res = snd_pcm_action_group(ops, substream, state, true);
1370 res = snd_pcm_action_single(ops, substream, state);
1371 snd_pcm_group_unref(group, substream);
1379 struct snd_pcm_substream *substream,
1382 guard(pcm_stream_lock_irq)(substream);
1383 return snd_pcm_action(ops, substream, state);
1389 struct snd_pcm_substream *substream,
1396 res = snd_pcm_buffer_access_lock(substream->runtime);
1399 if (snd_pcm_stream_linked(substream))
1400 res = snd_pcm_action_group(ops, substream, state, false);
1402 res = snd_pcm_action_single(ops, substream, state);
1403 snd_pcm_buffer_access_unlock(substream->runtime);
1410 static int snd_pcm_pre_start(struct snd_pcm_substream *substream,
1413 struct snd_pcm_runtime *runtime = substream->runtime;
1416 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
1417 !snd_pcm_playback_data(substream))
1420 runtime->trigger_master = substream;
1424 static int snd_pcm_do_start(struct snd_pcm_substream *substream,
1429 if (substream->runtime->trigger_master != substream)
1431 err = substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START);
1434 __snd_pcm_set_state(substream->runtime, SNDRV_PCM_STATE_XRUN);
1438 static void snd_pcm_undo_start(struct snd_pcm_substream *substream,
1441 if (substream->runtime->trigger_master == substream) {
1442 substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP);
1443 substream->runtime->stop_operating = true;
1447 static void snd_pcm_post_start(struct snd_pcm_substream *substream,
1450 struct snd_pcm_runtime *runtime = substream->runtime;
1451 snd_pcm_trigger_tstamp(substream);
1456 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
1458 snd_pcm_playback_silence(substream, ULONG_MAX);
1459 snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTART);
1471 * @substream: the PCM substream instance
1476 int snd_pcm_start(struct snd_pcm_substream *substream)
1478 return snd_pcm_action(&snd_pcm_action_start, substream,
1483 static int snd_pcm_start_lock_irq(struct snd_pcm_substream *substream)
1485 return snd_pcm_action_lock_irq(&snd_pcm_action_start, substream,
1492 static int snd_pcm_pre_stop(struct snd_pcm_substream *substream,
1495 struct snd_pcm_runtime *runtime = substream->runtime;
1498 runtime->trigger_master = substream;
1502 static int snd_pcm_do_stop(struct snd_pcm_substream *substream,
1505 if (substream->runtime->trigger_master == substream &&
1506 snd_pcm_running(substream)) {
1507 substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP);
1508 substream->runtime->stop_operating = true;
1513 static void snd_pcm_post_stop(struct snd_pcm_substream *substream,
1516 struct snd_pcm_runtime *runtime = substream->runtime;
1518 snd_pcm_trigger_tstamp(substream);
1520 snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTOP);
1533 * snd_pcm_stop - try to stop all running streams in the substream group
1534 * @substream: the PCM substream instance
1541 int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state)
1543 return snd_pcm_action(&snd_pcm_action_stop, substream, state);
1549 * @substream: the PCM substream
1556 int snd_pcm_drain_done(struct snd_pcm_substream *substream)
1558 return snd_pcm_action_single(&snd_pcm_action_stop, substream,
1564 * @substream: the PCM substream instance
1566 * This stops the given running substream (and all linked substreams) as XRUN.
1567 * Unlike snd_pcm_stop(), this function takes the substream lock by itself.
1571 int snd_pcm_stop_xrun(struct snd_pcm_substream *substream)
1573 guard(pcm_stream_lock_irqsave)(substream);
1574 if (substream->runtime && snd_pcm_running(substream))
1575 __snd_pcm_xrun(substream);
1585 static int snd_pcm_pre_pause(struct snd_pcm_substream *substream,
1588 struct snd_pcm_runtime *runtime = substream->runtime;
1596 runtime->trigger_master = substream;
1600 static int snd_pcm_do_pause(struct snd_pcm_substream *substream,
1603 if (substream->runtime->trigger_master != substream)
1609 substream->runtime->hw_ptr_jiffies = jiffies - HZ * 1000;
1610 return substream->ops->trigger(substream,
1616 static void snd_pcm_undo_pause(struct snd_pcm_substream *substream,
1619 if (substream->runtime->trigger_master == substream)
1620 substream->ops->trigger(substream,
1626 static void snd_pcm_post_pause(struct snd_pcm_substream *substream,
1629 struct snd_pcm_runtime *runtime = substream->runtime;
1630 snd_pcm_trigger_tstamp(substream);
1633 snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MPAUSE);
1638 snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MCONTINUE);
1652 static int snd_pcm_pause(struct snd_pcm_substream *substream, bool push)
1654 return snd_pcm_action(&snd_pcm_action_pause, substream,
1658 static int snd_pcm_pause_lock_irq(struct snd_pcm_substream *substream,
1661 return snd_pcm_action_lock_irq(&snd_pcm_action_pause, substream,
1668 static int snd_pcm_pre_suspend(struct snd_pcm_substream *substream,
1671 struct snd_pcm_runtime *runtime = substream->runtime;
1681 runtime->trigger_master = substream;
1685 static int snd_pcm_do_suspend(struct snd_pcm_substream *substream,
1688 struct snd_pcm_runtime *runtime = substream->runtime;
1689 if (runtime->trigger_master != substream)
1691 if (! snd_pcm_running(substream))
1693 substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND);
1698 static void snd_pcm_post_suspend(struct snd_pcm_substream *substream,
1701 struct snd_pcm_runtime *runtime = substream->runtime;
1702 snd_pcm_trigger_tstamp(substream);
1706 snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSUSPEND);
1719 * @substream: the PCM substream
1725 static int snd_pcm_suspend(struct snd_pcm_substream *substream)
1727 guard(pcm_stream_lock_irqsave)(substream);
1728 return snd_pcm_action(&snd_pcm_action_suspend, substream,
1742 struct snd_pcm_substream *substream;
1748 for_each_pcm_substream(pcm, stream, substream) {
1750 if (!substream->runtime)
1755 * not have their substream ops set.
1757 if (!substream->ops)
1760 err = snd_pcm_suspend(substream);
1765 for_each_pcm_substream(pcm, stream, substream)
1766 snd_pcm_sync_stop(substream, false);
1774 static int snd_pcm_pre_resume(struct snd_pcm_substream *substream,
1777 struct snd_pcm_runtime *runtime = substream->runtime;
1780 runtime->trigger_master = substream;
1784 static int snd_pcm_do_resume(struct snd_pcm_substream *substream,
1787 struct snd_pcm_runtime *runtime = substream->runtime;
1788 if (runtime->trigger_master != substream)
1793 substream->stream != SNDRV_PCM_STREAM_PLAYBACK))
1795 return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME);
1798 static void snd_pcm_undo_resume(struct snd_pcm_substream *substream,
1801 if (substream->runtime->trigger_master == substream &&
1802 snd_pcm_running(substream))
1803 substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND);
1806 static void snd_pcm_post_resume(struct snd_pcm_substream *substream,
1809 struct snd_pcm_runtime *runtime = substream->runtime;
1810 snd_pcm_trigger_tstamp(substream);
1812 snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MRESUME);
1822 static int snd_pcm_resume(struct snd_pcm_substream *substream)
1824 return snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream,
1830 static int snd_pcm_resume(struct snd_pcm_substream *substream)
1842 static int snd_pcm_xrun(struct snd_pcm_substream *substream)
1844 struct snd_pcm_runtime *runtime = substream->runtime;
1846 guard(pcm_stream_lock_irq)(substream);
1851 __snd_pcm_xrun(substream);
1862 static int snd_pcm_pre_reset(struct snd_pcm_substream *substream,
1865 struct snd_pcm_runtime *runtime = substream->runtime;
1877 static int snd_pcm_do_reset(struct snd_pcm_substream *substream,
1880 struct snd_pcm_runtime *runtime = substream->runtime;
1881 int err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL);
1884 guard(pcm_stream_lock_irq)(substream);
1893 static void snd_pcm_post_reset(struct snd_pcm_substream *substream,
1896 struct snd_pcm_runtime *runtime = substream->runtime;
1897 guard(pcm_stream_lock_irq)(substream);
1899 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
1901 snd_pcm_playback_silence(substream, ULONG_MAX);
1910 static int snd_pcm_reset(struct snd_pcm_substream *substream)
1912 return snd_pcm_action_nonatomic(&snd_pcm_action_reset, substream,
1920 static int snd_pcm_pre_prepare(struct snd_pcm_substream *substream,
1923 struct snd_pcm_runtime *runtime = substream->runtime;
1929 if (snd_pcm_running(substream))
1931 substream->f_flags = f_flags;
1935 static int snd_pcm_do_prepare(struct snd_pcm_substream *substream,
1939 snd_pcm_sync_stop(substream, true);
1940 err = substream->ops->prepare(substream);
1943 return snd_pcm_do_reset(substream, state);
1946 static void snd_pcm_post_prepare(struct snd_pcm_substream *substream,
1949 struct snd_pcm_runtime *runtime = substream->runtime;
1951 snd_pcm_set_state(substream, SNDRV_PCM_STATE_PREPARED);
1961 * snd_pcm_prepare - prepare the PCM substream to be triggerable
1962 * @substream: the PCM substream instance
1967 static int snd_pcm_prepare(struct snd_pcm_substream *substream,
1975 f_flags = substream->f_flags;
1977 scoped_guard(pcm_stream_lock_irq, substream) {
1978 switch (substream->runtime->state) {
1980 snd_pcm_pause(substream, false);
1983 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
1989 substream,
1998 static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream,
2001 struct snd_pcm_runtime *runtime = substream->runtime;
2008 runtime->trigger_master = substream;
2012 static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream,
2015 struct snd_pcm_runtime *runtime = substream->runtime;
2016 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2020 if (! snd_pcm_playback_empty(substream)) {
2021 snd_pcm_do_start(substream, SNDRV_PCM_STATE_DRAINING);
2022 snd_pcm_post_start(substream, SNDRV_PCM_STATE_DRAINING);
2043 snd_pcm_do_stop(substream, new_state);
2044 snd_pcm_post_stop(substream, new_state);
2049 runtime->trigger_master == substream &&
2051 return substream->ops->trigger(substream,
2057 static void snd_pcm_post_drain_init(struct snd_pcm_substream *substream,
2070 * When the substream is linked, sync until the draining of all playback streams
2075 static int snd_pcm_drain(struct snd_pcm_substream *substream,
2086 card = substream->pcm->card;
2087 runtime = substream->runtime;
2095 } else if (substream->f_flags & O_NONBLOCK)
2098 snd_pcm_stream_lock_irq(substream);
2101 snd_pcm_pause(substream, false);
2104 result = snd_pcm_action(&snd_pcm_action_drain_init, substream,
2121 /* find a substream to drain */
2123 group = snd_pcm_stream_group_ref(substream);
2124 snd_pcm_group_for_each_entry(s, substream) {
2133 snd_pcm_group_unref(group, substream);
2139 snd_pcm_stream_unlock_irq(substream);
2152 snd_pcm_stream_lock_irq(substream);
2153 group = snd_pcm_stream_group_ref(substream);
2154 snd_pcm_group_for_each_entry(s, substream) {
2160 snd_pcm_group_unref(group, substream);
2167 if (substream->runtime->state == SNDRV_PCM_STATE_SUSPENDED)
2170 dev_dbg(substream->pcm->card->dev,
2172 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
2180 snd_pcm_stream_unlock_irq(substream);
2190 static int snd_pcm_drop(struct snd_pcm_substream *substream)
2195 if (PCM_RUNTIME_CHECK(substream))
2197 runtime = substream->runtime;
2203 guard(pcm_stream_lock_irq)(substream);
2206 snd_pcm_pause(substream, false);
2208 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
2236 static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
2242 bool nonatomic = substream->pcm->nonatomic;
2251 substream1 = pcm_file->substream;
2253 if (substream == substream1)
2262 if (substream->runtime->state == SNDRV_PCM_STATE_OPEN ||
2263 substream->runtime->state != substream1->runtime->state ||
2264 substream->pcm->nonatomic != substream1->pcm->nonatomic)
2269 scoped_guard(pcm_stream_lock_irq, substream) {
2270 if (!snd_pcm_stream_linked(substream)) {
2271 snd_pcm_group_assign(substream, group);
2274 target_group = substream->group;
2286 static void relink_to_local(struct snd_pcm_substream *substream)
2288 snd_pcm_stream_lock_nested(substream);
2289 snd_pcm_group_assign(substream, &substream->self_group);
2290 snd_pcm_stream_unlock(substream);
2293 static int snd_pcm_unlink(struct snd_pcm_substream *substream)
2296 bool nonatomic = substream->pcm->nonatomic;
2301 if (!snd_pcm_stream_linked(substream))
2304 group = substream->group;
2307 relink_to_local(substream);
2440 struct snd_pcm_substream *substream = rule->private;
2442 t.max = substream->buffer_bytes_max;
2484 static int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream)
2486 struct snd_pcm_runtime *runtime = substream->runtime;
2608 static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream)
2610 struct snd_pcm_runtime *runtime = substream->runtime;
2619 if (hw_support_mmap(substream)) {
2665 snd_pcm_hw_rule_buffer_bytes_max, substream,
2691 static void pcm_release_private(struct snd_pcm_substream *substream)
2693 if (snd_pcm_stream_linked(substream))
2694 snd_pcm_unlink(substream);
2697 void snd_pcm_release_substream(struct snd_pcm_substream *substream)
2699 substream->ref_count--;
2700 if (substream->ref_count > 0)
2703 snd_pcm_drop(substream);
2704 if (substream->hw_opened) {
2705 if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
2706 do_hw_free(substream);
2707 substream->ops->close(substream);
2708 substream->hw_opened = 0;
2710 if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req))
2711 cpu_latency_qos_remove_request(&substream->latency_pm_qos_req);
2712 if (substream->pcm_release) {
2713 substream->pcm_release(substream);
2714 substream->pcm_release = NULL;
2716 snd_pcm_detach_substream(substream);
2724 struct snd_pcm_substream *substream;
2727 err = snd_pcm_attach_substream(pcm, stream, file, &substream);
2730 if (substream->ref_count > 1) {
2731 *rsubstream = substream;
2735 err = snd_pcm_hw_constraints_init(substream);
2741 err = substream->ops->open(substream);
2745 substream->hw_opened = 1;
2747 err = snd_pcm_hw_constraints_complete(substream);
2756 if (substream->managed_buffer_alloc &&
2757 substream->dma_buffer.dev.need_sync)
2758 substream->runtime->hw.info |= SNDRV_PCM_INFO_EXPLICIT_SYNC;
2760 *rsubstream = substream;
2764 snd_pcm_release_substream(substream);
2774 struct snd_pcm_substream *substream;
2777 err = snd_pcm_open_substream(pcm, stream, file, &substream);
2783 snd_pcm_release_substream(substream);
2786 pcm_file->substream = substream;
2787 if (substream->ref_count == 1)
2788 substream->pcm_release = pcm_release_private;
2882 struct snd_pcm_substream *substream;
2886 substream = pcm_file->substream;
2887 if (snd_BUG_ON(!substream))
2889 pcm = substream->pcm;
2895 snd_pcm_release_substream(substream);
2907 static int do_pcm_hwsync(struct snd_pcm_substream *substream)
2909 switch (substream->runtime->state) {
2911 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
2915 return snd_pcm_update_hw_ptr(substream);
2929 static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream,
2933 struct snd_pcm_runtime *runtime = substream->runtime;
2944 ret = pcm_lib_apply_appl_ptr(substream, appl_ptr);
2949 static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream,
2953 struct snd_pcm_runtime *runtime = substream->runtime;
2964 ret = pcm_lib_apply_appl_ptr(substream, appl_ptr);
2973 static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream,
2981 scoped_guard(pcm_stream_lock_irq, substream) {
2982 ret = do_pcm_hwsync(substream);
2984 ret = rewind_appl_ptr(substream, frames,
2985 snd_pcm_hw_avail(substream));
2988 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
2992 static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,
3000 scoped_guard(pcm_stream_lock_irq, substream) {
3001 ret = do_pcm_hwsync(substream);
3003 ret = forward_appl_ptr(substream, frames,
3004 snd_pcm_avail(substream));
3007 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
3011 static int snd_pcm_delay(struct snd_pcm_substream *substream,
3016 scoped_guard(pcm_stream_lock_irq, substream) {
3017 err = do_pcm_hwsync(substream);
3019 *delay = snd_pcm_calc_delay(substream);
3021 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU);
3026 static inline int snd_pcm_hwsync(struct snd_pcm_substream *substream)
3028 return snd_pcm_delay(substream, NULL);
3031 static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream,
3034 struct snd_pcm_runtime *runtime = substream->runtime;
3048 err = snd_pcm_hwsync(substream);
3052 scoped_guard(pcm_stream_lock_irq, substream) {
3054 err = pcm_lib_apply_appl_ptr(substream,
3072 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
3119 static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream,
3122 struct snd_pcm_runtime *runtime = substream->runtime;
3139 err = snd_pcm_hwsync(substream);
3148 scoped_guard(pcm_stream_lock_irq, substream) {
3151 err = pcm_lib_apply_appl_ptr(substream,
3168 snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
3184 static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg)
3186 struct snd_pcm_runtime *runtime = substream->runtime;
3197 static int snd_pcm_xferi_frames_ioctl(struct snd_pcm_substream *substream,
3201 struct snd_pcm_runtime *runtime = substream->runtime;
3210 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3211 result = snd_pcm_lib_write(substream, xferi.buf, xferi.frames);
3213 result = snd_pcm_lib_read(substream, xferi.buf, xferi.frames);
3219 static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream,
3223 struct snd_pcm_runtime *runtime = substream->runtime;
3239 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3240 result = snd_pcm_lib_writev(substream, bufs, xfern.frames);
3242 result = snd_pcm_lib_readv(substream, bufs, xfern.frames);
3248 static int snd_pcm_rewind_ioctl(struct snd_pcm_substream *substream,
3258 result = snd_pcm_rewind(substream, frames);
3264 static int snd_pcm_forward_ioctl(struct snd_pcm_substream *substream,
3274 result = snd_pcm_forward(substream, frames);
3281 struct snd_pcm_substream *substream,
3287 if (PCM_RUNTIME_CHECK(substream))
3290 if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED)
3293 res = snd_power_wait(substream->pcm->card);
3301 return snd_pcm_info_user(substream, arg);
3305 return snd_pcm_tstamp(substream, arg);
3312 return snd_pcm_hw_refine_user(substream, arg);
3314 return snd_pcm_hw_params_user(substream, arg);
3316 return snd_pcm_hw_free(substream);
3318 return snd_pcm_sw_params_user(substream, arg);
3320 return snd_pcm_status_user32(substream, arg, false);
3322 return snd_pcm_status_user32(substream, arg, true);
3324 return snd_pcm_status_user64(substream, arg, false);
3326 return snd_pcm_status_user64(substream, arg, true);
3328 return snd_pcm_channel_info_user(substream, arg);
3330 return snd_pcm_prepare(substream, file);
3332 return snd_pcm_reset(substream);
3334 return snd_pcm_start_lock_irq(substream);
3336 return snd_pcm_link(substream, (int)(unsigned long) arg);
3338 return snd_pcm_unlink(substream);
3340 return snd_pcm_resume(substream);
3342 return snd_pcm_xrun(substream);
3344 return snd_pcm_hwsync(substream);
3351 err = snd_pcm_delay(substream, &delay);
3359 return snd_pcm_ioctl_sync_ptr_compat(substream, arg);
3361 return snd_pcm_sync_ptr(substream, arg);
3364 return snd_pcm_hw_refine_old_user(substream, arg);
3366 return snd_pcm_hw_params_old_user(substream, arg);
3369 return snd_pcm_drain(substream, file);
3371 return snd_pcm_drop(substream);
3373 return snd_pcm_pause_lock_irq(substream, (unsigned long)arg);
3376 return snd_pcm_xferi_frames_ioctl(substream, arg);
3379 return snd_pcm_xfern_frames_ioctl(substream, arg);
3381 return snd_pcm_rewind_ioctl(substream, arg);
3383 return snd_pcm_forward_ioctl(substream, arg);
3385 pcm_dbg(substream->pcm, "unknown ioctl = 0x%x\n", cmd);
3399 return snd_pcm_common_ioctl(file, pcm_file->substream, cmd,
3405 * @substream: PCM substream
3415 int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
3421 if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED)
3428 if (substream->stream != SNDRV_PCM_STREAM_CAPTURE)
3430 result = snd_pcm_forward(substream, *frames);
3434 return snd_pcm_hw_params(substream, arg);
3436 return snd_pcm_sw_params(substream, arg);
3438 return snd_pcm_prepare(substream, NULL);
3440 return snd_pcm_start_lock_irq(substream);
3442 return snd_pcm_drain(substream, NULL);
3444 return snd_pcm_drop(substream);
3446 return snd_pcm_delay(substream, frames);
3457 struct snd_pcm_substream *substream;
3462 substream = pcm_file->substream;
3463 if (PCM_RUNTIME_CHECK(substream))
3465 runtime = substream->runtime;
3472 result = snd_pcm_lib_read(substream, buf, count);
3482 struct snd_pcm_substream *substream;
3487 substream = pcm_file->substream;
3488 if (PCM_RUNTIME_CHECK(substream))
3490 runtime = substream->runtime;
3497 result = snd_pcm_lib_write(substream, buf, count);
3506 struct snd_pcm_substream *substream;
3515 substream = pcm_file->substream;
3516 if (PCM_RUNTIME_CHECK(substream))
3518 runtime = substream->runtime;
3536 result = snd_pcm_lib_readv(substream, bufs, frames);
3545 struct snd_pcm_substream *substream;
3554 substream = pcm_file->substream;
3555 if (PCM_RUNTIME_CHECK(substream))
3557 runtime = substream->runtime;
3574 result = snd_pcm_lib_writev(substream, bufs, frames);
3583 struct snd_pcm_substream *substream;
3590 substream = pcm_file->substream;
3591 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3595 if (PCM_RUNTIME_CHECK(substream))
3598 runtime = substream->runtime;
3605 guard(pcm_stream_lock_irq)(substream);
3606 avail = snd_pcm_avail(substream);
3615 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
3642 struct snd_pcm_substream *substream = vmf->vma->vm_private_data;
3645 if (substream == NULL)
3647 runtime = substream->runtime;
3658 static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
3668 area->vm_private_data = substream;
3680 struct snd_pcm_substream *substream = vmf->vma->vm_private_data;
3683 if (substream == NULL)
3685 runtime = substream->runtime;
3696 static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file,
3706 area->vm_private_data = substream;
3717 if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_EXPLICIT_SYNC)
3724 (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR))
3734 if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_EXPLICIT_SYNC)
3740 if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)
3752 static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file,
3757 static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file,
3769 struct snd_pcm_substream *substream = vmf->vma->vm_private_data;
3775 if (substream == NULL)
3777 runtime = substream->runtime;
3782 if (substream->ops->page)
3783 page = substream->ops->page(substream, offset);
3784 else if (!snd_pcm_get_dma_buf(substream))
3787 page = snd_sgbuf_get_page(snd_pcm_get_dma_buf(substream), offset);
3812 * @substream: PCM substream
3820 int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3824 if (!substream->ops->page &&
3825 !snd_dma_buffer_mmap(snd_pcm_get_dma_buf(substream), area))
3839 * @substream: PCM substream
3848 int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,
3851 struct snd_pcm_runtime *runtime = substream->runtime;
3862 int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
3871 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3878 runtime = substream->runtime;
3895 area->vm_private_data = substream;
3896 if (substream->ops->mmap)
3897 err = substream->ops->mmap(substream, area);
3899 err = snd_pcm_lib_default_mmap(substream, area);
3901 atomic_inc(&substream->mmap_count);
3909 struct snd_pcm_substream *substream;
3913 substream = pcm_file->substream;
3914 if (PCM_RUNTIME_CHECK(substream))
3916 if (substream->runtime->state == SNDRV_PCM_STATE_DISCONNECTED)
3928 return snd_pcm_mmap_status(substream, file, area);
3936 return snd_pcm_mmap_control(substream, file, area);
3938 return snd_pcm_mmap_data(substream, file, area);
3946 struct snd_pcm_substream *substream;
3950 substream = pcm_file->substream;
3951 if (PCM_RUNTIME_CHECK(substream))
3953 runtime = substream->runtime;
4014 static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
4029 err = snd_pcm_hw_refine(substream, params);
4033 err = fixup_unreferenced_params(substream, params);
4043 static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
4059 err = snd_pcm_hw_params(substream, params);
4078 struct snd_pcm_substream *substream = pcm_file->substream;
4079 struct snd_pcm_runtime *runtime = substream->runtime;