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/uha_eisa.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: uha_eisa.c,v 1.29 2008/04/28 20:23:48 martin Exp $     */
    2 
    3 /*-
    4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Charles M. Hannum.
    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  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: uha_eisa.c,v 1.29 2008/04/28 20:23:48 martin Exp $");
   34 
   35 #include "opt_ddb.h"
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/device.h>
   40 #include <sys/kernel.h>
   41 #include <sys/proc.h>
   42 #include <sys/user.h>
   43 
   44 #include <sys/bus.h>
   45 #include <sys/intr.h>
   46 
   47 #include <dev/scsipi/scsi_all.h>
   48 #include <dev/scsipi/scsipi_all.h>
   49 #include <dev/scsipi/scsiconf.h>
   50 
   51 #include <dev/eisa/eisavar.h>
   52 #include <dev/eisa/eisadevs.h>
   53 
   54 #include <dev/ic/uhareg.h>
   55 #include <dev/ic/uhavar.h>
   56 
   57 #define UHA_EISA_SLOT_OFFSET    0xc80
   58 #define UHA_EISA_IOSIZE         0x020
   59 
   60 static int      uha_eisa_match(struct device *, struct cfdata *, void *);
   61 static void     uha_eisa_attach(struct device *, struct device *, void *);
   62 
   63 CFATTACH_DECL(uha_eisa, sizeof(struct uha_softc),
   64     uha_eisa_match, uha_eisa_attach, NULL, NULL);
   65 
   66 #ifndef DDB
   67 #define Debugger() panic("should call debugger here (uha_eisa.c)")
   68 #endif /* ! DDB */
   69 
   70 static int      u24_find(bus_space_tag_t, bus_space_handle_t,
   71                     struct uha_probe_data *);
   72 static void     u24_start_mbox(struct uha_softc *, struct uha_mscp *);
   73 static int      u24_poll(struct uha_softc *, struct scsipi_xfer *, int);
   74 static int      u24_intr(void *);
   75 static void     u24_init(struct uha_softc *);
   76 
   77 /*
   78  * Check the slots looking for a board we recognise
   79  * If we find one, note it's address (slot) and call
   80  * the actual probe routine to check it out.
   81  */
   82 static int
   83 uha_eisa_match(struct device *parent, struct cfdata *match,
   84     void *aux)
   85 {
   86         struct eisa_attach_args *ea = aux;
   87         bus_space_tag_t iot = ea->ea_iot;
   88         bus_space_handle_t ioh;
   89         int rv;
   90 
   91         /* must match one of our known ID strings */
   92         if (strncmp(ea->ea_idstring, "USC024", 6))
   93                 return (0);
   94 
   95         if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
   96             UHA_EISA_SLOT_OFFSET, UHA_EISA_IOSIZE, 0, &ioh))
   97                 return (0);
   98 
   99         rv = u24_find(iot, ioh, NULL);
  100 
  101         bus_space_unmap(iot, ioh, UHA_EISA_IOSIZE);
  102 
  103         return (rv);
  104 }
  105 
  106 /*
  107  * Attach all the sub-devices we can find
  108  */
  109 static void
  110 uha_eisa_attach(struct device *parent, struct device *self, void *aux)
  111 {
  112         struct eisa_attach_args *ea = aux;
  113         struct uha_softc *sc = device_private(self);
  114         bus_space_tag_t iot = ea->ea_iot;
  115         bus_dma_tag_t dmat = ea->ea_dmat;
  116         bus_space_handle_t ioh;
  117         struct uha_probe_data upd;
  118         eisa_chipset_tag_t ec = ea->ea_ec;
  119         eisa_intr_handle_t ih;
  120         const char *model, *intrstr;
  121 
  122         if (!strncmp(ea->ea_idstring, "USC024", 6))
  123                 model = EISA_PRODUCT_USC0240;
  124         else
  125                 model = "unknown model!";
  126         printf(": %s\n", model);
  127 
  128         if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
  129             UHA_EISA_SLOT_OFFSET, UHA_EISA_IOSIZE, 0, &ioh))
  130                 panic("uha_eisa_attach: could not map I/O addresses");
  131 
  132         sc->sc_iot = iot;
  133         sc->sc_ioh = ioh;
  134         sc->sc_dmat = dmat;
  135         if (!u24_find(iot, ioh, &upd))
  136                 panic("uha_eisa_attach: u24_find failed!");
  137 
  138         sc->sc_dmaflags = 0;
  139 
  140         if (eisa_intr_map(ec, upd.sc_irq, &ih)) {
  141                 aprint_error_dev(&sc->sc_dev, "couldn't map interrupt (%d)\n",
  142                     upd.sc_irq);
  143                 return;
  144         }
  145         intrstr = eisa_intr_string(ec, ih);
  146         sc->sc_ih = eisa_intr_establish(ec, ih, IST_LEVEL, IPL_BIO,
  147             u24_intr, sc);
  148         if (sc->sc_ih == NULL) {
  149                 aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt");
  150                 if (intrstr != NULL)
  151                         printf(" at %s", intrstr);
  152                 printf("\n");
  153                 return;
  154         }
  155         printf("%s: interrupting at %s\n", device_xname(&sc->sc_dev), intrstr);
  156 
  157         /* Save function pointers for later use. */
  158         sc->start_mbox = u24_start_mbox;
  159         sc->poll = u24_poll;
  160         sc->init = u24_init;
  161 
  162         uha_attach(sc, &upd);
  163 }
  164 
  165 static int
  166 u24_find(bus_space_tag_t iot, bus_space_handle_t ioh, struct uha_probe_data *sc)
  167 {
  168         u_int8_t config0, config1, config2;
  169         int irq, drq;
  170         int resetcount = 4000;  /* 4 secs? */
  171 
  172         config0 = bus_space_read_1(iot, ioh, U24_CONFIG + 0);
  173         config1 = bus_space_read_1(iot, ioh, U24_CONFIG + 1);
  174         config2 = bus_space_read_1(iot, ioh, U24_CONFIG + 2);
  175         if ((config0 & U24_MAGIC1) == 0 ||
  176             (config1 & U24_MAGIC2) == 0)
  177                 return (0);
  178 
  179         drq = -1;
  180 
  181         switch (config0 & U24_IRQ_MASK) {
  182         case U24_IRQ10:
  183                 irq = 10;
  184                 break;
  185         case U24_IRQ11:
  186                 irq = 11;
  187                 break;
  188         case U24_IRQ14:
  189                 irq = 14;
  190                 break;
  191         case U24_IRQ15:
  192                 irq = 15;
  193                 break;
  194         default:
  195                 printf("u24_find: illegal irq setting %x\n",
  196                     config0 & U24_IRQ_MASK);
  197                 return (0);
  198         }
  199 
  200         bus_space_write_1(iot, ioh, U24_LINT, UHA_ASRST);
  201 
  202         while (--resetcount) {
  203                 if (bus_space_read_1(iot, ioh, U24_LINT))
  204                         break;
  205                 delay(1000);    /* 1 mSec per loop */
  206         }
  207         if (!resetcount) {
  208                 printf("u24_find: board timed out during reset\n");
  209                 return (0);
  210         }
  211 
  212         /* if we want to fill in softc, do so now */
  213         if (sc) {
  214                 sc->sc_irq = irq;
  215                 sc->sc_drq = drq;
  216                 sc->sc_scsi_dev = config2 & U24_HOSTID_MASK;
  217         }
  218 
  219         return (1);
  220 }
  221 
  222 static void
  223 u24_start_mbox(struct uha_softc *sc, struct uha_mscp *mscp)
  224 {
  225         bus_space_tag_t iot = sc->sc_iot;
  226         bus_space_handle_t ioh = sc->sc_ioh;
  227         int spincount = 100000; /* 1s should be enough */
  228 
  229         while (--spincount) {
  230                 if ((bus_space_read_1(iot, ioh, U24_LINT) & U24_LDIP) == 0)
  231                         break;
  232                 delay(100);
  233         }
  234         if (!spincount) {
  235                 aprint_error_dev(&sc->sc_dev, "uha_start_mbox, board not responding\n");
  236                 Debugger();
  237         }
  238 
  239         bus_space_write_4(iot, ioh, U24_OGMPTR,
  240             sc->sc_dmamap_mscp->dm_segs[0].ds_addr + UHA_MSCP_OFF(mscp));
  241         if (mscp->flags & MSCP_ABORT)
  242                 bus_space_write_1(iot, ioh, U24_OGMCMD, 0x80);
  243         else
  244                 bus_space_write_1(iot, ioh, U24_OGMCMD, 0x01);
  245         bus_space_write_1(iot, ioh, U24_LINT, U24_OGMFULL);
  246 
  247         if ((mscp->xs->xs_control & XS_CTL_POLL) == 0)
  248                 callout_reset(&mscp->xs->xs_callout,
  249                     mstohz(mscp->timeout), uha_timeout, mscp);
  250 }
  251 
  252 static int
  253 u24_poll(struct uha_softc *sc, struct scsipi_xfer *xs, int count)
  254 {
  255         bus_space_tag_t iot = sc->sc_iot;
  256         bus_space_handle_t ioh = sc->sc_ioh;
  257 
  258         while (count) {
  259                 /*
  260                  * If we had interrupts enabled, would we
  261                  * have got an interrupt?
  262                  */
  263                 if (bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP)
  264                         u24_intr(sc);
  265                 if (xs->xs_status & XS_STS_DONE)
  266                         return (0);
  267                 delay(1000);
  268                 count--;
  269         }
  270         return (1);
  271 }
  272 
  273 static int
  274 u24_intr(void *arg)
  275 {
  276         struct uha_softc *sc = arg;
  277         bus_space_tag_t iot = sc->sc_iot;
  278         bus_space_handle_t ioh = sc->sc_ioh;
  279         struct uha_mscp *mscp;
  280         u_char uhastat;
  281         u_long mboxval;
  282 
  283 #ifdef  UHADEBUG
  284         printf("%s: uhaintr ", device_xname(&sc->sc_dev));
  285 #endif /*UHADEBUG */
  286 
  287         if ((bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP) == 0)
  288                 return (0);
  289 
  290         for (;;) {
  291                 /*
  292                  * First get all the information and then
  293                  * acknowledge the interrupt
  294                  */
  295                 uhastat = bus_space_read_1(iot, ioh, U24_SINT);
  296                 mboxval = bus_space_read_4(iot, ioh, U24_ICMPTR);
  297                 bus_space_write_1(iot, ioh, U24_SINT, U24_ICM_ACK);
  298                 bus_space_write_1(iot, ioh, U24_ICMCMD, 0);
  299 
  300 #ifdef  UHADEBUG
  301                 printf("status = 0x%x ", uhastat);
  302 #endif /*UHADEBUG*/
  303 
  304                 /*
  305                  * Process the completed operation
  306                  */
  307                 mscp = uha_mscp_phys_kv(sc, mboxval);
  308                 if (!mscp) {
  309                         printf("%s: BAD MSCP RETURNED!\n",
  310                             device_xname(&sc->sc_dev));
  311                         continue;       /* whatever it was, it'll timeout */
  312                 }
  313                 callout_stop(&mscp->xs->xs_callout);
  314                 uha_done(sc, mscp);
  315 
  316                 if ((bus_space_read_1(iot, ioh, U24_SINT) & U24_SDIP) == 0)
  317                         return (1);
  318         }
  319 }
  320 
  321 static void
  322 u24_init(struct uha_softc *sc)
  323 {
  324         bus_space_tag_t iot = sc->sc_iot;
  325         bus_space_handle_t ioh = sc->sc_ioh;
  326 
  327         /* free OGM and ICM */
  328         bus_space_write_1(iot, ioh, U24_OGMCMD, 0);
  329         bus_space_write_1(iot, ioh, U24_ICMCMD, 0);
  330         /* make sure interrupts are enabled */
  331 #ifdef UHADEBUG
  332         printf("u24_init: lmask=%02x, smask=%02x\n",
  333             bus_space_read_1(iot, ioh, U24_LMASK),
  334             bus_space_read_1(iot, ioh, U24_SMASK));
  335 #endif
  336         bus_space_write_1(iot, ioh, U24_LMASK, 0xd2);   /* XXX */
  337         bus_space_write_1(iot, ioh, U24_SMASK, 0x92);   /* XXX */
  338 }

Cache object: 610200bc48897ba3af68beadfc9fcef6


[ 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.