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