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