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/aha/aha_isa.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 /*
    2  * Product specific probe and attach routines for:
    3  *      Adaptec 154x.
    4  *
    5  * Copyright (c) 1999-2003 M. Warner Losh
    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  *    without modification, immediately at the beginning of the file.
   14  * 2. The name of the author may not be used to endorse or promote products
   15  *    derived from this software without specific prior written permission.
   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 FOR
   21  * 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  * Derived from bt isa from end, written by:
   30  *
   31  * Copyright (c) 1998 Justin T. Gibbs
   32  * All rights reserved.
   33  *
   34  * Redistribution and use in source and binary forms, with or without
   35  * modification, are permitted provided that the following conditions
   36  * are met:
   37  * 1. Redistributions of source code must retain the above copyright
   38  *    notice, this list of conditions, and the following disclaimer,
   39  *    without modification, immediately at the beginning of the file.
   40  * 2. The name of the author may not be used to endorse or promote products
   41  *    derived from this software without specific prior written permission.
   42  *
   43  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   44  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   45  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   46  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
   47  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   48  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   49  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   50  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   51  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   52  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   53  * SUCH DAMAGE.
   54  */
   55 
   56 #include <sys/cdefs.h>
   57 __FBSDID("$FreeBSD: releng/5.2/sys/dev/aha/aha_isa.c 122597 2003-11-13 04:14:53Z imp $");
   58 
   59 #include <sys/param.h>
   60 #include <sys/systm.h>
   61 #include <sys/kernel.h>
   62 #include <sys/lock.h>
   63 #include <sys/mutex.h>
   64 
   65 #include <machine/bus_pio.h>
   66 #include <machine/bus.h>
   67 #include <machine/resource.h>
   68 #include <sys/module.h>
   69 #include <sys/bus.h>
   70 #include <sys/rman.h>
   71 
   72 #include <isa/isavar.h>
   73 
   74 #include <dev/aha/ahareg.h>
   75 
   76 #include <cam/scsi/scsi_all.h>
   77 
   78 static struct isa_pnp_id aha_ids[] = {
   79         {ADP0100_PNP,           "Adaptec 1540/1542 ISA SCSI"},  /* ADP0100 */
   80         {AHA1540_PNP,           "Adaptec 1540/aha-1640/aha-1535"},/* ADP1540 */
   81         {AHA1542_PNP,           "Adaptec 1542/aha-1535"},       /* ADP1542 */
   82         {AHA1542_PNPCOMPAT,     "Adaptec 1542 compatible"},     /* PNP00A0 */
   83         {ICU0091_PNP,           "Adaptec AHA-1540/1542 SCSI"},  /* ICU0091 */
   84         {0}
   85 };
   86 
   87 /*
   88  * I/O ports listed in the order enumerated by the card for certain op codes.
   89  */
   90 static bus_addr_t aha_board_ports[] =
   91 {
   92         0x330,
   93         0x334,
   94         0x230,
   95         0x234,
   96         0x130,
   97         0x134
   98 };
   99 
  100 /*
  101  * Check if the device can be found at the port given
  102  */
  103 static int
  104 aha_isa_probe(device_t dev)
  105 {
  106         /*
  107          * find unit and check we have that many defined
  108          */
  109         struct  aha_softc *aha = device_get_softc(dev);
  110         int     error;
  111         u_long  port_start;
  112         struct resource *port_res;
  113         int     port_rid;
  114         int     drq;
  115         int     irq;
  116         config_data_t config_data;
  117 
  118         aha->dev = dev;
  119         /* Check isapnp ids */
  120         if (ISA_PNP_PROBE(device_get_parent(dev), dev, aha_ids) == ENXIO)
  121                 return (ENXIO);
  122 
  123         port_rid = 0;
  124         port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid,
  125           0, ~0, AHA_NREGS, RF_ACTIVE);
  126 
  127         if (port_res == NULL)
  128                 return (ENXIO);
  129 
  130         port_start = rman_get_start(port_res);
  131         aha_alloc(aha, device_get_unit(dev), rman_get_bustag(port_res),
  132             rman_get_bushandle(port_res));
  133 
  134         /* See if there is really a card present */
  135         if (aha_probe(aha) || aha_fetch_adapter_info(aha)) {
  136                 aha_free(aha);
  137                 bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
  138                 return (ENXIO);
  139         }
  140 
  141         /*
  142          * Determine our IRQ, and DMA settings and
  143          * export them to the configuration system.
  144          */
  145         error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
  146             (uint8_t*)&config_data, sizeof(config_data), DEFAULT_CMD_TIMEOUT);
  147 
  148         if (error != 0) {
  149                 device_printf(dev, "Could not determine IRQ or DMA "
  150                     "settings for adapter at %#jx.  Failing probe\n",
  151                     (uintmax_t)port_start);
  152                 aha_free(aha);
  153                 bus_release_resource(dev, SYS_RES_IOPORT, port_rid, 
  154                     port_res);
  155                 return (ENXIO);
  156         }
  157 
  158         bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
  159 
  160         switch (config_data.dma_chan) {
  161         case DMA_CHAN_5:
  162                 drq = 5;
  163                 break;
  164         case DMA_CHAN_6:
  165                 drq = 6;
  166                 break;
  167         case DMA_CHAN_7:
  168                 drq = 7;
  169                 break;
  170         default:
  171                 device_printf(dev, "Invalid DMA setting for adapter at %#jx.",
  172                     (uintmax_t)port_start);
  173                 return (ENXIO);
  174         }
  175         error = bus_set_resource(dev, SYS_RES_DRQ, 0, drq, 1);
  176         if (error)
  177                 return error;
  178 
  179         irq = ffs(config_data.irq) + 8;
  180         error = bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1);
  181         return (error);
  182 }
  183 
  184 /*
  185  * Attach all the sub-devices we can find
  186  */
  187 static int
  188 aha_isa_attach(device_t dev)
  189 {
  190         struct  aha_softc *aha = device_get_softc(dev);
  191         bus_dma_filter_t *filter;
  192         void             *filter_arg;
  193         bus_addr_t       lowaddr;
  194         void             *ih;
  195         int              error;
  196 
  197         aha->dev = dev;
  198         aha->portrid = 0;
  199         aha->port = bus_alloc_resource(dev, SYS_RES_IOPORT, &aha->portrid,
  200             0, ~0, AHA_NREGS, RF_ACTIVE);
  201         if (!aha->port) {
  202                 device_printf(dev, "Unable to allocate I/O ports\n");
  203                 return ENOMEM;
  204         }
  205 
  206         aha->irqrid = 0;
  207         aha->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &aha->irqrid, 0, ~0, 1,
  208             RF_ACTIVE);
  209         if (!aha->irq) {
  210                 device_printf(dev, "Unable to allocate excluse use of irq\n");
  211                 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  212                 return ENOMEM;
  213         }
  214 
  215         aha->drqrid = 0;
  216         aha->drq = bus_alloc_resource(dev, SYS_RES_DRQ, &aha->drqrid, 0, ~0, 1,
  217             RF_ACTIVE);
  218         if (!aha->drq) {
  219                 device_printf(dev, "Unable to allocate drq\n");
  220                 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  221                 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
  222                 return ENOMEM;
  223         }
  224 
  225 #if 0                           /* is the drq ever unset? */
  226         if (dev->id_drq != -1)
  227                 isa_dmacascade(dev->id_drq);
  228 #endif
  229         isa_dmacascade(rman_get_start(aha->drq));
  230 
  231         /* Allocate our parent dmatag */
  232         filter = NULL;
  233         filter_arg = NULL;
  234         lowaddr = BUS_SPACE_MAXADDR_24BIT;
  235 
  236         if (bus_dma_tag_create( /* parent       */ NULL,
  237                                 /* alignemnt    */ 1,
  238                                 /* boundary     */ 0,
  239                                 /* lowaddr      */ lowaddr,
  240                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  241                                 /* filter       */ filter,
  242                                 /* filterarg    */ filter_arg,
  243                                 /* maxsize      */ BUS_SPACE_MAXSIZE_24BIT,
  244                                 /* nsegments    */ ~0,
  245                                 /* maxsegsz     */ BUS_SPACE_MAXSIZE_24BIT,
  246                                 /* flags        */ 0,
  247                                 /* lockfunc     */ busdma_lock_mutex,
  248                                 /* lockarg      */ &Giant,
  249                                 &aha->parent_dmat) != 0) {
  250                 aha_free(aha);
  251                 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  252                 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
  253                 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
  254                 return (ENOMEM);
  255         }                              
  256 
  257         if (aha_init(aha)) {
  258                 device_printf(dev, "init failed\n");
  259                 aha_free(aha);
  260                 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  261                 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
  262                 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
  263                 return (ENOMEM);
  264         }
  265 
  266         error = aha_attach(aha);
  267         if (error) {
  268                 device_printf(dev, "attach failed\n");
  269                 aha_free(aha);
  270                 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  271                 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
  272                 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
  273                 return (error);
  274         }
  275 
  276         error = bus_setup_intr(dev, aha->irq, INTR_TYPE_CAM|INTR_ENTROPY, aha_intr, aha,
  277             &ih);
  278         if (error) {
  279                 device_printf(dev, "Unable to register interrupt handler\n");
  280                 aha_free(aha);
  281                 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  282                 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
  283                 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
  284                 return (error);
  285         }
  286 
  287         return (0);
  288 }
  289 
  290 static int
  291 aha_isa_detach(device_t dev)
  292 {
  293         struct aha_softc *aha = (struct aha_softc *)device_get_softc(dev);
  294         int error;
  295 
  296         error = bus_teardown_intr(dev, aha->irq, aha->ih);
  297         if (error) {
  298                 device_printf(dev, "failed to unregister interrupt handler\n");
  299         }
  300 
  301         bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
  302         bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
  303         bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
  304 
  305         error = aha_detach(aha);
  306         if (error) {
  307                 device_printf(dev, "detach failed\n");
  308                 return (error);
  309         }
  310         aha_free(aha);
  311 
  312         return (0);
  313 }
  314 
  315 static void
  316 aha_isa_identify(driver_t *driver, device_t parent)
  317 {
  318         int i;
  319         bus_addr_t ioport;
  320         struct aha_softc aha;
  321         int rid;
  322         struct resource *res;
  323         device_t child;
  324 
  325         /* Attempt to find an adapter */
  326         for (i = 0; i < sizeof(aha_board_ports) / sizeof(aha_board_ports[0]);
  327             i++) {
  328                 bzero(&aha, sizeof(aha));
  329                 ioport = aha_board_ports[i];
  330                 /*
  331                  * XXX Check to see if we have a hard-wired aha device at
  332                  * XXX this port, if so, skip.  This should also cover the
  333                  * XXX case where we are run multiple times due to, eg,
  334                  * XXX kldload/kldunload.
  335                  */
  336                 rid = 0;
  337                 res = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid,
  338                     ioport, ioport, AHA_NREGS, RF_ACTIVE);
  339                 if (res == NULL)
  340                         continue;
  341                 aha_alloc(&aha, -1, rman_get_bustag(res),
  342                     rman_get_bushandle(res));
  343                 /* See if there is really a card present */
  344                 if (aha_probe(&aha) || aha_fetch_adapter_info(&aha))
  345                         goto not_this_one;
  346                 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "aha", -1);
  347                 bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, AHA_NREGS);
  348                 /*
  349                  * Could query the board and set IRQ/DRQ, but probe does
  350                  * that.
  351                  */
  352         not_this_one:;
  353                 bus_release_resource(parent, SYS_RES_IOPORT, rid, res);
  354                 aha_free(&aha);
  355         }
  356 }
  357 
  358 static device_method_t aha_isa_methods[] = {
  359         /* Device interface */
  360         DEVMETHOD(device_probe,         aha_isa_probe),
  361         DEVMETHOD(device_attach,        aha_isa_attach),
  362         DEVMETHOD(device_detach,        aha_isa_detach),
  363         DEVMETHOD(device_identify,      aha_isa_identify),
  364 
  365         { 0, 0 }
  366 };
  367 
  368 static driver_t aha_isa_driver = {
  369         "aha",
  370         aha_isa_methods,
  371         sizeof(struct aha_softc),
  372 };
  373 
  374 static devclass_t aha_devclass;
  375 
  376 DRIVER_MODULE(aha, isa, aha_isa_driver, aha_devclass, 0, 0);

Cache object: 911d3fe34776ac6d1b9247e79807e7b8


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