Lines Matching full:runtime
98 static inline bool __snd_rawmidi_ready(struct snd_rawmidi_runtime *runtime) in __snd_rawmidi_ready() argument
100 return runtime->avail >= runtime->avail_min; in __snd_rawmidi_ready()
105 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_ready() local
109 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_ready()
110 ready = __snd_rawmidi_ready(runtime); in snd_rawmidi_ready()
111 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_ready()
118 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_ready_append() local
120 return runtime->avail >= runtime->avail_min && in snd_rawmidi_ready_append()
121 (!substream->append || runtime->avail >= count); in snd_rawmidi_ready_append()
126 struct snd_rawmidi_runtime *runtime = in snd_rawmidi_input_event_work() local
129 if (runtime->event) in snd_rawmidi_input_event_work()
130 runtime->event(runtime->substream); in snd_rawmidi_input_event_work()
133 /* buffer refcount management: call with runtime->lock held */
134 static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime) in snd_rawmidi_buffer_ref() argument
136 runtime->buffer_ref++; in snd_rawmidi_buffer_ref()
139 static inline void snd_rawmidi_buffer_unref(struct snd_rawmidi_runtime *runtime) in snd_rawmidi_buffer_unref() argument
141 runtime->buffer_ref--; in snd_rawmidi_buffer_unref()
146 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_runtime_create() local
148 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); in snd_rawmidi_runtime_create()
149 if (!runtime) in snd_rawmidi_runtime_create()
151 runtime->substream = substream; in snd_rawmidi_runtime_create()
152 spin_lock_init(&runtime->lock); in snd_rawmidi_runtime_create()
153 init_waitqueue_head(&runtime->sleep); in snd_rawmidi_runtime_create()
154 INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work); in snd_rawmidi_runtime_create()
155 runtime->event = NULL; in snd_rawmidi_runtime_create()
156 runtime->buffer_size = PAGE_SIZE; in snd_rawmidi_runtime_create()
157 runtime->avail_min = 1; in snd_rawmidi_runtime_create()
159 runtime->avail = 0; in snd_rawmidi_runtime_create()
161 runtime->avail = runtime->buffer_size; in snd_rawmidi_runtime_create()
162 runtime->buffer = kvzalloc(runtime->buffer_size, GFP_KERNEL); in snd_rawmidi_runtime_create()
163 if (!runtime->buffer) { in snd_rawmidi_runtime_create()
164 kfree(runtime); in snd_rawmidi_runtime_create()
167 runtime->appl_ptr = runtime->hw_ptr = 0; in snd_rawmidi_runtime_create()
168 substream->runtime = runtime; in snd_rawmidi_runtime_create()
174 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_runtime_free() local
176 kvfree(runtime->buffer); in snd_rawmidi_runtime_free()
177 kfree(runtime); in snd_rawmidi_runtime_free()
178 substream->runtime = NULL; in snd_rawmidi_runtime_free()
195 cancel_work_sync(&substream->runtime->event_work); in snd_rawmidi_input_trigger()
198 static void __reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime, in __reset_runtime_ptrs() argument
201 runtime->drain = 0; in __reset_runtime_ptrs()
202 runtime->appl_ptr = runtime->hw_ptr = 0; in __reset_runtime_ptrs()
203 runtime->avail = is_input ? 0 : runtime->buffer_size; in __reset_runtime_ptrs()
206 static void reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime, in reset_runtime_ptrs() argument
211 spin_lock_irqsave(&runtime->lock, flags); in reset_runtime_ptrs()
212 __reset_runtime_ptrs(runtime, is_input); in reset_runtime_ptrs()
213 spin_unlock_irqrestore(&runtime->lock, flags); in reset_runtime_ptrs()
219 reset_runtime_ptrs(substream->runtime, false); in snd_rawmidi_drop_output()
228 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_drain_output() local
231 runtime->drain = 1; in snd_rawmidi_drain_output()
232 timeout = wait_event_interruptible_timeout(runtime->sleep, in snd_rawmidi_drain_output()
233 (runtime->avail >= runtime->buffer_size), in snd_rawmidi_drain_output()
237 if (runtime->avail < runtime->buffer_size && !timeout) { in snd_rawmidi_drain_output()
240 (long)runtime->avail, (long)runtime->buffer_size); in snd_rawmidi_drain_output()
243 runtime->drain = 0; in snd_rawmidi_drain_output()
259 reset_runtime_ptrs(substream->runtime, true); in snd_rawmidi_drain_input()
483 if (rawmidi_file->input && rawmidi_file->input->runtime) in snd_rawmidi_open()
484 rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR); in snd_rawmidi_open()
485 if (rawmidi_file->output && rawmidi_file->output->runtime) in snd_rawmidi_open()
486 rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR); in snd_rawmidi_open()
525 if (substream->runtime->private_free) in close_substream()
526 substream->runtime->private_free(substream); in close_substream()
678 static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime, in resize_runtime_buffer() argument
688 if (params->buffer_size != runtime->buffer_size) { in resize_runtime_buffer()
692 spin_lock_irq(&runtime->lock); in resize_runtime_buffer()
693 if (runtime->buffer_ref) { in resize_runtime_buffer()
694 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
698 oldbuf = runtime->buffer; in resize_runtime_buffer()
699 runtime->buffer = newbuf; in resize_runtime_buffer()
700 runtime->buffer_size = params->buffer_size; in resize_runtime_buffer()
701 __reset_runtime_ptrs(runtime, is_input); in resize_runtime_buffer()
702 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
705 runtime->avail_min = params->avail_min; in resize_runtime_buffer()
716 return resize_runtime_buffer(substream->runtime, params, false); in snd_rawmidi_output_params()
724 return resize_runtime_buffer(substream->runtime, params, true); in snd_rawmidi_input_params()
731 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_output_status() local
735 spin_lock_irq(&runtime->lock); in snd_rawmidi_output_status()
736 status->avail = runtime->avail; in snd_rawmidi_output_status()
737 spin_unlock_irq(&runtime->lock); in snd_rawmidi_output_status()
744 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_input_status() local
748 spin_lock_irq(&runtime->lock); in snd_rawmidi_input_status()
749 status->avail = runtime->avail; in snd_rawmidi_input_status()
750 status->xruns = runtime->xruns; in snd_rawmidi_input_status()
751 runtime->xruns = 0; in snd_rawmidi_input_status()
752 spin_unlock_irq(&runtime->lock); in snd_rawmidi_input_status()
981 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_receive() local
985 if (runtime->buffer == NULL) { in snd_rawmidi_receive()
990 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_receive()
993 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_receive()
994 runtime->buffer[runtime->hw_ptr++] = buffer[0]; in snd_rawmidi_receive()
995 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
996 runtime->avail++; in snd_rawmidi_receive()
999 runtime->xruns++; in snd_rawmidi_receive()
1003 count1 = runtime->buffer_size - runtime->hw_ptr; in snd_rawmidi_receive()
1006 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in snd_rawmidi_receive()
1007 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1008 memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1); in snd_rawmidi_receive()
1009 runtime->hw_ptr += count1; in snd_rawmidi_receive()
1010 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
1011 runtime->avail += count1; in snd_rawmidi_receive()
1017 if (count1 > (int)(runtime->buffer_size - runtime->avail)) { in snd_rawmidi_receive()
1018 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1019 runtime->xruns += count - count1; in snd_rawmidi_receive()
1022 memcpy(runtime->buffer, buffer, count1); in snd_rawmidi_receive()
1023 runtime->hw_ptr = count1; in snd_rawmidi_receive()
1024 runtime->avail += count1; in snd_rawmidi_receive()
1030 if (runtime->event) in snd_rawmidi_receive()
1031 schedule_work(&runtime->event_work); in snd_rawmidi_receive()
1032 else if (__snd_rawmidi_ready(runtime)) in snd_rawmidi_receive()
1033 wake_up(&runtime->sleep); in snd_rawmidi_receive()
1035 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_receive()
1046 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_read1() local
1050 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1051 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_read1()
1052 while (count > 0 && runtime->avail) { in snd_rawmidi_kernel_read1()
1053 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1056 if (count1 > (int)runtime->avail) in snd_rawmidi_kernel_read1()
1057 count1 = runtime->avail; in snd_rawmidi_kernel_read1()
1059 /* update runtime->appl_ptr before unlocking for userbuf */ in snd_rawmidi_kernel_read1()
1060 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1061 runtime->appl_ptr += count1; in snd_rawmidi_kernel_read1()
1062 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_read1()
1063 runtime->avail -= count1; in snd_rawmidi_kernel_read1()
1066 memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1); in snd_rawmidi_kernel_read1()
1068 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1070 runtime->buffer + appl_ptr, count1)) in snd_rawmidi_kernel_read1()
1072 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1080 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_read1()
1081 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1100 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_read() local
1106 runtime = substream->runtime; in snd_rawmidi_read()
1110 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1111 while (!__snd_rawmidi_ready(runtime)) { in snd_rawmidi_read()
1115 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1119 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1121 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1123 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1128 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1129 if (!runtime->avail) { in snd_rawmidi_read()
1130 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1134 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1156 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_empty() local
1160 if (runtime->buffer == NULL) { in snd_rawmidi_transmit_empty()
1165 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1166 result = runtime->avail >= runtime->buffer_size; in snd_rawmidi_transmit_empty()
1167 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1184 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_peek() local
1186 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_peek()
1192 if (runtime->avail >= runtime->buffer_size) { in __snd_rawmidi_transmit_peek()
1197 *buffer = runtime->buffer[runtime->hw_ptr]; in __snd_rawmidi_transmit_peek()
1200 count1 = runtime->buffer_size - runtime->hw_ptr; in __snd_rawmidi_transmit_peek()
1203 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in __snd_rawmidi_transmit_peek()
1204 count1 = runtime->buffer_size - runtime->avail; in __snd_rawmidi_transmit_peek()
1205 memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1); in __snd_rawmidi_transmit_peek()
1209 if (count > (int)(runtime->buffer_size - runtime->avail - count1)) in __snd_rawmidi_transmit_peek()
1210 count = runtime->buffer_size - runtime->avail - count1; in __snd_rawmidi_transmit_peek()
1211 memcpy(buffer + count1, runtime->buffer, count); in __snd_rawmidi_transmit_peek()
1237 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_peek() local
1241 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1243 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1257 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_ack() local
1259 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_ack()
1264 snd_BUG_ON(runtime->avail + count > runtime->buffer_size); in __snd_rawmidi_transmit_ack()
1265 runtime->hw_ptr += count; in __snd_rawmidi_transmit_ack()
1266 runtime->hw_ptr %= runtime->buffer_size; in __snd_rawmidi_transmit_ack()
1267 runtime->avail += count; in __snd_rawmidi_transmit_ack()
1270 if (runtime->drain || __snd_rawmidi_ready(runtime)) in __snd_rawmidi_transmit_ack()
1271 wake_up(&runtime->sleep); in __snd_rawmidi_transmit_ack()
1290 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_ack() local
1294 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1296 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1314 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit() local
1318 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit()
1328 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit()
1341 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_proceed() local
1345 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_proceed()
1346 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_proceed()
1347 count = runtime->buffer_size - runtime->avail; in snd_rawmidi_proceed()
1350 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_proceed()
1362 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_write1() local
1367 if (snd_BUG_ON(!runtime->buffer)) in snd_rawmidi_kernel_write1()
1371 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1373 if ((long)runtime->avail < count) { in snd_rawmidi_kernel_write1()
1374 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1378 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_write1()
1379 while (count > 0 && runtime->avail > 0) { in snd_rawmidi_kernel_write1()
1380 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1383 if (count1 > (long)runtime->avail) in snd_rawmidi_kernel_write1()
1384 count1 = runtime->avail; in snd_rawmidi_kernel_write1()
1386 /* update runtime->appl_ptr before unlocking for userbuf */ in snd_rawmidi_kernel_write1()
1387 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1388 runtime->appl_ptr += count1; in snd_rawmidi_kernel_write1()
1389 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_write1()
1390 runtime->avail -= count1; in snd_rawmidi_kernel_write1()
1393 memcpy(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1396 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1397 if (copy_from_user(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1399 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1403 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1409 count1 = runtime->avail < runtime->buffer_size; in snd_rawmidi_kernel_write1()
1410 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_write1()
1411 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1430 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_write() local
1435 runtime = substream->runtime; in snd_rawmidi_write()
1437 if (substream->append && count > runtime->buffer_size) in snd_rawmidi_write()
1441 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1446 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1450 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1452 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1454 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1459 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1460 if (!runtime->avail && !timeout) { in snd_rawmidi_write()
1461 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1465 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1476 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1477 while (runtime->avail != runtime->buffer_size) { in snd_rawmidi_write()
1479 unsigned int last_avail = runtime->avail; in snd_rawmidi_write()
1482 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1484 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1486 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1489 if (runtime->avail == last_avail && !timeout) in snd_rawmidi_write()
1491 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1493 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1501 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_poll() local
1506 runtime = rfile->input->runtime; in snd_rawmidi_poll()
1508 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1511 runtime = rfile->output->runtime; in snd_rawmidi_poll()
1512 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1542 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_proc_info_read() local
1561 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1562 spin_lock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1563 buffer_size = runtime->buffer_size; in snd_rawmidi_proc_info_read()
1564 avail = runtime->avail; in snd_rawmidi_proc_info_read()
1565 spin_unlock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1570 runtime->oss ? "OSS compatible" : "native", in snd_rawmidi_proc_info_read()
1588 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1589 spin_lock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1590 buffer_size = runtime->buffer_size; in snd_rawmidi_proc_info_read()
1591 avail = runtime->avail; in snd_rawmidi_proc_info_read()
1592 xruns = runtime->xruns; in snd_rawmidi_proc_info_read()
1593 spin_unlock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1870 if (s->runtime) in snd_rawmidi_dev_disconnect()
1871 wake_up(&s->runtime->sleep); in snd_rawmidi_dev_disconnect()