rawmidi.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  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. rfile = file->private_data;
  485. rmidi = rfile->rmidi;
  486. rawmidi_release_priv(rfile);
  487. kfree(rfile);
  488. snd_card_file_remove(rmidi->card, file);
  489. module_put(rmidi->card->module);
  490. return 0;
  491. }
  492. static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
  493. struct snd_rawmidi_info *info)
  494. {
  495. struct snd_rawmidi *rmidi;
  496. if (substream == NULL)
  497. return -ENODEV;
  498. rmidi = substream->rmidi;
  499. memset(info, 0, sizeof(*info));
  500. info->card = rmidi->card->number;
  501. info->device = rmidi->device;
  502. info->subdevice = substream->number;
  503. info->stream = substream->stream;
  504. info->flags = rmidi->info_flags;
  505. strcpy(info->id, rmidi->id);
  506. strcpy(info->name, rmidi->name);
  507. strcpy(info->subname, substream->name);
  508. info->subdevices_count = substream->pstr->substream_count;
  509. info->subdevices_avail = (substream->pstr->substream_count -
  510. substream->pstr->substream_opened);
  511. return 0;
  512. }
  513. static int snd_rawmidi_info_user(struct snd_rawmidi_substream *substream,
  514. struct snd_rawmidi_info __user * _info)
  515. {
  516. struct snd_rawmidi_info info;
  517. int err;
  518. if ((err = snd_rawmidi_info(substream, &info)) < 0)
  519. return err;
  520. if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
  521. return -EFAULT;
  522. return 0;
  523. }
  524. int snd_rawmidi_info_select(struct snd_card *card, struct snd_rawmidi_info *info)
  525. {
  526. struct snd_rawmidi *rmidi;
  527. struct snd_rawmidi_str *pstr;
  528. struct snd_rawmidi_substream *substream;
  529. mutex_lock(&register_mutex);
  530. rmidi = snd_rawmidi_search(card, info->device);
  531. mutex_unlock(&register_mutex);
  532. if (!rmidi)
  533. return -ENXIO;
  534. if (info->stream < 0 || info->stream > 1)
  535. return -EINVAL;
  536. pstr = &rmidi->streams[info->stream];
  537. if (pstr->substream_count == 0)
  538. return -ENOENT;
  539. if (info->subdevice >= pstr->substream_count)
  540. return -ENXIO;
  541. list_for_each_entry(substream, &pstr->substreams, list) {
  542. if ((unsigned int)substream->number == info->subdevice)
  543. return snd_rawmidi_info(substream, info);
  544. }
  545. return -ENXIO;
  546. }
  547. static int snd_rawmidi_info_select_user(struct snd_card *card,
  548. struct snd_rawmidi_info __user *_info)
  549. {
  550. int err;
  551. struct snd_rawmidi_info info;
  552. if (get_user(info.device, &_info->device))
  553. return -EFAULT;
  554. if (get_user(info.stream, &_info->stream))
  555. return -EFAULT;
  556. if (get_user(info.subdevice, &_info->subdevice))
  557. return -EFAULT;
  558. if ((err = snd_rawmidi_info_select(card, &info)) < 0)
  559. return err;
  560. if (copy_to_user(_info, &info, sizeof(struct snd_rawmidi_info)))
  561. return -EFAULT;
  562. return 0;
  563. }
  564. int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,
  565. struct snd_rawmidi_params * params)
  566. {
  567. char *newbuf;
  568. struct snd_rawmidi_runtime *runtime = substream->runtime;
  569. if (substream->append && substream->use_count > 1)
  570. return -EBUSY;
  571. snd_rawmidi_drain_output(substream);
  572. if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) {
  573. return -EINVAL;
  574. }
  575. if (params->avail_min < 1 || params->avail_min > params->buffer_size) {
  576. return -EINVAL;
  577. }
  578. if (params->buffer_size != runtime->buffer_size) {
  579. newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
  580. if (!newbuf)
  581. return -ENOMEM;
  582. kfree(runtime->buffer);
  583. runtime->buffer = newbuf;
  584. runtime->buffer_size = params->buffer_size;
  585. runtime->avail = runtime->buffer_size;
  586. }
  587. runtime->avail_min = params->avail_min;
  588. substream->active_sensing = !params->no_active_sensing;
  589. return 0;
  590. }
  591. int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,
  592. struct snd_rawmidi_params * params)
  593. {
  594. char *newbuf;
  595. struct snd_rawmidi_runtime *runtime = substream->runtime;
  596. snd_rawmidi_drain_input(substream);
  597. if (params->buffer_size < 32 || params->buffer_size > 1024L * 1024L) {
  598. return -EINVAL;
  599. }
  600. if (params->avail_min < 1 || params->avail_min > params->buffer_size) {
  601. return -EINVAL;
  602. }
  603. if (params->buffer_size != runtime->buffer_size) {
  604. newbuf = kmalloc(params->buffer_size, GFP_KERNEL);
  605. if (!newbuf)
  606. return -ENOMEM;
  607. kfree(runtime->buffer);
  608. runtime->buffer = newbuf;
  609. runtime->buffer_size = params->buffer_size;
  610. }
  611. runtime->avail_min = params->avail_min;
  612. return 0;
  613. }
  614. static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream,
  615. struct snd_rawmidi_status * status)
  616. {
  617. struct snd_rawmidi_runtime *runtime = substream->runtime;
  618. memset(status, 0, sizeof(*status));
  619. status->stream = SNDRV_RAWMIDI_STREAM_OUTPUT;
  620. spin_lock_irq(&runtime->lock);
  621. status->avail = runtime->avail;
  622. spin_unlock_irq(&runtime->lock);
  623. return 0;
  624. }
  625. static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream,
  626. struct snd_rawmidi_status * status)
  627. {
  628. struct snd_rawmidi_runtime *runtime = substream->runtime;
  629. memset(status, 0, sizeof(*status));
  630. status->stream = SNDRV_RAWMIDI_STREAM_INPUT;
  631. spin_lock_irq(&runtime->lock);
  632. status->avail = runtime->avail;
  633. status->xruns = runtime->xruns;
  634. runtime->xruns = 0;
  635. spin_unlock_irq(&runtime->lock);
  636. return 0;
  637. }
  638. static long snd_rawmidi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  639. {
  640. struct snd_rawmidi_file *rfile;
  641. void __user *argp = (void __user *)arg;
  642. rfile = file->private_data;
  643. if (((cmd >> 8) & 0xff) != 'W')
  644. return -ENOTTY;
  645. switch (cmd) {
  646. case SNDRV_RAWMIDI_IOCTL_PVERSION:
  647. return put_user(SNDRV_RAWMIDI_VERSION, (int __user *)argp) ? -EFAULT : 0;
  648. case SNDRV_RAWMIDI_IOCTL_INFO:
  649. {
  650. int stream;
  651. struct snd_rawmidi_info __user *info = argp;
  652. if (get_user(stream, &info->stream))
  653. return -EFAULT;
  654. switch (stream) {
  655. case SNDRV_RAWMIDI_STREAM_INPUT:
  656. return snd_rawmidi_info_user(rfile->input, info);
  657. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  658. return snd_rawmidi_info_user(rfile->output, info);
  659. default:
  660. return -EINVAL;
  661. }
  662. }
  663. case SNDRV_RAWMIDI_IOCTL_PARAMS:
  664. {
  665. struct snd_rawmidi_params params;
  666. if (copy_from_user(&params, argp, sizeof(struct snd_rawmidi_params)))
  667. return -EFAULT;
  668. switch (params.stream) {
  669. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  670. if (rfile->output == NULL)
  671. return -EINVAL;
  672. return snd_rawmidi_output_params(rfile->output, &params);
  673. case SNDRV_RAWMIDI_STREAM_INPUT:
  674. if (rfile->input == NULL)
  675. return -EINVAL;
  676. return snd_rawmidi_input_params(rfile->input, &params);
  677. default:
  678. return -EINVAL;
  679. }
  680. }
  681. case SNDRV_RAWMIDI_IOCTL_STATUS:
  682. {
  683. int err = 0;
  684. struct snd_rawmidi_status status;
  685. if (copy_from_user(&status, argp, sizeof(struct snd_rawmidi_status)))
  686. return -EFAULT;
  687. switch (status.stream) {
  688. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  689. if (rfile->output == NULL)
  690. return -EINVAL;
  691. err = snd_rawmidi_output_status(rfile->output, &status);
  692. break;
  693. case SNDRV_RAWMIDI_STREAM_INPUT:
  694. if (rfile->input == NULL)
  695. return -EINVAL;
  696. err = snd_rawmidi_input_status(rfile->input, &status);
  697. break;
  698. default:
  699. return -EINVAL;
  700. }
  701. if (err < 0)
  702. return err;
  703. if (copy_to_user(argp, &status, sizeof(struct snd_rawmidi_status)))
  704. return -EFAULT;
  705. return 0;
  706. }
  707. case SNDRV_RAWMIDI_IOCTL_DROP:
  708. {
  709. int val;
  710. if (get_user(val, (int __user *) argp))
  711. return -EFAULT;
  712. switch (val) {
  713. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  714. if (rfile->output == NULL)
  715. return -EINVAL;
  716. return snd_rawmidi_drop_output(rfile->output);
  717. default:
  718. return -EINVAL;
  719. }
  720. }
  721. case SNDRV_RAWMIDI_IOCTL_DRAIN:
  722. {
  723. int val;
  724. if (get_user(val, (int __user *) argp))
  725. return -EFAULT;
  726. switch (val) {
  727. case SNDRV_RAWMIDI_STREAM_OUTPUT:
  728. if (rfile->output == NULL)
  729. return -EINVAL;
  730. return snd_rawmidi_drain_output(rfile->output);
  731. case SNDRV_RAWMIDI_STREAM_INPUT:
  732. if (rfile->input == NULL)
  733. return -EINVAL;
  734. return snd_rawmidi_drain_input(rfile->input);
  735. default:
  736. return -EINVAL;
  737. }
  738. }
  739. #ifdef CONFIG_SND_DEBUG
  740. default:
  741. snd_printk(KERN_WARNING "rawmidi: unknown command = 0x%x\n", cmd);
  742. #endif
  743. }
  744. return -ENOTTY;
  745. }
  746. static int snd_rawmidi_control_ioctl(struct snd_card *card,
  747. struct snd_ctl_file *control,
  748. unsigned int cmd,
  749. unsigned long arg)
  750. {
  751. void __user *argp = (void __user *)arg;
  752. switch (cmd) {
  753. case SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE:
  754. {
  755. int device;
  756. if (get_user(device, (int __user *)argp))
  757. return -EFAULT;
  758. if (device >= SNDRV_RAWMIDI_DEVICES) /* next device is -1 */
  759. device = SNDRV_RAWMIDI_DEVICES - 1;
  760. mutex_lock(&register_mutex);
  761. device = device < 0 ? 0 : device + 1;
  762. while (device < SNDRV_RAWMIDI_DEVICES) {
  763. if (snd_rawmidi_search(card, device))
  764. break;
  765. device++;
  766. }
  767. if (device == SNDRV_RAWMIDI_DEVICES)
  768. device = -1;
  769. mutex_unlock(&register_mutex);
  770. if (put_user(device, (int __user *)argp))
  771. return -EFAULT;
  772. return 0;
  773. }
  774. case SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE:
  775. {
  776. int val;
  777. if (get_user(val, (int __user *)argp))
  778. return -EFAULT;
  779. control->prefer_rawmidi_subdevice = val;
  780. return 0;
  781. }
  782. case SNDRV_CTL_IOCTL_RAWMIDI_INFO:
  783. return snd_rawmidi_info_select_user(card, argp);
  784. }
  785. return -ENOIOCTLCMD;
  786. }
  787. /**
  788. * snd_rawmidi_receive - receive the input data from the device
  789. * @substream: the rawmidi substream
  790. * @buffer: the buffer pointer
  791. * @count: the data size to read
  792. *
  793. * Reads the data from the internal buffer.
  794. *
  795. * Returns the size of read data, or a negative error code on failure.
  796. */
  797. int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,
  798. const unsigned char *buffer, int count)
  799. {
  800. unsigned long flags;
  801. int result = 0, count1;
  802. struct snd_rawmidi_runtime *runtime = substream->runtime;
  803. if (!substream->opened)
  804. return -EBADFD;
  805. if (runtime->buffer == NULL) {
  806. snd_printd("snd_rawmidi_receive: input is not active!!!\n");
  807. return -EINVAL;
  808. }
  809. spin_lock_irqsave(&runtime->lock, flags);
  810. if (count == 1) { /* special case, faster code */
  811. substream->bytes++;
  812. if (runtime->avail < runtime->buffer_size) {
  813. runtime->buffer[runtime->hw_ptr++] = buffer[0];
  814. runtime->hw_ptr %= runtime->buffer_size;
  815. runtime->avail++;
  816. result++;
  817. } else {
  818. runtime->xruns++;
  819. }
  820. } else {
  821. substream->bytes += count;
  822. count1 = runtime->buffer_size - runtime->hw_ptr;
  823. if (count1 > count)
  824. count1 = count;
  825. if (count1 > (int)(runtime->buffer_size - runtime->avail))
  826. count1 = runtime->buffer_size - runtime->avail;
  827. memcpy(runtime->buffer + runtime->hw_ptr, buffer, count1);
  828. runtime->hw_ptr += count1;
  829. runtime->hw_ptr %= runtime->buffer_size;
  830. runtime->avail += count1;
  831. count -= count1;
  832. result += count1;
  833. if (count > 0) {
  834. buffer += count1;
  835. count1 = count;
  836. if (count1 > (int)(runtime->buffer_size - runtime->avail)) {
  837. count1 = runtime->buffer_size - runtime->avail;
  838. runtime->xruns += count - count1;
  839. }
  840. if (count1 > 0) {
  841. memcpy(runtime->buffer, buffer, count1);
  842. runtime->hw_ptr = count1;
  843. runtime->avail += count1;
  844. result += count1;
  845. }
  846. }
  847. }
  848. if (result > 0) {
  849. if (runtime->event)
  850. tasklet_schedule(&runtime->tasklet);
  851. else if (snd_rawmidi_ready(substream))
  852. wake_up(&runtime->sleep);
  853. }
  854. spin_unlock_irqrestore(&runtime->lock, flags);
  855. return result;
  856. }
  857. static long snd_rawmidi_kernel_read1(struct snd_rawmidi_substream *substream,
  858. unsigned char __user *userbuf,
  859. unsigned char *kernelbuf, long count)
  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 (kernelbuf)
  872. memcpy(kernelbuf + result, runtime->buffer + runtime->appl_ptr, count1);
  873. if (userbuf) {
  874. spin_unlock_irqrestore(&runtime->lock, flags);
  875. if (copy_to_user(userbuf + 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, NULL/*userbuf*/, buf, count);
  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 __user *)buf,
  934. NULL/*kernelbuf*/,
  935. count);
  936. if (count1 < 0)
  937. return result > 0 ? result : count1;
  938. result += count1;
  939. buf += count1;
  940. count -= count1;
  941. }
  942. return result;
  943. }
  944. /**
  945. * snd_rawmidi_transmit_empty - check whether the output buffer is empty
  946. * @substream: the rawmidi substream
  947. *
  948. * Returns 1 if the internal output buffer is empty, 0 if not.
  949. */
  950. int snd_rawmidi_transmit_empty(struct snd_rawmidi_substream *substream)
  951. {
  952. struct snd_rawmidi_runtime *runtime = substream->runtime;
  953. int result;
  954. unsigned long flags;
  955. if (runtime->buffer == NULL) {
  956. snd_printd("snd_rawmidi_transmit_empty: output is not active!!!\n");
  957. return 1;
  958. }
  959. spin_lock_irqsave(&runtime->lock, flags);
  960. result = runtime->avail >= runtime->buffer_size;
  961. spin_unlock_irqrestore(&runtime->lock, flags);
  962. return result;
  963. }
  964. /**
  965. * snd_rawmidi_transmit_peek - copy data from the internal buffer
  966. * @substream: the rawmidi substream
  967. * @buffer: the buffer pointer
  968. * @count: data size to transfer
  969. *
  970. * Copies data from the internal output buffer to the given buffer.
  971. *
  972. * Call this in the interrupt handler when the midi output is ready,
  973. * and call snd_rawmidi_transmit_ack() after the transmission is
  974. * finished.
  975. *
  976. * Returns the size of copied data, or a negative error code on failure.
  977. */
  978. int snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,
  979. unsigned char *buffer, int count)
  980. {
  981. unsigned long flags;
  982. int result, count1;
  983. struct snd_rawmidi_runtime *runtime = substream->runtime;
  984. if (runtime->buffer == NULL) {
  985. snd_printd("snd_rawmidi_transmit_peek: output is not active!!!\n");
  986. return -EINVAL;
  987. }
  988. result = 0;
  989. spin_lock_irqsave(&runtime->lock, flags);
  990. if (runtime->avail >= runtime->buffer_size) {
  991. /* warning: lowlevel layer MUST trigger down the hardware */
  992. goto __skip;
  993. }
  994. if (count == 1) { /* special case, faster code */
  995. *buffer = runtime->buffer[runtime->hw_ptr];
  996. result++;
  997. } else {
  998. count1 = runtime->buffer_size - runtime->hw_ptr;
  999. if (count1 > count)
  1000. count1 = count;
  1001. if (count1 > (int)(runtime->buffer_size - runtime->avail))
  1002. count1 = runtime->buffer_size - runtime->avail;
  1003. memcpy(buffer, runtime->buffer + runtime->hw_ptr, count1);
  1004. count -= count1;
  1005. result += count1;
  1006. if (count > 0) {
  1007. if (count > (int)(runtime->buffer_size - runtime->avail - count1))
  1008. count = runtime->buffer_size - runtime->avail - count1;
  1009. memcpy(buffer + count1, runtime->buffer, count);
  1010. result += count;
  1011. }
  1012. }
  1013. __skip:
  1014. spin_unlock_irqrestore(&runtime->lock, flags);
  1015. return result;
  1016. }
  1017. /**
  1018. * snd_rawmidi_transmit_ack - acknowledge the transmission
  1019. * @substream: the rawmidi substream
  1020. * @count: the tranferred count
  1021. *
  1022. * Advances the hardware pointer for the internal output buffer with
  1023. * the given size and updates the condition.
  1024. * Call after the transmission is finished.
  1025. *
  1026. * Returns the advanced size if successful, or a negative error code on failure.
  1027. */
  1028. int snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream, int count)
  1029. {
  1030. unsigned long flags;
  1031. struct snd_rawmidi_runtime *runtime = substream->runtime;
  1032. if (runtime->buffer == NULL) {
  1033. snd_printd("snd_rawmidi_transmit_ack: output is not active!!!\n");
  1034. return -EINVAL;
  1035. }
  1036. spin_lock_irqsave(&runtime->lock, flags);
  1037. snd_BUG_ON(runtime->avail + count > runtime->buffer_size);
  1038. runtime->hw_ptr += count;
  1039. runtime->hw_ptr %= runtime->buffer_size;
  1040. runtime->avail += count;
  1041. substream->bytes += count;
  1042. if (count > 0) {
  1043. if (runtime->drain || snd_rawmidi_ready(substream))
  1044. wake_up(&runtime->sleep);
  1045. }
  1046. spin_unlock_irqrestore(&runtime->lock, flags);
  1047. return count;
  1048. }
  1049. /**
  1050. * snd_rawmidi_transmit - copy from the buffer to the device
  1051. * @substream: the rawmidi substream
  1052. * @buffer: the buffer pointer
  1053. * @count: the data size to transfer
  1054. *
  1055. * Copies data from the buffer to the device and advances the pointer.
  1056. *
  1057. * Returns the copied size if successful, or a negative error code on failure.
  1058. */
  1059. int snd_rawmidi_transmit(struct snd_rawmidi_substream *substream,
  1060. unsigned char *buffer, int count)
  1061. {
  1062. if (!substream->opened)
  1063. return -EBADFD;
  1064. count = snd_rawmidi_transmit_peek(substream, buffer, count);
  1065. if (count < 0)
  1066. return count;
  1067. return snd_rawmidi_transmit_ack(substream, count);
  1068. }
  1069. static long snd_rawmidi_kernel_write1(struct snd_rawmidi_substream *substream,
  1070. const unsigned char __user *userbuf,
  1071. const unsigned char *kernelbuf,
  1072. long count)
  1073. {
  1074. unsigned long flags;
  1075. long count1, result;
  1076. struct snd_rawmidi_runtime *runtime = substream->runtime;
  1077. if (snd_BUG_ON(!kernelbuf && !userbuf))
  1078. return -EINVAL;
  1079. if (snd_BUG_ON(!runtime->buffer))
  1080. return -EINVAL;
  1081. result = 0;
  1082. spin_lock_irqsave(&runtime->lock, flags);
  1083. if (substream->append) {
  1084. if ((long)runtime->avail < count) {
  1085. spin_unlock_irqrestore(&runtime->lock, flags);
  1086. return -EAGAIN;
  1087. }
  1088. }
  1089. while (count > 0 && runtime->avail > 0) {
  1090. count1 = runtime->buffer_size - runtime->appl_ptr;
  1091. if (count1 > count)
  1092. count1 = count;
  1093. if (count1 > (long)runtime->avail)
  1094. count1 = runtime->avail;
  1095. if (kernelbuf)
  1096. memcpy(runtime->buffer + runtime->appl_ptr,
  1097. kernelbuf + result, count1);
  1098. else if (userbuf) {
  1099. spin_unlock_irqrestore(&runtime->lock, flags);
  1100. if (copy_from_user(runtime->buffer + runtime->appl_ptr,
  1101. userbuf + result, count1)) {
  1102. spin_lock_irqsave(&runtime->lock, flags);
  1103. result = result > 0 ? result : -EFAULT;
  1104. goto __end;
  1105. }
  1106. spin_lock_irqsave(&runtime->lock, flags);
  1107. }
  1108. runtime->appl_ptr += count1;
  1109. runtime->appl_ptr %= runtime->buffer_size;
  1110. runtime->avail -= count1;
  1111. result += count1;
  1112. count -= count1;
  1113. }
  1114. __end:
  1115. count1 = runtime->avail < runtime->buffer_size;
  1116. spin_unlock_irqrestore(&runtime->lock, flags);
  1117. if (count1)
  1118. snd_rawmidi_output_trigger(substream, 1);
  1119. return result;
  1120. }
  1121. long snd_rawmidi_kernel_write(struct snd_rawmidi_substream *substream,
  1122. const unsigned char *buf, long count)
  1123. {
  1124. return snd_rawmidi_kernel_write1(substream, NULL, buf, count);
  1125. }
  1126. static ssize_t snd_rawmidi_write(struct file *file, const char __user *buf,
  1127. size_t count, loff_t *offset)
  1128. {
  1129. long result, timeout;
  1130. int count1;
  1131. struct snd_rawmidi_file *rfile;
  1132. struct snd_rawmidi_runtime *runtime;
  1133. struct snd_rawmidi_substream *substream;
  1134. rfile = file->private_data;
  1135. substream = rfile->output;
  1136. runtime = substream->runtime;
  1137. /* we cannot put an atomic message to our buffer */
  1138. if (substream->append && count > runtime->buffer_size)
  1139. return -EIO;
  1140. result = 0;
  1141. while (count > 0) {
  1142. spin_lock_irq(&runtime->lock);
  1143. while (!snd_rawmidi_ready_append(substream, count)) {
  1144. wait_queue_t wait;
  1145. if (file->f_flags & O_NONBLOCK) {
  1146. spin_unlock_irq(&runtime->lock);
  1147. return result > 0 ? result : -EAGAIN;
  1148. }
  1149. init_waitqueue_entry(&wait, current);
  1150. add_wait_queue(&runtime->sleep, &wait);
  1151. set_current_state(TASK_INTERRUPTIBLE);
  1152. spin_unlock_irq(&runtime->lock);
  1153. timeout = schedule_timeout(30 * HZ);
  1154. remove_wait_queue(&runtime->sleep, &wait);
  1155. if (signal_pending(current))
  1156. return result > 0 ? result : -ERESTARTSYS;
  1157. if (!runtime->avail && !timeout)
  1158. return result > 0 ? result : -EIO;
  1159. spin_lock_irq(&runtime->lock);
  1160. }
  1161. spin_unlock_irq(&runtime->lock);
  1162. count1 = snd_rawmidi_kernel_write1(substream, buf, NULL, count);
  1163. if (count1 < 0)
  1164. return result > 0 ? result : count1;
  1165. result += count1;
  1166. buf += count1;
  1167. if ((size_t)count1 < count && (file->f_flags & O_NONBLOCK))
  1168. break;
  1169. count -= count1;
  1170. }
  1171. if (file->f_flags & O_DSYNC) {
  1172. spin_lock_irq(&runtime->lock);
  1173. while (runtime->avail != runtime->buffer_size) {
  1174. wait_queue_t wait;
  1175. unsigned int last_avail = runtime->avail;
  1176. init_waitqueue_entry(&wait, current);
  1177. add_wait_queue(&runtime->sleep, &wait);
  1178. set_current_state(TASK_INTERRUPTIBLE);
  1179. spin_unlock_irq(&runtime->lock);
  1180. timeout = schedule_timeout(30 * HZ);
  1181. remove_wait_queue(&runtime->sleep, &wait);
  1182. if (signal_pending(current))
  1183. return result > 0 ? result : -ERESTARTSYS;
  1184. if (runtime->avail == last_avail && !timeout)
  1185. return result > 0 ? result : -EIO;
  1186. spin_lock_irq(&runtime->lock);
  1187. }
  1188. spin_unlock_irq(&runtime->lock);
  1189. }
  1190. return result;
  1191. }
  1192. static unsigned int snd_rawmidi_poll(struct file *file, poll_table * wait)
  1193. {
  1194. struct snd_rawmidi_file *rfile;
  1195. struct snd_rawmidi_runtime *runtime;
  1196. unsigned int mask;
  1197. rfile = file->private_data;
  1198. if (rfile->input != NULL) {
  1199. runtime = rfile->input->runtime;
  1200. snd_rawmidi_input_trigger(rfile->input, 1);
  1201. poll_wait(file, &runtime->sleep, wait);
  1202. }
  1203. if (rfile->output != NULL) {
  1204. runtime = rfile->output->runtime;
  1205. poll_wait(file, &runtime->sleep, wait);
  1206. }
  1207. mask = 0;
  1208. if (rfile->input != NULL) {
  1209. if (snd_rawmidi_ready(rfile->input))
  1210. mask |= POLLIN | POLLRDNORM;
  1211. }
  1212. if (rfile->output != NULL) {
  1213. if (snd_rawmidi_ready(rfile->output))
  1214. mask |= POLLOUT | POLLWRNORM;
  1215. }
  1216. return mask;
  1217. }
  1218. /*
  1219. */
  1220. #ifdef CONFIG_COMPAT
  1221. #include "rawmidi_compat.c"
  1222. #else
  1223. #define snd_rawmidi_ioctl_compat NULL
  1224. #endif
  1225. /*
  1226. */
  1227. static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
  1228. struct snd_info_buffer *buffer)
  1229. {
  1230. struct snd_rawmidi *rmidi;
  1231. struct snd_rawmidi_substream *substream;
  1232. struct snd_rawmidi_runtime *runtime;
  1233. rmidi = entry->private_data;
  1234. snd_iprintf(buffer, "%s\n\n", rmidi->name);
  1235. mutex_lock(&rmidi->open_mutex);
  1236. if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT) {
  1237. list_for_each_entry(substream,
  1238. &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams,
  1239. list) {
  1240. snd_iprintf(buffer,
  1241. "Output %d\n"
  1242. " Tx bytes : %lu\n",
  1243. substream->number,
  1244. (unsigned long) substream->bytes);
  1245. if (substream->opened) {
  1246. snd_iprintf(buffer,
  1247. " Owner PID : %d\n",
  1248. pid_vnr(substream->pid));
  1249. runtime = substream->runtime;
  1250. snd_iprintf(buffer,
  1251. " Mode : %s\n"
  1252. " Buffer size : %lu\n"
  1253. " Avail : %lu\n",
  1254. runtime->oss ? "OSS compatible" : "native",
  1255. (unsigned long) runtime->buffer_size,
  1256. (unsigned long) runtime->avail);
  1257. }
  1258. }
  1259. }
  1260. if (rmidi->info_flags & SNDRV_RAWMIDI_INFO_INPUT) {
  1261. list_for_each_entry(substream,
  1262. &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams,
  1263. list) {
  1264. snd_iprintf(buffer,
  1265. "Input %d\n"
  1266. " Rx bytes : %lu\n",
  1267. substream->number,
  1268. (unsigned long) substream->bytes);
  1269. if (substream->opened) {
  1270. snd_iprintf(buffer,
  1271. " Owner PID : %d\n",
  1272. pid_vnr(substream->pid));
  1273. runtime = substream->runtime;
  1274. snd_iprintf(buffer,
  1275. " Buffer size : %lu\n"
  1276. " Avail : %lu\n"
  1277. " Overruns : %lu\n",
  1278. (unsigned long) runtime->buffer_size,
  1279. (unsigned long) runtime->avail,
  1280. (unsigned long) runtime->xruns);
  1281. }
  1282. }
  1283. }
  1284. mutex_unlock(&rmidi->open_mutex);
  1285. }
  1286. /*
  1287. * Register functions
  1288. */
  1289. static const struct file_operations snd_rawmidi_f_ops =
  1290. {
  1291. .owner = THIS_MODULE,
  1292. .read = snd_rawmidi_read,
  1293. .write = snd_rawmidi_write,
  1294. .open = snd_rawmidi_open,
  1295. .release = snd_rawmidi_release,
  1296. .llseek = no_llseek,
  1297. .poll = snd_rawmidi_poll,
  1298. .unlocked_ioctl = snd_rawmidi_ioctl,
  1299. .compat_ioctl = snd_rawmidi_ioctl_compat,
  1300. };
  1301. static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
  1302. struct snd_rawmidi_str *stream,
  1303. int direction,
  1304. int count)
  1305. {
  1306. struct snd_rawmidi_substream *substream;
  1307. int idx;
  1308. for (idx = 0; idx < count; idx++) {
  1309. substream = kzalloc(sizeof(*substream), GFP_KERNEL);
  1310. if (substream == NULL) {
  1311. snd_printk(KERN_ERR "rawmidi: cannot allocate substream\n");
  1312. return -ENOMEM;
  1313. }
  1314. substream->stream = direction;
  1315. substream->number = idx;
  1316. substream->rmidi = rmidi;
  1317. substream->pstr = stream;
  1318. list_add_tail(&substream->list, &stream->substreams);
  1319. stream->substream_count++;
  1320. }
  1321. return 0;
  1322. }
  1323. /**
  1324. * snd_rawmidi_new - create a rawmidi instance
  1325. * @card: the card instance
  1326. * @id: the id string
  1327. * @device: the device index
  1328. * @output_count: the number of output streams
  1329. * @input_count: the number of input streams
  1330. * @rrawmidi: the pointer to store the new rawmidi instance
  1331. *
  1332. * Creates a new rawmidi instance.
  1333. * Use snd_rawmidi_set_ops() to set the operators to the new instance.
  1334. *
  1335. * Returns zero if successful, or a negative error code on failure.
  1336. */
  1337. int snd_rawmidi_new(struct snd_card *card, char *id, int device,
  1338. int output_count, int input_count,
  1339. struct snd_rawmidi ** rrawmidi)
  1340. {
  1341. struct snd_rawmidi *rmidi;
  1342. int err;
  1343. static struct snd_device_ops ops = {
  1344. .dev_free = snd_rawmidi_dev_free,
  1345. .dev_register = snd_rawmidi_dev_register,
  1346. .dev_disconnect = snd_rawmidi_dev_disconnect,
  1347. };
  1348. if (snd_BUG_ON(!card))
  1349. return -ENXIO;
  1350. if (rrawmidi)
  1351. *rrawmidi = NULL;
  1352. rmidi = kzalloc(sizeof(*rmidi), GFP_KERNEL);
  1353. if (rmidi == NULL) {
  1354. snd_printk(KERN_ERR "rawmidi: cannot allocate\n");
  1355. return -ENOMEM;
  1356. }
  1357. rmidi->card = card;
  1358. rmidi->device = device;
  1359. mutex_init(&rmidi->open_mutex);
  1360. init_waitqueue_head(&rmidi->open_wait);
  1361. INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
  1362. INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
  1363. if (id != NULL)
  1364. strlcpy(rmidi->id, id, sizeof(rmidi->id));
  1365. if ((err = snd_rawmidi_alloc_substreams(rmidi,
  1366. &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT],
  1367. SNDRV_RAWMIDI_STREAM_INPUT,
  1368. input_count)) < 0) {
  1369. snd_rawmidi_free(rmidi);
  1370. return err;
  1371. }
  1372. if ((err = snd_rawmidi_alloc_substreams(rmidi,
  1373. &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT],
  1374. SNDRV_RAWMIDI_STREAM_OUTPUT,
  1375. output_count)) < 0) {
  1376. snd_rawmidi_free(rmidi);
  1377. return err;
  1378. }
  1379. if ((err = snd_device_new(card, SNDRV_DEV_RAWMIDI, rmidi, &ops)) < 0) {
  1380. snd_rawmidi_free(rmidi);
  1381. return err;
  1382. }
  1383. if (rrawmidi)
  1384. *rrawmidi = rmidi;
  1385. return 0;
  1386. }
  1387. static void snd_rawmidi_free_substreams(struct snd_rawmidi_str *stream)
  1388. {
  1389. struct snd_rawmidi_substream *substream;
  1390. while (!list_empty(&stream->substreams)) {
  1391. substream = list_entry(stream->substreams.next, struct snd_rawmidi_substream, list);
  1392. list_del(&substream->list);
  1393. kfree(substream);
  1394. }
  1395. }
  1396. static int snd_rawmidi_free(struct snd_rawmidi *rmidi)
  1397. {
  1398. if (!rmidi)
  1399. return 0;
  1400. snd_info_free_entry(rmidi->proc_entry);
  1401. rmidi->proc_entry = NULL;
  1402. mutex_lock(&register_mutex);
  1403. if (rmidi->ops && rmidi->ops->dev_unregister)
  1404. rmidi->ops->dev_unregister(rmidi);
  1405. mutex_unlock(&register_mutex);
  1406. snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]);
  1407. snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]);
  1408. if (rmidi->private_free)
  1409. rmidi->private_free(rmidi);
  1410. kfree(rmidi);
  1411. return 0;
  1412. }
  1413. static int snd_rawmidi_dev_free(struct snd_device *device)
  1414. {
  1415. struct snd_rawmidi *rmidi = device->device_data;
  1416. return snd_rawmidi_free(rmidi);
  1417. }
  1418. #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
  1419. static void snd_rawmidi_dev_seq_free(struct snd_seq_device *device)
  1420. {
  1421. struct snd_rawmidi *rmidi = device->private_data;
  1422. rmidi->seq_dev = NULL;
  1423. }
  1424. #endif
  1425. static int snd_rawmidi_dev_register(struct snd_device *device)
  1426. {
  1427. int err;
  1428. struct snd_info_entry *entry;
  1429. char name[16];
  1430. struct snd_rawmidi *rmidi = device->device_data;
  1431. if (rmidi->device >= SNDRV_RAWMIDI_DEVICES)
  1432. return -ENOMEM;
  1433. mutex_lock(&register_mutex);
  1434. if (snd_rawmidi_search(rmidi->card, rmidi->device)) {
  1435. mutex_unlock(&register_mutex);
  1436. return -EBUSY;
  1437. }
  1438. list_add_tail(&rmidi->list, &snd_rawmidi_devices);
  1439. sprintf(name, "midiC%iD%i", rmidi->card->number, rmidi->device);
  1440. if ((err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI,
  1441. rmidi->card, rmidi->device,
  1442. &snd_rawmidi_f_ops, rmidi, name)) < 0) {
  1443. snd_printk(KERN_ERR "unable to register rawmidi device %i:%i\n", rmidi->card->number, rmidi->device);
  1444. list_del(&rmidi->list);
  1445. mutex_unlock(&register_mutex);
  1446. return err;
  1447. }
  1448. if (rmidi->ops && rmidi->ops->dev_register &&
  1449. (err = rmidi->ops->dev_register(rmidi)) < 0) {
  1450. snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
  1451. list_del(&rmidi->list);
  1452. mutex_unlock(&register_mutex);
  1453. return err;
  1454. }
  1455. #ifdef CONFIG_SND_OSSEMUL
  1456. rmidi->ossreg = 0;
  1457. if ((int)rmidi->device == midi_map[rmidi->card->number]) {
  1458. if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI,
  1459. rmidi->card, 0, &snd_rawmidi_f_ops,
  1460. rmidi, name) < 0) {
  1461. snd_printk(KERN_ERR "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 0);
  1462. } else {
  1463. rmidi->ossreg++;
  1464. #ifdef SNDRV_OSS_INFO_DEV_MIDI
  1465. snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIDI, rmidi->card->number, rmidi->name);
  1466. #endif
  1467. }
  1468. }
  1469. if ((int)rmidi->device == amidi_map[rmidi->card->number]) {
  1470. if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI,
  1471. rmidi->card, 1, &snd_rawmidi_f_ops,
  1472. rmidi, name) < 0) {
  1473. snd_printk(KERN_ERR "unable to register OSS rawmidi device %i:%i\n", rmidi->card->number, 1);
  1474. } else {
  1475. rmidi->ossreg++;
  1476. }
  1477. }
  1478. #endif /* CONFIG_SND_OSSEMUL */
  1479. mutex_unlock(&register_mutex);
  1480. sprintf(name, "midi%d", rmidi->device);
  1481. entry = snd_info_create_card_entry(rmidi->card, name, rmidi->card->proc_root);
  1482. if (entry) {
  1483. entry->private_data = rmidi;
  1484. entry->c.text.read = snd_rawmidi_proc_info_read;
  1485. if (snd_info_register(entry) < 0) {
  1486. snd_info_free_entry(entry);
  1487. entry = NULL;
  1488. }
  1489. }
  1490. rmidi->proc_entry = entry;
  1491. #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
  1492. if (!rmidi->ops || !rmidi->ops->dev_register) { /* own registration mechanism */
  1493. if (snd_seq_device_new(rmidi->card, rmidi->device, SNDRV_SEQ_DEV_ID_MIDISYNTH, 0, &rmidi->seq_dev) >= 0) {
  1494. rmidi->seq_dev->private_data = rmidi;
  1495. rmidi->seq_dev->private_free = snd_rawmidi_dev_seq_free;
  1496. sprintf(rmidi->seq_dev->name, "MIDI %d-%d", rmidi->card->number, rmidi->device);
  1497. snd_device_register(rmidi->card, rmidi->seq_dev);
  1498. }
  1499. }
  1500. #endif
  1501. return 0;
  1502. }
  1503. static int snd_rawmidi_dev_disconnect(struct snd_device *device)
  1504. {
  1505. struct snd_rawmidi *rmidi = device->device_data;
  1506. mutex_lock(&register_mutex);
  1507. list_del_init(&rmidi->list);
  1508. #ifdef CONFIG_SND_OSSEMUL
  1509. if (rmidi->ossreg) {
  1510. if ((int)rmidi->device == midi_map[rmidi->card->number]) {
  1511. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 0);
  1512. #ifdef SNDRV_OSS_INFO_DEV_MIDI
  1513. snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIDI, rmidi->card->number);
  1514. #endif
  1515. }
  1516. if ((int)rmidi->device == amidi_map[rmidi->card->number])
  1517. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIDI, rmidi->card, 1);
  1518. rmidi->ossreg = 0;
  1519. }
  1520. #endif /* CONFIG_SND_OSSEMUL */
  1521. snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device);
  1522. mutex_unlock(&register_mutex);
  1523. return 0;
  1524. }
  1525. /**
  1526. * snd_rawmidi_set_ops - set the rawmidi operators
  1527. * @rmidi: the rawmidi instance
  1528. * @stream: the stream direction, SNDRV_RAWMIDI_STREAM_XXX
  1529. * @ops: the operator table
  1530. *
  1531. * Sets the rawmidi operators for the given stream direction.
  1532. */
  1533. void snd_rawmidi_set_ops(struct snd_rawmidi *rmidi, int stream,
  1534. struct snd_rawmidi_ops *ops)
  1535. {
  1536. struct snd_rawmidi_substream *substream;
  1537. list_for_each_entry(substream, &rmidi->streams[stream].substreams, list)
  1538. substream->ops = ops;
  1539. }
  1540. /*
  1541. * ENTRY functions
  1542. */
  1543. static int __init alsa_rawmidi_init(void)
  1544. {
  1545. snd_ctl_register_ioctl(snd_rawmidi_control_ioctl);
  1546. snd_ctl_register_ioctl_compat(snd_rawmidi_control_ioctl);
  1547. #ifdef CONFIG_SND_OSSEMUL
  1548. { int i;
  1549. /* check device map table */
  1550. for (i = 0; i < SNDRV_CARDS; i++) {
  1551. if (midi_map[i] < 0 || midi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
  1552. snd_printk(KERN_ERR "invalid midi_map[%d] = %d\n", i, midi_map[i]);
  1553. midi_map[i] = 0;
  1554. }
  1555. if (amidi_map[i] < 0 || amidi_map[i] >= SNDRV_RAWMIDI_DEVICES) {
  1556. snd_printk(KERN_ERR "invalid amidi_map[%d] = %d\n", i, amidi_map[i]);
  1557. amidi_map[i] = 1;
  1558. }
  1559. }
  1560. }
  1561. #endif /* CONFIG_SND_OSSEMUL */
  1562. return 0;
  1563. }
  1564. static void __exit alsa_rawmidi_exit(void)
  1565. {
  1566. snd_ctl_unregister_ioctl(snd_rawmidi_control_ioctl);
  1567. snd_ctl_unregister_ioctl_compat(snd_rawmidi_control_ioctl);
  1568. }
  1569. module_init(alsa_rawmidi_init)
  1570. module_exit(alsa_rawmidi_exit)
  1571. EXPORT_SYMBOL(snd_rawmidi_output_params);
  1572. EXPORT_SYMBOL(snd_rawmidi_input_params);
  1573. EXPORT_SYMBOL(snd_rawmidi_drop_output);
  1574. EXPORT_SYMBOL(snd_rawmidi_drain_output);
  1575. EXPORT_SYMBOL(snd_rawmidi_drain_input);
  1576. EXPORT_SYMBOL(snd_rawmidi_receive);
  1577. EXPORT_SYMBOL(snd_rawmidi_transmit_empty);
  1578. EXPORT_SYMBOL(snd_rawmidi_transmit_peek);
  1579. EXPORT_SYMBOL(snd_rawmidi_transmit_ack);
  1580. EXPORT_SYMBOL(snd_rawmidi_transmit);
  1581. EXPORT_SYMBOL(snd_rawmidi_new);
  1582. EXPORT_SYMBOL(snd_rawmidi_set_ops);
  1583. EXPORT_SYMBOL(snd_rawmidi_info_select);
  1584. EXPORT_SYMBOL(snd_rawmidi_kernel_open);
  1585. EXPORT_SYMBOL(snd_rawmidi_kernel_release);
  1586. EXPORT_SYMBOL(snd_rawmidi_kernel_read);
  1587. EXPORT_SYMBOL(snd_rawmidi_kernel_write);