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$ 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 #define SEQ_CDEV_MAJOR MIDI_CDEV_MAJOR 61 62 /* 63 * the following assumes that FreeBSD 3.X uses poll(2) instead of select(2). 64 * This change dates to late 1997. 65 */ 66 #include <sys/poll.h> 67 #define d_select_t d_poll_t 68 69 typedef struct _seqdev_info seqdev_info; 70 71 typedef int (seq_callback_t)(seqdev_info *sd, int reason); 72 73 /* 74 * The order of mutex lock (from the first to the last) 75 * 76 * 1. sequencer flags, queues, timer and device list 77 * 2. midi synth voice and channel 78 * 3. midi synth status 79 * 4. generic midi flags and queues 80 * 5. midi device 81 */ 82 83 /* 84 * descriptor of sequencer operations ... 85 * 86 */ 87 88 struct _seqdev_info { 89 90 /* 91 * the first part of the descriptor is filled up from a 92 * template. 93 */ 94 char name[64]; 95 96 int type ; 97 98 d_open_t *open; 99 d_close_t *close; 100 d_read_t *read; 101 d_write_t *write; 102 d_ioctl_t *ioctl; 103 d_poll_t *poll; 104 seq_callback_t *callback; 105 106 /* 107 * combinations of the following flags are used as second argument in 108 * the callback from the dma module to the device-specific routines. 109 */ 110 111 #define SEQ_CB_RD 0x100 /* read callback */ 112 #define SEQ_CB_WR 0x200 /* write callback */ 113 #define SEQ_CB_REASON_MASK 0xff 114 #define SEQ_CB_START 0x01 /* start dma op */ 115 #define SEQ_CB_STOP 0x03 /* stop dma op */ 116 #define SEQ_CB_ABORT 0x04 /* abort dma op */ 117 #define SEQ_CB_INIT 0x05 /* init board parameters */ 118 119 /* 120 * callback extensions 121 */ 122 #define SEQ_CB_DMADONE 0x10 123 #define SEQ_CB_DMAUPDATE 0x11 124 #define SEQ_CB_DMASTOP 0x12 125 126 /* init can only be called with int enabled and 127 * no pending DMA activity. 128 */ 129 130 /* 131 * whereas from here, parameters are set at runtime. 132 * io_base == 0 means that the board is not configured. 133 */ 134 135 int unit; /* unit number of the device */ 136 void *softc; /* softc for a device */ 137 138 int bd_id ; /* used to hold board-id info, eg. sb version, 139 * mss codec type, etc. etc. 140 */ 141 142 struct mtx flagqueue_mtx; /* Mutex to protect flags and queues */ 143 struct cv insync_cv; /* Conditional variable for sync */ 144 145 /* Queues */ 146 midi_dbuf midi_dbuf_in; /* midi input event/message queue */ 147 midi_dbuf midi_dbuf_out; /* midi output event/message queue */ 148 149 150 /* 151 * these parameters describe the operation of the board. 152 * Generic things like busy flag, speed, etc are here. 153 */ 154 155 /* Flags */ 156 volatile u_long flags ; /* 32 bits, used for various purposes. */ 157 158 /* 159 * we have separate flags for read and write, although in some 160 * cases this is probably not necessary (e.g. because we cannot 161 * know how many processes are using the device, we cannot 162 * distinguish if open, close, abort are for a write or for a 163 * read). 164 */ 165 166 /* 167 * the following flag is used by open-close routines 168 * to mark the status of the device. 169 */ 170 #define SEQ_F_BUSY 0x0001 /* has been opened */ 171 /* 172 * the next two are used to allow only one pending operation of 173 * each type. 174 */ 175 #define SEQ_F_READING 0x0004 /* have a pending read */ 176 #define SEQ_F_WRITING 0x0008 /* have a pending write */ 177 178 /* 179 * flag used to mark a pending close. 180 */ 181 #define SEQ_F_CLOSING 0x0040 /* a pending close */ 182 183 /* 184 * if user has not set block size, then make it adaptive 185 * (0.25s, or the perhaps last read/write ?) 186 */ 187 #define SEQ_F_HAS_SIZE 0x0080 /* user set block size */ 188 /* 189 * assorted flags related to operating mode. 190 */ 191 #define SEQ_F_STEREO 0x0100 /* doing stereo */ 192 #define SEQ_F_NBIO 0x0200 /* do non-blocking i/o */ 193 194 /* 195 * these flags mark a pending abort on a r/w operation. 196 */ 197 #define SEQ_F_ABORTING 0x1000 /* a pending abort */ 198 199 /* 200 * this is used to mark that board initialization is needed, e.g. 201 * because of a change in sampling rate, format, etc. -- It will 202 * be done at the next convenient time. 203 */ 204 #define SEQ_F_INIT 0x4000 /* changed parameters. need init */ 205 206 #define SEQ_F_INSYNC 0x8000 /* a pending sync */ 207 208 int play_blocksize, rec_blocksize; /* blocksize for io and dma ops */ 209 210 #define swsel midi_dbuf_out.sel 211 #define srsel midi_dbuf_in.sel 212 u_long interrupts; /* counter of interrupts */ 213 u_long magic; 214 #define MAGIC(unit) ( 0xa4d10de0 + unit ) 215 void *device_data ; /* just in case it is needed...*/ 216 217 /* The tailq entry of the next sequencer device. */ 218 TAILQ_ENTRY(_seqdev_info) sd_link; 219 } ; 220 221 222 /* 223 * then ioctls and other stuff 224 */ 225 #define NSEQ_MAX 16 /* Number of supported devices */ 226 227 /* 228 * many variables should be reduced to a range. Here define a macro 229 */ 230 231 #define RANGE(var, low, high) (var) = \ 232 ((var)<(low)?(low) : (var)>(high)?(high) : (var)) 233 234 /* 235 * finally, all default parameters 236 */ 237 #define SEQ_BUFFSIZE (4 * 1024) /* XXX */ 238 239 /* 240 * some macros for debugging purposes 241 * DDB/DEB to enable/disable debugging stuff 242 * BVDDB to enable debugging when bootverbose 243 */ 244 #define DDB(x) x /* XXX */ 245 #define BVDDB(x) if (bootverbose) x 246 247 #ifndef DEB 248 #define DEB(x) 249 #endif 250 251 #define MIDI_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM 252 synthesizer and MIDI output) */ 253 254 #endif /* _SEQUENCER_H_ */ 255