sound.h revision 78670
150724Scg/* 250724Scg * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk> 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 78670 2001-06-23 17:36:51Z cg $ 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> 5563469Scg#if __FreeBSD_version > 500000 5660041Sphk#include <sys/bio.h> 5763469Scg#endif 5850724Scg#include <sys/buf.h> 5950724Scg#include <machine/clock.h> /* for DELAY */ 6050724Scg#include <machine/resource.h> 6150724Scg#include <machine/bus.h> 6250724Scg#include <sys/rman.h> 6350724Scg#include <sys/mman.h> 6450724Scg#include <sys/poll.h> 6550724Scg#include <sys/soundcard.h> 6670617Sjhb#include <sys/sysctl.h> 6750724Scg#include <isa/isavar.h> 6873769Scg#include <sys/kobj.h> 6950724Scg#include <vm/vm.h> 7050724Scg#include <vm/pmap.h> 7150724Scg 7278670Scg#undef USING_MUTEX 7378670Scg#undef USING_DEVFS 7478670Scg 7573126Scg#if __FreeBSD_version > 500000 7673126Scg#define USING_MUTEX 7773126Scg#define USING_DEVFS 7873760Scg#endif 7973126Scg#define SND_DYNSYSCTL 8073126Scg 8178670Scg#ifndef INTR_MPSAFE 8278670Scg#define INTR_MPSAFE 0 8378670Scg#endif 8478670Scg 8550724Scg#else 8650724Scgstruct isa_device { int dummy; }; 8750724Scg#define d_open_t void 8850724Scg#define d_close_t void 8950724Scg#define d_read_t void 9050724Scg#define d_write_t void 9150724Scg#define d_ioctl_t void 9250724Scg#define d_select_t void 9355205Speter#endif /* _KERNEL */ 9450724Scg 9550724Scg#endif /* _OS_H_ */ 9650724Scg 9774763Scgstruct pcm_channel; 9874763Scgstruct pcm_feeder; 9974763Scgstruct snd_dbuf; 10074763Scgstruct snd_mixer; 10174763Scg 10274763Scg#include <dev/sound/pcm/buffer.h> 10353465Scg#include <dev/sound/pcm/channel.h> 10464881Scg#include <dev/sound/pcm/feeder.h> 10553465Scg#include <dev/sound/pcm/mixer.h> 10653465Scg#include <dev/sound/pcm/dsp.h> 10750724Scg 10877269Scgstruct snddev_channel { 10977269Scg SLIST_ENTRY(snddev_channel) link; 11077269Scg struct pcm_channel *channel; 11177269Scg}; 11277269Scg 11374763Scg#define SND_STATUSLEN 64 11474763Scg/* descriptor of audio device */ 11574763Scgstruct snddev_info { 11677269Scg SLIST_HEAD(, snddev_channel) channels; 11778362Scg struct pcm_channel *fakechan; 11878395Scg unsigned chancount; 11974763Scg unsigned flags; 12078362Scg int inprog; 12174763Scg void *devinfo; 12274763Scg device_t dev; 12374763Scg char status[SND_STATUSLEN]; 12474763Scg struct sysctl_ctx_list sysctl_tree; 12574763Scg struct sysctl_oid *sysctl_tree_top; 12677882Scg void *lock; 12774763Scg}; 12874763Scg 12964442Scg#ifndef ISADMA_WRITE 13064442Scg#define ISADMA_WRITE B_WRITE 13164442Scg#define ISADMA_READ B_READ 13264442Scg#define ISADMA_RAW B_RAW 13364442Scg#endif 13464442Scg 13562483Scg#define PCM_MODVER 1 13662483Scg 13762483Scg#define PCM_MINVER 1 13862483Scg#define PCM_PREFVER PCM_MODVER 13962483Scg#define PCM_MAXVER 1 14062483Scg 14178362Scg/* 14278362ScgPROPOSAL: 14378362Scgeach unit needs: 14478362Scgstatus, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices 14578362ScgdspW and audio are deprecated. 14678362Scgdsp needs min 64 channels, will give it 256 14750724Scg 14878362Scgminor = (unit << 20) + (dev << 16) + channel 14978362Scgcurrently minor = (channel << 16) + (unit << 4) + dev 15078362Scg 15178362Scgnomenclature: 15278362Scg /dev/pcmX/dsp.(0..255) 15378362Scg /dev/pcmX/dspW 15478362Scg /dev/pcmX/audio 15578362Scg /dev/pcmX/status 15678362Scg /dev/pcmX/mixer 15778362Scg [etc.] 15878362Scg*/ 15978362Scg 16078362Scg#define PCMMINOR(x) (minor(x)) 16178362Scg#define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16) 16278362Scg#define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4) 16378362Scg#define PCMDEV(x) (PCMMINOR(x) & 0x0000000f) 16478362Scg#define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f)) 16578362Scg 16650724Scg#define SD_F_SIMPLEX 0x00000001 16750724Scg#define SD_F_PRIO_RD 0x10000000 16850724Scg#define SD_F_PRIO_WR 0x20000000 16950724Scg#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 17050724Scg#define SD_F_DIR_SET 0x40000000 17150724Scg#define SD_F_TRANSIENT 0xf0000000 17250724Scg 17350724Scg/* many variables should be reduced to a range. Here define a macro */ 17450724Scg#define RANGE(var, low, high) (var) = \ 17550724Scg (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 17655204Scg#define DSP_BUFFSIZE (8192) 17750724Scg 17850724Scg/* make figuring out what a format is easier. got AFMT_STEREO already */ 17965486Scg#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 18050724Scg#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 18168405Scg#define AFMT_8BIT (AFMT_U8 | AFMT_S8) 18250724Scg#define AFMT_SIGNED (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 18350724Scg#define AFMT_BIGENDIAN (AFMT_S16_BE | AFMT_U16_BE) 18450724Scg 18574763Scgstruct pcm_channel *fkchan_setup(device_t dev); 18674763Scgint fkchan_kill(struct pcm_channel *c); 18750724Scg 18850724Scg/* 18978362Scg * Major nuber for the sound driver. 19078362Scg */ 19178362Scg#define SND_CDEV_MAJOR 30 19278362Scg 19378362Scg/* 19450724Scg * Minor numbers for the sound driver. 19550724Scg * 19650724Scg * Unfortunately Creative called the codec chip of SB as a DSP. For this 19750724Scg * reason the /dev/dsp is reserved for digitized audio use. There is a 19850724Scg * device for true DSP processors but it will be called something else. 19950724Scg * In v3.0 it's /dev/sndproc but this could be a temporary solution. 20050724Scg */ 20150724Scg 20250724Scg#define SND_DEV_CTL 0 /* Control port /dev/mixer */ 20350724Scg#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 20450724Scg#define SND_DEV_MIDIN 2 /* Raw midi access */ 20550724Scg#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 20650724Scg#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 20750724Scg#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 20850724Scg#define SND_DEV_STATUS 6 /* /dev/sndstat */ 20950724Scg /* #7 not in use now. */ 21050724Scg#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 21150724Scg#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 21250724Scg#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 21351769Scg#define SND_DEV_NORESET 10 21450724Scg 21550724Scg#define DSP_DEFAULT_SPEED 8000 21650724Scg 21750724Scg#define ON 1 21850724Scg#define OFF 0 21950724Scg 22055205Speter#ifdef _KERNEL 22150724Scg 22278362Scgextern int snd_unit; 22378362Scgextern devclass_t pcm_devclass; 22478362Scg 22550724Scg/* 22650724Scg * some macros for debugging purposes 22750724Scg * DDB/DEB to enable/disable debugging stuff 22850724Scg * BVDDB to enable debugging when bootverbose 22950724Scg */ 23050724Scg#define DDB(x) x /* XXX */ 23150724Scg#define BVDDB(x) if (bootverbose) x 23250724Scg 23350724Scg#ifndef DEB 23450724Scg#define DEB(x) 23550724Scg#endif 23650724Scg 23770617SjhbSYSCTL_DECL(_hw_snd); 23870617Sjhb 23978214Scgstruct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid); 24078214Scgint pcm_chnrelease(struct pcm_channel *c); 24177269Scgint pcm_chnref(struct pcm_channel *c, int ref); 24277269Scg 24377269Scgstruct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); 24477269Scgint pcm_chn_destroy(struct pcm_channel *ch); 24577269Scgint pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 24677269Scgint pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); 24777269Scg 24870134Scgint pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 24950724Scgint pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 25065340Scgint pcm_unregister(device_t dev); 25150724Scgint pcm_setstatus(device_t dev, char *str); 25250724Scgu_int32_t pcm_getflags(device_t dev); 25350724Scgvoid pcm_setflags(device_t dev, u_int32_t val); 25458384Scgvoid *pcm_getdevinfo(device_t dev); 25550724Scg 25673131Scgint snd_setup_intr(device_t dev, struct resource *res, int flags, 25773131Scg driver_intr_t hand, void *param, void **cookiep); 25873131Scg 25973131Scgvoid *snd_mtxcreate(const char *desc); 26073131Scgvoid snd_mtxfree(void *m); 26173131Scgvoid snd_mtxassert(void *m); 26273131Scgvoid snd_mtxlock(void *m); 26373131Scgvoid snd_mtxunlock(void *m); 26455205Speter#endif /* _KERNEL */ 26550724Scg 26650724Scg/* usage of flags in device config entry (config file) */ 26750724Scg#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 26850724Scg#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 26950724Scg 27050724Scg/* ought to be made obsolete */ 27150724Scg#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 27250724Scg#define DV_F_DEV_SHIFT 8 /* force device type/class */ 273