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/cm/if_cm_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 /*      $NetBSD: if_bah_zbus.c,v 1.6 2000/01/23 21:06:12 aymeric Exp $ */
    2 
    3 #include <sys/cdefs.h>
    4 __FBSDID("$FreeBSD: releng/8.4/sys/dev/cm/if_cm_isa.c 166901 2007-02-23 12:19:07Z piso $");
    5 
    6 /*-
    7  * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
    8  * All rights reserved.
    9  *
   10  * This code is derived from software contributed to The NetBSD Foundation
   11  * by Ignatios Souvatzis.
   12  *
   13  * Redistribution and use in source and binary forms, with or without
   14  * modification, are permitted provided that the following conditions
   15  * are met:
   16  * 1. Redistributions of source code must retain the above copyright
   17  *    notice, this list of conditions and the following disclaimer.
   18  * 2. Redistributions in binary form must reproduce the above copyright
   19  *    notice, this list of conditions and the following disclaimer in the
   20  *    documentation and/or other materials provided with the distribution.
   21  * 3. All advertising materials mentioning features or use of this software
   22  *    must display the following acknowledgement:
   23  *        This product includes software developed by the NetBSD
   24  *        Foundation, Inc. and its contributors.
   25  * 4. Neither the name of The NetBSD Foundation nor the names of its
   26  *    contributors may be used to endorse or promote products derived
   27  *    from this software without specific prior written permission.
   28  *
   29  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   30  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   31  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   32  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   33  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   34  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   36  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   37  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   39  * POSSIBILITY OF SUCH DAMAGE.
   40  */
   41 
   42 #include <sys/param.h>
   43 #include <sys/systm.h>
   44 #include <sys/socket.h>
   45 #include <sys/kernel.h>
   46 
   47 #include <sys/module.h>
   48 #include <sys/bus.h>
   49 
   50 #include <machine/bus.h>
   51 #include <sys/rman.h>
   52 #include <machine/resource.h>
   53 
   54 #include <net/if.h>
   55 #include <net/if_arc.h>
   56 
   57 #include <dev/cm/smc90cx6reg.h>
   58 #include <dev/cm/smc90cx6var.h>
   59 
   60 static int cm_isa_probe         (device_t);
   61 static int cm_isa_attach        (device_t);
   62 
   63 static int
   64 cm_isa_probe(dev)
   65         device_t dev;
   66 {
   67         struct cm_softc *sc = device_get_softc(dev);
   68         int rid;
   69 
   70         rid = 0;
   71         sc->port_res = bus_alloc_resource(
   72             dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, CM_IO_PORTS, RF_ACTIVE);
   73         if (sc->port_res == NULL)
   74                 return (ENOENT);
   75 
   76         if (GETREG(CMSTAT) == 0xff) {
   77                 cm_release_resources(dev);
   78                 return (ENXIO);
   79         }
   80 
   81         rid = 0;
   82         sc->mem_res = bus_alloc_resource(
   83             dev, SYS_RES_MEMORY, &rid, 0ul, ~0ul, CM_MEM_SIZE, RF_ACTIVE);
   84         if (sc->mem_res == NULL) {
   85                 cm_release_resources(dev);
   86                 return (ENOENT);
   87         }
   88 
   89         rid = 0;
   90         sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
   91         if (sc->irq_res == NULL) {
   92                 cm_release_resources(dev);
   93                 return (ENOENT);
   94         }
   95 
   96         return (0);
   97 }
   98 
   99 static int
  100 cm_isa_attach(dev)
  101         device_t dev;
  102 {
  103         struct cm_softc *sc = device_get_softc(dev);
  104         int error;
  105 
  106         /* init mtx and setup interrupt */
  107         mtx_init(&sc->sc_mtx, device_get_nameunit(dev),
  108             MTX_NETWORK_LOCK, MTX_DEF);
  109         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
  110             NULL, cmintr, sc, &sc->irq_handle);
  111         if (error)
  112                 goto err;
  113 
  114         /* attach */
  115         error = cm_attach(dev);
  116         if (error)
  117                 goto err;
  118 
  119         return 0;
  120 
  121 err:
  122         mtx_destroy(&sc->sc_mtx);
  123         cm_release_resources(dev);
  124         return (error);
  125 }
  126 
  127 static int
  128 cm_isa_detach(device_t dev)
  129 {
  130         struct cm_softc *sc = device_get_softc(dev);
  131         struct ifnet *ifp = sc->sc_ifp;
  132 
  133         /* stop and detach */
  134         CM_LOCK(sc);
  135         cm_stop_locked(sc);
  136         ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
  137         CM_UNLOCK(sc);
  138 
  139         callout_drain(&sc->sc_recon_ch);
  140         arc_ifdetach(ifp);
  141 
  142         /* teardown interrupt, destroy mtx and release resources */
  143         bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
  144         mtx_destroy(&sc->sc_mtx);
  145         if_free(ifp);
  146         cm_release_resources(dev);
  147 
  148         bus_generic_detach(dev);
  149         return (0);
  150 }
  151 
  152 static device_method_t cm_isa_methods[] = {
  153         /* Device interface */
  154         DEVMETHOD(device_probe,         cm_isa_probe),
  155         DEVMETHOD(device_attach,        cm_isa_attach),
  156         DEVMETHOD(device_detach,        cm_isa_detach),
  157 
  158         { 0, 0 }
  159 };
  160 
  161 static driver_t cm_isa_driver = {
  162         "cm",
  163         cm_isa_methods,
  164         sizeof(struct cm_softc)
  165 };
  166 
  167 DRIVER_MODULE(cm, isa, cm_isa_driver, cm_devclass, 0, 0);
  168 MODULE_DEPEND(cm, isa, 1, 1, 1);

Cache object: bc56875e05494fbaa4263f58ae30f765


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