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 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 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$ 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 35 static int getchns(snddev_info *d, int chan, pcm_channel **rdch, pcm_channel **wrch); 36 37 static pcm_channel * 38 allocchn(snddev_info *d, int direction) 39 { 40 pcm_channel *chns = (direction == PCMDIR_PLAY)? d->play : d->rec; 41 int i, cnt = (direction == PCMDIR_PLAY)? d->playcount : d->reccount; 42 for (i = 0; i < cnt; i++) { 43 if (!(chns[i].flags & CHN_F_BUSY)) { 44 chns[i].flags |= CHN_F_BUSY; 45 return &chns[i]; 46 } 47 } 48 return NULL; 49 } 50 51 static int 52 getchns(snddev_info *d, int chan, pcm_channel **rdch, pcm_channel **wrch) 53 { 54 KASSERT((d->flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \ 55 ("getchns: read and write both prioritised")); 56 57 if ((d->flags & SD_F_SIMPLEX) && (d->flags & SD_F_PRIO_SET)) { 58 *rdch = (d->flags & SD_F_PRIO_RD)? d->arec[chan] : &d->fakechan; 59 *wrch = (d->flags & SD_F_PRIO_WR)? d->aplay[chan] : &d->fakechan; 60 } else { 61 *rdch = d->arec[chan]; 62 *wrch = d->aplay[chan]; 63 } 64 return 0; 65 } 66 67 static void 68 setchns(snddev_info *d, int chan) 69 { 70 KASSERT((d->flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \ 71 ("getchns: read and write both prioritised")); 72 d->flags |= SD_F_DIR_SET; 73 if (d->swap) d->swap(d->devinfo, (d->flags & SD_F_PRIO_WR)? PCMDIR_PLAY : PCMDIR_REC); 74 } 75 76 int 77 dsp_open(snddev_info *d, int chan, int oflags, int devtype) 78 { 79 pcm_channel *rdch = NULL, *wrch = NULL; 80 u_int32_t fmt; 81 82 if (chan >= d->chancount) return ENODEV; 83 if (d->aplay[chan] || d->arec[chan]) return EBUSY; 84 if (oflags & FREAD) { 85 rdch = allocchn(d, PCMDIR_REC); 86 if (!rdch) return EBUSY; 87 } 88 if (oflags & FWRITE) { 89 wrch = allocchn(d, PCMDIR_PLAY); 90 if (!wrch) { 91 if (rdch) rdch->flags &= ~CHN_F_BUSY; 92 return EBUSY; 93 } 94 } 95 d->aplay[chan] = wrch; 96 d->arec[chan] = rdch; 97 switch (devtype) { 98 case SND_DEV_DSP16: 99 fmt = AFMT_S16_LE; 100 break; 101 102 case SND_DEV_DSP: 103 fmt = AFMT_U8; 104 break; 105 106 case SND_DEV_AUDIO: 107 fmt = AFMT_MU_LAW; 108 break; 109 110 case SND_DEV_NORESET: 111 fmt = 0; 112 break; 113 114 default: 115 return ENXIO; 116 } 117 118 if (rdch) { 119 chn_reset(rdch); 120 if (oflags & O_NONBLOCK) rdch->flags |= CHN_F_NBIO; 121 if (fmt) { 122 rdch->volume = (100 << 8) | 100; 123 rdch->format = fmt; 124 rdch->speed = DSP_DEFAULT_SPEED; 125 rdch->blocksize = 2048; 126 } 127 } 128 if (wrch) { 129 chn_reset(wrch); 130 if (oflags & O_NONBLOCK) wrch->flags |= CHN_F_NBIO; 131 if (fmt) { 132 wrch->volume = (100 << 8) | 100; 133 wrch->format = fmt; 134 wrch->speed = DSP_DEFAULT_SPEED; 135 wrch->blocksize = 2048; 136 } 137 } 138 return 0; 139 } 140 141 int 142 dsp_close(snddev_info *d, int chan, int devtype) 143 { 144 pcm_channel *rdch, *wrch; 145 146 d->flags &= ~SD_F_TRANSIENT; 147 rdch = d->arec[chan]; 148 wrch = d->aplay[chan]; 149 150 if (rdch) { 151 chn_abort(rdch); 152 rdch->flags &= ~(CHN_F_BUSY | CHN_F_RUNNING | CHN_F_MAPPED); 153 } 154 if (wrch) { 155 chn_flush(wrch); 156 wrch->flags &= ~(CHN_F_BUSY | CHN_F_RUNNING | CHN_F_MAPPED); 157 } 158 d->aplay[chan] = NULL; 159 d->arec[chan] = NULL; 160 return 0; 161 } 162 163 int 164 dsp_read(snddev_info *d, int chan, struct uio *buf, int flag) 165 { 166 pcm_channel *rdch, *wrch; 167 168 if (!(d->flags & SD_F_PRIO_SET)) d->flags |= SD_F_PRIO_RD; 169 if (!(d->flags & SD_F_DIR_SET)) setchns(d, chan); 170 getchns(d, chan, &rdch, &wrch); 171 KASSERT(rdch, ("dsp_read: nonexistant channel")); 172 KASSERT(rdch->flags & CHN_F_BUSY, ("dsp_read: nonbusy channel")); 173 if (rdch->flags & CHN_F_MAPPED) return EINVAL; 174 if (!(rdch->flags & CHN_F_RUNNING)) { 175 rdch->flags |= CHN_F_RUNNING; 176 chn_reinit(rdch); 177 } 178 return chn_read(rdch, buf); 179 } 180 181 int 182 dsp_write(snddev_info *d, int chan, struct uio *buf, int flag) 183 { 184 pcm_channel *rdch, *wrch; 185 186 if (!(d->flags & SD_F_PRIO_SET)) d->flags |= SD_F_PRIO_WR; 187 if (!(d->flags & SD_F_DIR_SET)) setchns(d, chan); 188 getchns(d, chan, &rdch, &wrch); 189 KASSERT(wrch, ("dsp_write: nonexistant channel")); 190 KASSERT(wrch->flags & CHN_F_BUSY, ("dsp_write: nonbusy channel")); 191 if (wrch->flags & CHN_F_MAPPED) return EINVAL; 192 if (!(wrch->flags & CHN_F_RUNNING)) { 193 wrch->flags |= CHN_F_RUNNING; 194 chn_reinit(wrch); 195 } 196 return chn_write(wrch, buf); 197 } 198 199 int 200 dsp_ioctl(snddev_info *d, int chan, u_long cmd, caddr_t arg) 201 { 202 int ret = 0, *arg_i = (int *)arg; 203 u_long s; 204 pcm_channel *wrch = NULL, *rdch = NULL; 205 206 rdch = d->arec[chan]; 207 wrch = d->aplay[chan]; 208 209 /* 210 * all routines are called with int. blocked. Make sure that 211 * ints are re-enabled when calling slow or blocking functions! 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) 221 while (chn_wrfeed(wrch) > 0); 222 *arg_i = wrch? wrch->buffer2nd.fl : 0; 223 break; 224 225 case AIOSSIZE: /* set the current blocksize */ 226 { 227 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->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; 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 } 251 } 252 /* FALLTHROUGH */ 253 254 case AIOGFMT: 255 { 256 snd_chan_param *p = (snd_chan_param *)arg; 257 p->play_rate = wrch? wrch->speed : 0; 258 p->rec_rate = rdch? rdch->speed : 0; 259 p->play_format = wrch? wrch->format : 0; 260 p->rec_format = rdch? rdch->format : 0; 261 } 262 break; 263 264 case AIOGCAP: /* get capabilities */ 265 { 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); 274 p->bufsize = min(rdch? rdch->buffer2nd.bufsize : 1000000, 275 wrch? wrch->buffer2nd.bufsize : 1000000); 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 { 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 */ 302 if (rdch && rdch->buffer.dl) 303 while (chn_rdfeed(rdch) > 0); 304 *arg_i = rdch? rdch->buffer2nd.rl : 0; 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 */ 313 if (rdch) rdch->flags &= ~CHN_F_NBIO; 314 if (wrch) wrch->flags &= ~CHN_F_NBIO; 315 if (*arg_i) { 316 if (rdch) rdch->flags |= CHN_F_NBIO; 317 if (wrch) wrch->flags |= CHN_F_NBIO; 318 } 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: 327 if (wrch) 328 *arg_i = wrch->blocksize2nd; 329 else if (rdch) 330 *arg_i = rdch->blocksize2nd; 331 else 332 *arg_i = 0; 333 break ; 334 335 case SNDCTL_DSP_SETBLKSIZE: 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); 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); 350 if (wrch) chn_sync(wrch, wrch->buffer2nd.bufsize - 4); 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 359 case SOUND_PCM_READ_RATE: 360 *arg_i = wrch? wrch->speed : rdch->speed; 361 break; 362 363 case SNDCTL_DSP_STEREO: 364 splx(s); 365 if (wrch) chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | 366 ((*arg_i)? AFMT_STEREO : 0)); 367 if (rdch) chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | 368 ((*arg_i)? AFMT_STEREO : 0)); 369 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 1 : 0; 370 break; 371 372 case SOUND_PCM_WRITE_CHANNELS: 373 splx(s); 374 if (wrch) chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | 375 ((*arg_i == 2)? AFMT_STEREO : 0)); 376 if (rdch) chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | 377 ((*arg_i == 2)? AFMT_STEREO : 0)); 378 /* fallthru */ 379 380 case SOUND_PCM_READ_CHANNELS: 381 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1; 382 break; 383 384 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */ 385 *arg_i = wrch? chn_getcaps(wrch)->formats : chn_getcaps(rdch)->formats; 386 break ; 387 388 case SNDCTL_DSP_SETFMT: /* sets _one_ format */ 389 splx(s); 390 if (wrch) chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO)); 391 if (rdch) chn_setformat(rdch, (*arg_i) | (rdch->format & AFMT_STEREO)); 392 *arg_i = (wrch? wrch->format: rdch->format) & ~AFMT_STEREO; 393 break; 394 395 case SNDCTL_DSP_SUBDIVIDE: 396 /* XXX watch out, this is RW! */ 397 DEB(printf("SNDCTL_DSP_SUBDIVIDE unimplemented\n");) 398 break; 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; 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 } 423 424 /* eg: 4dwave can only interrupt at buffer midpoint, so 425 * it will force blocksize == bufsize/2 426 */ 427 count = c->buffer2nd.bufsize / c->blocksize2nd; 428 bytes = ffs(c->blocksize2nd) - 1; 429 *arg_i = (count << 16) | bytes; 430 } 431 break; 432 433 case SNDCTL_DSP_GETISPACE: /* XXX Space for reading? Makes no sense... */ 434 /* return the size of data available in the input queue */ 435 { 436 audio_buf_info *a = (audio_buf_info *)arg; 437 if (rdch) { 438 snd_dbuf *b = &rdch->buffer; 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; 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; 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; 474 } 475 } 476 break; 477 478 case SNDCTL_DSP_GETIPTR: 479 { 480 count_info *a = (count_info *)arg; 481 if (rdch) { 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; 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; 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; 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; 523 break; 524 525 case SOUND_PCM_READ_BITS: 526 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_16BIT)? 16 : 8; 527 break; 528 529 case SNDCTL_DSP_SETTRIGGER: 530 if (rdch) { 531 rdch->flags &= ~CHN_F_TRIGGERED; 532 if (*arg_i & PCM_ENABLE_INPUT) 533 rdch->flags |= CHN_F_TRIGGERED; 534 chn_intr(rdch); 535 } 536 if (wrch) { 537 wrch->flags &= ~CHN_F_TRIGGERED; 538 if (*arg_i & PCM_ENABLE_OUTPUT) 539 wrch->flags |= CHN_F_TRIGGERED; 540 chn_intr(wrch); 541 } 542 break; 543 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 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; 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: 571 case SOUND_PCM_READ_FILTER: 572 /* dunno what these do, don't sound important */ 573 default: 574 DEB(printf("default ioctl chan%d fn 0x%08lx fail\n", chan, cmd)); 575 ret = EINVAL; 576 break; 577 } 578 splx(s); 579 return ret; 580 } 581 582 int 583 dsp_poll(snddev_info *d, int chan, int events, struct proc *p) 584 { 585 int ret = 0, e; 586 pcm_channel *wrch = NULL, *rdch = NULL; 587 588 getchns(d, chan, &rdch, &wrch); 589 e = events & (POLLOUT | POLLWRNORM); 590 if (wrch && e) ret |= chn_poll(wrch, e, p); 591 e = events & (POLLIN | POLLRDNORM); 592 if (rdch && e) ret |= chn_poll(rdch, e, p); 593 return ret; 594 } 595 596 int 597 dsp_mmap(snddev_info *d, int chan, vm_offset_t offset, int nprot) 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"); 607 c->flags |= CHN_F_MAPPED; 608 return atop(vtophys(c->buffer2nd.buf + offset)); 609 } 610 return -1; 611 } 612 613