seq_oss.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * OSS compatible sequencer driver
  3. *
  4. * registration of device and proc
  5. *
  6. * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <sound/driver.h>
  23. #include <linux/init.h>
  24. #include <linux/smp_lock.h>
  25. #include <linux/moduleparam.h>
  26. #include <sound/core.h>
  27. #include <sound/minors.h>
  28. #include <sound/initval.h>
  29. #include "seq_oss_device.h"
  30. #include "seq_oss_synth.h"
  31. /*
  32. * module option
  33. */
  34. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  35. MODULE_DESCRIPTION("OSS-compatible sequencer module");
  36. MODULE_LICENSE("GPL");
  37. /* Takashi says this is really only for sound-service-0-, but this is OK. */
  38. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
  39. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
  40. #ifdef SNDRV_SEQ_OSS_DEBUG
  41. module_param(seq_oss_debug, int, 0644);
  42. MODULE_PARM_DESC(seq_oss_debug, "debug option");
  43. int seq_oss_debug = 0;
  44. #endif
  45. /*
  46. * prototypes
  47. */
  48. static int register_device(void);
  49. static void unregister_device(void);
  50. static int register_proc(void);
  51. static void unregister_proc(void);
  52. static int odev_open(struct inode *inode, struct file *file);
  53. static int odev_release(struct inode *inode, struct file *file);
  54. static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
  55. static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
  56. static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  57. static unsigned int odev_poll(struct file *file, poll_table * wait);
  58. #ifdef CONFIG_PROC_FS
  59. static void info_read(snd_info_entry_t *entry, snd_info_buffer_t *buf);
  60. #endif
  61. /*
  62. * module interface
  63. */
  64. static int __init alsa_seq_oss_init(void)
  65. {
  66. int rc;
  67. static snd_seq_dev_ops_t ops = {
  68. snd_seq_oss_synth_register,
  69. snd_seq_oss_synth_unregister,
  70. };
  71. snd_seq_autoload_lock();
  72. if ((rc = register_device()) < 0)
  73. goto error;
  74. if ((rc = register_proc()) < 0) {
  75. unregister_device();
  76. goto error;
  77. }
  78. if ((rc = snd_seq_oss_create_client()) < 0) {
  79. unregister_proc();
  80. unregister_device();
  81. goto error;
  82. }
  83. if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops,
  84. sizeof(snd_seq_oss_reg_t))) < 0) {
  85. snd_seq_oss_delete_client();
  86. unregister_proc();
  87. unregister_device();
  88. goto error;
  89. }
  90. /* success */
  91. snd_seq_oss_synth_init();
  92. error:
  93. snd_seq_autoload_unlock();
  94. return rc;
  95. }
  96. static void __exit alsa_seq_oss_exit(void)
  97. {
  98. snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS);
  99. snd_seq_oss_delete_client();
  100. unregister_proc();
  101. unregister_device();
  102. }
  103. module_init(alsa_seq_oss_init)
  104. module_exit(alsa_seq_oss_exit)
  105. /*
  106. * ALSA minor device interface
  107. */
  108. static DECLARE_MUTEX(register_mutex);
  109. static int
  110. odev_open(struct inode *inode, struct file *file)
  111. {
  112. int level, rc;
  113. if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
  114. level = SNDRV_SEQ_OSS_MODE_MUSIC;
  115. else
  116. level = SNDRV_SEQ_OSS_MODE_SYNTH;
  117. down(&register_mutex);
  118. rc = snd_seq_oss_open(file, level);
  119. up(&register_mutex);
  120. return rc;
  121. }
  122. static int
  123. odev_release(struct inode *inode, struct file *file)
  124. {
  125. seq_oss_devinfo_t *dp;
  126. if ((dp = file->private_data) == NULL)
  127. return 0;
  128. snd_seq_oss_drain_write(dp);
  129. down(&register_mutex);
  130. snd_seq_oss_release(dp);
  131. up(&register_mutex);
  132. return 0;
  133. }
  134. static ssize_t
  135. odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  136. {
  137. seq_oss_devinfo_t *dp;
  138. dp = file->private_data;
  139. snd_assert(dp != NULL, return -EIO);
  140. return snd_seq_oss_read(dp, buf, count);
  141. }
  142. static ssize_t
  143. odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
  144. {
  145. seq_oss_devinfo_t *dp;
  146. dp = file->private_data;
  147. snd_assert(dp != NULL, return -EIO);
  148. return snd_seq_oss_write(dp, buf, count, file);
  149. }
  150. static long
  151. odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  152. {
  153. seq_oss_devinfo_t *dp;
  154. dp = file->private_data;
  155. snd_assert(dp != NULL, return -EIO);
  156. return snd_seq_oss_ioctl(dp, cmd, arg);
  157. }
  158. #ifdef CONFIG_COMPAT
  159. #define odev_ioctl_compat odev_ioctl
  160. #else
  161. #define odev_ioctl_compat NULL
  162. #endif
  163. static unsigned int
  164. odev_poll(struct file *file, poll_table * wait)
  165. {
  166. seq_oss_devinfo_t *dp;
  167. dp = file->private_data;
  168. snd_assert(dp != NULL, return 0);
  169. return snd_seq_oss_poll(dp, file, wait);
  170. }
  171. /*
  172. * registration of sequencer minor device
  173. */
  174. static struct file_operations seq_oss_f_ops =
  175. {
  176. .owner = THIS_MODULE,
  177. .read = odev_read,
  178. .write = odev_write,
  179. .open = odev_open,
  180. .release = odev_release,
  181. .poll = odev_poll,
  182. .unlocked_ioctl = odev_ioctl,
  183. .compat_ioctl = odev_ioctl_compat,
  184. };
  185. static snd_minor_t seq_oss_reg = {
  186. .comment = "sequencer",
  187. .f_ops = &seq_oss_f_ops,
  188. };
  189. static int __init
  190. register_device(void)
  191. {
  192. int rc;
  193. down(&register_mutex);
  194. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
  195. NULL, 0,
  196. &seq_oss_reg,
  197. SNDRV_SEQ_OSS_DEVNAME)) < 0) {
  198. snd_printk(KERN_ERR "can't register device seq\n");
  199. up(&register_mutex);
  200. return rc;
  201. }
  202. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
  203. NULL, 0,
  204. &seq_oss_reg,
  205. SNDRV_SEQ_OSS_DEVNAME)) < 0) {
  206. snd_printk(KERN_ERR "can't register device music\n");
  207. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
  208. up(&register_mutex);
  209. return rc;
  210. }
  211. debug_printk(("device registered\n"));
  212. up(&register_mutex);
  213. return 0;
  214. }
  215. static void
  216. unregister_device(void)
  217. {
  218. down(&register_mutex);
  219. debug_printk(("device unregistered\n"));
  220. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
  221. snd_printk(KERN_ERR "error unregister device music\n");
  222. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
  223. snd_printk(KERN_ERR "error unregister device seq\n");
  224. up(&register_mutex);
  225. }
  226. /*
  227. * /proc interface
  228. */
  229. #ifdef CONFIG_PROC_FS
  230. static snd_info_entry_t *info_entry;
  231. static void
  232. info_read(snd_info_entry_t *entry, snd_info_buffer_t *buf)
  233. {
  234. down(&register_mutex);
  235. snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
  236. snd_seq_oss_system_info_read(buf);
  237. snd_seq_oss_synth_info_read(buf);
  238. snd_seq_oss_midi_info_read(buf);
  239. up(&register_mutex);
  240. }
  241. #endif /* CONFIG_PROC_FS */
  242. static int __init
  243. register_proc(void)
  244. {
  245. #ifdef CONFIG_PROC_FS
  246. snd_info_entry_t *entry;
  247. entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
  248. if (entry == NULL)
  249. return -ENOMEM;
  250. entry->content = SNDRV_INFO_CONTENT_TEXT;
  251. entry->private_data = NULL;
  252. entry->c.text.read_size = 1024;
  253. entry->c.text.read = info_read;
  254. if (snd_info_register(entry) < 0) {
  255. snd_info_free_entry(entry);
  256. return -ENOMEM;
  257. }
  258. info_entry = entry;
  259. #endif
  260. return 0;
  261. }
  262. static void
  263. unregister_proc(void)
  264. {
  265. #ifdef CONFIG_PROC_FS
  266. if (info_entry)
  267. snd_info_unregister(info_entry);
  268. info_entry = NULL;
  269. #endif
  270. }