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