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