Lines Matching refs: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()
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()
484 if (rawmidi_file->input && rawmidi_file->input->runtime) in snd_rawmidi_open()
485 rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR); in snd_rawmidi_open()
486 if (rawmidi_file->output && rawmidi_file->output->runtime) in snd_rawmidi_open()
487 rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR); in snd_rawmidi_open()
526 if (substream->runtime->private_free) in close_substream()
527 substream->runtime->private_free(substream); in close_substream()
679 static int resize_runtime_buffer(struct snd_rawmidi_runtime *runtime, in resize_runtime_buffer() argument
692 if (params->buffer_size != runtime->buffer_size) { in resize_runtime_buffer()
696 spin_lock_irq(&runtime->lock); in resize_runtime_buffer()
697 if (runtime->buffer_ref) { in resize_runtime_buffer()
698 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
702 oldbuf = runtime->buffer; in resize_runtime_buffer()
703 runtime->buffer = newbuf; in resize_runtime_buffer()
704 runtime->buffer_size = params->buffer_size; in resize_runtime_buffer()
705 __reset_runtime_ptrs(runtime, is_input); in resize_runtime_buffer()
706 spin_unlock_irq(&runtime->lock); in resize_runtime_buffer()
709 runtime->avail_min = params->avail_min; in resize_runtime_buffer()
720 return resize_runtime_buffer(substream->runtime, params, false); in snd_rawmidi_output_params()
738 err = resize_runtime_buffer(substream->runtime, params, true); in snd_rawmidi_input_params()
751 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_output_status() local
755 spin_lock_irq(&runtime->lock); in snd_rawmidi_output_status()
756 status->avail = runtime->avail; in snd_rawmidi_output_status()
757 spin_unlock_irq(&runtime->lock); in snd_rawmidi_output_status()
764 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_input_status() local
768 spin_lock_irq(&runtime->lock); in snd_rawmidi_input_status()
769 status->avail = runtime->avail; in snd_rawmidi_input_status()
770 status->xruns = runtime->xruns; in snd_rawmidi_input_status()
771 runtime->xruns = 0; in snd_rawmidi_input_status()
772 spin_unlock_irq(&runtime->lock); in snd_rawmidi_input_status()
998 struct snd_rawmidi_runtime *runtime = substream->runtime; in receive_with_tstamp_framing() local
1006 if (snd_BUG_ON((runtime->hw_ptr & 0x1f) != 0)) in receive_with_tstamp_framing()
1010 if ((int)(runtime->buffer_size - runtime->avail) < frame_size) { in receive_with_tstamp_framing()
1011 runtime->xruns += src_count; in receive_with_tstamp_framing()
1023 dest_ptr = (struct snd_rawmidi_framing_tstamp *) (runtime->buffer + runtime->hw_ptr); in receive_with_tstamp_framing()
1025 runtime->avail += frame_size; in receive_with_tstamp_framing()
1026 runtime->hw_ptr += frame_size; in receive_with_tstamp_framing()
1027 runtime->hw_ptr %= runtime->buffer_size; in receive_with_tstamp_framing()
1067 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_receive() local
1071 if (runtime->buffer == NULL) { in snd_rawmidi_receive()
1077 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_receive()
1082 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_receive()
1083 runtime->buffer[runtime->hw_ptr++] = buffer[0]; in snd_rawmidi_receive()
1084 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
1085 runtime->avail++; in snd_rawmidi_receive()
1088 runtime->xruns++; in snd_rawmidi_receive()
1092 count1 = runtime->buffer_size - runtime->hw_ptr; in snd_rawmidi_receive()
1095 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in snd_rawmidi_receive()
1096 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1097 memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1); in snd_rawmidi_receive()
1098 runtime->hw_ptr += count1; in snd_rawmidi_receive()
1099 runtime->hw_ptr %= runtime->buffer_size; in snd_rawmidi_receive()
1100 runtime->avail += count1; in snd_rawmidi_receive()
1106 if (count1 > (int)(runtime->buffer_size - runtime->avail)) { in snd_rawmidi_receive()
1107 count1 = runtime->buffer_size - runtime->avail; in snd_rawmidi_receive()
1108 runtime->xruns += count - count1; in snd_rawmidi_receive()
1111 memcpy(runtime->buffer, buffer, count1); in snd_rawmidi_receive()
1112 runtime->hw_ptr = count1; in snd_rawmidi_receive()
1113 runtime->avail += count1; in snd_rawmidi_receive()
1119 if (runtime->event) in snd_rawmidi_receive()
1120 schedule_work(&runtime->event_work); in snd_rawmidi_receive()
1121 else if (__snd_rawmidi_ready(runtime)) in snd_rawmidi_receive()
1122 wake_up(&runtime->sleep); in snd_rawmidi_receive()
1124 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_receive()
1135 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_read1() local
1139 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1140 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_read1()
1141 while (count > 0 && runtime->avail) { in snd_rawmidi_kernel_read1()
1142 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1145 if (count1 > (int)runtime->avail) in snd_rawmidi_kernel_read1()
1146 count1 = runtime->avail; in snd_rawmidi_kernel_read1()
1149 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_read1()
1150 runtime->appl_ptr += count1; in snd_rawmidi_kernel_read1()
1151 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_read1()
1152 runtime->avail -= count1; in snd_rawmidi_kernel_read1()
1155 memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1); in snd_rawmidi_kernel_read1()
1157 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1159 runtime->buffer + appl_ptr, count1)) in snd_rawmidi_kernel_read1()
1161 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1169 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_read1()
1170 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_read1()
1189 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_read() local
1195 runtime = substream->runtime; in snd_rawmidi_read()
1199 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1200 while (!__snd_rawmidi_ready(runtime)) { in snd_rawmidi_read()
1204 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1208 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1210 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1212 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_read()
1217 spin_lock_irq(&runtime->lock); in snd_rawmidi_read()
1218 if (!runtime->avail) { in snd_rawmidi_read()
1219 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1223 spin_unlock_irq(&runtime->lock); in snd_rawmidi_read()
1245 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_empty() local
1249 if (runtime->buffer == NULL) { in snd_rawmidi_transmit_empty()
1254 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1255 result = runtime->avail >= runtime->buffer_size; in snd_rawmidi_transmit_empty()
1256 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_empty()
1273 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_peek() local
1275 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_peek()
1281 if (runtime->avail >= runtime->buffer_size) { in __snd_rawmidi_transmit_peek()
1286 *buffer = runtime->buffer[runtime->hw_ptr]; in __snd_rawmidi_transmit_peek()
1289 count1 = runtime->buffer_size - runtime->hw_ptr; in __snd_rawmidi_transmit_peek()
1292 if (count1 > (int)(runtime->buffer_size - runtime->avail)) in __snd_rawmidi_transmit_peek()
1293 count1 = runtime->buffer_size - runtime->avail; in __snd_rawmidi_transmit_peek()
1294 memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1); in __snd_rawmidi_transmit_peek()
1298 if (count > (int)(runtime->buffer_size - runtime->avail - count1)) in __snd_rawmidi_transmit_peek()
1299 count = runtime->buffer_size - runtime->avail - count1; in __snd_rawmidi_transmit_peek()
1300 memcpy(buffer + count1, runtime->buffer, count); in __snd_rawmidi_transmit_peek()
1326 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_peek() local
1330 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1332 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_peek()
1346 struct snd_rawmidi_runtime *runtime = substream->runtime; in __snd_rawmidi_transmit_ack() local
1348 if (runtime->buffer == NULL) { in __snd_rawmidi_transmit_ack()
1353 snd_BUG_ON(runtime->avail + count > runtime->buffer_size); in __snd_rawmidi_transmit_ack()
1354 runtime->hw_ptr += count; in __snd_rawmidi_transmit_ack()
1355 runtime->hw_ptr %= runtime->buffer_size; in __snd_rawmidi_transmit_ack()
1356 runtime->avail += count; in __snd_rawmidi_transmit_ack()
1359 if (runtime->drain || __snd_rawmidi_ready(runtime)) in __snd_rawmidi_transmit_ack()
1360 wake_up(&runtime->sleep); in __snd_rawmidi_transmit_ack()
1379 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit_ack() local
1383 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1385 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit_ack()
1403 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_transmit() local
1407 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_transmit()
1417 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_transmit()
1430 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_proceed() local
1434 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_proceed()
1435 if (runtime->avail < runtime->buffer_size) { in snd_rawmidi_proceed()
1436 count = runtime->buffer_size - runtime->avail; in snd_rawmidi_proceed()
1439 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_proceed()
1451 struct snd_rawmidi_runtime *runtime = substream->runtime; in snd_rawmidi_kernel_write1() local
1456 if (snd_BUG_ON(!runtime->buffer)) in snd_rawmidi_kernel_write1()
1460 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1462 if ((long)runtime->avail < count) { in snd_rawmidi_kernel_write1()
1463 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1467 snd_rawmidi_buffer_ref(runtime); in snd_rawmidi_kernel_write1()
1468 while (count > 0 && runtime->avail > 0) { in snd_rawmidi_kernel_write1()
1469 count1 = runtime->buffer_size - runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1472 if (count1 > (long)runtime->avail) in snd_rawmidi_kernel_write1()
1473 count1 = runtime->avail; in snd_rawmidi_kernel_write1()
1476 appl_ptr = runtime->appl_ptr; in snd_rawmidi_kernel_write1()
1477 runtime->appl_ptr += count1; in snd_rawmidi_kernel_write1()
1478 runtime->appl_ptr %= runtime->buffer_size; in snd_rawmidi_kernel_write1()
1479 runtime->avail -= count1; in snd_rawmidi_kernel_write1()
1482 memcpy(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1485 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1486 if (copy_from_user(runtime->buffer + appl_ptr, in snd_rawmidi_kernel_write1()
1488 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1492 spin_lock_irqsave(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1498 count1 = runtime->avail < runtime->buffer_size; in snd_rawmidi_kernel_write1()
1499 snd_rawmidi_buffer_unref(runtime); in snd_rawmidi_kernel_write1()
1500 spin_unlock_irqrestore(&runtime->lock, flags); in snd_rawmidi_kernel_write1()
1519 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_write() local
1524 runtime = substream->runtime; in snd_rawmidi_write()
1526 if (substream->append && count > runtime->buffer_size) in snd_rawmidi_write()
1530 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1535 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1539 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1541 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1543 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1548 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1549 if (!runtime->avail && !timeout) { in snd_rawmidi_write()
1550 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1554 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1565 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1566 while (runtime->avail != runtime->buffer_size) { in snd_rawmidi_write()
1568 unsigned int last_avail = runtime->avail; in snd_rawmidi_write()
1571 add_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1573 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1575 remove_wait_queue(&runtime->sleep, &wait); in snd_rawmidi_write()
1578 if (runtime->avail == last_avail && !timeout) in snd_rawmidi_write()
1580 spin_lock_irq(&runtime->lock); in snd_rawmidi_write()
1582 spin_unlock_irq(&runtime->lock); in snd_rawmidi_write()
1590 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_poll() local
1595 runtime = rfile->input->runtime; in snd_rawmidi_poll()
1597 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1600 runtime = rfile->output->runtime; in snd_rawmidi_poll()
1601 poll_wait(file, &runtime->sleep, wait); in snd_rawmidi_poll()
1631 struct snd_rawmidi_runtime *runtime; in snd_rawmidi_proc_info_read() local
1652 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1653 spin_lock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1654 buffer_size = runtime->buffer_size; in snd_rawmidi_proc_info_read()
1655 avail = runtime->avail; in snd_rawmidi_proc_info_read()
1656 spin_unlock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1661 runtime->oss ? "OSS compatible" : "native", in snd_rawmidi_proc_info_read()
1679 runtime = substream->runtime; in snd_rawmidi_proc_info_read()
1680 spin_lock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1681 buffer_size = runtime->buffer_size; in snd_rawmidi_proc_info_read()
1682 avail = runtime->avail; in snd_rawmidi_proc_info_read()
1683 xruns = runtime->xruns; in snd_rawmidi_proc_info_read()
1684 spin_unlock_irq(&runtime->lock); in snd_rawmidi_proc_info_read()
1971 if (s->runtime) in snd_rawmidi_dev_disconnect()
1972 wake_up(&s->runtime->sleep); in snd_rawmidi_dev_disconnect()