1 /*-
2 * Copyright (c) 2000 Mitsuru IWASAKI
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 AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: releng/5.1/sys/dev/ex/if_ex_pccard.c 112801 2003-03-29 15:38:53Z mdodd $
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 #include <sys/rman.h>
40
41 #include <net/if.h>
42 #include <net/if_arp.h>
43 #include <net/if_media.h>
44
45
46 #include <dev/ex/if_exreg.h>
47 #include <dev/ex/if_exvar.h>
48
49 #include <dev/pccard/pccardvar.h>
50
51 /* Bus Front End Functions */
52 static int ex_pccard_probe (device_t);
53 static int ex_pccard_attach (device_t);
54
55 static device_method_t ex_pccard_methods[] = {
56 /* Device interface */
57 DEVMETHOD(device_probe, ex_pccard_probe),
58 DEVMETHOD(device_attach, ex_pccard_attach),
59 DEVMETHOD(device_detach, ex_detach),
60
61 { 0, 0 }
62 };
63
64 static driver_t ex_pccard_driver = {
65 "ex",
66 ex_pccard_methods,
67 sizeof(struct ex_softc),
68 };
69
70 DRIVER_MODULE(ex, pccard, ex_pccard_driver, ex_devclass, 0, 0);
71
72 static int
73 ex_pccard_probe(device_t dev)
74 {
75 u_int iobase;
76 u_int irq;
77
78 iobase = bus_get_resource_start(dev, SYS_RES_IOPORT, 0);
79 if (!iobase) {
80 printf("ex: no iobase?\n");
81 return(ENXIO);
82 }
83
84 if (bootverbose)
85 printf("ex: ex_pccard_probe() found card at 0x%03x\n", iobase);
86
87 irq = bus_get_resource_start(dev, SYS_RES_IRQ, 0);
88
89 if (irq == 0) {
90 printf("ex: invalid IRQ.\n");
91 return(ENXIO);
92 }
93
94 return(0);
95 }
96
97 static int
98 ex_pccard_attach(device_t dev)
99 {
100 struct ex_softc * sc = device_get_softc(dev);
101 int error = 0;
102 int i;
103 u_char sum;
104 u_char ether_addr[ETHER_ADDR_LEN];
105
106 sc->dev = dev;
107 sc->ioport_rid = 0;
108 sc->irq_rid = 0;
109
110 if ((error = ex_alloc_resources(dev)) != 0) {
111 device_printf(dev, "ex_alloc_resources() failed!\n");
112 goto bad;
113 }
114
115 /*
116 * Fill in several fields of the softc structure:
117 * - I/O base address.
118 * - Hardware Ethernet address.
119 * - IRQ number.
120 */
121 sc->iobase = rman_get_start(sc->ioport);
122 sc->irq_no = rman_get_start(sc->irq);
123
124 pccard_get_ether(dev, ether_addr);
125 for (i = 0, sum = 0; i < ETHER_ADDR_LEN; i++)
126 sum |= ether_addr[i];
127 if (sum)
128 bcopy(ether_addr, sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
129
130 if ((error = ex_attach(dev)) != 0) {
131 device_printf(dev, "ex_attach() failed!\n");
132 goto bad;
133 }
134
135 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
136 ex_intr, (void *)sc, &sc->ih);
137 if (error) {
138 device_printf(dev, "bus_setup_intr() failed!\n");
139 goto bad;
140 }
141
142 return(0);
143 bad:
144 ex_release_resources(dev);
145 return (error);
146 }
Cache object: 2076ea2c85c5a9a8bf7b393f95a35294
|