rawmidi.c 48 KB

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