Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 Steve Schmidtke |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Al Viro | 37185b3 | 2012-10-08 03:27:32 +0100 | [diff] [blame] | 6 | #include <linux/fs.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/slab.h> |
| 9 | #include <linux/sound.h> |
| 10 | #include <linux/soundcard.h> |
| 11 | #include <linux/mutex.h> |
| 12 | #include <asm/uaccess.h> |
| 13 | #include <init.h> |
| 14 | #include <os.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | struct hostaudio_state { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 17 | int fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | struct hostmixer_state { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 21 | int fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | #define HOSTAUDIO_DEV_DSP "/dev/sound/dsp" |
| 25 | #define HOSTAUDIO_DEV_MIXER "/dev/sound/mixer" |
| 26 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 27 | /* |
| 28 | * Changed either at boot time or module load time. At boot, this is |
Jeff Dike | b612e47 | 2007-02-10 01:43:59 -0800 | [diff] [blame] | 29 | * single-threaded; at module load, multiple modules would each have |
| 30 | * their own copy of these variables. |
| 31 | */ |
| 32 | static char *dsp = HOSTAUDIO_DEV_DSP; |
| 33 | static char *mixer = HOSTAUDIO_DEV_MIXER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | #define DSP_HELP \ |
| 36 | " This is used to specify the host dsp device to the hostaudio driver.\n" \ |
| 37 | " The default is \"" HOSTAUDIO_DEV_DSP "\".\n\n" |
| 38 | |
| 39 | #define MIXER_HELP \ |
| 40 | " This is used to specify the host mixer device to the hostaudio driver.\n"\ |
| 41 | " The default is \"" HOSTAUDIO_DEV_MIXER "\".\n\n" |
| 42 | |
FUJITA Tomonori | e3c6cf6 | 2010-10-15 14:34:13 -0700 | [diff] [blame] | 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); |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #ifndef MODULE |
| 49 | static int set_dsp(char *name, int *add) |
| 50 | { |
| 51 | dsp = name; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 52 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | __uml_setup("dsp=", set_dsp, "dsp=<dsp device>\n" DSP_HELP); |
| 56 | |
| 57 | static int set_mixer(char *name, int *add) |
| 58 | { |
| 59 | mixer = name; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 60 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | __uml_setup("mixer=", set_mixer, "mixer=<mixer device>\n" MIXER_HELP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #endif |
| 65 | |
Arnd Bergmann | 9a181c5 | 2010-09-11 18:38:03 +0200 | [diff] [blame] | 66 | static DEFINE_MUTEX(hostaudio_mutex); |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* /dev/dsp file operations */ |
| 69 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 70 | static ssize_t hostaudio_read(struct file *file, char __user *buffer, |
| 71 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 73 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | void *kbuf; |
| 75 | int err; |
| 76 | |
| 77 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 78 | printk(KERN_DEBUG "hostaudio: read called, count = %d\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #endif |
| 80 | |
| 81 | kbuf = kmalloc(count, GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 82 | if (kbuf == NULL) |
| 83 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Jeff Dike | a6ea4cc | 2007-05-06 14:51:43 -0700 | [diff] [blame] | 85 | err = os_read_file(state->fd, kbuf, count); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 86 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | goto out; |
| 88 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 89 | if (copy_to_user(buffer, kbuf, err)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | err = -EFAULT; |
| 91 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 92 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | kfree(kbuf); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 94 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Al Viro | 4d338e1 | 2006-03-31 02:30:15 -0800 | [diff] [blame] | 97 | static ssize_t hostaudio_write(struct file *file, const char __user *buffer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | size_t count, loff_t *ppos) |
| 99 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 100 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | void *kbuf; |
| 102 | int err; |
| 103 | |
| 104 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 105 | printk(KERN_DEBUG "hostaudio: write called, count = %d\n", count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #endif |
| 107 | |
| 108 | kbuf = kmalloc(count, GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 109 | if (kbuf == NULL) |
| 110 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | err = -EFAULT; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 113 | if (copy_from_user(kbuf, buffer, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | goto out; |
| 115 | |
Jeff Dike | a6ea4cc | 2007-05-06 14:51:43 -0700 | [diff] [blame] | 116 | err = os_write_file(state->fd, kbuf, count); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 117 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | goto out; |
| 119 | *ppos += err; |
| 120 | |
| 121 | out: |
| 122 | kfree(kbuf); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 123 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 126 | static unsigned int hostaudio_poll(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | struct poll_table_struct *wait) |
| 128 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 129 | unsigned int mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 132 | printk(KERN_DEBUG "hostaudio: poll called (unimplemented)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #endif |
| 134 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 135 | return mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
John Kacur | d6c89d9 | 2010-05-07 17:34:28 +0200 | [diff] [blame] | 138 | static long hostaudio_ioctl(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | unsigned int cmd, unsigned long arg) |
| 140 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 141 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | unsigned long data = 0; |
| 143 | int err; |
| 144 | |
| 145 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 146 | printk(KERN_DEBUG "hostaudio: ioctl called, cmd = %u\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #endif |
| 148 | switch(cmd){ |
| 149 | case SNDCTL_DSP_SPEED: |
| 150 | case SNDCTL_DSP_STEREO: |
| 151 | case SNDCTL_DSP_GETBLKSIZE: |
| 152 | case SNDCTL_DSP_CHANNELS: |
| 153 | case SNDCTL_DSP_SUBDIVIDE: |
| 154 | case SNDCTL_DSP_SETFRAGMENT: |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 155 | if (get_user(data, (int __user *) arg)) |
Johann Felix Soden | 484f1e2 | 2008-05-12 14:01:51 -0700 | [diff] [blame] | 156 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | break; |
| 158 | default: |
| 159 | break; |
| 160 | } |
| 161 | |
| 162 | err = os_ioctl_generic(state->fd, cmd, (unsigned long) &data); |
| 163 | |
| 164 | switch(cmd){ |
| 165 | case SNDCTL_DSP_SPEED: |
| 166 | case SNDCTL_DSP_STEREO: |
| 167 | case SNDCTL_DSP_GETBLKSIZE: |
| 168 | case SNDCTL_DSP_CHANNELS: |
| 169 | case SNDCTL_DSP_SUBDIVIDE: |
| 170 | case SNDCTL_DSP_SETFRAGMENT: |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 171 | if (put_user(data, (int __user *) arg)) |
| 172 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | break; |
| 174 | default: |
| 175 | break; |
| 176 | } |
| 177 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 178 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static int hostaudio_open(struct inode *inode, struct file *file) |
| 182 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 183 | struct hostaudio_state *state; |
| 184 | int r = 0, w = 0; |
| 185 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | #ifdef DEBUG |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 188 | kernel_param_lock(THIS_MODULE); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 189 | printk(KERN_DEBUG "hostaudio: open called (host: %s)\n", dsp); |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 190 | kernel_param_unlock(THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | #endif |
| 192 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 193 | state = kmalloc(sizeof(struct hostaudio_state), GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 194 | if (state == NULL) |
| 195 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 197 | if (file->f_mode & FMODE_READ) |
| 198 | r = 1; |
| 199 | if (file->f_mode & FMODE_WRITE) |
| 200 | w = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 202 | kernel_param_lock(THIS_MODULE); |
Arnd Bergmann | 9a181c5 | 2010-09-11 18:38:03 +0200 | [diff] [blame] | 203 | mutex_lock(&hostaudio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | ret = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0); |
Arnd Bergmann | 9a181c5 | 2010-09-11 18:38:03 +0200 | [diff] [blame] | 205 | mutex_unlock(&hostaudio_mutex); |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 206 | kernel_param_unlock(THIS_MODULE); |
Arnd Bergmann | 90dc763 | 2010-07-11 12:16:36 +0200 | [diff] [blame] | 207 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 208 | if (ret < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | kfree(state); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 210 | return ret; |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | state->fd = ret; |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 213 | file->private_data = state; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 214 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static int hostaudio_release(struct inode *inode, struct file *file) |
| 218 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 219 | struct hostaudio_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 222 | printk(KERN_DEBUG "hostaudio: release called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | #endif |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 224 | os_close_file(state->fd); |
| 225 | kfree(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 227 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* /dev/mixer file operations */ |
| 231 | |
John Kacur | d6c89d9 | 2010-05-07 17:34:28 +0200 | [diff] [blame] | 232 | static long hostmixer_ioctl_mixdev(struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | unsigned int cmd, unsigned long arg) |
| 234 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 235 | struct hostmixer_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 238 | printk(KERN_DEBUG "hostmixer: ioctl called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | #endif |
| 240 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 241 | return os_ioctl_generic(state->fd, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static int hostmixer_open_mixdev(struct inode *inode, struct file *file) |
| 245 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 246 | struct hostmixer_state *state; |
| 247 | int r = 0, w = 0; |
| 248 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 251 | printk(KERN_DEBUG "hostmixer: open called (host: %s)\n", mixer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | #endif |
| 253 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 254 | state = kmalloc(sizeof(struct hostmixer_state), GFP_KERNEL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 255 | if (state == NULL) |
| 256 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 258 | if (file->f_mode & FMODE_READ) |
| 259 | r = 1; |
| 260 | if (file->f_mode & FMODE_WRITE) |
| 261 | w = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 263 | kernel_param_lock(THIS_MODULE); |
Arnd Bergmann | 9a181c5 | 2010-09-11 18:38:03 +0200 | [diff] [blame] | 264 | mutex_lock(&hostaudio_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | ret = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0); |
Arnd Bergmann | 9a181c5 | 2010-09-11 18:38:03 +0200 | [diff] [blame] | 266 | mutex_unlock(&hostaudio_mutex); |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 267 | kernel_param_unlock(THIS_MODULE); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 268 | |
| 269 | if (ret < 0) { |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 270 | kernel_param_lock(THIS_MODULE); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 271 | printk(KERN_ERR "hostaudio_open_mixdev failed to open '%s', " |
| 272 | "err = %d\n", dsp, -ret); |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 273 | kernel_param_unlock(THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | kfree(state); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 275 | return ret; |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 278 | file->private_data = state; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 279 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static int hostmixer_release(struct inode *inode, struct file *file) |
| 283 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 284 | struct hostmixer_state *state = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | #ifdef DEBUG |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 287 | printk(KERN_DEBUG "hostmixer: release called\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | #endif |
| 289 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 290 | os_close_file(state->fd); |
| 291 | kfree(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 293 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* kernel module operations */ |
| 297 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 298 | static const struct file_operations hostaudio_fops = { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 299 | .owner = THIS_MODULE, |
| 300 | .llseek = no_llseek, |
| 301 | .read = hostaudio_read, |
| 302 | .write = hostaudio_write, |
| 303 | .poll = hostaudio_poll, |
John Kacur | d6c89d9 | 2010-05-07 17:34:28 +0200 | [diff] [blame] | 304 | .unlocked_ioctl = hostaudio_ioctl, |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 305 | .mmap = NULL, |
| 306 | .open = hostaudio_open, |
| 307 | .release = hostaudio_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | }; |
| 309 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 310 | static const struct file_operations hostmixer_fops = { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 311 | .owner = THIS_MODULE, |
| 312 | .llseek = no_llseek, |
John Kacur | d6c89d9 | 2010-05-07 17:34:28 +0200 | [diff] [blame] | 313 | .unlocked_ioctl = hostmixer_ioctl_mixdev, |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 314 | .open = hostmixer_open_mixdev, |
| 315 | .release = hostmixer_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | struct { |
| 319 | int dev_audio; |
| 320 | int dev_mixer; |
| 321 | } module_data; |
| 322 | |
| 323 | MODULE_AUTHOR("Steve Schmidtke"); |
| 324 | MODULE_DESCRIPTION("UML Audio Relay"); |
| 325 | MODULE_LICENSE("GPL"); |
| 326 | |
| 327 | static int __init hostaudio_init_module(void) |
| 328 | { |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 329 | kernel_param_lock(THIS_MODULE); |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 330 | printk(KERN_INFO "UML Audio Relay (host dsp = %s, host mixer = %s)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | dsp, mixer); |
Dan Streetman | b51d23e | 2015-06-17 06:18:52 +0930 | [diff] [blame^] | 332 | kernel_param_unlock(THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | module_data.dev_audio = register_sound_dsp(&hostaudio_fops, -1); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 335 | if (module_data.dev_audio < 0) { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 336 | printk(KERN_ERR "hostaudio: couldn't register DSP device!\n"); |
| 337 | return -ENODEV; |
| 338 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | module_data.dev_mixer = register_sound_mixer(&hostmixer_fops, -1); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 341 | if (module_data.dev_mixer < 0) { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 342 | printk(KERN_ERR "hostmixer: couldn't register mixer " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | "device!\n"); |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 344 | unregister_sound_dsp(module_data.dev_audio); |
| 345 | return -ENODEV; |
| 346 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void __exit hostaudio_cleanup_module (void) |
| 352 | { |
Jeff Dike | d471c0f | 2007-02-10 01:44:00 -0800 | [diff] [blame] | 353 | unregister_sound_mixer(module_data.dev_mixer); |
| 354 | unregister_sound_dsp(module_data.dev_audio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | module_init(hostaudio_init_module); |
| 358 | module_exit(hostaudio_cleanup_module); |