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