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 <linux/kernel.h>
  34. #include <asm/dma.h>
  35. #include <asm/io.h>
  36. #include <linux/wait.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/mutex.h>
  42. #include <linux/module.h>
  43. #include <linux/mm.h>
  44. #include <linux/device.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[MAX_MEM_BLOCKS];
  55. static DEFINE_MUTEX(soundcard_mutex);
  56. int sound_nblocks = 0;
  57. /* Persistent DMA buffers */
  58. #ifdef CONFIG_SOUND_DMAP
  59. int sound_dmap_flag = 1;
  60. #else
  61. int sound_dmap_flag = 0;
  62. #endif
  63. static char dma_alloc_map[MAX_DMA_CHANNELS];
  64. #define DMA_MAP_UNAVAIL 0
  65. #define DMA_MAP_FREE 1
  66. #define DMA_MAP_BUSY 2
  67. unsigned long seq_time = 0; /* Time for /dev/sequencer */
  68. extern struct class *sound_class;
  69. /*
  70. * Table for configurable mixer volume handling
  71. */
  72. static mixer_vol_table mixer_vols[MAX_MIXER_DEV];
  73. static int num_mixer_volumes;
  74. int *load_mixer_volumes(char *name, int *levels, int present)
  75. {
  76. int i, n;
  77. for (i = 0; i < num_mixer_volumes; i++) {
  78. if (strncmp(name, mixer_vols[i].name, 32) == 0) {
  79. if (present)
  80. mixer_vols[i].num = i;
  81. return mixer_vols[i].levels;
  82. }
  83. }
  84. if (num_mixer_volumes >= MAX_MIXER_DEV) {
  85. printk(KERN_ERR "Sound: Too many mixers (%s)\n", name);
  86. return levels;
  87. }
  88. n = num_mixer_volumes++;
  89. strncpy(mixer_vols[n].name, name, 32);
  90. if (present)
  91. mixer_vols[n].num = n;
  92. else
  93. mixer_vols[n].num = -1;
  94. for (i = 0; i < 32; i++)
  95. mixer_vols[n].levels[i] = levels[i];
  96. return mixer_vols[n].levels;
  97. }
  98. EXPORT_SYMBOL(load_mixer_volumes);
  99. static int set_mixer_levels(void __user * arg)
  100. {
  101. /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */
  102. mixer_vol_table buf;
  103. if (__copy_from_user(&buf, arg, sizeof(buf)))
  104. return -EFAULT;
  105. load_mixer_volumes(buf.name, buf.levels, 0);
  106. if (__copy_to_user(arg, &buf, sizeof(buf)))
  107. return -EFAULT;
  108. return 0;
  109. }
  110. static int get_mixer_levels(void __user * arg)
  111. {
  112. int n;
  113. if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num))))
  114. return -EFAULT;
  115. if (n < 0 || n >= num_mixer_volumes)
  116. return -EINVAL;
  117. if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table)))
  118. return -EFAULT;
  119. return 0;
  120. }
  121. /* 4K page size but our output routines use some slack for overruns */
  122. #define PROC_BLOCK_SIZE (3*1024)
  123. static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
  124. {
  125. int dev = iminor(file->f_path.dentry->d_inode);
  126. int ret = -EINVAL;
  127. /*
  128. * The OSS drivers aren't remotely happy without this locking,
  129. * and unless someone fixes them when they are about to bite the
  130. * big one anyway, we might as well bandage here..
  131. */
  132. mutex_lock(&soundcard_mutex);
  133. DEB(printk("sound_read(dev=%d, count=%d)\n", dev, count));
  134. switch (dev & 0x0f) {
  135. case SND_DEV_DSP:
  136. case SND_DEV_DSP16:
  137. case SND_DEV_AUDIO:
  138. ret = audio_read(dev, file, buf, count);
  139. break;
  140. case SND_DEV_SEQ:
  141. case SND_DEV_SEQ2:
  142. ret = sequencer_read(dev, file, buf, count);
  143. break;
  144. case SND_DEV_MIDIN:
  145. ret = MIDIbuf_read(dev, file, buf, count);
  146. }
  147. mutex_unlock(&soundcard_mutex);
  148. return ret;
  149. }
  150. static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  151. {
  152. int dev = iminor(file->f_path.dentry->d_inode);
  153. int ret = -EINVAL;
  154. mutex_lock(&soundcard_mutex);
  155. DEB(printk("sound_write(dev=%d, count=%d)\n", dev, count));
  156. switch (dev & 0x0f) {
  157. case SND_DEV_SEQ:
  158. case SND_DEV_SEQ2:
  159. ret = sequencer_write(dev, file, buf, count);
  160. break;
  161. case SND_DEV_DSP:
  162. case SND_DEV_DSP16:
  163. case SND_DEV_AUDIO:
  164. ret = audio_write(dev, file, buf, count);
  165. break;
  166. case SND_DEV_MIDIN:
  167. ret = MIDIbuf_write(dev, file, buf, count);
  168. break;
  169. }
  170. mutex_unlock(&soundcard_mutex);
  171. return ret;
  172. }
  173. static int sound_open(struct inode *inode, struct file *file)
  174. {
  175. int dev = iminor(inode);
  176. int retval;
  177. DEB(printk("sound_open(dev=%d)\n", dev));
  178. if ((dev >= SND_NDEVS) || (dev < 0)) {
  179. printk(KERN_ERR "Invalid minor device %d\n", dev);
  180. return -ENXIO;
  181. }
  182. mutex_lock(&soundcard_mutex);
  183. switch (dev & 0x0f) {
  184. case SND_DEV_CTL:
  185. dev >>= 4;
  186. if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) {
  187. request_module("mixer%d", dev);
  188. }
  189. retval = -ENXIO;
  190. if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
  191. break;
  192. if (!try_module_get(mixer_devs[dev]->owner))
  193. break;
  194. retval = 0;
  195. break;
  196. case SND_DEV_SEQ:
  197. case SND_DEV_SEQ2:
  198. retval = sequencer_open(dev, file);
  199. break;
  200. case SND_DEV_MIDIN:
  201. retval = MIDIbuf_open(dev, file);
  202. break;
  203. case SND_DEV_DSP:
  204. case SND_DEV_DSP16:
  205. case SND_DEV_AUDIO:
  206. retval = audio_open(dev, file);
  207. break;
  208. default:
  209. printk(KERN_ERR "Invalid minor device %d\n", dev);
  210. retval = -ENXIO;
  211. }
  212. mutex_unlock(&soundcard_mutex);
  213. return retval;
  214. }
  215. static int sound_release(struct inode *inode, struct file *file)
  216. {
  217. int dev = iminor(inode);
  218. mutex_lock(&soundcard_mutex);
  219. DEB(printk("sound_release(dev=%d)\n", dev));
  220. switch (dev & 0x0f) {
  221. case SND_DEV_CTL:
  222. module_put(mixer_devs[dev >> 4]->owner);
  223. break;
  224. case SND_DEV_SEQ:
  225. case SND_DEV_SEQ2:
  226. sequencer_release(dev, file);
  227. break;
  228. case SND_DEV_MIDIN:
  229. MIDIbuf_release(dev, file);
  230. break;
  231. case SND_DEV_DSP:
  232. case SND_DEV_DSP16:
  233. case SND_DEV_AUDIO:
  234. audio_release(dev, file);
  235. break;
  236. default:
  237. printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev);
  238. }
  239. mutex_unlock(&soundcard_mutex);
  240. return 0;
  241. }
  242. static int get_mixer_info(int dev, void __user *arg)
  243. {
  244. mixer_info info;
  245. memset(&info, 0, sizeof(info));
  246. strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
  247. strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
  248. info.modify_counter = mixer_devs[dev]->modify_counter;
  249. if (__copy_to_user(arg, &info, sizeof(info)))
  250. return -EFAULT;
  251. return 0;
  252. }
  253. static int get_old_mixer_info(int dev, void __user *arg)
  254. {
  255. _old_mixer_info info;
  256. memset(&info, 0, sizeof(info));
  257. strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
  258. strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
  259. if (copy_to_user(arg, &info, sizeof(info)))
  260. return -EFAULT;
  261. return 0;
  262. }
  263. static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg)
  264. {
  265. if (mixdev < 0 || mixdev >= MAX_MIXER_DEV)
  266. return -ENXIO;
  267. /* Try to load the mixer... */
  268. if (mixer_devs[mixdev] == NULL) {
  269. request_module("mixer%d", mixdev);
  270. }
  271. if (mixdev >= num_mixers || !mixer_devs[mixdev])
  272. return -ENXIO;
  273. if (cmd == SOUND_MIXER_INFO)
  274. return get_mixer_info(mixdev, arg);
  275. if (cmd == SOUND_OLD_MIXER_INFO)
  276. return get_old_mixer_info(mixdev, arg);
  277. if (_SIOC_DIR(cmd) & _SIOC_WRITE)
  278. mixer_devs[mixdev]->modify_counter++;
  279. if (!mixer_devs[mixdev]->ioctl)
  280. return -EINVAL;
  281. return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
  282. }
  283. static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  284. {
  285. int len = 0, dtype;
  286. int dev = iminor(file->f_dentry->d_inode);
  287. long ret = -EINVAL;
  288. void __user *p = (void __user *)arg;
  289. if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) {
  290. /*
  291. * Have to validate the address given by the process.
  292. */
  293. len = _SIOC_SIZE(cmd);
  294. if (len < 1 || len > 65536 || !p)
  295. return -EFAULT;
  296. if (_SIOC_DIR(cmd) & _SIOC_WRITE)
  297. if (!access_ok(VERIFY_READ, p, len))
  298. return -EFAULT;
  299. if (_SIOC_DIR(cmd) & _SIOC_READ)
  300. if (!access_ok(VERIFY_WRITE, p, len))
  301. return -EFAULT;
  302. }
  303. DEB(printk("sound_ioctl(dev=%d, cmd=0x%x, arg=0x%x)\n", dev, cmd, arg));
  304. if (cmd == OSS_GETVERSION)
  305. return __put_user(SOUND_VERSION, (int __user *)p);
  306. mutex_lock(&soundcard_mutex);
  307. if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */
  308. (dev & 0x0f) != SND_DEV_CTL) {
  309. dtype = dev & 0x0f;
  310. switch (dtype) {
  311. case SND_DEV_DSP:
  312. case SND_DEV_DSP16:
  313. case SND_DEV_AUDIO:
  314. ret = sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
  315. cmd, p);
  316. break;
  317. default:
  318. ret = sound_mixer_ioctl(dev >> 4, cmd, p);
  319. break;
  320. }
  321. mutex_unlock(&soundcard_mutex);
  322. return ret;
  323. }
  324. switch (dev & 0x0f) {
  325. case SND_DEV_CTL:
  326. if (cmd == SOUND_MIXER_GETLEVELS)
  327. ret = get_mixer_levels(p);
  328. else if (cmd == SOUND_MIXER_SETLEVELS)
  329. ret = set_mixer_levels(p);
  330. else
  331. ret = sound_mixer_ioctl(dev >> 4, cmd, p);
  332. break;
  333. case SND_DEV_SEQ:
  334. case SND_DEV_SEQ2:
  335. ret = sequencer_ioctl(dev, file, cmd, p);
  336. break;
  337. case SND_DEV_DSP:
  338. case SND_DEV_DSP16:
  339. case SND_DEV_AUDIO:
  340. ret = audio_ioctl(dev, file, cmd, p);
  341. break;
  342. case SND_DEV_MIDIN:
  343. ret = MIDIbuf_ioctl(dev, file, cmd, p);
  344. break;
  345. }
  346. mutex_unlock(&soundcard_mutex);
  347. return ret;
  348. }
  349. static unsigned int sound_poll(struct file *file, poll_table * wait)
  350. {
  351. struct inode *inode = file->f_path.dentry->d_inode;
  352. int dev = iminor(inode);
  353. DEB(printk("sound_poll(dev=%d)\n", dev));
  354. switch (dev & 0x0f) {
  355. case SND_DEV_SEQ:
  356. case SND_DEV_SEQ2:
  357. return sequencer_poll(dev, file, wait);
  358. case SND_DEV_MIDIN:
  359. return MIDIbuf_poll(dev, file, wait);
  360. case SND_DEV_DSP:
  361. case SND_DEV_DSP16:
  362. case SND_DEV_AUDIO:
  363. return DMAbuf_poll(file, dev >> 4, wait);
  364. }
  365. return 0;
  366. }
  367. static int sound_mmap(struct file *file, struct vm_area_struct *vma)
  368. {
  369. int dev_class;
  370. unsigned long size;
  371. struct dma_buffparms *dmap = NULL;
  372. int dev = iminor(file->f_path.dentry->d_inode);
  373. dev_class = dev & 0x0f;
  374. dev >>= 4;
  375. if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
  376. printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
  377. return -EINVAL;
  378. }
  379. mutex_lock(&soundcard_mutex);
  380. if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
  381. dmap = audio_devs[dev]->dmap_out;
  382. else if (vma->vm_flags & VM_READ)
  383. dmap = audio_devs[dev]->dmap_in;
  384. else {
  385. printk(KERN_ERR "Sound: Undefined mmap() access\n");
  386. mutex_unlock(&soundcard_mutex);
  387. return -EINVAL;
  388. }
  389. if (dmap == NULL) {
  390. printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
  391. mutex_unlock(&soundcard_mutex);
  392. return -EIO;
  393. }
  394. if (dmap->raw_buf == NULL) {
  395. printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
  396. mutex_unlock(&soundcard_mutex);
  397. return -EIO;
  398. }
  399. if (dmap->mapping_flags) {
  400. printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
  401. mutex_unlock(&soundcard_mutex);
  402. return -EIO;
  403. }
  404. if (vma->vm_pgoff != 0) {
  405. printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
  406. mutex_unlock(&soundcard_mutex);
  407. return -EINVAL;
  408. }
  409. size = vma->vm_end - vma->vm_start;
  410. if (size != dmap->bytes_in_use) {
  411. printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
  412. }
  413. if (remap_pfn_range(vma, vma->vm_start,
  414. virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
  415. vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
  416. mutex_unlock(&soundcard_mutex);
  417. return -EAGAIN;
  418. }
  419. dmap->mapping_flags |= DMA_MAP_MAPPED;
  420. if( audio_devs[dev]->d->mmap)
  421. audio_devs[dev]->d->mmap(dev);
  422. memset(dmap->raw_buf,
  423. dmap->neutral_byte,
  424. dmap->bytes_in_use);
  425. mutex_unlock(&soundcard_mutex);
  426. return 0;
  427. }
  428. const struct file_operations oss_sound_fops = {
  429. .owner = THIS_MODULE,
  430. .llseek = no_llseek,
  431. .read = sound_read,
  432. .write = sound_write,
  433. .poll = sound_poll,
  434. .unlocked_ioctl = sound_ioctl,
  435. .mmap = sound_mmap,
  436. .open = sound_open,
  437. .release = sound_release,
  438. };
  439. /*
  440. * Create the required special subdevices
  441. */
  442. static int create_special_devices(void)
  443. {
  444. int seq1,seq2;
  445. seq1=register_sound_special(&oss_sound_fops, 1);
  446. if(seq1==-1)
  447. goto bad;
  448. seq2=register_sound_special(&oss_sound_fops, 8);
  449. if(seq2!=-1)
  450. return 0;
  451. unregister_sound_special(1);
  452. bad:
  453. return -1;
  454. }
  455. static int dmabuf;
  456. static int dmabug;
  457. module_param(dmabuf, int, 0444);
  458. module_param(dmabug, int, 0444);
  459. /* additional minors for compatibility */
  460. struct oss_minor_dev {
  461. unsigned short minor;
  462. unsigned int enabled;
  463. } dev_list[] = {
  464. { SND_DEV_DSP16 },
  465. { SND_DEV_AUDIO },
  466. };
  467. static int __init oss_init(void)
  468. {
  469. int err;
  470. int i, j;
  471. #ifdef CONFIG_PCI
  472. if(dmabug)
  473. isa_dma_bridge_buggy = dmabug;
  474. #endif
  475. err = create_special_devices();
  476. if (err) {
  477. printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
  478. return err;
  479. }
  480. /* Protecting the innocent */
  481. sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
  482. for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
  483. j = 0;
  484. do {
  485. unsigned short minor = dev_list[i].minor + j * 0x10;
  486. if (!register_sound_special(&oss_sound_fops, minor))
  487. dev_list[i].enabled = (1 << j);
  488. } while (++j < num_audiodevs);
  489. }
  490. if (sound_nblocks >= MAX_MEM_BLOCKS - 1)
  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 < ARRAY_SIZE(dev_list); i++) {
  498. j = 0;
  499. do {
  500. if (dev_list[i].enabled & (1 << j))
  501. unregister_sound_special(dev_list[i].minor);
  502. } while (++j < num_audiodevs);
  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);