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
691 if (params->buffer_size != runtime->buffer_size) { in resize_runtime_buffer()
695 spin_lock_irq(&runtime->lock); in resize_runtime_buffer()
696 if (runtime->buffer_ref) { in resize_runtime_buffer()
697 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
701 oldbuf = runtime->buffer; in resize_runtime_buffer()
702 runtime->buffer = newbuf; in resize_runtime_buffer()
703 runtime->buffer_size = params->buffer_size; in resize_runtime_buffer()
704 __reset_runtime_ptrs(runtime, is_input); in resize_runtime_buffer()
705 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
708 runtime->avail_min = params->avail_min; in resize_runtime_buffer()
719 return resize_runtime_buffer(substream->runtime, params, false); in snd_rawmidi_output_params()
737 err = resize_runtime_buffer(substream->runtime, params, true); in snd_rawmidi_input_params()
750 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_output_status() local
754 spin_lock_irq(&runtime->lock); in snd_rawmidi_output_status()
755 status->avail = runtime->avail; in snd_rawmidi_output_status()
756 spin_unlock_irq(&runtime->lock); in snd_rawmidi_output_status()
763 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_input_status() local
767 spin_lock_irq(&runtime->lock); in snd_rawmidi_input_status()
768 status->avail = runtime->avail; in snd_rawmidi_input_status()
769 status->xruns = runtime->xruns; in snd_rawmidi_input_status()
770 runtime->xruns = 0; in snd_rawmidi_input_status()
771 spin_unlock_irq(&runtime->lock); in snd_rawmidi_input_status()
997 struct snd_rawmidi_runtime *runtime = substream->runtime; in receive_with_tstamp_framing() local
1005 if (snd_BUG_ON((runtime->hw_ptr & 0x1f) != 0)) in receive_with_tstamp_framing()
1009 if ((int)(runtime->buffer_size - runtime->avail) < frame_size) { in receive_with_tstamp_framing()
1010 runtime->xruns += src_count; in receive_with_tstamp_framing()
1022 dest_ptr = (struct snd_rawmidi_framing_tstamp *) (runtime->buffer + runtime->hw_ptr); in receive_with_tstamp_framing()
1024 runtime->avail += frame_size; in receive_with_tstamp_framing()
1025 runtime->hw_ptr += frame_size; in receive_with_tstamp_framing()
1026 runtime->hw_ptr %= runtime->buffer_size; in receive_with_tstamp_framing()
1066 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_receive() local
1070 if (runtime->buffer == NULL) { in snd_rawmidi_receive()
1076 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_receive()
1081 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_receive()
1082 runtime->buffer[runtime->hw_ptr++] = buffer[0]; in snd_rawmidi_receive()
1083 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
1084 runtime->avail++; in snd_rawmidi_receive()
1087 runtime->xruns++; in snd_rawmidi_receive()
1091 count1 = runtime->buffer_size - runtime->hw_ptr; in snd_rawmidi_receive()
1094 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in snd_rawmidi_receive()
1095 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1096 memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1); in snd_rawmidi_receive()
1097 runtime->hw_ptr += count1; in snd_rawmidi_receive()
1098 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
1099 runtime->avail += count1; in snd_rawmidi_receive()
1105 if (count1 > (int)(runtime->buffer_size - runtime->avail)) { in snd_rawmidi_receive()
1106 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1107 runtime->xruns += count - count1; in snd_rawmidi_receive()
1110 memcpy(runtime->buffer, buffer, count1); in snd_rawmidi_receive()
1111 runtime->hw_ptr = count1; in snd_rawmidi_receive()
1112 runtime->avail += count1; in snd_rawmidi_receive()
1118 if (runtime->event) in snd_rawmidi_receive()
1119 schedule_work(&runtime->event_work); in snd_rawmidi_receive()
1120 else if (__snd_rawmidi_ready(runtime)) in snd_rawmidi_receive()
1121 wake_up(&runtime->sleep); in snd_rawmidi_receive()
1123 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_receive()
1134 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_read1() local
1138 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1139 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_read1()
1140 while (count > 0 && runtime->avail) { in snd_rawmidi_kernel_read1()
1141 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1144 if (count1 > (int)runtime->avail) in snd_rawmidi_kernel_read1()
1145 count1 = runtime->avail; in snd_rawmidi_kernel_read1()
1147 /* update runtime->appl_ptr before unlocking for userbuf */ in snd_rawmidi_kernel_read1()
1148 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1149 runtime->appl_ptr += count1; in snd_rawmidi_kernel_read1()
1150 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_read1()
1151 runtime->avail -= count1; in snd_rawmidi_kernel_read1()
1154 memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1); in snd_rawmidi_kernel_read1()
1156 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1158 runtime->buffer + appl_ptr, count1)) in snd_rawmidi_kernel_read1()
1160 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1168 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_read1()
1169 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1188 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_read() local
1194 runtime = substream->runtime; in snd_rawmidi_read()
1198 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1199 while (!__snd_rawmidi_ready(runtime)) { in snd_rawmidi_read()
1203 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1207 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1209 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1211 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1216 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1217 if (!runtime->avail) { in snd_rawmidi_read()
1218 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1222 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1244 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_empty() local
1248 if (runtime->buffer == NULL) { in snd_rawmidi_transmit_empty()
1253 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1254 result = runtime->avail >= runtime->buffer_size; in snd_rawmidi_transmit_empty()
1255 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1272 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_peek() local
1274 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_peek()
1280 if (runtime->avail >= runtime->buffer_size) { in __snd_rawmidi_transmit_peek()
1285 *buffer = runtime->buffer[runtime->hw_ptr]; in __snd_rawmidi_transmit_peek()
1288 count1 = runtime->buffer_size - runtime->hw_ptr; in __snd_rawmidi_transmit_peek()
1291 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in __snd_rawmidi_transmit_peek()
1292 count1 = runtime->buffer_size - runtime->avail; in __snd_rawmidi_transmit_peek()
1293 memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1); in __snd_rawmidi_transmit_peek()
1297 if (count > (int)(runtime->buffer_size - runtime->avail - count1)) in __snd_rawmidi_transmit_peek()
1298 count = runtime->buffer_size - runtime->avail - count1; in __snd_rawmidi_transmit_peek()
1299 memcpy(buffer + count1, runtime->buffer, count); in __snd_rawmidi_transmit_peek()
1325 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_peek() local
1329 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1331 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1345 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_ack() local
1347 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_ack()
1352 snd_BUG_ON(runtime->avail + count > runtime->buffer_size); in __snd_rawmidi_transmit_ack()
1353 runtime->hw_ptr += count; in __snd_rawmidi_transmit_ack()
1354 runtime->hw_ptr %= runtime->buffer_size; in __snd_rawmidi_transmit_ack()
1355 runtime->avail += count; in __snd_rawmidi_transmit_ack()
1358 if (runtime->drain || __snd_rawmidi_ready(runtime)) in __snd_rawmidi_transmit_ack()
1359 wake_up(&runtime->sleep); in __snd_rawmidi_transmit_ack()
1378 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_ack() local
1382 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1384 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1402 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit() local
1406 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit()
1416 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit()
1429 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_proceed() local
1433 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_proceed()
1434 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_proceed()
1435 count = runtime->buffer_size - runtime->avail; in snd_rawmidi_proceed()
1438 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_proceed()
1450 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_write1() local
1455 if (snd_BUG_ON(!runtime->buffer)) in snd_rawmidi_kernel_write1()
1459 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1461 if ((long)runtime->avail < count) { in snd_rawmidi_kernel_write1()
1462 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1466 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_write1()
1467 while (count > 0 && runtime->avail > 0) { in snd_rawmidi_kernel_write1()
1468 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1471 if (count1 > (long)runtime->avail) in snd_rawmidi_kernel_write1()
1472 count1 = runtime->avail; in snd_rawmidi_kernel_write1()
1474 /* update runtime->appl_ptr before unlocking for userbuf */ in snd_rawmidi_kernel_write1()
1475 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1476 runtime->appl_ptr += count1; in snd_rawmidi_kernel_write1()
1477 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_write1()
1478 runtime->avail -= count1; in snd_rawmidi_kernel_write1()
1481 memcpy(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1484 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1485 if (copy_from_user(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1487 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1491 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1497 count1 = runtime->avail < runtime->buffer_size; in snd_rawmidi_kernel_write1()
1498 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_write1()
1499 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1518 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_write() local
1523 runtime = substream->runtime; in snd_rawmidi_write()
1525 if (substream->append && count > runtime->buffer_size) in snd_rawmidi_write()
1529 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1534 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1538 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1540 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1542 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1547 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1548 if (!runtime->avail && !timeout) { in snd_rawmidi_write()
1549 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1553 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1564 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1565 while (runtime->avail != runtime->buffer_size) { in snd_rawmidi_write()
1567 unsigned int last_avail = runtime->avail; in snd_rawmidi_write()
1570 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1572 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1574 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1577 if (runtime->avail == last_avail && !timeout) in snd_rawmidi_write()
1579 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1581 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1589 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_poll() local
1594 runtime = rfile->input->runtime; in snd_rawmidi_poll()
1596 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1599 runtime = rfile->output->runtime; in snd_rawmidi_poll()
1600 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1630 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_proc_info_read() local
1651 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1652 spin_lock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1653 buffer_size = runtime->buffer_size; in snd_rawmidi_proc_info_read()
1654 avail = runtime->avail; in snd_rawmidi_proc_info_read()
1655 spin_unlock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1660 runtime->oss ? "OSS compatible" : "native", in snd_rawmidi_proc_info_read()
1678 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1679 spin_lock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1680 buffer_size = runtime->buffer_size; in snd_rawmidi_proc_info_read()
1681 avail = runtime->avail; in snd_rawmidi_proc_info_read()
1682 xruns = runtime->xruns; in snd_rawmidi_proc_info_read()
1683 spin_unlock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1970 if (s->runtime) in snd_rawmidi_dev_disconnect()
1971 wake_up(&s->runtime->sleep); in snd_rawmidi_dev_disconnect()