This source file includes following definitions.
- reorganize_buffers
- dma_init_buffers
- open_dmap
- close_dmap
- DMAbuf_open
- dma_reset
- dma_reset_output
- dma_reset_input
- dma_sync
- DMAbuf_release
- activate_recording
- DMAbuf_getrdbuffer
- DMAbuf_rmchars
- dma_subdivide
- dma_set_fragment
- get_buffer_pointer
- DMAbuf_ioctl
- DMAbuf_start_devices
- space_in_queue
- DMAbuf_getwrbuffer
- DMAbuf_get_curr_buffer
- DMAbuf_set_count
- DMAbuf_start_output
- DMAbuf_start_dma
- DMAbuf_init
- DMAbuf_outputintr
- DMAbuf_inputintr
- DMAbuf_open_dma
- DMAbuf_close_dma
- DMAbuf_reset_dma
- DMAbuf_select
- DMAbuf_open
- DMAbuf_release
- DMAbuf_getwrbuffer
- DMAbuf_getrdbuffer
- DMAbuf_rmchars
- DMAbuf_start_output
- DMAbuf_ioctl
- DMAbuf_init
- DMAbuf_start_dma
- DMAbuf_open_dma
- DMAbuf_close_dma
- DMAbuf_reset_dma
- DMAbuf_inputintr
- DMAbuf_outputintr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #include "sound_config.h"
31
32 #if defined(CONFIG_AUDIO) || defined(CONFIG_GUS)
33
34 static wait_handle *in_sleeper[MAX_AUDIO_DEV] =
35 {NULL};
36 static volatile struct snd_wait in_sleep_flag[MAX_AUDIO_DEV] =
37 {
38 {0}};
39 static wait_handle *out_sleeper[MAX_AUDIO_DEV] =
40 {NULL};
41 static volatile struct snd_wait out_sleep_flag[MAX_AUDIO_DEV] =
42 {
43 {0}};
44
45 static int ndmaps = 0;
46
47 #define MAX_DMAP (MAX_AUDIO_DEV*2)
48
49 static struct dma_buffparms dmaps[MAX_DMAP] =
50 {
51 {0}};
52
53
54
55
56
57 static int space_in_queue (int dev);
58
59 static void dma_reset_output (int dev);
60 static void dma_reset_input (int dev);
61
62 static void
63 reorganize_buffers (int dev, struct dma_buffparms *dmap)
64 {
65
66
67
68
69 struct audio_operations *dsp_dev = audio_devs[dev];
70
71 unsigned i, n;
72 unsigned sr, nc, sz, bsz;
73
74 if (dmap->fragment_size == 0)
75 {
76
77 sr = dsp_dev->ioctl (dev, SOUND_PCM_READ_RATE, 0, 1);
78 nc = dsp_dev->ioctl (dev, SOUND_PCM_READ_CHANNELS, 0, 1);
79 sz = dsp_dev->ioctl (dev, SOUND_PCM_READ_BITS, 0, 1);
80
81 if (sz == 8)
82 dmap->neutral_byte = 0x80;
83 else
84 dmap->neutral_byte = 0x00;
85
86 if (sr < 1 || nc < 1 || sz < 1)
87 {
88 printk ("Warning: Invalid PCM parameters[%d] sr=%d, nc=%d, sz=%d\n",
89 dev, sr, nc, sz);
90 sr = DSP_DEFAULT_SPEED;
91 nc = 1;
92 sz = 8;
93 }
94
95 sz = sr * nc * sz;
96
97 sz /= 8;
98
99
100
101
102
103
104
105 bsz = dsp_dev->buffsize;
106 while (bsz > sz)
107 bsz /= 2;
108
109 if (bsz == dsp_dev->buffsize)
110 bsz /= 2;
111
112 if (dmap->subdivision == 0)
113 dmap->subdivision = 1;
114 else
115 bsz /= dmap->subdivision;
116
117 if (bsz < 16)
118 bsz = 16;
119
120 dmap->fragment_size = bsz;
121 }
122 else
123 {
124
125
126
127
128 if (dmap->fragment_size > (audio_devs[dev]->buffsize / 2))
129 dmap->fragment_size = (audio_devs[dev]->buffsize / 2);
130 bsz = dmap->fragment_size;
131 }
132
133 bsz &= ~0x03;
134 #ifdef OS_DMA_ALIGN_CHECK
135 OS_DMA_ALIGN_CHECK (bsz);
136 #endif
137
138 n = dsp_dev->buffsize / bsz;
139 if (n > MAX_SUB_BUFFERS)
140 n = MAX_SUB_BUFFERS;
141 if (n > dmap->max_fragments)
142 n = dmap->max_fragments;
143 dmap->nbufs = n;
144 dmap->bytes_in_use = n * bsz;
145
146 for (i = 0; i < dmap->nbufs; i++)
147 {
148 dmap->counts[i] = 0;
149 }
150
151 dmap->flags |= DMA_ALLOC_DONE;
152 }
153
154 static void
155 dma_init_buffers (int dev, struct dma_buffparms *dmap)
156 {
157 if (dmap == audio_devs[dev]->dmap_out)
158 {
159 out_sleep_flag[dev].mode = WK_NONE;
160 }
161 else
162 {
163 in_sleep_flag[dev].mode = WK_NONE;
164 }
165
166 dmap->flags = DMA_BUSY;
167 dmap->qlen = dmap->qhead = dmap->qtail = 0;
168 dmap->nbufs = 1;
169 dmap->bytes_in_use = audio_devs[dev]->buffsize;
170
171 dmap->dma_mode = DMODE_NONE;
172 dmap->mapping_flags = 0;
173 dmap->neutral_byte = 0x00;
174 dmap->cfrag = -1;
175 dmap->closing = 0;
176 }
177
178 static int
179 open_dmap (int dev, int mode, struct dma_buffparms *dmap, int chan)
180 {
181 if (dmap->flags & DMA_BUSY)
182 return -EBUSY;
183
184 {
185 int err;
186
187 if ((err = sound_alloc_dmap (dev, dmap, chan)) < 0)
188 return err;
189 }
190
191 if (dmap->raw_buf == NULL)
192 return -ENOSPC;
193
194 if (sound_open_dma (chan, audio_devs[dev]->name))
195 {
196 printk ("Unable to grab(2) DMA%d for the audio driver\n", chan);
197 return -EBUSY;
198 }
199
200 dmap->open_mode = mode;
201 dmap->subdivision = dmap->underrun_count = 0;
202 dmap->fragment_size = 0;
203 dmap->max_fragments = 65536;
204 dmap->byte_counter = 0;
205
206 dma_init_buffers (dev, dmap);
207
208 return 0;
209 }
210
211 static void
212 close_dmap (int dev, struct dma_buffparms *dmap, int chan)
213 {
214 sound_close_dma (chan);
215
216 if (dmap->flags & DMA_BUSY)
217 dmap->dma_mode = DMODE_NONE;
218 dmap->flags &= ~DMA_BUSY;
219
220 sound_free_dmap (dev, dmap);
221 }
222
223 int
224 DMAbuf_open (int dev, int mode)
225 {
226 int retval;
227 struct dma_buffparms *dmap_in = NULL;
228 struct dma_buffparms *dmap_out = NULL;
229
230 if (dev >= num_audiodevs)
231 {
232 printk ("PCM device %d not installed.\n", dev);
233 return -ENXIO;
234 }
235
236 if (!audio_devs[dev])
237 {
238 printk ("PCM device %d not initialized\n", dev);
239 return -ENXIO;
240 }
241
242 if (!(audio_devs[dev]->flags & DMA_DUPLEX))
243 {
244 audio_devs[dev]->dmap_in = audio_devs[dev]->dmap_out;
245 audio_devs[dev]->dmachan2 = audio_devs[dev]->dmachan1;
246 }
247
248 if ((retval = audio_devs[dev]->open (dev, mode)) < 0)
249 return retval;
250
251 dmap_out = audio_devs[dev]->dmap_out;
252 dmap_in = audio_devs[dev]->dmap_in;
253
254 if ((retval = open_dmap (dev, mode, dmap_out, audio_devs[dev]->dmachan1)) < 0)
255 {
256 audio_devs[dev]->close (dev);
257 return retval;
258 }
259
260 audio_devs[dev]->enable_bits = mode;
261 if (audio_devs[dev]->flags & DMA_DUPLEX && dmap_out != dmap_in)
262 if ((retval = open_dmap (dev, mode, dmap_in, audio_devs[dev]->dmachan2)) < 0)
263 {
264 audio_devs[dev]->close (dev);
265 close_dmap (dev, dmap_out, audio_devs[dev]->dmachan1);
266 return retval;
267 }
268 audio_devs[dev]->open_mode = mode;
269 audio_devs[dev]->go = 1;
270 in_sleep_flag[dev].mode = WK_NONE;
271 out_sleep_flag[dev].mode = WK_NONE;
272
273 audio_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_BITS, (ioctl_arg) 8, 1);
274 audio_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_CHANNELS, (ioctl_arg) 1, 1);
275 audio_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_RATE, (ioctl_arg) DSP_DEFAULT_SPEED, 1);
276
277 return 0;
278 }
279
280 static void
281 dma_reset (int dev)
282 {
283 unsigned long flags;
284
285 save_flags (flags);
286 cli ();
287 audio_devs[dev]->reset (dev);
288 restore_flags (flags);
289
290 dma_reset_output (dev);
291
292 if (audio_devs[dev]->flags & DMA_DUPLEX)
293 dma_reset_input (dev);
294 }
295
296 static void
297 dma_reset_output (int dev)
298 {
299 unsigned long flags;
300
301 save_flags (flags);
302 cli ();
303 if (!(audio_devs[dev]->flags & DMA_DUPLEX) ||
304 !audio_devs[dev]->halt_output)
305 audio_devs[dev]->reset (dev);
306 else
307 audio_devs[dev]->halt_output (dev);
308 restore_flags (flags);
309
310 dma_init_buffers (dev, audio_devs[dev]->dmap_out);
311 reorganize_buffers (dev, audio_devs[dev]->dmap_out);
312 }
313
314 static void
315 dma_reset_input (int dev)
316 {
317 unsigned long flags;
318
319 save_flags (flags);
320 cli ();
321 if (!(audio_devs[dev]->flags & DMA_DUPLEX) ||
322 !audio_devs[dev]->halt_input)
323 audio_devs[dev]->reset (dev);
324 else
325 audio_devs[dev]->halt_input (dev);
326 restore_flags (flags);
327
328 dma_init_buffers (dev, audio_devs[dev]->dmap_in);
329 reorganize_buffers (dev, audio_devs[dev]->dmap_in);
330 }
331
332 static int
333 dma_sync (int dev)
334 {
335 unsigned long flags;
336
337 if (!audio_devs[dev]->go && (!audio_devs[dev]->enable_bits & PCM_ENABLE_OUTPUT))
338 return 0;
339
340 if (audio_devs[dev]->dmap_out->dma_mode == DMODE_OUTPUT)
341 {
342 save_flags (flags);
343 cli ();
344
345 while (!current_got_fatal_signal ()
346 && audio_devs[dev]->dmap_out->qlen > 1)
347 {
348
349 {
350 unsigned long tl;
351
352 if (HZ)
353 current_set_timeout (tl = jiffies + (HZ));
354 else
355 tl = 0xffffffff;
356 out_sleep_flag[dev].mode = WK_SLEEP;
357 module_interruptible_sleep_on (&out_sleeper[dev]);
358 if (!(out_sleep_flag[dev].mode & WK_WAKEUP))
359 {
360 if (jiffies >= tl)
361 out_sleep_flag[dev].mode |= WK_TIMEOUT;
362 }
363 out_sleep_flag[dev].mode &= ~WK_SLEEP;
364 };
365 if ((out_sleep_flag[dev].mode & WK_TIMEOUT))
366 {
367 restore_flags (flags);
368 return audio_devs[dev]->dmap_out->qlen;
369 }
370 }
371 restore_flags (flags);
372
373
374
375
376
377
378 save_flags (flags);
379 cli ();
380 if (audio_devs[dev]->local_qlen)
381 {
382 while (!(current_got_fatal_signal ())
383 && audio_devs[dev]->local_qlen (dev))
384 {
385
386 {
387 unsigned long tl;
388
389 if (HZ)
390 current_set_timeout (tl = jiffies + (HZ));
391 else
392 tl = 0xffffffff;
393 out_sleep_flag[dev].mode = WK_SLEEP;
394 module_interruptible_sleep_on (&out_sleeper[dev]);
395 if (!(out_sleep_flag[dev].mode & WK_WAKEUP))
396 {
397 if (jiffies >= tl)
398 out_sleep_flag[dev].mode |= WK_TIMEOUT;
399 }
400 out_sleep_flag[dev].mode &= ~WK_SLEEP;
401 };
402 }
403 }
404 restore_flags (flags);
405 }
406 return audio_devs[dev]->dmap_out->qlen;
407 }
408
409 int
410 DMAbuf_release (int dev, int mode)
411 {
412 unsigned long flags;
413
414 audio_devs[dev]->dmap_out->closing = 1;
415 audio_devs[dev]->dmap_in->closing = 1;
416
417 if (!(current_got_fatal_signal ())
418 && (audio_devs[dev]->dmap_out->dma_mode == DMODE_OUTPUT))
419 {
420 dma_sync (dev);
421 }
422
423 save_flags (flags);
424 cli ();
425
426 audio_devs[dev]->close (dev);
427
428 close_dmap (dev, audio_devs[dev]->dmap_out, audio_devs[dev]->dmachan1);
429
430 if (audio_devs[dev]->flags & DMA_DUPLEX)
431 close_dmap (dev, audio_devs[dev]->dmap_in, audio_devs[dev]->dmachan2);
432 audio_devs[dev]->open_mode = 0;
433
434 restore_flags (flags);
435
436 return 0;
437 }
438
439 static int
440 activate_recording (int dev, struct dma_buffparms *dmap)
441 {
442 if (!(audio_devs[dev]->enable_bits & PCM_ENABLE_INPUT))
443 return 0;
444
445 if (dmap->flags & DMA_RESTART)
446 {
447 dma_reset_input (dev);
448 dmap->flags &= ~DMA_RESTART;
449 }
450
451 if (dmap->dma_mode == DMODE_OUTPUT)
452 {
453 dma_sync (dev);
454 dma_reset (dev);
455 dmap->dma_mode = DMODE_NONE;
456 }
457
458 if (!(dmap->flags & DMA_ALLOC_DONE))
459 reorganize_buffers (dev, dmap);
460
461 if (!dmap->dma_mode)
462 {
463 int err;
464
465 if ((err = audio_devs[dev]->prepare_for_input (dev,
466 dmap->fragment_size, dmap->nbufs)) < 0)
467 {
468 return err;
469 }
470 dmap->dma_mode = DMODE_INPUT;
471 }
472
473 if (!(dmap->flags & DMA_ACTIVE))
474 {
475 audio_devs[dev]->start_input (dev, dmap->raw_buf_phys +
476 dmap->qtail * dmap->fragment_size,
477 dmap->fragment_size, 0,
478 !(audio_devs[dev]->flags & DMA_AUTOMODE) ||
479 !(dmap->flags & DMA_STARTED));
480 dmap->flags |= DMA_ACTIVE | DMA_STARTED;
481 if (audio_devs[dev]->trigger)
482 audio_devs[dev]->trigger (dev,
483 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
484 }
485 return 0;
486 }
487
488 int
489 DMAbuf_getrdbuffer (int dev, char **buf, int *len, int dontblock)
490 {
491 unsigned long flags;
492 int err = EIO;
493 struct dma_buffparms *dmap = audio_devs[dev]->dmap_in;
494
495 save_flags (flags);
496 cli ();
497 #ifdef ALLOW_BUFFER_MAPPING
498 if (audio_devs[dev]->dmap_in->mapping_flags & DMA_MAP_MAPPED)
499 {
500 printk ("Sound: Can't read from mmapped device (1)\n");
501 return -EINVAL;
502 }
503 else
504 #endif
505 if (!dmap->qlen)
506 {
507 int timeout;
508
509 if ((err = activate_recording (dev, dmap)) < 0)
510 {
511 restore_flags (flags);
512 return err;
513 }
514
515
516
517 if (dontblock)
518 {
519 restore_flags (flags);
520 return -EAGAIN;
521 }
522
523 if (!(audio_devs[dev]->enable_bits & PCM_ENABLE_INPUT) &
524 audio_devs[dev]->go)
525 {
526 restore_flags (flags);
527 return -EAGAIN;
528 }
529
530 if (!audio_devs[dev]->go)
531 timeout = 0;
532 else
533 timeout = 2 * HZ;
534
535
536 {
537 unsigned long tl;
538
539 if (timeout)
540 current_set_timeout (tl = jiffies + (timeout));
541 else
542 tl = 0xffffffff;
543 in_sleep_flag[dev].mode = WK_SLEEP;
544 module_interruptible_sleep_on (&in_sleeper[dev]);
545 if (!(in_sleep_flag[dev].mode & WK_WAKEUP))
546 {
547 if (jiffies >= tl)
548 in_sleep_flag[dev].mode |= WK_TIMEOUT;
549 }
550 in_sleep_flag[dev].mode &= ~WK_SLEEP;
551 };
552 if ((in_sleep_flag[dev].mode & WK_TIMEOUT))
553 {
554 printk ("Sound: DMA (input) timed out - IRQ/DRQ config error?\n");
555 err = EIO;
556 audio_devs[dev]->reset (dev);
557 ;
558 }
559 else
560 err = EINTR;
561 }
562 restore_flags (flags);
563
564 if (!dmap->qlen)
565 return -err;
566
567 *buf = &dmap->raw_buf[dmap->qhead * dmap->fragment_size + dmap->counts[dmap->qhead]];
568 *len = dmap->fragment_size - dmap->counts[dmap->qhead];
569
570 return dmap->qhead;
571 }
572
573 int
574 DMAbuf_rmchars (int dev, int buff_no, int c)
575 {
576 struct dma_buffparms *dmap = audio_devs[dev]->dmap_in;
577
578 int p = dmap->counts[dmap->qhead] + c;
579
580 #ifdef ALLOW_BUFFER_MAPPING
581 if (audio_devs[dev]->dmap_in->mapping_flags & DMA_MAP_MAPPED)
582 {
583 printk ("Sound: Can't read from mmapped device (2)\n");
584 return -EINVAL;
585 }
586 else
587 #endif
588 if (p >= dmap->fragment_size)
589 {
590 dmap->counts[dmap->qhead] = 0;
591 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
592 printk ("\nSound: Audio queue1 corrupted for dev%d (%d/%d)\n",
593 dev, dmap->qlen, dmap->nbufs);
594 dmap->qlen--;
595 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
596 }
597 else
598 dmap->counts[dmap->qhead] = p;
599
600 return 0;
601 }
602
603 static int
604 dma_subdivide (int dev, struct dma_buffparms *dmap, ioctl_arg arg, int fact)
605 {
606 if (fact == 0)
607 {
608 fact = dmap->subdivision;
609 if (fact == 0)
610 fact = 1;
611 return snd_ioctl_return ((int *) arg, fact);
612 }
613
614 if (dmap->subdivision != 0 ||
615 dmap->fragment_size)
616 return -EINVAL;
617
618 if (fact > MAX_REALTIME_FACTOR)
619 return -EINVAL;
620
621 if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
622 return -EINVAL;
623
624 dmap->subdivision = fact;
625 return snd_ioctl_return ((int *) arg, fact);
626 }
627
628 static int
629 dma_set_fragment (int dev, struct dma_buffparms *dmap, ioctl_arg arg, int fact)
630 {
631 int bytes, count;
632
633 if (fact == 0)
634 return -EIO;
635
636 if (dmap->subdivision != 0 ||
637 dmap->fragment_size)
638 return -EINVAL;
639
640 bytes = fact & 0xffff;
641 count = (fact >> 16) & 0xffff;
642
643 if (count == 0)
644 count = MAX_SUB_BUFFERS;
645
646 if (bytes < 4 || bytes > 17)
647 return -EINVAL;
648
649 if (count < 2)
650 return -EINVAL;
651
652 #ifdef OS_DMA_MINBITS
653 if (bytes < OS_DMA_MINBITS)
654 bytes = OS_DMA_MINBITS;
655 #endif
656
657 dmap->fragment_size = (1 << bytes);
658 dmap->max_fragments = count;
659
660 if (dmap->fragment_size > audio_devs[dev]->buffsize)
661 dmap->fragment_size = audio_devs[dev]->buffsize;
662
663 if (dmap->fragment_size == audio_devs[dev]->buffsize &&
664 audio_devs[dev]->flags & DMA_AUTOMODE)
665 dmap->fragment_size /= 2;
666
667 dmap->subdivision = 1;
668 return snd_ioctl_return ((int *) arg, bytes | (count << 16));
669 }
670
671 static int
672 get_buffer_pointer (int dev, int chan, struct dma_buffparms *dmap)
673 {
674 int pos;
675 unsigned long flags;
676
677 save_flags (flags);
678 cli ();
679 if (!(dmap->flags & DMA_ACTIVE))
680 pos = 0;
681 else
682 {
683 clear_dma_ff (chan);
684 disable_dma (chan);
685 pos = get_dma_residue (chan);
686 enable_dma (chan);
687 }
688 restore_flags (flags);
689
690
691 if (audio_devs[dev]->flags & DMA_AUTOMODE)
692 return dmap->bytes_in_use - pos;
693 else
694 {
695 pos = dmap->fragment_size - pos;
696 if (pos < 0)
697 return 0;
698 return pos;
699 }
700 }
701
702 int
703 DMAbuf_ioctl (int dev, unsigned int cmd, ioctl_arg arg, int local)
704 {
705 struct dma_buffparms *dmap_out = audio_devs[dev]->dmap_out;
706 struct dma_buffparms *dmap_in = audio_devs[dev]->dmap_in;
707
708 switch (cmd)
709 {
710 case SNDCTL_DSP_RESET:
711 dma_reset (dev);
712 return 0;
713 break;
714
715 case SNDCTL_DSP_SYNC:
716 dma_sync (dev);
717 dma_reset (dev);
718 return 0;
719 break;
720
721 case SNDCTL_DSP_GETBLKSIZE:
722 if (!(dmap_out->flags & DMA_ALLOC_DONE))
723 reorganize_buffers (dev, dmap_out);
724
725 return snd_ioctl_return ((int *) arg, dmap_out->fragment_size);
726 break;
727
728 case SNDCTL_DSP_SUBDIVIDE:
729 {
730 int fact = get_fs_long ((long *) arg);
731 int ret;
732
733 ret = dma_subdivide (dev, dmap_out, arg, fact);
734 if (ret < 0)
735 return ret;
736
737 if (audio_devs[dev]->flags & DMA_DUPLEX)
738 ret = dma_subdivide (dev, dmap_in, arg, fact);
739
740 return ret;
741 }
742 break;
743
744 case SNDCTL_DSP_SETFRAGMENT:
745 {
746 int fact = get_fs_long ((long *) arg);
747 int ret;
748
749 ret = dma_set_fragment (dev, dmap_out, arg, fact);
750 if (ret < 0)
751 return ret;
752
753 if (audio_devs[dev]->flags & DMA_DUPLEX)
754 ret = dma_set_fragment (dev, dmap_in, arg, fact);
755
756 return ret;
757 }
758 break;
759
760 case SNDCTL_DSP_GETISPACE:
761 case SNDCTL_DSP_GETOSPACE:
762 if (!local)
763 return -EINVAL;
764 else
765 {
766 struct dma_buffparms *dmap = dmap_out;
767
768 audio_buf_info *info = (audio_buf_info *) arg;
769
770 if (cmd == SNDCTL_DSP_GETISPACE && audio_devs[dev]->flags & DMA_DUPLEX)
771 dmap = dmap_in;
772
773 #ifdef ALLOW_BUFFER_MAPPING
774 if (dmap->mapping_flags & DMA_MAP_MAPPED)
775 return -EINVAL;
776 #endif
777
778 if (!(dmap->flags & DMA_ALLOC_DONE))
779 reorganize_buffers (dev, dmap);
780
781 info->fragstotal = dmap->nbufs;
782
783 if (cmd == SNDCTL_DSP_GETISPACE)
784 info->fragments = dmap->qlen;
785 else
786 {
787 if (!space_in_queue (dev))
788 info->fragments = 0;
789 else
790 {
791 info->fragments = dmap->nbufs - dmap->qlen;
792 if (audio_devs[dev]->local_qlen)
793 {
794 int tmp = audio_devs[dev]->local_qlen (dev);
795
796 if (tmp && info->fragments)
797 tmp--;
798
799
800 info->fragments -= tmp;
801 }
802 }
803 }
804
805 if (info->fragments < 0)
806 info->fragments = 0;
807 else if (info->fragments > dmap->nbufs)
808 info->fragments = dmap->nbufs;
809
810 info->fragsize = dmap->fragment_size;
811 info->bytes = info->fragments * dmap->fragment_size;
812
813 if (cmd == SNDCTL_DSP_GETISPACE && dmap->qlen)
814 info->bytes -= dmap->counts[dmap->qhead];
815 }
816 return 0;
817
818 case SNDCTL_DSP_SETTRIGGER:
819 {
820 unsigned long flags;
821
822 int bits = get_fs_long ((long *) arg) & audio_devs[dev]->open_mode;
823 int changed;
824
825 if (audio_devs[dev]->trigger == NULL)
826 return -EINVAL;
827
828 if (!(audio_devs[dev]->flags & DMA_DUPLEX))
829 if ((bits & PCM_ENABLE_INPUT) && (bits & PCM_ENABLE_OUTPUT))
830 {
831 printk ("Sound: Device doesn't have full duplex capability\n");
832 return -EINVAL;
833 }
834
835 save_flags (flags);
836 cli ();
837 changed = audio_devs[dev]->enable_bits ^ bits;
838
839 if ((changed & bits) & PCM_ENABLE_INPUT && audio_devs[dev]->go)
840 {
841 if (!(dmap_in->flags & DMA_ALLOC_DONE))
842 reorganize_buffers (dev, dmap_in);
843
844 activate_recording (dev, dmap_in);
845 }
846
847 #ifdef ALLOW_BUFFER_MAPPING
848 if ((changed & bits) & PCM_ENABLE_OUTPUT &&
849 dmap_out->mapping_flags & DMA_MAP_MAPPED &&
850 audio_devs[dev]->go)
851 {
852 if (!(dmap_out->flags & DMA_ALLOC_DONE))
853 reorganize_buffers (dev, dmap_out);
854
855 dmap_out->counts[dmap_out->qhead] = dmap_out->fragment_size;
856 DMAbuf_start_output (dev, 0, dmap_out->fragment_size);
857 }
858 #endif
859
860 audio_devs[dev]->enable_bits = bits;
861 if (changed && audio_devs[dev]->trigger)
862 audio_devs[dev]->trigger (dev, bits * audio_devs[dev]->go);
863 restore_flags (flags);
864 }
865 case SNDCTL_DSP_GETTRIGGER:
866 return snd_ioctl_return ((int *) arg, audio_devs[dev]->enable_bits);
867 break;
868
869 case SNDCTL_DSP_SETSYNCRO:
870
871 if (!audio_devs[dev]->trigger)
872 return -EINVAL;
873
874 audio_devs[dev]->trigger (dev, 0);
875 audio_devs[dev]->go = 0;
876 return 0;
877 break;
878
879 case SNDCTL_DSP_GETIPTR:
880 {
881 count_info info;
882 unsigned long flags;
883
884 save_flags (flags);
885 cli ();
886 info.bytes = audio_devs[dev]->dmap_in->byte_counter;
887 info.ptr = get_buffer_pointer (dev, audio_devs[dev]->dmachan2, audio_devs[dev]->dmap_in);
888 info.blocks = audio_devs[dev]->dmap_in->qlen;
889 info.bytes += info.ptr;
890 memcpy_tofs ((&((char *) arg)[0]), (char *) &info, sizeof (info));
891
892 #ifdef ALLOW_BUFFER_MAPPING
893 if (audio_devs[dev]->dmap_in->mapping_flags & DMA_MAP_MAPPED)
894 audio_devs[dev]->dmap_in->qlen = 0;
895 #endif
896 restore_flags (flags);
897 return 0;
898 }
899 break;
900
901 case SNDCTL_DSP_GETOPTR:
902 {
903 count_info info;
904 unsigned long flags;
905
906 save_flags (flags);
907 cli ();
908 info.bytes = audio_devs[dev]->dmap_out->byte_counter;
909 info.ptr = get_buffer_pointer (dev, audio_devs[dev]->dmachan1, audio_devs[dev]->dmap_out);
910 info.blocks = audio_devs[dev]->dmap_out->qlen;
911 info.bytes += info.ptr;
912 memcpy_tofs ((&((char *) arg)[0]), (char *) &info, sizeof (info));
913
914 #ifdef ALLOW_BUFFER_MAPPING
915 if (audio_devs[dev]->dmap_out->mapping_flags & DMA_MAP_MAPPED)
916 audio_devs[dev]->dmap_out->qlen = 0;
917 #endif
918 restore_flags (flags);
919 return 0;
920 }
921 break;
922
923
924 default:
925 return audio_devs[dev]->ioctl (dev, cmd, arg, local);
926 }
927
928 }
929
930
931
932
933
934
935 void
936 DMAbuf_start_devices (unsigned int devmask)
937 {
938 int dev;
939
940 for (dev = 0; dev < num_audiodevs; dev++)
941 if (devmask & (1 << dev))
942 if (audio_devs[dev]->open_mode != 0)
943 if (!audio_devs[dev]->go)
944 {
945
946 audio_devs[dev]->go = 1;
947
948 if (audio_devs[dev]->trigger)
949 audio_devs[dev]->trigger (dev,
950 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
951 }
952 }
953
954 static int
955 space_in_queue (int dev)
956 {
957 int len, max, tmp;
958 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
959
960 if (dmap->qlen >= dmap->nbufs)
961 return 0;
962
963
964
965
966
967
968 max = dmap->max_fragments;
969 len = dmap->qlen;
970
971 if (audio_devs[dev]->local_qlen)
972 {
973 tmp = audio_devs[dev]->local_qlen (dev);
974 if (tmp && len)
975 tmp--;
976
977
978 len += tmp;
979 }
980
981 if (len >= max)
982 return 0;
983 return 1;
984 }
985
986 int
987 DMAbuf_getwrbuffer (int dev, char **buf, int *size, int dontblock)
988 {
989 unsigned long flags;
990 int abort, err = EIO;
991 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
992
993 #ifdef ALLOW_BUFFER_MAPPING
994 if (audio_devs[dev]->dmap_out->mapping_flags & DMA_MAP_MAPPED)
995 {
996 printk ("Sound: Can't write to mmapped device (3)\n");
997 return -EINVAL;
998 }
999 #endif
1000
1001 if (dmap->dma_mode == DMODE_INPUT)
1002 {
1003 dma_reset (dev);
1004 dmap->dma_mode = DMODE_NONE;
1005 }
1006 else if (dmap->flags & DMA_RESTART)
1007 {
1008 dma_sync (dev);
1009 dma_reset_output (dev);
1010 }
1011
1012 dmap->flags &= ~DMA_RESTART;
1013
1014 if (!(dmap->flags & DMA_ALLOC_DONE))
1015 reorganize_buffers (dev, dmap);
1016
1017 if (!dmap->dma_mode)
1018 {
1019 int err;
1020
1021 dmap->dma_mode = DMODE_OUTPUT;
1022 if ((err = audio_devs[dev]->prepare_for_output (dev,
1023 dmap->fragment_size, dmap->nbufs)) < 0)
1024 return err;
1025 }
1026
1027 save_flags (flags);
1028 cli ();
1029
1030 abort = 0;
1031 while (!space_in_queue (dev) &&
1032 !abort)
1033 {
1034 int timeout;
1035
1036 if (dontblock)
1037 {
1038 restore_flags (flags);
1039 return -EAGAIN;
1040 }
1041
1042 if (!(audio_devs[dev]->enable_bits & PCM_ENABLE_OUTPUT) &&
1043 audio_devs[dev]->go)
1044 {
1045 restore_flags (flags);
1046 return -EAGAIN;
1047 }
1048
1049
1050
1051
1052 if (!audio_devs[dev]->go)
1053 timeout = 0;
1054 else
1055 timeout = 2 * HZ;
1056
1057
1058 {
1059 unsigned long tl;
1060
1061 if (timeout)
1062 current_set_timeout (tl = jiffies + (timeout));
1063 else
1064 tl = 0xffffffff;
1065 out_sleep_flag[dev].mode = WK_SLEEP;
1066 module_interruptible_sleep_on (&out_sleeper[dev]);
1067 if (!(out_sleep_flag[dev].mode & WK_WAKEUP))
1068 {
1069 if (jiffies >= tl)
1070 out_sleep_flag[dev].mode |= WK_TIMEOUT;
1071 }
1072 out_sleep_flag[dev].mode &= ~WK_SLEEP;
1073 };
1074 if ((out_sleep_flag[dev].mode & WK_TIMEOUT))
1075 {
1076 printk ("Sound: DMA (output) timed out - IRQ/DRQ config error?\n");
1077 err = EIO;
1078 abort = 1;
1079 ;
1080 audio_devs[dev]->reset (dev);
1081 }
1082 else if (current_got_fatal_signal ())
1083 {
1084 err = EINTR;
1085 abort = 1;
1086 }
1087 }
1088 restore_flags (flags);
1089
1090 if (!space_in_queue (dev))
1091 {
1092 return -err;
1093 }
1094
1095 *buf = dmap->raw_buf + dmap->qtail * dmap->fragment_size;
1096 *size = dmap->fragment_size;
1097 dmap->counts[dmap->qtail] = 0;
1098
1099 return dmap->qtail;
1100 }
1101
1102 int
1103 DMAbuf_get_curr_buffer (int dev, int *buf_no, char **dma_buf, int *buf_ptr, int *buf_size)
1104 {
1105 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
1106
1107 if (dmap->cfrag < 0)
1108 return -1;
1109
1110 *dma_buf = dmap->raw_buf + dmap->qtail * dmap->fragment_size;
1111 *buf_ptr = dmap->counts[dmap->qtail];
1112 *buf_size = dmap->fragment_size;
1113 return *buf_no = dmap->cfrag;
1114 }
1115
1116 int
1117 DMAbuf_set_count (int dev, int buff_no, int l)
1118 {
1119 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
1120
1121 if (buff_no == dmap->qtail)
1122 {
1123 dmap->cfrag = buff_no;
1124 dmap->counts[buff_no] = l;
1125 }
1126 else
1127 dmap->cfrag = -1;
1128 return 0;
1129 }
1130
1131 int
1132 DMAbuf_start_output (int dev, int buff_no, int l)
1133 {
1134 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
1135
1136 dmap->cfrag = -1;
1137
1138
1139
1140
1141 #ifdef ALLOW_BUFFER_MAPPING
1142 if (audio_devs[dev]->dmap_out->mapping_flags & DMA_MAP_MAPPED)
1143 {
1144 l = dmap->fragment_size;
1145 dmap->counts[dmap->qtail] = l;
1146 dmap->flags &= ~DMA_RESTART;
1147 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1148 }
1149 else
1150 #else
1151 if (dmap != NULL)
1152 #endif
1153 {
1154
1155
1156 dmap->qlen++;
1157 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
1158 printk ("\nSound: Audio queue2 corrupted for dev%d (%d/%d)\n",
1159 dev, dmap->qlen, dmap->nbufs);
1160
1161 dmap->counts[dmap->qtail] = l;
1162
1163 if ((l != dmap->fragment_size) &&
1164 ((audio_devs[dev]->flags & DMA_AUTOMODE) &&
1165 audio_devs[dev]->flags & NEEDS_RESTART))
1166 dmap->flags |= DMA_RESTART;
1167 else
1168 dmap->flags &= ~DMA_RESTART;
1169
1170 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1171 }
1172
1173 if (!(dmap->flags & DMA_ACTIVE))
1174 {
1175 dmap->flags |= DMA_ACTIVE;
1176 audio_devs[dev]->output_block (dev, dmap->raw_buf_phys +
1177 dmap->qhead * dmap->fragment_size,
1178 dmap->counts[dmap->qhead], 0,
1179 !(audio_devs[dev]->flags & DMA_AUTOMODE) ||
1180 !(dmap->flags & DMA_STARTED));
1181 dmap->flags |= DMA_STARTED;
1182 if (audio_devs[dev]->trigger)
1183 audio_devs[dev]->trigger (dev,
1184 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
1185 }
1186
1187 return 0;
1188 }
1189
1190 int
1191 DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
1192 {
1193 int chan;
1194 struct dma_buffparms *dmap;
1195 unsigned long flags;
1196
1197 if (dma_mode == DMA_MODE_WRITE)
1198 {
1199 chan = audio_devs[dev]->dmachan1;
1200 dmap = audio_devs[dev]->dmap_out;
1201 }
1202 else
1203 {
1204 chan = audio_devs[dev]->dmachan2;
1205 dmap = audio_devs[dev]->dmap_in;
1206 }
1207
1208
1209
1210
1211
1212
1213 if (audio_devs[dev]->flags & DMA_AUTOMODE)
1214 {
1215
1216
1217
1218 save_flags (flags);
1219 cli ();
1220 disable_dma (chan);
1221 clear_dma_ff (chan);
1222 set_dma_mode (chan, dma_mode | DMA_AUTOINIT);
1223 set_dma_addr (chan, dmap->raw_buf_phys);
1224 set_dma_count (chan, dmap->bytes_in_use);
1225 enable_dma (chan);
1226 restore_flags (flags);
1227 }
1228 else
1229 {
1230 save_flags (flags);
1231 cli ();
1232 disable_dma (chan);
1233 clear_dma_ff (chan);
1234 set_dma_mode (chan, dma_mode);
1235 set_dma_addr (chan, physaddr);
1236 set_dma_count (chan, count);
1237 enable_dma (chan);
1238 restore_flags (flags);
1239 }
1240
1241 return count;
1242 }
1243
1244 long
1245 DMAbuf_init (long mem_start)
1246 {
1247 int dev;
1248
1249
1250
1251
1252
1253
1254 for (dev = 0; dev < num_audiodevs; dev++)
1255 if (audio_devs[dev]->dmap_out == NULL)
1256 {
1257 audio_devs[dev]->dmap_out =
1258 audio_devs[dev]->dmap_in =
1259 &dmaps[ndmaps++];
1260
1261 if (audio_devs[dev]->flags & DMA_DUPLEX)
1262 audio_devs[dev]->dmap_in =
1263 &dmaps[ndmaps++];
1264 }
1265 return mem_start;
1266 }
1267
1268 void
1269 DMAbuf_outputintr (int dev, int event_type)
1270 {
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281 unsigned long flags;
1282 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
1283
1284 int p;
1285
1286 dmap->byte_counter += dmap->counts[dmap->qhead];
1287
1288 #ifdef OS_DMA_INTR
1289 sound_dma_intr (dev, audio_devs[dev]->dmap_out, audio_devs[dev]->dmachan1);
1290 #endif
1291
1292 #ifdef ALLOW_BUFFER_MAPPING
1293 if (dmap->mapping_flags & DMA_MAP_MAPPED)
1294 {
1295
1296
1297 p = dmap->fragment_size * dmap->qhead;
1298 memset (dmap->raw_buf + p,
1299 dmap->neutral_byte,
1300 dmap->fragment_size);
1301
1302 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
1303 dmap->qlen++;
1304 dmap->flags &= ~DMA_ACTIVE;
1305 dmap->counts[dmap->qhead] = dmap->fragment_size;
1306
1307 if (!(audio_devs[dev]->flags & DMA_AUTOMODE))
1308 {
1309 audio_devs[dev]->output_block (dev, dmap->raw_buf_phys +
1310 dmap->qhead * dmap->fragment_size,
1311 dmap->counts[dmap->qhead], 1,
1312 !(audio_devs[dev]->flags & DMA_AUTOMODE));
1313 if (audio_devs[dev]->trigger)
1314 audio_devs[dev]->trigger (dev,
1315 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
1316 }
1317 dmap->flags |= DMA_ACTIVE;
1318 }
1319 else
1320 #endif
1321 if (event_type != 2)
1322 {
1323 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
1324 {
1325 printk ("\nSound: Audio queue3 corrupted for dev%d (%d/%d)\n",
1326 dev, dmap->qlen, dmap->nbufs);
1327 return;
1328 }
1329
1330 dmap->qlen--;
1331 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
1332 dmap->flags &= ~DMA_ACTIVE;
1333
1334 if (event_type == 1 && dmap->qlen < 1)
1335 {
1336 dmap->underrun_count++;
1337
1338 if (dmap->closing)
1339 {
1340 audio_devs[dev]->halt_xfer (dev);
1341 }
1342 else
1343 {
1344 dmap->qlen++;
1345 dmap->cfrag = -1;
1346 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1347
1348 p = dmap->fragment_size * dmap->qhead;
1349 memset (dmap->raw_buf + p,
1350 dmap->neutral_byte,
1351 dmap->fragment_size);
1352 }
1353 }
1354
1355 if (dmap->qlen)
1356 {
1357 if (!(audio_devs[dev]->flags & DMA_AUTOMODE))
1358 {
1359 audio_devs[dev]->output_block (dev, dmap->raw_buf_phys +
1360 dmap->qhead * dmap->fragment_size,
1361 dmap->counts[dmap->qhead], 1,
1362 !(audio_devs[dev]->flags & DMA_AUTOMODE));
1363 if (audio_devs[dev]->trigger)
1364 audio_devs[dev]->trigger (dev,
1365 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
1366 }
1367 dmap->flags |= DMA_ACTIVE;
1368 }
1369 }
1370
1371 save_flags (flags);
1372 cli ();
1373 if ((out_sleep_flag[dev].mode & WK_SLEEP))
1374 {
1375 {
1376 out_sleep_flag[dev].mode = WK_WAKEUP;
1377 module_wake_up (&out_sleeper[dev]);
1378 };
1379 }
1380 restore_flags (flags);
1381 }
1382
1383 void
1384 DMAbuf_inputintr (int dev)
1385 {
1386 unsigned long flags;
1387 struct dma_buffparms *dmap = audio_devs[dev]->dmap_in;
1388
1389 dmap->byte_counter += dmap->fragment_size;
1390
1391 #ifdef OS_DMA_INTR
1392 sound_dma_intr (dev, audio_devs[dev]->dmap_in, audio_devs[dev]->dmachan2);
1393 #endif
1394
1395 #ifdef ALLOW_BUFFER_MAPPING
1396 if (dmap->mapping_flags & DMA_MAP_MAPPED)
1397 {
1398 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1399 dmap->qlen++;
1400
1401 if (!(audio_devs[dev]->flags & DMA_AUTOMODE))
1402 {
1403 audio_devs[dev]->start_input (dev, dmap->raw_buf_phys +
1404 dmap->qtail * dmap->fragment_size,
1405 dmap->fragment_size, 1,
1406 !(audio_devs[dev]->flags & DMA_AUTOMODE));
1407 if (audio_devs[dev]->trigger)
1408 audio_devs[dev]->trigger (dev,
1409 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
1410 }
1411
1412 dmap->flags |= DMA_ACTIVE;
1413 }
1414 else
1415 #endif
1416 if (dmap->qlen == (dmap->nbufs - 1))
1417 {
1418 printk ("Sound: Recording overrun\n");
1419 dmap->underrun_count++;
1420
1421 if (audio_devs[dev]->flags & DMA_AUTOMODE)
1422 {
1423
1424 if ((audio_devs[dev]->flags & DMA_DUPLEX) &&
1425 audio_devs[dev]->halt_input)
1426 audio_devs[dev]->halt_input (dev);
1427 else
1428 audio_devs[dev]->halt_xfer (dev);
1429
1430 dmap->flags &= ~DMA_ACTIVE;
1431 if (audio_devs[dev]->flags & DMA_AUTOMODE)
1432 dmap->flags |= DMA_RESTART;
1433 else
1434 dmap->flags &= ~DMA_RESTART;
1435 }
1436 }
1437 else
1438 {
1439 dmap->qlen++;
1440 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
1441 printk ("\nSound: Audio queue4 corrupted for dev%d (%d/%d)\n",
1442 dev, dmap->qlen, dmap->nbufs);
1443 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1444 }
1445
1446 if (!(audio_devs[dev]->flags & DMA_AUTOMODE))
1447 {
1448 audio_devs[dev]->start_input (dev, dmap->raw_buf_phys +
1449 dmap->qtail * dmap->fragment_size,
1450 dmap->fragment_size, 1,
1451 !(audio_devs[dev]->flags & DMA_AUTOMODE));
1452 if (audio_devs[dev]->trigger)
1453 audio_devs[dev]->trigger (dev,
1454 audio_devs[dev]->enable_bits * audio_devs[dev]->go);
1455 }
1456
1457 dmap->flags |= DMA_ACTIVE;
1458
1459 save_flags (flags);
1460 cli ();
1461 if ((in_sleep_flag[dev].mode & WK_SLEEP))
1462 {
1463 {
1464 in_sleep_flag[dev].mode = WK_WAKEUP;
1465 module_wake_up (&in_sleeper[dev]);
1466 };
1467 }
1468 restore_flags (flags);
1469 }
1470
1471 int
1472 DMAbuf_open_dma (int dev)
1473 {
1474 int chan = audio_devs[dev]->dmachan1;
1475 int err;
1476 unsigned long flags;
1477
1478 if ((err = open_dmap (dev, OPEN_READWRITE, audio_devs[dev]->dmap_out, audio_devs[dev]->dmachan1)) < 0)
1479 {
1480 return -EBUSY;
1481 }
1482 dma_init_buffers (dev, audio_devs[dev]->dmap_out);
1483 audio_devs[dev]->dmap_out->flags |= DMA_ALLOC_DONE;
1484 audio_devs[dev]->dmap_out->fragment_size = audio_devs[dev]->buffsize;
1485
1486
1487 if (audio_devs[dev]->flags & DMA_DUPLEX)
1488 {
1489 if ((err = open_dmap (dev, OPEN_READWRITE, audio_devs[dev]->dmap_in, audio_devs[dev]->dmachan2)) < 0)
1490 {
1491 printk ("Unable to grab DMA%d for the audio driver\n",
1492 audio_devs[dev]->dmachan2);
1493 close_dmap (dev, audio_devs[dev]->dmap_out, audio_devs[dev]->dmachan1);
1494 return -EBUSY;
1495 }
1496 dma_init_buffers (dev, audio_devs[dev]->dmap_in);
1497 audio_devs[dev]->dmap_in->flags |= DMA_ALLOC_DONE;
1498 audio_devs[dev]->dmap_in->fragment_size = audio_devs[dev]->buffsize;
1499
1500 }
1501 else
1502 {
1503 audio_devs[dev]->dmap_in = audio_devs[dev]->dmap_out;
1504 audio_devs[dev]->dmachan2 = audio_devs[dev]->dmachan1;
1505 }
1506
1507
1508 save_flags (flags);
1509 cli ();
1510 disable_dma (chan);
1511 clear_dma_ff (chan);
1512 restore_flags (flags);
1513
1514 return 0;
1515 }
1516
1517 void
1518 DMAbuf_close_dma (int dev)
1519 {
1520 DMAbuf_reset_dma (dev);
1521 close_dmap (dev, audio_devs[dev]->dmap_out, audio_devs[dev]->dmachan1);
1522
1523 if (audio_devs[dev]->flags & DMA_DUPLEX)
1524 close_dmap (dev, audio_devs[dev]->dmap_in, audio_devs[dev]->dmachan2);
1525
1526 }
1527
1528 void
1529 DMAbuf_reset_dma (int dev)
1530 {
1531 }
1532
1533 int
1534 DMAbuf_select (int dev, struct fileinfo *file, int sel_type, select_table_handle * wait)
1535 {
1536 struct dma_buffparms *dmap;
1537 unsigned long flags;
1538
1539 switch (sel_type)
1540 {
1541 case SEL_IN:
1542 dmap = audio_devs[dev]->dmap_in;
1543
1544 #ifdef ALLOW_BUFFER_MAPPING
1545 if (dmap->mapping_flags & DMA_MAP_MAPPED)
1546 {
1547 if (dmap->qlen)
1548 return 1;
1549
1550 save_flags (flags);
1551 cli ();
1552 in_sleep_flag[dev].mode = WK_SLEEP;
1553 module_select_wait (&in_sleeper[dev], wait);
1554 restore_flags (flags);
1555 return 0;
1556 }
1557 #endif
1558
1559 if (dmap->dma_mode != DMODE_INPUT)
1560 {
1561 if ((audio_devs[dev]->flags & DMA_DUPLEX) && !dmap->qlen &&
1562 audio_devs[dev]->enable_bits & PCM_ENABLE_INPUT &&
1563 audio_devs[dev]->go)
1564 {
1565 unsigned long flags;
1566
1567 save_flags (flags);
1568 cli ();
1569 activate_recording (dev, dmap);
1570 restore_flags (flags);
1571 }
1572 return 0;
1573 }
1574
1575 if (!dmap->qlen)
1576 {
1577 save_flags (flags);
1578 cli ();
1579 in_sleep_flag[dev].mode = WK_SLEEP;
1580 module_select_wait (&in_sleeper[dev], wait);
1581 restore_flags (flags);
1582 return 0;
1583 }
1584 return 1;
1585 break;
1586
1587 case SEL_OUT:
1588 dmap = audio_devs[dev]->dmap_out;
1589
1590 #ifdef ALLOW_BUFFER_MAPPING
1591 if (dmap->mapping_flags & DMA_MAP_MAPPED)
1592 {
1593 if (dmap->qlen)
1594 return 1;
1595
1596 save_flags (flags);
1597 cli ();
1598 out_sleep_flag[dev].mode = WK_SLEEP;
1599 module_select_wait (&out_sleeper[dev], wait);
1600 restore_flags (flags);
1601 return 0;
1602 }
1603 #endif
1604
1605 if (dmap->dma_mode == DMODE_INPUT)
1606 {
1607 return 0;
1608 }
1609
1610 if (dmap->dma_mode == DMODE_NONE)
1611 {
1612 return 1;
1613 }
1614
1615 if (!space_in_queue (dev))
1616 {
1617 save_flags (flags);
1618 cli ();
1619 out_sleep_flag[dev].mode = WK_SLEEP;
1620 module_select_wait (&out_sleeper[dev], wait);
1621 restore_flags (flags);
1622 return 0;
1623 }
1624 return 1;
1625 break;
1626
1627 case SEL_EX:
1628 return 0;
1629 }
1630
1631 return 0;
1632 }
1633
1634
1635 #else
1636
1637
1638
1639
1640 int
1641 DMAbuf_open (int dev, int mode)
1642 {
1643 return -ENXIO;
1644 }
1645
1646 int
1647 DMAbuf_release (int dev, int mode)
1648 {
1649 return 0;
1650 }
1651
1652 int
1653 DMAbuf_getwrbuffer (int dev, char **buf, int *size, int dontblock)
1654 {
1655 return -EIO;
1656 }
1657
1658 int
1659 DMAbuf_getrdbuffer (int dev, char **buf, int *len, int dontblock)
1660 {
1661 return -EIO;
1662 }
1663
1664 int
1665 DMAbuf_rmchars (int dev, int buff_no, int c)
1666 {
1667 return -EIO;
1668 }
1669
1670 int
1671 DMAbuf_start_output (int dev, int buff_no, int l)
1672 {
1673 return -EIO;
1674 }
1675
1676 int
1677 DMAbuf_ioctl (int dev, unsigned int cmd, ioctl_arg arg, int local)
1678 {
1679 return -EIO;
1680 }
1681
1682 long
1683 DMAbuf_init (long mem_start)
1684 {
1685 return mem_start;
1686 }
1687
1688 int
1689 DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
1690 {
1691 return -EIO;
1692 }
1693
1694 int
1695 DMAbuf_open_dma (int dev)
1696 {
1697 return -ENXIO;
1698 }
1699
1700 void
1701 DMAbuf_close_dma (int dev)
1702 {
1703 return;
1704 }
1705
1706 void
1707 DMAbuf_reset_dma (int dev)
1708 {
1709 return;
1710 }
1711
1712 void
1713 DMAbuf_inputintr (int dev)
1714 {
1715 return;
1716 }
1717
1718 void
1719 DMAbuf_outputintr (int dev, int underrun_flag)
1720 {
1721 return;
1722 }
1723 #endif