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_pci.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 BT946, BT948, BT956, BT958 SCSI controllers
    4  *
    5  * Copyright (c) 1995, 1997, 1998 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, 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 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD$");
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/kernel.h>
   36 #include <sys/module.h>
   37 #include <sys/lock.h>
   38 #include <sys/mutex.h>
   39 #include <sys/bus.h>
   40 
   41 #include <dev/pci/pcireg.h>
   42 #include <dev/pci/pcivar.h>
   43 
   44 #include <machine/bus.h>
   45 #include <machine/resource.h>
   46 #include <sys/rman.h>
   47 
   48 #include <dev/buslogic/btreg.h>
   49 
   50 #define BT_PCI_IOADDR   PCIR_BAR(0)
   51 #define BT_PCI_MEMADDR  PCIR_BAR(1)
   52 
   53 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER      0x1040104Bul
   54 #define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC   0x0140104Bul
   55 #define PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT       0x8130104Bul
   56 
   57 static int
   58 bt_pci_alloc_resources(device_t dev)
   59 {
   60         int             command, type = 0, rid, zero;
   61         struct resource *regs = 0;
   62         struct resource *irq = 0;
   63 
   64         command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1);
   65 #if 0
   66         /* XXX Memory Mapped I/O seems to cause problems */
   67         if (command & PCIM_CMD_MEMEN) {
   68                 type = SYS_RES_MEMORY;
   69                 rid = BT_PCI_MEMADDR;
   70                 regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE);
   71         }
   72 #else
   73         if (!regs && (command & PCIM_CMD_PORTEN)) {
   74                 type = SYS_RES_IOPORT;
   75                 rid = BT_PCI_IOADDR;
   76                 regs = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE);
   77         }
   78 #endif
   79         if (!regs)
   80                 return (ENOMEM);
   81         
   82         zero = 0;
   83         irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &zero,
   84                                      RF_ACTIVE | RF_SHAREABLE);
   85         if (!irq) {
   86                 bus_release_resource(dev, type, rid, regs);
   87                 return (ENOMEM);
   88         }
   89 
   90         bt_init_softc(dev, regs, irq, 0);
   91 
   92         return (0);
   93 }
   94 
   95 static void
   96 bt_pci_release_resources(device_t dev)
   97 {
   98         struct bt_softc *bt = device_get_softc(dev);
   99 
  100         if (bt->port)
  101                 /* XXX can't cope with memory registers anyway */
  102                 bus_release_resource(dev, SYS_RES_IOPORT,
  103                                      BT_PCI_IOADDR, bt->port);
  104         if (bt->irq)
  105                 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
  106         bt_free_softc(dev);
  107 }
  108 
  109 static int
  110 bt_pci_probe(device_t dev)
  111 {
  112         switch (pci_get_devid(dev)) {
  113                 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER:
  114                 case PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC:
  115                 {
  116                         struct bt_softc   *bt = device_get_softc(dev);
  117                         pci_info_data_t pci_info;
  118                         int error;
  119 
  120                         error = bt_pci_alloc_resources(dev);
  121                         if (error)
  122                                 return (error);
  123 
  124                         /*
  125                          * Determine if an ISA compatible I/O port has been
  126                          * enabled.  If so, record the port so it will not
  127                          * be probed by our ISA probe.  If the PCI I/O port
  128                          * was not set to the compatibility port, disable it.
  129                          */
  130                         error = bt_cmd(bt, BOP_INQUIRE_PCI_INFO,
  131                                        /*param*/NULL, /*paramlen*/0,
  132                                        (u_int8_t*)&pci_info, sizeof(pci_info),
  133                                        DEFAULT_CMD_TIMEOUT);
  134                         if (error == 0
  135                          && pci_info.io_port < BIO_DISABLED) {
  136                                 bt_mark_probed_bio(pci_info.io_port);
  137                                 if (rman_get_start(bt->port) !=
  138                                     bt_iop_from_bio(pci_info.io_port)) {
  139                                         u_int8_t new_addr;
  140 
  141                                         new_addr = BIO_DISABLED;
  142                                         bt_cmd(bt, BOP_MODIFY_IO_ADDR,
  143                                                /*param*/&new_addr,
  144                                                /*paramlen*/1, /*reply_buf*/NULL,
  145                                                /*reply_len*/0,
  146                                                DEFAULT_CMD_TIMEOUT);
  147                                 }
  148                         }
  149                         bt_pci_release_resources(dev);
  150                         device_set_desc(dev, "Buslogic Multi-Master SCSI Host Adapter");
  151                         return (0);
  152                 }
  153                 default:
  154                         break;
  155         }
  156 
  157         return (ENXIO);
  158 }
  159 
  160 static int
  161 bt_pci_attach(device_t dev)
  162 {
  163         struct bt_softc   *bt = device_get_softc(dev);
  164         int                opri;
  165         int                error;
  166 
  167         /* Initialize softc */
  168         error = bt_pci_alloc_resources(dev);
  169         if (error) {
  170                 device_printf(dev, "can't allocate resources in bt_pci_attach\n");
  171                 return error;
  172         }
  173 
  174         /* Allocate a dmatag for our CCB DMA maps */
  175         /* XXX Should be a child of the PCI bus dma tag */
  176         if (bus_dma_tag_create( /* PCI parent   */ bus_get_dma_tag(dev),
  177                                 /* alignemnt    */ 1,
  178                                 /* boundary     */ 0,
  179                                 /* lowaddr      */ BUS_SPACE_MAXADDR_32BIT,
  180                                 /* highaddr     */ BUS_SPACE_MAXADDR,
  181                                 /* filter       */ NULL,
  182                                 /* filterarg    */ NULL,
  183                                 /* maxsize      */ BUS_SPACE_MAXSIZE_32BIT,
  184                                 /* nsegments    */ ~0,
  185                                 /* maxsegsz     */ BUS_SPACE_MAXSIZE_32BIT,
  186                                 /* flags        */ 0,
  187                                 /* lockfunc     */ busdma_lock_mutex,
  188                                 /* lockarg      */ &Giant,
  189                                 &bt->parent_dmat) != 0) {
  190                 bt_pci_release_resources(dev);
  191                 return (ENOMEM);
  192         }
  193 
  194         /*
  195          * Protect ourself from spurrious interrupts during
  196          * intialization and attach.  We should really rely
  197          * on interrupts during attach, but we don't have
  198          * access to our interrupts during ISA probes, so until
  199          * that changes, we mask our interrupts during attach
  200          * too.
  201          */
  202         opri = splcam();
  203 
  204         if (bt_probe(dev) || bt_fetch_adapter_info(dev) || bt_init(dev)) {
  205                 bt_pci_release_resources(dev);
  206                 splx(opri);
  207                 return (ENXIO);
  208         }
  209 
  210         error = bt_attach(dev);
  211         splx(opri);
  212 
  213         if (error) {
  214                 bt_pci_release_resources(dev);
  215                 return (error);
  216         }
  217 
  218         return (0);
  219 }
  220 
  221 static device_method_t bt_pci_methods[] = {
  222         /* Device interface */
  223         DEVMETHOD(device_probe,         bt_pci_probe),
  224         DEVMETHOD(device_attach,        bt_pci_attach),
  225 
  226         { 0, 0 }
  227 };
  228 
  229 static driver_t bt_pci_driver = {
  230         "bt",
  231         bt_pci_methods,
  232         sizeof(struct bt_softc),
  233 };
  234 
  235 static devclass_t bt_devclass;
  236 
  237 DRIVER_MODULE(bt, pci, bt_pci_driver, bt_devclass, 0, 0);
  238 MODULE_DEPEND(bt, pci, 1, 1, 1);

Cache object: 46e2444fb2ac382570783406fcbbe92d


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