The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/eisa/cac_eisa.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

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

Cache object: 5c6971c99ab243389aea1237933c2438


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.