Home | History | Annotate | Line # | Download | only in dev
hpibvar.h revision 1.12.2.1
      1 /*	$NetBSD: hpibvar.h,v 1.12.2.1 1997/10/14 08:55:06 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1982, 1990, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)hpibvar.h	8.1 (Berkeley) 6/10/93
     72  */
     73 
     74 #include <sys/queue.h>
     75 
     76 #define	HPIB_IPL(x)	((((x) >> 4) & 0x3) + 3)
     77 
     78 #define	HPIBA		32
     79 #define	HPIBB		1
     80 #define	HPIBC		8
     81 #define	HPIBA_BA	21
     82 #define	HPIBC_BA	30
     83 #define	HPIBA_IPL	3
     84 
     85 #define	CSA_BA		0x1F
     86 
     87 #define	IDS_WDMA	0x04
     88 #define	IDS_WRITE	0x08
     89 #define	IDS_IR		0x40
     90 #define	IDS_IE		0x80
     91 #define	IDS_DMA(x)	(1 << (x))
     92 
     93 #define	C_SDC		0x04	/* Selected device clear */
     94 #define	C_SDC_P		0x04	/*  with odd parity */
     95 #define	C_DCL		0x14	/* Universal device clear */
     96 #define	C_DCL_P		0x94	/*  with odd parity */
     97 #define	C_LAG		0x20	/* Listener address group commands */
     98 #define	C_UNL		0x3f	/* Universal unlisten */
     99 #define	C_UNL_P		0xbf	/*  with odd parity */
    100 #define	C_TAG		0x40	/* Talker address group commands */
    101 #define	C_UNA		0x5e	/* Unaddress (master talk address?) */
    102 #define	C_UNA_P		0x5e	/*  with odd parity */
    103 #define	C_UNT		0x5f	/* Universal untalk */
    104 #define	C_UNT_P		0xdf	/*  with odd parity */
    105 #define	C_SCG		0x60	/* Secondary group commands */
    106 
    107 struct hpibbus_softc;
    108 
    109 /*
    110  * Each of the HP-IB controller drivers fills in this structure, which
    111  * is used by the indirect driver to call controller-specific functions.
    112  */
    113 struct	hpib_controller {
    114 	void	(*hpib_reset) __P((struct hpibbus_softc *));
    115 	int	(*hpib_send) __P((struct hpibbus_softc *,
    116 		    int, int, void *, int));
    117 	int	(*hpib_recv) __P((struct hpibbus_softc *,
    118 		    int, int, void *, int));
    119 	int	(*hpib_ppoll) __P((struct hpibbus_softc *));
    120 	void	(*hpib_ppwatch) __P((void *));
    121 	void	(*hpib_go) __P((struct hpibbus_softc *,
    122 		    int, int, void *, int, int, int));
    123 	void	(*hpib_done) __P((struct hpibbus_softc *));
    124 	int	(*hpib_intr) __P((void *));
    125 };
    126 
    127 /*
    128  * Attach an HP-IB bus to an HP-IB controller.
    129  */
    130 struct hpibdev_attach_args {
    131 	struct	hpib_controller *ha_ops;	/* controller ops vector */
    132 	int	ha_type;			/* XXX */
    133 	int	ha_ba;
    134 	struct hpibbus_softc **ha_softcpp;	/* XXX */
    135 };
    136 
    137 /*
    138  * Attach an HP-IB device to an HP-IB bus.
    139  */
    140 struct hpibbus_attach_args {
    141 	u_int16_t ha_id;		/* device id */
    142 	int	ha_slave;		/* HP-IB bus slave */
    143 	int	ha_punit;		/* physical unit on slave */
    144 };
    145 
    146 /* Locator short-hand */
    147 #include "locators.h"
    148 
    149 #define	hpibbuscf_slave		cf_loc[HPIBBUSCF_SLAVE]
    150 #define	hpibbuscf_punit		cf_loc[HPIBBUSCF_PUNIT]
    151 
    152 #define	HPIB_NSLAVES		8	/* number of slaves on a bus */
    153 #define	HPIB_NPUNITS		2	/* number of punits per slave */
    154 
    155 /*
    156  * An HP-IB job queue entry.  Slave drivers have one of these used
    157  * to queue requests with the controller.
    158  */
    159 struct hpibqueue {
    160 	TAILQ_ENTRY(hpibqueue) hq_list;	/* entry on queue */
    161 	void	*hq_softc;		/* slave's softc */
    162 	int	hq_slave;		/* slave on bus */
    163 
    164 	/*
    165 	 * Callbacks used to start and stop the slave driver.
    166 	 */
    167 	void	(*hq_start) __P((void *));
    168 	void	(*hq_go) __P((void *));
    169 	void	(*hq_intr) __P((void *));
    170 };
    171 
    172 struct dmaqueue;
    173 
    174 /*
    175  * Software state per HP-IB bus.
    176  */
    177 struct hpibbus_softc {
    178 	struct	device sc_dev;		/* generic device glue */
    179 	struct	hpib_controller *sc_ops; /* controller ops vector */
    180 	volatile int sc_flags;		/* misc flags */
    181 	struct	dmaqueue *sc_dq;
    182 	TAILQ_HEAD(, hpibqueue) sc_queue;
    183 	int	sc_ba;
    184 	int	sc_type;
    185 	char	*sc_addr;
    186 	int	sc_count;
    187 	int	sc_curcnt;
    188 
    189 	/*
    190 	 * HP-IB is an indirect bus; this cheezy resource map
    191 	 * keeps track of slave/punit allocations.
    192 	 */
    193 	char	sc_rmap[HPIB_NSLAVES][HPIB_NPUNITS];
    194 };
    195 
    196 /* sc_flags */
    197 #define	HPIBF_IO	0x1
    198 #define	HPIBF_DONE	0x2
    199 #define	HPIBF_PPOLL	0x4
    200 #define	HPIBF_READ	0x8
    201 #define	HPIBF_TIMO	0x10
    202 #define	HPIBF_DMA16	0x8000
    203 
    204 #ifdef _KERNEL
    205 extern	caddr_t internalhpib;
    206 extern	int hpibtimeout;
    207 extern	int hpibdmathresh;
    208 
    209 void	hpibreset __P((int));
    210 int	hpibsend __P((int, int, int, void *, int));
    211 int	hpibrecv __P((int, int, int, void *, int));
    212 int	hpibustart __P((int));
    213 void	hpibstart __P((void *));
    214 void	hpibgo __P((int, int, int, void *, int, int, int));
    215 void	hpibdone __P((void *));
    216 int	hpibpptest __P((int, int));
    217 void	hpibppclear __P((int));
    218 void	hpibawait __P((int));
    219 int	hpibswait __P((int, int));
    220 int	hpibid __P((int, int));
    221 
    222 int	hpibreq __P((struct device *, struct hpibqueue *));
    223 void	hpibfree __P((struct device *, struct hpibqueue *));
    224 int	hpibbus_alloc __P((struct hpibbus_softc *, int, int));
    225 void	hpibbus_free __P((struct hpibbus_softc *, int, int));
    226 
    227 int	hpibintr __P((void *));
    228 int	hpibdevprint __P((void *, const char *));
    229 #endif
    230