1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * OSS compatible sequencer driver
4 *
5 * MIDI device handlers
6 *
7 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
8 */
9
10 #include <sound/asoundef.h>
11 #include "seq_oss_midi.h"
12 #include "seq_oss_readq.h"
13 #include "seq_oss_timer.h"
14 #include "seq_oss_event.h"
15 #include <sound/seq_midi_event.h>
16 #include "../seq_lock.h"
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/nospec.h>
20
21
22 /*
23 * constants
24 */
25 #define SNDRV_SEQ_OSS_MAX_MIDI_NAME 30
26
27 /*
28 * definition of midi device record
29 */
30 struct seq_oss_midi {
31 int seq_device; /* device number */
32 int client; /* sequencer client number */
33 int port; /* sequencer port number */
34 unsigned int flags; /* port capability */
35 int opened; /* flag for opening */
36 unsigned char name[SNDRV_SEQ_OSS_MAX_MIDI_NAME];
37 struct snd_midi_event *coder; /* MIDI event coder */
38 struct seq_oss_devinfo *devinfo; /* assigned OSSseq device */
39 snd_use_lock_t use_lock;
40 };
41
42
43 /*
44 * midi device table
45 */
46 static int max_midi_devs;
47 static struct seq_oss_midi *midi_devs[SNDRV_SEQ_OSS_MAX_MIDI_DEVS];
48
49 static DEFINE_SPINLOCK(register_lock);
50
51 /*
52 * prototypes
53 */
54 static struct seq_oss_midi *get_mdev(int dev);
55 static struct seq_oss_midi *get_mididev(struct seq_oss_devinfo *dp, int dev);
56 static int send_synth_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, int dev);
57 static int send_midi_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, struct seq_oss_midi *mdev);
58
59 /*
60 * look up the existing ports
61 * this looks a very exhausting job.
62 */
63 int
snd_seq_oss_midi_lookup_ports(int client)64 snd_seq_oss_midi_lookup_ports(int client)
65 {
66 struct snd_seq_client_info *clinfo;
67 struct snd_seq_port_info *pinfo;
68
69 clinfo = kzalloc(sizeof(*clinfo), GFP_KERNEL);
70 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL);
71 if (! clinfo || ! pinfo) {
72 kfree(clinfo);
73 kfree(pinfo);
74 return -ENOMEM;
75 }
76 clinfo->client = -1;
77 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, clinfo) == 0) {
78 if (clinfo->client == client)
79 continue; /* ignore myself */
80 pinfo->addr.client = clinfo->client;
81 pinfo->addr.port = -1;
82 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, pinfo) == 0)
83 snd_seq_oss_midi_check_new_port(pinfo);
84 }
85 kfree(clinfo);
86 kfree(pinfo);
87 return 0;
88 }
89
90
91 /*
92 */
93 static struct seq_oss_midi *
get_mdev(int dev)94 get_mdev(int dev)
95 {
96 struct seq_oss_midi *mdev;
97 unsigned long flags;
98
99 spin_lock_irqsave(®ister_lock, flags);
100 mdev = midi_devs[dev];
101 if (mdev)
102 snd_use_lock_use(&mdev->use_lock);
103 spin_unlock_irqrestore(®ister_lock, flags);
104 return mdev;
105 }
106
107 /*
108 * look for the identical slot
109 */
110 static struct seq_oss_midi *
find_slot(int client,int port)111 find_slot(int client, int port)
112 {
113 int i;
114 struct seq_oss_midi *mdev;
115 unsigned long flags;
116
117 spin_lock_irqsave(®ister_lock, flags);
118 for (i = 0; i < max_midi_devs; i++) {
119 mdev = midi_devs[i];
120 if (mdev && mdev->client == client && mdev->port == port) {
121 /* found! */
122 snd_use_lock_use(&mdev->use_lock);
123 spin_unlock_irqrestore(®ister_lock, flags);
124 return mdev;
125 }
126 }
127 spin_unlock_irqrestore(®ister_lock, flags);
128 return NULL;
129 }
130
131
132 #define PERM_WRITE (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_SUBS_WRITE)
133 #define PERM_READ (SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ)
134 /*
135 * register a new port if it doesn't exist yet
136 */
137 int
snd_seq_oss_midi_check_new_port(struct snd_seq_port_info * pinfo)138 snd_seq_oss_midi_check_new_port(struct snd_seq_port_info *pinfo)
139 {
140 int i;
141 struct seq_oss_midi *mdev;
142 unsigned long flags;
143
144 /* the port must include generic midi */
145 if (! (pinfo->type & SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC))
146 return 0;
147 /* either read or write subscribable */
148 if ((pinfo->capability & PERM_WRITE) != PERM_WRITE &&
149 (pinfo->capability & PERM_READ) != PERM_READ)
150 return 0;
151
152 /*
153 * look for the identical slot
154 */
155 if ((mdev = find_slot(pinfo->addr.client, pinfo->addr.port)) != NULL) {
156 /* already exists */
157 snd_use_lock_free(&mdev->use_lock);
158 return 0;
159 }
160
161 /*
162 * allocate midi info record
163 */
164 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
165 if (!mdev)
166 return -ENOMEM;
167
168 /* copy the port information */
169 mdev->client = pinfo->addr.client;
170 mdev->port = pinfo->addr.port;
171 mdev->flags = pinfo->capability;
172 mdev->opened = 0;
173 snd_use_lock_init(&mdev->use_lock);
174
175 /* copy and truncate the name of synth device */
176 strlcpy(mdev->name, pinfo->name, sizeof(mdev->name));
177
178 /* create MIDI coder */
179 if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &mdev->coder) < 0) {
180 pr_err("ALSA: seq_oss: can't malloc midi coder\n");
181 kfree(mdev);
182 return -ENOMEM;
183 }
184 /* OSS sequencer adds running status to all sequences */
185 snd_midi_event_no_status(mdev->coder, 1);
186
187 /*
188 * look for en empty slot
189 */
190 spin_lock_irqsave(®ister_lock, flags);
191 for (i = 0; i < max_midi_devs; i++) {
192 if (midi_devs[i] == NULL)
193 break;
194 }
195 if (i >= max_midi_devs) {
196 if (max_midi_devs >= SNDRV_SEQ_OSS_MAX_MIDI_DEVS) {
197 spin_unlock_irqrestore(®ister_lock, flags);
198 snd_midi_event_free(mdev->coder);
199 kfree(mdev);
200 return -ENOMEM;
201 }
202 max_midi_devs++;
203 }
204 mdev->seq_device = i;
205 midi_devs[mdev->seq_device] = mdev;
206 spin_unlock_irqrestore(®ister_lock, flags);
207
208 return 0;
209 }
210
211 /*
212 * release the midi device if it was registered
213 */
214 int
snd_seq_oss_midi_check_exit_port(int client,int port)215 snd_seq_oss_midi_check_exit_port(int client, int port)
216 {
217 struct seq_oss_midi *mdev;
218 unsigned long flags;
219 int index;
220
221 if ((mdev = find_slot(client, port)) != NULL) {
222 spin_lock_irqsave(®ister_lock, flags);
223 midi_devs[mdev->seq_device] = NULL;
224 spin_unlock_irqrestore(®ister_lock, flags);
225 snd_use_lock_free(&mdev->use_lock);
226 snd_use_lock_sync(&mdev->use_lock);
227 snd_midi_event_free(mdev->coder);
228 kfree(mdev);
229 }
230 spin_lock_irqsave(®ister_lock, flags);
231 for (index = max_midi_devs - 1; index >= 0; index--) {
232 if (midi_devs[index])
233 break;
234 }
235 max_midi_devs = index + 1;
236 spin_unlock_irqrestore(®ister_lock, flags);
237 return 0;
238 }
239
240
241 /*
242 * release the midi device if it was registered
243 */
244 void
snd_seq_oss_midi_clear_all(void)245 snd_seq_oss_midi_clear_all(void)
246 {
247 int i;
248 struct seq_oss_midi *mdev;
249 unsigned long flags;
250
251 spin_lock_irqsave(®ister_lock, flags);
252 for (i = 0; i < max_midi_devs; i++) {
253 if ((mdev = midi_devs[i]) != NULL) {
254 snd_midi_event_free(mdev->coder);
255 kfree(mdev);
256 midi_devs[i] = NULL;
257 }
258 }
259 max_midi_devs = 0;
260 spin_unlock_irqrestore(®ister_lock, flags);
261 }
262
263
264 /*
265 * set up midi tables
266 */
267 void
snd_seq_oss_midi_setup(struct seq_oss_devinfo * dp)268 snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp)
269 {
270 spin_lock_irq(®ister_lock);
271 dp->max_mididev = max_midi_devs;
272 spin_unlock_irq(®ister_lock);
273 }
274
275 /*
276 * clean up midi tables
277 */
278 void
snd_seq_oss_midi_cleanup(struct seq_oss_devinfo * dp)279 snd_seq_oss_midi_cleanup(struct seq_oss_devinfo *dp)
280 {
281 int i;
282 for (i = 0; i < dp->max_mididev; i++)
283 snd_seq_oss_midi_close(dp, i);
284 dp->max_mididev = 0;
285 }
286
287
288 /*
289 * open all midi devices. ignore errors.
290 */
291 void
snd_seq_oss_midi_open_all(struct seq_oss_devinfo * dp,int file_mode)292 snd_seq_oss_midi_open_all(struct seq_oss_devinfo *dp, int file_mode)
293 {
294 int i;
295 for (i = 0; i < dp->max_mididev; i++)
296 snd_seq_oss_midi_open(dp, i, file_mode);
297 }
298
299
300 /*
301 * get the midi device information
302 */
303 static struct seq_oss_midi *
get_mididev(struct seq_oss_devinfo * dp,int dev)304 get_mididev(struct seq_oss_devinfo *dp, int dev)
305 {
306 if (dev < 0 || dev >= dp->max_mididev)
307 return NULL;
308 dev = array_index_nospec(dev, dp->max_mididev);
309 return get_mdev(dev);
310 }
311
312
313 /*
314 * open the midi device if not opened yet
315 */
316 int
snd_seq_oss_midi_open(struct seq_oss_devinfo * dp,int dev,int fmode)317 snd_seq_oss_midi_open(struct seq_oss_devinfo *dp, int dev, int fmode)
318 {
319 int perm;
320 struct seq_oss_midi *mdev;
321 struct snd_seq_port_subscribe subs;
322
323 if ((mdev = get_mididev(dp, dev)) == NULL)
324 return -ENODEV;
325
326 /* already used? */
327 if (mdev->opened && mdev->devinfo != dp) {
328 snd_use_lock_free(&mdev->use_lock);
329 return -EBUSY;
330 }
331
332 perm = 0;
333 if (is_write_mode(fmode))
334 perm |= PERM_WRITE;
335 if (is_read_mode(fmode))
336 perm |= PERM_READ;
337 perm &= mdev->flags;
338 if (perm == 0) {
339 snd_use_lock_free(&mdev->use_lock);
340 return -ENXIO;
341 }
342
343 /* already opened? */
344 if ((mdev->opened & perm) == perm) {
345 snd_use_lock_free(&mdev->use_lock);
346 return 0;
347 }
348
349 perm &= ~mdev->opened;
350
351 memset(&subs, 0, sizeof(subs));
352
353 if (perm & PERM_WRITE) {
354 subs.sender = dp->addr;
355 subs.dest.client = mdev->client;
356 subs.dest.port = mdev->port;
357 if (snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &subs) >= 0)
358 mdev->opened |= PERM_WRITE;
359 }
360 if (perm & PERM_READ) {
361 subs.sender.client = mdev->client;
362 subs.sender.port = mdev->port;
363 subs.dest = dp->addr;
364 subs.flags = SNDRV_SEQ_PORT_SUBS_TIMESTAMP;
365 subs.queue = dp->queue; /* queue for timestamps */
366 if (snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &subs) >= 0)
367 mdev->opened |= PERM_READ;
368 }
369
370 if (! mdev->opened) {
371 snd_use_lock_free(&mdev->use_lock);
372 return -ENXIO;
373 }
374
375 mdev->devinfo = dp;
376 snd_use_lock_free(&mdev->use_lock);
377 return 0;
378 }
379
380 /*
381 * close the midi device if already opened
382 */
383 int
snd_seq_oss_midi_close(struct seq_oss_devinfo * dp,int dev)384 snd_seq_oss_midi_close(struct seq_oss_devinfo *dp, int dev)
385 {
386 struct seq_oss_midi *mdev;
387 struct snd_seq_port_subscribe subs;
388
389 if ((mdev = get_mididev(dp, dev)) == NULL)
390 return -ENODEV;
391 if (! mdev->opened || mdev->devinfo != dp) {
392 snd_use_lock_free(&mdev->use_lock);
393 return 0;
394 }
395
396 memset(&subs, 0, sizeof(subs));
397 if (mdev->opened & PERM_WRITE) {
398 subs.sender = dp->addr;
399 subs.dest.client = mdev->client;
400 subs.dest.port = mdev->port;
401 snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, &subs);
402 }
403 if (mdev->opened & PERM_READ) {
404 subs.sender.client = mdev->client;
405 subs.sender.port = mdev->port;
406 subs.dest = dp->addr;
407 snd_seq_kernel_client_ctl(dp->cseq, SNDRV_SEQ_IOCTL_UNSUBSCRIBE_PORT, &subs);
408 }
409
410 mdev->opened = 0;
411 mdev->devinfo = NULL;
412
413 snd_use_lock_free(&mdev->use_lock);
414 return 0;
415 }
416
417 /*
418 * change seq capability flags to file mode flags
419 */
420 int
snd_seq_oss_midi_filemode(struct seq_oss_devinfo * dp,int dev)421 snd_seq_oss_midi_filemode(struct seq_oss_devinfo *dp, int dev)
422 {
423 struct seq_oss_midi *mdev;
424 int mode;
425
426 if ((mdev = get_mididev(dp, dev)) == NULL)
427 return 0;
428
429 mode = 0;
430 if (mdev->opened & PERM_WRITE)
431 mode |= SNDRV_SEQ_OSS_FILE_WRITE;
432 if (mdev->opened & PERM_READ)
433 mode |= SNDRV_SEQ_OSS_FILE_READ;
434
435 snd_use_lock_free(&mdev->use_lock);
436 return mode;
437 }
438
439 /*
440 * reset the midi device and close it:
441 * so far, only close the device.
442 */
443 void
snd_seq_oss_midi_reset(struct seq_oss_devinfo * dp,int dev)444 snd_seq_oss_midi_reset(struct seq_oss_devinfo *dp, int dev)
445 {
446 struct seq_oss_midi *mdev;
447
448 if ((mdev = get_mididev(dp, dev)) == NULL)
449 return;
450 if (! mdev->opened) {
451 snd_use_lock_free(&mdev->use_lock);
452 return;
453 }
454
455 if (mdev->opened & PERM_WRITE) {
456 struct snd_seq_event ev;
457 int c;
458
459 memset(&ev, 0, sizeof(ev));
460 ev.dest.client = mdev->client;
461 ev.dest.port = mdev->port;
462 ev.queue = dp->queue;
463 ev.source.port = dp->port;
464 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_SYNTH) {
465 ev.type = SNDRV_SEQ_EVENT_SENSING;
466 snd_seq_oss_dispatch(dp, &ev, 0, 0);
467 }
468 for (c = 0; c < 16; c++) {
469 ev.type = SNDRV_SEQ_EVENT_CONTROLLER;
470 ev.data.control.channel = c;
471 ev.data.control.param = MIDI_CTL_ALL_NOTES_OFF;
472 snd_seq_oss_dispatch(dp, &ev, 0, 0);
473 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC) {
474 ev.data.control.param =
475 MIDI_CTL_RESET_CONTROLLERS;
476 snd_seq_oss_dispatch(dp, &ev, 0, 0);
477 ev.type = SNDRV_SEQ_EVENT_PITCHBEND;
478 ev.data.control.value = 0;
479 snd_seq_oss_dispatch(dp, &ev, 0, 0);
480 }
481 }
482 }
483 // snd_seq_oss_midi_close(dp, dev);
484 snd_use_lock_free(&mdev->use_lock);
485 }
486
487
488 /*
489 * get client/port of the specified MIDI device
490 */
491 void
snd_seq_oss_midi_get_addr(struct seq_oss_devinfo * dp,int dev,struct snd_seq_addr * addr)492 snd_seq_oss_midi_get_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_addr *addr)
493 {
494 struct seq_oss_midi *mdev;
495
496 if ((mdev = get_mididev(dp, dev)) == NULL)
497 return;
498 addr->client = mdev->client;
499 addr->port = mdev->port;
500 snd_use_lock_free(&mdev->use_lock);
501 }
502
503
504 /*
505 * input callback - this can be atomic
506 */
507 int
snd_seq_oss_midi_input(struct snd_seq_event * ev,int direct,void * private_data)508 snd_seq_oss_midi_input(struct snd_seq_event *ev, int direct, void *private_data)
509 {
510 struct seq_oss_devinfo *dp = (struct seq_oss_devinfo *)private_data;
511 struct seq_oss_midi *mdev;
512 int rc;
513
514 if (dp->readq == NULL)
515 return 0;
516 if ((mdev = find_slot(ev->source.client, ev->source.port)) == NULL)
517 return 0;
518 if (! (mdev->opened & PERM_READ)) {
519 snd_use_lock_free(&mdev->use_lock);
520 return 0;
521 }
522
523 if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_MUSIC)
524 rc = send_synth_event(dp, ev, mdev->seq_device);
525 else
526 rc = send_midi_event(dp, ev, mdev);
527
528 snd_use_lock_free(&mdev->use_lock);
529 return rc;
530 }
531
532 /*
533 * convert ALSA sequencer event to OSS synth event
534 */
535 static int
send_synth_event(struct seq_oss_devinfo * dp,struct snd_seq_event * ev,int dev)536 send_synth_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, int dev)
537 {
538 union evrec ossev;
539
540 memset(&ossev, 0, sizeof(ossev));
541
542 switch (ev->type) {
543 case SNDRV_SEQ_EVENT_NOTEON:
544 ossev.v.cmd = MIDI_NOTEON; break;
545 case SNDRV_SEQ_EVENT_NOTEOFF:
546 ossev.v.cmd = MIDI_NOTEOFF; break;
547 case SNDRV_SEQ_EVENT_KEYPRESS:
548 ossev.v.cmd = MIDI_KEY_PRESSURE; break;
549 case SNDRV_SEQ_EVENT_CONTROLLER:
550 ossev.l.cmd = MIDI_CTL_CHANGE; break;
551 case SNDRV_SEQ_EVENT_PGMCHANGE:
552 ossev.l.cmd = MIDI_PGM_CHANGE; break;
553 case SNDRV_SEQ_EVENT_CHANPRESS:
554 ossev.l.cmd = MIDI_CHN_PRESSURE; break;
555 case SNDRV_SEQ_EVENT_PITCHBEND:
556 ossev.l.cmd = MIDI_PITCH_BEND; break;
557 default:
558 return 0; /* not supported */
559 }
560
561 ossev.v.dev = dev;
562
563 switch (ev->type) {
564 case SNDRV_SEQ_EVENT_NOTEON:
565 case SNDRV_SEQ_EVENT_NOTEOFF:
566 case SNDRV_SEQ_EVENT_KEYPRESS:
567 ossev.v.code = EV_CHN_VOICE;
568 ossev.v.note = ev->data.note.note;
569 ossev.v.parm = ev->data.note.velocity;
570 ossev.v.chn = ev->data.note.channel;
571 break;
572 case SNDRV_SEQ_EVENT_CONTROLLER:
573 case SNDRV_SEQ_EVENT_PGMCHANGE:
574 case SNDRV_SEQ_EVENT_CHANPRESS:
575 ossev.l.code = EV_CHN_COMMON;
576 ossev.l.p1 = ev->data.control.param;
577 ossev.l.val = ev->data.control.value;
578 ossev.l.chn = ev->data.control.channel;
579 break;
580 case SNDRV_SEQ_EVENT_PITCHBEND:
581 ossev.l.code = EV_CHN_COMMON;
582 ossev.l.val = ev->data.control.value + 8192;
583 ossev.l.chn = ev->data.control.channel;
584 break;
585 }
586
587 snd_seq_oss_readq_put_timestamp(dp->readq, ev->time.tick, dp->seq_mode);
588 snd_seq_oss_readq_put_event(dp->readq, &ossev);
589
590 return 0;
591 }
592
593 /*
594 * decode event and send MIDI bytes to read queue
595 */
596 static int
send_midi_event(struct seq_oss_devinfo * dp,struct snd_seq_event * ev,struct seq_oss_midi * mdev)597 send_midi_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev, struct seq_oss_midi *mdev)
598 {
599 char msg[32];
600 int len;
601
602 snd_seq_oss_readq_put_timestamp(dp->readq, ev->time.tick, dp->seq_mode);
603 if (!dp->timer->running)
604 len = snd_seq_oss_timer_start(dp->timer);
605 if (ev->type == SNDRV_SEQ_EVENT_SYSEX) {
606 snd_seq_oss_readq_sysex(dp->readq, mdev->seq_device, ev);
607 snd_midi_event_reset_decode(mdev->coder);
608 } else {
609 len = snd_midi_event_decode(mdev->coder, msg, sizeof(msg), ev);
610 if (len > 0)
611 snd_seq_oss_readq_puts(dp->readq, mdev->seq_device, msg, len);
612 }
613
614 return 0;
615 }
616
617
618 /*
619 * dump midi data
620 * return 0 : enqueued
621 * non-zero : invalid - ignored
622 */
623 int
snd_seq_oss_midi_putc(struct seq_oss_devinfo * dp,int dev,unsigned char c,struct snd_seq_event * ev)624 snd_seq_oss_midi_putc(struct seq_oss_devinfo *dp, int dev, unsigned char c, struct snd_seq_event *ev)
625 {
626 struct seq_oss_midi *mdev;
627
628 if ((mdev = get_mididev(dp, dev)) == NULL)
629 return -ENODEV;
630 if (snd_midi_event_encode_byte(mdev->coder, c, ev)) {
631 snd_seq_oss_fill_addr(dp, ev, mdev->client, mdev->port);
632 snd_use_lock_free(&mdev->use_lock);
633 return 0;
634 }
635 snd_use_lock_free(&mdev->use_lock);
636 return -EINVAL;
637 }
638
639 /*
640 * create OSS compatible midi_info record
641 */
642 int
snd_seq_oss_midi_make_info(struct seq_oss_devinfo * dp,int dev,struct midi_info * inf)643 snd_seq_oss_midi_make_info(struct seq_oss_devinfo *dp, int dev, struct midi_info *inf)
644 {
645 struct seq_oss_midi *mdev;
646
647 if ((mdev = get_mididev(dp, dev)) == NULL)
648 return -ENXIO;
649 inf->device = dev;
650 inf->dev_type = 0; /* FIXME: ?? */
651 inf->capabilities = 0; /* FIXME: ?? */
652 strlcpy(inf->name, mdev->name, sizeof(inf->name));
653 snd_use_lock_free(&mdev->use_lock);
654 return 0;
655 }
656
657
658 #ifdef CONFIG_SND_PROC_FS
659 /*
660 * proc interface
661 */
662 static char *
capmode_str(int val)663 capmode_str(int val)
664 {
665 val &= PERM_READ|PERM_WRITE;
666 if (val == (PERM_READ|PERM_WRITE))
667 return "read/write";
668 else if (val == PERM_READ)
669 return "read";
670 else if (val == PERM_WRITE)
671 return "write";
672 else
673 return "none";
674 }
675
676 void
snd_seq_oss_midi_info_read(struct snd_info_buffer * buf)677 snd_seq_oss_midi_info_read(struct snd_info_buffer *buf)
678 {
679 int i;
680 struct seq_oss_midi *mdev;
681
682 snd_iprintf(buf, "\nNumber of MIDI devices: %d\n", max_midi_devs);
683 for (i = 0; i < max_midi_devs; i++) {
684 snd_iprintf(buf, "\nmidi %d: ", i);
685 mdev = get_mdev(i);
686 if (mdev == NULL) {
687 snd_iprintf(buf, "*empty*\n");
688 continue;
689 }
690 snd_iprintf(buf, "[%s] ALSA port %d:%d\n", mdev->name,
691 mdev->client, mdev->port);
692 snd_iprintf(buf, " capability %s / opened %s\n",
693 capmode_str(mdev->flags),
694 capmode_str(mdev->opened));
695 snd_use_lock_free(&mdev->use_lock);
696 }
697 }
698 #endif /* CONFIG_SND_PROC_FS */
699