2 * OSS compatible sequencer driver
4 * OSS compatible i/o control
6 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "seq_oss_device.h"
24 #include "seq_oss_readq.h"
25 #include "seq_oss_writeq.h"
26 #include "seq_oss_timer.h"
27 #include "seq_oss_synth.h"
28 #include "seq_oss_midi.h"
29 #include "seq_oss_event.h"
31 static int snd_seq_oss_synth_info_user(struct seq_oss_devinfo
*dp
, void __user
*arg
)
33 struct synth_info info
;
35 if (copy_from_user(&info
, arg
, sizeof(info
)))
37 if (snd_seq_oss_synth_make_info(dp
, info
.device
, &info
) < 0)
39 if (copy_to_user(arg
, &info
, sizeof(info
)))
44 static int snd_seq_oss_midi_info_user(struct seq_oss_devinfo
*dp
, void __user
*arg
)
46 struct midi_info info
;
48 if (copy_from_user(&info
, arg
, sizeof(info
)))
50 if (snd_seq_oss_midi_make_info(dp
, info
.device
, &info
) < 0)
52 if (copy_to_user(arg
, &info
, sizeof(info
)))
57 static int snd_seq_oss_oob_user(struct seq_oss_devinfo
*dp
, void __user
*arg
)
60 struct snd_seq_event tmpev
;
62 if (copy_from_user(ev
, arg
, 8))
64 memset(&tmpev
, 0, sizeof(tmpev
));
65 snd_seq_oss_fill_addr(dp
, &tmpev
, dp
->addr
.port
, dp
->addr
.client
);
67 if (! snd_seq_oss_process_event(dp
, (union evrec
*)ev
, &tmpev
)) {
68 snd_seq_oss_dispatch(dp
, &tmpev
, 0, 0);
74 snd_seq_oss_ioctl(struct seq_oss_devinfo
*dp
, unsigned int cmd
, unsigned long carg
)
77 void __user
*arg
= (void __user
*)carg
;
81 case SNDCTL_TMR_TIMEBASE
:
82 case SNDCTL_TMR_TEMPO
:
83 case SNDCTL_TMR_START
:
85 case SNDCTL_TMR_CONTINUE
:
86 case SNDCTL_TMR_METRONOME
:
87 case SNDCTL_TMR_SOURCE
:
88 case SNDCTL_TMR_SELECT
:
89 case SNDCTL_SEQ_CTRLRATE
:
90 return snd_seq_oss_timer_ioctl(dp
->timer
, cmd
, arg
);
92 case SNDCTL_SEQ_PANIC
:
93 snd_seq_oss_reset(dp
);
97 if (! is_write_mode(dp
->file_mode
) || dp
->writeq
== NULL
)
99 while (snd_seq_oss_writeq_sync(dp
->writeq
))
101 if (signal_pending(current
))
105 case SNDCTL_SEQ_RESET
:
106 snd_seq_oss_reset(dp
);
109 case SNDCTL_SEQ_TESTMIDI
:
110 if (get_user(dev
, p
))
112 return snd_seq_oss_midi_open(dp
, dev
, dp
->file_mode
);
114 case SNDCTL_SEQ_GETINCOUNT
:
115 if (dp
->readq
== NULL
|| ! is_read_mode(dp
->file_mode
))
117 return put_user(dp
->readq
->qlen
, p
) ? -EFAULT
: 0;
119 case SNDCTL_SEQ_GETOUTCOUNT
:
120 if (! is_write_mode(dp
->file_mode
) || dp
->writeq
== NULL
)
122 return put_user(snd_seq_oss_writeq_get_free_size(dp
->writeq
), p
) ? -EFAULT
: 0;
124 case SNDCTL_SEQ_GETTIME
:
125 return put_user(snd_seq_oss_timer_cur_tick(dp
->timer
), p
) ? -EFAULT
: 0;
127 case SNDCTL_SEQ_RESETSAMPLES
:
128 if (get_user(dev
, p
))
130 return snd_seq_oss_synth_ioctl(dp
, dev
, cmd
, carg
);
132 case SNDCTL_SEQ_NRSYNTHS
:
133 return put_user(dp
->max_synthdev
, p
) ? -EFAULT
: 0;
135 case SNDCTL_SEQ_NRMIDIS
:
136 return put_user(dp
->max_mididev
, p
) ? -EFAULT
: 0;
138 case SNDCTL_SYNTH_MEMAVL
:
139 if (get_user(dev
, p
))
141 val
= snd_seq_oss_synth_ioctl(dp
, dev
, cmd
, carg
);
142 return put_user(val
, p
) ? -EFAULT
: 0;
144 case SNDCTL_FM_4OP_ENABLE
:
145 if (get_user(dev
, p
))
147 snd_seq_oss_synth_ioctl(dp
, dev
, cmd
, carg
);
150 case SNDCTL_SYNTH_INFO
:
151 case SNDCTL_SYNTH_ID
:
152 return snd_seq_oss_synth_info_user(dp
, arg
);
154 case SNDCTL_SEQ_OUTOFBAND
:
155 return snd_seq_oss_oob_user(dp
, arg
);
157 case SNDCTL_MIDI_INFO
:
158 return snd_seq_oss_midi_info_user(dp
, arg
);
160 case SNDCTL_SEQ_THRESHOLD
:
161 if (! is_write_mode(dp
->file_mode
))
163 if (get_user(val
, p
))
167 if (val
>= dp
->writeq
->maxlen
)
168 val
= dp
->writeq
->maxlen
- 1;
169 snd_seq_oss_writeq_set_output(dp
->writeq
, val
);
172 case SNDCTL_MIDI_PRETIME
:
173 if (dp
->readq
== NULL
|| !is_read_mode(dp
->file_mode
))
175 if (get_user(val
, p
))
180 val
= (HZ
* val
) / 10;
181 dp
->readq
->pre_event_timeout
= val
;
182 return put_user(val
, p
) ? -EFAULT
: 0;
185 if (! is_write_mode(dp
->file_mode
))
187 return snd_seq_oss_synth_ioctl(dp
, 0, cmd
, carg
);