pcmcia.c revision 1.95 1 1.95 thorpej /* $NetBSD: pcmcia.c,v 1.95 2021/04/24 23:36:58 thorpej Exp $ */
2 1.42 mycroft
3 1.42 mycroft /*
4 1.42 mycroft * Copyright (c) 2004 Charles M. Hannum. All rights reserved.
5 1.42 mycroft *
6 1.42 mycroft * Redistribution and use in source and binary forms, with or without
7 1.42 mycroft * modification, are permitted provided that the following conditions
8 1.42 mycroft * are met:
9 1.42 mycroft * 1. Redistributions of source code must retain the above copyright
10 1.42 mycroft * notice, this list of conditions and the following disclaimer.
11 1.42 mycroft * 2. Redistributions in binary form must reproduce the above copyright
12 1.42 mycroft * notice, this list of conditions and the following disclaimer in the
13 1.42 mycroft * documentation and/or other materials provided with the distribution.
14 1.42 mycroft * 3. All advertising materials mentioning features or use of this software
15 1.42 mycroft * must display the following acknowledgement:
16 1.42 mycroft * This product includes software developed by Charles M. Hannum.
17 1.42 mycroft * 4. The name of the author may not be used to endorse or promote products
18 1.42 mycroft * derived from this software without specific prior written permission.
19 1.42 mycroft */
20 1.2 thorpej
21 1.2 thorpej /*
22 1.2 thorpej * Copyright (c) 1997 Marc Horowitz. All rights reserved.
23 1.2 thorpej *
24 1.2 thorpej * Redistribution and use in source and binary forms, with or without
25 1.2 thorpej * modification, are permitted provided that the following conditions
26 1.2 thorpej * are met:
27 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
28 1.2 thorpej * notice, this list of conditions and the following disclaimer.
29 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
30 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
31 1.2 thorpej * documentation and/or other materials provided with the distribution.
32 1.2 thorpej * 3. All advertising materials mentioning features or use of this software
33 1.2 thorpej * must display the following acknowledgement:
34 1.2 thorpej * This product includes software developed by Marc Horowitz.
35 1.2 thorpej * 4. The name of the author may not be used to endorse or promote products
36 1.2 thorpej * derived from this software without specific prior written permission.
37 1.2 thorpej *
38 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39 1.2 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 1.2 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41 1.2 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
42 1.2 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 1.2 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 1.2 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 1.2 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 1.2 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
47 1.2 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 1.2 thorpej */
49 1.26 lukem
50 1.26 lukem #include <sys/cdefs.h>
51 1.95 thorpej __KERNEL_RCSID(0, "$NetBSD: pcmcia.c,v 1.95 2021/04/24 23:36:58 thorpej Exp $");
52 1.2 thorpej
53 1.2 thorpej #include "opt_pcmciaverbose.h"
54 1.2 thorpej
55 1.2 thorpej #include <sys/param.h>
56 1.2 thorpej #include <sys/systm.h>
57 1.2 thorpej #include <sys/device.h>
58 1.2 thorpej
59 1.84 jmcneill #include <net/if.h>
60 1.84 jmcneill
61 1.2 thorpej #include <dev/pcmcia/pcmciareg.h>
62 1.2 thorpej #include <dev/pcmcia/pcmciachip.h>
63 1.2 thorpej #include <dev/pcmcia/pcmciavar.h>
64 1.21 uch #ifdef IT8368E_LEGACY_MODE /* XXX -uch */
65 1.21 uch #include <arch/hpcmips/dev/it8368var.h>
66 1.21 uch #endif
67 1.2 thorpej
68 1.3 enami #include "locators.h"
69 1.3 enami
70 1.2 thorpej #ifdef PCMCIADEBUG
71 1.2 thorpej int pcmcia_debug = 0;
72 1.2 thorpej #define DPRINTF(arg) if (pcmcia_debug) printf arg
73 1.2 thorpej #else
74 1.2 thorpej #define DPRINTF(arg)
75 1.2 thorpej #endif
76 1.2 thorpej
77 1.2 thorpej #ifdef PCMCIAVERBOSE
78 1.2 thorpej int pcmcia_verbose = 1;
79 1.2 thorpej #else
80 1.2 thorpej int pcmcia_verbose = 0;
81 1.2 thorpej #endif
82 1.2 thorpej
83 1.93 cegger int pcmcia_match(device_t, cfdata_t, void *);
84 1.93 cegger void pcmcia_attach(device_t, device_t, void *);
85 1.85 dyoung int pcmcia_detach(device_t, int);
86 1.93 cegger int pcmcia_rescan(device_t, const char *, const int *);
87 1.93 cegger void pcmcia_childdetached(device_t, device_t);
88 1.72 perry int pcmcia_print(void *, const char *);
89 1.2 thorpej
90 1.91 dyoung CFATTACH_DECL3_NEW(pcmcia, sizeof(struct pcmcia_softc),
91 1.85 dyoung pcmcia_match, pcmcia_attach, pcmcia_detach, NULL,
92 1.91 dyoung pcmcia_rescan, pcmcia_childdetached, DVF_DETACH_SHUTDOWN);
93 1.2 thorpej
94 1.2 thorpej int
95 1.88 dsl pcmcia_ccr_read(struct pcmcia_function *pf, int ccr)
96 1.2 thorpej {
97 1.2 thorpej
98 1.2 thorpej return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh,
99 1.43 mycroft pf->pf_ccr_offset + ccr * 2));
100 1.2 thorpej }
101 1.2 thorpej
102 1.2 thorpej void
103 1.88 dsl pcmcia_ccr_write(struct pcmcia_function *pf, int ccr, int val)
104 1.2 thorpej {
105 1.2 thorpej
106 1.43 mycroft if (pf->ccr_mask & (1 << ccr)) {
107 1.2 thorpej bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh,
108 1.43 mycroft pf->pf_ccr_offset + ccr * 2, val);
109 1.2 thorpej }
110 1.2 thorpej }
111 1.2 thorpej
112 1.2 thorpej int
113 1.93 cegger pcmcia_match(device_t parent, cfdata_t match, void *aux)
114 1.2 thorpej {
115 1.14 haya struct pcmciabus_attach_args *paa = aux;
116 1.14 haya
117 1.30 thorpej if (strcmp(paa->paa_busname, match->cf_name)) {
118 1.14 haya return 0;
119 1.14 haya }
120 1.2 thorpej /* if the autoconfiguration got this far, there's a socket here */
121 1.2 thorpej return (1);
122 1.2 thorpej }
123 1.2 thorpej
124 1.2 thorpej void
125 1.93 cegger pcmcia_attach(device_t parent, device_t self, void *aux)
126 1.2 thorpej {
127 1.2 thorpej struct pcmciabus_attach_args *paa = aux;
128 1.87 drochner struct pcmcia_softc *sc = device_private(self);
129 1.2 thorpej
130 1.83 jmcneill aprint_naive("\n");
131 1.83 jmcneill aprint_normal("\n");
132 1.2 thorpej
133 1.87 drochner sc->dev = self;
134 1.2 thorpej sc->pct = paa->pct;
135 1.2 thorpej sc->pch = paa->pch;
136 1.2 thorpej
137 1.2 thorpej sc->ih = NULL;
138 1.84 jmcneill
139 1.84 jmcneill if (!pmf_device_register(self, NULL, NULL))
140 1.84 jmcneill aprint_error_dev(self, "couldn't establish power handler\n");
141 1.2 thorpej }
142 1.2 thorpej
143 1.2 thorpej int
144 1.85 dyoung pcmcia_detach(device_t self, int flags)
145 1.85 dyoung {
146 1.85 dyoung int rc;
147 1.85 dyoung
148 1.85 dyoung if ((rc = config_detach_children(self, flags)) != 0)
149 1.85 dyoung return rc;
150 1.85 dyoung
151 1.85 dyoung pmf_device_deregister(self);
152 1.85 dyoung return 0;
153 1.85 dyoung }
154 1.85 dyoung
155 1.85 dyoung int
156 1.93 cegger pcmcia_card_attach(device_t dev)
157 1.2 thorpej {
158 1.87 drochner struct pcmcia_softc *sc = device_private(dev);
159 1.2 thorpej struct pcmcia_function *pf;
160 1.71 drochner int error;
161 1.77 drochner static const int wildcard[PCMCIACF_NLOCS] = {
162 1.81 drochner PCMCIACF_FUNCTION_DEFAULT
163 1.71 drochner };
164 1.2 thorpej
165 1.2 thorpej /*
166 1.2 thorpej * this is here so that when socket_enable calls gettype, trt happens
167 1.2 thorpej */
168 1.29 lukem SIMPLEQ_FIRST(&sc->card.pf_head) = NULL;
169 1.2 thorpej
170 1.59 mycroft pcmcia_socket_enable(dev);
171 1.2 thorpej
172 1.2 thorpej pcmcia_read_cis(sc);
173 1.59 mycroft pcmcia_check_cis_quirks(sc);
174 1.2 thorpej
175 1.71 drochner #if 1 /* XXX remove this, done below ??? */
176 1.2 thorpej /*
177 1.2 thorpej * bail now if the card has no functions, or if there was an error in
178 1.2 thorpej * the cis.
179 1.2 thorpej */
180 1.64 mycroft if (sc->card.error ||
181 1.64 mycroft SIMPLEQ_EMPTY(&sc->card.pf_head)) {
182 1.64 mycroft printf("%s: card appears to have bogus CIS\n",
183 1.87 drochner device_xname(sc->dev));
184 1.71 drochner error = EIO;
185 1.59 mycroft goto done;
186 1.64 mycroft }
187 1.71 drochner #endif
188 1.2 thorpej
189 1.2 thorpej if (pcmcia_verbose)
190 1.2 thorpej pcmcia_print_cis(sc);
191 1.2 thorpej
192 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
193 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
194 1.2 thorpej continue;
195 1.2 thorpej
196 1.11 thorpej #ifdef DIAGNOSTIC
197 1.11 thorpej if (pf->child != NULL) {
198 1.11 thorpej printf("%s: %s still attached to function %d!\n",
199 1.87 drochner device_xname(sc->dev), device_xname(pf->child),
200 1.11 thorpej pf->number);
201 1.11 thorpej panic("pcmcia_card_attach");
202 1.11 thorpej }
203 1.11 thorpej #endif
204 1.2 thorpej pf->sc = sc;
205 1.11 thorpej pf->child = NULL;
206 1.2 thorpej pf->cfe = NULL;
207 1.52 mycroft pf->pf_ih = NULL;
208 1.2 thorpej }
209 1.2 thorpej
210 1.95 thorpej error = pcmcia_rescan(dev, NULL, wildcard);
211 1.71 drochner done:
212 1.71 drochner pcmcia_socket_disable(dev);
213 1.71 drochner return (error);
214 1.71 drochner }
215 1.71 drochner
216 1.71 drochner int
217 1.95 thorpej pcmcia_rescan(device_t self, const char *ifattr, const int *locators)
218 1.71 drochner {
219 1.87 drochner struct pcmcia_softc *sc = device_private(self);
220 1.71 drochner struct pcmcia_function *pf;
221 1.71 drochner struct pcmcia_attach_args paa;
222 1.75 drochner int locs[PCMCIACF_NLOCS];
223 1.71 drochner
224 1.71 drochner if (sc->card.error ||
225 1.71 drochner SIMPLEQ_EMPTY(&sc->card.pf_head)) {
226 1.71 drochner /* XXX silently ignore if no card present? */
227 1.71 drochner return (EIO);
228 1.71 drochner }
229 1.71 drochner
230 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
231 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
232 1.2 thorpej continue;
233 1.2 thorpej
234 1.71 drochner if ((locators[PCMCIACF_FUNCTION] != PCMCIACF_FUNCTION_DEFAULT)
235 1.71 drochner && (locators[PCMCIACF_FUNCTION] != pf->number))
236 1.71 drochner continue;
237 1.71 drochner
238 1.71 drochner if (pf->child)
239 1.71 drochner continue;
240 1.71 drochner
241 1.75 drochner locs[PCMCIACF_FUNCTION] = pf->number;
242 1.71 drochner
243 1.2 thorpej paa.manufacturer = sc->card.manufacturer;
244 1.2 thorpej paa.product = sc->card.product;
245 1.2 thorpej paa.card = &sc->card;
246 1.2 thorpej paa.pf = pf;
247 1.2 thorpej
248 1.95 thorpej pf->child = config_found(self, &paa, pcmcia_print,
249 1.95 thorpej CFARG_SUBMATCH, config_stdsubmatch,
250 1.95 thorpej CFARG_LOCATORS, locs,
251 1.95 thorpej CFARG_EOL);
252 1.2 thorpej }
253 1.2 thorpej
254 1.71 drochner return (0);
255 1.2 thorpej }
256 1.2 thorpej
257 1.2 thorpej void
258 1.93 cegger pcmcia_card_detach(device_t dev, int flags)
259 1.89 dsl /* flags: DETACH_* flags */
260 1.2 thorpej {
261 1.87 drochner struct pcmcia_softc *sc = device_private(dev);
262 1.11 thorpej struct pcmcia_function *pf;
263 1.11 thorpej int error;
264 1.10 thorpej
265 1.11 thorpej /*
266 1.11 thorpej * We are running on either the PCMCIA socket's event thread
267 1.11 thorpej * or in user context detaching a device by user request.
268 1.10 thorpej */
269 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
270 1.69 mycroft pf->pf_flags |= PFF_DETACHED;
271 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
272 1.11 thorpej continue;
273 1.11 thorpej if (pf->child == NULL)
274 1.11 thorpej continue;
275 1.11 thorpej DPRINTF(("%s: detaching %s (function %d)\n",
276 1.87 drochner device_xname(sc->dev), device_xname(pf->child), pf->number));
277 1.11 thorpej if ((error = config_detach(pf->child, flags)) != 0) {
278 1.11 thorpej printf("%s: error %d detaching %s (function %d)\n",
279 1.87 drochner device_xname(sc->dev), error, device_xname(pf->child),
280 1.11 thorpej pf->number);
281 1.71 drochner }
282 1.11 thorpej }
283 1.53 mycroft
284 1.53 mycroft if (sc->sc_enabled_count != 0) {
285 1.53 mycroft #ifdef DIAGNOSTIC
286 1.53 mycroft printf("pcmcia_card_detach: enabled_count should be 0 here??\n");
287 1.53 mycroft #endif
288 1.53 mycroft pcmcia_chip_socket_disable(sc->pct, sc->pch);
289 1.53 mycroft sc->sc_enabled_count = 0;
290 1.53 mycroft }
291 1.11 thorpej }
292 1.11 thorpej
293 1.11 thorpej void
294 1.93 cegger pcmcia_childdetached(device_t self, device_t child)
295 1.71 drochner {
296 1.87 drochner struct pcmcia_softc *sc = device_private(self);
297 1.71 drochner struct pcmcia_function *pf;
298 1.71 drochner
299 1.71 drochner SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
300 1.71 drochner if (SIMPLEQ_EMPTY(&pf->cfe_head))
301 1.71 drochner continue;
302 1.71 drochner if (pf->child == child) {
303 1.79 thorpej KASSERT(device_locator(child, PCMCIACF_FUNCTION)
304 1.71 drochner == pf->number);
305 1.71 drochner pf->child = NULL;
306 1.71 drochner return;
307 1.71 drochner }
308 1.71 drochner }
309 1.71 drochner
310 1.86 cegger aprint_error_dev(self, "pcmcia_childdetached: %s not found\n",
311 1.86 cegger device_xname(child));
312 1.71 drochner }
313 1.71 drochner
314 1.71 drochner void
315 1.93 cegger pcmcia_card_deactivate(device_t dev)
316 1.11 thorpej {
317 1.87 drochner struct pcmcia_softc *sc = device_private(dev);
318 1.11 thorpej struct pcmcia_function *pf;
319 1.10 thorpej
320 1.11 thorpej /*
321 1.11 thorpej * We're in the chip's card removal interrupt handler.
322 1.11 thorpej * Deactivate the child driver. The PCMCIA socket's
323 1.11 thorpej * event thread will run later to finish the detach.
324 1.11 thorpej */
325 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
326 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
327 1.11 thorpej continue;
328 1.11 thorpej if (pf->child == NULL)
329 1.11 thorpej continue;
330 1.11 thorpej DPRINTF(("%s: deactivating %s (function %d)\n",
331 1.87 drochner device_xname(sc->dev), device_xname(pf->child), pf->number));
332 1.11 thorpej config_deactivate(pf->child);
333 1.11 thorpej }
334 1.2 thorpej }
335 1.2 thorpej
336 1.2 thorpej int
337 1.88 dsl pcmcia_print(void *arg, const char *pnp)
338 1.2 thorpej {
339 1.2 thorpej struct pcmcia_attach_args *pa = arg;
340 1.2 thorpej struct pcmcia_softc *sc = pa->pf->sc;
341 1.2 thorpej struct pcmcia_card *card = &sc->card;
342 1.18 augustss char devinfo[256];
343 1.2 thorpej
344 1.38 mycroft if (pnp)
345 1.38 mycroft aprint_normal("%s", pnp);
346 1.38 mycroft
347 1.38 mycroft pcmcia_devinfo(card, !!pnp, devinfo, sizeof(devinfo));
348 1.38 mycroft
349 1.57 mycroft aprint_normal(" function %d: %s\n", pa->pf->number, devinfo);
350 1.2 thorpej
351 1.2 thorpej return (UNCONF);
352 1.18 augustss }
353 1.18 augustss
354 1.18 augustss void
355 1.88 dsl pcmcia_devinfo(struct pcmcia_card *card, int showhex, char *cp, size_t cplen)
356 1.18 augustss {
357 1.18 augustss int i, n;
358 1.18 augustss
359 1.37 mycroft if (cplen > 1) {
360 1.37 mycroft *cp++ = '<';
361 1.38 mycroft *cp = '\0';
362 1.37 mycroft cplen--;
363 1.37 mycroft }
364 1.37 mycroft
365 1.37 mycroft for (i = 0; i < 4 && card->cis1_info[i] != NULL && cplen > 1; i++) {
366 1.39 mycroft n = snprintf(cp, cplen, "%s%s", i ? ", " : "",
367 1.18 augustss card->cis1_info[i]);
368 1.18 augustss cp += n;
369 1.38 mycroft if (cplen < n)
370 1.38 mycroft return;
371 1.18 augustss cplen -= n;
372 1.18 augustss }
373 1.37 mycroft
374 1.37 mycroft if (cplen > 1) {
375 1.37 mycroft *cp++ = '>';
376 1.38 mycroft *cp = '\0';
377 1.37 mycroft cplen--;
378 1.37 mycroft }
379 1.37 mycroft
380 1.37 mycroft if (showhex && cplen > 1)
381 1.37 mycroft snprintf(cp, cplen, " (manufacturer 0x%04x, product 0x%04x)",
382 1.37 mycroft card->manufacturer, card->product);
383 1.16 cgd }
384 1.16 cgd
385 1.56 mycroft const void *
386 1.88 dsl pcmcia_product_lookup(struct pcmcia_attach_args *pa, const void *tab, size_t nent, size_t ent_size, pcmcia_product_match_fn matchfn)
387 1.16 cgd {
388 1.56 mycroft const struct pcmcia_product *pp;
389 1.56 mycroft int n;
390 1.16 cgd int matches;
391 1.16 cgd
392 1.16 cgd #ifdef DIAGNOSTIC
393 1.56 mycroft if (sizeof *pp > ent_size)
394 1.73 perry panic("pcmcia_product_lookup: bogus ent_size %ld",
395 1.17 nathanw (long) ent_size);
396 1.16 cgd #endif
397 1.16 cgd
398 1.56 mycroft for (pp = tab, n = nent; n; pp = (const struct pcmcia_product *)
399 1.56 mycroft ((const char *)pp + ent_size), n--) {
400 1.56 mycroft /* see if it matches vendor/product */
401 1.58 mycroft matches = 0;
402 1.56 mycroft if ((pp->pp_vendor != PCMCIA_VENDOR_INVALID &&
403 1.56 mycroft pp->pp_vendor == pa->manufacturer) &&
404 1.56 mycroft (pp->pp_product != PCMCIA_PRODUCT_INVALID &&
405 1.56 mycroft pp->pp_product == pa->product))
406 1.56 mycroft matches = 1;
407 1.58 mycroft if ((pp->pp_cisinfo[0] && pa->card->cis1_info[0] &&
408 1.56 mycroft !strcmp(pp->pp_cisinfo[0], pa->card->cis1_info[0])) &&
409 1.56 mycroft (pp->pp_cisinfo[1] && pa->card->cis1_info[1] &&
410 1.56 mycroft !strcmp(pp->pp_cisinfo[1], pa->card->cis1_info[1])) &&
411 1.56 mycroft (!pp->pp_cisinfo[2] || (pa->card->cis1_info[2] &&
412 1.56 mycroft !strcmp(pp->pp_cisinfo[2], pa->card->cis1_info[2]))) &&
413 1.56 mycroft (!pp->pp_cisinfo[3] || (pa->card->cis1_info[3] &&
414 1.56 mycroft !strcmp(pp->pp_cisinfo[3], pa->card->cis1_info[3]))))
415 1.56 mycroft matches = 1;
416 1.16 cgd
417 1.16 cgd /* if a separate match function is given, let it override */
418 1.56 mycroft if (matchfn)
419 1.56 mycroft matches = (*matchfn)(pa, pp, matches);
420 1.16 cgd
421 1.16 cgd if (matches)
422 1.56 mycroft return (pp);
423 1.16 cgd }
424 1.56 mycroft return (0);
425 1.2 thorpej }
426 1.2 thorpej
427 1.60 mycroft void
428 1.93 cegger pcmcia_socket_settype(device_t dev, int type)
429 1.2 thorpej {
430 1.87 drochner struct pcmcia_softc *sc = device_private(dev);
431 1.2 thorpej
432 1.60 mycroft pcmcia_chip_socket_settype(sc->pct, sc->pch, type);
433 1.2 thorpej }
434 1.2 thorpej
435 1.2 thorpej /*
436 1.2 thorpej * Initialize a PCMCIA function. May be called as long as the function is
437 1.2 thorpej * disabled.
438 1.2 thorpej */
439 1.2 thorpej void
440 1.88 dsl pcmcia_function_init(struct pcmcia_function *pf, struct pcmcia_config_entry *cfe)
441 1.2 thorpej {
442 1.2 thorpej if (pf->pf_flags & PFF_ENABLED)
443 1.2 thorpej panic("pcmcia_function_init: function is enabled");
444 1.2 thorpej
445 1.2 thorpej /* Remember which configuration entry we are using. */
446 1.2 thorpej pf->cfe = cfe;
447 1.2 thorpej }
448 1.2 thorpej
449 1.59 mycroft void
450 1.93 cegger pcmcia_socket_enable(device_t dev)
451 1.5 marc {
452 1.87 drochner struct pcmcia_softc *sc = device_private(dev);
453 1.40 mycroft
454 1.59 mycroft if (sc->sc_enabled_count++ == 0)
455 1.59 mycroft pcmcia_chip_socket_enable(sc->pct, sc->pch);
456 1.87 drochner DPRINTF(("%s: ++enabled_count = %d\n", device_xname(sc->dev),
457 1.59 mycroft sc->sc_enabled_count));
458 1.5 marc }
459 1.5 marc
460 1.59 mycroft void
461 1.93 cegger pcmcia_socket_disable(device_t dev)
462 1.5 marc {
463 1.87 drochner struct pcmcia_softc *sc = device_private(dev);
464 1.40 mycroft
465 1.59 mycroft if (--sc->sc_enabled_count == 0)
466 1.59 mycroft pcmcia_chip_socket_disable(sc->pct, sc->pch);
467 1.87 drochner DPRINTF(("%s: --enabled_count = %d\n", device_xname(sc->dev),
468 1.59 mycroft sc->sc_enabled_count));
469 1.5 marc }
470 1.5 marc
471 1.2 thorpej /* Enable a PCMCIA function */
472 1.2 thorpej int
473 1.88 dsl pcmcia_function_enable(struct pcmcia_function *pf)
474 1.2 thorpej {
475 1.53 mycroft struct pcmcia_softc *sc = pf->sc;
476 1.2 thorpej struct pcmcia_function *tmp;
477 1.2 thorpej int reg;
478 1.55 mycroft int error;
479 1.2 thorpej
480 1.2 thorpej if (pf->cfe == NULL)
481 1.2 thorpej panic("pcmcia_function_enable: function not initialized");
482 1.2 thorpej
483 1.5 marc /*
484 1.5 marc * Increase the reference count on the socket, enabling power, if
485 1.5 marc * necessary.
486 1.5 marc */
487 1.87 drochner pcmcia_socket_enable(sc->dev);
488 1.87 drochner pcmcia_socket_settype(sc->dev, pf->cfe->iftype);
489 1.5 marc
490 1.2 thorpej if (pf->pf_flags & PFF_ENABLED) {
491 1.2 thorpej /*
492 1.2 thorpej * Don't do anything if we're already enabled.
493 1.2 thorpej */
494 1.2 thorpej return (0);
495 1.2 thorpej }
496 1.2 thorpej
497 1.2 thorpej /*
498 1.2 thorpej * it's possible for different functions' CCRs to be in the same
499 1.2 thorpej * underlying page. Check for that.
500 1.2 thorpej */
501 1.2 thorpej
502 1.53 mycroft SIMPLEQ_FOREACH(tmp, &sc->card.pf_head, pf_list) {
503 1.2 thorpej if ((tmp->pf_flags & PFF_ENABLED) &&
504 1.2 thorpej (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
505 1.2 thorpej ((pf->ccr_base + PCMCIA_CCR_SIZE) <=
506 1.2 thorpej (tmp->ccr_base - tmp->pf_ccr_offset +
507 1.2 thorpej tmp->pf_ccr_realsize))) {
508 1.2 thorpej pf->pf_ccrt = tmp->pf_ccrt;
509 1.2 thorpej pf->pf_ccrh = tmp->pf_ccrh;
510 1.2 thorpej pf->pf_ccr_realsize = tmp->pf_ccr_realsize;
511 1.2 thorpej
512 1.2 thorpej /*
513 1.2 thorpej * pf->pf_ccr_offset = (tmp->pf_ccr_offset -
514 1.2 thorpej * tmp->ccr_base) + pf->ccr_base;
515 1.2 thorpej */
516 1.2 thorpej pf->pf_ccr_offset =
517 1.2 thorpej (tmp->pf_ccr_offset + pf->ccr_base) -
518 1.2 thorpej tmp->ccr_base;
519 1.2 thorpej pf->pf_ccr_window = tmp->pf_ccr_window;
520 1.2 thorpej break;
521 1.2 thorpej }
522 1.2 thorpej }
523 1.2 thorpej
524 1.2 thorpej if (tmp == NULL) {
525 1.55 mycroft error = pcmcia_mem_alloc(pf, PCMCIA_CCR_SIZE, &pf->pf_pcmh);
526 1.55 mycroft if (error)
527 1.2 thorpej goto bad;
528 1.2 thorpej
529 1.55 mycroft error = pcmcia_mem_map(pf, PCMCIA_MEM_ATTR, pf->ccr_base,
530 1.2 thorpej PCMCIA_CCR_SIZE, &pf->pf_pcmh, &pf->pf_ccr_offset,
531 1.55 mycroft &pf->pf_ccr_window);
532 1.55 mycroft if (error) {
533 1.2 thorpej pcmcia_mem_free(pf, &pf->pf_pcmh);
534 1.2 thorpej goto bad;
535 1.2 thorpej }
536 1.2 thorpej }
537 1.2 thorpej
538 1.68 mycroft if (pcmcia_mfc(sc) || 1) {
539 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE0,
540 1.65 mycroft (pf->pf_mfc_iobase >> 0) & 0xff);
541 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE1,
542 1.65 mycroft (pf->pf_mfc_iobase >> 8) & 0xff);
543 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE2,
544 1.65 mycroft (pf->pf_mfc_iobase >> 16) & 0xff);
545 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE3,
546 1.65 mycroft (pf->pf_mfc_iobase >> 24) & 0xff);
547 1.65 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOLIMIT,
548 1.65 mycroft pf->pf_mfc_iomax - pf->pf_mfc_iobase);
549 1.41 mycroft }
550 1.41 mycroft
551 1.67 mycroft reg = 0;
552 1.67 mycroft if (pf->cfe->flags & PCMCIA_CFE_AUDIO)
553 1.67 mycroft reg |= PCMCIA_CCR_STATUS_AUDIO;
554 1.67 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_STATUS, reg);
555 1.67 mycroft
556 1.67 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_SOCKETCOPY, 0);
557 1.67 mycroft
558 1.2 thorpej reg = (pf->cfe->number & PCMCIA_CCR_OPTION_CFINDEX);
559 1.2 thorpej reg |= PCMCIA_CCR_OPTION_LEVIREQ;
560 1.53 mycroft if (pcmcia_mfc(sc)) {
561 1.5 marc reg |= (PCMCIA_CCR_OPTION_FUNC_ENABLE |
562 1.5 marc PCMCIA_CCR_OPTION_ADDR_DECODE);
563 1.52 mycroft if (pf->pf_ih)
564 1.5 marc reg |= PCMCIA_CCR_OPTION_IREQ_ENABLE;
565 1.5 marc
566 1.5 marc }
567 1.2 thorpej pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
568 1.2 thorpej
569 1.12 marc #ifdef PCMCIADEBUG
570 1.12 marc if (pcmcia_debug) {
571 1.53 mycroft SIMPLEQ_FOREACH(tmp, &sc->card.pf_head, pf_list) {
572 1.12 marc printf("%s: function %d CCR at %d offset %lx: "
573 1.12 marc "%x %x %x %x, %x %x %x %x, %x\n",
574 1.87 drochner device_xname(tmp->sc->dev), tmp->number,
575 1.15 aymeric tmp->pf_ccr_window,
576 1.15 aymeric (unsigned long) tmp->pf_ccr_offset,
577 1.43 mycroft pcmcia_ccr_read(tmp, 0),
578 1.43 mycroft pcmcia_ccr_read(tmp, 1),
579 1.43 mycroft pcmcia_ccr_read(tmp, 2),
580 1.43 mycroft pcmcia_ccr_read(tmp, 3),
581 1.43 mycroft
582 1.43 mycroft pcmcia_ccr_read(tmp, 5),
583 1.73 perry pcmcia_ccr_read(tmp, 6),
584 1.43 mycroft pcmcia_ccr_read(tmp, 7),
585 1.43 mycroft pcmcia_ccr_read(tmp, 8),
586 1.5 marc
587 1.43 mycroft pcmcia_ccr_read(tmp, 9));
588 1.12 marc }
589 1.12 marc }
590 1.12 marc #endif
591 1.5 marc
592 1.21 uch #ifdef IT8368E_LEGACY_MODE
593 1.21 uch /* return to I/O mode */
594 1.21 uch it8368_mode(pf, IT8368_IO_MODE, IT8368_WIDTH_16);
595 1.21 uch #endif
596 1.66 mycroft
597 1.66 mycroft pf->pf_flags |= PFF_ENABLED;
598 1.2 thorpej return (0);
599 1.2 thorpej
600 1.55 mycroft bad:
601 1.2 thorpej /*
602 1.2 thorpej * Decrement the reference count, and power down the socket, if
603 1.2 thorpej * necessary.
604 1.2 thorpej */
605 1.86 cegger printf("%s: couldn't map the CCR\n", device_xname(pf->child));
606 1.87 drochner pcmcia_socket_disable(sc->dev);
607 1.5 marc
608 1.55 mycroft return (error);
609 1.2 thorpej }
610 1.2 thorpej
611 1.2 thorpej /* Disable PCMCIA function. */
612 1.2 thorpej void
613 1.88 dsl pcmcia_function_disable(struct pcmcia_function *pf)
614 1.2 thorpej {
615 1.59 mycroft struct pcmcia_softc *sc = pf->sc;
616 1.2 thorpej struct pcmcia_function *tmp;
617 1.48 mycroft int reg;
618 1.2 thorpej
619 1.2 thorpej if (pf->cfe == NULL)
620 1.2 thorpej panic("pcmcia_function_enable: function not initialized");
621 1.2 thorpej
622 1.2 thorpej if ((pf->pf_flags & PFF_ENABLED) == 0) {
623 1.2 thorpej /*
624 1.36 briggs * Don't do anything but decrement if we're already disabled.
625 1.2 thorpej */
626 1.36 briggs goto out;
627 1.2 thorpej }
628 1.2 thorpej
629 1.69 mycroft if (pcmcia_mfc(sc) &&
630 1.69 mycroft (pf->pf_flags & PFF_DETACHED) == 0) {
631 1.48 mycroft reg = pcmcia_ccr_read(pf, PCMCIA_CCR_OPTION);
632 1.48 mycroft reg &= ~(PCMCIA_CCR_OPTION_FUNC_ENABLE|
633 1.48 mycroft PCMCIA_CCR_OPTION_ADDR_DECODE|
634 1.48 mycroft PCMCIA_CCR_OPTION_IREQ_ENABLE);
635 1.48 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
636 1.48 mycroft }
637 1.48 mycroft
638 1.2 thorpej /*
639 1.2 thorpej * it's possible for different functions' CCRs to be in the same
640 1.2 thorpej * underlying page. Check for that. Note we mark us as disabled
641 1.2 thorpej * first to avoid matching ourself.
642 1.2 thorpej */
643 1.2 thorpej
644 1.2 thorpej pf->pf_flags &= ~PFF_ENABLED;
645 1.59 mycroft SIMPLEQ_FOREACH(tmp, &sc->card.pf_head, pf_list) {
646 1.2 thorpej if ((tmp->pf_flags & PFF_ENABLED) &&
647 1.2 thorpej (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
648 1.2 thorpej ((pf->ccr_base + PCMCIA_CCR_SIZE) <=
649 1.2 thorpej (tmp->ccr_base - tmp->pf_ccr_offset + tmp->pf_ccr_realsize)))
650 1.2 thorpej break;
651 1.2 thorpej }
652 1.2 thorpej
653 1.2 thorpej /* Not used by anyone else; unmap the CCR. */
654 1.2 thorpej if (tmp == NULL) {
655 1.2 thorpej pcmcia_mem_unmap(pf, pf->pf_ccr_window);
656 1.2 thorpej pcmcia_mem_free(pf, &pf->pf_pcmh);
657 1.2 thorpej }
658 1.2 thorpej
659 1.36 briggs out:
660 1.2 thorpej /*
661 1.2 thorpej * Decrement the reference count, and power down the socket, if
662 1.2 thorpej * necessary.
663 1.2 thorpej */
664 1.87 drochner pcmcia_socket_disable(sc->dev);
665 1.2 thorpej }
666 1.2 thorpej
667 1.2 thorpej int
668 1.88 dsl pcmcia_io_map(struct pcmcia_function *pf, int width, struct pcmcia_io_handle *pcihp, int *windowp)
669 1.2 thorpej {
670 1.68 mycroft struct pcmcia_softc *sc = pf->sc;
671 1.49 mycroft int error;
672 1.2 thorpej
673 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
674 1.51 mycroft printf("pcmcia_io_map: function is enabled!\n");
675 1.49 mycroft
676 1.68 mycroft error = pcmcia_chip_io_map(sc->pct, sc->pch,
677 1.49 mycroft width, 0, pcihp->size, pcihp, windowp);
678 1.49 mycroft if (error)
679 1.49 mycroft return (error);
680 1.2 thorpej
681 1.2 thorpej /*
682 1.2 thorpej * XXX in the multifunction multi-iospace-per-function case, this
683 1.2 thorpej * needs to cooperate with io_alloc to make sure that the spaces
684 1.2 thorpej * don't overlap, and that the ccr's are set correctly
685 1.2 thorpej */
686 1.2 thorpej
687 1.68 mycroft if (pcmcia_mfc(sc) || 1) {
688 1.65 mycroft bus_addr_t iobase = pcihp->addr;
689 1.65 mycroft bus_addr_t iomax = pcihp->addr + pcihp->size - 1;
690 1.5 marc
691 1.65 mycroft DPRINTF(("window iobase %lx iomax %lx\n", (long)iobase,
692 1.65 mycroft (long)iomax));
693 1.65 mycroft if (pf->pf_mfc_iobase == 0) {
694 1.65 mycroft pf->pf_mfc_iobase = iobase;
695 1.65 mycroft pf->pf_mfc_iomax = iomax;
696 1.65 mycroft } else {
697 1.65 mycroft if (iobase < pf->pf_mfc_iobase)
698 1.65 mycroft pf->pf_mfc_iobase = iobase;
699 1.65 mycroft if (iomax > pf->pf_mfc_iomax)
700 1.65 mycroft pf->pf_mfc_iomax = iomax;
701 1.65 mycroft }
702 1.65 mycroft DPRINTF(("function iobase %lx iomax %lx\n",
703 1.65 mycroft (long)pf->pf_mfc_iobase, (long)pf->pf_mfc_iomax));
704 1.2 thorpej }
705 1.41 mycroft
706 1.2 thorpej return (0);
707 1.11 thorpej }
708 1.11 thorpej
709 1.11 thorpej void
710 1.88 dsl pcmcia_io_unmap(struct pcmcia_function *pf, int window)
711 1.11 thorpej {
712 1.68 mycroft struct pcmcia_softc *sc = pf->sc;
713 1.11 thorpej
714 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
715 1.51 mycroft printf("pcmcia_io_unmap: function is enabled!\n");
716 1.49 mycroft
717 1.68 mycroft pcmcia_chip_io_unmap(sc->pct, sc->pch, window);
718 1.2 thorpej }
719 1.2 thorpej
720 1.2 thorpej void *
721 1.90 cegger pcmcia_intr_establish(struct pcmcia_function *pf, int ipl,
722 1.90 cegger int (*ih_fct)(void *), void *ih_arg)
723 1.2 thorpej {
724 1.2 thorpej
725 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
726 1.51 mycroft printf("pcmcia_intr_establish: function is enabled!\n");
727 1.52 mycroft if (pf->pf_ih)
728 1.52 mycroft panic("pcmcia_intr_establish: already done\n");
729 1.49 mycroft
730 1.52 mycroft pf->pf_ih = pcmcia_chip_intr_establish(pf->sc->pct, pf->sc->pch,
731 1.52 mycroft pf, ipl, ih_fct, ih_arg);
732 1.55 mycroft if (!pf->pf_ih)
733 1.86 cegger aprint_error_dev(pf->child, "interrupt establish failed\n");
734 1.52 mycroft return (pf->pf_ih);
735 1.2 thorpej }
736 1.2 thorpej
737 1.2 thorpej void
738 1.88 dsl pcmcia_intr_disestablish(struct pcmcia_function *pf, void *ih)
739 1.2 thorpej {
740 1.52 mycroft
741 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
742 1.51 mycroft printf("pcmcia_intr_disestablish: function is enabled!\n");
743 1.52 mycroft if (!pf->pf_ih)
744 1.52 mycroft panic("pcmcia_intr_distestablish: already done\n");
745 1.49 mycroft
746 1.52 mycroft pcmcia_chip_intr_disestablish(pf->sc->pct, pf->sc->pch, ih);
747 1.52 mycroft pf->pf_ih = 0;
748 1.2 thorpej }
749 1.53 mycroft
750 1.53 mycroft int
751 1.88 dsl pcmcia_config_alloc(struct pcmcia_function *pf, struct pcmcia_config_entry *cfe)
752 1.53 mycroft {
753 1.61 mycroft int error = 0;
754 1.53 mycroft int n, m;
755 1.53 mycroft
756 1.53 mycroft for (n = 0; n < cfe->num_iospace; n++) {
757 1.53 mycroft bus_addr_t start = cfe->iospace[n].start;
758 1.53 mycroft bus_size_t length = cfe->iospace[n].length;
759 1.53 mycroft bus_size_t align = cfe->iomask ? (1 << cfe->iomask) :
760 1.53 mycroft length;
761 1.53 mycroft bus_size_t skew = start & (align - 1);
762 1.53 mycroft
763 1.54 mycroft if ((start - skew) == 0 && align < 0x400) {
764 1.54 mycroft if (skew)
765 1.54 mycroft printf("Drats! I need a skew!\n");
766 1.53 mycroft start = 0;
767 1.54 mycroft }
768 1.53 mycroft
769 1.53 mycroft DPRINTF(("pcmcia_config_alloc: io %d start=%lx length=%lx align=%lx skew=%lx\n",
770 1.53 mycroft n, (long)start, (long)length, (long)align, (long)skew));
771 1.53 mycroft
772 1.53 mycroft error = pcmcia_io_alloc(pf, start, length, align,
773 1.53 mycroft &cfe->iospace[n].handle);
774 1.53 mycroft if (error)
775 1.53 mycroft break;
776 1.53 mycroft }
777 1.53 mycroft if (n < cfe->num_iospace) {
778 1.53 mycroft for (m = 0; m < n; m++)
779 1.53 mycroft pcmcia_io_free(pf, &cfe->iospace[m].handle);
780 1.53 mycroft return (error);
781 1.53 mycroft }
782 1.53 mycroft
783 1.53 mycroft for (n = 0; n < cfe->num_memspace; n++) {
784 1.53 mycroft bus_size_t length = cfe->memspace[n].length;
785 1.53 mycroft
786 1.53 mycroft DPRINTF(("pcmcia_config_alloc: mem %d length %lx\n", n,
787 1.53 mycroft (long)length));
788 1.53 mycroft
789 1.53 mycroft error = pcmcia_mem_alloc(pf, length, &cfe->memspace[n].handle);
790 1.53 mycroft if (error)
791 1.53 mycroft break;
792 1.53 mycroft }
793 1.53 mycroft if (n < cfe->num_memspace) {
794 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
795 1.53 mycroft pcmcia_io_free(pf, &cfe->iospace[m].handle);
796 1.53 mycroft for (m = 0; m < n; m++)
797 1.53 mycroft pcmcia_mem_free(pf, &cfe->memspace[m].handle);
798 1.53 mycroft return (error);
799 1.53 mycroft }
800 1.53 mycroft
801 1.53 mycroft /* This one's good! */
802 1.61 mycroft return (error);
803 1.53 mycroft }
804 1.53 mycroft
805 1.53 mycroft void
806 1.88 dsl pcmcia_config_free(struct pcmcia_function *pf)
807 1.53 mycroft {
808 1.53 mycroft struct pcmcia_config_entry *cfe = pf->cfe;
809 1.53 mycroft int m;
810 1.53 mycroft
811 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
812 1.53 mycroft pcmcia_io_free(pf, &cfe->iospace[m].handle);
813 1.53 mycroft for (m = 0; m < cfe->num_memspace; m++)
814 1.53 mycroft pcmcia_mem_free(pf, &cfe->memspace[m].handle);
815 1.53 mycroft }
816 1.53 mycroft
817 1.53 mycroft int
818 1.88 dsl pcmcia_config_map(struct pcmcia_function *pf)
819 1.53 mycroft {
820 1.53 mycroft struct pcmcia_config_entry *cfe = pf->cfe;
821 1.61 mycroft int error = 0;
822 1.53 mycroft int n, m;
823 1.53 mycroft
824 1.53 mycroft for (n = 0; n < cfe->num_iospace; n++) {
825 1.53 mycroft int width;
826 1.53 mycroft
827 1.62 mycroft if (cfe->flags & PCMCIA_CFE_IO16)
828 1.62 mycroft width = PCMCIA_WIDTH_AUTO;
829 1.62 mycroft else
830 1.53 mycroft width = PCMCIA_WIDTH_IO8;
831 1.53 mycroft error = pcmcia_io_map(pf, width, &cfe->iospace[n].handle,
832 1.53 mycroft &cfe->iospace[n].window);
833 1.53 mycroft if (error)
834 1.53 mycroft break;
835 1.53 mycroft }
836 1.53 mycroft if (n < cfe->num_iospace) {
837 1.53 mycroft for (m = 0; m < n; m++)
838 1.53 mycroft pcmcia_io_unmap(pf, cfe->iospace[m].window);
839 1.53 mycroft return (error);
840 1.53 mycroft }
841 1.53 mycroft
842 1.53 mycroft for (n = 0; n < cfe->num_memspace; n++) {
843 1.53 mycroft bus_size_t length = cfe->memspace[n].length;
844 1.53 mycroft int width;
845 1.53 mycroft
846 1.53 mycroft DPRINTF(("pcmcia_config_alloc: mem %d length %lx\n", n,
847 1.53 mycroft (long)length));
848 1.53 mycroft
849 1.53 mycroft /*XXX*/
850 1.53 mycroft width = PCMCIA_WIDTH_MEM8|PCMCIA_MEM_COMMON;
851 1.53 mycroft error = pcmcia_mem_map(pf, width, 0, length,
852 1.53 mycroft &cfe->memspace[n].handle, &cfe->memspace[n].offset,
853 1.53 mycroft &cfe->memspace[n].window);
854 1.53 mycroft if (error)
855 1.53 mycroft break;
856 1.53 mycroft }
857 1.53 mycroft if (n < cfe->num_memspace) {
858 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
859 1.53 mycroft pcmcia_io_unmap(pf, cfe->iospace[m].window);
860 1.53 mycroft for (m = 0; m < n; m++)
861 1.53 mycroft pcmcia_mem_unmap(pf, cfe->memspace[m].window);
862 1.53 mycroft return (error);
863 1.53 mycroft }
864 1.53 mycroft
865 1.53 mycroft /* This one's good! */
866 1.61 mycroft return (error);
867 1.53 mycroft }
868 1.53 mycroft
869 1.53 mycroft void
870 1.88 dsl pcmcia_config_unmap(struct pcmcia_function *pf)
871 1.53 mycroft {
872 1.53 mycroft struct pcmcia_config_entry *cfe = pf->cfe;
873 1.53 mycroft int m;
874 1.53 mycroft
875 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
876 1.53 mycroft pcmcia_io_unmap(pf, cfe->iospace[m].window);
877 1.53 mycroft for (m = 0; m < cfe->num_memspace; m++)
878 1.53 mycroft pcmcia_mem_unmap(pf, cfe->memspace[m].window);
879 1.53 mycroft }
880 1.53 mycroft
881 1.53 mycroft int
882 1.90 cegger pcmcia_function_configure(struct pcmcia_function *pf,
883 1.90 cegger int (*validator)(struct pcmcia_config_entry *))
884 1.53 mycroft {
885 1.53 mycroft struct pcmcia_config_entry *cfe;
886 1.53 mycroft int error = ENOENT;
887 1.53 mycroft
888 1.53 mycroft SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
889 1.53 mycroft error = validator(cfe);
890 1.53 mycroft if (error)
891 1.53 mycroft continue;
892 1.53 mycroft error = pcmcia_config_alloc(pf, cfe);
893 1.53 mycroft if (!error)
894 1.53 mycroft break;
895 1.53 mycroft }
896 1.53 mycroft if (!cfe) {
897 1.53 mycroft DPRINTF(("pcmcia_function_configure: no config entry found, error=%d\n",
898 1.53 mycroft error));
899 1.53 mycroft return (error);
900 1.53 mycroft }
901 1.53 mycroft
902 1.53 mycroft /* Remember which configuration entry we are using. */
903 1.53 mycroft pf->cfe = cfe;
904 1.53 mycroft
905 1.53 mycroft error = pcmcia_config_map(pf);
906 1.53 mycroft if (error) {
907 1.53 mycroft DPRINTF(("pcmcia_function_configure: map failed, error=%d\n",
908 1.53 mycroft error));
909 1.53 mycroft return (error);
910 1.53 mycroft }
911 1.53 mycroft
912 1.53 mycroft return (0);
913 1.53 mycroft }
914 1.53 mycroft
915 1.53 mycroft void
916 1.88 dsl pcmcia_function_unconfigure(struct pcmcia_function *pf)
917 1.53 mycroft {
918 1.53 mycroft
919 1.53 mycroft pcmcia_config_unmap(pf);
920 1.53 mycroft pcmcia_config_free(pf);
921 1.53 mycroft }
922