Deleted Added
full compact
dsp.c (54535) dsp.c (55204)
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/sound/pcm/dsp.c 54535 1999-12-13 03:29:09Z cg $
26 * $FreeBSD: head/sys/dev/sound/pcm/dsp.c 55204 1999-12-29 03:46:54Z cg $
27 */
28
29#include <sys/param.h>
30#include <sys/queue.h>
31#include <sys/kernel.h>
32
33#include <dev/sound/pcm/sound.h>
34

--- 177 unchanged lines hidden (view full) ---

212 */
213 s = spltty();
214 switch(cmd) {
215
216 /*
217 * we start with the new ioctl interface.
218 */
219 case AIONWRITE: /* how many bytes can write ? */
27 */
28
29#include <sys/param.h>
30#include <sys/queue.h>
31#include <sys/kernel.h>
32
33#include <dev/sound/pcm/sound.h>
34

--- 177 unchanged lines hidden (view full) ---

212 */
213 s = spltty();
214 switch(cmd) {
215
216 /*
217 * we start with the new ioctl interface.
218 */
219 case AIONWRITE: /* how many bytes can write ? */
220 if (wrch && wrch->buffer.dl) chn_dmaupdate(wrch);
221 *arg_i = wrch? wrch->buffer.fl : 0;
220 if (wrch && wrch->buffer.dl)
221 while (chn_wrfeed(wrch) > 0);
222 *arg_i = wrch? wrch->buffer2nd.fl : 0;
222 break;
223
224 case AIOSSIZE: /* set the current blocksize */
225 {
226 struct snd_size *p = (struct snd_size *)arg;
223 break;
224
225 case AIOSSIZE: /* set the current blocksize */
226 {
227 struct snd_size *p = (struct snd_size *)arg;
227 splx(s);
228 if (wrch) chn_setblocksize(wrch, p->play_size);
229 if (rdch) chn_setblocksize(rdch, p->rec_size);
230 }
231 /* FALLTHROUGH */
232 case AIOGSIZE: /* get the current blocksize */
233 {
234 struct snd_size *p = (struct snd_size *)arg;
228 if (wrch) chn_setblocksize(wrch, p->play_size);
229 if (rdch) chn_setblocksize(rdch, p->rec_size);
230 }
231 /* FALLTHROUGH */
232 case AIOGSIZE: /* get the current blocksize */
233 {
234 struct snd_size *p = (struct snd_size *)arg;
235 if (wrch) p->play_size = wrch->blocksize;
236 if (rdch) p->rec_size = rdch->blocksize;
235 if (wrch) p->play_size = wrch->blocksize2nd;
236 if (rdch) p->rec_size = rdch->blocksize2nd;
237 }
238 break;
239
240 case AIOSFMT:
241 {
242 snd_chan_param *p = (snd_chan_param *)arg;
237 }
238 break;
239
240 case AIOSFMT:
241 {
242 snd_chan_param *p = (snd_chan_param *)arg;
243 splx(s);
244 if (wrch) {
245 chn_setformat(wrch, p->play_format);
246 chn_setspeed(wrch, p->play_rate);
247 }
248 if (rdch) {
249 chn_setformat(rdch, p->rec_format);
250 chn_setspeed(rdch, p->rec_rate);
251 }

--- 15 unchanged lines hidden (view full) ---

267 snd_capabilities *p = (snd_capabilities *)arg;
268 pcmchan_caps *pcaps = NULL, *rcaps = NULL;
269 if (rdch) rcaps = chn_getcaps(rdch);
270 if (wrch) pcaps = chn_getcaps(wrch);
271 p->rate_min = max(rcaps? rcaps->minspeed : 0,
272 pcaps? pcaps->minspeed : 0);
273 p->rate_max = min(rcaps? rcaps->maxspeed : 1000000,
274 pcaps? pcaps->maxspeed : 1000000);
243 if (wrch) {
244 chn_setformat(wrch, p->play_format);
245 chn_setspeed(wrch, p->play_rate);
246 }
247 if (rdch) {
248 chn_setformat(rdch, p->rec_format);
249 chn_setspeed(rdch, p->rec_rate);
250 }

--- 15 unchanged lines hidden (view full) ---

266 snd_capabilities *p = (snd_capabilities *)arg;
267 pcmchan_caps *pcaps = NULL, *rcaps = NULL;
268 if (rdch) rcaps = chn_getcaps(rdch);
269 if (wrch) pcaps = chn_getcaps(wrch);
270 p->rate_min = max(rcaps? rcaps->minspeed : 0,
271 pcaps? pcaps->minspeed : 0);
272 p->rate_max = min(rcaps? rcaps->maxspeed : 1000000,
273 pcaps? pcaps->maxspeed : 1000000);
275 p->bufsize = min(rdch? rdch->buffer.bufsize : 1000000,
276 wrch? wrch->buffer.bufsize : 1000000);
274 p->bufsize = min(rdch? rdch->buffer2nd.bufsize : 1000000,
275 wrch? wrch->buffer2nd.bufsize : 1000000);
277 /* XXX bad on sb16 */
278 p->formats = (rcaps? rcaps->formats : 0xffffffff) &
279 (pcaps? pcaps->formats : 0xffffffff);
280 p->mixers = 1; /* default: one mixer */
281 p->inputs = d->mixer.devs;
282 p->left = p->right = 100;
283 }
284 break;
285
286 case AIOSTOP:
287 if (*arg_i == AIOSYNC_PLAY && wrch) *arg_i = chn_abort(wrch);
288 else if (*arg_i == AIOSYNC_CAPTURE && rdch) *arg_i = chn_abort(rdch);
289 else {
276 /* XXX bad on sb16 */
277 p->formats = (rcaps? rcaps->formats : 0xffffffff) &
278 (pcaps? pcaps->formats : 0xffffffff);
279 p->mixers = 1; /* default: one mixer */
280 p->inputs = d->mixer.devs;
281 p->left = p->right = 100;
282 }
283 break;
284
285 case AIOSTOP:
286 if (*arg_i == AIOSYNC_PLAY && wrch) *arg_i = chn_abort(wrch);
287 else if (*arg_i == AIOSYNC_CAPTURE && rdch) *arg_i = chn_abort(rdch);
288 else {
290 splx(s);
291 printf("AIOSTOP: bad channel 0x%x\n", *arg_i);
292 *arg_i = 0;
293 }
294 break;
295
296 case AIOSYNC:
297 printf("AIOSYNC chan 0x%03lx pos %lu unimplemented\n",
298 ((snd_sync_parm *)arg)->chan, ((snd_sync_parm *)arg)->pos);
299 break;
300 /*
301 * here follow the standard ioctls (filio.h etc.)
302 */
303 case FIONREAD: /* get # bytes to read */
289 printf("AIOSTOP: bad channel 0x%x\n", *arg_i);
290 *arg_i = 0;
291 }
292 break;
293
294 case AIOSYNC:
295 printf("AIOSYNC chan 0x%03lx pos %lu unimplemented\n",
296 ((snd_sync_parm *)arg)->chan, ((snd_sync_parm *)arg)->pos);
297 break;
298 /*
299 * here follow the standard ioctls (filio.h etc.)
300 */
301 case FIONREAD: /* get # bytes to read */
304 if (rdch && rdch->buffer.dl) chn_dmaupdate(rdch);
305 *arg_i = rdch? rdch->buffer.rl : 0;
302 if (rdch && rdch->buffer.dl)
303 while (chn_rdfeed(rdch) > 0);
304 *arg_i = rdch? rdch->buffer2nd.rl : 0;
306 break;
307
308 case FIOASYNC: /*set/clear async i/o */
309 DEB( printf("FIOASYNC\n") ; )
310 break;
311
312 case SNDCTL_DSP_NONBLOCK:
313 case FIONBIO: /* set/clear non-blocking i/o */

--- 6 unchanged lines hidden (view full) ---

320 break;
321
322 /*
323 * Finally, here is the linux-compatible ioctl interface
324 */
325#define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
326 case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
327 case SNDCTL_DSP_GETBLKSIZE:
305 break;
306
307 case FIOASYNC: /*set/clear async i/o */
308 DEB( printf("FIOASYNC\n") ; )
309 break;
310
311 case SNDCTL_DSP_NONBLOCK:
312 case FIONBIO: /* set/clear non-blocking i/o */

--- 6 unchanged lines hidden (view full) ---

319 break;
320
321 /*
322 * Finally, here is the linux-compatible ioctl interface
323 */
324#define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
325 case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
326 case SNDCTL_DSP_GETBLKSIZE:
328 *arg_i = CHN_2NDBUFBLKSIZE;
327 if (wrch)
328 *arg_i = wrch->blocksize2nd;
329 else if (rdch)
330 *arg_i = rdch->blocksize2nd;
331 else
332 *arg_i = 0;
329 break ;
330
331 case SNDCTL_DSP_SETBLKSIZE:
333 break ;
334
335 case SNDCTL_DSP_SETBLKSIZE:
332 splx(s);
333 if (wrch) chn_setblocksize(wrch, *arg_i);
334 if (rdch) chn_setblocksize(rdch, *arg_i);
335 break;
336
337 case SNDCTL_DSP_RESET:
338 DEB(printf("dsp reset\n"));
336 if (wrch) chn_setblocksize(wrch, *arg_i);
337 if (rdch) chn_setblocksize(rdch, *arg_i);
338 break;
339
340 case SNDCTL_DSP_RESET:
341 DEB(printf("dsp reset\n"));
342 splx(s);
339 if (wrch) chn_abort(wrch);
340 if (rdch) chn_abort(rdch);
341 break;
342
343 case SNDCTL_DSP_SYNC:
344 DEB(printf("dsp sync\n"));
345 splx(s);
343 if (wrch) chn_abort(wrch);
344 if (rdch) chn_abort(rdch);
345 break;
346
347 case SNDCTL_DSP_SYNC:
348 DEB(printf("dsp sync\n"));
349 splx(s);
346 if (wrch) chn_sync(wrch, wrch->buffer.bufsize - 4);
350 if (wrch) chn_sync(wrch, wrch->buffer2nd.bufsize - 4);
347 break;
348
349 case SNDCTL_DSP_SPEED:
350 splx(s);
351 if (wrch) chn_setspeed(wrch, *arg_i);
352 if (rdch) chn_setspeed(rdch, *arg_i);
353 /* fallthru */
354

--- 40 unchanged lines hidden (view full) ---

395
396 case SNDCTL_DSP_SETFRAGMENT:
397 /* XXX watch out, this is RW! */
398 DEB(printf("SNDCTL_DSP_SETFRAGMENT 0x%08x\n", *(int *)arg));
399 {
400 int bytes = 1 << min(*arg_i & 0xffff, 16);
401 int count = (*arg_i >> 16) & 0xffff;
402 pcm_channel *c = wrch? wrch : rdch;
351 break;
352
353 case SNDCTL_DSP_SPEED:
354 splx(s);
355 if (wrch) chn_setspeed(wrch, *arg_i);
356 if (rdch) chn_setspeed(rdch, *arg_i);
357 /* fallthru */
358

--- 40 unchanged lines hidden (view full) ---

399
400 case SNDCTL_DSP_SETFRAGMENT:
401 /* XXX watch out, this is RW! */
402 DEB(printf("SNDCTL_DSP_SETFRAGMENT 0x%08x\n", *(int *)arg));
403 {
404 int bytes = 1 << min(*arg_i & 0xffff, 16);
405 int count = (*arg_i >> 16) & 0xffff;
406 pcm_channel *c = wrch? wrch : rdch;
403 splx(s);
404 if (rdch) chn_setblocksize(rdch, bytes);
405 if (wrch) chn_setblocksize(wrch, bytes);
407 if (count == 0)
408 count = CHN_2NDBUFWHOLESIZE / bytes;
409 if (count < 2) {
410 ret = EINVAL;
411 break;
412 }
413 if (rdch) {
414 chn_setblocksize(rdch, bytes * count);
415 rdch->blocksize2nd = bytes;
416 rdch->fragments = rdch->buffer2nd.bufsize / rdch->blocksize2nd;
417 }
418 if (wrch) {
419 chn_setblocksize(wrch, bytes * count);
420 wrch->blocksize2nd = bytes;
421 wrch->fragments = wrch->buffer2nd.bufsize / wrch->blocksize2nd;
422 }
406
407 /* eg: 4dwave can only interrupt at buffer midpoint, so
408 * it will force blocksize == bufsize/2
409 */
423
424 /* eg: 4dwave can only interrupt at buffer midpoint, so
425 * it will force blocksize == bufsize/2
426 */
410 count = c->buffer.bufsize / c->blocksize;
411 bytes = ffs(c->blocksize) - 1;
427 count = c->buffer2nd.bufsize / c->blocksize2nd;
428 bytes = ffs(c->blocksize2nd) - 1;
412 *arg_i = (count << 16) | bytes;
413 }
414 break;
415
429 *arg_i = (count << 16) | bytes;
430 }
431 break;
432
416 case SNDCTL_DSP_GETISPACE:
417 /* return space available in the input queue */
433 case SNDCTL_DSP_GETISPACE: /* XXX Space for reading? Makes no sense... */
434 /* return the size of data available in the input queue */
418 {
419 audio_buf_info *a = (audio_buf_info *)arg;
420 if (rdch) {
421 snd_dbuf *b = &rdch->buffer;
435 {
436 audio_buf_info *a = (audio_buf_info *)arg;
437 if (rdch) {
438 snd_dbuf *b = &rdch->buffer;
422 if (b->dl) chn_dmaupdate(rdch);
423 a->bytes = b->fl;
424 a->fragments = 1;
425 a->fragstotal = b->bufsize / rdch->blocksize;
426 a->fragsize = rdch->blocksize;
439 snd_dbuf *bs = &rdch->buffer2nd;
440 if (b->dl)
441 /*
442 * Suck up the secondary and DMA buffer.
443 * chn_rdfeed*() takes care of the alignment.
444 */
445 while (chn_rdfeed(rdch) > 0);
446 a->bytes = bs->rl;
447 a->fragments = a->bytes / rdch->blocksize2nd;
448 a->fragstotal = bs->bufsize / rdch->blocksize2nd;
449 a->fragsize = rdch->blocksize2nd;
427 }
428 }
429 break;
430
431 case SNDCTL_DSP_GETOSPACE:
432 /* return space available in the output queue */
433 {
434 audio_buf_info *a = (audio_buf_info *)arg;
435 if (wrch) {
436 snd_dbuf *b = &wrch->buffer;
450 }
451 }
452 break;
453
454 case SNDCTL_DSP_GETOSPACE:
455 /* return space available in the output queue */
456 {
457 audio_buf_info *a = (audio_buf_info *)arg;
458 if (wrch) {
459 snd_dbuf *b = &wrch->buffer;
437 if (b->dl) chn_dmaupdate(wrch);
438 a->bytes = b->fl;
439 a->fragments = 1;
440 a->fragstotal = b->bufsize / wrch->blocksize;
441 a->fragsize = wrch->blocksize;
460 snd_dbuf *bs = &wrch->buffer2nd;
461 if (b->dl) {
462 /*
463 * Fill up the secondary and DMA buffer.
464 * chn_wrfeed*() takes care of the alignment.
465 * Check for underflow before writing into the buffers.
466 */
467 chn_checkunderflow(wrch);
468 while (chn_wrfeed(wrch) > 0);
469 }
470 a->bytes = bs->fl;
471 a->fragments = a->bytes / wrch->blocksize2nd;
472 a->fragstotal = bs->bufsize / wrch->blocksize2nd;
473 a->fragsize = wrch->blocksize2nd;
442 }
443 }
444 break;
445
446 case SNDCTL_DSP_GETIPTR:
447 {
448 count_info *a = (count_info *)arg;
449 if (rdch) {
474 }
475 }
476 break;
477
478 case SNDCTL_DSP_GETIPTR:
479 {
480 count_info *a = (count_info *)arg;
481 if (rdch) {
450 snd_dbuf *b = &rdch->buffer;
451 if (b->dl) chn_dmaupdate(rdch);
452 a->bytes = b->total;
453 a->blocks = (b->total - b->prev_total) / rdch->blocksize;
454 a->ptr = b->fp;
455 b->prev_total += a->blocks * rdch->blocksize;
482 snd_dbuf *b = &rdch->buffer;
483 snd_dbuf *bs = &rdch->buffer2nd;
484 if (b->dl)
485 /*
486 * Suck up the secondary and DMA buffer.
487 * chn_rdfeed*() takes care of the alignment.
488 */
489 while (chn_rdfeed(rdch) > 0);
490 a->bytes = bs->total;
491 a->blocks = bs->rl / rdch->blocksize2nd;
492 a->ptr = bs->rl % rdch->blocksize2nd;
456 } else ret = EINVAL;
457 }
458 break;
459
460 case SNDCTL_DSP_GETOPTR:
461 {
462 count_info *a = (count_info *)arg;
463 if (wrch) {
464 snd_dbuf *b = &wrch->buffer;
493 } else ret = EINVAL;
494 }
495 break;
496
497 case SNDCTL_DSP_GETOPTR:
498 {
499 count_info *a = (count_info *)arg;
500 if (wrch) {
501 snd_dbuf *b = &wrch->buffer;
465 if (b->dl) chn_dmaupdate(wrch);
466 a->bytes = b->total;
467 a->blocks = (b->total - b->prev_total) / wrch->blocksize;
468 a->ptr = b->rp;
469 b->prev_total += a->blocks * wrch->blocksize;
502 snd_dbuf *bs = &wrch->buffer2nd;
503 if (b->dl) {
504 /*
505 * Fill up the secondary and DMA buffer.
506 * chn_wrfeed*() takes care of the alignment.
507 * Check for underflow before writing into the buffers.
508 */
509 chn_checkunderflow(wrch);
510 while (chn_wrfeed(wrch) > 0);
511 }
512 a->bytes = bs->total;
513 a->blocks = bs->rl / wrch->blocksize2nd;
514 a->ptr = bs->fl % wrch->blocksize2nd;
470 } else ret = EINVAL;
471 }
472 break;
473
474 case SNDCTL_DSP_GETCAPS:
475 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
476 if (rdch && wrch && !(d->flags & SD_F_SIMPLEX))
477 *arg_i |= DSP_CAP_DUPLEX;

--- 21 unchanged lines hidden (view full) ---

499 case SNDCTL_DSP_GETTRIGGER:
500 *arg_i = 0;
501 if (wrch && wrch->flags & CHN_F_TRIGGERED)
502 *arg_i |= PCM_ENABLE_OUTPUT;
503 if (rdch && rdch->flags & CHN_F_TRIGGERED)
504 *arg_i |= PCM_ENABLE_INPUT;
505 break;
506
515 } else ret = EINVAL;
516 }
517 break;
518
519 case SNDCTL_DSP_GETCAPS:
520 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
521 if (rdch && wrch && !(d->flags & SD_F_SIMPLEX))
522 *arg_i |= DSP_CAP_DUPLEX;

--- 21 unchanged lines hidden (view full) ---

544 case SNDCTL_DSP_GETTRIGGER:
545 *arg_i = 0;
546 if (wrch && wrch->flags & CHN_F_TRIGGERED)
547 *arg_i |= PCM_ENABLE_OUTPUT;
548 if (rdch && rdch->flags & CHN_F_TRIGGERED)
549 *arg_i |= PCM_ENABLE_INPUT;
550 break;
551
507 case SNDCTL_DSP_GETODELAY:
508 if (wrch) {
509 snd_dbuf *b = &wrch->buffer;
510 if (b->dl)
511 chn_dmaupdate(wrch);
512 *arg = b->total;
513 } else
514 ret = EINVAL;
515 break;
552 case SNDCTL_DSP_GETODELAY:
553 if (wrch) {
554 snd_dbuf *b = &wrch->buffer;
555 if (b->dl) {
556 chn_checkunderflow(wrch);
557 while (chn_wrfeed(wrch) > 0);
558 }
559 *arg = b->total;
560 } else
561 ret = EINVAL;
562 break;
516
517 case SNDCTL_DSP_MAPINBUF:
518 case SNDCTL_DSP_MAPOUTBUF:
519 case SNDCTL_DSP_SETSYNCRO:
520 /* undocumented */
521
522 case SNDCTL_DSP_POST:
523 case SOUND_PCM_WRITE_FILTER:

--- 27 unchanged lines hidden (view full) ---

551{
552 pcm_channel *wrch = NULL, *rdch = NULL, *c = NULL;
553
554 getchns(d, chan, &rdch, &wrch);
555 /* XXX this is broken by line 204 of vm/device_pager.c, so force write buffer */
556 if (1 || (wrch && (nprot & PROT_WRITE))) c = wrch;
557 else if (rdch && (nprot & PROT_READ)) c = rdch;
558 if (c) {
563
564 case SNDCTL_DSP_MAPINBUF:
565 case SNDCTL_DSP_MAPOUTBUF:
566 case SNDCTL_DSP_SETSYNCRO:
567 /* undocumented */
568
569 case SNDCTL_DSP_POST:
570 case SOUND_PCM_WRITE_FILTER:

--- 27 unchanged lines hidden (view full) ---

598{
599 pcm_channel *wrch = NULL, *rdch = NULL, *c = NULL;
600
601 getchns(d, chan, &rdch, &wrch);
602 /* XXX this is broken by line 204 of vm/device_pager.c, so force write buffer */
603 if (1 || (wrch && (nprot & PROT_WRITE))) c = wrch;
604 else if (rdch && (nprot & PROT_READ)) c = rdch;
605 if (c) {
606 printf("dsp_mmap.\n");
559 c->flags |= CHN_F_MAPPED;
607 c->flags |= CHN_F_MAPPED;
560 return atop(vtophys(c->buffer.buf + offset));
608 return atop(vtophys(c->buffer2nd.buf + offset));
561 }
562 return -1;
563}
564
609 }
610 return -1;
611}
612