4 * The system call switch
6 * Copyright by Hannu Savolainen 1993
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met: 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 2.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <i386/isa/sound/sound_config.h>
34 #define SNDSTAT_BUF_SIZE 4000
37 * /dev/sndstatus -device
39 static char *status_buf = NULL;
40 static int status_len, status_ptr;
41 static int status_busy = 0;
48 if (status_len + l >= SNDSTAT_BUF_SIZE)
51 bcopy(s, &status_buf[status_len], l);
58 * in principle, we never overflow the buffer. But... if radix=2 ...
59 * and if smaller... lr970711
63 put_status_int(u_int val, int radix)
66 static char hx[] = "0123456789abcdef";
67 char buf[33]; /* int is 32 bit+null, in base 2 */
69 if (radix < 2 || radix > 16) /* better than panic */
70 return put_status("???");
73 return put_status("0");
86 if (status_len + l >= SNDSTAT_BUF_SIZE)
89 bcopy(&buf[10 - l], &status_buf[status_len], l);
99 * Write the status information to the status_buf and update
100 * status_len. There is a limit of SNDSTAT_BUF_SIZE bytes for the data.
101 * put_status handles this and returns 0 in case of failure. Since
102 * it never oveflows the buffer, we do not care to check.
110 put_status("VoxWare Sound Driver:" SOUND_VERSION_STRING
111 " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY ",\n"
112 SOUND_UNAME_A ")\n");
114 put_status("VoxWare Sound Driver:" SOUND_VERSION_STRING
115 " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY "@"
116 SOUND_CONFIG_HOST "." SOUND_CONFIG_DOMAIN ")\n");
119 put_status("Config options: ") ;
120 /* put_status_int(SELECTED_SOUND_OPTIONS, 16) ; */
121 put_status("\n\nInstalled drivers: \n") ;
123 for (i = 0; i < num_sound_drivers; i++)
124 if (sound_drivers[i].card_type != 0) {
125 put_status("Type ") ;
126 put_status_int(sound_drivers[i].card_type, 10);
128 put_status(sound_drivers[i].name) ;
131 put_status("\n\nCard config: \n") ;
133 for (i = 0; i < num_sound_cards; i++)
134 if (snd_installed_cards[i].card_type != 0) {
137 if (!snd_installed_cards[i].enabled)
140 if ((drv = snd_find_driver(snd_installed_cards[i].card_type)) != -1)
141 put_status(sound_drivers[drv].name) ;
143 put_status(" at 0x") ;
144 put_status_int(snd_installed_cards[i].config.io_base, 16);
146 put_status(" irq ") ;
147 tmp = snd_installed_cards[i].config.irq;
150 put_status_int(tmp, 10) ;
152 if (snd_installed_cards[i].config.dma != -1) {
153 put_status(" drq ") ;
154 put_status_int(snd_installed_cards[i].config.dma, 10) ;
155 if (snd_installed_cards[i].config.dma2 != -1) {
157 put_status_int(snd_installed_cards[i].config.dma2, 10) ;
160 if (!snd_installed_cards[i].enabled)
165 if (!sound_started) {
166 put_status("\n\n***** Sound driver not started *****\n\n");
170 put_status("\nAudio devices: NOT ENABLED IN CONFIG\n") ;
172 put_status("\nAudio devices:\n") ;
174 for (i = 0; i < num_audiodevs; i++) {
175 put_status_int(i, 10) ;
177 put_status(audio_devs[i]->name) ;
179 if (audio_devs[i]->flags & DMA_DUPLEX)
180 put_status(" (DUPLEX)") ;
186 #ifndef CONFIG_SEQUENCER
187 put_status("\nSynth devices: NOT ENABLED IN CONFIG\n");
189 put_status("\nSynth devices:\n") ;
191 for (i = 0; i < num_synths; i++) {
192 put_status_int(i, 10) ;
194 put_status(synth_devs[i]->info->name) ;
200 put_status("\nMidi devices: NOT ENABLED IN CONFIG\n") ;
202 put_status("\nMidi devices:\n") ;
204 for (i = 0; i < num_midis; i++) {
205 put_status_int(i, 10) ;
207 put_status(midi_devs[i]->info.name) ;
212 put_status("\nTimers:\n");
214 for (i = 0; i < num_sound_timers; i++) {
215 put_status_int(i, 10);
217 put_status(sound_timer_devs[i]->info.name);
221 put_status("\nMixers:\n");
223 for (i = 0; i < num_mixers; i++) {
224 put_status_int(i, 10);
226 put_status(mixer_devs[i]->name);
232 read_status(snd_rw_buf * buf, int count)
235 * Return at most 'count' bytes from the status_buf.
240 c = status_len - status_ptr;
248 if (uiomove(&status_buf[status_ptr], l, buf)) {
249 printf("sb: Bad copyout()!\n");
257 sound_read_sw(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
259 DEB(printf("sound_read_sw(dev=%d, count=%d)\n", dev, count));
261 switch (dev & 0x0f) {
263 return read_status(buf, count);
270 return audio_read(dev, file, buf, count);
274 #ifdef CONFIG_SEQUENCER
277 return sequencer_read(dev, file, buf, count);
283 return MIDIbuf_read(dev, file, buf, count);
287 printf("Sound: Undefined minor device %d\n", dev);
294 sound_write_sw(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
297 DEB(printf("sound_write_sw(dev=%d, count=%d)\n", dev, count));
299 switch (dev & 0x0f) {
301 #ifdef CONFIG_SEQUENCER
304 return sequencer_write(dev, file, buf, count);
312 return audio_write(dev, file, buf, count);
318 return MIDIbuf_write(dev, file, buf, count);
329 sound_open_sw(int dev, struct fileinfo * file)
333 DEB(printf("sound_open_sw(dev=%d)\n", dev));
335 if ((dev >= SND_NDEVS) || (dev < 0)) {
336 printf("Invalid minor device %d\n", dev);
339 switch (dev & 0x0f) {
344 if ((status_buf = (char *) malloc(SNDSTAT_BUF_SIZE, M_TEMP, M_WAITOK)) == NULL)
346 status_len = status_ptr = 0;
354 #ifdef CONFIG_SEQUENCER
357 if ((retval = sequencer_open(dev, file)) < 0)
364 if ((retval = MIDIbuf_open(dev, file)) < 0)
373 if ((retval = audio_open(dev, file)) < 0)
379 printf("Invalid minor device %d\n", dev);
387 sound_release_sw(int dev, struct fileinfo * file)
390 DEB(printf("sound_release_sw(dev=%d)\n", dev));
392 switch (dev & 0x0f) {
395 free(status_buf, M_TEMP);
403 #ifdef CONFIG_SEQUENCER
406 sequencer_release(dev, file);
412 MIDIbuf_release(dev, file);
420 audio_release(dev, file);
425 printf("Sound error: Releasing unknown device 0x%02x\n", dev);
430 sound_ioctl_sw(int dev, struct fileinfo * file, u_int cmd, ioctl_arg arg)
432 DEB(printf("sound_ioctl_sw(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
434 if (((cmd >> 8) & 0xff) == 'M' && num_mixers > 0) /* Mixer ioctl */
435 if ((dev & 0x0f) != SND_DEV_CTL) {
436 int dtype = dev & 0x0f;
444 mixdev = audio_devs[dev >> 4]->mixer_dev;
445 if (mixdev < 0 || mixdev >= num_mixers)
447 return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
452 return mixer_devs[0]->ioctl(0, cmd, arg);
455 switch (dev & 0x0f) {
464 if (dev >= num_mixers)
467 return mixer_devs[dev]->ioctl(dev, cmd, arg);
470 #ifdef CONFIG_SEQUENCER
473 return sequencer_ioctl(dev, file, cmd, arg);
481 return audio_ioctl(dev, file, cmd, arg);
487 return MIDIbuf_ioctl(dev, file, cmd, arg);