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