soundcard.c 17 KB

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