ppbus_msq.h revision 1.1 1 /*-
2 * Copyright (c) 1998 Nicolas Souchu
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: src/sys/dev/ppbus/ppb_msq.h,v 1.8 2000/01/14 00:17:55 nsouch Exp $
27 *
28 */
29 #ifndef __PPBUS_MSQ_H
30 #define __PPBUS_MSQ_H
31
32
33 /*
34 * Basic definitions
35 */
36
37 /* Microsequence stuff. */
38 #define PPBUS_MS_MAXLEN 64 /* XXX according to MS_INS_MASK */
39 #define PPBUS_MS_MAXARGS 3 /* according to MS_ARG_MASK */
40
41 /* Maximum number of mode dependent submicrosequences for in/out operations. */
42 #define PPBUS_MAX_XFER 6
43
44 /* Argument in microsequence structure */
45 union ppbus_insarg {
46 int i;
47 void *p;
48 char *c;
49 int (* f)(void *, char *);
50 };
51
52 /* Microsequence structure */
53 struct ppbus_microseq {
54 int opcode; /* microins. opcode */
55 union ppbus_insarg arg[PPBUS_MS_MAXARGS]; /* arguments */
56 };
57
58 /* Microseqences used for GET/PUT operations */
59 struct ppbus_xfer {
60 struct ppbus_microseq *loop; /* the loop microsequence */
61 };
62
63 /* microsequence parameter descriptor */
64 #define MS_INS_MASK 0x00ff /* mask to retrieve the instruction position < 256 XXX */
65 #define MS_ARG_MASK 0x0f00 /* mask to retrieve the argument number */
66 #define MS_TYP_MASK 0xf000 /* mask to retrieve the type of the param */
67
68 /* offset of each mask (see above) */
69 #define MS_INS_OFFSET 0
70 #define MS_ARG_OFFSET 8
71 #define MS_TYP_OFFSET 12
72
73 /* list of parameter types */
74 #define MS_TYP_INT 0x0 /* integer */
75 #define MS_TYP_CHA 0x1 /* character */
76 #define MS_TYP_PTR 0x2 /* void pointer */
77 #define MS_TYP_FUN 0x3 /* function pointer */
78
79 #define MS_PARAM(ins,arg,typ) \
80 (((ins<<MS_INS_OFFSET) & MS_INS_MASK) | \
81 ((arg<<MS_ARG_OFFSET) & MS_ARG_MASK) | \
82 ((typ<<MS_TYP_OFFSET) & MS_TYP_MASK))
83
84 #define MS_INS(param) ((param & MS_INS_MASK) >> MS_INS_OFFSET)
85 #define MS_ARG(param) ((param & MS_ARG_MASK) >> MS_ARG_OFFSET)
86 #define MS_TYP(param) ((param & MS_TYP_MASK) >> MS_TYP_OFFSET)
87
88 /* microsequence opcodes - do not change! */
89 #define MS_OP_GET 0 /* get <ptr>, <len> */
90 #define MS_OP_PUT 1 /* put <ptr>, <len> */
91
92 #define MS_OP_RFETCH 2 /* rfetch <reg>, <mask>, <ptr> */
93 #define MS_OP_RSET 3 /* rset <reg>, <mask>, <mask> */
94 #define MS_OP_RASSERT 4 /* rassert <reg>, <mask> */
95 #define MS_OP_DELAY 5 /* delay <val> */
96 #define MS_OP_SET 6 /* set <val> */
97 #define MS_OP_DBRA 7 /* dbra <offset> */
98 #define MS_OP_BRSET 8 /* brset <mask>, <offset> */
99 #define MS_OP_BRCLEAR 9 /* brclear <mask>, <offset> */
100 #define MS_OP_RET 10 /* ret <retcode> */
101 #define MS_OP_C_CALL 11 /* c_call <function>, <parameter> */
102 #define MS_OP_PTR 12 /* ptr <pointer> */
103 #define MS_OP_ADELAY 13 /* adelay <val> */
104 #define MS_OP_BRSTAT 14 /* brstat <mask>, <mask>, <offset> */
105 #define MS_OP_SUBRET 15 /* subret <code> */
106 #define MS_OP_CALL 16 /* call <microsequence> */
107 #define MS_OP_RASSERT_P 17 /* rassert_p <iter>, <reg> */
108 #define MS_OP_RFETCH_P 18 /* rfetch_p <iter>, <reg>, <mask> */
109 #define MS_OP_TRIG 19 /* trigger <reg>, <len>, <array> */
110
111 /* common masks */
112 #define MS_CLEAR_ALL 0x0
113 #define MS_ASSERT_NONE 0x0
114 #define MS_ASSERT_ALL 0xff
115 #define MS_FETCH_ALL 0xff
116
117 /* undefined parameter value */
118 #define MS_NULL 0
119 #define MS_UNKNOWN MS_NULL
120
121 /* predifined parameters */
122 #define MS_ACCUM -1 /* use accum previously set by MS_OP_SET */
123
124 /* these are register numbers according to our PC-like parallel port model */
125 #define MS_REG_DTR 0x0
126 #define MS_REG_STR 0x1
127 #define MS_REG_CTR 0x2
128 #define MS_REG_EPP_A 0x3
129 #define MS_REG_EPP_D 0x4
130
131 /*
132 * Microsequence macro abstraction level
133 */
134
135 /* register operations */
136 #define MS_RSET(reg,assert,clear) { MS_OP_RSET, {{ reg }, { assert }, { clear }}}
137 #define MS_RASSERT(reg,byte) { MS_OP_RASSERT, { { reg }, { byte }}}
138 #define MS_RCLR(reg,clear) { MS_OP_RSET, {{ reg }, { MS_ASSERT_NONE }, { clear }}}
139
140 #define MS_RFETCH(reg,mask,ptr) { MS_OP_RFETCH, {{ reg }, { mask }, { ptr }}}
141
142 /* trigger the port with array[char, delay,...] */
143 #define MS_TRIG(reg,len,array) { MS_OP_TRIG, {{ reg }, { len }, { array }}}
144
145 /* assert/fetch from/to ptr */
146 #define MS_RASSERT_P(n,reg) { MS_OP_RASSERT_P, {{ n }, { reg }}}
147 #define MS_RFETCH_P(n,reg,mask) { MS_OP_RFETCH_P, {{ n }, { reg }, { mask }}}
148
149 /* ptr manipulation */
150 #define MS_PTR(ptr) { MS_OP_PTR, {{ ptr }}}
151
152 #define MS_DASS(byte) MS_RASSERT(MS_REG_DTR,byte)
153 #define MS_SASS(byte) MS_RASSERT(MS_REG_STR,byte)
154 #define MS_CASS(byte) MS_RASSERT(MS_REG_CTR,byte)
155
156 #define MS_SET(accum) { MS_OP_SET, {{ accum }}}
157 #define MS_BRSET(mask,offset) { MS_OP_BRSET, {{ mask }, { offset }}}
158 #define MS_DBRA(offset) { MS_OP_DBRA, {{ offset }}}
159 #define MS_BRCLEAR(mask,offset) { MS_OP_BRCLEAR, {{ mask }, { offset }}}
160 #define MS_BRSTAT(mask_set,mask_clr,offset) \
161 { MS_OP_BRSTAT, {{ mask_set }, { mask_clr }, { offset }}}
162
163 /* C function or submicrosequence call */
164 #define MS_C_CALL(function,parameter) \
165 { MS_OP_C_CALL, {{ function }, { parameter }}}
166 #define MS_CALL(microseq) { MS_OP_CALL, {{ microseq }}}
167
168 /* mode dependent read/write operations
169 * ppb_MS_xxx_init() call required otherwise default is
170 * IEEE1284 operating mode */
171 #define MS_PUT(ptr,len) { MS_OP_PUT, {{ ptr }, { len }}}
172 #define MS_GET(ptr,len) { MS_OP_GET, {{ ptr }, { len }}}
173
174 /* delay in microseconds */
175 #define MS_DELAY(udelay) { MS_OP_DELAY, {{ udelay }}}
176
177 /* asynchroneous delay in ms */
178 #define MS_ADELAY(mdelay) { MS_OP_ADELAY, {{ mdelay }}}
179
180 /* return from submicrosequence execution or microseqence execution */
181 #define MS_SUBRET(code) { MS_OP_SUBRET, {{ code }}}
182 #define MS_RET(code) { MS_OP_RET, {{ code }}}
183
184 #ifdef _KERNEL
185
186 /*
187 * Function abstraction level
188 */
189
190 #define ppbus_MS_GET_init(bus,dev,body) ppbus_MS_init(bus, dev, body, MS_OP_GET)
191
192 #define ppbus_MS_PUT_init(bus,dev,body) ppbus_MS_init(bus, dev, body, MS_OP_PUT)
193
194 /* Function prototypes */
195 int ppbus_MS_init(
196 struct device *, /* ppbus bus */
197 struct device *, /* ppbus device */
198 struct ppbus_microseq *, /* loop msq to assign */
199 int opcode /* MS_OP_GET, MS_OP_PUT */
200 );
201
202 int ppbus_MS_init_msq(
203 struct ppbus_microseq *,
204 int, /* number of parameters */
205 ... /* descriptor, value, ... */
206 );
207
208 int ppbus_MS_exec(
209 struct device *, /* ppbus bus */
210 struct device *, /* ppbus device */
211 int, /* microseq opcode */
212 union ppbus_insarg, /* param1 */
213 union ppbus_insarg, /* param2 */
214 union ppbus_insarg, /* param3 */
215 int * /* returned value */
216 );
217
218 int ppbus_MS_loop(
219 struct device *, /* ppbus bus */
220 struct device *, /* ppbus device */
221 struct ppbus_microseq *, /* prologue msq of loop */
222 struct ppbus_microseq *, /* body msq of loop */
223 struct ppbus_microseq *, /* epilogue msq of loop */
224 int, /* number of iter */
225 int * /* returned value */
226 );
227
228 int ppbus_MS_microseq(
229 struct device *, /* ppbus bus */
230 struct device *, /* ppbus device */
231 struct ppbus_microseq *, /* msq to execute */
232 int * /* returned value */
233 );
234
235 #endif /* _KERNEL */
236
237 #endif /* __PPBUS_MSQ_H */
238