1 /* $OpenBSD: cac_eisa.c,v 1.5 2017/09/08 05:36:52 deraadt Exp $ */ 2 /* $NetBSD: cac_eisa.c,v 1.1 2000/09/01 12:15:20 ad Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Andrew Doran. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 2000 Jonathan Lemon 35 * Copyright (c) 1999 by Matthew N. Dodd <winter@jurai.net> 36 * All Rights Reserved. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions, and the following disclaimer, 43 * without modification, immediately at the beginning of the file. 44 * 2. The name of the author may not be used to endorse or promote products 45 * derived from this software without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 51 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * SUCH DAMAGE. 58 */ 59 60 /* 61 * EISA front-end for cac(4) driver. 62 */ 63 64 #include <sys/param.h> 65 #include <sys/systm.h> 66 #include <sys/device.h> 67 68 #include <machine/bus.h> 69 #include <machine/intr.h> 70 71 #include <dev/eisa/eisavar.h> 72 #include <dev/eisa/eisadevs.h> 73 74 #include <scsi/scsi_all.h> 75 #include <scsi/scsi_disk.h> 76 #include <scsi/scsiconf.h> 77 78 #include <dev/ic/cacreg.h> 79 #include <dev/ic/cacvar.h> 80 81 #define CAC_EISA_SLOT_OFFSET 0x0c88 82 #define CAC_EISA_IOSIZE 0x0017 83 #define CAC_EISA_IOCONF 0x38 84 85 int cac_eisa_match(struct device *, void *, void *); 86 void cac_eisa_attach(struct device *, struct device *, void *); 87 88 struct cac_ccb *cac_eisa_l0_completed(struct cac_softc *); 89 int cac_eisa_l0_fifo_full(struct cac_softc *); 90 void cac_eisa_l0_intr_enable(struct cac_softc *, int); 91 int cac_eisa_l0_intr_pending(struct cac_softc *); 92 void cac_eisa_l0_submit(struct cac_softc *, struct cac_ccb *); 93 94 struct cfattach cac_eisa_ca = { 95 sizeof(struct cac_softc), cac_eisa_match, cac_eisa_attach 96 }; 97 98 static const 99 struct cac_linkage cac_eisa_l0 = { 100 cac_eisa_l0_completed, 101 cac_eisa_l0_fifo_full, 102 cac_eisa_l0_intr_enable, 103 cac_eisa_l0_intr_pending, 104 cac_eisa_l0_submit 105 }; 106 107 static const 108 struct cac_eisa_type { 109 const char *ct_prodstr; 110 const char *ct_typestr; 111 const struct cac_linkage *ct_linkage; 112 } cac_eisa_type[] = { 113 { "CPQ4001", "IDA", &cac_eisa_l0 }, 114 { "CPQ4002", "IDA-2", &cac_eisa_l0 }, 115 { "CPQ4010", "IEAS", &cac_eisa_l0 }, 116 { "CPQ4020", "SMART", &cac_eisa_l0 }, 117 { "CPQ4030", "SMART-2/E", &cac_l0 }, 118 }; 119 120 int 121 cac_eisa_match(parent, match, aux) 122 struct device *parent; 123 void *match, *aux; 124 { 125 struct eisa_attach_args *ea; 126 int i; 127 128 ea = aux; 129 130 for (i = 0; i < sizeof(cac_eisa_type) / sizeof(cac_eisa_type[0]); i++) 131 if (strcmp(ea->ea_idstring, cac_eisa_type[i].ct_prodstr) == 0) 132 return (1); 133 134 return (0); 135 } 136 137 void 138 cac_eisa_attach(parent, self, aux) 139 struct device *parent; 140 struct device *self; 141 void *aux; 142 { 143 struct eisa_attach_args *ea; 144 bus_space_handle_t ioh; 145 eisa_chipset_tag_t ec; 146 eisa_intr_handle_t ih; 147 struct cac_softc *sc; 148 bus_space_tag_t iot; 149 const char *intrstr; 150 int irq, i; 151 152 ea = aux; 153 sc = (struct cac_softc *)self; 154 iot = ea->ea_iot; 155 ec = ea->ea_ec; 156 157 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + 158 CAC_EISA_SLOT_OFFSET, CAC_EISA_IOSIZE, 0, &ioh)) { 159 printf(": can't map i/o space\n"); 160 return; 161 } 162 163 /* 164 * Print board type and attach to the bus-independent code. 165 */ 166 for (i = 0; i < nitems(cac_eisa_type); i++) 167 if (strcmp(ea->ea_idstring, cac_eisa_type[i].ct_prodstr) == 0) 168 break; 169 170 if (i == nitems(cac_eisa_type)) { 171 printf(": failed to attach %s\n", ea->ea_idstring); 172 return; 173 } 174 175 sc->sc_iot = iot; 176 sc->sc_ioh = ioh; 177 sc->sc_dmat = ea->ea_dmat; 178 179 /* 180 * Map and establish the interrupt. 181 */ 182 switch (bus_space_read_1(iot, ioh, CAC_EISA_IOCONF) & 0xf0) { 183 case 0x20: 184 irq = 10; 185 break; 186 case 0x10: 187 irq = 11; 188 break; 189 case 0x40: 190 irq = 14; 191 break; 192 case 0x80: 193 irq = 15; 194 break; 195 default: 196 printf(": controller on invalid IRQ\n"); 197 return; 198 } 199 200 if (eisa_intr_map(ec, irq, &ih)) { 201 printf(": can't map interrupt (%d)\n", irq); 202 return; 203 } 204 205 intrstr = eisa_intr_string(ec, ih); 206 if ((sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO, 207 cac_intr, sc, sc->sc_dv.dv_xname)) == NULL) { 208 printf(": can't establish interrupt"); 209 if (intrstr != NULL) 210 printf(" at %s", intrstr); 211 printf("\n"); 212 return; 213 } 214 215 printf(" %s: Compaq %s\n", intrstr, cac_eisa_type[i].ct_typestr); 216 sc->sc_cl = cac_eisa_type[i].ct_linkage; 217 cac_init(sc, 0); 218 } 219 220 /* 221 * Linkage specific to EISA boards. 222 */ 223 224 int 225 cac_eisa_l0_fifo_full(struct cac_softc *sc) 226 { 227 228 return ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) & 229 CAC_EISA_CHANNEL_CLEAR) == 0); 230 } 231 232 void 233 cac_eisa_l0_submit(struct cac_softc *sc, struct cac_ccb *ccb) 234 { 235 u_int16_t size; 236 237 /* 238 * On these boards, `ccb_hdr.size' is actually for control flags. 239 * Set it to zero and pass the value by means of an I/O port. 240 */ 241 size = letoh16(ccb->ccb_hdr.size) << 2; 242 ccb->ccb_hdr.size = 0; 243 244 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, (caddr_t)ccb - sc->sc_ccbs, 245 sizeof(struct cac_ccb), BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 246 247 cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_CLEAR); 248 cac_outl(sc, CAC_EISAREG_LIST_ADDR, ccb->ccb_paddr); 249 cac_outw(sc, CAC_EISAREG_LIST_LEN, size); 250 cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_BUSY); 251 } 252 253 struct cac_ccb * 254 cac_eisa_l0_completed(struct cac_softc *sc) 255 { 256 struct cac_ccb *ccb; 257 u_int32_t off; 258 u_int8_t status; 259 260 if ((cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) & 261 CAC_EISA_CHANNEL_BUSY) == 0) 262 return (NULL); 263 264 cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, CAC_EISA_CHANNEL_BUSY); 265 off = cac_inl(sc, CAC_EISAREG_COMPLETE_ADDR); 266 status = cac_inb(sc, CAC_EISAREG_LIST_STATUS); 267 cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_CLEAR); 268 269 if (off == 0) 270 return (NULL); 271 272 off = (off & ~3) - sc->sc_ccbs_paddr; 273 ccb = (struct cac_ccb *)(sc->sc_ccbs + off); 274 275 bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap, off, sizeof(struct cac_ccb), 276 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 277 278 ccb->ccb_req.error = status; 279 return (ccb); 280 } 281 282 int 283 cac_eisa_l0_intr_pending(struct cac_softc *sc) 284 { 285 286 return (cac_inb(sc, CAC_EISAREG_SYSTEM_DOORBELL) & 287 CAC_EISA_CHANNEL_BUSY); 288 } 289 290 void 291 cac_eisa_l0_intr_enable(struct cac_softc *sc, int state) 292 { 293 294 if (state) { 295 cac_outb(sc, CAC_EISAREG_SYSTEM_DOORBELL, 296 ~CAC_EISA_CHANNEL_CLEAR); 297 cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, 298 CAC_EISA_CHANNEL_BUSY); 299 cac_outb(sc, CAC_EISAREG_INTR_MASK, CAC_INTR_ENABLE); 300 cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_ENABLE); 301 } else 302 cac_outb(sc, CAC_EISAREG_SYSTEM_MASK, CAC_INTR_DISABLE); 303 } 304