seq_oss.c 7.0 KB

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