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