2 * Copyright (C) 2002 Steve Schmidtke
3 * Licensed under the GPL
6 #include "linux/config.h"
7 #include "linux/module.h"
8 #include "linux/init.h"
9 #include "linux/slab.h"
11 #include "linux/sound.h"
12 #include "linux/soundcard.h"
13 #include "asm/uaccess.h"
14 #include "kern_util.h"
16 #include "hostaudio.h"
18 /* Only changed from linux_main at boot time */
19 char *dsp = HOSTAUDIO_DEV_DSP;
20 char *mixer = HOSTAUDIO_DEV_MIXER;
23 " This is used to specify the host dsp device to the hostaudio driver.\n" \
24 " The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n"
27 " This is used to specify the host mixer device to the hostaudio driver.\n" \
28 " The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n"
31 static int set_dsp(char *name, int *add)
37 __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP);
39 static int set_mixer(char *name, int *add)
45 __uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP);
49 MODULE_PARM(dsp, "s");
50 MODULE_PARM_DESC(dsp, DSP_HELP);
52 MODULE_PARM(mixer, "s");
53 MODULE_PARM_DESC(mixer, MIXER_HELP);
57 /* /dev/dsp file operations */
59 static ssize_t hostaudio_read(struct file *file, char *buffer, size_t count,
62 struct hostaudio_state *state = file->private_data;
67 printk("hostaudio: read called, count = %d\n", count);
70 kbuf = kmalloc(count, GFP_KERNEL);
74 err = hostaudio_read_user(state, kbuf, count, ppos);
78 if(copy_to_user(buffer, kbuf, err))
86 static ssize_t hostaudio_write(struct file *file, const char *buffer,
87 size_t count, loff_t *ppos)
89 struct hostaudio_state *state = file->private_data;
94 printk("hostaudio: write called, count = %d\n", count);
97 kbuf = kmalloc(count, GFP_KERNEL);
102 if(copy_from_user(kbuf, buffer, count))
105 err = hostaudio_write_user(state, kbuf, count, ppos);
114 static unsigned int hostaudio_poll(struct file *file,
115 struct poll_table_struct *wait)
117 unsigned int mask = 0;
120 printk("hostaudio: poll called (unimplemented)\n");
126 static int hostaudio_ioctl(struct inode *inode, struct file *file,
127 unsigned int cmd, unsigned long arg)
129 struct hostaudio_state *state = file->private_data;
130 unsigned long data = 0;
134 printk("hostaudio: ioctl called, cmd = %u\n", cmd);
137 case SNDCTL_DSP_SPEED:
138 case SNDCTL_DSP_STEREO:
139 case SNDCTL_DSP_GETBLKSIZE:
140 case SNDCTL_DSP_CHANNELS:
141 case SNDCTL_DSP_SUBDIVIDE:
142 case SNDCTL_DSP_SETFRAGMENT:
143 if(get_user(data, (int *) arg))
150 err = hostaudio_ioctl_user(state, cmd, (unsigned long) &data);
153 case SNDCTL_DSP_SPEED:
154 case SNDCTL_DSP_STEREO:
155 case SNDCTL_DSP_GETBLKSIZE:
156 case SNDCTL_DSP_CHANNELS:
157 case SNDCTL_DSP_SUBDIVIDE:
158 case SNDCTL_DSP_SETFRAGMENT:
159 if(put_user(data, (int *) arg))
169 static int hostaudio_open(struct inode *inode, struct file *file)
171 struct hostaudio_state *state;
176 printk("hostaudio: open called (host: %s)\n", dsp);
179 state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL);
180 if(state == NULL) return(-ENOMEM);
182 if(file->f_mode & FMODE_READ) r = 1;
183 if(file->f_mode & FMODE_WRITE) w = 1;
185 ret = hostaudio_open_user(state, r, w, dsp);
191 file->private_data = state;
195 static int hostaudio_release(struct inode *inode, struct file *file)
197 struct hostaudio_state *state = file->private_data;
201 printk("hostaudio: release called\n");
204 ret = hostaudio_release_user(state);
210 /* /dev/mixer file operations */
212 static int hostmixer_ioctl_mixdev(struct inode *inode, struct file *file,
213 unsigned int cmd, unsigned long arg)
215 struct hostmixer_state *state = file->private_data;
218 printk("hostmixer: ioctl called\n");
221 return(hostmixer_ioctl_mixdev_user(state, cmd, arg));
224 static int hostmixer_open_mixdev(struct inode *inode, struct file *file)
226 struct hostmixer_state *state;
231 printk("hostmixer: open called (host: %s)\n", mixer);
234 state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL);
235 if(state == NULL) return(-ENOMEM);
237 if(file->f_mode & FMODE_READ) r = 1;
238 if(file->f_mode & FMODE_WRITE) w = 1;
240 ret = hostmixer_open_mixdev_user(state, r, w, mixer);
247 file->private_data = state;
251 static int hostmixer_release(struct inode *inode, struct file *file)
253 struct hostmixer_state *state = file->private_data;
257 printk("hostmixer: release called\n");
260 ret = hostmixer_release_mixdev_user(state);
267 /* kernel module operations */
269 static struct file_operations hostaudio_fops = {
270 .owner = THIS_MODULE,
272 .read = hostaudio_read,
273 .write = hostaudio_write,
274 .poll = hostaudio_poll,
275 .ioctl = hostaudio_ioctl,
277 .open = hostaudio_open,
278 .release = hostaudio_release,
281 static struct file_operations hostmixer_fops = {
282 .owner = THIS_MODULE,
284 .ioctl = hostmixer_ioctl_mixdev,
285 .open = hostmixer_open_mixdev,
286 .release = hostmixer_release,
294 MODULE_AUTHOR("Steve Schmidtke");
295 MODULE_DESCRIPTION("UML Audio Relay");
296 MODULE_LICENSE("GPL");
298 static int __init hostaudio_init_module(void)
300 printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n",
303 module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1);
304 if(module_data.dev_audio < 0){
305 printk(KERN_ERR "hostaudio: couldn't register DSP device!\n");
309 module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1);
310 if(module_data.dev_mixer < 0){
311 printk(KERN_ERR "hostmixer: couldn't register mixer "
313 unregister_sound_dsp(module_data.dev_audio);
320 static void __exit hostaudio_cleanup_module (void)
322 unregister_sound_mixer(module_data.dev_mixer);
323 unregister_sound_dsp(module_data.dev_audio);
326 module_init(hostaudio_init_module);
327 module_exit(hostaudio_cleanup_module);
330 * Overrides for Emacs so that we follow Linus's tabbing style.
331 * Emacs will notice this stuff at the end of the file and automatically
332 * adjust the settings for this buffer only. This must remain at the end
334 * ---------------------------------------------------------------------------
336 * c-file-style: "linux"