1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/init.h>
24#include <linux/module.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
33
34
35MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
36MODULE_DESCRIPTION("OSS-compatible sequencer module");
37MODULE_LICENSE("GPL");
38
39MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_SEQUENCER);
40MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MUSIC);
41
42#ifdef SNDRV_SEQ_OSS_DEBUG
43module_param(seq_oss_debug, int, 0644);
44MODULE_PARM_DESC(seq_oss_debug, "debug option");
45int seq_oss_debug = 0;
46#endif
47
48
49
50
51
52static int register_device(void);
53static void unregister_device(void);
54#ifdef CONFIG_PROC_FS
55static int register_proc(void);
56static void unregister_proc(void);
57#else
58static inline int register_proc(void) { return 0; }
59static inline void unregister_proc(void) {}
60#endif
61
62static int odev_open(struct inode *inode, struct file *file);
63static int odev_release(struct inode *inode, struct file *file);
64static ssize_t odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset);
65static ssize_t odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset);
66static long odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
67static unsigned int odev_poll(struct file *file, poll_table * wait);
68
69
70
71
72
73
74static int __init alsa_seq_oss_init(void)
75{
76 int rc;
77 static struct snd_seq_dev_ops ops = {
78 snd_seq_oss_synth_register,
79 snd_seq_oss_synth_unregister,
80 };
81
82 snd_seq_autoload_lock();
83 if ((rc = register_device()) < 0)
84 goto error;
85 if ((rc = register_proc()) < 0) {
86 unregister_device();
87 goto error;
88 }
89 if ((rc = snd_seq_oss_create_client()) < 0) {
90 unregister_proc();
91 unregister_device();
92 goto error;
93 }
94
95 if ((rc = snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OSS, &ops,
96 sizeof(struct snd_seq_oss_reg))) < 0) {
97 snd_seq_oss_delete_client();
98 unregister_proc();
99 unregister_device();
100 goto error;
101 }
102
103
104 snd_seq_oss_synth_init();
105
106 error:
107 snd_seq_autoload_unlock();
108 return rc;
109}
110
111static void __exit alsa_seq_oss_exit(void)
112{
113 snd_seq_device_unregister_driver(SNDRV_SEQ_DEV_ID_OSS);
114 snd_seq_oss_delete_client();
115 unregister_proc();
116 unregister_device();
117}
118
119module_init(alsa_seq_oss_init)
120module_exit(alsa_seq_oss_exit)
121
122
123
124
125
126static DEFINE_MUTEX(register_mutex);
127
128static int
129odev_open(struct inode *inode, struct file *file)
130{
131 int level, rc;
132
133 if (iminor(inode) == SNDRV_MINOR_OSS_MUSIC)
134 level = SNDRV_SEQ_OSS_MODE_MUSIC;
135 else
136 level = SNDRV_SEQ_OSS_MODE_SYNTH;
137
138 mutex_lock(®ister_mutex);
139 rc = snd_seq_oss_open(file, level);
140 mutex_unlock(®ister_mutex);
141
142 return rc;
143}
144
145static int
146odev_release(struct inode *inode, struct file *file)
147{
148 struct seq_oss_devinfo *dp;
149
150 if ((dp = file->private_data) == NULL)
151 return 0;
152
153 snd_seq_oss_drain_write(dp);
154
155 mutex_lock(®ister_mutex);
156 snd_seq_oss_release(dp);
157 mutex_unlock(®ister_mutex);
158
159 return 0;
160}
161
162static ssize_t
163odev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
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_read(dp, buf, count);
170}
171
172
173static ssize_t
174odev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
175{
176 struct seq_oss_devinfo *dp;
177 dp = file->private_data;
178 if (snd_BUG_ON(!dp))
179 return -ENXIO;
180 return snd_seq_oss_write(dp, buf, count, file);
181}
182
183static long
184odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
185{
186 struct seq_oss_devinfo *dp;
187 dp = file->private_data;
188 if (snd_BUG_ON(!dp))
189 return -ENXIO;
190 return snd_seq_oss_ioctl(dp, cmd, arg);
191}
192
193#ifdef CONFIG_COMPAT
194#define odev_ioctl_compat odev_ioctl
195#else
196#define odev_ioctl_compat NULL
197#endif
198
199static unsigned int
200odev_poll(struct file *file, poll_table * wait)
201{
202 struct seq_oss_devinfo *dp;
203 dp = file->private_data;
204 if (snd_BUG_ON(!dp))
205 return -ENXIO;
206 return snd_seq_oss_poll(dp, file, wait);
207}
208
209
210
211
212
213static const struct file_operations seq_oss_f_ops =
214{
215 .owner = THIS_MODULE,
216 .read = odev_read,
217 .write = odev_write,
218 .open = odev_open,
219 .release = odev_release,
220 .poll = odev_poll,
221 .unlocked_ioctl = odev_ioctl,
222 .compat_ioctl = odev_ioctl_compat,
223 .llseek = noop_llseek,
224};
225
226static int __init
227register_device(void)
228{
229 int rc;
230
231 mutex_lock(®ister_mutex);
232 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER,
233 NULL, 0,
234 &seq_oss_f_ops, NULL,
235 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
236 snd_printk(KERN_ERR "can't register device seq\n");
237 mutex_unlock(®ister_mutex);
238 return rc;
239 }
240 if ((rc = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC,
241 NULL, 0,
242 &seq_oss_f_ops, NULL,
243 SNDRV_SEQ_OSS_DEVNAME)) < 0) {
244 snd_printk(KERN_ERR "can't register device music\n");
245 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0);
246 mutex_unlock(®ister_mutex);
247 return rc;
248 }
249 debug_printk(("device registered\n"));
250 mutex_unlock(®ister_mutex);
251 return 0;
252}
253
254static void
255unregister_device(void)
256{
257 mutex_lock(®ister_mutex);
258 debug_printk(("device unregistered\n"));
259 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MUSIC, NULL, 0) < 0)
260 snd_printk(KERN_ERR "error unregister device music\n");
261 if (snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_SEQUENCER, NULL, 0) < 0)
262 snd_printk(KERN_ERR "error unregister device seq\n");
263 mutex_unlock(®ister_mutex);
264}
265
266
267
268
269
270#ifdef CONFIG_PROC_FS
271
272static struct snd_info_entry *info_entry;
273
274static void
275info_read(struct snd_info_entry *entry, struct snd_info_buffer *buf)
276{
277 mutex_lock(®ister_mutex);
278 snd_iprintf(buf, "OSS sequencer emulation version %s\n", SNDRV_SEQ_OSS_VERSION_STR);
279 snd_seq_oss_system_info_read(buf);
280 snd_seq_oss_synth_info_read(buf);
281 snd_seq_oss_midi_info_read(buf);
282 mutex_unlock(®ister_mutex);
283}
284
285
286static int __init
287register_proc(void)
288{
289 struct snd_info_entry *entry;
290
291 entry = snd_info_create_module_entry(THIS_MODULE, SNDRV_SEQ_OSS_PROCNAME, snd_seq_root);
292 if (entry == NULL)
293 return -ENOMEM;
294
295 entry->content = SNDRV_INFO_CONTENT_TEXT;
296 entry->private_data = NULL;
297 entry->c.text.read = info_read;
298 if (snd_info_register(entry) < 0) {
299 snd_info_free_entry(entry);
300 return -ENOMEM;
301 }
302 info_entry = entry;
303 return 0;
304}
305
306static void
307unregister_proc(void)
308{
309 snd_info_free_entry(info_entry);
310 info_entry = NULL;
311}
312#endif
313