Do a major clean-up of the BUSDMA architecture. A large number of
[dragonfly.git] / sys / dev / sound / pcm / sound.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
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.10.2.11 2002/04/22 15:49:36 cg Exp $
1f7ab7c9 28 * $DragonFly: src/sys/dev/sound/pcm/sound.h,v 1.9 2006/10/25 20:56:02 dillon 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>
984263bc
MD
57#include <sys/rman.h>
58#include <sys/mman.h>
59#include <sys/poll.h>
60#include <sys/sbuf.h>
61#include <sys/soundcard.h>
62#include <sys/sysctl.h>
1f7ab7c9 63#include <sys/kobj.h>
b6d92ffb 64#include <sys/thread2.h>
1f7ab7c9
MD
65
66#include <machine/clock.h> /* for DELAY */
67
1f2de5d4 68#include <bus/isa/isavar.h>
1f7ab7c9 69
984263bc
MD
70#include <vm/vm.h>
71#include <vm/pmap.h>
72
73#undef USING_MUTEX
74#undef USING_DEVFS
75
8cc1f625 76#if defined(__FreeBSD__) && __FreeBSD_version > 500000
984263bc
MD
77#define USING_MUTEX
78#define USING_DEVFS
79#endif
80
81#define SND_DYNSYSCTL
82
984263bc
MD
83struct pcm_channel;
84struct pcm_feeder;
85struct snd_dbuf;
86struct snd_mixer;
87
88#include <dev/sound/pcm/buffer.h>
89#include <dev/sound/pcm/channel.h>
90#include <dev/sound/pcm/feeder.h>
91#include <dev/sound/pcm/mixer.h>
92#include <dev/sound/pcm/dsp.h>
93
94#define PCM_SOFTC_SIZE 512
95
96#define SND_STATUSLEN 64
97/* descriptor of audio device */
984263bc
MD
98
99#define PCM_MODVER 1
100
101#define PCM_MINVER 1
102#define PCM_PREFVER PCM_MODVER
103#define PCM_MAXVER 1
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
124#define PCMMINOR(x) (minor(x))
125#define PCMCHAN(x) ((PCMMINOR(x) & 0x00ff0000) >> 16)
126#define PCMUNIT(x) ((PCMMINOR(x) & 0x000000f0) >> 4)
127#define PCMDEV(x) (PCMMINOR(x) & 0x0000000f)
128#define PCMMKMINOR(u, d, c) ((((c) & 0xff) << 16) | (((u) & 0x0f) << 4) | ((d) & 0x0f))
129
130#define SD_F_SIMPLEX 0x00000001
131#define SD_F_AUTOVCHAN 0x00000002
132#define SD_F_PRIO_RD 0x10000000
133#define SD_F_PRIO_WR 0x20000000
134#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
135#define SD_F_DIR_SET 0x40000000
136#define SD_F_TRANSIENT 0xf0000000
137
138/* many variables should be reduced to a range. Here define a macro */
139#define RANGE(var, low, high) (var) = \
140 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
141#define DSP_BUFFSIZE (8192)
142
143/* make figuring out what a format is easier. got AFMT_STEREO already */
144#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
145#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
146#define AFMT_8BIT (AFMT_U8 | AFMT_S8)
147#define AFMT_SIGNED (AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
148#define AFMT_BIGENDIAN (AFMT_S16_BE | AFMT_U16_BE)
149
150struct pcm_channel *fkchan_setup(device_t dev);
151int fkchan_kill(struct pcm_channel *c);
152
153/*
154 * Major nuber for the sound driver.
155 */
156#define SND_CDEV_MAJOR 30
157
158#define SND_MAXVCHANS 255
159
160/*
161 * Minor numbers for the sound driver.
162 *
163 * Unfortunately Creative called the codec chip of SB as a DSP. For this
164 * reason the /dev/dsp is reserved for digitized audio use. There is a
165 * device for true DSP processors but it will be called something else.
166 * In v3.0 it's /dev/sndproc but this could be a temporary solution.
167 */
168
169#define SND_DEV_CTL 0 /* Control port /dev/mixer */
170#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */
171#define SND_DEV_MIDIN 2 /* Raw midi access */
172#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */
173#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */
174#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */
175#define SND_DEV_STATUS 6 /* /dev/sndstat */
176 /* #7 not in use now. */
177#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */
178#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */
179#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */
180#define SND_DEV_NORESET 10
181#define SND_DEV_DSPREC 11 /* recording channels */
182
183#define DSP_DEFAULT_SPEED 8000
184
185#define ON 1
186#define OFF 0
187
188extern int pcm_veto_load;
189extern int snd_unit;
190extern devclass_t pcm_devclass;
191
192/*
193 * some macros for debugging purposes
194 * DDB/DEB to enable/disable debugging stuff
195 * BVDDB to enable debugging when bootverbose
196 */
197#define DDB(x) x /* XXX */
198#define BVDDB(x) if (bootverbose) x
199
200#ifndef DEB
201#define DEB(x)
202#endif
203
204SYSCTL_DECL(_hw_snd);
205
206struct sysctl_ctx_list *snd_sysctl_tree(device_t dev);
207struct sysctl_oid *snd_sysctl_tree_top(device_t dev);
208
209void pcm_lock(struct snddev_info *d);
210void pcm_unlock(struct snddev_info *d);
211struct pcm_channel *pcm_getfakechan(struct snddev_info *d);
212struct pcm_channel *pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum);
213int pcm_chnrelease(struct pcm_channel *c);
214int pcm_chnref(struct pcm_channel *c, int ref);
215int pcm_inprog(struct snddev_info *d, int delta);
216
217struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo);
218int pcm_chn_destroy(struct pcm_channel *ch);
219int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch, int mkdev);
220int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch, int rmdev);
221
222int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo);
223unsigned int pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max);
224int pcm_register(device_t dev, void *devinfo, int numplay, int numrec);
225int pcm_unregister(device_t dev);
226int pcm_setstatus(device_t dev, char *str);
227u_int32_t pcm_getflags(device_t dev);
228void pcm_setflags(device_t dev, u_int32_t val);
229void *pcm_getdevinfo(device_t dev);
230
231int snd_setup_intr(device_t dev, struct resource *res, int flags,
e9cb6d99
MD
232 driver_intr_t hand, void *param,
233 void **cookiep, lwkt_serialize_t serializer);
984263bc
MD
234
235void *snd_mtxcreate(const char *desc, const char *type);
236void snd_mtxfree(void *m);
237void snd_mtxassert(void *m);
238void snd_mtxlock(void *m);
239void snd_mtxunlock(void *m);
240
241int sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS);
242
243typedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose);
244int sndstat_register(device_t dev, char *str, sndstat_handler handler);
245int sndstat_registerfile(char *str);
246int sndstat_unregister(device_t dev);
247int sndstat_unregisterfile(char *str);
248int sndstat_busy(void);
249
250#define SND_DECLARE_FILE(version) \
251 _SND_DECLARE_FILE(__LINE__, version)
252
253#define _SND_DECLARE_FILE(uniq, version) \
254 __SND_DECLARE_FILE(uniq, version)
255
256#define __SND_DECLARE_FILE(uniq, version) \
257 static char sndstat_vinfo[] = version; \
258 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
259 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
260
261/* usage of flags in device config entry (config file) */
262#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */
263#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */
264
265/* ought to be made obsolete */
266#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */
267#define DV_F_DEV_SHIFT 8 /* force device type/class */
268
269#endif /* _KERNEL */
270
271#endif /* _OS_H_ */