seq_oss.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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/moduleparam.h>
  25. #include <linux/mutex.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. #ifdef CONFIG_PROC_FS
  51. static int register_proc(void);
  52. static void unregister_proc(void);
  53. #else
  54. static inline int register_proc(void) { return 0; }
  55. static inline void unregister_proc(void) {}
  56. #endif
  57. static int odev_open(struct inode *inode, struct file *file);
  58. static int odev_release(struct inode *inode, struct file *file);
  59. static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
  60. static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
  61. static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  62. static unsigned int odev_poll(struct file *file, poll_table * wait);
  63. /*
  64. * module interface
  65. */
  66. static int __init alsa_seq_oss_init(void)
  67. {
  68. int rc;
  69. static struct snd_seq_dev_ops ops = {
  70. snd_seq_oss_synth_register,
  71. snd_seq_oss_synth_unregister,
  72. };
  73. snd_seq_autoload_lock();
  74. if ((rc = register_device()) < 0)
  75. goto error;
  76. if ((rc = register_proc()) < 0) {
  77. unregister_device();
  78. goto error;
  79. }
  80. if ((rc = snd_seq_oss_create_client()) < 0) {
  81. unregister_proc();
  82. unregister_device();
  83. goto error;
  84. }
  85. if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops,
  86. sizeof(struct snd_seq_oss_reg))) < 0) {
  87. snd_seq_oss_delete_client();
  88. unregister_proc();
  89. unregister_device();
  90. goto error;
  91. }
  92. /* success */
  93. snd_seq_oss_synth_init();
  94. error:
  95. snd_seq_autoload_unlock();
  96. return rc;
  97. }
  98. static void __exit alsa_seq_oss_exit(void)
  99. {
  100. snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS);
  101. snd_seq_oss_delete_client();
  102. unregister_proc();
  103. unregister_device();
  104. }
  105. module_init(alsa_seq_oss_init)
  106. module_exit(alsa_seq_oss_exit)
  107. /*
  108. * ALSA minor device interface
  109. */
  110. static DEFINE_MUTEX(register_mutex);
  111. static int
  112. odev_open(struct inode *inode, struct file *file)
  113. {
  114. int level, rc;
  115. if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
  116. level = SNDRV_SEQ_OSS_MODE_MUSIC;
  117. else
  118. level = SNDRV_SEQ_OSS_MODE_SYNTH;
  119. mutex_lock(&register_mutex);
  120. rc = snd_seq_oss_open(file, level);
  121. mutex_unlock(&register_mutex);
  122. return rc;
  123. }
  124. static int
  125. odev_release(struct inode *inode, struct file *file)
  126. {
  127. struct seq_oss_devinfo *dp;
  128. if ((dp = file->private_data) == NULL)
  129. return 0;
  130. snd_seq_oss_drain_write(dp);
  131. mutex_lock(&register_mutex);
  132. snd_seq_oss_release(dp);
  133. mutex_unlock(&register_mutex);
  134. return 0;
  135. }
  136. static ssize_t
  137. odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  138. {
  139. struct seq_oss_devinfo *dp;
  140. dp = file->private_data;
  141. snd_assert(dp != NULL, return -EIO);
  142. return snd_seq_oss_read(dp, buf, count);
  143. }
  144. static ssize_t
  145. odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
  146. {
  147. struct seq_oss_devinfo *dp;
  148. dp = file->private_data;
  149. snd_assert(dp != NULL, return -EIO);
  150. return snd_seq_oss_write(dp, buf, count, file);
  151. }
  152. static long
  153. odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  154. {
  155. struct seq_oss_devinfo *dp;
  156. dp = file->private_data;
  157. snd_assert(dp != NULL, return -EIO);
  158. return snd_seq_oss_ioctl(dp, cmd, arg);
  159. }
  160. #ifdef CONFIG_COMPAT
  161. #define odev_ioctl_compat odev_ioctl
  162. #else
  163. #define odev_ioctl_compat NULL
  164. #endif
  165. static unsigned int
  166. odev_poll(struct file *file, poll_table * wait)
  167. {
  168. struct seq_oss_devinfo *dp;
  169. dp = file->private_data;
  170. snd_assert(dp != NULL, return 0);
  171. return snd_seq_oss_poll(dp, file, wait);
  172. }
  173. /*
  174. * registration of sequencer minor device
  175. */
  176. static const struct file_operations seq_oss_f_ops =
  177. {
  178. .owner = THIS_MODULE,
  179. .read = odev_read,
  180. .write = odev_write,
  181. .open = odev_open,
  182. .release = odev_release,
  183. .poll = odev_poll,
  184. .unlocked_ioctl = odev_ioctl,
  185. .compat_ioctl = odev_ioctl_compat,
  186. };
  187. static int __init
  188. register_device(void)
  189. {
  190. int rc;
  191. mutex_lock(&register_mutex);
  192. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
  193. NULL, 0,
  194. &seq_oss_f_ops, NULL,
  195. SNDRV_SEQ_OSS_DEVNAME)) < 0) {
  196. snd_printk(KERN_ERR "can't register device seq\n");
  197. mutex_unlock(&register_mutex);
  198. return rc;
  199. }
  200. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
  201. NULL, 0,
  202. &seq_oss_f_ops, NULL,
  203. SNDRV_SEQ_OSS_DEVNAME)) < 0) {
  204. snd_printk(KERN_ERR "can't register device music\n");
  205. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
  206. mutex_unlock(&register_mutex);
  207. return rc;
  208. }
  209. debug_printk(("device registered\n"));
  210. mutex_unlock(&register_mutex);
  211. return 0;
  212. }
  213. static void
  214. unregister_device(void)
  215. {
  216. mutex_lock(&register_mutex);
  217. debug_printk(("device unregistered\n"));
  218. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
  219. snd_printk(KERN_ERR "error unregister device music\n");
  220. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
  221. snd_printk(KERN_ERR "error unregister device seq\n");
  222. mutex_unlock(&register_mutex);
  223. }
  224. /*
  225. * /proc interface
  226. */
  227. #ifdef CONFIG_PROC_FS
  228. static struct snd_info_entry *info_entry;
  229. static void
  230. info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
  231. {
  232. mutex_lock(&register_mutex);
  233. snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
  234. snd_seq_oss_system_info_read(buf);
  235. snd_seq_oss_synth_info_read(buf);
  236. snd_seq_oss_midi_info_read(buf);
  237. mutex_unlock(&register_mutex);
  238. }
  239. static int __init
  240. register_proc(void)
  241. {
  242. struct snd_info_entry *entry;
  243. entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
  244. if (entry == NULL)
  245. return -ENOMEM;
  246. entry->content = SNDRV_INFO_CONTENT_TEXT;
  247. entry->private_data = NULL;
  248. entry->c.text.read = info_read;
  249. if (snd_info_register(entry) < 0) {
  250. snd_info_free_entry(entry);
  251. return -ENOMEM;
  252. }
  253. info_entry = entry;
  254. return 0;
  255. }
  256. static void
  257. unregister_proc(void)
  258. {
  259. snd_info_free_entry(info_entry);
  260. info_entry = NULL;
  261. }
  262. #endif /* CONFIG_PROC_FS */