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