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 *
| 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: 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 35static int getchns(snddev_info *d, int chan, pcm_channel **rdch, pcm_channel **wrch); 36 37static pcm_channel * 38allocchn(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 51static int 52getchns(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) { 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 67static void 68setchns(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 76int 77dsp_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 141int 142dsp_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 163int 164dsp_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(wrch, ("dsp_read: nonexistant channel")); 172 KASSERT(wrch->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 181int 182dsp_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 199int 200dsp_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 ? */
| 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 35static int getchns(snddev_info *d, int chan, pcm_channel **rdch, pcm_channel **wrch); 36 37static pcm_channel * 38allocchn(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 51static int 52getchns(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) { 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 67static void 68setchns(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 76int 77dsp_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 141int 142dsp_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 163int 164dsp_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(wrch, ("dsp_read: nonexistant channel")); 172 KASSERT(wrch->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 181int 182dsp_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 199int 200dsp_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) 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 } 252 } 253 /* FALLTHROUGH */ 254 255 case AIOGFMT: 256 { 257 snd_chan_param *p = (snd_chan_param *)arg; 258 p->play_rate = wrch? wrch->speed : 0; 259 p->rec_rate = rdch? rdch->speed : 0; 260 p->play_format = wrch? wrch->format : 0; 261 p->rec_format = rdch? rdch->format : 0; 262 } 263 break; 264 265 case AIOGCAP: /* get capabilities */ 266 { 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 } 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);
|
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 */ 314 if (rdch) rdch->flags &= ~CHN_F_NBIO; 315 if (wrch) wrch->flags &= ~CHN_F_NBIO; 316 if (*arg_i) { 317 if (rdch) rdch->flags |= CHN_F_NBIO; 318 if (wrch) wrch->flags |= CHN_F_NBIO; 319 } 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 */ 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:
|
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 355 case SOUND_PCM_READ_RATE: 356 *arg_i = wrch? wrch->speed : rdch->speed; 357 break; 358 359 case SNDCTL_DSP_STEREO: 360 splx(s); 361 if (wrch) chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | 362 ((*arg_i)? AFMT_STEREO : 0)); 363 if (rdch) chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | 364 ((*arg_i)? AFMT_STEREO : 0)); 365 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 1 : 0; 366 break; 367 368 case SOUND_PCM_WRITE_CHANNELS: 369 splx(s); 370 if (wrch) chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | 371 ((*arg_i == 2)? AFMT_STEREO : 0)); 372 if (rdch) chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | 373 ((*arg_i == 2)? AFMT_STEREO : 0)); 374 /* fallthru */ 375 376 case SOUND_PCM_READ_CHANNELS: 377 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1; 378 break; 379 380 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */ 381 *arg_i = wrch? chn_getcaps(wrch)->formats : chn_getcaps(rdch)->formats; 382 break ; 383 384 case SNDCTL_DSP_SETFMT: /* sets _one_ format */ 385 splx(s); 386 if (wrch) chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO)); 387 if (rdch) chn_setformat(rdch, (*arg_i) | (rdch->format & AFMT_STEREO)); 388 *arg_i = (wrch? wrch->format: rdch->format) & ~AFMT_STEREO; 389 break; 390 391 case SNDCTL_DSP_SUBDIVIDE: 392 /* XXX watch out, this is RW! */ 393 DEB(printf("SNDCTL_DSP_SUBDIVIDE unimplemented\n");) 394 break; 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 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;
|
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; 478 break; 479 480 case SOUND_PCM_READ_BITS: 481 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_16BIT)? 16 : 8; 482 break; 483 484 case SNDCTL_DSP_SETTRIGGER: 485 if (rdch) { 486 rdch->flags &= ~CHN_F_TRIGGERED; 487 if (*arg_i & PCM_ENABLE_INPUT) 488 rdch->flags |= CHN_F_TRIGGERED; 489 chn_intr(rdch); 490 } 491 if (wrch) { 492 wrch->flags &= ~CHN_F_TRIGGERED; 493 if (*arg_i & PCM_ENABLE_OUTPUT) 494 wrch->flags |= CHN_F_TRIGGERED; 495 chn_intr(wrch); 496 } 497 break; 498 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; 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
|
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: 524 case SOUND_PCM_READ_FILTER: 525 /* dunno what these do, don't sound important */ 526 default: 527 DEB(printf("default ioctl chan%d fn 0x%08lx fail\n", chan, cmd)); 528 ret = EINVAL; 529 break; 530 } 531 splx(s); 532 return ret; 533} 534 535int 536dsp_poll(snddev_info *d, int chan, int events, struct proc *p) 537{ 538 int ret = 0, e; 539 pcm_channel *wrch = NULL, *rdch = NULL; 540 541 getchns(d, chan, &rdch, &wrch); 542 e = events & (POLLOUT | POLLWRNORM); 543 if (wrch && e) ret |= chn_poll(wrch, e, p); 544 e = events & (POLLIN | POLLRDNORM); 545 if (rdch && e) ret |= chn_poll(rdch, e, p); 546 return ret; 547} 548 549int 550dsp_mmap(snddev_info *d, int chan, vm_offset_t offset, int nprot) 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: 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 582int 583dsp_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 596int 597dsp_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");
|
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
|