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/advansys/adv_isa.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  * Device probe and attach routines for the following
    3  * Advanced Systems Inc. SCSI controllers:
    4  *
    5  *   Connectivity Products:
    6  *      ABP510/5150 - Bus-Master ISA (240 CDB) *
    7  *      ABP5140 - Bus-Master ISA PnP (16 CDB) * **
    8  *      ABP5142 - Bus-Master ISA PnP with floppy (16 CDB) ***
    9  *
   10  *   Single Channel Products:
   11  *      ABP542 - Bus-Master ISA with floppy (240 CDB)
   12  *      ABP842 - Bus-Master VL (240 CDB) 
   13  *
   14  *   Dual Channel Products:  
   15  *      ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
   16  *
   17  *    * This board has been shipped by HP with the 4020i CD-R drive.
   18  *      The board has no BIOS so it cannot control a boot device, but 
   19  *      it can control any secondary SCSI device.
   20  *   ** This board has been sold by SIIG as the i540 SpeedMaster.
   21  *  *** This board has been sold by SIIG as the i542 SpeedMaster.
   22  *
   23  * Copyright (c) 1996, 1997 Justin T. Gibbs.
   24  * All rights reserved.
   25  *
   26  * Redistribution and use in source and binary forms, with or without
   27  * modification, are permitted provided that the following conditions
   28  * are met:
   29  * 1. Redistributions of source code must retain the above copyright
   30  *    notice, this list of conditions, and the following disclaimer,
   31  *    without modification, immediately at the beginning of the file.
   32  * 2. The name of the author may not be used to endorse or promote products
   33  *    derived from this software without specific prior written permission.
   34  *
   35  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   36  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   38  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
   39  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   40  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   41  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   42  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   43  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   44  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   45  * SUCH DAMAGE.
   46  */
   47 
   48 #include <sys/cdefs.h>
   49 __FBSDID("$FreeBSD$");
   50 
   51 #include <sys/param.h>
   52 #include <sys/systm.h> 
   53 #include <sys/kernel.h> 
   54 #include <sys/module.h> 
   55 #include <sys/lock.h>
   56 #include <sys/mutex.h>
   57 
   58 #include <machine/bus_pio.h>
   59 #include <machine/bus.h>
   60 #include <machine/resource.h>
   61 #include <sys/bus.h> 
   62 #include <sys/rman.h> 
   63 
   64 #include <isa/isavar.h>
   65 
   66 #include <dev/advansys/advansys.h>
   67 
   68 #include <cam/scsi/scsi_all.h>
   69 
   70 #define ADV_ISA_MAX_DMA_ADDR    (0x00FFFFFFL)
   71 #define ADV_ISA_MAX_DMA_COUNT   (0x00FFFFFFL)
   72 
   73 #define ADV_VL_MAX_DMA_ADDR     (0x07FFFFFFL)
   74 #define ADV_VL_MAX_DMA_COUNT    (0x07FFFFFFL)
   75 
   76 /*
   77  * The overrun buffer shared amongst all ISA/VL adapters.
   78  */
   79 static  u_int8_t*       overrun_buf;
   80 static  bus_dma_tag_t   overrun_dmat;
   81 static  bus_dmamap_t    overrun_dmamap;
   82 static  bus_addr_t      overrun_physbase;
   83 
   84 /* Possible port addresses an ISA or VL adapter can live at */
   85 static u_int16_t adv_isa_ioports[] =
   86 {
   87         0x100,
   88         0x110,  /* First selection in BIOS setup */
   89         0x120,
   90         0x130,  /* Second selection in BIOS setup */
   91         0x140,
   92         0x150,  /* Third selection in BIOS setup */
   93         0x190,  /* Fourth selection in BIOS setup */
   94         0x210,  /* Fifth selection in BIOS setup */
   95         0x230,  /* Sixth selection in BIOS setup */
   96         0x250,  /* Seventh selection in BIOS setup */
   97         0x330   /* Eighth and default selection in BIOS setup */
   98 };
   99 
  100 #define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1)
  101 
  102 static  int     adv_isa_probe(device_t dev);
  103 static  int     adv_isa_attach(device_t dev);
  104 static  void    adv_set_isapnp_wait_for_key(void);
  105 static  int     adv_get_isa_dma_channel(struct adv_softc *adv);
  106 static  int     adv_set_isa_dma_settings(struct adv_softc *adv);
  107 
  108 static int
  109 adv_isa_probe(device_t dev)
  110 {
  111         int     port_index;
  112         int     max_port_index;
  113         u_long  iobase, iocount, irq;
  114         int     user_iobase = 0;
  115         int     rid = 0;
  116         void    *ih;
  117         struct resource *iores, *irqres;
  118 
  119         /*
  120          * Default to scanning all possible device locations.
  121          */
  122         port_index = 0;
  123         max_port_index = MAX_ISA_IOPORT_INDEX;
  124 
  125         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, &iocount) == 0) {
  126                 user_iobase = 1;
  127                 for (;port_index <= max_port_index; port_index++)
  128                         if (iobase <= adv_isa_ioports[port_index])
  129                                 break;
  130                 if ((port_index > max_port_index)
  131                  || (iobase != adv_isa_ioports[port_index])) {
  132                         if (bootverbose)
  133                             printf("adv%d: Invalid baseport of 0x%lx specified. "
  134                                 "Nearest valid baseport is 0x%x.  Failing "
  135                                 "probe.\n", device_get_unit(dev), iobase,
  136                                 (port_index <= max_port_index) ?
  137                                         adv_isa_ioports[port_index] :
  138                                         adv_isa_ioports[max_port_index]);
  139                         return ENXIO;
  140                 }
  141                 max_port_index = port_index;
  142         }
  143 
  144         /* Perform the actual probing */
  145         adv_set_isapnp_wait_for_key();
  146         for (;port_index <= max_port_index; port_index++) {
  147                 u_int16_t port_addr = adv_isa_ioports[port_index];
  148                 bus_size_t maxsegsz;
  149                 bus_size_t maxsize;
  150                 bus_addr_t lowaddr;
  151                 int error;
  152                 struct adv_softc *adv;
  153 
  154                 if (port_addr == 0)
  155                         /* Already been attached */
  156                         continue;
  157                 
  158                 if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port_addr, 1))
  159                         continue;
  160 
  161                 /* XXX what is the real portsize? */
  162                 iores = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
  163                                                RF_ACTIVE);
  164                 if (iores == NULL)
  165                         continue;
  166 
  167                 if (adv_find_signature(rman_get_bustag(iores),
  168                                        rman_get_bushandle(iores)) == 0) {
  169                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  170                         continue;
  171                 }
  172 
  173                 /*
  174                  * Got one.  Now allocate our softc
  175                  * and see if we can initialize the card.
  176                  */
  177                 adv = adv_alloc(dev, rman_get_bustag(iores),
  178                                 rman_get_bushandle(iores));
  179                 if (adv == NULL) {
  180                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  181                         break;
  182                 }
  183 
  184                 /*
  185                  * Stop the chip.
  186                  */
  187                 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
  188                 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
  189                 /*
  190                  * Determine the chip version.
  191                  */
  192                 adv->chip_version = ADV_INB(adv, ADV_NONEISA_CHIP_REVISION);
  193                 if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
  194                     && (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
  195                         adv->type = ADV_VL;
  196                         maxsegsz = ADV_VL_MAX_DMA_COUNT;
  197                         maxsize = BUS_SPACE_MAXSIZE_32BIT;
  198                         lowaddr = ADV_VL_MAX_DMA_ADDR;
  199                         bus_delete_resource(dev, SYS_RES_DRQ, 0);
  200                 } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
  201                            && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
  202                         if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
  203                                 adv->type = ADV_ISAPNP;
  204                                 ADV_OUTB(adv, ADV_REG_IFC,
  205                                          ADV_IFC_INIT_DEFAULT);
  206                         } else {
  207                                 adv->type = ADV_ISA;
  208                         }
  209                         maxsegsz = ADV_ISA_MAX_DMA_COUNT;
  210                         maxsize = BUS_SPACE_MAXSIZE_24BIT;
  211                         lowaddr = ADV_ISA_MAX_DMA_ADDR;
  212                         adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
  213                         adv->isa_dma_channel = adv_get_isa_dma_channel(adv);
  214                         bus_set_resource(dev, SYS_RES_DRQ, 0,
  215                                          adv->isa_dma_channel, 1);
  216                 } else {
  217                         panic("advisaprobe: Unknown card revision\n");
  218                 }
  219 
  220                 /*
  221                  * Allocate a parent dmatag for all tags created
  222                  * by the MI portions of the advansys driver
  223                  */
  224                 /* XXX Should be a child of the ISA bus dma tag */ 
  225                 error = bus_dma_tag_create(
  226                                 /* parent       */ NULL,
  227                                 /* alignemnt    */ 1,
  228                                 /* boundary     */ 0,
  229                                 /* lowaddr      */ lowaddr,
  230                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  231                                 /* filter       */ NULL,
  232                                 /* filterarg    */ NULL,
  233                                 /* maxsize      */ maxsize,
  234                                 /* nsegments    */ ~0,
  235                                 /* maxsegsz     */ maxsegsz,
  236                                 /* flags        */ 0,
  237                                 /* lockfunc     */ busdma_lock_mutex,
  238                                 /* lockarg      */ &Giant,
  239                                 &adv->parent_dmat); 
  240 
  241                 if (error != 0) {
  242                         printf("%s: Could not allocate DMA tag - error %d\n",
  243                                adv_name(adv), error); 
  244                         adv_free(adv); 
  245                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  246                         break;
  247                 }
  248 
  249                 adv->init_level += 2;
  250 
  251                 if (overrun_buf == NULL) {
  252                         /* Need to allocate our overrun buffer */
  253                         if (bus_dma_tag_create(
  254                                 /* parent       */ adv->parent_dmat,
  255                                 /* alignment    */ 8,
  256                                 /* boundary     */ 0,
  257                                 /* lowaddr      */ ADV_ISA_MAX_DMA_ADDR,
  258                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  259                                 /* filter       */ NULL,
  260                                 /* filterarg    */ NULL,
  261                                 /* maxsize      */ ADV_OVERRUN_BSIZE,
  262                                 /* nsegments    */ 1,
  263                                 /* maxsegsz     */ BUS_SPACE_MAXSIZE_32BIT,
  264                                 /* flags        */ 0,
  265                                 /* lockfunc     */ NULL,
  266                                 /* lockarg      */ NULL,
  267                                 &overrun_dmat) != 0) {
  268                                 adv_free(adv);
  269                                 bus_release_resource(dev, SYS_RES_IOPORT, 0,
  270                                                      iores);
  271                                 break;
  272                         }
  273                         if (bus_dmamem_alloc(overrun_dmat,
  274                                              (void **)&overrun_buf,
  275                                              BUS_DMA_NOWAIT,
  276                                              &overrun_dmamap) != 0) {
  277                                 bus_dma_tag_destroy(overrun_dmat);
  278                                 adv_free(adv);
  279                                 bus_release_resource(dev, SYS_RES_IOPORT, 0,
  280                                                      iores);
  281                                 break;
  282                         }
  283                         /* And permanently map it in */  
  284                         bus_dmamap_load(overrun_dmat, overrun_dmamap,
  285                                         overrun_buf, ADV_OVERRUN_BSIZE,
  286                                         adv_map, &overrun_physbase,
  287                                         /*flags*/0);
  288                 }
  289 
  290                 adv->overrun_physbase = overrun_physbase;
  291 
  292                 if (adv_init(adv) != 0) {
  293                         bus_dmamap_unload(overrun_dmat, overrun_dmamap);
  294                         bus_dmamem_free(overrun_dmat, overrun_buf,
  295                             overrun_dmamap);
  296                         bus_dma_tag_destroy(overrun_dmat);
  297                         adv_free(adv);
  298                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  299                         break;
  300                 }
  301 
  302                 switch (adv->type) {
  303                 case ADV_ISAPNP:
  304                         if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG) {
  305                                 adv->bug_fix_control
  306                                     |= ADV_BUG_FIX_ASYN_USE_SYN;
  307                                 adv->fix_asyn_xfer = ~0;
  308                         }
  309                         /* Fall Through */
  310                 case ADV_ISA:
  311                         adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
  312                         adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
  313                         adv_set_isa_dma_settings(adv);
  314                         break;
  315 
  316                 case ADV_VL:
  317                         adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
  318                         adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
  319                         break;
  320                 default:
  321                         panic("advisaprobe: Invalid card type\n");
  322                 }
  323                         
  324                 /* Determine our IRQ */
  325                 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL))
  326                         bus_set_resource(dev, SYS_RES_IRQ, 0,
  327                                          adv_get_chip_irq(adv), 1);
  328                 else
  329                         adv_set_chip_irq(adv, irq);
  330 
  331                 irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
  332                                                 RF_ACTIVE);
  333                 if (irqres == NULL ||
  334                     bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY,
  335                                    adv_intr, adv, &ih)) {
  336                         bus_dmamap_unload(overrun_dmat, overrun_dmamap);
  337                         bus_dmamem_free(overrun_dmat, overrun_buf,
  338                             overrun_dmamap);
  339                         bus_dma_tag_destroy(overrun_dmat);
  340                         adv_free(adv);
  341                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  342                         break;
  343                 }
  344 
  345                 /* Mark as probed */
  346                 adv_isa_ioports[port_index] = 0;
  347                 return 0;
  348         }
  349 
  350         if (user_iobase)
  351                 bus_set_resource(dev, SYS_RES_IOPORT, 0, iobase, iocount);
  352         else
  353                 bus_delete_resource(dev, SYS_RES_IOPORT, 0);
  354 
  355         return ENXIO;
  356 }
  357 
  358 static int
  359 adv_isa_attach(device_t dev)
  360 {
  361         struct adv_softc *adv = device_get_softc(dev);
  362 
  363         return (adv_attach(adv));
  364 }
  365 
  366 static int
  367 adv_get_isa_dma_channel(struct adv_softc *adv)
  368 {
  369         int channel;
  370 
  371         channel = ADV_INW(adv, ADV_CONFIG_LSW) & ADV_CFG_LSW_ISA_DMA_CHANNEL;  
  372         if (channel == 0x03)
  373                 return (0);
  374         else if (channel == 0x00)
  375                 return (7);
  376         return (channel + 4);
  377 }
  378 
  379 static int
  380 adv_set_isa_dma_settings(struct adv_softc *adv)
  381 {
  382         u_int16_t cfg_lsw;
  383         u_int8_t  value;
  384 
  385         if ((adv->isa_dma_channel >= 5) && (adv->isa_dma_channel <= 7)) { 
  386                 if (adv->isa_dma_channel == 7)
  387                         value = 0x00;
  388                 else     
  389                         value = adv->isa_dma_channel - 4;
  390                 cfg_lsw = ADV_INW(adv, ADV_CONFIG_LSW)
  391                         & ~ADV_CFG_LSW_ISA_DMA_CHANNEL;  
  392                 cfg_lsw |= value;
  393                 ADV_OUTW(adv, ADV_CONFIG_LSW, cfg_lsw);
  394 
  395                 adv->isa_dma_speed &= 0x07;
  396                 adv_set_bank(adv, 1);
  397                 ADV_OUTB(adv, ADV_DMA_SPEED, adv->isa_dma_speed);
  398                 adv_set_bank(adv, 0);
  399                 isa_dmacascade(adv->isa_dma_channel);
  400         }
  401         return (0);
  402 }
  403 
  404 static void
  405 adv_set_isapnp_wait_for_key(void)
  406 {
  407         static  int isapnp_wait_set = 0;
  408         if (isapnp_wait_set == 0) {
  409                 outb(ADV_ISA_PNP_PORT_ADDR, 0x02);
  410                 outb(ADV_ISA_PNP_PORT_WRITE, 0x02);
  411                 isapnp_wait_set++;
  412         }
  413 }
  414 
  415 static device_method_t adv_isa_methods[] = {
  416         /* Device interface */
  417         DEVMETHOD(device_probe,         adv_isa_probe),
  418         DEVMETHOD(device_attach,        adv_isa_attach),
  419         { 0, 0 }
  420 };
  421 
  422 static driver_t adv_isa_driver = {
  423         "adv", adv_isa_methods, sizeof(struct adv_softc)
  424 };
  425 
  426 static devclass_t adv_isa_devclass;
  427 DRIVER_MODULE(adv, isa, adv_isa_driver, adv_isa_devclass, 0, 0);

Cache object: a8c2fddf8d87cf27bab86c9ab8a7e593


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