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