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_PSWAPLR 0x00000008 142 #define SD_F_RSWAPLR 0x00000010 143 #define SD_F_PRIO_RD 0x10000000 144 #define SD_F_PRIO_WR 0x20000000 145 #define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 146 #define SD_F_DIR_SET 0x40000000 147 #define SD_F_TRANSIENT 0xf0000000 148 149 /* many variables should be reduced to a range. Here define a macro */ 150 #define RANGE(var, low, high) (var) = \ 151 (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 152 #define DSP_BUFFSIZE (8192) 153 154 /* 155 * Macros for reading/writing PCM sample / int values from bytes array. 156 * Since every process is done using signed integer (and to make our life 157 * less miserable), unsigned sample will be converted to its signed 158 * counterpart and restored during writing back. To avoid overflow, 159 * we truncate 32bit (and only 32bit) samples down to 24bit (see below 160 * for the reason), unless PCM_USE_64BIT_ARITH is defined. 161 */ 162 163 /* 164 * Automatically turn on 64bit arithmetic on suitable archs 165 * (amd64 64bit, ia64, etc..) for wider 32bit samples / integer processing. 166 */ 167 #if LONG_BIT >= 64 168 #undef PCM_USE_64BIT_ARITH 169 #define PCM_USE_64BIT_ARITH 1 170 #else 171 #if 0 172 #undef PCM_USE_64BIT_ARITH 173 #define PCM_USE_64BIT_ARITH 1 174 #endif 175 #endif 176 177 #ifdef PCM_USE_64BIT_ARITH 178 typedef int64_t intpcm_t; 179 #else 180 typedef int32_t intpcm_t; 181 #endif 182 183 /* 32bit fixed point shift */ 184 #define PCM_FXSHIFT 8 185 186 #define PCM_S8_MAX 0x7f 187 #define PCM_S8_MIN -0x80 188 #define PCM_S16_MAX 0x7fff 189 #define PCM_S16_MIN -0x8000 190 #define PCM_S24_MAX 0x7fffff 191 #define PCM_S24_MIN -0x800000 192 #ifdef PCM_USE_64BIT_ARITH 193 #if LONG_BIT >= 64 194 #define PCM_S32_MAX 0x7fffffffL 195 #define PCM_S32_MIN -0x80000000L 196 #else 197 #define PCM_S32_MAX 0x7fffffffLL 198 #define PCM_S32_MIN -0x80000000LL 199 #endif 200 #else 201 #define PCM_S32_MAX 0x7fffffff 202 #define PCM_S32_MIN (-0x7fffffff - 1) 203 #endif 204 205 /* Bytes-per-sample definition */ 206 #define PCM_8_BPS 1 207 #define PCM_16_BPS 2 208 #define PCM_24_BPS 3 209 #define PCM_32_BPS 4 210 211 #if BYTE_ORDER == LITTLE_ENDIAN 212 #define PCM_READ_S16_LE(b8) *((int16_t *)(b8)) 213 #define _PCM_READ_S32_LE(b8) *((int32_t *)(b8)) 214 #define PCM_READ_S16_BE(b8) \ 215 ((int32_t)((b8)[1] | ((int8_t)((b8)[0])) << 8)) 216 #define _PCM_READ_S32_BE(b8) \ 217 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \ 218 ((int8_t)((b8)[0])) << 24)) 219 220 #define PCM_WRITE_S16_LE(b8, val) *((int16_t *)(b8)) = (val) 221 #define _PCM_WRITE_S32_LE(b8, val) *((int32_t *)(b8)) = (val) 222 #define PCM_WRITE_S16_BE(bb8, vval) do { \ 223 int32_t val = (vval); \ 224 uint8_t *b8 = (bb8); \ 225 b8[1] = val; \ 226 b8[0] = val >> 8; \ 227 } while(0) 228 #define _PCM_WRITE_S32_BE(bb8, vval) do { \ 229 int32_t val = (vval); \ 230 uint8_t *b8 = (bb8); \ 231 b8[3] = val; \ 232 b8[2] = val >> 8; \ 233 b8[1] = val >> 16; \ 234 b8[0] = val >> 24; \ 235 } while(0) 236 237 #define PCM_READ_U16_LE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000)) 238 #define _PCM_READ_U32_LE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000)) 239 #define PCM_READ_U16_BE(b8) \ 240 ((int32_t)((b8)[1] | ((int8_t)((b8)[0] ^ 0x80)) << 8)) 241 #define _PCM_READ_U32_BE(b8) \ 242 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \ 243 ((int8_t)((b8)[0] ^ 0x80)) << 24)) 244 245 #define PCM_WRITE_U16_LE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000 246 #define _PCM_WRITE_U32_LE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000 247 #define PCM_WRITE_U16_BE(bb8, vval) do { \ 248 int32_t val = (vval); \ 249 uint8_t *b8 = (bb8); \ 250 b8[1] = val; \ 251 b8[0] = (val >> 8) ^ 0x80; \ 252 } while(0) 253 #define _PCM_WRITE_U32_BE(bb8, vval) do { \ 254 int32_t val = (vval); \ 255 uint8_t *b8 = (bb8); \ 256 b8[3] = val; \ 257 b8[2] = val >> 8; \ 258 b8[1] = val >> 16; \ 259 b8[0] = (val >> 24) ^ 0x80; \ 260 } while(0) 261 #else /* !LITTLE_ENDIAN */ 262 #define PCM_READ_S16_LE(b8) \ 263 ((int32_t)((b8)[0] | ((int8_t)((b8)[1])) << 8)) 264 #define _PCM_READ_S32_LE(b8) \ 265 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \ 266 ((int8_t)((b8)[3])) << 24)) 267 #define PCM_READ_S16_BE(b8) *((int16_t *)(b8)) 268 #define _PCM_READ_S32_BE(b8) *((int32_t *)(b8)) 269 270 #define PCM_WRITE_S16_LE(bb8, vval) do { \ 271 int32_t val = (vval); \ 272 uint8_t *b8 = (bb8); \ 273 b8[0] = val; \ 274 b8[1] = val >> 8; \ 275 } while(0) 276 #define _PCM_WRITE_S32_LE(bb8, vval) do { \ 277 int32_t val = (vval); \ 278 uint8_t *b8 = (bb8); \ 279 b8[0] = val; \ 280 b8[1] = val >> 8; \ 281 b8[2] = val >> 16; \ 282 b8[3] = val >> 24; \ 283 } while(0) 284 #define PCM_WRITE_S16_BE(b8, val) *((int16_t *)(b8)) = (val) 285 #define _PCM_WRITE_S32_BE(b8, val) *((int32_t *)(b8)) = (val) 286 287 #define PCM_READ_U16_LE(b8) \ 288 ((int32_t)((b8)[0] | ((int8_t)((b8)[1] ^ 0x80)) << 8)) 289 #define _PCM_READ_U32_LE(b8) \ 290 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \ 291 ((int8_t)((b8)[3] ^ 0x80)) << 24)) 292 #define PCM_READ_U16_BE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000)) 293 #define _PCM_READ_U32_BE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000)) 294 295 #define PCM_WRITE_U16_LE(bb8, vval) do { \ 296 int32_t val = (vval); \ 297 uint8_t *b8 = (bb8); \ 298 b8[0] = val; \ 299 b8[1] = (val >> 8) ^ 0x80; \ 300 } while(0) 301 #define _PCM_WRITE_U32_LE(bb8, vval) do { \ 302 int32_t val = (vval); \ 303 uint8_t *b8 = (bb8); \ 304 b8[0] = val; \ 305 b8[1] = val >> 8; \ 306 b8[2] = val >> 16; \ 307 b8[3] = (val >> 24) ^ 0x80; \ 308 } while(0) 309 #define PCM_WRITE_U16_BE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000 310 #define _PCM_WRITE_U32_BE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000 311 #endif 312 313 #define PCM_READ_S24_LE(b8) \ 314 ((int32_t)((b8)[0] | (b8)[1] << 8 | ((int8_t)((b8)[2])) << 16)) 315 #define PCM_READ_S24_BE(b8) \ 316 ((int32_t)((b8)[2] | (b8)[1] << 8 | ((int8_t)((b8)[0])) << 16)) 317 318 #define PCM_WRITE_S24_LE(bb8, vval) do { \ 319 int32_t val = (vval); \ 320 uint8_t *b8 = (bb8); \ 321 b8[0] = val; \ 322 b8[1] = val >> 8; \ 323 b8[2] = val >> 16; \ 324 } while(0) 325 #define PCM_WRITE_S24_BE(bb8, vval) do { \ 326 int32_t val = (vval); \ 327 uint8_t *b8 = (bb8); \ 328 b8[2] = val; \ 329 b8[1] = val >> 8; \ 330 b8[0] = val >> 16; \ 331 } while(0) 332 333 #define PCM_READ_U24_LE(b8) \ 334 ((int32_t)((b8)[0] | (b8)[1] << 8 | \ 335 ((int8_t)((b8)[2] ^ 0x80)) << 16)) 336 #define PCM_READ_U24_BE(b8) \ 337 ((int32_t)((b8)[2] | (b8)[1] << 8 | \ 338 ((int8_t)((b8)[0] ^ 0x80)) << 16)) 339 340 #define PCM_WRITE_U24_LE(bb8, vval) do { \ 341 int32_t val = (vval); \ 342 uint8_t *b8 = (bb8); \ 343 b8[0] = val; \ 344 b8[1] = val >> 8; \ 345 b8[2] = (val >> 16) ^ 0x80; \ 346 } while(0) 347 #define PCM_WRITE_U24_BE(bb8, vval) do { \ 348 int32_t val = (vval); \ 349 uint8_t *b8 = (bb8); \ 350 b8[2] = val; \ 351 b8[1] = val >> 8; \ 352 b8[0] = (val >> 16) ^ 0x80; \ 353 } while(0) 354 355 #ifdef PCM_USE_64BIT_ARITH 356 #define PCM_READ_S32_LE(b8) _PCM_READ_S32_LE(b8) 357 #define PCM_READ_S32_BE(b8) _PCM_READ_S32_BE(b8) 358 #define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, val) 359 #define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, val) 360 361 #define PCM_READ_U32_LE(b8) _PCM_READ_U32_LE(b8) 362 #define PCM_READ_U32_BE(b8) _PCM_READ_U32_BE(b8) 363 #define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, val) 364 #define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, val) 365 #else /* !PCM_USE_64BIT_ARITH */ 366 /* 367 * 24bit integer ?!? This is quite unfortunate, eh? Get the fact straight: 368 * Dynamic range for: 369 * 1) Human =~ 140db 370 * 2) 16bit = 96db (close enough) 371 * 3) 24bit = 144db (perfect) 372 * 4) 32bit = 196db (way too much) 373 * 5) Bugs Bunny = Gazillion!@%$Erbzzztt-EINVAL db 374 * Since we're not Bugs Bunny ..uh..err.. avoiding 64bit arithmetic, 24bit 375 * is pretty much sufficient for our signed integer processing. 376 */ 377 #define PCM_READ_S32_LE(b8) (_PCM_READ_S32_LE(b8) >> PCM_FXSHIFT) 378 #define PCM_READ_S32_BE(b8) (_PCM_READ_S32_BE(b8) >> PCM_FXSHIFT) 379 #define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, (val) << PCM_FXSHIFT) 380 #define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, (val) << PCM_FXSHIFT) 381 382 #define PCM_READ_U32_LE(b8) (_PCM_READ_U32_LE(b8) >> PCM_FXSHIFT) 383 #define PCM_READ_U32_BE(b8) (_PCM_READ_U32_BE(b8) >> PCM_FXSHIFT) 384 #define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, (val) << PCM_FXSHIFT) 385 #define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, (val) << PCM_FXSHIFT) 386 #endif 387 388 /* 389 * 8bit sample is pretty much useless since it doesn't provide 390 * sufficient dynamic range throughout our filtering process. 391 * For the sake of completeness, declare it anyway. 392 */ 393 #define PCM_READ_S8(b8) *((int8_t *)(b8)) 394 #define PCM_READ_S8_NE(b8) PCM_READ_S8(b8) 395 #define PCM_READ_U8(b8) ((int8_t)(*((uint8_t *)(b8)) ^ 0x80)) 396 #define PCM_READ_U8_NE(b8) PCM_READ_U8(b8) 397 398 #define PCM_WRITE_S8(b8, val) *((int8_t *)(b8)) = (val) 399 #define PCM_WRITE_S8_NE(b8, val) PCM_WRITE_S8(b8, val) 400 #define PCM_WRITE_U8(b8, val) *((uint8_t *)(b8)) = (val) ^ 0x80 401 #define PCM_WRITE_U8_NE(b8, val) PCM_WRITE_U8(b8, val) 402 403 #define PCM_CLAMP_S8(val) \ 404 (((val) > PCM_S8_MAX) ? PCM_S8_MAX : \ 405 (((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val))) 406 #define PCM_CLAMP_S16(val) \ 407 (((val) > PCM_S16_MAX) ? PCM_S16_MAX : \ 408 (((val) < PCM_S16_MIN) ? PCM_S16_MIN : (val))) 409 #define PCM_CLAMP_S24(val) \ 410 (((val) > PCM_S24_MAX) ? PCM_S24_MAX : \ 411 (((val) < PCM_S24_MIN) ? PCM_S24_MIN : (val))) 412 413 #ifdef PCM_USE_64BIT_ARITH 414 #define PCM_CLAMP_S32(val) \ 415 (((val) > PCM_S32_MAX) ? PCM_S32_MAX : \ 416 (((val) < PCM_S32_MIN) ? PCM_S32_MIN : (val))) 417 #else 418 #define PCM_CLAMP_S32(val) \ 419 (((val) > PCM_S24_MAX) ? PCM_S32_MAX : \ 420 (((val) < PCM_S24_MIN) ? PCM_S32_MIN : \ 421 ((val) << PCM_FXSHIFT))) 422 #endif 423 424 #define PCM_CLAMP_U8(val) PCM_CLAMP_S8(val) 425 #define PCM_CLAMP_U16(val) PCM_CLAMP_S16(val) 426 #define PCM_CLAMP_U24(val) PCM_CLAMP_S24(val) 427 #define PCM_CLAMP_U32(val) PCM_CLAMP_S32(val) 428 429 /* make figuring out what a format is easier. got AFMT_STEREO already */ 430 #define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 431 #define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE) 432 #define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 433 #define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8) 434 #define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \ 435 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 436 #define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \ 437 AFMT_S16_BE | AFMT_U16_BE) 438 439 struct pcm_channel *fkchan_setup(device_t dev); 440 int fkchan_kill(struct pcm_channel *c); 441 442 /* XXX Flawed definition. I'll fix it someday. */ 443 #define SND_MAXVCHANS PCMMAXCHAN 444 445 /* 446 * Minor numbers for the sound driver. 447 * 448 * Unfortunately Creative called the codec chip of SB as a DSP. For this 449 * reason the /dev/dsp is reserved for digitized audio use. There is a 450 * device for true DSP processors but it will be called something else. 451 * In v3.0 it's /dev/sndproc but this could be a temporary solution. 452 */ 453 454 #define SND_DEV_CTL 0 /* Control port /dev/mixer */ 455 #define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 456 #define SND_DEV_MIDIN 2 /* Raw midi access */ 457 #define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 458 #define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 459 #define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 460 #define SND_DEV_STATUS 6 /* /dev/sndstat */ 461 /* #7 not in use now. */ 462 #define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 463 #define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 464 #define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 465 #define SND_DEV_NORESET 10 466 #define SND_DEV_DSPHW 11 /* specific channel request */ 467 468 #define DSP_DEFAULT_SPEED 8000 469 470 #define ON 1 471 #define OFF 0 472 473 extern int pcm_veto_load; 474 extern int snd_unit; 475 extern int snd_maxautovchans; 476 extern int snd_verbose; 477 extern devclass_t pcm_devclass; 478 extern struct unrhdr *pcmsg_unrhdr; 479 480 /* 481 * some macros for debugging purposes 482 * DDB/DEB to enable/disable debugging stuff 483 * BVDDB to enable debugging when bootverbose 484 */ 485 #define BVDDB(x) if (bootverbose) x 486 487 #ifndef DEB 488 #define DEB(x) 489 #endif 490 491 SYSCTL_DECL(_hw_snd); 492 493 struct pcm_channel *pcm_getfakechan(struct snddev_info *d); 494 int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int chnum); 495 int pcm_chnrelease(struct pcm_channel *c); 496 int pcm_chnref(struct pcm_channel *c, int ref); 497 int pcm_inprog(struct snddev_info *d, int delta); 498 499 struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); 500 int pcm_chn_destroy(struct pcm_channel *ch); 501 int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 502 int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); 503 504 int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 505 unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz); 506 int pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 507 int pcm_unregister(device_t dev); 508 int pcm_setstatus(device_t dev, char *str); 509 u_int32_t pcm_getflags(device_t dev); 510 void pcm_setflags(device_t dev, u_int32_t val); 511 void *pcm_getdevinfo(device_t dev); 512 513 514 int snd_setup_intr(device_t dev, struct resource *res, int flags, 515 driver_intr_t hand, void *param, void **cookiep); 516 517 void *snd_mtxcreate(const char *desc, const char *type); 518 void snd_mtxfree(void *m); 519 void snd_mtxassert(void *m); 520 #define snd_mtxlock(m) mtx_lock(m) 521 #define snd_mtxunlock(m) mtx_unlock(m) 522 523 int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); 524 525 typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 526 int sndstat_acquire(void); 527 int sndstat_release(void); 528 int sndstat_register(device_t dev, char *str, sndstat_handler handler); 529 int sndstat_registerfile(char *str); 530 int sndstat_unregister(device_t dev); 531 int sndstat_unregisterfile(char *str); 532 533 #define SND_DECLARE_FILE(version) \ 534 _SND_DECLARE_FILE(__LINE__, version) 535 536 #define _SND_DECLARE_FILE(uniq, version) \ 537 __SND_DECLARE_FILE(uniq, version) 538 539 #define __SND_DECLARE_FILE(uniq, version) \ 540 static char sndstat_vinfo[] = version; \ 541 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ 542 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); 543 544 /* usage of flags in device config entry (config file) */ 545 #define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 546 #define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 547 548 /* ought to be made obsolete but still used by mss */ 549 #define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 550 #define DV_F_DEV_SHIFT 8 /* force device type/class */ 551 552 #define PCM_DEBUG_MTX 553 554 /* 555 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c 556 * so that the macro versions of pcm_{,un}lock can dereference them. 557 * we also have to do this now makedev() has gone away. 558 */ 559 560 struct snddev_channel { 561 SLIST_ENTRY(snddev_channel) link; 562 struct pcm_channel *channel; 563 int chan_num; 564 struct cdev *dsp_devt; 565 struct cdev *dspW_devt; 566 struct cdev *audio_devt; 567 struct cdev *dspHW_devt; 568 }; 569 570 struct snddev_info { 571 SLIST_HEAD(, snddev_channel) channels; 572 struct pcm_channel *fakechan; 573 unsigned devcount, playcount, reccount, vchancount; 574 unsigned flags; 575 int inprog; 576 unsigned int bufsz; 577 void *devinfo; 578 device_t dev; 579 char status[SND_STATUSLEN]; 580 struct mtx *lock; 581 struct cdev *mixer_dev; 582 583 }; 584 585 void sound_oss_sysinfo(oss_sysinfo *); 586 587 #ifdef PCM_DEBUG_MTX 588 #define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock) 589 #define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock) 590 #else 591 void pcm_lock(struct snddev_info *d); 592 void pcm_unlock(struct snddev_info *d); 593 #endif 594 595 #ifdef KLD_MODULE 596 #define PCM_KLDSTRING(a) ("kld " # a) 597 #else 598 #define PCM_KLDSTRING(a) "" 599 #endif 600 601 #endif /* _KERNEL */ 602 603 #endif /* _OS_H_ */ 604