Home | History | Annotate | Line # | Download | only in ossaudio
ossaudio.c revision 1.52
      1  1.52        ad /*	$NetBSD: ossaudio.c,v 1.52 2006/07/23 22:06:09 ad Exp $	*/
      2  1.22  augustss 
      3  1.27  augustss /*-
      4  1.22  augustss  * Copyright (c) 1997 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  * 3. All advertising materials mentioning features or use of this software
     16  1.22  augustss  *    must display the following acknowledgement:
     17  1.22  augustss  *        This product includes software developed by the NetBSD
     18  1.22  augustss  *        Foundation, Inc. and its contributors.
     19  1.22  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  1.22  augustss  *    contributors may be used to endorse or promote products derived
     21  1.22  augustss  *    from this software without specific prior written permission.
     22  1.22  augustss  *
     23  1.22  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.22  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.22  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.22  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.22  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.22  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.22  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.22  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.22  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.22  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.22  augustss  * POSSIBILITY OF SUCH DAMAGE.
     34  1.22  augustss  */
     35  1.38     lukem 
     36  1.38     lukem #include <sys/cdefs.h>
     37  1.52        ad __KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.52 2006/07/23 22:06:09 ad Exp $");
     38  1.22  augustss 
     39   1.1   mycroft #include <sys/param.h>
     40   1.1   mycroft #include <sys/proc.h>
     41   1.1   mycroft #include <sys/systm.h>
     42   1.1   mycroft #include <sys/file.h>
     43   1.6  augustss #include <sys/vnode.h>
     44   1.1   mycroft #include <sys/filedesc.h>
     45   1.1   mycroft #include <sys/ioctl.h>
     46   1.1   mycroft #include <sys/mount.h>
     47  1.26  augustss #include <sys/kernel.h>
     48   1.1   mycroft #include <sys/audioio.h>
     49  1.26  augustss #include <sys/midiio.h>
     50   1.1   mycroft 
     51  1.41   thorpej #include <sys/sa.h>
     52   1.1   mycroft #include <sys/syscallargs.h>
     53   1.1   mycroft 
     54   1.6  augustss #include <compat/ossaudio/ossaudio.h>
     55   1.6  augustss #include <compat/ossaudio/ossaudiovar.h>
     56   1.6  augustss 
     57  1.16  augustss #ifdef AUDIO_DEBUG
     58  1.16  augustss #define DPRINTF(x) if (ossdebug) printf x
     59  1.16  augustss int ossdebug = 0;
     60  1.16  augustss #else
     61  1.16  augustss #define DPRINTF(x)
     62  1.16  augustss #endif
     63  1.16  augustss 
     64  1.32      tron #define TO_OSSVOL(x)	(((x) * 100 + 127) / 255)
     65  1.32      tron #define FROM_OSSVOL(x)	((((x) > 100 ? 100 : (x)) * 255 + 50) / 100)
     66  1.17  augustss 
     67  1.49  christos static struct audiodevinfo *getdevinfo __P((struct file *, struct lwp *));
     68  1.31  augustss static int opaque_to_enum(struct audiodevinfo *di, audio_mixer_name_t *label, int opq);
     69  1.31  augustss static int enum_to_ord(struct audiodevinfo *di, int enm);
     70  1.31  augustss static int enum_to_mask(struct audiodevinfo *di, int enm);
     71   1.1   mycroft 
     72  1.49  christos static void setblocksize __P((struct file *, struct audio_info *, struct lwp *));
     73  1.14  augustss 
     74  1.16  augustss 
     75   1.1   mycroft int
     76  1.49  christos oss_ioctl_audio(l, uap, retval)
     77  1.49  christos 	struct lwp *l;
     78  1.21  augustss 	struct oss_sys_ioctl_args /* {
     79   1.1   mycroft 		syscallarg(int) fd;
     80   1.1   mycroft 		syscallarg(u_long) com;
     81   1.1   mycroft 		syscallarg(caddr_t) data;
     82   1.1   mycroft 	} */ *uap;
     83   1.1   mycroft 	register_t *retval;
     84  1.47     perry {
     85  1.49  christos 	struct proc *p = l->l_proc;
     86  1.21  augustss 	struct file *fp;
     87  1.21  augustss 	struct filedesc *fdp;
     88   1.1   mycroft 	u_long com;
     89   1.1   mycroft 	struct audio_info tmpinfo;
     90  1.13  augustss 	struct audio_offset tmpoffs;
     91  1.13  augustss 	struct oss_audio_buf_info bufinfo;
     92  1.13  augustss 	struct oss_count_info cntinfo;
     93  1.16  augustss 	struct audio_encoding tmpenc;
     94  1.21  augustss 	u_int u;
     95  1.13  augustss 	int idat, idata;
     96  1.28   thorpej 	int error = 0;
     97  1.49  christos 	int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
     98   1.1   mycroft 
     99   1.1   mycroft 	fdp = p->p_fd;
    100  1.36   thorpej 	if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    101   1.1   mycroft 		return (EBADF);
    102   1.1   mycroft 
    103  1.28   thorpej 	FILE_USE(fp);
    104  1.28   thorpej 
    105  1.28   thorpej 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
    106  1.28   thorpej 		error = EBADF;
    107  1.28   thorpej 		goto out;
    108  1.28   thorpej 	}
    109   1.1   mycroft 
    110  1.26  augustss 	com = SCARG(uap, com);
    111  1.26  augustss 	DPRINTF(("oss_ioctl_audio: com=%08lx\n", com));
    112   1.6  augustss 
    113   1.1   mycroft 	retval[0] = 0;
    114   1.1   mycroft 
    115  1.26  augustss 	ioctlf = fp->f_ops->fo_ioctl;
    116   1.1   mycroft 	switch (com) {
    117   1.6  augustss 	case OSS_SNDCTL_DSP_RESET:
    118  1.49  christos 		error = ioctlf(fp, AUDIO_FLUSH, (caddr_t)0, l);
    119   1.1   mycroft 		if (error)
    120  1.28   thorpej 			goto out;
    121   1.1   mycroft 		break;
    122   1.6  augustss 	case OSS_SNDCTL_DSP_SYNC:
    123  1.49  christos 		error = ioctlf(fp, AUDIO_DRAIN, (caddr_t)0, l);
    124   1.1   mycroft 		if (error)
    125  1.28   thorpej 			goto out;
    126  1.39   mycroft 		break;
    127  1.39   mycroft 	case OSS_SNDCTL_DSP_POST:
    128  1.39   mycroft 		/* This call is merely advisory, and may be a nop. */
    129   1.1   mycroft 		break;
    130   1.6  augustss 	case OSS_SNDCTL_DSP_SPEED:
    131  1.50   xtraeme 		AUDIO_INITINFO(&tmpinfo);
    132   1.1   mycroft 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    133   1.1   mycroft 		if (error)
    134  1.28   thorpej 			goto out;
    135   1.1   mycroft 		tmpinfo.play.sample_rate =
    136   1.1   mycroft 		tmpinfo.record.sample_rate = idat;
    137  1.49  christos 		error = ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    138  1.16  augustss 		DPRINTF(("oss_sys_ioctl: SNDCTL_DSP_SPEED %d = %d\n",
    139  1.16  augustss 			 idat, error));
    140  1.16  augustss 		if (error)
    141  1.28   thorpej 			goto out;
    142   1.6  augustss 		/* fall into ... */
    143   1.6  augustss 	case OSS_SOUND_PCM_READ_RATE:
    144  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    145   1.1   mycroft 		if (error)
    146  1.28   thorpej 			goto out;
    147   1.1   mycroft 		idat = tmpinfo.play.sample_rate;
    148   1.1   mycroft 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    149   1.1   mycroft 		if (error)
    150  1.28   thorpej 			goto out;
    151   1.1   mycroft 		break;
    152   1.6  augustss 	case OSS_SNDCTL_DSP_STEREO:
    153  1.50   xtraeme 		AUDIO_INITINFO(&tmpinfo);
    154   1.1   mycroft 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    155   1.1   mycroft 		if (error)
    156  1.28   thorpej 			goto out;
    157   1.1   mycroft 		tmpinfo.play.channels =
    158   1.1   mycroft 		tmpinfo.record.channels = idat ? 2 : 1;
    159  1.49  christos 		(void) ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    160  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    161   1.1   mycroft 		if (error)
    162  1.28   thorpej 			goto out;
    163   1.1   mycroft 		idat = tmpinfo.play.channels - 1;
    164   1.1   mycroft 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    165   1.1   mycroft 		if (error)
    166  1.28   thorpej 			goto out;
    167   1.1   mycroft 		break;
    168   1.6  augustss 	case OSS_SNDCTL_DSP_GETBLKSIZE:
    169  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    170   1.1   mycroft 		if (error)
    171  1.28   thorpej 			goto out;
    172  1.49  christos 		setblocksize(fp, &tmpinfo, l);
    173   1.1   mycroft 		idat = tmpinfo.blocksize;
    174   1.1   mycroft 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    175   1.1   mycroft 		if (error)
    176  1.28   thorpej 			goto out;
    177   1.1   mycroft 		break;
    178   1.6  augustss 	case OSS_SNDCTL_DSP_SETFMT:
    179  1.50   xtraeme 		AUDIO_INITINFO(&tmpinfo);
    180   1.1   mycroft 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    181   1.1   mycroft 		if (error)
    182  1.28   thorpej 			goto out;
    183   1.1   mycroft 		switch (idat) {
    184   1.6  augustss 		case OSS_AFMT_MU_LAW:
    185   1.1   mycroft 			tmpinfo.play.precision =
    186   1.1   mycroft 			tmpinfo.record.precision = 8;
    187   1.1   mycroft 			tmpinfo.play.encoding =
    188   1.1   mycroft 			tmpinfo.record.encoding = AUDIO_ENCODING_ULAW;
    189   1.1   mycroft 			break;
    190   1.6  augustss 		case OSS_AFMT_A_LAW:
    191   1.1   mycroft 			tmpinfo.play.precision =
    192   1.1   mycroft 			tmpinfo.record.precision = 8;
    193   1.1   mycroft 			tmpinfo.play.encoding =
    194   1.1   mycroft 			tmpinfo.record.encoding = AUDIO_ENCODING_ALAW;
    195   1.1   mycroft 			break;
    196   1.6  augustss 		case OSS_AFMT_U8:
    197   1.1   mycroft 			tmpinfo.play.precision =
    198   1.1   mycroft 			tmpinfo.record.precision = 8;
    199   1.1   mycroft 			tmpinfo.play.encoding =
    200   1.8  augustss 			tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR;
    201   1.8  augustss 			break;
    202   1.8  augustss 		case OSS_AFMT_S8:
    203   1.8  augustss 			tmpinfo.play.precision =
    204   1.8  augustss 			tmpinfo.record.precision = 8;
    205   1.8  augustss 			tmpinfo.play.encoding =
    206  1.12  augustss 			tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR;
    207   1.1   mycroft 			break;
    208   1.6  augustss 		case OSS_AFMT_S16_LE:
    209   1.1   mycroft 			tmpinfo.play.precision =
    210   1.1   mycroft 			tmpinfo.record.precision = 16;
    211   1.1   mycroft 			tmpinfo.play.encoding =
    212  1.12  augustss 			tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR_LE;
    213   1.8  augustss 			break;
    214   1.8  augustss 		case OSS_AFMT_S16_BE:
    215   1.8  augustss 			tmpinfo.play.precision =
    216   1.8  augustss 			tmpinfo.record.precision = 16;
    217   1.8  augustss 			tmpinfo.play.encoding =
    218  1.12  augustss 			tmpinfo.record.encoding = AUDIO_ENCODING_SLINEAR_BE;
    219   1.8  augustss 			break;
    220   1.8  augustss 		case OSS_AFMT_U16_LE:
    221   1.8  augustss 			tmpinfo.play.precision =
    222   1.8  augustss 			tmpinfo.record.precision = 16;
    223   1.8  augustss 			tmpinfo.play.encoding =
    224   1.8  augustss 			tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR_LE;
    225   1.8  augustss 			break;
    226   1.8  augustss 		case OSS_AFMT_U16_BE:
    227   1.8  augustss 			tmpinfo.play.precision =
    228   1.8  augustss 			tmpinfo.record.precision = 16;
    229   1.8  augustss 			tmpinfo.play.encoding =
    230   1.8  augustss 			tmpinfo.record.encoding = AUDIO_ENCODING_ULINEAR_BE;
    231   1.1   mycroft 			break;
    232   1.1   mycroft 		default:
    233  1.28   thorpej 			error = EINVAL;
    234  1.28   thorpej 			goto out;
    235   1.1   mycroft 		}
    236  1.49  christos 		(void) ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    237   1.6  augustss 		/* fall into ... */
    238   1.6  augustss 	case OSS_SOUND_PCM_READ_BITS:
    239  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    240   1.1   mycroft 		if (error)
    241  1.28   thorpej 			goto out;
    242   1.5   mycroft 		switch (tmpinfo.play.encoding) {
    243   1.5   mycroft 		case AUDIO_ENCODING_ULAW:
    244   1.6  augustss 			idat = OSS_AFMT_MU_LAW;
    245   1.5   mycroft 			break;
    246   1.5   mycroft 		case AUDIO_ENCODING_ALAW:
    247   1.6  augustss 			idat = OSS_AFMT_A_LAW;
    248   1.5   mycroft 			break;
    249  1.12  augustss 		case AUDIO_ENCODING_SLINEAR_LE:
    250   1.8  augustss 			if (tmpinfo.play.precision == 16)
    251   1.8  augustss 				idat = OSS_AFMT_S16_LE;
    252   1.8  augustss 			else
    253   1.8  augustss 				idat = OSS_AFMT_S8;
    254   1.8  augustss 			break;
    255  1.12  augustss 		case AUDIO_ENCODING_SLINEAR_BE:
    256   1.8  augustss 			if (tmpinfo.play.precision == 16)
    257   1.8  augustss 				idat = OSS_AFMT_S16_BE;
    258   1.8  augustss 			else
    259   1.8  augustss 				idat = OSS_AFMT_S8;
    260   1.8  augustss 			break;
    261   1.8  augustss 		case AUDIO_ENCODING_ULINEAR_LE:
    262   1.8  augustss 			if (tmpinfo.play.precision == 16)
    263   1.8  augustss 				idat = OSS_AFMT_U16_LE;
    264   1.8  augustss 			else
    265   1.8  augustss 				idat = OSS_AFMT_U8;
    266   1.8  augustss 			break;
    267   1.8  augustss 		case AUDIO_ENCODING_ULINEAR_BE:
    268   1.8  augustss 			if (tmpinfo.play.precision == 16)
    269   1.8  augustss 				idat = OSS_AFMT_U16_BE;
    270   1.8  augustss 			else
    271   1.8  augustss 				idat = OSS_AFMT_U8;
    272   1.5   mycroft 			break;
    273   1.5   mycroft 		case AUDIO_ENCODING_ADPCM:
    274   1.6  augustss 			idat = OSS_AFMT_IMA_ADPCM;
    275   1.5   mycroft 			break;
    276   1.5   mycroft 		}
    277   1.5   mycroft 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    278   1.5   mycroft 		if (error)
    279  1.28   thorpej 			goto out;
    280   1.1   mycroft 		break;
    281   1.6  augustss 	case OSS_SNDCTL_DSP_CHANNELS:
    282  1.50   xtraeme 		AUDIO_INITINFO(&tmpinfo);
    283   1.6  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    284   1.6  augustss 		if (error)
    285  1.28   thorpej 			goto out;
    286   1.6  augustss 		tmpinfo.play.channels =
    287   1.6  augustss 		tmpinfo.record.channels = idat;
    288  1.49  christos 		(void) ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    289   1.6  augustss 		/* fall into ... */
    290   1.6  augustss 	case OSS_SOUND_PCM_READ_CHANNELS:
    291  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    292   1.6  augustss 		if (error)
    293  1.28   thorpej 			goto out;
    294   1.6  augustss 		idat = tmpinfo.play.channels;
    295   1.6  augustss 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    296   1.6  augustss 		if (error)
    297  1.28   thorpej 			goto out;
    298   1.6  augustss 		break;
    299   1.6  augustss 	case OSS_SOUND_PCM_WRITE_FILTER:
    300   1.6  augustss 	case OSS_SOUND_PCM_READ_FILTER:
    301  1.28   thorpej 		error = EINVAL; /* XXX unimplemented */
    302  1.28   thorpej 		goto out;
    303   1.6  augustss 	case OSS_SNDCTL_DSP_SUBDIVIDE:
    304   1.9  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    305   1.9  augustss 		if (error)
    306  1.28   thorpej 			goto out;
    307  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    308  1.49  christos 		setblocksize(fp, &tmpinfo, l);
    309   1.9  augustss 		if (error)
    310  1.28   thorpej 			goto out;
    311   1.9  augustss 		if (idat == 0)
    312  1.23  augustss 			idat = tmpinfo.play.buffer_size / tmpinfo.blocksize;
    313  1.23  augustss 		idat = (tmpinfo.play.buffer_size / idat) & -4;
    314  1.50   xtraeme 		AUDIO_INITINFO(&tmpinfo);
    315   1.9  augustss 		tmpinfo.blocksize = idat;
    316  1.49  christos 		error = ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    317   1.9  augustss 		if (error)
    318  1.28   thorpej 			goto out;
    319  1.23  augustss 		idat = tmpinfo.play.buffer_size / tmpinfo.blocksize;
    320   1.9  augustss 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    321   1.9  augustss 		if (error)
    322  1.28   thorpej 			goto out;
    323   1.9  augustss 		break;
    324   1.6  augustss 	case OSS_SNDCTL_DSP_SETFRAGMENT:
    325  1.50   xtraeme 		AUDIO_INITINFO(&tmpinfo);
    326   1.1   mycroft 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    327   1.1   mycroft 		if (error)
    328  1.28   thorpej 			goto out;
    329  1.28   thorpej 		if ((idat & 0xffff) < 4 || (idat & 0xffff) > 17) {
    330  1.28   thorpej 			error = EINVAL;
    331  1.28   thorpej 			goto out;
    332  1.28   thorpej 		}
    333   1.1   mycroft 		tmpinfo.blocksize = 1 << (idat & 0xffff);
    334  1.24   mycroft 		tmpinfo.hiwat = (idat >> 16) & 0x7fff;
    335  1.21  augustss 		DPRINTF(("oss_audio: SETFRAGMENT blksize=%d, hiwat=%d\n",
    336  1.21  augustss 			 tmpinfo.blocksize, tmpinfo.hiwat));
    337  1.21  augustss 		if (tmpinfo.hiwat == 0)	/* 0 means set to max */
    338  1.21  augustss 			tmpinfo.hiwat = 65536;
    339  1.49  christos 		(void) ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    340  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    341   1.1   mycroft 		if (error)
    342  1.28   thorpej 			goto out;
    343  1.21  augustss 		u = tmpinfo.blocksize;
    344  1.25  augustss 		for(idat = 0; u > 1; idat++, u >>= 1)
    345  1.21  augustss 			;
    346  1.24   mycroft 		idat |= (tmpinfo.hiwat & 0x7fff) << 16;
    347   1.1   mycroft 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    348   1.1   mycroft 		if (error)
    349  1.28   thorpej 			goto out;
    350   1.1   mycroft 		break;
    351   1.6  augustss 	case OSS_SNDCTL_DSP_GETFMTS:
    352  1.47     perry 		for(idat = 0, tmpenc.index = 0;
    353  1.49  christos 		    ioctlf(fp, AUDIO_GETENC, (caddr_t)&tmpenc, l) == 0;
    354  1.16  augustss 		    tmpenc.index++) {
    355  1.16  augustss 			switch(tmpenc.encoding) {
    356  1.16  augustss 			case AUDIO_ENCODING_ULAW:
    357  1.16  augustss 				idat |= OSS_AFMT_MU_LAW;
    358  1.16  augustss 				break;
    359  1.16  augustss 			case AUDIO_ENCODING_ALAW:
    360  1.16  augustss 				idat |= OSS_AFMT_A_LAW;
    361  1.16  augustss 				break;
    362  1.16  augustss 			case AUDIO_ENCODING_SLINEAR:
    363  1.16  augustss 				idat |= OSS_AFMT_S8;
    364  1.16  augustss 				break;
    365  1.16  augustss 			case AUDIO_ENCODING_SLINEAR_LE:
    366  1.16  augustss 				if (tmpenc.precision == 16)
    367  1.16  augustss 					idat |= OSS_AFMT_S16_LE;
    368  1.16  augustss 				else
    369  1.16  augustss 					idat |= OSS_AFMT_S8;
    370  1.16  augustss 				break;
    371  1.16  augustss 			case AUDIO_ENCODING_SLINEAR_BE:
    372  1.16  augustss 				if (tmpenc.precision == 16)
    373  1.16  augustss 					idat |= OSS_AFMT_S16_BE;
    374  1.16  augustss 				else
    375  1.16  augustss 					idat |= OSS_AFMT_S8;
    376  1.16  augustss 				break;
    377  1.16  augustss 			case AUDIO_ENCODING_ULINEAR:
    378  1.16  augustss 				idat |= OSS_AFMT_U8;
    379  1.16  augustss 				break;
    380  1.16  augustss 			case AUDIO_ENCODING_ULINEAR_LE:
    381  1.16  augustss 				if (tmpenc.precision == 16)
    382  1.16  augustss 					idat |= OSS_AFMT_U16_LE;
    383  1.16  augustss 				else
    384  1.16  augustss 					idat |= OSS_AFMT_U8;
    385  1.16  augustss 				break;
    386  1.16  augustss 			case AUDIO_ENCODING_ULINEAR_BE:
    387  1.16  augustss 				if (tmpenc.precision == 16)
    388  1.16  augustss 					idat |= OSS_AFMT_U16_BE;
    389  1.16  augustss 				else
    390  1.16  augustss 					idat |= OSS_AFMT_U8;
    391  1.16  augustss 				break;
    392  1.16  augustss 			case AUDIO_ENCODING_ADPCM:
    393  1.16  augustss 				idat |= OSS_AFMT_IMA_ADPCM;
    394  1.16  augustss 				break;
    395  1.16  augustss 			default:
    396  1.16  augustss 				break;
    397  1.16  augustss 			}
    398  1.16  augustss 		}
    399  1.16  augustss 		DPRINTF(("oss_sys_ioctl: SNDCTL_DSP_GETFMTS = %x\n", idat));
    400   1.6  augustss 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    401   1.6  augustss 		if (error)
    402  1.28   thorpej 			goto out;
    403   1.6  augustss 		break;
    404   1.6  augustss 	case OSS_SNDCTL_DSP_GETOSPACE:
    405  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    406  1.35  augustss 		if (error)
    407  1.35  augustss 			goto out;
    408  1.49  christos 		setblocksize(fp, &tmpinfo, l);
    409  1.35  augustss 		bufinfo.fragsize = tmpinfo.blocksize;
    410  1.35  augustss 		bufinfo.fragments = tmpinfo.hiwat -
    411  1.35  augustss 		    (tmpinfo.play.seek + tmpinfo.blocksize - 1) /
    412  1.35  augustss 		    tmpinfo.blocksize;
    413  1.35  augustss 		bufinfo.fragstotal = tmpinfo.hiwat;
    414  1.35  augustss 		bufinfo.bytes =
    415  1.35  augustss 		    tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.play.seek;
    416  1.35  augustss 		error = copyout(&bufinfo, SCARG(uap, data), sizeof bufinfo);
    417  1.35  augustss 		if (error)
    418  1.35  augustss 			goto out;
    419  1.35  augustss 		break;
    420  1.14  augustss 	case OSS_SNDCTL_DSP_GETISPACE:
    421  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    422  1.13  augustss 		if (error)
    423  1.28   thorpej 			goto out;
    424  1.49  christos 		setblocksize(fp, &tmpinfo, l);
    425  1.13  augustss 		bufinfo.fragsize = tmpinfo.blocksize;
    426  1.35  augustss 		bufinfo.fragments = tmpinfo.hiwat -
    427  1.35  augustss 		    (tmpinfo.record.seek + tmpinfo.blocksize - 1) /
    428  1.35  augustss 		    tmpinfo.blocksize;
    429  1.35  augustss                 bufinfo.fragstotal = tmpinfo.hiwat;
    430  1.35  augustss 		bufinfo.bytes =
    431  1.35  augustss 		    tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.record.seek;
    432  1.16  augustss 		DPRINTF(("oss_sys_ioctl: SNDCTL_DSP_GETxSPACE = %d %d %d %d\n",
    433  1.47     perry 			 bufinfo.fragsize, bufinfo.fragments,
    434  1.16  augustss 			 bufinfo.fragstotal, bufinfo.bytes));
    435  1.13  augustss 		error = copyout(&bufinfo, SCARG(uap, data), sizeof bufinfo);
    436  1.13  augustss 		if (error)
    437  1.28   thorpej 			goto out;
    438  1.13  augustss 		break;
    439   1.6  augustss 	case OSS_SNDCTL_DSP_NONBLOCK:
    440  1.18  augustss 		idat = 1;
    441  1.49  christos 		error = ioctlf(fp, FIONBIO, (caddr_t)&idat, l);
    442  1.19  augustss 		if (error)
    443  1.28   thorpej 			goto out;
    444  1.18  augustss 		break;
    445   1.6  augustss 	case OSS_SNDCTL_DSP_GETCAPS:
    446  1.49  christos 		error = ioctlf(fp, AUDIO_GETPROPS, (caddr_t)&idata, l);
    447  1.13  augustss 		if (error)
    448  1.28   thorpej 			goto out;
    449  1.13  augustss 		idat = OSS_DSP_CAP_TRIGGER; /* pretend we have trigger */
    450  1.13  augustss 		if (idata & AUDIO_PROP_FULLDUPLEX)
    451  1.13  augustss 			idat |= OSS_DSP_CAP_DUPLEX;
    452  1.13  augustss 		if (idata & AUDIO_PROP_MMAP)
    453  1.13  augustss 			idat |= OSS_DSP_CAP_MMAP;
    454  1.16  augustss 		DPRINTF(("oss_sys_ioctl: SNDCTL_DSP_GETCAPS = %x\n", idat));
    455  1.13  augustss 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    456  1.13  augustss 		if (error)
    457  1.28   thorpej 			goto out;
    458  1.13  augustss 		break;
    459  1.13  augustss #if 0
    460  1.13  augustss 	case OSS_SNDCTL_DSP_GETTRIGGER:
    461  1.49  christos 		error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, l);
    462  1.13  augustss 		if (error)
    463  1.28   thorpej 			goto out;
    464  1.13  augustss 		idat = (tmpinfo.play.pause ? 0 : OSS_PCM_ENABLE_OUTPUT) |
    465  1.13  augustss 		       (tmpinfo.record.pause ? 0 : OSS_PCM_ENABLE_INPUT);
    466  1.13  augustss 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    467  1.13  augustss 		if (error)
    468  1.28   thorpej 			goto out;
    469  1.13  augustss 		break;
    470  1.13  augustss 	case OSS_SNDCTL_DSP_SETTRIGGER:
    471  1.48      tron 		(void) ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p);
    472  1.13  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    473  1.13  augustss 		if (error)
    474  1.28   thorpej 			goto out;
    475  1.13  augustss 		tmpinfo.play.pause = (idat & OSS_PCM_ENABLE_OUTPUT) == 0;
    476  1.13  augustss 		tmpinfo.record.pause = (idat & OSS_PCM_ENABLE_INPUT) == 0;
    477  1.49  christos 		(void) ioctlf(fp, AUDIO_SETINFO, (caddr_t)&tmpinfo, l);
    478   1.1   mycroft 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    479   1.1   mycroft 		if (error)
    480  1.28   thorpej 			goto out;
    481   1.1   mycroft 		break;
    482  1.13  augustss #else
    483   1.6  augustss 	case OSS_SNDCTL_DSP_GETTRIGGER:
    484   1.6  augustss 	case OSS_SNDCTL_DSP_SETTRIGGER:
    485  1.13  augustss 		/* XXX Do nothing for now. */
    486  1.13  augustss 		idat = OSS_PCM_ENABLE_OUTPUT;
    487  1.28   thorpej 		error = copyout(&idat, SCARG(uap, data), sizeof idat);
    488  1.28   thorpej 		goto out;
    489  1.13  augustss #endif
    490   1.6  augustss 	case OSS_SNDCTL_DSP_GETIPTR:
    491  1.49  christos 		error = ioctlf(fp, AUDIO_GETIOFFS, (caddr_t)&tmpoffs, l);
    492  1.13  augustss 		if (error)
    493  1.28   thorpej 			goto out;
    494  1.13  augustss 		cntinfo.bytes = tmpoffs.samples;
    495  1.13  augustss 		cntinfo.blocks = tmpoffs.deltablks;
    496  1.13  augustss 		cntinfo.ptr = tmpoffs.offset;
    497  1.13  augustss 		error = copyout(&cntinfo, SCARG(uap, data), sizeof cntinfo);
    498  1.13  augustss 		if (error)
    499  1.28   thorpej 			goto out;
    500  1.13  augustss 		break;
    501   1.6  augustss 	case OSS_SNDCTL_DSP_GETOPTR:
    502  1.49  christos 		error = ioctlf(fp, AUDIO_GETOOFFS, (caddr_t)&tmpoffs, l);
    503  1.13  augustss 		if (error)
    504  1.28   thorpej 			goto out;
    505  1.13  augustss 		cntinfo.bytes = tmpoffs.samples;
    506  1.13  augustss 		cntinfo.blocks = tmpoffs.deltablks;
    507  1.13  augustss 		cntinfo.ptr = tmpoffs.offset;
    508  1.13  augustss 		error = copyout(&cntinfo, SCARG(uap, data), sizeof cntinfo);
    509  1.13  augustss 		if (error)
    510  1.28   thorpej 			goto out;
    511  1.13  augustss 		break;
    512  1.40  jdolecek 	case OSS_SNDCTL_DSP_SETDUPLEX:
    513  1.40  jdolecek 		idat = 1;
    514  1.49  christos 		error = ioctlf(fp, AUDIO_SETFD, (caddr_t)&idat, l);
    515  1.40  jdolecek 		goto out;
    516   1.6  augustss 	case OSS_SNDCTL_DSP_MAPINBUF:
    517   1.6  augustss 	case OSS_SNDCTL_DSP_MAPOUTBUF:
    518   1.6  augustss 	case OSS_SNDCTL_DSP_SETSYNCRO:
    519   1.6  augustss 	case OSS_SNDCTL_DSP_PROFILE:
    520  1.28   thorpej 		error = EINVAL;
    521  1.28   thorpej 		goto out;
    522   1.1   mycroft 	default:
    523  1.28   thorpej 		error = EINVAL;
    524  1.28   thorpej 		goto out;
    525   1.1   mycroft 	}
    526   1.1   mycroft 
    527  1.28   thorpej  out:
    528  1.49  christos 	FILE_UNUSE(fp, l);
    529  1.28   thorpej 	return error;
    530   1.3   mycroft }
    531   1.3   mycroft 
    532   1.6  augustss /* If the NetBSD mixer device should have more than 32 devices
    533   1.6  augustss  * some will not be available to Linux */
    534  1.20  augustss #define NETBSD_MAXDEVS 64
    535   1.6  augustss struct audiodevinfo {
    536   1.6  augustss 	int done;
    537   1.6  augustss 	dev_t dev;
    538  1.47     perry 	int16_t devmap[OSS_SOUND_MIXER_NRDEVICES],
    539   1.7  augustss 	        rdevmap[NETBSD_MAXDEVS];
    540  1.31  augustss 	char names[NETBSD_MAXDEVS][MAX_AUDIO_DEV_LEN];
    541  1.31  augustss 	int enum2opaque[NETBSD_MAXDEVS];
    542   1.6  augustss         u_long devmask, recmask, stereomask;
    543   1.6  augustss 	u_long caps, source;
    544   1.6  augustss };
    545   1.6  augustss 
    546  1.31  augustss static int
    547  1.31  augustss opaque_to_enum(struct audiodevinfo *di, audio_mixer_name_t *label, int opq)
    548  1.31  augustss {
    549  1.31  augustss 	int i, o;
    550  1.31  augustss 
    551  1.31  augustss 	for (i = 0; i < NETBSD_MAXDEVS; i++) {
    552  1.31  augustss 		o = di->enum2opaque[i];
    553  1.31  augustss 		if (o == opq)
    554  1.31  augustss 			break;
    555  1.31  augustss 		if (o == -1 && label != NULL &&
    556  1.31  augustss 		    !strncmp(di->names[i], label->name, sizeof di->names[i])) {
    557  1.31  augustss 			di->enum2opaque[i] = opq;
    558  1.31  augustss 			break;
    559  1.31  augustss 		}
    560  1.31  augustss 	}
    561  1.31  augustss 	if (i >= NETBSD_MAXDEVS)
    562  1.31  augustss 		i = -1;
    563  1.31  augustss 	/*printf("opq_to_enum %s %d -> %d\n", label->name, opq, i);*/
    564  1.31  augustss 	return (i);
    565  1.31  augustss }
    566  1.31  augustss 
    567  1.31  augustss static int
    568  1.31  augustss enum_to_ord(struct audiodevinfo *di, int enm)
    569  1.31  augustss {
    570  1.31  augustss 	if (enm >= NETBSD_MAXDEVS)
    571  1.31  augustss 		return (-1);
    572  1.31  augustss 
    573  1.31  augustss 	/*printf("enum_to_ord %d -> %d\n", enm, di->enum2opaque[enm]);*/
    574  1.31  augustss 	return (di->enum2opaque[enm]);
    575  1.31  augustss }
    576  1.31  augustss 
    577  1.31  augustss static int
    578  1.31  augustss enum_to_mask(struct audiodevinfo *di, int enm)
    579  1.31  augustss {
    580  1.31  augustss 	int m;
    581  1.31  augustss 	if (enm >= NETBSD_MAXDEVS)
    582  1.31  augustss 		return (0);
    583  1.31  augustss 
    584  1.31  augustss 	m = di->enum2opaque[enm];
    585  1.31  augustss 	if (m == -1)
    586  1.31  augustss 		m = 0;
    587  1.31  augustss 	/*printf("enum_to_mask %d -> %d\n", enm, di->enum2opaque[enm]);*/
    588  1.31  augustss 	return (m);
    589  1.31  augustss }
    590  1.31  augustss 
    591  1.47     perry /*
    592   1.6  augustss  * Collect the audio device information to allow faster
    593   1.6  augustss  * emulation of the Linux mixer ioctls.  Cache the information
    594   1.6  augustss  * to eliminate the overhead of repeating all the ioctls needed
    595   1.6  augustss  * to collect the information.
    596   1.6  augustss  */
    597   1.6  augustss static struct audiodevinfo *
    598  1.49  christos getdevinfo(fp, l)
    599   1.6  augustss 	struct file *fp;
    600  1.49  christos 	struct lwp *l;
    601   1.6  augustss {
    602   1.6  augustss 	mixer_devinfo_t mi;
    603  1.31  augustss 	int i, j, e;
    604  1.33  jdolecek 	static const struct {
    605  1.33  jdolecek 		const char *name;
    606   1.6  augustss 		int code;
    607   1.6  augustss 	} *dp, devs[] = {
    608   1.6  augustss 		{ AudioNmicrophone,	OSS_SOUND_MIXER_MIC },
    609   1.6  augustss 		{ AudioNline,		OSS_SOUND_MIXER_LINE },
    610   1.6  augustss 		{ AudioNcd,		OSS_SOUND_MIXER_CD },
    611   1.6  augustss 		{ AudioNdac,		OSS_SOUND_MIXER_PCM },
    612  1.37       kim 		{ AudioNaux,		OSS_SOUND_MIXER_LINE1 },
    613   1.6  augustss 		{ AudioNrecord,		OSS_SOUND_MIXER_IMIX },
    614  1.15  augustss 		{ AudioNmaster,		OSS_SOUND_MIXER_VOLUME },
    615   1.6  augustss 		{ AudioNtreble,		OSS_SOUND_MIXER_TREBLE },
    616   1.6  augustss 		{ AudioNbass,		OSS_SOUND_MIXER_BASS },
    617   1.6  augustss 		{ AudioNspeaker,	OSS_SOUND_MIXER_SPEAKER },
    618   1.6  augustss /*		{ AudioNheadphone,	?? },*/
    619   1.6  augustss 		{ AudioNoutput,		OSS_SOUND_MIXER_OGAIN },
    620   1.6  augustss 		{ AudioNinput,		OSS_SOUND_MIXER_IGAIN },
    621  1.15  augustss /*		{ AudioNmaster,		OSS_SOUND_MIXER_SPEAKER },*/
    622   1.6  augustss /*		{ AudioNstereo,		?? },*/
    623   1.6  augustss /*		{ AudioNmono,		?? },*/
    624   1.6  augustss 		{ AudioNfmsynth,	OSS_SOUND_MIXER_SYNTH },
    625   1.6  augustss /*		{ AudioNwave,		OSS_SOUND_MIXER_PCM },*/
    626  1.10  augustss 		{ AudioNmidi,		OSS_SOUND_MIXER_SYNTH },
    627   1.6  augustss /*		{ AudioNmixerout,	?? },*/
    628   1.6  augustss 		{ 0, -1 }
    629   1.6  augustss 	};
    630  1.49  christos 	int (*ioctlf)(struct file *, u_long, void *, struct lwp *) =
    631   1.6  augustss 	    fp->f_ops->fo_ioctl;
    632   1.6  augustss 	struct vnode *vp;
    633   1.6  augustss 	struct vattr va;
    634   1.6  augustss 	static struct audiodevinfo devcache = { 0 };
    635   1.6  augustss 	struct audiodevinfo *di = &devcache;
    636  1.46      kent 	int mlen, dlen;
    637   1.6  augustss 
    638  1.47     perry 	/*
    639  1.31  augustss 	 * Figure out what device it is so we can check if the
    640   1.6  augustss 	 * cached data is valid.
    641   1.6  augustss 	 */
    642   1.6  augustss 	vp = (struct vnode *)fp->f_data;
    643   1.6  augustss 	if (vp->v_type != VCHR)
    644   1.6  augustss 		return 0;
    645  1.52        ad 	if (VOP_GETATTR(vp, &va, l->l_cred, l))
    646   1.6  augustss 		return 0;
    647   1.6  augustss 	if (di->done && di->dev == va.va_rdev)
    648   1.6  augustss 		return di;
    649   1.6  augustss 
    650   1.6  augustss 	di->done = 1;
    651   1.6  augustss 	di->dev = va.va_rdev;
    652   1.6  augustss 	di->devmask = 0;
    653   1.6  augustss 	di->recmask = 0;
    654   1.6  augustss 	di->stereomask = 0;
    655  1.31  augustss 	di->source = ~0;
    656   1.6  augustss 	di->caps = 0;
    657   1.6  augustss 	for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++)
    658   1.6  augustss 		di->devmap[i] = -1;
    659  1.31  augustss 	for(i = 0; i < NETBSD_MAXDEVS; i++) {
    660   1.6  augustss 		di->rdevmap[i] = -1;
    661  1.31  augustss 		di->names[i][0] = '\0';
    662  1.31  augustss 		di->enum2opaque[i] = -1;
    663  1.31  augustss 	}
    664   1.6  augustss 	for(i = 0; i < NETBSD_MAXDEVS; i++) {
    665   1.6  augustss 		mi.index = i;
    666  1.49  christos 		if (ioctlf(fp, AUDIO_MIXER_DEVINFO, (caddr_t)&mi, l) < 0)
    667   1.6  augustss 			break;
    668   1.6  augustss 		switch(mi.type) {
    669   1.6  augustss 		case AUDIO_MIXER_VALUE:
    670  1.46      kent 			for(dp = devs; dp->name; dp++) {
    671  1.46      kent 				if (strcmp(dp->name, mi.label.name) == 0)
    672   1.6  augustss 					break;
    673  1.46      kent 				dlen = strlen(dp->name);
    674  1.46      kent 				mlen = strlen(mi.label.name);
    675  1.46      kent 				if (dlen < mlen
    676  1.46      kent 				    && mi.label.name[mlen-dlen-1] == '.'
    677  1.46      kent 				    && strcmp(dp->name, mi.label.name + mlen - dlen) == 0)
    678  1.46      kent 					break;
    679  1.46      kent 			}
    680   1.6  augustss 			if (dp->code >= 0) {
    681   1.6  augustss 				di->devmap[dp->code] = i;
    682   1.6  augustss 				di->rdevmap[i] = dp->code;
    683   1.6  augustss 				di->devmask |= 1 << dp->code;
    684   1.6  augustss 				if (mi.un.v.num_channels == 2)
    685   1.6  augustss 					di->stereomask |= 1 << dp->code;
    686  1.47     perry 				strncpy(di->names[i], mi.label.name,
    687  1.31  augustss 					sizeof di->names[i]);
    688   1.6  augustss 			}
    689   1.6  augustss 			break;
    690  1.31  augustss 		}
    691  1.31  augustss 	}
    692  1.31  augustss 	for(i = 0; i < NETBSD_MAXDEVS; i++) {
    693  1.31  augustss 		mi.index = i;
    694  1.49  christos 		if (ioctlf(fp, AUDIO_MIXER_DEVINFO, (caddr_t)&mi, l) < 0)
    695  1.31  augustss 			break;
    696  1.31  augustss 		if (strcmp(mi.label.name, AudioNsource) != 0)
    697  1.31  augustss 			continue;
    698  1.31  augustss 		di->source = i;
    699  1.31  augustss 		switch(mi.type) {
    700   1.6  augustss 		case AUDIO_MIXER_ENUM:
    701  1.31  augustss 			for(j = 0; j < mi.un.e.num_mem; j++) {
    702  1.31  augustss 				e = opaque_to_enum(di,
    703  1.31  augustss 						   &mi.un.e.member[j].label,
    704  1.31  augustss 						   mi.un.e.member[j].ord);
    705  1.31  augustss 				if (e >= 0)
    706  1.31  augustss 					di->recmask |= 1 << di->rdevmap[e];
    707   1.6  augustss 			}
    708  1.31  augustss 			di->caps = OSS_SOUND_CAP_EXCL_INPUT;
    709   1.6  augustss 			break;
    710   1.6  augustss 		case AUDIO_MIXER_SET:
    711  1.31  augustss 			for(j = 0; j < mi.un.s.num_mem; j++) {
    712  1.31  augustss 				e = opaque_to_enum(di,
    713  1.31  augustss 						   &mi.un.s.member[j].label,
    714  1.31  augustss 						   mi.un.s.member[j].mask);
    715  1.31  augustss 				if (e >= 0)
    716  1.31  augustss 					di->recmask |= 1 << di->rdevmap[e];
    717   1.6  augustss 			}
    718   1.6  augustss 			break;
    719   1.6  augustss 		}
    720   1.6  augustss 	}
    721   1.6  augustss 	return di;
    722   1.6  augustss }
    723   1.6  augustss 
    724   1.6  augustss int
    725  1.49  christos oss_ioctl_mixer(lwp, uap, retval)
    726  1.49  christos 	struct lwp *lwp;
    727  1.21  augustss 	struct oss_sys_ioctl_args /* {
    728   1.6  augustss 		syscallarg(int) fd;
    729   1.6  augustss 		syscallarg(u_long) com;
    730   1.6  augustss 		syscallarg(caddr_t) data;
    731   1.6  augustss 	} */ *uap;
    732   1.6  augustss 	register_t *retval;
    733  1.47     perry {
    734  1.49  christos 	struct proc *p = lwp->l_proc;
    735   1.6  augustss 	struct file *fp;
    736   1.6  augustss 	struct filedesc *fdp;
    737   1.6  augustss 	u_long com;
    738   1.6  augustss 	struct audiodevinfo *di;
    739   1.6  augustss 	mixer_ctrl_t mc;
    740  1.30  augustss 	struct oss_mixer_info omi;
    741  1.30  augustss 	struct audio_device adev;
    742   1.6  augustss 	int idat;
    743   1.6  augustss 	int i;
    744   1.6  augustss 	int error;
    745  1.31  augustss 	int l, r, n, e;
    746  1.49  christos 	int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
    747   1.6  augustss 
    748   1.6  augustss 	fdp = p->p_fd;
    749  1.36   thorpej 	if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    750   1.6  augustss 		return (EBADF);
    751   1.6  augustss 
    752  1.28   thorpej 	FILE_USE(fp);
    753  1.28   thorpej 
    754  1.28   thorpej 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
    755  1.28   thorpej 		error = EBADF;
    756  1.28   thorpej 		goto out;
    757  1.28   thorpej 	}
    758   1.6  augustss 
    759   1.6  augustss 	com = SCARG(uap, com);
    760  1.26  augustss 	DPRINTF(("oss_ioctl_mixer: com=%08lx\n", com));
    761  1.26  augustss 
    762   1.6  augustss 	retval[0] = 0;
    763   1.6  augustss 
    764  1.49  christos 	di = getdevinfo(fp, lwp);
    765  1.28   thorpej 	if (di == 0) {
    766  1.28   thorpej 		error = EINVAL;
    767  1.28   thorpej 		goto out;
    768  1.28   thorpej 	}
    769   1.6  augustss 
    770   1.6  augustss 	ioctlf = fp->f_ops->fo_ioctl;
    771   1.6  augustss 	switch (com) {
    772  1.31  augustss 	case OSS_GET_VERSION:
    773  1.31  augustss 		idat = OSS_SOUND_VERSION;
    774  1.31  augustss 		break;
    775  1.30  augustss 	case OSS_SOUND_MIXER_INFO:
    776  1.30  augustss 	case OSS_SOUND_OLD_MIXER_INFO:
    777  1.49  christos 		error = ioctlf(fp, AUDIO_GETDEV, (caddr_t)&adev, lwp);
    778  1.30  augustss 		if (error)
    779  1.43  augustss 			goto out;
    780  1.30  augustss 		omi.modify_counter = 1;
    781  1.30  augustss 		strncpy(omi.id, adev.name, sizeof omi.id);
    782  1.30  augustss 		strncpy(omi.name, adev.name, sizeof omi.name);
    783  1.43  augustss 		error = copyout(&omi, SCARG(uap, data), OSS_IOCTL_SIZE(com));
    784  1.43  augustss 		goto out;
    785   1.6  augustss 	case OSS_SOUND_MIXER_READ_RECSRC:
    786  1.28   thorpej 		if (di->source == -1) {
    787  1.28   thorpej 			error = EINVAL;
    788  1.28   thorpej 			goto out;
    789  1.28   thorpej 		}
    790   1.6  augustss 		mc.dev = di->source;
    791   1.6  augustss 		if (di->caps & OSS_SOUND_CAP_EXCL_INPUT) {
    792   1.6  augustss 			mc.type = AUDIO_MIXER_ENUM;
    793  1.49  christos 			error = ioctlf(fp, AUDIO_MIXER_READ, (caddr_t)&mc, lwp);
    794   1.6  augustss 			if (error)
    795  1.28   thorpej 				goto out;
    796  1.31  augustss 			e = opaque_to_enum(di, NULL, mc.un.ord);
    797  1.31  augustss 			if (e >= 0)
    798  1.31  augustss 				idat = 1 << di->rdevmap[e];
    799   1.6  augustss 		} else {
    800   1.6  augustss 			mc.type = AUDIO_MIXER_SET;
    801  1.49  christos 			error = ioctlf(fp, AUDIO_MIXER_READ, (caddr_t)&mc, lwp);
    802   1.6  augustss 			if (error)
    803  1.28   thorpej 				goto out;
    804  1.31  augustss 			e = opaque_to_enum(di, NULL, mc.un.mask);
    805  1.31  augustss 			if (e >= 0)
    806  1.31  augustss 				idat = 1 << di->rdevmap[e];
    807   1.6  augustss 		}
    808   1.6  augustss 		break;
    809   1.6  augustss 	case OSS_SOUND_MIXER_READ_DEVMASK:
    810   1.6  augustss 		idat = di->devmask;
    811   1.6  augustss 		break;
    812   1.6  augustss 	case OSS_SOUND_MIXER_READ_RECMASK:
    813   1.6  augustss 		idat = di->recmask;
    814   1.6  augustss 		break;
    815   1.6  augustss 	case OSS_SOUND_MIXER_READ_STEREODEVS:
    816   1.6  augustss 		idat = di->stereomask;
    817   1.6  augustss 		break;
    818   1.6  augustss 	case OSS_SOUND_MIXER_READ_CAPS:
    819   1.6  augustss 		idat = di->caps;
    820   1.6  augustss 		break;
    821   1.6  augustss 	case OSS_SOUND_MIXER_WRITE_RECSRC:
    822  1.15  augustss 	case OSS_SOUND_MIXER_WRITE_R_RECSRC:
    823  1.28   thorpej 		if (di->source == -1) {
    824  1.28   thorpej 			error = EINVAL;
    825  1.28   thorpej 			goto out;
    826  1.28   thorpej 		}
    827   1.6  augustss 		mc.dev = di->source;
    828   1.6  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
    829   1.6  augustss 		if (error)
    830  1.28   thorpej 			goto out;
    831   1.7  augustss 		if (di->caps & OSS_SOUND_CAP_EXCL_INPUT) {
    832   1.7  augustss 			mc.type = AUDIO_MIXER_ENUM;
    833   1.7  augustss 			for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++)
    834   1.7  augustss 				if (idat & (1 << i))
    835   1.7  augustss 					break;
    836   1.7  augustss 			if (i >= OSS_SOUND_MIXER_NRDEVICES ||
    837  1.43  augustss 			    di->devmap[i] == -1) {
    838  1.43  augustss 				error = EINVAL;
    839  1.43  augustss 				goto out;
    840  1.43  augustss 			}
    841  1.31  augustss 			mc.un.ord = enum_to_ord(di, di->devmap[i]);
    842   1.7  augustss 		} else {
    843   1.7  augustss 			mc.type = AUDIO_MIXER_SET;
    844  1.11  augustss 			mc.un.mask = 0;
    845  1.10  augustss 			for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++) {
    846   1.7  augustss 				if (idat & (1 << i)) {
    847  1.43  augustss 					if (di->devmap[i] == -1) {
    848  1.43  augustss 						error = EINVAL;
    849  1.43  augustss 						goto out;
    850  1.43  augustss 					}
    851  1.31  augustss 					mc.un.mask |= enum_to_mask(di, di->devmap[i]);
    852   1.7  augustss 				}
    853  1.10  augustss 			}
    854   1.7  augustss 		}
    855  1.49  christos 		error = ioctlf(fp, AUDIO_MIXER_WRITE, (caddr_t)&mc, lwp);
    856  1.28   thorpej 		goto out;
    857   1.6  augustss 	default:
    858   1.6  augustss 		if (OSS_MIXER_READ(OSS_SOUND_MIXER_FIRST) <= com &&
    859   1.6  augustss 		    com < OSS_MIXER_READ(OSS_SOUND_MIXER_NRDEVICES)) {
    860   1.6  augustss 			n = OSS_GET_DEV(com);
    861  1.28   thorpej 			if (di->devmap[n] == -1) {
    862  1.28   thorpej 				error = EINVAL;
    863  1.28   thorpej 				goto out;
    864  1.28   thorpej 			}
    865  1.17  augustss 		    doread:
    866   1.6  augustss 			mc.dev = di->devmap[n];
    867   1.6  augustss 			mc.type = AUDIO_MIXER_VALUE;
    868   1.6  augustss 			mc.un.value.num_channels = di->stereomask & (1<<n) ? 2 : 1;
    869  1.49  christos 			error = ioctlf(fp, AUDIO_MIXER_READ, (caddr_t)&mc, lwp);
    870   1.6  augustss 			if (error)
    871  1.28   thorpej 				goto out;
    872   1.6  augustss 			if (mc.un.value.num_channels != 2) {
    873   1.6  augustss 				l = r = mc.un.value.level[AUDIO_MIXER_LEVEL_MONO];
    874   1.6  augustss 			} else {
    875   1.6  augustss 				l = mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT];
    876   1.6  augustss 				r = mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
    877   1.6  augustss 			}
    878  1.17  augustss 			idat = TO_OSSVOL(l) | (TO_OSSVOL(r) << 8);
    879  1.47     perry 			DPRINTF(("OSS_MIXER_READ  n=%d (dev=%d) l=%d, r=%d, idat=%04x\n",
    880  1.17  augustss 				 n, di->devmap[n], l, r, idat));
    881   1.6  augustss 			break;
    882  1.15  augustss 		} else if ((OSS_MIXER_WRITE_R(OSS_SOUND_MIXER_FIRST) <= com &&
    883  1.15  augustss 			   com < OSS_MIXER_WRITE_R(OSS_SOUND_MIXER_NRDEVICES)) ||
    884  1.15  augustss 			   (OSS_MIXER_WRITE(OSS_SOUND_MIXER_FIRST) <= com &&
    885  1.15  augustss 			   com < OSS_MIXER_WRITE(OSS_SOUND_MIXER_NRDEVICES))) {
    886   1.6  augustss 			n = OSS_GET_DEV(com);
    887  1.28   thorpej 			if (di->devmap[n] == -1) {
    888  1.28   thorpej 				error = EINVAL;
    889  1.28   thorpej 				goto out;
    890  1.28   thorpej 			}
    891   1.6  augustss 			error = copyin(SCARG(uap, data), &idat, sizeof idat);
    892   1.6  augustss 			if (error)
    893  1.28   thorpej 				goto out;
    894  1.17  augustss 			l = FROM_OSSVOL( idat       & 0xff);
    895  1.17  augustss 			r = FROM_OSSVOL((idat >> 8) & 0xff);
    896   1.6  augustss 			mc.dev = di->devmap[n];
    897   1.6  augustss 			mc.type = AUDIO_MIXER_VALUE;
    898   1.6  augustss 			if (di->stereomask & (1<<n)) {
    899   1.6  augustss 				mc.un.value.num_channels = 2;
    900   1.6  augustss 				mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
    901   1.6  augustss 				mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
    902   1.6  augustss 			} else {
    903   1.6  augustss 				mc.un.value.num_channels = 1;
    904   1.6  augustss 				mc.un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r)/2;
    905   1.6  augustss 			}
    906  1.47     perry 			DPRINTF(("OSS_MIXER_WRITE n=%d (dev=%d) l=%d, r=%d, idat=%04x\n",
    907  1.17  augustss 				 n, di->devmap[n], l, r, idat));
    908  1.49  christos 			error = ioctlf(fp, AUDIO_MIXER_WRITE, (caddr_t)&mc, lwp);
    909   1.6  augustss 			if (error)
    910  1.28   thorpej 				goto out;
    911  1.15  augustss 			if (OSS_MIXER_WRITE(OSS_SOUND_MIXER_FIRST) <= com &&
    912  1.28   thorpej 			   com < OSS_MIXER_WRITE(OSS_SOUND_MIXER_NRDEVICES)) {
    913  1.28   thorpej 				error = 0;
    914  1.28   thorpej 				goto out;
    915  1.28   thorpej 			}
    916   1.6  augustss 			goto doread;
    917  1.15  augustss 		} else {
    918  1.15  augustss #ifdef AUDIO_DEBUG
    919  1.15  augustss 			printf("oss_audio: unknown mixer ioctl %04lx\n", com);
    920  1.15  augustss #endif
    921  1.28   thorpej 			error = EINVAL;
    922  1.28   thorpej 			goto out;
    923  1.15  augustss 		}
    924   1.6  augustss 	}
    925  1.28   thorpej 	error = copyout(&idat, SCARG(uap, data), sizeof idat);
    926  1.28   thorpej  out:
    927  1.49  christos 	FILE_UNUSE(fp, lwp);
    928  1.28   thorpej 	return error;
    929   1.6  augustss }
    930   1.6  augustss 
    931  1.26  augustss /* Sequencer emulation */
    932   1.3   mycroft int
    933  1.49  christos oss_ioctl_sequencer(l, uap, retval)
    934  1.49  christos 	struct lwp *l;
    935  1.21  augustss 	struct oss_sys_ioctl_args /* {
    936   1.3   mycroft 		syscallarg(int) fd;
    937   1.3   mycroft 		syscallarg(u_long) com;
    938   1.3   mycroft 		syscallarg(caddr_t) data;
    939   1.3   mycroft 	} */ *uap;
    940   1.3   mycroft 	register_t *retval;
    941  1.47     perry {
    942  1.49  christos 	struct proc *p = l->l_proc;
    943  1.21  augustss 	struct file *fp;
    944  1.21  augustss 	struct filedesc *fdp;
    945   1.3   mycroft 	u_long com;
    946  1.26  augustss 	int idat, idat1;
    947  1.26  augustss 	struct synth_info si;
    948  1.26  augustss 	struct oss_synth_info osi;
    949  1.26  augustss 	struct oss_seq_event_rec oser;
    950   1.3   mycroft 	int error;
    951  1.49  christos 	int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
    952   1.3   mycroft 
    953   1.3   mycroft 	fdp = p->p_fd;
    954  1.36   thorpej 	if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    955   1.3   mycroft 		return (EBADF);
    956   1.3   mycroft 
    957  1.28   thorpej 	FILE_USE(fp);
    958  1.28   thorpej 
    959  1.28   thorpej 	if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
    960  1.28   thorpej 		error = EBADF;
    961  1.28   thorpej 		goto out;
    962  1.28   thorpej 	}
    963   1.3   mycroft 
    964   1.3   mycroft 	com = SCARG(uap, com);
    965  1.26  augustss 	DPRINTF(("oss_ioctl_sequencer: com=%08lx\n", com));
    966  1.26  augustss 
    967   1.3   mycroft 	retval[0] = 0;
    968   1.3   mycroft 
    969  1.26  augustss 	ioctlf = fp->f_ops->fo_ioctl;
    970  1.26  augustss 	switch (com) {
    971  1.26  augustss 	case OSS_SEQ_RESET:
    972  1.49  christos 		error = ioctlf(fp, SEQUENCER_RESET, (caddr_t)&idat, l);
    973  1.28   thorpej 		goto out;
    974  1.26  augustss 	case OSS_SEQ_SYNC:
    975  1.49  christos 		error = ioctlf(fp, SEQUENCER_SYNC, (caddr_t)&idat, l);
    976  1.28   thorpej 		goto out;
    977  1.26  augustss 	case OSS_SYNTH_INFO:
    978  1.26  augustss 		error = copyin(SCARG(uap, data), &osi, sizeof osi);
    979  1.26  augustss 		if (error)
    980  1.28   thorpej 			goto out;
    981  1.26  augustss 		si.device = osi.device;
    982  1.49  christos 		error = ioctlf(fp, SEQUENCER_INFO, (caddr_t)&si, l);
    983  1.26  augustss 		if (error)
    984  1.28   thorpej 			goto out;
    985  1.26  augustss 		strncpy(osi.name, si.name, sizeof osi.name);
    986  1.26  augustss 		osi.device = si.device;
    987  1.26  augustss 		switch(si.synth_type) {
    988  1.47     perry 		case SYNTH_TYPE_FM:
    989  1.26  augustss 			osi.synth_type = OSS_SYNTH_TYPE_FM; break;
    990  1.47     perry 		case SYNTH_TYPE_SAMPLE:
    991  1.26  augustss 			osi.synth_type = OSS_SYNTH_TYPE_SAMPLE; break;
    992  1.47     perry 		case SYNTH_TYPE_MIDI:
    993  1.26  augustss 			osi.synth_type = OSS_SYNTH_TYPE_MIDI; break;
    994  1.26  augustss 		default:
    995  1.26  augustss 			osi.synth_type = 0; break;
    996  1.26  augustss 		}
    997  1.26  augustss 		switch(si.synth_subtype) {
    998  1.47     perry 		case SYNTH_SUB_FM_TYPE_ADLIB:
    999  1.26  augustss 			osi.synth_subtype = OSS_FM_TYPE_ADLIB; break;
   1000  1.47     perry 		case SYNTH_SUB_FM_TYPE_OPL3:
   1001  1.26  augustss 			osi.synth_subtype = OSS_FM_TYPE_OPL3; break;
   1002  1.47     perry 		case SYNTH_SUB_MIDI_TYPE_MPU401:
   1003  1.26  augustss 			osi.synth_subtype = OSS_MIDI_TYPE_MPU401; break;
   1004  1.47     perry 		case SYNTH_SUB_SAMPLE_TYPE_BASIC:
   1005  1.26  augustss 			osi.synth_subtype = OSS_SAMPLE_TYPE_BASIC; break;
   1006  1.26  augustss 		default:
   1007  1.26  augustss 			osi.synth_subtype = 0; break;
   1008  1.26  augustss 		}
   1009  1.26  augustss 		osi.perc_mode = 0;
   1010  1.26  augustss 		osi.nr_voices = si.nr_voices;
   1011  1.26  augustss 		osi.nr_drums = 0;
   1012  1.26  augustss 		osi.instr_bank_size = si.instr_bank_size;
   1013  1.26  augustss 		osi.capabilities = 0;
   1014  1.47     perry 		if (si.capabilities & SYNTH_CAP_OPL3)
   1015  1.26  augustss 			osi.capabilities |= OSS_SYNTH_CAP_OPL3;
   1016  1.26  augustss 		if (si.capabilities & SYNTH_CAP_INPUT)
   1017  1.26  augustss 			osi.capabilities |= OSS_SYNTH_CAP_INPUT;
   1018  1.28   thorpej 		error = copyout(&osi, SCARG(uap, data), sizeof osi);
   1019  1.28   thorpej 		goto out;
   1020  1.26  augustss 	case OSS_SEQ_CTRLRATE:
   1021  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1022  1.26  augustss 		if (error)
   1023  1.28   thorpej 			goto out;
   1024  1.49  christos 		error = ioctlf(fp, SEQUENCER_CTRLRATE, (caddr_t)&idat, l);
   1025  1.26  augustss 		if (error)
   1026  1.28   thorpej 			goto out;
   1027  1.26  augustss 		retval[0] = idat;
   1028  1.26  augustss 		break;
   1029  1.26  augustss 	case OSS_SEQ_GETOUTCOUNT:
   1030  1.49  christos 		error = ioctlf(fp, SEQUENCER_GETOUTCOUNT, (caddr_t)&idat, l);
   1031  1.26  augustss 		if (error)
   1032  1.28   thorpej 			goto out;
   1033  1.26  augustss 		retval[0] = idat;
   1034  1.26  augustss 		break;
   1035  1.26  augustss 	case OSS_SEQ_GETINCOUNT:
   1036  1.49  christos 		error = ioctlf(fp, SEQUENCER_GETINCOUNT, (caddr_t)&idat, l);
   1037  1.26  augustss 		if (error)
   1038  1.28   thorpej 			goto out;
   1039  1.26  augustss 		retval[0] = idat;
   1040  1.26  augustss 		break;
   1041  1.26  augustss 	case OSS_SEQ_NRSYNTHS:
   1042  1.49  christos 		error = ioctlf(fp, SEQUENCER_NRSYNTHS, (caddr_t)&idat, l);
   1043  1.26  augustss 		if (error)
   1044  1.28   thorpej 			goto out;
   1045  1.26  augustss 		retval[0] = idat;
   1046  1.26  augustss 		break;
   1047  1.26  augustss 	case OSS_SEQ_NRMIDIS:
   1048  1.49  christos 		error = ioctlf(fp, SEQUENCER_NRMIDIS, (caddr_t)&idat, l);
   1049  1.26  augustss 		if (error)
   1050  1.28   thorpej 			goto out;
   1051  1.26  augustss 		retval[0] = idat;
   1052  1.26  augustss 		break;
   1053  1.26  augustss 	case OSS_SEQ_THRESHOLD:
   1054  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1055  1.26  augustss 		if (error)
   1056  1.28   thorpej 			goto out;
   1057  1.49  christos 		error = ioctlf(fp, SEQUENCER_THRESHOLD, (caddr_t)&idat, l);
   1058  1.28   thorpej 		goto out;
   1059  1.26  augustss 	case OSS_MEMAVL:
   1060  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1061  1.26  augustss 		if (error)
   1062  1.28   thorpej 			goto out;
   1063  1.49  christos 		error = ioctlf(fp, SEQUENCER_MEMAVL, (caddr_t)&idat, l);
   1064  1.26  augustss 		if (error)
   1065  1.28   thorpej 			goto out;
   1066  1.26  augustss 		retval[0] = idat;
   1067  1.26  augustss 		break;
   1068  1.26  augustss 	case OSS_SEQ_PANIC:
   1069  1.49  christos 		error = ioctlf(fp, SEQUENCER_PANIC, (caddr_t)&idat, l);
   1070  1.28   thorpej 		goto out;
   1071  1.26  augustss 	case OSS_SEQ_OUTOFBAND:
   1072  1.26  augustss 		error = copyin(SCARG(uap, data), &oser, sizeof oser);
   1073  1.26  augustss 		if (error)
   1074  1.28   thorpej 			goto out;
   1075  1.49  christos 		error = ioctlf(fp, SEQUENCER_OUTOFBAND, (caddr_t)&oser, l);
   1076  1.26  augustss 		if (error)
   1077  1.28   thorpej 			goto out;
   1078  1.26  augustss 		break;
   1079  1.26  augustss 	case OSS_SEQ_GETTIME:
   1080  1.49  christos 		error = ioctlf(fp, SEQUENCER_GETTIME, (caddr_t)&idat, l);
   1081  1.26  augustss 		if (error)
   1082  1.28   thorpej 			goto out;
   1083  1.26  augustss 		retval[0] = idat;
   1084  1.26  augustss 		break;
   1085  1.26  augustss 	case OSS_TMR_TIMEBASE:
   1086  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1087  1.26  augustss 		if (error)
   1088  1.28   thorpej 			goto out;
   1089  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_TIMEBASE, (caddr_t)&idat, l);
   1090  1.26  augustss 		if (error)
   1091  1.28   thorpej 			goto out;
   1092  1.26  augustss 		retval[0] = idat;
   1093  1.26  augustss 		break;
   1094  1.26  augustss 	case OSS_TMR_START:
   1095  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_START, (caddr_t)&idat, l);
   1096  1.28   thorpej 		goto out;
   1097  1.26  augustss 	case OSS_TMR_STOP:
   1098  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_STOP, (caddr_t)&idat, l);
   1099  1.28   thorpej 		goto out;
   1100  1.26  augustss 	case OSS_TMR_CONTINUE:
   1101  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_CONTINUE, (caddr_t)&idat, l);
   1102  1.28   thorpej 		goto out;
   1103  1.26  augustss 	case OSS_TMR_TEMPO:
   1104  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1105  1.26  augustss 		if (error)
   1106  1.28   thorpej 			goto out;
   1107  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_TEMPO, (caddr_t)&idat, l);
   1108  1.26  augustss 		if (error)
   1109  1.28   thorpej 			goto out;
   1110  1.26  augustss 		retval[0] = idat;
   1111  1.26  augustss 		break;
   1112  1.26  augustss 	case OSS_TMR_SOURCE:
   1113  1.26  augustss 		error = copyin(SCARG(uap, data), &idat1, sizeof idat);
   1114  1.26  augustss 		if (error)
   1115  1.28   thorpej 			goto out;
   1116  1.26  augustss 		idat = 0;
   1117  1.26  augustss 		if (idat1 & OSS_TMR_INTERNAL) idat |= SEQUENCER_TMR_INTERNAL;
   1118  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_SOURCE, (caddr_t)&idat, l);
   1119  1.26  augustss 		if (error)
   1120  1.28   thorpej 			goto out;
   1121  1.26  augustss 		idat1 = idat;
   1122  1.26  augustss 		if (idat1 & SEQUENCER_TMR_INTERNAL) idat |= OSS_TMR_INTERNAL;
   1123  1.26  augustss 		retval[0] = idat;
   1124  1.26  augustss 		break;
   1125  1.26  augustss 	case OSS_TMR_METRONOME:
   1126  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1127  1.26  augustss 		if (error)
   1128  1.28   thorpej 			goto out;
   1129  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_METRONOME, (caddr_t)&idat, l);
   1130  1.28   thorpej 		goto out;
   1131  1.26  augustss 	case OSS_TMR_SELECT:
   1132  1.26  augustss 		error = copyin(SCARG(uap, data), &idat, sizeof idat);
   1133  1.26  augustss 		if (error)
   1134  1.28   thorpej 			goto out;
   1135  1.26  augustss 		retval[0] = idat;
   1136  1.49  christos 		error = ioctlf(fp, SEQUENCER_TMR_SELECT, (caddr_t)&idat, l);
   1137  1.28   thorpej 		goto out;
   1138  1.26  augustss 	default:
   1139  1.28   thorpej 		error = EINVAL;
   1140  1.28   thorpej 		goto out;
   1141  1.26  augustss 	}
   1142  1.26  augustss 
   1143  1.28   thorpej 	error = copyout(&idat, SCARG(uap, data), sizeof idat);
   1144  1.28   thorpej  out:
   1145  1.49  christos 	FILE_UNUSE(fp, l);
   1146  1.28   thorpej 	return error;
   1147  1.14  augustss }
   1148  1.14  augustss 
   1149  1.14  augustss /*
   1150  1.14  augustss  * Check that the blocksize is a power of 2 as OSS wants.
   1151  1.14  augustss  * If not, set it to be.
   1152  1.14  augustss  */
   1153  1.33  jdolecek static void
   1154  1.49  christos setblocksize(fp, info, l)
   1155  1.14  augustss 	struct file *fp;
   1156  1.14  augustss 	struct audio_info *info;
   1157  1.49  christos 	struct lwp *l;
   1158  1.14  augustss {
   1159  1.14  augustss 	struct audio_info set;
   1160  1.14  augustss 	int s;
   1161  1.14  augustss 
   1162  1.49  christos 	 if (info->blocksize & (info->blocksize-1)) {
   1163  1.14  augustss 		for(s = 32; s < info->blocksize; s <<= 1)
   1164  1.14  augustss 			;
   1165  1.50   xtraeme 		AUDIO_INITINFO(&set);
   1166  1.14  augustss 		set.blocksize = s;
   1167  1.49  christos 		fp->f_ops->fo_ioctl(fp, AUDIO_SETINFO, (caddr_t)&set, l);
   1168  1.49  christos 		fp->f_ops->fo_ioctl(fp, AUDIO_GETINFO, (caddr_t)info, l);
   1169  1.14  augustss 	}
   1170   1.1   mycroft }
   1171