Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isapnp / if_cs_isapnp.c
blob4c8b8099595c4bd4b47fade6d1a011a6d4e47a12
1 /* $NetBSD: if_cs_isapnp.c,v 1.16 2009/09/22 14:55:19 tsutsui Exp $ */
3 /*-
4 * Copyright (c)2001 YAMAMOTO Takashi,
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: if_cs_isapnp.c,v 1.16 2009/09/22 14:55:19 tsutsui Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/socket.h>
37 #include "rnd.h"
38 #if NRND > 0
39 #include <sys/rnd.h>
40 #endif
42 #include <net/if.h>
43 #include <net/if_ether.h>
44 #include <net/if_media.h>
46 #include <sys/bus.h>
47 #include <sys/intr.h>
49 #include <dev/isa/isavar.h>
51 #include <dev/ic/cs89x0reg.h>
52 #include <dev/ic/cs89x0var.h>
54 #include <dev/isapnp/isapnpreg.h>
55 #include <dev/isapnp/isapnpvar.h>
56 #include <dev/isapnp/isapnpdevs.h>
58 #define DEVNAME(sc) device_xname((sc)->sc_dev)
60 static int cs_isapnp_match(device_t, cfdata_t, void *);
61 static void cs_isapnp_attach(device_t, device_t, void *);
63 #ifdef notyet
64 CFATTACH_DECL_NEW(cs_isapnp, sizeof(struct cs_softc_isa),
65 cs_isapnp_match, cs_isapnp_attach, NULL, NULL);
66 #else
67 CFATTACH_DECL_NEW(cs_isapnp, sizeof(struct cs_softc),
68 cs_isapnp_match, cs_isapnp_attach, NULL, NULL);
69 #endif
71 int
72 cs_isapnp_match(device_t parent, cfdata_t match, void *aux)
74 int pri, variant;
76 pri = isapnp_devmatch(aux, &isapnp_cs_devinfo, &variant);
77 if (pri && variant > 0)
78 pri = 0;
79 return pri;
82 void
83 cs_isapnp_attach(device_t parent, device_t self, void *aux)
85 #ifdef notyet
86 struct cs_softc_isa *isc = device_private(sc);
87 struct cs_softc *sc = &sc->sc_cs;
88 #else
89 struct cs_softc *sc = device_private(self);
90 #endif
91 struct isapnp_attach_args *ipa = aux;
92 #ifdef notyet
93 int i;
94 #endif
96 sc->sc_dev = self;
98 printf("\n");
100 if (ipa->ipa_nio != 1 || ipa->ipa_nirq != 1 || ipa->ipa_ndrq) {
101 printf("%s: unexpected resource requirements\n",
102 DEVNAME(sc));
103 return;
106 if (ipa->ipa_io[0].length != CS8900_IOSIZE) {
107 printf("%s: unexpected io size\n", DEVNAME(sc));
108 return;
111 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
112 printf("%s: unable to allocate resources\n", DEVNAME(sc));
113 return;
116 printf("%s: %s %s\n", DEVNAME(sc), ipa->ipa_devident,
117 ipa->ipa_devclass);
119 #ifdef notyet
120 #ifdef DEBUG
121 printf("%s: nio=%u, nmem=%u, nmem32=%u, ndrq=%u, nirq=%u\n", DEVNAME(sc),
122 ipa->ipa_nio, ipa->ipa_nmem, ipa->ipa_nmem32, ipa->ipa_ndrq, ipa->ipa_nirq);
123 #endif
124 isc->sc_ic = ipa->ipa_ic;
125 isc->sc_drq = -1;
126 #endif
127 sc->sc_iot = ipa->ipa_iot;
128 sc->sc_ioh = ipa->ipa_io[0].h;
129 sc->sc_irq = ipa->ipa_irq[0].num;
131 #ifdef notyet
132 for (i = 0; i < ipa->ipa_nmem; i++) {
133 if (ipa->ipa_mem[i].length == CS8900_MEMSIZE) {
134 #if 0
135 u_int16_t id;
137 id = CS_READ_PACKET_PAGE_MEM(sc, PKTPG_EISA_NUM);
138 if (id != EISA_NUM_CRYSTAL) {
139 printf("%s: unexpected id(%u)\n",
140 DEVNAME(sc), id);
141 continue;
143 printf("%s: correct id(%u) from mem=%u\n",
144 DEVNAME(sc), id, (u_int)ipa->ipa_mem[i].h);
145 #endif
147 sc->sc_memt = ipa->ipa_memt;
148 sc->sc_memh = ipa->ipa_mem[i].h;
149 sc->sc_pktpgaddr = ipa->ipa_mem[i].base;
150 sc->sc_cfgflags |= CFGFLG_MEM_MODE;
151 printf("%s: memory mode\n", DEVNAME(sc));
152 break;
155 #endif
157 sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
158 ipa->ipa_irq[0].type, IPL_NET, cs_intr, sc);
159 if (sc->sc_ih == 0) {
160 printf("%s: unable to establish interrupt\n",
161 DEVNAME(sc));
162 goto fail;
165 if (cs_attach(sc, 0, 0, 0, 0)) {
166 printf("%s: unable to attach\n", DEVNAME(sc));
167 goto fail;
170 return;
172 fail:
173 if (sc->sc_ih)
174 isa_intr_disestablish(ipa->ipa_ic, sc->sc_ih);
175 isapnp_unconfig(ipa->ipa_iot, ipa->ipa_memt, ipa);