Linux Audio

Check our new training course

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