dev_table.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. sound_nblocks++;
  54. if (sound_nblocks >= MAX_MEM_BLOCKS)
  55. sound_nblocks = MAX_MEM_BLOCKS - 1;
  56. op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_operations)));
  57. sound_nblocks++;
  58. if (sound_nblocks >= MAX_MEM_BLOCKS)
  59. sound_nblocks = MAX_MEM_BLOCKS - 1;
  60. if (d == NULL || op == NULL) {
  61. printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
  62. sound_unload_audiodev(num);
  63. return -(ENOMEM);
  64. }
  65. memset((char *) op, 0, sizeof(struct audio_operations));
  66. init_waitqueue_head(&op->in_sleeper);
  67. init_waitqueue_head(&op->out_sleeper);
  68. init_waitqueue_head(&op->poll_sleeper);
  69. if (driver_size < sizeof(struct audio_driver))
  70. memset((char *) d, 0, sizeof(struct audio_driver));
  71. memcpy((char *) d, (char *) driver, driver_size);
  72. op->d = d;
  73. strlcpy(op->name, name, sizeof(op->name));
  74. op->flags = flags;
  75. op->format_mask = format_mask;
  76. op->devc = devc;
  77. /*
  78. * Hardcoded defaults
  79. */
  80. audio_devs[num] = op;
  81. DMAbuf_init(num, dma1, dma2);
  82. audio_init_devices();
  83. return num;
  84. }
  85. EXPORT_SYMBOL(sound_install_audiodrv);
  86. int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
  87. int driver_size, void *devc)
  88. {
  89. struct mixer_operations *op;
  90. int n = sound_alloc_mixerdev();
  91. if (n == -1) {
  92. printk(KERN_ERR "Sound: Too many mixer drivers\n");
  93. return -EBUSY;
  94. }
  95. if (vers != MIXER_DRIVER_VERSION ||
  96. driver_size > sizeof(struct mixer_operations)) {
  97. printk(KERN_ERR "Sound: Incompatible mixer driver for %s\n", name);
  98. return -EINVAL;
  99. }
  100. /* FIXME: This leaks a mixer_operations struct every time its called
  101. until you unload sound! */
  102. op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct mixer_operations)));
  103. sound_nblocks++;
  104. if (sound_nblocks >= MAX_MEM_BLOCKS)
  105. sound_nblocks = MAX_MEM_BLOCKS - 1;
  106. if (op == NULL) {
  107. printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
  108. return -ENOMEM;
  109. }
  110. memset((char *) op, 0, sizeof(struct mixer_operations));
  111. memcpy((char *) op, (char *) driver, driver_size);
  112. strlcpy(op->name, name, sizeof(op->name));
  113. op->devc = devc;
  114. mixer_devs[n] = op;
  115. return n;
  116. }
  117. EXPORT_SYMBOL(sound_install_mixer);
  118. void sound_unload_audiodev(int dev)
  119. {
  120. if (dev != -1) {
  121. DMAbuf_deinit(dev);
  122. audio_devs[dev] = NULL;
  123. unregister_sound_dsp((dev<<4)+3);
  124. }
  125. }
  126. EXPORT_SYMBOL(sound_unload_audiodev);
  127. static int sound_alloc_audiodev(void)
  128. {
  129. int i = register_sound_dsp(&oss_sound_fops, -1);
  130. if(i==-1)
  131. return i;
  132. i>>=4;
  133. if(i>=num_audiodevs)
  134. num_audiodevs = i + 1;
  135. return i;
  136. }
  137. int sound_alloc_mididev(void)
  138. {
  139. int i = register_sound_midi(&oss_sound_fops, -1);
  140. if(i==-1)
  141. return i;
  142. i>>=4;
  143. if(i>=num_midis)
  144. num_midis = i + 1;
  145. return i;
  146. }
  147. EXPORT_SYMBOL(sound_alloc_mididev);
  148. int sound_alloc_synthdev(void)
  149. {
  150. int i;
  151. for (i = 0; i < MAX_SYNTH_DEV; i++) {
  152. if (synth_devs[i] == NULL) {
  153. if (i >= num_synths)
  154. num_synths++;
  155. return i;
  156. }
  157. }
  158. return -1;
  159. }
  160. EXPORT_SYMBOL(sound_alloc_synthdev);
  161. int sound_alloc_mixerdev(void)
  162. {
  163. int i = register_sound_mixer(&oss_sound_fops, -1);
  164. if(i==-1)
  165. return -1;
  166. i>>=4;
  167. if(i>=num_mixers)
  168. num_mixers = i + 1;
  169. return i;
  170. }
  171. EXPORT_SYMBOL(sound_alloc_mixerdev);
  172. int sound_alloc_timerdev(void)
  173. {
  174. int i;
  175. for (i = 0; i < MAX_TIMER_DEV; i++) {
  176. if (sound_timer_devs[i] == NULL) {
  177. if (i >= num_sound_timers)
  178. num_sound_timers++;
  179. return i;
  180. }
  181. }
  182. return -1;
  183. }
  184. EXPORT_SYMBOL(sound_alloc_timerdev);
  185. void sound_unload_mixerdev(int dev)
  186. {
  187. if (dev != -1) {
  188. mixer_devs[dev] = NULL;
  189. unregister_sound_mixer(dev<<4);
  190. num_mixers--;
  191. }
  192. }
  193. EXPORT_SYMBOL(sound_unload_mixerdev);
  194. void sound_unload_mididev(int dev)
  195. {
  196. if (dev != -1) {
  197. midi_devs[dev] = NULL;
  198. unregister_sound_midi((dev<<4)+2);
  199. }
  200. }
  201. EXPORT_SYMBOL(sound_unload_mididev);
  202. void sound_unload_synthdev(int dev)
  203. {
  204. if (dev != -1)
  205. synth_devs[dev] = NULL;
  206. }
  207. EXPORT_SYMBOL(sound_unload_synthdev);
  208. void sound_unload_timerdev(int dev)
  209. {
  210. if (dev != -1)
  211. sound_timer_devs[dev] = NULL;
  212. }
  213. EXPORT_SYMBOL(sound_unload_timerdev);