root/dev/eisa/dpt_eisa.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. dpt_eisa_irq
  2. dpt_eisa_match
  3. dpt_eisa_attach

    1 /*      $OpenBSD: dpt_eisa.c,v 1.3 2003/10/21 10:27:12 jmc Exp $        */
    2 /*      $NetBSD: dpt_eisa.c,v 1.2 1999/10/18 21:59:19 ad Exp $  */
    3 
    4 /*
    5  * Copyright (c) 1999 Andy Doran <ad@NetBSD.org>
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  *
   29  */
   30 
   31 /*
   32  * EISA front-end for DPT EATA SCSI driver.
   33  */
   34 
   35 #include <sys/cdefs.h>
   36 #ifdef __NetBSD__
   37 __KERNEL_RCSID(0, "$NetBSD: dpt_eisa.c,v 1.2 1999/10/18 21:59:19 ad Exp $");
   38 #endif /* __NetBSD__ */
   39 
   40 #include <sys/types.h>
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/device.h>
   44 
   45 #include <machine/bus.h>
   46 #include <machine/intr.h>
   47 
   48 #ifdef __NetBSD__
   49 #include <dev/scsipi/scsi_all.h>
   50 #include <dev/scsipi/scsipi_all.h>
   51 #include <dev/scsipi/scsiconf.h>
   52 #endif /* __NetBSD__ */
   53 #ifdef __OpenBSD__
   54 #include <scsi/scsi_all.h>
   55 #include <scsi/scsiconf.h>
   56 #endif /* __OpenBSD__ */
   57 
   58 #include <dev/eisa/eisavar.h>
   59 #include <dev/eisa/eisadevs.h>
   60 
   61 #include <dev/ic/dptreg.h>
   62 #include <dev/ic/dptvar.h>
   63 
   64 #define DPT_EISA_SLOT_OFFSET            0x0c00
   65 #define DPT_EISA_IOSIZE                 0x0100
   66 #define DPT_EISA_IOCONF                 0x90
   67 #define DPT_EISA_EATA_REG_OFFSET        0x88
   68 
   69 int     dpt_eisa_irq(bus_space_tag_t, bus_space_handle_t, int *);
   70 #ifdef __NetBSD__
   71 int     dpt_eisa_match(struct device *, struct cfdata *, void *);
   72 #endif /* __NetBSD__ */
   73 #ifdef __OpenBSD__
   74 int     dpt_eisa_match(struct device *, void *, void *);
   75 #endif /* __OpenBSD__ */
   76 void    dpt_eisa_attach(struct device *, struct device *, void *);
   77 
   78 struct cfattach dpt_eisa_ca = {
   79         sizeof(struct dpt_softc), dpt_eisa_match, dpt_eisa_attach
   80 };
   81 
   82 const char *dpt_eisa_boards[] = {
   83         "DPT2402",
   84         "DPTA401",
   85         "DPTA402",
   86         "DPTA410",
   87         "DPTA411",
   88         "DPTA412",
   89         "DPTA420",
   90         "DPTA501",
   91         "DPTA502",
   92         "DPTA701",
   93         "DPTBC01",
   94         "NEC8200",      /* OEM */
   95         "ATT2408",      /* OEM */
   96         NULL
   97 }; 
   98 
   99 int
  100 dpt_eisa_irq(iot, ioh, irq)
  101         bus_space_tag_t iot;
  102         bus_space_handle_t ioh;
  103         int *irq;
  104 {
  105 
  106         switch (bus_space_read_1(iot, ioh, DPT_EISA_IOCONF) & 0x38) {
  107         case 0x08:
  108                 *irq = 11;
  109                 break;
  110         case 0x10:
  111                 *irq = 15;
  112                 break;
  113         case 0x20:
  114                 *irq = 14;
  115                 break;
  116         default:
  117                 return (-1);
  118         }
  119 
  120         return (0);
  121 }
  122 
  123 int
  124 dpt_eisa_match(parent, match, aux)
  125         struct device *parent;
  126 #ifdef __NetBSD__
  127         struct cfdata *match;
  128 #endif /* __NetBSD__ */
  129 #ifdef __OpenBSD__
  130         void *match;
  131 #endif /* __OpenBSD__ */
  132         void *aux;
  133 {
  134         struct eisa_attach_args *ea;
  135         int i;
  136 
  137         ea = aux;
  138 
  139         for (i = 0; dpt_eisa_boards[i] != NULL; i++)
  140                 if (strcmp(ea->ea_idstring, dpt_eisa_boards[i]) == 0)
  141                         break;
  142 
  143         return (dpt_eisa_boards[i] != NULL);
  144 }
  145 
  146 void
  147 dpt_eisa_attach(parent, self, aux)
  148         struct device *parent, *self;
  149         void *aux;
  150 {
  151         struct eisa_attach_args *ea;
  152         bus_space_handle_t ioh;
  153         eisa_chipset_tag_t ec;
  154         eisa_intr_handle_t ih;
  155         struct dpt_softc *sc;
  156         bus_space_tag_t iot;
  157         const char *intrstr;
  158         int irq;
  159         
  160         ea = aux;
  161         sc = (struct dpt_softc *)self;
  162         iot = ea->ea_iot;
  163         ec = ea->ea_ec;
  164         
  165         printf(": ");
  166 
  167         if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
  168             DPT_EISA_SLOT_OFFSET, DPT_EISA_IOSIZE, 0, &ioh)) {
  169                 printf("can't map i/o space\n");
  170                 return;
  171         }
  172 
  173         sc->sc_iot = iot;
  174         sc->sc_ioh = ioh;
  175         sc->sc_dmat = ea->ea_dmat;
  176 
  177         /* Map and establish the interrupt. */
  178         if (dpt_eisa_irq(iot, ioh, &irq)) {
  179                 printf("HBA on invalid IRQ (%d)\n", irq);
  180                 return;
  181         }
  182 
  183         if (eisa_intr_map(ec, irq, &ih)) {
  184                 printf("can't map interrupt (%d)\n", irq);
  185                 return;
  186         }
  187         
  188         intrstr = eisa_intr_string(ec, ih);
  189 #ifdef __NetBSD__
  190         sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
  191             dpt_intr, sc);
  192 #endif /* __NetBSD__ */
  193 #ifdef __OpenBSD__
  194         sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
  195             dpt_intr, sc, sc->sc_dv.dv_xname);
  196 #endif /* __OpenBSD__ */
  197         if (sc->sc_ih == NULL) {
  198                 printf("can't establish interrupt");
  199                 if (intrstr != NULL)
  200                         printf(" at %s", intrstr);
  201                 printf("\n");
  202                 return;
  203         }
  204 
  205         /* Read the EATA configuration */
  206         if (dpt_readcfg(sc)) {
  207                 printf("%s: readcfg failed - see dpt(4)\n", 
  208                     sc->sc_dv.dv_xname);
  209                 return; 
  210         }
  211 
  212         /* Now attach to the bus-independent code */
  213         dpt_init(sc, intrstr);
  214 }

/* [<][>][^][v][top][bottom][index][help] */