pcmcia.c revision 1.54 1 1.54 mycroft /* $NetBSD: pcmcia.c,v 1.54 2004/08/10 05:21:59 mycroft 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.54 mycroft __KERNEL_RCSID(0, "$NetBSD: pcmcia.c,v 1.54 2004/08/10 05:21:59 mycroft 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.2 thorpej #include <dev/pcmcia/pcmciareg.h>
60 1.2 thorpej #include <dev/pcmcia/pcmciachip.h>
61 1.2 thorpej #include <dev/pcmcia/pcmciavar.h>
62 1.21 uch #ifdef IT8368E_LEGACY_MODE /* XXX -uch */
63 1.21 uch #include <arch/hpcmips/dev/it8368var.h>
64 1.21 uch #endif
65 1.2 thorpej
66 1.3 enami #include "locators.h"
67 1.3 enami
68 1.2 thorpej #ifdef PCMCIADEBUG
69 1.2 thorpej int pcmcia_debug = 0;
70 1.2 thorpej #define DPRINTF(arg) if (pcmcia_debug) printf arg
71 1.2 thorpej #else
72 1.2 thorpej #define DPRINTF(arg)
73 1.2 thorpej #endif
74 1.2 thorpej
75 1.2 thorpej #ifdef PCMCIAVERBOSE
76 1.2 thorpej int pcmcia_verbose = 1;
77 1.2 thorpej #else
78 1.2 thorpej int pcmcia_verbose = 0;
79 1.2 thorpej #endif
80 1.2 thorpej
81 1.2 thorpej int pcmcia_match __P((struct device *, struct cfdata *, void *));
82 1.2 thorpej int pcmcia_submatch __P((struct device *, struct cfdata *, void *));
83 1.2 thorpej void pcmcia_attach __P((struct device *, struct device *, void *));
84 1.2 thorpej int pcmcia_print __P((void *, const char *));
85 1.2 thorpej
86 1.33 thorpej CFATTACH_DECL(pcmcia, sizeof(struct pcmcia_softc),
87 1.34 thorpej pcmcia_match, pcmcia_attach, NULL, NULL);
88 1.2 thorpej
89 1.2 thorpej int
90 1.2 thorpej pcmcia_ccr_read(pf, ccr)
91 1.2 thorpej struct pcmcia_function *pf;
92 1.2 thorpej int ccr;
93 1.2 thorpej {
94 1.2 thorpej
95 1.2 thorpej return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh,
96 1.43 mycroft pf->pf_ccr_offset + ccr * 2));
97 1.2 thorpej }
98 1.2 thorpej
99 1.2 thorpej void
100 1.2 thorpej pcmcia_ccr_write(pf, ccr, val)
101 1.2 thorpej struct pcmcia_function *pf;
102 1.2 thorpej int ccr;
103 1.2 thorpej 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.2 thorpej pcmcia_match(parent, match, aux)
114 1.2 thorpej struct device *parent;
115 1.2 thorpej struct cfdata *match;
116 1.2 thorpej void *aux;
117 1.2 thorpej {
118 1.14 haya struct pcmciabus_attach_args *paa = aux;
119 1.14 haya
120 1.30 thorpej if (strcmp(paa->paa_busname, match->cf_name)) {
121 1.14 haya return 0;
122 1.14 haya }
123 1.2 thorpej /* if the autoconfiguration got this far, there's a socket here */
124 1.2 thorpej return (1);
125 1.2 thorpej }
126 1.2 thorpej
127 1.2 thorpej void
128 1.2 thorpej pcmcia_attach(parent, self, aux)
129 1.2 thorpej struct device *parent, *self;
130 1.2 thorpej void *aux;
131 1.2 thorpej {
132 1.2 thorpej struct pcmciabus_attach_args *paa = aux;
133 1.2 thorpej struct pcmcia_softc *sc = (struct pcmcia_softc *) self;
134 1.2 thorpej
135 1.2 thorpej printf("\n");
136 1.2 thorpej
137 1.2 thorpej sc->pct = paa->pct;
138 1.2 thorpej sc->pch = paa->pch;
139 1.2 thorpej sc->iobase = paa->iobase;
140 1.2 thorpej sc->iosize = paa->iosize;
141 1.2 thorpej
142 1.2 thorpej sc->ih = NULL;
143 1.2 thorpej }
144 1.2 thorpej
145 1.2 thorpej int
146 1.2 thorpej pcmcia_card_attach(dev)
147 1.2 thorpej struct device *dev;
148 1.2 thorpej {
149 1.2 thorpej struct pcmcia_softc *sc = (struct pcmcia_softc *) dev;
150 1.2 thorpej struct pcmcia_function *pf;
151 1.2 thorpej struct pcmcia_attach_args paa;
152 1.2 thorpej int attached;
153 1.2 thorpej
154 1.2 thorpej /*
155 1.2 thorpej * this is here so that when socket_enable calls gettype, trt happens
156 1.2 thorpej */
157 1.29 lukem SIMPLEQ_FIRST(&sc->card.pf_head) = NULL;
158 1.2 thorpej
159 1.2 thorpej pcmcia_chip_socket_enable(sc->pct, sc->pch);
160 1.2 thorpej
161 1.2 thorpej pcmcia_read_cis(sc);
162 1.2 thorpej
163 1.2 thorpej pcmcia_chip_socket_disable(sc->pct, sc->pch);
164 1.13 marc
165 1.13 marc pcmcia_check_cis_quirks(sc);
166 1.2 thorpej
167 1.2 thorpej /*
168 1.2 thorpej * bail now if the card has no functions, or if there was an error in
169 1.2 thorpej * the cis.
170 1.2 thorpej */
171 1.2 thorpej
172 1.2 thorpej if (sc->card.error)
173 1.2 thorpej return (1);
174 1.29 lukem if (SIMPLEQ_EMPTY(&sc->card.pf_head))
175 1.2 thorpej return (1);
176 1.2 thorpej
177 1.2 thorpej if (pcmcia_verbose)
178 1.2 thorpej pcmcia_print_cis(sc);
179 1.2 thorpej
180 1.2 thorpej attached = 0;
181 1.2 thorpej
182 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
183 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
184 1.2 thorpej continue;
185 1.2 thorpej
186 1.11 thorpej #ifdef DIAGNOSTIC
187 1.11 thorpej if (pf->child != NULL) {
188 1.11 thorpej printf("%s: %s still attached to function %d!\n",
189 1.11 thorpej sc->dev.dv_xname, pf->child->dv_xname,
190 1.11 thorpej pf->number);
191 1.11 thorpej panic("pcmcia_card_attach");
192 1.11 thorpej }
193 1.11 thorpej #endif
194 1.2 thorpej pf->sc = sc;
195 1.11 thorpej pf->child = NULL;
196 1.2 thorpej pf->cfe = NULL;
197 1.52 mycroft pf->pf_ih = NULL;
198 1.2 thorpej }
199 1.2 thorpej
200 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
201 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
202 1.2 thorpej continue;
203 1.2 thorpej
204 1.2 thorpej paa.manufacturer = sc->card.manufacturer;
205 1.2 thorpej paa.product = sc->card.product;
206 1.2 thorpej paa.card = &sc->card;
207 1.2 thorpej paa.pf = pf;
208 1.2 thorpej
209 1.11 thorpej if ((pf->child = config_found_sm(&sc->dev, &paa, pcmcia_print,
210 1.20 chopps pcmcia_submatch)) != NULL)
211 1.2 thorpej attached++;
212 1.2 thorpej }
213 1.2 thorpej
214 1.2 thorpej return (attached ? 0 : 1);
215 1.2 thorpej }
216 1.2 thorpej
217 1.2 thorpej void
218 1.11 thorpej pcmcia_card_detach(dev, flags)
219 1.2 thorpej struct device *dev;
220 1.11 thorpej int flags; /* DETACH_* flags */
221 1.2 thorpej {
222 1.10 thorpej struct pcmcia_softc *sc = (struct pcmcia_softc *) dev;
223 1.11 thorpej struct pcmcia_function *pf;
224 1.11 thorpej int error;
225 1.10 thorpej
226 1.11 thorpej /*
227 1.11 thorpej * We are running on either the PCMCIA socket's event thread
228 1.11 thorpej * or in user context detaching a device by user request.
229 1.10 thorpej */
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.11 thorpej continue;
233 1.11 thorpej if (pf->child == NULL)
234 1.11 thorpej continue;
235 1.11 thorpej DPRINTF(("%s: detaching %s (function %d)\n",
236 1.11 thorpej sc->dev.dv_xname, pf->child->dv_xname, pf->number));
237 1.11 thorpej if ((error = config_detach(pf->child, flags)) != 0) {
238 1.11 thorpej printf("%s: error %d detaching %s (function %d)\n",
239 1.11 thorpej sc->dev.dv_xname, error, pf->child->dv_xname,
240 1.11 thorpej pf->number);
241 1.11 thorpej } else
242 1.11 thorpej pf->child = NULL;
243 1.11 thorpej }
244 1.53 mycroft
245 1.53 mycroft if (sc->sc_enabled_count != 0) {
246 1.53 mycroft #ifdef DIAGNOSTIC
247 1.53 mycroft printf("pcmcia_card_detach: enabled_count should be 0 here??\n");
248 1.53 mycroft #endif
249 1.53 mycroft pcmcia_chip_socket_disable(sc->pct, sc->pch);
250 1.53 mycroft sc->sc_enabled_count = 0;
251 1.53 mycroft }
252 1.11 thorpej }
253 1.11 thorpej
254 1.11 thorpej void
255 1.11 thorpej pcmcia_card_deactivate(dev)
256 1.11 thorpej struct device *dev;
257 1.11 thorpej {
258 1.11 thorpej struct pcmcia_softc *sc = (struct pcmcia_softc *) dev;
259 1.11 thorpej struct pcmcia_function *pf;
260 1.10 thorpej
261 1.11 thorpej /*
262 1.11 thorpej * We're in the chip's card removal interrupt handler.
263 1.11 thorpej * Deactivate the child driver. The PCMCIA socket's
264 1.11 thorpej * event thread will run later to finish the detach.
265 1.11 thorpej */
266 1.29 lukem SIMPLEQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
267 1.29 lukem if (SIMPLEQ_EMPTY(&pf->cfe_head))
268 1.11 thorpej continue;
269 1.11 thorpej if (pf->child == NULL)
270 1.11 thorpej continue;
271 1.11 thorpej DPRINTF(("%s: deactivating %s (function %d)\n",
272 1.11 thorpej sc->dev.dv_xname, pf->child->dv_xname, pf->number));
273 1.11 thorpej config_deactivate(pf->child);
274 1.11 thorpej }
275 1.2 thorpej }
276 1.2 thorpej
277 1.2 thorpej int
278 1.2 thorpej pcmcia_submatch(parent, cf, aux)
279 1.2 thorpej struct device *parent;
280 1.2 thorpej struct cfdata *cf;
281 1.2 thorpej void *aux;
282 1.2 thorpej {
283 1.2 thorpej struct pcmcia_attach_args *paa = aux;
284 1.2 thorpej
285 1.3 enami if (cf->cf_loc[PCMCIACF_FUNCTION] != PCMCIACF_FUNCTION_DEFAULT &&
286 1.3 enami cf->cf_loc[PCMCIACF_FUNCTION] != paa->pf->number)
287 1.2 thorpej return (0);
288 1.2 thorpej
289 1.31 thorpej return (config_match(parent, cf, aux));
290 1.2 thorpej }
291 1.2 thorpej
292 1.2 thorpej int
293 1.2 thorpej pcmcia_print(arg, pnp)
294 1.2 thorpej void *arg;
295 1.2 thorpej const char *pnp;
296 1.2 thorpej {
297 1.2 thorpej struct pcmcia_attach_args *pa = arg;
298 1.2 thorpej struct pcmcia_softc *sc = pa->pf->sc;
299 1.2 thorpej struct pcmcia_card *card = &sc->card;
300 1.18 augustss char devinfo[256];
301 1.2 thorpej
302 1.38 mycroft if (pnp)
303 1.38 mycroft aprint_normal("%s", pnp);
304 1.38 mycroft
305 1.38 mycroft pcmcia_devinfo(card, !!pnp, devinfo, sizeof(devinfo));
306 1.38 mycroft
307 1.38 mycroft aprint_normal(" function %d: %s", pa->pf->number, devinfo);
308 1.2 thorpej
309 1.2 thorpej return (UNCONF);
310 1.18 augustss }
311 1.18 augustss
312 1.18 augustss void
313 1.18 augustss pcmcia_devinfo(card, showhex, cp, cplen)
314 1.18 augustss struct pcmcia_card *card;
315 1.19 enami int showhex;
316 1.18 augustss char *cp;
317 1.38 mycroft size_t cplen;
318 1.18 augustss {
319 1.18 augustss int i, n;
320 1.18 augustss
321 1.37 mycroft if (cplen > 1) {
322 1.37 mycroft *cp++ = '<';
323 1.38 mycroft *cp = '\0';
324 1.37 mycroft cplen--;
325 1.37 mycroft }
326 1.37 mycroft
327 1.37 mycroft for (i = 0; i < 4 && card->cis1_info[i] != NULL && cplen > 1; i++) {
328 1.39 mycroft n = snprintf(cp, cplen, "%s%s", i ? ", " : "",
329 1.18 augustss card->cis1_info[i]);
330 1.18 augustss cp += n;
331 1.38 mycroft if (cplen < n)
332 1.38 mycroft return;
333 1.18 augustss cplen -= n;
334 1.18 augustss }
335 1.37 mycroft
336 1.37 mycroft if (cplen > 1) {
337 1.37 mycroft *cp++ = '>';
338 1.38 mycroft *cp = '\0';
339 1.37 mycroft cplen--;
340 1.37 mycroft }
341 1.37 mycroft
342 1.37 mycroft if (showhex && cplen > 1)
343 1.37 mycroft snprintf(cp, cplen, " (manufacturer 0x%04x, product 0x%04x)",
344 1.37 mycroft card->manufacturer, card->product);
345 1.16 cgd }
346 1.16 cgd
347 1.16 cgd const struct pcmcia_product *
348 1.16 cgd pcmcia_product_lookup(pa, tab, ent_size, matchfn)
349 1.16 cgd struct pcmcia_attach_args *pa;
350 1.16 cgd const struct pcmcia_product *tab;
351 1.16 cgd size_t ent_size;
352 1.16 cgd pcmcia_product_match_fn matchfn;
353 1.16 cgd {
354 1.16 cgd const struct pcmcia_product *ent;
355 1.16 cgd int matches;
356 1.16 cgd
357 1.16 cgd #ifdef DIAGNOSTIC
358 1.16 cgd if (sizeof *ent > ent_size)
359 1.17 nathanw panic("pcmcia_product_lookup: bogus ent_size %ld",
360 1.17 nathanw (long) ent_size);
361 1.16 cgd #endif
362 1.16 cgd
363 1.16 cgd for (ent = tab;
364 1.16 cgd ent->pp_name != NULL;
365 1.16 cgd ent = (const struct pcmcia_product *)
366 1.16 cgd ((const char *)ent + ent_size)) {
367 1.16 cgd
368 1.16 cgd /* see if it matches vendor/product/function */
369 1.16 cgd matches = (pa->manufacturer == ent->pp_vendor) &&
370 1.16 cgd (pa->product == ent->pp_product) &&
371 1.16 cgd (pa->pf->number == ent->pp_expfunc);
372 1.16 cgd
373 1.16 cgd /* if a separate match function is given, let it override */
374 1.16 cgd if (matchfn != NULL)
375 1.16 cgd matches = (*matchfn)(pa, ent, matches);
376 1.16 cgd
377 1.16 cgd if (matches)
378 1.16 cgd return (ent);
379 1.16 cgd }
380 1.16 cgd return (NULL);
381 1.2 thorpej }
382 1.2 thorpej
383 1.2 thorpej int
384 1.2 thorpej pcmcia_card_gettype(dev)
385 1.2 thorpej struct device *dev;
386 1.2 thorpej {
387 1.7 enami struct pcmcia_softc *sc = (struct pcmcia_softc *)dev;
388 1.7 enami struct pcmcia_function *pf;
389 1.2 thorpej
390 1.2 thorpej /*
391 1.2 thorpej * set the iftype to memory if this card has no functions (not yet
392 1.7 enami * probed), or only one function, and that is not initialized yet or
393 1.7 enami * that is memory.
394 1.2 thorpej */
395 1.7 enami pf = SIMPLEQ_FIRST(&sc->card.pf_head);
396 1.7 enami if (pf == NULL ||
397 1.7 enami (SIMPLEQ_NEXT(pf, pf_list) == NULL &&
398 1.7 enami (pf->cfe == NULL || pf->cfe->iftype == PCMCIA_IFTYPE_MEMORY)))
399 1.2 thorpej return (PCMCIA_IFTYPE_MEMORY);
400 1.2 thorpej else
401 1.2 thorpej return (PCMCIA_IFTYPE_IO);
402 1.2 thorpej }
403 1.2 thorpej
404 1.2 thorpej /*
405 1.2 thorpej * Initialize a PCMCIA function. May be called as long as the function is
406 1.2 thorpej * disabled.
407 1.2 thorpej */
408 1.2 thorpej void
409 1.2 thorpej pcmcia_function_init(pf, cfe)
410 1.2 thorpej struct pcmcia_function *pf;
411 1.2 thorpej struct pcmcia_config_entry *cfe;
412 1.2 thorpej {
413 1.2 thorpej if (pf->pf_flags & PFF_ENABLED)
414 1.2 thorpej panic("pcmcia_function_init: function is enabled");
415 1.2 thorpej
416 1.2 thorpej /* Remember which configuration entry we are using. */
417 1.2 thorpej pf->cfe = cfe;
418 1.2 thorpej }
419 1.2 thorpej
420 1.40 mycroft void pcmcia_socket_enable(dev)
421 1.40 mycroft struct device *dev;
422 1.5 marc {
423 1.40 mycroft struct pcmcia_softc *sc = (void *)dev;
424 1.40 mycroft
425 1.40 mycroft pcmcia_chip_socket_enable(sc->pct, sc->pch);
426 1.5 marc }
427 1.5 marc
428 1.40 mycroft void pcmcia_socket_disable(dev)
429 1.40 mycroft struct device *dev;
430 1.5 marc {
431 1.40 mycroft struct pcmcia_softc *sc = (void *)dev;
432 1.40 mycroft
433 1.40 mycroft pcmcia_chip_socket_disable(sc->pct, sc->pch);
434 1.5 marc }
435 1.5 marc
436 1.2 thorpej /* Enable a PCMCIA function */
437 1.2 thorpej int
438 1.2 thorpej pcmcia_function_enable(pf)
439 1.2 thorpej struct pcmcia_function *pf;
440 1.2 thorpej {
441 1.53 mycroft struct pcmcia_softc *sc = pf->sc;
442 1.2 thorpej struct pcmcia_function *tmp;
443 1.2 thorpej int reg;
444 1.2 thorpej
445 1.2 thorpej if (pf->cfe == NULL)
446 1.2 thorpej panic("pcmcia_function_enable: function not initialized");
447 1.2 thorpej
448 1.5 marc /*
449 1.5 marc * Increase the reference count on the socket, enabling power, if
450 1.5 marc * necessary.
451 1.5 marc */
452 1.53 mycroft if (sc->sc_enabled_count++ == 0)
453 1.53 mycroft pcmcia_chip_socket_enable(sc->pct, sc->pch);
454 1.53 mycroft DPRINTF(("%s: ++enabled_count = %d\n", sc->dev.dv_xname,
455 1.53 mycroft sc->sc_enabled_count));
456 1.5 marc
457 1.2 thorpej if (pf->pf_flags & PFF_ENABLED) {
458 1.2 thorpej /*
459 1.2 thorpej * Don't do anything if we're already enabled.
460 1.2 thorpej */
461 1.2 thorpej return (0);
462 1.2 thorpej }
463 1.2 thorpej
464 1.2 thorpej /*
465 1.2 thorpej * it's possible for different functions' CCRs to be in the same
466 1.2 thorpej * underlying page. Check for that.
467 1.2 thorpej */
468 1.2 thorpej
469 1.53 mycroft SIMPLEQ_FOREACH(tmp, &sc->card.pf_head, pf_list) {
470 1.2 thorpej if ((tmp->pf_flags & PFF_ENABLED) &&
471 1.2 thorpej (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
472 1.2 thorpej ((pf->ccr_base + PCMCIA_CCR_SIZE) <=
473 1.2 thorpej (tmp->ccr_base - tmp->pf_ccr_offset +
474 1.2 thorpej tmp->pf_ccr_realsize))) {
475 1.2 thorpej pf->pf_ccrt = tmp->pf_ccrt;
476 1.2 thorpej pf->pf_ccrh = tmp->pf_ccrh;
477 1.2 thorpej pf->pf_ccr_realsize = tmp->pf_ccr_realsize;
478 1.2 thorpej
479 1.2 thorpej /*
480 1.2 thorpej * pf->pf_ccr_offset = (tmp->pf_ccr_offset -
481 1.2 thorpej * tmp->ccr_base) + pf->ccr_base;
482 1.2 thorpej */
483 1.2 thorpej pf->pf_ccr_offset =
484 1.2 thorpej (tmp->pf_ccr_offset + pf->ccr_base) -
485 1.2 thorpej tmp->ccr_base;
486 1.2 thorpej pf->pf_ccr_window = tmp->pf_ccr_window;
487 1.2 thorpej break;
488 1.2 thorpej }
489 1.2 thorpej }
490 1.2 thorpej
491 1.2 thorpej if (tmp == NULL) {
492 1.2 thorpej if (pcmcia_mem_alloc(pf, PCMCIA_CCR_SIZE, &pf->pf_pcmh))
493 1.2 thorpej goto bad;
494 1.2 thorpej
495 1.2 thorpej if (pcmcia_mem_map(pf, PCMCIA_MEM_ATTR, pf->ccr_base,
496 1.2 thorpej PCMCIA_CCR_SIZE, &pf->pf_pcmh, &pf->pf_ccr_offset,
497 1.2 thorpej &pf->pf_ccr_window)) {
498 1.2 thorpej pcmcia_mem_free(pf, &pf->pf_pcmh);
499 1.2 thorpej goto bad;
500 1.2 thorpej }
501 1.2 thorpej }
502 1.2 thorpej
503 1.53 mycroft if (pcmcia_mfc(sc)) {
504 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE0,
505 1.41 mycroft (pf->pf_mfc_iobase[0] >> 0) & 0xff);
506 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE1,
507 1.41 mycroft (pf->pf_mfc_iobase[0] >> 8) & 0xff);
508 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE2,
509 1.41 mycroft (pf->pf_mfc_iobase[1] >> 0) & 0xff);
510 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOBASE3,
511 1.41 mycroft (pf->pf_mfc_iobase[1] >> 8) & 0xff);
512 1.41 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_IOSIZE, pf->pf_mfc_iomask);
513 1.41 mycroft }
514 1.41 mycroft
515 1.2 thorpej reg = (pf->cfe->number & PCMCIA_CCR_OPTION_CFINDEX);
516 1.2 thorpej reg |= PCMCIA_CCR_OPTION_LEVIREQ;
517 1.53 mycroft if (pcmcia_mfc(sc)) {
518 1.5 marc reg |= (PCMCIA_CCR_OPTION_FUNC_ENABLE |
519 1.5 marc PCMCIA_CCR_OPTION_ADDR_DECODE);
520 1.52 mycroft if (pf->pf_ih)
521 1.5 marc reg |= PCMCIA_CCR_OPTION_IREQ_ENABLE;
522 1.5 marc
523 1.5 marc }
524 1.2 thorpej pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
525 1.2 thorpej
526 1.2 thorpej reg = 0;
527 1.2 thorpej if ((pf->cfe->flags & PCMCIA_CFE_IO16) == 0)
528 1.2 thorpej reg |= PCMCIA_CCR_STATUS_IOIS8;
529 1.2 thorpej if (pf->cfe->flags & PCMCIA_CFE_AUDIO)
530 1.2 thorpej reg |= PCMCIA_CCR_STATUS_AUDIO;
531 1.2 thorpej pcmcia_ccr_write(pf, PCMCIA_CCR_STATUS, reg);
532 1.2 thorpej
533 1.2 thorpej pcmcia_ccr_write(pf, PCMCIA_CCR_SOCKETCOPY, 0);
534 1.2 thorpej
535 1.12 marc #ifdef PCMCIADEBUG
536 1.12 marc if (pcmcia_debug) {
537 1.53 mycroft SIMPLEQ_FOREACH(tmp, &sc->card.pf_head, pf_list) {
538 1.12 marc printf("%s: function %d CCR at %d offset %lx: "
539 1.12 marc "%x %x %x %x, %x %x %x %x, %x\n",
540 1.12 marc tmp->sc->dev.dv_xname, tmp->number,
541 1.15 aymeric tmp->pf_ccr_window,
542 1.15 aymeric (unsigned long) tmp->pf_ccr_offset,
543 1.43 mycroft pcmcia_ccr_read(tmp, 0),
544 1.43 mycroft pcmcia_ccr_read(tmp, 1),
545 1.43 mycroft pcmcia_ccr_read(tmp, 2),
546 1.43 mycroft pcmcia_ccr_read(tmp, 3),
547 1.43 mycroft
548 1.43 mycroft pcmcia_ccr_read(tmp, 5),
549 1.43 mycroft pcmcia_ccr_read(tmp, 6),
550 1.43 mycroft pcmcia_ccr_read(tmp, 7),
551 1.43 mycroft pcmcia_ccr_read(tmp, 8),
552 1.5 marc
553 1.43 mycroft pcmcia_ccr_read(tmp, 9));
554 1.12 marc }
555 1.12 marc }
556 1.12 marc #endif
557 1.5 marc
558 1.2 thorpej pf->pf_flags |= PFF_ENABLED;
559 1.21 uch
560 1.21 uch #ifdef IT8368E_LEGACY_MODE
561 1.21 uch /* return to I/O mode */
562 1.21 uch it8368_mode(pf, IT8368_IO_MODE, IT8368_WIDTH_16);
563 1.21 uch #endif
564 1.2 thorpej return (0);
565 1.2 thorpej
566 1.2 thorpej bad:
567 1.2 thorpej /*
568 1.2 thorpej * Decrement the reference count, and power down the socket, if
569 1.2 thorpej * necessary.
570 1.2 thorpej */
571 1.53 mycroft if (--sc->sc_enabled_count == 0)
572 1.53 mycroft pcmcia_chip_socket_disable(sc->pct, sc->pch);
573 1.53 mycroft DPRINTF(("%s: --enabled_count = %d\n", sc->dev.dv_xname,
574 1.53 mycroft sc->sc_enabled_count));
575 1.5 marc
576 1.2 thorpej return (1);
577 1.2 thorpej }
578 1.2 thorpej
579 1.2 thorpej /* Disable PCMCIA function. */
580 1.2 thorpej void
581 1.2 thorpej pcmcia_function_disable(pf)
582 1.2 thorpej struct pcmcia_function *pf;
583 1.2 thorpej {
584 1.2 thorpej struct pcmcia_function *tmp;
585 1.48 mycroft int reg;
586 1.2 thorpej
587 1.2 thorpej if (pf->cfe == NULL)
588 1.2 thorpej panic("pcmcia_function_enable: function not initialized");
589 1.2 thorpej
590 1.2 thorpej if ((pf->pf_flags & PFF_ENABLED) == 0) {
591 1.2 thorpej /*
592 1.36 briggs * Don't do anything but decrement if we're already disabled.
593 1.2 thorpej */
594 1.36 briggs goto out;
595 1.2 thorpej }
596 1.2 thorpej
597 1.48 mycroft if (pcmcia_mfc(pf->sc)) {
598 1.48 mycroft reg = pcmcia_ccr_read(pf, PCMCIA_CCR_OPTION);
599 1.48 mycroft reg &= ~(PCMCIA_CCR_OPTION_FUNC_ENABLE|
600 1.48 mycroft PCMCIA_CCR_OPTION_ADDR_DECODE|
601 1.48 mycroft PCMCIA_CCR_OPTION_IREQ_ENABLE);
602 1.48 mycroft pcmcia_ccr_write(pf, PCMCIA_CCR_OPTION, reg);
603 1.48 mycroft }
604 1.48 mycroft
605 1.2 thorpej /*
606 1.2 thorpej * it's possible for different functions' CCRs to be in the same
607 1.2 thorpej * underlying page. Check for that. Note we mark us as disabled
608 1.2 thorpej * first to avoid matching ourself.
609 1.2 thorpej */
610 1.2 thorpej
611 1.2 thorpej pf->pf_flags &= ~PFF_ENABLED;
612 1.29 lukem SIMPLEQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
613 1.2 thorpej if ((tmp->pf_flags & PFF_ENABLED) &&
614 1.2 thorpej (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
615 1.2 thorpej ((pf->ccr_base + PCMCIA_CCR_SIZE) <=
616 1.2 thorpej (tmp->ccr_base - tmp->pf_ccr_offset + tmp->pf_ccr_realsize)))
617 1.2 thorpej break;
618 1.2 thorpej }
619 1.2 thorpej
620 1.2 thorpej /* Not used by anyone else; unmap the CCR. */
621 1.2 thorpej if (tmp == NULL) {
622 1.2 thorpej pcmcia_mem_unmap(pf, pf->pf_ccr_window);
623 1.2 thorpej pcmcia_mem_free(pf, &pf->pf_pcmh);
624 1.2 thorpej }
625 1.2 thorpej
626 1.36 briggs out:
627 1.2 thorpej /*
628 1.2 thorpej * Decrement the reference count, and power down the socket, if
629 1.2 thorpej * necessary.
630 1.2 thorpej */
631 1.2 thorpej if (--pf->sc->sc_enabled_count == 0)
632 1.2 thorpej pcmcia_chip_socket_disable(pf->sc->pct, pf->sc->pch);
633 1.5 marc DPRINTF(("%s: --enabled_count = %d\n", pf->sc->dev.dv_xname,
634 1.5 marc pf->sc->sc_enabled_count));
635 1.2 thorpej }
636 1.2 thorpej
637 1.2 thorpej int
638 1.41 mycroft pcmcia_io_map(pf, width, pcihp, windowp)
639 1.2 thorpej struct pcmcia_function *pf;
640 1.2 thorpej int width;
641 1.2 thorpej struct pcmcia_io_handle *pcihp;
642 1.2 thorpej int *windowp;
643 1.2 thorpej {
644 1.49 mycroft int error;
645 1.2 thorpej
646 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
647 1.51 mycroft printf("pcmcia_io_map: function is enabled!\n");
648 1.49 mycroft
649 1.49 mycroft error = pcmcia_chip_io_map(pf->sc->pct, pf->sc->pch,
650 1.49 mycroft width, 0, pcihp->size, pcihp, windowp);
651 1.49 mycroft if (error)
652 1.49 mycroft return (error);
653 1.2 thorpej
654 1.2 thorpej /*
655 1.2 thorpej * XXX in the multifunction multi-iospace-per-function case, this
656 1.2 thorpej * needs to cooperate with io_alloc to make sure that the spaces
657 1.2 thorpej * don't overlap, and that the ccr's are set correctly
658 1.2 thorpej */
659 1.2 thorpej
660 1.2 thorpej if (pcmcia_mfc(pf->sc)) {
661 1.41 mycroft int win;
662 1.41 mycroft long iomask;
663 1.5 marc
664 1.5 marc /* round up to nearest (2^n)-1 */
665 1.41 mycroft for (iomask = 1; iomask < pcihp->size; iomask <<= 1)
666 1.5 marc ;
667 1.41 mycroft iomask--;
668 1.5 marc
669 1.41 mycroft win = pf->pf_mfc_windows;
670 1.41 mycroft KASSERT(win < 2);
671 1.41 mycroft printf("win %d = addr %lx size %lx iomask %lx\n", win, (long)pcihp->addr, (long)pcihp->size, (long)iomask);
672 1.41 mycroft pf->pf_mfc_iobase[win] = pcihp->addr;
673 1.41 mycroft pf->pf_mfc_iomask = iomask;
674 1.2 thorpej }
675 1.41 mycroft
676 1.2 thorpej return (0);
677 1.11 thorpej }
678 1.11 thorpej
679 1.11 thorpej void
680 1.11 thorpej pcmcia_io_unmap(pf, window)
681 1.11 thorpej struct pcmcia_function *pf;
682 1.11 thorpej int window;
683 1.11 thorpej {
684 1.11 thorpej
685 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
686 1.51 mycroft printf("pcmcia_io_unmap: function is enabled!\n");
687 1.49 mycroft
688 1.41 mycroft if (pcmcia_mfc(pf->sc)) {
689 1.41 mycroft /*
690 1.41 mycroft * Don't bother trying to unmap windows in the CCR here,
691 1.41 mycroft * because we generally get called when a card has been
692 1.41 mycroft * ejected, and the CCR isn't there any more.
693 1.41 mycroft */
694 1.41 mycroft --pf->pf_mfc_windows;
695 1.41 mycroft }
696 1.41 mycroft
697 1.11 thorpej pcmcia_chip_io_unmap(pf->sc->pct, pf->sc->pch, window);
698 1.2 thorpej }
699 1.2 thorpej
700 1.2 thorpej void *
701 1.2 thorpej pcmcia_intr_establish(pf, ipl, ih_fct, ih_arg)
702 1.2 thorpej struct pcmcia_function *pf;
703 1.2 thorpej int ipl;
704 1.2 thorpej int (*ih_fct) __P((void *));
705 1.2 thorpej void *ih_arg;
706 1.2 thorpej {
707 1.2 thorpej
708 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
709 1.51 mycroft printf("pcmcia_intr_establish: function is enabled!\n");
710 1.52 mycroft if (pf->pf_ih)
711 1.52 mycroft panic("pcmcia_intr_establish: already done\n");
712 1.49 mycroft
713 1.52 mycroft pf->pf_ih = pcmcia_chip_intr_establish(pf->sc->pct, pf->sc->pch,
714 1.52 mycroft pf, ipl, ih_fct, ih_arg);
715 1.52 mycroft return (pf->pf_ih);
716 1.2 thorpej }
717 1.2 thorpej
718 1.2 thorpej void
719 1.2 thorpej pcmcia_intr_disestablish(pf, ih)
720 1.2 thorpej struct pcmcia_function *pf;
721 1.2 thorpej void *ih;
722 1.2 thorpej {
723 1.52 mycroft
724 1.49 mycroft if (pf->pf_flags & PFF_ENABLED)
725 1.51 mycroft printf("pcmcia_intr_disestablish: function is enabled!\n");
726 1.52 mycroft if (!pf->pf_ih)
727 1.52 mycroft panic("pcmcia_intr_distestablish: already done\n");
728 1.49 mycroft
729 1.52 mycroft pcmcia_chip_intr_disestablish(pf->sc->pct, pf->sc->pch, ih);
730 1.52 mycroft pf->pf_ih = 0;
731 1.2 thorpej }
732 1.53 mycroft
733 1.53 mycroft int
734 1.53 mycroft pcmcia_config_alloc(pf, cfe)
735 1.53 mycroft struct pcmcia_function *pf;
736 1.53 mycroft struct pcmcia_config_entry *cfe;
737 1.53 mycroft {
738 1.53 mycroft int error;
739 1.53 mycroft int n, m;
740 1.53 mycroft
741 1.53 mycroft for (n = 0; n < cfe->num_iospace; n++) {
742 1.53 mycroft bus_addr_t start = cfe->iospace[n].start;
743 1.53 mycroft bus_size_t length = cfe->iospace[n].length;
744 1.53 mycroft bus_size_t align = cfe->iomask ? (1 << cfe->iomask) :
745 1.53 mycroft length;
746 1.53 mycroft bus_size_t skew = start & (align - 1);
747 1.53 mycroft
748 1.54 mycroft if ((start - skew) == 0 && align < 0x400) {
749 1.54 mycroft if (skew)
750 1.54 mycroft printf("Drats! I need a skew!\n");
751 1.53 mycroft start = 0;
752 1.54 mycroft }
753 1.53 mycroft
754 1.53 mycroft DPRINTF(("pcmcia_config_alloc: io %d start=%lx length=%lx align=%lx skew=%lx\n",
755 1.53 mycroft n, (long)start, (long)length, (long)align, (long)skew));
756 1.53 mycroft
757 1.53 mycroft error = pcmcia_io_alloc(pf, start, length, align,
758 1.53 mycroft &cfe->iospace[n].handle);
759 1.53 mycroft if (error)
760 1.53 mycroft break;
761 1.53 mycroft }
762 1.53 mycroft if (n < cfe->num_iospace) {
763 1.53 mycroft for (m = 0; m < n; m++)
764 1.53 mycroft pcmcia_io_free(pf, &cfe->iospace[m].handle);
765 1.53 mycroft return (error);
766 1.53 mycroft }
767 1.53 mycroft
768 1.53 mycroft for (n = 0; n < cfe->num_memspace; n++) {
769 1.53 mycroft bus_size_t length = cfe->memspace[n].length;
770 1.53 mycroft
771 1.53 mycroft DPRINTF(("pcmcia_config_alloc: mem %d length %lx\n", n,
772 1.53 mycroft (long)length));
773 1.53 mycroft
774 1.53 mycroft error = pcmcia_mem_alloc(pf, length, &cfe->memspace[n].handle);
775 1.53 mycroft if (error)
776 1.53 mycroft break;
777 1.53 mycroft }
778 1.53 mycroft if (n < cfe->num_memspace) {
779 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
780 1.53 mycroft pcmcia_io_free(pf, &cfe->iospace[m].handle);
781 1.53 mycroft for (m = 0; m < n; m++)
782 1.53 mycroft pcmcia_mem_free(pf, &cfe->memspace[m].handle);
783 1.53 mycroft return (error);
784 1.53 mycroft }
785 1.53 mycroft
786 1.53 mycroft /* This one's good! */
787 1.53 mycroft return (0);
788 1.53 mycroft }
789 1.53 mycroft
790 1.53 mycroft void
791 1.53 mycroft pcmcia_config_free(pf)
792 1.53 mycroft struct pcmcia_function *pf;
793 1.53 mycroft {
794 1.53 mycroft struct pcmcia_config_entry *cfe = pf->cfe;
795 1.53 mycroft int m;
796 1.53 mycroft
797 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
798 1.53 mycroft pcmcia_io_free(pf, &cfe->iospace[m].handle);
799 1.53 mycroft for (m = 0; m < cfe->num_memspace; m++)
800 1.53 mycroft pcmcia_mem_free(pf, &cfe->memspace[m].handle);
801 1.53 mycroft }
802 1.53 mycroft
803 1.53 mycroft int
804 1.53 mycroft pcmcia_config_map(pf)
805 1.53 mycroft struct pcmcia_function *pf;
806 1.53 mycroft {
807 1.53 mycroft struct pcmcia_config_entry *cfe = pf->cfe;
808 1.53 mycroft int error;
809 1.53 mycroft int n, m;
810 1.53 mycroft
811 1.53 mycroft for (n = 0; n < cfe->num_iospace; n++) {
812 1.53 mycroft int width;
813 1.53 mycroft
814 1.53 mycroft switch (cfe->flags & (PCMCIA_CFE_IO8|PCMCIA_CFE_IO16)) {
815 1.53 mycroft case PCMCIA_CFE_IO8:
816 1.53 mycroft width = PCMCIA_WIDTH_IO8;
817 1.53 mycroft break;
818 1.53 mycroft case PCMCIA_CFE_IO16:
819 1.53 mycroft width = PCMCIA_WIDTH_IO16;
820 1.53 mycroft break;
821 1.53 mycroft case PCMCIA_CFE_IO8|PCMCIA_CFE_IO16:
822 1.53 mycroft default:
823 1.53 mycroft width = PCMCIA_WIDTH_AUTO;
824 1.53 mycroft break;
825 1.53 mycroft }
826 1.53 mycroft error = pcmcia_io_map(pf, width, &cfe->iospace[n].handle,
827 1.53 mycroft &cfe->iospace[n].window);
828 1.53 mycroft if (error)
829 1.53 mycroft break;
830 1.53 mycroft }
831 1.53 mycroft if (n < cfe->num_iospace) {
832 1.53 mycroft for (m = 0; m < n; m++)
833 1.53 mycroft pcmcia_io_unmap(pf, cfe->iospace[m].window);
834 1.53 mycroft return (error);
835 1.53 mycroft }
836 1.53 mycroft
837 1.53 mycroft for (n = 0; n < cfe->num_memspace; n++) {
838 1.53 mycroft bus_size_t length = cfe->memspace[n].length;
839 1.53 mycroft int width;
840 1.53 mycroft
841 1.53 mycroft DPRINTF(("pcmcia_config_alloc: mem %d length %lx\n", n,
842 1.53 mycroft (long)length));
843 1.53 mycroft
844 1.53 mycroft /*XXX*/
845 1.53 mycroft width = PCMCIA_WIDTH_MEM8|PCMCIA_MEM_COMMON;
846 1.53 mycroft error = pcmcia_mem_map(pf, width, 0, length,
847 1.53 mycroft &cfe->memspace[n].handle, &cfe->memspace[n].offset,
848 1.53 mycroft &cfe->memspace[n].window);
849 1.53 mycroft if (error)
850 1.53 mycroft break;
851 1.53 mycroft }
852 1.53 mycroft if (n < cfe->num_memspace) {
853 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
854 1.53 mycroft pcmcia_io_unmap(pf, cfe->iospace[m].window);
855 1.53 mycroft for (m = 0; m < n; m++)
856 1.53 mycroft pcmcia_mem_unmap(pf, cfe->memspace[m].window);
857 1.53 mycroft return (error);
858 1.53 mycroft }
859 1.53 mycroft
860 1.53 mycroft /* This one's good! */
861 1.53 mycroft return (0);
862 1.53 mycroft }
863 1.53 mycroft
864 1.53 mycroft void
865 1.53 mycroft pcmcia_config_unmap(pf)
866 1.53 mycroft struct pcmcia_function *pf;
867 1.53 mycroft {
868 1.53 mycroft struct pcmcia_config_entry *cfe = pf->cfe;
869 1.53 mycroft int m;
870 1.53 mycroft
871 1.53 mycroft for (m = 0; m < cfe->num_iospace; m++)
872 1.53 mycroft pcmcia_io_unmap(pf, cfe->iospace[m].window);
873 1.53 mycroft for (m = 0; m < cfe->num_memspace; m++)
874 1.53 mycroft pcmcia_mem_unmap(pf, cfe->memspace[m].window);
875 1.53 mycroft }
876 1.53 mycroft
877 1.53 mycroft int
878 1.53 mycroft pcmcia_function_configure(pf, validator)
879 1.53 mycroft struct pcmcia_function *pf;
880 1.53 mycroft int (*validator) __P((struct pcmcia_config_entry *));
881 1.53 mycroft {
882 1.53 mycroft struct pcmcia_config_entry *cfe;
883 1.53 mycroft int error = ENOENT;
884 1.53 mycroft
885 1.53 mycroft SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
886 1.53 mycroft error = validator(cfe);
887 1.53 mycroft if (error)
888 1.53 mycroft continue;
889 1.53 mycroft error = pcmcia_config_alloc(pf, cfe);
890 1.53 mycroft if (!error)
891 1.53 mycroft break;
892 1.53 mycroft }
893 1.53 mycroft if (!cfe) {
894 1.53 mycroft DPRINTF(("pcmcia_function_configure: no config entry found, error=%d\n",
895 1.53 mycroft error));
896 1.53 mycroft return (error);
897 1.53 mycroft }
898 1.53 mycroft
899 1.53 mycroft /* Remember which configuration entry we are using. */
900 1.53 mycroft pf->cfe = cfe;
901 1.53 mycroft
902 1.53 mycroft error = pcmcia_config_map(pf);
903 1.53 mycroft if (error) {
904 1.53 mycroft DPRINTF(("pcmcia_function_configure: map failed, error=%d\n",
905 1.53 mycroft error));
906 1.53 mycroft return (error);
907 1.53 mycroft }
908 1.53 mycroft
909 1.53 mycroft return (0);
910 1.53 mycroft }
911 1.53 mycroft
912 1.53 mycroft void
913 1.53 mycroft pcmcia_function_unconfigure(pf)
914 1.53 mycroft struct pcmcia_function *pf;
915 1.53 mycroft {
916 1.53 mycroft
917 1.53 mycroft pcmcia_config_unmap(pf);
918 1.53 mycroft pcmcia_config_free(pf);
919 1.53 mycroft }
920