2 * Copyright (c) 1995, David Greenman
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 * National Semiconductor DP8393X SONIC Driver
35 * This is the C-bus specific attachment on FreeBSD
36 * written by Motomichi Matsuzaki <mzaki@e-mail.ne.jp>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/socket.h>
42 #include <sys/kernel.h>
44 #include <sys/module.h>
46 #include <machine/bus.h>
47 #include <machine/resource.h>
50 #include <net/if_arp.h>
51 #include <net/if_media.h>
53 #include <isa/isavar.h>
54 #include <sys/malloc.h> /* as dependency for isa/isa_common.h */
55 #include <isa/isa_common.h> /* for snc_isapnp_reconfig() */
57 #include <dev/snc/dp83932var.h>
58 #include <dev/snc/if_sncreg.h>
59 #include <dev/snc/if_sncvar.h>
61 static void snc_isapnp_reconfig (device_t);
62 static int snc_isa_probe (device_t);
63 static int snc_isa_attach (device_t);
65 static struct isa_pnp_id snc_ids[] = {
66 { 0x6180a3b8, NULL }, /* NEC8061 NEC PC-9801-104 */
71 snc_isapnp_reconfig(device_t dev)
73 struct isa_device *idev = DEVTOISA(dev);
74 struct isa_config config;
78 bzero(&config, sizeof(config));
80 for (rid = 0; rid < ISA_NMEM; rid++) {
81 if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count))
83 config.ic_mem[rid].ir_start = start;
84 config.ic_mem[rid].ir_end = start;
85 config.ic_mem[rid].ir_size = count;
88 for (rid = 0; rid < ISA_NPORT; rid++) {
89 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count))
91 config.ic_port[rid].ir_start = start;
92 config.ic_port[rid].ir_end = start;
93 config.ic_port[rid].ir_size = count;
95 config.ic_nport = rid;
96 for (rid = 0; rid < ISA_NIRQ; rid++) {
97 if (bus_get_resource(dev, SYS_RES_IRQ, rid, &start, &count))
99 config.ic_irqmask[rid] = 1 << start;
101 config.ic_nirq = rid;
102 for (rid = 0; rid < ISA_NDRQ; rid++) {
103 if (bus_get_resource(dev, SYS_RES_DRQ, rid, &start, &count))
105 config.ic_drqmask[rid] = 1 << start;
107 config.ic_ndrq = rid;
109 idev->id_config_cb(idev->id_config_arg, &config, 1);
113 snc_isa_probe(device_t dev)
115 struct snc_softc *sc = device_get_softc(dev);
119 bzero(sc, sizeof(struct snc_softc));
121 /* Check isapnp ids */
122 error = ISA_PNP_PROBE(device_get_parent(dev), dev, snc_ids);
124 /* If the card had a PnP ID that didn't match any we know about */
125 if (error == ENXIO) {
130 case 0: /* Matched PnP */
131 type = SNEC_TYPE_PNP;
134 case ENOENT: /* Legacy ISA */
135 type = SNEC_TYPE_LEGACY;
138 default: /* If we had some other problem. */
142 if (type == SNEC_TYPE_PNP && isa_get_portsize(dev) == 0) {
145 struct resource *res = NULL;
147 for (port = 0x0888; port <= 0x3888; port += 0x1000) {
148 bus_set_resource(dev, SYS_RES_IOPORT, rid,
150 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
151 0ul, ~0ul, SNEC_NREGS,
156 printf("snc_isa_probe: broken PnP resource, ");
158 printf("use port 0x%x\n", port);
159 bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
160 snc_isapnp_reconfig(dev);
162 printf("and can't find port\n");
166 error = snc_alloc_port(dev, 0);
167 error = max(error, snc_alloc_memory(dev, 0));
168 error = max(error, snc_alloc_irq(dev, 0, 0));
170 if (!error && !snc_probe(dev, type))
173 snc_release_resources(dev);
178 snc_isa_attach(device_t dev)
180 struct snc_softc *sc = device_get_softc(dev);
182 bzero(sc, sizeof(struct snc_softc));
184 snc_alloc_port(dev, 0);
185 snc_alloc_memory(dev, 0);
186 snc_alloc_irq(dev, 0, 0);
188 /* This interface is always enabled. */
191 return snc_attach(dev);
194 static device_method_t snc_isa_methods[] = {
195 /* Device interface */
196 DEVMETHOD(device_probe, snc_isa_probe),
197 DEVMETHOD(device_attach, snc_isa_attach),
198 DEVMETHOD(device_shutdown, snc_shutdown),
203 static driver_t snc_isa_driver = {
206 sizeof(struct snc_softc)
209 DRIVER_MODULE(snc, isa, snc_isa_driver, snc_devclass, 0, 0);
210 MODULE_DEPEND(snc, isa, 1, 1, 1);
211 MODULE_DEPEND(snc, ether, 1, 1, 1);