ossaudio.c revision 1.60 1 1.60 dsl /* $NetBSD: ossaudio.c,v 1.60 2007/12/08 18:36:22 dsl 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.60 dsl __KERNEL_RCSID(0, "$NetBSD: ossaudio.c,v 1.60 2007/12/08 18:36:22 dsl 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.59 dsl static struct audiodevinfo *getdevinfo(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.59 dsl static void setblocksize(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.60 dsl getdevinfo(struct file *fp, struct lwp *l)
611 1.6 augustss {
612 1.6 augustss mixer_devinfo_t mi;
613 1.31 augustss int i, j, e;
614 1.33 jdolecek static const struct {
615 1.33 jdolecek const char *name;
616 1.6 augustss int code;
617 1.6 augustss } *dp, devs[] = {
618 1.6 augustss { AudioNmicrophone, OSS_SOUND_MIXER_MIC },
619 1.6 augustss { AudioNline, OSS_SOUND_MIXER_LINE },
620 1.6 augustss { AudioNcd, OSS_SOUND_MIXER_CD },
621 1.6 augustss { AudioNdac, OSS_SOUND_MIXER_PCM },
622 1.37 kim { AudioNaux, OSS_SOUND_MIXER_LINE1 },
623 1.6 augustss { AudioNrecord, OSS_SOUND_MIXER_IMIX },
624 1.15 augustss { AudioNmaster, OSS_SOUND_MIXER_VOLUME },
625 1.6 augustss { AudioNtreble, OSS_SOUND_MIXER_TREBLE },
626 1.6 augustss { AudioNbass, OSS_SOUND_MIXER_BASS },
627 1.6 augustss { AudioNspeaker, OSS_SOUND_MIXER_SPEAKER },
628 1.6 augustss /* { AudioNheadphone, ?? },*/
629 1.6 augustss { AudioNoutput, OSS_SOUND_MIXER_OGAIN },
630 1.6 augustss { AudioNinput, OSS_SOUND_MIXER_IGAIN },
631 1.15 augustss /* { AudioNmaster, OSS_SOUND_MIXER_SPEAKER },*/
632 1.6 augustss /* { AudioNstereo, ?? },*/
633 1.6 augustss /* { AudioNmono, ?? },*/
634 1.6 augustss { AudioNfmsynth, OSS_SOUND_MIXER_SYNTH },
635 1.6 augustss /* { AudioNwave, OSS_SOUND_MIXER_PCM },*/
636 1.10 augustss { AudioNmidi, OSS_SOUND_MIXER_SYNTH },
637 1.6 augustss /* { AudioNmixerout, ?? },*/
638 1.6 augustss { 0, -1 }
639 1.6 augustss };
640 1.49 christos int (*ioctlf)(struct file *, u_long, void *, struct lwp *) =
641 1.6 augustss fp->f_ops->fo_ioctl;
642 1.6 augustss struct vnode *vp;
643 1.6 augustss struct vattr va;
644 1.53 christos static struct audiodevinfo devcache;
645 1.6 augustss struct audiodevinfo *di = &devcache;
646 1.46 kent int mlen, dlen;
647 1.6 augustss
648 1.47 perry /*
649 1.31 augustss * Figure out what device it is so we can check if the
650 1.6 augustss * cached data is valid.
651 1.6 augustss */
652 1.6 augustss vp = (struct vnode *)fp->f_data;
653 1.6 augustss if (vp->v_type != VCHR)
654 1.6 augustss return 0;
655 1.58 pooka if (VOP_GETATTR(vp, &va, l->l_cred))
656 1.6 augustss return 0;
657 1.6 augustss if (di->done && di->dev == va.va_rdev)
658 1.6 augustss return di;
659 1.6 augustss
660 1.6 augustss di->done = 1;
661 1.6 augustss di->dev = va.va_rdev;
662 1.6 augustss di->devmask = 0;
663 1.6 augustss di->recmask = 0;
664 1.6 augustss di->stereomask = 0;
665 1.31 augustss di->source = ~0;
666 1.6 augustss di->caps = 0;
667 1.6 augustss for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++)
668 1.6 augustss di->devmap[i] = -1;
669 1.31 augustss for(i = 0; i < NETBSD_MAXDEVS; i++) {
670 1.6 augustss di->rdevmap[i] = -1;
671 1.31 augustss di->names[i][0] = '\0';
672 1.31 augustss di->enum2opaque[i] = -1;
673 1.31 augustss }
674 1.6 augustss for(i = 0; i < NETBSD_MAXDEVS; i++) {
675 1.6 augustss mi.index = i;
676 1.55 christos if (ioctlf(fp, AUDIO_MIXER_DEVINFO, (void *)&mi, l) < 0)
677 1.6 augustss break;
678 1.6 augustss switch(mi.type) {
679 1.6 augustss case AUDIO_MIXER_VALUE:
680 1.46 kent for(dp = devs; dp->name; dp++) {
681 1.46 kent if (strcmp(dp->name, mi.label.name) == 0)
682 1.6 augustss break;
683 1.46 kent dlen = strlen(dp->name);
684 1.46 kent mlen = strlen(mi.label.name);
685 1.46 kent if (dlen < mlen
686 1.46 kent && mi.label.name[mlen-dlen-1] == '.'
687 1.46 kent && strcmp(dp->name, mi.label.name + mlen - dlen) == 0)
688 1.46 kent break;
689 1.46 kent }
690 1.6 augustss if (dp->code >= 0) {
691 1.6 augustss di->devmap[dp->code] = i;
692 1.6 augustss di->rdevmap[i] = dp->code;
693 1.6 augustss di->devmask |= 1 << dp->code;
694 1.6 augustss if (mi.un.v.num_channels == 2)
695 1.6 augustss di->stereomask |= 1 << dp->code;
696 1.47 perry strncpy(di->names[i], mi.label.name,
697 1.31 augustss sizeof di->names[i]);
698 1.6 augustss }
699 1.6 augustss break;
700 1.31 augustss }
701 1.31 augustss }
702 1.31 augustss for(i = 0; i < NETBSD_MAXDEVS; i++) {
703 1.31 augustss mi.index = i;
704 1.55 christos if (ioctlf(fp, AUDIO_MIXER_DEVINFO, (void *)&mi, l) < 0)
705 1.31 augustss break;
706 1.31 augustss if (strcmp(mi.label.name, AudioNsource) != 0)
707 1.31 augustss continue;
708 1.31 augustss di->source = i;
709 1.31 augustss switch(mi.type) {
710 1.6 augustss case AUDIO_MIXER_ENUM:
711 1.31 augustss for(j = 0; j < mi.un.e.num_mem; j++) {
712 1.31 augustss e = opaque_to_enum(di,
713 1.31 augustss &mi.un.e.member[j].label,
714 1.31 augustss mi.un.e.member[j].ord);
715 1.31 augustss if (e >= 0)
716 1.31 augustss di->recmask |= 1 << di->rdevmap[e];
717 1.6 augustss }
718 1.31 augustss di->caps = OSS_SOUND_CAP_EXCL_INPUT;
719 1.6 augustss break;
720 1.6 augustss case AUDIO_MIXER_SET:
721 1.31 augustss for(j = 0; j < mi.un.s.num_mem; j++) {
722 1.31 augustss e = opaque_to_enum(di,
723 1.31 augustss &mi.un.s.member[j].label,
724 1.31 augustss mi.un.s.member[j].mask);
725 1.31 augustss if (e >= 0)
726 1.31 augustss di->recmask |= 1 << di->rdevmap[e];
727 1.6 augustss }
728 1.6 augustss break;
729 1.6 augustss }
730 1.6 augustss }
731 1.6 augustss return di;
732 1.6 augustss }
733 1.6 augustss
734 1.6 augustss int
735 1.49 christos oss_ioctl_mixer(lwp, uap, retval)
736 1.49 christos struct lwp *lwp;
737 1.21 augustss struct oss_sys_ioctl_args /* {
738 1.6 augustss syscallarg(int) fd;
739 1.6 augustss syscallarg(u_long) com;
740 1.55 christos syscallarg(void *) data;
741 1.6 augustss } */ *uap;
742 1.6 augustss register_t *retval;
743 1.47 perry {
744 1.49 christos struct proc *p = lwp->l_proc;
745 1.6 augustss struct file *fp;
746 1.6 augustss struct filedesc *fdp;
747 1.6 augustss u_long com;
748 1.6 augustss struct audiodevinfo *di;
749 1.6 augustss mixer_ctrl_t mc;
750 1.30 augustss struct oss_mixer_info omi;
751 1.30 augustss struct audio_device adev;
752 1.6 augustss int idat;
753 1.6 augustss int i;
754 1.6 augustss int error;
755 1.31 augustss int l, r, n, e;
756 1.49 christos int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
757 1.6 augustss
758 1.6 augustss fdp = p->p_fd;
759 1.36 thorpej if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
760 1.6 augustss return (EBADF);
761 1.6 augustss
762 1.28 thorpej FILE_USE(fp);
763 1.28 thorpej
764 1.28 thorpej if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
765 1.28 thorpej error = EBADF;
766 1.28 thorpej goto out;
767 1.28 thorpej }
768 1.6 augustss
769 1.6 augustss com = SCARG(uap, com);
770 1.26 augustss DPRINTF(("oss_ioctl_mixer: com=%08lx\n", com));
771 1.26 augustss
772 1.6 augustss retval[0] = 0;
773 1.6 augustss
774 1.49 christos di = getdevinfo(fp, lwp);
775 1.28 thorpej if (di == 0) {
776 1.28 thorpej error = EINVAL;
777 1.28 thorpej goto out;
778 1.28 thorpej }
779 1.6 augustss
780 1.6 augustss ioctlf = fp->f_ops->fo_ioctl;
781 1.6 augustss switch (com) {
782 1.31 augustss case OSS_GET_VERSION:
783 1.31 augustss idat = OSS_SOUND_VERSION;
784 1.31 augustss break;
785 1.30 augustss case OSS_SOUND_MIXER_INFO:
786 1.30 augustss case OSS_SOUND_OLD_MIXER_INFO:
787 1.55 christos error = ioctlf(fp, AUDIO_GETDEV, (void *)&adev, lwp);
788 1.30 augustss if (error)
789 1.43 augustss goto out;
790 1.30 augustss omi.modify_counter = 1;
791 1.30 augustss strncpy(omi.id, adev.name, sizeof omi.id);
792 1.30 augustss strncpy(omi.name, adev.name, sizeof omi.name);
793 1.43 augustss error = copyout(&omi, SCARG(uap, data), OSS_IOCTL_SIZE(com));
794 1.43 augustss goto out;
795 1.6 augustss case OSS_SOUND_MIXER_READ_RECSRC:
796 1.28 thorpej if (di->source == -1) {
797 1.28 thorpej error = EINVAL;
798 1.28 thorpej goto out;
799 1.28 thorpej }
800 1.6 augustss mc.dev = di->source;
801 1.6 augustss if (di->caps & OSS_SOUND_CAP_EXCL_INPUT) {
802 1.6 augustss mc.type = AUDIO_MIXER_ENUM;
803 1.55 christos error = ioctlf(fp, AUDIO_MIXER_READ, (void *)&mc, lwp);
804 1.6 augustss if (error)
805 1.28 thorpej goto out;
806 1.31 augustss e = opaque_to_enum(di, NULL, mc.un.ord);
807 1.31 augustss if (e >= 0)
808 1.31 augustss idat = 1 << di->rdevmap[e];
809 1.6 augustss } else {
810 1.6 augustss mc.type = AUDIO_MIXER_SET;
811 1.55 christos error = ioctlf(fp, AUDIO_MIXER_READ, (void *)&mc, lwp);
812 1.6 augustss if (error)
813 1.28 thorpej goto out;
814 1.31 augustss e = opaque_to_enum(di, NULL, mc.un.mask);
815 1.31 augustss if (e >= 0)
816 1.31 augustss idat = 1 << di->rdevmap[e];
817 1.6 augustss }
818 1.6 augustss break;
819 1.6 augustss case OSS_SOUND_MIXER_READ_DEVMASK:
820 1.6 augustss idat = di->devmask;
821 1.6 augustss break;
822 1.6 augustss case OSS_SOUND_MIXER_READ_RECMASK:
823 1.6 augustss idat = di->recmask;
824 1.6 augustss break;
825 1.6 augustss case OSS_SOUND_MIXER_READ_STEREODEVS:
826 1.6 augustss idat = di->stereomask;
827 1.6 augustss break;
828 1.6 augustss case OSS_SOUND_MIXER_READ_CAPS:
829 1.6 augustss idat = di->caps;
830 1.6 augustss break;
831 1.6 augustss case OSS_SOUND_MIXER_WRITE_RECSRC:
832 1.15 augustss case OSS_SOUND_MIXER_WRITE_R_RECSRC:
833 1.28 thorpej if (di->source == -1) {
834 1.28 thorpej error = EINVAL;
835 1.28 thorpej goto out;
836 1.28 thorpej }
837 1.6 augustss mc.dev = di->source;
838 1.6 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
839 1.6 augustss if (error)
840 1.28 thorpej goto out;
841 1.7 augustss if (di->caps & OSS_SOUND_CAP_EXCL_INPUT) {
842 1.7 augustss mc.type = AUDIO_MIXER_ENUM;
843 1.7 augustss for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++)
844 1.7 augustss if (idat & (1 << i))
845 1.7 augustss break;
846 1.7 augustss if (i >= OSS_SOUND_MIXER_NRDEVICES ||
847 1.43 augustss di->devmap[i] == -1) {
848 1.43 augustss error = EINVAL;
849 1.43 augustss goto out;
850 1.43 augustss }
851 1.31 augustss mc.un.ord = enum_to_ord(di, di->devmap[i]);
852 1.7 augustss } else {
853 1.7 augustss mc.type = AUDIO_MIXER_SET;
854 1.11 augustss mc.un.mask = 0;
855 1.10 augustss for(i = 0; i < OSS_SOUND_MIXER_NRDEVICES; i++) {
856 1.7 augustss if (idat & (1 << i)) {
857 1.43 augustss if (di->devmap[i] == -1) {
858 1.43 augustss error = EINVAL;
859 1.43 augustss goto out;
860 1.43 augustss }
861 1.31 augustss mc.un.mask |= enum_to_mask(di, di->devmap[i]);
862 1.7 augustss }
863 1.10 augustss }
864 1.7 augustss }
865 1.55 christos error = ioctlf(fp, AUDIO_MIXER_WRITE, (void *)&mc, lwp);
866 1.28 thorpej goto out;
867 1.6 augustss default:
868 1.6 augustss if (OSS_MIXER_READ(OSS_SOUND_MIXER_FIRST) <= com &&
869 1.6 augustss com < OSS_MIXER_READ(OSS_SOUND_MIXER_NRDEVICES)) {
870 1.6 augustss n = OSS_GET_DEV(com);
871 1.28 thorpej if (di->devmap[n] == -1) {
872 1.28 thorpej error = EINVAL;
873 1.28 thorpej goto out;
874 1.28 thorpej }
875 1.17 augustss doread:
876 1.6 augustss mc.dev = di->devmap[n];
877 1.6 augustss mc.type = AUDIO_MIXER_VALUE;
878 1.6 augustss mc.un.value.num_channels = di->stereomask & (1<<n) ? 2 : 1;
879 1.55 christos error = ioctlf(fp, AUDIO_MIXER_READ, (void *)&mc, lwp);
880 1.6 augustss if (error)
881 1.28 thorpej goto out;
882 1.6 augustss if (mc.un.value.num_channels != 2) {
883 1.6 augustss l = r = mc.un.value.level[AUDIO_MIXER_LEVEL_MONO];
884 1.6 augustss } else {
885 1.6 augustss l = mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT];
886 1.6 augustss r = mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
887 1.6 augustss }
888 1.17 augustss idat = TO_OSSVOL(l) | (TO_OSSVOL(r) << 8);
889 1.47 perry DPRINTF(("OSS_MIXER_READ n=%d (dev=%d) l=%d, r=%d, idat=%04x\n",
890 1.17 augustss n, di->devmap[n], l, r, idat));
891 1.6 augustss break;
892 1.15 augustss } else if ((OSS_MIXER_WRITE_R(OSS_SOUND_MIXER_FIRST) <= com &&
893 1.15 augustss com < OSS_MIXER_WRITE_R(OSS_SOUND_MIXER_NRDEVICES)) ||
894 1.15 augustss (OSS_MIXER_WRITE(OSS_SOUND_MIXER_FIRST) <= com &&
895 1.15 augustss com < OSS_MIXER_WRITE(OSS_SOUND_MIXER_NRDEVICES))) {
896 1.6 augustss n = OSS_GET_DEV(com);
897 1.28 thorpej if (di->devmap[n] == -1) {
898 1.28 thorpej error = EINVAL;
899 1.28 thorpej goto out;
900 1.28 thorpej }
901 1.6 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
902 1.6 augustss if (error)
903 1.28 thorpej goto out;
904 1.17 augustss l = FROM_OSSVOL( idat & 0xff);
905 1.17 augustss r = FROM_OSSVOL((idat >> 8) & 0xff);
906 1.6 augustss mc.dev = di->devmap[n];
907 1.6 augustss mc.type = AUDIO_MIXER_VALUE;
908 1.6 augustss if (di->stereomask & (1<<n)) {
909 1.6 augustss mc.un.value.num_channels = 2;
910 1.6 augustss mc.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
911 1.6 augustss mc.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
912 1.6 augustss } else {
913 1.6 augustss mc.un.value.num_channels = 1;
914 1.6 augustss mc.un.value.level[AUDIO_MIXER_LEVEL_MONO] = (l+r)/2;
915 1.6 augustss }
916 1.47 perry DPRINTF(("OSS_MIXER_WRITE n=%d (dev=%d) l=%d, r=%d, idat=%04x\n",
917 1.17 augustss n, di->devmap[n], l, r, idat));
918 1.55 christos error = ioctlf(fp, AUDIO_MIXER_WRITE, (void *)&mc, lwp);
919 1.6 augustss if (error)
920 1.28 thorpej goto out;
921 1.15 augustss if (OSS_MIXER_WRITE(OSS_SOUND_MIXER_FIRST) <= com &&
922 1.28 thorpej com < OSS_MIXER_WRITE(OSS_SOUND_MIXER_NRDEVICES)) {
923 1.28 thorpej error = 0;
924 1.28 thorpej goto out;
925 1.28 thorpej }
926 1.6 augustss goto doread;
927 1.15 augustss } else {
928 1.15 augustss #ifdef AUDIO_DEBUG
929 1.15 augustss printf("oss_audio: unknown mixer ioctl %04lx\n", com);
930 1.15 augustss #endif
931 1.28 thorpej error = EINVAL;
932 1.28 thorpej goto out;
933 1.15 augustss }
934 1.6 augustss }
935 1.28 thorpej error = copyout(&idat, SCARG(uap, data), sizeof idat);
936 1.28 thorpej out:
937 1.49 christos FILE_UNUSE(fp, lwp);
938 1.28 thorpej return error;
939 1.6 augustss }
940 1.6 augustss
941 1.26 augustss /* Sequencer emulation */
942 1.3 mycroft int
943 1.49 christos oss_ioctl_sequencer(l, uap, retval)
944 1.49 christos struct lwp *l;
945 1.21 augustss struct oss_sys_ioctl_args /* {
946 1.3 mycroft syscallarg(int) fd;
947 1.3 mycroft syscallarg(u_long) com;
948 1.55 christos syscallarg(void *) data;
949 1.3 mycroft } */ *uap;
950 1.3 mycroft register_t *retval;
951 1.47 perry {
952 1.49 christos struct proc *p = l->l_proc;
953 1.21 augustss struct file *fp;
954 1.21 augustss struct filedesc *fdp;
955 1.3 mycroft u_long com;
956 1.26 augustss int idat, idat1;
957 1.26 augustss struct synth_info si;
958 1.26 augustss struct oss_synth_info osi;
959 1.26 augustss struct oss_seq_event_rec oser;
960 1.3 mycroft int error;
961 1.49 christos int (*ioctlf)(struct file *, u_long, void *, struct lwp *);
962 1.3 mycroft
963 1.3 mycroft fdp = p->p_fd;
964 1.36 thorpej if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
965 1.3 mycroft return (EBADF);
966 1.3 mycroft
967 1.28 thorpej FILE_USE(fp);
968 1.28 thorpej
969 1.28 thorpej if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
970 1.28 thorpej error = EBADF;
971 1.28 thorpej goto out;
972 1.28 thorpej }
973 1.3 mycroft
974 1.3 mycroft com = SCARG(uap, com);
975 1.26 augustss DPRINTF(("oss_ioctl_sequencer: com=%08lx\n", com));
976 1.26 augustss
977 1.3 mycroft retval[0] = 0;
978 1.3 mycroft
979 1.26 augustss ioctlf = fp->f_ops->fo_ioctl;
980 1.26 augustss switch (com) {
981 1.26 augustss case OSS_SEQ_RESET:
982 1.55 christos error = ioctlf(fp, SEQUENCER_RESET, (void *)&idat, l);
983 1.28 thorpej goto out;
984 1.26 augustss case OSS_SEQ_SYNC:
985 1.55 christos error = ioctlf(fp, SEQUENCER_SYNC, (void *)&idat, l);
986 1.28 thorpej goto out;
987 1.26 augustss case OSS_SYNTH_INFO:
988 1.26 augustss error = copyin(SCARG(uap, data), &osi, sizeof osi);
989 1.26 augustss if (error)
990 1.28 thorpej goto out;
991 1.26 augustss si.device = osi.device;
992 1.55 christos error = ioctlf(fp, SEQUENCER_INFO, (void *)&si, l);
993 1.26 augustss if (error)
994 1.28 thorpej goto out;
995 1.26 augustss strncpy(osi.name, si.name, sizeof osi.name);
996 1.26 augustss osi.device = si.device;
997 1.26 augustss switch(si.synth_type) {
998 1.47 perry case SYNTH_TYPE_FM:
999 1.26 augustss osi.synth_type = OSS_SYNTH_TYPE_FM; break;
1000 1.47 perry case SYNTH_TYPE_SAMPLE:
1001 1.26 augustss osi.synth_type = OSS_SYNTH_TYPE_SAMPLE; break;
1002 1.47 perry case SYNTH_TYPE_MIDI:
1003 1.26 augustss osi.synth_type = OSS_SYNTH_TYPE_MIDI; break;
1004 1.26 augustss default:
1005 1.26 augustss osi.synth_type = 0; break;
1006 1.26 augustss }
1007 1.26 augustss switch(si.synth_subtype) {
1008 1.47 perry case SYNTH_SUB_FM_TYPE_ADLIB:
1009 1.26 augustss osi.synth_subtype = OSS_FM_TYPE_ADLIB; break;
1010 1.47 perry case SYNTH_SUB_FM_TYPE_OPL3:
1011 1.26 augustss osi.synth_subtype = OSS_FM_TYPE_OPL3; break;
1012 1.47 perry case SYNTH_SUB_MIDI_TYPE_MPU401:
1013 1.26 augustss osi.synth_subtype = OSS_MIDI_TYPE_MPU401; break;
1014 1.47 perry case SYNTH_SUB_SAMPLE_TYPE_BASIC:
1015 1.26 augustss osi.synth_subtype = OSS_SAMPLE_TYPE_BASIC; break;
1016 1.26 augustss default:
1017 1.26 augustss osi.synth_subtype = 0; break;
1018 1.26 augustss }
1019 1.26 augustss osi.perc_mode = 0;
1020 1.26 augustss osi.nr_voices = si.nr_voices;
1021 1.26 augustss osi.nr_drums = 0;
1022 1.26 augustss osi.instr_bank_size = si.instr_bank_size;
1023 1.26 augustss osi.capabilities = 0;
1024 1.47 perry if (si.capabilities & SYNTH_CAP_OPL3)
1025 1.26 augustss osi.capabilities |= OSS_SYNTH_CAP_OPL3;
1026 1.26 augustss if (si.capabilities & SYNTH_CAP_INPUT)
1027 1.26 augustss osi.capabilities |= OSS_SYNTH_CAP_INPUT;
1028 1.28 thorpej error = copyout(&osi, SCARG(uap, data), sizeof osi);
1029 1.28 thorpej goto out;
1030 1.26 augustss case OSS_SEQ_CTRLRATE:
1031 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
1032 1.26 augustss if (error)
1033 1.28 thorpej goto out;
1034 1.55 christos error = ioctlf(fp, SEQUENCER_CTRLRATE, (void *)&idat, l);
1035 1.26 augustss if (error)
1036 1.28 thorpej goto out;
1037 1.26 augustss retval[0] = idat;
1038 1.26 augustss break;
1039 1.26 augustss case OSS_SEQ_GETOUTCOUNT:
1040 1.55 christos error = ioctlf(fp, SEQUENCER_GETOUTCOUNT, (void *)&idat, l);
1041 1.26 augustss if (error)
1042 1.28 thorpej goto out;
1043 1.26 augustss retval[0] = idat;
1044 1.26 augustss break;
1045 1.26 augustss case OSS_SEQ_GETINCOUNT:
1046 1.55 christos error = ioctlf(fp, SEQUENCER_GETINCOUNT, (void *)&idat, l);
1047 1.26 augustss if (error)
1048 1.28 thorpej goto out;
1049 1.26 augustss retval[0] = idat;
1050 1.26 augustss break;
1051 1.26 augustss case OSS_SEQ_NRSYNTHS:
1052 1.55 christos error = ioctlf(fp, SEQUENCER_NRSYNTHS, (void *)&idat, l);
1053 1.26 augustss if (error)
1054 1.28 thorpej goto out;
1055 1.26 augustss retval[0] = idat;
1056 1.26 augustss break;
1057 1.26 augustss case OSS_SEQ_NRMIDIS:
1058 1.55 christos error = ioctlf(fp, SEQUENCER_NRMIDIS, (void *)&idat, l);
1059 1.26 augustss if (error)
1060 1.28 thorpej goto out;
1061 1.26 augustss retval[0] = idat;
1062 1.26 augustss break;
1063 1.26 augustss case OSS_SEQ_THRESHOLD:
1064 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
1065 1.26 augustss if (error)
1066 1.28 thorpej goto out;
1067 1.55 christos error = ioctlf(fp, SEQUENCER_THRESHOLD, (void *)&idat, l);
1068 1.28 thorpej goto out;
1069 1.26 augustss case OSS_MEMAVL:
1070 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
1071 1.26 augustss if (error)
1072 1.28 thorpej goto out;
1073 1.55 christos error = ioctlf(fp, SEQUENCER_MEMAVL, (void *)&idat, l);
1074 1.26 augustss if (error)
1075 1.28 thorpej goto out;
1076 1.26 augustss retval[0] = idat;
1077 1.26 augustss break;
1078 1.26 augustss case OSS_SEQ_PANIC:
1079 1.55 christos error = ioctlf(fp, SEQUENCER_PANIC, (void *)&idat, l);
1080 1.28 thorpej goto out;
1081 1.26 augustss case OSS_SEQ_OUTOFBAND:
1082 1.26 augustss error = copyin(SCARG(uap, data), &oser, sizeof oser);
1083 1.26 augustss if (error)
1084 1.28 thorpej goto out;
1085 1.55 christos error = ioctlf(fp, SEQUENCER_OUTOFBAND, (void *)&oser, l);
1086 1.26 augustss if (error)
1087 1.28 thorpej goto out;
1088 1.26 augustss break;
1089 1.26 augustss case OSS_SEQ_GETTIME:
1090 1.55 christos error = ioctlf(fp, SEQUENCER_GETTIME, (void *)&idat, l);
1091 1.26 augustss if (error)
1092 1.28 thorpej goto out;
1093 1.26 augustss retval[0] = idat;
1094 1.26 augustss break;
1095 1.26 augustss case OSS_TMR_TIMEBASE:
1096 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
1097 1.26 augustss if (error)
1098 1.28 thorpej goto out;
1099 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_TIMEBASE, (void *)&idat, l);
1100 1.26 augustss if (error)
1101 1.28 thorpej goto out;
1102 1.26 augustss retval[0] = idat;
1103 1.26 augustss break;
1104 1.26 augustss case OSS_TMR_START:
1105 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_START, (void *)&idat, l);
1106 1.28 thorpej goto out;
1107 1.26 augustss case OSS_TMR_STOP:
1108 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_STOP, (void *)&idat, l);
1109 1.28 thorpej goto out;
1110 1.26 augustss case OSS_TMR_CONTINUE:
1111 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_CONTINUE, (void *)&idat, l);
1112 1.28 thorpej goto out;
1113 1.26 augustss case OSS_TMR_TEMPO:
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.55 christos error = ioctlf(fp, SEQUENCER_TMR_TEMPO, (void *)&idat, l);
1118 1.26 augustss if (error)
1119 1.28 thorpej goto out;
1120 1.26 augustss retval[0] = idat;
1121 1.26 augustss break;
1122 1.26 augustss case OSS_TMR_SOURCE:
1123 1.26 augustss error = copyin(SCARG(uap, data), &idat1, sizeof idat);
1124 1.26 augustss if (error)
1125 1.28 thorpej goto out;
1126 1.26 augustss idat = 0;
1127 1.26 augustss if (idat1 & OSS_TMR_INTERNAL) idat |= SEQUENCER_TMR_INTERNAL;
1128 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_SOURCE, (void *)&idat, l);
1129 1.26 augustss if (error)
1130 1.28 thorpej goto out;
1131 1.26 augustss idat1 = idat;
1132 1.26 augustss if (idat1 & SEQUENCER_TMR_INTERNAL) idat |= OSS_TMR_INTERNAL;
1133 1.26 augustss retval[0] = idat;
1134 1.26 augustss break;
1135 1.26 augustss case OSS_TMR_METRONOME:
1136 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
1137 1.26 augustss if (error)
1138 1.28 thorpej goto out;
1139 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_METRONOME, (void *)&idat, l);
1140 1.28 thorpej goto out;
1141 1.26 augustss case OSS_TMR_SELECT:
1142 1.26 augustss error = copyin(SCARG(uap, data), &idat, sizeof idat);
1143 1.26 augustss if (error)
1144 1.28 thorpej goto out;
1145 1.26 augustss retval[0] = idat;
1146 1.55 christos error = ioctlf(fp, SEQUENCER_TMR_SELECT, (void *)&idat, l);
1147 1.28 thorpej goto out;
1148 1.26 augustss default:
1149 1.28 thorpej error = EINVAL;
1150 1.28 thorpej goto out;
1151 1.26 augustss }
1152 1.26 augustss
1153 1.28 thorpej error = copyout(&idat, SCARG(uap, data), sizeof idat);
1154 1.28 thorpej out:
1155 1.49 christos FILE_UNUSE(fp, l);
1156 1.28 thorpej return error;
1157 1.14 augustss }
1158 1.14 augustss
1159 1.14 augustss /*
1160 1.14 augustss * Check that the blocksize is a power of 2 as OSS wants.
1161 1.14 augustss * If not, set it to be.
1162 1.14 augustss */
1163 1.33 jdolecek static void
1164 1.60 dsl setblocksize(struct file *fp, struct audio_info *info, struct lwp *l)
1165 1.14 augustss {
1166 1.14 augustss struct audio_info set;
1167 1.14 augustss int s;
1168 1.14 augustss
1169 1.49 christos if (info->blocksize & (info->blocksize-1)) {
1170 1.14 augustss for(s = 32; s < info->blocksize; s <<= 1)
1171 1.14 augustss ;
1172 1.50 xtraeme AUDIO_INITINFO(&set);
1173 1.14 augustss set.blocksize = s;
1174 1.55 christos fp->f_ops->fo_ioctl(fp, AUDIO_SETINFO, (void *)&set, l);
1175 1.56 joerg fp->f_ops->fo_ioctl(fp, AUDIO_GETBUFINFO, (void *)info, l);
1176 1.14 augustss }
1177 1.1 mycroft }
1178