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>
17 #include "sound_config.h"
19 static int sound_alloc_audiodev(void);
21 int sound_install_audiodrv(int vers
, char *name
, struct audio_driver
*driver
,
22 int driver_size
, int flags
, unsigned int format_mask
,
23 void *devc
, int dma1
, int dma2
)
25 struct audio_driver
*d
;
26 struct audio_operations
*op
;
29 if (vers
!= AUDIO_DRIVER_VERSION
|| driver_size
> sizeof(struct audio_driver
)) {
30 printk(KERN_ERR
"Sound: Incompatible audio driver for %s\n", name
);
33 num
= sound_alloc_audiodev();
36 printk(KERN_ERR
"sound: Too many audio drivers\n");
39 d
= (struct audio_driver
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct audio_driver
)));
41 if (sound_nblocks
< 1024)
44 op
= (struct audio_operations
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct audio_operations
)));
46 if (sound_nblocks
< 1024)
48 if (d
== NULL
|| op
== NULL
) {
49 printk(KERN_ERR
"Sound: Can't allocate driver for (%s)\n", name
);
50 sound_unload_audiodev(num
);
53 memset((char *) op
, 0, sizeof(struct audio_operations
));
54 init_waitqueue_head(&op
->in_sleeper
);
55 init_waitqueue_head(&op
->out_sleeper
);
56 init_waitqueue_head(&op
->poll_sleeper
);
57 if (driver_size
< sizeof(struct audio_driver
))
58 memset((char *) d
, 0, sizeof(struct audio_driver
));
60 memcpy((char *) d
, (char *) driver
, driver_size
);
63 strlcpy(op
->name
, name
, sizeof(op
->name
));
65 op
->format_mask
= format_mask
;
73 DMAbuf_init(num
, dma1
, dma2
);
79 int sound_install_mixer(int vers
, char *name
, struct mixer_operations
*driver
,
80 int driver_size
, void *devc
)
82 struct mixer_operations
*op
;
84 int n
= sound_alloc_mixerdev();
87 printk(KERN_ERR
"Sound: Too many mixer drivers\n");
90 if (vers
!= MIXER_DRIVER_VERSION
||
91 driver_size
> sizeof(struct mixer_operations
)) {
92 printk(KERN_ERR
"Sound: Incompatible mixer driver for %s\n", name
);
96 /* FIXME: This leaks a mixer_operations struct every time its called
97 until you unload sound! */
99 op
= (struct mixer_operations
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct mixer_operations
)));
101 if (sound_nblocks
< 1024)
104 printk(KERN_ERR
"Sound: Can't allocate mixer driver for (%s)\n", name
);
107 memset((char *) op
, 0, sizeof(struct mixer_operations
));
108 memcpy((char *) op
, (char *) driver
, driver_size
);
110 strlcpy(op
->name
, name
, sizeof(op
->name
));
117 void sound_unload_audiodev(int dev
)
121 audio_devs
[dev
] = NULL
;
122 unregister_sound_dsp((dev
<<4)+3);
126 static int sound_alloc_audiodev(void)
128 int i
= register_sound_dsp(&oss_sound_fops
, -1);
133 num_audiodevs
= i
+ 1;
137 int sound_alloc_mididev(void)
139 int i
= register_sound_midi(&oss_sound_fops
, -1);
148 int sound_alloc_synthdev(void)
152 for (i
= 0; i
< MAX_SYNTH_DEV
; i
++) {
153 if (synth_devs
[i
] == NULL
) {
162 int sound_alloc_mixerdev(void)
164 int i
= register_sound_mixer(&oss_sound_fops
, -1);
173 int sound_alloc_timerdev(void)
177 for (i
= 0; i
< MAX_TIMER_DEV
; i
++) {
178 if (sound_timer_devs
[i
] == NULL
) {
179 if (i
>= num_sound_timers
)
187 void sound_unload_mixerdev(int dev
)
190 mixer_devs
[dev
] = NULL
;
191 unregister_sound_mixer(dev
<<4);
196 void sound_unload_mididev(int dev
)
199 midi_devs
[dev
] = NULL
;
200 unregister_sound_midi((dev
<<4)+2);
204 void sound_unload_synthdev(int dev
)
207 synth_devs
[dev
] = NULL
;
210 void sound_unload_timerdev(int dev
)
213 sound_timer_devs
[dev
] = NULL
;