patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / core / seq / oss / seq_oss_ioctl.c
1 /*
2  * OSS compatible sequencer driver
3  *
4  * OSS compatible i/o control
5  *
6  * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
7  *
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.
12  *
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.
17  *
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
21  */
22
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"
30
31 int
32 snd_seq_oss_ioctl(seq_oss_devinfo_t *dp, unsigned int cmd, unsigned long carg)
33 {
34         int dev, val;
35         struct synth_info inf;
36         struct midi_info minf;
37         unsigned char ev[8];
38         void __user *arg = (void __user *)carg;
39         int __user *p = arg;
40         snd_seq_event_t tmpev;
41
42         switch (cmd) {
43         case SNDCTL_TMR_TIMEBASE:
44         case SNDCTL_TMR_TEMPO:
45         case SNDCTL_TMR_START:
46         case SNDCTL_TMR_STOP:
47         case SNDCTL_TMR_CONTINUE:
48         case SNDCTL_TMR_METRONOME:
49         case SNDCTL_TMR_SOURCE:
50         case SNDCTL_TMR_SELECT:
51         case SNDCTL_SEQ_CTRLRATE:
52                 return snd_seq_oss_timer_ioctl(dp->timer, cmd, arg);
53
54         case SNDCTL_SEQ_PANIC:
55                 debug_printk(("panic\n"));
56                 snd_seq_oss_reset(dp);
57                 return -EINVAL;
58
59         case SNDCTL_SEQ_SYNC:
60                 debug_printk(("sync\n"));
61                 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
62                         return 0;
63                 while (snd_seq_oss_writeq_sync(dp->writeq))
64                         ;
65                 if (signal_pending(current))
66                         return -ERESTARTSYS;
67                 return 0;
68
69         case SNDCTL_SEQ_RESET:
70                 debug_printk(("reset\n"));
71                 snd_seq_oss_reset(dp);
72                 return 0;
73
74         case SNDCTL_SEQ_TESTMIDI:
75                 debug_printk(("test midi\n"));
76                 if (get_user(dev, p))
77                         return -EFAULT;
78                 return snd_seq_oss_midi_open(dp, dev, dp->file_mode);
79
80         case SNDCTL_SEQ_GETINCOUNT:
81                 debug_printk(("get in count\n"));
82                 if (dp->readq == NULL || ! is_read_mode(dp->file_mode))
83                         return 0;
84                 return put_user(dp->readq->qlen, p) ? -EFAULT : 0;
85
86         case SNDCTL_SEQ_GETOUTCOUNT:
87                 debug_printk(("get out count\n"));
88                 if (! is_write_mode(dp->file_mode) || dp->writeq == NULL)
89                         return 0;
90                 return put_user(snd_seq_oss_writeq_get_free_size(dp->writeq), p) ? -EFAULT : 0;
91
92         case SNDCTL_SEQ_GETTIME:
93                 debug_printk(("get time\n"));
94                 return put_user(snd_seq_oss_timer_cur_tick(dp->timer), p) ? -EFAULT : 0;
95
96         case SNDCTL_SEQ_RESETSAMPLES:
97                 debug_printk(("reset samples\n"));
98                 if (get_user(dev, p))
99                         return -EFAULT;
100                 return snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
101
102         case SNDCTL_SEQ_NRSYNTHS:
103                 debug_printk(("nr synths\n"));
104                 return put_user(dp->max_synthdev, p) ? -EFAULT : 0;
105
106         case SNDCTL_SEQ_NRMIDIS:
107                 debug_printk(("nr midis\n"));
108                 return put_user(dp->max_mididev, p) ? -EFAULT : 0;
109
110         case SNDCTL_SYNTH_MEMAVL:
111                 debug_printk(("mem avail\n"));
112                 if (get_user(dev, p))
113                         return -EFAULT;
114                 val = snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
115                 return put_user(val, p) ? -EFAULT : 0;
116
117         case SNDCTL_FM_4OP_ENABLE:
118                 debug_printk(("4op\n"));
119                 if (get_user(dev, p))
120                         return -EFAULT;
121                 snd_seq_oss_synth_ioctl(dp, dev, cmd, carg);
122                 return 0;
123
124         case SNDCTL_SYNTH_INFO:
125         case SNDCTL_SYNTH_ID:
126                 debug_printk(("synth info\n"));
127                 if (copy_from_user(&inf, arg, sizeof(inf)))
128                         return -EFAULT;
129                 if (snd_seq_oss_synth_make_info(dp, inf.device, &inf) < 0)
130                         return -EINVAL;
131                 if (copy_to_user(arg, &inf, sizeof(inf)))
132                         return -EFAULT;
133                 return 0;
134
135         case SNDCTL_SEQ_OUTOFBAND:
136                 debug_printk(("out of bound\n"));
137                 if (copy_from_user(ev, arg, 8))
138                         return -EFAULT;
139                 memset(&tmpev, 0, sizeof(tmpev));
140                 snd_seq_oss_fill_addr(dp, &tmpev, dp->addr.port, dp->addr.client);
141                 tmpev.time.tick = 0;
142                 if (! snd_seq_oss_process_event(dp, (evrec_t*)ev, &tmpev)) {
143                         snd_seq_oss_dispatch(dp, &tmpev, 0, 0);
144                 }
145                 return 0;
146
147         case SNDCTL_MIDI_INFO:
148                 debug_printk(("midi info\n"));
149                 if (copy_from_user(&minf, arg, sizeof(minf)))
150                         return -EFAULT;
151                 if (snd_seq_oss_midi_make_info(dp, minf.device, &minf) < 0)
152                         return -EINVAL;
153                 if (copy_to_user(arg, &minf, sizeof(minf)))
154                         return -EFAULT;
155                 return 0;
156
157         case SNDCTL_SEQ_THRESHOLD:
158                 debug_printk(("threshold\n"));
159                 if (! is_write_mode(dp->file_mode))
160                         return 0;
161                 if (get_user(val, p))
162                         return -EFAULT;
163                 if (val < 1)
164                         val = 1;
165                 if (val >= dp->writeq->maxlen)
166                         val = dp->writeq->maxlen - 1;
167                 snd_seq_oss_writeq_set_output(dp->writeq, val);
168                 return 0;
169
170         case SNDCTL_MIDI_PRETIME:
171                 debug_printk(("pretime\n"));
172                 if (dp->readq == NULL || !is_read_mode(dp->file_mode))
173                         return 0;
174                 if (get_user(val, p))
175                         return -EFAULT;
176                 if (val <= 0)
177                         val = -1;
178                 else
179                         val = (HZ * val) / 10;
180                 dp->readq->pre_event_timeout = val;
181                 return put_user(val, p) ? -EFAULT : 0;
182
183         default:
184                 debug_printk(("others\n"));
185                 if (! is_write_mode(dp->file_mode))
186                         return -EIO;
187                 return snd_seq_oss_synth_ioctl(dp, 0, cmd, carg);
188         }
189         return 0;
190 }
191