Home | History | Annotate | Line # | Download | only in qbus
ubavar.h revision 1.24
      1 /*	$NetBSD: ubavar.h,v 1.24 1999/05/27 16:04:48 ragge Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986 Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)ubavar.h	7.7 (Berkeley) 6/28/90
     36  */
     37 
     38 /*
     39  * This file contains definitions related to the kernel structures
     40  * for dealing with the unibus adapters.
     41  *
     42  * Each uba has a uba_softc structure.
     43  * Each unibus controller which is not a device has a uba_ctlr structure.
     44  * Each unibus device has a uba_device structure.
     45  */
     46 
     47 #include <sys/buf.h>
     48 #include <sys/device.h>
     49 
     50 #include <machine/trap.h> /* For struct ivec_dsp */
     51 /*
     52  * Per-uba structure.
     53  *
     54  * This structure holds the interrupt vector for the uba,
     55  * and its address in physical and virtual space.  At boot time
     56  * we determine the devices attached to the uba's and their
     57  * interrupt vectors, filling in uh_vec.  We free the map
     58  * register and bdp resources of the uba into the structures
     59  * defined here.
     60  *
     61  * During normal operation, resources are allocated and returned
     62  * to the structures here.  We watch the number of passive releases
     63  * on each uba, and if the number is excessive may reset the uba.
     64  *
     65  * When uba resources are needed and not available, or if a device
     66  * which can tolerate no other uba activity (rk07) gets on the bus,
     67  * then device drivers may have to wait to get to the bus and are
     68  * queued here.  It is also possible for processes to block in
     69  * the unibus driver in resource wait (mrwant, bdpwant); these
     70  * wait states are also recorded here.
     71  */
     72 struct	uba_softc {
     73 	struct	device uh_dev;		/* Device struct, autoconfig */
     74 	SIMPLEQ_HEAD(, uba_unit) uh_resq;	/* resource wait chain */
     75 	int	uh_type;		/* type of adaptor */
     76 	struct	uba_regs *uh_uba;	/* virt addr of uba adaptor regs */
     77 	struct	pte *uh_mr;		/* start of page map */
     78 	int	uh_memsize;		/* size of uba memory, pages */
     79 	caddr_t	uh_iopage;		/* start of uba io page */
     80 	void	(**uh_reset) __P((int));/* UBA reset function array */
     81 	int	*uh_resarg;		/* array of ubareset args */
     82 	int	uh_resno;		/* Number of devices to reset */
     83 	short	uh_mrwant;		/* someone is waiting for map reg */
     84 	short	uh_bdpwant;		/* someone awaits bdp's */
     85 	int	uh_bdpfree;		/* free bdp's */
     86 	int	uh_zvcnt;		/* number of recent 0 vectors */
     87 	long	uh_zvtime;		/* time over which zvcnt accumulated */
     88 	int	uh_zvtotal;		/* total number of 0 vectors */
     89 	int	uh_lastiv;		/* last free interrupt vector */
     90 	short	uh_users;		/* transient bdp use count */
     91 	short	uh_xclu;		/* an rk07 is using this uba! */
     92 	int	uh_lastmem;		/* limit of any unibus memory */
     93 	struct	map *uh_map;		/* register free map */
     94 	int	(*uh_errchk) __P((struct uba_softc *));
     95 	void	(*uh_beforescan) __P((struct uba_softc *));
     96 	void	(*uh_afterscan) __P((struct uba_softc *));
     97 	void	(*uh_ubainit) __P((struct uba_softc *));
     98 	void	(*uh_ubapurge) __P((struct uba_softc *, int));
     99 	short	uh_nr;			/* Unibus sequential number */
    100 	short	uh_nbdp;		/* # of BDP's */
    101 	int	uh_ibase;		/* Base address for vectors */
    102 	bus_space_tag_t	uh_iot;		/* Tag for this Unibus */
    103 	bus_space_handle_t uh_ioh;	/* Handle for I/O space */
    104 };
    105 
    106 #define	UAMSIZ	100
    107 
    108 /*
    109  * Per-controller structure.
    110  * The unit struct is common to both the adapter and the controller
    111  * to which it belongs. It is only used on controllers that handles
    112  * BDP's, and calls the adapter queueing subroutines.
    113  */
    114 struct	uba_unit {
    115 	SIMPLEQ_ENTRY(uba_unit) uu_resq;/* Queue while waiting for resources */
    116 	void	*uu_softc;	/* Pointer to units softc */
    117 	int	uu_ubinfo;	/* save unibus registers, etc */
    118 	int	uu_bdp;		/* for controllers that hang on to bdp's */
    119 	int    (*uu_ready) __P((struct uba_unit *));
    120 	short   uu_xclu;        /* want exclusive use of bdp's */
    121 	short   uu_keepbdp;     /* hang on to bdp's once allocated */
    122 };
    123 
    124 /*
    125  * uba_attach_args is used during autoconfiguration. It is sent
    126  * from ubascan() to each (possible) device.
    127  */
    128 struct uba_attach_args {
    129 	bus_space_tag_t	ua_iot;		/* Tag for this bus I/O-space */
    130 	bus_addr_t	ua_ioh;		/* I/O regs addr */
    131 		    /* Pointer to int routine, filled in by probe*/
    132 	void		(*ua_ivec) __P((int));
    133 		    /* UBA reset routine, filled in by probe */
    134 	void		(*ua_reset) __P((int));
    135 	int		ua_iaddr;	/* Full CSR address of device */
    136 	int		ua_br;		/* IPL this dev interrupted on */
    137 	int		ua_cvec;	/* Vector for this device */
    138 };
    139 
    140 /*
    141  * Flags to UBA map/bdp allocation routines
    142  */
    143 #define	UBA_NEEDBDP	0x01		/* transfer needs a bdp */
    144 #define	UBA_CANTWAIT	0x02		/* don't block me */
    145 #define	UBA_NEED16	0x04		/* need 16 bit addresses only */
    146 #define	UBA_HAVEBDP	0x08		/* use bdp specified in high bits */
    147 
    148 /*
    149  * Macros to bust return word from map allocation routines.
    150  * SHOULD USE STRUCTURE TO STORE UBA RESOURCE ALLOCATION:
    151  */
    152 #ifdef notyet
    153 struct ubinfo {
    154 	long	ub_addr;	/* unibus address: mr + boff */
    155 	int	ub_nmr;		/* number of registers, 0 if empty */
    156 	int	ub_bdp;		/* bdp number, 0 if none */
    157 };
    158 #define	UBAI_MR(i)	(((i) >> 9) & 0x7ff)	/* starting map register */
    159 #define	UBAI_BOFF(i)	((i)&0x1ff)		/* page offset */
    160 #else
    161 #define	UBAI_BDP(i)	((int)(((unsigned)(i)) >> 28))
    162 #define	BDPMASK		0xf0000000
    163 #define	UBAI_NMR(i)	((int)((i) >> 20) & 0xff)	/* max 255 (=127.5K) */
    164 #define	UBA_MAXNMR	255
    165 #define	UBAI_MR(i)	((int)((i) >> 9) & 0x7ff)	/* max 2047 */
    166 #define	UBA_MAXMR	2047
    167 #define	UBAI_BOFF(i)	((int)((i) & 0x1ff))
    168 #define	UBAI_ADDR(i)	((int)((i) & 0xfffff))	/* uba addr (boff+mr) */
    169 #define	UBAI_INFO(off, mr, nmr, bdp) \
    170 	(((bdp) << 28) | ((nmr) << 20) | ((mr) << 9) | (off))
    171 #endif
    172 
    173 #ifndef _LOCORE
    174 #ifdef _KERNEL
    175 #define	ubago(ui)	ubaqueue(ui)
    176 #define b_forw  b_hash.le_next	/* Nice to have when handling uba queues */
    177 
    178 void	uba_attach __P((struct uba_softc *, unsigned long));
    179 int	uballoc __P((struct uba_softc *, caddr_t, int, int));
    180 void	ubarelse __P((struct uba_softc *, int *));
    181 int	ubaqueue __P((struct uba_unit *, struct buf *));
    182 void	ubadone __P((struct uba_unit *));
    183 void	ubareset __P((int));
    184 int	ubasetup __P((struct uba_softc *, struct buf *, int));
    185 
    186 #endif /* _KERNEL */
    187 #endif !_LOCORE
    188