Merge branch 'vendor/OPENPAM'
[dragonfly.git] / sys / dev / sound / pcm / sound.h
1 /*-
2  * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3  * Copyright by Hannu Savolainen 1995
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/sys/dev/sound/pcm/sound.h,v 1.63.2.3 2007/05/13 20:53:39 ariff Exp $
28  */
29
30 /*
31  * first, include kernel header files.
32  */
33
34 #ifndef _OS_H_
35 #define _OS_H_
36
37 #ifdef _KERNEL
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/filio.h>
41 #include <sys/sockio.h>
42 #include <sys/fcntl.h>
43 #include <sys/tty.h>
44 #include <sys/proc.h>
45 #include <sys/kernel.h> /* for DATA_SET */
46 #include <sys/module.h>
47 #include <sys/conf.h>
48 #include <sys/file.h>
49 #include <sys/uio.h>
50 #include <sys/syslog.h>
51 #include <sys/errno.h>
52 #include <sys/malloc.h>
53 #include <sys/bus.h>
54 #include <sys/buf.h>
55 #include <machine/clock.h>      /* for DELAY */
56 #include <sys/resource.h>
57 #include <sys/bus.h>
58 #include <sys/rman.h>
59 #include <sys/mman.h>
60 #include <sys/poll.h>
61 #include <sys/sbuf.h>
62 #include <sys/soundcard.h>
63 #include <sys/sysctl.h>
64 #include <sys/kobj.h>
65 #include <sys/thread2.h>
66 #include <sys/taskqueue.h>
67
68 #include <machine/clock.h>      /* for DELAY */
69
70 #include <vm/vm.h>
71 #include <vm/pmap.h>
72
73 #undef  USING_MUTEX
74 #undef  USING_DEVFS
75
76 #include <sys/lock.h>           /* lockmgr locks */
77 typedef struct lock *sndlock_t; /* opaque lock structure */
78
79 #define USING_MUTEX
80 #define INTR_TYPE_AV    0
81
82 #define SND_DYNSYSCTL
83
84 struct pcm_channel;
85 struct pcm_feeder;
86 struct snd_dbuf;
87 struct snd_mixer;
88
89 #include <dev/sound/pcm/buffer.h>
90 #include <dev/sound/pcm/channel.h>
91 #include <dev/sound/pcm/feeder.h>
92 #include <dev/sound/pcm/mixer.h>
93
94 #define PCM_SOFTC_SIZE  512
95
96 #define SND_STATUSLEN   64
97
98 #define SOUND_MODVER    1
99
100 #define SOUND_MINVER    1
101 #define SOUND_PREFVER   SOUND_MODVER
102 #define SOUND_MAXVER    1
103
104 /*
105 minor = (channel << 16) + unit
106
107 nomenclature:
108         /dev/sndtat
109         /dev/mixerX
110         /dev/dspX
111         /dev/dspX.Y (cloned channels)
112 */
113
114 #define PCMMAXCHAN              0xffff
115 #define PCMMAXUNIT              0xff
116 #define PCMMINOR(x)             (minor(x))
117 #define PCMCHAN(x)              ((PCMMINOR(x) >> 16) & PCMMAXCHAN)
118 #define PCMUNIT(x)              (PCMMINOR(x) & PCMMAXUNIT)
119 #define PCMMKMINOR(u, c)        ((((c) & PCMMAXCHAN) << 16) | ((u) & PCMMAXUNIT))
120
121 #define SD_F_SIMPLEX            0x00000001
122 #define SD_F_AUTOVCHAN          0x00000002
123 #define SD_F_SOFTPCMVOL         0x00000004
124 #define SD_F_PRIO_RD            0x10000000
125 #define SD_F_PRIO_WR            0x20000000
126 #define SD_F_PRIO_SET           (SD_F_PRIO_RD | SD_F_PRIO_WR)
127 #define SD_F_DIR_SET            0x40000000
128 #define SD_F_TRANSIENT          0xf0000000
129
130 /* many variables should be reduced to a range. Here define a macro */
131 #define RANGE(var, low, high) (var) = \
132         (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
133 #define DSP_BUFFSIZE (8192)
134
135 /* make figuring out what a format is easier. got AFMT_STEREO already */
136 #define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
137 #define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE)
138 #define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
139 #define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8)
140 #define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \
141                         AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
142 #define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \
143                         AFMT_S16_BE | AFMT_U16_BE)
144
145 struct pcm_channel *fkchan_setup(device_t dev);
146 int fkchan_kill(struct pcm_channel *c);
147
148 /* XXX Flawed definition. I'll fix it someday. */
149 #define SND_MAXVCHANS   PCMMAXCHAN
150
151 /*
152  * Minor numbers for the sound driver.
153  *
154  * Unfortunately Creative called the codec chip of SB as a DSP. For this
155  * reason the /dev/dsp is reserved for digitized audio use. There is a
156  * device for true DSP processors but it will be called something else.
157  * In v3.0 it's /dev/sndproc but this could be a temporary solution.
158  */
159
160 #define SND_DEV_CTL     0       /* Control port /dev/mixer */
161 #define SND_DEV_SEQ     1       /* Sequencer /dev/sequencer */
162 #define SND_DEV_MIDIN   2       /* Raw midi access */
163 #define SND_DEV_DSP     3       /* Digitized voice /dev/dsp */
164 #define SND_DEV_STATUS  6       /* /dev/sndstat */
165                                 /* #7 not in use now. */
166 #define SND_DEV_SEQ2    8       /* /dev/sequencer, level 2 interface */
167 #define SND_DEV_SNDPROC 9       /* /dev/sndproc for programmable devices */
168 #define SND_DEV_PSS     SND_DEV_SNDPROC /* ? */
169 #define SND_DEV_NORESET 10
170 #define SND_DEV_DSPREC  11      /* recording channels */
171
172 #define DSP_DEFAULT_SPEED       8000
173
174 #define ON              1
175 #define OFF             0
176
177 extern int pcm_veto_load;
178 extern int snd_maxautovchans;
179 extern devclass_t pcm_devclass;
180
181 /*
182  * some macros for debugging purposes
183  * DDB/DEB to enable/disable debugging stuff
184  * BVDDB   to enable debugging when bootverbose
185  */
186 #define BVDDB(x) if (bootverbose) x
187
188 #ifndef DEB
189 #define DEB(x)
190 #endif
191
192 SYSCTL_DECL(_hw_snd);
193
194 struct sysctl_ctx_list *snd_sysctl_tree(device_t dev);
195 struct sysctl_oid *snd_sysctl_tree_top(device_t dev);
196
197 struct pcm_channel *pcm_getfakechan(struct snddev_info *d);
198 int pcm_setvchans(struct snddev_info *d, int newcnt);
199 int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int chnum);
200 int pcm_chnrelease(struct pcm_channel *c);
201 int pcm_chnref(struct pcm_channel *c, int ref);
202 int pcm_inprog(struct snddev_info *d, int delta);
203
204 struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
205 struct pcm_channel *pcm_chn_iterate(struct snddev_info *d, void **cookie);
206 int pcm_chn_destroy(struct pcm_channel *ch);
207 int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);
208 int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch);
209
210 int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
211 unsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max);
212 int pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
213 int pcm_unregister(device_t dev);
214 int pcm_setstatus(device_t dev, char *str);
215 u_int32_t pcm_getflags(device_t dev);
216 void pcm_setflags(device_t dev, u_int32_t val);
217 void *pcm_getdevinfo(device_t dev);
218
219
220 int snd_setup_intr(device_t dev, struct resource *res, int flags,
221                    driver_intr_t hand, void *param, void **cookiep);
222
223 void *snd_mtxcreate(const char *desc, const char *type);
224 void snd_mtxfree(void *m);
225 void snd_mtxassert(void *m);
226 void snd_mtxlock(void *m);
227 void snd_mtxunlock(void *m);
228 int snd_mtxsleep(void *, sndlock_t, int, const char *, int);
229
230 int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
231
232 typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
233 int sndstat_acquire(void);
234 int sndstat_release(void);
235 int sndstat_register(device_t dev, char *str, sndstat_handler handler);
236 int sndstat_registerfile(char *str);
237 int sndstat_unregister(device_t dev);
238 int sndstat_unregisterfile(char *str);
239
240 #define SND_DECLARE_FILE(version) \
241         _SND_DECLARE_FILE(__LINE__, version)
242
243 #define _SND_DECLARE_FILE(uniq, version) \
244         __SND_DECLARE_FILE(uniq, version)
245
246 #define __SND_DECLARE_FILE(uniq, version) \
247         static char sndstat_vinfo[] = version; \
248         SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
249         SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
250
251 /* usage of flags in device config entry (config file) */
252 #define DV_F_DRQ_MASK   0x00000007      /* mask for secondary drq */
253 #define DV_F_DUAL_DMA   0x00000010      /* set to use secondary dma channel */
254
255 /* ought to be made obsolete but still used by mss */
256 #define DV_F_DEV_MASK   0x0000ff00      /* force device type/class */
257 #define DV_F_DEV_SHIFT  8               /* force device type/class */
258
259 #define PCM_DEBUG_MTX
260
261 /*
262  * this is rather kludgey- we need to duplicate these struct def'ns from sound.c
263  * so that the macro versions of pcm_{,un}lock can dereference them.
264  * we also have to do this now makedev() has gone away.
265  */
266
267 struct snddev_channel {
268         SLIST_ENTRY(snddev_channel) link;
269         struct pcm_channel *channel;
270         int chan_num;
271         struct cdev *dsp_dev;
272         int open;
273 };
274
275 struct snddev_info {
276         SLIST_HEAD(, snddev_channel) channels;
277         struct pcm_channel *fakechan;
278         unsigned devcount, playcount, reccount, vchancount;
279         unsigned flags;
280         int inprog;
281         unsigned int bufsz;
282         void *devinfo;
283         device_t dev;
284         char status[SND_STATUSLEN];
285         struct sysctl_ctx_list sysctl_tree;
286         struct sysctl_oid *sysctl_tree_top;
287         sndlock_t       lock;
288         struct cdev *mixer_dev;
289         struct cdev *dsp_clonedev;
290 };
291
292 #ifdef  PCM_DEBUG_MTX
293 #define pcm_lock(d) snd_mtxlock(((struct snddev_info *)(d))->lock)
294 #define pcm_unlock(d) snd_mtxunlock(((struct snddev_info *)(d))->lock)
295 #else
296 void pcm_lock(struct snddev_info *d);
297 void pcm_unlock(struct snddev_info *d);
298 #endif
299
300 #ifdef KLD_MODULE
301 #define PCM_KLDSTRING(a) ("kld " # a)
302 #else
303 #define PCM_KLDSTRING(a) ""
304 #endif
305
306 #endif /* _KERNEL */
307
308 #endif  /* _OS_H_ */