2 * sound/oss/dev_table.c
7 * Copyright (C) by Hannu Savolainen 1993-1997
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
14 #include <linux/init.h>
16 #include "sound_config.h"
18 struct audio_operations *audio_devs[MAX_AUDIO_DEV];
19 EXPORT_SYMBOL(audio_devs);
22 EXPORT_SYMBOL(num_audiodevs);
24 struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
25 EXPORT_SYMBOL(mixer_devs);
28 EXPORT_SYMBOL(num_mixers);
30 struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
31 EXPORT_SYMBOL(synth_devs);
35 struct midi_operations *midi_devs[MAX_MIDI_DEV];
36 EXPORT_SYMBOL(midi_devs);
39 EXPORT_SYMBOL(num_midis);
41 struct sound_timer_operations *sound_timer_devs[MAX_TIMER_DEV] = {
42 &default_sound_timer, NULL
44 EXPORT_SYMBOL(sound_timer_devs);
46 int num_sound_timers = 1;
49 static int sound_alloc_audiodev(void);
51 int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
52 int driver_size, int flags, unsigned int format_mask,
53 void *devc, int dma1, int dma2)
55 struct audio_driver *d;
56 struct audio_operations *op;
59 if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
60 printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
63 num = sound_alloc_audiodev();
66 printk(KERN_ERR "sound: Too many audio drivers\n");
69 d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));
71 if (sound_nblocks >= MAX_MEM_BLOCKS)
72 sound_nblocks = MAX_MEM_BLOCKS - 1;
74 op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations)));
76 if (sound_nblocks >= MAX_MEM_BLOCKS)
77 sound_nblocks = MAX_MEM_BLOCKS - 1;
79 if (d == NULL || op == NULL) {
80 printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
81 sound_unload_audiodev(num);
84 memset((char *) op, 0, sizeof(struct audio_operations));
85 init_waitqueue_head(&op->in_sleeper);
86 init_waitqueue_head(&op->out_sleeper);
87 init_waitqueue_head(&op->poll_sleeper);
88 if (driver_size < sizeof(struct audio_driver))
89 memset((char *) d, 0, sizeof(struct audio_driver));
91 memcpy((char *) d, (char *) driver, driver_size);
94 strlcpy(op->name, name, sizeof(op->name));
96 op->format_mask = format_mask;
102 audio_devs[num] = op;
104 DMAbuf_init(num, dma1, dma2);
106 audio_init_devices();
109 EXPORT_SYMBOL(sound_install_audiodrv);
111 int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
112 int driver_size, void *devc)
114 struct mixer_operations *op;
116 int n = sound_alloc_mixerdev();
119 printk(KERN_ERR "Sound: Too many mixer drivers\n");
122 if (vers != MIXER_DRIVER_VERSION ||
123 driver_size > sizeof(struct mixer_operations)) {
124 printk(KERN_ERR "Sound: Incompatible mixer driver for %s\n", name);
128 /* FIXME: This leaks a mixer_operations struct every time its called
129 until you unload sound! */
131 op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations)));
133 if (sound_nblocks >= MAX_MEM_BLOCKS)
134 sound_nblocks = MAX_MEM_BLOCKS - 1;
137 printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
140 memset((char *) op, 0, sizeof(struct mixer_operations));
141 memcpy((char *) op, (char *) driver, driver_size);
143 strlcpy(op->name, name, sizeof(op->name));
149 EXPORT_SYMBOL(sound_install_mixer);
151 void sound_unload_audiodev(int dev)
155 audio_devs[dev] = NULL;
156 unregister_sound_dsp((dev<<4)+3);
159 EXPORT_SYMBOL(sound_unload_audiodev);
161 static int sound_alloc_audiodev(void)
163 int i = register_sound_dsp(&oss_sound_fops, -1);
168 num_audiodevs = i + 1;
172 int sound_alloc_mididev(void)
174 int i = register_sound_midi(&oss_sound_fops, -1);
182 EXPORT_SYMBOL(sound_alloc_mididev);
184 int sound_alloc_synthdev(void)
188 for (i = 0; i < MAX_SYNTH_DEV; i++) {
189 if (synth_devs[i] == NULL) {
197 EXPORT_SYMBOL(sound_alloc_synthdev);
199 int sound_alloc_mixerdev(void)
201 int i = register_sound_mixer(&oss_sound_fops, -1);
209 EXPORT_SYMBOL(sound_alloc_mixerdev);
211 int sound_alloc_timerdev(void)
215 for (i = 0; i < MAX_TIMER_DEV; i++) {
216 if (sound_timer_devs[i] == NULL) {
217 if (i >= num_sound_timers)
224 EXPORT_SYMBOL(sound_alloc_timerdev);
226 void sound_unload_mixerdev(int dev)
229 mixer_devs[dev] = NULL;
230 unregister_sound_mixer(dev<<4);
234 EXPORT_SYMBOL(sound_unload_mixerdev);
236 void sound_unload_mididev(int dev)
239 midi_devs[dev] = NULL;
240 unregister_sound_midi((dev<<4)+2);
243 EXPORT_SYMBOL(sound_unload_mididev);
245 void sound_unload_synthdev(int dev)
248 synth_devs[dev] = NULL;
250 EXPORT_SYMBOL(sound_unload_synthdev);
252 void sound_unload_timerdev(int dev)
255 sound_timer_devs[dev] = NULL;
257 EXPORT_SYMBOL(sound_unload_timerdev);