dev_table.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * sound/oss/dev_table.c
  3. *
  4. * Device call tables.
  5. *
  6. *
  7. * Copyright (C) by Hannu Savolainen 1993-1997
  8. *
  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
  11. * for more info.
  12. */
  13. #include <linux/init.h>
  14. #include "sound_config.h"
  15. struct audio_operations *audio_devs[MAX_AUDIO_DEV];
  16. EXPORT_SYMBOL(audio_devs);
  17. int num_audiodevs;
  18. EXPORT_SYMBOL(num_audiodevs);
  19. struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
  20. EXPORT_SYMBOL(mixer_devs);
  21. int num_mixers;
  22. EXPORT_SYMBOL(num_mixers);
  23. struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
  24. EXPORT_SYMBOL(synth_devs);
  25. int num_synths;
  26. struct midi_operations *midi_devs[MAX_MIDI_DEV];
  27. EXPORT_SYMBOL(midi_devs);
  28. int num_midis;
  29. EXPORT_SYMBOL(num_midis);
  30. struct sound_timer_operations *sound_timer_devs[MAX_TIMER_DEV] = {
  31. &default_sound_timer, NULL
  32. };
  33. EXPORT_SYMBOL(sound_timer_devs);
  34. int num_sound_timers = 1;
  35. static int sound_alloc_audiodev(void);
  36. int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
  37. int driver_size, int flags, unsigned int format_mask,
  38. void *devc, int dma1, int dma2)
  39. {
  40. struct audio_driver *d;
  41. struct audio_operations *op;
  42. int num;
  43. if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
  44. printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
  45. return -(EINVAL);
  46. }
  47. num = sound_alloc_audiodev();
  48. if (num == -1) {
  49. printk(KERN_ERR "sound: Too many audio drivers\n");
  50. return -(EBUSY);
  51. }
  52. d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));
  53. if (sound_nblocks < 1024)
  54. sound_nblocks++;
  55. op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations)));
  56. if (sound_nblocks < 1024)
  57. sound_nblocks++;
  58. if (d == NULL || op == NULL) {
  59. printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
  60. sound_unload_audiodev(num);
  61. return -(ENOMEM);
  62. }
  63. memset((char *) op, 0, sizeof(struct audio_operations));
  64. init_waitqueue_head(&op->in_sleeper);
  65. init_waitqueue_head(&op->out_sleeper);
  66. init_waitqueue_head(&op->poll_sleeper);
  67. if (driver_size < sizeof(struct audio_driver))
  68. memset((char *) d, 0, sizeof(struct audio_driver));
  69. memcpy((char *) d, (char *) driver, driver_size);
  70. op->d = d;
  71. strlcpy(op->name, name, sizeof(op->name));
  72. op->flags = flags;
  73. op->format_mask = format_mask;
  74. op->devc = devc;
  75. /*
  76. * Hardcoded defaults
  77. */
  78. audio_devs[num] = op;
  79. DMAbuf_init(num, dma1, dma2);
  80. audio_init_devices();
  81. return num;
  82. }
  83. EXPORT_SYMBOL(sound_install_audiodrv);
  84. int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
  85. int driver_size, void *devc)
  86. {
  87. struct mixer_operations *op;
  88. int n = sound_alloc_mixerdev();
  89. if (n == -1) {
  90. printk(KERN_ERR "Sound: Too many mixer drivers\n");
  91. return -EBUSY;
  92. }
  93. if (vers != MIXER_DRIVER_VERSION ||
  94. driver_size > sizeof(struct mixer_operations)) {
  95. printk(KERN_ERR "Sound: Incompatible mixer driver for %s\n", name);
  96. return -EINVAL;
  97. }
  98. /* FIXME: This leaks a mixer_operations struct every time its called
  99. until you unload sound! */
  100. op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations)));
  101. if (sound_nblocks < 1024)
  102. sound_nblocks++;
  103. if (op == NULL) {
  104. printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
  105. return -ENOMEM;
  106. }
  107. memset((char *) op, 0, sizeof(struct mixer_operations));
  108. memcpy((char *) op, (char *) driver, driver_size);
  109. strlcpy(op->name, name, sizeof(op->name));
  110. op->devc = devc;
  111. mixer_devs[n] = op;
  112. return n;
  113. }
  114. EXPORT_SYMBOL(sound_install_mixer);
  115. void sound_unload_audiodev(int dev)
  116. {
  117. if (dev != -1) {
  118. DMAbuf_deinit(dev);
  119. audio_devs[dev] = NULL;
  120. unregister_sound_dsp((dev<<4)+3);
  121. }
  122. }
  123. EXPORT_SYMBOL(sound_unload_audiodev);
  124. static int sound_alloc_audiodev(void)
  125. {
  126. int i = register_sound_dsp(&oss_sound_fops, -1);
  127. if(i==-1)
  128. return i;
  129. i>>=4;
  130. if(i>=num_audiodevs)
  131. num_audiodevs = i + 1;
  132. return i;
  133. }
  134. int sound_alloc_mididev(void)
  135. {
  136. int i = register_sound_midi(&oss_sound_fops, -1);
  137. if(i==-1)
  138. return i;
  139. i>>=4;
  140. if(i>=num_midis)
  141. num_midis = i + 1;
  142. return i;
  143. }
  144. EXPORT_SYMBOL(sound_alloc_mididev);
  145. int sound_alloc_synthdev(void)
  146. {
  147. int i;
  148. for (i = 0; i < MAX_SYNTH_DEV; i++) {
  149. if (synth_devs[i] == NULL) {
  150. if (i >= num_synths)
  151. num_synths++;
  152. return i;
  153. }
  154. }
  155. return -1;
  156. }
  157. EXPORT_SYMBOL(sound_alloc_synthdev);
  158. int sound_alloc_mixerdev(void)
  159. {
  160. int i = register_sound_mixer(&oss_sound_fops, -1);
  161. if(i==-1)
  162. return -1;
  163. i>>=4;
  164. if(i>=num_mixers)
  165. num_mixers = i + 1;
  166. return i;
  167. }
  168. EXPORT_SYMBOL(sound_alloc_mixerdev);
  169. int sound_alloc_timerdev(void)
  170. {
  171. int i;
  172. for (i = 0; i < MAX_TIMER_DEV; i++) {
  173. if (sound_timer_devs[i] == NULL) {
  174. if (i >= num_sound_timers)
  175. num_sound_timers++;
  176. return i;
  177. }
  178. }
  179. return -1;
  180. }
  181. EXPORT_SYMBOL(sound_alloc_timerdev);
  182. void sound_unload_mixerdev(int dev)
  183. {
  184. if (dev != -1) {
  185. mixer_devs[dev] = NULL;
  186. unregister_sound_mixer(dev<<4);
  187. num_mixers--;
  188. }
  189. }
  190. EXPORT_SYMBOL(sound_unload_mixerdev);
  191. void sound_unload_mididev(int dev)
  192. {
  193. if (dev != -1) {
  194. midi_devs[dev] = NULL;
  195. unregister_sound_midi((dev<<4)+2);
  196. }
  197. }
  198. EXPORT_SYMBOL(sound_unload_mididev);
  199. void sound_unload_synthdev(int dev)
  200. {
  201. if (dev != -1)
  202. synth_devs[dev] = NULL;
  203. }
  204. EXPORT_SYMBOL(sound_unload_synthdev);
  205. void sound_unload_timerdev(int dev)
  206. {
  207. if (dev != -1)
  208. sound_timer_devs[dev] = NULL;
  209. }
  210. EXPORT_SYMBOL(sound_unload_timerdev);