rawmidi.c 48 KB

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