rawmidi.c 48 KB

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