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/ar/if_ar_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  * Copyright (c) 1995 - 2001 John Hay.  All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  * 3. Neither the name of the author nor the names of any co-contributors
   13  *    may be used to endorse or promote products derived from this software
   14  *    without specific prior written permission.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY John Hay ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL John Hay BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  */
   28 
   29 #include <sys/cdefs.h>
   30 __FBSDID("$FreeBSD$");
   31 
   32 /*
   33  * Programming assumptions and other issues.
   34  *
   35  * The descriptors of a DMA channel will fit in a 16K memory window.
   36  *
   37  * The buffers of a transmit DMA channel will fit in a 16K memory window.
   38  *
   39  * Only the ISA bus cards with X.21 and V.35 is tested.
   40  *
   41  * When interface is going up, handshaking is set and it is only cleared
   42  * when the interface is down'ed.
   43  *
   44  * There should be a way to set/reset Raw HDLC/PPP, Loopback, DCE/DTE,
   45  * internal/external clock, etc.....
   46  */
   47 
   48 #include <sys/param.h>
   49 #include <sys/systm.h>
   50 #include <sys/kernel.h>
   51 #include <sys/module.h>
   52 #include <sys/bus.h>
   53 #include <machine/bus.h>
   54 #include <machine/resource.h>
   55 #include <machine/bus_pio.h>
   56 #include <machine/bus_memio.h>
   57 #include <sys/rman.h>
   58 
   59 #include <isa/isavar.h>
   60 #include "isa_if.h"
   61 
   62 #include <dev/ic/hd64570.h>
   63 #include <dev/ar/if_arregs.h>
   64 
   65 #ifdef TRACE
   66 #define TRC(x)               x
   67 #else
   68 #define TRC(x)
   69 #endif
   70 
   71 #define TRCL(x)              x
   72 
   73 static int ar_isa_probe (device_t);
   74 static int ar_isa_attach (device_t);
   75 
   76 static struct isa_pnp_id ar_ids[] = {
   77         {0,             NULL}
   78 };
   79 
   80 static device_method_t ar_methods[] = {
   81         DEVMETHOD(device_probe,         ar_isa_probe),
   82         DEVMETHOD(device_attach,        ar_isa_attach),
   83         DEVMETHOD(device_detach,        ar_detach),
   84         { 0, 0 }
   85 };
   86 
   87 static driver_t ar_isa_driver = {
   88         "ar",
   89         ar_methods,
   90         sizeof (struct ar_hardc)
   91 };
   92 
   93 DRIVER_MODULE(ar, isa, ar_isa_driver, ar_devclass, 0, 0);
   94 MODULE_DEPEND(ar, isa, 1, 1, 1);
   95 
   96 /*
   97  * Probe to see if it is there.
   98  * Get its information and fill it in.
   99  */
  100 static int
  101 ar_isa_probe(device_t device)
  102 {
  103         int error;
  104         u_long membase, memsize;
  105         struct ar_hardc *hc;
  106 
  107         error = ISA_PNP_PROBE(device_get_parent(device), device, ar_ids);
  108         if(error == ENXIO || error == 0)
  109                 return (error);
  110 
  111         hc = (struct ar_hardc *)device_get_softc(device);
  112 
  113         if((error = ar_allocate_ioport(device, 0, ARC_IO_SIZ))) {
  114                 return (ENXIO);
  115         }
  116 
  117         /*
  118          * Now see if the card is realy there.
  119          *
  120          * XXX For now I just check the undocumented ports
  121          * for "570". We will probably have to do more checking.
  122          */
  123         if((ar_inb(hc, AR_ID_5) != '5') ||
  124            (ar_inb(hc, AR_ID_7) != '7') ||
  125            (ar_inb(hc, AR_ID_0) != '')) {
  126                 ar_deallocate_resources(device);
  127                 return (ENXIO);
  128         }
  129         membase = bus_get_resource_start(device, SYS_RES_MEMORY, 0);
  130         memsize = ar_inb(hc, AR_REV);
  131         memsize = 1 << ((memsize & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
  132         memsize *= ARC_WIN_SIZ;
  133         error = bus_set_resource(device, SYS_RES_MEMORY, 0, membase, memsize);
  134         ar_deallocate_resources(device);
  135 
  136         return (error);
  137 }
  138 
  139 /*
  140  * Malloc memory for the softc structures.
  141  * Reset the card to put it in a known state.
  142  * Register the ports on the adapter.
  143  * Fill in the info for each port.
  144  * Attach each port to sppp and bpf.
  145  */
  146 static int
  147 ar_isa_attach(device_t device)
  148 {
  149         u_int tmp;
  150         u_long irq, junk;
  151         struct ar_hardc *hc;
  152 
  153         hc = (struct ar_hardc *)device_get_softc(device);
  154         if(ar_allocate_ioport(device, 0, ARC_IO_SIZ))
  155                 return (ENXIO);
  156 
  157         tmp = ar_inb(hc, AR_BMI);
  158         hc->bustype = tmp & AR_BUS_MSK;
  159         hc->memsize = (tmp & AR_MEM_MSK) >> AR_MEM_SHFT;
  160         hc->memsize = 1 << hc->memsize;
  161         hc->memsize <<= 16;
  162         hc->interface[0] = (tmp & AR_IFACE_MSK);
  163         hc->interface[1] = hc->interface[0];
  164         hc->interface[2] = hc->interface[0];
  165         hc->interface[3] = hc->interface[0];
  166         tmp = ar_inb(hc, AR_REV);
  167         hc->revision = tmp & AR_REV_MSK;
  168         hc->winsize = 1 << ((tmp & AR_WSIZ_MSK) >> AR_WSIZ_SHFT);
  169         hc->winsize *= ARC_WIN_SIZ;
  170         hc->winmsk = hc->winsize - 1;
  171         hc->numports = ar_inb(hc, AR_PNUM);
  172         hc->handshake = ar_inb(hc, AR_HNDSH);
  173 
  174         if(ar_allocate_memory(device, 0, hc->winsize))
  175                 return (ENXIO);
  176 
  177         hc->mem_start = rman_get_virtual(hc->res_memory);
  178         hc->mem_end = hc->mem_start + hc->winsize;
  179         hc->cunit = device_get_unit(device);
  180 
  181         switch(hc->interface[0]) {
  182         case AR_IFACE_EIA_232:
  183                 printf("ar%d: The EIA 232 interface is not supported.\n",
  184                         hc->cunit);
  185                 ar_deallocate_resources(device);
  186                 return (ENXIO);
  187         case AR_IFACE_V_35:
  188                 break;
  189         case AR_IFACE_EIA_530:
  190                 printf("ar%d: WARNING: The EIA 530 interface is untested.\n",
  191                         hc->cunit);
  192                 break;
  193         case AR_IFACE_X_21:
  194                 break;
  195         case AR_IFACE_COMBO:
  196                 printf("ar%d: WARNING: The COMBO interface is untested.\n",
  197                         hc->cunit);
  198                 break;
  199         }
  200 
  201         /*
  202          * Do a little sanity check.
  203          */
  204         if((hc->numports > NPORT) || (hc->memsize > (512*1024))) {
  205                 ar_deallocate_resources(device);
  206                 return (ENXIO);
  207         }
  208 
  209         if(ar_allocate_irq(device, 0, 1))
  210                 return (ENXIO);
  211 
  212         if(bus_get_resource(device, SYS_RES_IRQ, 0, &irq, &junk)) {
  213                 ar_deallocate_resources(device);
  214                 return (ENXIO);
  215         }
  216         hc->isa_irq = irq;
  217 
  218         if(ar_attach(device)) {
  219                 ar_deallocate_resources(device);
  220                 return (ENXIO);
  221         }
  222 
  223         return (0);
  224 }
  225 
  226 /*
  227  ********************************* END ************************************
  228  */

Cache object: 99f14b3666c4d731e72284aa6c58a802


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