dmasound_core.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841
  1. /*
  2. * linux/sound/oss/dmasound/dmasound_core.c
  3. *
  4. *
  5. * OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for
  6. * Linux/m68k
  7. * Extended to support Power Macintosh for Linux/ppc by Paul Mackerras
  8. *
  9. * (c) 1995 by Michael Schlueter & Michael Marte
  10. *
  11. * Michael Schlueter (michael@duck.syd.de) did the basic structure of the VFS
  12. * interface and the u-law to signed byte conversion.
  13. *
  14. * Michael Marte (marte@informatik.uni-muenchen.de) did the sound queue,
  15. * /dev/mixer, /dev/sndstat and complemented the VFS interface. He would like
  16. * to thank:
  17. * - Michael Schlueter for initial ideas and documentation on the MFP and
  18. * the DMA sound hardware.
  19. * - Therapy? for their CD 'Troublegum' which really made me rock.
  20. *
  21. * /dev/sndstat is based on code by Hannu Savolainen, the author of the
  22. * VoxWare family of drivers.
  23. *
  24. * This file is subject to the terms and conditions of the GNU General Public
  25. * License. See the file COPYING in the main directory of this archive
  26. * for more details.
  27. *
  28. * History:
  29. *
  30. * 1995/8/25 First release
  31. *
  32. * 1995/9/02 Roman Hodek:
  33. * - Fixed atari_stram_alloc() call, the timer
  34. * programming and several race conditions
  35. * 1995/9/14 Roman Hodek:
  36. * - After some discussion with Michael Schlueter,
  37. * revised the interrupt disabling
  38. * - Slightly speeded up U8->S8 translation by using
  39. * long operations where possible
  40. * - Added 4:3 interpolation for /dev/audio
  41. *
  42. * 1995/9/20 Torsten Scherer:
  43. * - Fixed a bug in sq_write and changed /dev/audio
  44. * converting to play at 12517Hz instead of 6258Hz.
  45. *
  46. * 1995/9/23 Torsten Scherer:
  47. * - Changed sq_interrupt() and sq_play() to pre-program
  48. * the DMA for another frame while there's still one
  49. * running. This allows the IRQ response to be
  50. * arbitrarily delayed and playing will still continue.
  51. *
  52. * 1995/10/14 Guenther Kelleter, Torsten Scherer:
  53. * - Better support for Falcon audio (the Falcon doesn't
  54. * raise an IRQ at the end of a frame, but at the
  55. * beginning instead!). uses 'if (codec_dma)' in lots
  56. * of places to simply switch between Falcon and TT
  57. * code.
  58. *
  59. * 1995/11/06 Torsten Scherer:
  60. * - Started introducing a hardware abstraction scheme
  61. * (may perhaps also serve for Amigas?)
  62. * - Can now play samples at almost all frequencies by
  63. * means of a more generalized expand routine
  64. * - Takes a good deal of care to cut data only at
  65. * sample sizes
  66. * - Buffer size is now a kernel runtime option
  67. * - Implemented fsync() & several minor improvements
  68. * Guenther Kelleter:
  69. * - Useful hints and bug fixes
  70. * - Cross-checked it for Falcons
  71. *
  72. * 1996/3/9 Geert Uytterhoeven:
  73. * - Support added for Amiga, A-law, 16-bit little
  74. * endian.
  75. * - Unification to drivers/sound/dmasound.c.
  76. *
  77. * 1996/4/6 Martin Mitchell:
  78. * - Updated to 1.3 kernel.
  79. *
  80. * 1996/6/13 Topi Kanerva:
  81. * - Fixed things that were broken (mainly the amiga
  82. * 14-bit routines)
  83. * - /dev/sndstat shows now the real hardware frequency
  84. * - The lowpass filter is disabled by default now
  85. *
  86. * 1996/9/25 Geert Uytterhoeven:
  87. * - Modularization
  88. *
  89. * 1998/6/10 Andreas Schwab:
  90. * - Converted to use sound_core
  91. *
  92. * 1999/12/28 Richard Zidlicky:
  93. * - Added support for Q40
  94. *
  95. * 2000/2/27 Geert Uytterhoeven:
  96. * - Clean up and split the code into 4 parts:
  97. * o dmasound_core: machine-independent code
  98. * o dmasound_atari: Atari TT and Falcon support
  99. * o dmasound_awacs: Apple PowerMac support
  100. * o dmasound_paula: Amiga support
  101. *
  102. * 2000/3/25 Geert Uytterhoeven:
  103. * - Integration of dmasound_q40
  104. * - Small clean ups
  105. *
  106. * 2001/01/26 [1.0] Iain Sandoe
  107. * - make /dev/sndstat show revision & edition info.
  108. * - since dmasound.mach.sq_setup() can fail on pmac
  109. * its type has been changed to int and the returns
  110. * are checked.
  111. * [1.1] - stop missing translations from being called.
  112. * 2001/02/08 [1.2] - remove unused translation tables & move machine-
  113. * specific tables to low-level.
  114. * - return correct info. for SNDCTL_DSP_GETFMTS.
  115. * [1.3] - implement SNDCTL_DSP_GETCAPS fully.
  116. * [1.4] - make /dev/sndstat text length usage deterministic.
  117. * - make /dev/sndstat call to low-level
  118. * dmasound.mach.state_info() pass max space to ll driver.
  119. * - tidy startup banners and output info.
  120. * [1.5] - tidy up a little (removed some unused #defines in
  121. * dmasound.h)
  122. * - fix up HAS_RECORD conditionalisation.
  123. * - add record code in places it is missing...
  124. * - change buf-sizes to bytes to allow < 1kb for pmac
  125. * if user param entry is < 256 the value is taken to
  126. * be in kb > 256 is taken to be in bytes.
  127. * - make default buff/frag params conditional on
  128. * machine to allow smaller values for pmac.
  129. * - made the ioctls, read & write comply with the OSS
  130. * rules on setting params.
  131. * - added parsing of _setup() params for record.
  132. * 2001/04/04 [1.6] - fix bug where sample rates higher than maximum were
  133. * being reported as OK.
  134. * - fix open() to return -EBUSY as per OSS doc. when
  135. * audio is in use - this is independent of O_NOBLOCK.
  136. * - fix bug where SNDCTL_DSP_POST was blocking.
  137. */
  138. /* Record capability notes 30/01/2001:
  139. * At present these observations apply only to pmac LL driver (the only one
  140. * that can do record, at present). However, if other LL drivers for machines
  141. * with record are added they may apply.
  142. *
  143. * The fragment parameters for the record and play channels are separate.
  144. * However, if the driver is opened O_RDWR there is no way (in the current OSS
  145. * API) to specify their values independently for the record and playback
  146. * channels. Since the only common factor between the input & output is the
  147. * sample rate (on pmac) it should be possible to open /dev/dspX O_WRONLY and
  148. * /dev/dspY O_RDONLY. The input & output channels could then have different
  149. * characteristics (other than the first that sets sample rate claiming the
  150. * right to set it for ever). As it stands, the format, channels, number of
  151. * bits & sample rate are assumed to be common. In the future perhaps these
  152. * should be the responsibility of the LL driver - and then if a card really
  153. * does not share items between record & playback they can be specified
  154. * separately.
  155. */
  156. /* Thread-safeness of shared_resources notes: 31/01/2001
  157. * If the user opens O_RDWR and then splits record & play between two threads
  158. * both of which inherit the fd - and then starts changing things from both
  159. * - we will have difficulty telling.
  160. *
  161. * It's bad application coding - but ...
  162. * TODO: think about how to sort this out... without bogging everything down in
  163. * semaphores.
  164. *
  165. * Similarly, the OSS spec says "all changes to parameters must be between
  166. * open() and the first read() or write(). - and a bit later on (by
  167. * implication) "between SNDCTL_DSP_RESET and the first read() or write() after
  168. * it". If the app is multi-threaded and this rule is broken between threads
  169. * we will have trouble spotting it - and the fault will be rather obscure :-(
  170. *
  171. * We will try and put out at least a kmsg if we see it happen... but I think
  172. * it will be quite hard to trap it with an -EXXX return... because we can't
  173. * see the fault until after the damage is done.
  174. */
  175. #include <linux/module.h>
  176. #include <linux/slab.h>
  177. #include <linux/sound.h>
  178. #include <linux/init.h>
  179. #include <linux/soundcard.h>
  180. #include <linux/poll.h>
  181. #include <linux/smp_lock.h>
  182. #include <asm/uaccess.h>
  183. #include "dmasound.h"
  184. #define DMASOUND_CORE_REVISION 1
  185. #define DMASOUND_CORE_EDITION 6
  186. /*
  187. * Declarations
  188. */
  189. int dmasound_catchRadius = 0;
  190. module_param(dmasound_catchRadius, int, 0);
  191. static unsigned int numWriteBufs = DEFAULT_N_BUFFERS;
  192. module_param(numWriteBufs, int, 0);
  193. static unsigned int writeBufSize = DEFAULT_BUFF_SIZE ; /* in bytes */
  194. module_param(writeBufSize, int, 0);
  195. #ifdef HAS_RECORD
  196. static unsigned int numReadBufs = DEFAULT_N_BUFFERS;
  197. module_param(numReadBufs, int, 0);
  198. static unsigned int readBufSize = DEFAULT_BUFF_SIZE; /* in bytes */
  199. module_param(readBufSize, int, 0);
  200. #endif
  201. MODULE_LICENSE("GPL");
  202. #ifdef MODULE
  203. static int sq_unit = -1;
  204. static int mixer_unit = -1;
  205. static int state_unit = -1;
  206. static int irq_installed;
  207. #endif /* MODULE */
  208. /* software implemented recording volume! */
  209. uint software_input_volume = SW_INPUT_VOLUME_SCALE * SW_INPUT_VOLUME_DEFAULT;
  210. EXPORT_SYMBOL(software_input_volume);
  211. /* control over who can modify resources shared between play/record */
  212. static mode_t shared_resource_owner;
  213. static int shared_resources_initialised;
  214. /*
  215. * Mid level stuff
  216. */
  217. struct sound_settings dmasound = { .lock = SPIN_LOCK_UNLOCKED };
  218. static inline void sound_silence(void)
  219. {
  220. dmasound.mach.silence(); /* _MUST_ stop DMA */
  221. }
  222. static inline int sound_set_format(int format)
  223. {
  224. return dmasound.mach.setFormat(format);
  225. }
  226. static int sound_set_speed(int speed)
  227. {
  228. if (speed < 0)
  229. return dmasound.soft.speed;
  230. /* trap out-of-range speed settings.
  231. at present we allow (arbitrarily) low rates - using soft
  232. up-conversion - but we can't allow > max because there is
  233. no soft down-conversion.
  234. */
  235. if (dmasound.mach.max_dsp_speed &&
  236. (speed > dmasound.mach.max_dsp_speed))
  237. speed = dmasound.mach.max_dsp_speed ;
  238. dmasound.soft.speed = speed;
  239. if (dmasound.minDev == SND_DEV_DSP)
  240. dmasound.dsp.speed = dmasound.soft.speed;
  241. return dmasound.soft.speed;
  242. }
  243. static int sound_set_stereo(int stereo)
  244. {
  245. if (stereo < 0)
  246. return dmasound.soft.stereo;
  247. stereo = !!stereo; /* should be 0 or 1 now */
  248. dmasound.soft.stereo = stereo;
  249. if (dmasound.minDev == SND_DEV_DSP)
  250. dmasound.dsp.stereo = stereo;
  251. return stereo;
  252. }
  253. static ssize_t sound_copy_translate(TRANS *trans, const u_char __user *userPtr,
  254. size_t userCount, u_char frame[],
  255. ssize_t *frameUsed, ssize_t frameLeft)
  256. {
  257. ssize_t (*ct_func)(const u_char __user *, size_t, u_char *, ssize_t *, ssize_t);
  258. switch (dmasound.soft.format) {
  259. case AFMT_MU_LAW:
  260. ct_func = trans->ct_ulaw;
  261. break;
  262. case AFMT_A_LAW:
  263. ct_func = trans->ct_alaw;
  264. break;
  265. case AFMT_S8:
  266. ct_func = trans->ct_s8;
  267. break;
  268. case AFMT_U8:
  269. ct_func = trans->ct_u8;
  270. break;
  271. case AFMT_S16_BE:
  272. ct_func = trans->ct_s16be;
  273. break;
  274. case AFMT_U16_BE:
  275. ct_func = trans->ct_u16be;
  276. break;
  277. case AFMT_S16_LE:
  278. ct_func = trans->ct_s16le;
  279. break;
  280. case AFMT_U16_LE:
  281. ct_func = trans->ct_u16le;
  282. break;
  283. default:
  284. return 0;
  285. }
  286. /* if the user has requested a non-existent translation don't try
  287. to call it but just return 0 bytes moved
  288. */
  289. if (ct_func)
  290. return ct_func(userPtr, userCount, frame, frameUsed, frameLeft);
  291. return 0;
  292. }
  293. /*
  294. * /dev/mixer abstraction
  295. */
  296. static struct {
  297. int busy;
  298. int modify_counter;
  299. } mixer;
  300. static int mixer_open(struct inode *inode, struct file *file)
  301. {
  302. if (!try_module_get(dmasound.mach.owner))
  303. return -ENODEV;
  304. mixer.busy = 1;
  305. return 0;
  306. }
  307. static int mixer_release(struct inode *inode, struct file *file)
  308. {
  309. lock_kernel();
  310. mixer.busy = 0;
  311. module_put(dmasound.mach.owner);
  312. unlock_kernel();
  313. return 0;
  314. }
  315. static int mixer_ioctl(struct inode *inode, struct file *file, u_int cmd,
  316. u_long arg)
  317. {
  318. if (_SIOC_DIR(cmd) & _SIOC_WRITE)
  319. mixer.modify_counter++;
  320. switch (cmd) {
  321. case OSS_GETVERSION:
  322. return IOCTL_OUT(arg, SOUND_VERSION);
  323. case SOUND_MIXER_INFO:
  324. {
  325. mixer_info info;
  326. memset(&info, 0, sizeof(info));
  327. strlcpy(info.id, dmasound.mach.name2, sizeof(info.id));
  328. strlcpy(info.name, dmasound.mach.name2, sizeof(info.name));
  329. info.modify_counter = mixer.modify_counter;
  330. if (copy_to_user((void __user *)arg, &info, sizeof(info)))
  331. return -EFAULT;
  332. return 0;
  333. }
  334. }
  335. if (dmasound.mach.mixer_ioctl)
  336. return dmasound.mach.mixer_ioctl(cmd, arg);
  337. return -EINVAL;
  338. }
  339. static const struct file_operations mixer_fops =
  340. {
  341. .owner = THIS_MODULE,
  342. .llseek = no_llseek,
  343. .ioctl = mixer_ioctl,
  344. .open = mixer_open,
  345. .release = mixer_release,
  346. };
  347. static void mixer_init(void)
  348. {
  349. #ifndef MODULE
  350. int mixer_unit;
  351. #endif
  352. mixer_unit = register_sound_mixer(&mixer_fops, -1);
  353. if (mixer_unit < 0)
  354. return;
  355. mixer.busy = 0;
  356. dmasound.treble = 0;
  357. dmasound.bass = 0;
  358. if (dmasound.mach.mixer_init)
  359. dmasound.mach.mixer_init();
  360. }
  361. /*
  362. * Sound queue stuff, the heart of the driver
  363. */
  364. struct sound_queue dmasound_write_sq;
  365. static void sq_reset_output(void) ;
  366. #ifdef HAS_RECORD
  367. struct sound_queue dmasound_read_sq;
  368. static void sq_reset_input(void) ;
  369. #endif
  370. static int sq_allocate_buffers(struct sound_queue *sq, int num, int size)
  371. {
  372. int i;
  373. if (sq->buffers)
  374. return 0;
  375. sq->numBufs = num;
  376. sq->bufSize = size;
  377. sq->buffers = kmalloc (num * sizeof(char *), GFP_KERNEL);
  378. if (!sq->buffers)
  379. return -ENOMEM;
  380. for (i = 0; i < num; i++) {
  381. sq->buffers[i] = dmasound.mach.dma_alloc(size, GFP_KERNEL);
  382. if (!sq->buffers[i]) {
  383. while (i--)
  384. dmasound.mach.dma_free(sq->buffers[i], size);
  385. kfree(sq->buffers);
  386. sq->buffers = NULL;
  387. return -ENOMEM;
  388. }
  389. }
  390. return 0;
  391. }
  392. static void sq_release_buffers(struct sound_queue *sq)
  393. {
  394. int i;
  395. if (sq->buffers) {
  396. for (i = 0; i < sq->numBufs; i++)
  397. dmasound.mach.dma_free(sq->buffers[i], sq->bufSize);
  398. kfree(sq->buffers);
  399. sq->buffers = NULL;
  400. }
  401. }
  402. static int sq_setup(struct sound_queue *sq)
  403. {
  404. int (*setup_func)(void) = NULL;
  405. int hard_frame ;
  406. if (sq->locked) { /* are we already set? - and not changeable */
  407. #ifdef DEBUG_DMASOUND
  408. printk("dmasound_core: tried to sq_setup a locked queue\n") ;
  409. #endif
  410. return -EINVAL ;
  411. }
  412. sq->locked = 1 ; /* don't think we have a race prob. here _check_ */
  413. /* make sure that the parameters are set up
  414. This should have been done already...
  415. */
  416. dmasound.mach.init();
  417. /* OK. If the user has set fragment parameters explicitly, then we
  418. should leave them alone... as long as they are valid.
  419. Invalid user fragment params can occur if we allow the whole buffer
  420. to be used when the user requests the fragments sizes (with no soft
  421. x-lation) and then the user subsequently sets a soft x-lation that
  422. requires increased internal buffering.
  423. Othwerwise (if the user did not set them) OSS says that we should
  424. select frag params on the basis of 0.5 s output & 0.1 s input
  425. latency. (TODO. For now we will copy in the defaults.)
  426. */
  427. if (sq->user_frags <= 0) {
  428. sq->max_count = sq->numBufs ;
  429. sq->max_active = sq->numBufs ;
  430. sq->block_size = sq->bufSize;
  431. /* set up the user info */
  432. sq->user_frags = sq->numBufs ;
  433. sq->user_frag_size = sq->bufSize ;
  434. sq->user_frag_size *=
  435. (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
  436. sq->user_frag_size /=
  437. (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
  438. } else {
  439. /* work out requested block size */
  440. sq->block_size = sq->user_frag_size ;
  441. sq->block_size *=
  442. (dmasound.hard.size * (dmasound.hard.stereo+1) ) ;
  443. sq->block_size /=
  444. (dmasound.soft.size * (dmasound.soft.stereo+1) ) ;
  445. /* the user wants to write frag-size chunks */
  446. sq->block_size *= dmasound.hard.speed ;
  447. sq->block_size /= dmasound.soft.speed ;
  448. /* this only works for size values which are powers of 2 */
  449. hard_frame =
  450. (dmasound.hard.size * (dmasound.hard.stereo+1))/8 ;
  451. sq->block_size += (hard_frame - 1) ;
  452. sq->block_size &= ~(hard_frame - 1) ; /* make sure we are aligned */
  453. /* let's just check for obvious mistakes */
  454. if ( sq->block_size <= 0 || sq->block_size > sq->bufSize) {
  455. #ifdef DEBUG_DMASOUND
  456. printk("dmasound_core: invalid frag size (user set %d)\n", sq->user_frag_size) ;
  457. #endif
  458. sq->block_size = sq->bufSize ;
  459. }
  460. if ( sq->user_frags <= sq->numBufs ) {
  461. sq->max_count = sq->user_frags ;
  462. /* if user has set max_active - then use it */
  463. sq->max_active = (sq->max_active <= sq->max_count) ?
  464. sq->max_active : sq->max_count ;
  465. } else {
  466. #ifdef DEBUG_DMASOUND
  467. printk("dmasound_core: invalid frag count (user set %d)\n", sq->user_frags) ;
  468. #endif
  469. sq->max_count =
  470. sq->max_active = sq->numBufs ;
  471. }
  472. }
  473. sq->front = sq->count = sq->rear_size = 0;
  474. sq->syncing = 0;
  475. sq->active = 0;
  476. if (sq == &write_sq) {
  477. sq->rear = -1;
  478. setup_func = dmasound.mach.write_sq_setup;
  479. }
  480. #ifdef HAS_RECORD
  481. else {
  482. sq->rear = 0;
  483. setup_func = dmasound.mach.read_sq_setup;
  484. }
  485. #endif
  486. if (setup_func)
  487. return setup_func();
  488. return 0 ;
  489. }
  490. static inline void sq_play(void)
  491. {
  492. dmasound.mach.play();
  493. }
  494. static ssize_t sq_write(struct file *file, const char __user *src, size_t uLeft,
  495. loff_t *ppos)
  496. {
  497. ssize_t uWritten = 0;
  498. u_char *dest;
  499. ssize_t uUsed = 0, bUsed, bLeft;
  500. unsigned long flags ;
  501. /* ++TeSche: Is something like this necessary?
  502. * Hey, that's an honest question! Or does any other part of the
  503. * filesystem already checks this situation? I really don't know.
  504. */
  505. if (uLeft == 0)
  506. return 0;
  507. /* implement any changes we have made to the soft/hard params.
  508. this is not satisfactory really, all we have done up to now is to
  509. say what we would like - there hasn't been any real checking of capability
  510. */
  511. if (shared_resources_initialised == 0) {
  512. dmasound.mach.init() ;
  513. shared_resources_initialised = 1 ;
  514. }
  515. /* set up the sq if it is not already done. This may seem a dumb place
  516. to do it - but it is what OSS requires. It means that write() can
  517. return memory allocation errors. To avoid this possibility use the
  518. GETBLKSIZE or GETOSPACE ioctls (after you've fiddled with all the
  519. params you want to change) - these ioctls also force the setup.
  520. */
  521. if (write_sq.locked == 0) {
  522. if ((uWritten = sq_setup(&write_sq)) < 0) return uWritten ;
  523. uWritten = 0 ;
  524. }
  525. /* FIXME: I think that this may be the wrong behaviour when we get strapped
  526. for time and the cpu is close to being (or actually) behind in sending data.
  527. - because we've lost the time that the N samples, already in the buffer,
  528. would have given us to get here with the next lot from the user.
  529. */
  530. /* The interrupt doesn't start to play the last, incomplete frame.
  531. * Thus we can append to it without disabling the interrupts! (Note
  532. * also that write_sq.rear isn't affected by the interrupt.)
  533. */
  534. /* as of 1.6 this behaviour changes if SNDCTL_DSP_POST has been issued:
  535. this will mimic the behaviour of syncing and allow the sq_play() to
  536. queue a partial fragment. Since sq_play() may/will be called from
  537. the IRQ handler - at least on Pmac we have to deal with it.
  538. The strategy - possibly not optimum - is to kill _POST status if we
  539. get here. This seems, at least, reasonable - in the sense that POST
  540. is supposed to indicate that we might not write before the queue
  541. is drained - and if we get here in time then it does not apply.
  542. */
  543. spin_lock_irqsave(&dmasound.lock, flags);
  544. write_sq.syncing &= ~2 ; /* take out POST status */
  545. spin_unlock_irqrestore(&dmasound.lock, flags);
  546. if (write_sq.count > 0 &&
  547. (bLeft = write_sq.block_size-write_sq.rear_size) > 0) {
  548. dest = write_sq.buffers[write_sq.rear];
  549. bUsed = write_sq.rear_size;
  550. uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
  551. dest, &bUsed, bLeft);
  552. if (uUsed <= 0)
  553. return uUsed;
  554. src += uUsed;
  555. uWritten += uUsed;
  556. uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
  557. write_sq.rear_size = bUsed;
  558. }
  559. while (uLeft) {
  560. while (write_sq.count >= write_sq.max_active) {
  561. sq_play();
  562. if (write_sq.open_mode & O_NONBLOCK)
  563. return uWritten > 0 ? uWritten : -EAGAIN;
  564. SLEEP(write_sq.action_queue);
  565. if (signal_pending(current))
  566. return uWritten > 0 ? uWritten : -EINTR;
  567. }
  568. /* Here, we can avoid disabling the interrupt by first
  569. * copying and translating the data, and then updating
  570. * the write_sq variables. Until this is done, the interrupt
  571. * won't see the new frame and we can work on it
  572. * undisturbed.
  573. */
  574. dest = write_sq.buffers[(write_sq.rear+1) % write_sq.max_count];
  575. bUsed = 0;
  576. bLeft = write_sq.block_size;
  577. uUsed = sound_copy_translate(dmasound.trans_write, src, uLeft,
  578. dest, &bUsed, bLeft);
  579. if (uUsed <= 0)
  580. break;
  581. src += uUsed;
  582. uWritten += uUsed;
  583. uLeft = (uUsed <= uLeft) ? (uLeft - uUsed) : 0 ; /* paranoia */
  584. if (bUsed) {
  585. write_sq.rear = (write_sq.rear+1) % write_sq.max_count;
  586. write_sq.rear_size = bUsed;
  587. write_sq.count++;
  588. }
  589. } /* uUsed may have been 0 */
  590. sq_play();
  591. return uUsed < 0? uUsed: uWritten;
  592. }
  593. static unsigned int sq_poll(struct file *file, struct poll_table_struct *wait)
  594. {
  595. unsigned int mask = 0;
  596. int retVal;
  597. if (write_sq.locked == 0) {
  598. if ((retVal = sq_setup(&write_sq)) < 0)
  599. return retVal;
  600. return 0;
  601. }
  602. if (file->f_mode & FMODE_WRITE )
  603. poll_wait(file, &write_sq.action_queue, wait);
  604. #ifdef HAS_RECORD
  605. if (file->f_mode & FMODE_READ)
  606. poll_wait(file, &read_sq.action_queue, wait);
  607. if (file->f_mode & FMODE_READ)
  608. if (read_sq.block_size - read_sq.rear_size > 0)
  609. mask |= POLLIN | POLLRDNORM;
  610. #endif
  611. if (file->f_mode & FMODE_WRITE)
  612. if (write_sq.count < write_sq.max_active || write_sq.block_size - write_sq.rear_size > 0)
  613. mask |= POLLOUT | POLLWRNORM;
  614. return mask;
  615. }
  616. #ifdef HAS_RECORD
  617. /*
  618. * Here is how the values are used for reading.
  619. * The value 'active' simply indicates the DMA is running. This is done
  620. * so the driver semantics are DMA starts when the first read is posted.
  621. * The value 'front' indicates the buffer we should next send to the user.
  622. * The value 'rear' indicates the buffer the DMA is currently filling.
  623. * When 'front' == 'rear' the buffer "ring" is empty (we always have an
  624. * empty available). The 'rear_size' is used to track partial offsets
  625. * into the buffer we are currently returning to the user.
  626. * This level (> [1.5]) doesn't care what strategy the LL driver uses with
  627. * DMA on over-run. It can leave it running (and keep active == 1) or it
  628. * can kill it and set active == 0 in which case this routine will spot
  629. * it and restart the DMA.
  630. */
  631. static ssize_t sq_read(struct file *file, char __user *dst, size_t uLeft,
  632. loff_t *ppos)
  633. {
  634. ssize_t uRead, bLeft, bUsed, uUsed;
  635. if (uLeft == 0)
  636. return 0;
  637. /* cater for the compatibility mode - record compiled in but no LL */
  638. if (dmasound.mach.record == NULL)
  639. return -EINVAL ;
  640. /* see comment in sq_write()
  641. */
  642. if( shared_resources_initialised == 0) {
  643. dmasound.mach.init() ;
  644. shared_resources_initialised = 1 ;
  645. }
  646. /* set up the sq if it is not already done. see comments in sq_write().
  647. */
  648. if (read_sq.locked == 0) {
  649. if ((uRead = sq_setup(&read_sq)) < 0)
  650. return uRead ;
  651. }
  652. uRead = 0;
  653. /* Move what the user requests, depending upon other options.
  654. */
  655. while (uLeft > 0) {
  656. /* we happened to get behind and the LL driver killed DMA
  657. then we should set it going again. This also sets it
  658. going the first time through.
  659. */
  660. if ( !read_sq.active )
  661. dmasound.mach.record();
  662. /* When front == rear, the DMA is not done yet.
  663. */
  664. while (read_sq.front == read_sq.rear) {
  665. if (read_sq.open_mode & O_NONBLOCK) {
  666. return uRead > 0 ? uRead : -EAGAIN;
  667. }
  668. SLEEP(read_sq.action_queue);
  669. if (signal_pending(current))
  670. return uRead > 0 ? uRead : -EINTR;
  671. }
  672. /* The amount we move is either what is left in the
  673. * current buffer or what the user wants.
  674. */
  675. bLeft = read_sq.block_size - read_sq.rear_size;
  676. bUsed = read_sq.rear_size;
  677. uUsed = sound_copy_translate(dmasound.trans_read, dst, uLeft,
  678. read_sq.buffers[read_sq.front],
  679. &bUsed, bLeft);
  680. if (uUsed <= 0)
  681. return uUsed;
  682. dst += uUsed;
  683. uRead += uUsed;
  684. uLeft -= uUsed;
  685. read_sq.rear_size += bUsed;
  686. if (read_sq.rear_size >= read_sq.block_size) {
  687. read_sq.rear_size = 0;
  688. read_sq.front++;
  689. if (read_sq.front >= read_sq.max_active)
  690. read_sq.front = 0;
  691. }
  692. }
  693. return uRead;
  694. }
  695. #endif /* HAS_RECORD */
  696. static inline void sq_init_waitqueue(struct sound_queue *sq)
  697. {
  698. init_waitqueue_head(&sq->action_queue);
  699. init_waitqueue_head(&sq->open_queue);
  700. init_waitqueue_head(&sq->sync_queue);
  701. sq->busy = 0;
  702. }
  703. #if 0 /* blocking open() */
  704. static inline void sq_wake_up(struct sound_queue *sq, struct file *file,
  705. mode_t mode)
  706. {
  707. if (file->f_mode & mode) {
  708. sq->busy = 0; /* CHECK: IS THIS OK??? */
  709. WAKE_UP(sq->open_queue);
  710. }
  711. }
  712. #endif
  713. static int sq_open2(struct sound_queue *sq, struct file *file, mode_t mode,
  714. int numbufs, int bufsize)
  715. {
  716. int rc = 0;
  717. if (file->f_mode & mode) {
  718. if (sq->busy) {
  719. #if 0 /* blocking open() */
  720. rc = -EBUSY;
  721. if (file->f_flags & O_NONBLOCK)
  722. return rc;
  723. rc = -EINTR;
  724. while (sq->busy) {
  725. SLEEP(sq->open_queue);
  726. if (signal_pending(current))
  727. return rc;
  728. }
  729. rc = 0;
  730. #else
  731. /* OSS manual says we will return EBUSY regardless
  732. of O_NOBLOCK.
  733. */
  734. return -EBUSY ;
  735. #endif
  736. }
  737. sq->busy = 1; /* Let's play spot-the-race-condition */
  738. /* allocate the default number & size of buffers.
  739. (i.e. specified in _setup() or as module params)
  740. can't be changed at the moment - but _could_ be perhaps
  741. in the setfragments ioctl.
  742. */
  743. if (( rc = sq_allocate_buffers(sq, numbufs, bufsize))) {
  744. #if 0 /* blocking open() */
  745. sq_wake_up(sq, file, mode);
  746. #else
  747. sq->busy = 0 ;
  748. #endif
  749. return rc;
  750. }
  751. sq->open_mode = file->f_mode;
  752. }
  753. return rc;
  754. }
  755. #define write_sq_init_waitqueue() sq_init_waitqueue(&write_sq)
  756. #if 0 /* blocking open() */
  757. #define write_sq_wake_up(file) sq_wake_up(&write_sq, file, FMODE_WRITE)
  758. #endif
  759. #define write_sq_release_buffers() sq_release_buffers(&write_sq)
  760. #define write_sq_open(file) \
  761. sq_open2(&write_sq, file, FMODE_WRITE, numWriteBufs, writeBufSize )
  762. #ifdef HAS_RECORD
  763. #define read_sq_init_waitqueue() sq_init_waitqueue(&read_sq)
  764. #if 0 /* blocking open() */
  765. #define read_sq_wake_up(file) sq_wake_up(&read_sq, file, FMODE_READ)
  766. #endif
  767. #define read_sq_release_buffers() sq_release_buffers(&read_sq)
  768. #define read_sq_open(file) \
  769. sq_open2(&read_sq, file, FMODE_READ, numReadBufs, readBufSize )
  770. #else
  771. #define read_sq_init_waitqueue() do {} while (0)
  772. #if 0 /* blocking open() */
  773. #define read_sq_wake_up(file) do {} while (0)
  774. #endif
  775. #define read_sq_release_buffers() do {} while (0)
  776. #define sq_reset_input() do {} while (0)
  777. #endif
  778. static int sq_open(struct inode *inode, struct file *file)
  779. {
  780. int rc;
  781. if (!try_module_get(dmasound.mach.owner))
  782. return -ENODEV;
  783. rc = write_sq_open(file); /* checks the f_mode */
  784. if (rc)
  785. goto out;
  786. #ifdef HAS_RECORD
  787. if (dmasound.mach.record) {
  788. rc = read_sq_open(file); /* checks the f_mode */
  789. if (rc)
  790. goto out;
  791. } else { /* no record function installed; in compat mode */
  792. if (file->f_mode & FMODE_READ) {
  793. /* TODO: if O_RDWR, release any resources grabbed by write part */
  794. rc = -ENXIO;
  795. goto out;
  796. }
  797. }
  798. #else /* !HAS_RECORD */
  799. if (file->f_mode & FMODE_READ) {
  800. /* TODO: if O_RDWR, release any resources grabbed by write part */
  801. rc = -ENXIO ; /* I think this is what is required by open(2) */
  802. goto out;
  803. }
  804. #endif /* HAS_RECORD */
  805. if (dmasound.mach.sq_open)
  806. dmasound.mach.sq_open(file->f_mode);
  807. /* CHECK whether this is sensible - in the case that dsp0 could be opened
  808. O_RDONLY and dsp1 could be opened O_WRONLY
  809. */
  810. dmasound.minDev = iminor(inode) & 0x0f;
  811. /* OK. - we should make some attempt at consistency. At least the H'ware
  812. options should be set with a valid mode. We will make it that the LL
  813. driver must supply defaults for hard & soft params.
  814. */
  815. if (shared_resource_owner == 0) {
  816. /* you can make this AFMT_U8/mono/8K if you want to mimic old
  817. OSS behaviour - while we still have soft translations ;-) */
  818. dmasound.soft = dmasound.mach.default_soft ;
  819. dmasound.dsp = dmasound.mach.default_soft ;
  820. dmasound.hard = dmasound.mach.default_hard ;
  821. }
  822. #ifndef DMASOUND_STRICT_OSS_COMPLIANCE
  823. /* none of the current LL drivers can actually do this "native" at the moment
  824. OSS does not really require us to supply /dev/audio if we can't do it.
  825. */
  826. if (dmasound.minDev == SND_DEV_AUDIO) {
  827. sound_set_speed(8000);
  828. sound_set_stereo(0);
  829. sound_set_format(AFMT_MU_LAW);
  830. }
  831. #endif
  832. return 0;
  833. out:
  834. module_put(dmasound.mach.owner);
  835. return rc;
  836. }
  837. static void sq_reset_output(void)
  838. {
  839. sound_silence(); /* this _must_ stop DMA, we might be about to lose the buffers */
  840. write_sq.active = 0;
  841. write_sq.count = 0;
  842. write_sq.rear_size = 0;
  843. /* write_sq.front = (write_sq.rear+1) % write_sq.max_count;*/
  844. write_sq.front = 0 ;
  845. write_sq.rear = -1 ; /* same as for set-up */
  846. /* OK - we can unlock the parameters and fragment settings */
  847. write_sq.locked = 0 ;
  848. write_sq.user_frags = 0 ;
  849. write_sq.user_frag_size = 0 ;
  850. }
  851. #ifdef HAS_RECORD
  852. static void sq_reset_input(void)
  853. {
  854. if (dmasound.mach.record && read_sq.active) {
  855. if (dmasound.mach.abort_read) { /* this routine must really be present */
  856. read_sq.syncing = 1 ;
  857. /* this can use the read_sq.sync_queue to sleep if
  858. necessary - it should not return until DMA
  859. is really stopped - because we might deallocate
  860. the buffers as the next action...
  861. */
  862. dmasound.mach.abort_read() ;
  863. } else {
  864. printk(KERN_ERR
  865. "dmasound_core: %s has no abort_read()!! all bets are off\n",
  866. dmasound.mach.name) ;
  867. }
  868. }
  869. read_sq.syncing =
  870. read_sq.active =
  871. read_sq.front =
  872. read_sq.count =
  873. read_sq.rear = 0 ;
  874. /* OK - we can unlock the parameters and fragment settings */
  875. read_sq.locked = 0 ;
  876. read_sq.user_frags = 0 ;
  877. read_sq.user_frag_size = 0 ;
  878. }
  879. #endif
  880. static void sq_reset(void)
  881. {
  882. sq_reset_output() ;
  883. sq_reset_input() ;
  884. /* we could consider resetting the shared_resources_owner here... but I
  885. think it is probably still rather non-obvious to application writer
  886. */
  887. /* we release everything else though */
  888. shared_resources_initialised = 0 ;
  889. }
  890. static int sq_fsync(struct file *filp, struct dentry *dentry)
  891. {
  892. int rc = 0;
  893. int timeout = 5;
  894. write_sq.syncing |= 1;
  895. sq_play(); /* there may be an incomplete frame waiting */
  896. while (write_sq.active) {
  897. SLEEP(write_sq.sync_queue);
  898. if (signal_pending(current)) {
  899. /* While waiting for audio output to drain, an
  900. * interrupt occurred. Stop audio output immediately
  901. * and clear the queue. */
  902. sq_reset_output();
  903. rc = -EINTR;
  904. break;
  905. }
  906. if (!--timeout) {
  907. printk(KERN_WARNING "dmasound: Timeout draining output\n");
  908. sq_reset_output();
  909. rc = -EIO;
  910. break;
  911. }
  912. }
  913. /* flag no sync regardless of whether we had a DSP_POST or not */
  914. write_sq.syncing = 0 ;
  915. return rc;
  916. }
  917. static int sq_release(struct inode *inode, struct file *file)
  918. {
  919. int rc = 0;
  920. lock_kernel();
  921. #ifdef HAS_RECORD
  922. /* probably best to do the read side first - so that time taken to do it
  923. overlaps with playing any remaining output samples.
  924. */
  925. if (file->f_mode & FMODE_READ) {
  926. sq_reset_input() ; /* make sure dma is stopped and all is quiet */
  927. read_sq_release_buffers();
  928. read_sq.busy = 0;
  929. }
  930. #endif
  931. if (file->f_mode & FMODE_WRITE) {
  932. if (write_sq.busy)
  933. rc = sq_fsync(file, file->f_path.dentry);
  934. sq_reset_output() ; /* make sure dma is stopped and all is quiet */
  935. write_sq_release_buffers();
  936. write_sq.busy = 0;
  937. }
  938. if (file->f_mode & shared_resource_owner) { /* it's us that has them */
  939. shared_resource_owner = 0 ;
  940. shared_resources_initialised = 0 ;
  941. dmasound.hard = dmasound.mach.default_hard ;
  942. }
  943. module_put(dmasound.mach.owner);
  944. #if 0 /* blocking open() */
  945. /* Wake up a process waiting for the queue being released.
  946. * Note: There may be several processes waiting for a call
  947. * to open() returning. */
  948. /* Iain: hmm I don't understand this next comment ... */
  949. /* There is probably a DOS atack here. They change the mode flag. */
  950. /* XXX add check here,*/
  951. read_sq_wake_up(file); /* checks f_mode */
  952. write_sq_wake_up(file); /* checks f_mode */
  953. #endif /* blocking open() */
  954. unlock_kernel();
  955. return rc;
  956. }
  957. /* here we see if we have a right to modify format, channels, size and so on
  958. if no-one else has claimed it already then we do...
  959. TODO: We might change this to mask O_RDWR such that only one or the other channel
  960. is the owner - if we have problems.
  961. */
  962. static int shared_resources_are_mine(mode_t md)
  963. {
  964. if (shared_resource_owner)
  965. return (shared_resource_owner & md ) ;
  966. else {
  967. shared_resource_owner = md ;
  968. return 1 ;
  969. }
  970. }
  971. /* if either queue is locked we must deny the right to change shared params
  972. */
  973. static int queues_are_quiescent(void)
  974. {
  975. #ifdef HAS_RECORD
  976. if (dmasound.mach.record)
  977. if (read_sq.locked)
  978. return 0 ;
  979. #endif
  980. if (write_sq.locked)
  981. return 0 ;
  982. return 1 ;
  983. }
  984. /* check and set a queue's fragments per user's wishes...
  985. we will check against the pre-defined literals and the actual sizes.
  986. This is a bit fraught - because soft translations can mess with our
  987. buffer requirements *after* this call - OSS says "call setfrags first"
  988. */
  989. /* It is possible to replace all the -EINVAL returns with an override that
  990. just puts the allowable value in. This may be what many OSS apps require
  991. */
  992. static int set_queue_frags(struct sound_queue *sq, int bufs, int size)
  993. {
  994. if (sq->locked) {
  995. #ifdef DEBUG_DMASOUND
  996. printk("dmasound_core: tried to set_queue_frags on a locked queue\n") ;
  997. #endif
  998. return -EINVAL ;
  999. }
  1000. if ((size < MIN_FRAG_SIZE) || (size > MAX_FRAG_SIZE))
  1001. return -EINVAL ;
  1002. size = (1<<size) ; /* now in bytes */
  1003. if (size > sq->bufSize)
  1004. return -EINVAL ; /* this might still not work */
  1005. if (bufs <= 0)
  1006. return -EINVAL ;
  1007. if (bufs > sq->numBufs) /* the user is allowed say "don't care" with 0x7fff */
  1008. bufs = sq->numBufs ;
  1009. /* there is, currently, no way to specify max_active separately
  1010. from max_count. This could be a LL driver issue - I guess
  1011. if there is a requirement for these values to be different then
  1012. we will have to pass that info. up to this level.
  1013. */
  1014. sq->user_frags =
  1015. sq->max_active = bufs ;
  1016. sq->user_frag_size = size ;
  1017. return 0 ;
  1018. }
  1019. static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
  1020. u_long arg)
  1021. {
  1022. int val, result;
  1023. u_long fmt;
  1024. int data;
  1025. int size, nbufs;
  1026. audio_buf_info info;
  1027. switch (cmd) {
  1028. case SNDCTL_DSP_RESET:
  1029. sq_reset();
  1030. return 0;
  1031. break ;
  1032. case SNDCTL_DSP_GETFMTS:
  1033. fmt = dmasound.mach.hardware_afmts ; /* this is what OSS says.. */
  1034. return IOCTL_OUT(arg, fmt);
  1035. break ;
  1036. case SNDCTL_DSP_GETBLKSIZE:
  1037. /* this should tell the caller about bytes that the app can
  1038. read/write - the app doesn't care about our internal buffers.
  1039. We force sq_setup() here as per OSS 1.1 (which should
  1040. compute the values necessary).
  1041. Since there is no mechanism to specify read/write separately, for
  1042. fds opened O_RDWR, the write_sq values will, arbitrarily, overwrite
  1043. the read_sq ones.
  1044. */
  1045. size = 0 ;
  1046. #ifdef HAS_RECORD
  1047. if (dmasound.mach.record && (file->f_mode & FMODE_READ)) {
  1048. if ( !read_sq.locked )
  1049. sq_setup(&read_sq) ; /* set params */
  1050. size = read_sq.user_frag_size ;
  1051. }
  1052. #endif
  1053. if (file->f_mode & FMODE_WRITE) {
  1054. if ( !write_sq.locked )
  1055. sq_setup(&write_sq) ;
  1056. size = write_sq.user_frag_size ;
  1057. }
  1058. return IOCTL_OUT(arg, size);
  1059. break ;
  1060. case SNDCTL_DSP_POST:
  1061. /* all we are going to do is to tell the LL that any
  1062. partial frags can be queued for output.
  1063. The LL will have to clear this flag when last output
  1064. is queued.
  1065. */
  1066. write_sq.syncing |= 0x2 ;
  1067. sq_play() ;
  1068. return 0 ;
  1069. case SNDCTL_DSP_SYNC:
  1070. /* This call, effectively, has the same behaviour as SNDCTL_DSP_RESET
  1071. except that it waits for output to finish before resetting
  1072. everything - read, however, is killed imediately.
  1073. */
  1074. result = 0 ;
  1075. if ((file->f_mode & FMODE_READ) && dmasound.mach.record)
  1076. sq_reset_input() ;
  1077. if (file->f_mode & FMODE_WRITE) {
  1078. result = sq_fsync(file, file->f_path.dentry);
  1079. sq_reset_output() ;
  1080. }
  1081. /* if we are the shared resource owner then release them */
  1082. if (file->f_mode & shared_resource_owner)
  1083. shared_resources_initialised = 0 ;
  1084. return result ;
  1085. break ;
  1086. case SOUND_PCM_READ_RATE:
  1087. return IOCTL_OUT(arg, dmasound.soft.speed);
  1088. case SNDCTL_DSP_SPEED:
  1089. /* changing this on the fly will have weird effects on the sound.
  1090. Where there are rate conversions implemented in soft form - it
  1091. will cause the _ctx_xxx() functions to be substituted.
  1092. However, there doesn't appear to be any reason to dis-allow it from
  1093. a driver pov.
  1094. */
  1095. if (shared_resources_are_mine(file->f_mode)) {
  1096. IOCTL_IN(arg, data);
  1097. data = sound_set_speed(data) ;
  1098. shared_resources_initialised = 0 ;
  1099. return IOCTL_OUT(arg, data);
  1100. } else
  1101. return -EINVAL ;
  1102. break ;
  1103. /* OSS says these next 4 actions are undefined when the device is
  1104. busy/active - we will just return -EINVAL.
  1105. To be allowed to change one - (a) you have to own the right
  1106. (b) the queue(s) must be quiescent
  1107. */
  1108. case SNDCTL_DSP_STEREO:
  1109. if (shared_resources_are_mine(file->f_mode) &&
  1110. queues_are_quiescent()) {
  1111. IOCTL_IN(arg, data);
  1112. shared_resources_initialised = 0 ;
  1113. return IOCTL_OUT(arg, sound_set_stereo(data));
  1114. } else
  1115. return -EINVAL ;
  1116. break ;
  1117. case SOUND_PCM_WRITE_CHANNELS:
  1118. if (shared_resources_are_mine(file->f_mode) &&
  1119. queues_are_quiescent()) {
  1120. IOCTL_IN(arg, data);
  1121. /* the user might ask for 20 channels, we will return 1 or 2 */
  1122. shared_resources_initialised = 0 ;
  1123. return IOCTL_OUT(arg, sound_set_stereo(data-1)+1);
  1124. } else
  1125. return -EINVAL ;
  1126. break ;
  1127. case SNDCTL_DSP_SETFMT:
  1128. if (shared_resources_are_mine(file->f_mode) &&
  1129. queues_are_quiescent()) {
  1130. int format;
  1131. IOCTL_IN(arg, data);
  1132. shared_resources_initialised = 0 ;
  1133. format = sound_set_format(data);
  1134. result = IOCTL_OUT(arg, format);
  1135. if (result < 0)
  1136. return result;
  1137. if (format != data && data != AFMT_QUERY)
  1138. return -EINVAL;
  1139. return 0;
  1140. } else
  1141. return -EINVAL ;
  1142. case SNDCTL_DSP_SUBDIVIDE:
  1143. return -EINVAL ;
  1144. case SNDCTL_DSP_SETFRAGMENT:
  1145. /* we can do this independently for the two queues - with the
  1146. proviso that for fds opened O_RDWR we cannot separate the
  1147. actions and both queues will be set per the last call.
  1148. NOTE: this does *NOT* actually set the queue up - merely
  1149. registers our intentions.
  1150. */
  1151. IOCTL_IN(arg, data);
  1152. result = 0 ;
  1153. nbufs = (data >> 16) & 0x7fff ; /* 0x7fff is 'use maximum' */
  1154. size = data & 0xffff;
  1155. #ifdef HAS_RECORD
  1156. if ((file->f_mode & FMODE_READ) && dmasound.mach.record) {
  1157. result = set_queue_frags(&read_sq, nbufs, size) ;
  1158. if (result)
  1159. return result ;
  1160. }
  1161. #endif
  1162. if (file->f_mode & FMODE_WRITE) {
  1163. result = set_queue_frags(&write_sq, nbufs, size) ;
  1164. if (result)
  1165. return result ;
  1166. }
  1167. /* NOTE: this return value is irrelevant - OSS specifically says that
  1168. the value is 'random' and that the user _must_ check the actual
  1169. frags values using SNDCTL_DSP_GETBLKSIZE or similar */
  1170. return IOCTL_OUT(arg, data);
  1171. break ;
  1172. case SNDCTL_DSP_GETOSPACE:
  1173. /*
  1174. */
  1175. if (file->f_mode & FMODE_WRITE) {
  1176. if ( !write_sq.locked )
  1177. sq_setup(&write_sq) ;
  1178. info.fragments = write_sq.max_active - write_sq.count;
  1179. info.fragstotal = write_sq.max_active;
  1180. info.fragsize = write_sq.user_frag_size;
  1181. info.bytes = info.fragments * info.fragsize;
  1182. if (copy_to_user((void __user *)arg, &info, sizeof(info)))
  1183. return -EFAULT;
  1184. return 0;
  1185. } else
  1186. return -EINVAL ;
  1187. break ;
  1188. case SNDCTL_DSP_GETCAPS:
  1189. val = dmasound.mach.capabilities & 0xffffff00;
  1190. return IOCTL_OUT(arg,val);
  1191. default:
  1192. return mixer_ioctl(inode, file, cmd, arg);
  1193. }
  1194. return -EINVAL;
  1195. }
  1196. static const struct file_operations sq_fops =
  1197. {
  1198. .owner = THIS_MODULE,
  1199. .llseek = no_llseek,
  1200. .write = sq_write,
  1201. .poll = sq_poll,
  1202. .ioctl = sq_ioctl,
  1203. .open = sq_open,
  1204. .release = sq_release,
  1205. };
  1206. #ifdef HAS_RECORD
  1207. static const struct file_operations sq_fops_record =
  1208. {
  1209. .owner = THIS_MODULE,
  1210. .llseek = no_llseek,
  1211. .write = sq_write,
  1212. .poll = sq_poll,
  1213. .ioctl = sq_ioctl,
  1214. .open = sq_open,
  1215. .release = sq_release,
  1216. .read = sq_read,
  1217. };
  1218. #endif
  1219. static int sq_init(void)
  1220. {
  1221. const struct file_operations *fops = &sq_fops;
  1222. #ifndef MODULE
  1223. int sq_unit;
  1224. #endif
  1225. #ifdef HAS_RECORD
  1226. if (dmasound.mach.record)
  1227. fops = &sq_fops_record;
  1228. #endif
  1229. sq_unit = register_sound_dsp(fops, -1);
  1230. if (sq_unit < 0) {
  1231. printk(KERN_ERR "dmasound_core: couldn't register fops\n") ;
  1232. return sq_unit ;
  1233. }
  1234. write_sq_init_waitqueue();
  1235. read_sq_init_waitqueue();
  1236. /* These parameters will be restored for every clean open()
  1237. * in the case of multiple open()s (e.g. dsp0 & dsp1) they
  1238. * will be set so long as the shared resources have no owner.
  1239. */
  1240. if (shared_resource_owner == 0) {
  1241. dmasound.soft = dmasound.mach.default_soft ;
  1242. dmasound.hard = dmasound.mach.default_hard ;
  1243. dmasound.dsp = dmasound.mach.default_soft ;
  1244. shared_resources_initialised = 0 ;
  1245. }
  1246. return 0 ;
  1247. }
  1248. /*
  1249. * /dev/sndstat
  1250. */
  1251. /* we allow more space for record-enabled because there are extra output lines.
  1252. the number here must include the amount we are prepared to give to the low-level
  1253. driver.
  1254. */
  1255. #ifdef HAS_RECORD
  1256. #define STAT_BUFF_LEN 1024
  1257. #else
  1258. #define STAT_BUFF_LEN 768
  1259. #endif
  1260. /* this is how much space we will allow the low-level driver to use
  1261. in the stat buffer. Currently, 2 * (80 character line + <NL>).
  1262. We do not police this (it is up to the ll driver to be honest).
  1263. */
  1264. #define LOW_LEVEL_STAT_ALLOC 162
  1265. static struct {
  1266. int busy;
  1267. char buf[STAT_BUFF_LEN]; /* state.buf should not overflow! */
  1268. int len, ptr;
  1269. } state;
  1270. /* publish this function for use by low-level code, if required */
  1271. char *get_afmt_string(int afmt)
  1272. {
  1273. switch(afmt) {
  1274. case AFMT_MU_LAW:
  1275. return "mu-law";
  1276. break;
  1277. case AFMT_A_LAW:
  1278. return "A-law";
  1279. break;
  1280. case AFMT_U8:
  1281. return "unsigned 8 bit";
  1282. break;
  1283. case AFMT_S8:
  1284. return "signed 8 bit";
  1285. break;
  1286. case AFMT_S16_BE:
  1287. return "signed 16 bit BE";
  1288. break;
  1289. case AFMT_U16_BE:
  1290. return "unsigned 16 bit BE";
  1291. break;
  1292. case AFMT_S16_LE:
  1293. return "signed 16 bit LE";
  1294. break;
  1295. case AFMT_U16_LE:
  1296. return "unsigned 16 bit LE";
  1297. break;
  1298. case 0:
  1299. return "format not set" ;
  1300. break ;
  1301. default:
  1302. break ;
  1303. }
  1304. return "ERROR: Unsupported AFMT_XXXX code" ;
  1305. }
  1306. static int state_open(struct inode *inode, struct file *file)
  1307. {
  1308. char *buffer = state.buf;
  1309. int len = 0;
  1310. if (state.busy)
  1311. return -EBUSY;
  1312. if (!try_module_get(dmasound.mach.owner))
  1313. return -ENODEV;
  1314. state.ptr = 0;
  1315. state.busy = 1;
  1316. len += sprintf(buffer+len, "%sDMA sound driver rev %03d :\n",
  1317. dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
  1318. ((dmasound.mach.version>>8) & 0x0f));
  1319. len += sprintf(buffer+len,
  1320. "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
  1321. DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
  1322. (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
  1323. /* call the low-level module to fill in any stat info. that it has
  1324. if present. Maximum buffer usage is specified.
  1325. */
  1326. if (dmasound.mach.state_info)
  1327. len += dmasound.mach.state_info(buffer+len,
  1328. (size_t) LOW_LEVEL_STAT_ALLOC) ;
  1329. /* make usage of the state buffer as deterministic as poss.
  1330. exceptional conditions could cause overrun - and this is flagged as
  1331. a kernel error.
  1332. */
  1333. /* formats and settings */
  1334. len += sprintf(buffer+len,"\t\t === Formats & settings ===\n") ;
  1335. len += sprintf(buffer+len,"Parameter %20s%20s\n","soft","hard") ;
  1336. len += sprintf(buffer+len,"Format :%20s%20s\n",
  1337. get_afmt_string(dmasound.soft.format),
  1338. get_afmt_string(dmasound.hard.format));
  1339. len += sprintf(buffer+len,"Samp Rate:%14d s/sec%14d s/sec\n",
  1340. dmasound.soft.speed, dmasound.hard.speed);
  1341. len += sprintf(buffer+len,"Channels :%20s%20s\n",
  1342. dmasound.soft.stereo ? "stereo" : "mono",
  1343. dmasound.hard.stereo ? "stereo" : "mono" );
  1344. /* sound queue status */
  1345. len += sprintf(buffer+len,"\t\t === Sound Queue status ===\n");
  1346. len += sprintf(buffer+len,"Allocated:%8s%6s\n","Buffers","Size") ;
  1347. len += sprintf(buffer+len,"%9s:%8d%6d\n",
  1348. "write", write_sq.numBufs, write_sq.bufSize) ;
  1349. #ifdef HAS_RECORD
  1350. if (dmasound.mach.record)
  1351. len += sprintf(buffer+len,"%9s:%8d%6d\n",
  1352. "read", read_sq.numBufs, read_sq.bufSize) ;
  1353. #endif
  1354. len += sprintf(buffer+len,
  1355. "Current : MaxFrg FragSiz MaxAct Frnt Rear "
  1356. "Cnt RrSize A B S L xruns\n") ;
  1357. len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
  1358. "write", write_sq.max_count, write_sq.block_size,
  1359. write_sq.max_active, write_sq.front, write_sq.rear,
  1360. write_sq.count, write_sq.rear_size, write_sq.active,
  1361. write_sq.busy, write_sq.syncing, write_sq.locked, write_sq.xruns) ;
  1362. #ifdef HAS_RECORD
  1363. if (dmasound.mach.record)
  1364. len += sprintf(buffer+len,"%9s:%7d%8d%7d%5d%5d%4d%7d%2d%2d%2d%2d%7d\n",
  1365. "read", read_sq.max_count, read_sq.block_size,
  1366. read_sq.max_active, read_sq.front, read_sq.rear,
  1367. read_sq.count, read_sq.rear_size, read_sq.active,
  1368. read_sq.busy, read_sq.syncing, read_sq.locked, read_sq.xruns) ;
  1369. #endif
  1370. #ifdef DEBUG_DMASOUND
  1371. printk("dmasound: stat buffer used %d bytes\n", len) ;
  1372. #endif
  1373. if (len >= STAT_BUFF_LEN)
  1374. printk(KERN_ERR "dmasound_core: stat buffer overflowed!\n");
  1375. state.len = len;
  1376. return 0;
  1377. }
  1378. static int state_release(struct inode *inode, struct file *file)
  1379. {
  1380. lock_kernel();
  1381. state.busy = 0;
  1382. module_put(dmasound.mach.owner);
  1383. unlock_kernel();
  1384. return 0;
  1385. }
  1386. static ssize_t state_read(struct file *file, char __user *buf, size_t count,
  1387. loff_t *ppos)
  1388. {
  1389. int n = state.len - state.ptr;
  1390. if (n > count)
  1391. n = count;
  1392. if (n <= 0)
  1393. return 0;
  1394. if (copy_to_user(buf, &state.buf[state.ptr], n))
  1395. return -EFAULT;
  1396. state.ptr += n;
  1397. return n;
  1398. }
  1399. static const struct file_operations state_fops = {
  1400. .owner = THIS_MODULE,
  1401. .llseek = no_llseek,
  1402. .read = state_read,
  1403. .open = state_open,
  1404. .release = state_release,
  1405. };
  1406. static int state_init(void)
  1407. {
  1408. #ifndef MODULE
  1409. int state_unit;
  1410. #endif
  1411. state_unit = register_sound_special(&state_fops, SND_DEV_STATUS);
  1412. if (state_unit < 0)
  1413. return state_unit ;
  1414. state.busy = 0;
  1415. return 0 ;
  1416. }
  1417. /*
  1418. * Config & Setup
  1419. *
  1420. * This function is called by _one_ chipset-specific driver
  1421. */
  1422. int dmasound_init(void)
  1423. {
  1424. int res ;
  1425. #ifdef MODULE
  1426. if (irq_installed)
  1427. return -EBUSY;
  1428. #endif
  1429. /* Set up sound queue, /dev/audio and /dev/dsp. */
  1430. /* Set default settings. */
  1431. if ((res = sq_init()) < 0)
  1432. return res ;
  1433. /* Set up /dev/sndstat. */
  1434. if ((res = state_init()) < 0)
  1435. return res ;
  1436. /* Set up /dev/mixer. */
  1437. mixer_init();
  1438. if (!dmasound.mach.irqinit()) {
  1439. printk(KERN_ERR "DMA sound driver: Interrupt initialization failed\n");
  1440. return -ENODEV;
  1441. }
  1442. #ifdef MODULE
  1443. irq_installed = 1;
  1444. #endif
  1445. printk(KERN_INFO "%s DMA sound driver rev %03d installed\n",
  1446. dmasound.mach.name, (DMASOUND_CORE_REVISION<<4) +
  1447. ((dmasound.mach.version>>8) & 0x0f));
  1448. printk(KERN_INFO
  1449. "Core driver edition %02d.%02d : %s driver edition %02d.%02d\n",
  1450. DMASOUND_CORE_REVISION, DMASOUND_CORE_EDITION, dmasound.mach.name2,
  1451. (dmasound.mach.version >> 8), (dmasound.mach.version & 0xff)) ;
  1452. printk(KERN_INFO "Write will use %4d fragments of %7d bytes as default\n",
  1453. numWriteBufs, writeBufSize) ;
  1454. #ifdef HAS_RECORD
  1455. if (dmasound.mach.record)
  1456. printk(KERN_INFO
  1457. "Read will use %4d fragments of %7d bytes as default\n",
  1458. numReadBufs, readBufSize) ;
  1459. #endif
  1460. return 0;
  1461. }
  1462. #ifdef MODULE
  1463. void dmasound_deinit(void)
  1464. {
  1465. if (irq_installed) {
  1466. sound_silence();
  1467. dmasound.mach.irqcleanup();
  1468. irq_installed = 0;
  1469. }
  1470. write_sq_release_buffers();
  1471. read_sq_release_buffers();
  1472. if (mixer_unit >= 0)
  1473. unregister_sound_mixer(mixer_unit);
  1474. if (state_unit >= 0)
  1475. unregister_sound_special(state_unit);
  1476. if (sq_unit >= 0)
  1477. unregister_sound_dsp(sq_unit);
  1478. }
  1479. #else /* !MODULE */
  1480. static int dmasound_setup(char *str)
  1481. {
  1482. int ints[6], size;
  1483. str = get_options(str, ARRAY_SIZE(ints), ints);
  1484. /* check the bootstrap parameter for "dmasound=" */
  1485. /* FIXME: other than in the most naive of cases there is no sense in these
  1486. * buffers being other than powers of two. This is not checked yet.
  1487. */
  1488. switch (ints[0]) {
  1489. #ifdef HAS_RECORD
  1490. case 5:
  1491. if ((ints[5] < 0) || (ints[5] > MAX_CATCH_RADIUS))
  1492. printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
  1493. else
  1494. catchRadius = ints[5];
  1495. /* fall through */
  1496. case 4:
  1497. if (ints[4] < MIN_BUFFERS)
  1498. printk("dmasound_setup: invalid number of read buffers, using default = %d\n",
  1499. numReadBufs);
  1500. else
  1501. numReadBufs = ints[4];
  1502. /* fall through */
  1503. case 3:
  1504. if ((size = ints[3]) < 256) /* check for small buffer specs */
  1505. size <<= 10 ;
  1506. if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
  1507. printk("dmasound_setup: invalid read buffer size, using default = %d\n", readBufSize);
  1508. else
  1509. readBufSize = size;
  1510. /* fall through */
  1511. #else
  1512. case 3:
  1513. if ((ints[3] < 0) || (ints[3] > MAX_CATCH_RADIUS))
  1514. printk("dmasound_setup: invalid catch radius, using default = %d\n", catchRadius);
  1515. else
  1516. catchRadius = ints[3];
  1517. /* fall through */
  1518. #endif
  1519. case 2:
  1520. if (ints[1] < MIN_BUFFERS)
  1521. printk("dmasound_setup: invalid number of buffers, using default = %d\n", numWriteBufs);
  1522. else
  1523. numWriteBufs = ints[1];
  1524. /* fall through */
  1525. case 1:
  1526. if ((size = ints[2]) < 256) /* check for small buffer specs */
  1527. size <<= 10 ;
  1528. if (size < MIN_BUFSIZE || size > MAX_BUFSIZE)
  1529. printk("dmasound_setup: invalid write buffer size, using default = %d\n", writeBufSize);
  1530. else
  1531. writeBufSize = size;
  1532. case 0:
  1533. break;
  1534. default:
  1535. printk("dmasound_setup: invalid number of arguments\n");
  1536. return 0;
  1537. }
  1538. return 1;
  1539. }
  1540. __setup("dmasound=", dmasound_setup);
  1541. #endif /* !MODULE */
  1542. /*
  1543. * Conversion tables
  1544. */
  1545. #ifdef HAS_8BIT_TABLES
  1546. /* 8 bit mu-law */
  1547. char dmasound_ulaw2dma8[] = {
  1548. -126, -122, -118, -114, -110, -106, -102, -98,
  1549. -94, -90, -86, -82, -78, -74, -70, -66,
  1550. -63, -61, -59, -57, -55, -53, -51, -49,
  1551. -47, -45, -43, -41, -39, -37, -35, -33,
  1552. -31, -30, -29, -28, -27, -26, -25, -24,
  1553. -23, -22, -21, -20, -19, -18, -17, -16,
  1554. -16, -15, -15, -14, -14, -13, -13, -12,
  1555. -12, -11, -11, -10, -10, -9, -9, -8,
  1556. -8, -8, -7, -7, -7, -7, -6, -6,
  1557. -6, -6, -5, -5, -5, -5, -4, -4,
  1558. -4, -4, -4, -4, -3, -3, -3, -3,
  1559. -3, -3, -3, -3, -2, -2, -2, -2,
  1560. -2, -2, -2, -2, -2, -2, -2, -2,
  1561. -1, -1, -1, -1, -1, -1, -1, -1,
  1562. -1, -1, -1, -1, -1, -1, -1, -1,
  1563. -1, -1, -1, -1, -1, -1, -1, 0,
  1564. 125, 121, 117, 113, 109, 105, 101, 97,
  1565. 93, 89, 85, 81, 77, 73, 69, 65,
  1566. 62, 60, 58, 56, 54, 52, 50, 48,
  1567. 46, 44, 42, 40, 38, 36, 34, 32,
  1568. 30, 29, 28, 27, 26, 25, 24, 23,
  1569. 22, 21, 20, 19, 18, 17, 16, 15,
  1570. 15, 14, 14, 13, 13, 12, 12, 11,
  1571. 11, 10, 10, 9, 9, 8, 8, 7,
  1572. 7, 7, 6, 6, 6, 6, 5, 5,
  1573. 5, 5, 4, 4, 4, 4, 3, 3,
  1574. 3, 3, 3, 3, 2, 2, 2, 2,
  1575. 2, 2, 2, 2, 1, 1, 1, 1,
  1576. 1, 1, 1, 1, 1, 1, 1, 1,
  1577. 0, 0, 0, 0, 0, 0, 0, 0,
  1578. 0, 0, 0, 0, 0, 0, 0, 0,
  1579. 0, 0, 0, 0, 0, 0, 0, 0
  1580. };
  1581. /* 8 bit A-law */
  1582. char dmasound_alaw2dma8[] = {
  1583. -22, -21, -24, -23, -18, -17, -20, -19,
  1584. -30, -29, -32, -31, -26, -25, -28, -27,
  1585. -11, -11, -12, -12, -9, -9, -10, -10,
  1586. -15, -15, -16, -16, -13, -13, -14, -14,
  1587. -86, -82, -94, -90, -70, -66, -78, -74,
  1588. -118, -114, -126, -122, -102, -98, -110, -106,
  1589. -43, -41, -47, -45, -35, -33, -39, -37,
  1590. -59, -57, -63, -61, -51, -49, -55, -53,
  1591. -2, -2, -2, -2, -2, -2, -2, -2,
  1592. -2, -2, -2, -2, -2, -2, -2, -2,
  1593. -1, -1, -1, -1, -1, -1, -1, -1,
  1594. -1, -1, -1, -1, -1, -1, -1, -1,
  1595. -6, -6, -6, -6, -5, -5, -5, -5,
  1596. -8, -8, -8, -8, -7, -7, -7, -7,
  1597. -3, -3, -3, -3, -3, -3, -3, -3,
  1598. -4, -4, -4, -4, -4, -4, -4, -4,
  1599. 21, 20, 23, 22, 17, 16, 19, 18,
  1600. 29, 28, 31, 30, 25, 24, 27, 26,
  1601. 10, 10, 11, 11, 8, 8, 9, 9,
  1602. 14, 14, 15, 15, 12, 12, 13, 13,
  1603. 86, 82, 94, 90, 70, 66, 78, 74,
  1604. 118, 114, 126, 122, 102, 98, 110, 106,
  1605. 43, 41, 47, 45, 35, 33, 39, 37,
  1606. 59, 57, 63, 61, 51, 49, 55, 53,
  1607. 1, 1, 1, 1, 1, 1, 1, 1,
  1608. 1, 1, 1, 1, 1, 1, 1, 1,
  1609. 0, 0, 0, 0, 0, 0, 0, 0,
  1610. 0, 0, 0, 0, 0, 0, 0, 0,
  1611. 5, 5, 5, 5, 4, 4, 4, 4,
  1612. 7, 7, 7, 7, 6, 6, 6, 6,
  1613. 2, 2, 2, 2, 2, 2, 2, 2,
  1614. 3, 3, 3, 3, 3, 3, 3, 3
  1615. };
  1616. #endif /* HAS_8BIT_TABLES */
  1617. /*
  1618. * Visible symbols for modules
  1619. */
  1620. EXPORT_SYMBOL(dmasound);
  1621. EXPORT_SYMBOL(dmasound_init);
  1622. #ifdef MODULE
  1623. EXPORT_SYMBOL(dmasound_deinit);
  1624. #endif
  1625. EXPORT_SYMBOL(dmasound_write_sq);
  1626. #ifdef HAS_RECORD
  1627. EXPORT_SYMBOL(dmasound_read_sq);
  1628. #endif
  1629. EXPORT_SYMBOL(dmasound_catchRadius);
  1630. #ifdef HAS_8BIT_TABLES
  1631. EXPORT_SYMBOL(dmasound_ulaw2dma8);
  1632. EXPORT_SYMBOL(dmasound_alaw2dma8);
  1633. #endif
  1634. EXPORT_SYMBOL(get_afmt_string) ;