uba_bi.c revision 1.16
11.16Sandvar/*	$NetBSD: uba_bi.c,v 1.16 2024/02/04 18:52:35 andvar Exp $ */
21.1Sragge/*
31.1Sragge * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
41.1Sragge * All rights reserved.
51.1Sragge *
61.1Sragge * Redistribution and use in source and binary forms, with or without
71.1Sragge * modification, are permitted provided that the following conditions
81.1Sragge * are met:
91.1Sragge * 1. Redistributions of source code must retain the above copyright
101.1Sragge *    notice, this list of conditions and the following disclaimer.
111.1Sragge * 2. Redistributions in binary form must reproduce the above copyright
121.1Sragge *    notice, this list of conditions and the following disclaimer in the
131.1Sragge *    documentation and/or other materials provided with the distribution.
141.1Sragge * 3. All advertising materials mentioning features or use of this software
151.1Sragge *    must display the following acknowledgement:
161.10Sperry *	This product includes software developed at Ludd, University of
171.1Sragge *	Lule}, Sweden and its contributors.
181.1Sragge * 4. The name of the author may not be used to endorse or promote products
191.1Sragge *    derived from this software without specific prior written permission
201.1Sragge *
211.1Sragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.1Sragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.1Sragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.1Sragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.1Sragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.1Sragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.1Sragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.1Sragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.1Sragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.1Sragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Sragge */
321.1Sragge
331.1Sragge/*
341.1Sragge * DWBUA BI-Unibus adapter
351.1Sragge */
361.5Slukem
371.5Slukem#include <sys/cdefs.h>
381.16Sandvar__KERNEL_RCSID(0, "$NetBSD: uba_bi.c,v 1.16 2024/02/04 18:52:35 andvar Exp $");
391.1Sragge
401.1Sragge#include <sys/param.h>
411.1Sragge#include <sys/kernel.h>
421.1Sragge#include <sys/buf.h>
431.1Sragge#include <sys/device.h>
441.1Sragge#include <sys/proc.h>
451.1Sragge#include <sys/malloc.h>
461.1Sragge#include <sys/systm.h>
471.1Sragge
481.1Sragge#include <machine/sid.h>
491.1Sragge#include <machine/pte.h>
501.1Sragge#include <machine/pcb.h>
511.1Sragge#include <machine/trap.h>
521.1Sragge#include <machine/scb.h>
531.1Sragge
541.1Sragge#include <vax/bi/bireg.h>
551.1Sragge#include <vax/bi/bivar.h>
561.1Sragge
571.1Sragge#include <vax/uba/ubareg.h>
581.1Sragge#include <vax/uba/ubavar.h>
591.1Sragge
601.1Sragge#include "locators.h"
611.1Sragge
621.1Sragge#define	BUA(uba)	((struct dwbua_regs *)(uba))
631.1Sragge
641.12Smattstatic	int uba_bi_match(device_t, cfdata_t, void *);
651.12Smattstatic	void uba_bi_attach(device_t, device_t, void *);
661.9Sperrystatic	void bua_init(struct uba_softc *);
671.9Sperrystatic	void bua_purge(struct uba_softc *, int);
681.1Sragge
691.1Sragge/* bua_csr */
701.1Sragge#define BUACSR_ERR      0x80000000      /* composite error */
711.1Sragge#define BUACSR_BIF      0x10000000      /* BI failure */
721.1Sragge#define BUACSR_SSYNTO   0x08000000      /* slave sync timeout */
731.1Sragge#define BUACSR_UIE      0x04000000      /* unibus interlock error */
741.1Sragge#define BUACSR_IVMR     0x02000000      /* invalid map register */
751.1Sragge#define BUACSR_BADBDP   0x01000000      /* bad BDP select */
761.1Sragge#define BUACSR_BUAEIE   0x00100000      /* bua error interrupt enable (?) */
771.1Sragge#define BUACSR_UPI      0x00020000      /* unibus power init */
781.1Sragge#define BUACSR_UREGDUMP 0x00010000      /* microdiag register dump */
791.16Sandvar#define BUACSR_IERRNO   0x000000ff      /* mask for internal error number */
801.1Sragge
811.1Sragge/* bua_offset */
821.1Sragge#define BUAOFFSET_MASK  0x00003e00      /* hence max offset = 15872 */
831.1Sragge
841.1Sragge/* bua_dpr */
851.1Sragge#define BUADPR_DPSEL    0x00e00000      /* data path select (?) */
861.1Sragge#define BUADPR_PURGE    0x00000001      /* purge bdp */
871.1Sragge
881.1Sragge/* bua_map -- in particular, those bits that are not in DW780s & DW750s */
891.1Sragge#define BUAMR_IOADR     0x40000000      /* I/O address space */
901.1Sragge#define BUAMR_LAE       0x04000000      /* longword access enable */
911.1Sragge
921.1Sraggestatic	int allocvec;
931.1Sragge
941.12SmattCFATTACH_DECL_NEW(uba_bi, sizeof(struct uba_softc),
951.8Sthorpej    uba_bi_match, uba_bi_attach, NULL, NULL);
961.1Sragge
971.1Sraggestruct dwbua_regs {
981.1Sragge	struct  biiregs bn_biic;   /* interface */
991.1Sragge	int	pad1[396];
1001.1Sragge	int	bn_csr;
1011.1Sragge	int	bn_vor;		/* Vector offset from SCB */
1021.1Sragge	int	bn_fubar;	/* Failed Unibus address register */
1031.1Sragge	int	bn_bifar;	/* BI failed address register */
1041.1Sragge	int	bn_mdiag[5];	/* microdiag regs for BDP */
1051.1Sragge	int	pad2[3];
1061.1Sragge	int	bn_dpcsr[6];	/* Data path control and status register */
1071.1Sragge	int	pad3[38];
1081.1Sragge	struct	pte bn_map[UBAPAGES];	/* Unibus map registers */
1091.1Sragge	int	pad4[UBAIOPAGES];
1101.1Sragge};
1111.1Sragge
1121.1Sragge/*
1131.1Sragge * Poke at a supposed DWBUA to see if it is there.
1141.1Sragge */
1151.1Sraggestatic int
1161.12Smattuba_bi_match(device_t parent, cfdata_t cf, void *aux)
1171.1Sragge{
1181.1Sragge	struct bi_attach_args *ba = aux;
1191.1Sragge
1201.1Sragge	if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) &&
1211.1Sragge	    (ba->ba_node->biic.bi_dtype != BIDT_KLESI))
1221.1Sragge		return 0;
1231.1Sragge
1241.1Sragge	if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
1251.1Sragge	    cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
1261.1Sragge		return 0;
1271.1Sragge
1281.1Sragge	return 1;
1291.1Sragge}
1301.1Sragge
1311.1Sraggevoid
1321.12Smattuba_bi_attach(device_t parent, device_t self, void *aux)
1331.1Sragge{
1341.12Smatt	struct uba_softc *sc = device_private(self);
1351.12Smatt	struct bi_attach_args *ba = aux;
1361.1Sragge	volatile int timo;
1371.1Sragge
1381.1Sragge	if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA)
1391.1Sragge		printf(": DWBUA\n");
1401.1Sragge	else
1411.1Sragge		printf(": KLESI-B\n");
1421.1Sragge
1431.1Sragge	/*
1441.1Sragge	 * Fill in bus specific data.
1451.1Sragge	 */
1461.12Smatt	sc->uh_dev = self;
1471.1Sragge	sc->uh_uba = (void *)ba->ba_node;
1481.1Sragge	sc->uh_nbdp = NBDPBUA;
1491.1Sragge/*	sc->uh_nr is 0; uninteresting here */
1501.1Sragge/*	sc->uh_afterscan; not used */
1511.1Sragge/*	sc->uh_errchk; not used */
1521.1Sragge/*	sc->uh_beforescan */
1531.1Sragge	sc->uh_ubapurge = bua_purge;
1541.1Sragge	sc->uh_ubainit = bua_init;
1551.1Sragge/*	sc->uh_type not used */
1561.1Sragge	sc->uh_memsize = UBAPAGES;
1571.1Sragge	sc->uh_mr = BUA(sc->uh_uba)->bn_map;
1581.1Sragge
1591.1Sragge#ifdef notdef
1601.1Sragge	/* Can we get separate interrupts? */
1611.1Sragge	scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
1621.1Sragge#endif
1631.1Sragge	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE;
1641.1Sragge	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT;
1651.1Sragge	DELAY(1000);
1661.1Sragge	timo = 1000;
1671.1Sragge	while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE)
1681.1Sragge		if (timo == 0) {
1691.13Scegger			aprint_error_dev(self, "BROKE bit set\n");
1701.1Sragge			return;
1711.1Sragge		}
1721.1Sragge
1731.1Sragge	BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu;
1741.10Sperry	BUA(sc->uh_uba)->bn_biic.bi_csr =
1751.1Sragge	    (BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH;
1761.3Sragge	BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++);
1771.1Sragge
1781.2Sragge	uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG);
1791.1Sragge}
1801.1Sragge
1811.1Sragge
1821.1Sraggevoid
1831.14Sdslbua_init(struct uba_softc *sc)
1841.1Sragge{
1851.1Sragge	BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI;
1861.1Sragge	DELAY(500000);
1871.1Sragge};
1881.1Sragge
1891.1Sraggevoid
1901.14Sdslbua_purge(struct uba_softc *sc, int bdp)
1911.1Sragge{
1921.1Sragge	BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE;
1931.1Sragge}
194