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/buslogic/bt_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 /*
    2  * Product specific probe and attach routines for:
    3  *      Buslogic BT74x SCSI controllers
    4  *
    5  * Copyright (c) 1995, 1998, 1999 Justin T. Gibbs
    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 immediately at the beginning of the file, without modification,
   13  *    this list of conditions, and the following disclaimer.
   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  * $FreeBSD: releng/5.1/sys/dev/buslogic/bt_eisa.c 112782 2003-03-29 09:46:10Z mdodd $
   30  */
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/module.h>
   36 #include <sys/bus.h>
   37 
   38 #include <machine/bus_pio.h>
   39 #include <machine/bus.h>
   40 #include <machine/resource.h>
   41 #include <sys/rman.h>
   42 
   43 #include <dev/eisa/eisaconf.h>
   44 
   45 #include <dev/buslogic/btreg.h>
   46 
   47 #define EISA_DEVICE_ID_BUSLOGIC_74X_B   0x0ab34201
   48 #define EISA_DEVICE_ID_BUSLOGIC_74X_C   0x0ab34202
   49 #define EISA_DEVICE_ID_SDC3222B         0x0ab34281
   50 #define EISA_DEVICE_ID_SDC3222F         0x0ab34781
   51 #define EISA_DEVICE_ID_SDC3222WS        0x0ab34981
   52 #define EISA_DEVICE_ID_SDC3222WB        0x0ab34982
   53 #define EISA_DEVICE_ID_AMI_4801         0x05a94801
   54 
   55 #define BT_IOSIZE               0x04            /* Move to central header */
   56 #define BT_EISA_IOSIZE          0x100
   57 #define BT_EISA_SLOT_OFFSET     0xc00
   58 
   59 #define EISA_IOCONF                     0x08C
   60 #define         PORTADDR                0x07
   61 #define                 PORT_330        0x00
   62 #define                 PORT_334        0x01
   63 #define                 PORT_230        0x02
   64 #define                 PORT_234        0x03
   65 #define                 PORT_130        0x04
   66 #define                 PORT_134        0x05
   67 #define         IRQ_CHANNEL             0xe0
   68 #define                 INT_11          0x40
   69 #define                 INT_10          0x20
   70 #define                 INT_15          0xa0
   71 #define                 INT_12          0x60
   72 #define                 INT_14          0x80
   73 #define                 INT_9           0x00
   74 
   75 #define EISA_IRQ_TYPE                   0x08D
   76 #define       LEVEL                     0x40
   77 
   78 /* Definitions for the AMI Series 48 controler */
   79 #define AMI_EISA_IOSIZE                 0x500   /* Two separate ranges?? */
   80 #define AMI_EISA_SLOT_OFFSET            0x800
   81 #define AMI_EISA_IOCONF                 0x000
   82 #define         AMI_DMA_CHANNEL         0x03
   83 #define         AMI_IRQ_CHANNEL         0x1c
   84 #define                 AMI_INT_15      0x14
   85 #define                 AMI_INT_14      0x10
   86 #define                 AMI_INT_12      0x0c
   87 #define                 AMI_INT_11      0x00
   88 #define                 AMI_INT_10      0x08
   89 #define                 AMI_INT_9       0x04
   90 #define         AMI_BIOS_ADDR           0xe0
   91 
   92 #define AMI_EISA_IOCONF1                0x001
   93 #define         AMI_PORTADDR            0x0e
   94 #define                 AMI_PORT_334    0x08
   95 #define                 AMI_PORT_330    0x00
   96 #define                 AMI_PORT_234    0x0c
   97 #define                 AMI_PORT_230    0x04
   98 #define                 AMI_PORT_134    0x0a
   99 #define                 AMI_PORT_130    0x02
  100 #define         AMI_IRQ_LEVEL           0x01
  101 
  102 
  103 #define AMI_MISC2_OPTIONS               0x49E
  104 #define         AMI_ENABLE_ISA_DMA      0x08
  105 
  106 static const char *bt_match(eisa_id_t type);
  107 
  108 static int
  109 bt_eisa_alloc_resources(device_t dev)
  110 {
  111         struct  bt_softc *bt = device_get_softc(dev);
  112         int rid;
  113         struct resource *port;
  114         struct resource *irq;
  115         int shared;
  116 
  117         /*
  118          * XXX assumes that the iospace ranges are sorted in increasing
  119          * order.
  120          */
  121         rid = 0;
  122         port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
  123                                   0, ~0, 1, RF_ACTIVE);
  124         if (!port)
  125                 return (ENOMEM);
  126 
  127         bt_init_softc(dev, port, 0, 0);
  128 
  129         if (eisa_get_irq(dev) != -1) {
  130                 shared = bt->level_trigger_ints ? RF_SHAREABLE : 0;
  131                 rid = 0;
  132                 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
  133                                          0, ~0, 1, shared | RF_ACTIVE);
  134                 if (!irq) {
  135                         if (port)
  136                                 bus_release_resource(dev, SYS_RES_IOPORT,
  137                                                      0, port);
  138                         return (ENOMEM);
  139                 }
  140         } else
  141                 irq = 0;
  142         bt->irq = irq;
  143 
  144         return (0);
  145 }
  146 
  147 static void
  148 bt_eisa_release_resources(device_t dev)
  149 {
  150         struct  bt_softc *bt = device_get_softc(dev);
  151 
  152         if (bt->port)
  153                 bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->port);
  154         if (bt->irq)
  155                 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
  156         bt_free_softc(dev);
  157 }
  158 
  159 static const char*
  160 bt_match(eisa_id_t type)
  161 {
  162         switch(type) {
  163                 case EISA_DEVICE_ID_BUSLOGIC_74X_B:
  164                         return ("Buslogic 74xB SCSI host adapter");
  165                         break;
  166                 case EISA_DEVICE_ID_BUSLOGIC_74X_C:
  167                         return ("Buslogic 74xC SCSI host adapter");
  168                         break;
  169                 case EISA_DEVICE_ID_SDC3222B:
  170                         return ("Storage Dimensions SDC3222B SCSI host adapter");
  171                         break;
  172                 case EISA_DEVICE_ID_SDC3222F:
  173                         return ("Storage Dimensions SDC3222F SCSI host adapter");
  174                         break;
  175                 case EISA_DEVICE_ID_SDC3222WS:
  176                         return ("Storage Dimensions SDC3222WS SCSI host adapter");
  177                         break;
  178                 case EISA_DEVICE_ID_SDC3222WB:
  179                         return ("Storage Dimensions SDC3222WB SCSI host adapter");
  180                         break;
  181                 case EISA_DEVICE_ID_AMI_4801:
  182                         return ("AMI Series 48 SCSI host adapter");
  183                         break;
  184                 default:
  185                         break;
  186         }
  187         return (NULL);
  188 }
  189 
  190 static int
  191 bt_eisa_probe(device_t dev)
  192 {
  193         const char *desc;
  194         u_long iobase;
  195         struct bt_probe_info info;
  196         u_long port;
  197         u_long iosize;
  198         u_int  ioconf;
  199         int    result;
  200         int    shared;
  201 
  202         desc = bt_match(eisa_get_id(dev));
  203         if (!desc)
  204                 return (ENXIO);
  205         device_set_desc(dev, desc);
  206 
  207         iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE); 
  208         if (eisa_get_id(dev) == EISA_DEVICE_ID_AMI_4801) {
  209                 u_int ioconf1;
  210 
  211                 iobase += AMI_EISA_SLOT_OFFSET;
  212                 iosize = AMI_EISA_IOSIZE;
  213                 ioconf1 = inb(iobase + AMI_EISA_IOCONF1);
  214                 /* Determine "ISA" I/O port */
  215                 switch (ioconf1 & AMI_PORTADDR) {
  216                 case AMI_PORT_330:
  217                         port = 0x330;
  218                         break;
  219                 case AMI_PORT_334:
  220                         port = 0x334;
  221                         break;
  222                 case AMI_PORT_230:
  223                         port = 0x230;
  224                         break;
  225                 case AMI_PORT_234:
  226                         port = 0x234;
  227                         break;
  228                 case AMI_PORT_134:
  229                         port = 0x134;
  230                         break;
  231                 case AMI_PORT_130:
  232                         port = 0x130;
  233                         break;
  234                 default:
  235                         /* Disabled */
  236                         printf("bt: AMI EISA Adapter at "
  237                                "slot %d has a disabled I/O "
  238                                "port.  Cannot attach.\n",
  239                                eisa_get_slot(dev));
  240                         return (ENXIO);
  241                 }
  242                 shared = (inb(iobase + AMI_EISA_IOCONF1) & AMI_IRQ_LEVEL) ?
  243                                 EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE;
  244         } else {
  245                 iobase += BT_EISA_SLOT_OFFSET;
  246                 iosize = BT_EISA_IOSIZE;
  247 
  248                 ioconf = inb(iobase + EISA_IOCONF);
  249                 /* Determine "ISA" I/O port */
  250                 switch (ioconf & PORTADDR) {
  251                 case PORT_330:
  252                         port = 0x330;
  253                         break;
  254                 case PORT_334:
  255                         port = 0x334;
  256                         break;
  257                 case PORT_230:
  258                         port = 0x230;
  259                         break;
  260                 case PORT_234:
  261                         port = 0x234;
  262                         break;
  263                 case PORT_130:
  264                         port = 0x130;
  265                         break;
  266                 case PORT_134:
  267                         port = 0x134;
  268                         break;
  269                 default:
  270                         /* Disabled */
  271                         printf("bt: Buslogic EISA Adapter at "
  272                                "slot %d has a disabled I/O "
  273                                "port.  Cannot attach.\n",
  274                                eisa_get_slot(dev));
  275                         return (ENXIO);
  276                 }
  277                 shared = (inb(iobase + EISA_IRQ_TYPE) & LEVEL) ?
  278                                 EISA_TRIGGER_LEVEL : EISA_TRIGGER_EDGE;
  279         }
  280         bt_mark_probed_iop(port);
  281 
  282         /* Tell parent where our resources are going to be */
  283         eisa_add_iospace(dev, iobase, iosize, RESVADDR_NONE);
  284         eisa_add_iospace(dev, port, BT_IOSIZE, RESVADDR_NONE);
  285 
  286         /* And allocate them */
  287         bt_eisa_alloc_resources(dev);
  288 
  289         if (bt_port_probe(dev, &info) != 0) {
  290                 printf("bt_eisa_probe: Probe failed for "
  291                        "card at slot 0x%x\n", eisa_get_slot(dev));
  292                 result = ENXIO;
  293         } else {
  294                 eisa_add_intr(dev, info.irq, shared);
  295                 result = 0;
  296         }
  297         bt_eisa_release_resources(dev);
  298 
  299         return (result);
  300 }
  301 
  302 static int
  303 bt_eisa_attach(device_t dev)
  304 {
  305         struct bt_softc *bt = device_get_softc(dev);
  306 
  307         /* Allocate resources */
  308         bt_eisa_alloc_resources(dev);
  309 
  310         /* Allocate a dmatag for our SCB DMA maps */
  311         /* XXX Should be a child of the PCI bus dma tag */
  312         if (bus_dma_tag_create( /* parent       */ NULL,
  313                                 /* alignment    */ 1,
  314                                 /* boundary     */ 0,
  315                                 /* lowaddr      */ BUS_SPACE_MAXADDR_32BIT,
  316                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  317                                 /* filter       */ NULL,
  318                                 /* filterarg    */ NULL,
  319                                 /* maxsize      */ BUS_SPACE_MAXSIZE_32BIT,
  320                                 /* nsegments    */ ~0,
  321                                 /* maxsegsz     */ BUS_SPACE_MAXSIZE_32BIT,
  322                                 /* flags        */ 0,
  323                                 &bt->parent_dmat) != 0) {
  324                 bt_eisa_release_resources(dev);
  325                 return -1;
  326         }
  327 
  328         /*
  329          * Now that we know we own the resources we need, do the full
  330          * card initialization.
  331          */
  332         if (bt_probe(dev) || bt_fetch_adapter_info(dev) || bt_init(dev)) {
  333                 bt_eisa_release_resources(dev);
  334                 return -1;
  335         }
  336 
  337         /* Attach sub-devices - always succeeds (sets up intr) */
  338         bt_attach(dev);
  339 
  340         return 0;
  341 }
  342 
  343 static device_method_t bt_eisa_methods[] = {
  344         /* Device interface */
  345         DEVMETHOD(device_probe,         bt_eisa_probe),
  346         DEVMETHOD(device_attach,        bt_eisa_attach),
  347 
  348         { 0, 0 }
  349 };
  350 
  351 static driver_t bt_eisa_driver = {
  352         "bt",
  353         bt_eisa_methods,
  354         sizeof(struct bt_softc),
  355 };
  356 
  357 static devclass_t bt_devclass;
  358 
  359 DRIVER_MODULE(bt, eisa, bt_eisa_driver, bt_devclass, 0, 0);

Cache object: a2a9d4e9a1b558bfc948d9f51d46ad2d


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