LCOV - code coverage report
Current view: top level - dev/pcmcia - aic_pcmcia.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 59 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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           0 : aic_pcmcia_match(parent, match, aux)
      86             :         struct device *parent;
      87             :         void *match, *aux;
      88             : {
      89           0 :         struct pcmcia_attach_args *pa = aux;
      90             :         int i;
      91             : 
      92           0 :         for (i = 0; i < nitems(aic_pcmcia_prod); i++)
      93           0 :                 if (pa->manufacturer == aic_pcmcia_prod[i].app_vendor &&
      94           0 :                     pa->product == aic_pcmcia_prod[i].app_product &&
      95           0 :                     pa->pf->number == aic_pcmcia_prod[i].app_expfunc)
      96           0 :                         return (1);
      97           0 :         return (0);
      98           0 : }
      99             : 
     100             : void
     101           0 : aic_pcmcia_attach(parent, self, aux)
     102             :         struct device *parent, *self;
     103             :         void *aux;
     104             : {
     105           0 :         struct aic_pcmcia_softc *psc = (void *)self;
     106           0 :         struct aic_softc *sc = &psc->sc_aic;
     107           0 :         struct pcmcia_attach_args *pa = aux;
     108             :         struct pcmcia_config_entry *cfe;
     109           0 :         struct pcmcia_function *pf = pa->pf;
     110             :         const char *intrstr;
     111             : 
     112           0 :         psc->sc_pf = pf;
     113             : 
     114           0 :         for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
     115           0 :             cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
     116           0 :                 if (cfe->num_memspace != 0 ||
     117           0 :                     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           0 :                 if (pa->manufacturer == PCMCIA_VENDOR_NEWMEDIA &&
     124           0 :                     pa->product == PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER &&
     125           0 :                     cfe->iospace[0].start == 0)
     126             :                         continue;
     127             : 
     128           0 :                 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
     129           0 :                     cfe->iospace[0].length, AIC_NPORTS, &psc->sc_pcioh) == 0)
     130             :                         break;
     131             :         }
     132             : 
     133           0 :         if (cfe == 0) {
     134           0 :                 printf(": can't alloc i/o space\n");
     135           0 :                 return;
     136             :         }
     137             : 
     138           0 :         sc->sc_iot = psc->sc_pcioh.iot;
     139           0 :         sc->sc_ioh = psc->sc_pcioh.ioh;
     140             : 
     141             :         /* Enable the card. */
     142           0 :         pcmcia_function_init(pf, cfe);
     143           0 :         if (pcmcia_function_enable(pf)) {
     144           0 :                 printf(": function enable failed\n");
     145           0 :                 return;
     146             :         }
     147             : 
     148             :         /* Map in the io space */
     149           0 :         if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
     150           0 :             &psc->sc_pcioh, &psc->sc_io_window)) {
     151           0 :                 printf(": can't map i/o space\n");
     152           0 :                 return;
     153             :         }
     154             : 
     155           0 :         printf(" port 0x%lx/%lu", psc->sc_pcioh.addr,
     156           0 :             (u_long)psc->sc_pcioh.size);
     157             : 
     158           0 :         if (!aic_find(sc->sc_iot, sc->sc_ioh)) {
     159           0 :                 printf(": unable to detect chip!\n");
     160           0 :                 return;
     161             :         }
     162             : 
     163             :         /* Establish the interrupt handler. */
     164           0 :         psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO,
     165           0 :             aicintr, sc, sc->sc_dev.dv_xname);
     166           0 :         intrstr = pcmcia_intr_string(psc->sc_pf, psc->sc_ih);
     167           0 :         printf("%s%s\n", *intrstr ? ", " : "", intrstr);
     168           0 :         if (psc->sc_ih == NULL)
     169           0 :                 return;
     170             : 
     171           0 :         aicattach(sc);
     172             : 
     173           0 : }
     174             : 
     175             : int
     176           0 : aic_pcmcia_detach(self, flags)
     177             :         struct device *self;
     178             :         int flags;
     179             : {
     180           0 :         struct aic_pcmcia_softc *sc= (void *)self;
     181             :         int error;
     182             : 
     183           0 :         error = aic_detach(self, flags);
     184           0 :         if (error)
     185           0 :                 return (error);
     186             : 
     187             :         /* Unmap our i/o window and i/o space. */
     188           0 :         pcmcia_io_unmap(sc->sc_pf, sc->sc_io_window);
     189           0 :         pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh);
     190             : 
     191           0 :         return (0);
     192           0 : }

Generated by: LCOV version 1.13