rawmidi.c 48 KB

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