soundcard.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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_inode(file));
  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. switch (dev & 0x0f) {
  134. case SND_DEV_DSP:
  135. case SND_DEV_DSP16:
  136. case SND_DEV_AUDIO:
  137. ret = audio_read(dev, file, buf, count);
  138. break;
  139. case SND_DEV_SEQ:
  140. case SND_DEV_SEQ2:
  141. ret = sequencer_read(dev, file, buf, count);
  142. break;
  143. case SND_DEV_MIDIN:
  144. ret = MIDIbuf_read(dev, file, buf, count);
  145. }
  146. mutex_unlock(&soundcard_mutex);
  147. return ret;
  148. }
  149. static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
  150. {
  151. int dev = iminor(file_inode(file));
  152. int ret = -EINVAL;
  153. mutex_lock(&soundcard_mutex);
  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. mutex_unlock(&soundcard_mutex);
  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. if ((dev >= SND_NDEVS) || (dev < 0)) {
  176. printk(KERN_ERR "Invalid minor device %d\n", dev);
  177. return -ENXIO;
  178. }
  179. mutex_lock(&soundcard_mutex);
  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. retval = -ENXIO;
  187. if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
  188. break;
  189. if (!try_module_get(mixer_devs[dev]->owner))
  190. break;
  191. retval = 0;
  192. break;
  193. case SND_DEV_SEQ:
  194. case SND_DEV_SEQ2:
  195. retval = sequencer_open(dev, file);
  196. break;
  197. case SND_DEV_MIDIN:
  198. retval = MIDIbuf_open(dev, file);
  199. break;
  200. case SND_DEV_DSP:
  201. case SND_DEV_DSP16:
  202. case SND_DEV_AUDIO:
  203. retval = audio_open(dev, file);
  204. break;
  205. default:
  206. printk(KERN_ERR "Invalid minor device %d\n", dev);
  207. retval = -ENXIO;
  208. }
  209. mutex_unlock(&soundcard_mutex);
  210. return retval;
  211. }
  212. static int sound_release(struct inode *inode, struct file *file)
  213. {
  214. int dev = iminor(inode);
  215. mutex_lock(&soundcard_mutex);
  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. mutex_unlock(&soundcard_mutex);
  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 long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  280. {
  281. int len = 0, dtype;
  282. int dev = iminor(file_inode(file));
  283. long ret = -EINVAL;
  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. if (cmd == OSS_GETVERSION)
  300. return __put_user(SOUND_VERSION, (int __user *)p);
  301. mutex_lock(&soundcard_mutex);
  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. ret = sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
  310. cmd, p);
  311. break;
  312. default:
  313. ret = sound_mixer_ioctl(dev >> 4, cmd, p);
  314. break;
  315. }
  316. mutex_unlock(&soundcard_mutex);
  317. return ret;
  318. }
  319. switch (dev & 0x0f) {
  320. case SND_DEV_CTL:
  321. if (cmd == SOUND_MIXER_GETLEVELS)
  322. ret = get_mixer_levels(p);
  323. else if (cmd == SOUND_MIXER_SETLEVELS)
  324. ret = set_mixer_levels(p);
  325. else
  326. ret = sound_mixer_ioctl(dev >> 4, cmd, p);
  327. break;
  328. case SND_DEV_SEQ:
  329. case SND_DEV_SEQ2:
  330. ret = sequencer_ioctl(dev, file, cmd, p);
  331. break;
  332. case SND_DEV_DSP:
  333. case SND_DEV_DSP16:
  334. case SND_DEV_AUDIO:
  335. ret = audio_ioctl(dev, file, cmd, p);
  336. break;
  337. case SND_DEV_MIDIN:
  338. ret = MIDIbuf_ioctl(dev, file, cmd, p);
  339. break;
  340. }
  341. mutex_unlock(&soundcard_mutex);
  342. return ret;
  343. }
  344. static unsigned int sound_poll(struct file *file, poll_table * wait)
  345. {
  346. struct inode *inode = file_inode(file);
  347. int dev = iminor(inode);
  348. switch (dev & 0x0f) {
  349. case SND_DEV_SEQ:
  350. case SND_DEV_SEQ2:
  351. return sequencer_poll(dev, file, wait);
  352. case SND_DEV_MIDIN:
  353. return MIDIbuf_poll(dev, file, wait);
  354. case SND_DEV_DSP:
  355. case SND_DEV_DSP16:
  356. case SND_DEV_AUDIO:
  357. return DMAbuf_poll(file, dev >> 4, wait);
  358. }
  359. return 0;
  360. }
  361. static int sound_mmap(struct file *file, struct vm_area_struct *vma)
  362. {
  363. int dev_class;
  364. unsigned long size;
  365. struct dma_buffparms *dmap = NULL;
  366. int dev = iminor(file_inode(file));
  367. dev_class = dev & 0x0f;
  368. dev >>= 4;
  369. if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
  370. printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
  371. return -EINVAL;
  372. }
  373. mutex_lock(&soundcard_mutex);
  374. if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
  375. dmap = audio_devs[dev]->dmap_out;
  376. else if (vma->vm_flags & VM_READ)
  377. dmap = audio_devs[dev]->dmap_in;
  378. else {
  379. printk(KERN_ERR "Sound: Undefined mmap() access\n");
  380. mutex_unlock(&soundcard_mutex);
  381. return -EINVAL;
  382. }
  383. if (dmap == NULL) {
  384. printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
  385. mutex_unlock(&soundcard_mutex);
  386. return -EIO;
  387. }
  388. if (dmap->raw_buf == NULL) {
  389. printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
  390. mutex_unlock(&soundcard_mutex);
  391. return -EIO;
  392. }
  393. if (dmap->mapping_flags) {
  394. printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
  395. mutex_unlock(&soundcard_mutex);
  396. return -EIO;
  397. }
  398. if (vma->vm_pgoff != 0) {
  399. printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
  400. mutex_unlock(&soundcard_mutex);
  401. return -EINVAL;
  402. }
  403. size = vma->vm_end - vma->vm_start;
  404. if (size != dmap->bytes_in_use) {
  405. printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
  406. }
  407. if (remap_pfn_range(vma, vma->vm_start,
  408. virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
  409. vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
  410. mutex_unlock(&soundcard_mutex);
  411. return -EAGAIN;
  412. }
  413. dmap->mapping_flags |= DMA_MAP_MAPPED;
  414. if( audio_devs[dev]->d->mmap)
  415. audio_devs[dev]->d->mmap(dev);
  416. memset(dmap->raw_buf,
  417. dmap->neutral_byte,
  418. dmap->bytes_in_use);
  419. mutex_unlock(&soundcard_mutex);
  420. return 0;
  421. }
  422. const struct file_operations oss_sound_fops = {
  423. .owner = THIS_MODULE,
  424. .llseek = no_llseek,
  425. .read = sound_read,
  426. .write = sound_write,
  427. .poll = sound_poll,
  428. .unlocked_ioctl = sound_ioctl,
  429. .mmap = sound_mmap,
  430. .open = sound_open,
  431. .release = sound_release,
  432. };
  433. /*
  434. * Create the required special subdevices
  435. */
  436. static int create_special_devices(void)
  437. {
  438. int seq1,seq2;
  439. seq1=register_sound_special(&oss_sound_fops, 1);
  440. if(seq1==-1)
  441. goto bad;
  442. seq2=register_sound_special(&oss_sound_fops, 8);
  443. if(seq2!=-1)
  444. return 0;
  445. unregister_sound_special(1);
  446. bad:
  447. return -1;
  448. }
  449. static int dmabuf;
  450. static int dmabug;
  451. module_param(dmabuf, int, 0444);
  452. module_param(dmabug, int, 0444);
  453. /* additional minors for compatibility */
  454. struct oss_minor_dev {
  455. unsigned short minor;
  456. unsigned int enabled;
  457. } dev_list[] = {
  458. { SND_DEV_DSP16 },
  459. { SND_DEV_AUDIO },
  460. };
  461. static int __init oss_init(void)
  462. {
  463. int err;
  464. int i, j;
  465. #ifdef CONFIG_PCI
  466. if(dmabug)
  467. isa_dma_bridge_buggy = dmabug;
  468. #endif
  469. err = create_special_devices();
  470. if (err) {
  471. printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
  472. return err;
  473. }
  474. /* Protecting the innocent */
  475. sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
  476. for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
  477. j = 0;
  478. do {
  479. unsigned short minor = dev_list[i].minor + j * 0x10;
  480. if (!register_sound_special(&oss_sound_fops, minor))
  481. dev_list[i].enabled = (1 << j);
  482. } while (++j < num_audiodevs);
  483. }
  484. if (sound_nblocks >= MAX_MEM_BLOCKS - 1)
  485. printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
  486. return 0;
  487. }
  488. static void __exit oss_cleanup(void)
  489. {
  490. int i, j;
  491. for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
  492. j = 0;
  493. do {
  494. if (dev_list[i].enabled & (1 << j))
  495. unregister_sound_special(dev_list[i].minor);
  496. } while (++j < num_audiodevs);
  497. }
  498. unregister_sound_special(1);
  499. unregister_sound_special(8);
  500. sound_stop_timer();
  501. sequencer_unload();
  502. for (i = 0; i < MAX_DMA_CHANNELS; i++)
  503. if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) {
  504. printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i);
  505. sound_free_dma(i);
  506. }
  507. for (i = 0; i < sound_nblocks; i++)
  508. vfree(sound_mem_blocks[i]);
  509. }
  510. module_init(oss_init);
  511. module_exit(oss_cleanup);
  512. MODULE_LICENSE("GPL");
  513. MODULE_DESCRIPTION("OSS Sound subsystem");
  514. MODULE_AUTHOR("Hannu Savolainen, et al.");
  515. int sound_alloc_dma(int chn, char *deviceID)
  516. {
  517. int err;
  518. if ((err = request_dma(chn, deviceID)) != 0)
  519. return err;
  520. dma_alloc_map[chn] = DMA_MAP_FREE;
  521. return 0;
  522. }
  523. EXPORT_SYMBOL(sound_alloc_dma);
  524. int sound_open_dma(int chn, char *deviceID)
  525. {
  526. if (!valid_dma(chn)) {
  527. printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn);
  528. return 1;
  529. }
  530. if (dma_alloc_map[chn] != DMA_MAP_FREE) {
  531. printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]);
  532. return 1;
  533. }
  534. dma_alloc_map[chn] = DMA_MAP_BUSY;
  535. return 0;
  536. }
  537. EXPORT_SYMBOL(sound_open_dma);
  538. void sound_free_dma(int chn)
  539. {
  540. if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) {
  541. /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */
  542. return;
  543. }
  544. free_dma(chn);
  545. dma_alloc_map[chn] = DMA_MAP_UNAVAIL;
  546. }
  547. EXPORT_SYMBOL(sound_free_dma);
  548. void sound_close_dma(int chn)
  549. {
  550. if (dma_alloc_map[chn] != DMA_MAP_BUSY) {
  551. printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn);
  552. return;
  553. }
  554. dma_alloc_map[chn] = DMA_MAP_FREE;
  555. }
  556. EXPORT_SYMBOL(sound_close_dma);
  557. static void do_sequencer_timer(unsigned long dummy)
  558. {
  559. sequencer_timer(0);
  560. }
  561. static DEFINE_TIMER(seq_timer, do_sequencer_timer, 0, 0);
  562. void request_sound_timer(int count)
  563. {
  564. extern unsigned long seq_time;
  565. if (count < 0) {
  566. seq_timer.expires = (-count) + jiffies;
  567. add_timer(&seq_timer);
  568. return;
  569. }
  570. count += seq_time;
  571. count -= jiffies;
  572. if (count < 1)
  573. count = 1;
  574. seq_timer.expires = (count) + jiffies;
  575. add_timer(&seq_timer);
  576. }
  577. void sound_stop_timer(void)
  578. {
  579. del_timer(&seq_timer);
  580. }
  581. void conf_printf(char *name, struct address_info *hw_config)
  582. {
  583. #ifndef CONFIG_SOUND_TRACEINIT
  584. return;
  585. #else
  586. printk("<%s> at 0x%03x", name, hw_config->io_base);
  587. if (hw_config->irq)
  588. printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq);
  589. if (hw_config->dma != -1 || hw_config->dma2 != -1)
  590. {
  591. printk(" dma %d", hw_config->dma);
  592. if (hw_config->dma2 != -1)
  593. printk(",%d", hw_config->dma2);
  594. }
  595. printk("\n");
  596. #endif
  597. }
  598. EXPORT_SYMBOL(conf_printf);
  599. void conf_printf2(char *name, int base, int irq, int dma, int dma2)
  600. {
  601. #ifndef CONFIG_SOUND_TRACEINIT
  602. return;
  603. #else
  604. printk("<%s> at 0x%03x", name, base);
  605. if (irq)
  606. printk(" irq %d", (irq > 0) ? irq : -irq);
  607. if (dma != -1 || dma2 != -1)
  608. {
  609. printk(" dma %d", dma);
  610. if (dma2 != -1)
  611. printk(",%d", dma2);
  612. }
  613. printk("\n");
  614. #endif
  615. }
  616. EXPORT_SYMBOL(conf_printf2);