soundcard.c 17 KB

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