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