138061Smsmith/*-
238061Smsmith * Copyright (c) 1998 Nicolas Souchu
338061Smsmith * All rights reserved.
438061Smsmith *
538061Smsmith * Redistribution and use in source and binary forms, with or without
638061Smsmith * modification, are permitted provided that the following conditions
738061Smsmith * are met:
838061Smsmith * 1. Redistributions of source code must retain the above copyright
938061Smsmith *    notice, this list of conditions and the following disclaimer.
1038061Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1138061Smsmith *    notice, this list of conditions and the following disclaimer in the
1238061Smsmith *    documentation and/or other materials provided with the distribution.
1338061Smsmith *
1438061Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1538061Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1638061Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1738061Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1838061Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1938061Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2038061Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2138061Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2238061Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2338061Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2438061Smsmith * SUCH DAMAGE.
2538061Smsmith *
2650477Speter * $FreeBSD$
2738061Smsmith *
2838061Smsmith */
2938061Smsmith#ifndef __PPB_MSQ_H
3038061Smsmith#define __PPB_MSQ_H
3138061Smsmith
3238061Smsmith/*
3338061Smsmith * Basic definitions
3438061Smsmith */
3538061Smsmith
3638061Smsmith/* microsequence parameter descriptor */
3742475Snsouch#define MS_INS_MASK	0x00ff	/* mask to retrieve the instruction position < 256	XXX */
3838061Smsmith#define MS_ARG_MASK	0x0f00	/* mask to retrieve the argument number */
3938061Smsmith#define MS_TYP_MASK	0xf000	/* mask to retrieve the type of the param */
4038061Smsmith
4138061Smsmith/* offset of each mask (see above) */
4238061Smsmith#define MS_INS_OFFSET	0
4338061Smsmith#define MS_ARG_OFFSET	8
4438061Smsmith#define MS_TYP_OFFSET	12
4538061Smsmith
4638061Smsmith/* list of parameter types */
4738061Smsmith#define MS_TYP_INT	0x0	/* integer */
4838061Smsmith#define MS_TYP_CHA	0x1	/* character */
4938061Smsmith#define MS_TYP_PTR	0x2	/* void pointer */
5038061Smsmith#define MS_TYP_FUN	0x3	/* function pointer */
5138061Smsmith
5238061Smsmith#define MS_PARAM(ins,arg,typ) \
5338061Smsmith	(((ins<<MS_INS_OFFSET) & MS_INS_MASK) | \
5438061Smsmith	 ((arg<<MS_ARG_OFFSET) & MS_ARG_MASK) | \
5538061Smsmith	 ((typ<<MS_TYP_OFFSET) & MS_TYP_MASK))
5638061Smsmith
5738061Smsmith#define MS_INS(param) ((param & MS_INS_MASK) >> MS_INS_OFFSET)
5838061Smsmith#define MS_ARG(param) ((param & MS_ARG_MASK) >> MS_ARG_OFFSET)
5938061Smsmith#define MS_TYP(param) ((param & MS_TYP_MASK) >> MS_TYP_OFFSET)
6038061Smsmith
6138061Smsmith/* microsequence opcodes - do not change! */
6238061Smsmith#define MS_OP_GET       0	/* get <ptr>, <len>			*/
6338061Smsmith#define MS_OP_PUT       1	/* put <ptr>, <len>			*/
6438061Smsmith
6538061Smsmith#define MS_OP_RFETCH	2	/* rfetch <reg>, <mask>, <ptr>		*/
6638061Smsmith#define MS_OP_RSET	3	/* rset <reg>, <mask>, <mask>		*/
6738061Smsmith#define MS_OP_RASSERT	4	/* rassert <reg>, <mask>		*/
6838061Smsmith#define MS_OP_DELAY     5	/* delay <val>				*/
6938061Smsmith#define MS_OP_SET       6	/* set <val>				*/
7038061Smsmith#define MS_OP_DBRA      7	/* dbra <offset>			*/
7138061Smsmith#define MS_OP_BRSET     8	/* brset <mask>, <offset>		*/
7238061Smsmith#define MS_OP_BRCLEAR   9	/* brclear <mask>, <offset>		*/
7338061Smsmith#define MS_OP_RET       10	/* ret <retcode>			*/
7438061Smsmith#define MS_OP_C_CALL	11	/* c_call <function>, <parameter>	*/
7538061Smsmith#define MS_OP_PTR	12	/* ptr <pointer>			*/
7639134Snsouch#define MS_OP_ADELAY	13	/* adelay <val>				*/
7739134Snsouch#define MS_OP_BRSTAT	14	/* brstat <mask>, <mask>, <offset>	*/
7838061Smsmith#define MS_OP_SUBRET	15	/* subret <code>			*/
7938061Smsmith#define MS_OP_CALL	16	/* call <microsequence>			*/
8038061Smsmith#define MS_OP_RASSERT_P	17	/* rassert_p <iter>, <reg>		*/
8138061Smsmith#define MS_OP_RFETCH_P	18	/* rfetch_p <iter>, <reg>, <mask>	*/
8238061Smsmith#define MS_OP_TRIG	19	/* trigger <reg>, <len>, <array>	*/
8338061Smsmith
8438061Smsmith/* common masks */
8538061Smsmith#define MS_CLEAR_ALL	0x0
8638061Smsmith#define MS_ASSERT_NONE	0x0
8738061Smsmith#define MS_ASSERT_ALL	0xff
8838061Smsmith#define MS_FETCH_ALL	0xff
8938061Smsmith
9038061Smsmith/* undefined parameter value */
9139134Snsouch#define MS_NULL		0
9239134Snsouch#define MS_UNKNOWN	MS_NULL
9338061Smsmith
9439134Snsouch/* predifined parameters */
9539134Snsouch#define MS_ACCUM	-1	/* use accum previously set by MS_OP_SET */
9639134Snsouch
9738061Smsmith/* these are register numbers according to our PC-like parallel port model */
9838061Smsmith#define MS_REG_DTR	0x0
9938061Smsmith#define MS_REG_STR	0x1
10038061Smsmith#define MS_REG_CTR	0x2
10143433Snsouch#define MS_REG_EPP_A	0x3
10243433Snsouch#define MS_REG_EPP_D	0x4
10338061Smsmith
10438061Smsmith/*
10538061Smsmith * Microsequence macro abstraction level
10638061Smsmith */
10738061Smsmith
10838061Smsmith/* register operations */
109106696Salfred#define MS_RSET(reg,assert,clear) { MS_OP_RSET, {{ (reg) }, { (assert) }, { (clear) }}}
110106696Salfred#define MS_RASSERT(reg,byte)	  { MS_OP_RASSERT, { { (reg) }, { (byte) }}}
111106696Salfred#define MS_RCLR(reg,clear)	  { MS_OP_RSET, {{ (reg) }, { MS_ASSERT_NONE }, { (clear) }}}
11238061Smsmith
113106696Salfred#define MS_RFETCH(reg,mask,ptr) { MS_OP_RFETCH, {{ (reg) }, { (mask) }, { (ptr) }}}
11438061Smsmith
11538061Smsmith/* trigger the port with array[char, delay,...] */
116106696Salfred#define MS_TRIG(reg,len,array)	{ MS_OP_TRIG, {{ (reg) }, { (len) }, { (array) }}}
11738061Smsmith
11838061Smsmith/* assert/fetch from/to ptr */
119106696Salfred#define MS_RASSERT_P(n,reg)	  { MS_OP_RASSERT_P, {{ (n) }, { (reg) }}}
120106696Salfred#define MS_RFETCH_P(n,reg,mask)	  { MS_OP_RFETCH_P, {{ (n) }, { (reg) }, { (mask) }}}
12138061Smsmith
12238061Smsmith/* ptr manipulation */
123106696Salfred#define MS_PTR(ptr)	{ MS_OP_PTR, {{ (ptr) }}}
12438061Smsmith
12538061Smsmith#define MS_DASS(byte) MS_RASSERT(MS_REG_DTR,byte)
12638061Smsmith#define MS_SASS(byte) MS_RASSERT(MS_REG_STR,byte)
12738061Smsmith#define MS_CASS(byte) MS_RASSERT(MS_REG_CTR,byte)
12838061Smsmith
129106696Salfred#define MS_SET(accum)		{ MS_OP_SET, {{ (accum) }}}
130106696Salfred#define MS_BRSET(mask,offset)	{ MS_OP_BRSET, {{ (mask) }, { (offset) }}}
131106696Salfred#define MS_DBRA(offset)		{ MS_OP_DBRA, {{ (offset) }}}
132106696Salfred#define MS_BRCLEAR(mask,offset)	{ MS_OP_BRCLEAR, {{ (mask) }, { (offset) }}}
13339134Snsouch#define MS_BRSTAT(mask_set,mask_clr,offset) \
134106696Salfred		{ MS_OP_BRSTAT, {{ mask_set }, { mask_clr }, { (offset) }}}
13538061Smsmith
13638061Smsmith/* C function or submicrosequence call */
13738061Smsmith#define MS_C_CALL(function,parameter) \
138106696Salfred		{ MS_OP_C_CALL, {{ (function) }, { (parameter) }}}
139106696Salfred#define MS_CALL(microseq) { MS_OP_CALL, {{ (microseq) }}}
14038061Smsmith
14138061Smsmith/* mode dependent read/write operations
14238061Smsmith * ppb_MS_xxx_init() call required otherwise default is
14338061Smsmith * IEEE1284 operating mode */
144106696Salfred#define MS_PUT(ptr,len) { MS_OP_PUT, {{ (ptr) }, { (len) }}}
145106696Salfred#define MS_GET(ptr,len) { MS_OP_GET, {{ (ptr) }, { (len) }}}
14638061Smsmith
14738061Smsmith/* delay in microseconds */
148106696Salfred#define MS_DELAY(udelay) { MS_OP_DELAY, {{ (udelay) }}}
14938061Smsmith
15039134Snsouch/* asynchroneous delay in ms */
151106696Salfred#define MS_ADELAY(mdelay) { MS_OP_ADELAY, {{ (mdelay) }}}
15239134Snsouch
15338061Smsmith/* return from submicrosequence execution or microseqence execution */
154106696Salfred#define MS_SUBRET(code)	{ MS_OP_SUBRET,	{{ (code) }}}
155106696Salfred#define MS_RET(code)	{ MS_OP_RET, {{ (code) }}}
15638061Smsmith
15738061Smsmith/*
15838061Smsmith * Function abstraction level
15938061Smsmith */
16038061Smsmith
16155939Snsouch#define ppb_MS_GET_init(bus,dev,body) ppb_MS_init(bus, dev, body, MS_OP_GET)
16238061Smsmith
16355939Snsouch#define ppb_MS_PUT_init(bus,dev,body) ppb_MS_init(bus, dev, body, MS_OP_PUT)
16438061Smsmith
16538061Smsmithextern int ppb_MS_init(
16655939Snsouch		device_t,			/* ppbus bus */
16755939Snsouch		device_t,			/* ppbus device */
16838061Smsmith		struct ppb_microseq *,		/* loop msq to assign */
16938061Smsmith		int opcode			/* MS_OP_GET, MS_OP_PUT */
17038061Smsmith		);
17138061Smsmith
17238061Smsmithextern int ppb_MS_init_msq(
17338061Smsmith		struct ppb_microseq *,
17438061Smsmith		int,				/* number of parameters */
17538061Smsmith		...				/* descriptor, value, ... */
17638061Smsmith		);
17738061Smsmith
17838061Smsmithextern int ppb_MS_exec(
17955939Snsouch		device_t,			/* ppbus bus */
18055939Snsouch		device_t,			/* ppbus device */
18138061Smsmith		int,				/* microseq opcode */
18238061Smsmith		union ppb_insarg,		/* param1 */
18338061Smsmith		union ppb_insarg,		/* param2 */
18438061Smsmith		union ppb_insarg,		/* param3 */
18538061Smsmith		int *				/* returned value */
18638061Smsmith		);
18738061Smsmith
18838061Smsmithextern int ppb_MS_loop(
18955939Snsouch		device_t,			/* ppbus bus */
19055939Snsouch		device_t,			/* ppbus device */
19138061Smsmith		struct ppb_microseq *,		/* prologue msq of loop */
19238061Smsmith		struct ppb_microseq *,		/* body msq of loop */
19338061Smsmith		struct ppb_microseq *,		/* epilogue msq of loop */
19438061Smsmith		int,				/* number of iter */
19538061Smsmith		int *				/* returned value */
19638061Smsmith		);
19738061Smsmith
19838061Smsmithextern int ppb_MS_microseq(
19955939Snsouch		device_t,			/* ppbus bus */
20055939Snsouch		device_t,			/* ppbus device */
20138061Smsmith		struct ppb_microseq *,		/* msq to execute */
20238061Smsmith		int *				/* returned value */
20338061Smsmith		);
20438061Smsmith
20538061Smsmith#endif
206