1 /* 2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk> 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.10.2.11 2002/04/22 15:49:36 cg Exp $ 28 * $DragonFly: src/sys/dev/sound/pcm/sound.h,v 1.4 2004/02/13 01:45:14 joerg 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 #if defined(__FreeBSD__) && __FreeBSD_version > 500000 57 #include <sys/bio.h> 58 #endif 59 #include <sys/buf.h> 60 #include <machine/clock.h> /* for DELAY */ 61 #include <machine/resource.h> 62 #include <machine/bus.h> 63 #include <sys/rman.h> 64 #include <sys/mman.h> 65 #include <sys/poll.h> 66 #include <sys/sbuf.h> 67 #include <sys/soundcard.h> 68 #include <sys/sysctl.h> 69 #include <bus/isa/isavar.h> 70 #include <sys/kobj.h> 71 #include <vm/vm.h> 72 #include <vm/pmap.h> 73 74 #undef USING_MUTEX 75 #undef USING_DEVFS 76 77 #if defined(__FreeBSD__) && __FreeBSD_version > 500000 78 #define USING_MUTEX 79 #define USING_DEVFS 80 #endif 81 82 #define SND_DYNSYSCTL 83 84 #ifndef INTR_MPSAFE 85 #define INTR_TYPE_AV INTR_TYPE_TTY 86 #endif 87 88 #ifndef INTR_MPSAFE 89 #define INTR_MPSAFE 0 90 #endif 91 92 struct pcm_channel; 93 struct pcm_feeder; 94 struct snd_dbuf; 95 struct snd_mixer; 96 97 #include <dev/sound/pcm/buffer.h> 98 #include <dev/sound/pcm/channel.h> 99 #include <dev/sound/pcm/feeder.h> 100 #include <dev/sound/pcm/mixer.h> 101 #include <dev/sound/pcm/dsp.h> 102 103 #define PCM_SOFTC_SIZE 512 104 105 #define SND_STATUSLEN 64 106 /* descriptor of audio device */ 107 #ifndef ISADMA_WRITE 108 #define ISADMA_WRITE B_WRITE 109 #define ISADMA_READ B_READ 110 #define ISADMA_RAW B_RAW 111 #endif 112 113 #define PCM_MODVER 1 114 115 #define PCM_MINVER 1 116 #define PCM_PREFVER PCM_MODVER 117 #define PCM_MAXVER 1 118 119 /* 120 PROPOSAL: 121 each unit needs: 122 status, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices 123 dspW and audio are deprecated. 124 dsp needs min 64 channels, will give it 256 125 126 minor = (unit << 20) + (dev << 16) + channel 127 currently minor = (channel << 16) + (unit << 4) + dev 128 129 nomenclature: 130 /dev/pcmX/dsp.(0..255) 131 /dev/pcmX/dspW 132 /dev/pcmX/audio 133 /dev/pcmX/status 134 /dev/pcmX/mixer 135 [etc.] 136 */ 137 138 #define PCMMINOR(x) (minor(x)) 139 #define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16) 140 #define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4) 141 #define PCMDEV(x) (PCMMINOR(x) & 0x0000000f) 142 #define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f)) 143 144 #define SD_F_SIMPLEX 0x00000001 145 #define SD_F_AUTOVCHAN 0x00000002 146 #define SD_F_PRIO_RD 0x10000000 147 #define SD_F_PRIO_WR 0x20000000 148 #define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 149 #define SD_F_DIR_SET 0x40000000 150 #define SD_F_TRANSIENT 0xf0000000 151 152 /* many variables should be reduced to a range. Here define a macro */ 153 #define RANGE(var, low, high) (var) = \ 154 (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 155 #define DSP_BUFFSIZE (8192) 156 157 /* make figuring out what a format is easier. got AFMT_STEREO already */ 158 #define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 159 #define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 160 #define AFMT_8BIT (AFMT_U8 | AFMT_S8) 161 #define AFMT_SIGNED (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 162 #define AFMT_BIGENDIAN (AFMT_S16_BE | AFMT_U16_BE) 163 164 struct pcm_channel *fkchan_setup(device_t dev); 165 int fkchan_kill(struct pcm_channel *c); 166 167 /* 168 * Major nuber for the sound driver. 169 */ 170 #define SND_CDEV_MAJOR 30 171 172 #define SND_MAXVCHANS 255 173 174 /* 175 * Minor numbers for the sound driver. 176 * 177 * Unfortunately Creative called the codec chip of SB as a DSP. For this 178 * reason the /dev/dsp is reserved for digitized audio use. There is a 179 * device for true DSP processors but it will be called something else. 180 * In v3.0 it's /dev/sndproc but this could be a temporary solution. 181 */ 182 183 #define SND_DEV_CTL 0 /* Control port /dev/mixer */ 184 #define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 185 #define SND_DEV_MIDIN 2 /* Raw midi access */ 186 #define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 187 #define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 188 #define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 189 #define SND_DEV_STATUS 6 /* /dev/sndstat */ 190 /* #7 not in use now. */ 191 #define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 192 #define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 193 #define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 194 #define SND_DEV_NORESET 10 195 #define SND_DEV_DSPREC 11 /* recording channels */ 196 197 #define DSP_DEFAULT_SPEED 8000 198 199 #define ON 1 200 #define OFF 0 201 202 extern int pcm_veto_load; 203 extern int snd_unit; 204 extern devclass_t pcm_devclass; 205 206 /* 207 * some macros for debugging purposes 208 * DDB/DEB to enable/disable debugging stuff 209 * BVDDB to enable debugging when bootverbose 210 */ 211 #define DDB(x) x /* XXX */ 212 #define BVDDB(x) if (bootverbose) x 213 214 #ifndef DEB 215 #define DEB(x) 216 #endif 217 218 SYSCTL_DECL(_hw_snd); 219 220 struct sysctl_ctx_list *snd_sysctl_tree(device_t dev); 221 struct sysctl_oid *snd_sysctl_tree_top(device_t dev); 222 223 void pcm_lock(struct snddev_info *d); 224 void pcm_unlock(struct snddev_info *d); 225 struct pcm_channel *pcm_getfakechan(struct snddev_info *d); 226 struct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum); 227 int pcm_chnrelease(struct pcm_channel *c); 228 int pcm_chnref(struct pcm_channel *c, int ref); 229 int pcm_inprog(struct snddev_info *d, int delta); 230 231 struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); 232 int pcm_chn_destroy(struct pcm_channel *ch); 233 int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch, int mkdev); 234 int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch, int rmdev); 235 236 int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 237 unsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max); 238 int pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 239 int pcm_unregister(device_t dev); 240 int pcm_setstatus(device_t dev, char *str); 241 u_int32_t pcm_getflags(device_t dev); 242 void pcm_setflags(device_t dev, u_int32_t val); 243 void *pcm_getdevinfo(device_t dev); 244 245 int snd_setup_intr(device_t dev, struct resource *res, int flags, 246 driver_intr_t hand, void *param, void **cookiep); 247 248 void *snd_mtxcreate(const char *desc, const char *type); 249 void snd_mtxfree(void *m); 250 void snd_mtxassert(void *m); 251 void snd_mtxlock(void *m); 252 void snd_mtxunlock(void *m); 253 254 int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); 255 256 typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 257 int sndstat_register(device_t dev, char *str, sndstat_handler handler); 258 int sndstat_registerfile(char *str); 259 int sndstat_unregister(device_t dev); 260 int sndstat_unregisterfile(char *str); 261 int sndstat_busy(void); 262 263 #define SND_DECLARE_FILE(version) \ 264 _SND_DECLARE_FILE(__LINE__, version) 265 266 #define _SND_DECLARE_FILE(uniq, version) \ 267 __SND_DECLARE_FILE(uniq, version) 268 269 #define __SND_DECLARE_FILE(uniq, version) \ 270 static char sndstat_vinfo[] = version; \ 271 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ 272 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); 273 274 /* usage of flags in device config entry (config file) */ 275 #define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 276 #define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 277 278 /* ought to be made obsolete */ 279 #define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 280 #define DV_F_DEV_SHIFT 8 /* force device type/class */ 281 282 #endif /* _KERNEL */ 283 284 #endif /* _OS_H_ */ 285