rawmidi.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  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 (!substream->opened)
  135. return;
  136. if (up) {
  137. tasklet_schedule(&substream->runtime->tasklet);
  138. } else {
  139. tasklet_kill(&substream->runtime->tasklet);
  140. substream->ops->trigger(substream, 0);
  141. }
  142. }
  143. static void snd_rawmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
  144. {
  145. if (!substream->opened)
  146. return;
  147. substream->ops->trigger(substream, up);
  148. if (!up && substream->runtime->event)
  149. tasklet_kill(&substream->runtime->tasklet);
  150. }
  151. int snd_rawmidi_drop_output(struct snd_rawmidi_substream *substream)
  152. {
  153. unsigned long flags;
  154. struct snd_rawmidi_runtime *runtime = substream->runtime;
  155. snd_rawmidi_output_trigger(substream, 0);
  156. runtime->drain = 0;
  157. spin_lock_irqsave(&runtime->lock, flags);
  158. runtime->appl_ptr = runtime->hw_ptr = 0;
  159. runtime->avail = runtime->buffer_size;
  160. spin_unlock_irqrestore(&runtime->lock, flags);
  161. return 0;
  162. }
  163. int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)
  164. {
  165. int err;
  166. long timeout;
  167. struct snd_rawmidi_runtime *runtime = substream->runtime;
  168. err = 0;
  169. runtime->drain = 1;
  170. timeout = wait_event_interruptible_timeout(runtime->sleep,
  171. (runtime->avail >= runtime->buffer_size),
  172. 10*HZ);
  173. if (signal_pending(current))
  174. err = -ERESTARTSYS;
  175. if (runtime->avail < runtime->buffer_size && !timeout) {
  176. snd_printk(KERN_WARNING "rawmidi drain error (avail = %li, buffer_size = %li)\n", (long)runtime->avail, (long)runtime->buffer_size);
  177. err = -EIO;
  178. }
  179. runtime->drain = 0;
  180. if (err != -ERESTARTSYS) {
  181. /* we need wait a while to make sure that Tx FIFOs are empty */
  182. if (substream->ops->drain)
  183. substream->ops->drain(substream);
  184. else
  185. msleep(50);
  186. snd_rawmidi_drop_output(substream);
  187. }
  188. return err;
  189. }
  190. int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream)
  191. {
  192. unsigned long flags;
  193. struct snd_rawmidi_runtime *runtime = substream->runtime;
  194. snd_rawmidi_input_trigger(substream, 0);
  195. runtime->drain = 0;
  196. spin_lock_irqsave(&runtime->lock, flags);
  197. runtime->appl_ptr = runtime->hw_ptr = 0;
  198. runtime->avail = 0;
  199. spin_unlock_irqrestore(&runtime->lock, flags);
  200. return 0;
  201. }
  202. /* look for an available substream for the given stream direction;
  203. * if a specific subdevice is given, try to assign it
  204. */
  205. static int assign_substream(struct snd_rawmidi *rmidi, int subdevice,
  206. int stream, int mode,
  207. struct snd_rawmidi_substream **sub_ret)
  208. {
  209. struct snd_rawmidi_substream *substream;
  210. struct snd_rawmidi_str *s = &rmidi->streams[stream];
  211. static unsigned int info_flags[2] = {
  212. [SNDRV_RAWMIDI_STREAM_OUTPUT] = SNDRV_RAWMIDI_INFO_OUTPUT,
  213. [SNDRV_RAWMIDI_STREAM_INPUT] = SNDRV_RAWMIDI_INFO_INPUT,
  214. };
  215. if (!(rmidi->info_flags & info_flags[stream]))
  216. return -ENXIO;
  217. if (subdevice >= 0 && subdevice >= s->substream_count)
  218. return -ENODEV;
  219. if (s->substream_opened >= s->substream_count)
  220. return -EAGAIN;
  221. list_for_each_entry(substream, &s->substreams, list) {
  222. if (substream->opened) {
  223. if (stream == SNDRV_RAWMIDI_STREAM_INPUT ||
  224. !(mode & SNDRV_RAWMIDI_LFLG_APPEND))
  225. continue;
  226. }
  227. if (subdevice < 0 || subdevice == substream->number) {
  228. *sub_ret = substream;
  229. return 0;
  230. }
  231. }
  232. return -EAGAIN;
  233. }
  234. /* open and do ref-counting for the given substream */
  235. static int open_substream(struct snd_rawmidi *rmidi,
  236. struct snd_rawmidi_substream *substream,
  237. int mode)
  238. {
  239. int err;
  240. if (substream->use_count == 0) {
  241. err = snd_rawmidi_runtime_create(substream);
  242. if (err < 0)
  243. return err;
  244. err = substream->ops->open(substream);
  245. if (err < 0)
  246. return err;
  247. substream->opened = 1;
  248. substream->active_sensing = 0;
  249. if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
  250. substream->append = 1;
  251. }
  252. substream->use_count++;
  253. rmidi->streams[substream->stream].substream_opened++;
  254. return 0;
  255. }
  256. static void close_substream(struct snd_rawmidi *rmidi,
  257. struct snd_rawmidi_substream *substream,
  258. int cleanup);
  259. static int rawmidi_open_priv(struct snd_rawmidi *rmidi, int subdevice, int mode,
  260. struct snd_rawmidi_file *rfile)
  261. {
  262. struct snd_rawmidi_substream *sinput = NULL, *soutput = NULL;
  263. int err;
  264. rfile->input = rfile->output = NULL;
  265. if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
  266. err = assign_substream(rmidi, subdevice,
  267. SNDRV_RAWMIDI_STREAM_INPUT,
  268. mode, &sinput);
  269. if (err < 0)
  270. goto __error;
  271. }
  272. if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
  273. err = assign_substream(rmidi, subdevice,
  274. SNDRV_RAWMIDI_STREAM_OUTPUT,
  275. mode, &soutput);
  276. if (err < 0)
  277. goto __error;
  278. }
  279. if (sinput) {
  280. err = open_substream(rmidi, sinput, mode);
  281. if (err < 0)
  282. goto __error;
  283. }
  284. if (soutput) {
  285. err = open_substream(rmidi, soutput, mode);
  286. if (err < 0) {
  287. if (sinput)
  288. close_substream(rmidi, sinput, 0);
  289. goto __error;
  290. }
  291. }
  292. rfile->rmidi = rmidi;
  293. rfile->input = sinput;
  294. rfile->output = soutput;
  295. return 0;
  296. __error:
  297. if (sinput && sinput->runtime)
  298. snd_rawmidi_runtime_free(sinput);
  299. if (soutput && soutput->runtime)
  300. snd_rawmidi_runtime_free(soutput);
  301. return err;
  302. }
  303. /* called from sound/core/seq/seq_midi.c */
  304. int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
  305. int mode, struct snd_rawmidi_file * rfile)
  306. {
  307. struct snd_rawmidi *rmidi;
  308. int err;
  309. if (snd_BUG_ON(!rfile))
  310. return -EINVAL;
  311. mutex_lock(&register_mutex);
  312. rmidi = snd_rawmidi_search(card, device);
  313. if (rmidi == NULL) {
  314. mutex_unlock(&register_mutex);
  315. return -ENODEV;
  316. }
  317. if (!try_module_get(rmidi->card->module)) {
  318. mutex_unlock(&register_mutex);
  319. return -ENXIO;
  320. }
  321. mutex_unlock(&register_mutex);
  322. mutex_lock(&rmidi->open_mutex);
  323. err = rawmidi_open_priv(rmidi, subdevice, mode, rfile);
  324. mutex_unlock(&rmidi->open_mutex);
  325. if (err < 0)
  326. module_put(rmidi->card->module);
  327. return err;
  328. }
  329. static int snd_rawmidi_open(struct inode *inode, struct file *file)
  330. {
  331. int maj = imajor(inode);
  332. struct snd_card *card;
  333. int subdevice;
  334. unsigned short fflags;
  335. int err;
  336. struct snd_rawmidi *rmidi;
  337. struct snd_rawmidi_file *rawmidi_file = NULL;
  338. wait_queue_t wait;
  339. struct snd_ctl_file *kctl;
  340. if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK))
  341. return -EINVAL; /* invalid combination */
  342. if (maj == snd_major) {
  343. rmidi = snd_lookup_minor_data(iminor(inode),
  344. SNDRV_DEVICE_TYPE_RAWMIDI);
  345. #ifdef CONFIG_SND_OSSEMUL
  346. } else if (maj == SOUND_MAJOR) {
  347. rmidi = snd_lookup_oss_minor_data(iminor(inode),
  348. SNDRV_OSS_DEVICE_TYPE_MIDI);
  349. #endif
  350. } else
  351. return -ENXIO;
  352. if (rmidi == NULL)
  353. return -ENODEV;
  354. if (!try_module_get(rmidi->card->module))
  355. return -ENXIO;
  356. mutex_lock(&rmidi->open_mutex);
  357. card = rmidi->card;
  358. err = snd_card_file_add(card, file);
  359. if (err < 0)
  360. goto __error_card;
  361. fflags = snd_rawmidi_file_flags(file);
  362. if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */
  363. fflags |= SNDRV_RAWMIDI_LFLG_APPEND;
  364. rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL);
  365. if (rawmidi_file == NULL) {
  366. err = -ENOMEM;
  367. goto __error;
  368. }
  369. init_waitqueue_entry(&wait, current);
  370. add_wait_queue(&rmidi->open_wait, &wait);
  371. while (1) {
  372. subdevice = -1;
  373. read_lock(&card->ctl_files_rwlock);
  374. list_for_each_entry(kctl, &card->ctl_files, list) {
  375. if (kctl->pid == current->pid) {
  376. subdevice = kctl->prefer_rawmidi_subdevice;
  377. if (subdevice != -1)
  378. break;
  379. }
  380. }
  381. read_unlock(&card->ctl_files_rwlock);
  382. err = rawmidi_open_priv(rmidi, subdevice, fflags, rawmidi_file);
  383. if (err >= 0)
  384. break;
  385. if (err == -EAGAIN) {
  386. if (file->f_flags & O_NONBLOCK) {
  387. err = -EBUSY;
  388. break;
  389. }
  390. } else
  391. break;
  392. set_current_state(TASK_INTERRUPTIBLE);
  393. mutex_unlock(&rmidi->open_mutex);
  394. schedule();
  395. mutex_lock(&rmidi->open_mutex);
  396. if (signal_pending(current)) {
  397. err = -ERESTARTSYS;
  398. break;
  399. }
  400. }
  401. remove_wait_queue(&rmidi->open_wait, &wait);
  402. if (err < 0) {
  403. kfree(rawmidi_file);
  404. goto __error;
  405. }
  406. #ifdef CONFIG_SND_OSSEMUL
  407. if (rawmidi_file->input && rawmidi_file->input->runtime)
  408. rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR);
  409. if (rawmidi_file->output && rawmidi_file->output->runtime)
  410. rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR);
  411. #endif
  412. file->private_data = rawmidi_file;
  413. mutex_unlock(&rmidi->open_mutex);
  414. return 0;
  415. __error:
  416. snd_card_file_remove(card, file);
  417. __error_card:
  418. mutex_unlock(&rmidi->open_mutex);
  419. module_put(rmidi->card->module);
  420. return err;
  421. }
  422. static void close_substream(struct snd_rawmidi *rmidi,
  423. struct snd_rawmidi_substream *substream,
  424. int cleanup)
  425. {
  426. rmidi->streams[substream->stream].substream_opened--;
  427. if (--substream->use_count)
  428. return;
  429. if (cleanup) {
  430. if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT)
  431. snd_rawmidi_input_trigger(substream, 0);
  432. else {
  433. if (substream->active_sensing) {
  434. unsigned char buf = 0xfe;
  435. /* sending single active sensing message
  436. * to shut the device up
  437. */
  438. snd_rawmidi_kernel_write(substream, &buf, 1);
  439. }
  440. if (snd_rawmidi_drain_output(substream) == -ERESTARTSYS)
  441. snd_rawmidi_output_trigger(substream, 0);
  442. }
  443. }
  444. substream->ops->close(substream);
  445. if (substream->runtime->private_free)
  446. substream->runtime->private_free(substream);
  447. snd_rawmidi_runtime_free(substream);
  448. substream->opened = 0;
  449. substream->append = 0;
  450. }
  451. static void rawmidi_release_priv(struct snd_rawmidi_file *rfile)
  452. {
  453. struct snd_rawmidi *rmidi;
  454. rmidi = rfile->rmidi;
  455. mutex_lock(&rmidi->open_mutex);
  456. if (rfile->input) {
  457. close_substream(rmidi, rfile->input, 1);
  458. rfile->input = NULL;
  459. }
  460. if (rfile->output) {
  461. close_substream(rmidi, rfile->output, 1);
  462. rfile->output = NULL;
  463. }
  464. rfile->rmidi = NULL;
  465. mutex_unlock(&rmidi->open_mutex);
  466. wake_up(&rmidi->open_wait);
  467. }
  468. /* called from sound/core/seq/seq_midi.c */
  469. int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile)
  470. {
  471. struct snd_rawmidi *rmidi;
  472. if (snd_BUG_ON(!rfile))
  473. return -ENXIO;
  474. rmidi = rfile->rmidi;
  475. rawmidi_release_priv(rfile);
  476. module_put(rmidi->card->module);
  477. return 0;
  478. }
  479. static int snd_rawmidi_release(struct inode *inode, struct file *file)
  480. {
  481. struct snd_rawmidi_file *rfile;
  482. struct snd_rawmidi *rmidi;
  483. rfile = file->private_data;
  484. rmidi = rfile->rmidi;
  485. rawmidi_release_priv(rfile);
  486. kfree(rfile);
  487. snd_card_file_remove(rmidi->card, file);
  488. module_put(rmidi->card->module);
  489. return 0;
  490. }
  491. static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
  492. struct snd_rawmidi_info *info)
  493. {
  494. struct snd_rawmidi *rmidi;
  495. if (substream == NULL)
  496. return -ENODEV;
  497. rmidi = substream->rmidi;
  498. memset(info, 0, sizeof(*info));
  499. info->card = rmidi->card->number;
  500. info->device = rmidi->device;
  501. info->subdevice = substream->number;
  502. info->stream = substream->stream;
  503. info->flags = rmidi->info_flags;
  504. strcpy(info->id, rmidi->id);
  505. strcpy(info->name, rmidi->name);
  506. strcpy(info->subname, substream->name);
  507. info->subdevices_count = substream->pstr->substream_count;
  508. info->subdevices_avail = (substream->pstr->substream_count -
  509. substream->pstr->substream_opened);
  510. return 0;
  511. }
  512. static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream,
  513. struct snd_rawmidi_info __user * _info)
  514. {
  515. struct snd_rawmidi_info info;
  516. int err;
  517. if ((err = snd_rawmidi_info(substream, &info)) < 0)
  518. return err;
  519. if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
  520. return -EFAULT;
  521. return 0;
  522. }
  523. int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info)
  524. {
  525. struct snd_rawmidi *rmidi;
  526. struct snd_rawmidi_str *pstr;
  527. struct snd_rawmidi_substream *substream;
  528. mutex_lock(&register_mutex);
  529. rmidi = snd_rawmidi_search(card, info->device);
  530. mutex_unlock(&register_mutex);
  531. if (!rmidi)
  532. return -ENXIO;
  533. if (info->stream < 0 || info->stream > 1)
  534. return -EINVAL;
  535. pstr = &rmidi->streams[info->stream];
  536. if (pstr->substream_count == 0)
  537. return -ENOENT;
  538. if (info->subdevice >= pstr->substream_count)
  539. return -ENXIO;
  540. list_for_each_entry(substream, &pstr->substreams, list) {
  541. if ((unsigned int)substream->number == info->subdevice)
  542. return snd_rawmidi_info(substream, info);
  543. }
  544. return -ENXIO;
  545. }
  546. static int snd_rawmidi_info_select_user(struct snd_card *card,
  547. struct snd_rawmidi_info __user *_info)
  548. {
  549. int err;
  550. struct snd_rawmidi_info info;
  551. if (get_user(info.device, &_info->device))
  552. return -EFAULT;
  553. if (get_user(info.stream, &_info->stream))
  554. return -EFAULT;
  555. if (get_user(info.subdevice, &_info->subdevice))
  556. return -EFAULT;
  557. if ((err = snd_rawmidi_info_select(card, &info)) < 0)
  558. return err;
  559. if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
  560. return -EFAULT;
  561. return 0;
  562. }
  563. int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
  564. struct snd_rawmidi_params * params)
  565. {
  566. char *newbuf;
  567. struct snd_rawmidi_runtime *runtime = substream->runtime;
  568. if (substream->append && substream->use_count > 1)
  569. return -EBUSY;
  570. snd_rawmidi_drain_output(substream);
  571. if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) {
  572. return -EINVAL;
  573. }
  574. if (params->avail_min < 1 || params->avail_min > params->buffer_size) {
  575. return -EINVAL;
  576. }
  577. if (params->buffer_size != runtime->buffer_size) {
  578. newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
  579. if (!newbuf)
  580. return -ENOMEM;
  581. kfree(runtime->buffer);
  582. runtime->buffer = newbuf;
  583. runtime->buffer_size = params->buffer_size;
  584. runtime->avail = runtime->buffer_size;
  585. }
  586. runtime->avail_min = params->avail_min;
  587. substream->active_sensing = !params->no_active_sensing;
  588. return 0;
  589. }
  590. int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
  591. struct snd_rawmidi_params * params)
  592. {
  593. char *newbuf;
  594. struct snd_rawmidi_runtime *runtime = substream->runtime;
  595. snd_rawmidi_drain_input(substream);
  596. if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) {
  597. return -EINVAL;
  598. }
  599. if (params->avail_min < 1 || params->avail_min > params->buffer_size) {
  600. return -EINVAL;
  601. }
  602. if (params->buffer_size != runtime->buffer_size) {
  603. newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
  604. if (!newbuf)
  605. return -ENOMEM;
  606. kfree(runtime->buffer);
  607. runtime->buffer = newbuf;
  608. runtime->buffer_size = params->buffer_size;
  609. }
  610. runtime->avail_min = params->avail_min;
  611. return 0;
  612. }
  613. static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream,
  614. struct snd_rawmidi_status * status)
  615. {
  616. struct snd_rawmidi_runtime *runtime = substream->runtime;
  617. memset(status, 0, sizeof(*status));
  618. status->stream = SNDRV_RAWMIDI_STREAM_OUTPUT;
  619. spin_lock_irq(&runtime->lock);
  620. status->avail = runtime->avail;
  621. spin_unlock_irq(&runtime->lock);
  622. return 0;
  623. }
  624. static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream,
  625. struct snd_rawmidi_status * status)
  626. {
  627. struct snd_rawmidi_runtime *runtime = substream->runtime;
  628. memset(status, 0, sizeof(*status));
  629. status->stream = SNDRV_RAWMIDI_STREAM_INPUT;
  630. spin_lock_irq(&runtime->lock);
  631. status->avail = runtime->avail;
  632. status->xruns = runtime->xruns;
  633. runtime->xruns = 0;
  634. spin_unlock_irq(&runtime->lock);
  635. return 0;
  636. }
  637. static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  638. {
  639. struct snd_rawmidi_file *rfile;
  640. void __user *argp = (void __user *)arg;
  641. rfile = file->private_data;
  642. if (((cmd >> 8) & 0xff) != 'W')
  643. return -ENOTTY;
  644. switch (cmd) {
  645. case SNDRV_RAWMIDI_IOCTL_PVERSION:
  646. return put_user(SNDRV_RAWMIDI_VERSION, (int __user *)argp) ? -EFAULT : 0;
  647. case SNDRV_RAWMIDI_IOCTL_INFO:
  648. {
  649. int stream;
  650. struct snd_rawmidi_info __user *info = argp;
  651. if (get_user(stream, &info->stream))
  652. return -EFAULT;
  653. switch (stream) {
  654. case SNDRV_RAWMIDI_STREAM_INPUT:
  655. return snd_rawmidi_info_user(rfile->input, info);
  656. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  657. return snd_rawmidi_info_user(rfile->output, info);
  658. default:
  659. return -EINVAL;
  660. }
  661. }
  662. case SNDRV_RAWMIDI_IOCTL_PARAMS:
  663. {
  664. struct snd_rawmidi_params params;
  665. if (copy_from_user(&params, argp, sizeof(struct snd_rawmidi_params)))
  666. return -EFAULT;
  667. switch (params.stream) {
  668. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  669. if (rfile->output == NULL)
  670. return -EINVAL;
  671. return snd_rawmidi_output_params(rfile->output, &params);
  672. case SNDRV_RAWMIDI_STREAM_INPUT:
  673. if (rfile->input == NULL)
  674. return -EINVAL;
  675. return snd_rawmidi_input_params(rfile->input, &params);
  676. default:
  677. return -EINVAL;
  678. }
  679. }
  680. case SNDRV_RAWMIDI_IOCTL_STATUS:
  681. {
  682. int err = 0;
  683. struct snd_rawmidi_status status;
  684. if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status)))
  685. return -EFAULT;
  686. switch (status.stream) {
  687. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  688. if (rfile->output == NULL)
  689. return -EINVAL;
  690. err = snd_rawmidi_output_status(rfile->output, &status);
  691. break;
  692. case SNDRV_RAWMIDI_STREAM_INPUT:
  693. if (rfile->input == NULL)
  694. return -EINVAL;
  695. err = snd_rawmidi_input_status(rfile->input, &status);
  696. break;
  697. default:
  698. return -EINVAL;
  699. }
  700. if (err < 0)
  701. return err;
  702. if (copy_to_user(argp, &status, sizeof(struct snd_rawmidi_status)))
  703. return -EFAULT;
  704. return 0;
  705. }
  706. case SNDRV_RAWMIDI_IOCTL_DROP:
  707. {
  708. int val;
  709. if (get_user(val, (int __user *) argp))
  710. return -EFAULT;
  711. switch (val) {
  712. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  713. if (rfile->output == NULL)
  714. return -EINVAL;
  715. return snd_rawmidi_drop_output(rfile->output);
  716. default:
  717. return -EINVAL;
  718. }
  719. }
  720. case SNDRV_RAWMIDI_IOCTL_DRAIN:
  721. {
  722. int val;
  723. if (get_user(val, (int __user *) argp))
  724. return -EFAULT;
  725. switch (val) {
  726. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  727. if (rfile->output == NULL)
  728. return -EINVAL;
  729. return snd_rawmidi_drain_output(rfile->output);
  730. case SNDRV_RAWMIDI_STREAM_INPUT:
  731. if (rfile->input == NULL)
  732. return -EINVAL;
  733. return snd_rawmidi_drain_input(rfile->input);
  734. default:
  735. return -EINVAL;
  736. }
  737. }
  738. #ifdef CONFIG_SND_DEBUG
  739. default:
  740. snd_printk(KERN_WARNING "rawmidi: unknown command = 0x%x\n", cmd);
  741. #endif
  742. }
  743. return -ENOTTY;
  744. }
  745. static int snd_rawmidi_control_ioctl(struct snd_card *card,
  746. struct snd_ctl_file *control,
  747. unsigned int cmd,
  748. unsigned long arg)
  749. {
  750. void __user *argp = (void __user *)arg;
  751. switch (cmd) {
  752. case SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE:
  753. {
  754. int device;
  755. if (get_user(device, (int __user *)argp))
  756. return -EFAULT;
  757. mutex_lock(&register_mutex);
  758. device = device < 0 ? 0 : device + 1;
  759. while (device < SNDRV_RAWMIDI_DEVICES) {
  760. if (snd_rawmidi_search(card, device))
  761. break;
  762. device++;
  763. }
  764. if (device == SNDRV_RAWMIDI_DEVICES)
  765. device = -1;
  766. mutex_unlock(&register_mutex);
  767. if (put_user(device, (int __user *)argp))
  768. return -EFAULT;
  769. return 0;
  770. }
  771. case SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE:
  772. {
  773. int val;
  774. if (get_user(val, (int __user *)argp))
  775. return -EFAULT;
  776. control->prefer_rawmidi_subdevice = val;
  777. return 0;
  778. }
  779. case SNDRV_CTL_IOCTL_RAWMIDI_INFO:
  780. return snd_rawmidi_info_select_user(card, argp);
  781. }
  782. return -ENOIOCTLCMD;
  783. }
  784. /**
  785. * snd_rawmidi_receive - receive the input data from the device
  786. * @substream: the rawmidi substream
  787. * @buffer: the buffer pointer
  788. * @count: the data size to read
  789. *
  790. * Reads the data from the internal buffer.
  791. *
  792. * Returns the size of read data, or a negative error code on failure.
  793. */
  794. int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
  795. const unsigned char *buffer, int count)
  796. {
  797. unsigned long flags;
  798. int result = 0, count1;
  799. struct snd_rawmidi_runtime *runtime = substream->runtime;
  800. if (!substream->opened)
  801. return -EBADFD;
  802. if (runtime->buffer == NULL) {
  803. snd_printd("snd_rawmidi_receive: input is not active!!!\n");
  804. return -EINVAL;
  805. }
  806. spin_lock_irqsave(&runtime->lock, flags);
  807. if (count == 1) { /* special case, faster code */
  808. substream->bytes++;
  809. if (runtime->avail < runtime->buffer_size) {
  810. runtime->buffer[runtime->hw_ptr++] = buffer[0];
  811. runtime->hw_ptr %= runtime->buffer_size;
  812. runtime->avail++;
  813. result++;
  814. } else {
  815. runtime->xruns++;
  816. }
  817. } else {
  818. substream->bytes += count;
  819. count1 = runtime->buffer_size - runtime->hw_ptr;
  820. if (count1 > count)
  821. count1 = count;
  822. if (count1 > (int)(runtime->buffer_size - runtime->avail))
  823. count1 = runtime->buffer_size - runtime->avail;
  824. memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1);
  825. runtime->hw_ptr += count1;
  826. runtime->hw_ptr %= runtime->buffer_size;
  827. runtime->avail += count1;
  828. count -= count1;
  829. result += count1;
  830. if (count > 0) {
  831. buffer += count1;
  832. count1 = count;
  833. if (count1 > (int)(runtime->buffer_size - runtime->avail)) {
  834. count1 = runtime->buffer_size - runtime->avail;
  835. runtime->xruns += count - count1;
  836. }
  837. if (count1 > 0) {
  838. memcpy(runtime->buffer, buffer, count1);
  839. runtime->hw_ptr = count1;
  840. runtime->avail += count1;
  841. result += count1;
  842. }
  843. }
  844. }
  845. if (result > 0) {
  846. if (runtime->event)
  847. tasklet_schedule(&runtime->tasklet);
  848. else if (snd_rawmidi_ready(substream))
  849. wake_up(&runtime->sleep);
  850. }
  851. spin_unlock_irqrestore(&runtime->lock, flags);
  852. return result;
  853. }
  854. static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
  855. unsigned char __user *userbuf,
  856. unsigned char *kernelbuf, long count)
  857. {
  858. unsigned long flags;
  859. long result = 0, count1;
  860. struct snd_rawmidi_runtime *runtime = substream->runtime;
  861. while (count > 0 && runtime->avail) {
  862. count1 = runtime->buffer_size - runtime->appl_ptr;
  863. if (count1 > count)
  864. count1 = count;
  865. spin_lock_irqsave(&runtime->lock, flags);
  866. if (count1 > (int)runtime->avail)
  867. count1 = runtime->avail;
  868. if (kernelbuf)
  869. memcpy(kernelbuf + result, runtime->buffer + runtime->appl_ptr, count1);
  870. if (userbuf) {
  871. spin_unlock_irqrestore(&runtime->lock, flags);
  872. if (copy_to_user(userbuf + result,
  873. runtime->buffer + runtime->appl_ptr, count1)) {
  874. return result > 0 ? result : -EFAULT;
  875. }
  876. spin_lock_irqsave(&runtime->lock, flags);
  877. }
  878. runtime->appl_ptr += count1;
  879. runtime->appl_ptr %= runtime->buffer_size;
  880. runtime->avail -= count1;
  881. spin_unlock_irqrestore(&runtime->lock, flags);
  882. result += count1;
  883. count -= count1;
  884. }
  885. return result;
  886. }
  887. long snd_rawmidi_kernel_read(struct snd_rawmidi_substream *substream,
  888. unsigned char *buf, long count)
  889. {
  890. snd_rawmidi_input_trigger(substream, 1);
  891. return snd_rawmidi_kernel_read1(substream, NULL/*userbuf*/, buf, count);
  892. }
  893. static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t count,
  894. loff_t *offset)
  895. {
  896. long result;
  897. int count1;
  898. struct snd_rawmidi_file *rfile;
  899. struct snd_rawmidi_substream *substream;
  900. struct snd_rawmidi_runtime *runtime;
  901. rfile = file->private_data;
  902. substream = rfile->input;
  903. if (substream == NULL)
  904. return -EIO;
  905. runtime = substream->runtime;
  906. snd_rawmidi_input_trigger(substream, 1);
  907. result = 0;
  908. while (count > 0) {
  909. spin_lock_irq(&runtime->lock);
  910. while (!snd_rawmidi_ready(substream)) {
  911. wait_queue_t wait;
  912. if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
  913. spin_unlock_irq(&runtime->lock);
  914. return result > 0 ? result : -EAGAIN;
  915. }
  916. init_waitqueue_entry(&wait, current);
  917. add_wait_queue(&runtime->sleep, &wait);
  918. set_current_state(TASK_INTERRUPTIBLE);
  919. spin_unlock_irq(&runtime->lock);
  920. schedule();
  921. remove_wait_queue(&runtime->sleep, &wait);
  922. if (signal_pending(current))
  923. return result > 0 ? result : -ERESTARTSYS;
  924. if (!runtime->avail)
  925. return result > 0 ? result : -EIO;
  926. spin_lock_irq(&runtime->lock);
  927. }
  928. spin_unlock_irq(&runtime->lock);
  929. count1 = snd_rawmidi_kernel_read1(substream,
  930. (unsigned char __user *)buf,
  931. NULL/*kernelbuf*/,
  932. count);
  933. if (count1 < 0)
  934. return result > 0 ? result : count1;
  935. result += count1;
  936. buf += count1;
  937. count -= count1;
  938. }
  939. return result;
  940. }
  941. /**
  942. * snd_rawmidi_transmit_empty - check whether the output buffer is empty
  943. * @substream: the rawmidi substream
  944. *
  945. * Returns 1 if the internal output buffer is empty, 0 if not.
  946. */
  947. int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
  948. {
  949. struct snd_rawmidi_runtime *runtime = substream->runtime;
  950. int result;
  951. unsigned long flags;
  952. if (runtime->buffer == NULL) {
  953. snd_printd("snd_rawmidi_transmit_empty: output is not active!!!\n");
  954. return 1;
  955. }
  956. spin_lock_irqsave(&runtime->lock, flags);
  957. result = runtime->avail >= runtime->buffer_size;
  958. spin_unlock_irqrestore(&runtime->lock, flags);
  959. return result;
  960. }
  961. /**
  962. * snd_rawmidi_transmit_peek - copy data from the internal buffer
  963. * @substream: the rawmidi substream
  964. * @buffer: the buffer pointer
  965. * @count: data size to transfer
  966. *
  967. * Copies data from the internal output buffer to the given buffer.
  968. *
  969. * Call this in the interrupt handler when the midi output is ready,
  970. * and call snd_rawmidi_transmit_ack() after the transmission is
  971. * finished.
  972. *
  973. * Returns the size of copied data, or a negative error code on failure.
  974. */
  975. int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
  976. unsigned char *buffer, int count)
  977. {
  978. unsigned long flags;
  979. int result, count1;
  980. struct snd_rawmidi_runtime *runtime = substream->runtime;
  981. if (runtime->buffer == NULL) {
  982. snd_printd("snd_rawmidi_transmit_peek: output is not active!!!\n");
  983. return -EINVAL;
  984. }
  985. result = 0;
  986. spin_lock_irqsave(&runtime->lock, flags);
  987. if (runtime->avail >= runtime->buffer_size) {
  988. /* warning: lowlevel layer MUST trigger down the hardware */
  989. goto __skip;
  990. }
  991. if (count == 1) { /* special case, faster code */
  992. *buffer = runtime->buffer[runtime->hw_ptr];
  993. result++;
  994. } else {
  995. count1 = runtime->buffer_size - runtime->hw_ptr;
  996. if (count1 > count)
  997. count1 = count;
  998. if (count1 > (int)(runtime->buffer_size - runtime->avail))
  999. count1 = runtime->buffer_size - runtime->avail;
  1000. memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1);
  1001. count -= count1;
  1002. result += count1;
  1003. if (count > 0) {
  1004. if (count > (int)(runtime->buffer_size - runtime->avail - count1))
  1005. count = runtime->buffer_size - runtime->avail - count1;
  1006. memcpy(buffer + count1, runtime->buffer, count);
  1007. result += count;
  1008. }
  1009. }
  1010. __skip:
  1011. spin_unlock_irqrestore(&runtime->lock, flags);
  1012. return result;
  1013. }
  1014. /**
  1015. * snd_rawmidi_transmit_ack - acknowledge the transmission
  1016. * @substream: the rawmidi substream
  1017. * @count: the tranferred count
  1018. *
  1019. * Advances the hardware pointer for the internal output buffer with
  1020. * the given size and updates the condition.
  1021. * Call after the transmission is finished.
  1022. *
  1023. * Returns the advanced size if successful, or a negative error code on failure.
  1024. */
  1025. int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
  1026. {
  1027. unsigned long flags;
  1028. struct snd_rawmidi_runtime *runtime = substream->runtime;
  1029. if (runtime->buffer == NULL) {
  1030. snd_printd("snd_rawmidi_transmit_ack: output is not active!!!\n");
  1031. return -EINVAL;
  1032. }
  1033. spin_lock_irqsave(&runtime->lock, flags);
  1034. snd_BUG_ON(runtime->avail + count > runtime->buffer_size);
  1035. runtime->hw_ptr += count;
  1036. runtime->hw_ptr %= runtime->buffer_size;
  1037. runtime->avail += count;
  1038. substream->bytes += count;
  1039. if (count > 0) {
  1040. if (runtime->drain || snd_rawmidi_ready(substream))
  1041. wake_up(&runtime->sleep);
  1042. }
  1043. spin_unlock_irqrestore(&runtime->lock, flags);
  1044. return count;
  1045. }
  1046. /**
  1047. * snd_rawmidi_transmit - copy from the buffer to the device
  1048. * @substream: the rawmidi substream
  1049. * @buffer: the buffer pointer
  1050. * @count: the data size to transfer
  1051. *
  1052. * Copies data from the buffer to the device and advances the pointer.
  1053. *
  1054. * Returns the copied size if successful, or a negative error code on failure.
  1055. */
  1056. int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
  1057. unsigned char *buffer, int count)
  1058. {
  1059. if (!substream->opened)
  1060. return -EBADFD;
  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);