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