soundcard.c 17 KB

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