1 /*
2 * Include file for midi sequencer driver.
3 *
4 * Copyright by Seigo Tanimura 1999.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: releng/5.0/sys/dev/sound/midi/sequencer.h 88869 2002-01-04 01:13:49Z tanimura $
28 *
29 */
30
31 /*
32 * first, include kernel header files.
33 */
34
35 #ifndef _SEQUENCER_H_
36 #define _SEQUENCER_H_
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/ioccom.h>
41
42 #include <sys/filio.h>
43 #include <sys/sockio.h>
44 #include <sys/fcntl.h>
45 #include <sys/tty.h>
46 #include <sys/proc.h>
47
48 #include <sys/kernel.h> /* for DATA_SET */
49
50 #include <sys/conf.h>
51 #include <sys/file.h>
52 #include <sys/uio.h>
53 #include <sys/syslog.h>
54 #include <sys/errno.h>
55 #include <sys/malloc.h>
56 #include <sys/condvar.h>
57 #include <machine/clock.h> /* for DELAY */
58 #include <sys/soundcard.h>
59
60 #include <dev/sound/midi/timer.h>
61
62 #define SEQ_CDEV_MAJOR MIDI_CDEV_MAJOR
63
64 /*
65 * the following assumes that FreeBSD 3.X uses poll(2) instead of select(2).
66 * This change dates to late 1997.
67 */
68 #include <sys/poll.h>
69 #define d_select_t d_poll_t
70
71 /* Return value from seq_playevent and timer event handers. */
72 enum {
73 MORE,
74 TIMERARMED,
75 QUEUEFULL
76 };
77
78 typedef struct _seqdev_info seqdev_info;
79
80 /*
81 * The order of mutex lock (from the first to the last)
82 *
83 * 1. sequencer flags, queues, timer and device list
84 * 2. midi synth voice and channel
85 * 3. midi synth status
86 * 4. generic midi flags and queues
87 * 5. midi device
88 */
89
90 /*
91 * descriptor of sequencer operations ...
92 *
93 */
94
95 struct _seqdev_info {
96
97 /*
98 * the first part of the descriptor is filled up from a
99 * template.
100 */
101 char name[64];
102
103 int type ;
104
105 d_open_t *open;
106 d_close_t *close;
107 d_read_t *read;
108 d_write_t *write;
109 d_ioctl_t *ioctl;
110 d_poll_t *poll;
111 midi_callback_t *callback;
112
113 /*
114 * combinations of the following flags are used as second argument in
115 * the callback from the dma module to the device-specific routines.
116 */
117
118 #define SEQ_CB_RD 0x100 /* read callback */
119 #define SEQ_CB_WR 0x200 /* write callback */
120 #define SEQ_CB_REASON_MASK 0xff
121 #define SEQ_CB_START 0x01 /* start dma op */
122 #define SEQ_CB_STOP 0x03 /* stop dma op */
123 #define SEQ_CB_ABORT 0x04 /* abort dma op */
124 #define SEQ_CB_INIT 0x05 /* init board parameters */
125
126 /*
127 * callback extensions
128 */
129 #define SEQ_CB_DMADONE 0x10
130 #define SEQ_CB_DMAUPDATE 0x11
131 #define SEQ_CB_DMASTOP 0x12
132
133 /* init can only be called with int enabled and
134 * no pending DMA activity.
135 */
136
137 /*
138 * whereas from here, parameters are set at runtime.
139 * io_base == 0 means that the board is not configured.
140 */
141
142 int unit; /* unit number of the device */
143 void *softc; /* softc for a device */
144
145 int bd_id ; /* used to hold board-id info, eg. sb version,
146 * mss codec type, etc. etc.
147 */
148
149 struct mtx flagqueue_mtx; /* Mutex to protect flags and queues */
150 struct cv insync_cv; /* Conditional variable for sync */
151
152 /* Queues */
153 midi_dbuf midi_dbuf_in; /* midi input event/message queue */
154 midi_dbuf midi_dbuf_out; /* midi output event/message queue */
155
156
157 /*
158 * these parameters describe the operation of the board.
159 * Generic things like busy flag, speed, etc are here.
160 */
161
162 /* Flags */
163 volatile u_long flags ; /* 32 bits, used for various purposes. */
164
165 /*
166 * we have separate flags for read and write, although in some
167 * cases this is probably not necessary (e.g. because we cannot
168 * know how many processes are using the device, we cannot
169 * distinguish if open, close, abort are for a write or for a
170 * read).
171 */
172
173 /*
174 * the following flag is used by open-close routines
175 * to mark the status of the device.
176 */
177 #define SEQ_F_BUSY 0x0001 /* has been opened */
178 /*
179 * the next two are used to allow only one pending operation of
180 * each type.
181 */
182 #define SEQ_F_READING 0x0004 /* have a pending read */
183 #define SEQ_F_WRITING 0x0008 /* have a pending write */
184
185 /*
186 * flag used to mark a pending close.
187 */
188 #define SEQ_F_CLOSING 0x0040 /* a pending close */
189
190 /*
191 * if user has not set block size, then make it adaptive
192 * (0.25s, or the perhaps last read/write ?)
193 */
194 #define SEQ_F_HAS_SIZE 0x0080 /* user set block size */
195 /*
196 * assorted flags related to operating mode.
197 */
198 #define SEQ_F_STEREO 0x0100 /* doing stereo */
199 #define SEQ_F_NBIO 0x0200 /* do non-blocking i/o */
200
201 /*
202 * these flags mark a pending abort on a r/w operation.
203 */
204 #define SEQ_F_ABORTING 0x1000 /* a pending abort */
205
206 /*
207 * this is used to mark that board initialization is needed, e.g.
208 * because of a change in sampling rate, format, etc. -- It will
209 * be done at the next convenient time.
210 */
211 #define SEQ_F_INIT 0x4000 /* changed parameters. need init */
212
213 #define SEQ_F_INSYNC 0x8000 /* a pending sync */
214
215 int play_blocksize, rec_blocksize; /* blocksize for io and dma ops */
216
217 #define swsel midi_dbuf_out.sel
218 #define srsel midi_dbuf_in.sel
219 u_long interrupts; /* counter of interrupts */
220 u_long magic;
221 #define MAGIC(unit) ( 0xa4d10de0 + unit )
222 void *device_data ; /* just in case it is needed...*/
223
224 /* The tailq entry of the next sequencer device. */
225 TAILQ_ENTRY(_seqdev_info) sd_link;
226 };
227
228
229 /*
230 * then ioctls and other stuff
231 */
232 #define NSEQ_MAX 16 /* Number of supported devices */
233
234 /*
235 * many variables should be reduced to a range. Here define a macro
236 */
237
238 #define RANGE(var, low, high) (var) = \
239 ((var)<(low)?(low) : (var)>(high)?(high) : (var))
240
241 /*
242 * finally, all default parameters
243 */
244 #define SEQ_BUFFSIZE (1024) /* XXX */
245
246 #define MIDI_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
247 synthesizer and MIDI output) */
248 #define MIDI_DEV_MUSIC 8 /* Sequencer output /dev/music (FM
249 synthesizer and MIDI output) */
250
251 #ifdef _KERNEL
252
253 extern midi_cmdtab cmdtab_seqioctl[];
254 extern midi_cmdtab cmdtab_timer[];
255
256 void seq_timer(void *arg);
257 int seq_copytoinput(void *arg, u_char *event, int len);
258
259 SYSCTL_DECL(_hw_midi_seq);
260
261 extern int seq_debug;
262 #define SEQ_DEBUG(x) \
263 do { \
264 if (seq_debug) { \
265 (x); \
266 } \
267 } while(0)
268
269 #endif /* _KERNEL */
270
271
272 #endif /* _SEQUENCER_H_ */
Cache object: 2acf7d6eb2ac729a7c6c0f50766cdb46
|