sound.h revision 149950
1139749Simp/*- 2119853Scg * Copyright (c) 1999 Cameron Grant <cg@freebsd.org> 350724Scg * Copyright by Hannu Savolainen 1995 450724Scg * All rights reserved. 550724Scg * 650724Scg * Redistribution and use in source and binary forms, with or without 750724Scg * modification, are permitted provided that the following conditions 850724Scg * are met: 950724Scg * 1. Redistributions of source code must retain the above copyright 1050724Scg * notice, this list of conditions and the following disclaimer. 1150724Scg * 2. Redistributions in binary form must reproduce the above copyright 1250724Scg * notice, this list of conditions and the following disclaimer in the 1350724Scg * documentation and/or other materials provided with the distribution. 1450724Scg * 1550724Scg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1650724Scg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1750724Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1850724Scg * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1950724Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2050724Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2150724Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2250724Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2350724Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2450724Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2550724Scg * SUCH DAMAGE. 2650724Scg * 2750733Speter * $FreeBSD: head/sys/dev/sound/pcm/sound.h 149950 2005-09-10 17:47:39Z netchild $ 2850724Scg */ 2950724Scg 3050724Scg/* 3150724Scg * first, include kernel header files. 3250724Scg */ 3350724Scg 3450724Scg#ifndef _OS_H_ 3550724Scg#define _OS_H_ 3650724Scg 3755205Speter#ifdef _KERNEL 3850724Scg#include <sys/param.h> 3950724Scg#include <sys/systm.h> 4050724Scg#include <sys/ioccom.h> 4150724Scg#include <sys/filio.h> 4250724Scg#include <sys/sockio.h> 4350724Scg#include <sys/fcntl.h> 4450724Scg#include <sys/tty.h> 4550724Scg#include <sys/proc.h> 4650724Scg#include <sys/kernel.h> /* for DATA_SET */ 4750724Scg#include <sys/module.h> 4850724Scg#include <sys/conf.h> 4950724Scg#include <sys/file.h> 5050724Scg#include <sys/uio.h> 5150724Scg#include <sys/syslog.h> 5250724Scg#include <sys/errno.h> 5350724Scg#include <sys/malloc.h> 5450724Scg#include <sys/bus.h> 55103327Sphk#if __FreeBSD_version < 500000 56103327Sphk#include <sys/buf.h> 5763469Scg#endif 5850724Scg#include <machine/clock.h> /* for DELAY */ 5950724Scg#include <machine/resource.h> 6050724Scg#include <machine/bus.h> 6150724Scg#include <sys/rman.h> 6250724Scg#include <sys/mman.h> 6350724Scg#include <sys/poll.h> 6482180Scg#include <sys/sbuf.h> 6550724Scg#include <sys/soundcard.h> 6670617Sjhb#include <sys/sysctl.h> 6773769Scg#include <sys/kobj.h> 6850724Scg#include <vm/vm.h> 6950724Scg#include <vm/pmap.h> 7050724Scg 7178670Scg#undef USING_MUTEX 7278670Scg#undef USING_DEVFS 7378670Scg 7473126Scg#if __FreeBSD_version > 500000 75103338Sbde#include <sys/lock.h> 76103338Sbde#include <sys/mutex.h> 77103338Sbde 7873126Scg#define USING_MUTEX 7973126Scg#define USING_DEVFS 80128232Sgreen#else 81128232Sgreen#define INTR_TYPE_AV INTR_TYPE_TTY 82128232Sgreen#define INTR_MPSAFE 0 8373760Scg#endif 8482180Scg 8573126Scg#define SND_DYNSYSCTL 8673126Scg 8774763Scgstruct pcm_channel; 8874763Scgstruct pcm_feeder; 8974763Scgstruct snd_dbuf; 9074763Scgstruct snd_mixer; 9174763Scg 9274763Scg#include <dev/sound/pcm/buffer.h> 9353465Scg#include <dev/sound/pcm/channel.h> 9464881Scg#include <dev/sound/pcm/feeder.h> 9553465Scg#include <dev/sound/pcm/mixer.h> 9650724Scg 9782180Scg#define PCM_SOFTC_SIZE 512 9877269Scg 9974763Scg#define SND_STATUSLEN 64 10064442Scg 101132236Stanimura#define SOUND_MODVER 1 10262483Scg 103132236Stanimura#define SOUND_MINVER 1 104132236Stanimura#define SOUND_PREFVER SOUND_MODVER 105132236Stanimura#define SOUND_MAXVER 1 10662483Scg 10778362Scg/* 10878362ScgPROPOSAL: 10978362Scgeach unit needs: 11078362Scgstatus, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices 11178362ScgdspW and audio are deprecated. 11278362Scgdsp needs min 64 channels, will give it 256 11350724Scg 11478362Scgminor = (unit << 20) + (dev << 16) + channel 11578362Scgcurrently minor = (channel << 16) + (unit << 4) + dev 11678362Scg 11778362Scgnomenclature: 11878362Scg /dev/pcmX/dsp.(0..255) 11978362Scg /dev/pcmX/dspW 12078362Scg /dev/pcmX/audio 12178362Scg /dev/pcmX/status 12278362Scg /dev/pcmX/mixer 12378362Scg [etc.] 12478362Scg*/ 12578362Scg 12678362Scg#define PCMMINOR(x) (minor(x)) 12778362Scg#define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16) 12878362Scg#define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4) 12978362Scg#define PCMDEV(x) (PCMMINOR(x) & 0x0000000f) 13078362Scg#define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f)) 13178362Scg 13250724Scg#define SD_F_SIMPLEX 0x00000001 13378853Scg#define SD_F_AUTOVCHAN 0x00000002 13450724Scg#define SD_F_PRIO_RD 0x10000000 13550724Scg#define SD_F_PRIO_WR 0x20000000 13650724Scg#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 13750724Scg#define SD_F_DIR_SET 0x40000000 13850724Scg#define SD_F_TRANSIENT 0xf0000000 13950724Scg 14050724Scg/* many variables should be reduced to a range. Here define a macro */ 14150724Scg#define RANGE(var, low, high) (var) = \ 14250724Scg (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 14355204Scg#define DSP_BUFFSIZE (8192) 14450724Scg 14550724Scg/* make figuring out what a format is easier. got AFMT_STEREO already */ 14665486Scg#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 147148606Snetchild#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE) 14850724Scg#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 149149950Snetchild#define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8) 150148606Snetchild#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \ 151148606Snetchild AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 152148606Snetchild#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \ 153148606Snetchild AFMT_S16_BE | AFMT_U16_BE) 15450724Scg 15574763Scgstruct pcm_channel *fkchan_setup(device_t dev); 15674763Scgint fkchan_kill(struct pcm_channel *c); 15750724Scg 15878853Scg#define SND_MAXVCHANS 255 15978853Scg 16078362Scg/* 16150724Scg * Minor numbers for the sound driver. 16250724Scg * 16350724Scg * Unfortunately Creative called the codec chip of SB as a DSP. For this 16450724Scg * reason the /dev/dsp is reserved for digitized audio use. There is a 16550724Scg * device for true DSP processors but it will be called something else. 16650724Scg * In v3.0 it's /dev/sndproc but this could be a temporary solution. 16750724Scg */ 16850724Scg 16950724Scg#define SND_DEV_CTL 0 /* Control port /dev/mixer */ 17050724Scg#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 17150724Scg#define SND_DEV_MIDIN 2 /* Raw midi access */ 17250724Scg#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 17350724Scg#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 17450724Scg#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 17550724Scg#define SND_DEV_STATUS 6 /* /dev/sndstat */ 17650724Scg /* #7 not in use now. */ 17750724Scg#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 17850724Scg#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 17950724Scg#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 18051769Scg#define SND_DEV_NORESET 10 18183089Scg#define SND_DEV_DSPREC 11 /* recording channels */ 18250724Scg 18350724Scg#define DSP_DEFAULT_SPEED 8000 18450724Scg 18550724Scg#define ON 1 18650724Scg#define OFF 0 18750724Scg 18889834Scgextern int pcm_veto_load; 18978362Scgextern int snd_unit; 19078362Scgextern devclass_t pcm_devclass; 19178362Scg 19250724Scg/* 19350724Scg * some macros for debugging purposes 19450724Scg * DDB/DEB to enable/disable debugging stuff 19550724Scg * BVDDB to enable debugging when bootverbose 19650724Scg */ 19750724Scg#define BVDDB(x) if (bootverbose) x 19850724Scg 19950724Scg#ifndef DEB 20050724Scg#define DEB(x) 20150724Scg#endif 20250724Scg 20370617SjhbSYSCTL_DECL(_hw_snd); 20470617Sjhb 20582180Scgstruct sysctl_ctx_list *snd_sysctl_tree(device_t dev); 20682180Scgstruct sysctl_oid *snd_sysctl_tree_top(device_t dev); 20782180Scg 20882180Scgstruct pcm_channel *pcm_getfakechan(struct snddev_info *d); 20983089Scgstruct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum); 21078214Scgint pcm_chnrelease(struct pcm_channel *c); 21177269Scgint pcm_chnref(struct pcm_channel *c, int ref); 21282180Scgint pcm_inprog(struct snddev_info *d, int delta); 21377269Scg 21477269Scgstruct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); 21577269Scgint pcm_chn_destroy(struct pcm_channel *ch); 216124740Smatkint pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 217124740Smatkint pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); 21877269Scg 21970134Scgint pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 22083614Scgunsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max); 22150724Scgint pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 22265340Scgint pcm_unregister(device_t dev); 22350724Scgint pcm_setstatus(device_t dev, char *str); 22450724Scgu_int32_t pcm_getflags(device_t dev); 22550724Scgvoid pcm_setflags(device_t dev, u_int32_t val); 22658384Scgvoid *pcm_getdevinfo(device_t dev); 22750724Scg 228124617Sphk 22973131Scgint snd_setup_intr(device_t dev, struct resource *res, int flags, 23073131Scg driver_intr_t hand, void *param, void **cookiep); 23173131Scg 23293814Sjhbvoid *snd_mtxcreate(const char *desc, const char *type); 23373131Scgvoid snd_mtxfree(void *m); 23473131Scgvoid snd_mtxassert(void *m); 235119096Scg#define snd_mtxlock(m) mtx_lock(m) 236119096Scg#define snd_mtxunlock(m) mtx_unlock(m) 237119096Scg 23882180Scgint sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); 23982180Scg 24082180Scgtypedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 24182180Scgint sndstat_register(device_t dev, char *str, sndstat_handler handler); 24282180Scgint sndstat_registerfile(char *str); 24382180Scgint sndstat_unregister(device_t dev); 24482180Scgint sndstat_unregisterfile(char *str); 24583476Sgreidint sndstat_busy(void); 24682180Scg 24782180Scg#define SND_DECLARE_FILE(version) \ 24882180Scg _SND_DECLARE_FILE(__LINE__, version) 24982180Scg 25082180Scg#define _SND_DECLARE_FILE(uniq, version) \ 25182180Scg __SND_DECLARE_FILE(uniq, version) 25282180Scg 25382180Scg#define __SND_DECLARE_FILE(uniq, version) \ 25482180Scg static char sndstat_vinfo[] = version; \ 25582180Scg SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ 25682180Scg SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); 25782180Scg 25850724Scg/* usage of flags in device config entry (config file) */ 25950724Scg#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 26050724Scg#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 26150724Scg 262119096Scg/* ought to be made obsolete but still used by mss */ 26350724Scg#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 26450724Scg#define DV_F_DEV_SHIFT 8 /* force device type/class */ 26582180Scg 266119096Scg#define PCM_DEBUG_MTX 267107237Scg 268119096Scg/* 269119096Scg * this is rather kludgey- we need to duplicate these struct def'ns from sound.c 270119096Scg * so that the macro versions of pcm_{,un}lock can dereference them. 271124617Sphk * we also have to do this now makedev() has gone away. 272119096Scg */ 273119096Scg 274119096Scgstruct snddev_channel { 275119096Scg SLIST_ENTRY(snddev_channel) link; 276119096Scg struct pcm_channel *channel; 277124740Smatk int chan_num; 278130585Sphk struct cdev *dsp_devt; 279130585Sphk struct cdev *dspW_devt; 280130585Sphk struct cdev *audio_devt; 281130585Sphk struct cdev *dspr_devt; 282119096Scg}; 283119096Scg 284119096Scgstruct snddev_info { 285119096Scg SLIST_HEAD(, snddev_channel) channels; 286119096Scg struct pcm_channel *fakechan; 287119096Scg unsigned devcount, playcount, reccount, vchancount; 288119096Scg unsigned flags; 289119096Scg int inprog; 290119096Scg unsigned int bufsz; 291119096Scg void *devinfo; 292119096Scg device_t dev; 293119096Scg char status[SND_STATUSLEN]; 294119096Scg struct sysctl_ctx_list sysctl_tree; 295119096Scg struct sysctl_oid *sysctl_tree_top; 296119096Scg struct mtx *lock; 297130585Sphk struct cdev *mixer_dev; 298124617Sphk 299119096Scg}; 300119096Scg 301124617Sphk#ifdef PCM_DEBUG_MTX 302119096Scg#define pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock) 303119096Scg#define pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock) 304119096Scg#else 305119096Scgvoid pcm_lock(struct snddev_info *d); 306119096Scgvoid pcm_unlock(struct snddev_info *d); 307119096Scg#endif 308119096Scg 309126695Smatk#ifdef KLD_MODULE 310126695Smatk#define PCM_KLDSTRING(a) ("kld " # a) 311126695Smatk#else 312126695Smatk#define PCM_KLDSTRING(a) "" 313126695Smatk#endif 314126695Smatk 31582180Scg#endif /* _KERNEL */ 31682180Scg 31782180Scg#endif /* _OS_H_ */ 318