kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / dev / netif / cs / if_cs_pccard.c
1 /*
2  * Copyright (c) 1999 M. Warner Losh <imp@village.org> 
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD: src/sys/dev/cs/if_cs_pccard.c,v 1.1.2.1 2001/01/25 20:13:48 imp Exp $
26  * $DragonFly: src/sys/dev/netif/cs/if_cs_pccard.c,v 1.3 2003/08/07 21:17:00 dillon Exp $
27  */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/socket.h>
33
34 #include <sys/module.h>
35 #include <sys/bus.h>
36
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39  
40 #include <net/ethernet.h> 
41 #include <net/if.h> 
42 #include <net/if_arp.h>
43
44 #include "if_csvar.h"
45 #include <bus/pccard/pccardvar.h>
46
47 #include "card_if.h"
48
49 static int
50 cs_pccard_probe(device_t dev)
51 {
52         int error;
53
54         error = cs_cs89x0_probe(dev);
55         cs_release_resources(dev);
56         return (error);
57 }
58
59 static int
60 cs_pccard_attach(device_t dev)
61 {
62         struct cs_softc *sc = device_get_softc(dev);
63         int flags = device_get_flags(dev);
64         int error;
65         
66         if (sc->port_used > 0)
67                 cs_alloc_port(dev, sc->port_rid, sc->port_used);
68         if (sc->mem_used)
69                 cs_alloc_memory(dev, sc->mem_rid, sc->mem_used);
70         error = cs_alloc_irq(dev, sc->irq_rid, 0);
71         if (error != 0)
72                 goto bad;
73                 
74         error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
75             csintr, sc, &sc->irq_handle);
76         if (error != 0)
77                 goto bad;
78
79         return (cs_attach(sc, device_get_unit(dev), flags));
80 bad:
81         cs_release_resources(dev);
82         return (error);
83 }
84
85 static device_method_t cs_pccard_methods[] = {
86         /* Device interface */
87         DEVMETHOD(device_probe,         cs_pccard_probe),
88         DEVMETHOD(device_attach,        cs_pccard_attach),
89 #ifdef CS_HAS_DETACH
90         DEVMETHOD(device_detach,        cs_detach),
91 #endif
92         { 0, 0 }
93 };
94
95 static driver_t cs_pccard_driver = {
96         "cs",
97         cs_pccard_methods,
98         sizeof(struct cs_softc),
99 };
100
101 extern devclass_t cs_devclass;
102
103 DRIVER_MODULE(if_cs, pccard, cs_pccard_driver, cs_devclass, 0, 0);
104 MODULE_DEPEND(if_cs, pccard, 1, 1, 1);