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