sound.h revision 119853
1321936Shselasky/*
2321936Shselasky * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3321936Shselasky * Copyright by Hannu Savolainen 1995
4321936Shselasky * All rights reserved.
5321936Shselasky *
6321936Shselasky * Redistribution and use in source and binary forms, with or without
7321936Shselasky * modification, are permitted provided that the following conditions
8321936Shselasky * are met:
9321936Shselasky * 1. Redistributions of source code must retain the above copyright
10321936Shselasky *    notice, this list of conditions and the following disclaimer.
11321936Shselasky * 2. Redistributions in binary form must reproduce the above copyright
12321936Shselasky *    notice, this list of conditions and the following disclaimer in the
13321936Shselasky *    documentation and/or other materials provided with the distribution.
14321936Shselasky *
15321936Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16321936Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17321936Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18321936Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19321936Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20321936Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21321936Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22321936Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23321936Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24321936Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25321936Shselasky * SUCH DAMAGE.
26321936Shselasky *
27321936Shselasky * $FreeBSD: head/sys/dev/sound/pcm/sound.h 119853 2003-09-07 16:28:03Z cg $
28321936Shselasky */
29321936Shselasky
30321936Shselasky/*
31321936Shselasky * first, include kernel header files.
32321936Shselasky */
33321936Shselasky
34321936Shselasky#ifndef _OS_H_
35321936Shselasky#define _OS_H_
36321936Shselasky
37321936Shselasky#ifdef _KERNEL
38321936Shselasky#include <sys/param.h>
39321936Shselasky#include <sys/systm.h>
40321936Shselasky#include <sys/ioccom.h>
41321936Shselasky#include <sys/filio.h>
42321936Shselasky#include <sys/sockio.h>
43321936Shselasky#include <sys/fcntl.h>
44321936Shselasky#include <sys/tty.h>
45321936Shselasky#include <sys/proc.h>
46321936Shselasky#include <sys/kernel.h> /* for DATA_SET */
47321936Shselasky#include <sys/module.h>
48321936Shselasky#include <sys/conf.h>
49321936Shselasky#include <sys/file.h>
50321936Shselasky#include <sys/uio.h>
51321936Shselasky#include <sys/syslog.h>
52321936Shselasky#include <sys/errno.h>
53321936Shselasky#include <sys/malloc.h>
54321936Shselasky#include <sys/bus.h>
55321936Shselasky#if __FreeBSD_version < 500000
56321936Shselasky#include <sys/buf.h>
57321936Shselasky#endif
58321936Shselasky#include <machine/clock.h>	/* for DELAY */
59321936Shselasky#include <machine/resource.h>
60321936Shselasky#include <machine/bus.h>
61321936Shselasky#include <sys/rman.h>
62321936Shselasky#include <sys/mman.h>
63321936Shselasky#include <sys/poll.h>
64321936Shselasky#include <sys/sbuf.h>
65321936Shselasky#include <sys/soundcard.h>
66321936Shselasky#include <sys/sysctl.h>
67321936Shselasky#include <sys/kobj.h>
68321936Shselasky#include <vm/vm.h>
69321936Shselasky#include <vm/pmap.h>
70321936Shselasky
71321936Shselasky#undef	USING_MUTEX
72321936Shselasky#undef	USING_DEVFS
73321936Shselasky
74321936Shselasky#if __FreeBSD_version > 500000
75321936Shselasky#include <sys/lock.h>
76321936Shselasky#include <sys/mutex.h>
77321936Shselasky
78321936Shselasky#define USING_MUTEX
79321936Shselasky#define USING_DEVFS
80321936Shselasky#endif
81321936Shselasky
82321936Shselasky#define SND_DYNSYSCTL
83321936Shselasky
84321936Shselasky#ifndef	INTR_MPSAFE
85321936Shselasky#define	INTR_TYPE_AV	INTR_TYPE_TTY
86321936Shselasky#endif
87321936Shselasky
88321936Shselasky#ifndef	INTR_MPSAFE
89321936Shselasky#define	INTR_MPSAFE	0
90321936Shselasky#endif
91321936Shselasky
92321936Shselaskystruct pcm_channel;
93321936Shselaskystruct pcm_feeder;
94321936Shselaskystruct snd_dbuf;
95321936Shselaskystruct snd_mixer;
96321936Shselasky
97321936Shselasky#include <dev/sound/pcm/buffer.h>
98321936Shselasky#include <dev/sound/pcm/channel.h>
99329568Shselasky#include <dev/sound/pcm/feeder.h>
100329568Shselasky#include <dev/sound/pcm/mixer.h>
101329568Shselasky#include <dev/sound/pcm/dsp.h>
102329568Shselasky
103329568Shselasky#define	PCM_SOFTC_SIZE	512
104329568Shselasky
105329568Shselasky#define SND_STATUSLEN	64
106329568Shselasky
107321936Shselasky#define PCM_MODVER	1
108321936Shselasky
109321936Shselasky#define PCM_MINVER	1
110321936Shselasky#define PCM_PREFVER	PCM_MODVER
111321936Shselasky#define PCM_MAXVER	1
112321936Shselasky
113321936Shselasky/*
114321936ShselaskyPROPOSAL:
115321936Shselaskyeach unit needs:
116321936Shselaskystatus, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices
117321936ShselaskydspW and audio are deprecated.
118321936Shselaskydsp needs min 64 channels, will give it 256
119321936Shselasky
120321936Shselaskyminor = (unit << 20) + (dev << 16) + channel
121321936Shselaskycurrently minor = (channel << 16) + (unit << 4) + dev
122321936Shselasky
123321936Shselaskynomenclature:
124321936Shselasky	/dev/pcmX/dsp.(0..255)
125321936Shselasky	/dev/pcmX/dspW
126321936Shselasky	/dev/pcmX/audio
127321936Shselasky	/dev/pcmX/status
128321936Shselasky	/dev/pcmX/mixer
129321936Shselasky	[etc.]
130321936Shselasky*/
131321936Shselasky
132321936Shselasky#define PCMMINOR(x) (minor(x))
133321936Shselasky#define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16)
134321936Shselasky#define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4)
135321936Shselasky#define PCMDEV(x)   (PCMMINOR(x) & 0x0000000f)
136321936Shselasky#define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))
137321936Shselasky
138321936Shselasky#define SD_F_SIMPLEX		0x00000001
139329568Shselasky#define	SD_F_AUTOVCHAN		0x00000002
140329568Shselasky#define SD_F_PRIO_RD		0x10000000
141329568Shselasky#define SD_F_PRIO_WR		0x20000000
142329568Shselasky#define SD_F_PRIO_SET		(SD_F_PRIO_RD | SD_F_PRIO_WR)
143321936Shselasky#define SD_F_DIR_SET		0x40000000
144321936Shselasky#define SD_F_TRANSIENT		0xf0000000
145321936Shselasky
146321936Shselasky/* many variables should be reduced to a range. Here define a macro */
147321936Shselasky#define RANGE(var, low, high) (var) = \
148321936Shselasky	(((var)<(low))? (low) : ((var)>(high))? (high) : (var))
149321936Shselasky#define DSP_BUFFSIZE (8192)
150321936Shselasky
151321936Shselasky/* make figuring out what a format is easier. got AFMT_STEREO already */
152321936Shselasky#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
153321936Shselasky#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
154321936Shselasky#define AFMT_8BIT (AFMT_U8 | AFMT_S8)
155321936Shselasky#define AFMT_SIGNED (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
156321936Shselasky#define AFMT_BIGENDIAN (AFMT_S16_BE | AFMT_U16_BE)
157321936Shselasky
158321936Shselaskystruct pcm_channel *fkchan_setup(device_t dev);
159321936Shselaskyint fkchan_kill(struct pcm_channel *c);
160321936Shselasky
161321936Shselasky/*
162321936Shselasky * Major nuber for the sound driver.
163321936Shselasky */
164321936Shselasky#define SND_CDEV_MAJOR 30
165321936Shselasky
166321936Shselasky#define	SND_MAXVCHANS	255
167321936Shselasky
168321936Shselasky/*
169321936Shselasky * Minor numbers for the sound driver.
170321936Shselasky *
171321936Shselasky * Unfortunately Creative called the codec chip of SB as a DSP. For this
172321936Shselasky * reason the /dev/dsp is reserved for digitized audio use. There is a
173321936Shselasky * device for true DSP processors but it will be called something else.
174321936Shselasky * In v3.0 it's /dev/sndproc but this could be a temporary solution.
175321936Shselasky */
176321936Shselasky
177321936Shselasky#define SND_DEV_CTL	0	/* Control port /dev/mixer */
178321936Shselasky#define SND_DEV_SEQ	1	/* Sequencer /dev/sequencer */
179321936Shselasky#define SND_DEV_MIDIN	2	/* Raw midi access */
180321936Shselasky#define SND_DEV_DSP	3	/* Digitized voice /dev/dsp */
181321936Shselasky#define SND_DEV_AUDIO	4	/* Sparc compatible /dev/audio */
182321936Shselasky#define SND_DEV_DSP16	5	/* Like /dev/dsp but 16 bits/sample */
183321936Shselasky#define SND_DEV_STATUS	6	/* /dev/sndstat */
184321936Shselasky				/* #7 not in use now. */
185321936Shselasky#define SND_DEV_SEQ2	8	/* /dev/sequencer, level 2 interface */
186321936Shselasky#define SND_DEV_SNDPROC 9	/* /dev/sndproc for programmable devices */
187321936Shselasky#define SND_DEV_PSS	SND_DEV_SNDPROC /* ? */
188321936Shselasky#define SND_DEV_NORESET	10
189321936Shselasky#define	SND_DEV_DSPREC	11	/* recording channels */
190321936Shselasky
191321936Shselasky#define DSP_DEFAULT_SPEED	8000
192321936Shselasky
193321936Shselasky#define ON		1
194321936Shselasky#define OFF		0
195321936Shselasky
196321936Shselaskyextern int pcm_veto_load;
197321936Shselaskyextern int snd_unit;
198321936Shselaskyextern devclass_t pcm_devclass;
199321936Shselasky
200321936Shselasky/*
201321936Shselasky * some macros for debugging purposes
202321936Shselasky * DDB/DEB to enable/disable debugging stuff
203321936Shselasky * BVDDB   to enable debugging when bootverbose
204321936Shselasky */
205321936Shselasky#define DDB(x)	x	/* XXX */
206321936Shselasky#define BVDDB(x) if (bootverbose) x
207329568Shselasky
208329568Shselasky#ifndef DEB
209329568Shselasky#define DEB(x)
210329568Shselasky#endif
211321936Shselasky
212321936ShselaskySYSCTL_DECL(_hw_snd);
213321936Shselasky
214321936Shselaskystruct sysctl_ctx_list *snd_sysctl_tree(device_t dev);
215321936Shselaskystruct sysctl_oid *snd_sysctl_tree_top(device_t dev);
216321936Shselasky
217321936Shselaskystruct pcm_channel *pcm_getfakechan(struct snddev_info *d);
218321936Shselaskystruct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum);
219321936Shselaskyint pcm_chnrelease(struct pcm_channel *c);
220321936Shselaskyint pcm_chnref(struct pcm_channel *c, int ref);
221321936Shselaskyint pcm_inprog(struct snddev_info *d, int delta);
222321936Shselasky
223321936Shselaskystruct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
224321936Shselaskyint pcm_chn_destroy(struct pcm_channel *ch);
225321936Shselaskyint pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch, int mkdev);
226321936Shselaskyint pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch, int rmdev);
227321936Shselasky
228321936Shselaskyint pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
229321936Shselaskyunsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max);
230321936Shselaskyint pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
231321936Shselaskyint pcm_unregister(device_t dev);
232321936Shselaskyint pcm_setstatus(device_t dev, char *str);
233321936Shselaskyu_int32_t pcm_getflags(device_t dev);
234321936Shselaskyvoid pcm_setflags(device_t dev, u_int32_t val);
235321936Shselaskyvoid *pcm_getdevinfo(device_t dev);
236321936Shselasky
237321936Shselaskyint snd_setup_intr(device_t dev, struct resource *res, int flags,
238321936Shselasky		   driver_intr_t hand, void *param, void **cookiep);
239321936Shselasky
240321936Shselaskyvoid *snd_mtxcreate(const char *desc, const char *type);
241321936Shselaskyvoid snd_mtxfree(void *m);
242321936Shselaskyvoid snd_mtxassert(void *m);
243321936Shselasky#define	snd_mtxlock(m) mtx_lock(m)
244321936Shselasky#define	snd_mtxunlock(m) mtx_unlock(m)
245321936Shselasky
246321936Shselaskyint sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
247321936Shselasky
248321936Shselaskytypedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
249321936Shselaskyint sndstat_register(device_t dev, char *str, sndstat_handler handler);
250321936Shselaskyint sndstat_registerfile(char *str);
251321936Shselaskyint sndstat_unregister(device_t dev);
252321936Shselaskyint sndstat_unregisterfile(char *str);
253321936Shselaskyint sndstat_busy(void);
254321936Shselasky
255321936Shselasky#define SND_DECLARE_FILE(version) \
256321936Shselasky	_SND_DECLARE_FILE(__LINE__, version)
257321936Shselasky
258321936Shselasky#define _SND_DECLARE_FILE(uniq, version) \
259321936Shselasky	__SND_DECLARE_FILE(uniq, version)
260321936Shselasky
261321936Shselasky#define __SND_DECLARE_FILE(uniq, version) \
262321936Shselasky	static char sndstat_vinfo[] = version; \
263321936Shselasky	SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
264321936Shselasky	SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
265321936Shselasky
266321936Shselasky/* usage of flags in device config entry (config file) */
267321936Shselasky#define DV_F_DRQ_MASK	0x00000007	/* mask for secondary drq */
268321936Shselasky#define	DV_F_DUAL_DMA	0x00000010	/* set to use secondary dma channel */
269321936Shselasky
270321936Shselasky/* ought to be made obsolete but still used by mss */
271321936Shselasky#define	DV_F_DEV_MASK	0x0000ff00	/* force device type/class */
272321936Shselasky#define	DV_F_DEV_SHIFT	8		/* force device type/class */
273321936Shselasky
274321936Shselasky#define	PCM_DEBUG_MTX
275321936Shselasky
276321936Shselasky/*
277321936Shselasky * this is rather kludgey- we need to duplicate these struct def'ns from sound.c
278 * so that the macro versions of pcm_{,un}lock can dereference them.
279 */
280
281#ifdef	PCM_DEBUG_MTX
282struct snddev_channel {
283	SLIST_ENTRY(snddev_channel) link;
284	struct pcm_channel *channel;
285};
286
287struct snddev_info {
288	SLIST_HEAD(, snddev_channel) channels;
289	struct pcm_channel *fakechan;
290	unsigned devcount, playcount, reccount, vchancount;
291	unsigned flags;
292	int inprog;
293	unsigned int bufsz;
294	void *devinfo;
295	device_t dev;
296	char status[SND_STATUSLEN];
297	struct sysctl_ctx_list sysctl_tree;
298	struct sysctl_oid *sysctl_tree_top;
299	struct mtx *lock;
300};
301
302#define	pcm_lock(d) mtx_lock(((struct snddev_info *)(d))->lock)
303#define	pcm_unlock(d) mtx_unlock(((struct snddev_info *)(d))->lock)
304#else
305void pcm_lock(struct snddev_info *d);
306void pcm_unlock(struct snddev_info *d);
307#endif
308
309#endif /* _KERNEL */
310
311#endif	/* _OS_H_ */
312