1 /* $OpenBSD: aic_pcmcia.c,v 1.17 2015/03/14 03:38:49 jsg Exp $ */ 2 /* $NetBSD: aic_pcmcia.c,v 1.6 1998/07/19 17:28:15 christos Exp $ */ 3 4 /* 5 * Copyright (c) 1997 Marc Horowitz. 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 Marc Horowitz. 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 #include <sys/param.h> 34 #include <sys/systm.h> 35 #include <sys/selinfo.h> 36 #include <sys/device.h> 37 38 #include <machine/cpu.h> 39 #include <machine/bus.h> 40 #include <machine/intr.h> 41 42 #include <scsi/scsi_all.h> 43 #include <scsi/scsiconf.h> 44 45 #include <dev/ic/aic6360var.h> 46 47 #include <dev/pcmcia/pcmciavar.h> 48 #include <dev/pcmcia/pcmciadevs.h> 49 50 int aic_pcmcia_match(struct device *, void *, void *); 51 void aic_pcmcia_attach(struct device *, struct device *, void *); 52 int aic_pcmcia_detach(struct device *, int); 53 54 struct aic_pcmcia_softc { 55 struct aic_softc sc_aic; /* real "aic" softc */ 56 57 /* PCMCIA-specific goo. */ 58 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */ 59 int sc_io_window; /* our i/o window */ 60 struct pcmcia_function *sc_pf; /* our PCMCIA function */ 61 void *sc_ih; /* interrupt handler */ 62 }; 63 64 struct cfattach aic_pcmcia_ca = { 65 sizeof(struct aic_pcmcia_softc), aic_pcmcia_match, aic_pcmcia_attach, 66 aic_pcmcia_detach 67 }; 68 69 struct aic_pcmcia_product { 70 u_int16_t app_vendor; /* PCMCIA vendor ID */ 71 u_int16_t app_product; /* PCMCIA product ID */ 72 int app_expfunc; /* expected function number */ 73 } aic_pcmcia_prod[] = { 74 { PCMCIA_VENDOR_ADAPTEC, PCMCIA_PRODUCT_ADAPTEC_APA1460_1, 75 0 }, 76 77 { PCMCIA_VENDOR_ADAPTEC, PCMCIA_PRODUCT_ADAPTEC_APA1460_2, 78 0 }, 79 80 { PCMCIA_VENDOR_NEWMEDIA, PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER, 81 0 } 82 }; 83 84 int 85 aic_pcmcia_match(parent, match, aux) 86 struct device *parent; 87 void *match, *aux; 88 { 89 struct pcmcia_attach_args *pa = aux; 90 int i; 91 92 for (i = 0; i < nitems(aic_pcmcia_prod); i++) 93 if (pa->manufacturer == aic_pcmcia_prod[i].app_vendor && 94 pa->product == aic_pcmcia_prod[i].app_product && 95 pa->pf->number == aic_pcmcia_prod[i].app_expfunc) 96 return (1); 97 return (0); 98 } 99 100 void 101 aic_pcmcia_attach(parent, self, aux) 102 struct device *parent, *self; 103 void *aux; 104 { 105 struct aic_pcmcia_softc *psc = (void *)self; 106 struct aic_softc *sc = &psc->sc_aic; 107 struct pcmcia_attach_args *pa = aux; 108 struct pcmcia_config_entry *cfe; 109 struct pcmcia_function *pf = pa->pf; 110 const char *intrstr; 111 112 psc->sc_pf = pf; 113 114 for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL; 115 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) { 116 if (cfe->num_memspace != 0 || 117 cfe->num_iospace != 1) 118 continue; 119 120 /* The bustoaster has a default config as first 121 * entry, we don't want to use that. */ 122 123 if (pa->manufacturer == PCMCIA_VENDOR_NEWMEDIA && 124 pa->product == PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER && 125 cfe->iospace[0].start == 0) 126 continue; 127 128 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start, 129 cfe->iospace[0].length, AIC_NPORTS, &psc->sc_pcioh) == 0) 130 break; 131 } 132 133 if (cfe == 0) { 134 printf(": can't alloc i/o space\n"); 135 return; 136 } 137 138 sc->sc_iot = psc->sc_pcioh.iot; 139 sc->sc_ioh = psc->sc_pcioh.ioh; 140 141 /* Enable the card. */ 142 pcmcia_function_init(pf, cfe); 143 if (pcmcia_function_enable(pf)) { 144 printf(": function enable failed\n"); 145 return; 146 } 147 148 /* Map in the io space */ 149 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size, 150 &psc->sc_pcioh, &psc->sc_io_window)) { 151 printf(": can't map i/o space\n"); 152 return; 153 } 154 155 printf(" port 0x%lx/%lu", psc->sc_pcioh.addr, 156 (u_long)psc->sc_pcioh.size); 157 158 if (!aic_find(sc->sc_iot, sc->sc_ioh)) { 159 printf(": unable to detect chip!\n"); 160 return; 161 } 162 163 /* Establish the interrupt handler. */ 164 psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, 165 aicintr, sc, sc->sc_dev.dv_xname); 166 intrstr = pcmcia_intr_string(psc->sc_pf, psc->sc_ih); 167 printf("%s%s\n", *intrstr ? ", " : "", intrstr); 168 if (psc->sc_ih == NULL) 169 return; 170 171 aicattach(sc); 172 173 } 174 175 int 176 aic_pcmcia_detach(self, flags) 177 struct device *self; 178 int flags; 179 { 180 struct aic_pcmcia_softc *sc= (void *)self; 181 int error; 182 183 error = aic_detach(self, flags); 184 if (error) 185 return (error); 186 187 /* Unmap our i/o window and i/o space. */ 188 pcmcia_io_unmap(sc->sc_pf, sc->sc_io_window); 189 pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh); 190 191 return (0); 192 } 193