blob: 92aa762ffb7e97c998db3ca1da3a5cddc2968139 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * linux/sound/oss/soundcard.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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 Torvalds1da177e2005-04-16 15:20:36 -070025
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>
Ahmed S. Darwishb322f402007-02-12 00:52:07 -080035#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/dma.h>
37#include <asm/io.h>
38#include <linux/wait.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#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>
Al Virof23f6e02006-10-20 15:17:02 -040045#include <linux/mm.h>
Jean Delvare6473d162007-03-06 02:45:12 -080046#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
49 * This ought to be moved into include/asm/dma.h
50 */
51#ifndef valid_dma
52#define valid_dma(n) ((n) >= 0 && (n) < MAX_DMA_CHANNELS && (n) != 4)
53#endif
54
55/*
56 * Table for permanently allocated memory (used when unloading the module)
57 */
Dan Carpenter444c1952010-01-03 12:39:27 +010058void * sound_mem_blocks[MAX_MEM_BLOCKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070059int sound_nblocks = 0;
60
61/* Persistent DMA buffers */
62#ifdef CONFIG_SOUND_DMAP
63int sound_dmap_flag = 1;
64#else
65int sound_dmap_flag = 0;
66#endif
67
68static char dma_alloc_map[MAX_DMA_CHANNELS];
69
70#define DMA_MAP_UNAVAIL 0
71#define DMA_MAP_FREE 1
72#define DMA_MAP_BUSY 2
73
74
75unsigned long seq_time = 0; /* Time for /dev/sequencer */
gregkh@suse.de619e6662005-03-23 09:51:41 -080076extern struct class *sound_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/*
79 * Table for configurable mixer volume handling
80 */
81static mixer_vol_table mixer_vols[MAX_MIXER_DEV];
82static int num_mixer_volumes;
83
84int *load_mixer_volumes(char *name, int *levels, int present)
85{
86 int i, n;
87
88 for (i = 0; i < num_mixer_volumes; i++) {
89 if (strcmp(name, mixer_vols[i].name) == 0) {
90 if (present)
91 mixer_vols[i].num = i;
92 return mixer_vols[i].levels;
93 }
94 }
95 if (num_mixer_volumes >= MAX_MIXER_DEV) {
96 printk(KERN_ERR "Sound: Too many mixers (%s)\n", name);
97 return levels;
98 }
99 n = num_mixer_volumes++;
100
101 strcpy(mixer_vols[n].name, name);
102
103 if (present)
104 mixer_vols[n].num = n;
105 else
106 mixer_vols[n].num = -1;
107
108 for (i = 0; i < 32; i++)
109 mixer_vols[n].levels[i] = levels[i];
110 return mixer_vols[n].levels;
111}
Adrian Bunkece7f772006-10-04 02:17:31 -0700112EXPORT_SYMBOL(load_mixer_volumes);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int set_mixer_levels(void __user * arg)
115{
116 /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */
117 mixer_vol_table buf;
118
119 if (__copy_from_user(&buf, arg, sizeof(buf)))
120 return -EFAULT;
121 load_mixer_volumes(buf.name, buf.levels, 0);
122 if (__copy_to_user(arg, &buf, sizeof(buf)))
123 return -EFAULT;
124 return 0;
125}
126
127static int get_mixer_levels(void __user * arg)
128{
129 int n;
130
131 if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num))))
132 return -EFAULT;
133 if (n < 0 || n >= num_mixer_volumes)
134 return -EINVAL;
135 if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table)))
136 return -EFAULT;
137 return 0;
138}
139
140/* 4K page size but our output routines use some slack for overruns */
141#define PROC_BLOCK_SIZE (3*1024)
142
143static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
144{
Josef Sipek7bc56322006-12-08 02:37:40 -0800145 int dev = iminor(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 int ret = -EINVAL;
147
148 /*
149 * The OSS drivers aren't remotely happy without this locking,
150 * and unless someone fixes them when they are about to bite the
151 * big one anyway, we might as well bandage here..
152 */
153
154 lock_kernel();
155
156 DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count));
157 switch (dev & 0x0f) {
158 case SND_DEV_DSP:
159 case SND_DEV_DSP16:
160 case SND_DEV_AUDIO:
161 ret = audio_read(dev, file, buf, count);
162 break;
163
164 case SND_DEV_SEQ:
165 case SND_DEV_SEQ2:
166 ret = sequencer_read(dev, file, buf, count);
167 break;
168
169 case SND_DEV_MIDIN:
170 ret = MIDIbuf_read(dev, file, buf, count);
171 }
172 unlock_kernel();
173 return ret;
174}
175
176static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
177{
Josef Sipek7bc56322006-12-08 02:37:40 -0800178 int dev = iminor(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 int ret = -EINVAL;
180
181 lock_kernel();
182 DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count));
183 switch (dev & 0x0f) {
184 case SND_DEV_SEQ:
185 case SND_DEV_SEQ2:
186 ret = sequencer_write(dev, file, buf, count);
187 break;
188
189 case SND_DEV_DSP:
190 case SND_DEV_DSP16:
191 case SND_DEV_AUDIO:
192 ret = audio_write(dev, file, buf, count);
193 break;
194
195 case SND_DEV_MIDIN:
196 ret = MIDIbuf_write(dev, file, buf, count);
197 break;
198 }
199 unlock_kernel();
200 return ret;
201}
202
203static int sound_open(struct inode *inode, struct file *file)
204{
205 int dev = iminor(inode);
206 int retval;
207
208 DEB(printk("sound_open(dev=%d)\n", dev));
209 if ((dev >= SND_NDEVS) || (dev < 0)) {
210 printk(KERN_ERR "Invalid minor device %d\n", dev);
211 return -ENXIO;
212 }
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200213 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 switch (dev & 0x0f) {
215 case SND_DEV_CTL:
216 dev >>= 4;
217 if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) {
218 request_module("mixer%d", dev);
219 }
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200220 retval = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200222 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 if (!try_module_get(mixer_devs[dev]->owner))
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200225 break;
226
227 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 break;
229
230 case SND_DEV_SEQ:
231 case SND_DEV_SEQ2:
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200232 retval = sequencer_open(dev, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 break;
234
235 case SND_DEV_MIDIN:
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200236 retval = MIDIbuf_open(dev, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 break;
238
239 case SND_DEV_DSP:
240 case SND_DEV_DSP16:
241 case SND_DEV_AUDIO:
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200242 retval = audio_open(dev, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 break;
244
245 default:
246 printk(KERN_ERR "Invalid minor device %d\n", dev);
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200247 retval = -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249
Arnd Bergmann90dc7632010-07-11 12:16:36 +0200250 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return 0;
252}
253
254static int sound_release(struct inode *inode, struct file *file)
255{
256 int dev = iminor(inode);
257
258 lock_kernel();
259 DEB(printk("sound_release(dev=%d)\n", dev));
260 switch (dev & 0x0f) {
261 case SND_DEV_CTL:
262 module_put(mixer_devs[dev >> 4]->owner);
263 break;
264
265 case SND_DEV_SEQ:
266 case SND_DEV_SEQ2:
267 sequencer_release(dev, file);
268 break;
269
270 case SND_DEV_MIDIN:
271 MIDIbuf_release(dev, file);
272 break;
273
274 case SND_DEV_DSP:
275 case SND_DEV_DSP16:
276 case SND_DEV_AUDIO:
277 audio_release(dev, file);
278 break;
279
280 default:
281 printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev);
282 }
283 unlock_kernel();
284
285 return 0;
286}
287
288static int get_mixer_info(int dev, void __user *arg)
289{
290 mixer_info info;
291 memset(&info, 0, sizeof(info));
292 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
293 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
294 info.modify_counter = mixer_devs[dev]->modify_counter;
295 if (__copy_to_user(arg, &info, sizeof(info)))
296 return -EFAULT;
297 return 0;
298}
299
300static int get_old_mixer_info(int dev, void __user *arg)
301{
302 _old_mixer_info info;
303 memset(&info, 0, sizeof(info));
304 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
305 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
306 if (copy_to_user(arg, &info, sizeof(info)))
307 return -EFAULT;
308 return 0;
309}
310
311static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg)
312{
313 if (mixdev < 0 || mixdev >= MAX_MIXER_DEV)
314 return -ENXIO;
315 /* Try to load the mixer... */
316 if (mixer_devs[mixdev] == NULL) {
317 request_module("mixer%d", mixdev);
318 }
319 if (mixdev >= num_mixers || !mixer_devs[mixdev])
320 return -ENXIO;
321 if (cmd == SOUND_MIXER_INFO)
322 return get_mixer_info(mixdev, arg);
323 if (cmd == SOUND_OLD_MIXER_INFO)
324 return get_old_mixer_info(mixdev, arg);
325 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
326 mixer_devs[mixdev]->modify_counter++;
327 if (!mixer_devs[mixdev]->ioctl)
328 return -EINVAL;
329 return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
330}
331
Alan Cox6b985152010-01-04 16:22:59 +0000332static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
334 int len = 0, dtype;
Alan Cox6b985152010-01-04 16:22:59 +0000335 int dev = iminor(file->f_dentry->d_inode);
336 long ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 void __user *p = (void __user *)arg;
338
339 if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) {
340 /*
341 * Have to validate the address given by the process.
342 */
343 len = _SIOC_SIZE(cmd);
344 if (len < 1 || len > 65536 || !p)
345 return -EFAULT;
346 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
347 if (!access_ok(VERIFY_READ, p, len))
348 return -EFAULT;
349 if (_SIOC_DIR(cmd) & _SIOC_READ)
350 if (!access_ok(VERIFY_WRITE, p, len))
351 return -EFAULT;
352 }
353 DEB(printk("sound_ioctl(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
354 if (cmd == OSS_GETVERSION)
355 return __put_user(SOUND_VERSION, (int __user *)p);
356
Alan Cox6b985152010-01-04 16:22:59 +0000357 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */
359 (dev & 0x0f) != SND_DEV_CTL) {
360 dtype = dev & 0x0f;
361 switch (dtype) {
362 case SND_DEV_DSP:
363 case SND_DEV_DSP16:
364 case SND_DEV_AUDIO:
Alan Cox6b985152010-01-04 16:22:59 +0000365 ret = sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 cmd, p);
Alan Cox6b985152010-01-04 16:22:59 +0000367 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 default:
Alan Cox6b985152010-01-04 16:22:59 +0000369 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
370 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
Alan Cox6b985152010-01-04 16:22:59 +0000372 unlock_kernel();
373 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 }
Alan Cox6b985152010-01-04 16:22:59 +0000375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 switch (dev & 0x0f) {
377 case SND_DEV_CTL:
378 if (cmd == SOUND_MIXER_GETLEVELS)
Alan Cox6b985152010-01-04 16:22:59 +0000379 ret = get_mixer_levels(p);
380 else if (cmd == SOUND_MIXER_SETLEVELS)
381 ret = set_mixer_levels(p);
382 else
383 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
384 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 case SND_DEV_SEQ:
387 case SND_DEV_SEQ2:
Alan Cox6b985152010-01-04 16:22:59 +0000388 ret = sequencer_ioctl(dev, file, cmd, p);
389 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 case SND_DEV_DSP:
392 case SND_DEV_DSP16:
393 case SND_DEV_AUDIO:
394 return audio_ioctl(dev, file, cmd, p);
395 break;
396
397 case SND_DEV_MIDIN:
398 return MIDIbuf_ioctl(dev, file, cmd, p);
399 break;
400
401 }
Alan Cox6b985152010-01-04 16:22:59 +0000402 unlock_kernel();
403 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
405
406static unsigned int sound_poll(struct file *file, poll_table * wait)
407{
Josef Sipek7bc56322006-12-08 02:37:40 -0800408 struct inode *inode = file->f_path.dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 int dev = iminor(inode);
410
411 DEB(printk("sound_poll(dev=%d)\n", dev));
412 switch (dev & 0x0f) {
413 case SND_DEV_SEQ:
414 case SND_DEV_SEQ2:
415 return sequencer_poll(dev, file, wait);
416
417 case SND_DEV_MIDIN:
418 return MIDIbuf_poll(dev, file, wait);
419
420 case SND_DEV_DSP:
421 case SND_DEV_DSP16:
422 case SND_DEV_AUDIO:
423 return DMAbuf_poll(file, dev >> 4, wait);
424 }
425 return 0;
426}
427
428static int sound_mmap(struct file *file, struct vm_area_struct *vma)
429{
430 int dev_class;
431 unsigned long size;
432 struct dma_buffparms *dmap = NULL;
Josef Sipek7bc56322006-12-08 02:37:40 -0800433 int dev = iminor(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 dev_class = dev & 0x0f;
436 dev >>= 4;
437
438 if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
439 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
440 return -EINVAL;
441 }
442 lock_kernel();
443 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
444 dmap = audio_devs[dev]->dmap_out;
445 else if (vma->vm_flags & VM_READ)
446 dmap = audio_devs[dev]->dmap_in;
447 else {
448 printk(KERN_ERR "Sound: Undefined mmap() access\n");
449 unlock_kernel();
450 return -EINVAL;
451 }
452
453 if (dmap == NULL) {
454 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
455 unlock_kernel();
456 return -EIO;
457 }
458 if (dmap->raw_buf == NULL) {
459 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
460 unlock_kernel();
461 return -EIO;
462 }
463 if (dmap->mapping_flags) {
464 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
465 unlock_kernel();
466 return -EIO;
467 }
468 if (vma->vm_pgoff != 0) {
469 printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
470 unlock_kernel();
471 return -EINVAL;
472 }
473 size = vma->vm_end - vma->vm_start;
474
475 if (size != dmap->bytes_in_use) {
476 printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
477 }
478 if (remap_pfn_range(vma, vma->vm_start,
479 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
480 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
481 unlock_kernel();
482 return -EAGAIN;
483 }
484
485 dmap->mapping_flags |= DMA_MAP_MAPPED;
486
487 if( audio_devs[dev]->d->mmap)
488 audio_devs[dev]->d->mmap(dev);
489
490 memset(dmap->raw_buf,
491 dmap->neutral_byte,
492 dmap->bytes_in_use);
493 unlock_kernel();
494 return 0;
495}
496
Arjan van de Ven9c2e08c2007-02-12 00:55:37 -0800497const struct file_operations oss_sound_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .owner = THIS_MODULE,
499 .llseek = no_llseek,
500 .read = sound_read,
501 .write = sound_write,
502 .poll = sound_poll,
Alan Cox6b985152010-01-04 16:22:59 +0000503 .unlocked_ioctl = sound_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .mmap = sound_mmap,
505 .open = sound_open,
506 .release = sound_release,
507};
508
509/*
510 * Create the required special subdevices
511 */
512
513static int create_special_devices(void)
514{
515 int seq1,seq2;
516 seq1=register_sound_special(&oss_sound_fops, 1);
517 if(seq1==-1)
518 goto bad;
519 seq2=register_sound_special(&oss_sound_fops, 8);
520 if(seq2!=-1)
521 return 0;
522 unregister_sound_special(1);
523bad:
524 return -1;
525}
526
527
528/* These device names follow the official Linux device list,
529 * Documentation/devices.txt. Let us know if there are other
530 * common names we should support for compatibility.
531 * Only those devices not created by the generic code in sound_core.c are
532 * registered here.
533 */
534static const struct {
535 unsigned short minor;
536 char *name;
537 umode_t mode;
538 int *num;
539} dev_list[] = { /* list of minor devices */
540/* seems to be some confusion here -- this device is not in the device list */
541 {SND_DEV_DSP16, "dspW", S_IWUGO | S_IRUSR | S_IRGRP,
542 &num_audiodevs},
543 {SND_DEV_AUDIO, "audio", S_IWUGO | S_IRUSR | S_IRGRP,
544 &num_audiodevs},
545};
546
547static int dmabuf;
548static int dmabug;
549
550module_param(dmabuf, int, 0444);
551module_param(dmabug, int, 0444);
552
553static int __init oss_init(void)
554{
555 int err;
556 int i, j;
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#ifdef CONFIG_PCI
559 if(dmabug)
560 isa_dma_bridge_buggy = dmabug;
561#endif
562
563 err = create_special_devices();
564 if (err) {
565 printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
566 return err;
567 }
568
569 /* Protecting the innocent */
570 sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
571
Ahmed S. Darwishb322f402007-02-12 00:52:07 -0800572 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
Greg Kroah-Hartmanabe9ab82008-07-21 20:03:34 -0700573 device_create(sound_class, NULL,
574 MKDEV(SOUND_MAJOR, dev_list[i].minor), NULL,
575 "%s", dev_list[i].name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 if (!dev_list[i].num)
578 continue;
579
Greg Kroah-Hartman0936f262005-06-20 21:15:16 -0700580 for (j = 1; j < *dev_list[i].num; j++)
Greg Kroah-Hartmanabe9ab82008-07-21 20:03:34 -0700581 device_create(sound_class, NULL,
582 MKDEV(SOUND_MAJOR,
583 dev_list[i].minor + (j*0x10)),
584 NULL, "%s%d", dev_list[i].name, j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Dan Carpenter444c1952010-01-03 12:39:27 +0100587 if (sound_nblocks >= MAX_MEM_BLOCKS - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
589
590 return 0;
591}
592
593static void __exit oss_cleanup(void)
594{
595 int i, j;
596
Ahmed S. Darwishb322f402007-02-12 00:52:07 -0800597 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
Greg Kroah-Hartmand80f19f2006-08-07 22:19:37 -0700598 device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 if (!dev_list[i].num)
600 continue;
Greg Kroah-Hartman0936f262005-06-20 21:15:16 -0700601 for (j = 1; j < *dev_list[i].num; j++)
Greg Kroah-Hartmand80f19f2006-08-07 22:19:37 -0700602 device_destroy(sound_class, MKDEV(SOUND_MAJOR, dev_list[i].minor + (j*0x10)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
604
605 unregister_sound_special(1);
606 unregister_sound_special(8);
607
608 sound_stop_timer();
609
610 sequencer_unload();
611
612 for (i = 0; i < MAX_DMA_CHANNELS; i++)
613 if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) {
614 printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i);
615 sound_free_dma(i);
616 }
617
618 for (i = 0; i < sound_nblocks; i++)
619 vfree(sound_mem_blocks[i]);
620
621}
622
623module_init(oss_init);
624module_exit(oss_cleanup);
625MODULE_LICENSE("GPL");
Adrian Bunkece7f772006-10-04 02:17:31 -0700626MODULE_DESCRIPTION("OSS Sound subsystem");
627MODULE_AUTHOR("Hannu Savolainen, et al.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629
630int sound_alloc_dma(int chn, char *deviceID)
631{
632 int err;
633
634 if ((err = request_dma(chn, deviceID)) != 0)
635 return err;
636
637 dma_alloc_map[chn] = DMA_MAP_FREE;
638
639 return 0;
640}
Adrian Bunkece7f772006-10-04 02:17:31 -0700641EXPORT_SYMBOL(sound_alloc_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643int sound_open_dma(int chn, char *deviceID)
644{
645 if (!valid_dma(chn)) {
646 printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn);
647 return 1;
648 }
649
650 if (dma_alloc_map[chn] != DMA_MAP_FREE) {
651 printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]);
652 return 1;
653 }
654 dma_alloc_map[chn] = DMA_MAP_BUSY;
655 return 0;
656}
Adrian Bunkece7f772006-10-04 02:17:31 -0700657EXPORT_SYMBOL(sound_open_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659void sound_free_dma(int chn)
660{
661 if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) {
662 /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */
663 return;
664 }
665 free_dma(chn);
666 dma_alloc_map[chn] = DMA_MAP_UNAVAIL;
667}
Adrian Bunkece7f772006-10-04 02:17:31 -0700668EXPORT_SYMBOL(sound_free_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670void sound_close_dma(int chn)
671{
672 if (dma_alloc_map[chn] != DMA_MAP_BUSY) {
673 printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn);
674 return;
675 }
676 dma_alloc_map[chn] = DMA_MAP_FREE;
677}
Adrian Bunkece7f772006-10-04 02:17:31 -0700678EXPORT_SYMBOL(sound_close_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680static void do_sequencer_timer(unsigned long dummy)
681{
682 sequencer_timer(0);
683}
684
685
Ingo Molnar8d06afa2005-09-09 13:10:40 -0700686static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688void request_sound_timer(int count)
689{
690 extern unsigned long seq_time;
691
692 if (count < 0) {
693 seq_timer.expires = (-count) + jiffies;
694 add_timer(&seq_timer);
695 return;
696 }
697 count += seq_time;
698
699 count -= jiffies;
700
701 if (count < 1)
702 count = 1;
703
704 seq_timer.expires = (count) + jiffies;
705 add_timer(&seq_timer);
706}
707
708void sound_stop_timer(void)
709{
710 del_timer(&seq_timer);
711}
712
713void conf_printf(char *name, struct address_info *hw_config)
714{
715#ifndef CONFIG_SOUND_TRACEINIT
716 return;
717#else
718 printk("<%s> at 0x%03x", name, hw_config->io_base);
719
720 if (hw_config->irq)
721 printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq);
722
723 if (hw_config->dma != -1 || hw_config->dma2 != -1)
724 {
725 printk(" dma %d", hw_config->dma);
726 if (hw_config->dma2 != -1)
727 printk(",%d", hw_config->dma2);
728 }
729 printk("\n");
730#endif
731}
Adrian Bunkece7f772006-10-04 02:17:31 -0700732EXPORT_SYMBOL(conf_printf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734void conf_printf2(char *name, int base, int irq, int dma, int dma2)
735{
736#ifndef CONFIG_SOUND_TRACEINIT
737 return;
738#else
739 printk("<%s> at 0x%03x", name, base);
740
741 if (irq)
742 printk(" irq %d", (irq > 0) ? irq : -irq);
743
744 if (dma != -1 || dma2 != -1)
745 {
746 printk(" dma %d", dma);
747 if (dma2 != -1)
748 printk(",%d", dma2);
749 }
750 printk("\n");
751#endif
752}
Adrian Bunkece7f772006-10-04 02:17:31 -0700753EXPORT_SYMBOL(conf_printf2);
754