1 /* $NetBSD: uba_bi.c,v 1.13 2008/04/06 07:23:57 cegger 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/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: uba_bi.c,v 1.13 2008/04/06 07:23:57 cegger Exp $"); 39 40 #include <sys/param.h> 41 #include <sys/kernel.h> 42 #include <sys/buf.h> 43 #include <sys/device.h> 44 #include <sys/proc.h> 45 #include <sys/user.h> 46 #include <sys/malloc.h> 47 #include <sys/systm.h> 48 49 #include <machine/sid.h> 50 #include <machine/pte.h> 51 #include <machine/pcb.h> 52 #include <machine/trap.h> 53 #include <machine/scb.h> 54 55 #include <vax/bi/bireg.h> 56 #include <vax/bi/bivar.h> 57 58 #include <vax/uba/ubareg.h> 59 #include <vax/uba/ubavar.h> 60 61 #include "locators.h" 62 63 #define BUA(uba) ((struct dwbua_regs *)(uba)) 64 65 static int uba_bi_match(device_t, cfdata_t, void *); 66 static void uba_bi_attach(device_t, device_t, void *); 67 static void bua_init(struct uba_softc *); 68 static void bua_purge(struct uba_softc *, int); 69 70 /* bua_csr */ 71 #define BUACSR_ERR 0x80000000 /* composite error */ 72 #define BUACSR_BIF 0x10000000 /* BI failure */ 73 #define BUACSR_SSYNTO 0x08000000 /* slave sync timeout */ 74 #define BUACSR_UIE 0x04000000 /* unibus interlock error */ 75 #define BUACSR_IVMR 0x02000000 /* invalid map register */ 76 #define BUACSR_BADBDP 0x01000000 /* bad BDP select */ 77 #define BUACSR_BUAEIE 0x00100000 /* bua error interrupt enable (?) */ 78 #define BUACSR_UPI 0x00020000 /* unibus power init */ 79 #define BUACSR_UREGDUMP 0x00010000 /* microdiag register dump */ 80 #define BUACSR_IERRNO 0x000000ff /* mask for internal errror number */ 81 82 /* bua_offset */ 83 #define BUAOFFSET_MASK 0x00003e00 /* hence max offset = 15872 */ 84 85 /* bua_dpr */ 86 #define BUADPR_DPSEL 0x00e00000 /* data path select (?) */ 87 #define BUADPR_PURGE 0x00000001 /* purge bdp */ 88 89 /* bua_map -- in particular, those bits that are not in DW780s & DW750s */ 90 #define BUAMR_IOADR 0x40000000 /* I/O address space */ 91 #define BUAMR_LAE 0x04000000 /* longword access enable */ 92 93 static int allocvec; 94 95 CFATTACH_DECL_NEW(uba_bi, sizeof(struct uba_softc), 96 uba_bi_match, uba_bi_attach, NULL, NULL); 97 98 struct dwbua_regs { 99 struct biiregs bn_biic; /* interface */ 100 int pad1[396]; 101 int bn_csr; 102 int bn_vor; /* Vector offset from SCB */ 103 int bn_fubar; /* Failed Unibus address register */ 104 int bn_bifar; /* BI failed address register */ 105 int bn_mdiag[5]; /* microdiag regs for BDP */ 106 int pad2[3]; 107 int bn_dpcsr[6]; /* Data path control and status register */ 108 int pad3[38]; 109 struct pte bn_map[UBAPAGES]; /* Unibus map registers */ 110 int pad4[UBAIOPAGES]; 111 }; 112 113 /* 114 * Poke at a supposed DWBUA to see if it is there. 115 */ 116 static int 117 uba_bi_match(device_t parent, cfdata_t cf, void *aux) 118 { 119 struct bi_attach_args *ba = aux; 120 121 if ((ba->ba_node->biic.bi_dtype != BIDT_DWBUA) && 122 (ba->ba_node->biic.bi_dtype != BIDT_KLESI)) 123 return 0; 124 125 if (cf->cf_loc[BICF_NODE] != BICF_NODE_DEFAULT && 126 cf->cf_loc[BICF_NODE] != ba->ba_nodenr) 127 return 0; 128 129 return 1; 130 } 131 132 void 133 uba_bi_attach(device_t parent, device_t self, void *aux) 134 { 135 struct uba_softc *sc = device_private(self); 136 struct bi_attach_args *ba = aux; 137 volatile int timo; 138 139 if (ba->ba_node->biic.bi_dtype == BIDT_DWBUA) 140 printf(": DWBUA\n"); 141 else 142 printf(": KLESI-B\n"); 143 144 /* 145 * Fill in bus specific data. 146 */ 147 sc->uh_dev = self; 148 sc->uh_uba = (void *)ba->ba_node; 149 sc->uh_nbdp = NBDPBUA; 150 /* sc->uh_nr is 0; uninteresting here */ 151 /* sc->uh_afterscan; not used */ 152 /* sc->uh_errchk; not used */ 153 /* sc->uh_beforescan */ 154 sc->uh_ubapurge = bua_purge; 155 sc->uh_ubainit = bua_init; 156 /* sc->uh_type not used */ 157 sc->uh_memsize = UBAPAGES; 158 sc->uh_mr = BUA(sc->uh_uba)->bn_map; 159 160 #ifdef notdef 161 /* Can we get separate interrupts? */ 162 scb->scb_nexvec[1][ba->ba_nodenr] = &sc->sc_ivec; 163 #endif 164 BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_ARB_NONE; 165 BUA(sc->uh_uba)->bn_biic.bi_csr |= BICSR_STS | BICSR_INIT; 166 DELAY(1000); 167 timo = 1000; 168 while (BUA(sc->uh_uba)->bn_biic.bi_csr & BICSR_BROKE) 169 if (timo == 0) { 170 aprint_error_dev(self, "BROKE bit set\n"); 171 return; 172 } 173 174 BUA(sc->uh_uba)->bn_biic.bi_intrdes = ba->ba_intcpu; 175 BUA(sc->uh_uba)->bn_biic.bi_csr = 176 (BUA(sc->uh_uba)->bn_biic.bi_csr&~BICSR_ARB_MASK) | BICSR_ARB_HIGH; 177 BUA(sc->uh_uba)->bn_vor = VAX_NBPG + (VAX_NBPG * allocvec++); 178 179 uba_attach(sc, BUA(sc->uh_uba)->bn_biic.bi_sadr + UBAPAGES * VAX_NBPG); 180 } 181 182 183 void 184 bua_init(sc) 185 struct uba_softc *sc; 186 { 187 BUA(sc->uh_uba)->bn_csr |= BUACSR_UPI; 188 DELAY(500000); 189 }; 190 191 void 192 bua_purge(sc, bdp) 193 struct uba_softc *sc; 194 int bdp; 195 { 196 BUA(sc->uh_uba)->bn_dpcsr[bdp] |= BUADPR_PURGE; 197 } 198