Home | History | Annotate | Line # | Download | only in uba
uba_sbi.c revision 1.6
      1 /*	$NetBSD: uba_sbi.c,v 1.6 2000/06/04 17:59:50 ragge Exp $	   */
      2 /*
      3  * Copyright (c) 1996 Jonathan Stone.
      4  * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
      5  * Copyright (c) 1982, 1986 The Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
     37  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
     38  */
     39 
     40 #include <sys/param.h>
     41 #include <sys/device.h>
     42 #include <sys/systm.h>
     43 #include <sys/kernel.h>
     44 
     45 #define _VAX_BUS_DMA_PRIVATE
     46 #include <machine/bus.h>
     47 #include <machine/mtpr.h>
     48 #include <machine/nexus.h>
     49 #include <machine/cpu.h>
     50 #include <machine/sgmap.h>
     51 #include <machine/scb.h>
     52 
     53 #include <dev/qbus/ubavar.h>
     54 
     55 #include <vax/uba/uba_common.h>
     56 
     57 #include "locators.h"
     58 #include "ioconf.h"
     59 
     60 /* Some SBI-specific defines */
     61 #define UBASIZE		(UBAPAGES * VAX_NBPG)
     62 #define UMEMA8600(i)   	(0x20100000+(i)*0x40000)
     63 #define	UMEMB8600(i)	(0x22100000+(i)*0x40000)
     64 
     65 /*
     66  * Some status registers.
     67  */
     68 #define UBACNFGR_UBIC  0x00010000      /* unibus init complete */
     69 #define UBACNFGR_BITS \
     70 "\40\40PARFLT\37WSQFLT\36URDFLT\35ISQFLT\34MXTFLT\33XMTFLT\30ADPDN\27ADPUP\23UBINIT\22UBPDN\21UBIC"
     71 
     72 #define UBACR_IFS      0x00000040      /* interrupt field switch */
     73 #define UBACR_BRIE     0x00000020      /* BR interrupt enable */
     74 #define UBACR_USEFIE   0x00000010      /* UNIBUS to SBI error field IE */
     75 #define UBACR_SUEFIE   0x00000008      /* SBI to UNIBUS error field IE */
     76 #define UBACR_ADINIT   0x00000001      /* adapter init */
     77 
     78 #define UBADPR_BNE     0x80000000      /* buffer not empty - purge */
     79 
     80 #define UBABRRVR_DIV    0x0000ffff      /* device interrupt vector field */
     81 
     82 #define UBASR_BITS \
     83 "\20\13RDTO\12RDS\11CRD\10CXTER\7CXTMO\6DPPE\5IVMR\4MRPF\3LEB\2UBSTO\1UBSSYNTO"
     84 
     85 char    ubasr_bits[] = UBASR_BITS;
     86 
     87 /*
     88  * The DW780 are directly connected to the SBI on 11/780 and 8600.
     89  */
     90 static	int	dw780_match(struct device *, struct cfdata *, void *);
     91 static	void	dw780_attach(struct device *, struct device *, void *);
     92 static	void	dw780_init(struct uba_softc*);
     93 static	void    dw780_beforescan(struct uba_softc *);
     94 static	void    dw780_afterscan(struct uba_softc *);
     95 static	int     dw780_errchk(struct uba_softc *);
     96 static	void    uba_dw780int(void *);
     97 static  void	ubaerror(struct uba_softc *, int *, int *);
     98 #ifdef notyet
     99 static	void	dw780_purge(struct uba_softc *, int);
    100 #endif
    101 
    102 struct	cfattach uba_sbi_ca = {
    103 	sizeof(struct uba_vsoftc), dw780_match, dw780_attach
    104 };
    105 
    106 extern	struct vax_bus_space vax_mem_bus_space;
    107 
    108 volatile int svec;
    109 
    110 int
    111 dw780_match(struct device *parent, struct cfdata *cf, void *aux)
    112 {
    113 	struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
    114 
    115 	if (cf->cf_loc[SBICF_TR] != sa->sa_nexnum &&
    116 	    cf->cf_loc[SBICF_TR] != SBICF_TR_DEFAULT)
    117 		return 0;
    118 	/*
    119 	 * The uba type is actually only telling where the uba
    120 	 * space is in nexus space.
    121 	 */
    122 	if ((sa->sa_type & ~3) != NEX_UBA0)
    123 		return 0;
    124 
    125 	return 1;
    126 }
    127 
    128 void
    129 dw780_attach(struct device *parent, struct device *self, void *aux)
    130 {
    131 	struct uba_vsoftc *sc = (void *)self;
    132 	struct sbi_attach_args *sa = aux;
    133 	int ubaddr = sa->sa_type & 3;
    134 	int i;
    135 
    136 	printf(": DW780\n");
    137 	/*
    138 	 * Fill in bus specific data.
    139 	 */
    140 	sc->uv_sc.uh_ubainit = dw780_init;
    141 #ifdef notyet
    142 	sc->uv_sc.uh_ubapurge = dw780_purge;
    143 #endif
    144 	sc->uv_sc.uh_beforescan = dw780_beforescan;
    145 	sc->uv_sc.uh_afterscan = dw780_afterscan;
    146 	sc->uv_sc.uh_errchk = dw780_errchk;
    147 	sc->uv_sc.uh_iot = &vax_mem_bus_space;
    148 	sc->uv_sc.uh_dmat = &sc->uv_dmat;
    149 	sc->uv_uba = (void *)sa->sa_ioh;
    150 	sc->uh_ibase = VAX_NBPG + ubaddr * VAX_NBPG;
    151 
    152 	/*
    153 	 * Set up dispatch vectors for DW780.
    154 	 */
    155 	for (i = 14; i < 17; i++)
    156 		scb_vecalloc(vecnum(0, i, sa->sa_nexnum), uba_dw780int,
    157 		    sc, SCB_ISTACK, &sc->uv_sc.uh_intrcnt);
    158 	evcnt_attach(&sc->uv_sc.uh_dev, "intr", &sc->uv_sc.uh_intrcnt);
    159 
    160 	/*
    161 	 * Fill in variables used by the sgmap system.
    162 	 */
    163 	sc->uv_size = UBASIZE;		/* Size in bytes of Unibus space */
    164 
    165 	uba_dma_init(sc);
    166 	uba_attach(&sc->uv_sc, (parent->dv_unit ? UMEMB8600(ubaddr) :
    167 	    UMEMA8600(ubaddr)) + (UBAPAGES * VAX_NBPG));
    168 }
    169 
    170 void
    171 dw780_beforescan(sc)
    172 	struct uba_softc *sc;
    173 {
    174 	struct uba_vsoftc *vc = (void *)sc;
    175 	volatile int *hej = &vc->uv_uba->uba_sr;
    176 
    177 	*hej = *hej;
    178 	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE;
    179 }
    180 
    181 void
    182 dw780_afterscan(sc)
    183 	struct uba_softc *sc;
    184 {
    185 	struct uba_vsoftc *vc = (void *)sc;
    186 
    187 	vc->uv_uba->uba_cr = UBACR_IFS | UBACR_BRIE |
    188 	    UBACR_USEFIE | UBACR_SUEFIE |
    189 	    (vc->uv_uba->uba_cr & 0x7c000000);
    190 }
    191 
    192 
    193 int
    194 dw780_errchk(sc)
    195 	struct uba_softc *sc;
    196 {
    197 	struct uba_vsoftc *vc = (void *)sc;
    198 	volatile int *hej = &vc->uv_uba->uba_sr;
    199 
    200 	if (*hej) {
    201 		*hej = *hej;
    202 		return 1;
    203 	}
    204 	return 0;
    205 }
    206 
    207 void
    208 uba_dw780int(arg)
    209 	void	*arg;
    210 {
    211 	struct	uba_vsoftc *vc = arg;
    212 	struct	uba_regs *ur = vc->uv_uba;
    213 	struct	ivec_dsp *scb_vec;
    214 	int	br, vec;
    215 
    216 	br = mfpr(PR_IPL);
    217 	vec = ur->uba_brrvr[br - 0x14];
    218 	if (vec <= 0) {
    219 		ubaerror(&vc->uv_sc, &br, (int *)&vec);
    220 		if (svec == 0)
    221 			return;
    222 	}
    223 	if (cold)
    224 		scb_fake(vec + vc->uh_ibase, br);
    225 	else {
    226 		scb_vec = (struct ivec_dsp *)((int)scb + 512 + 4 * vec);
    227 		(*scb_vec->hoppaddr)(scb_vec->pushlarg);
    228 	}
    229 }
    230 
    231 void
    232 dw780_init(sc)
    233 	struct uba_softc *sc;
    234 {
    235 	struct uba_vsoftc *vc = (void *)sc;
    236 
    237 	vc->uv_uba->uba_cr = UBACR_ADINIT;
    238 	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
    239 	while ((vc->uv_uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
    240 		;
    241 }
    242 
    243 #ifdef notyet
    244 void
    245 dw780_purge(sc, bdp)
    246 	struct uba_softc *sc;
    247 	int bdp;
    248 {
    249 	struct uba_vsoftc *vc = (void *)sc;
    250 
    251 	vc->uv_uba->uba_dpr[bdp] |= UBADPR_BNE;
    252 }
    253 #endif
    254 
    255 int	ubawedgecnt = 10;
    256 int	ubacrazy = 500;
    257 int	zvcnt_max = 5000;	/* in 8 sec */
    258 int	ubaerrcnt;
    259 /*
    260  * This routine is called by the locore code to process a UBA
    261  * error on an 11/780 or 8600.	The arguments are passed
    262  * on the stack, and value-result (through some trickery).
    263  * In particular, the uvec argument is used for further
    264  * uba processing so the result aspect of it is very important.
    265  * It must not be declared register.
    266  */
    267 /*ARGSUSED*/
    268 void
    269 ubaerror(uh, ipl, uvec)
    270 	register struct uba_softc *uh;
    271 	int *ipl, *uvec;
    272 {
    273 	struct uba_vsoftc *vc = (void *)uh;
    274 	struct	uba_regs *uba = vc->uv_uba;
    275 	register int sr, s;
    276 
    277 	if (*uvec == 0) {
    278 		/*
    279 		 * Declare dt as unsigned so that negative values
    280 		 * are handled as >8 below, in case time was set back.
    281 		 */
    282 		u_long	dt = time.tv_sec - vc->uh_zvtime;
    283 
    284 		vc->uh_zvtotal++;
    285 		if (dt > 8) {
    286 			vc->uh_zvtime = time.tv_sec;
    287 			vc->uh_zvcnt = 0;
    288 		}
    289 		if (++vc->uh_zvcnt > zvcnt_max) {
    290 			printf("%s: too many zero vectors (%d in <%d sec)\n",
    291 				vc->uv_sc.uh_dev.dv_xname, vc->uh_zvcnt, (int)dt + 1);
    292 			printf("\tIPL 0x%x\n\tcnfgr: %b	 Adapter Code: 0x%x\n",
    293 				*ipl, uba->uba_cnfgr&(~0xff), UBACNFGR_BITS,
    294 				uba->uba_cnfgr&0xff);
    295 			printf("\tsr: %b\n\tdcr: %x (MIC %sOK)\n",
    296 				uba->uba_sr, ubasr_bits, uba->uba_dcr,
    297 				(uba->uba_dcr&0x8000000)?"":"NOT ");
    298 			ubareset(&vc->uv_sc);
    299 		}
    300 		return;
    301 	}
    302 	if (uba->uba_cnfgr & NEX_CFGFLT) {
    303 		printf("%s: sbi fault sr=%b cnfgr=%b\n",
    304 		    vc->uv_sc.uh_dev.dv_xname, uba->uba_sr, ubasr_bits,
    305 		    uba->uba_cnfgr, NEXFLT_BITS);
    306 		ubareset(&vc->uv_sc);
    307 		*uvec = 0;
    308 		return;
    309 	}
    310 	sr = uba->uba_sr;
    311 	s = splimp();
    312 	printf("%s: uba error sr=%b fmer=%x fubar=%o\n", vc->uv_sc.uh_dev.dv_xname,
    313 	    uba->uba_sr, ubasr_bits, uba->uba_fmer, 4*uba->uba_fubar);
    314 	splx(s);
    315 	uba->uba_sr = sr;
    316 	*uvec &= UBABRRVR_DIV;
    317 	if (++ubaerrcnt % ubawedgecnt == 0) {
    318 		if (ubaerrcnt > ubacrazy)
    319 			panic("uba crazy");
    320 		printf("ERROR LIMIT ");
    321 		ubareset(&vc->uv_sc);
    322 		*uvec = 0;
    323 	}
    324 }
    325