rawmidi.c 48 KB

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