sound.h revision 103327
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 103327 2002-09-14 18:58:36Z phk $ 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> 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 7982180Scg 8073126Scg#define SND_DYNSYSCTL 8173126Scg 8278670Scg#ifndef INTR_MPSAFE 8379141Scg#define INTR_TYPE_AV INTR_TYPE_TTY 8479141Scg#endif 8579141Scg 8679141Scg#ifndef INTR_MPSAFE 8778670Scg#define INTR_MPSAFE 0 8878670Scg#endif 8978670Scg 9074763Scgstruct pcm_channel; 9174763Scgstruct pcm_feeder; 9274763Scgstruct snd_dbuf; 9374763Scgstruct snd_mixer; 9474763Scg 9574763Scg#include <dev/sound/pcm/buffer.h> 9653465Scg#include <dev/sound/pcm/channel.h> 9764881Scg#include <dev/sound/pcm/feeder.h> 9853465Scg#include <dev/sound/pcm/mixer.h> 9953465Scg#include <dev/sound/pcm/dsp.h> 10050724Scg 10182180Scg#define PCM_SOFTC_SIZE 512 10277269Scg 10374763Scg#define SND_STATUSLEN 64 10474763Scg/* descriptor of audio device */ 10564442Scg#ifndef ISADMA_WRITE 10664442Scg#define ISADMA_WRITE B_WRITE 10764442Scg#define ISADMA_READ B_READ 10864442Scg#define ISADMA_RAW B_RAW 10964442Scg#endif 11064442Scg 11162483Scg#define PCM_MODVER 1 11262483Scg 11362483Scg#define PCM_MINVER 1 11462483Scg#define PCM_PREFVER PCM_MODVER 11562483Scg#define PCM_MAXVER 1 11662483Scg 11778362Scg/* 11878362ScgPROPOSAL: 11978362Scgeach unit needs: 12078362Scgstatus, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices 12178362ScgdspW and audio are deprecated. 12278362Scgdsp needs min 64 channels, will give it 256 12350724Scg 12478362Scgminor = (unit << 20) + (dev << 16) + channel 12578362Scgcurrently minor = (channel << 16) + (unit << 4) + dev 12678362Scg 12778362Scgnomenclature: 12878362Scg /dev/pcmX/dsp.(0..255) 12978362Scg /dev/pcmX/dspW 13078362Scg /dev/pcmX/audio 13178362Scg /dev/pcmX/status 13278362Scg /dev/pcmX/mixer 13378362Scg [etc.] 13478362Scg*/ 13578362Scg 13678362Scg#define PCMMINOR(x) (minor(x)) 13778362Scg#define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16) 13878362Scg#define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4) 13978362Scg#define PCMDEV(x) (PCMMINOR(x) & 0x0000000f) 14078362Scg#define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f)) 14178362Scg 14250724Scg#define SD_F_SIMPLEX 0x00000001 14378853Scg#define SD_F_AUTOVCHAN 0x00000002 14450724Scg#define SD_F_PRIO_RD 0x10000000 14550724Scg#define SD_F_PRIO_WR 0x20000000 14650724Scg#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 14750724Scg#define SD_F_DIR_SET 0x40000000 14850724Scg#define SD_F_TRANSIENT 0xf0000000 14950724Scg 15050724Scg/* many variables should be reduced to a range. Here define a macro */ 15150724Scg#define RANGE(var, low, high) (var) = \ 15250724Scg (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 15355204Scg#define DSP_BUFFSIZE (8192) 15450724Scg 15550724Scg/* make figuring out what a format is easier. got AFMT_STEREO already */ 15665486Scg#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 15750724Scg#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 15868405Scg#define AFMT_8BIT (AFMT_U8 | AFMT_S8) 15950724Scg#define AFMT_SIGNED (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 16050724Scg#define AFMT_BIGENDIAN (AFMT_S16_BE | AFMT_U16_BE) 16150724Scg 16274763Scgstruct pcm_channel *fkchan_setup(device_t dev); 16374763Scgint fkchan_kill(struct pcm_channel *c); 16450724Scg 16550724Scg/* 16678362Scg * Major nuber for the sound driver. 16778362Scg */ 16878362Scg#define SND_CDEV_MAJOR 30 16978362Scg 17078853Scg#define SND_MAXVCHANS 255 17178853Scg 17278362Scg/* 17350724Scg * Minor numbers for the sound driver. 17450724Scg * 17550724Scg * Unfortunately Creative called the codec chip of SB as a DSP. For this 17650724Scg * reason the /dev/dsp is reserved for digitized audio use. There is a 17750724Scg * device for true DSP processors but it will be called something else. 17850724Scg * In v3.0 it's /dev/sndproc but this could be a temporary solution. 17950724Scg */ 18050724Scg 18150724Scg#define SND_DEV_CTL 0 /* Control port /dev/mixer */ 18250724Scg#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 18350724Scg#define SND_DEV_MIDIN 2 /* Raw midi access */ 18450724Scg#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 18550724Scg#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 18650724Scg#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 18750724Scg#define SND_DEV_STATUS 6 /* /dev/sndstat */ 18850724Scg /* #7 not in use now. */ 18950724Scg#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 19050724Scg#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 19150724Scg#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 19251769Scg#define SND_DEV_NORESET 10 19383089Scg#define SND_DEV_DSPREC 11 /* recording channels */ 19450724Scg 19550724Scg#define DSP_DEFAULT_SPEED 8000 19650724Scg 19750724Scg#define ON 1 19850724Scg#define OFF 0 19950724Scg 20089834Scgextern int pcm_veto_load; 20178362Scgextern int snd_unit; 20278362Scgextern devclass_t pcm_devclass; 20378362Scg 20450724Scg/* 20550724Scg * some macros for debugging purposes 20650724Scg * DDB/DEB to enable/disable debugging stuff 20750724Scg * BVDDB to enable debugging when bootverbose 20850724Scg */ 20950724Scg#define DDB(x) x /* XXX */ 21050724Scg#define BVDDB(x) if (bootverbose) x 21150724Scg 21250724Scg#ifndef DEB 21350724Scg#define DEB(x) 21450724Scg#endif 21550724Scg 21670617SjhbSYSCTL_DECL(_hw_snd); 21770617Sjhb 21882180Scgstruct sysctl_ctx_list *snd_sysctl_tree(device_t dev); 21982180Scgstruct sysctl_oid *snd_sysctl_tree_top(device_t dev); 22082180Scg 22182180Scgvoid pcm_lock(struct snddev_info *d); 22282180Scgvoid pcm_unlock(struct snddev_info *d); 22382180Scgstruct pcm_channel *pcm_getfakechan(struct snddev_info *d); 22483089Scgstruct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum); 22578214Scgint pcm_chnrelease(struct pcm_channel *c); 22677269Scgint pcm_chnref(struct pcm_channel *c, int ref); 22782180Scgint pcm_inprog(struct snddev_info *d, int delta); 22877269Scg 22977269Scgstruct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo); 23077269Scgint pcm_chn_destroy(struct pcm_channel *ch); 23178895Scgint pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch, int mkdev); 23278895Scgint pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch, int rmdev); 23377269Scg 23470134Scgint pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 23583614Scgunsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max); 23650724Scgint pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 23765340Scgint pcm_unregister(device_t dev); 23850724Scgint pcm_setstatus(device_t dev, char *str); 23950724Scgu_int32_t pcm_getflags(device_t dev); 24050724Scgvoid pcm_setflags(device_t dev, u_int32_t val); 24158384Scgvoid *pcm_getdevinfo(device_t dev); 24250724Scg 24373131Scgint snd_setup_intr(device_t dev, struct resource *res, int flags, 24473131Scg driver_intr_t hand, void *param, void **cookiep); 24573131Scg 24693814Sjhbvoid *snd_mtxcreate(const char *desc, const char *type); 24773131Scgvoid snd_mtxfree(void *m); 24873131Scgvoid snd_mtxassert(void *m); 24973131Scgvoid snd_mtxlock(void *m); 25073131Scgvoid snd_mtxunlock(void *m); 25150724Scg 25282180Scgint sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS); 25382180Scg 25482180Scgtypedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 25582180Scgint sndstat_register(device_t dev, char *str, sndstat_handler handler); 25682180Scgint sndstat_registerfile(char *str); 25782180Scgint sndstat_unregister(device_t dev); 25882180Scgint sndstat_unregisterfile(char *str); 25983476Sgreidint sndstat_busy(void); 26082180Scg 26182180Scg#define SND_DECLARE_FILE(version) \ 26282180Scg _SND_DECLARE_FILE(__LINE__, version) 26382180Scg 26482180Scg#define _SND_DECLARE_FILE(uniq, version) \ 26582180Scg __SND_DECLARE_FILE(uniq, version) 26682180Scg 26782180Scg#define __SND_DECLARE_FILE(uniq, version) \ 26882180Scg static char sndstat_vinfo[] = version; \ 26982180Scg SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ 27082180Scg SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); 27182180Scg 27250724Scg/* usage of flags in device config entry (config file) */ 27350724Scg#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 27450724Scg#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 27550724Scg 27650724Scg/* ought to be made obsolete */ 27750724Scg#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 27850724Scg#define DV_F_DEV_SHIFT 8 /* force device type/class */ 27982180Scg 28082180Scg#endif /* _KERNEL */ 28182180Scg 28282180Scg#endif /* _OS_H_ */ 283