Lines Matching refs:runtime
101 static inline bool __snd_rawmidi_ready(struct snd_rawmidi_runtime *runtime)
103 return runtime->avail >= runtime->avail_min;
109 return __snd_rawmidi_ready(substream->runtime);
115 struct snd_rawmidi_runtime *runtime = substream->runtime;
117 return runtime->avail >= runtime->avail_min &&
118 (!substream->append || runtime->avail >= count);
123 struct snd_rawmidi_runtime *runtime =
126 if (runtime->event)
127 runtime->event(runtime->substream);
131 static inline void snd_rawmidi_buffer_ref(struct snd_rawmidi_runtime *runtime)
133 runtime->buffer_ref++;
136 static inline void snd_rawmidi_buffer_unref(struct snd_rawmidi_runtime *runtime)
138 runtime->buffer_ref--;
146 while (substream->runtime->buffer_ref) {
160 struct snd_rawmidi_runtime *runtime;
162 runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
163 if (!runtime)
165 runtime->substream = substream;
166 init_waitqueue_head(&runtime->sleep);
167 INIT_WORK(&runtime->event_work, snd_rawmidi_input_event_work);
168 runtime->event = NULL;
169 runtime->buffer_size = PAGE_SIZE;
170 runtime->avail_min = 1;
172 runtime->avail = 0;
174 runtime->avail = runtime->buffer_size;
175 runtime->buffer = kvzalloc(runtime->buffer_size, GFP_KERNEL);
176 if (!runtime->buffer) {
177 kfree(runtime);
180 runtime->appl_ptr = runtime->hw_ptr = 0;
181 substream->runtime = runtime;
183 runtime->align = 3;
188 static inline int get_align(struct snd_rawmidi_runtime *runtime)
191 return runtime->align;
197 #define get_aligned_size(runtime, size) ((size) & ~get_align(runtime))
201 struct snd_rawmidi_runtime *runtime = substream->runtime;
203 kvfree(runtime->buffer);
204 kfree(runtime);
205 substream->runtime = NULL;
222 cancel_work_sync(&substream->runtime->event_work);
225 static void __reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime,
228 runtime->drain = 0;
229 runtime->appl_ptr = runtime->hw_ptr = 0;
230 runtime->avail = is_input ? 0 : runtime->buffer_size;
237 if (substream->opened && substream->runtime)
238 __reset_runtime_ptrs(substream->runtime, is_input);
253 struct snd_rawmidi_runtime *runtime;
256 runtime = substream->runtime;
257 if (!substream->opened || !runtime || !runtime->buffer)
259 snd_rawmidi_buffer_ref(runtime);
260 runtime->drain = 1;
263 timeout = wait_event_interruptible_timeout(runtime->sleep,
264 (runtime->avail >= runtime->buffer_size),
270 if (runtime->avail < runtime->buffer_size && !timeout) {
273 (long)runtime->avail, (long)runtime->buffer_size);
276 runtime->drain = 0;
289 snd_rawmidi_buffer_unref(runtime);
514 if (rawmidi_file->input && rawmidi_file->input->runtime)
515 rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR);
516 if (rawmidi_file->output && rawmidi_file->output->runtime)
517 rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR);
561 if (substream->runtime->private_free)
562 substream->runtime->private_free(substream);
714 struct snd_rawmidi_runtime *runtime = substream->runtime;
724 if (params->buffer_size & get_align(runtime))
726 if (params->buffer_size != runtime->buffer_size) {
731 if (runtime->buffer_ref) {
736 oldbuf = runtime->buffer;
737 runtime->buffer = newbuf;
738 runtime->buffer_size = params->buffer_size;
739 __reset_runtime_ptrs(runtime, is_input);
743 runtime->avail_min = params->avail_min;
792 struct snd_rawmidi_runtime *runtime = substream->runtime;
797 status->avail = runtime->avail;
804 struct snd_rawmidi_runtime *runtime = substream->runtime;
809 status->avail = runtime->avail;
810 status->xruns = runtime->xruns;
811 runtime->xruns = 0;
1079 struct snd_rawmidi_runtime *runtime = substream->runtime;
1084 int align = get_align(runtime);
1087 if (snd_BUG_ON((runtime->hw_ptr & 0x1f) != 0))
1091 if ((int)(runtime->buffer_size - runtime->avail) < frame_size) {
1092 runtime->xruns += src_count;
1098 frame.length = get_aligned_size(runtime, src_count);
1106 dest_ptr = (struct snd_rawmidi_framing_tstamp *) (runtime->buffer + runtime->hw_ptr);
1108 runtime->avail += frame_size;
1109 runtime->hw_ptr += frame_size;
1110 runtime->hw_ptr %= runtime->buffer_size;
1148 struct snd_rawmidi_runtime *runtime;
1153 runtime = substream->runtime;
1154 if (!runtime || !runtime->buffer) {
1160 count = get_aligned_size(runtime, count);
1168 if (runtime->avail < runtime->buffer_size) {
1169 runtime->buffer[runtime->hw_ptr++] = buffer[0];
1170 runtime->hw_ptr %= runtime->buffer_size;
1171 runtime->avail++;
1174 runtime->xruns++;
1178 count1 = runtime->buffer_size - runtime->hw_ptr;
1181 if (count1 > (int)(runtime->buffer_size - runtime->avail))
1182 count1 = runtime->buffer_size - runtime->avail;
1183 count1 = get_aligned_size(runtime, count1);
1186 memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1);
1187 runtime->hw_ptr += count1;
1188 runtime->hw_ptr %= runtime->buffer_size;
1189 runtime->avail += count1;
1195 if (count1 > (int)(runtime->buffer_size - runtime->avail)) {
1196 count1 = runtime->buffer_size - runtime->avail;
1197 runtime->xruns += count - count1;
1200 memcpy(runtime->buffer, buffer, count1);
1201 runtime->hw_ptr = count1;
1202 runtime->avail += count1;
1208 if (runtime->event)
1209 schedule_work(&runtime->event_work);
1210 else if (__snd_rawmidi_ready(runtime))
1211 wake_up(&runtime->sleep);
1223 struct snd_rawmidi_runtime *runtime = substream->runtime;
1228 snd_rawmidi_buffer_ref(runtime);
1229 while (count > 0 && runtime->avail) {
1230 count1 = runtime->buffer_size - runtime->appl_ptr;
1233 if (count1 > (int)runtime->avail)
1234 count1 = runtime->avail;
1236 /* update runtime->appl_ptr before unlocking for userbuf */
1237 appl_ptr = runtime->appl_ptr;
1238 runtime->appl_ptr += count1;
1239 runtime->appl_ptr %= runtime->buffer_size;
1240 runtime->avail -= count1;
1243 memcpy(kernelbuf + result, runtime->buffer + appl_ptr, count1);
1247 runtime->buffer + appl_ptr, count1))
1257 snd_rawmidi_buffer_unref(runtime);
1277 struct snd_rawmidi_runtime *runtime;
1283 runtime = substream->runtime;
1288 while (!__snd_rawmidi_ready(runtime)) {
1296 add_wait_queue(&runtime->sleep, &wait);
1300 remove_wait_queue(&runtime->sleep, &wait);
1306 if (!runtime->avail) {
1333 struct snd_rawmidi_runtime *runtime;
1336 runtime = substream->runtime;
1337 if (!substream->opened || !runtime || !runtime->buffer) {
1342 return (runtime->avail >= runtime->buffer_size);
1358 struct snd_rawmidi_runtime *runtime = substream->runtime;
1360 if (runtime->buffer == NULL) {
1366 if (runtime->avail >= runtime->buffer_size) {
1371 *buffer = runtime->buffer[runtime->hw_ptr];
1374 count1 = runtime->buffer_size - runtime->hw_ptr;
1377 if (count1 > (int)(runtime->buffer_size - runtime->avail))
1378 count1 = runtime->buffer_size - runtime->avail;
1379 count1 = get_aligned_size(runtime, count1);
1382 memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1);
1386 if (count > (int)(runtime->buffer_size - runtime->avail - count1))
1387 count = runtime->buffer_size - runtime->avail - count1;
1388 count = get_aligned_size(runtime, count);
1391 memcpy(buffer + count1, runtime->buffer, count);
1417 if (!substream->opened || !substream->runtime)
1433 struct snd_rawmidi_runtime *runtime = substream->runtime;
1435 if (runtime->buffer == NULL) {
1440 snd_BUG_ON(runtime->avail + count > runtime->buffer_size);
1441 count = get_aligned_size(runtime, count);
1442 runtime->hw_ptr += count;
1443 runtime->hw_ptr %= runtime->buffer_size;
1444 runtime->avail += count;
1447 if (runtime->drain || __snd_rawmidi_ready(runtime))
1448 wake_up(&runtime->sleep);
1467 if (!substream->opened || !substream->runtime)
1504 struct snd_rawmidi_runtime *runtime;
1508 runtime = substream->runtime;
1509 if (substream->opened && runtime &&
1510 runtime->avail < runtime->buffer_size) {
1511 count = runtime->buffer_size - runtime->avail;
1525 struct snd_rawmidi_runtime *runtime = substream->runtime;
1530 if (snd_BUG_ON(!runtime->buffer))
1536 if ((long)runtime->avail < count) {
1541 snd_rawmidi_buffer_ref(runtime);
1542 while (count > 0 && runtime->avail > 0) {
1543 count1 = runtime->buffer_size - runtime->appl_ptr;
1546 if (count1 > (long)runtime->avail)
1547 count1 = runtime->avail;
1549 /* update runtime->appl_ptr before unlocking for userbuf */
1550 appl_ptr = runtime->appl_ptr;
1551 runtime->appl_ptr += count1;
1552 runtime->appl_ptr %= runtime->buffer_size;
1553 runtime->avail -= count1;
1556 memcpy(runtime->buffer + appl_ptr,
1560 if (copy_from_user(runtime->buffer + appl_ptr,
1572 count1 = runtime->avail < runtime->buffer_size;
1573 snd_rawmidi_buffer_unref(runtime);
1593 struct snd_rawmidi_runtime *runtime;
1598 runtime = substream->runtime;
1600 if (substream->append && count > runtime->buffer_size)
1613 add_wait_queue(&runtime->sleep, &wait);
1617 remove_wait_queue(&runtime->sleep, &wait);
1623 if (!runtime->avail && !timeout) {
1640 while (runtime->avail != runtime->buffer_size) {
1642 unsigned int last_avail = runtime->avail;
1645 add_wait_queue(&runtime->sleep, &wait);
1649 remove_wait_queue(&runtime->sleep, &wait);
1652 if (runtime->avail == last_avail && !timeout)
1664 struct snd_rawmidi_runtime *runtime;
1669 runtime = rfile->input->runtime;
1671 poll_wait(file, &runtime->sleep, wait);
1674 runtime = rfile->output->runtime;
1675 poll_wait(file, &runtime->sleep, wait);
1705 struct snd_rawmidi_runtime *runtime;
1731 runtime = substream->runtime;
1733 buffer_size = runtime->buffer_size;
1734 avail = runtime->avail;
1740 runtime->oss ? "OSS compatible" : "native",
1758 runtime = substream->runtime;
1760 buffer_size = runtime->buffer_size;
1761 avail = runtime->avail;
1762 xruns = runtime->xruns;
2063 if (s->runtime)
2064 wake_up(&s->runtime->sleep);