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: src/sys/dev/sound/pcm/sound.h,v 1.63.2.3 2007/05/13 20:53:39 ariff Exp $ 28 * $DragonFly: src/sys/dev/sound/pcm/sound.h,v 1.14 2008/01/05 13:34:22 corecode Exp $ 29 */ 30 31 /* 32 * first, include kernel header files. 33 */ 34 35 #ifndef _OS_H_ 36 #define _OS_H_ 37 38 #ifdef _KERNEL 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/ioccom.h> 42 #include <sys/filio.h> 43 #include <sys/sockio.h> 44 #include <sys/fcntl.h> 45 #include <sys/tty.h> 46 #include <sys/proc.h> 47 #include <sys/kernel.h> /* for DATA_SET */ 48 #include <sys/module.h> 49 #include <sys/conf.h> 50 #include <sys/file.h> 51 #include <sys/uio.h> 52 #include <sys/syslog.h> 53 #include <sys/errno.h> 54 #include <sys/malloc.h> 55 #include <sys/bus.h> 56 #include <sys/buf.h> 57 #include <machine/clock.h> /* for DELAY */ 58 #include <sys/resource.h> 59 #include <sys/bus.h> 60 #include <sys/rman.h> 61 #include <sys/mman.h> 62 #include <sys/poll.h> 63 #include <sys/sbuf.h> 64 #include <sys/soundcard.h> 65 #include <sys/sysctl.h> 66 #include <sys/kobj.h> 67 #include <sys/thread2.h> 68 #include <sys/taskqueue.h> 69 70 #include <machine/clock.h> /* for DELAY */ 71 72 #include <vm/vm.h> 73 #include <vm/pmap.h> 74 75 #undef USING_MUTEX 76 #undef USING_DEVFS 77 78 #include <sys/lock.h> /* lockmgr locks */ 79 typedef struct lock *sndlock_t; /* opaque lock structure */ 80 81 #define USING_MUTEX 82 #define INTR_TYPE_AV 0 83 84 #define SND_DYNSYSCTL 85 86 struct pcm_channel; 87 struct pcm_feeder; 88 struct snd_dbuf; 89 struct snd_mixer; 90 91 #include <dev/sound/pcm/buffer.h> 92 #include <dev/sound/pcm/channel.h> 93 #include <dev/sound/pcm/feeder.h> 94 #include <dev/sound/pcm/mixer.h> 95 96 #define PCM_SOFTC_SIZE 512 97 98 #define SND_STATUSLEN 64 99 100 #define SOUND_MODVER 1 101 102 #define SOUND_MINVER 1 103 #define SOUND_PREFVER SOUND_MODVER 104 #define SOUND_MAXVER 1 105 106 /* 107 PROPOSAL: 108 each unit needs: 109 status, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices 110 dspW and audio are deprecated. 111 dsp needs min 64 channels, will give it 256 112 113 minor = (unit << 20) + (dev << 16) + channel 114 currently minor = (channel << 16) + (unit << 4) + dev 115 116 nomenclature: 117 /dev/pcmX/dsp.(0..255) 118 /dev/pcmX/dspW 119 /dev/pcmX/audio 120 /dev/pcmX/status 121 /dev/pcmX/mixer 122 [etc.] 123 */ 124 125 #define PCMMAXCHAN 0xff 126 #define PCMMAXDEV 0x0f 127 #define PCMMAXUNIT 0x0f 128 #define PCMMINOR(x) (minor(x)) 129 #define PCMCHAN(x) ((PCMMINOR(x) >> 16) & PCMMAXCHAN) 130 #define PCMUNIT(x) ((PCMMINOR(x) >> 4) & PCMMAXUNIT) 131 #define PCMDEV(x) (PCMMINOR(x) & PCMMAXDEV) 132 #define PCMMKMINOR(u, d, c) ((((c) & PCMMAXCHAN) << 16) | \ 133 (((u) & PCMMAXUNIT) << 4) | ((d) & PCMMAXDEV)) 134 135 #define SD_F_SIMPLEX 0x00000001 136 #define SD_F_AUTOVCHAN 0x00000002 137 #define SD_F_SOFTPCMVOL 0x00000004 138 #define SD_F_PRIO_RD 0x10000000 139 #define SD_F_PRIO_WR 0x20000000 140 #define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 141 #define SD_F_DIR_SET 0x40000000 142 #define SD_F_TRANSIENT 0xf0000000 143 144 /* many variables should be reduced to a range. Here define a macro */ 145 #define RANGE(var, low, high) (var) = \ 146 (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 147 #define DSP_BUFFSIZE (8192) 148 149 /* make figuring out what a format is easier. got AFMT_STEREO already */ 150 #define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 151 #define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE) 152 #define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 153 #define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8) 154 #define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \ 155 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 156 #define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \ 157 AFMT_S16_BE | AFMT_U16_BE) 158 159 struct pcm_channel *fkchan_setup(device_t dev); 160 int fkchan_kill(struct pcm_channel *c); 161 162 /* 163 * Major nuber for the sound driver. 164 */ 165 #define SND_CDEV_MAJOR 30 166 167 /* XXX Flawed definition. I'll fix it someday. */ 168 #define SND_MAXVCHANS PCMMAXCHAN 169 170 /* 171 * Minor numbers for the sound driver. 172 * 173 * Unfortunately Creative called the codec chip of SB as a DSP. For this 174 * reason the /dev/dsp is reserved for digitized audio use. There is a 175 * device for true DSP processors but it will be called something else. 176 * In v3.0 it's /dev/sndproc but this could be a temporary solution. 177 */ 178 179 #define SND_DEV_CTL 0 /* Control port /dev/mixer */ 180 #define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 181 #define SND_DEV_MIDIN 2 /* Raw midi access */ 182 #define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 183 #define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 184 #define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 185 #define SND_DEV_STATUS 6 /* /dev/sndstat */ 186 /* #7 not in use now. */ 187 #define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 188 #define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 189 #define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 190 #define SND_DEV_NORESET 10 191 #define SND_DEV_DSPREC 11 /* recording channels */ 192 193 #define DSP_DEFAULT_SPEED 8000 194 195 #define ON 1 196 #define OFF 0 197 198 extern int pcm_veto_load; 199 extern int snd_unit; 200 extern devclass_t pcm_devclass; 201 202 /* 203 * some macros for debugging purposes 204 * DDB/DEB to enable/disable debugging stuff 205 * BVDDB to enable debugging when bootverbose 206 */ 207 #define BVDDB(x) if (bootverbose) x 208 209 #ifndef DEB 210 #define DEB(x) 211 #endif 212 213 SYSCTL_DECL(_hw_snd); 214 215 struct sysctl_ctx_list *snd_sysctl_tree(device_t dev); 216 struct sysctl_oid *snd_sysctl_tree_top(device_t dev); 217 218 struct pcm_channel *pcm_getfakechan(struct snddev_info *d); 219 int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int chnum); 220 int pcm_chnrelease(struct pcm_channel *c); 221 int pcm_chnref(struct pcm_channel *c, int ref); 222 int pcm_inprog(struct snddev_info *d, int delta); 223 224 struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); 225 struct pcm_channel *pcm_chn_iterate(struct snddev_info *d, void **cookie); 226 int pcm_chn_destroy(struct pcm_channel *ch); 227 int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 228 int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); 229 230 int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 231 unsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max); 232 int pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 233 int pcm_unregister(device_t dev); 234 int pcm_setstatus(device_t dev, char *str); 235 u_int32_t pcm_getflags(device_t dev); 236 void pcm_setflags(device_t dev, u_int32_t val); 237 void *pcm_getdevinfo(device_t dev); 238 239 240 int snd_setup_intr(device_t dev, struct resource *res, int flags, 241 driver_intr_t hand, void *param, void **cookiep); 242 243 void *snd_mtxcreate(const char *desc, const char *type); 244 void snd_mtxfree(void *m); 245 void snd_mtxassert(void *m); 246 void snd_mtxlock(void *m); 247 void snd_mtxunlock(void *m); 248 int snd_mtxsleep(void *, sndlock_t, int, const char *, int); 249 250 int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); 251 252 typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 253 int sndstat_acquire(void); 254 int sndstat_release(void); 255 int sndstat_register(device_t dev, char *str, sndstat_handler handler); 256 int sndstat_registerfile(char *str); 257 int sndstat_unregister(device_t dev); 258 int sndstat_unregisterfile(char *str); 259 260 #define SND_DECLARE_FILE(version) \ 261 _SND_DECLARE_FILE(__LINE__, version) 262 263 #define _SND_DECLARE_FILE(uniq, version) \ 264 __SND_DECLARE_FILE(uniq, version) 265 266 #define __SND_DECLARE_FILE(uniq, version) \ 267 static char sndstat_vinfo[] = version; \ 268 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ 269 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); 270 271 /* usage of flags in device config entry (config file) */ 272 #define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 273 #define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 274 275 /* ought to be made obsolete but still used by mss */ 276 #define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 277 #define DV_F_DEV_SHIFT 8 /* force device type/class */ 278 279 #define PCM_DEBUG_MTX 280 281 /* 282 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c 283 * so that the macro versions of pcm_{,un}lock can dereference them. 284 * we also have to do this now makedev() has gone away. 285 */ 286 287 struct snddev_channel { 288 SLIST_ENTRY(snddev_channel) link; 289 struct pcm_channel *channel; 290 int chan_num; 291 struct cdev *dsp_devt; 292 struct cdev *dspW_devt; 293 struct cdev *audio_devt; 294 struct cdev *dspr_devt; 295 }; 296 297 struct snddev_info { 298 SLIST_HEAD(, snddev_channel) channels; 299 struct pcm_channel *fakechan; 300 unsigned devcount, playcount, reccount, vchancount; 301 unsigned flags; 302 int inprog; 303 unsigned int bufsz; 304 void *devinfo; 305 device_t dev; 306 char status[SND_STATUSLEN]; 307 struct sysctl_ctx_list sysctl_tree; 308 struct sysctl_oid *sysctl_tree_top; 309 sndlock_t lock; 310 struct cdev *mixer_dev; 311 312 }; 313 314 #ifdef PCM_DEBUG_MTX 315 #define pcm_lock(d) snd_mtxlock(((struct snddev_info *)(d))->lock) 316 #define pcm_unlock(d) snd_mtxunlock(((struct snddev_info *)(d))->lock) 317 #else 318 void pcm_lock(struct snddev_info *d); 319 void pcm_unlock(struct snddev_info *d); 320 #endif 321 322 #ifdef KLD_MODULE 323 #define PCM_KLDSTRING(a) ("kld " # a) 324 #else 325 #define PCM_KLDSTRING(a) "" 326 #endif 327 328 #endif /* _KERNEL */ 329 330 #endif /* _OS_H_ */ 331