rawmidi.c 48 KB

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