rawmidi.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  1. /*
  2. * Abstract layer for MIDI v1.0 stream
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #include <sound/core.h>
  23. #include <linux/major.h>
  24. #include <linux/init.h>
  25. #include <linux/sched.h>
  26. #include <linux/slab.h>
  27. #include <linux/time.h>
  28. #include <linux/wait.h>
  29. #include <linux/mutex.h>
  30. #include <linux/moduleparam.h>
  31. #include <linux/delay.h>
  32. #include <sound/rawmidi.h>
  33. #include <sound/info.h>
  34. #include <sound/control.h>
  35. #include <sound/minors.h>
  36. #include <sound/initval.h>
  37. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  38. MODULE_DESCRIPTION("Midlevel RawMidi code for ALSA.");
  39. MODULE_LICENSE("GPL");
  40. #ifdef CONFIG_SND_OSSEMUL
  41. static int midi_map[SNDRV_CARDS];
  42. static int amidi_map[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
  43. module_param_array(midi_map, int, NULL, 0444);
  44. MODULE_PARM_DESC(midi_map, "Raw MIDI device number assigned to 1st OSS device.");
  45. module_param_array(amidi_map, int, NULL, 0444);
  46. MODULE_PARM_DESC(amidi_map, "Raw MIDI device number assigned to 2nd OSS device.");
  47. #endif /* CONFIG_SND_OSSEMUL */
  48. static int snd_rawmidi_free(struct snd_rawmidi *rawmidi);
  49. static int snd_rawmidi_dev_free(struct snd_device *device);
  50. static int snd_rawmidi_dev_register(struct snd_device *device);
  51. static int snd_rawmidi_dev_disconnect(struct snd_device *device);
  52. static LIST_HEAD(snd_rawmidi_devices);
  53. static DEFINE_MUTEX(register_mutex);
  54. static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device)
  55. {
  56. struct snd_rawmidi *rawmidi;
  57. list_for_each_entry(rawmidi, &snd_rawmidi_devices, list)
  58. if (rawmidi->card == card && rawmidi->device == device)
  59. return rawmidi;
  60. return NULL;
  61. }
  62. static inline unsigned short snd_rawmidi_file_flags(struct file *file)
  63. {
  64. switch (file->f_mode & (FMODE_READ | FMODE_WRITE)) {
  65. case FMODE_WRITE:
  66. return SNDRV_RAWMIDI_LFLG_OUTPUT;
  67. case FMODE_READ:
  68. return SNDRV_RAWMIDI_LFLG_INPUT;
  69. default:
  70. return SNDRV_RAWMIDI_LFLG_OPEN;
  71. }
  72. }
  73. static inline int snd_rawmidi_ready(struct snd_rawmidi_substream *substream)
  74. {
  75. struct snd_rawmidi_runtime *runtime = substream->runtime;
  76. return runtime->avail >= runtime->avail_min;
  77. }
  78. static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substream,
  79. size_t count)
  80. {
  81. struct snd_rawmidi_runtime *runtime = substream->runtime;
  82. return runtime->avail >= runtime->avail_min &&
  83. (!substream->append || runtime->avail >= count);
  84. }
  85. static void snd_rawmidi_input_event_tasklet(unsigned long data)
  86. {
  87. struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *)data;
  88. substream->runtime->event(substream);
  89. }
  90. static void snd_rawmidi_output_trigger_tasklet(unsigned long data)
  91. {
  92. struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *)data;
  93. substream->ops->trigger(substream, 1);
  94. }
  95. static int snd_rawmidi_runtime_create(struct snd_rawmidi_substream *substream)
  96. {
  97. struct snd_rawmidi_runtime *runtime;
  98. if ((runtime = kzalloc(sizeof(*runtime), GFP_KERNEL)) == NULL)
  99. return -ENOMEM;
  100. spin_lock_init(&runtime->lock);
  101. init_waitqueue_head(&runtime->sleep);
  102. if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT)
  103. tasklet_init(&runtime->tasklet,
  104. snd_rawmidi_input_event_tasklet,
  105. (unsigned long)substream);
  106. else
  107. tasklet_init(&runtime->tasklet,
  108. snd_rawmidi_output_trigger_tasklet,
  109. (unsigned long)substream);
  110. runtime->event = NULL;
  111. runtime->buffer_size = PAGE_SIZE;
  112. runtime->avail_min = 1;
  113. if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT)
  114. runtime->avail = 0;
  115. else
  116. runtime->avail = runtime->buffer_size;
  117. if ((runtime->buffer = kmalloc(runtime->buffer_size, GFP_KERNEL)) == NULL) {
  118. kfree(runtime);
  119. return -ENOMEM;
  120. }
  121. runtime->appl_ptr = runtime->hw_ptr = 0;
  122. substream->runtime = runtime;
  123. return 0;
  124. }
  125. static int snd_rawmidi_runtime_free(struct snd_rawmidi_substream *substream)
  126. {
  127. struct snd_rawmidi_runtime *runtime = substream->runtime;
  128. kfree(runtime->buffer);
  129. kfree(runtime);
  130. substream->runtime = NULL;
  131. return 0;
  132. }
  133. static inline void snd_rawmidi_output_trigger(struct snd_rawmidi_substream *substream,int up)
  134. {
  135. if (up) {
  136. tasklet_hi_schedule(&substream->runtime->tasklet);
  137. } else {
  138. tasklet_kill(&substream->runtime->tasklet);
  139. substream->ops->trigger(substream, 0);
  140. }
  141. }
  142. static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
  143. {
  144. substream->ops->trigger(substream, up);
  145. if (!up && substream->runtime->event)
  146. tasklet_kill(&substream->runtime->tasklet);
  147. }
  148. int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream)
  149. {
  150. unsigned long flags;
  151. struct snd_rawmidi_runtime *runtime = substream->runtime;
  152. snd_rawmidi_output_trigger(substream, 0);
  153. runtime->drain = 0;
  154. spin_lock_irqsave(&runtime->lock, flags);
  155. runtime->appl_ptr = runtime->hw_ptr = 0;
  156. runtime->avail = runtime->buffer_size;
  157. spin_unlock_irqrestore(&runtime->lock, flags);
  158. return 0;
  159. }
  160. int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
  161. {
  162. int err;
  163. long timeout;
  164. struct snd_rawmidi_runtime *runtime = substream->runtime;
  165. err = 0;
  166. runtime->drain = 1;
  167. timeout = wait_event_interruptible_timeout(runtime->sleep,
  168. (runtime->avail >= runtime->buffer_size),
  169. 10*HZ);
  170. if (signal_pending(current))
  171. err = -ERESTARTSYS;
  172. if (runtime->avail < runtime->buffer_size && !timeout) {
  173. snd_printk(KERN_WARNING "rawmidi drain error (avail = %li, buffer_size = %li)\n", (long)runtime->avail, (long)runtime->buffer_size);
  174. err = -EIO;
  175. }
  176. runtime->drain = 0;
  177. if (err != -ERESTARTSYS) {
  178. /* we need wait a while to make sure that Tx FIFOs are empty */
  179. if (substream->ops->drain)
  180. substream->ops->drain(substream);
  181. else
  182. msleep(50);
  183. snd_rawmidi_drop_output(substream);
  184. }
  185. return err;
  186. }
  187. int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream)
  188. {
  189. unsigned long flags;
  190. struct snd_rawmidi_runtime *runtime = substream->runtime;
  191. snd_rawmidi_input_trigger(substream, 0);
  192. runtime->drain = 0;
  193. spin_lock_irqsave(&runtime->lock, flags);
  194. runtime->appl_ptr = runtime->hw_ptr = 0;
  195. runtime->avail = 0;
  196. spin_unlock_irqrestore(&runtime->lock, flags);
  197. return 0;
  198. }
  199. int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
  200. int mode, struct snd_rawmidi_file * rfile)
  201. {
  202. struct snd_rawmidi *rmidi;
  203. struct list_head *list1, *list2;
  204. struct snd_rawmidi_substream *sinput = NULL, *soutput = NULL;
  205. struct snd_rawmidi_runtime *input = NULL, *output = NULL;
  206. int err;
  207. if (rfile)
  208. rfile->input = rfile->output = NULL;
  209. mutex_lock(&register_mutex);
  210. rmidi = snd_rawmidi_search(card, device);
  211. mutex_unlock(&register_mutex);
  212. if (rmidi == NULL) {
  213. err = -ENODEV;
  214. goto __error1;
  215. }
  216. if (!try_module_get(rmidi->card->module)) {
  217. err = -EFAULT;
  218. goto __error1;
  219. }
  220. if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
  221. mutex_lock(&rmidi->open_mutex);
  222. if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
  223. if (!(rmidi->info_flags & SNDRV_RAWMIDI_INFO_INPUT)) {
  224. err = -ENXIO;
  225. goto __error;
  226. }
  227. if (subdevice >= 0 && (unsigned int)subdevice >= rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_count) {
  228. err = -ENODEV;
  229. goto __error;
  230. }
  231. if (rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_opened >=
  232. rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_count) {
  233. err = -EAGAIN;
  234. goto __error;
  235. }
  236. }
  237. if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
  238. if (!(rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT)) {
  239. err = -ENXIO;
  240. goto __error;
  241. }
  242. if (subdevice >= 0 && (unsigned int)subdevice >= rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_count) {
  243. err = -ENODEV;
  244. goto __error;
  245. }
  246. if (rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_opened >=
  247. rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_count) {
  248. err = -EAGAIN;
  249. goto __error;
  250. }
  251. }
  252. list1 = rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams.next;
  253. while (1) {
  254. if (list1 == &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) {
  255. sinput = NULL;
  256. if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
  257. err = -EAGAIN;
  258. goto __error;
  259. }
  260. break;
  261. }
  262. sinput = list_entry(list1, struct snd_rawmidi_substream, list);
  263. if ((mode & SNDRV_RAWMIDI_LFLG_INPUT) && sinput->opened)
  264. goto __nexti;
  265. if (subdevice < 0 || (subdevice >= 0 && subdevice == sinput->number))
  266. break;
  267. __nexti:
  268. list1 = list1->next;
  269. }
  270. list2 = rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams.next;
  271. while (1) {
  272. if (list2 == &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) {
  273. soutput = NULL;
  274. if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
  275. err = -EAGAIN;
  276. goto __error;
  277. }
  278. break;
  279. }
  280. soutput = list_entry(list2, struct snd_rawmidi_substream, list);
  281. if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
  282. if (mode & SNDRV_RAWMIDI_LFLG_APPEND) {
  283. if (soutput->opened && !soutput->append)
  284. goto __nexto;
  285. } else {
  286. if (soutput->opened)
  287. goto __nexto;
  288. }
  289. }
  290. if (subdevice < 0 || (subdevice >= 0 && subdevice == soutput->number))
  291. break;
  292. __nexto:
  293. list2 = list2->next;
  294. }
  295. if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
  296. if ((err = snd_rawmidi_runtime_create(sinput)) < 0)
  297. goto __error;
  298. input = sinput->runtime;
  299. if ((err = sinput->ops->open(sinput)) < 0)
  300. goto __error;
  301. sinput->opened = 1;
  302. rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_opened++;
  303. } else {
  304. sinput = NULL;
  305. }
  306. if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
  307. if (soutput->opened)
  308. goto __skip_output;
  309. if ((err = snd_rawmidi_runtime_create(soutput)) < 0) {
  310. if (mode & SNDRV_RAWMIDI_LFLG_INPUT)
  311. sinput->ops->close(sinput);
  312. goto __error;
  313. }
  314. output = soutput->runtime;
  315. if ((err = soutput->ops->open(soutput)) < 0) {
  316. if (mode & SNDRV_RAWMIDI_LFLG_INPUT)
  317. sinput->ops->close(sinput);
  318. goto __error;
  319. }
  320. __skip_output:
  321. soutput->opened = 1;
  322. if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
  323. soutput->append = 1;
  324. if (soutput->use_count++ == 0)
  325. soutput->active_sensing = 1;
  326. rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_opened++;
  327. } else {
  328. soutput = NULL;
  329. }
  330. if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
  331. mutex_unlock(&rmidi->open_mutex);
  332. if (rfile) {
  333. rfile->rmidi = rmidi;
  334. rfile->input = sinput;
  335. rfile->output = soutput;
  336. }
  337. return 0;
  338. __error:
  339. if (input != NULL)
  340. snd_rawmidi_runtime_free(sinput);
  341. if (output != NULL)
  342. snd_rawmidi_runtime_free(soutput);
  343. module_put(rmidi->card->module);
  344. if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
  345. mutex_unlock(&rmidi->open_mutex);
  346. __error1:
  347. return err;
  348. }
  349. static int snd_rawmidi_open(struct inode *inode, struct file *file)
  350. {
  351. int maj = imajor(inode);
  352. struct snd_card *card;
  353. int subdevice;
  354. unsigned short fflags;
  355. int err;
  356. struct snd_rawmidi *rmidi;
  357. struct snd_rawmidi_file *rawmidi_file;
  358. wait_queue_t wait;
  359. struct snd_ctl_file *kctl;
  360. if (maj == snd_major) {
  361. rmidi = snd_lookup_minor_data(iminor(inode),
  362. SNDRV_DEVICE_TYPE_RAWMIDI);
  363. #ifdef CONFIG_SND_OSSEMUL
  364. } else if (maj == SOUND_MAJOR) {
  365. rmidi = snd_lookup_oss_minor_data(iminor(inode),
  366. SNDRV_OSS_DEVICE_TYPE_MIDI);
  367. #endif
  368. } else
  369. return -ENXIO;
  370. if (rmidi == NULL)
  371. return -ENODEV;
  372. if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK))
  373. return -EINVAL; /* invalid combination */
  374. card = rmidi->card;
  375. err = snd_card_file_add(card, file);
  376. if (err < 0)
  377. return -ENODEV;
  378. fflags = snd_rawmidi_file_flags(file);
  379. if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */
  380. fflags |= SNDRV_RAWMIDI_LFLG_APPEND;
  381. fflags |= SNDRV_RAWMIDI_LFLG_NOOPENLOCK;
  382. rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL);
  383. if (rawmidi_file == NULL) {
  384. snd_card_file_remove(card, file);
  385. return -ENOMEM;
  386. }
  387. init_waitqueue_entry(&wait, current);
  388. add_wait_queue(&rmidi->open_wait, &wait);
  389. mutex_lock(&rmidi->open_mutex);
  390. while (1) {
  391. subdevice = -1;
  392. down_read(&card->controls_rwsem);
  393. list_for_each_entry(kctl, &card->ctl_files, list) {
  394. if (kctl->pid == current->pid) {
  395. subdevice = kctl->prefer_rawmidi_subdevice;
  396. if (subdevice != -1)
  397. break;
  398. }
  399. }
  400. up_read(&card->controls_rwsem);
  401. err = snd_rawmidi_kernel_open(rmidi->card, rmidi->device,
  402. subdevice, fflags, rawmidi_file);
  403. if (err >= 0)
  404. break;
  405. if (err == -EAGAIN) {
  406. if (file->f_flags & O_NONBLOCK) {
  407. err = -EBUSY;
  408. break;
  409. }
  410. } else
  411. break;
  412. set_current_state(TASK_INTERRUPTIBLE);
  413. mutex_unlock(&rmidi->open_mutex);
  414. schedule();
  415. mutex_lock(&rmidi->open_mutex);
  416. if (signal_pending(current)) {
  417. err = -ERESTARTSYS;
  418. break;
  419. }
  420. }
  421. #ifdef CONFIG_SND_OSSEMUL
  422. if (rawmidi_file->input && rawmidi_file->input->runtime)
  423. rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR);
  424. if (rawmidi_file->output && rawmidi_file->output->runtime)
  425. rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR);
  426. #endif
  427. remove_wait_queue(&rmidi->open_wait, &wait);
  428. if (err >= 0) {
  429. file->private_data = rawmidi_file;
  430. } else {
  431. snd_card_file_remove(card, file);
  432. kfree(rawmidi_file);
  433. }
  434. mutex_unlock(&rmidi->open_mutex);
  435. return err;
  436. }
  437. int snd_rawmidi_kernel_release(struct snd_rawmidi_file * rfile)
  438. {
  439. struct snd_rawmidi *rmidi;
  440. struct snd_rawmidi_substream *substream;
  441. struct snd_rawmidi_runtime *runtime;
  442. snd_assert(rfile != NULL, return -ENXIO);
  443. snd_assert(rfile->input != NULL || rfile->output != NULL, return -ENXIO);
  444. rmidi = rfile->rmidi;
  445. mutex_lock(&rmidi->open_mutex);
  446. if (rfile->input != NULL) {
  447. substream = rfile->input;
  448. rfile->input = NULL;
  449. runtime = substream->runtime;
  450. snd_rawmidi_input_trigger(substream, 0);
  451. substream->ops->close(substream);
  452. if (runtime->private_free != NULL)
  453. runtime->private_free(substream);
  454. snd_rawmidi_runtime_free(substream);
  455. substream->opened = 0;
  456. rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_opened--;
  457. }
  458. if (rfile->output != NULL) {
  459. substream = rfile->output;
  460. rfile->output = NULL;
  461. if (--substream->use_count == 0) {
  462. runtime = substream->runtime;
  463. if (substream->active_sensing) {
  464. unsigned char buf = 0xfe;
  465. /* sending single active sensing message to shut the device up */
  466. snd_rawmidi_kernel_write(substream, &buf, 1);
  467. }
  468. if (snd_rawmidi_drain_output(substream) == -ERESTARTSYS)
  469. snd_rawmidi_output_trigger(substream, 0);
  470. substream->ops->close(substream);
  471. if (runtime->private_free != NULL)
  472. runtime->private_free(substream);
  473. snd_rawmidi_runtime_free(substream);
  474. substream->opened = 0;
  475. substream->append = 0;
  476. }
  477. rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_opened--;
  478. }
  479. mutex_unlock(&rmidi->open_mutex);
  480. module_put(rmidi->card->module);
  481. return 0;
  482. }
  483. static int snd_rawmidi_release(struct inode *inode, struct file *file)
  484. {
  485. struct snd_rawmidi_file *rfile;
  486. struct snd_rawmidi *rmidi;
  487. int err;
  488. rfile = file->private_data;
  489. err = snd_rawmidi_kernel_release(rfile);
  490. rmidi = rfile->rmidi;
  491. wake_up(&rmidi->open_wait);
  492. kfree(rfile);
  493. snd_card_file_remove(rmidi->card, file);
  494. return err;
  495. }
  496. static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
  497. struct snd_rawmidi_info *info)
  498. {
  499. struct snd_rawmidi *rmidi;
  500. if (substream == NULL)
  501. return -ENODEV;
  502. rmidi = substream->rmidi;
  503. memset(info, 0, sizeof(*info));
  504. info->card = rmidi->card->number;
  505. info->device = rmidi->device;
  506. info->subdevice = substream->number;
  507. info->stream = substream->stream;
  508. info->flags = rmidi->info_flags;
  509. strcpy(info->id, rmidi->id);
  510. strcpy(info->name, rmidi->name);
  511. strcpy(info->subname, substream->name);
  512. info->subdevices_count = substream->pstr->substream_count;
  513. info->subdevices_avail = (substream->pstr->substream_count -
  514. substream->pstr->substream_opened);
  515. return 0;
  516. }
  517. static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream,
  518. struct snd_rawmidi_info __user * _info)
  519. {
  520. struct snd_rawmidi_info info;
  521. int err;
  522. if ((err = snd_rawmidi_info(substream, &info)) < 0)
  523. return err;
  524. if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
  525. return -EFAULT;
  526. return 0;
  527. }
  528. int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info)
  529. {
  530. struct snd_rawmidi *rmidi;
  531. struct snd_rawmidi_str *pstr;
  532. struct snd_rawmidi_substream *substream;
  533. mutex_lock(&register_mutex);
  534. rmidi = snd_rawmidi_search(card, info->device);
  535. mutex_unlock(&register_mutex);
  536. if (!rmidi)
  537. return -ENXIO;
  538. if (info->stream < 0 || info->stream > 1)
  539. return -EINVAL;
  540. pstr = &rmidi->streams[info->stream];
  541. if (pstr->substream_count == 0)
  542. return -ENOENT;
  543. if (info->subdevice >= pstr->substream_count)
  544. return -ENXIO;
  545. list_for_each_entry(substream, &pstr->substreams, list) {
  546. if ((unsigned int)substream->number == info->subdevice)
  547. return snd_rawmidi_info(substream, info);
  548. }
  549. return -ENXIO;
  550. }
  551. static int snd_rawmidi_info_select_user(struct snd_card *card,
  552. struct snd_rawmidi_info __user *_info)
  553. {
  554. int err;
  555. struct snd_rawmidi_info info;
  556. if (get_user(info.device, &_info->device))
  557. return -EFAULT;
  558. if (get_user(info.stream, &_info->stream))
  559. return -EFAULT;
  560. if (get_user(info.subdevice, &_info->subdevice))
  561. return -EFAULT;
  562. if ((err = snd_rawmidi_info_select(card, &info)) < 0)
  563. return err;
  564. if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
  565. return -EFAULT;
  566. return 0;
  567. }
  568. int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
  569. struct snd_rawmidi_params * params)
  570. {
  571. char *newbuf;
  572. struct snd_rawmidi_runtime *runtime = substream->runtime;
  573. if (substream->append && substream->use_count > 1)
  574. return -EBUSY;
  575. snd_rawmidi_drain_output(substream);
  576. if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) {
  577. return -EINVAL;
  578. }
  579. if (params->avail_min < 1 || params->avail_min > params->buffer_size) {
  580. return -EINVAL;
  581. }
  582. if (params->buffer_size != runtime->buffer_size) {
  583. newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
  584. if (!newbuf)
  585. return -ENOMEM;
  586. kfree(runtime->buffer);
  587. runtime->buffer = newbuf;
  588. runtime->buffer_size = params->buffer_size;
  589. runtime->avail = runtime->buffer_size;
  590. }
  591. runtime->avail_min = params->avail_min;
  592. substream->active_sensing = !params->no_active_sensing;
  593. return 0;
  594. }
  595. int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
  596. struct snd_rawmidi_params * params)
  597. {
  598. char *newbuf;
  599. struct snd_rawmidi_runtime *runtime = substream->runtime;
  600. snd_rawmidi_drain_input(substream);
  601. if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) {
  602. return -EINVAL;
  603. }
  604. if (params->avail_min < 1 || params->avail_min > params->buffer_size) {
  605. return -EINVAL;
  606. }
  607. if (params->buffer_size != runtime->buffer_size) {
  608. newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
  609. if (!newbuf)
  610. return -ENOMEM;
  611. kfree(runtime->buffer);
  612. runtime->buffer = newbuf;
  613. runtime->buffer_size = params->buffer_size;
  614. }
  615. runtime->avail_min = params->avail_min;
  616. return 0;
  617. }
  618. static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream,
  619. struct snd_rawmidi_status * status)
  620. {
  621. struct snd_rawmidi_runtime *runtime = substream->runtime;
  622. memset(status, 0, sizeof(*status));
  623. status->stream = SNDRV_RAWMIDI_STREAM_OUTPUT;
  624. spin_lock_irq(&runtime->lock);
  625. status->avail = runtime->avail;
  626. spin_unlock_irq(&runtime->lock);
  627. return 0;
  628. }
  629. static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream,
  630. struct snd_rawmidi_status * status)
  631. {
  632. struct snd_rawmidi_runtime *runtime = substream->runtime;
  633. memset(status, 0, sizeof(*status));
  634. status->stream = SNDRV_RAWMIDI_STREAM_INPUT;
  635. spin_lock_irq(&runtime->lock);
  636. status->avail = runtime->avail;
  637. status->xruns = runtime->xruns;
  638. runtime->xruns = 0;
  639. spin_unlock_irq(&runtime->lock);
  640. return 0;
  641. }
  642. static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  643. {
  644. struct snd_rawmidi_file *rfile;
  645. void __user *argp = (void __user *)arg;
  646. rfile = file->private_data;
  647. if (((cmd >> 8) & 0xff) != 'W')
  648. return -ENOTTY;
  649. switch (cmd) {
  650. case SNDRV_RAWMIDI_IOCTL_PVERSION:
  651. return put_user(SNDRV_RAWMIDI_VERSION, (int __user *)argp) ? -EFAULT : 0;
  652. case SNDRV_RAWMIDI_IOCTL_INFO:
  653. {
  654. int stream;
  655. struct snd_rawmidi_info __user *info = argp;
  656. if (get_user(stream, &info->stream))
  657. return -EFAULT;
  658. switch (stream) {
  659. case SNDRV_RAWMIDI_STREAM_INPUT:
  660. return snd_rawmidi_info_user(rfile->input, info);
  661. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  662. return snd_rawmidi_info_user(rfile->output, info);
  663. default:
  664. return -EINVAL;
  665. }
  666. }
  667. case SNDRV_RAWMIDI_IOCTL_PARAMS:
  668. {
  669. struct snd_rawmidi_params params;
  670. if (copy_from_user(&params, argp, sizeof(struct snd_rawmidi_params)))
  671. return -EFAULT;
  672. switch (params.stream) {
  673. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  674. if (rfile->output == NULL)
  675. return -EINVAL;
  676. return snd_rawmidi_output_params(rfile->output, &params);
  677. case SNDRV_RAWMIDI_STREAM_INPUT:
  678. if (rfile->input == NULL)
  679. return -EINVAL;
  680. return snd_rawmidi_input_params(rfile->input, &params);
  681. default:
  682. return -EINVAL;
  683. }
  684. }
  685. case SNDRV_RAWMIDI_IOCTL_STATUS:
  686. {
  687. int err = 0;
  688. struct snd_rawmidi_status status;
  689. if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status)))
  690. return -EFAULT;
  691. switch (status.stream) {
  692. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  693. if (rfile->output == NULL)
  694. return -EINVAL;
  695. err = snd_rawmidi_output_status(rfile->output, &status);
  696. break;
  697. case SNDRV_RAWMIDI_STREAM_INPUT:
  698. if (rfile->input == NULL)
  699. return -EINVAL;
  700. err = snd_rawmidi_input_status(rfile->input, &status);
  701. break;
  702. default:
  703. return -EINVAL;
  704. }
  705. if (err < 0)
  706. return err;
  707. if (copy_to_user(argp, &status, sizeof(struct snd_rawmidi_status)))
  708. return -EFAULT;
  709. return 0;
  710. }
  711. case SNDRV_RAWMIDI_IOCTL_DROP:
  712. {
  713. int val;
  714. if (get_user(val, (int __user *) argp))
  715. return -EFAULT;
  716. switch (val) {
  717. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  718. if (rfile->output == NULL)
  719. return -EINVAL;
  720. return snd_rawmidi_drop_output(rfile->output);
  721. default:
  722. return -EINVAL;
  723. }
  724. }
  725. case SNDRV_RAWMIDI_IOCTL_DRAIN:
  726. {
  727. int val;
  728. if (get_user(val, (int __user *) argp))
  729. return -EFAULT;
  730. switch (val) {
  731. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  732. if (rfile->output == NULL)
  733. return -EINVAL;
  734. return snd_rawmidi_drain_output(rfile->output);
  735. case SNDRV_RAWMIDI_STREAM_INPUT:
  736. if (rfile->input == NULL)
  737. return -EINVAL;
  738. return snd_rawmidi_drain_input(rfile->input);
  739. default:
  740. return -EINVAL;
  741. }
  742. }
  743. #ifdef CONFIG_SND_DEBUG
  744. default:
  745. snd_printk(KERN_WARNING "rawmidi: unknown command = 0x%x\n", cmd);
  746. #endif
  747. }
  748. return -ENOTTY;
  749. }
  750. static int snd_rawmidi_control_ioctl(struct snd_card *card,
  751. struct snd_ctl_file *control,
  752. unsigned int cmd,
  753. unsigned long arg)
  754. {
  755. void __user *argp = (void __user *)arg;
  756. switch (cmd) {
  757. case SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE:
  758. {
  759. int device;
  760. if (get_user(device, (int __user *)argp))
  761. return -EFAULT;
  762. mutex_lock(&register_mutex);
  763. device = device < 0 ? 0 : device + 1;
  764. while (device < SNDRV_RAWMIDI_DEVICES) {
  765. if (snd_rawmidi_search(card, device))
  766. break;
  767. device++;
  768. }
  769. if (device == SNDRV_RAWMIDI_DEVICES)
  770. device = -1;
  771. mutex_unlock(&register_mutex);
  772. if (put_user(device, (int __user *)argp))
  773. return -EFAULT;
  774. return 0;
  775. }
  776. case SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE:
  777. {
  778. int val;
  779. if (get_user(val, (int __user *)argp))
  780. return -EFAULT;
  781. control->prefer_rawmidi_subdevice = val;
  782. return 0;
  783. }
  784. case SNDRV_CTL_IOCTL_RAWMIDI_INFO:
  785. return snd_rawmidi_info_select_user(card, argp);
  786. }
  787. return -ENOIOCTLCMD;
  788. }
  789. /**
  790. * snd_rawmidi_receive - receive the input data from the device
  791. * @substream: the rawmidi substream
  792. * @buffer: the buffer pointer
  793. * @count: the data size to read
  794. *
  795. * Reads the data from the internal buffer.
  796. *
  797. * Returns the size of read data, or a negative error code on failure.
  798. */
  799. int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
  800. const unsigned char *buffer, int count)
  801. {
  802. unsigned long flags;
  803. int result = 0, count1;
  804. struct snd_rawmidi_runtime *runtime = substream->runtime;
  805. if (runtime->buffer == NULL) {
  806. snd_printd("snd_rawmidi_receive: input is not active!!!\n");
  807. return -EINVAL;
  808. }
  809. spin_lock_irqsave(&runtime->lock, flags);
  810. if (count == 1) { /* special case, faster code */
  811. substream->bytes++;
  812. if (runtime->avail < runtime->buffer_size) {
  813. runtime->buffer[runtime->hw_ptr++] = buffer[0];
  814. runtime->hw_ptr %= runtime->buffer_size;
  815. runtime->avail++;
  816. result++;
  817. } else {
  818. runtime->xruns++;
  819. }
  820. } else {
  821. substream->bytes += count;
  822. count1 = runtime->buffer_size - runtime->hw_ptr;
  823. if (count1 > count)
  824. count1 = count;
  825. if (count1 > (int)(runtime->buffer_size - runtime->avail))
  826. count1 = runtime->buffer_size - runtime->avail;
  827. memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1);
  828. runtime->hw_ptr += count1;
  829. runtime->hw_ptr %= runtime->buffer_size;
  830. runtime->avail += count1;
  831. count -= count1;
  832. result += count1;
  833. if (count > 0) {
  834. buffer += count1;
  835. count1 = count;
  836. if (count1 > (int)(runtime->buffer_size - runtime->avail)) {
  837. count1 = runtime->buffer_size - runtime->avail;
  838. runtime->xruns += count - count1;
  839. }
  840. if (count1 > 0) {
  841. memcpy(runtime->buffer, buffer, count1);
  842. runtime->hw_ptr = count1;
  843. runtime->avail += count1;
  844. result += count1;
  845. }
  846. }
  847. }
  848. if (result > 0) {
  849. if (runtime->event)
  850. tasklet_hi_schedule(&runtime->tasklet);
  851. else if (snd_rawmidi_ready(substream))
  852. wake_up(&runtime->sleep);
  853. }
  854. spin_unlock_irqrestore(&runtime->lock, flags);
  855. return result;
  856. }
  857. static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
  858. unsigned char *buf, long count, int kernel)
  859. {
  860. unsigned long flags;
  861. long result = 0, count1;
  862. struct snd_rawmidi_runtime *runtime = substream->runtime;
  863. while (count > 0 && runtime->avail) {
  864. count1 = runtime->buffer_size - runtime->appl_ptr;
  865. if (count1 > count)
  866. count1 = count;
  867. spin_lock_irqsave(&runtime->lock, flags);
  868. if (count1 > (int)runtime->avail)
  869. count1 = runtime->avail;
  870. if (kernel) {
  871. memcpy(buf + result, runtime->buffer + runtime->appl_ptr, count1);
  872. } else {
  873. spin_unlock_irqrestore(&runtime->lock, flags);
  874. if (copy_to_user((char __user *)buf + result,
  875. runtime->buffer + runtime->appl_ptr, count1)) {
  876. return result > 0 ? result : -EFAULT;
  877. }
  878. spin_lock_irqsave(&runtime->lock, flags);
  879. }
  880. runtime->appl_ptr += count1;
  881. runtime->appl_ptr %= runtime->buffer_size;
  882. runtime->avail -= count1;
  883. spin_unlock_irqrestore(&runtime->lock, flags);
  884. result += count1;
  885. count -= count1;
  886. }
  887. return result;
  888. }
  889. long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
  890. unsigned char *buf, long count)
  891. {
  892. snd_rawmidi_input_trigger(substream, 1);
  893. return snd_rawmidi_kernel_read1(substream, buf, count, 1);
  894. }
  895. static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count,
  896. loff_t *offset)
  897. {
  898. long result;
  899. int count1;
  900. struct snd_rawmidi_file *rfile;
  901. struct snd_rawmidi_substream *substream;
  902. struct snd_rawmidi_runtime *runtime;
  903. rfile = file->private_data;
  904. substream = rfile->input;
  905. if (substream == NULL)
  906. return -EIO;
  907. runtime = substream->runtime;
  908. snd_rawmidi_input_trigger(substream, 1);
  909. result = 0;
  910. while (count > 0) {
  911. spin_lock_irq(&runtime->lock);
  912. while (!snd_rawmidi_ready(substream)) {
  913. wait_queue_t wait;
  914. if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
  915. spin_unlock_irq(&runtime->lock);
  916. return result > 0 ? result : -EAGAIN;
  917. }
  918. init_waitqueue_entry(&wait, current);
  919. add_wait_queue(&runtime->sleep, &wait);
  920. set_current_state(TASK_INTERRUPTIBLE);
  921. spin_unlock_irq(&runtime->lock);
  922. schedule();
  923. remove_wait_queue(&runtime->sleep, &wait);
  924. if (signal_pending(current))
  925. return result > 0 ? result : -ERESTARTSYS;
  926. if (!runtime->avail)
  927. return result > 0 ? result : -EIO;
  928. spin_lock_irq(&runtime->lock);
  929. }
  930. spin_unlock_irq(&runtime->lock);
  931. count1 = snd_rawmidi_kernel_read1(substream,
  932. (unsigned char __force *)buf,
  933. count, 0);
  934. if (count1 < 0)
  935. return result > 0 ? result : count1;
  936. result += count1;
  937. buf += count1;
  938. count -= count1;
  939. }
  940. return result;
  941. }
  942. /**
  943. * snd_rawmidi_transmit_empty - check whether the output buffer is empty
  944. * @substream: the rawmidi substream
  945. *
  946. * Returns 1 if the internal output buffer is empty, 0 if not.
  947. */
  948. int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
  949. {
  950. struct snd_rawmidi_runtime *runtime = substream->runtime;
  951. int result;
  952. unsigned long flags;
  953. if (runtime->buffer == NULL) {
  954. snd_printd("snd_rawmidi_transmit_empty: output is not active!!!\n");
  955. return 1;
  956. }
  957. spin_lock_irqsave(&runtime->lock, flags);
  958. result = runtime->avail >= runtime->buffer_size;
  959. spin_unlock_irqrestore(&runtime->lock, flags);
  960. return result;
  961. }
  962. /**
  963. * snd_rawmidi_transmit_peek - copy data from the internal buffer
  964. * @substream: the rawmidi substream
  965. * @buffer: the buffer pointer
  966. * @count: data size to transfer
  967. *
  968. * Copies data from the internal output buffer to the given buffer.
  969. *
  970. * Call this in the interrupt handler when the midi output is ready,
  971. * and call snd_rawmidi_transmit_ack() after the transmission is
  972. * finished.
  973. *
  974. * Returns the size of copied data, or a negative error code on failure.
  975. */
  976. int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
  977. unsigned char *buffer, int count)
  978. {
  979. unsigned long flags;
  980. int result, count1;
  981. struct snd_rawmidi_runtime *runtime = substream->runtime;
  982. if (runtime->buffer == NULL) {
  983. snd_printd("snd_rawmidi_transmit_peek: output is not active!!!\n");
  984. return -EINVAL;
  985. }
  986. result = 0;
  987. spin_lock_irqsave(&runtime->lock, flags);
  988. if (runtime->avail >= runtime->buffer_size) {
  989. /* warning: lowlevel layer MUST trigger down the hardware */
  990. goto __skip;
  991. }
  992. if (count == 1) { /* special case, faster code */
  993. *buffer = runtime->buffer[runtime->hw_ptr];
  994. result++;
  995. } else {
  996. count1 = runtime->buffer_size - runtime->hw_ptr;
  997. if (count1 > count)
  998. count1 = count;
  999. if (count1 > (int)(runtime->buffer_size - runtime->avail))
  1000. count1 = runtime->buffer_size - runtime->avail;
  1001. memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1);
  1002. count -= count1;
  1003. result += count1;
  1004. if (count > 0) {
  1005. if (count > (int)(runtime->buffer_size - runtime->avail - count1))
  1006. count = runtime->buffer_size - runtime->avail - count1;
  1007. memcpy(buffer + count1, runtime->buffer, count);
  1008. result += count;
  1009. }
  1010. }
  1011. __skip:
  1012. spin_unlock_irqrestore(&runtime->lock, flags);
  1013. return result;
  1014. }
  1015. /**
  1016. * snd_rawmidi_transmit_ack - acknowledge the transmission
  1017. * @substream: the rawmidi substream
  1018. * @count: the tranferred count
  1019. *
  1020. * Advances the hardware pointer for the internal output buffer with
  1021. * the given size and updates the condition.
  1022. * Call after the transmission is finished.
  1023. *
  1024. * Returns the advanced size if successful, or a negative error code on failure.
  1025. */
  1026. int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
  1027. {
  1028. unsigned long flags;
  1029. struct snd_rawmidi_runtime *runtime = substream->runtime;
  1030. if (runtime->buffer == NULL) {
  1031. snd_printd("snd_rawmidi_transmit_ack: output is not active!!!\n");
  1032. return -EINVAL;
  1033. }
  1034. spin_lock_irqsave(&runtime->lock, flags);
  1035. snd_assert(runtime->avail + count <= runtime->buffer_size, );
  1036. runtime->hw_ptr += count;
  1037. runtime->hw_ptr %= runtime->buffer_size;
  1038. runtime->avail += count;
  1039. substream->bytes += count;
  1040. if (count > 0) {
  1041. if (runtime->drain || snd_rawmidi_ready(substream))
  1042. wake_up(&runtime->sleep);
  1043. }
  1044. spin_unlock_irqrestore(&runtime->lock, flags);
  1045. return count;
  1046. }
  1047. /**
  1048. * snd_rawmidi_transmit - copy from the buffer to the device
  1049. * @substream: the rawmidi substream
  1050. * @buffer: the buffer pointer
  1051. * @count: the data size to transfer
  1052. *
  1053. * Copies data from the buffer to the device and advances the pointer.
  1054. *
  1055. * Returns the copied size if successful, or a negative error code on failure.
  1056. */
  1057. int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
  1058. unsigned char *buffer, int count)
  1059. {
  1060. count = snd_rawmidi_transmit_peek(substream, buffer, count);
  1061. if (count < 0)
  1062. return count;
  1063. return snd_rawmidi_transmit_ack(substream, count);
  1064. }
  1065. static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
  1066. const unsigned char *buf, long count, int kernel)
  1067. {
  1068. unsigned long flags;
  1069. long count1, result;
  1070. struct snd_rawmidi_runtime *runtime = substream->runtime;
  1071. snd_assert(buf != NULL, return -EINVAL);
  1072. snd_assert(runtime->buffer != NULL, return -EINVAL);
  1073. result = 0;
  1074. spin_lock_irqsave(&runtime->lock, flags);
  1075. if (substream->append) {
  1076. if ((long)runtime->avail < count) {
  1077. spin_unlock_irqrestore(&runtime->lock, flags);
  1078. return -EAGAIN;
  1079. }
  1080. }
  1081. while (count > 0 && runtime->avail > 0) {
  1082. count1 = runtime->buffer_size - runtime->appl_ptr;
  1083. if (count1 > count)
  1084. count1 = count;
  1085. if (count1 > (long)runtime->avail)
  1086. count1 = runtime->avail;
  1087. if (kernel) {
  1088. memcpy(runtime->buffer + runtime->appl_ptr, buf, count1);
  1089. } else {
  1090. spin_unlock_irqrestore(&runtime->lock, flags);
  1091. if (copy_from_user(runtime->buffer + runtime->appl_ptr,
  1092. (char __user *)buf, count1)) {
  1093. spin_lock_irqsave(&runtime->lock, flags);
  1094. result = result > 0 ? result : -EFAULT;
  1095. goto __end;
  1096. }
  1097. spin_lock_irqsave(&runtime->lock, flags);
  1098. }
  1099. runtime->appl_ptr += count1;
  1100. runtime->appl_ptr %= runtime->buffer_size;
  1101. runtime->avail -= count1;
  1102. result += count1;
  1103. buf += count1;
  1104. count -= count1;
  1105. }
  1106. __end:
  1107. count1 = runtime->avail < runtime->buffer_size;
  1108. spin_unlock_irqrestore(&runtime->lock, flags);
  1109. if (count1)
  1110. snd_rawmidi_output_trigger(substream, 1);
  1111. return result;
  1112. }
  1113. long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
  1114. const unsigned char *buf, long count)
  1115. {
  1116. return snd_rawmidi_kernel_write1(substream, buf, count, 1);
  1117. }
  1118. static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
  1119. size_t count, loff_t *offset)
  1120. {
  1121. long result, timeout;
  1122. int count1;
  1123. struct snd_rawmidi_file *rfile;
  1124. struct snd_rawmidi_runtime *runtime;
  1125. struct snd_rawmidi_substream *substream;
  1126. rfile = file->private_data;
  1127. substream = rfile->output;
  1128. runtime = substream->runtime;
  1129. /* we cannot put an atomic message to our buffer */
  1130. if (substream->append && count > runtime->buffer_size)
  1131. return -EIO;
  1132. result = 0;
  1133. while (count > 0) {
  1134. spin_lock_irq(&runtime->lock);
  1135. while (!snd_rawmidi_ready_append(substream, count)) {
  1136. wait_queue_t wait;
  1137. if (file->f_flags & O_NONBLOCK) {
  1138. spin_unlock_irq(&runtime->lock);
  1139. return result > 0 ? result : -EAGAIN;
  1140. }
  1141. init_waitqueue_entry(&wait, current);
  1142. add_wait_queue(&runtime->sleep, &wait);
  1143. set_current_state(TASK_INTERRUPTIBLE);
  1144. spin_unlock_irq(&runtime->lock);
  1145. timeout = schedule_timeout(30 * HZ);
  1146. remove_wait_queue(&runtime->sleep, &wait);
  1147. if (signal_pending(current))
  1148. return result > 0 ? result : -ERESTARTSYS;
  1149. if (!runtime->avail && !timeout)
  1150. return result > 0 ? result : -EIO;
  1151. spin_lock_irq(&runtime->lock);
  1152. }
  1153. spin_unlock_irq(&runtime->lock);
  1154. count1 = snd_rawmidi_kernel_write1(substream,
  1155. (unsigned char __force *)buf,
  1156. count, 0);
  1157. if (count1 < 0)
  1158. return result > 0 ? result : count1;
  1159. result += count1;
  1160. buf += count1;
  1161. if ((size_t)count1 < count && (file->f_flags & O_NONBLOCK))
  1162. break;
  1163. count -= count1;
  1164. }
  1165. if (file->f_flags & O_SYNC) {
  1166. spin_lock_irq(&runtime->lock);
  1167. while (runtime->avail != runtime->buffer_size) {
  1168. wait_queue_t wait;
  1169. unsigned int last_avail = runtime->avail;
  1170. init_waitqueue_entry(&wait, current);
  1171. add_wait_queue(&runtime->sleep, &wait);
  1172. set_current_state(TASK_INTERRUPTIBLE);
  1173. spin_unlock_irq(&runtime->lock);
  1174. timeout = schedule_timeout(30 * HZ);
  1175. remove_wait_queue(&runtime->sleep, &wait);
  1176. if (signal_pending(current))
  1177. return result > 0 ? result : -ERESTARTSYS;
  1178. if (runtime->avail == last_avail && !timeout)
  1179. return result > 0 ? result : -EIO;
  1180. spin_lock_irq(&runtime->lock);
  1181. }
  1182. spin_unlock_irq(&runtime->lock);
  1183. }
  1184. return result;
  1185. }
  1186. static unsigned int snd_rawmidi_poll(struct file *file, poll_table * wait)
  1187. {
  1188. struct snd_rawmidi_file *rfile;
  1189. struct snd_rawmidi_runtime *runtime;
  1190. unsigned int mask;
  1191. rfile = file->private_data;
  1192. if (rfile->input != NULL) {
  1193. runtime = rfile->input->runtime;
  1194. snd_rawmidi_input_trigger(rfile->input, 1);
  1195. poll_wait(file, &runtime->sleep, wait);
  1196. }
  1197. if (rfile->output != NULL) {
  1198. runtime = rfile->output->runtime;
  1199. poll_wait(file, &runtime->sleep, wait);
  1200. }
  1201. mask = 0;
  1202. if (rfile->input != NULL) {
  1203. if (snd_rawmidi_ready(rfile->input))
  1204. mask |= POLLIN | POLLRDNORM;
  1205. }
  1206. if (rfile->output != NULL) {
  1207. if (snd_rawmidi_ready(rfile->output))
  1208. mask |= POLLOUT | POLLWRNORM;
  1209. }
  1210. return mask;
  1211. }
  1212. /*
  1213. */
  1214. #ifdef CONFIG_COMPAT
  1215. #include "rawmidi_compat.c"
  1216. #else
  1217. #define snd_rawmidi_ioctl_compat NULL
  1218. #endif
  1219. /*
  1220. */
  1221. static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
  1222. struct snd_info_buffer *buffer)
  1223. {
  1224. struct snd_rawmidi *rmidi;
  1225. struct snd_rawmidi_substream *substream;
  1226. struct snd_rawmidi_runtime *runtime;
  1227. rmidi = entry->private_data;
  1228. snd_iprintf(buffer, "%s\n\n", rmidi->name);
  1229. mutex_lock(&rmidi->open_mutex);
  1230. if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT) {
  1231. list_for_each_entry(substream,
  1232. &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams,
  1233. list) {
  1234. snd_iprintf(buffer,
  1235. "Output %d\n"
  1236. " Tx bytes : %lu\n",
  1237. substream->number,
  1238. (unsigned long) substream->bytes);
  1239. if (substream->opened) {
  1240. runtime = substream->runtime;
  1241. snd_iprintf(buffer,
  1242. " Mode : %s\n"
  1243. " Buffer size : %lu\n"
  1244. " Avail : %lu\n",
  1245. runtime->oss ? "OSS compatible" : "native",
  1246. (unsigned long) runtime->buffer_size,
  1247. (unsigned long) runtime->avail);
  1248. }
  1249. }
  1250. }
  1251. if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_INPUT) {
  1252. list_for_each_entry(substream,
  1253. &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams,
  1254. list) {
  1255. snd_iprintf(buffer,
  1256. "Input %d\n"
  1257. " Rx bytes : %lu\n",
  1258. substream->number,
  1259. (unsigned long) substream->bytes);
  1260. if (substream->opened) {
  1261. runtime = substream->runtime;
  1262. snd_iprintf(buffer,
  1263. " Buffer size : %lu\n"
  1264. " Avail : %lu\n"
  1265. " Overruns : %lu\n",
  1266. (unsigned long) runtime->buffer_size,
  1267. (unsigned long) runtime->avail,
  1268. (unsigned long) runtime->xruns);
  1269. }
  1270. }
  1271. }
  1272. mutex_unlock(&rmidi->open_mutex);
  1273. }
  1274. /*
  1275. * Register functions
  1276. */
  1277. static const struct file_operations snd_rawmidi_f_ops =
  1278. {
  1279. .owner = THIS_MODULE,
  1280. .read = snd_rawmidi_read,
  1281. .write = snd_rawmidi_write,
  1282. .open = snd_rawmidi_open,
  1283. .release = snd_rawmidi_release,
  1284. .poll = snd_rawmidi_poll,
  1285. .unlocked_ioctl = snd_rawmidi_ioctl,
  1286. .compat_ioctl = snd_rawmidi_ioctl_compat,
  1287. };
  1288. static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
  1289. struct snd_rawmidi_str *stream,
  1290. int direction,
  1291. int count)
  1292. {
  1293. struct snd_rawmidi_substream *substream;
  1294. int idx;
  1295. for (idx = 0; idx < count; idx++) {
  1296. substream = kzalloc(sizeof(*substream), GFP_KERNEL);
  1297. if (substream == NULL) {
  1298. snd_printk(KERN_ERR "rawmidi: cannot allocate substream\n");
  1299. return -ENOMEM;
  1300. }
  1301. substream->stream = direction;
  1302. substream->number = idx;
  1303. substream->rmidi = rmidi;
  1304. substream->pstr = stream;
  1305. list_add_tail(&substream->list, &stream->substreams);
  1306. stream->substream_count++;
  1307. }
  1308. return 0;
  1309. }
  1310. /**
  1311. * snd_rawmidi_new - create a rawmidi instance
  1312. * @card: the card instance
  1313. * @id: the id string
  1314. * @device: the device index
  1315. * @output_count: the number of output streams
  1316. * @input_count: the number of input streams
  1317. * @rrawmidi: the pointer to store the new rawmidi instance
  1318. *
  1319. * Creates a new rawmidi instance.
  1320. * Use snd_rawmidi_set_ops() to set the operators to the new instance.
  1321. *
  1322. * Returns zero if successful, or a negative error code on failure.
  1323. */
  1324. int snd_rawmidi_new(struct snd_card *card, char *id, int device,
  1325. int output_count, int input_count,
  1326. struct snd_rawmidi ** rrawmidi)
  1327. {
  1328. struct snd_rawmidi *rmidi;
  1329. int err;
  1330. static struct snd_device_ops ops = {
  1331. .dev_free = snd_rawmidi_dev_free,
  1332. .dev_register = snd_rawmidi_dev_register,
  1333. .dev_disconnect = snd_rawmidi_dev_disconnect,
  1334. };
  1335. snd_assert(rrawmidi != NULL, return -EINVAL);
  1336. *rrawmidi = NULL;
  1337. snd_assert(card != NULL, return -ENXIO);
  1338. rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL);
  1339. if (rmidi == NULL) {
  1340. snd_printk(KERN_ERR "rawmidi: cannot allocate\n");
  1341. return -ENOMEM;
  1342. }
  1343. rmidi->card = card;
  1344. rmidi->device = device;
  1345. mutex_init(&rmidi->open_mutex);
  1346. init_waitqueue_head(&rmidi->open_wait);
  1347. INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
  1348. INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
  1349. if (id != NULL)
  1350. strlcpy(rmidi->id, id, sizeof(rmidi->id));
  1351. if ((err = snd_rawmidi_alloc_substreams(rmidi,
  1352. &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT],
  1353. SNDRV_RAWMIDI_STREAM_INPUT,
  1354. input_count)) < 0) {
  1355. snd_rawmidi_free(rmidi);
  1356. return err;
  1357. }
  1358. if ((err = snd_rawmidi_alloc_substreams(rmidi,
  1359. &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT],
  1360. SNDRV_RAWMIDI_STREAM_OUTPUT,
  1361. output_count)) < 0) {
  1362. snd_rawmidi_free(rmidi);
  1363. return err;
  1364. }
  1365. if ((err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops)) < 0) {
  1366. snd_rawmidi_free(rmidi);
  1367. return err;
  1368. }
  1369. *rrawmidi = rmidi;
  1370. return 0;
  1371. }
  1372. static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
  1373. {
  1374. struct snd_rawmidi_substream *substream;
  1375. while (!list_empty(&stream->substreams)) {
  1376. substream = list_entry(stream->substreams.next, struct snd_rawmidi_substream, list);
  1377. list_del(&substream->list);
  1378. kfree(substream);
  1379. }
  1380. }
  1381. static int snd_rawmidi_free(struct snd_rawmidi *rmidi)
  1382. {
  1383. snd_assert(rmidi != NULL, return -ENXIO);
  1384. snd_info_free_entry(rmidi->proc_entry);
  1385. rmidi->proc_entry = NULL;
  1386. mutex_lock(&register_mutex);
  1387. if (rmidi->ops && rmidi->ops->dev_unregister)
  1388. rmidi->ops->dev_unregister(rmidi);
  1389. mutex_unlock(&register_mutex);
  1390. snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]);
  1391. snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]);
  1392. if (rmidi->private_free)
  1393. rmidi->private_free(rmidi);
  1394. kfree(rmidi);
  1395. return 0;
  1396. }
  1397. static int snd_rawmidi_dev_free(struct snd_device *device)
  1398. {
  1399. struct snd_rawmidi *rmidi = device->device_data;
  1400. return snd_rawmidi_free(rmidi);
  1401. }
  1402. #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
  1403. static void snd_rawmidi_dev_seq_free(struct snd_seq_device *device)
  1404. {
  1405. struct snd_rawmidi *rmidi = device->private_data;
  1406. rmidi->seq_dev = NULL;
  1407. }
  1408. #endif
  1409. static int snd_rawmidi_dev_register(struct snd_device *device)
  1410. {
  1411. int err;
  1412. struct snd_info_entry *entry;
  1413. char name[16];
  1414. struct snd_rawmidi *rmidi = device->device_data;
  1415. if (rmidi->device >= SNDRV_RAWMIDI_DEVICES)
  1416. return -ENOMEM;
  1417. mutex_lock(&register_mutex);
  1418. if (snd_rawmidi_search(rmidi->card, rmidi->device)) {
  1419. mutex_unlock(&register_mutex);
  1420. return -EBUSY;
  1421. }
  1422. list_add_tail(&rmidi->list, &snd_rawmidi_devices);
  1423. sprintf(name, "midiC%iD%i", rmidi->card->number, rmidi->device);
  1424. if ((err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI,
  1425. rmidi->card, rmidi->device,
  1426. &snd_rawmidi_f_ops, rmidi, name)) < 0) {
  1427. snd_printk(KERN_ERR "unable to register rawmidi device %i:%i\n", rmidi->card->number, rmidi->device);
  1428. list_del(&rmidi->list);
  1429. mutex_unlock(&register_mutex);
  1430. return err;
  1431. }
  1432. if (rmidi->ops && rmidi->ops->dev_register &&
  1433. (err = rmidi->ops->dev_register(rmidi)) < 0) {
  1434. snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
  1435. list_del(&rmidi->list);
  1436. mutex_unlock(&register_mutex);
  1437. return err;
  1438. }
  1439. #ifdef CONFIG_SND_OSSEMUL
  1440. rmidi->ossreg = 0;
  1441. if ((int)rmidi->device == midi_map[rmidi->card->number]) {
  1442. if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI,
  1443. rmidi->card, 0, &snd_rawmidi_f_ops,
  1444. rmidi, name) < 0) {
  1445. snd_printk(KERN_ERR "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 0);
  1446. } else {
  1447. rmidi->ossreg++;
  1448. #ifdef SNDRV_OSS_INFO_DEV_MIDI
  1449. snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIDI, rmidi->card->number, rmidi->name);
  1450. #endif
  1451. }
  1452. }
  1453. if ((int)rmidi->device == amidi_map[rmidi->card->number]) {
  1454. if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI,
  1455. rmidi->card, 1, &snd_rawmidi_f_ops,
  1456. rmidi, name) < 0) {
  1457. snd_printk(KERN_ERR "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 1);
  1458. } else {
  1459. rmidi->ossreg++;
  1460. }
  1461. }
  1462. #endif /* CONFIG_SND_OSSEMUL */
  1463. mutex_unlock(&register_mutex);
  1464. sprintf(name, "midi%d", rmidi->device);
  1465. entry = snd_info_create_card_entry(rmidi->card, name, rmidi->card->proc_root);
  1466. if (entry) {
  1467. entry->private_data = rmidi;
  1468. entry->c.text.read = snd_rawmidi_proc_info_read;
  1469. if (snd_info_register(entry) < 0) {
  1470. snd_info_free_entry(entry);
  1471. entry = NULL;
  1472. }
  1473. }
  1474. rmidi->proc_entry = entry;
  1475. #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
  1476. if (!rmidi->ops || !rmidi->ops->dev_register) { /* own registration mechanism */
  1477. if (snd_seq_device_new(rmidi->card, rmidi->device, SNDRV_SEQ_DEV_ID_MIDISYNTH, 0, &rmidi->seq_dev) >= 0) {
  1478. rmidi->seq_dev->private_data = rmidi;
  1479. rmidi->seq_dev->private_free = snd_rawmidi_dev_seq_free;
  1480. sprintf(rmidi->seq_dev->name, "MIDI %d-%d", rmidi->card->number, rmidi->device);
  1481. snd_device_register(rmidi->card, rmidi->seq_dev);
  1482. }
  1483. }
  1484. #endif
  1485. return 0;
  1486. }
  1487. static int snd_rawmidi_dev_disconnect(struct snd_device *device)
  1488. {
  1489. struct snd_rawmidi *rmidi = device->device_data;
  1490. mutex_lock(&register_mutex);
  1491. list_del_init(&rmidi->list);
  1492. #ifdef CONFIG_SND_OSSEMUL
  1493. if (rmidi->ossreg) {
  1494. if ((int)rmidi->device == midi_map[rmidi->card->number]) {
  1495. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 0);
  1496. #ifdef SNDRV_OSS_INFO_DEV_MIDI
  1497. snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIDI, rmidi->card->number);
  1498. #endif
  1499. }
  1500. if ((int)rmidi->device == amidi_map[rmidi->card->number])
  1501. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 1);
  1502. rmidi->ossreg = 0;
  1503. }
  1504. #endif /* CONFIG_SND_OSSEMUL */
  1505. snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
  1506. mutex_unlock(&register_mutex);
  1507. return 0;
  1508. }
  1509. /**
  1510. * snd_rawmidi_set_ops - set the rawmidi operators
  1511. * @rmidi: the rawmidi instance
  1512. * @stream: the stream direction, SNDRV_RAWMIDI_STREAM_XXX
  1513. * @ops: the operator table
  1514. *
  1515. * Sets the rawmidi operators for the given stream direction.
  1516. */
  1517. void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
  1518. struct snd_rawmidi_ops *ops)
  1519. {
  1520. struct snd_rawmidi_substream *substream;
  1521. list_for_each_entry(substream, &rmidi->streams[stream].substreams, list)
  1522. substream->ops = ops;
  1523. }
  1524. /*
  1525. * ENTRY functions
  1526. */
  1527. static int __init alsa_rawmidi_init(void)
  1528. {
  1529. snd_ctl_register_ioctl(snd_rawmidi_control_ioctl);
  1530. snd_ctl_register_ioctl_compat(snd_rawmidi_control_ioctl);
  1531. #ifdef CONFIG_SND_OSSEMUL
  1532. { int i;
  1533. /* check device map table */
  1534. for (i = 0; i < SNDRV_CARDS; i++) {
  1535. if (midi_map[i] < 0 || midi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
  1536. snd_printk(KERN_ERR "invalid midi_map[%d] = %d\n", i, midi_map[i]);
  1537. midi_map[i] = 0;
  1538. }
  1539. if (amidi_map[i] < 0 || amidi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
  1540. snd_printk(KERN_ERR "invalid amidi_map[%d] = %d\n", i, amidi_map[i]);
  1541. amidi_map[i] = 1;
  1542. }
  1543. }
  1544. }
  1545. #endif /* CONFIG_SND_OSSEMUL */
  1546. return 0;
  1547. }
  1548. static void __exit alsa_rawmidi_exit(void)
  1549. {
  1550. snd_ctl_unregister_ioctl(snd_rawmidi_control_ioctl);
  1551. snd_ctl_unregister_ioctl_compat(snd_rawmidi_control_ioctl);
  1552. }
  1553. module_init(alsa_rawmidi_init)
  1554. module_exit(alsa_rawmidi_exit)
  1555. EXPORT_SYMBOL(snd_rawmidi_output_params);
  1556. EXPORT_SYMBOL(snd_rawmidi_input_params);
  1557. EXPORT_SYMBOL(snd_rawmidi_drop_output);
  1558. EXPORT_SYMBOL(snd_rawmidi_drain_output);
  1559. EXPORT_SYMBOL(snd_rawmidi_drain_input);
  1560. EXPORT_SYMBOL(snd_rawmidi_receive);
  1561. EXPORT_SYMBOL(snd_rawmidi_transmit_empty);
  1562. EXPORT_SYMBOL(snd_rawmidi_transmit_peek);
  1563. EXPORT_SYMBOL(snd_rawmidi_transmit_ack);
  1564. EXPORT_SYMBOL(snd_rawmidi_transmit);
  1565. EXPORT_SYMBOL(snd_rawmidi_new);
  1566. EXPORT_SYMBOL(snd_rawmidi_set_ops);
  1567. EXPORT_SYMBOL(snd_rawmidi_info_select);
  1568. EXPORT_SYMBOL(snd_rawmidi_kernel_open);
  1569. EXPORT_SYMBOL(snd_rawmidi_kernel_release);
  1570. EXPORT_SYMBOL(snd_rawmidi_kernel_read);
  1571. EXPORT_SYMBOL(snd_rawmidi_kernel_write);