uba_bi.c revision 1.4
1/*	$NetBSD: uba_bi.c,v 1.4 1999/07/12 13:43:40 ragge Exp $ */
2/*
3 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
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. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed at Ludd, University of
17 *	Lule}, Sweden and its contributors.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * DWBUA BI-Unibus adapter
35 */
36
37#include <sys/param.h>
38#include <sys/kernel.h>
39#include <sys/buf.h>
40#include <sys/device.h>
41#include <sys/proc.h>
42#include <sys/user.h>
43#include <sys/malloc.h>
44#include <sys/systm.h>
45
46#include <machine/sid.h>
47#include <machine/pte.h>
48#include <machine/pcb.h>
49#include <machine/trap.h>
50#include <machine/scb.h>
51
52#include <vax/bi/bireg.h>
53#include <vax/bi/bivar.h>
54
55#include <vax/uba/ubareg.h>
56#include <vax/uba/ubavar.h>
57
58#include "locators.h"
59
60#define	BUA(uba)	((struct dwbua_regs *)(uba))
61
62static	int uba_bi_match __P((struct device *, struct cfdata *, void *));
63static	void uba_bi_attach __P((struct device *, struct device *, void *));
64static	void bua_init __P((struct uba_softc *));
65static	void bua_purge __P((struct uba_softc *, int));
66
67/* bua_csr */
68#define BUACSR_ERR      0x80000000      /* composite error */
69#define BUACSR_BIF      0x10000000      /* BI failure */
70#define BUACSR_SSYNTO   0x08000000      /* slave sync timeout */
71#define BUACSR_UIE      0x04000000      /* unibus interlock error */
72#define BUACSR_IVMR     0x02000000      /* invalid map register */
73#define BUACSR_BADBDP   0x01000000      /* bad BDP select */
74#define BUACSR_BUAEIE   0x00100000      /* bua error interrupt enable (?) */
75#define BUACSR_UPI      0x00020000      /* unibus power init */
76#define BUACSR_UREGDUMP 0x00010000      /* microdiag register dump */
77#define BUACSR_IERRNO   0x000000ff      /* mask for internal errror number */
78
79/* bua_offset */
80#define BUAOFFSET_MASK  0x00003e00      /* hence max offset = 15872 */
81
82/* bua_dpr */
83#define BUADPR_DPSEL    0x00e00000      /* data path select (?) */
84#define BUADPR_PURGE    0x00000001      /* purge bdp */
85
86/* bua_map -- in particular, those bits that are not in DW780s & DW750s */
87#define BUAMR_IOADR     0x40000000      /* I/O address space */
88#define BUAMR_LAE       0x04000000      /* longword access enable */
89
90static	int allocvec;
91
92struct	cfattach uba_bi_ca = {
93	sizeof(struct uba_softc), uba_bi_match, uba_bi_attach,
94};
95
96struct dwbua_regs {
97	struct  biiregs bn_biic;   /* interface */
98	int	pad1[396];
99	int	bn_csr;
100	int	bn_vor;		/* Vector offset from SCB */
101	int	bn_fubar;	/* Failed Unibus address register */
102	int	bn_bifar;	/* BI failed address register */
103	int	bn_mdiag[5];	/* microdiag regs for BDP */
104	int	pad2[3];
105	int	bn_dpcsr[6];	/* Data path control and status register */
106	int	pad3[38];
107	struct	pte bn_map[UBAPAGES];	/* Unibus map registers */
108	int	pad4[UBAIOPAGES];
109};
110
111/*
112 * Poke at a supposed DWBUA to see if it is there.
113 */
114static int
115uba_bi_match(parent, cf, aux)
116	struct	device *parent;
117	struct	cfdata *cf;
118	void	*aux;
119{
120	struct bi_attach_args *ba = aux;
121
122	if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) &&
123	    (ba->ba_node->biic.bi_dtype != BIDT_KLESI))
124		return 0;
125
126	if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT &&
127	    cf->cf_loc[BICF_NODE] != ba->ba_nodenr)
128		return 0;
129
130	return 1;
131}
132
133void
134uba_bi_attach(parent, self, aux)
135	struct device *parent, *self;
136	void *aux;
137{
138	struct	uba_softc *sc = (void *)self;
139	struct	bi_attach_args *ba = aux;
140	volatile int timo;
141
142	if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA)
143		printf(": DWBUA\n");
144	else
145		printf(": KLESI-B\n");
146
147	/*
148	 * Fill in bus specific data.
149	 */
150	sc->uh_uba = (void *)ba->ba_node;
151	sc->uh_nbdp = NBDPBUA;
152/*	sc->uh_nr is 0; uninteresting here */
153/*	sc->uh_afterscan; not used */
154/*	sc->uh_errchk; not used */
155/*	sc->uh_beforescan */
156	sc->uh_ubapurge = bua_purge;
157	sc->uh_ubainit = bua_init;
158/*	sc->uh_type not used */
159	sc->uh_memsize = UBAPAGES;
160	sc->uh_mr = BUA(sc->uh_uba)->bn_map;
161
162#ifdef notdef
163	/* Can we get separate interrupts? */
164	scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec;
165#endif
166	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE;
167	BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT;
168	DELAY(1000);
169	timo = 1000;
170	while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE)
171		if (timo == 0) {
172			printf("%s: BROKE bit set\n", self->dv_xname);
173			return;
174		}
175
176	BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu;
177	BUA(sc->uh_uba)->bn_biic.bi_csr =
178	    (BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH;
179	BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++);
180
181	uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG);
182}
183
184
185void
186bua_init(sc)
187	struct uba_softc *sc;
188{
189	BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI;
190	DELAY(500000);
191};
192
193void
194bua_purge(sc, bdp)
195	struct uba_softc *sc;
196	int bdp;
197{
198	BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE;
199}
200