soundcard.c 17 KB

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