2 * Copyright (C) 2002 Steve Schmidtke
3 * Licensed under the GPL
6 #include "linux/module.h"
7 #include "linux/init.h"
8 #include "linux/slab.h"
10 #include "linux/sound.h"
11 #include "linux/soundcard.h"
12 #include "asm/uaccess.h"
13 #include "kern_util.h"
17 struct hostaudio_state {
21 struct hostmixer_state {
25 #define HOSTAUDIO_DEV_DSP "/dev/sound/dsp"
26 #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"
44 static int set_dsp(char *name, int *add)
50 __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
52 static int set_mixer(char *name, int *add)
58 __uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP);
62 module_param(dsp, charp, 0644);
63 MODULE_PARM_DESC(dsp, DSP_HELP);
65 module_param(mixer, charp, 0644);
66 MODULE_PARM_DESC(mixer, MIXER_HELP);
70 /* /dev/dsp file operations */
72 static ssize_t hostaudio_read(struct file *file, char __user *buffer,
73 size_t count, loff_t *ppos)
75 struct hostaudio_state *state = file->private_data;
80 printk("hostaudio: read called, count = %d\n", count);
83 kbuf = kmalloc(count, GFP_KERNEL);
87 err = os_read_file(state->fd, kbuf, count);
91 if(copy_to_user(buffer, kbuf, err))
99 static ssize_t hostaudio_write(struct file *file, const char __user *buffer,
100 size_t count, loff_t *ppos)
102 struct hostaudio_state *state = file->private_data;
107 printk("hostaudio: write called, count = %d\n", count);
110 kbuf = kmalloc(count, GFP_KERNEL);
115 if(copy_from_user(kbuf, buffer, count))
118 err = os_write_file(state->fd, kbuf, count);
128 static unsigned int hostaudio_poll(struct file *file,
129 struct poll_table_struct *wait)
131 unsigned int mask = 0;
134 printk("hostaudio: poll called (unimplemented)\n");
140 static int hostaudio_ioctl(struct inode *inode, struct file *file,
141 unsigned int cmd, unsigned long arg)
143 struct hostaudio_state *state = file->private_data;
144 unsigned long data = 0;
148 printk("hostaudio: ioctl called, cmd = %u\n", cmd);
151 case SNDCTL_DSP_SPEED:
152 case SNDCTL_DSP_STEREO:
153 case SNDCTL_DSP_GETBLKSIZE:
154 case SNDCTL_DSP_CHANNELS:
155 case SNDCTL_DSP_SUBDIVIDE:
156 case SNDCTL_DSP_SETFRAGMENT:
157 if(get_user(data, (int __user *) arg))
164 err = os_ioctl_generic(state->fd, cmd, (unsigned long) &data);
167 case SNDCTL_DSP_SPEED:
168 case SNDCTL_DSP_STEREO:
169 case SNDCTL_DSP_GETBLKSIZE:
170 case SNDCTL_DSP_CHANNELS:
171 case SNDCTL_DSP_SUBDIVIDE:
172 case SNDCTL_DSP_SETFRAGMENT:
173 if(put_user(data, (int __user *) arg))
183 static int hostaudio_open(struct inode *inode, struct file *file)
185 struct hostaudio_state *state;
190 printk("hostaudio: open called (host: %s)\n", dsp);
193 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
197 if(file->f_mode & FMODE_READ) r = 1;
198 if(file->f_mode & FMODE_WRITE) w = 1;
200 ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
207 file->private_data = state;
211 static int hostaudio_release(struct inode *inode, struct file *file)
213 struct hostaudio_state *state = file->private_data;
216 printk("hostaudio: release called\n");
219 os_close_file(state->fd);
225 /* /dev/mixer file operations */
227 static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file,
228 unsigned int cmd, unsigned long arg)
230 struct hostmixer_state *state = file->private_data;
233 printk("hostmixer: ioctl called\n");
236 return(os_ioctl_generic(state->fd, cmd, arg));
239 static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
241 struct hostmixer_state *state;
246 printk("hostmixer: open called (host: %s)\n", mixer);
249 state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
250 if(state == NULL) return(-ENOMEM);
252 if(file->f_mode & FMODE_READ) r = 1;
253 if(file->f_mode & FMODE_WRITE) w = 1;
255 ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
258 printk("hostaudio_open_mixdev failed to open '%s', err = %d\n",
264 file->private_data = state;
268 static int hostmixer_release(struct inode *inode, struct file *file)
270 struct hostmixer_state *state = file->private_data;
273 printk("hostmixer: release called\n");
276 os_close_file(state->fd);
283 /* kernel module operations */
285 static const struct file_operations hostaudio_fops = {
286 .owner = THIS_MODULE,
288 .read = hostaudio_read,
289 .write = hostaudio_write,
290 .poll = hostaudio_poll,
291 .ioctl = hostaudio_ioctl,
293 .open = hostaudio_open,
294 .release = hostaudio_release,
297 static const struct file_operations hostmixer_fops = {
298 .owner = THIS_MODULE,
300 .ioctl = hostmixer_ioctl_mixdev,
301 .open = hostmixer_open_mixdev,
302 .release = hostmixer_release,
310 MODULE_AUTHOR("Steve Schmidtke");
311 MODULE_DESCRIPTION("UML Audio Relay");
312 MODULE_LICENSE("GPL");
314 static int __init hostaudio_init_module(void)
316 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
319 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
320 if(module_data.dev_audio < 0){
321 printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
325 module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
326 if(module_data.dev_mixer < 0){
327 printk(KERN_ERR "hostmixer: couldn't register mixer "
329 unregister_sound_dsp(module_data.dev_audio);
336 static void __exit hostaudio_cleanup_module (void)
338 unregister_sound_mixer(module_data.dev_mixer);
339 unregister_sound_dsp(module_data.dev_audio);
342 module_init(hostaudio_init_module);
343 module_exit(hostaudio_cleanup_module);
346 * Overrides for Emacs so that we follow Linus's tabbing style.
347 * Emacs will notice this stuff at the end of the file and automatically
348 * adjust the settings for this buffer only. This must remain at the end
350 * ---------------------------------------------------------------------------
352 * c-file-style: "linux"