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/netif/ar/if_ar_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  * Copyright (c) 1999 - 2001 John Hay.
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. Neither the name of the author nor the names of any co-contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    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
   21  * FOR 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: src/sys/dev/ar/if_ar_pci.c,v 1.11 2004/05/30 20:08:26 phk Exp $
   30  */
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/malloc.h>
   36 #include <sys/module.h>
   37 #include <sys/bus.h>
   38 #include <sys/rman.h>
   39 
   40 #include "pcidevs.h"
   41 #include <bus/pci/pcireg.h>
   42 #include <bus/pci/pcivar.h>
   43 
   44 #include <dev/netif/ic_layer/hd64570.h>
   45 #include <dev/netif/ar/if_arregs.h>
   46 
   47 #ifdef TRACE
   48 #define TRC(x)               x
   49 #else
   50 #define TRC(x)
   51 #endif
   52 
   53 #define TRCL(x)              x
   54 
   55 static struct ar_type {
   56         uint16_t         ar_vid;
   57         uint16_t         ar_did;
   58         const char      *ar_name;
   59         const char      *ar_errmsg;
   60 } ar_devs[] = {
   61         { PCI_VENDOR_DIGI, PCI_PRODUCT_DIGI_SYNC570I_2P,
   62                 "Digi SYNC/570i-PCI 2 port",
   63                 NULL },
   64         { PCI_VENDOR_DIGI, PCI_PRODUCT_DIGI_SYNC570I_2PB1,
   65                 "Digi SYNC/570i-PCI 2 port (mapped below 1M)",
   66                 "Please change the jumper to select linear mode." },
   67         { PCI_VENDOR_DIGI, PCI_PRODUCT_DIGI_SYNC570I_4P,
   68                 "Digi SYNC/570i-PCI 4 port",
   69                 NULL },
   70         { PCI_VENDOR_DIGI, PCI_PRODUCT_DIGI_SYNC570I_4PB1,
   71                 "Digi SYNC/570i-PCI 4 port (mapped below 1M)",
   72                 "Please change the jumper to select linear mode." },
   73         { 0, 0, NULL }
   74 };
   75 
   76 static int      ar_pci_probe(device_t);
   77 static int      ar_pci_attach(device_t);
   78 
   79 static device_method_t ar_pci_methods[] = {
   80         /* Device interface */
   81         DEVMETHOD(device_probe,         ar_pci_probe),
   82         DEVMETHOD(device_attach,        ar_pci_attach),
   83         DEVMETHOD(device_detach,        ar_detach),
   84         DEVMETHOD_END
   85 };
   86 
   87 static driver_t ar_pci_driver = {
   88         "ar",
   89         ar_pci_methods,
   90         sizeof(struct ar_hardc),
   91 };
   92 
   93 DRIVER_MODULE(if_ar, pci, ar_pci_driver, ar_devclass, NULL, NULL);
   94 
   95 static int
   96 ar_pci_probe(device_t device)
   97 {
   98         struct ar_type *t;
   99         uint16_t product = pci_get_device(device);
  100         uint16_t vendor = pci_get_vendor(device);
  101 
  102         for (t = ar_devs; t->ar_name != NULL; t++) {
  103                 if (vendor == t->ar_vid && product == t->ar_did) {
  104                         if (t->ar_errmsg != NULL) {
  105                                 kprintf("%s\n%s\n", t->ar_name, t->ar_errmsg);
  106                                 return(ENXIO);
  107                         } else {
  108                                 device_set_desc(device, t->ar_name);
  109                                 return(0);
  110                         }
  111                 }
  112         }
  113         return (ENXIO);
  114 }
  115 
  116 static int
  117 ar_pci_attach(device_t device)
  118 {
  119         int error;
  120         u_int i, tmp;
  121         struct ar_hardc *hc;
  122 
  123         hc = (struct ar_hardc *)device_get_softc(device);
  124         bzero(hc, sizeof(struct ar_hardc));
  125 
  126         error = ar_allocate_plx_memory(device, 0x10, 1);
  127         if(error)
  128                 goto errexit;
  129 
  130         error = ar_allocate_memory(device, 0x18, 1);
  131         if(error)
  132                 goto errexit;
  133 
  134         error = ar_allocate_irq(device, 0, 1);
  135         if(error)
  136                 goto errexit;
  137 
  138         hc->mem_start = rman_get_virtual(hc->res_memory);
  139 
  140         hc->cunit = device_get_unit(device);
  141         hc->sca[0] = (sca_regs *)(hc->mem_start + AR_PCI_SCA_1_OFFSET);
  142         hc->sca[1] = (sca_regs *)(hc->mem_start + AR_PCI_SCA_2_OFFSET);
  143         hc->orbase = (u_char *)(hc->mem_start + AR_PCI_ORBASE_OFFSET);
  144 
  145         tmp = hc->orbase[AR_BMI * 4];
  146         hc->bustype = tmp & AR_BUS_MSK;
  147         hc->memsize = (tmp & AR_MEM_MSK) >> AR_MEM_SHFT;
  148         hc->memsize = 1 << hc->memsize;
  149         hc->memsize <<= 16;
  150         hc->interface[0] = (tmp & AR_IFACE_MSK);
  151         tmp = hc->orbase[AR_REV * 4];
  152         hc->revision = tmp & AR_REV_MSK;
  153         hc->winsize = (1 << ((tmp & AR_WSIZ_MSK) >> AR_WSIZ_SHFT)) * 16 * 1024;
  154         hc->mem_end = (caddr_t)(hc->mem_start + hc->winsize);
  155         hc->winmsk = hc->winsize - 1;
  156         hc->numports = hc->orbase[AR_PNUM * 4];
  157         hc->handshake = hc->orbase[AR_HNDSH * 4];
  158 
  159         for(i = 1; i < hc->numports; i++)
  160                 hc->interface[i] = hc->interface[0];
  161 
  162         TRC(kprintf("arp%d: bus %x, rev %d, memstart %p, winsize %d, "
  163             "winmsk %x, interface %x\n",
  164             unit, hc->bustype, hc->revision, hc->mem_start, hc->winsize,
  165             hc->winmsk, hc->interface[0]));
  166 
  167         ar_attach(device);
  168 
  169         /* Magic to enable the card to generate interrupts. */
  170         bus_space_write_1(rman_get_bustag(hc->res_plx_memory),
  171             rman_get_bushandle(hc->res_plx_memory), 0x69, 0x09);
  172 
  173         return (0);
  174 
  175 errexit:
  176         ar_deallocate_resources(device);
  177         return (ENXIO);
  178 }
  179 

Cache object: 973d6ddc138cc320811aca7d36db5137


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