2 * Copyright (C) 2002 Steve Schmidtke
3 * Licensed under the GPL
7 #include "linux/module.h"
8 #include "linux/slab.h"
9 #include "linux/sound.h"
10 #include "linux/soundcard.h"
11 #include "linux/smp_lock.h"
12 #include "asm/uaccess.h"
16 struct hostaudio_state {
20 struct hostmixer_state {
24 #define HOSTAUDIO_DEV_DSP "/dev/sound/dsp"
25 #define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer"
28 * Changed either at boot time or module load time. At boot, this is
29 * single-threaded; at module load, multiple modules would each have
30 * their own copy of these variables.
32 static char *dsp = HOSTAUDIO_DEV_DSP;
33 static char *mixer = HOSTAUDIO_DEV_MIXER;
36 " This is used to specify the host dsp device to the hostaudio driver.\n" \
37 " The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n"
40 " This is used to specify the host mixer device to the hostaudio driver.\n"\
41 " The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n"
43 module_param(dsp, charp, 0644);
44 MODULE_PARM_DESC(dsp, DSP_HELP);
45 module_param(mixer, charp, 0644);
46 MODULE_PARM_DESC(mixer, MIXER_HELP);
49 static int set_dsp(char *name, int *add)
55 __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
57 static int set_mixer(char *name, int *add)
63 __uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP);
66 /* /dev/dsp file operations */
68 static ssize_t hostaudio_read(struct file *file, char __user *buffer,
69 size_t count, loff_t *ppos)
71 struct hostaudio_state *state = file->private_data;
76 printk(KERN_DEBUG "hostaudio: read called, count = %d\n", count);
79 kbuf = kmalloc(count, GFP_KERNEL);
83 err = os_read_file(state->fd, kbuf, count);
87 if (copy_to_user(buffer, kbuf, err))
95 static ssize_t hostaudio_write(struct file *file, const char __user *buffer,
96 size_t count, loff_t *ppos)
98 struct hostaudio_state *state = file->private_data;
103 printk(KERN_DEBUG "hostaudio: write called, count = %d\n", count);
106 kbuf = kmalloc(count, GFP_KERNEL);
111 if (copy_from_user(kbuf, buffer, count))
114 err = os_write_file(state->fd, kbuf, count);
124 static unsigned int hostaudio_poll(struct file *file,
125 struct poll_table_struct *wait)
127 unsigned int mask = 0;
130 printk(KERN_DEBUG "hostaudio: poll called (unimplemented)\n");
136 static long hostaudio_ioctl(struct file *file,
137 unsigned int cmd, unsigned long arg)
139 struct hostaudio_state *state = file->private_data;
140 unsigned long data = 0;
144 printk(KERN_DEBUG "hostaudio: ioctl called, cmd = %u\n", cmd);
147 case SNDCTL_DSP_SPEED:
148 case SNDCTL_DSP_STEREO:
149 case SNDCTL_DSP_GETBLKSIZE:
150 case SNDCTL_DSP_CHANNELS:
151 case SNDCTL_DSP_SUBDIVIDE:
152 case SNDCTL_DSP_SETFRAGMENT:
153 if (get_user(data, (int __user *) arg))
160 err = os_ioctl_generic(state->fd, cmd, (unsigned long) &data);
163 case SNDCTL_DSP_SPEED:
164 case SNDCTL_DSP_STEREO:
165 case SNDCTL_DSP_GETBLKSIZE:
166 case SNDCTL_DSP_CHANNELS:
167 case SNDCTL_DSP_SUBDIVIDE:
168 case SNDCTL_DSP_SETFRAGMENT:
169 if (put_user(data, (int __user *) arg))
179 static int hostaudio_open(struct inode *inode, struct file *file)
181 struct hostaudio_state *state;
186 kparam_block_sysfs_write(dsp);
187 printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp);
188 kparam_unblock_sysfs_write(dsp);
191 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
195 if (file->f_mode & FMODE_READ)
197 if (file->f_mode & FMODE_WRITE)
200 kparam_block_sysfs_write(dsp);
202 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
204 kparam_unblock_sysfs_write(dsp);
211 file->private_data = state;
215 static int hostaudio_release(struct inode *inode, struct file *file)
217 struct hostaudio_state *state = file->private_data;
220 printk(KERN_DEBUG "hostaudio: release called\n");
222 os_close_file(state->fd);
228 /* /dev/mixer file operations */
230 static long hostmixer_ioctl_mixdev(struct file *file,
231 unsigned int cmd, unsigned long arg)
233 struct hostmixer_state *state = file->private_data;
236 printk(KERN_DEBUG "hostmixer: ioctl called\n");
239 return os_ioctl_generic(state->fd, cmd, arg);
242 static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
244 struct hostmixer_state *state;
249 printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer);
252 state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
256 if (file->f_mode & FMODE_READ)
258 if (file->f_mode & FMODE_WRITE)
261 kparam_block_sysfs_write(mixer);
263 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
265 kparam_unblock_sysfs_write(mixer);
268 kparam_block_sysfs_write(dsp);
269 printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', "
270 "err = %d\n", dsp, -ret);
271 kparam_unblock_sysfs_write(dsp);
276 file->private_data = state;
280 static int hostmixer_release(struct inode *inode, struct file *file)
282 struct hostmixer_state *state = file->private_data;
285 printk(KERN_DEBUG "hostmixer: release called\n");
288 os_close_file(state->fd);
294 /* kernel module operations */
296 static const struct file_operations hostaudio_fops = {
297 .owner = THIS_MODULE,
299 .read = hostaudio_read,
300 .write = hostaudio_write,
301 .poll = hostaudio_poll,
302 .unlocked_ioctl = hostaudio_ioctl,
304 .open = hostaudio_open,
305 .release = hostaudio_release,
308 static const struct file_operations hostmixer_fops = {
309 .owner = THIS_MODULE,
311 .unlocked_ioctl = hostmixer_ioctl_mixdev,
312 .open = hostmixer_open_mixdev,
313 .release = hostmixer_release,
321 MODULE_AUTHOR("Steve Schmidtke");
322 MODULE_DESCRIPTION("UML Audio Relay");
323 MODULE_LICENSE("GPL");
325 static int __init hostaudio_init_module(void)
327 __kernel_param_lock();
328 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
330 __kernel_param_unlock();
332 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
333 if (module_data.dev_audio < 0) {
334 printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
338 module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
339 if (module_data.dev_mixer < 0) {
340 printk(KERN_ERR "hostmixer: couldn't register mixer "
342 unregister_sound_dsp(module_data.dev_audio);
349 static void __exit hostaudio_cleanup_module (void)
351 unregister_sound_mixer(module_data.dev_mixer);
352 unregister_sound_dsp(module_data.dev_audio);
355 module_init(hostaudio_init_module);
356 module_exit(hostaudio_cleanup_module);