Lines Matching refs:substream
106 static bool snd_rawmidi_ready(struct snd_rawmidi_substream *substream) in snd_rawmidi_ready() argument
111 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_ready()
112 ready = __snd_rawmidi_ready(substream->runtime); in snd_rawmidi_ready()
113 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_ready()
117 static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substream, in snd_rawmidi_ready_append() argument
120 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_ready_append()
123 (!substream->append || runtime->avail >= count); in snd_rawmidi_ready_append()
132 runtime->event(runtime->substream); in snd_rawmidi_input_event_work()
146 static void snd_rawmidi_buffer_ref_sync(struct snd_rawmidi_substream *substream) in snd_rawmidi_buffer_ref_sync() argument
150 spin_lock_irq(&substream->lock); in snd_rawmidi_buffer_ref_sync()
151 while (substream->runtime->buffer_ref) { in snd_rawmidi_buffer_ref_sync()
152 spin_unlock_irq(&substream->lock); in snd_rawmidi_buffer_ref_sync()
154 rmidi_err(substream->rmidi, "Buffer ref sync timeout\n"); in snd_rawmidi_buffer_ref_sync()
158 spin_lock_irq(&substream->lock); in snd_rawmidi_buffer_ref_sync()
160 spin_unlock_irq(&substream->lock); in snd_rawmidi_buffer_ref_sync()
163 static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream) in snd_rawmidi_runtime_create() argument
170 runtime->substream = substream; in snd_rawmidi_runtime_create()
176 if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT) in snd_rawmidi_runtime_create()
186 substream->runtime = runtime; in snd_rawmidi_runtime_create()
187 if (rawmidi_is_ump(substream->rmidi)) in snd_rawmidi_runtime_create()
204 static int snd_rawmidi_runtime_free(struct snd_rawmidi_substream *substream) in snd_rawmidi_runtime_free() argument
206 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_runtime_free()
210 substream->runtime = NULL; in snd_rawmidi_runtime_free()
214 static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *substream, int up) in snd_rawmidi_output_trigger() argument
216 if (!substream->opened) in snd_rawmidi_output_trigger()
218 substream->ops->trigger(substream, up); in snd_rawmidi_output_trigger()
221 static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up) in snd_rawmidi_input_trigger() argument
223 if (!substream->opened) in snd_rawmidi_input_trigger()
225 substream->ops->trigger(substream, up); in snd_rawmidi_input_trigger()
227 cancel_work_sync(&substream->runtime->event_work); in snd_rawmidi_input_trigger()
238 static void reset_runtime_ptrs(struct snd_rawmidi_substream *substream, in reset_runtime_ptrs() argument
243 spin_lock_irqsave(&substream->lock, flags); in reset_runtime_ptrs()
244 if (substream->opened && substream->runtime) in reset_runtime_ptrs()
245 __reset_runtime_ptrs(substream->runtime, is_input); in reset_runtime_ptrs()
246 spin_unlock_irqrestore(&substream->lock, flags); in reset_runtime_ptrs()
249 int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream) in snd_rawmidi_drop_output() argument
251 snd_rawmidi_output_trigger(substream, 0); in snd_rawmidi_drop_output()
252 reset_runtime_ptrs(substream, false); in snd_rawmidi_drop_output()
257 int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream) in snd_rawmidi_drain_output() argument
263 spin_lock_irq(&substream->lock); in snd_rawmidi_drain_output()
264 runtime = substream->runtime; in snd_rawmidi_drain_output()
265 if (!substream->opened || !runtime || !runtime->buffer) { in snd_rawmidi_drain_output()
271 spin_unlock_irq(&substream->lock); in snd_rawmidi_drain_output()
279 spin_lock_irq(&substream->lock); in snd_rawmidi_drain_output()
283 rmidi_warn(substream->rmidi, in snd_rawmidi_drain_output()
289 spin_unlock_irq(&substream->lock); in snd_rawmidi_drain_output()
293 if (substream->ops->drain) in snd_rawmidi_drain_output()
294 substream->ops->drain(substream); in snd_rawmidi_drain_output()
297 snd_rawmidi_drop_output(substream); in snd_rawmidi_drain_output()
300 spin_lock_irq(&substream->lock); in snd_rawmidi_drain_output()
302 spin_unlock_irq(&substream->lock); in snd_rawmidi_drain_output()
308 int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream) in snd_rawmidi_drain_input() argument
310 snd_rawmidi_input_trigger(substream, 0); in snd_rawmidi_drain_input()
311 reset_runtime_ptrs(substream, true); in snd_rawmidi_drain_input()
323 struct snd_rawmidi_substream *substream; in assign_substream() local
335 list_for_each_entry(substream, &s->substreams, list) { in assign_substream()
336 if (substream->opened) { in assign_substream()
339 !substream->append) in assign_substream()
342 if (subdevice < 0 || subdevice == substream->number) { in assign_substream()
343 *sub_ret = substream; in assign_substream()
352 struct snd_rawmidi_substream *substream, in open_substream() argument
357 if (substream->use_count == 0) { in open_substream()
358 err = snd_rawmidi_runtime_create(substream); in open_substream()
361 err = substream->ops->open(substream); in open_substream()
363 snd_rawmidi_runtime_free(substream); in open_substream()
366 spin_lock_irq(&substream->lock); in open_substream()
367 substream->opened = 1; in open_substream()
368 substream->active_sensing = 0; in open_substream()
370 substream->append = 1; in open_substream()
371 substream->pid = get_pid(task_pid(current)); in open_substream()
372 rmidi->streams[substream->stream].substream_opened++; in open_substream()
373 spin_unlock_irq(&substream->lock); in open_substream()
375 substream->use_count++; in open_substream()
380 struct snd_rawmidi_substream *substream,
549 struct snd_rawmidi_substream *substream, in close_substream() argument
552 if (--substream->use_count) in close_substream()
556 if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT) in close_substream()
557 snd_rawmidi_input_trigger(substream, 0); in close_substream()
559 if (substream->active_sensing) { in close_substream()
564 snd_rawmidi_kernel_write(substream, &buf, 1); in close_substream()
566 if (snd_rawmidi_drain_output(substream) == -ERESTARTSYS) in close_substream()
567 snd_rawmidi_output_trigger(substream, 0); in close_substream()
569 snd_rawmidi_buffer_ref_sync(substream); in close_substream()
571 spin_lock_irq(&substream->lock); in close_substream()
572 substream->opened = 0; in close_substream()
573 substream->append = 0; in close_substream()
574 spin_unlock_irq(&substream->lock); in close_substream()
575 substream->ops->close(substream); in close_substream()
576 if (substream->runtime->private_free) in close_substream()
577 substream->runtime->private_free(substream); in close_substream()
578 snd_rawmidi_runtime_free(substream); in close_substream()
579 put_pid(substream->pid); in close_substream()
580 substream->pid = NULL; in close_substream()
581 rmidi->streams[substream->stream].substream_opened--; in close_substream()
634 static int snd_rawmidi_info(struct snd_rawmidi_substream *substream, in snd_rawmidi_info() argument
639 if (substream == NULL) in snd_rawmidi_info()
641 rmidi = substream->rmidi; in snd_rawmidi_info()
645 info->subdevice = substream->number; in snd_rawmidi_info()
646 info->stream = substream->stream; in snd_rawmidi_info()
650 strcpy(info->subname, substream->name); in snd_rawmidi_info()
651 info->subdevices_count = substream->pstr->substream_count; in snd_rawmidi_info()
652 info->subdevices_avail = (substream->pstr->substream_count - in snd_rawmidi_info()
653 substream->pstr->substream_opened); in snd_rawmidi_info()
657 static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream, in snd_rawmidi_info_user() argument
663 err = snd_rawmidi_info(substream, &info); in snd_rawmidi_info_user()
676 struct snd_rawmidi_substream *substream; in __snd_rawmidi_info_select() local
689 list_for_each_entry(substream, &pstr->substreams, list) { in __snd_rawmidi_info_select()
690 if ((unsigned int)substream->number == info->subdevice) in __snd_rawmidi_info_select()
691 return snd_rawmidi_info(substream, info); in __snd_rawmidi_info_select()
727 static int resize_runtime_buffer(struct snd_rawmidi_substream *substream, in resize_runtime_buffer() argument
731 struct snd_rawmidi_runtime *runtime = substream->runtime; in resize_runtime_buffer()
747 spin_lock_irq(&substream->lock); in resize_runtime_buffer()
749 spin_unlock_irq(&substream->lock); in resize_runtime_buffer()
757 spin_unlock_irq(&substream->lock); in resize_runtime_buffer()
764 int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream, in snd_rawmidi_output_params() argument
769 snd_rawmidi_drain_output(substream); in snd_rawmidi_output_params()
770 mutex_lock(&substream->rmidi->open_mutex); in snd_rawmidi_output_params()
771 if (substream->append && substream->use_count > 1) in snd_rawmidi_output_params()
774 err = resize_runtime_buffer(substream, params, false); in snd_rawmidi_output_params()
777 substream->active_sensing = !params->no_active_sensing; in snd_rawmidi_output_params()
778 mutex_unlock(&substream->rmidi->open_mutex); in snd_rawmidi_output_params()
783 int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, in snd_rawmidi_input_params() argument
790 snd_rawmidi_drain_input(substream); in snd_rawmidi_input_params()
791 mutex_lock(&substream->rmidi->open_mutex); in snd_rawmidi_input_params()
799 err = resize_runtime_buffer(substream, params, true); in snd_rawmidi_input_params()
802 substream->framing = framing; in snd_rawmidi_input_params()
803 substream->clock_type = clock_type; in snd_rawmidi_input_params()
805 mutex_unlock(&substream->rmidi->open_mutex); in snd_rawmidi_input_params()
810 static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream, in snd_rawmidi_output_status() argument
813 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_output_status()
817 spin_lock_irq(&substream->lock); in snd_rawmidi_output_status()
819 spin_unlock_irq(&substream->lock); in snd_rawmidi_output_status()
823 static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream, in snd_rawmidi_input_status() argument
826 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_input_status()
830 spin_lock_irq(&substream->lock); in snd_rawmidi_input_status()
834 spin_unlock_irq(&substream->lock); in snd_rawmidi_input_status()
1101 static int receive_with_tstamp_framing(struct snd_rawmidi_substream *substream, in receive_with_tstamp_framing() argument
1104 struct snd_rawmidi_runtime *runtime = substream->runtime; in receive_with_tstamp_framing()
1140 static struct timespec64 get_framing_tstamp(struct snd_rawmidi_substream *substream) in get_framing_tstamp() argument
1144 switch (substream->clock_type) { in get_framing_tstamp()
1168 int snd_rawmidi_receive(struct snd_rawmidi_substream *substream, in snd_rawmidi_receive() argument
1172 struct timespec64 ts64 = get_framing_tstamp(substream); in snd_rawmidi_receive()
1176 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_receive()
1177 if (!substream->opened) { in snd_rawmidi_receive()
1181 runtime = substream->runtime; in snd_rawmidi_receive()
1183 rmidi_dbg(substream->rmidi, in snd_rawmidi_receive()
1193 if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) { in snd_rawmidi_receive()
1194 result = receive_with_tstamp_framing(substream, buffer, count, &ts64); in snd_rawmidi_receive()
1196 substream->bytes++; in snd_rawmidi_receive()
1206 substream->bytes += count; in snd_rawmidi_receive()
1243 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_receive()
1248 static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream, in snd_rawmidi_kernel_read1() argument
1254 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_read1()
1258 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_kernel_read1()
1276 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_kernel_read1()
1280 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_kernel_read1()
1289 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_kernel_read1()
1293 long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream, in snd_rawmidi_kernel_read() argument
1296 snd_rawmidi_input_trigger(substream, 1); in snd_rawmidi_kernel_read()
1297 return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count); in snd_rawmidi_kernel_read()
1307 struct snd_rawmidi_substream *substream; in snd_rawmidi_read() local
1311 substream = rfile->input; in snd_rawmidi_read()
1312 if (substream == NULL) in snd_rawmidi_read()
1314 runtime = substream->runtime; in snd_rawmidi_read()
1315 snd_rawmidi_input_trigger(substream, 1); in snd_rawmidi_read()
1318 spin_lock_irq(&substream->lock); in snd_rawmidi_read()
1323 spin_unlock_irq(&substream->lock); in snd_rawmidi_read()
1329 spin_unlock_irq(&substream->lock); in snd_rawmidi_read()
1336 spin_lock_irq(&substream->lock); in snd_rawmidi_read()
1338 spin_unlock_irq(&substream->lock); in snd_rawmidi_read()
1342 spin_unlock_irq(&substream->lock); in snd_rawmidi_read()
1343 count1 = snd_rawmidi_kernel_read1(substream, in snd_rawmidi_read()
1362 int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream) in snd_rawmidi_transmit_empty() argument
1368 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_transmit_empty()
1369 runtime = substream->runtime; in snd_rawmidi_transmit_empty()
1370 if (!substream->opened || !runtime || !runtime->buffer) { in snd_rawmidi_transmit_empty()
1371 rmidi_dbg(substream->rmidi, in snd_rawmidi_transmit_empty()
1377 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_transmit_empty()
1390 static int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, in __snd_rawmidi_transmit_peek() argument
1394 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_peek()
1397 rmidi_dbg(substream->rmidi, in __snd_rawmidi_transmit_peek()
1449 int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream, in snd_rawmidi_transmit_peek() argument
1455 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_transmit_peek()
1456 if (!substream->opened || !substream->runtime) in snd_rawmidi_transmit_peek()
1459 result = __snd_rawmidi_transmit_peek(substream, buffer, count); in snd_rawmidi_transmit_peek()
1460 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_transmit_peek()
1472 static int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, in __snd_rawmidi_transmit_ack() argument
1475 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_ack()
1478 rmidi_dbg(substream->rmidi, in __snd_rawmidi_transmit_ack()
1487 substream->bytes += count; in __snd_rawmidi_transmit_ack()
1506 int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count) in snd_rawmidi_transmit_ack() argument
1511 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_transmit_ack()
1512 if (!substream->opened || !substream->runtime) in snd_rawmidi_transmit_ack()
1515 result = __snd_rawmidi_transmit_ack(substream, count); in snd_rawmidi_transmit_ack()
1516 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_transmit_ack()
1531 int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream, in snd_rawmidi_transmit() argument
1537 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_transmit()
1538 if (!substream->opened) in snd_rawmidi_transmit()
1541 count = __snd_rawmidi_transmit_peek(substream, buffer, count); in snd_rawmidi_transmit()
1545 result = __snd_rawmidi_transmit_ack(substream, count); in snd_rawmidi_transmit()
1547 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_transmit()
1558 int snd_rawmidi_proceed(struct snd_rawmidi_substream *substream) in snd_rawmidi_proceed() argument
1564 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_proceed()
1565 runtime = substream->runtime; in snd_rawmidi_proceed()
1566 if (substream->opened && runtime && in snd_rawmidi_proceed()
1569 __snd_rawmidi_transmit_ack(substream, count); in snd_rawmidi_proceed()
1571 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_proceed()
1576 static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream, in snd_rawmidi_kernel_write1() argument
1583 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_write1()
1592 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_kernel_write1()
1593 if (substream->append) { in snd_rawmidi_kernel_write1()
1595 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_kernel_write1()
1617 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_kernel_write1()
1620 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_kernel_write1()
1624 spin_lock_irqsave(&substream->lock, flags); in snd_rawmidi_kernel_write1()
1632 spin_unlock_irqrestore(&substream->lock, flags); in snd_rawmidi_kernel_write1()
1634 snd_rawmidi_output_trigger(substream, 1); in snd_rawmidi_kernel_write1()
1638 long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream, in snd_rawmidi_kernel_write() argument
1641 return snd_rawmidi_kernel_write1(substream, NULL, buf, count); in snd_rawmidi_kernel_write()
1652 struct snd_rawmidi_substream *substream; in snd_rawmidi_write() local
1655 substream = rfile->output; in snd_rawmidi_write()
1656 runtime = substream->runtime; in snd_rawmidi_write()
1658 if (substream->append && count > runtime->buffer_size) in snd_rawmidi_write()
1662 spin_lock_irq(&substream->lock); in snd_rawmidi_write()
1663 while (!snd_rawmidi_ready_append(substream, count)) { in snd_rawmidi_write()
1667 spin_unlock_irq(&substream->lock); in snd_rawmidi_write()
1673 spin_unlock_irq(&substream->lock); in snd_rawmidi_write()
1680 spin_lock_irq(&substream->lock); in snd_rawmidi_write()
1682 spin_unlock_irq(&substream->lock); in snd_rawmidi_write()
1686 spin_unlock_irq(&substream->lock); in snd_rawmidi_write()
1687 count1 = snd_rawmidi_kernel_write1(substream, buf, NULL, count); in snd_rawmidi_write()
1697 spin_lock_irq(&substream->lock); in snd_rawmidi_write()
1705 spin_unlock_irq(&substream->lock); in snd_rawmidi_write()
1712 spin_lock_irq(&substream->lock); in snd_rawmidi_write()
1714 spin_unlock_irq(&substream->lock); in snd_rawmidi_write()
1762 struct snd_rawmidi_substream *substream; in snd_rawmidi_proc_info_read() local
1777 list_for_each_entry(substream, in snd_rawmidi_proc_info_read()
1783 substream->number, in snd_rawmidi_proc_info_read()
1784 (unsigned long) substream->bytes); in snd_rawmidi_proc_info_read()
1785 if (substream->opened) { in snd_rawmidi_proc_info_read()
1788 pid_vnr(substream->pid)); in snd_rawmidi_proc_info_read()
1789 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1790 spin_lock_irq(&substream->lock); in snd_rawmidi_proc_info_read()
1793 spin_unlock_irq(&substream->lock); in snd_rawmidi_proc_info_read()
1804 list_for_each_entry(substream, in snd_rawmidi_proc_info_read()
1810 substream->number, in snd_rawmidi_proc_info_read()
1811 (unsigned long) substream->bytes); in snd_rawmidi_proc_info_read()
1812 if (substream->opened) { in snd_rawmidi_proc_info_read()
1815 pid_vnr(substream->pid)); in snd_rawmidi_proc_info_read()
1816 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1817 spin_lock_irq(&substream->lock); in snd_rawmidi_proc_info_read()
1821 spin_unlock_irq(&substream->lock); in snd_rawmidi_proc_info_read()
1827 if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) { in snd_rawmidi_proc_info_read()
1828 clock_type = substream->clock_type >> SNDRV_RAWMIDI_MODE_CLOCK_SHIFT; in snd_rawmidi_proc_info_read()
1862 struct snd_rawmidi_substream *substream; in snd_rawmidi_alloc_substreams() local
1866 substream = kzalloc(sizeof(*substream), GFP_KERNEL); in snd_rawmidi_alloc_substreams()
1867 if (!substream) in snd_rawmidi_alloc_substreams()
1869 substream->stream = direction; in snd_rawmidi_alloc_substreams()
1870 substream->number = idx; in snd_rawmidi_alloc_substreams()
1871 substream->rmidi = rmidi; in snd_rawmidi_alloc_substreams()
1872 substream->pstr = stream; in snd_rawmidi_alloc_substreams()
1873 spin_lock_init(&substream->lock); in snd_rawmidi_alloc_substreams()
1874 list_add_tail(&substream->list, &stream->substreams); in snd_rawmidi_alloc_substreams()
1971 struct snd_rawmidi_substream *substream; in snd_rawmidi_free_substreams() local
1974 substream = list_entry(stream->substreams.next, struct snd_rawmidi_substream, list); in snd_rawmidi_free_substreams()
1975 list_del(&substream->list); in snd_rawmidi_free_substreams()
1976 kfree(substream); in snd_rawmidi_free_substreams()
2159 struct snd_rawmidi_substream *substream; in snd_rawmidi_set_ops() local
2161 list_for_each_entry(substream, &rmidi->streams[stream].substreams, list) in snd_rawmidi_set_ops()
2162 substream->ops = ops; in snd_rawmidi_set_ops()