Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Uwe Zeisberger | f30c226 | 2006-10-03 23:01:26 +0200 | [diff] [blame] | 2 | * linux/sound/oss/soundcard.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Sound card driver for Linux |
| 5 | * |
| 6 | * |
| 7 | * Copyright (C) by Hannu Savolainen 1993-1997 |
| 8 | * |
| 9 | * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL) |
| 10 | * Version 2 (June 1991). See the "COPYING" file distributed with this software |
| 11 | * for more info. |
| 12 | * |
| 13 | * |
| 14 | * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed) |
| 15 | * integrated sound_switch.c |
| 16 | * Stefan Reinauer : integrated /proc/sound (equals to /dev/sndstat, |
| 17 | * which should disappear in the near future) |
| 18 | * Eric Dumas : devfs support (22-Jan-98) <dumas@linux.eu.org> with |
| 19 | * fixups by C. Scott Ananian <cananian@alumni.princeton.edu> |
| 20 | * Richard Gooch : moved common (non OSS-specific) devices to sound_core.c |
| 21 | * Rob Riggs : Added persistent DMA buffers support (1998/10/17) |
| 22 | * Christoph Hellwig : Some cleanup work (2000/03/01) |
| 23 | */ |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "sound_config.h" |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/signal.h> |
| 31 | #include <linux/fcntl.h> |
| 32 | #include <linux/ctype.h> |
| 33 | #include <linux/stddef.h> |
| 34 | #include <linux/kmod.h> |
| 35 | #include <asm/dma.h> |
| 36 | #include <asm/io.h> |
| 37 | #include <linux/wait.h> |
| 38 | #include <linux/slab.h> |
| 39 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/major.h> |
| 41 | #include <linux/delay.h> |
| 42 | #include <linux/proc_fs.h> |
| 43 | #include <linux/smp_lock.h> |
| 44 | #include <linux/module.h> |
| 45 | |
| 46 | /* |
| 47 | * This ought to be moved into include/asm/dma.h |
| 48 | */ |
| 49 | #ifndef valid_dma |
| 50 | #define valid_dma(n) ((n) >= 0 && (n) < MAX_DMA_CHANNELS && (n) != 4) |
| 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * Table for permanently allocated memory (used when unloading the module) |
| 55 | */ |
| 56 | void * sound_mem_blocks[1024]; |
| 57 | int sound_nblocks = 0; |
| 58 | |
| 59 | /* Persistent DMA buffers */ |
| 60 | #ifdef CONFIG_SOUND_DMAP |
| 61 | int sound_dmap_flag = 1; |
| 62 | #else |
| 63 | int sound_dmap_flag = 0; |
| 64 | #endif |
| 65 | |
| 66 | static char dma_alloc_map[MAX_DMA_CHANNELS]; |
| 67 | |
| 68 | #define DMA_MAP_UNAVAIL 0 |
| 69 | #define DMA_MAP_FREE 1 |
| 70 | #define DMA_MAP_BUSY 2 |
| 71 | |
| 72 | |
| 73 | unsigned long seq_time = 0; /* Time for /dev/sequencer */ |
gregkh@suse.de | 619e666 | 2005-03-23 09:51:41 -0800 | [diff] [blame] | 74 | extern struct class *sound_class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Table for configurable mixer volume handling |
| 78 | */ |
| 79 | static mixer_vol_table mixer_vols[MAX_MIXER_DEV]; |
| 80 | static int num_mixer_volumes; |
| 81 | |
| 82 | int *load_mixer_volumes(char *name, int *levels, int present) |
| 83 | { |
| 84 | int i, n; |
| 85 | |
| 86 | for (i = 0; i < num_mixer_volumes; i++) { |
| 87 | if (strcmp(name, mixer_vols[i].name) == 0) { |
| 88 | if (present) |
| 89 | mixer_vols[i].num = i; |
| 90 | return mixer_vols[i].levels; |
| 91 | } |
| 92 | } |
| 93 | if (num_mixer_volumes >= MAX_MIXER_DEV) { |
| 94 | printk(KERN_ERR "Sound: Too many mixers (%s)\n", name); |
| 95 | return levels; |
| 96 | } |
| 97 | n = num_mixer_volumes++; |
| 98 | |
| 99 | strcpy(mixer_vols[n].name, name); |
| 100 | |
| 101 | if (present) |
| 102 | mixer_vols[n].num = n; |
| 103 | else |
| 104 | mixer_vols[n].num = -1; |
| 105 | |
| 106 | for (i = 0; i < 32; i++) |
| 107 | mixer_vols[n].levels[i] = levels[i]; |
| 108 | return mixer_vols[n].levels; |
| 109 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 110 | EXPORT_SYMBOL(load_mixer_volumes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | static int set_mixer_levels(void __user * arg) |
| 113 | { |
| 114 | /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */ |
| 115 | mixer_vol_table buf; |
| 116 | |
| 117 | if (__copy_from_user(&buf, arg, sizeof(buf))) |
| 118 | return -EFAULT; |
| 119 | load_mixer_volumes(buf.name, buf.levels, 0); |
| 120 | if (__copy_to_user(arg, &buf, sizeof(buf))) |
| 121 | return -EFAULT; |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static int get_mixer_levels(void __user * arg) |
| 126 | { |
| 127 | int n; |
| 128 | |
| 129 | if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num)))) |
| 130 | return -EFAULT; |
| 131 | if (n < 0 || n >= num_mixer_volumes) |
| 132 | return -EINVAL; |
| 133 | if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table))) |
| 134 | return -EFAULT; |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* 4K page size but our output routines use some slack for overruns */ |
| 139 | #define PROC_BLOCK_SIZE (3*1024) |
| 140 | |
| 141 | static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
| 142 | { |
| 143 | int dev = iminor(file->f_dentry->d_inode); |
| 144 | int ret = -EINVAL; |
| 145 | |
| 146 | /* |
| 147 | * The OSS drivers aren't remotely happy without this locking, |
| 148 | * and unless someone fixes them when they are about to bite the |
| 149 | * big one anyway, we might as well bandage here.. |
| 150 | */ |
| 151 | |
| 152 | lock_kernel(); |
| 153 | |
| 154 | DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count)); |
| 155 | switch (dev & 0x0f) { |
| 156 | case SND_DEV_DSP: |
| 157 | case SND_DEV_DSP16: |
| 158 | case SND_DEV_AUDIO: |
| 159 | ret = audio_read(dev, file, buf, count); |
| 160 | break; |
| 161 | |
| 162 | case SND_DEV_SEQ: |
| 163 | case SND_DEV_SEQ2: |
| 164 | ret = sequencer_read(dev, file, buf, count); |
| 165 | break; |
| 166 | |
| 167 | case SND_DEV_MIDIN: |
| 168 | ret = MIDIbuf_read(dev, file, buf, count); |
| 169 | } |
| 170 | unlock_kernel(); |
| 171 | return ret; |
| 172 | } |
| 173 | |
| 174 | static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
| 175 | { |
| 176 | int dev = iminor(file->f_dentry->d_inode); |
| 177 | int ret = -EINVAL; |
| 178 | |
| 179 | lock_kernel(); |
| 180 | DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count)); |
| 181 | switch (dev & 0x0f) { |
| 182 | case SND_DEV_SEQ: |
| 183 | case SND_DEV_SEQ2: |
| 184 | ret = sequencer_write(dev, file, buf, count); |
| 185 | break; |
| 186 | |
| 187 | case SND_DEV_DSP: |
| 188 | case SND_DEV_DSP16: |
| 189 | case SND_DEV_AUDIO: |
| 190 | ret = audio_write(dev, file, buf, count); |
| 191 | break; |
| 192 | |
| 193 | case SND_DEV_MIDIN: |
| 194 | ret = MIDIbuf_write(dev, file, buf, count); |
| 195 | break; |
| 196 | } |
| 197 | unlock_kernel(); |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | static int sound_open(struct inode *inode, struct file *file) |
| 202 | { |
| 203 | int dev = iminor(inode); |
| 204 | int retval; |
| 205 | |
| 206 | DEB(printk("sound_open(dev=%d)\n", dev)); |
| 207 | if ((dev >= SND_NDEVS) || (dev < 0)) { |
| 208 | printk(KERN_ERR "Invalid minor device %d\n", dev); |
| 209 | return -ENXIO; |
| 210 | } |
| 211 | switch (dev & 0x0f) { |
| 212 | case SND_DEV_CTL: |
| 213 | dev >>= 4; |
| 214 | if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) { |
| 215 | request_module("mixer%d", dev); |
| 216 | } |
| 217 | if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL)) |
| 218 | return -ENXIO; |
| 219 | |
| 220 | if (!try_module_get(mixer_devs[dev]->owner)) |
| 221 | return -ENXIO; |
| 222 | break; |
| 223 | |
| 224 | case SND_DEV_SEQ: |
| 225 | case SND_DEV_SEQ2: |
| 226 | if ((retval = sequencer_open(dev, file)) < 0) |
| 227 | return retval; |
| 228 | break; |
| 229 | |
| 230 | case SND_DEV_MIDIN: |
| 231 | if ((retval = MIDIbuf_open(dev, file)) < 0) |
| 232 | return retval; |
| 233 | break; |
| 234 | |
| 235 | case SND_DEV_DSP: |
| 236 | case SND_DEV_DSP16: |
| 237 | case SND_DEV_AUDIO: |
| 238 | if ((retval = audio_open(dev, file)) < 0) |
| 239 | return retval; |
| 240 | break; |
| 241 | |
| 242 | default: |
| 243 | printk(KERN_ERR "Invalid minor device %d\n", dev); |
| 244 | return -ENXIO; |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static int sound_release(struct inode *inode, struct file *file) |
| 251 | { |
| 252 | int dev = iminor(inode); |
| 253 | |
| 254 | lock_kernel(); |
| 255 | DEB(printk("sound_release(dev=%d)\n", dev)); |
| 256 | switch (dev & 0x0f) { |
| 257 | case SND_DEV_CTL: |
| 258 | module_put(mixer_devs[dev >> 4]->owner); |
| 259 | break; |
| 260 | |
| 261 | case SND_DEV_SEQ: |
| 262 | case SND_DEV_SEQ2: |
| 263 | sequencer_release(dev, file); |
| 264 | break; |
| 265 | |
| 266 | case SND_DEV_MIDIN: |
| 267 | MIDIbuf_release(dev, file); |
| 268 | break; |
| 269 | |
| 270 | case SND_DEV_DSP: |
| 271 | case SND_DEV_DSP16: |
| 272 | case SND_DEV_AUDIO: |
| 273 | audio_release(dev, file); |
| 274 | break; |
| 275 | |
| 276 | default: |
| 277 | printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev); |
| 278 | } |
| 279 | unlock_kernel(); |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static int get_mixer_info(int dev, void __user *arg) |
| 285 | { |
| 286 | mixer_info info; |
| 287 | memset(&info, 0, sizeof(info)); |
| 288 | strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id)); |
| 289 | strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name)); |
| 290 | info.modify_counter = mixer_devs[dev]->modify_counter; |
| 291 | if (__copy_to_user(arg, &info, sizeof(info))) |
| 292 | return -EFAULT; |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static int get_old_mixer_info(int dev, void __user *arg) |
| 297 | { |
| 298 | _old_mixer_info info; |
| 299 | memset(&info, 0, sizeof(info)); |
| 300 | strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id)); |
| 301 | strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name)); |
| 302 | if (copy_to_user(arg, &info, sizeof(info))) |
| 303 | return -EFAULT; |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg) |
| 308 | { |
| 309 | if (mixdev < 0 || mixdev >= MAX_MIXER_DEV) |
| 310 | return -ENXIO; |
| 311 | /* Try to load the mixer... */ |
| 312 | if (mixer_devs[mixdev] == NULL) { |
| 313 | request_module("mixer%d", mixdev); |
| 314 | } |
| 315 | if (mixdev >= num_mixers || !mixer_devs[mixdev]) |
| 316 | return -ENXIO; |
| 317 | if (cmd == SOUND_MIXER_INFO) |
| 318 | return get_mixer_info(mixdev, arg); |
| 319 | if (cmd == SOUND_OLD_MIXER_INFO) |
| 320 | return get_old_mixer_info(mixdev, arg); |
| 321 | if (_SIOC_DIR(cmd) & _SIOC_WRITE) |
| 322 | mixer_devs[mixdev]->modify_counter++; |
| 323 | if (!mixer_devs[mixdev]->ioctl) |
| 324 | return -EINVAL; |
| 325 | return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg); |
| 326 | } |
| 327 | |
| 328 | static int sound_ioctl(struct inode *inode, struct file *file, |
| 329 | unsigned int cmd, unsigned long arg) |
| 330 | { |
| 331 | int len = 0, dtype; |
| 332 | int dev = iminor(inode); |
| 333 | void __user *p = (void __user *)arg; |
| 334 | |
| 335 | if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) { |
| 336 | /* |
| 337 | * Have to validate the address given by the process. |
| 338 | */ |
| 339 | len = _SIOC_SIZE(cmd); |
| 340 | if (len < 1 || len > 65536 || !p) |
| 341 | return -EFAULT; |
| 342 | if (_SIOC_DIR(cmd) & _SIOC_WRITE) |
| 343 | if (!access_ok(VERIFY_READ, p, len)) |
| 344 | return -EFAULT; |
| 345 | if (_SIOC_DIR(cmd) & _SIOC_READ) |
| 346 | if (!access_ok(VERIFY_WRITE, p, len)) |
| 347 | return -EFAULT; |
| 348 | } |
| 349 | DEB(printk("sound_ioctl(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg)); |
| 350 | if (cmd == OSS_GETVERSION) |
| 351 | return __put_user(SOUND_VERSION, (int __user *)p); |
| 352 | |
| 353 | if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */ |
| 354 | (dev & 0x0f) != SND_DEV_CTL) { |
| 355 | dtype = dev & 0x0f; |
| 356 | switch (dtype) { |
| 357 | case SND_DEV_DSP: |
| 358 | case SND_DEV_DSP16: |
| 359 | case SND_DEV_AUDIO: |
| 360 | return sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev, |
| 361 | cmd, p); |
| 362 | |
| 363 | default: |
| 364 | return sound_mixer_ioctl(dev >> 4, cmd, p); |
| 365 | } |
| 366 | } |
| 367 | switch (dev & 0x0f) { |
| 368 | case SND_DEV_CTL: |
| 369 | if (cmd == SOUND_MIXER_GETLEVELS) |
| 370 | return get_mixer_levels(p); |
| 371 | if (cmd == SOUND_MIXER_SETLEVELS) |
| 372 | return set_mixer_levels(p); |
| 373 | return sound_mixer_ioctl(dev >> 4, cmd, p); |
| 374 | |
| 375 | case SND_DEV_SEQ: |
| 376 | case SND_DEV_SEQ2: |
| 377 | return sequencer_ioctl(dev, file, cmd, p); |
| 378 | |
| 379 | case SND_DEV_DSP: |
| 380 | case SND_DEV_DSP16: |
| 381 | case SND_DEV_AUDIO: |
| 382 | return audio_ioctl(dev, file, cmd, p); |
| 383 | break; |
| 384 | |
| 385 | case SND_DEV_MIDIN: |
| 386 | return MIDIbuf_ioctl(dev, file, cmd, p); |
| 387 | break; |
| 388 | |
| 389 | } |
| 390 | return -EINVAL; |
| 391 | } |
| 392 | |
| 393 | static unsigned int sound_poll(struct file *file, poll_table * wait) |
| 394 | { |
| 395 | struct inode *inode = file->f_dentry->d_inode; |
| 396 | int dev = iminor(inode); |
| 397 | |
| 398 | DEB(printk("sound_poll(dev=%d)\n", dev)); |
| 399 | switch (dev & 0x0f) { |
| 400 | case SND_DEV_SEQ: |
| 401 | case SND_DEV_SEQ2: |
| 402 | return sequencer_poll(dev, file, wait); |
| 403 | |
| 404 | case SND_DEV_MIDIN: |
| 405 | return MIDIbuf_poll(dev, file, wait); |
| 406 | |
| 407 | case SND_DEV_DSP: |
| 408 | case SND_DEV_DSP16: |
| 409 | case SND_DEV_AUDIO: |
| 410 | return DMAbuf_poll(file, dev >> 4, wait); |
| 411 | } |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | static int sound_mmap(struct file *file, struct vm_area_struct *vma) |
| 416 | { |
| 417 | int dev_class; |
| 418 | unsigned long size; |
| 419 | struct dma_buffparms *dmap = NULL; |
| 420 | int dev = iminor(file->f_dentry->d_inode); |
| 421 | |
| 422 | dev_class = dev & 0x0f; |
| 423 | dev >>= 4; |
| 424 | |
| 425 | if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) { |
| 426 | printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n"); |
| 427 | return -EINVAL; |
| 428 | } |
| 429 | lock_kernel(); |
| 430 | if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */ |
| 431 | dmap = audio_devs[dev]->dmap_out; |
| 432 | else if (vma->vm_flags & VM_READ) |
| 433 | dmap = audio_devs[dev]->dmap_in; |
| 434 | else { |
| 435 | printk(KERN_ERR "Sound: Undefined mmap() access\n"); |
| 436 | unlock_kernel(); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
| 440 | if (dmap == NULL) { |
| 441 | printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n"); |
| 442 | unlock_kernel(); |
| 443 | return -EIO; |
| 444 | } |
| 445 | if (dmap->raw_buf == NULL) { |
| 446 | printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n"); |
| 447 | unlock_kernel(); |
| 448 | return -EIO; |
| 449 | } |
| 450 | if (dmap->mapping_flags) { |
| 451 | printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n"); |
| 452 | unlock_kernel(); |
| 453 | return -EIO; |
| 454 | } |
| 455 | if (vma->vm_pgoff != 0) { |
| 456 | printk(KERN_ERR "Sound: mmap() offset must be 0.\n"); |
| 457 | unlock_kernel(); |
| 458 | return -EINVAL; |
| 459 | } |
| 460 | size = vma->vm_end - vma->vm_start; |
| 461 | |
| 462 | if (size != dmap->bytes_in_use) { |
| 463 | printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use); |
| 464 | } |
| 465 | if (remap_pfn_range(vma, vma->vm_start, |
| 466 | virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT, |
| 467 | vma->vm_end - vma->vm_start, vma->vm_page_prot)) { |
| 468 | unlock_kernel(); |
| 469 | return -EAGAIN; |
| 470 | } |
| 471 | |
| 472 | dmap->mapping_flags |= DMA_MAP_MAPPED; |
| 473 | |
| 474 | if( audio_devs[dev]->d->mmap) |
| 475 | audio_devs[dev]->d->mmap(dev); |
| 476 | |
| 477 | memset(dmap->raw_buf, |
| 478 | dmap->neutral_byte, |
| 479 | dmap->bytes_in_use); |
| 480 | unlock_kernel(); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | struct file_operations oss_sound_fops = { |
| 485 | .owner = THIS_MODULE, |
| 486 | .llseek = no_llseek, |
| 487 | .read = sound_read, |
| 488 | .write = sound_write, |
| 489 | .poll = sound_poll, |
| 490 | .ioctl = sound_ioctl, |
| 491 | .mmap = sound_mmap, |
| 492 | .open = sound_open, |
| 493 | .release = sound_release, |
| 494 | }; |
| 495 | |
| 496 | /* |
| 497 | * Create the required special subdevices |
| 498 | */ |
| 499 | |
| 500 | static int create_special_devices(void) |
| 501 | { |
| 502 | int seq1,seq2; |
| 503 | seq1=register_sound_special(&oss_sound_fops, 1); |
| 504 | if(seq1==-1) |
| 505 | goto bad; |
| 506 | seq2=register_sound_special(&oss_sound_fops, 8); |
| 507 | if(seq2!=-1) |
| 508 | return 0; |
| 509 | unregister_sound_special(1); |
| 510 | bad: |
| 511 | return -1; |
| 512 | } |
| 513 | |
| 514 | |
| 515 | /* These device names follow the official Linux device list, |
| 516 | * Documentation/devices.txt. Let us know if there are other |
| 517 | * common names we should support for compatibility. |
| 518 | * Only those devices not created by the generic code in sound_core.c are |
| 519 | * registered here. |
| 520 | */ |
| 521 | static const struct { |
| 522 | unsigned short minor; |
| 523 | char *name; |
| 524 | umode_t mode; |
| 525 | int *num; |
| 526 | } dev_list[] = { /* list of minor devices */ |
| 527 | /* seems to be some confusion here -- this device is not in the device list */ |
| 528 | {SND_DEV_DSP16, "dspW", S_IWUGO | S_IRUSR | S_IRGRP, |
| 529 | &num_audiodevs}, |
| 530 | {SND_DEV_AUDIO, "audio", S_IWUGO | S_IRUSR | S_IRGRP, |
| 531 | &num_audiodevs}, |
| 532 | }; |
| 533 | |
| 534 | static int dmabuf; |
| 535 | static int dmabug; |
| 536 | |
| 537 | module_param(dmabuf, int, 0444); |
| 538 | module_param(dmabug, int, 0444); |
| 539 | |
| 540 | static int __init oss_init(void) |
| 541 | { |
| 542 | int err; |
| 543 | int i, j; |
| 544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | #ifdef CONFIG_PCI |
| 546 | if(dmabug) |
| 547 | isa_dma_bridge_buggy = dmabug; |
| 548 | #endif |
| 549 | |
| 550 | err = create_special_devices(); |
| 551 | if (err) { |
| 552 | printk(KERN_ERR "sound: driver already loaded/included in kernel\n"); |
| 553 | return err; |
| 554 | } |
| 555 | |
| 556 | /* Protecting the innocent */ |
| 557 | sound_dmap_flag = (dmabuf > 0 ? 1 : 0); |
| 558 | |
| 559 | for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) { |
Greg Kroah-Hartman | d80f19f | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 560 | device_create(sound_class, NULL, |
| 561 | MKDEV(SOUND_MAJOR, dev_list[i].minor), |
| 562 | "%s", dev_list[i].name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | if (!dev_list[i].num) |
| 565 | continue; |
| 566 | |
Greg Kroah-Hartman | 0936f26 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 567 | for (j = 1; j < *dev_list[i].num; j++) |
Greg Kroah-Hartman | d80f19f | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 568 | device_create(sound_class, NULL, |
| 569 | MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)), |
| 570 | "%s%d", dev_list[i].name, j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | if (sound_nblocks >= 1024) |
| 574 | printk(KERN_ERR "Sound warning: Deallocation table was too small.\n"); |
| 575 | |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | static void __exit oss_cleanup(void) |
| 580 | { |
| 581 | int i, j; |
| 582 | |
| 583 | for (i = 0; i < sizeof (dev_list) / sizeof *dev_list; i++) { |
Greg Kroah-Hartman | d80f19f | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 584 | device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (!dev_list[i].num) |
| 586 | continue; |
Greg Kroah-Hartman | 0936f26 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 587 | for (j = 1; j < *dev_list[i].num; j++) |
Greg Kroah-Hartman | d80f19f | 2006-08-07 22:19:37 -0700 | [diff] [blame] | 588 | device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | unregister_sound_special(1); |
| 592 | unregister_sound_special(8); |
| 593 | |
| 594 | sound_stop_timer(); |
| 595 | |
| 596 | sequencer_unload(); |
| 597 | |
| 598 | for (i = 0; i < MAX_DMA_CHANNELS; i++) |
| 599 | if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) { |
| 600 | printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i); |
| 601 | sound_free_dma(i); |
| 602 | } |
| 603 | |
| 604 | for (i = 0; i < sound_nblocks; i++) |
| 605 | vfree(sound_mem_blocks[i]); |
| 606 | |
| 607 | } |
| 608 | |
| 609 | module_init(oss_init); |
| 610 | module_exit(oss_cleanup); |
| 611 | MODULE_LICENSE("GPL"); |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 612 | MODULE_DESCRIPTION("OSS Sound subsystem"); |
| 613 | MODULE_AUTHOR("Hannu Savolainen, et al."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
| 615 | |
| 616 | int sound_alloc_dma(int chn, char *deviceID) |
| 617 | { |
| 618 | int err; |
| 619 | |
| 620 | if ((err = request_dma(chn, deviceID)) != 0) |
| 621 | return err; |
| 622 | |
| 623 | dma_alloc_map[chn] = DMA_MAP_FREE; |
| 624 | |
| 625 | return 0; |
| 626 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 627 | EXPORT_SYMBOL(sound_alloc_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
| 629 | int sound_open_dma(int chn, char *deviceID) |
| 630 | { |
| 631 | if (!valid_dma(chn)) { |
| 632 | printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn); |
| 633 | return 1; |
| 634 | } |
| 635 | |
| 636 | if (dma_alloc_map[chn] != DMA_MAP_FREE) { |
| 637 | printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]); |
| 638 | return 1; |
| 639 | } |
| 640 | dma_alloc_map[chn] = DMA_MAP_BUSY; |
| 641 | return 0; |
| 642 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 643 | EXPORT_SYMBOL(sound_open_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | void sound_free_dma(int chn) |
| 646 | { |
| 647 | if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) { |
| 648 | /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */ |
| 649 | return; |
| 650 | } |
| 651 | free_dma(chn); |
| 652 | dma_alloc_map[chn] = DMA_MAP_UNAVAIL; |
| 653 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 654 | EXPORT_SYMBOL(sound_free_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | void sound_close_dma(int chn) |
| 657 | { |
| 658 | if (dma_alloc_map[chn] != DMA_MAP_BUSY) { |
| 659 | printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn); |
| 660 | return; |
| 661 | } |
| 662 | dma_alloc_map[chn] = DMA_MAP_FREE; |
| 663 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 664 | EXPORT_SYMBOL(sound_close_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | static void do_sequencer_timer(unsigned long dummy) |
| 667 | { |
| 668 | sequencer_timer(0); |
| 669 | } |
| 670 | |
| 671 | |
Ingo Molnar | 8d06afa | 2005-09-09 13:10:40 -0700 | [diff] [blame] | 672 | static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
| 674 | void request_sound_timer(int count) |
| 675 | { |
| 676 | extern unsigned long seq_time; |
| 677 | |
| 678 | if (count < 0) { |
| 679 | seq_timer.expires = (-count) + jiffies; |
| 680 | add_timer(&seq_timer); |
| 681 | return; |
| 682 | } |
| 683 | count += seq_time; |
| 684 | |
| 685 | count -= jiffies; |
| 686 | |
| 687 | if (count < 1) |
| 688 | count = 1; |
| 689 | |
| 690 | seq_timer.expires = (count) + jiffies; |
| 691 | add_timer(&seq_timer); |
| 692 | } |
| 693 | |
| 694 | void sound_stop_timer(void) |
| 695 | { |
| 696 | del_timer(&seq_timer); |
| 697 | } |
| 698 | |
| 699 | void conf_printf(char *name, struct address_info *hw_config) |
| 700 | { |
| 701 | #ifndef CONFIG_SOUND_TRACEINIT |
| 702 | return; |
| 703 | #else |
| 704 | printk("<%s> at 0x%03x", name, hw_config->io_base); |
| 705 | |
| 706 | if (hw_config->irq) |
| 707 | printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq); |
| 708 | |
| 709 | if (hw_config->dma != -1 || hw_config->dma2 != -1) |
| 710 | { |
| 711 | printk(" dma %d", hw_config->dma); |
| 712 | if (hw_config->dma2 != -1) |
| 713 | printk(",%d", hw_config->dma2); |
| 714 | } |
| 715 | printk("\n"); |
| 716 | #endif |
| 717 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 718 | EXPORT_SYMBOL(conf_printf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | void conf_printf2(char *name, int base, int irq, int dma, int dma2) |
| 721 | { |
| 722 | #ifndef CONFIG_SOUND_TRACEINIT |
| 723 | return; |
| 724 | #else |
| 725 | printk("<%s> at 0x%03x", name, base); |
| 726 | |
| 727 | if (irq) |
| 728 | printk(" irq %d", (irq > 0) ? irq : -irq); |
| 729 | |
| 730 | if (dma != -1 || dma2 != -1) |
| 731 | { |
| 732 | printk(" dma %d", dma); |
| 733 | if (dma2 != -1) |
| 734 | printk(",%d", dma2); |
| 735 | } |
| 736 | printk("\n"); |
| 737 | #endif |
| 738 | } |
Adrian Bunk | ece7f77 | 2006-10-04 02:17:31 -0700 | [diff] [blame] | 739 | EXPORT_SYMBOL(conf_printf2); |
| 740 | |