1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * OSS compatible sequencer driver
5 * OSS compatible i/o control
7 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
10 #include "seq_oss_device.h"
11 #include "seq_oss_readq.h"
12 #include "seq_oss_writeq.h"
13 #include "seq_oss_timer.h"
14 #include "seq_oss_synth.h"
15 #include "seq_oss_midi.h"
16 #include "seq_oss_event.h"
18 static int snd_seq_oss_synth_info_user(struct seq_oss_devinfo *dp, void __user *arg)
20 struct synth_info info;
22 if (copy_from_user(&info, arg, sizeof(info)))
24 if (snd_seq_oss_synth_make_info(dp, info.device, &info) < 0)
26 if (copy_to_user(arg, &info, sizeof(info)))
31 static int snd_seq_oss_midi_info_user(struct seq_oss_devinfo *dp, void __user *arg)
33 struct midi_info info;
35 if (copy_from_user(&info, arg, sizeof(info)))
37 if (snd_seq_oss_midi_make_info(dp, info.device, &info) < 0)
39 if (copy_to_user(arg, &info, sizeof(info)))
44 static int snd_seq_oss_oob_user(struct seq_oss_devinfo *dp, void __user *arg)
47 struct snd_seq_event tmpev;
49 if (copy_from_user(ev, arg, 8))
51 memset(&tmpev, 0, sizeof(tmpev));
52 snd_seq_oss_fill_addr(dp, &tmpev, dp->addr.client, dp->addr.port);
54 if (! snd_seq_oss_process_event(dp, (union evrec *)ev, &tmpev)) {
55 snd_seq_oss_dispatch(dp, &tmpev, 0, 0);
61 snd_seq_oss_ioctl(struct seq_oss_devinfo *dp, unsigned int cmd, unsigned long carg)
64 void __user *arg = (void __user *)carg;
68 case SNDCTL_TMR_TIMEBASE:
69 case SNDCTL_TMR_TEMPO:
70 case SNDCTL_TMR_START:
72 case SNDCTL_TMR_CONTINUE:
73 case SNDCTL_TMR_METRONOME:
74 case SNDCTL_TMR_SOURCE:
75 case SNDCTL_TMR_SELECT:
76 case SNDCTL_SEQ_CTRLRATE:
77 return snd_seq_oss_timer_ioctl(dp->timer, cmd, arg);
79 case SNDCTL_SEQ_PANIC:
80 snd_seq_oss_reset(dp);
84 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
86 while (snd_seq_oss_writeq_sync(dp->writeq))
88 if (signal_pending(current))
92 case SNDCTL_SEQ_RESET:
93 snd_seq_oss_reset(dp);
96 case SNDCTL_SEQ_TESTMIDI:
99 return snd_seq_oss_midi_open(dp, dev, dp->file_mode);
101 case SNDCTL_SEQ_GETINCOUNT:
102 if (dp->readq == NULL || ! is_read_mode(dp->file_mode))
104 return put_user(dp->readq->qlen, p) ? -EFAULT : 0;
106 case SNDCTL_SEQ_GETOUTCOUNT:
107 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
109 return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0;
111 case SNDCTL_SEQ_GETTIME:
112 return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0;
114 case SNDCTL_SEQ_RESETSAMPLES:
115 if (get_user(dev, p))
117 return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
119 case SNDCTL_SEQ_NRSYNTHS:
120 return put_user(dp->max_synthdev, p) ? -EFAULT : 0;
122 case SNDCTL_SEQ_NRMIDIS:
123 return put_user(dp->max_mididev, p) ? -EFAULT : 0;
125 case SNDCTL_SYNTH_MEMAVL:
126 if (get_user(dev, p))
128 val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
129 return put_user(val, p) ? -EFAULT : 0;
131 case SNDCTL_FM_4OP_ENABLE:
132 if (get_user(dev, p))
134 snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
137 case SNDCTL_SYNTH_INFO:
138 case SNDCTL_SYNTH_ID:
139 return snd_seq_oss_synth_info_user(dp, arg);
141 case SNDCTL_SEQ_OUTOFBAND:
142 return snd_seq_oss_oob_user(dp, arg);
144 case SNDCTL_MIDI_INFO:
145 return snd_seq_oss_midi_info_user(dp, arg);
147 case SNDCTL_SEQ_THRESHOLD:
148 if (! is_write_mode(dp->file_mode))
150 if (get_user(val, p))
154 if (val >= dp->writeq->maxlen)
155 val = dp->writeq->maxlen - 1;
156 snd_seq_oss_writeq_set_output(dp->writeq, val);
159 case SNDCTL_MIDI_PRETIME:
160 if (dp->readq == NULL || !is_read_mode(dp->file_mode))
162 if (get_user(val, p))
167 val = (HZ * val) / 10;
168 dp->readq->pre_event_timeout = val;
169 return put_user(val, p) ? -EFAULT : 0;
172 if (! is_write_mode(dp->file_mode))
174 return snd_seq_oss_synth_ioctl(dp, 0, cmd, carg);