seq_oss.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/mutex.h>
  25. #include <sound/core.h>
  26. #include <sound/minors.h>
  27. #include <sound/initval.h>
  28. #include "seq_oss_device.h"
  29. #include "seq_oss_synth.h"
  30. /*
  31. * module option
  32. */
  33. MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
  34. MODULE_DESCRIPTION("OSS-compatible sequencer module");
  35. MODULE_LICENSE("GPL");
  36. /* Takashi says this is really only for sound-service-0-, but this is OK. */
  37. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
  38. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
  39. /*
  40. * prototypes
  41. */
  42. static int register_device(void);
  43. static void unregister_device(void);
  44. #ifdef CONFIG_SND_PROC_FS
  45. static int register_proc(void);
  46. static void unregister_proc(void);
  47. #else
  48. static inline int register_proc(void) { return 0; }
  49. static inline void unregister_proc(void) {}
  50. #endif
  51. static int odev_open(struct inode *inode, struct file *file);
  52. static int odev_release(struct inode *inode, struct file *file);
  53. static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
  54. static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
  55. static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  56. static unsigned int odev_poll(struct file *file, poll_table * wait);
  57. /*
  58. * module interface
  59. */
  60. static struct snd_seq_driver seq_oss_synth_driver = {
  61. .driver = {
  62. .name = KBUILD_MODNAME,
  63. .probe = snd_seq_oss_synth_probe,
  64. .remove = snd_seq_oss_synth_remove,
  65. },
  66. .id = SNDRV_SEQ_DEV_ID_OSS,
  67. .argsize = sizeof(struct snd_seq_oss_reg),
  68. };
  69. static int __init alsa_seq_oss_init(void)
  70. {
  71. int rc;
  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. rc = snd_seq_driver_register(&seq_oss_synth_driver);
  84. if (rc < 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. return rc;
  94. }
  95. static void __exit alsa_seq_oss_exit(void)
  96. {
  97. snd_seq_driver_unregister(&seq_oss_synth_driver);
  98. snd_seq_oss_delete_client();
  99. unregister_proc();
  100. unregister_device();
  101. }
  102. module_init(alsa_seq_oss_init)
  103. module_exit(alsa_seq_oss_exit)
  104. /*
  105. * ALSA minor device interface
  106. */
  107. static DEFINE_MUTEX(register_mutex);
  108. static int
  109. odev_open(struct inode *inode, struct file *file)
  110. {
  111. int level, rc;
  112. if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
  113. level = SNDRV_SEQ_OSS_MODE_MUSIC;
  114. else
  115. level = SNDRV_SEQ_OSS_MODE_SYNTH;
  116. mutex_lock(&register_mutex);
  117. rc = snd_seq_oss_open(file, level);
  118. mutex_unlock(&register_mutex);
  119. return rc;
  120. }
  121. static int
  122. odev_release(struct inode *inode, struct file *file)
  123. {
  124. struct seq_oss_devinfo *dp;
  125. if ((dp = file->private_data) == NULL)
  126. return 0;
  127. snd_seq_oss_drain_write(dp);
  128. mutex_lock(&register_mutex);
  129. snd_seq_oss_release(dp);
  130. mutex_unlock(&register_mutex);
  131. return 0;
  132. }
  133. static ssize_t
  134. odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
  135. {
  136. struct seq_oss_devinfo *dp;
  137. dp = file->private_data;
  138. if (snd_BUG_ON(!dp))
  139. return -ENXIO;
  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. struct seq_oss_devinfo *dp;
  146. dp = file->private_data;
  147. if (snd_BUG_ON(!dp))
  148. return -ENXIO;
  149. return snd_seq_oss_write(dp, buf, count, file);
  150. }
  151. static long
  152. odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  153. {
  154. struct seq_oss_devinfo *dp;
  155. dp = file->private_data;
  156. if (snd_BUG_ON(!dp))
  157. return -ENXIO;
  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. if (snd_BUG_ON(!dp))
  171. return -ENXIO;
  172. return snd_seq_oss_poll(dp, file, wait);
  173. }
  174. /*
  175. * registration of sequencer minor device
  176. */
  177. static const 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. .llseek = noop_llseek,
  188. };
  189. static int __init
  190. register_device(void)
  191. {
  192. int rc;
  193. mutex_lock(&register_mutex);
  194. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
  195. NULL, 0,
  196. &seq_oss_f_ops, NULL)) < 0) {
  197. pr_err("ALSA: seq_oss: 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)) < 0) {
  204. pr_err("ALSA: seq_oss: 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. mutex_unlock(&register_mutex);
  210. return 0;
  211. }
  212. static void
  213. unregister_device(void)
  214. {
  215. mutex_lock(&register_mutex);
  216. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
  217. pr_err("ALSA: seq_oss: error unregister device music\n");
  218. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
  219. pr_err("ALSA: seq_oss: error unregister device seq\n");
  220. mutex_unlock(&register_mutex);
  221. }
  222. /*
  223. * /proc interface
  224. */
  225. #ifdef CONFIG_SND_PROC_FS
  226. static struct snd_info_entry *info_entry;
  227. static void
  228. info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
  229. {
  230. mutex_lock(&register_mutex);
  231. snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
  232. snd_seq_oss_system_info_read(buf);
  233. snd_seq_oss_synth_info_read(buf);
  234. snd_seq_oss_midi_info_read(buf);
  235. mutex_unlock(&register_mutex);
  236. }
  237. static int __init
  238. register_proc(void)
  239. {
  240. struct snd_info_entry *entry;
  241. entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
  242. if (entry == NULL)
  243. return -ENOMEM;
  244. entry->content = SNDRV_INFO_CONTENT_TEXT;
  245. entry->private_data = NULL;
  246. entry->c.text.read = info_read;
  247. if (snd_info_register(entry) < 0) {
  248. snd_info_free_entry(entry);
  249. return -ENOMEM;
  250. }
  251. info_entry = entry;
  252. return 0;
  253. }
  254. static void
  255. unregister_proc(void)
  256. {
  257. snd_info_free_entry(info_entry);
  258. info_entry = NULL;
  259. }
  260. #endif /* CONFIG_SND_PROC_FS */