1 1.85 riastrad /* $NetBSD: ossaudio.c,v 1.85 2023/06/20 15:22:04 riastradh Exp $ */ 2 1.22 augustss 3 1.27 augustss /*- 4 1.62 ad * Copyright (c) 1997, 2008 The NetBSD Foundation, Inc. 5 1.22 augustss * All rights reserved. 6 1.22 augustss * 7 1.22 augustss * Redistribution and use in source and binary forms, with or without 8 1.22 augustss * modification, are permitted provided that the following conditions 9 1.22 augustss * are met: 10 1.22 augustss * 1. Redistributions of source code must retain the above copyright 11 1.22 augustss * notice, this list of conditions and the following disclaimer. 12 1.22 augustss * 2. Redistributions in binary form must reproduce the above copyright 13 1.22 augustss * notice, this list of conditions and the following disclaimer in the 14 1.22 augustss * documentation and/or other materials provided with the distribution. 15 1.22 augustss * 16 1.22 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 1.22 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.22 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.22 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.22 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.22 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.22 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.22 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.22 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.22 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.22 augustss * POSSIBILITY OF SUCH DAMAGE. 27 1.22 augustss */ 28 1.38 lukem 29 1.38 lukem #include <sys/cdefs.h> 30 1.85 riastrad __KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.85 2023/06/20 15:22:04 riastradh Exp $"); 31 1.22 augustss 32 1.1 mycroft #include <sys/param.h> 33 1.1 mycroft #include <sys/proc.h> 34 1.1 mycroft #include <sys/systm.h> 35 1.1 mycroft #include <sys/file.h> 36 1.6 augustss #include <sys/vnode.h> 37 1.1 mycroft #include <sys/filedesc.h> 38 1.1 mycroft #include <sys/ioctl.h> 39 1.1 mycroft #include <sys/mount.h> 40 1.26 augustss #include <sys/kernel.h> 41 1.1 mycroft #include <sys/audioio.h> 42 1.26 augustss #include <sys/midiio.h> 43 1.62 ad #include <sys/kauth.h> 44 1.1 mycroft #include <sys/syscallargs.h> 45 1.64 ad #include <sys/module.h> 46 1.1 mycroft 47 1.6 augustss #include <compat/ossaudio/ossaudio.h> 48 1.6 augustss #include <compat/ossaudio/ossaudiovar.h> 49 1.6 augustss 50 1.68 christos MODULE(MODULE_CLASS_EXEC, compat_ossaudio, NULL); 51 1.64 ad 52 1.16 augustss #ifdef AUDIO_DEBUG 53 1.16 augustss #define DPRINTF(x) if (ossdebug) printf x 54 1.16 augustss int ossdebug = 0; 55 1.16 augustss #else 56 1.16 augustss #define DPRINTF(x) 57 1.16 augustss #endif 58 1.16 augustss 59 1.32 tron #define TO_OSSVOL(x) (((x) * 100 + 127) / 255) 60 1.32 tron #define FROM_OSSVOL(x) ((((x) > 100 ? 100 : (x)) * 255 + 50) / 100) 61 1.17 augustss 62 1.78 isaki #define GETPRINFO(info, name) \ 63 1.78 isaki (((info)->mode == AUMODE_RECORD) \ 64 1.78 isaki ? (info)->record.name : (info)->play.name) 65 1.78 isaki 66 1.62 ad static struct audiodevinfo *getdevinfo(file_t *); 67 1.31 augustss static int opaque_to_enum(struct audiodevinfo *di, audio_mixer_name_t *label, int opq); 68 1.31 augustss static int enum_to_ord(struct audiodevinfo *di, int enm); 69 1.31 augustss static int enum_to_mask(struct audiodevinfo *di, int enm); 70 1.1 mycroft 71 1.81 nia static void setchannels(file_t *, int, int); 72 1.62 ad static void setblocksize(file_t *, struct audio_info *); 73 1.14 augustss 74 1.65 christos #ifdef AUDIO_DEBUG 75 1.65 christos static const char * 76 1.65 christos compat_ossaudio_getcmd(u_long cmd) 77 1.65 christos { 78 1.65 christos static char buf[64]; 79 1.65 christos switch (cmd) { 80 1.65 christos #define _DO(_a) \ 81 1.65 christos case _a: \ 82 1.65 christos return # _a; 83 1.65 christos _DO(OSS_SNDCTL_DSP_RESET) 84 1.65 christos _DO(OSS_SNDCTL_DSP_SYNC) 85 1.65 christos _DO(OSS_SNDCTL_DSP_SPEED) 86 1.65 christos _DO(OSS_SOUND_PCM_READ_RATE) 87 1.65 christos _DO(OSS_SNDCTL_DSP_STEREO) 88 1.65 christos _DO(OSS_SNDCTL_DSP_GETBLKSIZE) 89 1.65 christos _DO(OSS_SNDCTL_DSP_SETFMT) 90 1.65 christos _DO(OSS_SOUND_PCM_READ_BITS) 91 1.65 christos _DO(OSS_SNDCTL_DSP_CHANNELS) 92 1.65 christos _DO(OSS_SOUND_PCM_READ_CHANNELS) 93 1.65 christos _DO(OSS_SOUND_PCM_WRITE_FILTER) 94 1.65 christos _DO(OSS_SOUND_PCM_READ_FILTER) 95 1.65 christos _DO(OSS_SNDCTL_DSP_POST) 96 1.65 christos _DO(OSS_SNDCTL_DSP_SUBDIVIDE) 97 1.65 christos _DO(OSS_SNDCTL_DSP_SETFRAGMENT) 98 1.65 christos _DO(OSS_SNDCTL_DSP_GETFMTS) 99 1.65 christos _DO(OSS_SNDCTL_DSP_GETOSPACE) 100 1.65 christos _DO(OSS_SNDCTL_DSP_GETISPACE) 101 1.65 christos _DO(OSS_SNDCTL_DSP_NONBLOCK) 102 1.65 christos _DO(OSS_SNDCTL_DSP_GETCAPS) 103 1.65 christos _DO(OSS_SNDCTL_DSP_GETTRIGGER) 104 1.65 christos _DO(OSS_SNDCTL_DSP_SETTRIGGER) 105 1.65 christos _DO(OSS_SNDCTL_DSP_GETIPTR) 106 1.65 christos _DO(OSS_SNDCTL_DSP_GETOPTR) 107 1.65 christos _DO(OSS_SNDCTL_DSP_MAPINBUF) 108 1.65 christos _DO(OSS_SNDCTL_DSP_MAPOUTBUF) 109 1.65 christos _DO(OSS_SNDCTL_DSP_SETSYNCRO) 110 1.65 christos _DO(OSS_SNDCTL_DSP_SETDUPLEX) 111 1.65 christos _DO(OSS_SNDCTL_DSP_GETODELAY) 112 1.65 christos _DO(OSS_SNDCTL_DSP_PROFILE) 113 1.65 christos _DO(OSS_SOUND_MIXER_INFO) 114 1.65 christos _DO(OSS_SOUND_OLD_MIXER_INFO) 115 1.65 christos _DO(OSS_GET_VERSION) 116 1.65 christos _DO(OSS_SEQ_RESET) 117 1.65 christos _DO(OSS_SEQ_SYNC) 118 1.65 christos _DO(OSS_SYNTH_INFO) 119 1.65 christos _DO(OSS_SEQ_CTRLRATE) 120 1.65 christos _DO(OSS_SEQ_GETOUTCOUNT) 121 1.65 christos _DO(OSS_SEQ_GETINCOUNT) 122 1.65 christos _DO(OSS_SEQ_PERCMODE) 123 1.65 christos _DO(OSS_SEQ_TESTMIDI) 124 1.65 christos _DO(OSS_SEQ_RESETSAMPLES) 125 1.65 christos _DO(OSS_SEQ_NRSYNTHS) 126 1.65 christos _DO(OSS_SEQ_NRMIDIS) 127 1.65 christos #ifdef notyet 128 1.65 christos _DO(OSS_MIDI_INFO) 129 1.65 christos #endif 130 1.65 christos _DO(OSS_SEQ_THRESHOLD) 131 1.65 christos _DO(OSS_MEMAVL) 132 1.65 christos _DO(OSS_FM_4OP_ENABLE) 133 1.65 christos _DO(OSS_SEQ_PANIC) 134 1.65 christos _DO(OSS_SEQ_OUTOFBAND) 135 1.65 christos _DO(OSS_SEQ_GETTIME) 136 1.65 christos _DO(OSS_ID) 137 1.65 christos _DO(OSS_CONTROL) 138 1.65 christos _DO(OSS_REMOVESAMPLE) 139 1.65 christos _DO(OSS_TMR_TIMEBASE) 140 1.65 christos _DO(OSS_TMR_START) 141 1.65 christos _DO(OSS_TMR_STOP) 142 1.65 christos _DO(OSS_TMR_CONTINUE) 143 1.65 christos _DO(OSS_TMR_TEMPO) 144 1.65 christos _DO(OSS_TMR_SOURCE) 145 1.65 christos _DO(OSS_TMR_METRONOME) 146 1.65 christos _DO(OSS_TMR_SELECT) 147 1.65 christos #undef _DO 148 1.65 christos default: 149 1.65 christos (void)snprintf(buf, sizeof(buf), "*0x%lx*", cmd); 150 1.65 christos return buf; 151 1.65 christos } 152 1.65 christos } 153 1.65 christos #endif 154 1.65 christos 155 1.65 christos 156 1.64 ad static int 157 1.64 ad compat_ossaudio_modcmd(modcmd_t cmd, void *arg) 158 1.64 ad { 159 1.64 ad 160 1.64 ad switch (cmd) { 161 1.64 ad case MODULE_CMD_INIT: 162 1.64 ad case MODULE_CMD_FINI: 163 1.64 ad return 0; 164 1.64 ad default: 165 1.64 ad return ENOTTY; 166 1.64 ad } 167 1.64 ad } 168 1.16 augustss 169 1.1 mycroft int 170 1.61 dsl oss_ioctl_audio(struct lwp *l, const struct oss_sys_ioctl_args *uap, register_t *retval) 171 1.61 dsl { 172 1.61 dsl /* { 173 1.1 mycroft syscallarg(int) fd; 174 1.1 mycroft syscallarg(u_long) com; 175 1.55 christos syscallarg(void *) data; 176 1.61 dsl } */ 177 1.62 ad file_t *fp; 178 1.1 mycroft u_long com; 179 1.79 nia struct audio_info tmpinfo, hwfmt; 180 1.13 augustss struct audio_offset tmpoffs; 181 1.13 augustss struct oss_audio_buf_info bufinfo; 182 1.13 augustss struct oss_count_info cntinfo; 183 1.16 augustss struct audio_encoding tmpenc; 184 1.21 augustss u_int u; 185 1.78 isaki u_int encoding; 186 1.78 isaki u_int precision; 187 1.13 augustss int idat, idata; 188 1.28 thorpej int error = 0; 189 1.62 ad int (*ioctlf)(file_t *, u_long, void *); 190 1.1 mycroft 191 1.62 ad if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) 192 1.1 mycroft return (EBADF); 193 1.1 mycroft 194 1.28 thorpej if ((fp->f_flag & (FREAD | FWRITE)) == 0) { 195 1.28 thorpej error = EBADF; 196 1.28 thorpej goto out; 197 1.28 thorpej } 198 1.1 mycroft 199 1.26 augustss com = SCARG(uap, com); 200 1.65 christos DPRINTF(("%s: com=%s\n", __func__, compat_ossaudio_getcmd(com))); 201 1.6 augustss 202 1.1 mycroft retval[0] = 0; 203 1.1 mycroft 204 1.26 augustss ioctlf = fp->f_ops->fo_ioctl; 205 1.1 mycroft switch (com) { 206 1.6 augustss case OSS_SNDCTL_DSP_RESET: 207 1.62 ad error = ioctlf(fp, AUDIO_FLUSH, NULL); 208 1.65 christos if (error) { 209 1.65 christos DPRINTF(("%s: AUDIO_FLUSH %d\n", __func__, error)); 210 1.28 thorpej goto out; 211 1.65 christos } 212 1.1 mycroft break; 213 1.6 augustss case OSS_SNDCTL_DSP_SYNC: 214 1.62 ad error = ioctlf(fp, AUDIO_DRAIN, NULL); 215 1.65 christos if (error) { 216 1.65 christos DPRINTF(("%s: AUDIO_DRAIN %d\n", __func__, error)); 217 1.28 thorpej goto out; 218 1.65 christos } 219 1.39 mycroft break; 220 1.39 mycroft case OSS_SNDCTL_DSP_POST: 221 1.39 mycroft /* This call is merely advisory, and may be a nop. */ 222 1.1 mycroft break; 223 1.6 augustss case OSS_SNDCTL_DSP_SPEED: 224 1.50 xtraeme AUDIO_INITINFO(&tmpinfo); 225 1.1 mycroft error = copyin(SCARG(uap, data), &idat, sizeof idat); 226 1.65 christos if (error) { 227 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SPEED %d\n", 228 1.65 christos __func__, error)); 229 1.28 thorpej goto out; 230 1.65 christos } 231 1.1 mycroft tmpinfo.play.sample_rate = 232 1.1 mycroft tmpinfo.record.sample_rate = idat; 233 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SPEED > %d\n", __func__, idat)); 234 1.79 nia /* 235 1.79 nia * The default NetBSD behavior if an unsupported sample rate 236 1.79 nia * is set is to return an error code and keep the rate at the 237 1.79 nia * default of 8000 Hz. 238 1.79 nia * 239 1.79 nia * However, the OSS expectation is a sample rate supported by 240 1.79 nia * the hardware is returned if the exact rate could not be set. 241 1.79 nia * 242 1.79 nia * So, if the chosen sample rate is invalid, set and return 243 1.79 nia * the current hardware rate. 244 1.79 nia */ 245 1.79 nia if (ioctlf(fp, AUDIO_SETINFO, &tmpinfo) != 0) { 246 1.79 nia error = ioctlf(fp, AUDIO_GETFORMAT, &hwfmt); 247 1.79 nia if (error) { 248 1.79 nia DPRINTF(("%s: AUDIO_GETFORMAT %d\n", 249 1.79 nia __func__, error)); 250 1.79 nia goto out; 251 1.79 nia } 252 1.79 nia error = ioctlf(fp, AUDIO_GETINFO, &tmpinfo); 253 1.79 nia if (error) { 254 1.79 nia DPRINTF(("%s: AUDIO_GETINFO %d\n", 255 1.79 nia __func__, error)); 256 1.79 nia goto out; 257 1.79 nia } 258 1.79 nia tmpinfo.play.sample_rate = 259 1.79 nia tmpinfo.record.sample_rate = 260 1.79 nia (tmpinfo.mode == AUMODE_RECORD) ? 261 1.79 nia hwfmt.record.sample_rate : 262 1.79 nia hwfmt.play.sample_rate; 263 1.79 nia error = ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 264 1.79 nia if (error) { 265 1.79 nia DPRINTF(("%s: SNDCTL_DSP_SPEED %d = %d\n", 266 1.79 nia __func__, idat, error)); 267 1.79 nia goto out; 268 1.79 nia } 269 1.65 christos } 270 1.74 mrg /* FALLTHROUGH */ 271 1.6 augustss case OSS_SOUND_PCM_READ_RATE: 272 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 273 1.65 christos if (error) { 274 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 275 1.65 christos __func__, error)); 276 1.28 thorpej goto out; 277 1.65 christos } 278 1.78 isaki idat = GETPRINFO(&tmpinfo, sample_rate); 279 1.65 christos DPRINTF(("%s: SNDCTL_PCM_READ_RATE < %d\n", __func__, idat)); 280 1.1 mycroft error = copyout(&idat, SCARG(uap, data), sizeof idat); 281 1.65 christos if (error) { 282 1.65 christos DPRINTF(("%s: SOUND_PCM_READ_RATE %d = %d\n", 283 1.65 christos __func__, idat, error)); 284 1.28 thorpej goto out; 285 1.65 christos } 286 1.1 mycroft break; 287 1.6 augustss case OSS_SNDCTL_DSP_STEREO: 288 1.50 xtraeme AUDIO_INITINFO(&tmpinfo); 289 1.1 mycroft error = copyin(SCARG(uap, data), &idat, sizeof idat); 290 1.65 christos if (error) { 291 1.65 christos DPRINTF(("%s: SNDCTL_DSP_STEREO %d\n", 292 1.65 christos __func__, error)); 293 1.28 thorpej goto out; 294 1.65 christos } 295 1.1 mycroft tmpinfo.play.channels = 296 1.1 mycroft tmpinfo.record.channels = idat ? 2 : 1; 297 1.65 christos error = ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 298 1.65 christos if (error) { 299 1.65 christos DPRINTF(("%s: AUDIO_SETINFO %d\n", 300 1.65 christos __func__, error)); 301 1.65 christos goto out; 302 1.65 christos } 303 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 304 1.65 christos if (error) { 305 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 306 1.65 christos __func__, error)); 307 1.28 thorpej goto out; 308 1.65 christos } 309 1.78 isaki idat = GETPRINFO(&tmpinfo, channels) - 1; 310 1.1 mycroft error = copyout(&idat, SCARG(uap, data), sizeof idat); 311 1.65 christos if (error) { 312 1.65 christos DPRINTF(("%s: SNDCTL_DSP_STEREO %d = %d\n", 313 1.65 christos __func__, idat, error)); 314 1.28 thorpej goto out; 315 1.65 christos } 316 1.1 mycroft break; 317 1.6 augustss case OSS_SNDCTL_DSP_GETBLKSIZE: 318 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 319 1.65 christos if (error) { 320 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 321 1.65 christos __func__, error)); 322 1.28 thorpej goto out; 323 1.65 christos } 324 1.62 ad setblocksize(fp, &tmpinfo); 325 1.1 mycroft idat = tmpinfo.blocksize; 326 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETBLKSIZE < %d\n", 327 1.65 christos __func__, idat)); 328 1.1 mycroft error = copyout(&idat, SCARG(uap, data), sizeof idat); 329 1.65 christos if (error) { 330 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETBLKSIZE %d = %d\n", 331 1.65 christos __func__, idat, error)); 332 1.28 thorpej goto out; 333 1.65 christos } 334 1.1 mycroft break; 335 1.6 augustss case OSS_SNDCTL_DSP_SETFMT: 336 1.50 xtraeme AUDIO_INITINFO(&tmpinfo); 337 1.1 mycroft error = copyin(SCARG(uap, data), &idat, sizeof idat); 338 1.65 christos if (error) { 339 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SETFMT %d\n", 340 1.65 christos __func__, error)); 341 1.28 thorpej goto out; 342 1.65 christos } 343 1.1 mycroft switch (idat) { 344 1.6 augustss case OSS_AFMT_MU_LAW: 345 1.1 mycroft tmpinfo.play.precision = 346 1.1 mycroft tmpinfo.record.precision = 8; 347 1.1 mycroft tmpinfo.play.encoding = 348 1.1 mycroft tmpinfo.record.encoding = AUDIO_ENCODING_ULAW; 349 1.1 mycroft break; 350 1.6 augustss case OSS_AFMT_A_LAW: 351 1.1 mycroft tmpinfo.play.precision = 352 1.1 mycroft tmpinfo.record.precision = 8; 353 1.1 mycroft tmpinfo.play.encoding = 354 1.1 mycroft tmpinfo.record.encoding = AUDIO_ENCODING_ALAW; 355 1.1 mycroft break; 356 1.6 augustss case OSS_AFMT_U8: 357 1.1 mycroft tmpinfo.play.precision = 358 1.1 mycroft tmpinfo.record.precision = 8; 359 1.1 mycroft tmpinfo.play.encoding = 360 1.8 augustss tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR; 361 1.8 augustss break; 362 1.8 augustss case OSS_AFMT_S8: 363 1.8 augustss tmpinfo.play.precision = 364 1.8 augustss tmpinfo.record.precision = 8; 365 1.8 augustss tmpinfo.play.encoding = 366 1.12 augustss tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR; 367 1.1 mycroft break; 368 1.6 augustss case OSS_AFMT_S16_LE: 369 1.1 mycroft tmpinfo.play.precision = 370 1.1 mycroft tmpinfo.record.precision = 16; 371 1.1 mycroft tmpinfo.play.encoding = 372 1.12 augustss tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR_LE; 373 1.8 augustss break; 374 1.8 augustss case OSS_AFMT_S16_BE: 375 1.8 augustss tmpinfo.play.precision = 376 1.8 augustss tmpinfo.record.precision = 16; 377 1.8 augustss tmpinfo.play.encoding = 378 1.12 augustss tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR_BE; 379 1.8 augustss break; 380 1.8 augustss case OSS_AFMT_U16_LE: 381 1.8 augustss tmpinfo.play.precision = 382 1.8 augustss tmpinfo.record.precision = 16; 383 1.8 augustss tmpinfo.play.encoding = 384 1.8 augustss tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR_LE; 385 1.8 augustss break; 386 1.8 augustss case OSS_AFMT_U16_BE: 387 1.8 augustss tmpinfo.play.precision = 388 1.8 augustss tmpinfo.record.precision = 16; 389 1.8 augustss tmpinfo.play.encoding = 390 1.8 augustss tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR_BE; 391 1.1 mycroft break; 392 1.66 jmcneill case OSS_AFMT_AC3: 393 1.66 jmcneill tmpinfo.play.precision = 394 1.66 jmcneill tmpinfo.record.precision = 16; 395 1.66 jmcneill tmpinfo.play.encoding = 396 1.66 jmcneill tmpinfo.record.encoding = AUDIO_ENCODING_AC3; 397 1.66 jmcneill break; 398 1.1 mycroft default: 399 1.80 nia /* 400 1.80 nia * OSSv4 specifies that if an invalid format is chosen 401 1.80 nia * by an application then a sensible format supported 402 1.80 nia * by the hardware is returned. 403 1.80 nia * 404 1.80 nia * In this case, we pick S16LE since it's reasonably 405 1.80 nia * assumed to be supported by applications. 406 1.80 nia */ 407 1.80 nia tmpinfo.play.precision = 408 1.80 nia tmpinfo.record.precision = 16; 409 1.80 nia tmpinfo.play.encoding = 410 1.80 nia tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR_LE; 411 1.80 nia break; 412 1.1 mycroft } 413 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SETFMT > 0x%x\n", 414 1.65 christos __func__, idat)); 415 1.65 christos error = ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 416 1.65 christos if (error) { 417 1.65 christos DPRINTF(("%s: AUDIO_SETINFO %d\n", 418 1.65 christos __func__, error)); 419 1.65 christos goto out; 420 1.65 christos } 421 1.74 mrg /* FALLTHROUGH */ 422 1.6 augustss case OSS_SOUND_PCM_READ_BITS: 423 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 424 1.65 christos if (error) { 425 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 426 1.65 christos __func__, error)); 427 1.28 thorpej goto out; 428 1.65 christos } 429 1.78 isaki encoding = GETPRINFO(&tmpinfo, encoding); 430 1.78 isaki precision = GETPRINFO(&tmpinfo, precision); 431 1.78 isaki switch (encoding) { 432 1.5 mycroft case AUDIO_ENCODING_ULAW: 433 1.6 augustss idat = OSS_AFMT_MU_LAW; 434 1.5 mycroft break; 435 1.5 mycroft case AUDIO_ENCODING_ALAW: 436 1.6 augustss idat = OSS_AFMT_A_LAW; 437 1.5 mycroft break; 438 1.12 augustss case AUDIO_ENCODING_SLINEAR_LE: 439 1.78 isaki if (precision == 16) 440 1.8 augustss idat = OSS_AFMT_S16_LE; 441 1.8 augustss else 442 1.8 augustss idat = OSS_AFMT_S8; 443 1.8 augustss break; 444 1.12 augustss case AUDIO_ENCODING_SLINEAR_BE: 445 1.78 isaki if (precision == 16) 446 1.8 augustss idat = OSS_AFMT_S16_BE; 447 1.8 augustss else 448 1.8 augustss idat = OSS_AFMT_S8; 449 1.8 augustss break; 450 1.8 augustss case AUDIO_ENCODING_ULINEAR_LE: 451 1.78 isaki if (precision == 16) 452 1.8 augustss idat = OSS_AFMT_U16_LE; 453 1.8 augustss else 454 1.8 augustss idat = OSS_AFMT_U8; 455 1.8 augustss break; 456 1.8 augustss case AUDIO_ENCODING_ULINEAR_BE: 457 1.78 isaki if (precision == 16) 458 1.8 augustss idat = OSS_AFMT_U16_BE; 459 1.8 augustss else 460 1.8 augustss idat = OSS_AFMT_U8; 461 1.5 mycroft break; 462 1.5 mycroft case AUDIO_ENCODING_ADPCM: 463 1.6 augustss idat = OSS_AFMT_IMA_ADPCM; 464 1.5 mycroft break; 465 1.66 jmcneill case AUDIO_ENCODING_AC3: 466 1.66 jmcneill idat = OSS_AFMT_AC3; 467 1.66 jmcneill break; 468 1.65 christos default: 469 1.65 christos DPRINTF(("%s: SOUND_PCM_READ_BITS bad encoding %d\n", 470 1.65 christos __func__, tmpinfo.play.encoding)); 471 1.65 christos error = EINVAL; 472 1.65 christos goto out; 473 1.5 mycroft } 474 1.65 christos DPRINTF(("%s: SOUND_PCM_READ_BITS < 0x%x\n", 475 1.65 christos __func__, idat)); 476 1.5 mycroft error = copyout(&idat, SCARG(uap, data), sizeof idat); 477 1.65 christos if (error) { 478 1.65 christos DPRINTF(("%s: SOUND_PCM_READ_BITS %d = %d\n", 479 1.65 christos __func__, idat, error)); 480 1.28 thorpej goto out; 481 1.65 christos } 482 1.1 mycroft break; 483 1.6 augustss case OSS_SNDCTL_DSP_CHANNELS: 484 1.50 xtraeme AUDIO_INITINFO(&tmpinfo); 485 1.6 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 486 1.65 christos if (error) { 487 1.65 christos DPRINTF(("%s: SNDCTL_DSP_CHANNELS %d\n", 488 1.65 christos __func__, error)); 489 1.28 thorpej goto out; 490 1.65 christos } 491 1.81 nia error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 492 1.65 christos if (error) { 493 1.81 nia DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 494 1.65 christos __func__, error)); 495 1.65 christos goto out; 496 1.65 christos } 497 1.81 nia setchannels(fp, tmpinfo.mode, idat); 498 1.74 mrg /* FALLTHROUGH */ 499 1.6 augustss case OSS_SOUND_PCM_READ_CHANNELS: 500 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 501 1.65 christos if (error) { 502 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 503 1.65 christos __func__, error)); 504 1.28 thorpej goto out; 505 1.65 christos } 506 1.78 isaki idat = GETPRINFO(&tmpinfo, channels); 507 1.65 christos DPRINTF(("%s: SOUND_PCM_READ_CHANNELS < %d\n", __func__, idat)); 508 1.6 augustss error = copyout(&idat, SCARG(uap, data), sizeof idat); 509 1.65 christos if (error) { 510 1.65 christos DPRINTF(("%s: SOUND_PCM_READ_CHANNELS %d = %d\n", 511 1.65 christos __func__, idat, error)); 512 1.28 thorpej goto out; 513 1.65 christos } 514 1.6 augustss break; 515 1.6 augustss case OSS_SOUND_PCM_WRITE_FILTER: 516 1.6 augustss case OSS_SOUND_PCM_READ_FILTER: 517 1.28 thorpej error = EINVAL; /* XXX unimplemented */ 518 1.65 christos DPRINTF(("%s: SOUND_PCM_{READ,WRITE}_FILTER filter\n", 519 1.65 christos __func__)); 520 1.28 thorpej goto out; 521 1.6 augustss case OSS_SNDCTL_DSP_SUBDIVIDE: 522 1.9 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 523 1.65 christos if (error) { 524 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SUBDIVIDE %d\n", 525 1.65 christos __func__, error)); 526 1.28 thorpej goto out; 527 1.65 christos } 528 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 529 1.65 christos if (error) { 530 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 531 1.65 christos __func__, error)); 532 1.65 christos goto out; 533 1.65 christos } 534 1.62 ad setblocksize(fp, &tmpinfo); 535 1.9 augustss if (idat == 0) 536 1.23 augustss idat = tmpinfo.play.buffer_size / tmpinfo.blocksize; 537 1.23 augustss idat = (tmpinfo.play.buffer_size / idat) & -4; 538 1.50 xtraeme AUDIO_INITINFO(&tmpinfo); 539 1.9 augustss tmpinfo.blocksize = idat; 540 1.62 ad error = ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 541 1.65 christos if (error) { 542 1.65 christos DPRINTF(("%s: AUDIO_SETINFO %d\n", 543 1.65 christos __func__, error)); 544 1.28 thorpej goto out; 545 1.65 christos } 546 1.23 augustss idat = tmpinfo.play.buffer_size / tmpinfo.blocksize; 547 1.9 augustss error = copyout(&idat, SCARG(uap, data), sizeof idat); 548 1.65 christos if (error) { 549 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SUBDIVIDE %d = %d\n", 550 1.65 christos __func__, idat, error)); 551 1.28 thorpej goto out; 552 1.65 christos } 553 1.9 augustss break; 554 1.6 augustss case OSS_SNDCTL_DSP_SETFRAGMENT: 555 1.50 xtraeme AUDIO_INITINFO(&tmpinfo); 556 1.1 mycroft error = copyin(SCARG(uap, data), &idat, sizeof idat); 557 1.65 christos if (error) { 558 1.73 isaki DPRINTF(("%s: SNDCTL_DSP_SETFRAGMENT %d\n", 559 1.65 christos __func__, error)); 560 1.28 thorpej goto out; 561 1.65 christos } 562 1.28 thorpej if ((idat & 0xffff) < 4 || (idat & 0xffff) > 17) { 563 1.73 isaki DPRINTF(("%s: SNDCTL_DSP_SETFRAGMENT bad ival%d\n", 564 1.65 christos __func__, idat)); 565 1.28 thorpej error = EINVAL; 566 1.28 thorpej goto out; 567 1.28 thorpej } 568 1.1 mycroft tmpinfo.blocksize = 1 << (idat & 0xffff); 569 1.24 mycroft tmpinfo.hiwat = (idat >> 16) & 0x7fff; 570 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SETFRAGMENT blksize=%d, " 571 1.65 christos "hiwat=%d\n", __func__, tmpinfo.blocksize, tmpinfo.hiwat)); 572 1.21 augustss if (tmpinfo.hiwat == 0) /* 0 means set to max */ 573 1.21 augustss tmpinfo.hiwat = 65536; 574 1.65 christos error = ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 575 1.65 christos if (error) { 576 1.65 christos DPRINTF(("%s: AUDIO_SETINFO %d\n", 577 1.65 christos __func__, error)); 578 1.65 christos goto out; 579 1.65 christos } 580 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 581 1.65 christos if (error) { 582 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 583 1.65 christos __func__, error)); 584 1.28 thorpej goto out; 585 1.65 christos } 586 1.21 augustss u = tmpinfo.blocksize; 587 1.25 augustss for(idat = 0; u > 1; idat++, u >>= 1) 588 1.21 augustss ; 589 1.24 mycroft idat |= (tmpinfo.hiwat & 0x7fff) << 16; 590 1.1 mycroft error = copyout(&idat, SCARG(uap, data), sizeof idat); 591 1.65 christos if (error) { 592 1.65 christos DPRINTF(("%s: SNDCTL_DSP_SETFRAGMENT %d = %d\n", 593 1.65 christos __func__, idat, error)); 594 1.28 thorpej goto out; 595 1.65 christos } 596 1.1 mycroft break; 597 1.6 augustss case OSS_SNDCTL_DSP_GETFMTS: 598 1.65 christos for (idat = 0, tmpenc.index = 0; 599 1.62 ad ioctlf(fp, AUDIO_GETENC, &tmpenc) == 0; 600 1.16 augustss tmpenc.index++) { 601 1.16 augustss switch(tmpenc.encoding) { 602 1.16 augustss case AUDIO_ENCODING_ULAW: 603 1.16 augustss idat |= OSS_AFMT_MU_LAW; 604 1.16 augustss break; 605 1.16 augustss case AUDIO_ENCODING_ALAW: 606 1.16 augustss idat |= OSS_AFMT_A_LAW; 607 1.16 augustss break; 608 1.16 augustss case AUDIO_ENCODING_SLINEAR: 609 1.16 augustss idat |= OSS_AFMT_S8; 610 1.16 augustss break; 611 1.16 augustss case AUDIO_ENCODING_SLINEAR_LE: 612 1.16 augustss if (tmpenc.precision == 16) 613 1.16 augustss idat |= OSS_AFMT_S16_LE; 614 1.16 augustss else 615 1.16 augustss idat |= OSS_AFMT_S8; 616 1.16 augustss break; 617 1.16 augustss case AUDIO_ENCODING_SLINEAR_BE: 618 1.16 augustss if (tmpenc.precision == 16) 619 1.16 augustss idat |= OSS_AFMT_S16_BE; 620 1.16 augustss else 621 1.16 augustss idat |= OSS_AFMT_S8; 622 1.16 augustss break; 623 1.16 augustss case AUDIO_ENCODING_ULINEAR: 624 1.16 augustss idat |= OSS_AFMT_U8; 625 1.16 augustss break; 626 1.16 augustss case AUDIO_ENCODING_ULINEAR_LE: 627 1.16 augustss if (tmpenc.precision == 16) 628 1.16 augustss idat |= OSS_AFMT_U16_LE; 629 1.16 augustss else 630 1.16 augustss idat |= OSS_AFMT_U8; 631 1.16 augustss break; 632 1.16 augustss case AUDIO_ENCODING_ULINEAR_BE: 633 1.16 augustss if (tmpenc.precision == 16) 634 1.16 augustss idat |= OSS_AFMT_U16_BE; 635 1.16 augustss else 636 1.16 augustss idat |= OSS_AFMT_U8; 637 1.16 augustss break; 638 1.16 augustss case AUDIO_ENCODING_ADPCM: 639 1.16 augustss idat |= OSS_AFMT_IMA_ADPCM; 640 1.16 augustss break; 641 1.66 jmcneill case AUDIO_ENCODING_AC3: 642 1.66 jmcneill idat |= OSS_AFMT_AC3; 643 1.66 jmcneill break; 644 1.16 augustss default: 645 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETFMTS unknown %d\n", 646 1.65 christos __func__, tmpenc.encoding)); 647 1.16 augustss break; 648 1.16 augustss } 649 1.16 augustss } 650 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETFMTS < 0x%x\n", 651 1.65 christos __func__, idat)); 652 1.6 augustss error = copyout(&idat, SCARG(uap, data), sizeof idat); 653 1.65 christos if (error) { 654 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETFMTS = %x = %d\n", 655 1.65 christos __func__, idat, error)); 656 1.28 thorpej goto out; 657 1.65 christos } 658 1.6 augustss break; 659 1.6 augustss case OSS_SNDCTL_DSP_GETOSPACE: 660 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 661 1.65 christos if (error) { 662 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 663 1.65 christos __func__, error)); 664 1.35 augustss goto out; 665 1.65 christos } 666 1.62 ad setblocksize(fp, &tmpinfo); 667 1.84 riastrad memset(&bufinfo, 0, sizeof(bufinfo)); 668 1.35 augustss bufinfo.fragsize = tmpinfo.blocksize; 669 1.71 isaki bufinfo.fragments = tmpinfo.hiwat - 670 1.71 isaki (tmpinfo.play.seek + tmpinfo.blocksize - 1) / 671 1.35 augustss tmpinfo.blocksize; 672 1.35 augustss bufinfo.fragstotal = tmpinfo.hiwat; 673 1.71 isaki bufinfo.bytes = 674 1.71 isaki tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.play.seek; 675 1.35 augustss error = copyout(&bufinfo, SCARG(uap, data), sizeof bufinfo); 676 1.65 christos if (error) { 677 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETOSPACE = %d\n", 678 1.65 christos __func__, error)); 679 1.35 augustss goto out; 680 1.65 christos } 681 1.35 augustss break; 682 1.14 augustss case OSS_SNDCTL_DSP_GETISPACE: 683 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 684 1.65 christos if (error) { 685 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 686 1.65 christos __func__, error)); 687 1.28 thorpej goto out; 688 1.65 christos } 689 1.62 ad setblocksize(fp, &tmpinfo); 690 1.84 riastrad memset(&bufinfo, 0, sizeof(bufinfo)); 691 1.13 augustss bufinfo.fragsize = tmpinfo.blocksize; 692 1.70 nat bufinfo.fragments = tmpinfo.record.seek / tmpinfo.blocksize; 693 1.72 isaki bufinfo.fragstotal = 694 1.72 isaki tmpinfo.record.buffer_size / tmpinfo.blocksize; 695 1.72 isaki bufinfo.bytes = tmpinfo.record.seek; 696 1.13 augustss error = copyout(&bufinfo, SCARG(uap, data), sizeof bufinfo); 697 1.65 christos if (error) { 698 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETISPACE %d %d %d %d = %d\n", 699 1.65 christos __func__, bufinfo.fragsize, bufinfo.fragments, 700 1.65 christos bufinfo.fragstotal, bufinfo.bytes, error)); 701 1.28 thorpej goto out; 702 1.65 christos } 703 1.13 augustss break; 704 1.6 augustss case OSS_SNDCTL_DSP_NONBLOCK: 705 1.18 augustss idat = 1; 706 1.62 ad error = ioctlf(fp, FIONBIO, &idat); 707 1.65 christos if (error) { 708 1.73 isaki DPRINTF(("%s: FIONBIO %d\n", 709 1.65 christos __func__, error)); 710 1.28 thorpej goto out; 711 1.65 christos } 712 1.18 augustss break; 713 1.6 augustss case OSS_SNDCTL_DSP_GETCAPS: 714 1.62 ad error = ioctlf(fp, AUDIO_GETPROPS, &idata); 715 1.65 christos if (error) { 716 1.65 christos DPRINTF(("%s: AUDIO_GETPROPS %d\n", 717 1.65 christos __func__, error)); 718 1.28 thorpej goto out; 719 1.65 christos } 720 1.82 nia idat = OSS_DSP_CAP_TRIGGER; 721 1.13 augustss if (idata & AUDIO_PROP_FULLDUPLEX) 722 1.13 augustss idat |= OSS_DSP_CAP_DUPLEX; 723 1.13 augustss if (idata & AUDIO_PROP_MMAP) 724 1.13 augustss idat |= OSS_DSP_CAP_MMAP; 725 1.65 christos DPRINTF(("%s: SNDCL_DSP_GETCAPS %s duplex, %smmap\n", 726 1.65 christos __func__, (idat & OSS_DSP_CAP_DUPLEX) ? "full" : "half", 727 1.65 christos (idat & OSS_DSP_CAP_MMAP) ? "" : "no ")); 728 1.13 augustss error = copyout(&idat, SCARG(uap, data), sizeof idat); 729 1.65 christos if (error) { 730 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETCAPS %x = %d\n", __func__, 731 1.65 christos idat, error)); 732 1.28 thorpej goto out; 733 1.65 christos } 734 1.13 augustss break; 735 1.82 nia case OSS_SNDCTL_DSP_SETTRIGGER: 736 1.82 nia error = copyin(SCARG(uap, data), &idat, sizeof idat); 737 1.65 christos if (error) { 738 1.82 nia DPRINTF(("%s: SNDCTL_DSP_SETTRIGGER: %d\n", 739 1.65 christos __func__, error)); 740 1.28 thorpej goto out; 741 1.65 christos } 742 1.82 nia error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 743 1.65 christos if (error) { 744 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 745 1.65 christos __func__, error)); 746 1.65 christos goto out; 747 1.65 christos } 748 1.82 nia AUDIO_INITINFO(&tmpinfo); 749 1.82 nia if (tmpinfo.mode & AUMODE_PLAY) 750 1.82 nia tmpinfo.play.pause = (idat & OSS_PCM_ENABLE_OUTPUT) == 0; 751 1.82 nia if (tmpinfo.mode & AUMODE_RECORD) 752 1.82 nia tmpinfo.record.pause = (idat & OSS_PCM_ENABLE_INPUT) == 0; 753 1.82 nia (void)ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 754 1.82 nia /* FALLTHRU */ 755 1.82 nia case OSS_SNDCTL_DSP_GETTRIGGER: 756 1.82 nia error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 757 1.65 christos if (error) { 758 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 759 1.65 christos __func__, error)); 760 1.28 thorpej goto out; 761 1.65 christos } 762 1.82 nia idat = 0; 763 1.82 nia if ((tmpinfo.mode & AUMODE_PLAY) && !tmpinfo.play.pause) 764 1.82 nia idat |= OSS_PCM_ENABLE_OUTPUT; 765 1.82 nia if ((tmpinfo.mode & AUMODE_RECORD) && !tmpinfo.record.pause) 766 1.82 nia idat |= OSS_PCM_ENABLE_INPUT; 767 1.1 mycroft error = copyout(&idat, SCARG(uap, data), sizeof idat); 768 1.65 christos if (error) { 769 1.82 nia DPRINTF(("%s: SNDCTL_DSP_GETTRIGGER = %x = %d\n", 770 1.65 christos __func__, idat, error)); 771 1.28 thorpej goto out; 772 1.65 christos } 773 1.1 mycroft break; 774 1.6 augustss case OSS_SNDCTL_DSP_GETIPTR: 775 1.62 ad error = ioctlf(fp, AUDIO_GETIOFFS, &tmpoffs); 776 1.65 christos if (error) { 777 1.65 christos DPRINTF(("%s: AUDIO_GETIOFFS %d\n", 778 1.65 christos __func__, error)); 779 1.28 thorpej goto out; 780 1.65 christos } 781 1.84 riastrad memset(&cntinfo, 0, sizeof(cntinfo)); 782 1.13 augustss cntinfo.bytes = tmpoffs.samples; 783 1.13 augustss cntinfo.blocks = tmpoffs.deltablks; 784 1.13 augustss cntinfo.ptr = tmpoffs.offset; 785 1.13 augustss error = copyout(&cntinfo, SCARG(uap, data), sizeof cntinfo); 786 1.65 christos if (error) { 787 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETIPTR %d\n", 788 1.65 christos __func__, error)); 789 1.28 thorpej goto out; 790 1.65 christos } 791 1.13 augustss break; 792 1.6 augustss case OSS_SNDCTL_DSP_GETOPTR: 793 1.62 ad error = ioctlf(fp, AUDIO_GETOOFFS, &tmpoffs); 794 1.65 christos if (error) { 795 1.65 christos DPRINTF(("%s: AUDIO_GETOOFFS %d\n", 796 1.65 christos __func__, error)); 797 1.28 thorpej goto out; 798 1.65 christos } 799 1.84 riastrad memset(&cntinfo, 0, sizeof(cntinfo)); 800 1.13 augustss cntinfo.bytes = tmpoffs.samples; 801 1.13 augustss cntinfo.blocks = tmpoffs.deltablks; 802 1.13 augustss cntinfo.ptr = tmpoffs.offset; 803 1.13 augustss error = copyout(&cntinfo, SCARG(uap, data), sizeof cntinfo); 804 1.65 christos if (error) { 805 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETOPTR %d\n", 806 1.65 christos __func__, error)); 807 1.28 thorpej goto out; 808 1.65 christos } 809 1.13 augustss break; 810 1.40 jdolecek case OSS_SNDCTL_DSP_SETDUPLEX: 811 1.40 jdolecek idat = 1; 812 1.62 ad error = ioctlf(fp, AUDIO_SETFD, &idat); 813 1.65 christos if (error) { 814 1.65 christos DPRINTF(("%s: AUDIO_SETFD %d = %d\n", 815 1.65 christos __func__, idat, error)); 816 1.65 christos goto out; 817 1.65 christos } 818 1.65 christos break; 819 1.65 christos case OSS_SNDCTL_DSP_MAPINBUF: 820 1.65 christos DPRINTF(("%s: Unimplemented SNDCTL_DSP_MAPINBUF\n", 821 1.65 christos __func__)); 822 1.65 christos error = EINVAL; 823 1.40 jdolecek goto out; 824 1.6 augustss case OSS_SNDCTL_DSP_MAPOUTBUF: 825 1.65 christos DPRINTF(("%s: Unimplemented SNDCTL_DSP_MAPOUTBUF\n", 826 1.65 christos __func__)); 827 1.65 christos error = EINVAL; 828 1.65 christos goto out; 829 1.6 augustss case OSS_SNDCTL_DSP_SETSYNCRO: 830 1.65 christos DPRINTF(("%s: Unimplemented SNDCTL_DSP_GETSYNCHRO\n", 831 1.65 christos __func__)); 832 1.28 thorpej error = EINVAL; 833 1.28 thorpej goto out; 834 1.57 mlelstv case OSS_SNDCTL_DSP_GETODELAY: 835 1.62 ad error = ioctlf(fp, AUDIO_GETBUFINFO, &tmpinfo); 836 1.65 christos if (error) { 837 1.65 christos DPRINTF(("%s: AUDIO_GETBUFINFO %d\n", 838 1.65 christos __func__, error)); 839 1.57 mlelstv goto out; 840 1.65 christos } 841 1.57 mlelstv idat = tmpinfo.play.seek + tmpinfo.blocksize / 2; 842 1.57 mlelstv error = copyout(&idat, SCARG(uap, data), sizeof idat); 843 1.65 christos if (error) { 844 1.65 christos DPRINTF(("%s: SNDCTL_DSP_GETODELAY %d\n", 845 1.65 christos __func__, error)); 846 1.57 mlelstv goto out; 847 1.65 christos } 848 1.57 mlelstv break; 849 1.57 mlelstv case OSS_SNDCTL_DSP_PROFILE: 850 1.57 mlelstv /* This gives just a hint to the driver, 851 1.57 mlelstv * implementing it as a NOP is ok 852 1.57 mlelstv */ 853 1.65 christos DPRINTF(("%s: SNDCTL_DSP_PROFILE\n", __func__)); 854 1.57 mlelstv break; 855 1.1 mycroft default: 856 1.65 christos DPRINTF(("%s: Unimplemented 0x%lx\n", __func__, com)); 857 1.28 thorpej error = EINVAL; 858 1.28 thorpej goto out; 859 1.1 mycroft } 860 1.1 mycroft 861 1.28 thorpej out: 862 1.62 ad fd_putfile(SCARG(uap, fd)); 863 1.28 thorpej return error; 864 1.3 mycroft } 865 1.3 mycroft 866 1.6 augustss /* If the NetBSD mixer device should have more than 32 devices 867 1.6 augustss * some will not be available to Linux */ 868 1.20 augustss #define NETBSD_MAXDEVS 64 869 1.6 augustss struct audiodevinfo { 870 1.6 augustss int done; 871 1.6 augustss dev_t dev; 872 1.47 perry int16_t devmap[OSS_SOUND_MIXER_NRDEVICES], 873 1.7 augustss rdevmap[NETBSD_MAXDEVS]; 874 1.31 augustss char names[NETBSD_MAXDEVS][MAX_AUDIO_DEV_LEN]; 875 1.31 augustss int enum2opaque[NETBSD_MAXDEVS]; 876 1.6 augustss u_long devmask, recmask, stereomask; 877 1.6 augustss u_long caps, source; 878 1.6 augustss }; 879 1.6 augustss 880 1.31 augustss static int 881 1.31 augustss opaque_to_enum(struct audiodevinfo *di, audio_mixer_name_t *label, int opq) 882 1.31 augustss { 883 1.31 augustss int i, o; 884 1.31 augustss 885 1.31 augustss for (i = 0; i < NETBSD_MAXDEVS; i++) { 886 1.31 augustss o = di->enum2opaque[i]; 887 1.31 augustss if (o == opq) 888 1.31 augustss break; 889 1.31 augustss if (o == -1 && label != NULL && 890 1.31 augustss !strncmp(di->names[i], label->name, sizeof di->names[i])) { 891 1.31 augustss di->enum2opaque[i] = opq; 892 1.31 augustss break; 893 1.31 augustss } 894 1.31 augustss } 895 1.31 augustss if (i >= NETBSD_MAXDEVS) 896 1.31 augustss i = -1; 897 1.31 augustss /*printf("opq_to_enum %s %d -> %d\n", label->name, opq, i);*/ 898 1.31 augustss return (i); 899 1.31 augustss } 900 1.31 augustss 901 1.31 augustss static int 902 1.31 augustss enum_to_ord(struct audiodevinfo *di, int enm) 903 1.31 augustss { 904 1.31 augustss if (enm >= NETBSD_MAXDEVS) 905 1.31 augustss return (-1); 906 1.31 augustss 907 1.31 augustss /*printf("enum_to_ord %d -> %d\n", enm, di->enum2opaque[enm]);*/ 908 1.31 augustss return (di->enum2opaque[enm]); 909 1.31 augustss } 910 1.31 augustss 911 1.31 augustss static int 912 1.31 augustss enum_to_mask(struct audiodevinfo *di, int enm) 913 1.31 augustss { 914 1.31 augustss int m; 915 1.31 augustss if (enm >= NETBSD_MAXDEVS) 916 1.31 augustss return (0); 917 1.31 augustss 918 1.31 augustss m = di->enum2opaque[enm]; 919 1.31 augustss if (m == -1) 920 1.31 augustss m = 0; 921 1.31 augustss /*printf("enum_to_mask %d -> %d\n", enm, di->enum2opaque[enm]);*/ 922 1.31 augustss return (m); 923 1.31 augustss } 924 1.31 augustss 925 1.47 perry /* 926 1.6 augustss * Collect the audio device information to allow faster 927 1.6 augustss * emulation of the Linux mixer ioctls. Cache the information 928 1.6 augustss * to eliminate the overhead of repeating all the ioctls needed 929 1.6 augustss * to collect the information. 930 1.6 augustss */ 931 1.6 augustss static struct audiodevinfo * 932 1.62 ad getdevinfo(file_t *fp) 933 1.6 augustss { 934 1.6 augustss mixer_devinfo_t mi; 935 1.31 augustss int i, j, e; 936 1.33 jdolecek static const struct { 937 1.33 jdolecek const char *name; 938 1.6 augustss int code; 939 1.6 augustss } *dp, devs[] = { 940 1.6 augustss { AudioNmicrophone, OSS_SOUND_MIXER_MIC }, 941 1.6 augustss { AudioNline, OSS_SOUND_MIXER_LINE }, 942 1.6 augustss { AudioNcd, OSS_SOUND_MIXER_CD }, 943 1.6 augustss { AudioNdac, OSS_SOUND_MIXER_PCM }, 944 1.37 kim { AudioNaux, OSS_SOUND_MIXER_LINE1 }, 945 1.6 augustss { AudioNrecord, OSS_SOUND_MIXER_IMIX }, 946 1.15 augustss { AudioNmaster, OSS_SOUND_MIXER_VOLUME }, 947 1.6 augustss { AudioNtreble, OSS_SOUND_MIXER_TREBLE }, 948 1.6 augustss { AudioNbass, OSS_SOUND_MIXER_BASS }, 949 1.6 augustss { AudioNspeaker, OSS_SOUND_MIXER_SPEAKER }, 950 1.6 augustss /* { AudioNheadphone, ?? },*/ 951 1.6 augustss { AudioNoutput, OSS_SOUND_MIXER_OGAIN }, 952 1.6 augustss { AudioNinput, OSS_SOUND_MIXER_IGAIN }, 953 1.15 augustss /* { AudioNmaster, OSS_SOUND_MIXER_SPEAKER },*/ 954 1.6 augustss /* { AudioNstereo, ?? },*/ 955 1.6 augustss /* { AudioNmono, ?? },*/ 956 1.6 augustss { AudioNfmsynth, OSS_SOUND_MIXER_SYNTH }, 957 1.6 augustss /* { AudioNwave, OSS_SOUND_MIXER_PCM },*/ 958 1.10 augustss { AudioNmidi, OSS_SOUND_MIXER_SYNTH }, 959 1.6 augustss /* { AudioNmixerout, ?? },*/ 960 1.6 augustss { 0, -1 } 961 1.6 augustss }; 962 1.62 ad int (*ioctlf)(file_t *, u_long, void *) = fp->f_ops->fo_ioctl; 963 1.6 augustss struct vnode *vp; 964 1.6 augustss struct vattr va; 965 1.53 christos static struct audiodevinfo devcache; 966 1.6 augustss struct audiodevinfo *di = &devcache; 967 1.67 hannken int error, mlen, dlen; 968 1.6 augustss 969 1.47 perry /* 970 1.31 augustss * Figure out what device it is so we can check if the 971 1.6 augustss * cached data is valid. 972 1.6 augustss */ 973 1.69 matt vp = fp->f_vnode; 974 1.6 augustss if (vp->v_type != VCHR) 975 1.6 augustss return 0; 976 1.67 hannken vn_lock(vp, LK_SHARED | LK_RETRY); 977 1.67 hannken error = VOP_GETATTR(vp, &va, kauth_cred_get()); 978 1.67 hannken VOP_UNLOCK(vp); 979 1.67 hannken if (error) 980 1.6 augustss return 0; 981 1.6 augustss if (di->done && di->dev == va.va_rdev) 982 1.6 augustss return di; 983 1.6 augustss 984 1.6 augustss di->done = 1; 985 1.6 augustss di->dev = va.va_rdev; 986 1.6 augustss di->devmask = 0; 987 1.6 augustss di->recmask = 0; 988 1.6 augustss di->stereomask = 0; 989 1.31 augustss di->source = ~0; 990 1.6 augustss di->caps = 0; 991 1.6 augustss for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++) 992 1.6 augustss di->devmap[i] = -1; 993 1.31 augustss for(i = 0; i < NETBSD_MAXDEVS; i++) { 994 1.6 augustss di->rdevmap[i] = -1; 995 1.31 augustss di->names[i][0] = '\0'; 996 1.31 augustss di->enum2opaque[i] = -1; 997 1.31 augustss } 998 1.6 augustss for(i = 0; i < NETBSD_MAXDEVS; i++) { 999 1.6 augustss mi.index = i; 1000 1.75 maxv if (ioctlf(fp, AUDIO_MIXER_DEVINFO, &mi) != 0) 1001 1.6 augustss break; 1002 1.6 augustss switch(mi.type) { 1003 1.6 augustss case AUDIO_MIXER_VALUE: 1004 1.46 kent for(dp = devs; dp->name; dp++) { 1005 1.46 kent if (strcmp(dp->name, mi.label.name) == 0) 1006 1.6 augustss break; 1007 1.46 kent dlen = strlen(dp->name); 1008 1.46 kent mlen = strlen(mi.label.name); 1009 1.46 kent if (dlen < mlen 1010 1.46 kent && mi.label.name[mlen-dlen-1] == '.' 1011 1.46 kent && strcmp(dp->name, mi.label.name + mlen - dlen) == 0) 1012 1.46 kent break; 1013 1.46 kent } 1014 1.6 augustss if (dp->code >= 0) { 1015 1.6 augustss di->devmap[dp->code] = i; 1016 1.6 augustss di->rdevmap[i] = dp->code; 1017 1.6 augustss di->devmask |= 1 << dp->code; 1018 1.6 augustss if (mi.un.v.num_channels == 2) 1019 1.6 augustss di->stereomask |= 1 << dp->code; 1020 1.47 perry strncpy(di->names[i], mi.label.name, 1021 1.31 augustss sizeof di->names[i]); 1022 1.6 augustss } 1023 1.6 augustss break; 1024 1.31 augustss } 1025 1.31 augustss } 1026 1.31 augustss for(i = 0; i < NETBSD_MAXDEVS; i++) { 1027 1.31 augustss mi.index = i; 1028 1.75 maxv if (ioctlf(fp, AUDIO_MIXER_DEVINFO, &mi) != 0) 1029 1.31 augustss break; 1030 1.31 augustss if (strcmp(mi.label.name, AudioNsource) != 0) 1031 1.31 augustss continue; 1032 1.31 augustss di->source = i; 1033 1.31 augustss switch(mi.type) { 1034 1.6 augustss case AUDIO_MIXER_ENUM: 1035 1.31 augustss for(j = 0; j < mi.un.e.num_mem; j++) { 1036 1.31 augustss e = opaque_to_enum(di, 1037 1.31 augustss &mi.un.e.member[j].label, 1038 1.31 augustss mi.un.e.member[j].ord); 1039 1.31 augustss if (e >= 0) 1040 1.31 augustss di->recmask |= 1 << di->rdevmap[e]; 1041 1.6 augustss } 1042 1.31 augustss di->caps = OSS_SOUND_CAP_EXCL_INPUT; 1043 1.6 augustss break; 1044 1.6 augustss case AUDIO_MIXER_SET: 1045 1.31 augustss for(j = 0; j < mi.un.s.num_mem; j++) { 1046 1.31 augustss e = opaque_to_enum(di, 1047 1.31 augustss &mi.un.s.member[j].label, 1048 1.31 augustss mi.un.s.member[j].mask); 1049 1.31 augustss if (e >= 0) 1050 1.31 augustss di->recmask |= 1 << di->rdevmap[e]; 1051 1.6 augustss } 1052 1.6 augustss break; 1053 1.6 augustss } 1054 1.6 augustss } 1055 1.6 augustss return di; 1056 1.6 augustss } 1057 1.6 augustss 1058 1.6 augustss int 1059 1.61 dsl oss_ioctl_mixer(struct lwp *lwp, const struct oss_sys_ioctl_args *uap, register_t *retval) 1060 1.61 dsl { 1061 1.61 dsl /* { 1062 1.6 augustss syscallarg(int) fd; 1063 1.6 augustss syscallarg(u_long) com; 1064 1.55 christos syscallarg(void *) data; 1065 1.61 dsl } */ 1066 1.62 ad file_t *fp; 1067 1.6 augustss u_long com; 1068 1.6 augustss struct audiodevinfo *di; 1069 1.6 augustss mixer_ctrl_t mc; 1070 1.30 augustss struct oss_mixer_info omi; 1071 1.30 augustss struct audio_device adev; 1072 1.85 riastrad int idat = 0; 1073 1.6 augustss int i; 1074 1.6 augustss int error; 1075 1.31 augustss int l, r, n, e; 1076 1.62 ad int (*ioctlf)(file_t *, u_long, void *); 1077 1.6 augustss 1078 1.69 matt if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0) 1079 1.69 matt return error; 1080 1.6 augustss 1081 1.28 thorpej if ((fp->f_flag & (FREAD | FWRITE)) == 0) { 1082 1.28 thorpej error = EBADF; 1083 1.28 thorpej goto out; 1084 1.28 thorpej } 1085 1.6 augustss 1086 1.6 augustss com = SCARG(uap, com); 1087 1.65 christos DPRINTF(("%s: com=%s\n", __func__, compat_ossaudio_getcmd(com))); 1088 1.26 augustss 1089 1.6 augustss retval[0] = 0; 1090 1.6 augustss 1091 1.62 ad di = getdevinfo(fp); 1092 1.28 thorpej if (di == 0) { 1093 1.28 thorpej error = EINVAL; 1094 1.28 thorpej goto out; 1095 1.28 thorpej } 1096 1.6 augustss 1097 1.6 augustss ioctlf = fp->f_ops->fo_ioctl; 1098 1.6 augustss switch (com) { 1099 1.31 augustss case OSS_GET_VERSION: 1100 1.31 augustss idat = OSS_SOUND_VERSION; 1101 1.31 augustss break; 1102 1.30 augustss case OSS_SOUND_MIXER_INFO: 1103 1.30 augustss case OSS_SOUND_OLD_MIXER_INFO: 1104 1.62 ad error = ioctlf(fp, AUDIO_GETDEV, &adev); 1105 1.65 christos if (error) { 1106 1.65 christos DPRINTF(("%s: AUDIO_GETDEV %d\n", 1107 1.65 christos __func__, error)); 1108 1.43 augustss goto out; 1109 1.65 christos } 1110 1.83 nia memset(&omi, 0, sizeof omi); 1111 1.30 augustss omi.modify_counter = 1; 1112 1.30 augustss strncpy(omi.id, adev.name, sizeof omi.id); 1113 1.30 augustss strncpy(omi.name, adev.name, sizeof omi.name); 1114 1.43 augustss error = copyout(&omi, SCARG(uap, data), OSS_IOCTL_SIZE(com)); 1115 1.65 christos if (error) { 1116 1.65 christos DPRINTF(("%s: OSS_SOUND_MIXER_INFO %d\n", 1117 1.65 christos __func__, error)); 1118 1.65 christos goto out; 1119 1.65 christos } 1120 1.65 christos break; 1121 1.6 augustss case OSS_SOUND_MIXER_READ_RECSRC: 1122 1.76 christos if (di->source == (u_long)-1) { 1123 1.65 christos DPRINTF(("%s: OSS_SOUND_MIXER_READ_RECSRC bad source\n", 1124 1.65 christos __func__)); 1125 1.28 thorpej error = EINVAL; 1126 1.28 thorpej goto out; 1127 1.28 thorpej } 1128 1.6 augustss mc.dev = di->source; 1129 1.6 augustss if (di->caps & OSS_SOUND_CAP_EXCL_INPUT) { 1130 1.6 augustss mc.type = AUDIO_MIXER_ENUM; 1131 1.62 ad error = ioctlf(fp, AUDIO_MIXER_READ, &mc); 1132 1.65 christos if (error) { 1133 1.65 christos DPRINTF(("%s: AUDIO_MIXER_READ %d\n", 1134 1.65 christos __func__, error)); 1135 1.28 thorpej goto out; 1136 1.65 christos } 1137 1.31 augustss e = opaque_to_enum(di, NULL, mc.un.ord); 1138 1.31 augustss if (e >= 0) 1139 1.31 augustss idat = 1 << di->rdevmap[e]; 1140 1.6 augustss } else { 1141 1.6 augustss mc.type = AUDIO_MIXER_SET; 1142 1.62 ad error = ioctlf(fp, AUDIO_MIXER_READ, &mc); 1143 1.65 christos if (error) { 1144 1.65 christos DPRINTF(("%s: AUDIO_MIXER_READ %d\n", 1145 1.65 christos __func__, error)); 1146 1.28 thorpej goto out; 1147 1.65 christos } 1148 1.31 augustss e = opaque_to_enum(di, NULL, mc.un.mask); 1149 1.31 augustss if (e >= 0) 1150 1.31 augustss idat = 1 << di->rdevmap[e]; 1151 1.6 augustss } 1152 1.6 augustss break; 1153 1.6 augustss case OSS_SOUND_MIXER_READ_DEVMASK: 1154 1.6 augustss idat = di->devmask; 1155 1.6 augustss break; 1156 1.6 augustss case OSS_SOUND_MIXER_READ_RECMASK: 1157 1.6 augustss idat = di->recmask; 1158 1.6 augustss break; 1159 1.6 augustss case OSS_SOUND_MIXER_READ_STEREODEVS: 1160 1.6 augustss idat = di->stereomask; 1161 1.6 augustss break; 1162 1.6 augustss case OSS_SOUND_MIXER_READ_CAPS: 1163 1.6 augustss idat = di->caps; 1164 1.6 augustss break; 1165 1.6 augustss case OSS_SOUND_MIXER_WRITE_RECSRC: 1166 1.15 augustss case OSS_SOUND_MIXER_WRITE_R_RECSRC: 1167 1.76 christos if (di->source == (u_long)-1) { 1168 1.65 christos DPRINTF(("%s: OSS_SOUND_MIXER_WRITE_RECSRC bad " 1169 1.65 christos "source\n", __func__)); 1170 1.28 thorpej error = EINVAL; 1171 1.28 thorpej goto out; 1172 1.28 thorpej } 1173 1.6 augustss mc.dev = di->source; 1174 1.6 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1175 1.65 christos if (error) { 1176 1.65 christos DPRINTF(("%s: OSS_SOUND_MIXER_WRITE_RECSRC %d\n", 1177 1.65 christos __func__, error)); 1178 1.28 thorpej goto out; 1179 1.65 christos } 1180 1.7 augustss if (di->caps & OSS_SOUND_CAP_EXCL_INPUT) { 1181 1.7 augustss mc.type = AUDIO_MIXER_ENUM; 1182 1.7 augustss for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++) 1183 1.7 augustss if (idat & (1 << i)) 1184 1.7 augustss break; 1185 1.7 augustss if (i >= OSS_SOUND_MIXER_NRDEVICES || 1186 1.43 augustss di->devmap[i] == -1) { 1187 1.43 augustss error = EINVAL; 1188 1.65 christos DPRINTF(("%s: OSS_SOUND_MIXER_WRITE_RECSRC " 1189 1.65 christos "bad index %d\n", __func__, i)); 1190 1.43 augustss goto out; 1191 1.43 augustss } 1192 1.31 augustss mc.un.ord = enum_to_ord(di, di->devmap[i]); 1193 1.7 augustss } else { 1194 1.7 augustss mc.type = AUDIO_MIXER_SET; 1195 1.11 augustss mc.un.mask = 0; 1196 1.10 augustss for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++) { 1197 1.7 augustss if (idat & (1 << i)) { 1198 1.43 augustss if (di->devmap[i] == -1) { 1199 1.65 christos DPRINTF(("%s: OSS_SOUND_MIXER_" 1200 1.65 christos "WRITE_RECSRC bad devmap " 1201 1.65 christos "%d\n", __func__, i)); 1202 1.43 augustss error = EINVAL; 1203 1.43 augustss goto out; 1204 1.43 augustss } 1205 1.65 christos mc.un.mask |= enum_to_mask(di, 1206 1.65 christos di->devmap[i]); 1207 1.7 augustss } 1208 1.10 augustss } 1209 1.7 augustss } 1210 1.62 ad error = ioctlf(fp, AUDIO_MIXER_WRITE, &mc); 1211 1.65 christos if (error) { 1212 1.65 christos DPRINTF(("%s: AUDIO_MIXER_WRITE %d\n", 1213 1.65 christos __func__, error)); 1214 1.65 christos goto out; 1215 1.65 christos } 1216 1.28 thorpej goto out; 1217 1.6 augustss default: 1218 1.6 augustss if (OSS_MIXER_READ(OSS_SOUND_MIXER_FIRST) <= com && 1219 1.6 augustss com < OSS_MIXER_READ(OSS_SOUND_MIXER_NRDEVICES)) { 1220 1.6 augustss n = OSS_GET_DEV(com); 1221 1.28 thorpej if (di->devmap[n] == -1) { 1222 1.65 christos DPRINTF(("%s: 0x%lx bad devmap %d\n", 1223 1.65 christos __func__, com, n)); 1224 1.28 thorpej error = EINVAL; 1225 1.28 thorpej goto out; 1226 1.28 thorpej } 1227 1.17 augustss doread: 1228 1.6 augustss mc.dev = di->devmap[n]; 1229 1.6 augustss mc.type = AUDIO_MIXER_VALUE; 1230 1.65 christos mc.un.value.num_channels = di->stereomask & 1231 1.65 christos (1 << n) ? 2 : 1; 1232 1.62 ad error = ioctlf(fp, AUDIO_MIXER_READ, &mc); 1233 1.65 christos if (error) { 1234 1.65 christos DPRINTF(("%s: AUDIO_MIXER_READ %d\n", 1235 1.65 christos __func__, error)); 1236 1.28 thorpej goto out; 1237 1.65 christos } 1238 1.6 augustss if (mc.un.value.num_channels != 2) { 1239 1.65 christos l = r = 1240 1.65 christos mc.un.value.level[AUDIO_MIXER_LEVEL_MONO]; 1241 1.6 augustss } else { 1242 1.6 augustss l = mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT]; 1243 1.6 augustss r = mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT]; 1244 1.6 augustss } 1245 1.17 augustss idat = TO_OSSVOL(l) | (TO_OSSVOL(r) << 8); 1246 1.65 christos DPRINTF(("%s: n=%d (dev=%d) l=%d, r=%d, idat=%04x\n", 1247 1.65 christos __func__, n, di->devmap[n], l, r, idat)); 1248 1.6 augustss break; 1249 1.15 augustss } else if ((OSS_MIXER_WRITE_R(OSS_SOUND_MIXER_FIRST) <= com && 1250 1.65 christos com < OSS_MIXER_WRITE_R(OSS_SOUND_MIXER_NRDEVICES)) || 1251 1.65 christos (OSS_MIXER_WRITE(OSS_SOUND_MIXER_FIRST) <= com && 1252 1.65 christos com < OSS_MIXER_WRITE(OSS_SOUND_MIXER_NRDEVICES))) { 1253 1.6 augustss n = OSS_GET_DEV(com); 1254 1.28 thorpej if (di->devmap[n] == -1) { 1255 1.65 christos DPRINTF(("%s: 0x%lx bad devmap %d\n", 1256 1.65 christos __func__, com, n)); 1257 1.28 thorpej error = EINVAL; 1258 1.28 thorpej goto out; 1259 1.28 thorpej } 1260 1.6 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1261 1.65 christos if (error) { 1262 1.65 christos DPRINTF(("%s: 0x%lx error %d\n", 1263 1.65 christos __func__, com, error)); 1264 1.28 thorpej goto out; 1265 1.65 christos } 1266 1.17 augustss l = FROM_OSSVOL( idat & 0xff); 1267 1.17 augustss r = FROM_OSSVOL((idat >> 8) & 0xff); 1268 1.6 augustss mc.dev = di->devmap[n]; 1269 1.6 augustss mc.type = AUDIO_MIXER_VALUE; 1270 1.65 christos if (di->stereomask & (1 << n)) { 1271 1.6 augustss mc.un.value.num_channels = 2; 1272 1.6 augustss mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l; 1273 1.6 augustss mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r; 1274 1.6 augustss } else { 1275 1.6 augustss mc.un.value.num_channels = 1; 1276 1.65 christos mc.un.value.level[AUDIO_MIXER_LEVEL_MONO] = 1277 1.65 christos (l + r) / 2; 1278 1.6 augustss } 1279 1.65 christos DPRINTF(("%s: n=%d (dev=%d) l=%d, r=%d, idat=%04x\n", 1280 1.65 christos __func__, n, di->devmap[n], l, r, idat)); 1281 1.62 ad error = ioctlf(fp, AUDIO_MIXER_WRITE, &mc); 1282 1.65 christos if (error) { 1283 1.65 christos DPRINTF(("%s: AUDIO_MIXER_WRITE %d\n", 1284 1.65 christos __func__, error)); 1285 1.28 thorpej goto out; 1286 1.65 christos } 1287 1.15 augustss if (OSS_MIXER_WRITE(OSS_SOUND_MIXER_FIRST) <= com && 1288 1.28 thorpej com < OSS_MIXER_WRITE(OSS_SOUND_MIXER_NRDEVICES)) { 1289 1.28 thorpej error = 0; 1290 1.28 thorpej goto out; 1291 1.28 thorpej } 1292 1.6 augustss goto doread; 1293 1.15 augustss } else { 1294 1.65 christos DPRINTF(("%s: Unknown mixer ioctl 0x%lx\n", __func__, 1295 1.65 christos com)); 1296 1.28 thorpej error = EINVAL; 1297 1.28 thorpej goto out; 1298 1.15 augustss } 1299 1.6 augustss } 1300 1.28 thorpej error = copyout(&idat, SCARG(uap, data), sizeof idat); 1301 1.28 thorpej out: 1302 1.62 ad fd_putfile(SCARG(uap, fd)); 1303 1.28 thorpej return error; 1304 1.6 augustss } 1305 1.6 augustss 1306 1.26 augustss /* Sequencer emulation */ 1307 1.3 mycroft int 1308 1.61 dsl oss_ioctl_sequencer(struct lwp *l, const struct oss_sys_ioctl_args *uap, register_t *retval) 1309 1.61 dsl { 1310 1.61 dsl /* { 1311 1.3 mycroft syscallarg(int) fd; 1312 1.3 mycroft syscallarg(u_long) com; 1313 1.55 christos syscallarg(void *) data; 1314 1.61 dsl } */ 1315 1.62 ad file_t *fp; 1316 1.3 mycroft u_long com; 1317 1.26 augustss int idat, idat1; 1318 1.26 augustss struct synth_info si; 1319 1.26 augustss struct oss_synth_info osi; 1320 1.26 augustss struct oss_seq_event_rec oser; 1321 1.3 mycroft int error; 1322 1.62 ad int (*ioctlf)(file_t *, u_long, void *); 1323 1.3 mycroft 1324 1.62 ad if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) 1325 1.3 mycroft return (EBADF); 1326 1.3 mycroft 1327 1.28 thorpej if ((fp->f_flag & (FREAD | FWRITE)) == 0) { 1328 1.28 thorpej error = EBADF; 1329 1.28 thorpej goto out; 1330 1.28 thorpej } 1331 1.3 mycroft 1332 1.3 mycroft com = SCARG(uap, com); 1333 1.65 christos DPRINTF(("%s: com=%s\n", __func__, compat_ossaudio_getcmd(com))); 1334 1.26 augustss 1335 1.3 mycroft retval[0] = 0; 1336 1.3 mycroft 1337 1.26 augustss ioctlf = fp->f_ops->fo_ioctl; 1338 1.26 augustss switch (com) { 1339 1.26 augustss case OSS_SEQ_RESET: 1340 1.62 ad error = ioctlf(fp, SEQUENCER_RESET, &idat); 1341 1.28 thorpej goto out; 1342 1.26 augustss case OSS_SEQ_SYNC: 1343 1.62 ad error = ioctlf(fp, SEQUENCER_SYNC, &idat); 1344 1.28 thorpej goto out; 1345 1.26 augustss case OSS_SYNTH_INFO: 1346 1.26 augustss error = copyin(SCARG(uap, data), &osi, sizeof osi); 1347 1.26 augustss if (error) 1348 1.28 thorpej goto out; 1349 1.26 augustss si.device = osi.device; 1350 1.62 ad error = ioctlf(fp, SEQUENCER_INFO, &si); 1351 1.26 augustss if (error) 1352 1.28 thorpej goto out; 1353 1.26 augustss strncpy(osi.name, si.name, sizeof osi.name); 1354 1.26 augustss osi.device = si.device; 1355 1.26 augustss switch(si.synth_type) { 1356 1.47 perry case SYNTH_TYPE_FM: 1357 1.26 augustss osi.synth_type = OSS_SYNTH_TYPE_FM; break; 1358 1.47 perry case SYNTH_TYPE_SAMPLE: 1359 1.26 augustss osi.synth_type = OSS_SYNTH_TYPE_SAMPLE; break; 1360 1.47 perry case SYNTH_TYPE_MIDI: 1361 1.26 augustss osi.synth_type = OSS_SYNTH_TYPE_MIDI; break; 1362 1.26 augustss default: 1363 1.26 augustss osi.synth_type = 0; break; 1364 1.26 augustss } 1365 1.26 augustss switch(si.synth_subtype) { 1366 1.47 perry case SYNTH_SUB_FM_TYPE_ADLIB: 1367 1.26 augustss osi.synth_subtype = OSS_FM_TYPE_ADLIB; break; 1368 1.47 perry case SYNTH_SUB_FM_TYPE_OPL3: 1369 1.26 augustss osi.synth_subtype = OSS_FM_TYPE_OPL3; break; 1370 1.47 perry case SYNTH_SUB_MIDI_TYPE_MPU401: 1371 1.26 augustss osi.synth_subtype = OSS_MIDI_TYPE_MPU401; break; 1372 1.47 perry case SYNTH_SUB_SAMPLE_TYPE_BASIC: 1373 1.26 augustss osi.synth_subtype = OSS_SAMPLE_TYPE_BASIC; break; 1374 1.26 augustss default: 1375 1.26 augustss osi.synth_subtype = 0; break; 1376 1.26 augustss } 1377 1.26 augustss osi.perc_mode = 0; 1378 1.26 augustss osi.nr_voices = si.nr_voices; 1379 1.26 augustss osi.nr_drums = 0; 1380 1.26 augustss osi.instr_bank_size = si.instr_bank_size; 1381 1.26 augustss osi.capabilities = 0; 1382 1.47 perry if (si.capabilities & SYNTH_CAP_OPL3) 1383 1.26 augustss osi.capabilities |= OSS_SYNTH_CAP_OPL3; 1384 1.26 augustss if (si.capabilities & SYNTH_CAP_INPUT) 1385 1.26 augustss osi.capabilities |= OSS_SYNTH_CAP_INPUT; 1386 1.28 thorpej error = copyout(&osi, SCARG(uap, data), sizeof osi); 1387 1.28 thorpej goto out; 1388 1.26 augustss case OSS_SEQ_CTRLRATE: 1389 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1390 1.26 augustss if (error) 1391 1.28 thorpej goto out; 1392 1.62 ad error = ioctlf(fp, SEQUENCER_CTRLRATE, &idat); 1393 1.26 augustss if (error) 1394 1.28 thorpej goto out; 1395 1.26 augustss retval[0] = idat; 1396 1.26 augustss break; 1397 1.26 augustss case OSS_SEQ_GETOUTCOUNT: 1398 1.62 ad error = ioctlf(fp, SEQUENCER_GETOUTCOUNT, &idat); 1399 1.26 augustss if (error) 1400 1.28 thorpej goto out; 1401 1.26 augustss retval[0] = idat; 1402 1.26 augustss break; 1403 1.26 augustss case OSS_SEQ_GETINCOUNT: 1404 1.62 ad error = ioctlf(fp, SEQUENCER_GETINCOUNT, &idat); 1405 1.26 augustss if (error) 1406 1.28 thorpej goto out; 1407 1.26 augustss retval[0] = idat; 1408 1.26 augustss break; 1409 1.26 augustss case OSS_SEQ_NRSYNTHS: 1410 1.62 ad error = ioctlf(fp, SEQUENCER_NRSYNTHS, &idat); 1411 1.26 augustss if (error) 1412 1.28 thorpej goto out; 1413 1.26 augustss retval[0] = idat; 1414 1.26 augustss break; 1415 1.26 augustss case OSS_SEQ_NRMIDIS: 1416 1.62 ad error = ioctlf(fp, SEQUENCER_NRMIDIS, &idat); 1417 1.26 augustss if (error) 1418 1.28 thorpej goto out; 1419 1.26 augustss retval[0] = idat; 1420 1.26 augustss break; 1421 1.26 augustss case OSS_SEQ_THRESHOLD: 1422 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1423 1.26 augustss if (error) 1424 1.28 thorpej goto out; 1425 1.62 ad error = ioctlf(fp, SEQUENCER_THRESHOLD, &idat); 1426 1.28 thorpej goto out; 1427 1.26 augustss case OSS_MEMAVL: 1428 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1429 1.26 augustss if (error) 1430 1.28 thorpej goto out; 1431 1.62 ad error = ioctlf(fp, SEQUENCER_MEMAVL, &idat); 1432 1.26 augustss if (error) 1433 1.28 thorpej goto out; 1434 1.26 augustss retval[0] = idat; 1435 1.26 augustss break; 1436 1.26 augustss case OSS_SEQ_PANIC: 1437 1.62 ad error = ioctlf(fp, SEQUENCER_PANIC, &idat); 1438 1.28 thorpej goto out; 1439 1.26 augustss case OSS_SEQ_OUTOFBAND: 1440 1.26 augustss error = copyin(SCARG(uap, data), &oser, sizeof oser); 1441 1.26 augustss if (error) 1442 1.28 thorpej goto out; 1443 1.62 ad error = ioctlf(fp, SEQUENCER_OUTOFBAND, &oser); 1444 1.26 augustss if (error) 1445 1.28 thorpej goto out; 1446 1.26 augustss break; 1447 1.26 augustss case OSS_SEQ_GETTIME: 1448 1.62 ad error = ioctlf(fp, SEQUENCER_GETTIME, &idat); 1449 1.26 augustss if (error) 1450 1.28 thorpej goto out; 1451 1.26 augustss retval[0] = idat; 1452 1.26 augustss break; 1453 1.26 augustss case OSS_TMR_TIMEBASE: 1454 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1455 1.26 augustss if (error) 1456 1.28 thorpej goto out; 1457 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_TIMEBASE, &idat); 1458 1.26 augustss if (error) 1459 1.28 thorpej goto out; 1460 1.26 augustss retval[0] = idat; 1461 1.26 augustss break; 1462 1.26 augustss case OSS_TMR_START: 1463 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_START, &idat); 1464 1.28 thorpej goto out; 1465 1.26 augustss case OSS_TMR_STOP: 1466 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_STOP, &idat); 1467 1.28 thorpej goto out; 1468 1.26 augustss case OSS_TMR_CONTINUE: 1469 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_CONTINUE, &idat); 1470 1.28 thorpej goto out; 1471 1.26 augustss case OSS_TMR_TEMPO: 1472 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1473 1.26 augustss if (error) 1474 1.28 thorpej goto out; 1475 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_TEMPO, &idat); 1476 1.26 augustss if (error) 1477 1.28 thorpej goto out; 1478 1.26 augustss retval[0] = idat; 1479 1.26 augustss break; 1480 1.26 augustss case OSS_TMR_SOURCE: 1481 1.26 augustss error = copyin(SCARG(uap, data), &idat1, sizeof idat); 1482 1.26 augustss if (error) 1483 1.28 thorpej goto out; 1484 1.26 augustss idat = 0; 1485 1.26 augustss if (idat1 & OSS_TMR_INTERNAL) idat |= SEQUENCER_TMR_INTERNAL; 1486 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_SOURCE, &idat); 1487 1.26 augustss if (error) 1488 1.28 thorpej goto out; 1489 1.26 augustss idat1 = idat; 1490 1.26 augustss if (idat1 & SEQUENCER_TMR_INTERNAL) idat |= OSS_TMR_INTERNAL; 1491 1.26 augustss retval[0] = idat; 1492 1.26 augustss break; 1493 1.26 augustss case OSS_TMR_METRONOME: 1494 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1495 1.26 augustss if (error) 1496 1.28 thorpej goto out; 1497 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_METRONOME, &idat); 1498 1.28 thorpej goto out; 1499 1.26 augustss case OSS_TMR_SELECT: 1500 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat); 1501 1.26 augustss if (error) 1502 1.28 thorpej goto out; 1503 1.26 augustss retval[0] = idat; 1504 1.62 ad error = ioctlf(fp, SEQUENCER_TMR_SELECT, &idat); 1505 1.28 thorpej goto out; 1506 1.26 augustss default: 1507 1.65 christos DPRINTF(("%s: Unknown sequencer command 0x%lx\n", __func__, 1508 1.65 christos com)); 1509 1.28 thorpej error = EINVAL; 1510 1.28 thorpej goto out; 1511 1.26 augustss } 1512 1.26 augustss 1513 1.28 thorpej error = copyout(&idat, SCARG(uap, data), sizeof idat); 1514 1.28 thorpej out: 1515 1.62 ad fd_putfile(SCARG(uap, fd)); 1516 1.28 thorpej return error; 1517 1.14 augustss } 1518 1.14 augustss 1519 1.14 augustss /* 1520 1.81 nia * When AUDIO_SETINFO fails to set a channel count, the application's chosen 1521 1.81 nia * number is out of range of what the kernel allows. 1522 1.81 nia * 1523 1.81 nia * When this happens, we use the current hardware settings. This is just in 1524 1.81 nia * case an application is abusing SNDCTL_DSP_CHANNELS - OSSv4 always sets and 1525 1.81 nia * returns a reasonable value, even if it wasn't what the user requested. 1526 1.81 nia * 1527 1.81 nia * XXX: If a device is opened for both playback and recording, and supports 1528 1.81 nia * fewer channels for recording than playback, applications that do both will 1529 1.81 nia * behave very strangely. OSS doesn't allow for reporting separate channel 1530 1.81 nia * counts for recording and playback. This could be worked around by always 1531 1.81 nia * mixing recorded data up to the same number of channels as is being used 1532 1.81 nia * for playback. 1533 1.81 nia */ 1534 1.81 nia static void 1535 1.81 nia setchannels(file_t *fp, int mode, int nchannels) 1536 1.81 nia { 1537 1.81 nia struct audio_info tmpinfo, hwfmt; 1538 1.81 nia int (*ioctlf)(file_t *, u_long, void *); 1539 1.81 nia 1540 1.81 nia ioctlf = fp->f_ops->fo_ioctl; 1541 1.81 nia 1542 1.81 nia if (ioctlf(fp, AUDIO_GETFORMAT, &hwfmt) < 0) { 1543 1.81 nia hwfmt.record.channels = hwfmt.play.channels = 2; 1544 1.81 nia } 1545 1.81 nia 1546 1.81 nia if (mode & AUMODE_PLAY) { 1547 1.81 nia AUDIO_INITINFO(&tmpinfo); 1548 1.81 nia tmpinfo.play.channels = nchannels; 1549 1.81 nia if (ioctlf(fp, AUDIO_SETINFO, &tmpinfo) < 0) { 1550 1.81 nia AUDIO_INITINFO(&tmpinfo); 1551 1.81 nia tmpinfo.play.channels = hwfmt.play.channels; 1552 1.81 nia (void)ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 1553 1.81 nia } 1554 1.81 nia } 1555 1.81 nia 1556 1.81 nia if (mode & AUMODE_RECORD) { 1557 1.81 nia AUDIO_INITINFO(&tmpinfo); 1558 1.81 nia tmpinfo.record.channels = nchannels; 1559 1.81 nia if (ioctlf(fp, AUDIO_SETINFO, &tmpinfo) < 0) { 1560 1.81 nia AUDIO_INITINFO(&tmpinfo); 1561 1.81 nia tmpinfo.record.channels = hwfmt.record.channels; 1562 1.81 nia (void)ioctlf(fp, AUDIO_SETINFO, &tmpinfo); 1563 1.81 nia } 1564 1.81 nia } 1565 1.81 nia } 1566 1.81 nia 1567 1.81 nia /* 1568 1.14 augustss * Check that the blocksize is a power of 2 as OSS wants. 1569 1.14 augustss * If not, set it to be. 1570 1.14 augustss */ 1571 1.33 jdolecek static void 1572 1.62 ad setblocksize(file_t *fp, struct audio_info *info) 1573 1.14 augustss { 1574 1.14 augustss struct audio_info set; 1575 1.76 christos u_int s; 1576 1.14 augustss 1577 1.76 christos if (info->blocksize & (info->blocksize - 1)) { 1578 1.14 augustss for(s = 32; s < info->blocksize; s <<= 1) 1579 1.76 christos continue; 1580 1.50 xtraeme AUDIO_INITINFO(&set); 1581 1.14 augustss set.blocksize = s; 1582 1.62 ad fp->f_ops->fo_ioctl(fp, AUDIO_SETINFO, &set); 1583 1.62 ad fp->f_ops->fo_ioctl(fp, AUDIO_GETBUFINFO, info); 1584 1.14 augustss } 1585 1.1 mycroft } 1586