Lines Matching defs:runtime

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