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