seq_oss.c 7.4 KB

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