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: releng/5.2/sys/dev/advansys/adv_isa.c 119418 2003-08-24 17:55:58Z obrien $");
   50 
   51 #include <sys/param.h>
   52 #include <sys/systm.h> 
   53 #include <sys/kernel.h> 
   54 #include <sys/lock.h>
   55 #include <sys/mutex.h>
   56 
   57 #include <machine/bus_pio.h>
   58 #include <machine/bus.h>
   59 #include <machine/resource.h>
   60 #include <sys/bus.h> 
   61 #include <sys/rman.h> 
   62 
   63 #include <isa/isavar.h>
   64 
   65 #include <dev/advansys/advansys.h>
   66 
   67 #include <cam/scsi/scsi_all.h>
   68 
   69 #define ADV_ISA_MAX_DMA_ADDR    (0x00FFFFFFL)
   70 #define ADV_ISA_MAX_DMA_COUNT   (0x00FFFFFFL)
   71 
   72 #define ADV_VL_MAX_DMA_ADDR     (0x07FFFFFFL)
   73 #define ADV_VL_MAX_DMA_COUNT    (0x07FFFFFFL)
   74 
   75 /*
   76  * The overrun buffer shared amongst all ISA/VL adapters.
   77  */
   78 static  u_int8_t*       overrun_buf;
   79 static  bus_dma_tag_t   overrun_dmat;
   80 static  bus_dmamap_t    overrun_dmamap;
   81 static  bus_addr_t      overrun_physbase;
   82 
   83 /* Possible port addresses an ISA or VL adapter can live at */
   84 static u_int16_t adv_isa_ioports[] =
   85 {
   86         0x100,
   87         0x110,  /* First selection in BIOS setup */
   88         0x120,
   89         0x130,  /* Second selection in BIOS setup */
   90         0x140,
   91         0x150,  /* Third selection in BIOS setup */
   92         0x190,  /* Fourth selection in BIOS setup */
   93         0x210,  /* Fifth selection in BIOS setup */
   94         0x230,  /* Sixth selection in BIOS setup */
   95         0x250,  /* Seventh selection in BIOS setup */
   96         0x330   /* Eighth and default selection in BIOS setup */
   97 };
   98 
   99 #define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1)
  100 
  101 static  int     adv_isa_probe(device_t dev);
  102 static  int     adv_isa_attach(device_t dev);
  103 static  void    adv_set_isapnp_wait_for_key(void);
  104 static  int     adv_get_isa_dma_channel(struct adv_softc *adv);
  105 static  int     adv_set_isa_dma_settings(struct adv_softc *adv);
  106 
  107 static int
  108 adv_isa_probe(device_t dev)
  109 {
  110         int     port_index;
  111         int     max_port_index;
  112         u_long  iobase, iocount, irq;
  113         int     user_iobase = 0;
  114         int     rid = 0;
  115         void    *ih;
  116         struct resource *iores, *irqres;
  117 
  118         /*
  119          * Default to scanning all possible device locations.
  120          */
  121         port_index = 0;
  122         max_port_index = MAX_ISA_IOPORT_INDEX;
  123 
  124         if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, &iocount) == 0) {
  125                 user_iobase = 1;
  126                 for (;port_index <= max_port_index; port_index++)
  127                         if (iobase <= adv_isa_ioports[port_index])
  128                                 break;
  129                 if ((port_index > max_port_index)
  130                  || (iobase != adv_isa_ioports[port_index])) {
  131                         if (bootverbose)
  132                             printf("adv%d: Invalid baseport of 0x%lx specified. "
  133                                 "Nearest valid baseport is 0x%x.  Failing "
  134                                 "probe.\n", device_get_unit(dev), iobase,
  135                                 (port_index <= max_port_index) ?
  136                                         adv_isa_ioports[port_index] :
  137                                         adv_isa_ioports[max_port_index]);
  138                         return ENXIO;
  139                 }
  140                 max_port_index = port_index;
  141         }
  142 
  143         /* Perform the actual probing */
  144         adv_set_isapnp_wait_for_key();
  145         for (;port_index <= max_port_index; port_index++) {
  146                 u_int16_t port_addr = adv_isa_ioports[port_index];
  147                 bus_size_t maxsegsz;
  148                 bus_size_t maxsize;
  149                 bus_addr_t lowaddr;
  150                 int error;
  151                 struct adv_softc *adv;
  152 
  153                 if (port_addr == 0)
  154                         /* Already been attached */
  155                         continue;
  156                 
  157                 if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port_addr, 1))
  158                         continue;
  159 
  160                 /* XXX what is the real portsize? */
  161                 iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
  162                                            RF_ACTIVE);
  163                 if (iores == NULL)
  164                         continue;
  165 
  166                 if (adv_find_signature(rman_get_bustag(iores),
  167                                        rman_get_bushandle(iores)) == 0) {
  168                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  169                         continue;
  170                 }
  171 
  172                 /*
  173                  * Got one.  Now allocate our softc
  174                  * and see if we can initialize the card.
  175                  */
  176                 adv = adv_alloc(dev, rman_get_bustag(iores),
  177                                 rman_get_bushandle(iores));
  178                 if (adv == NULL) {
  179                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  180                         break;
  181                 }
  182 
  183                 /*
  184                  * Stop the chip.
  185                  */
  186                 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
  187                 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
  188                 /*
  189                  * Determine the chip version.
  190                  */
  191                 adv->chip_version = ADV_INB(adv, ADV_NONEISA_CHIP_REVISION);
  192                 if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
  193                     && (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
  194                         adv->type = ADV_VL;
  195                         maxsegsz = ADV_VL_MAX_DMA_COUNT;
  196                         maxsize = BUS_SPACE_MAXSIZE_32BIT;
  197                         lowaddr = ADV_VL_MAX_DMA_ADDR;
  198                         bus_delete_resource(dev, SYS_RES_DRQ, 0);
  199                 } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
  200                            && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
  201                         if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
  202                                 adv->type = ADV_ISAPNP;
  203                                 ADV_OUTB(adv, ADV_REG_IFC,
  204                                          ADV_IFC_INIT_DEFAULT);
  205                         } else {
  206                                 adv->type = ADV_ISA;
  207                         }
  208                         maxsegsz = ADV_ISA_MAX_DMA_COUNT;
  209                         maxsize = BUS_SPACE_MAXSIZE_24BIT;
  210                         lowaddr = ADV_ISA_MAX_DMA_ADDR;
  211                         adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
  212                         adv->isa_dma_channel = adv_get_isa_dma_channel(adv);
  213                         bus_set_resource(dev, SYS_RES_DRQ, 0,
  214                                          adv->isa_dma_channel, 1);
  215                 } else {
  216                         panic("advisaprobe: Unknown card revision\n");
  217                 }
  218 
  219                 /*
  220                  * Allocate a parent dmatag for all tags created
  221                  * by the MI portions of the advansys driver
  222                  */
  223                 /* XXX Should be a child of the ISA bus dma tag */ 
  224                 error = bus_dma_tag_create(
  225                                 /* parent       */ NULL,
  226                                 /* alignemnt    */ 1,
  227                                 /* boundary     */ 0,
  228                                 /* lowaddr      */ lowaddr,
  229                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  230                                 /* filter       */ NULL,
  231                                 /* filterarg    */ NULL,
  232                                 /* maxsize      */ maxsize,
  233                                 /* nsegments    */ ~0,
  234                                 /* maxsegsz     */ maxsegsz,
  235                                 /* flags        */ 0,
  236                                 /* lockfunc     */ busdma_lock_mutex,
  237                                 /* lockarg      */ &Giant,
  238                                 &adv->parent_dmat); 
  239 
  240                 if (error != 0) {
  241                         printf("%s: Could not allocate DMA tag - error %d\n",
  242                                adv_name(adv), error); 
  243                         adv_free(adv); 
  244                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  245                         break;
  246                 }
  247 
  248                 adv->init_level += 2;
  249 
  250                 if (overrun_buf == NULL) {
  251                         /* Need to allocate our overrun buffer */
  252                         if (bus_dma_tag_create(
  253                                 /* parent       */ adv->parent_dmat,
  254                                 /* alignment    */ 8,
  255                                 /* boundary     */ 0,
  256                                 /* lowaddr      */ ADV_ISA_MAX_DMA_ADDR,
  257                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  258                                 /* filter       */ NULL,
  259                                 /* filterarg    */ NULL,
  260                                 /* maxsize      */ ADV_OVERRUN_BSIZE,
  261                                 /* nsegments    */ 1,
  262                                 /* maxsegsz     */ BUS_SPACE_MAXSIZE_32BIT,
  263                                 /* flags        */ 0,
  264                                 /* lockfunc     */ NULL,
  265                                 /* lockarg      */ NULL,
  266                                 &overrun_dmat) != 0) {
  267                                 adv_free(adv);
  268                                 bus_release_resource(dev, SYS_RES_IOPORT, 0,
  269                                                      iores);
  270                                 break;
  271                         }
  272                         if (bus_dmamem_alloc(overrun_dmat,
  273                                              (void **)&overrun_buf,
  274                                              BUS_DMA_NOWAIT,
  275                                              &overrun_dmamap) != 0) {
  276                                 bus_dma_tag_destroy(overrun_dmat);
  277                                 adv_free(adv);
  278                                 bus_release_resource(dev, SYS_RES_IOPORT, 0,
  279                                                      iores);
  280                                 break;
  281                         }
  282                         /* And permanently map it in */  
  283                         bus_dmamap_load(overrun_dmat, overrun_dmamap,
  284                                         overrun_buf, ADV_OVERRUN_BSIZE,
  285                                         adv_map, &overrun_physbase,
  286                                         /*flags*/0);
  287                 }
  288 
  289                 adv->overrun_physbase = overrun_physbase;
  290 
  291                 if (adv_init(adv) != 0) {
  292                         bus_dmamap_unload(overrun_dmat, overrun_dmamap);
  293                         bus_dmamem_free(overrun_dmat, overrun_buf,
  294                             overrun_dmamap);
  295                         bus_dma_tag_destroy(overrun_dmat);
  296                         adv_free(adv);
  297                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  298                         break;
  299                 }
  300 
  301                 switch (adv->type) {
  302                 case ADV_ISAPNP:
  303                         if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG) {
  304                                 adv->bug_fix_control
  305                                     |= ADV_BUG_FIX_ASYN_USE_SYN;
  306                                 adv->fix_asyn_xfer = ~0;
  307                         }
  308                         /* Fall Through */
  309                 case ADV_ISA:
  310                         adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
  311                         adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
  312                         adv_set_isa_dma_settings(adv);
  313                         break;
  314 
  315                 case ADV_VL:
  316                         adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
  317                         adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
  318                         break;
  319                 default:
  320                         panic("advisaprobe: Invalid card type\n");
  321                 }
  322                         
  323                 /* Determine our IRQ */
  324                 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL))
  325                         bus_set_resource(dev, SYS_RES_IRQ, 0,
  326                                          adv_get_chip_irq(adv), 1);
  327                 else
  328                         adv_set_chip_irq(adv, irq);
  329 
  330                 irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
  331                                             RF_ACTIVE);
  332                 if (irqres == NULL ||
  333                     bus_setup_intr(dev, irqres, INTR_TYPE_CAM|INTR_ENTROPY,
  334                                    adv_intr, adv, &ih)) {
  335                         bus_dmamap_unload(overrun_dmat, overrun_dmamap);
  336                         bus_dmamem_free(overrun_dmat, overrun_buf,
  337                             overrun_dmamap);
  338                         bus_dma_tag_destroy(overrun_dmat);
  339                         adv_free(adv);
  340                         bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
  341                         break;
  342                 }
  343 
  344                 /* Mark as probed */
  345                 adv_isa_ioports[port_index] = 0;
  346                 return 0;
  347         }
  348 
  349         if (user_iobase)
  350                 bus_set_resource(dev, SYS_RES_IOPORT, 0, iobase, iocount);
  351         else
  352                 bus_delete_resource(dev, SYS_RES_IOPORT, 0);
  353 
  354         return ENXIO;
  355 }
  356 
  357 static int
  358 adv_isa_attach(device_t dev)
  359 {
  360         struct adv_softc *adv = device_get_softc(dev);
  361 
  362         return (adv_attach(adv));
  363 }
  364 
  365 static int
  366 adv_get_isa_dma_channel(struct adv_softc *adv)
  367 {
  368         int channel;
  369 
  370         channel = ADV_INW(adv, ADV_CONFIG_LSW) & ADV_CFG_LSW_ISA_DMA_CHANNEL;  
  371         if (channel == 0x03)
  372                 return (0);
  373         else if (channel == 0x00)
  374                 return (7);
  375         return (channel + 4);
  376 }
  377 
  378 static int
  379 adv_set_isa_dma_settings(struct adv_softc *adv)
  380 {
  381         u_int16_t cfg_lsw;
  382         u_int8_t  value;
  383 
  384         if ((adv->isa_dma_channel >= 5) && (adv->isa_dma_channel <= 7)) { 
  385                 if (adv->isa_dma_channel == 7)
  386                         value = 0x00;
  387                 else     
  388                         value = adv->isa_dma_channel - 4;
  389                 cfg_lsw = ADV_INW(adv, ADV_CONFIG_LSW)
  390                         & ~ADV_CFG_LSW_ISA_DMA_CHANNEL;  
  391                 cfg_lsw |= value;
  392                 ADV_OUTW(adv, ADV_CONFIG_LSW, cfg_lsw);
  393 
  394                 adv->isa_dma_speed &= 0x07;
  395                 adv_set_bank(adv, 1);
  396                 ADV_OUTB(adv, ADV_DMA_SPEED, adv->isa_dma_speed);
  397                 adv_set_bank(adv, 0);
  398                 isa_dmacascade(adv->isa_dma_channel);
  399         }
  400         return (0);
  401 }
  402 
  403 static void
  404 adv_set_isapnp_wait_for_key(void)
  405 {
  406         static  int isapnp_wait_set = 0;
  407         if (isapnp_wait_set == 0) {
  408                 outb(ADV_ISA_PNP_PORT_ADDR, 0x02);
  409                 outb(ADV_ISA_PNP_PORT_WRITE, 0x02);
  410                 isapnp_wait_set++;
  411         }
  412 }
  413 
  414 static device_method_t adv_isa_methods[] = {
  415         /* Device interface */
  416         DEVMETHOD(device_probe,         adv_isa_probe),
  417         DEVMETHOD(device_attach,        adv_isa_attach),
  418         { 0, 0 }
  419 };
  420 
  421 static driver_t adv_isa_driver = {
  422         "adv", adv_isa_methods, sizeof(struct adv_softc)
  423 };
  424 
  425 static devclass_t adv_isa_devclass;
  426 DRIVER_MODULE(adv, isa, adv_isa_driver, adv_isa_devclass, 0, 0);

Cache object: 0cdec1fe9dcf40d5de32bd4e630b85ef


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