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
28 * $DragonFly: src/sys/dev/sound/isa/i386/Attic/sound_switch.c,v 1.2 2003/08/07 21:17:12 dillon Exp $
31 #include "sound_config.h"
35 #define SNDSTAT_BUF_SIZE 4000
38 * /dev/sndstatus -device
40 static char *status_buf = NULL;
41 static int status_len, status_ptr;
42 static int status_busy = 0;
49 if (status_len + l >= SNDSTAT_BUF_SIZE)
52 bcopy(s, &status_buf[status_len], l);
59 * in principle, we never overflow the buffer. But... if radix=2 ...
60 * and if smaller... lr970711
64 put_status_int(u_int val, int radix)
67 static char hx[] = "0123456789abcdef";
68 char buf[33]; /* int is 32 bit+null, in base 2 */
70 if (radix < 2 || radix > 16) /* better than panic */
71 return put_status("???");
74 return put_status("0");
87 if (status_len + l >= SNDSTAT_BUF_SIZE)
90 bcopy(&buf[10 - l], &status_buf[status_len], l);
100 * Write the status information to the status_buf and update
101 * status_len. There is a limit of SNDSTAT_BUF_SIZE bytes for the data.
102 * put_status handles this and returns 0 in case of failure. Since
103 * it never oveflows the buffer, we do not care to check.
111 put_status("VoxWare Sound Driver:" SOUND_VERSION_STRING
112 " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY ",\n"
113 SOUND_UNAME_A ")\n");
115 put_status("VoxWare Sound Driver:" SOUND_VERSION_STRING
116 " (" SOUND_CONFIG_DATE " " SOUND_CONFIG_BY "@"
117 SOUND_CONFIG_HOST "." SOUND_CONFIG_DOMAIN ")\n");
120 put_status("Config options: ") ;
121 /* put_status_int(SELECTED_SOUND_OPTIONS, 16) ; */
122 put_status("\n\nInstalled drivers: \n") ;
124 for (i = 0; i < num_sound_drivers; i++)
125 if (sound_drivers[i].card_type != 0) {
126 put_status("Type ") ;
127 put_status_int(sound_drivers[i].card_type, 10);
129 put_status(sound_drivers[i].name) ;
132 put_status("\n\nCard config: \n") ;
134 for (i = 0; i < num_sound_cards; i++)
135 if (snd_installed_cards[i].card_type != 0) {
138 if (!snd_installed_cards[i].enabled)
141 if ((drv = snd_find_driver(snd_installed_cards[i].card_type)) != -1)
142 put_status(sound_drivers[drv].name) ;
144 put_status(" at 0x") ;
145 put_status_int(snd_installed_cards[i].config.io_base, 16);
147 put_status(" irq ") ;
148 tmp = snd_installed_cards[i].config.irq;
151 put_status_int(tmp, 10) ;
153 if (snd_installed_cards[i].config.dma != -1) {
154 put_status(" drq ") ;
155 put_status_int(snd_installed_cards[i].config.dma, 10) ;
156 if (snd_installed_cards[i].config.dma2 != -1) {
158 put_status_int(snd_installed_cards[i].config.dma2, 10) ;
161 if (!snd_installed_cards[i].enabled)
166 if (!sound_started) {
167 put_status("\n\n***** Sound driver not started *****\n\n");
171 put_status("\nAudio devices: NOT ENABLED IN CONFIG\n") ;
173 put_status("\nAudio devices:\n") ;
175 for (i = 0; i < num_audiodevs; i++) {
176 put_status_int(i, 10) ;
178 put_status(audio_devs[i]->name) ;
180 if (audio_devs[i]->flags & DMA_DUPLEX)
181 put_status(" (DUPLEX)") ;
187 #ifndef CONFIG_SEQUENCER
188 put_status("\nSynth devices: NOT ENABLED IN CONFIG\n");
190 put_status("\nSynth devices:\n") ;
192 for (i = 0; i < num_synths; i++) {
193 put_status_int(i, 10) ;
195 put_status(synth_devs[i]->info->name) ;
201 put_status("\nMidi devices: NOT ENABLED IN CONFIG\n") ;
203 put_status("\nMidi devices:\n") ;
205 for (i = 0; i < num_midis; i++) {
206 put_status_int(i, 10) ;
208 put_status(midi_devs[i]->info.name) ;
213 put_status("\nTimers:\n");
215 for (i = 0; i < num_sound_timers; i++) {
216 put_status_int(i, 10);
218 put_status(sound_timer_devs[i]->info.name);
222 put_status("\nMixers:\n");
224 for (i = 0; i < num_mixers; i++) {
225 put_status_int(i, 10);
227 put_status(mixer_devs[i]->name);
233 read_status(snd_rw_buf * buf, int count)
236 * Return at most 'count' bytes from the status_buf.
241 c = status_len - status_ptr;
249 if (uiomove(&status_buf[status_ptr], l, buf)) {
250 printf("sb: Bad copyout()!\n");
258 sound_read_sw(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
260 DEB(printf("sound_read_sw(dev=%d, count=%d)\n", dev, count));
262 switch (dev & 0x0f) {
264 return read_status(buf, count);
271 return audio_read(dev, file, buf, count);
275 #ifdef CONFIG_SEQUENCER
278 return sequencer_read(dev, file, buf, count);
284 return MIDIbuf_read(dev, file, buf, count);
288 printf("Sound: Undefined minor device %d\n", dev);
295 sound_write_sw(int dev, struct fileinfo * file, snd_rw_buf * buf, int count)
298 DEB(printf("sound_write_sw(dev=%d, count=%d)\n", dev, count));
300 switch (dev & 0x0f) {
302 #ifdef CONFIG_SEQUENCER
305 return sequencer_write(dev, file, buf, count);
313 return audio_write(dev, file, buf, count);
319 return MIDIbuf_write(dev, file, buf, count);
330 sound_open_sw(int dev, struct fileinfo * file)
334 DEB(printf("sound_open_sw(dev=%d)\n", dev));
336 if ((dev >= SND_NDEVS) || (dev < 0)) {
337 printf("Invalid minor device %d\n", dev);
340 switch (dev & 0x0f) {
345 if ((status_buf = (char *) malloc(SNDSTAT_BUF_SIZE, M_TEMP, M_WAITOK)) == NULL)
347 status_len = status_ptr = 0;
355 #ifdef CONFIG_SEQUENCER
358 if ((retval = sequencer_open(dev, file)) < 0)
365 if ((retval = MIDIbuf_open(dev, file)) < 0)
374 if ((retval = audio_open(dev, file)) < 0)
380 printf("Invalid minor device %d\n", dev);
388 sound_release_sw(int dev, struct fileinfo * file)
391 DEB(printf("sound_release_sw(dev=%d)\n", dev));
393 switch (dev & 0x0f) {
396 free(status_buf, M_TEMP);
404 #ifdef CONFIG_SEQUENCER
407 sequencer_release(dev, file);
413 MIDIbuf_release(dev, file);
421 audio_release(dev, file);
426 printf("Sound error: Releasing unknown device 0x%02x\n", dev);
431 sound_ioctl_sw(int dev, struct fileinfo * file, u_int cmd, ioctl_arg arg)
433 DEB(printf("sound_ioctl_sw(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
435 if (((cmd >> 8) & 0xff) == 'M' && num_mixers > 0) /* Mixer ioctl */
436 if ((dev & 0x0f) != SND_DEV_CTL) {
437 int dtype = dev & 0x0f;
445 mixdev = audio_devs[dev >> 4]->mixer_dev;
446 if (mixdev < 0 || mixdev >= num_mixers)
448 return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
453 return mixer_devs[0]->ioctl(0, cmd, arg);
456 switch (dev & 0x0f) {
465 if (dev >= num_mixers)
468 return mixer_devs[dev]->ioctl(dev, cmd, arg);
471 #ifdef CONFIG_SEQUENCER
474 return sequencer_ioctl(dev, file, cmd, arg);
482 return audio_ioctl(dev, file, cmd, arg);
488 return MIDIbuf_ioctl(dev, file, cmd, arg);