Lines Matching full:runtime
100 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_ready() local
102 return runtime->avail >= runtime->avail_min; in snd_rawmidi_ready()
108 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_ready_append() local
110 return runtime->avail >= runtime->avail_min && in snd_rawmidi_ready_append()
111 (!substream->append || runtime->avail >= count); in snd_rawmidi_ready_append()
116 struct snd_rawmidi_runtime *runtime = in snd_rawmidi_input_event_work() local
119 if (runtime->event) in snd_rawmidi_input_event_work()
120 runtime->event(runtime->substream); in snd_rawmidi_input_event_work()
123 /* buffer refcount management: call with runtime->lock held */
124 static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime) in snd_rawmidi_buffer_ref() argument
126 runtime->buffer_ref++; in snd_rawmidi_buffer_ref()
129 static inline void snd_rawmidi_buffer_unref(struct snd_rawmidi_runtime *runtime) in snd_rawmidi_buffer_unref() argument
131 runtime->buffer_ref--; in snd_rawmidi_buffer_unref()
136 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_runtime_create() local
138 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); in snd_rawmidi_runtime_create()
139 if (!runtime) in snd_rawmidi_runtime_create()
141 runtime->substream = substream; in snd_rawmidi_runtime_create()
142 spin_lock_init(&runtime->lock); in snd_rawmidi_runtime_create()
143 init_waitqueue_head(&runtime->sleep); in snd_rawmidi_runtime_create()
144 INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work); in snd_rawmidi_runtime_create()
145 runtime->event = NULL; in snd_rawmidi_runtime_create()
146 runtime->buffer_size = PAGE_SIZE; in snd_rawmidi_runtime_create()
147 runtime->avail_min = 1; in snd_rawmidi_runtime_create()
149 runtime->avail = 0; in snd_rawmidi_runtime_create()
151 runtime->avail = runtime->buffer_size; in snd_rawmidi_runtime_create()
152 runtime->buffer = kvzalloc(runtime->buffer_size, GFP_KERNEL); in snd_rawmidi_runtime_create()
153 if (!runtime->buffer) { in snd_rawmidi_runtime_create()
154 kfree(runtime); in snd_rawmidi_runtime_create()
157 runtime->appl_ptr = runtime->hw_ptr = 0; in snd_rawmidi_runtime_create()
158 substream->runtime = runtime; in snd_rawmidi_runtime_create()
164 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_runtime_free() local
166 kvfree(runtime->buffer); in snd_rawmidi_runtime_free()
167 kfree(runtime); in snd_rawmidi_runtime_free()
168 substream->runtime = NULL; in snd_rawmidi_runtime_free()
185 cancel_work_sync(&substream->runtime->event_work); in snd_rawmidi_input_trigger()
188 static void __reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime, in __reset_runtime_ptrs() argument
191 runtime->drain = 0; in __reset_runtime_ptrs()
192 runtime->appl_ptr = runtime->hw_ptr = 0; in __reset_runtime_ptrs()
193 runtime->avail = is_input ? 0 : runtime->buffer_size; in __reset_runtime_ptrs()
196 static void reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime, in reset_runtime_ptrs() argument
201 spin_lock_irqsave(&runtime->lock, flags); in reset_runtime_ptrs()
202 __reset_runtime_ptrs(runtime, is_input); in reset_runtime_ptrs()
203 spin_unlock_irqrestore(&runtime->lock, flags); in reset_runtime_ptrs()
209 reset_runtime_ptrs(substream->runtime, false); in snd_rawmidi_drop_output()
218 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_drain_output() local
221 runtime->drain = 1; in snd_rawmidi_drain_output()
222 timeout = wait_event_interruptible_timeout(runtime->sleep, in snd_rawmidi_drain_output()
223 (runtime->avail >= runtime->buffer_size), in snd_rawmidi_drain_output()
227 if (runtime->avail < runtime->buffer_size && !timeout) { in snd_rawmidi_drain_output()
230 (long)runtime->avail, (long)runtime->buffer_size); in snd_rawmidi_drain_output()
233 runtime->drain = 0; in snd_rawmidi_drain_output()
249 reset_runtime_ptrs(substream->runtime, true); in snd_rawmidi_drain_input()
473 if (rawmidi_file->input && rawmidi_file->input->runtime) in snd_rawmidi_open()
474 rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR); in snd_rawmidi_open()
475 if (rawmidi_file->output && rawmidi_file->output->runtime) in snd_rawmidi_open()
476 rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR); in snd_rawmidi_open()
515 if (substream->runtime->private_free) in close_substream()
516 substream->runtime->private_free(substream); in close_substream()
668 static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime, in resize_runtime_buffer() argument
678 if (params->buffer_size != runtime->buffer_size) { in resize_runtime_buffer()
682 spin_lock_irq(&runtime->lock); in resize_runtime_buffer()
683 if (runtime->buffer_ref) { in resize_runtime_buffer()
684 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
688 oldbuf = runtime->buffer; in resize_runtime_buffer()
689 runtime->buffer = newbuf; in resize_runtime_buffer()
690 runtime->buffer_size = params->buffer_size; in resize_runtime_buffer()
691 __reset_runtime_ptrs(runtime, is_input); in resize_runtime_buffer()
692 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
695 runtime->avail_min = params->avail_min; in resize_runtime_buffer()
706 return resize_runtime_buffer(substream->runtime, params, false); in snd_rawmidi_output_params()
714 return resize_runtime_buffer(substream->runtime, params, true); in snd_rawmidi_input_params()
721 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_output_status() local
725 spin_lock_irq(&runtime->lock); in snd_rawmidi_output_status()
726 status->avail = runtime->avail; in snd_rawmidi_output_status()
727 spin_unlock_irq(&runtime->lock); in snd_rawmidi_output_status()
734 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_input_status() local
738 spin_lock_irq(&runtime->lock); in snd_rawmidi_input_status()
739 status->avail = runtime->avail; in snd_rawmidi_input_status()
740 status->xruns = runtime->xruns; in snd_rawmidi_input_status()
741 runtime->xruns = 0; in snd_rawmidi_input_status()
742 spin_unlock_irq(&runtime->lock); in snd_rawmidi_input_status()
971 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_receive() local
975 if (runtime->buffer == NULL) { in snd_rawmidi_receive()
980 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_receive()
983 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_receive()
984 runtime->buffer[runtime->hw_ptr++] = buffer[0]; in snd_rawmidi_receive()
985 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
986 runtime->avail++; in snd_rawmidi_receive()
989 runtime->xruns++; in snd_rawmidi_receive()
993 count1 = runtime->buffer_size - runtime->hw_ptr; in snd_rawmidi_receive()
996 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in snd_rawmidi_receive()
997 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
998 memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1); in snd_rawmidi_receive()
999 runtime->hw_ptr += count1; in snd_rawmidi_receive()
1000 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
1001 runtime->avail += count1; in snd_rawmidi_receive()
1007 if (count1 > (int)(runtime->buffer_size - runtime->avail)) { in snd_rawmidi_receive()
1008 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1009 runtime->xruns += count - count1; in snd_rawmidi_receive()
1012 memcpy(runtime->buffer, buffer, count1); in snd_rawmidi_receive()
1013 runtime->hw_ptr = count1; in snd_rawmidi_receive()
1014 runtime->avail += count1; in snd_rawmidi_receive()
1020 if (runtime->event) in snd_rawmidi_receive()
1021 schedule_work(&runtime->event_work); in snd_rawmidi_receive()
1023 wake_up(&runtime->sleep); in snd_rawmidi_receive()
1025 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_receive()
1036 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_read1() local
1040 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1041 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_read1()
1042 while (count > 0 && runtime->avail) { in snd_rawmidi_kernel_read1()
1043 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1046 if (count1 > (int)runtime->avail) in snd_rawmidi_kernel_read1()
1047 count1 = runtime->avail; in snd_rawmidi_kernel_read1()
1049 /* update runtime->appl_ptr before unlocking for userbuf */ in snd_rawmidi_kernel_read1()
1050 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1051 runtime->appl_ptr += count1; in snd_rawmidi_kernel_read1()
1052 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_read1()
1053 runtime->avail -= count1; in snd_rawmidi_kernel_read1()
1056 memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1); in snd_rawmidi_kernel_read1()
1058 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1060 runtime->buffer + appl_ptr, count1)) in snd_rawmidi_kernel_read1()
1062 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1070 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_read1()
1071 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1090 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_read() local
1096 runtime = substream->runtime; in snd_rawmidi_read()
1100 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1105 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1109 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1111 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1113 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1118 if (!runtime->avail) in snd_rawmidi_read()
1120 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1122 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1144 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_empty() local
1148 if (runtime->buffer == NULL) { in snd_rawmidi_transmit_empty()
1153 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1154 result = runtime->avail >= runtime->buffer_size; in snd_rawmidi_transmit_empty()
1155 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1172 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_peek() local
1174 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_peek()
1180 if (runtime->avail >= runtime->buffer_size) { in __snd_rawmidi_transmit_peek()
1185 *buffer = runtime->buffer[runtime->hw_ptr]; in __snd_rawmidi_transmit_peek()
1188 count1 = runtime->buffer_size - runtime->hw_ptr; in __snd_rawmidi_transmit_peek()
1191 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in __snd_rawmidi_transmit_peek()
1192 count1 = runtime->buffer_size - runtime->avail; in __snd_rawmidi_transmit_peek()
1193 memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1); in __snd_rawmidi_transmit_peek()
1197 if (count > (int)(runtime->buffer_size - runtime->avail - count1)) in __snd_rawmidi_transmit_peek()
1198 count = runtime->buffer_size - runtime->avail - count1; in __snd_rawmidi_transmit_peek()
1199 memcpy(buffer + count1, runtime->buffer, count); in __snd_rawmidi_transmit_peek()
1225 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_peek() local
1229 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1231 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1245 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_ack() local
1247 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_ack()
1252 snd_BUG_ON(runtime->avail + count > runtime->buffer_size); in __snd_rawmidi_transmit_ack()
1253 runtime->hw_ptr += count; in __snd_rawmidi_transmit_ack()
1254 runtime->hw_ptr %= runtime->buffer_size; in __snd_rawmidi_transmit_ack()
1255 runtime->avail += count; in __snd_rawmidi_transmit_ack()
1258 if (runtime->drain || snd_rawmidi_ready(substream)) in __snd_rawmidi_transmit_ack()
1259 wake_up(&runtime->sleep); in __snd_rawmidi_transmit_ack()
1278 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_ack() local
1282 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1284 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1302 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit() local
1306 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit()
1316 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit()
1329 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_proceed() local
1333 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_proceed()
1334 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_proceed()
1335 count = runtime->buffer_size - runtime->avail; in snd_rawmidi_proceed()
1338 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_proceed()
1350 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_write1() local
1355 if (snd_BUG_ON(!runtime->buffer)) in snd_rawmidi_kernel_write1()
1359 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1361 if ((long)runtime->avail < count) { in snd_rawmidi_kernel_write1()
1362 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1366 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_write1()
1367 while (count > 0 && runtime->avail > 0) { in snd_rawmidi_kernel_write1()
1368 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1371 if (count1 > (long)runtime->avail) in snd_rawmidi_kernel_write1()
1372 count1 = runtime->avail; in snd_rawmidi_kernel_write1()
1374 /* update runtime->appl_ptr before unlocking for userbuf */ in snd_rawmidi_kernel_write1()
1375 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1376 runtime->appl_ptr += count1; in snd_rawmidi_kernel_write1()
1377 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_write1()
1378 runtime->avail -= count1; in snd_rawmidi_kernel_write1()
1381 memcpy(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1384 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1385 if (copy_from_user(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1387 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1391 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1397 count1 = runtime->avail < runtime->buffer_size; in snd_rawmidi_kernel_write1()
1398 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_write1()
1399 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1418 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_write() local
1423 runtime = substream->runtime; in snd_rawmidi_write()
1425 if (substream->append && count > runtime->buffer_size) in snd_rawmidi_write()
1429 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1434 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1438 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1440 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1442 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1447 if (!runtime->avail && !timeout) in snd_rawmidi_write()
1449 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1451 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1462 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1463 while (runtime->avail != runtime->buffer_size) { in snd_rawmidi_write()
1465 unsigned int last_avail = runtime->avail; in snd_rawmidi_write()
1468 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1470 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1472 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1475 if (runtime->avail == last_avail && !timeout) in snd_rawmidi_write()
1477 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1479 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1487 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_poll() local
1492 runtime = rfile->input->runtime; in snd_rawmidi_poll()
1494 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1497 runtime = rfile->output->runtime; in snd_rawmidi_poll()
1498 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1528 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_proc_info_read() local
1546 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1551 runtime->oss ? "OSS compatible" : "native", in snd_rawmidi_proc_info_read()
1552 (unsigned long) runtime->buffer_size, in snd_rawmidi_proc_info_read()
1553 (unsigned long) runtime->avail); in snd_rawmidi_proc_info_read()
1570 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1575 (unsigned long) runtime->buffer_size, in snd_rawmidi_proc_info_read()
1576 (unsigned long) runtime->avail, in snd_rawmidi_proc_info_read()
1577 (unsigned long) runtime->xruns); in snd_rawmidi_proc_info_read()
1851 if (s->runtime) in snd_rawmidi_dev_disconnect()
1852 wake_up(&s->runtime->sleep); in snd_rawmidi_dev_disconnect()