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