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