sound.h revision 83476
129415Sjmg/*
2119853Scg * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
339899Sluigi * Copyright by Hannu Savolainen 1995
429415Sjmg * All rights reserved.
529415Sjmg *
629415Sjmg * Redistribution and use in source and binary forms, with or without
729415Sjmg * modification, are permitted provided that the following conditions
850723Scg * are met:
950723Scg * 1. Redistributions of source code must retain the above copyright
1029415Sjmg *    notice, this list of conditions and the following disclaimer.
1129415Sjmg * 2. Redistributions in binary form must reproduce the above copyright
1230869Sjmg *    notice, this list of conditions and the following disclaimer in the
1330869Sjmg *    documentation and/or other materials provided with the distribution.
1430869Sjmg *
1530869Sjmg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1650723Scg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1750723Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1830869Sjmg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1950723Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2050723Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2150723Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2250723Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2350723Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2450723Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2550723Scg * SUCH DAMAGE.
2650723Scg *
2750723Scg * $FreeBSD: head/sys/dev/sound/pcm/sound.h 83476 2001-09-14 20:26:03Z greid $
2850723Scg */
2950723Scg
3029415Sjmg/*
3129415Sjmg * first, include kernel header files.
3253465Scg */
3329415Sjmg
3453465Scg#ifndef _OS_H_
3553553Stanimura#define _OS_H_
3629415Sjmg
37110499Snyan#ifdef _KERNEL
38110499Snyan#include <sys/param.h>
3970134Scg#include <sys/systm.h>
4070134Scg#include <sys/ioccom.h>
4182180Scg#include <sys/filio.h>
4282180Scg#include <sys/sockio.h>
4367803Scg#include <sys/fcntl.h>
4455706Scg#include <sys/tty.h>
4555254Scg#include <sys/proc.h>
4667803Scg#include <sys/kernel.h> /* for DATA_SET */
4750723Scg#include <sys/module.h>
4850723Scg#include <sys/conf.h>
4964881Scg#include <sys/file.h>
5050723Scg#include <sys/uio.h>
5174763Scg#include <sys/syslog.h>
5229415Sjmg#include <sys/errno.h>
5367803Scg#include <sys/malloc.h>
5464881Scg#include <sys/bus.h>
5550723Scg#if __FreeBSD_version > 500000
5664881Scg#include <sys/bio.h>
5750723Scg#endif
5874763Scg#include <sys/buf.h>
5929415Sjmg#include <machine/clock.h>	/* for DELAY */
6064881Scg#include <machine/resource.h>
6164881Scg#include <machine/bus.h>
6264881Scg#include <sys/rman.h>
6364881Scg#include <sys/mman.h>
6464881Scg#include <sys/poll.h>
6564881Scg#include <sys/sbuf.h>
6654462Scg#include <sys/soundcard.h>
6774763Scg#include <sys/sysctl.h>
6854462Scg#include <isa/isavar.h>
6950723Scg#include <sys/kobj.h>
7029415Sjmg#include <vm/vm.h>
7150723Scg#include <vm/pmap.h>
7250723Scg
7374763Scg#undef	USING_MUTEX
7474763Scg#undef	USING_DEVFS
7567803Scg
7667803Scg#if __FreeBSD_version > 500000
7750723Scg#define USING_MUTEX
7829415Sjmg#define USING_DEVFS
7950723Scg#endif
8050723Scg
8150723Scg#define SND_DYNSYSCTL
8254462Scg
8354462Scg#ifndef	INTR_MPSAFE
8465644Scg#define	INTR_TYPE_AV	INTR_TYPE_TTY
8555706Scg#endif
8629415Sjmg
8784111Scg#ifndef	INTR_MPSAFE
8850723Scg#define	INTR_MPSAFE	0
8950723Scg#endif
9070291Scg
9150723Scgstruct pcm_channel;
9274763Scgstruct pcm_feeder;
9350723Scgstruct snd_dbuf;
9450723Scgstruct snd_mixer;
9584111Scg
9674763Scg#include <dev/sound/pcm/buffer.h>
9774763Scg#include <dev/sound/pcm/channel.h>
9850723Scg#include <dev/sound/pcm/feeder.h>
9950723Scg#include <dev/sound/pcm/mixer.h>
10050723Scg#include <dev/sound/pcm/dsp.h>
10167803Scg
10250723Scg#define	PCM_SOFTC_SIZE	512
10350723Scg
10450723Scg#define SND_STATUSLEN	64
10550723Scg/* descriptor of audio device */
10654462Scg#ifndef ISADMA_WRITE
10729415Sjmg#define ISADMA_WRITE B_WRITE
10850723Scg#define ISADMA_READ B_READ
10984111Scg#define ISADMA_RAW B_RAW
11050723Scg#endif
11129415Sjmg
11250723Scg#define PCM_MODVER	1
11329415Sjmg
11450723Scg#define PCM_MINVER	1
11550723Scg#define PCM_PREFVER	PCM_MODVER
11650723Scg#define PCM_MAXVER	1
11750723Scg
11829415Sjmg/*
11929415SjmgPROPOSAL:
12084111Scgeach unit needs:
12184111Scgstatus, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices
12284111ScgdspW and audio are deprecated.
12384111Scgdsp needs min 64 channels, will give it 256
12484111Scg
12584111Scgminor = (unit << 20) + (dev << 16) + channel
12684111Scgcurrently minor = (channel << 16) + (unit << 4) + dev
12784111Scg
12884111Scgnomenclature:
12984111Scg	/dev/pcmX/dsp.(0..255)
13084111Scg	/dev/pcmX/dspW
13184111Scg	/dev/pcmX/audio
13229415Sjmg	/dev/pcmX/status
13350723Scg	/dev/pcmX/mixer
13429415Sjmg	[etc.]
13567803Scg*/
13650723Scg
13729415Sjmg#define PCMMINOR(x) (minor(x))
13850723Scg#define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16)
13950723Scg#define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4)
14050723Scg#define PCMDEV(x)   (PCMMINOR(x) & 0x0000000f)
141108064Ssemenu#define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))
14229415Sjmg
14329415Sjmg#define SD_F_SIMPLEX		0x00000001
14429415Sjmg#define	SD_F_AUTOVCHAN		0x00000002
14550723Scg#define SD_F_PRIO_RD		0x10000000
14629415Sjmg#define SD_F_PRIO_WR		0x20000000
14750723Scg#define SD_F_PRIO_SET		(SD_F_PRIO_RD | SD_F_PRIO_WR)
14850723Scg#define SD_F_DIR_SET		0x40000000
14929415Sjmg#define SD_F_TRANSIENT		0xf0000000
15050723Scg
15150723Scg/* many variables should be reduced to a range. Here define a macro */
15250723Scg#define RANGE(var, low, high) (var) = \
15350723Scg	(((var)<(low))? (low) : ((var)>(high))? (high) : (var))
15429415Sjmg#define DSP_BUFFSIZE (8192)
15529415Sjmg
15650723Scg/* make figuring out what a format is easier. got AFMT_STEREO already */
15750723Scg#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
15829415Sjmg#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
15950723Scg#define AFMT_8BIT (AFMT_U8 | AFMT_S8)
16029415Sjmg#define AFMT_SIGNED (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
16150723Scg#define AFMT_BIGENDIAN (AFMT_S16_BE | AFMT_U16_BE)
16270134Scg
16370134Scgstruct pcm_channel *fkchan_setup(device_t dev);
16470134Scgint fkchan_kill(struct pcm_channel *c);
16570134Scg
16670134Scg/*
16750723Scg * Major nuber for the sound driver.
16850723Scg */
16979116Sgreen#define SND_CDEV_MAJOR 30
17083366Sjulian
17174797Scg#define	SND_MAXVCHANS	255
17279090Sgreen
17350723Scg/*
17450723Scg * Minor numbers for the sound driver.
17529415Sjmg *
17650723Scg * Unfortunately Creative called the codec chip of SB as a DSP. For this
17750723Scg * reason the /dev/dsp is reserved for digitized audio use. There is a
17850723Scg * device for true DSP processors but it will be called something else.
17950723Scg * In v3.0 it's /dev/sndproc but this could be a temporary solution.
18050723Scg */
18150723Scg
18250723Scg#define SND_DEV_CTL	0	/* Control port /dev/mixer */
18350723Scg#define SND_DEV_SEQ	1	/* Sequencer /dev/sequencer */
18429415Sjmg#define SND_DEV_MIDIN	2	/* Raw midi access */
18567803Scg#define SND_DEV_DSP	3	/* Digitized voice /dev/dsp */
18650723Scg#define SND_DEV_AUDIO	4	/* Sparc compatible /dev/audio */
18750723Scg#define SND_DEV_DSP16	5	/* Like /dev/dsp but 16 bits/sample */
18850723Scg#define SND_DEV_STATUS	6	/* /dev/sndstat */
18950723Scg				/* #7 not in use now. */
19050723Scg#define SND_DEV_SEQ2	8	/* /dev/sequencer, level 2 interface */
19150723Scg#define SND_DEV_SNDPROC 9	/* /dev/sndproc for programmable devices */
19250723Scg#define SND_DEV_PSS	SND_DEV_SNDPROC /* ? */
19350723Scg#define SND_DEV_NORESET	10
19450723Scg#define	SND_DEV_DSPREC	11	/* recording channels */
19550723Scg
19667803Scg#define DSP_DEFAULT_SPEED	8000
19729415Sjmg
19850723Scg#define ON		1
19950723Scg#define OFF		0
20050723Scg
20184111Scgextern int snd_unit;
20284111Scgextern devclass_t pcm_devclass;
20350723Scg
20450723Scg/*
20550723Scg * some macros for debugging purposes
20684111Scg * DDB/DEB to enable/disable debugging stuff
20784111Scg * BVDDB   to enable debugging when bootverbose
20850723Scg */
20984111Scg#define DDB(x)	x	/* XXX */
21084111Scg#define BVDDB(x) if (bootverbose) x
21184111Scg
21284111Scg#ifndef DEB
21384111Scg#define DEB(x)
21484111Scg#endif
21584111Scg
21684111ScgSYSCTL_DECL(_hw_snd);
21784111Scg
21850723Scgstruct sysctl_ctx_list *snd_sysctl_tree(device_t dev);
21929415Sjmgstruct sysctl_oid *snd_sysctl_tree_top(device_t dev);
22050723Scg
22150723Scgvoid pcm_lock(struct snddev_info *d);
22250723Scgvoid pcm_unlock(struct snddev_info *d);
22350723Scgstruct pcm_channel *pcm_getfakechan(struct snddev_info *d);
22450723Scgstruct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum);
22550723Scgint pcm_chnrelease(struct pcm_channel *c);
22650723Scgint pcm_chnref(struct pcm_channel *c, int ref);
22774763Scgint pcm_inprog(struct snddev_info *d, int delta);
22850723Scg
22950723Scgstruct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
23050723Scgint pcm_chn_destroy(struct pcm_channel *ch);
23150723Scgint pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch, int mkdev);
23274763Scgint pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch, int rmdev);
23350723Scg
23431361Sjmgint pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
23550723Scgint pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
23650723Scgint pcm_unregister(device_t dev);
23750723Scgint pcm_setstatus(device_t dev, char *str);
23850723Scgu_int32_t pcm_getflags(device_t dev);
23929415Sjmgvoid pcm_setflags(device_t dev, u_int32_t val);
24074763Scgvoid *pcm_getdevinfo(device_t dev);
24150723Scg
24250723Scgint snd_setup_intr(device_t dev, struct resource *res, int flags,
24350723Scg		   driver_intr_t hand, void *param, void **cookiep);
24450723Scg
24574763Scgvoid *snd_mtxcreate(const char *desc);
24629415Sjmgvoid snd_mtxfree(void *m);
24750723Scgvoid snd_mtxassert(void *m);
24850723Scgvoid snd_mtxlock(void *m);
24929415Sjmgvoid snd_mtxunlock(void *m);
25050723Scg
25150723Scgint sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
25250723Scg
25350723Scgtypedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
25429415Sjmgint sndstat_register(device_t dev, char *str, sndstat_handler handler);
25550723Scgint sndstat_registerfile(char *str);
25650723Scgint sndstat_unregister(device_t dev);
25750723Scgint sndstat_unregisterfile(char *str);
25850723Scgint sndstat_busy(void);
25950723Scg
26050723Scg#define SND_DECLARE_FILE(version) \
26150723Scg	_SND_DECLARE_FILE(__LINE__, version)
26250723Scg
26329415Sjmg#define _SND_DECLARE_FILE(uniq, version) \
26450723Scg	__SND_DECLARE_FILE(uniq, version)
26550723Scg
26629415Sjmg#define __SND_DECLARE_FILE(uniq, version) \
26774763Scg	static char sndstat_vinfo[] = version; \
26874763Scg	SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
26974763Scg	SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
27050723Scg
27150723Scg/* usage of flags in device config entry (config file) */
27250723Scg#define DV_F_DRQ_MASK	0x00000007	/* mask for secondary drq */
27374763Scg#define	DV_F_DUAL_DMA	0x00000010	/* set to use secondary dma channel */
27474763Scg
27574763Scg/* ought to be made obsolete */
27650723Scg#define	DV_F_DEV_MASK	0x0000ff00	/* force device type/class */
27789774Sscottl#define	DV_F_DEV_SHIFT	8		/* force device type/class */
27850723Scg
27950723Scg#endif /* _KERNEL */
28050723Scg
28129415Sjmg#endif	/* _OS_H_ */
28229415Sjmg