xref: /freebsd/sys/dev/sound/pcm/sound.h (revision f856af0466c076beef4ea9b15d088e1119a945b8)
1 /*-
2  * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3  * Copyright by Hannu Savolainen 1995
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 /*
31  * first, include kernel header files.
32  */
33 
34 #ifndef _OS_H_
35 #define _OS_H_
36 
37 #ifdef _KERNEL
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/ioccom.h>
41 #include <sys/filio.h>
42 #include <sys/sockio.h>
43 #include <sys/fcntl.h>
44 #include <sys/tty.h>
45 #include <sys/proc.h>
46 #include <sys/kernel.h> /* for DATA_SET */
47 #include <sys/module.h>
48 #include <sys/conf.h>
49 #include <sys/file.h>
50 #include <sys/uio.h>
51 #include <sys/syslog.h>
52 #include <sys/errno.h>
53 #include <sys/malloc.h>
54 #include <sys/bus.h>
55 #if __FreeBSD_version < 500000
56 #include <sys/buf.h>
57 #endif
58 #include <machine/resource.h>
59 #include <machine/bus.h>
60 #include <sys/rman.h>
61 #include <sys/limits.h>
62 #include <sys/mman.h>
63 #include <sys/poll.h>
64 #include <sys/sbuf.h>
65 #include <sys/soundcard.h>
66 #include <sys/sysctl.h>
67 #include <sys/kobj.h>
68 #include <vm/vm.h>
69 #include <vm/pmap.h>
70 
71 #undef	USING_MUTEX
72 #undef	USING_DEVFS
73 
74 #if __FreeBSD_version > 500000
75 #include <sys/lock.h>
76 #include <sys/mutex.h>
77 #include <sys/condvar.h>
78 
79 #define USING_MUTEX
80 #define USING_DEVFS
81 #else
82 #define	INTR_TYPE_AV	INTR_TYPE_TTY
83 #define	INTR_MPSAFE	0
84 #endif
85 
86 #define SND_DYNSYSCTL
87 
88 struct pcm_channel;
89 struct pcm_feeder;
90 struct snd_dbuf;
91 struct snd_mixer;
92 
93 #include <dev/sound/pcm/buffer.h>
94 #include <dev/sound/pcm/channel.h>
95 #include <dev/sound/pcm/feeder.h>
96 #include <dev/sound/pcm/mixer.h>
97 #include <dev/sound/pcm/dsp.h>
98 
99 #define	PCM_SOFTC_SIZE	512
100 
101 #define SND_STATUSLEN	64
102 
103 #define SOUND_MODVER	1
104 
105 #define SOUND_MINVER	1
106 #define SOUND_PREFVER	SOUND_MODVER
107 #define SOUND_MAXVER	1
108 
109 /*
110 PROPOSAL:
111 each unit needs:
112 status, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices
113 dspW and audio are deprecated.
114 dsp needs min 64 channels, will give it 256
115 
116 minor = (unit << 20) + (dev << 16) + channel
117 currently minor = (channel << 16) + (unit << 4) + dev
118 
119 nomenclature:
120 	/dev/pcmX/dsp.(0..255)
121 	/dev/pcmX/dspW
122 	/dev/pcmX/audio
123 	/dev/pcmX/status
124 	/dev/pcmX/mixer
125 	[etc.]
126 */
127 
128 #define PCMMAXCHAN		0xff
129 #define PCMMAXDEV		0x0f
130 #define PCMMAXUNIT		0x0f
131 #define PCMMINOR(x)		(minor(x))
132 #define PCMCHAN(x)		((PCMMINOR(x) >> 16) & PCMMAXCHAN)
133 #define PCMUNIT(x)		((PCMMINOR(x) >> 4) & PCMMAXUNIT)
134 #define PCMDEV(x)		(PCMMINOR(x) & PCMMAXDEV)
135 #define PCMMKMINOR(u, d, c)	((((c) & PCMMAXCHAN) << 16) | \
136 				(((u) & PCMMAXUNIT) << 4) | ((d) & PCMMAXDEV))
137 
138 #define SD_F_SIMPLEX		0x00000001
139 #define SD_F_AUTOVCHAN		0x00000002
140 #define SD_F_SOFTPCMVOL		0x00000004
141 #define SD_F_PRIO_RD		0x10000000
142 #define SD_F_PRIO_WR		0x20000000
143 #define SD_F_PRIO_SET		(SD_F_PRIO_RD | SD_F_PRIO_WR)
144 #define SD_F_DIR_SET		0x40000000
145 #define SD_F_TRANSIENT		0xf0000000
146 
147 /* many variables should be reduced to a range. Here define a macro */
148 #define RANGE(var, low, high) (var) = \
149 	(((var)<(low))? (low) : ((var)>(high))? (high) : (var))
150 #define DSP_BUFFSIZE (8192)
151 
152 /*
153  * Macros for reading/writing PCM sample / int values from bytes array.
154  * Since every process is done using signed integer (and to make our life
155  * less miserable), unsigned sample will be converted to its signed
156  * counterpart and restored during writing back. To avoid overflow,
157  * we truncate 32bit (and only 32bit) samples down to 24bit (see below
158  * for the reason), unless PCM_USE_64BIT_ARITH is defined.
159  */
160 
161 /*
162  * Automatically turn on 64bit arithmetic on suitable archs
163  * (amd64 64bit, ia64, etc..) for wider 32bit samples / integer processing.
164  */
165 #if LONG_BIT >= 64
166 #undef PCM_USE_64BIT_ARITH
167 #define PCM_USE_64BIT_ARITH	1
168 #else
169 #if 0
170 #undef PCM_USE_64BIT_ARITH
171 #define PCM_USE_64BIT_ARITH	1
172 #endif
173 #endif
174 
175 #ifdef PCM_USE_64BIT_ARITH
176 typedef int64_t intpcm_t;
177 #else
178 typedef int32_t intpcm_t;
179 #endif
180 
181 /* 32bit fixed point shift */
182 #define	PCM_FXSHIFT	8
183 
184 #define PCM_S8_MAX	  0x7f
185 #define PCM_S8_MIN	 -0x80
186 #define PCM_S16_MAX	  0x7fff
187 #define PCM_S16_MIN	 -0x8000
188 #define PCM_S24_MAX	  0x7fffff
189 #define PCM_S24_MIN	 -0x800000
190 #ifdef PCM_USE_64BIT_ARITH
191 #if LONG_BIT >= 64
192 #define PCM_S32_MAX	  0x7fffffffL
193 #define PCM_S32_MIN	 -0x80000000L
194 #else
195 #define PCM_S32_MAX	  0x7fffffffLL
196 #define PCM_S32_MIN	 -0x80000000LL
197 #endif
198 #else
199 #define PCM_S32_MAX	  0x7fffffff
200 #define PCM_S32_MIN	(-0x7fffffff - 1)
201 #endif
202 
203 /* Bytes-per-sample definition */
204 #define PCM_8_BPS	1
205 #define PCM_16_BPS	2
206 #define PCM_24_BPS	3
207 #define PCM_32_BPS	4
208 
209 #if BYTE_ORDER == LITTLE_ENDIAN
210 #define PCM_READ_S16_LE(b8)		*((int16_t *)(b8))
211 #define _PCM_READ_S32_LE(b8)		*((int32_t *)(b8))
212 #define PCM_READ_S16_BE(b8) \
213 		((int32_t)((b8)[1] | ((int8_t)((b8)[0])) << 8))
214 #define _PCM_READ_S32_BE(b8) \
215 		((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \
216 			((int8_t)((b8)[0])) << 24))
217 
218 #define PCM_WRITE_S16_LE(b8, val)	*((int16_t *)(b8)) = (val)
219 #define _PCM_WRITE_S32_LE(b8, val)	*((int32_t *)(b8)) = (val)
220 #define PCM_WRITE_S16_BE(bb8, vval) do { \
221 			int32_t val = (vval); \
222 			uint8_t *b8 = (bb8); \
223 			b8[1] = val; \
224 			b8[0] = val >> 8; \
225 		} while(0)
226 #define _PCM_WRITE_S32_BE(bb8, vval) do { \
227 			int32_t val = (vval); \
228 			uint8_t *b8 = (bb8); \
229 			b8[3] = val; \
230 			b8[2] = val >> 8; \
231 			b8[1] = val >> 16; \
232 			b8[0] = val >> 24; \
233 		} while(0)
234 
235 #define PCM_READ_U16_LE(b8)		((int16_t)(*((uint16_t *)(b8)) ^ 0x8000))
236 #define _PCM_READ_U32_LE(b8)		((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000))
237 #define PCM_READ_U16_BE(b8) \
238 		((int32_t)((b8)[1] | ((int8_t)((b8)[0] ^ 0x80)) << 8))
239 #define _PCM_READ_U32_BE(b8) \
240 		((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \
241 			((int8_t)((b8)[0] ^ 0x80)) << 24))
242 
243 #define PCM_WRITE_U16_LE(b8, val)	*((uint16_t *)(b8)) = (val) ^ 0x8000
244 #define _PCM_WRITE_U32_LE(b8, val)	*((uint32_t *)(b8)) = (val) ^ 0x80000000
245 #define PCM_WRITE_U16_BE(bb8, vval) do { \
246 			int32_t val = (vval); \
247 			uint8_t *b8 = (bb8); \
248 			b8[1] = val; \
249 			b8[0] = (val >> 8) ^ 0x80; \
250 		} while(0)
251 #define _PCM_WRITE_U32_BE(bb8, vval) do { \
252 			int32_t val = (vval); \
253 			uint8_t *b8 = (bb8); \
254 			b8[3] = val; \
255 			b8[2] = val >> 8; \
256 			b8[1] = val >> 16; \
257 			b8[0] = (val >> 24) ^ 0x80; \
258 		} while(0)
259 #else /* !LITTLE_ENDIAN */
260 #define PCM_READ_S16_LE(b8) \
261 		((int32_t)((b8)[0] | ((int8_t)((b8)[1])) << 8))
262 #define _PCM_READ_S32_LE(b8) \
263 		((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \
264 			((int8_t)((b8)[3])) << 24))
265 #define PCM_READ_S16_BE(b8)		*((int16_t *)(b8))
266 #define _PCM_READ_S32_BE(b8)		*((int32_t *)(b8))
267 
268 #define PCM_WRITE_S16_LE(bb8, vval) do { \
269 			int32_t val = (vval); \
270 			uint8_t *b8 = (bb8); \
271 			b8[0] = val; \
272 			b8[1] = val >> 8; \
273 		} while(0)
274 #define _PCM_WRITE_S32_LE(bb8, vval) do { \
275 			int32_t val = (vval); \
276 			uint8_t *b8 = (bb8); \
277 			b8[0] = val; \
278 			b8[1] = val >> 8; \
279 			b8[2] = val >> 16; \
280 			b8[3] = val >> 24; \
281 		} while(0)
282 #define PCM_WRITE_S16_BE(b8, val)	*((int16_t *)(b8)) = (val)
283 #define _PCM_WRITE_S32_BE(b8, val)	*((int32_t *)(b8)) = (val)
284 
285 #define PCM_READ_U16_LE(b8) \
286 		((int32_t)((b8)[0] | ((int8_t)((b8)[1] ^ 0x80)) << 8))
287 #define _PCM_READ_U32_LE(b8) \
288 		((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \
289 			((int8_t)((b8)[3] ^ 0x80)) << 24))
290 #define PCM_READ_U16_BE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000))
291 #define _PCM_READ_U32_BE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000))
292 
293 #define PCM_WRITE_U16_LE(bb8, vval) do { \
294 			int32_t val = (vval); \
295 			uint8_t *b8 = (bb8); \
296 			b8[0] = val; \
297 			b8[1] = (val >> 8) ^ 0x80; \
298 		} while(0)
299 #define _PCM_WRITE_U32_LE(bb8, vval) do { \
300 			int32_t val = (vval); \
301 			uint8_t *b8 = (bb8); \
302 			b8[0] = val; \
303 			b8[1] = val >> 8; \
304 			b8[2] = val >> 16; \
305 			b8[3] = (val >> 24) ^ 0x80; \
306 		} while(0)
307 #define PCM_WRITE_U16_BE(b8, val)	*((uint16_t *)(b8)) = (val) ^ 0x8000
308 #define _PCM_WRITE_U32_BE(b8, val)	*((uint32_t *)(b8)) = (val) ^ 0x80000000
309 #endif
310 
311 #define PCM_READ_S24_LE(b8) \
312 		((int32_t)((b8)[0] | (b8)[1] << 8 | ((int8_t)((b8)[2])) << 16))
313 #define PCM_READ_S24_BE(b8) \
314 		((int32_t)((b8)[2] | (b8)[1] << 8 | ((int8_t)((b8)[0])) << 16))
315 
316 #define PCM_WRITE_S24_LE(bb8, vval) do { \
317 			int32_t val = (vval); \
318 			uint8_t *b8 = (bb8); \
319 			b8[0] = val; \
320 			b8[1] = val >> 8; \
321 			b8[2] = val >> 16; \
322 		} while(0)
323 #define PCM_WRITE_S24_BE(bb8, vval) do { \
324 			int32_t val = (vval); \
325 			uint8_t *b8 = (bb8); \
326 			b8[2] = val; \
327 			b8[1] = val >> 8; \
328 			b8[0] = val >> 16; \
329 		} while(0)
330 
331 #define PCM_READ_U24_LE(b8) \
332 		((int32_t)((b8)[0] | (b8)[1] << 8 | \
333 			((int8_t)((b8)[2] ^ 0x80)) << 16))
334 #define PCM_READ_U24_BE(b8) \
335 		((int32_t)((b8)[2] | (b8)[1] << 8 | \
336 			((int8_t)((b8)[0] ^ 0x80)) << 16))
337 
338 #define PCM_WRITE_U24_LE(bb8, vval) do { \
339 			int32_t val = (vval); \
340 			uint8_t *b8 = (bb8); \
341 			b8[0] = val; \
342 			b8[1] = val >> 8; \
343 			b8[2] = (val >> 16) ^ 0x80; \
344 		} while(0)
345 #define PCM_WRITE_U24_BE(bb8, vval) do { \
346 			int32_t val = (vval); \
347 			uint8_t *b8 = (bb8); \
348 			b8[2] = val; \
349 			b8[1] = val >> 8; \
350 			b8[0] = (val >> 16) ^ 0x80; \
351 		} while(0)
352 
353 #ifdef PCM_USE_64BIT_ARITH
354 #define PCM_READ_S32_LE(b8)		_PCM_READ_S32_LE(b8)
355 #define PCM_READ_S32_BE(b8)		_PCM_READ_S32_BE(b8)
356 #define PCM_WRITE_S32_LE(b8, val)	_PCM_WRITE_S32_LE(b8, val)
357 #define PCM_WRITE_S32_BE(b8, val)	_PCM_WRITE_S32_BE(b8, val)
358 
359 #define PCM_READ_U32_LE(b8)		_PCM_READ_U32_LE(b8)
360 #define PCM_READ_U32_BE(b8)		_PCM_READ_U32_BE(b8)
361 #define PCM_WRITE_U32_LE(b8, val)	_PCM_WRITE_U32_LE(b8, val)
362 #define PCM_WRITE_U32_BE(b8, val)	_PCM_WRITE_U32_BE(b8, val)
363 #else /* !PCM_USE_64BIT_ARITH */
364 /*
365  * 24bit integer ?!? This is quite unfortunate, eh? Get the fact straight:
366  * Dynamic range for:
367  *	1) Human =~ 140db
368  *	2) 16bit = 96db (close enough)
369  *	3) 24bit = 144db (perfect)
370  *	4) 32bit = 196db (way too much)
371  *	5) Bugs Bunny = Gazillion!@%$Erbzzztt-EINVAL db
372  * Since we're not Bugs Bunny ..uh..err.. avoiding 64bit arithmetic, 24bit
373  * is pretty much sufficient for our signed integer processing.
374  */
375 #define PCM_READ_S32_LE(b8)		(_PCM_READ_S32_LE(b8) >> PCM_FXSHIFT)
376 #define PCM_READ_S32_BE(b8)		(_PCM_READ_S32_BE(b8) >> PCM_FXSHIFT)
377 #define PCM_WRITE_S32_LE(b8, val)	_PCM_WRITE_S32_LE(b8, (val) << PCM_FXSHIFT)
378 #define PCM_WRITE_S32_BE(b8, val)	_PCM_WRITE_S32_BE(b8, (val) << PCM_FXSHIFT)
379 
380 #define PCM_READ_U32_LE(b8)		(_PCM_READ_U32_LE(b8) >> PCM_FXSHIFT)
381 #define PCM_READ_U32_BE(b8)		(_PCM_READ_U32_BE(b8) >> PCM_FXSHIFT)
382 #define PCM_WRITE_U32_LE(b8, val)	_PCM_WRITE_U32_LE(b8, (val) << PCM_FXSHIFT)
383 #define PCM_WRITE_U32_BE(b8, val)	_PCM_WRITE_U32_BE(b8, (val) << PCM_FXSHIFT)
384 #endif
385 
386 /*
387  * 8bit sample is pretty much useless since it doesn't provide
388  * sufficient dynamic range throughout our filtering process.
389  * For the sake of completeness, declare it anyway.
390  */
391 #define PCM_READ_S8(b8)			*((int8_t *)(b8))
392 #define PCM_READ_S8_NE(b8)		PCM_READ_S8(b8)
393 #define PCM_READ_U8(b8)			((int8_t)(*((uint8_t *)(b8)) ^ 0x80))
394 #define PCM_READ_U8_NE(b8)		PCM_READ_U8(b8)
395 
396 #define PCM_WRITE_S8(b8, val)		*((int8_t *)(b8)) = (val)
397 #define PCM_WRITE_S8_NE(b8, val)	PCM_WRITE_S8(b8, val)
398 #define PCM_WRITE_U8(b8, val)		*((uint8_t *)(b8)) = (val) ^ 0x80
399 #define PCM_WRITE_U8_NE(b8, val)	PCM_WRITE_U8(b8, val)
400 
401 #define PCM_CLAMP_S8(val) \
402 		(((val) > PCM_S8_MAX) ? PCM_S8_MAX : \
403 			(((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val)))
404 #define PCM_CLAMP_S16(val) \
405 		(((val) > PCM_S16_MAX) ? PCM_S16_MAX : \
406 			(((val) < PCM_S16_MIN) ? PCM_S16_MIN : (val)))
407 #define PCM_CLAMP_S24(val) \
408 		(((val) > PCM_S24_MAX) ? PCM_S24_MAX : \
409 			(((val) < PCM_S24_MIN) ? PCM_S24_MIN : (val)))
410 
411 #ifdef PCM_USE_64BIT_ARITH
412 #define PCM_CLAMP_S32(val) \
413 		(((val) > PCM_S32_MAX) ? PCM_S32_MAX : \
414 			(((val) < PCM_S32_MIN) ? PCM_S32_MIN : (val)))
415 #else
416 #define PCM_CLAMP_S32(val) \
417 		(((val) > PCM_S24_MAX) ? PCM_S32_MAX : \
418 			(((val) < PCM_S24_MIN) ? PCM_S32_MIN : \
419 			((val) << PCM_FXSHIFT)))
420 #endif
421 
422 #define PCM_CLAMP_U8(val)	PCM_CLAMP_S8(val)
423 #define PCM_CLAMP_U16(val)	PCM_CLAMP_S16(val)
424 #define PCM_CLAMP_U24(val)	PCM_CLAMP_S24(val)
425 #define PCM_CLAMP_U32(val)	PCM_CLAMP_S32(val)
426 
427 /* make figuring out what a format is easier. got AFMT_STEREO already */
428 #define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
429 #define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE)
430 #define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
431 #define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8)
432 #define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \
433 			AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
434 #define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \
435 			AFMT_S16_BE | AFMT_U16_BE)
436 
437 struct pcm_channel *fkchan_setup(device_t dev);
438 int fkchan_kill(struct pcm_channel *c);
439 
440 /* XXX Flawed definition. I'll fix it someday. */
441 #define	SND_MAXVCHANS	PCMMAXCHAN
442 
443 /*
444  * Minor numbers for the sound driver.
445  *
446  * Unfortunately Creative called the codec chip of SB as a DSP. For this
447  * reason the /dev/dsp is reserved for digitized audio use. There is a
448  * device for true DSP processors but it will be called something else.
449  * In v3.0 it's /dev/sndproc but this could be a temporary solution.
450  */
451 
452 #define SND_DEV_CTL	0	/* Control port /dev/mixer */
453 #define SND_DEV_SEQ	1	/* Sequencer /dev/sequencer */
454 #define SND_DEV_MIDIN	2	/* Raw midi access */
455 #define SND_DEV_DSP	3	/* Digitized voice /dev/dsp */
456 #define SND_DEV_AUDIO	4	/* Sparc compatible /dev/audio */
457 #define SND_DEV_DSP16	5	/* Like /dev/dsp but 16 bits/sample */
458 #define SND_DEV_STATUS	6	/* /dev/sndstat */
459 				/* #7 not in use now. */
460 #define SND_DEV_SEQ2	8	/* /dev/sequencer, level 2 interface */
461 #define SND_DEV_SNDPROC 9	/* /dev/sndproc for programmable devices */
462 #define SND_DEV_PSS	SND_DEV_SNDPROC /* ? */
463 #define SND_DEV_NORESET	10
464 #define SND_DEV_DSPHW	11	/* specific channel request */
465 
466 #define DSP_DEFAULT_SPEED	8000
467 
468 #define ON		1
469 #define OFF		0
470 
471 extern int pcm_veto_load;
472 extern int snd_unit;
473 extern int snd_maxautovchans;
474 extern int snd_verbose;
475 extern devclass_t pcm_devclass;
476 extern struct unrhdr *pcmsg_unrhdr;
477 
478 /*
479  * some macros for debugging purposes
480  * DDB/DEB to enable/disable debugging stuff
481  * BVDDB   to enable debugging when bootverbose
482  */
483 #define BVDDB(x) if (bootverbose) x
484 
485 #ifndef DEB
486 #define DEB(x)
487 #endif
488 
489 SYSCTL_DECL(_hw_snd);
490 
491 struct pcm_channel *pcm_getfakechan(struct snddev_info *d);
492 int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int chnum);
493 int pcm_chnrelease(struct pcm_channel *c);
494 int pcm_chnref(struct pcm_channel *c, int ref);
495 int pcm_inprog(struct snddev_info *d, int delta);
496 
497 struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
498 int pcm_chn_destroy(struct pcm_channel *ch);
499 int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);
500 int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch);
501 
502 int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
503 unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz);
504 int pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
505 int pcm_unregister(device_t dev);
506 int pcm_setstatus(device_t dev, char *str);
507 u_int32_t pcm_getflags(device_t dev);
508 void pcm_setflags(device_t dev, u_int32_t val);
509 void *pcm_getdevinfo(device_t dev);
510 
511 
512 int snd_setup_intr(device_t dev, struct resource *res, int flags,
513 		   driver_intr_t hand, void *param, void **cookiep);
514 
515 void *snd_mtxcreate(const char *desc, const char *type);
516 void snd_mtxfree(void *m);
517 void snd_mtxassert(void *m);
518 #define	snd_mtxlock(m) mtx_lock(m)
519 #define	snd_mtxunlock(m) mtx_unlock(m)
520 
521 int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
522 
523 typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
524 int sndstat_acquire(void);
525 int sndstat_release(void);
526 int sndstat_register(device_t dev, char *str, sndstat_handler handler);
527 int sndstat_registerfile(char *str);
528 int sndstat_unregister(device_t dev);
529 int sndstat_unregisterfile(char *str);
530 
531 #define SND_DECLARE_FILE(version) \
532 	_SND_DECLARE_FILE(__LINE__, version)
533 
534 #define _SND_DECLARE_FILE(uniq, version) \
535 	__SND_DECLARE_FILE(uniq, version)
536 
537 #define __SND_DECLARE_FILE(uniq, version) \
538 	static char sndstat_vinfo[] = version; \
539 	SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
540 	SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
541 
542 /* usage of flags in device config entry (config file) */
543 #define DV_F_DRQ_MASK	0x00000007	/* mask for secondary drq */
544 #define	DV_F_DUAL_DMA	0x00000010	/* set to use secondary dma channel */
545 
546 /* ought to be made obsolete but still used by mss */
547 #define	DV_F_DEV_MASK	0x0000ff00	/* force device type/class */
548 #define	DV_F_DEV_SHIFT	8		/* force device type/class */
549 
550 #define	PCM_DEBUG_MTX
551 
552 /*
553  * this is rather kludgey- we need to duplicate these struct def'ns from sound.c
554  * so that the macro versions of pcm_{,un}lock can dereference them.
555  * we also have to do this now makedev() has gone away.
556  */
557 
558 struct snddev_channel {
559 	SLIST_ENTRY(snddev_channel) link;
560 	struct pcm_channel *channel;
561 	int chan_num;
562 	struct cdev *dsp_devt;
563 	struct cdev *dspW_devt;
564 	struct cdev *audio_devt;
565 	struct cdev *dspHW_devt;
566 };
567 
568 struct snddev_info {
569 	SLIST_HEAD(, snddev_channel) channels;
570 	struct pcm_channel *fakechan;
571 	unsigned devcount, playcount, reccount, vchancount;
572 	unsigned flags;
573 	int inprog;
574 	unsigned int bufsz;
575 	void *devinfo;
576 	device_t dev;
577 	char status[SND_STATUSLEN];
578 	struct mtx *lock;
579 	struct cdev *mixer_dev;
580 
581 };
582 
583 void	sound_oss_sysinfo(oss_sysinfo *);
584 
585 #ifdef	PCM_DEBUG_MTX
586 #define	pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock)
587 #define	pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock)
588 #else
589 void pcm_lock(struct snddev_info *d);
590 void pcm_unlock(struct snddev_info *d);
591 #endif
592 
593 #ifdef KLD_MODULE
594 #define PCM_KLDSTRING(a) ("kld " # a)
595 #else
596 #define PCM_KLDSTRING(a) ""
597 #endif
598 
599 #endif /* _KERNEL */
600 
601 #endif	/* _OS_H_ */
602