]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/dev/cm/if_cm_isa.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / dev / cm / if_cm_isa.c
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$");
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  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/socket.h>
38 #include <sys/kernel.h>
39
40 #include <sys/module.h>
41 #include <sys/bus.h>
42
43 #include <machine/bus.h>
44 #include <sys/rman.h>
45 #include <machine/resource.h>
46
47 #include <net/if.h>
48 #include <net/if_arc.h>
49
50 #include <dev/cm/smc90cx6reg.h>
51 #include <dev/cm/smc90cx6var.h>
52
53 static int cm_isa_probe         (device_t);
54 static int cm_isa_attach        (device_t);
55
56 static int
57 cm_isa_probe(dev)
58         device_t dev;
59 {
60         struct cm_softc *sc = device_get_softc(dev);
61         int rid;
62
63         rid = 0;
64         sc->port_res = bus_alloc_resource(
65             dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, CM_IO_PORTS, RF_ACTIVE);
66         if (sc->port_res == NULL)
67                 return (ENOENT);
68
69         if (GETREG(CMSTAT) == 0xff) {
70                 cm_release_resources(dev);
71                 return (ENXIO);
72         }
73
74         rid = 0;
75         sc->mem_res = bus_alloc_resource(
76             dev, SYS_RES_MEMORY, &rid, 0ul, ~0ul, CM_MEM_SIZE, RF_ACTIVE);
77         if (sc->mem_res == NULL) {
78                 cm_release_resources(dev);
79                 return (ENOENT);
80         }
81
82         rid = 0;
83         sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
84         if (sc->irq_res == NULL) {
85                 cm_release_resources(dev);
86                 return (ENOENT);
87         }
88
89         return (0);
90 }
91
92 static int
93 cm_isa_attach(dev)
94         device_t dev;
95 {
96         struct cm_softc *sc = device_get_softc(dev);
97         int error;
98
99         /* init mtx and setup interrupt */
100         mtx_init(&sc->sc_mtx, device_get_nameunit(dev),
101             MTX_NETWORK_LOCK, MTX_DEF);
102         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET | INTR_MPSAFE,
103             NULL, cmintr, sc, &sc->irq_handle);
104         if (error)
105                 goto err;
106
107         /* attach */
108         error = cm_attach(dev);
109         if (error)
110                 goto err;
111
112         return 0;
113
114 err:
115         mtx_destroy(&sc->sc_mtx);
116         cm_release_resources(dev);
117         return (error);
118 }
119
120 static int
121 cm_isa_detach(device_t dev)
122 {
123         struct cm_softc *sc = device_get_softc(dev);
124         struct ifnet *ifp = sc->sc_ifp;
125
126         /* stop and detach */
127         CM_LOCK(sc);
128         cm_stop_locked(sc);
129         ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
130         CM_UNLOCK(sc);
131
132         callout_drain(&sc->sc_recon_ch);
133         arc_ifdetach(ifp);
134
135         /* teardown interrupt, destroy mtx and release resources */
136         bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
137         mtx_destroy(&sc->sc_mtx);
138         if_free(ifp);
139         cm_release_resources(dev);
140
141         bus_generic_detach(dev);
142         return (0);
143 }
144
145 static device_method_t cm_isa_methods[] = {
146         /* Device interface */
147         DEVMETHOD(device_probe,         cm_isa_probe),
148         DEVMETHOD(device_attach,        cm_isa_attach),
149         DEVMETHOD(device_detach,        cm_isa_detach),
150
151         { 0, 0 }
152 };
153
154 static driver_t cm_isa_driver = {
155         "cm",
156         cm_isa_methods,
157         sizeof(struct cm_softc)
158 };
159
160 DRIVER_MODULE(cm, isa, cm_isa_driver, cm_devclass, 0, 0);
161 MODULE_DEPEND(cm, isa, 1, 1, 1);