Deleted Added
sdiff udiff text old ( 54535 ) new ( 55204 )
full compact
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 $
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;
222 break;
223
224 case AIOSSIZE: /* set the current blocksize */
225 {
226 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;
235 if (wrch) p->play_size = wrch->blocksize;
236 if (rdch) p->rec_size = rdch->blocksize;
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);
275 p->bufsize = min(rdch? rdch->buffer.bufsize : 1000000,
276 wrch? wrch->buffer.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 {
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 */
304 if (rdch && rdch->buffer.dl) chn_dmaupdate(rdch);
305 *arg_i = rdch? rdch->buffer.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:
328 *arg_i = CHN_2NDBUFBLKSIZE;
329 break ;
330
331 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"));
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);
346 if (wrch) chn_sync(wrch, wrch->buffer.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;
403 splx(s);
404 if (rdch) chn_setblocksize(rdch, bytes);
405 if (wrch) chn_setblocksize(wrch, bytes);
406
407 /* eg: 4dwave can only interrupt at buffer midpoint, so
408 * it will force blocksize == bufsize/2
409 */
410 count = c->buffer.bufsize / c->blocksize;
411 bytes = ffs(c->blocksize) - 1;
412 *arg_i = (count << 16) | bytes;
413 }
414 break;
415
416 case SNDCTL_DSP_GETISPACE:
417 /* return space available in the input queue */
418 {
419 audio_buf_info *a = (audio_buf_info *)arg;
420 if (rdch) {
421 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;
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;
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;
442 }
443 }
444 break;
445
446 case SNDCTL_DSP_GETIPTR:
447 {
448 count_info *a = (count_info *)arg;
449 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;
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;
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;
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
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;
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) {
559 c->flags |= CHN_F_MAPPED;
560 return atop(vtophys(c->buffer.buf + offset));
561 }
562 return -1;
563}
564