This source file includes following definitions.
- reorganize_buffers
- dma_init_buffers
- DMAbuf_open
- dma_reset
- dma_sync
- DMAbuf_release
- DMAbuf_getrdbuffer
- DMAbuf_rmchars
- DMAbuf_ioctl
- space_in_queue
- DMAbuf_getwrbuffer
- DMAbuf_start_output
- DMAbuf_start_dma
- DMAbuf_init
- DMAbuf_outputintr
- DMAbuf_inputintr
- DMAbuf_open_dma
- DMAbuf_close_dma
- DMAbuf_reset_dma
- 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 #ifdef CONFIGURE_SOUNDCARD
33
34 #include "sound_calls.h"
35
36 #if !defined(EXCLUDE_AUDIO) || !defined(EXCLUDE_GUS)
37
38 DEFINE_WAIT_QUEUES (dev_sleeper[MAX_AUDIO_DEV], dev_sleep_flag[MAX_AUDIO_DEV]);
39
40 static struct dma_buffparms dmaps[MAX_AUDIO_DEV] =
41 {{0}};
42
43
44
45
46
47 static void
48 reorganize_buffers (int dev)
49 {
50
51
52
53
54 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
55 struct audio_operations *dsp_dev = audio_devs[dev];
56
57 unsigned i, p, n;
58 unsigned sr, nc, sz, bsz;
59
60 if (dmap->fragment_size == 0)
61 {
62
63 sr = dsp_dev->ioctl (dev, SOUND_PCM_READ_RATE, 0, 1);
64 nc = dsp_dev->ioctl (dev, SOUND_PCM_READ_CHANNELS, 0, 1);
65 sz = dsp_dev->ioctl (dev, SOUND_PCM_READ_BITS, 0, 1);
66
67 if (sr < 1 || nc < 1 || sz < 1)
68 {
69 printk ("Warning: Invalid PCM parameters[%d] sr=%d, nc=%d, sz=%d\n",
70 dev, sr, nc, sz);
71 sr = DSP_DEFAULT_SPEED;
72 nc = 1;
73 sz = 8;
74 }
75
76 sz /= 8;
77
78 sz = sr * nc * sz;
79
80
81
82
83
84
85
86 bsz = dsp_dev->buffsize;
87 while (bsz > sz)
88 bsz /= 2;
89
90 if (dsp_dev->buffcount == 1 && bsz == dsp_dev->buffsize)
91 bsz /= 2;
92
93 if (dmap->subdivision == 0)
94 dmap->subdivision = 1;
95
96 bsz /= dmap->subdivision;
97
98 if (bsz < 64)
99 bsz = 4096;
100
101 while ((dsp_dev->buffsize * dsp_dev->buffcount) / bsz > MAX_SUB_BUFFERS)
102 bsz *= 2;
103
104 dmap->fragment_size = bsz;
105 }
106 else
107 {
108
109
110
111
112 if (dmap->fragment_size > audio_devs[dev]->buffsize)
113 dmap->fragment_size = audio_devs[dev]->buffsize;
114 bsz = dmap->fragment_size;
115 }
116
117
118
119
120
121 n = 0;
122 for (i = 0; i < dmap->raw_count &&
123 n < dmap->max_fragments &&
124 n < MAX_SUB_BUFFERS; i++)
125 {
126 p = 0;
127
128 while ((p + bsz) <= dsp_dev->buffsize &&
129 n < dmap->max_fragments &&
130 n < MAX_SUB_BUFFERS)
131 {
132 dmap->buf[n] = dmap->raw_buf[i] + p;
133 dmap->buf_phys[n] = dmap->raw_buf_phys[i] + p;
134 p += bsz;
135 n++;
136 }
137 }
138
139 dmap->nbufs = n;
140 dmap->bytes_in_use = n * bsz;
141
142 for (i = 0; i < dmap->nbufs; i++)
143 {
144 dmap->counts[i] = 0;
145 }
146
147 dmap->flags |= DMA_ALLOC_DONE;
148 }
149
150 static void
151 dma_init_buffers (int dev)
152 {
153 struct dma_buffparms *dmap = audio_devs[dev]->dmap = &dmaps[dev];
154
155 RESET_WAIT_QUEUE (dev_sleeper[dev], dev_sleep_flag[dev]);
156
157 dmap->flags = DMA_BUSY;
158 dmap->qlen = dmap->qhead = dmap->qtail = 0;
159
160 dmap->qlen = dmap->qtail = dmap->qhead = 0;
161 dmap->dma_mode = DMODE_NONE;
162 }
163
164 int
165 DMAbuf_open (int dev, int mode)
166 {
167 int retval;
168 struct dma_buffparms *dmap = NULL;
169
170 if (dev >= num_audiodevs)
171 {
172 printk ("PCM device %d not installed.\n", dev);
173 return RET_ERROR (ENXIO);
174 }
175
176 if (!audio_devs[dev])
177 {
178 printk ("PCM device %d not initialized\n", dev);
179 return RET_ERROR (ENXIO);
180 }
181
182 dmap = audio_devs[dev]->dmap = &dmaps[dev];
183
184 if (dmap->flags & DMA_BUSY)
185 return RET_ERROR (EBUSY);
186
187 #ifdef USE_RUNTIME_DMAMEM
188 dmap->raw_buf[0] = NULL;
189 sound_dma_malloc (dev);
190 #endif
191
192 if (dmap->raw_buf[0] == NULL)
193 return RET_ERROR (ENOSPC);
194
195 if ((retval = audio_devs[dev]->open (dev, mode)) < 0)
196 return retval;
197
198 dmap->open_mode = mode;
199 dmap->subdivision = dmap->underrun_count = 0;
200 dmap->fragment_size = 0;
201 dmap->max_fragments = 65536;
202
203 dma_init_buffers (dev);
204 audio_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_BITS, 8, 1);
205 audio_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_CHANNELS, 1, 1);
206 audio_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_RATE, DSP_DEFAULT_SPEED, 1);
207
208 return 0;
209 }
210
211 static void
212 dma_reset (int dev)
213 {
214 int retval;
215 unsigned long flags;
216
217 DISABLE_INTR (flags);
218
219 audio_devs[dev]->reset (dev);
220 audio_devs[dev]->close (dev);
221
222 if ((retval = audio_devs[dev]->open (dev, audio_devs[dev]->dmap->open_mode)) < 0)
223 printk ("Sound: Reset failed - Can't reopen device\n");
224 RESTORE_INTR (flags);
225
226 dma_init_buffers (dev);
227 reorganize_buffers (dev);
228 }
229
230 static int
231 dma_sync (int dev)
232 {
233 unsigned long flags;
234
235 if (audio_devs[dev]->dmap->dma_mode == DMODE_OUTPUT)
236 {
237 DISABLE_INTR (flags);
238
239 while (!PROCESS_ABORTING (dev_sleeper[dev], dev_sleep_flag[dev])
240 && audio_devs[dev]->dmap->qlen)
241 {
242 DO_SLEEP (dev_sleeper[dev], dev_sleep_flag[dev], 10 * HZ);
243 if (TIMED_OUT (dev_sleeper[dev], dev_sleep_flag[dev]))
244 {
245 RESTORE_INTR (flags);
246 return audio_devs[dev]->dmap->qlen;
247 }
248 }
249 RESTORE_INTR (flags);
250
251
252
253
254
255
256 DISABLE_INTR (flags);
257 if (audio_devs[dev]->local_qlen)
258 {
259 while (!(PROCESS_ABORTING (dev_sleeper[dev], dev_sleep_flag[dev]))
260 && audio_devs[dev]->local_qlen (dev))
261 {
262 DO_SLEEP (dev_sleeper[dev], dev_sleep_flag[dev], HZ);
263 }
264 }
265 RESTORE_INTR (flags);
266 }
267 return audio_devs[dev]->dmap->qlen;
268 }
269
270 int
271 DMAbuf_release (int dev, int mode)
272 {
273 unsigned long flags;
274
275 if (!(PROCESS_ABORTING (dev_sleeper[dev], dev_sleep_flag[dev]))
276 && (audio_devs[dev]->dmap->dma_mode == DMODE_OUTPUT))
277 {
278 dma_sync (dev);
279 }
280
281 #ifdef USE_RUNTIME_DMAMEM
282 sound_dma_free (dev);
283 #endif
284
285 DISABLE_INTR (flags);
286 audio_devs[dev]->reset (dev);
287
288 audio_devs[dev]->close (dev);
289
290 audio_devs[dev]->dmap->dma_mode = DMODE_NONE;
291 audio_devs[dev]->dmap->flags &= ~DMA_BUSY;
292 RESTORE_INTR (flags);
293
294 return 0;
295 }
296
297 int
298 DMAbuf_getrdbuffer (int dev, char **buf, int *len)
299 {
300 unsigned long flags;
301 int err = EIO;
302 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
303
304 DISABLE_INTR (flags);
305 if (!dmap->qlen)
306 {
307 if (dmap->flags & DMA_RESTART)
308 {
309 dma_reset (dev);
310 dmap->flags &= ~DMA_RESTART;
311 }
312
313 if (dmap->dma_mode == DMODE_OUTPUT)
314 {
315 dma_sync (dev);
316 dma_reset (dev);
317 dmap->dma_mode = DMODE_NONE;
318 }
319
320 if (!(dmap->flags & DMA_ALLOC_DONE))
321 reorganize_buffers (dev);
322
323 if (!dmap->dma_mode)
324 {
325 int err;
326
327 if ((err = audio_devs[dev]->prepare_for_input (dev,
328 dmap->fragment_size, dmap->nbufs)) < 0)
329 {
330 RESTORE_INTR (flags);
331 return err;
332 }
333 dmap->dma_mode = DMODE_INPUT;
334 }
335
336 if (!(dmap->flags & DMA_ACTIVE))
337 {
338 audio_devs[dev]->start_input (dev, dmap->buf_phys[dmap->qtail],
339 dmap->fragment_size, 0,
340 !(audio_devs[dev]->flags & DMA_AUTOMODE) ||
341 !(dmap->flags & DMA_STARTED));
342 dmap->flags |= DMA_ACTIVE | DMA_STARTED;
343 }
344
345
346
347 DO_SLEEP (dev_sleeper[dev], dev_sleep_flag[dev], 2 * HZ);
348 if (TIMED_OUT (dev_sleeper[dev], dev_sleep_flag[dev]))
349 {
350 printk ("Sound: DMA timed out - IRQ/DRQ config error?\n");
351 err = EIO;
352 SET_ABORT_FLAG (dev_sleeper[dev], dev_sleep_flag[dev]);
353 }
354 else
355 err = EINTR;
356 }
357 RESTORE_INTR (flags);
358
359 if (!dmap->qlen)
360 return RET_ERROR (err);
361
362 *buf = &dmap->buf[dmap->qhead][dmap->counts[dmap->qhead]];
363 *len = dmap->fragment_size - dmap->counts[dmap->qhead];
364
365 return dmap->qhead;
366 }
367
368 int
369 DMAbuf_rmchars (int dev, int buff_no, int c)
370 {
371 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
372
373 int p = dmap->counts[dmap->qhead] + c;
374
375 if (p >= dmap->fragment_size)
376 {
377 dmap->counts[dmap->qhead] = 0;
378 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
379 printk ("\nSound: Audio queue1 corrupted for dev%d (%d/%d)\n",
380 dev, dmap->qlen, dmap->nbufs);
381 dmap->qlen--;
382 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
383 }
384 else
385 dmap->counts[dmap->qhead] = p;
386
387 return 0;
388 }
389
390 int
391 DMAbuf_ioctl (int dev, unsigned int cmd, unsigned int arg, int local)
392 {
393 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
394
395 switch (cmd)
396 {
397 case SNDCTL_DSP_RESET:
398 dma_reset (dev);
399 return 0;
400 break;
401
402 case SNDCTL_DSP_SYNC:
403 dma_sync (dev);
404 dma_reset (dev);
405 return 0;
406 break;
407
408 case SNDCTL_DSP_GETBLKSIZE:
409 if (!(dmap->flags & DMA_ALLOC_DONE))
410 reorganize_buffers (dev);
411
412 return IOCTL_OUT (arg, dmap->fragment_size);
413 break;
414
415 case SNDCTL_DSP_SUBDIVIDE:
416 {
417 int fact = IOCTL_IN (arg);
418
419 if (fact == 0)
420 {
421 fact = dmap->subdivision;
422 if (fact == 0)
423 fact = 1;
424 return IOCTL_OUT (arg, fact);
425 }
426
427 if (dmap->subdivision != 0 ||
428 dmap->fragment_size)
429 return RET_ERROR (EINVAL);
430
431 if (fact > MAX_REALTIME_FACTOR)
432 return RET_ERROR (EINVAL);
433
434 if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
435 return RET_ERROR (EINVAL);
436
437 dmap->subdivision = fact;
438 return IOCTL_OUT (arg, fact);
439 }
440 break;
441
442 case SNDCTL_DSP_SETFRAGMENT:
443 {
444 int fact = IOCTL_IN (arg);
445 int bytes, count;
446
447 if (fact == 0)
448 return RET_ERROR (EIO);
449
450 if (dmap->subdivision != 0 ||
451 dmap->fragment_size)
452 return RET_ERROR (EINVAL);
453
454 bytes = fact & 0xffff;
455 count = (fact >> 16) & 0xffff;
456
457 if (count == 0)
458 count = MAX_SUB_BUFFERS;
459
460 if (bytes < 7 || bytes > 17)
461 return RET_ERROR (EINVAL);
462
463 if (count < 2)
464 return RET_ERROR (EINVAL);
465
466 dmap->fragment_size = (1 << bytes);
467 dmap->max_fragments = count;
468
469 if (dmap->fragment_size > audio_devs[dev]->buffsize)
470 dmap->fragment_size = audio_devs[dev]->buffsize;
471
472 if (dmap->fragment_size == audio_devs[dev]->buffsize &&
473 audio_devs[dev]->flags & DMA_AUTOMODE)
474 dmap->fragment_size /= 2;
475
476 dmap->subdivision = 1;
477 return IOCTL_OUT (arg, bytes | (count << 16));
478 }
479 break;
480
481 default:
482 return audio_devs[dev]->ioctl (dev, cmd, arg, local);
483 }
484
485 return RET_ERROR (EIO);
486 }
487
488 static int
489 space_in_queue (int dev)
490 {
491 int len, max, tmp;
492 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
493
494 if (dmap->qlen == dmap->nbufs)
495 return 0;
496
497
498
499
500
501
502 max = dmap->max_fragments;
503 len = dmap->qlen;
504
505 if (audio_devs[dev]->local_qlen)
506 {
507 tmp = audio_devs[dev]->local_qlen (dev);
508 if (tmp & len)
509 tmp--;
510
511
512 len += tmp;
513 }
514
515 if (len >= max)
516 return 0;
517 return 1;
518 }
519
520 int
521 DMAbuf_getwrbuffer (int dev, char **buf, int *size)
522 {
523 unsigned long flags;
524 int abort, err = EIO;
525 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
526
527 if (dmap->dma_mode == DMODE_INPUT)
528 {
529 dma_reset (dev);
530 dmap->dma_mode = DMODE_NONE;
531 }
532 else if (dmap->flags & DMA_RESTART)
533 {
534 dma_sync (dev);
535 dma_reset (dev);
536 }
537
538 dmap->flags &= ~DMA_RESTART;
539
540 if (!(dmap->flags & DMA_ALLOC_DONE))
541 reorganize_buffers (dev);
542
543 if (!dmap->dma_mode)
544 {
545 int err;
546
547 dmap->dma_mode = DMODE_OUTPUT;
548 if ((err = audio_devs[dev]->prepare_for_output (dev,
549 dmap->fragment_size, dmap->nbufs)) < 0)
550 return err;
551 }
552
553
554 DISABLE_INTR (flags);
555
556 abort = 0;
557 while (!space_in_queue (dev) &&
558 !abort)
559 {
560
561
562
563 DO_SLEEP (dev_sleeper[dev], dev_sleep_flag[dev], 2 * HZ);
564 if (TIMED_OUT (dev_sleeper[dev], dev_sleep_flag[dev]))
565 {
566 printk ("Sound: DMA timed out - IRQ/DRQ config error?\n");
567 err = EIO;
568 abort = 1;
569 SET_ABORT_FLAG (dev_sleeper[dev], dev_sleep_flag[dev]);
570 }
571 else if (PROCESS_ABORTING (dev_sleeper[dev], dev_sleep_flag[dev]))
572 {
573 err = EINTR;
574 abort = 1;
575 }
576 }
577 RESTORE_INTR (flags);
578
579 if (!space_in_queue (dev))
580 {
581 return RET_ERROR (err);
582 }
583
584 *buf = dmap->buf[dmap->qtail];
585 *size = dmap->fragment_size;
586 dmap->counts[dmap->qtail] = 0;
587
588 return dmap->qtail;
589 }
590
591 int
592 DMAbuf_start_output (int dev, int buff_no, int l)
593 {
594 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
595
596 if (buff_no != dmap->qtail)
597 printk ("Sound warning: DMA buffers out of sync %d != %d\n", buff_no, dmap->qtail);
598
599 dmap->qlen++;
600 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
601 printk ("\nSound: Audio queue2 corrupted for dev%d (%d/%d)\n",
602 dev, dmap->qlen, dmap->nbufs);
603
604 dmap->counts[dmap->qtail] = l;
605
606 if ((l != dmap->fragment_size) &&
607 ((audio_devs[dev]->flags & DMA_AUTOMODE) &&
608 audio_devs[dev]->flags & NEEDS_RESTART))
609 dmap->flags |= DMA_RESTART;
610 else
611 dmap->flags &= ~DMA_RESTART;
612
613 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
614
615 if (!(dmap->flags & DMA_ACTIVE))
616 {
617 dmap->flags |= DMA_ACTIVE;
618 audio_devs[dev]->output_block (dev, dmap->buf_phys[dmap->qhead],
619 dmap->counts[dmap->qhead], 0,
620 !(audio_devs[dev]->flags & DMA_AUTOMODE) ||
621 !(dmap->flags & DMA_STARTED));
622 dmap->flags |= DMA_STARTED;
623 }
624
625 return 0;
626 }
627
628 int
629 DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
630 {
631 int chan = audio_devs[dev]->dmachan;
632 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
633 unsigned long flags;
634
635
636
637
638
639
640
641
642
643
644 if (audio_devs[dev]->flags & DMA_AUTOMODE)
645 {
646
647
648
649 #ifdef linux
650 DISABLE_INTR (flags);
651 disable_dma (chan);
652 clear_dma_ff (chan);
653 set_dma_mode (chan, dma_mode | DMA_AUTOINIT);
654 set_dma_addr (chan, dmap->raw_buf_phys[0]);
655 set_dma_count (chan, dmap->bytes_in_use);
656 enable_dma (chan);
657 RESTORE_INTR (flags);
658 #else
659
660 #ifdef __386BSD__
661 printk ("sound: Invalid DMA mode for device %d\n", dev);
662
663 isa_dmastart ((dma_mode == DMA_MODE_READ) ? B_READ : B_WRITE,
664 dmap->raw_buf_phys[0],
665 dmap->bytes_in_use,
666 chan);
667 #else
668 #if defined(GENERIC_SYSV)
669 #ifndef DMAMODE_AUTO
670 printk ("sound: Invalid DMA mode for device %d\n", dev);
671 #endif
672 dma_param (chan, ((dma_mode == DMA_MODE_READ) ? DMA_Rdmode : DMA_Wrmode)
673 #ifdef DMAMODE_AUTO
674 | DMAMODE_AUTO
675 #endif
676 ,
677 dmap->raw_buf_phys[0], dmap->bytes_in_use);
678 dma_enable (chan);
679 #else
680 #error This routine is not valid for this OS.
681 #endif
682 #endif
683
684 #endif
685 }
686 else
687 {
688 #ifdef linux
689 DISABLE_INTR (flags);
690 disable_dma (chan);
691 clear_dma_ff (chan);
692 set_dma_mode (chan, dma_mode);
693 set_dma_addr (chan, physaddr);
694 set_dma_count (chan, count);
695 enable_dma (chan);
696 RESTORE_INTR (flags);
697 #else
698 #ifdef __386BSD__
699 isa_dmastart ((dma_mode == DMA_MODE_READ) ? B_READ : B_WRITE,
700 physaddr,
701 count,
702 chan);
703 #else
704
705 #if defined(GENERIC_SYSV)
706 dma_param (chan, ((dma_mode == DMA_MODE_READ) ? DMA_Rdmode : DMA_Wrmode),
707 physaddr, count);
708 dma_enable (chan);
709 #else
710 #error This routine is not valid for this OS.
711 #endif
712 #endif
713
714 #endif
715 }
716
717 return count;
718 }
719
720 long
721 DMAbuf_init (long mem_start)
722 {
723 int dev;
724
725
726
727
728
729 for (dev = 0; dev < num_audiodevs; dev++)
730 audio_devs[dev]->dmap = &dmaps[dev];
731 return mem_start;
732 }
733
734 void
735 DMAbuf_outputintr (int dev, int event_type)
736 {
737
738
739
740
741
742
743
744
745
746
747 unsigned long flags;
748 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
749
750 if (event_type != 2)
751 {
752 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
753 {
754 printk ("\nSound: Audio queue3 corrupted for dev%d (%d/%d)\n",
755 dev, dmap->qlen, dmap->nbufs);
756 return;
757 }
758
759 dmap->qlen--;
760 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
761 dmap->flags &= ~DMA_ACTIVE;
762
763 if (dmap->qlen)
764 {
765 audio_devs[dev]->output_block (dev, dmap->buf_phys[dmap->qhead],
766 dmap->counts[dmap->qhead], 1,
767 !(audio_devs[dev]->flags & DMA_AUTOMODE));
768 dmap->flags |= DMA_ACTIVE;
769 }
770 else if (event_type == 1)
771 {
772 dmap->underrun_count++;
773 audio_devs[dev]->halt_xfer (dev);
774 if ((audio_devs[dev]->flags & DMA_AUTOMODE) &&
775 audio_devs[dev]->flags & NEEDS_RESTART)
776 dmap->flags |= DMA_RESTART;
777 else
778 dmap->flags &= ~DMA_RESTART;
779 }
780 }
781
782 DISABLE_INTR (flags);
783 if (SOMEONE_WAITING (dev_sleeper[dev], dev_sleep_flag[dev]))
784 {
785 WAKE_UP (dev_sleeper[dev], dev_sleep_flag[dev]);
786 }
787 RESTORE_INTR (flags);
788 }
789
790 void
791 DMAbuf_inputintr (int dev)
792 {
793 unsigned long flags;
794 struct dma_buffparms *dmap = audio_devs[dev]->dmap;
795
796 if (dmap->qlen == (dmap->nbufs - 1))
797 {
798 printk ("Sound: Recording overrun\n");
799 dmap->underrun_count++;
800 audio_devs[dev]->halt_xfer (dev);
801 dmap->flags &= ~DMA_ACTIVE;
802 if (audio_devs[dev]->flags & DMA_AUTOMODE)
803 dmap->flags |= DMA_RESTART;
804 else
805 dmap->flags &= ~DMA_RESTART;
806 }
807 else
808 {
809 dmap->qlen++;
810 if (dmap->qlen <= 0 || dmap->qlen > dmap->nbufs)
811 printk ("\nSound: Audio queue4 corrupted for dev%d (%d/%d)\n",
812 dev, dmap->qlen, dmap->nbufs);
813 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
814
815 audio_devs[dev]->start_input (dev, dmap->buf_phys[dmap->qtail],
816 dmap->fragment_size, 1,
817 !(audio_devs[dev]->flags & DMA_AUTOMODE));
818 dmap->flags |= DMA_ACTIVE;
819 }
820
821 DISABLE_INTR (flags);
822 if (SOMEONE_WAITING (dev_sleeper[dev], dev_sleep_flag[dev]))
823 {
824 WAKE_UP (dev_sleeper[dev], dev_sleep_flag[dev]);
825 }
826 RESTORE_INTR (flags);
827 }
828
829 int
830 DMAbuf_open_dma (int dev)
831 {
832 unsigned long flags;
833 int chan = audio_devs[dev]->dmachan;
834
835 if (ALLOC_DMA_CHN (chan,"audio"))
836 {
837 printk ("Unable to grab DMA%d for the audio driver\n", chan);
838 return RET_ERROR (EBUSY);
839 }
840
841 DISABLE_INTR (flags);
842 #ifdef linux
843 disable_dma (chan);
844 clear_dma_ff (chan);
845 #endif
846 RESTORE_INTR (flags);
847
848 return 0;
849 }
850
851 void
852 DMAbuf_close_dma (int dev)
853 {
854 int chan = audio_devs[dev]->dmachan;
855
856 DMAbuf_reset_dma (chan);
857 RELEASE_DMA_CHN (chan);
858 }
859
860 void
861 DMAbuf_reset_dma (int chan)
862 {
863 }
864
865
866
867
868
869
870
871
872
873 #else
874
875
876
877
878 int
879 DMAbuf_open (int dev, int mode)
880 {
881 return RET_ERROR (ENXIO);
882 }
883
884 int
885 DMAbuf_release (int dev, int mode)
886 {
887 return 0;
888 }
889
890 int
891 DMAbuf_getwrbuffer (int dev, char **buf, int *size)
892 {
893 return RET_ERROR (EIO);
894 }
895
896 int
897 DMAbuf_getrdbuffer (int dev, char **buf, int *len)
898 {
899 return RET_ERROR (EIO);
900 }
901
902 int
903 DMAbuf_rmchars (int dev, int buff_no, int c)
904 {
905 return RET_ERROR (EIO);
906 }
907
908 int
909 DMAbuf_start_output (int dev, int buff_no, int l)
910 {
911 return RET_ERROR (EIO);
912 }
913
914 int
915 DMAbuf_ioctl (int dev, unsigned int cmd, unsigned int arg, int local)
916 {
917 return RET_ERROR (EIO);
918 }
919
920 long
921 DMAbuf_init (long mem_start)
922 {
923 return mem_start;
924 }
925
926 int
927 DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
928 {
929 return RET_ERROR (EIO);
930 }
931
932 int
933 DMAbuf_open_dma (int chan)
934 {
935 return RET_ERROR (ENXIO);
936 }
937
938 void
939 DMAbuf_close_dma (int chan)
940 {
941 return;
942 }
943
944 void
945 DMAbuf_reset_dma (int chan)
946 {
947 return;
948 }
949
950 void
951 DMAbuf_inputintr (int dev)
952 {
953 return;
954 }
955
956 void
957 DMAbuf_outputintr (int dev, int underrun_flag)
958 {
959 return;
960 }
961
962 #endif
963
964 #endif