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