Say hello to a sound system update from FreeBSD. This includes the long
[dragonfly.git] / sys / dev / sound / pcm / sound.h
CommitLineData
558a398b
SS
1/*-
2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
984263bc
MD
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 *
558a398b
SS
27 * $FreeBSD: src/sys/dev/sound/pcm/sound.h,v 1.63.2.2 2006/04/04 17:43:48 ariff Exp $
28 * $DragonFly: src/sys/dev/sound/pcm/sound.h,v 1.10 2007/01/04 21:47:03 corecode Exp $
984263bc
MD
29 */
30
31/*
32 * first, include kernel header files.
33 */
34
35#ifndef _OS_H_
36#define _OS_H_
37
38#ifdef _KERNEL
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/ioccom.h>
42#include <sys/filio.h>
43#include <sys/sockio.h>
44#include <sys/fcntl.h>
45#include <sys/tty.h>
46#include <sys/proc.h>
47#include <sys/kernel.h> /* for DATA_SET */
48#include <sys/module.h>
49#include <sys/conf.h>
50#include <sys/file.h>
51#include <sys/uio.h>
52#include <sys/syslog.h>
53#include <sys/errno.h>
54#include <sys/malloc.h>
55#include <sys/bus.h>
984263bc 56#include <sys/buf.h>
558a398b
SS
57#include <machine/clock.h> /* for DELAY */
58#include <sys/resource.h>
59#include <sys/bus.h>
984263bc
MD
60#include <sys/rman.h>
61#include <sys/mman.h>
62#include <sys/poll.h>
63#include <sys/sbuf.h>
64#include <sys/soundcard.h>
65#include <sys/sysctl.h>
1f7ab7c9 66#include <sys/kobj.h>
b6d92ffb 67#include <sys/thread2.h>
1f7ab7c9
MD
68
69#include <machine/clock.h> /* for DELAY */
70
984263bc
MD
71#include <vm/vm.h>
72#include <vm/pmap.h>
73
74#undef USING_MUTEX
75#undef USING_DEVFS
76
558a398b
SS
77#include <sys/spinlock.h>
78#include <sys/spinlock2.h>
79
984263bc 80#define USING_MUTEX
558a398b 81#define INTR_TYPE_AV 0
984263bc
MD
82
83#define SND_DYNSYSCTL
84
984263bc
MD
85struct pcm_channel;
86struct pcm_feeder;
87struct snd_dbuf;
88struct snd_mixer;
89
90#include <dev/sound/pcm/buffer.h>
91#include <dev/sound/pcm/channel.h>
92#include <dev/sound/pcm/feeder.h>
93#include <dev/sound/pcm/mixer.h>
984263bc
MD
94
95#define PCM_SOFTC_SIZE 512
96
97#define SND_STATUSLEN 64
984263bc 98
558a398b 99#define SOUND_MODVER 1
984263bc 100
558a398b
SS
101#define SOUND_MINVER 1
102#define SOUND_PREFVER SOUND_MODVER
103#define SOUND_MAXVER 1
984263bc
MD
104
105/*
106PROPOSAL:
107each unit needs:
108status, mixer, dsp, dspW, audio, sequencer, midi-in, seq2, sndproc = 9 devices
109dspW and audio are deprecated.
110dsp needs min 64 channels, will give it 256
111
112minor = (unit << 20) + (dev << 16) + channel
113currently minor = (channel << 16) + (unit << 4) + dev
114
115nomenclature:
116 /dev/pcmX/dsp.(0..255)
117 /dev/pcmX/dspW
118 /dev/pcmX/audio
119 /dev/pcmX/status
120 /dev/pcmX/mixer
121 [etc.]
122*/
123
558a398b
SS
124#define PCMMAXCHAN 0xff
125#define PCMMAXDEV 0x0f
126#define PCMMAXUNIT 0x0f
127#define PCMMINOR(x) (minor(x))
128#define PCMCHAN(x) ((PCMMINOR(x) >> 16) & PCMMAXCHAN)
129#define PCMUNIT(x) ((PCMMINOR(x) >> 4) & PCMMAXUNIT)
130#define PCMDEV(x) (PCMMINOR(x) & PCMMAXDEV)
131#define PCMMKMINOR(u, d, c) ((((c) & PCMMAXCHAN) << 16) | \
132 (((u) & PCMMAXUNIT) << 4) | ((d) & PCMMAXDEV))
984263bc
MD
133
134#define SD_F_SIMPLEX 0x00000001
558a398b
SS
135#define SD_F_AUTOVCHAN 0x00000002
136#define SD_F_SOFTVOL 0x00000004
984263bc
MD
137#define SD_F_PRIO_RD 0x10000000
138#define SD_F_PRIO_WR 0x20000000
139#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
140#define SD_F_DIR_SET 0x40000000
141#define SD_F_TRANSIENT 0xf0000000
142
143/* many variables should be reduced to a range. Here define a macro */
144#define RANGE(var, low, high) (var) = \
145 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
146#define DSP_BUFFSIZE (8192)
147
148/* make figuring out what a format is easier. got AFMT_STEREO already */
149#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
558a398b 150#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE)
984263bc 151#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
558a398b
SS
152#define AFMT_8BIT (AFMT_MU_LAW | AFMT_A_LAW | AFMT_U8 | AFMT_S8)
153#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \
154 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
155#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \
156 AFMT_S16_BE | AFMT_U16_BE)
984263bc
MD
157
158struct pcm_channel *fkchan_setup(device_t dev);
159int fkchan_kill(struct pcm_channel *c);
160
161/*
162 * Major nuber for the sound driver.
163 */
164#define SND_CDEV_MAJOR 30
165
558a398b
SS
166/* XXX Flawed definition. I'll fix it someday. */
167#define SND_MAXVCHANS PCMMAXCHAN
984263bc
MD
168
169/*
170 * Minor numbers for the sound driver.
171 *
172 * Unfortunately Creative called the codec chip of SB as a DSP. For this
173 * reason the /dev/dsp is reserved for digitized audio use. There is a
174 * device for true DSP processors but it will be called something else.
175 * In v3.0 it's /dev/sndproc but this could be a temporary solution.
176 */
177
178#define SND_DEV_CTL 0 /* Control port /dev/mixer */
179#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */
180#define SND_DEV_MIDIN 2 /* Raw midi access */
181#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
182#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
183#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
184#define SND_DEV_STATUS 6 /* /dev/sndstat */
185 /* #7 not in use now. */
186#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
187#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
188#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */
189#define SND_DEV_NORESET 10
190#define SND_DEV_DSPREC 11 /* recording channels */
191
192#define DSP_DEFAULT_SPEED 8000
193
194#define ON 1
195#define OFF 0
196
197extern int pcm_veto_load;
198extern int snd_unit;
199extern devclass_t pcm_devclass;
200
201/*
202 * some macros for debugging purposes
203 * DDB/DEB to enable/disable debugging stuff
204 * BVDDB to enable debugging when bootverbose
205 */
984263bc
MD
206#define BVDDB(x) if (bootverbose) x
207
208#ifndef DEB
209#define DEB(x)
210#endif
211
212SYSCTL_DECL(_hw_snd);
213
214struct sysctl_ctx_list *snd_sysctl_tree(device_t dev);
215struct sysctl_oid *snd_sysctl_tree_top(device_t dev);
216
984263bc 217struct pcm_channel *pcm_getfakechan(struct snddev_info *d);
558a398b 218int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, int chnum);
984263bc
MD
219int pcm_chnrelease(struct pcm_channel *c);
220int pcm_chnref(struct pcm_channel *c, int ref);
221int pcm_inprog(struct snddev_info *d, int delta);
222
223struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
224int pcm_chn_destroy(struct pcm_channel *ch);
558a398b
SS
225int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);
226int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch);
984263bc
MD
227
228int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
229unsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max);
230int pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
231int pcm_unregister(device_t dev);
232int pcm_setstatus(device_t dev, char *str);
233u_int32_t pcm_getflags(device_t dev);
234void pcm_setflags(device_t dev, u_int32_t val);
235void *pcm_getdevinfo(device_t dev);
236
558a398b 237
984263bc 238int snd_setup_intr(device_t dev, struct resource *res, int flags,
558a398b 239 driver_intr_t hand, void *param, void **cookiep);
984263bc
MD
240
241void *snd_mtxcreate(const char *desc, const char *type);
242void snd_mtxfree(void *m);
243void snd_mtxassert(void *m);
558a398b
SS
244#define snd_mtxlock(m) spin_lock_wr(m)
245#define snd_mtxunlock(m) spin_unlock_wr(m)
984263bc
MD
246
247int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
248
249typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
558a398b
SS
250int sndstat_acquire(void);
251int sndstat_release(void);
984263bc
MD
252int sndstat_register(device_t dev, char *str, sndstat_handler handler);
253int sndstat_registerfile(char *str);
254int sndstat_unregister(device_t dev);
255int sndstat_unregisterfile(char *str);
984263bc
MD
256
257#define SND_DECLARE_FILE(version) \
258 _SND_DECLARE_FILE(__LINE__, version)
259
260#define _SND_DECLARE_FILE(uniq, version) \
261 __SND_DECLARE_FILE(uniq, version)
262
263#define __SND_DECLARE_FILE(uniq, version) \
264 static char sndstat_vinfo[] = version; \
265 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
266 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
267
268/* usage of flags in device config entry (config file) */
269#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */
270#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */
271
558a398b 272/* ought to be made obsolete but still used by mss */
984263bc
MD
273#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */
274#define DV_F_DEV_SHIFT 8 /* force device type/class */
275
558a398b
SS
276#define PCM_DEBUG_MTX
277
278/*
279 * this is rather kludgey- we need to duplicate these struct def'ns from sound.c
280 * so that the macro versions of pcm_{,un}lock can dereference them.
281 * we also have to do this now makedev() has gone away.
282 */
283
284struct snddev_channel {
285 SLIST_ENTRY(snddev_channel) link;
286 struct pcm_channel *channel;
287 int chan_num;
288 struct cdev *dsp_devt;
289 struct cdev *dspW_devt;
290 struct cdev *audio_devt;
291 struct cdev *dspr_devt;
292};
293
294struct snddev_info {
295 SLIST_HEAD(, snddev_channel) channels;
296 struct pcm_channel *fakechan;
297 unsigned devcount, playcount, reccount, vchancount;
298 unsigned flags;
299 int inprog;
300 unsigned int bufsz;
301 void *devinfo;
302 device_t dev;
303 char status[SND_STATUSLEN];
304 struct sysctl_ctx_list sysctl_tree;
305 struct sysctl_oid *sysctl_tree_top;
306 struct spinlock *lock;
307 struct cdev *mixer_dev;
308
309};
310
311#ifdef PCM_DEBUG_MTX
312#define pcm_lock(d) spin_lock_wr(((struct snddev_info *)(d))->lock)
313#define pcm_unlock(d) spin_unlock_wr(((struct snddev_info *)(d))->lock)
314#else
315void pcm_lock(struct snddev_info *d);
316void pcm_unlock(struct snddev_info *d);
317#endif
318
319#ifdef KLD_MODULE
320#define PCM_KLDSTRING(a) ("kld " # a)
321#else
322#define PCM_KLDSTRING(a) ""
323#endif
324
984263bc
MD
325#endif /* _KERNEL */
326
327#endif /* _OS_H_ */