dev_table.c 4.4 KB

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