sound.h (192921) | sound.h (193640) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org> | 2 * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org> 3 * Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org> |
3 * Copyright (c) 1995 Hannu Savolainen 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. --- 8 unchanged lines hidden (view full) --- 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 * | 4 * Copyright (c) 1995 Hannu Savolainen 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. --- 8 unchanged lines hidden (view full) --- 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * |
27 * $FreeBSD: head/sys/dev/sound/pcm/sound.h 192921 2009-05-27 18:17:58Z joel $ | 28 * $FreeBSD: head/sys/dev/sound/pcm/sound.h 193640 2009-06-07 19:12:08Z ariff $ |
28 */ 29 30/* 31 * first, include kernel header files. 32 */ 33 34#ifndef _OS_H_ 35#define _OS_H_ --- 24 unchanged lines hidden (view full) --- 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> | 29 */ 30 31/* 32 * first, include kernel header files. 33 */ 34 35#ifndef _OS_H_ 36#define _OS_H_ --- 24 unchanged lines hidden (view full) --- 61#include <sys/rman.h> 62#include <sys/limits.h> 63#include <sys/mman.h> 64#include <sys/poll.h> 65#include <sys/sbuf.h> 66#include <sys/soundcard.h> 67#include <sys/sysctl.h> 68#include <sys/kobj.h> |
69#ifdef SND_DEBUG 70#undef KOBJMETHOD 71#define KOBJMETHOD(NAME, FUNC) \ 72 { \ 73 &NAME##_desc, \ 74 (kobjop_t) ((FUNC != (NAME##_t *)NULL) ? FUNC : NULL) \ 75 } 76#endif 77#ifndef KOBJMETHOD_END 78#define KOBJMETHOD_END { NULL, NULL } 79#endif |
|
68#include <vm/vm.h> 69#include <vm/pmap.h> 70 | 80#include <vm/vm.h> 81#include <vm/pmap.h> 82 |
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 | 83#include <sys/lock.h> 84#include <sys/mutex.h> 85#include <sys/condvar.h> 86 |
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 | |
88struct pcm_channel; 89struct pcm_feeder; 90struct snd_dbuf; 91struct snd_mixer; 92 93#include <dev/sound/pcm/buffer.h> | 87struct pcm_channel; 88struct pcm_feeder; 89struct snd_dbuf; 90struct snd_mixer; 91 92#include <dev/sound/pcm/buffer.h> |
93#include <dev/sound/pcm/matrix.h> 94#include <dev/sound/pcm/matrix_map.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#include <dev/sound/clone.h> 99#include <dev/sound/unit.h> 100 | 95#include <dev/sound/pcm/channel.h> 96#include <dev/sound/pcm/feeder.h> 97#include <dev/sound/pcm/mixer.h> 98#include <dev/sound/pcm/dsp.h> 99#include <dev/sound/clone.h> 100#include <dev/sound/unit.h> 101 |
101#define PCM_SOFTC_SIZE 512 | 102#define PCM_SOFTC_SIZE (sizeof(struct snddev_info)) |
102 103#define SND_STATUSLEN 64 104 | 103 104#define SND_STATUSLEN 64 105 |
105#define SOUND_MODVER 2 | 106#define SOUND_MODVER 5 |
106 107#define SOUND_MINVER SOUND_MODVER 108#define SOUND_PREFVER SOUND_MODVER 109#define SOUND_MAXVER SOUND_MODVER 110 111/* 112 * We're abusing the fact that MAXMINOR still have enough room 113 * for our bit twiddling and nobody ever need 512 unique soundcards, --- 6 unchanged lines hidden (view full) --- 120#define PCMMAXCHAN (snd_max_c()) 121 122#define PCMMAXCLONE PCMMAXCHAN 123 124#define PCMUNIT(x) (snd_unit2u(dev2unit(x))) 125#define PCMDEV(x) (snd_unit2d(dev2unit(x))) 126#define PCMCHAN(x) (snd_unit2c(dev2unit(x))) 127 | 107 108#define SOUND_MINVER SOUND_MODVER 109#define SOUND_PREFVER SOUND_MODVER 110#define SOUND_MAXVER SOUND_MODVER 111 112/* 113 * We're abusing the fact that MAXMINOR still have enough room 114 * for our bit twiddling and nobody ever need 512 unique soundcards, --- 6 unchanged lines hidden (view full) --- 121#define PCMMAXCHAN (snd_max_c()) 122 123#define PCMMAXCLONE PCMMAXCHAN 124 125#define PCMUNIT(x) (snd_unit2u(dev2unit(x))) 126#define PCMDEV(x) (snd_unit2d(dev2unit(x))) 127#define PCMCHAN(x) (snd_unit2c(dev2unit(x))) 128 |
129/* XXX unit2minor compat */ 130#if __FreeBSD_version >= 800062 131#define PCMMINOR(x) (x) 132#else 133#define PCMMINOR(x) unit2minor(x) 134#endif 135 |
|
128/* 129 * By design, limit possible channels for each direction. 130 */ 131#define SND_MAXHWCHAN 256 132#define SND_MAXVCHANS SND_MAXHWCHAN 133 134#define SD_F_SIMPLEX 0x00000001 135#define SD_F_AUTOVCHAN 0x00000002 136#define SD_F_SOFTPCMVOL 0x00000004 | 136/* 137 * By design, limit possible channels for each direction. 138 */ 139#define SND_MAXHWCHAN 256 140#define SND_MAXVCHANS SND_MAXHWCHAN 141 142#define SD_F_SIMPLEX 0x00000001 143#define SD_F_AUTOVCHAN 0x00000002 144#define SD_F_SOFTPCMVOL 0x00000004 |
145/* 146 * Obsolete due to better matrixing 147 */ 148#if 0 |
|
137#define SD_F_PSWAPLR 0x00000008 138#define SD_F_RSWAPLR 0x00000010 | 149#define SD_F_PSWAPLR 0x00000008 150#define SD_F_RSWAPLR 0x00000010 |
139#define SD_F_DYING 0x00000020 140#define SD_F_SUICIDE 0x00000040 141#define SD_F_BUSY 0x00000080 142#define SD_F_MPSAFE 0x00000100 143#define SD_F_REGISTERED 0x00000200 | 151#endif 152#define SD_F_DYING 0x00000008 153#define SD_F_SUICIDE 0x00000010 154#define SD_F_BUSY 0x00000020 155#define SD_F_MPSAFE 0x00000040 156#define SD_F_REGISTERED 0x00000080 157#define SD_F_BITPERFECT 0x00000100 158#define SD_F_VPC 0x00000200 /* volume-per-channel */ 159#define SD_F_EQ 0x00000400 /* EQ */ 160#define SD_F_EQ_ENABLED 0x00000800 /* EQ enabled */ 161#define SD_F_EQ_BYPASSED 0x00001000 /* EQ bypassed */ 162#define SD_F_EQ_PC 0x00002000 /* EQ per-channel */ |
144 | 163 |
164#define SD_F_EQ_DEFAULT (SD_F_EQ | SD_F_EQ_ENABLED) 165#define SD_F_EQ_MASK (SD_F_EQ | SD_F_EQ_ENABLED | \ 166 SD_F_EQ_BYPASSED | SD_F_EQ_PC) 167 |
|
145#define SD_F_PRIO_RD 0x10000000 146#define SD_F_PRIO_WR 0x20000000 147#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 148#define SD_F_DIR_SET 0x40000000 149#define SD_F_TRANSIENT 0xf0000000 150 | 168#define SD_F_PRIO_RD 0x10000000 169#define SD_F_PRIO_WR 0x20000000 170#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 171#define SD_F_DIR_SET 0x40000000 172#define SD_F_TRANSIENT 0xf0000000 173 |
174#define SD_F_BITS "\020" \ 175 "\001SIMPLEX" \ 176 "\002AUTOVCHAN" \ 177 "\003SOFTPCMVOL" \ 178 "\004DYING" \ 179 "\005SUICIDE" \ 180 "\006BUSY" \ 181 "\007MPSAFE" \ 182 "\010REGISTERED" \ 183 "\011BITPERFECT" \ 184 "\012VPC" \ 185 "\013EQ" \ 186 "\014EQ_ENABLED" \ 187 "\015EQ_BYPASSED" \ 188 "\016EQ_PC" \ 189 "\035PRIO_RD" \ 190 "\036PRIO_WR" \ 191 "\037DIR_SET" 192 |
|
151#define PCM_ALIVE(x) ((x) != NULL && (x)->lock != NULL && \ 152 !((x)->flags & SD_F_DYING)) 153#define PCM_REGISTERED(x) (PCM_ALIVE(x) && \ 154 ((x)->flags & SD_F_REGISTERED)) 155 156/* many variables should be reduced to a range. Here define a macro */ 157#define RANGE(var, low, high) (var) = \ 158 (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 159#define DSP_BUFFSIZE (8192) 160 | 193#define PCM_ALIVE(x) ((x) != NULL && (x)->lock != NULL && \ 194 !((x)->flags & SD_F_DYING)) 195#define PCM_REGISTERED(x) (PCM_ALIVE(x) && \ 196 ((x)->flags & SD_F_REGISTERED)) 197 198/* many variables should be reduced to a range. Here define a macro */ 199#define RANGE(var, low, high) (var) = \ 200 (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 201#define DSP_BUFFSIZE (8192) 202 |
161/* 162 * Macros for reading/writing PCM sample / int values from bytes array. 163 * Since every process is done using signed integer (and to make our life 164 * less miserable), unsigned sample will be converted to its signed 165 * counterpart and restored during writing back. To avoid overflow, 166 * we truncate 32bit (and only 32bit) samples down to 24bit (see below 167 * for the reason), unless PCM_USE_64BIT_ARITH is defined. 168 */ | 203/* make figuring out what a format is easier. got AFMT_STEREO already */ 204#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 205#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE) 206#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 207#define AFMT_G711 (AFMT_MU_LAW | AFMT_A_LAW) 208#define AFMT_8BIT (AFMT_G711 | AFMT_U8 | AFMT_S8) 209#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \ 210 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 211#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \ 212 AFMT_S16_BE | AFMT_U16_BE) |
169 | 213 |
170/* 171 * Automatically turn on 64bit arithmetic on suitable archs 172 * (amd64 64bit, ia64, etc..) for wider 32bit samples / integer processing. 173 */ 174#if LONG_BIT >= 64 175#undef PCM_USE_64BIT_ARITH 176#define PCM_USE_64BIT_ARITH 1 177#else 178#if 0 179#undef PCM_USE_64BIT_ARITH 180#define PCM_USE_64BIT_ARITH 1 181#endif 182#endif | 214#define AFMT_CONVERTIBLE (AFMT_8BIT | AFMT_16BIT | AFMT_24BIT | \ 215 AFMT_32BIT) |
183 | 216 |
184#ifdef PCM_USE_64BIT_ARITH 185typedef int64_t intpcm_t; 186#else 187typedef int32_t intpcm_t; 188#endif | 217/* Supported vchan mixing formats */ 218#define AFMT_VCHAN (AFMT_CONVERTIBLE & ~AFMT_G711) |
189 | 219 |
190/* 32bit fixed point shift */ 191#define PCM_FXSHIFT 8 | 220#define AFMT_PASSTHROUGH AFMT_AC3 221#define AFMT_PASSTHROUGH_RATE 48000 222#define AFMT_PASSTHROUGH_CHANNEL 2 223#define AFMT_PASSTHROUGH_EXTCHANNEL 0 |
192 | 224 |
193#define PCM_S8_MAX 0x7f 194#define PCM_S8_MIN -0x80 195#define PCM_S16_MAX 0x7fff 196#define PCM_S16_MIN -0x8000 197#define PCM_S24_MAX 0x7fffff 198#define PCM_S24_MIN -0x800000 199#ifdef PCM_USE_64BIT_ARITH 200#if LONG_BIT >= 64 201#define PCM_S32_MAX 0x7fffffffL 202#define PCM_S32_MIN -0x80000000L 203#else 204#define PCM_S32_MAX 0x7fffffffLL 205#define PCM_S32_MIN -0x80000000LL 206#endif 207#else 208#define PCM_S32_MAX 0x7fffffff 209#define PCM_S32_MIN (-0x7fffffff - 1) 210#endif | 225/* 226 * We're simply using unused, contiguous bits from various AFMT_ definitions. 227 * ~(0xb00ff7ff) 228 */ 229#define AFMT_ENCODING_MASK 0xf00fffff 230#define AFMT_CHANNEL_MASK 0x01f00000 231#define AFMT_CHANNEL_SHIFT 20 232#define AFMT_EXTCHANNEL_MASK 0x0e000000 233#define AFMT_EXTCHANNEL_SHIFT 25 |
211 | 234 |
212/* Bytes-per-sample definition */ 213#define PCM_8_BPS 1 214#define PCM_16_BPS 2 215#define PCM_24_BPS 3 216#define PCM_32_BPS 4 | 235#define AFMT_ENCODING(v) ((v) & AFMT_ENCODING_MASK) |
217 | 236 |
218#if BYTE_ORDER == LITTLE_ENDIAN 219#define PCM_READ_S16_LE(b8) *((int16_t *)(b8)) 220#define _PCM_READ_S32_LE(b8) *((int32_t *)(b8)) 221#define PCM_READ_S16_BE(b8) \ 222 ((int32_t)((b8)[1] | ((int8_t)((b8)[0])) << 8)) 223#define _PCM_READ_S32_BE(b8) \ 224 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \ 225 ((int8_t)((b8)[0])) << 24)) | 237#define AFMT_EXTCHANNEL(v) (((v) & AFMT_EXTCHANNEL_MASK) >> \ 238 AFMT_EXTCHANNEL_SHIFT) |
226 | 239 |
227#define PCM_WRITE_S16_LE(b8, val) *((int16_t *)(b8)) = (val) 228#define _PCM_WRITE_S32_LE(b8, val) *((int32_t *)(b8)) = (val) 229#define PCM_WRITE_S16_BE(bb8, vval) do { \ 230 int32_t val = (vval); \ 231 uint8_t *b8 = (bb8); \ 232 b8[1] = val; \ 233 b8[0] = val >> 8; \ 234 } while(0) 235#define _PCM_WRITE_S32_BE(bb8, vval) do { \ 236 int32_t val = (vval); \ 237 uint8_t *b8 = (bb8); \ 238 b8[3] = val; \ 239 b8[2] = val >> 8; \ 240 b8[1] = val >> 16; \ 241 b8[0] = val >> 24; \ 242 } while(0) | 240#define AFMT_CHANNEL(v) (((v) & AFMT_CHANNEL_MASK) >> \ 241 AFMT_CHANNEL_SHIFT) |
243 | 242 |
244#define PCM_READ_U16_LE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000)) 245#define _PCM_READ_U32_LE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000)) 246#define PCM_READ_U16_BE(b8) \ 247 ((int32_t)((b8)[1] | ((int8_t)((b8)[0] ^ 0x80)) << 8)) 248#define _PCM_READ_U32_BE(b8) \ 249 ((int32_t)((b8)[3] | (b8)[2] << 8 | (b8)[1] << 16 | \ 250 ((int8_t)((b8)[0] ^ 0x80)) << 24)) | 243#define AFMT_BIT(v) (((v) & AFMT_32BIT) ? 32 : \ 244 (((v) & AFMT_24BIT) ? 24 : \ 245 ((((v) & AFMT_16BIT) || \ 246 ((v) & AFMT_PASSTHROUGH)) ? 16 : 8))) |
251 | 247 |
252#define PCM_WRITE_U16_LE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000 253#define _PCM_WRITE_U32_LE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000 254#define PCM_WRITE_U16_BE(bb8, vval) do { \ 255 int32_t val = (vval); \ 256 uint8_t *b8 = (bb8); \ 257 b8[1] = val; \ 258 b8[0] = (val >> 8) ^ 0x80; \ 259 } while(0) 260#define _PCM_WRITE_U32_BE(bb8, vval) do { \ 261 int32_t val = (vval); \ 262 uint8_t *b8 = (bb8); \ 263 b8[3] = val; \ 264 b8[2] = val >> 8; \ 265 b8[1] = val >> 16; \ 266 b8[0] = (val >> 24) ^ 0x80; \ 267 } while(0) 268#else /* !LITTLE_ENDIAN */ 269#define PCM_READ_S16_LE(b8) \ 270 ((int32_t)((b8)[0] | ((int8_t)((b8)[1])) << 8)) 271#define _PCM_READ_S32_LE(b8) \ 272 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \ 273 ((int8_t)((b8)[3])) << 24)) 274#define PCM_READ_S16_BE(b8) *((int16_t *)(b8)) 275#define _PCM_READ_S32_BE(b8) *((int32_t *)(b8)) | 248#define AFMT_BPS(v) (AFMT_BIT(v) >> 3) 249#define AFMT_ALIGN(v) (AFMT_BPS(v) * AFMT_CHANNEL(v)) |
276 | 250 |
277#define PCM_WRITE_S16_LE(bb8, vval) do { \ 278 int32_t val = (vval); \ 279 uint8_t *b8 = (bb8); \ 280 b8[0] = val; \ 281 b8[1] = val >> 8; \ 282 } while(0) 283#define _PCM_WRITE_S32_LE(bb8, vval) do { \ 284 int32_t val = (vval); \ 285 uint8_t *b8 = (bb8); \ 286 b8[0] = val; \ 287 b8[1] = val >> 8; \ 288 b8[2] = val >> 16; \ 289 b8[3] = val >> 24; \ 290 } while(0) 291#define PCM_WRITE_S16_BE(b8, val) *((int16_t *)(b8)) = (val) 292#define _PCM_WRITE_S32_BE(b8, val) *((int32_t *)(b8)) = (val) | 251#define SND_FORMAT(f, c, e) (AFMT_ENCODING(f) | \ 252 (((c) << AFMT_CHANNEL_SHIFT) & \ 253 AFMT_CHANNEL_MASK) | \ 254 (((e) << AFMT_EXTCHANNEL_SHIFT) & \ 255 AFMT_EXTCHANNEL_MASK)) |
293 | 256 |
294#define PCM_READ_U16_LE(b8) \ 295 ((int32_t)((b8)[0] | ((int8_t)((b8)[1] ^ 0x80)) << 8)) 296#define _PCM_READ_U32_LE(b8) \ 297 ((int32_t)((b8)[0] | (b8)[1] << 8 | (b8)[2] << 16 | \ 298 ((int8_t)((b8)[3] ^ 0x80)) << 24)) 299#define PCM_READ_U16_BE(b8) ((int16_t)(*((uint16_t *)(b8)) ^ 0x8000)) 300#define _PCM_READ_U32_BE(b8) ((int32_t)(*((uint32_t *)(b8)) ^ 0x80000000)) | 257#define AFMT_U8_NE AFMT_U8 258#define AFMT_S8_NE AFMT_S8 |
301 | 259 |
302#define PCM_WRITE_U16_LE(bb8, vval) do { \ 303 int32_t val = (vval); \ 304 uint8_t *b8 = (bb8); \ 305 b8[0] = val; \ 306 b8[1] = (val >> 8) ^ 0x80; \ 307 } while(0) 308#define _PCM_WRITE_U32_LE(bb8, vval) do { \ 309 int32_t val = (vval); \ 310 uint8_t *b8 = (bb8); \ 311 b8[0] = val; \ 312 b8[1] = val >> 8; \ 313 b8[2] = val >> 16; \ 314 b8[3] = (val >> 24) ^ 0x80; \ 315 } while(0) 316#define PCM_WRITE_U16_BE(b8, val) *((uint16_t *)(b8)) = (val) ^ 0x8000 317#define _PCM_WRITE_U32_BE(b8, val) *((uint32_t *)(b8)) = (val) ^ 0x80000000 318#endif | 260#undef AFMT_S16_NE |
319 | 261 |
320#define PCM_READ_S24_LE(b8) \ 321 ((int32_t)((b8)[0] | (b8)[1] << 8 | ((int8_t)((b8)[2])) << 16)) 322#define PCM_READ_S24_BE(b8) \ 323 ((int32_t)((b8)[2] | (b8)[1] << 8 | ((int8_t)((b8)[0])) << 16)) 324 325#define PCM_WRITE_S24_LE(bb8, vval) do { \ 326 int32_t val = (vval); \ 327 uint8_t *b8 = (bb8); \ 328 b8[0] = val; \ 329 b8[1] = val >> 8; \ 330 b8[2] = val >> 16; \ 331 } while(0) 332#define PCM_WRITE_S24_BE(bb8, vval) do { \ 333 int32_t val = (vval); \ 334 uint8_t *b8 = (bb8); \ 335 b8[2] = val; \ 336 b8[1] = val >> 8; \ 337 b8[0] = val >> 16; \ 338 } while(0) 339 340#define PCM_READ_U24_LE(b8) \ 341 ((int32_t)((b8)[0] | (b8)[1] << 8 | \ 342 ((int8_t)((b8)[2] ^ 0x80)) << 16)) 343#define PCM_READ_U24_BE(b8) \ 344 ((int32_t)((b8)[2] | (b8)[1] << 8 | \ 345 ((int8_t)((b8)[0] ^ 0x80)) << 16)) 346 347#define PCM_WRITE_U24_LE(bb8, vval) do { \ 348 int32_t val = (vval); \ 349 uint8_t *b8 = (bb8); \ 350 b8[0] = val; \ 351 b8[1] = val >> 8; \ 352 b8[2] = (val >> 16) ^ 0x80; \ 353 } while(0) 354#define PCM_WRITE_U24_BE(bb8, vval) do { \ 355 int32_t val = (vval); \ 356 uint8_t *b8 = (bb8); \ 357 b8[2] = val; \ 358 b8[1] = val >> 8; \ 359 b8[0] = (val >> 16) ^ 0x80; \ 360 } while(0) 361 362#ifdef PCM_USE_64BIT_ARITH 363#define PCM_READ_S32_LE(b8) _PCM_READ_S32_LE(b8) 364#define PCM_READ_S32_BE(b8) _PCM_READ_S32_BE(b8) 365#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, val) 366#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, val) 367 368#define PCM_READ_U32_LE(b8) _PCM_READ_U32_LE(b8) 369#define PCM_READ_U32_BE(b8) _PCM_READ_U32_BE(b8) 370#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, val) 371#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, val) 372#else /* !PCM_USE_64BIT_ARITH */ 373/* 374 * 24bit integer ?!? This is quite unfortunate, eh? Get the fact straight: 375 * Dynamic range for: 376 * 1) Human =~ 140db 377 * 2) 16bit = 96db (close enough) 378 * 3) 24bit = 144db (perfect) 379 * 4) 32bit = 196db (way too much) 380 * 5) Bugs Bunny = Gazillion!@%$Erbzzztt-EINVAL db 381 * Since we're not Bugs Bunny ..uh..err.. avoiding 64bit arithmetic, 24bit 382 * is pretty much sufficient for our signed integer processing. 383 */ 384#define PCM_READ_S32_LE(b8) (_PCM_READ_S32_LE(b8) >> PCM_FXSHIFT) 385#define PCM_READ_S32_BE(b8) (_PCM_READ_S32_BE(b8) >> PCM_FXSHIFT) 386#define PCM_WRITE_S32_LE(b8, val) _PCM_WRITE_S32_LE(b8, (val) << PCM_FXSHIFT) 387#define PCM_WRITE_S32_BE(b8, val) _PCM_WRITE_S32_BE(b8, (val) << PCM_FXSHIFT) 388 389#define PCM_READ_U32_LE(b8) (_PCM_READ_U32_LE(b8) >> PCM_FXSHIFT) 390#define PCM_READ_U32_BE(b8) (_PCM_READ_U32_BE(b8) >> PCM_FXSHIFT) 391#define PCM_WRITE_U32_LE(b8, val) _PCM_WRITE_U32_LE(b8, (val) << PCM_FXSHIFT) 392#define PCM_WRITE_U32_BE(b8, val) _PCM_WRITE_U32_BE(b8, (val) << PCM_FXSHIFT) 393#endif 394 395/* 396 * 8bit sample is pretty much useless since it doesn't provide 397 * sufficient dynamic range throughout our filtering process. 398 * For the sake of completeness, declare it anyway. 399 */ 400#define PCM_READ_S8(b8) *((int8_t *)(b8)) 401#define PCM_READ_S8_NE(b8) PCM_READ_S8(b8) 402#define PCM_READ_U8(b8) ((int8_t)(*((uint8_t *)(b8)) ^ 0x80)) 403#define PCM_READ_U8_NE(b8) PCM_READ_U8(b8) 404 405#define PCM_WRITE_S8(b8, val) *((int8_t *)(b8)) = (val) 406#define PCM_WRITE_S8_NE(b8, val) PCM_WRITE_S8(b8, val) 407#define PCM_WRITE_U8(b8, val) *((uint8_t *)(b8)) = (val) ^ 0x80 408#define PCM_WRITE_U8_NE(b8, val) PCM_WRITE_U8(b8, val) 409 410#define PCM_CLAMP_S8(val) \ 411 (((val) > PCM_S8_MAX) ? PCM_S8_MAX : \ 412 (((val) < PCM_S8_MIN) ? PCM_S8_MIN : (val))) 413#define PCM_CLAMP_S16(val) \ 414 (((val) > PCM_S16_MAX) ? PCM_S16_MAX : \ 415 (((val) < PCM_S16_MIN) ? PCM_S16_MIN : (val))) 416#define PCM_CLAMP_S24(val) \ 417 (((val) > PCM_S24_MAX) ? PCM_S24_MAX : \ 418 (((val) < PCM_S24_MIN) ? PCM_S24_MIN : (val))) 419 420#ifdef PCM_USE_64BIT_ARITH 421#define PCM_CLAMP_S32(val) \ 422 (((val) > PCM_S32_MAX) ? PCM_S32_MAX : \ 423 (((val) < PCM_S32_MIN) ? PCM_S32_MIN : (val))) | 262#if BYTE_ORDER == LITTLE_ENDIAN 263#define AFMT_S16_NE AFMT_S16_LE 264#define AFMT_S24_NE AFMT_S24_LE 265#define AFMT_S32_NE AFMT_S32_LE 266#define AFMT_U16_NE AFMT_U16_LE 267#define AFMT_U24_NE AFMT_U24_LE 268#define AFMT_U32_NE AFMT_U32_LE 269#define AFMT_S16_OE AFMT_S16_BE 270#define AFMT_S24_OE AFMT_S24_BE 271#define AFMT_S32_OE AFMT_S32_BE 272#define AFMT_U16_OE AFMT_U16_BE 273#define AFMT_U24_OE AFMT_U24_BE 274#define AFMT_U32_OE AFMT_U32_BE |
424#else | 275#else |
425#define PCM_CLAMP_S32(val) \ 426 (((val) > PCM_S24_MAX) ? PCM_S32_MAX : \ 427 (((val) < PCM_S24_MIN) ? PCM_S32_MIN : \ 428 ((val) << PCM_FXSHIFT))) | 276#define AFMT_S16_OE AFMT_S16_LE 277#define AFMT_S24_OE AFMT_S24_LE 278#define AFMT_S32_OE AFMT_S32_LE 279#define AFMT_U16_OE AFMT_U16_LE 280#define AFMT_U24_OE AFMT_U24_LE 281#define AFMT_U32_OE AFMT_U32_LE 282#define AFMT_S16_NE AFMT_S16_BE 283#define AFMT_S24_NE AFMT_S24_BE 284#define AFMT_S32_NE AFMT_S32_BE 285#define AFMT_U16_NE AFMT_U16_BE 286#define AFMT_U24_NE AFMT_U24_BE 287#define AFMT_U32_NE AFMT_U32_BE |
429#endif 430 | 288#endif 289 |
431#define PCM_CLAMP_U8(val) PCM_CLAMP_S8(val) 432#define PCM_CLAMP_U16(val) PCM_CLAMP_S16(val) 433#define PCM_CLAMP_U24(val) PCM_CLAMP_S24(val) 434#define PCM_CLAMP_U32(val) PCM_CLAMP_S32(val) | 290#define AFMT_SIGNED_NE (AFMT_S8_NE | AFMT_S16_NE | AFMT_S24_NE | AFMT_S32_NE) |
435 | 291 |
436/* make figuring out what a format is easier. got AFMT_STEREO already */ 437#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 438#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE) 439#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 440#define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8) 441#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \ 442 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 443#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \ 444 AFMT_S16_BE | AFMT_U16_BE) | 292#define AFMT_NE (AFMT_SIGNED_NE | AFMT_U8_NE | AFMT_U16_NE | \ 293 AFMT_U24_NE | AFMT_U32_NE) |
445 | 294 |
446struct pcm_channel *fkchan_setup(device_t dev); 447int fkchan_kill(struct pcm_channel *c); 448 | |
449/* 450 * Minor numbers for the sound driver. 451 * 452 * Unfortunately Creative called the codec chip of SB as a DSP. For this 453 * reason the /dev/dsp is reserved for digitized audio use. There is a 454 * device for true DSP processors but it will be called something else. 455 * In v3.0 it's /dev/sndproc but this could be a temporary solution. 456 */ --- 13 unchanged lines hidden (view full) --- 470 471#define SND_DEV_DSPHW_PLAY 11 /* specific playback channel */ 472#define SND_DEV_DSPHW_VPLAY 12 /* specific virtual playback channel */ 473#define SND_DEV_DSPHW_REC 13 /* specific record channel */ 474#define SND_DEV_DSPHW_VREC 14 /* specific virtual record channel */ 475 476#define SND_DEV_DSPHW_CD 15 /* s16le/stereo 44100Hz CD */ 477 | 295/* 296 * Minor numbers for the sound driver. 297 * 298 * Unfortunately Creative called the codec chip of SB as a DSP. For this 299 * reason the /dev/dsp is reserved for digitized audio use. There is a 300 * device for true DSP processors but it will be called something else. 301 * In v3.0 it's /dev/sndproc but this could be a temporary solution. 302 */ --- 13 unchanged lines hidden (view full) --- 316 317#define SND_DEV_DSPHW_PLAY 11 /* specific playback channel */ 318#define SND_DEV_DSPHW_VPLAY 12 /* specific virtual playback channel */ 319#define SND_DEV_DSPHW_REC 13 /* specific record channel */ 320#define SND_DEV_DSPHW_VREC 14 /* specific virtual record channel */ 321 322#define SND_DEV_DSPHW_CD 15 /* s16le/stereo 44100Hz CD */ 323 |
478#define SND_DEV_DSP_MMAP 16 /* OSSv4 compatible /dev/dsp_mmap */ | 324/* 325 * OSSv4 compatible device. For now, it serve no purpose and 326 * the cloning itself will forward the request to ordinary /dev/dsp 327 * instead. 328 */ 329#define SND_DEV_DSP_MMAP 16 /* /dev/dsp_mmap */ 330#define SND_DEV_DSP_AC3 17 /* /dev/dsp_ac3 */ 331#define SND_DEV_DSP_MULTICH 18 /* /dev/dsp_multich */ 332#define SND_DEV_DSP_SPDIFOUT 19 /* /dev/dsp_spdifout */ 333#define SND_DEV_DSP_SPDIFIN 20 /* /dev/dsp_spdifin */ |
479 | 334 |
480#define SND_DEV_LAST SND_DEV_DSP_MMAP | 335#define SND_DEV_LAST SND_DEV_DSP_SPDIFIN |
481#define SND_DEV_MAX PCMMAXDEV 482 483#define DSP_DEFAULT_SPEED 8000 484 485#define ON 1 486#define OFF 0 487 488extern int pcm_veto_load; --- 11 unchanged lines hidden (view full) --- 500#define BVDDB(x) if (bootverbose) x 501 502#ifndef DEB 503#define DEB(x) 504#endif 505 506SYSCTL_DECL(_hw_snd); 507 | 336#define SND_DEV_MAX PCMMAXDEV 337 338#define DSP_DEFAULT_SPEED 8000 339 340#define ON 1 341#define OFF 0 342 343extern int pcm_veto_load; --- 11 unchanged lines hidden (view full) --- 355#define BVDDB(x) if (bootverbose) x 356 357#ifndef DEB 358#define DEB(x) 359#endif 360 361SYSCTL_DECL(_hw_snd); 362 |
508struct pcm_channel *pcm_getfakechan(struct snddev_info *d); 509int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int devunit); | 363int pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num); 364int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, 365 pid_t pid, char *comm, int devunit); |
510int pcm_chnrelease(struct pcm_channel *c); 511int pcm_chnref(struct pcm_channel *c, int ref); 512int pcm_inprog(struct snddev_info *d, int delta); 513 514struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo); 515int pcm_chn_destroy(struct pcm_channel *ch); 516int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 517int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); --- 12 unchanged lines hidden (view full) --- 530 driver_intr_t hand, void *param, void **cookiep); 531 532void *snd_mtxcreate(const char *desc, const char *type); 533void snd_mtxfree(void *m); 534void snd_mtxassert(void *m); 535#define snd_mtxlock(m) mtx_lock(m) 536#define snd_mtxunlock(m) mtx_unlock(m) 537 | 366int pcm_chnrelease(struct pcm_channel *c); 367int pcm_chnref(struct pcm_channel *c, int ref); 368int pcm_inprog(struct snddev_info *d, int delta); 369 370struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo); 371int pcm_chn_destroy(struct pcm_channel *ch); 372int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 373int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); --- 12 unchanged lines hidden (view full) --- 386 driver_intr_t hand, void *param, void **cookiep); 387 388void *snd_mtxcreate(const char *desc, const char *type); 389void snd_mtxfree(void *m); 390void snd_mtxassert(void *m); 391#define snd_mtxlock(m) mtx_lock(m) 392#define snd_mtxunlock(m) mtx_unlock(m) 393 |
538int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); 539 | |
540typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 541int sndstat_acquire(struct thread *td); 542int sndstat_release(struct thread *td); 543int sndstat_register(device_t dev, char *str, sndstat_handler handler); 544int sndstat_registerfile(char *str); 545int sndstat_unregister(device_t dev); 546int sndstat_unregisterfile(char *str); 547 --- 11 unchanged lines hidden (view full) --- 559/* usage of flags in device config entry (config file) */ 560#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 561#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 562 563/* ought to be made obsolete but still used by mss */ 564#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 565#define DV_F_DEV_SHIFT 8 /* force device type/class */ 566 | 394typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 395int sndstat_acquire(struct thread *td); 396int sndstat_release(struct thread *td); 397int sndstat_register(device_t dev, char *str, sndstat_handler handler); 398int sndstat_registerfile(char *str); 399int sndstat_unregister(device_t dev); 400int sndstat_unregisterfile(char *str); 401 --- 11 unchanged lines hidden (view full) --- 413/* usage of flags in device config entry (config file) */ 414#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 415#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 416 417/* ought to be made obsolete but still used by mss */ 418#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 419#define DV_F_DEV_SHIFT 8 /* force device type/class */ 420 |
567#define PCM_DEBUG_MTX 568 | |
569/* 570 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c 571 * so that the macro versions of pcm_{,un}lock can dereference them. 572 * we also have to do this now makedev() has gone away. 573 */ 574 575struct snddev_info { 576 struct { 577 struct { 578 SLIST_HEAD(, pcm_channel) head; 579 struct { 580 SLIST_HEAD(, pcm_channel) head; 581 } busy; | 421/* 422 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c 423 * so that the macro versions of pcm_{,un}lock can dereference them. 424 * we also have to do this now makedev() has gone away. 425 */ 426 427struct snddev_info { 428 struct { 429 struct { 430 SLIST_HEAD(, pcm_channel) head; 431 struct { 432 SLIST_HEAD(, pcm_channel) head; 433 } busy; |
434 struct { 435 SLIST_HEAD(, pcm_channel) head; 436 } opened; |
|
582 } pcm; 583 } channels; 584 TAILQ_HEAD(dsp_cdevinfo_linkhead, dsp_cdevinfo) dsp_cdevinfo_pool; 585 struct snd_clone *clones; | 437 } pcm; 438 } channels; 439 TAILQ_HEAD(dsp_cdevinfo_linkhead, dsp_cdevinfo) dsp_cdevinfo_pool; 440 struct snd_clone *clones; |
586 struct pcm_channel *fakechan; | |
587 unsigned devcount, playcount, reccount, pvchancount, rvchancount ; 588 unsigned flags; 589 int inprog; 590 unsigned int bufsz; 591 void *devinfo; 592 device_t dev; 593 char status[SND_STATUSLEN]; 594 struct mtx *lock; 595 struct cdev *mixer_dev; 596 uint32_t pvchanrate, pvchanformat; 597 uint32_t rvchanrate, rvchanformat; | 441 unsigned devcount, playcount, reccount, pvchancount, rvchancount ; 442 unsigned flags; 443 int inprog; 444 unsigned int bufsz; 445 void *devinfo; 446 device_t dev; 447 char status[SND_STATUSLEN]; 448 struct mtx *lock; 449 struct cdev *mixer_dev; 450 uint32_t pvchanrate, pvchanformat; 451 uint32_t rvchanrate, rvchanformat; |
452 int32_t eqpreamp; |
|
598 struct sysctl_ctx_list play_sysctl_ctx, rec_sysctl_ctx; 599 struct sysctl_oid *play_sysctl_tree, *rec_sysctl_tree; 600 struct cv cv; 601}; 602 603void sound_oss_sysinfo(oss_sysinfo *); 604int sound_oss_card_info(oss_card_info *); 605 | 453 struct sysctl_ctx_list play_sysctl_ctx, rec_sysctl_ctx; 454 struct sysctl_oid *play_sysctl_tree, *rec_sysctl_tree; 455 struct cv cv; 456}; 457 458void sound_oss_sysinfo(oss_sysinfo *); 459int sound_oss_card_info(oss_card_info *); 460 |
606#ifdef PCM_DEBUG_MTX 607#define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock) 608#define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock) 609#else 610void pcm_lock(struct snddev_info *d); 611void pcm_unlock(struct snddev_info *d); 612#endif | 461#define PCM_LOCKOWNED(d) mtx_owned((d)->lock) 462#define PCM_LOCK(d) mtx_lock((d)->lock) 463#define PCM_UNLOCK(d) mtx_unlock((d)->lock) 464#define PCM_TRYLOCK(d) mtx_trylock((d)->lock) 465#define PCM_LOCKASSERT(d) mtx_assert((d)->lock, MA_OWNED) 466#define PCM_UNLOCKASSERT(d) mtx_assert((d)->lock, MA_NOTOWNED) |
613 614/* | 467 468/* |
615 * For PCM_CV_[WAIT | ACQUIRE | RELEASE], be sure to surround these 616 * with pcm_lock/unlock() sequence, or I'll come to gnaw upon you! | 469 * For PCM_[WAIT | ACQUIRE | RELEASE], be sure to surround these 470 * with PCM_LOCK/UNLOCK() sequence, or I'll come to gnaw upon you! |
617 */ 618#ifdef SND_DIAGNOSTIC 619#define PCM_WAIT(x) do { \ | 471 */ 472#ifdef SND_DIAGNOSTIC 473#define PCM_WAIT(x) do { \ |
620 if (mtx_owned((x)->lock) == 0) \ | 474 if (!PCM_LOCKOWNED(x)) \ |
621 panic("%s(%d): [PCM WAIT] Mutex not owned!", \ 622 __func__, __LINE__); \ 623 while ((x)->flags & SD_F_BUSY) { \ 624 if (snd_verbose > 3) \ 625 device_printf((x)->dev, \ 626 "%s(%d): [PCM WAIT] calling cv_wait().\n", \ 627 __func__, __LINE__); \ 628 cv_wait(&(x)->cv, (x)->lock); \ 629 } \ | 475 panic("%s(%d): [PCM WAIT] Mutex not owned!", \ 476 __func__, __LINE__); \ 477 while ((x)->flags & SD_F_BUSY) { \ 478 if (snd_verbose > 3) \ 479 device_printf((x)->dev, \ 480 "%s(%d): [PCM WAIT] calling cv_wait().\n", \ 481 __func__, __LINE__); \ 482 cv_wait(&(x)->cv, (x)->lock); \ 483 } \ |
630} while(0) | 484} while (0) |
631 632#define PCM_ACQUIRE(x) do { \ | 485 486#define PCM_ACQUIRE(x) do { \ |
633 if (mtx_owned((x)->lock) == 0) \ | 487 if (!PCM_LOCKOWNED(x)) \ |
634 panic("%s(%d): [PCM ACQUIRE] Mutex not owned!", \ 635 __func__, __LINE__); \ 636 if ((x)->flags & SD_F_BUSY) \ 637 panic("%s(%d): [PCM ACQUIRE] " \ 638 "Trying to acquire BUSY cv!", __func__, __LINE__); \ 639 (x)->flags |= SD_F_BUSY; \ | 488 panic("%s(%d): [PCM ACQUIRE] Mutex not owned!", \ 489 __func__, __LINE__); \ 490 if ((x)->flags & SD_F_BUSY) \ 491 panic("%s(%d): [PCM ACQUIRE] " \ 492 "Trying to acquire BUSY cv!", __func__, __LINE__); \ 493 (x)->flags |= SD_F_BUSY; \ |
640} while(0) | 494} while (0) |
641 642#define PCM_RELEASE(x) do { \ | 495 496#define PCM_RELEASE(x) do { \ |
643 if (mtx_owned((x)->lock) == 0) \ | 497 if (!PCM_LOCKOWNED(x)) \ |
644 panic("%s(%d): [PCM RELEASE] Mutex not owned!", \ 645 __func__, __LINE__); \ 646 if ((x)->flags & SD_F_BUSY) { \ 647 (x)->flags &= ~SD_F_BUSY; \ 648 if ((x)->cv.cv_waiters != 0) { \ 649 if ((x)->cv.cv_waiters > 1 && snd_verbose > 3) \ 650 device_printf((x)->dev, \ 651 "%s(%d): [PCM RELEASE] " \ 652 "cv_waiters=%d > 1!\n", \ 653 __func__, __LINE__, \ 654 (x)->cv.cv_waiters); \ 655 cv_broadcast(&(x)->cv); \ 656 } \ 657 } else \ 658 panic("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ 659 __func__, __LINE__); \ | 498 panic("%s(%d): [PCM RELEASE] Mutex not owned!", \ 499 __func__, __LINE__); \ 500 if ((x)->flags & SD_F_BUSY) { \ 501 (x)->flags &= ~SD_F_BUSY; \ 502 if ((x)->cv.cv_waiters != 0) { \ 503 if ((x)->cv.cv_waiters > 1 && snd_verbose > 3) \ 504 device_printf((x)->dev, \ 505 "%s(%d): [PCM RELEASE] " \ 506 "cv_waiters=%d > 1!\n", \ 507 __func__, __LINE__, \ 508 (x)->cv.cv_waiters); \ 509 cv_broadcast(&(x)->cv); \ 510 } \ 511 } else \ 512 panic("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ 513 __func__, __LINE__); \ |
660} while(0) | 514} while (0) |
661 662/* Quick version, for shorter path. */ 663#define PCM_ACQUIRE_QUICK(x) do { \ | 515 516/* Quick version, for shorter path. */ 517#define PCM_ACQUIRE_QUICK(x) do { \ |
664 if (mtx_owned((x)->lock) != 0) \ | 518 if (PCM_LOCKOWNED(x)) \ |
665 panic("%s(%d): [PCM ACQUIRE QUICK] Mutex owned!", \ 666 __func__, __LINE__); \ | 519 panic("%s(%d): [PCM ACQUIRE QUICK] Mutex owned!", \ 520 __func__, __LINE__); \ |
667 pcm_lock(x); \ | 521 PCM_LOCK(x); \ |
668 PCM_WAIT(x); \ 669 PCM_ACQUIRE(x); \ | 522 PCM_WAIT(x); \ 523 PCM_ACQUIRE(x); \ |
670 pcm_unlock(x); \ 671} while(0) | 524 PCM_UNLOCK(x); \ 525} while (0) |
672 673#define PCM_RELEASE_QUICK(x) do { \ | 526 527#define PCM_RELEASE_QUICK(x) do { \ |
674 if (mtx_owned((x)->lock) != 0) \ | 528 if (PCM_LOCKOWNED(x)) \ |
675 panic("%s(%d): [PCM RELEASE QUICK] Mutex owned!", \ 676 __func__, __LINE__); \ | 529 panic("%s(%d): [PCM RELEASE QUICK] Mutex owned!", \ 530 __func__, __LINE__); \ |
677 pcm_lock(x); \ | 531 PCM_LOCK(x); \ |
678 PCM_RELEASE(x); \ | 532 PCM_RELEASE(x); \ |
679 pcm_unlock(x); \ 680} while(0) | 533 PCM_UNLOCK(x); \ 534} while (0) |
681 682#define PCM_BUSYASSERT(x) do { \ 683 if (!((x) != NULL && ((x)->flags & SD_F_BUSY))) \ 684 panic("%s(%d): [PCM BUSYASSERT] " \ 685 "Failed, snddev_info=%p", __func__, __LINE__, x); \ | 535 536#define PCM_BUSYASSERT(x) do { \ 537 if (!((x) != NULL && ((x)->flags & SD_F_BUSY))) \ 538 panic("%s(%d): [PCM BUSYASSERT] " \ 539 "Failed, snddev_info=%p", __func__, __LINE__, x); \ |
686} while(0) | 540} while (0) |
687 688#define PCM_GIANT_ENTER(x) do { \ 689 int _pcm_giant = 0; \ | 541 542#define PCM_GIANT_ENTER(x) do { \ 543 int _pcm_giant = 0; \ |
690 if (mtx_owned((x)->lock) != 0) \ | 544 if (PCM_LOCKOWNED(x)) \ |
691 panic("%s(%d): [GIANT ENTER] PCM lock owned!", \ 692 __func__, __LINE__); \ 693 if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \ 694 device_printf((x)->dev, \ 695 "%s(%d): [GIANT ENTER] Giant owned!\n", \ 696 __func__, __LINE__); \ 697 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \ 698 do { \ 699 mtx_lock(&Giant); \ 700 _pcm_giant = 1; \ | 545 panic("%s(%d): [GIANT ENTER] PCM lock owned!", \ 546 __func__, __LINE__); \ 547 if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \ 548 device_printf((x)->dev, \ 549 "%s(%d): [GIANT ENTER] Giant owned!\n", \ 550 __func__, __LINE__); \ 551 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \ 552 do { \ 553 mtx_lock(&Giant); \ 554 _pcm_giant = 1; \ |
701 } while(0) | 555 } while (0) |
702 703#define PCM_GIANT_EXIT(x) do { \ | 556 557#define PCM_GIANT_EXIT(x) do { \ |
704 if (mtx_owned((x)->lock) != 0) \ | 558 if (PCM_LOCKOWNED(x)) \ |
705 panic("%s(%d): [GIANT EXIT] PCM lock owned!", \ 706 __func__, __LINE__); \ 707 if (!(_pcm_giant == 0 || _pcm_giant == 1)) \ 708 panic("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \ 709 __func__, __LINE__); \ 710 if ((x)->flags & SD_F_MPSAFE) { \ 711 if (_pcm_giant == 1) \ 712 panic("%s(%d): [GIANT EXIT] MPSAFE Giant?", \ --- 5 unchanged lines hidden (view full) --- 718 } \ 719 if (_pcm_giant != 0) { \ 720 if (mtx_owned(&Giant) == 0) \ 721 panic("%s(%d): [GIANT EXIT] Giant not owned!", \ 722 __func__, __LINE__); \ 723 _pcm_giant = 0; \ 724 mtx_unlock(&Giant); \ 725 } \ | 559 panic("%s(%d): [GIANT EXIT] PCM lock owned!", \ 560 __func__, __LINE__); \ 561 if (!(_pcm_giant == 0 || _pcm_giant == 1)) \ 562 panic("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \ 563 __func__, __LINE__); \ 564 if ((x)->flags & SD_F_MPSAFE) { \ 565 if (_pcm_giant == 1) \ 566 panic("%s(%d): [GIANT EXIT] MPSAFE Giant?", \ --- 5 unchanged lines hidden (view full) --- 572 } \ 573 if (_pcm_giant != 0) { \ 574 if (mtx_owned(&Giant) == 0) \ 575 panic("%s(%d): [GIANT EXIT] Giant not owned!", \ 576 __func__, __LINE__); \ 577 _pcm_giant = 0; \ 578 mtx_unlock(&Giant); \ 579 } \ |
726} while(0) | 580} while (0) |
727#else /* SND_DIAGNOSTIC */ 728#define PCM_WAIT(x) do { \ | 581#else /* SND_DIAGNOSTIC */ 582#define PCM_WAIT(x) do { \ |
729 mtx_assert((x)->lock, MA_OWNED); \ | 583 PCM_LOCKASSERT(x); \ |
730 while ((x)->flags & SD_F_BUSY) \ 731 cv_wait(&(x)->cv, (x)->lock); \ | 584 while ((x)->flags & SD_F_BUSY) \ 585 cv_wait(&(x)->cv, (x)->lock); \ |
732} while(0) | 586} while (0) |
733 734#define PCM_ACQUIRE(x) do { \ | 587 588#define PCM_ACQUIRE(x) do { \ |
735 mtx_assert((x)->lock, MA_OWNED); \ | 589 PCM_LOCKASSERT(x); \ |
736 KASSERT(!((x)->flags & SD_F_BUSY), \ 737 ("%s(%d): [PCM ACQUIRE] Trying to acquire BUSY cv!", \ 738 __func__, __LINE__)); \ 739 (x)->flags |= SD_F_BUSY; \ | 590 KASSERT(!((x)->flags & SD_F_BUSY), \ 591 ("%s(%d): [PCM ACQUIRE] Trying to acquire BUSY cv!", \ 592 __func__, __LINE__)); \ 593 (x)->flags |= SD_F_BUSY; \ |
740} while(0) | 594} while (0) |
741 742#define PCM_RELEASE(x) do { \ | 595 596#define PCM_RELEASE(x) do { \ |
743 mtx_assert((x)->lock, MA_OWNED); \ | 597 PCM_LOCKASSERT(x); \ |
744 KASSERT((x)->flags & SD_F_BUSY, \ 745 ("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ 746 __func__, __LINE__)); \ 747 (x)->flags &= ~SD_F_BUSY; \ 748 if ((x)->cv.cv_waiters != 0) \ 749 cv_broadcast(&(x)->cv); \ | 598 KASSERT((x)->flags & SD_F_BUSY, \ 599 ("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ 600 __func__, __LINE__)); \ 601 (x)->flags &= ~SD_F_BUSY; \ 602 if ((x)->cv.cv_waiters != 0) \ 603 cv_broadcast(&(x)->cv); \ |
750} while(0) | 604} while (0) |
751 752/* Quick version, for shorter path. */ 753#define PCM_ACQUIRE_QUICK(x) do { \ | 605 606/* Quick version, for shorter path. */ 607#define PCM_ACQUIRE_QUICK(x) do { \ |
754 mtx_assert((x)->lock, MA_NOTOWNED); \ 755 pcm_lock(x); \ | 608 PCM_UNLOCKASSERT(x); \ 609 PCM_LOCK(x); \ |
756 PCM_WAIT(x); \ 757 PCM_ACQUIRE(x); \ | 610 PCM_WAIT(x); \ 611 PCM_ACQUIRE(x); \ |
758 pcm_unlock(x); \ 759} while(0) | 612 PCM_UNLOCK(x); \ 613} while (0) |
760 761#define PCM_RELEASE_QUICK(x) do { \ | 614 615#define PCM_RELEASE_QUICK(x) do { \ |
762 mtx_assert((x)->lock, MA_NOTOWNED); \ 763 pcm_lock(x); \ | 616 PCM_UNLOCKASSERT(x); \ 617 PCM_LOCK(x); \ |
764 PCM_RELEASE(x); \ | 618 PCM_RELEASE(x); \ |
765 pcm_unlock(x); \ 766} while(0) | 619 PCM_UNLOCK(x); \ 620} while (0) |
767 768#define PCM_BUSYASSERT(x) KASSERT(x != NULL && \ 769 ((x)->flags & SD_F_BUSY), \ 770 ("%s(%d): [PCM BUSYASSERT] " \ 771 "Failed, snddev_info=%p", \ 772 __func__, __LINE__, x)) 773 774#define PCM_GIANT_ENTER(x) do { \ 775 int _pcm_giant = 0; \ | 621 622#define PCM_BUSYASSERT(x) KASSERT(x != NULL && \ 623 ((x)->flags & SD_F_BUSY), \ 624 ("%s(%d): [PCM BUSYASSERT] " \ 625 "Failed, snddev_info=%p", \ 626 __func__, __LINE__, x)) 627 628#define PCM_GIANT_ENTER(x) do { \ 629 int _pcm_giant = 0; \ |
776 mtx_assert((x)->lock, MA_NOTOWNED); \ | 630 PCM_UNLOCKASSERT(x); \ |
777 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \ 778 do { \ 779 mtx_lock(&Giant); \ 780 _pcm_giant = 1; \ | 631 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \ 632 do { \ 633 mtx_lock(&Giant); \ 634 _pcm_giant = 1; \ |
781 } while(0) | 635 } while (0) |
782 783#define PCM_GIANT_EXIT(x) do { \ | 636 637#define PCM_GIANT_EXIT(x) do { \ |
784 mtx_assert((x)->lock, MA_NOTOWNED); \ | 638 PCM_UNLOCKASSERT(x); \ |
785 KASSERT(_pcm_giant == 0 || _pcm_giant == 1, \ 786 ("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \ 787 __func__, __LINE__)); \ 788 KASSERT(!((x)->flags & SD_F_MPSAFE) || \ 789 (((x)->flags & SD_F_MPSAFE) && _pcm_giant == 0), \ 790 ("%s(%d): [GIANT EXIT] MPSAFE Giant?", \ 791 __func__, __LINE__)); \ 792 if (_pcm_giant != 0) { \ 793 mtx_assert(&Giant, MA_OWNED); \ 794 _pcm_giant = 0; \ 795 mtx_unlock(&Giant); \ 796 } \ | 639 KASSERT(_pcm_giant == 0 || _pcm_giant == 1, \ 640 ("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \ 641 __func__, __LINE__)); \ 642 KASSERT(!((x)->flags & SD_F_MPSAFE) || \ 643 (((x)->flags & SD_F_MPSAFE) && _pcm_giant == 0), \ 644 ("%s(%d): [GIANT EXIT] MPSAFE Giant?", \ 645 __func__, __LINE__)); \ 646 if (_pcm_giant != 0) { \ 647 mtx_assert(&Giant, MA_OWNED); \ 648 _pcm_giant = 0; \ 649 mtx_unlock(&Giant); \ 650 } \ |
797} while(0) | 651} while (0) |
798#endif /* !SND_DIAGNOSTIC */ 799 800#define PCM_GIANT_LEAVE(x) \ 801 PCM_GIANT_EXIT(x); \ | 652#endif /* !SND_DIAGNOSTIC */ 653 654#define PCM_GIANT_LEAVE(x) \ 655 PCM_GIANT_EXIT(x); \ |
802} while(0) | 656} while (0) |
803 804#ifdef KLD_MODULE 805#define PCM_KLDSTRING(a) ("kld " # a) 806#else 807#define PCM_KLDSTRING(a) "" 808#endif 809 810#endif /* _KERNEL */ 811 812#endif /* _OS_H_ */ | 657 658#ifdef KLD_MODULE 659#define PCM_KLDSTRING(a) ("kld " # a) 660#else 661#define PCM_KLDSTRING(a) "" 662#endif 663 664#endif /* _KERNEL */ 665 666#endif /* _OS_H_ */ |