1 /* $OpenBSD: asp.c,v 1.6 2002/03/14 01:26:31 millert Exp $ */ 2 3 /* 4 * Copyright (c) 1998,1999 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Michael Shalayeff. 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 MIND, 27 * USE, 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 * References: 35 * 36 * 1. Cobra/Coral I/O Subsystem External Reference Specification 37 * Hewlett-Packard 38 * 39 */ 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/device.h> 44 #include <sys/reboot.h> 45 46 #include <machine/bus.h> 47 #include <machine/iomod.h> 48 #include <machine/autoconf.h> 49 #include <machine/cpufunc.h> 50 51 #include <hppa/dev/cpudevs.h> 52 #include <hppa/dev/viper.h> 53 54 #include <hppa/gsc/gscbusvar.h> 55 56 struct asp_hwr { 57 u_int8_t asp_reset; 58 u_int8_t asp_resv[31]; 59 u_int8_t asp_version; 60 u_int8_t asp_resv1[15]; 61 u_int8_t asp_scsidsync; 62 u_int8_t asp_resv2[15]; 63 u_int8_t asp_error; 64 }; 65 66 struct asp_trs { 67 u_int32_t asp_irr; 68 u_int32_t asp_imr; 69 u_int32_t asp_ipr; 70 u_int32_t asp_icr; 71 u_int32_t asp_iar; 72 u_int32_t asp_resv[3]; 73 u_int8_t asp_cled; 74 u_int8_t asp_resv1[3]; 75 struct { 76 u_int :20, 77 asp_spu : 3, /* SPU ID board jumper */ 78 #define ASP_SPUCOBRA 0 79 #define ASP_SPUCORAL 1 80 #define ASP_SPUBUSH 2 81 #define ASP_SPUHARDBALL 3 82 #define ASP_SPUSCORPIO 4 83 #define ASP_SPUCORAL2 5 84 asp_sw : 1, /* front switch is normal */ 85 asp_clk : 1, /* SCSI clock is doubled */ 86 asp_lan : 2, /* LAN iface selector */ 87 #define ASP_LANINVAL 0 88 #define ASP_LANAUI 1 89 #define ASP_LANTHIN 2 90 #define ASP_LANMISS 3 91 asp_lanf: 1, /* LAN AUI fuse is ok */ 92 asp_spwr: 1, /* SCSI power ok */ 93 asp_scsi: 3; /* SCSI ctrl ID */ 94 } _asp_ios; 95 #define asp_spu _asp_ios.asp_spu 96 #define asp_sw _asp_ios.asp_sw 97 #define asp_clk _asp_ios.asp_clk 98 #define asp_lan _asp_ios.asp_lan 99 #define asp_lanf _asp_ios.asp_lanf 100 #define asp_spwr _asp_ios.asp_spwr 101 #define asp_scsi _asp_ios.asp_scsi 102 }; 103 104 const struct asp_spus_tag { 105 char name[12]; 106 int ledword; 107 } asp_spus[] = { 108 { "Cobra", 0 }, 109 { "Coral", 0 }, 110 { "Bushmaster", 0 }, 111 { "Hardball", 1 }, 112 { "Scorpio", 0 }, 113 { "Coral II", 1 }, 114 { "#6", 0 }, 115 { "#7", 0 } 116 }; 117 118 struct asp_softc { 119 struct device sc_dev; 120 struct gscbus_ic sc_ic; 121 122 volatile struct asp_hwr *sc_hw; 123 volatile struct asp_trs *sc_trs; 124 }; 125 126 /* ASP "Primary Controller" HPA */ 127 #define ASP_CHPA 0xF0800000 128 129 int aspmatch(struct device *, void *, void *); 130 void aspattach(struct device *, struct device *, void *); 131 132 struct cfattach asp_ca = { 133 sizeof(struct asp_softc), aspmatch, aspattach 134 }; 135 136 struct cfdriver asp_cd = { 137 NULL, "asp", DV_DULL 138 }; 139 140 void asp_intr_establish(void *v, u_int32_t mask); 141 void asp_intr_disestablish(void *v, u_int32_t mask); 142 u_int32_t asp_intr_check(void *v); 143 void asp_intr_ack(void *v, u_int32_t mask); 144 145 int 146 aspmatch(parent, cfdata, aux) 147 struct device *parent; 148 void *cfdata; 149 void *aux; 150 { 151 struct confargs *ca = aux; 152 /* struct cfdata *cf = cfdata; */ 153 154 if (ca->ca_type.iodc_type != HPPA_TYPE_BHA || 155 ca->ca_type.iodc_sv_model != HPPA_BHA_ASP) 156 return 0; 157 158 return 1; 159 } 160 161 void 162 aspattach(parent, self, aux) 163 struct device *parent; 164 struct device *self; 165 void *aux; 166 { 167 register struct confargs *ca = aux; 168 register struct asp_softc *sc = (struct asp_softc *)self; 169 struct gsc_attach_args ga; 170 bus_space_handle_t ioh; 171 register u_int32_t irr; 172 register int s; 173 174 if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) { 175 #ifdef DEBUG 176 printf("aspattach: can't map IO space\n"); 177 #endif 178 return; 179 } 180 181 sc->sc_trs = (struct asp_trs *)ASP_CHPA; 182 sc->sc_hw = (struct asp_hwr *)ca->ca_hpa; 183 184 machine_ledaddr = &sc->sc_trs->asp_cled; 185 machine_ledword = asp_spus[sc->sc_trs->asp_spu].ledword; 186 187 /* reset ASP */ 188 /* sc->sc_hw->asp_reset = 1; */ 189 /* delay(400000); */ 190 191 s = splhigh(); 192 viper_setintrwnd(1 << ca->ca_irq); 193 194 sc->sc_trs->asp_imr = ~0; 195 irr = sc->sc_trs->asp_irr; 196 sc->sc_trs->asp_imr = 0; 197 splx(s); 198 199 printf (": %s rev %d, lan %d scsi %d\n", 200 asp_spus[sc->sc_trs->asp_spu].name, sc->sc_hw->asp_version, 201 sc->sc_trs->asp_lan, sc->sc_trs->asp_scsi); 202 203 sc->sc_ic.gsc_type = gsc_asp; 204 sc->sc_ic.gsc_dv = sc; 205 sc->sc_ic.gsc_intr_establish = asp_intr_establish; 206 sc->sc_ic.gsc_intr_disestablish = asp_intr_disestablish; 207 sc->sc_ic.gsc_intr_check = asp_intr_check; 208 sc->sc_ic.gsc_intr_ack = asp_intr_ack; 209 210 ga.ga_ca = *ca; /* clone from us */ 211 ga.ga_name = "gsc"; 212 ga.ga_ic = &sc->sc_ic; 213 config_found(self, &ga, gscprint); 214 } 215 216 void 217 asp_intr_establish(v, mask) 218 void *v; 219 u_int32_t mask; 220 { 221 register struct asp_softc *sc = v; 222 223 sc->sc_trs->asp_imr |= mask; 224 } 225 226 void 227 asp_intr_disestablish(v, mask) 228 void *v; 229 u_int32_t mask; 230 { 231 register struct asp_softc *sc = v; 232 233 sc->sc_trs->asp_imr &= ~mask; 234 } 235 236 u_int32_t 237 asp_intr_check(v) 238 void *v; 239 { 240 register struct asp_softc *sc = v; 241 register u_int32_t irr, imr; 242 243 imr = sc->sc_trs->asp_imr; 244 irr = sc->sc_trs->asp_irr; 245 sc->sc_trs->asp_imr = imr & ~irr; 246 247 return irr; 248 } 249 250 void 251 asp_intr_ack(v, mask) 252 void *v; 253 u_int32_t mask; 254 { 255 register struct asp_softc *sc = v; 256 257 sc->sc_trs->asp_imr |= mask; 258 } 259