Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / netif / cm / if_cm_isa.c
1 /*      $NetBSD: if_bah_zbus.c,v 1.6 2000/01/23 21:06:12 aymeric Exp $ */
2 /*      $FreeBSD: src/sys/dev/cm/if_cm_isa.c,v 1.1.2.1 2002/02/13 22:33:41 fjoe Exp $ */
3
4 /*-
5  * Copyright (c) 1994, 1995, 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Ignatios Souvatzis.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/socket.h>
43 #include <sys/kernel.h>
44
45 #include <sys/module.h>
46 #include <sys/bus.h>
47
48 #include <machine/bus.h>
49
50 #include <net/if.h>
51 #include <net/if_arc.h>
52
53 #include <dev/cm/smc90cx6var.h>
54
55 static int cm_isa_probe         __P((device_t));
56 static int cm_isa_attach        __P((device_t));
57
58 static int
59 cm_isa_probe(dev)
60         device_t dev;
61 {
62         struct cm_softc *sc = device_get_softc(dev);
63         int error;
64
65         bzero(sc, sizeof(struct cm_softc));
66
67         error = cm_probe(dev);
68         if (error == 0)
69                 goto end;
70
71 end:
72         if (error == 0)
73                 error = cm_alloc_irq(dev, 0);
74
75         cm_release_resources(dev);
76         return (error);
77 }
78
79 static int
80 cm_isa_attach(dev)
81         device_t dev;
82 {
83         struct cm_softc *sc = device_get_softc(dev);
84         int error;
85
86         cm_alloc_port(dev, sc->port_rid, sc->port_used);
87         cm_alloc_memory(dev, sc->mem_rid, sc->mem_used);
88         cm_alloc_irq(dev, sc->irq_rid);
89
90         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
91                                cmintr, sc, &sc->irq_handle);
92         if (error) {
93                 cm_release_resources(dev);
94                 return (error);
95         }
96
97         return cm_attach(sc, device_get_unit(dev));
98 }
99
100 static int
101 cm_isa_detach(device_t dev)
102 {
103         struct cm_softc *sc = device_get_softc(dev);
104         struct ifnet *ifp = &sc->sc_arccom.ac_if;
105         int s;
106
107         cm_stop(sc);
108         ifp->if_flags &= ~IFF_RUNNING;
109
110         s = splimp();
111         arc_ifdetach(&sc->sc_arccom.ac_if);
112         splx(s);
113
114         bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
115         cm_release_resources(dev);
116
117         return (0);
118 }
119
120 static device_method_t cm_isa_methods[] = {
121         /* Device interface */
122         DEVMETHOD(device_probe,         cm_isa_probe),
123         DEVMETHOD(device_attach,        cm_isa_attach),
124         DEVMETHOD(device_detach,        cm_isa_detach),
125
126         { 0, 0 }
127 };
128
129 static driver_t cm_isa_driver = {
130         "cm",
131         cm_isa_methods,
132         sizeof(struct cm_softc)
133 };
134
135 DRIVER_MODULE(if_cm, isa, cm_isa_driver, cm_devclass, 0, 0);