rawmidi.c 48 KB

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