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