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