seq_oss.c 7.2 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 <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/mutex.h>
  25. #include <linux/compat.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. /*
  41. * prototypes
  42. */
  43. static int register_device(void);
  44. static void unregister_device(void);
  45. #ifdef CONFIG_SND_PROC_FS
  46. static int register_proc(void);
  47. static void unregister_proc(void);
  48. #else
  49. static inline int register_proc(void) { return 0; }
  50. static inline void unregister_proc(void) {}
  51. #endif
  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. /*
  59. * module interface
  60. */
  61. static struct snd_seq_driver seq_oss_synth_driver = {
  62. .driver = {
  63. .name = KBUILD_MODNAME,
  64. .probe = snd_seq_oss_synth_probe,
  65. .remove = snd_seq_oss_synth_remove,
  66. },
  67. .id = SNDRV_SEQ_DEV_ID_OSS,
  68. .argsize = sizeof(struct snd_seq_oss_reg),
  69. };
  70. static int __init alsa_seq_oss_init(void)
  71. {
  72. int rc;
  73. if ((rc = register_device()) < 0)
  74. goto error;
  75. if ((rc = register_proc()) < 0) {
  76. unregister_device();
  77. goto error;
  78. }
  79. if ((rc = snd_seq_oss_create_client()) < 0) {
  80. unregister_proc();
  81. unregister_device();
  82. goto error;
  83. }
  84. rc = snd_seq_driver_register(&seq_oss_synth_driver);
  85. if (rc < 0) {
  86. snd_seq_oss_delete_client();
  87. unregister_proc();
  88. unregister_device();
  89. goto error;
  90. }
  91. /* success */
  92. snd_seq_oss_synth_init();
  93. error:
  94. return rc;
  95. }
  96. static void __exit alsa_seq_oss_exit(void)
  97. {
  98. snd_seq_driver_unregister(&seq_oss_synth_driver);
  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 DEFINE_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. mutex_lock(&register_mutex);
  118. rc = snd_seq_oss_open(file, level);
  119. mutex_unlock(&register_mutex);
  120. return rc;
  121. }
  122. static int
  123. odev_release(struct inode *inode, struct file *file)
  124. {
  125. struct seq_oss_devinfo *dp;
  126. if ((dp = file->private_data) == NULL)
  127. return 0;
  128. snd_seq_oss_drain_write(dp);
  129. mutex_lock(&register_mutex);
  130. snd_seq_oss_release(dp);
  131. mutex_unlock(&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. struct seq_oss_devinfo *dp;
  138. dp = file->private_data;
  139. if (snd_BUG_ON(!dp))
  140. return -ENXIO;
  141. return snd_seq_oss_read(dp, buf, count);
  142. }
  143. static ssize_t
  144. odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
  145. {
  146. struct seq_oss_devinfo *dp;
  147. dp = file->private_data;
  148. if (snd_BUG_ON(!dp))
  149. return -ENXIO;
  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. if (snd_BUG_ON(!dp))
  158. return -ENXIO;
  159. return snd_seq_oss_ioctl(dp, cmd, arg);
  160. }
  161. #ifdef CONFIG_COMPAT
  162. static long odev_ioctl_compat(struct file *file, unsigned int cmd,
  163. unsigned long arg)
  164. {
  165. return odev_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
  166. }
  167. #else
  168. #define odev_ioctl_compat NULL
  169. #endif
  170. static unsigned int
  171. odev_poll(struct file *file, poll_table * wait)
  172. {
  173. struct seq_oss_devinfo *dp;
  174. dp = file->private_data;
  175. if (snd_BUG_ON(!dp))
  176. return -ENXIO;
  177. return snd_seq_oss_poll(dp, file, wait);
  178. }
  179. /*
  180. * registration of sequencer minor device
  181. */
  182. static const struct file_operations seq_oss_f_ops =
  183. {
  184. .owner = THIS_MODULE,
  185. .read = odev_read,
  186. .write = odev_write,
  187. .open = odev_open,
  188. .release = odev_release,
  189. .poll = odev_poll,
  190. .unlocked_ioctl = odev_ioctl,
  191. .compat_ioctl = odev_ioctl_compat,
  192. .llseek = noop_llseek,
  193. };
  194. static int __init
  195. register_device(void)
  196. {
  197. int rc;
  198. mutex_lock(&register_mutex);
  199. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
  200. NULL, 0,
  201. &seq_oss_f_ops, NULL)) < 0) {
  202. pr_err("ALSA: seq_oss: can't register device seq\n");
  203. mutex_unlock(&register_mutex);
  204. return rc;
  205. }
  206. if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
  207. NULL, 0,
  208. &seq_oss_f_ops, NULL)) < 0) {
  209. pr_err("ALSA: seq_oss: can't register device music\n");
  210. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
  211. mutex_unlock(&register_mutex);
  212. return rc;
  213. }
  214. mutex_unlock(&register_mutex);
  215. return 0;
  216. }
  217. static void
  218. unregister_device(void)
  219. {
  220. mutex_lock(&register_mutex);
  221. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
  222. pr_err("ALSA: seq_oss: error unregister device music\n");
  223. if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
  224. pr_err("ALSA: seq_oss: error unregister device seq\n");
  225. mutex_unlock(&register_mutex);
  226. }
  227. /*
  228. * /proc interface
  229. */
  230. #ifdef CONFIG_SND_PROC_FS
  231. static struct snd_info_entry *info_entry;
  232. static void
  233. info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
  234. {
  235. mutex_lock(&register_mutex);
  236. snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
  237. snd_seq_oss_system_info_read(buf);
  238. snd_seq_oss_synth_info_read(buf);
  239. snd_seq_oss_midi_info_read(buf);
  240. mutex_unlock(&register_mutex);
  241. }
  242. static int __init
  243. register_proc(void)
  244. {
  245. struct snd_info_entry *entry;
  246. entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
  247. if (entry == NULL)
  248. return -ENOMEM;
  249. entry->content = SNDRV_INFO_CONTENT_TEXT;
  250. entry->private_data = NULL;
  251. entry->c.text.read = info_read;
  252. if (snd_info_register(entry) < 0) {
  253. snd_info_free_entry(entry);
  254. return -ENOMEM;
  255. }
  256. info_entry = entry;
  257. return 0;
  258. }
  259. static void
  260. unregister_proc(void)
  261. {
  262. snd_info_free_entry(info_entry);
  263. info_entry = NULL;
  264. }
  265. #endif /* CONFIG_SND_PROC_FS */