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

Cache object: c88bde559adc731838b35f3d1a39597f


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