Home | History | Annotate | Line # | Download | only in uba
uba_sbi.c revision 1.21.16.1
      1 /*	$NetBSD: uba_sbi.c,v 1.21.16.1 2008/01/21 09:40:00 yamt 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.21.16.1 2008/01/21 09:40:00 yamt 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 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(struct device *, struct cfdata *, void *);
    124 static	void	dw780_attach(struct device *, struct device *, 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(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(struct device *parent, struct cfdata *cf, void *aux)
    145 {
    146 	struct sbi_attach_args *sa = (struct sbi_attach_args *)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(struct device *parent, struct device *self, void *aux)
    163 {
    164 	struct uba_vsoftc *sc = (void *)self;
    165 	struct sbi_attach_args *sa = aux;
    166 	int ubaddr = sa->sa_type & 3;
    167 	int i;
    168 
    169 	printf(": DW780\n");
    170 	/*
    171 	 * Fill in bus specific data.
    172 	 */
    173 	sc->uv_sc.uh_ubainit = dw780_init;
    174 #ifdef notyet
    175 	sc->uv_sc.uh_ubapurge = dw780_purge;
    176 #endif
    177 	sc->uv_sc.uh_beforescan = dw780_beforescan;
    178 	sc->uv_sc.uh_afterscan = dw780_afterscan;
    179 	sc->uv_sc.uh_errchk = dw780_errchk;
    180 	sc->uv_sc.uh_iot = &vax_mem_bus_space;
    181 	sc->uv_sc.uh_dmat = &sc->uv_dmat;
    182 	sc->uv_sc.uh_nr = ubaddr;
    183 	sc->uv_uba = (void *)sa->sa_ioh;
    184 	sc->uh_ibase = VAX_NBPG + ubaddr * VAX_NBPG;
    185 	sc->uv_sc.uh_type = UBA_UBA;
    186 
    187 	if (strayinit++ == 0) evcnt_attach_static(&strayint); /* Setup stray
    188 							         interrupt
    189 							         counter. */
    190 
    191 	/*
    192 	 * Set up dispatch vectors for DW780.
    193 	 */
    194 	for (i = 0x14; i < 0x18; i++)
    195 		scb_vecalloc(vecnum(0, i, sa->sa_nexnum), uba_dw780int,
    196 		    sc, SCB_ISTACK, &sc->uv_sc.uh_intrcnt);
    197 	evcnt_attach_dynamic(&sc->uv_sc.uh_intrcnt, EVCNT_TYPE_INTR, NULL,
    198 		sc->uv_sc.uh_dev.dv_xname, "intr");
    199 
    200 	/*
    201 	 * Fill in variables used by the sgmap system.
    202 	 */
    203 	sc->uv_size = UBASIZE;		/* Size in bytes of Unibus space */
    204 
    205 	uba_dma_init(sc);
    206 	uba_attach(&sc->uv_sc, (sa->sa_sbinum ? UMEMB8600(ubaddr) :
    207 	    UMEMA8600(ubaddr)) + (UBAPAGES * VAX_NBPG));
    208 }
    209 
    210 void
    211 dw780_beforescan(struct uba_softc *sc)
    212 {
    213 	struct uba_vsoftc *vc = (void *)sc;
    214 	volatile int *hej = &vc->uv_uba->uba_sr;
    215 
    216 	*hej = *hej;
    217 	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE;
    218 }
    219 
    220 void
    221 dw780_afterscan(struct uba_softc *sc)
    222 {
    223 	struct uba_vsoftc *vc = (void *)sc;
    224 
    225 	vc->uv_uba->uba_cr = UBACR_IFS | UBACR_BRIE |
    226 	    UBACR_USEFIE | UBACR_SUEFIE |
    227 	    (vc->uv_uba->uba_cr & 0x7c000000);
    228 }
    229 
    230 
    231 int
    232 dw780_errchk(struct uba_softc *sc)
    233 {
    234 	struct uba_vsoftc *vc = (void *)sc;
    235 	volatile int *hej = &vc->uv_uba->uba_sr;
    236 
    237 	if (*hej) {
    238 		*hej = *hej;
    239 		return 1;
    240 	}
    241 	return 0;
    242 }
    243 
    244 void
    245 uba_dw780int(void *arg)
    246 {
    247 	extern	void scb_stray(void *);
    248 	struct	uba_vsoftc *vc = arg;
    249 	struct	uba_regs *ur = vc->uv_uba;
    250 	struct	ivec_dsp *ivec;
    251 	struct  evcnt *uvec;
    252 	int	br, vec;
    253 
    254 	br = mfpr(PR_IPL);
    255 	uvec = &vc->uv_sc.uh_intrcnt;
    256 	vec = ur->uba_brrvr[br - 0x14];
    257 	if (vec <= 0) {
    258 		ubaerror(&vc->uv_sc, &br, &vec);
    259 		if (vec == 0)
    260 			return;
    261 	}
    262 
    263 	uvec->ev_count--;	/* This interrupt should not be counted against
    264 				   the uba. */
    265 	ivec = &scb_vec[(vc->uh_ibase + vec)/4];
    266 	if (cold && *ivec->hoppaddr == scb_stray) {
    267 		scb_fake(vec + vc->uh_ibase, br);
    268 	} else {
    269 		if (*ivec->hoppaddr == scb_stray)
    270 			strayint.ev_count++; /* Count against stray int */
    271 		else
    272 			ivec->ev->ev_count++; /* Count against device */
    273 		(*ivec->hoppaddr)(ivec->pushlarg);
    274 	}
    275 }
    276 
    277 void
    278 dw780_init(struct uba_softc *sc)
    279 {
    280 	struct uba_vsoftc *vc = (void *)sc;
    281 
    282 	vc->uv_uba->uba_cr = UBACR_ADINIT;
    283 	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
    284 	while ((vc->uv_uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
    285 		;
    286 }
    287 
    288 #ifdef notyet
    289 void
    290 dw780_purge(sc, bdp)
    291 	struct uba_softc *sc;
    292 	int bdp;
    293 {
    294 	struct uba_vsoftc *vc = (void *)sc;
    295 
    296 	vc->uv_uba->uba_dpr[bdp] |= UBADPR_BNE;
    297 }
    298 #endif
    299 
    300 int	ubawedgecnt = 10;
    301 int	ubacrazy = 500;
    302 int	zvcnt_max = 5000;	/* in 8 sec */
    303 int	ubaerrcnt;
    304 /*
    305  * This routine is called by the locore code to process a UBA
    306  * error on an 11/780 or 8600.	The arguments are passed
    307  * on the stack, and value-result (through some trickery).
    308  * In particular, the uvec argument is used for further
    309  * uba processing so the result aspect of it is very important.
    310  */
    311 /*ARGSUSED*/
    312 void
    313 ubaerror(struct uba_softc *uh, int *ipl, int *uvec)
    314 {
    315 	struct uba_vsoftc *vc = (void *)uh;
    316 	struct	uba_regs *uba = vc->uv_uba;
    317 	int sr, s;
    318 	char sbuf[256], sbuf2[256];
    319 
    320 	if (*uvec == 0) {
    321 		/*
    322 		 * Declare dt as unsigned so that negative values
    323 		 * are handled as >8 below, in case time was set back.
    324 		 */
    325 		u_long	dt = time_second - vc->uh_zvtime;
    326 
    327 		vc->uh_zvtotal++;
    328 		if (dt > 8) {
    329 			vc->uh_zvtime = time_second;
    330 			vc->uh_zvcnt = 0;
    331 		}
    332 		if (++vc->uh_zvcnt > zvcnt_max) {
    333 			printf("%s: too many zero vectors (%d in <%d sec)\n",
    334 				vc->uv_sc.uh_dev.dv_xname, vc->uh_zvcnt, (int)dt + 1);
    335 
    336 			bitmask_snprintf(uba->uba_cnfgr&(~0xff), UBACNFGR_BITS,
    337 					 sbuf, sizeof(sbuf));
    338 			printf("\tIPL 0x%x\n\tcnfgr: %s	 Adapter Code: 0x%x\n",
    339 				*ipl, sbuf, uba->uba_cnfgr&0xff);
    340 
    341 			bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
    342 			printf("\tsr: %s\n\tdcr: %x (MIC %sOK)\n",
    343 				sbuf, uba->uba_dcr,
    344 				(uba->uba_dcr&0x8000000)?"":"NOT ");
    345 
    346 			ubareset(&vc->uv_sc);
    347 		}
    348 		return;
    349 	}
    350 	if (uba->uba_cnfgr & NEX_CFGFLT) {
    351 		bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
    352 		bitmask_snprintf(uba->uba_cnfgr, NEXFLT_BITS, sbuf2, sizeof(sbuf2));
    353 		printf("%s: sbi fault sr=%s cnfgr=%s\n",
    354 		    vc->uv_sc.uh_dev.dv_xname, sbuf, sbuf2);
    355 		ubareset(&vc->uv_sc);
    356 		*uvec = 0;
    357 		return;
    358 	}
    359 	sr = uba->uba_sr;
    360 	s = spluba();
    361 	bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
    362 	printf("%s: uba error sr=%s fmer=%x fubar=%o\n", vc->uv_sc.uh_dev.dv_xname,
    363 	    sbuf, uba->uba_fmer, 4*uba->uba_fubar);
    364 	splx(s);
    365 	uba->uba_sr = sr;
    366 	*uvec &= UBABRRVR_DIV;
    367 	if (++ubaerrcnt % ubawedgecnt == 0) {
    368 		if (ubaerrcnt > ubacrazy)
    369 			panic("uba crazy");
    370 		printf("ERROR LIMIT ");
    371 		ubareset(&vc->uv_sc);
    372 		*uvec = 0;
    373 	}
    374 }
    375