uba_sbi.c revision 1.12.2.1
11.12.2.1Sjdolecek/*	$NetBSD: uba_sbi.c,v 1.12.2.1 2002/06/23 17:43:04 jdolecek Exp $	   */
21.1Sragge/*
31.1Sragge * Copyright (c) 1996 Jonathan Stone.
41.1Sragge * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
51.1Sragge * Copyright (c) 1982, 1986 The Regents of the University of California.
61.1Sragge * All rights reserved.
71.1Sragge *
81.1Sragge * Redistribution and use in source and binary forms, with or without
91.1Sragge * modification, are permitted provided that the following conditions
101.1Sragge * are met:
111.1Sragge * 1. Redistributions of source code must retain the above copyright
121.1Sragge *    notice, this list of conditions and the following disclaimer.
131.1Sragge * 2. Redistributions in binary form must reproduce the above copyright
141.1Sragge *    notice, this list of conditions and the following disclaimer in the
151.1Sragge *    documentation and/or other materials provided with the distribution.
161.1Sragge * 3. All advertising materials mentioning features or use of this software
171.1Sragge *    must display the following acknowledgement:
181.1Sragge *	This product includes software developed by the University of
191.1Sragge *	California, Berkeley and its contributors.
201.1Sragge * 4. Neither the name of the University nor the names of its contributors
211.1Sragge *    may be used to endorse or promote products derived from this software
221.1Sragge *    without specific prior written permission.
231.1Sragge *
241.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271.1Sragge * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341.1Sragge * SUCH DAMAGE.
351.1Sragge *
361.1Sragge *	@(#)uba.c	7.10 (Berkeley) 12/16/90
371.1Sragge *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
381.1Sragge */
391.1Sragge
401.1Sragge#include <sys/param.h>
411.1Sragge#include <sys/device.h>
421.1Sragge#include <sys/systm.h>
431.1Sragge#include <sys/kernel.h>
441.1Sragge
451.1Sragge#define _VAX_BUS_DMA_PRIVATE
461.1Sragge#include <machine/bus.h>
471.1Sragge#include <machine/mtpr.h>
481.1Sragge#include <machine/nexus.h>
491.1Sragge#include <machine/cpu.h>
501.1Sragge#include <machine/sgmap.h>
511.1Sragge#include <machine/scb.h>
521.1Sragge
531.1Sragge#include <dev/qbus/ubavar.h>
541.1Sragge
551.5Smatt#include <vax/uba/uba_common.h>
561.1Sragge
571.6Sragge#include "locators.h"
581.1Sragge#include "ioconf.h"
591.1Sragge
601.1Sragge/* Some SBI-specific defines */
611.1Sragge#define UBASIZE		(UBAPAGES * VAX_NBPG)
621.1Sragge#define UMEMA8600(i)   	(0x20100000+(i)*0x40000)
631.1Sragge#define	UMEMB8600(i)	(0x22100000+(i)*0x40000)
641.1Sragge
651.1Sragge/*
661.1Sragge * Some status registers.
671.1Sragge */
681.1Sragge#define UBACNFGR_UBIC  0x00010000      /* unibus init complete */
691.1Sragge#define UBACNFGR_BITS \
701.1Sragge"\40\40PARFLT\37WSQFLT\36URDFLT\35ISQFLT\34MXTFLT\33XMTFLT\30ADPDN\27ADPUP\23UBINIT\22UBPDN\21UBIC"
711.1Sragge
721.1Sragge#define UBACR_IFS      0x00000040      /* interrupt field switch */
731.1Sragge#define UBACR_BRIE     0x00000020      /* BR interrupt enable */
741.1Sragge#define UBACR_USEFIE   0x00000010      /* UNIBUS to SBI error field IE */
751.1Sragge#define UBACR_SUEFIE   0x00000008      /* SBI to UNIBUS error field IE */
761.1Sragge#define UBACR_ADINIT   0x00000001      /* adapter init */
771.1Sragge
781.1Sragge#define UBADPR_BNE     0x80000000      /* buffer not empty - purge */
791.1Sragge
801.1Sragge#define UBABRRVR_DIV    0x0000ffff      /* device interrupt vector field */
811.1Sragge
821.1Sragge#define UBASR_BITS \
831.1Sragge"\20\13RDTO\12RDS\11CRD\10CXTER\7CXTMO\6DPPE\5IVMR\4MRPF\3LEB\2UBSTO\1UBSSYNTO"
841.1Sragge
851.1Sraggechar    ubasr_bits[] = UBASR_BITS;
861.1Sragge
871.1Sragge/*
881.1Sragge * The DW780 are directly connected to the SBI on 11/780 and 8600.
891.1Sragge */
901.6Sraggestatic	int	dw780_match(struct device *, struct cfdata *, void *);
911.6Sraggestatic	void	dw780_attach(struct device *, struct device *, void *);
921.6Sraggestatic	void	dw780_init(struct uba_softc*);
931.6Sraggestatic	void    dw780_beforescan(struct uba_softc *);
941.6Sraggestatic	void    dw780_afterscan(struct uba_softc *);
951.6Sraggestatic	int     dw780_errchk(struct uba_softc *);
961.6Sraggestatic	void    uba_dw780int(void *);
971.6Sraggestatic  void	ubaerror(struct uba_softc *, int *, int *);
981.1Sragge#ifdef notyet
991.6Sraggestatic	void	dw780_purge(struct uba_softc *, int);
1001.1Sragge#endif
1011.1Sragge
1021.1Sraggestruct	cfattach uba_sbi_ca = {
1031.1Sragge	sizeof(struct uba_vsoftc), dw780_match, dw780_attach
1041.1Sragge};
1051.1Sragge
1061.1Sraggeextern	struct vax_bus_space vax_mem_bus_space;
1071.1Sragge
1081.1Sraggeint
1091.6Sraggedw780_match(struct device *parent, struct cfdata *cf, void *aux)
1101.1Sragge{
1111.1Sragge	struct sbi_attach_args *sa = (struct sbi_attach_args *)aux;
1121.1Sragge
1131.6Sragge	if (cf->cf_loc[SBICF_TR] != sa->sa_nexnum &&
1141.6Sragge	    cf->cf_loc[SBICF_TR] != SBICF_TR_DEFAULT)
1151.1Sragge		return 0;
1161.1Sragge	/*
1171.1Sragge	 * The uba type is actually only telling where the uba
1181.1Sragge	 * space is in nexus space.
1191.1Sragge	 */
1201.6Sragge	if ((sa->sa_type & ~3) != NEX_UBA0)
1211.1Sragge		return 0;
1221.1Sragge
1231.1Sragge	return 1;
1241.1Sragge}
1251.1Sragge
1261.1Sraggevoid
1271.6Sraggedw780_attach(struct device *parent, struct device *self, void *aux)
1281.1Sragge{
1291.1Sragge	struct uba_vsoftc *sc = (void *)self;
1301.1Sragge	struct sbi_attach_args *sa = aux;
1311.6Sragge	int ubaddr = sa->sa_type & 3;
1321.1Sragge	int i;
1331.1Sragge
1341.1Sragge	printf(": DW780\n");
1351.1Sragge	/*
1361.1Sragge	 * Fill in bus specific data.
1371.1Sragge	 */
1381.1Sragge	sc->uv_sc.uh_ubainit = dw780_init;
1391.1Sragge#ifdef notyet
1401.1Sragge	sc->uv_sc.uh_ubapurge = dw780_purge;
1411.1Sragge#endif
1421.1Sragge	sc->uv_sc.uh_beforescan = dw780_beforescan;
1431.1Sragge	sc->uv_sc.uh_afterscan = dw780_afterscan;
1441.1Sragge	sc->uv_sc.uh_errchk = dw780_errchk;
1451.1Sragge	sc->uv_sc.uh_iot = &vax_mem_bus_space;
1461.1Sragge	sc->uv_sc.uh_dmat = &sc->uv_dmat;
1471.6Sragge	sc->uv_uba = (void *)sa->sa_ioh;
1481.1Sragge	sc->uh_ibase = VAX_NBPG + ubaddr * VAX_NBPG;
1491.12Sragge	sc->uv_sc.uh_type = UBA_UBA;
1501.1Sragge
1511.1Sragge	/*
1521.1Sragge	 * Set up dispatch vectors for DW780.
1531.1Sragge	 */
1541.8Sragge	for (i = 0x14; i < 0x18; i++)
1551.6Sragge		scb_vecalloc(vecnum(0, i, sa->sa_nexnum), uba_dw780int,
1561.5Smatt		    sc, SCB_ISTACK, &sc->uv_sc.uh_intrcnt);
1571.7Smatt	evcnt_attach_dynamic(&sc->uv_sc.uh_intrcnt, EVCNT_TYPE_INTR, NULL,
1581.7Smatt		sc->uv_sc.uh_dev.dv_xname, "intr");
1591.5Smatt
1601.1Sragge	/*
1611.1Sragge	 * Fill in variables used by the sgmap system.
1621.1Sragge	 */
1631.4Sragge	sc->uv_size = UBASIZE;		/* Size in bytes of Unibus space */
1641.1Sragge
1651.1Sragge	uba_dma_init(sc);
1661.12.2.1Sjdolecek	uba_attach(&sc->uv_sc, (sa->sa_sbinum ? UMEMB8600(ubaddr) :
1671.1Sragge	    UMEMA8600(ubaddr)) + (UBAPAGES * VAX_NBPG));
1681.1Sragge}
1691.1Sragge
1701.1Sraggevoid
1711.12.2.1Sjdolecekdw780_beforescan(struct uba_softc *sc)
1721.1Sragge{
1731.1Sragge	struct uba_vsoftc *vc = (void *)sc;
1741.1Sragge	volatile int *hej = &vc->uv_uba->uba_sr;
1751.1Sragge
1761.1Sragge	*hej = *hej;
1771.1Sragge	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE;
1781.1Sragge}
1791.1Sragge
1801.1Sraggevoid
1811.12.2.1Sjdolecekdw780_afterscan(struct uba_softc *sc)
1821.1Sragge{
1831.1Sragge	struct uba_vsoftc *vc = (void *)sc;
1841.1Sragge
1851.1Sragge	vc->uv_uba->uba_cr = UBACR_IFS | UBACR_BRIE |
1861.1Sragge	    UBACR_USEFIE | UBACR_SUEFIE |
1871.1Sragge	    (vc->uv_uba->uba_cr & 0x7c000000);
1881.1Sragge}
1891.1Sragge
1901.1Sragge
1911.1Sraggeint
1921.12.2.1Sjdolecekdw780_errchk(struct uba_softc *sc)
1931.1Sragge{
1941.1Sragge	struct uba_vsoftc *vc = (void *)sc;
1951.1Sragge	volatile int *hej = &vc->uv_uba->uba_sr;
1961.1Sragge
1971.1Sragge	if (*hej) {
1981.1Sragge		*hej = *hej;
1991.1Sragge		return 1;
2001.1Sragge	}
2011.1Sragge	return 0;
2021.1Sragge}
2031.1Sragge
2041.1Sraggevoid
2051.12.2.1Sjdolecekuba_dw780int(void *arg)
2061.1Sragge{
2071.12.2.1Sjdolecek	extern	void scb_stray(void *);
2081.2Smatt	struct	uba_vsoftc *vc = arg;
2091.1Sragge	struct	uba_regs *ur = vc->uv_uba;
2101.12.2.1Sjdolecek	struct	ivec_dsp *ivec;
2111.2Smatt	int	br, vec;
2121.1Sragge
2131.1Sragge	br = mfpr(PR_IPL);
2141.1Sragge	vec = ur->uba_brrvr[br - 0x14];
2151.1Sragge	if (vec <= 0) {
2161.12.2.1Sjdolecek		ubaerror(&vc->uv_sc, &br, &vec);
2171.12.2.1Sjdolecek		if (vec == 0)
2181.1Sragge			return;
2191.1Sragge	}
2201.12.2.1Sjdolecek
2211.12.2.1Sjdolecek	if (cold && scb_vec[(vc->uh_ibase + vec)/4].hoppaddr == scb_stray) {
2221.1Sragge		scb_fake(vec + vc->uh_ibase, br);
2231.12.2.1Sjdolecek	} else {
2241.12.2.1Sjdolecek		ivec = &scb_vec[(vc->uh_ibase + vec)/4];
2251.12.2.1Sjdolecek		(*ivec->hoppaddr)(ivec->pushlarg);
2261.1Sragge	}
2271.1Sragge}
2281.1Sragge
2291.1Sraggevoid
2301.12.2.1Sjdolecekdw780_init(struct uba_softc *sc)
2311.1Sragge{
2321.1Sragge	struct uba_vsoftc *vc = (void *)sc;
2331.1Sragge
2341.1Sragge	vc->uv_uba->uba_cr = UBACR_ADINIT;
2351.1Sragge	vc->uv_uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
2361.1Sragge	while ((vc->uv_uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
2371.1Sragge		;
2381.1Sragge}
2391.1Sragge
2401.1Sragge#ifdef notyet
2411.1Sraggevoid
2421.1Sraggedw780_purge(sc, bdp)
2431.1Sragge	struct uba_softc *sc;
2441.1Sragge	int bdp;
2451.1Sragge{
2461.1Sragge	struct uba_vsoftc *vc = (void *)sc;
2471.1Sragge
2481.1Sragge	vc->uv_uba->uba_dpr[bdp] |= UBADPR_BNE;
2491.1Sragge}
2501.1Sragge#endif
2511.1Sragge
2521.1Sraggeint	ubawedgecnt = 10;
2531.1Sraggeint	ubacrazy = 500;
2541.1Sraggeint	zvcnt_max = 5000;	/* in 8 sec */
2551.1Sraggeint	ubaerrcnt;
2561.1Sragge/*
2571.1Sragge * This routine is called by the locore code to process a UBA
2581.1Sragge * error on an 11/780 or 8600.	The arguments are passed
2591.1Sragge * on the stack, and value-result (through some trickery).
2601.1Sragge * In particular, the uvec argument is used for further
2611.1Sragge * uba processing so the result aspect of it is very important.
2621.1Sragge */
2631.1Sragge/*ARGSUSED*/
2641.1Sraggevoid
2651.12.2.1Sjdolecekubaerror(struct uba_softc *uh, int *ipl, int *uvec)
2661.1Sragge{
2671.1Sragge	struct uba_vsoftc *vc = (void *)uh;
2681.1Sragge	struct	uba_regs *uba = vc->uv_uba;
2691.12.2.1Sjdolecek	int sr, s;
2701.10Sragge	char sbuf[256], sbuf2[256];
2711.1Sragge
2721.1Sragge	if (*uvec == 0) {
2731.1Sragge		/*
2741.1Sragge		 * Declare dt as unsigned so that negative values
2751.1Sragge		 * are handled as >8 below, in case time was set back.
2761.1Sragge		 */
2771.1Sragge		u_long	dt = time.tv_sec - vc->uh_zvtime;
2781.1Sragge
2791.1Sragge		vc->uh_zvtotal++;
2801.1Sragge		if (dt > 8) {
2811.1Sragge			vc->uh_zvtime = time.tv_sec;
2821.1Sragge			vc->uh_zvcnt = 0;
2831.1Sragge		}
2841.1Sragge		if (++vc->uh_zvcnt > zvcnt_max) {
2851.1Sragge			printf("%s: too many zero vectors (%d in <%d sec)\n",
2861.1Sragge				vc->uv_sc.uh_dev.dv_xname, vc->uh_zvcnt, (int)dt + 1);
2871.9Stv
2881.9Stv			bitmask_snprintf(uba->uba_cnfgr&(~0xff), UBACNFGR_BITS,
2891.9Stv					 sbuf, sizeof(sbuf));
2901.9Stv			printf("\tIPL 0x%x\n\tcnfgr: %s	 Adapter Code: 0x%x\n",
2911.9Stv				*ipl, sbuf, uba->uba_cnfgr&0xff);
2921.9Stv
2931.9Stv			bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
2941.9Stv			printf("\tsr: %s\n\tdcr: %x (MIC %sOK)\n",
2951.9Stv				sbuf, uba->uba_dcr,
2961.1Sragge				(uba->uba_dcr&0x8000000)?"":"NOT ");
2971.9Stv
2981.3Sragge			ubareset(&vc->uv_sc);
2991.1Sragge		}
3001.1Sragge		return;
3011.1Sragge	}
3021.1Sragge	if (uba->uba_cnfgr & NEX_CFGFLT) {
3031.9Stv		bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
3041.9Stv		bitmask_snprintf(uba->uba_cnfgr, NEXFLT_BITS, sbuf2, sizeof(sbuf2));
3051.9Stv		printf("%s: sbi fault sr=%s cnfgr=%s\n",
3061.9Stv		    vc->uv_sc.uh_dev.dv_xname, sbuf, sbuf2);
3071.3Sragge		ubareset(&vc->uv_sc);
3081.1Sragge		*uvec = 0;
3091.1Sragge		return;
3101.1Sragge	}
3111.1Sragge	sr = uba->uba_sr;
3121.11Sthorpej	s = spluba();
3131.9Stv	bitmask_snprintf(uba->uba_sr, ubasr_bits, sbuf, sizeof(sbuf));
3141.9Stv	printf("%s: uba error sr=%s fmer=%x fubar=%o\n", vc->uv_sc.uh_dev.dv_xname,
3151.9Stv	    sbuf, uba->uba_fmer, 4*uba->uba_fubar);
3161.1Sragge	splx(s);
3171.1Sragge	uba->uba_sr = sr;
3181.1Sragge	*uvec &= UBABRRVR_DIV;
3191.1Sragge	if (++ubaerrcnt % ubawedgecnt == 0) {
3201.1Sragge		if (ubaerrcnt > ubacrazy)
3211.1Sragge			panic("uba crazy");
3221.1Sragge		printf("ERROR LIMIT ");
3231.3Sragge		ubareset(&vc->uv_sc);
3241.1Sragge		*uvec = 0;
3251.1Sragge	}
3261.1Sragge}
327