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