xref: /dragonfly/sys/dev/pccard/exca/exca.c (revision 17b61719)
1 /* $FreeBSD: src/sys/dev/exca/exca.c,v 1.6 2002/10/07 06:18:50 imp Exp $ */
2 /* $DragonFly: src/sys/dev/pccard/exca/exca.c,v 1.1 2004/02/10 07:55:47 joerg Exp $ */
3 
4 /*
5  * Copyright (c) 2002 M Warner Losh.  All rights reserved.
6  *
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.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * This software may be derived from NetBSD i82365.c and other files with
28  * the following copyright:
29  *
30  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions
34  * are met:
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  * 2. Redistributions in binary form must reproduce the above copyright
38  *    notice, this list of conditions and the following disclaimer in the
39  *    documentation and/or other materials provided with the distribution.
40  * 3. All advertising materials mentioning features or use of this software
41  *    must display the following acknowledgement:
42  *	This product includes software developed by Marc Horowitz.
43  * 4. The name of the author may not be used to endorse or promote products
44  *    derived from this software without specific prior written permission.
45  *
46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  */
57 
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/errno.h>
61 #include <sys/kernel.h>
62 #include <sys/malloc.h>
63 #include <sys/queue.h>
64 #include <sys/module.h>
65 #include <sys/conf.h>
66 
67 #include <sys/bus.h>
68 #include <machine/bus.h>
69 #include <sys/rman.h>
70 #include <machine/resource.h>
71 
72 #include <bus/pccard/pccardreg.h>
73 #include <bus/pccard/pccardvar.h>
74 
75 #include <dev/pccard/exca/excareg.h>
76 #include <dev/pccard/exca/excavar.h>
77 
78 #ifdef EXCA_DEBUG
79 #define DEVPRINTF(dev, fmt, args...)	device_printf((dev), (fmt), ## args)
80 #define DPRINTF(fmt, args...)		printf(fmt, ## args)
81 #else
82 #define DEVPRINTF(dev, fmt, args...)
83 #define DPRINTF(fmt, args...)
84 #endif
85 
86 /* memory */
87 
88 #define	EXCA_MEMINFO(NUM) {						\
89 	EXCA_SYSMEM_ADDR ## NUM ## _START_LSB,				\
90 	EXCA_SYSMEM_ADDR ## NUM ## _START_MSB,				\
91 	EXCA_SYSMEM_ADDR ## NUM ## _STOP_LSB,				\
92 	EXCA_SYSMEM_ADDR ## NUM ## _STOP_MSB,				\
93 	EXCA_SYSMEM_ADDR ## NUM ## _WIN,				\
94 	EXCA_CARDMEM_ADDR ## NUM ## _LSB,				\
95 	EXCA_CARDMEM_ADDR ## NUM ## _MSB,				\
96 	EXCA_ADDRWIN_ENABLE_MEM ## NUM,					\
97 }
98 
99 static struct mem_map_index_st {
100 	int	sysmem_start_lsb;
101 	int	sysmem_start_msb;
102 	int	sysmem_stop_lsb;
103 	int	sysmem_stop_msb;
104 	int	sysmem_win;
105 	int	cardmem_lsb;
106 	int	cardmem_msb;
107 	int	memenable;
108 } mem_map_index[] = {
109 	EXCA_MEMINFO(0),
110 	EXCA_MEMINFO(1),
111 	EXCA_MEMINFO(2),
112 	EXCA_MEMINFO(3),
113 	EXCA_MEMINFO(4)
114 };
115 #undef	EXCA_MEMINFO
116 
117 /*
118  * Helper function.  This will map the requested memory slot.  We setup the
119  * map before we call this function.  This is used to initially force the
120  * mapping, as well as later restore the mapping after it has been destroyed
121  * in some fashion (due to a power event typically).
122  */
123 static void
124 exca_do_mem_map(struct exca_softc *sc, int win)
125 {
126 	struct mem_map_index_st *map;
127 	struct pccard_mem_handle *mem;
128 
129 	map = &mem_map_index[win];
130 	mem = &sc->mem[win];
131 	exca_write(sc, map->sysmem_start_lsb,
132 	    (mem->addr >> EXCA_SYSMEM_ADDRX_SHIFT) & 0xff);
133 	exca_write(sc, map->sysmem_start_msb,
134 	    ((mem->addr >> (EXCA_SYSMEM_ADDRX_SHIFT + 8)) &
135 	    EXCA_SYSMEM_ADDRX_START_MSB_ADDR_MASK) | 0x80);
136 
137 	exca_write(sc, map->sysmem_stop_lsb,
138 	    ((mem->addr + mem->realsize - 1) >>
139 	    EXCA_SYSMEM_ADDRX_SHIFT) & 0xff);
140 	exca_write(sc, map->sysmem_stop_msb,
141 	    (((mem->addr + mem->realsize - 1) >>
142 	    (EXCA_SYSMEM_ADDRX_SHIFT + 8)) &
143 	    EXCA_SYSMEM_ADDRX_STOP_MSB_ADDR_MASK) |
144 	    EXCA_SYSMEM_ADDRX_STOP_MSB_WAIT2);
145 
146 	exca_write(sc, map->sysmem_win,
147 	    (mem->addr >> EXCA_MEMREG_WIN_SHIFT) & 0xff);
148 
149 	exca_write(sc, map->cardmem_lsb,
150 	    (mem->offset >> EXCA_CARDMEM_ADDRX_SHIFT) & 0xff);
151 	exca_write(sc, map->cardmem_msb,
152 	    ((mem->offset >> (EXCA_CARDMEM_ADDRX_SHIFT + 8)) &
153 	    EXCA_CARDMEM_ADDRX_MSB_ADDR_MASK) |
154 	    ((mem->kind == PCCARD_MEM_ATTR) ?
155 	    EXCA_CARDMEM_ADDRX_MSB_REGACTIVE_ATTR : 0));
156 
157 	exca_setb(sc, EXCA_ADDRWIN_ENABLE, EXCA_ADDRWIN_ENABLE_MEMCS16 |
158 	    map->memenable);
159 
160 	DELAY(100);
161 #ifdef EXCA_DEBUG
162 	{
163 		int r1, r2, r3, r4, r5, r6, r7;
164 		r1 = exca_read(sc, map->sysmem_start_msb);
165 		r2 = exca_read(sc, map->sysmem_start_lsb);
166 		r3 = exca_read(sc, map->sysmem_stop_msb);
167 		r4 = exca_read(sc, map->sysmem_stop_lsb);
168 		r5 = exca_read(sc, map->cardmem_msb);
169 		r6 = exca_read(sc, map->cardmem_lsb);
170 		r7 = exca_read(sc, map->sysmem_win);
171 		printf("exca_do_mem_map window %d: %02x%02x %02x%02x "
172 		    "%02x%02x %02x (%08x+%08x.%08x*%08lx)\n",
173 		    win, r1, r2, r3, r4, r5, r6, r7,
174 		    mem->addr, mem->size, mem->realsize,
175 		    mem->offset);
176 	}
177 #endif
178 }
179 
180 /*
181  * public interface to map a resource.  kind is the type of memory to
182  * map (either common or attribute).  Memory created via this interface
183  * starts out at card address 0.  Since the only way to set this is
184  * to set it on a struct resource after it has been mapped, we're safe
185  * in maping this assumption.  Note that resources can be remapped using
186  * exca_do_mem_map so that's how the card address can be set later.
187  */
188 int
189 exca_mem_map(struct exca_softc *sc, int kind, struct resource *res)
190 {
191 	int win;
192 
193 	for (win = 0; win < EXCA_MEM_WINS; win++) {
194 		if ((sc->memalloc & (1 << win)) == 0) {
195 			sc->memalloc |= (1 << win);
196 			break;
197 		}
198 	}
199 	if (win >= EXCA_MEM_WINS)
200 		return (1);
201 	if (((rman_get_start(res) >> EXCA_CARDMEM_ADDRX_SHIFT) & 0xff) != 0 &&
202 	    (sc->flags & EXCA_HAS_MEMREG_WIN) == 0) {
203 		device_printf(sc->dev, "Does not support mapping above 24M.");
204 		return (1);
205 	}
206 
207 	sc->mem[win].cardaddr = 0;
208 	sc->mem[win].memt = rman_get_bustag(res);
209 	sc->mem[win].memh = rman_get_bushandle(res);
210 	sc->mem[win].addr = rman_get_start(res);
211 	sc->mem[win].size = rman_get_end(res) - sc->mem[win].addr + 1;
212 	sc->mem[win].realsize = sc->mem[win].size + EXCA_MEM_PAGESIZE - 1;
213 	sc->mem[win].realsize = sc->mem[win].realsize -
214 	    (sc->mem[win].realsize % EXCA_MEM_PAGESIZE);
215 	sc->mem[win].offset = (long)(sc->mem[win].addr);
216 	sc->mem[win].kind = kind;
217 	DPRINTF("exca_mem_map window %d bus %x+%x+%lx card addr %x\n",
218 	    win, sc->mem[win].addr, sc->mem[win].size,
219 	    sc->mem[win].offset, sc->mem[win].cardaddr);
220 	exca_do_mem_map(sc, win);
221 
222 	return (0);
223 }
224 
225 /*
226  * Private helper function.  This turns off a given memory map that is in
227  * use.  We do this by just clearing the enable bit in the pcic.  If we needed
228  * to make memory unmapping/mapping pairs faster, we would have to store
229  * more state information about the pcic and then use that to intelligently
230  * to the map/unmap.  However, since we don't do that sort of thing often
231  * (generally just at configure time), it isn't a case worth optimizing.
232  */
233 static void
234 exca_mem_unmap(struct exca_softc *sc, int window)
235 {
236 	if (window < 0 || window >= EXCA_MEM_WINS)
237 		panic("exca_mem_unmap: window out of range");
238 
239 	exca_clrb(sc, EXCA_ADDRWIN_ENABLE, mem_map_index[window].memenable);
240 	sc->memalloc &= ~(1 << window);
241 }
242 
243 /*
244  * Find the map that we're using to hold the resoruce.  This works well
245  * so long as the client drivers don't do silly things like map the same
246  * area mutliple times, or map both common and attribute memory at the
247  * same time.  This latter restriction is a bug.  We likely should just
248  * store a pointer to the res in the mem[x] data structure.
249  */
250 static int
251 exca_mem_findmap(struct exca_softc *sc, struct resource *res)
252 {
253 	int win;
254 
255 	for (win = 0; win < EXCA_MEM_WINS; win++) {
256 		if (sc->mem[win].memt == rman_get_bustag(res) &&
257 		    sc->mem[win].addr == rman_get_start(res) &&
258 		    sc->mem[win].size == rman_get_size(res))
259 			return (win);
260 	}
261 	return (-1);
262 }
263 
264 /*
265  * Set the memory flag.  This means that we are setting if the memory
266  * is coming from attribute memory or from common memory on the card.
267  * CIS entries are generally in attribute memory (although they can
268  * reside in common memory).  Generally, this is the only use for attribute
269  * memory.  However, some cards require their drivers to dance in both
270  * common and/or attribute memory and this interface (and setting the
271  * offset interface) exist for such cards.
272  */
273 int
274 exca_mem_set_flags(struct exca_softc *sc, struct resource *res, uint32_t flags)
275 {
276 	int win;
277 
278 	win = exca_mem_findmap(sc, res);
279 	if (win < 0) {
280 		device_printf(sc->dev,
281 		    "set_res_flags: specified resource not active\n");
282 		return (ENOENT);
283 	}
284 
285 	sc->mem[win].kind = flags;
286 	exca_do_mem_map(sc, win);
287 	return (0);
288 }
289 
290 /*
291  * Given a resource, go ahead and unmap it if we can find it in the
292  * resrouce list that's used.
293  */
294 int
295 exca_mem_unmap_res(struct exca_softc *sc, struct resource *res)
296 {
297 	int win;
298 
299 	win = exca_mem_findmap(sc, res);
300 	if (win < 0)
301 		return (ENOENT);
302 	exca_mem_unmap(sc, win);
303 	return (0);
304 }
305 
306 /*
307  * Set the offset of the memory.  We use this for reading the CIS and
308  * frobbing the pccard's pccard registers (POR, etc).  Some drivers
309  * need to access this functionality as well, since they have receive
310  * buffers defined in the attribute memory.  Thankfully, these cards
311  * are few and fare between.  Some cards also have common memory that
312  * is large and only map a small portion of it at a time (but these cards
313  * are rare, the more common case being to have just a small amount
314  * of common memory that the driver needs to bcopy data from in order to
315  * get at it.
316  */
317 int
318 exca_mem_set_offset(struct exca_softc *sc, struct resource *res,
319     uint32_t cardaddr, uint32_t *deltap)
320 {
321 	int win;
322 	uint32_t delta;
323 
324 	win = exca_mem_findmap(sc, res);
325 	if (win < 0) {
326 		device_printf(sc->dev,
327 		    "set_memory_offset: specified resource not active\n");
328 		return (ENOENT);
329 	}
330 	sc->mem[win].cardaddr = cardaddr;
331 	delta = cardaddr % EXCA_MEM_PAGESIZE;
332 	if (deltap)
333 		*deltap = delta;
334 	cardaddr -= delta;
335 	sc->mem[win].realsize = sc->mem[win].size + delta +
336 	    EXCA_MEM_PAGESIZE - 1;
337 	sc->mem[win].realsize = sc->mem[win].realsize -
338 	    (sc->mem[win].realsize % EXCA_MEM_PAGESIZE);
339 	sc->mem[win].offset = cardaddr - sc->mem[win].addr;
340 	exca_do_mem_map(sc, win);
341 	return (0);
342 }
343 
344 
345 /* I/O */
346 
347 #define	EXCA_IOINFO(NUM) {						\
348 	EXCA_IOADDR ## NUM ## _START_LSB,				\
349 	EXCA_IOADDR ## NUM ## _START_MSB,				\
350 	EXCA_IOADDR ## NUM ## _STOP_LSB,				\
351 	EXCA_IOADDR ## NUM ## _STOP_MSB,				\
352 	EXCA_ADDRWIN_ENABLE_IO ## NUM,					\
353 	EXCA_IOCTL_IO ## NUM ## _WAITSTATE				\
354 	| EXCA_IOCTL_IO ## NUM ## _ZEROWAIT				\
355 	| EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_MASK			\
356 	| EXCA_IOCTL_IO ## NUM ## _DATASIZE_MASK,			\
357 	{								\
358 		EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_CARD,		\
359 		EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_DATASIZE		\
360 		| EXCA_IOCTL_IO ## NUM ## _DATASIZE_8BIT,		\
361 		EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_DATASIZE		\
362 		| EXCA_IOCTL_IO ## NUM ## _DATASIZE_16BIT,		\
363 	}								\
364 }
365 
366 static struct io_map_index_st {
367 	int	start_lsb;
368 	int	start_msb;
369 	int	stop_lsb;
370 	int	stop_msb;
371 	int	ioenable;
372 	int	ioctlmask;
373 	int	ioctlbits[3]; /* indexed by PCCARD_WIDTH_* */
374 } io_map_index[] = {
375 	EXCA_IOINFO(0),
376 	EXCA_IOINFO(1),
377 };
378 #undef	EXCA_IOINFO
379 
380 static void
381 exca_do_io_map(struct exca_softc *sc, int win)
382 {
383 	struct io_map_index_st *map;
384 
385 	struct pccard_io_handle *io;
386 
387 	map = &io_map_index[win];
388 	io = &sc->io[win];
389 	exca_write(sc, map->start_lsb, io->addr & 0xff);
390 	exca_write(sc, map->start_msb, (io->addr >> 8) & 0xff);
391 
392 	exca_write(sc, map->stop_lsb, (io->addr + io->size - 1) & 0xff);
393 	exca_write(sc, map->stop_msb, ((io->addr + io->size - 1) >> 8) & 0xff);
394 
395 	exca_clrb(sc, EXCA_IOCTL, map->ioctlmask);
396 	exca_setb(sc, EXCA_IOCTL, map->ioctlbits[io->width]);
397 
398 	exca_setb(sc, EXCA_ADDRWIN_ENABLE, map->ioenable);
399 #ifdef EXCA_DEBUG
400 	{
401 		int r1, r2, r3, r4;
402 		r1 = exca_read(sc, map->start_msb);
403 		r2 = exca_read(sc, map->start_lsb);
404 		r3 = exca_read(sc, map->stop_msb);
405 		r4 = exca_read(sc, map->stop_lsb);
406 		DPRINTF("exca_do_io_map window %d: %02x%02x %02x%02x "
407 		    "(%08x+%08x)\n", win, r1, r2, r3, r4,
408 		    io->addr, io->size);
409 	}
410 #endif
411 }
412 
413 int
414 exca_io_map(struct exca_softc *sc, int width, struct resource *r)
415 {
416 	int win;
417 #ifdef EXCA_DEBUG
418 	static char *width_names[] = { "auto", "io8", "io16"};
419 #endif
420 	for (win=0; win < EXCA_IO_WINS; win++) {
421 		if ((sc->ioalloc & (1 << win)) == 0) {
422 			sc->ioalloc |= (1 << win);
423 			break;
424 		}
425 	}
426 	if (win >= EXCA_IO_WINS)
427 		return (1);
428 
429 	sc->io[win].iot = rman_get_bustag(r);
430 	sc->io[win].ioh = rman_get_bushandle(r);
431 	sc->io[win].addr = rman_get_start(r);
432 	sc->io[win].size = rman_get_end(r) - sc->io[win].addr + 1;
433 	sc->io[win].flags = 0;
434 	sc->io[win].width = width;
435 	DPRINTF("exca_io_map window %d %s port %x+%x\n",
436 	    win, width_names[width], sc->io[win].addr,
437 	    sc->io[win].size);
438 	exca_do_io_map(sc, win);
439 
440 	return (0);
441 }
442 
443 static void
444 exca_io_unmap(struct exca_softc *sc, int window)
445 {
446 	if (window >= EXCA_IO_WINS)
447 		panic("exca_io_unmap: window out of range");
448 
449 	exca_clrb(sc, EXCA_ADDRWIN_ENABLE, io_map_index[window].ioenable);
450 
451 	sc->ioalloc &= ~(1 << window);
452 
453 	sc->io[window].iot = 0;
454 	sc->io[window].ioh = 0;
455 	sc->io[window].addr = 0;
456 	sc->io[window].size = 0;
457 	sc->io[window].flags = 0;
458 	sc->io[window].width = 0;
459 }
460 
461 static int
462 exca_io_findmap(struct exca_softc *sc, struct resource *res)
463 {
464 	int win;
465 
466 	for (win = 0; win < EXCA_IO_WINS; win++) {
467 		if (sc->io[win].iot == rman_get_bustag(res) &&
468 		    sc->io[win].addr == rman_get_start(res) &&
469 		    sc->io[win].size == rman_get_size(res))
470 			return (win);
471 	}
472 	return (-1);
473 }
474 
475 
476 int
477 exca_io_unmap_res(struct exca_softc *sc, struct resource *res)
478 {
479 	int win;
480 
481 	win = exca_io_findmap(sc, res);
482 	if (win < 0)
483 		return (ENOENT);
484 	exca_io_unmap(sc, win);
485 	return (0);
486 }
487 
488 /* Misc */
489 
490 /*
491  * If interrupts are enabled, then we should be able to just wait for
492  * an interrupt routine to wake us up.  Busy waiting shouldn't be
493  * necessary.  Sadly, not all legacy ISA cards support an interrupt
494  * for the busy state transitions, at least according to their datasheets,
495  * so we busy wait a while here..
496  */
497 static void
498 exca_wait_ready(struct exca_softc *sc)
499 {
500 	int i;
501 	DEVPRINTF(sc->dev, "exca_wait_ready: status 0x%02x\n",
502 	    exca_read(sc, EXCA_IF_STATUS));
503 	for (i = 0; i < 10000; i++) {
504 		if (exca_read(sc, EXCA_IF_STATUS) & EXCA_IF_STATUS_READY)
505 			return;
506 		DELAY(500);
507 	}
508 	device_printf(sc->dev, "ready never happened, status = %02x\n",
509 	    exca_read(sc, EXCA_IF_STATUS));
510 }
511 
512 /*
513  * Reset the card.  Ideally, we'd do a lot of this via interrupts.
514  * However, many PC Cards will deassert the ready signal.  This means
515  * that they are asserting an interrupt.  This makes it hard to
516  * do anything but a busy wait here.  One could argue that these
517  * such cards are broken, or that the bridge that allows this sort
518  * of interrupt through isn't quite what you'd want (and may be a standards
519  * violation).  However, such arguing would leave a huge class of pc cards
520  * and bridges out of reach for use in the system.
521  *
522  * Maybe I should reevaluate the above based on the power bug I fixed
523  * in OLDCARD.
524  */
525 void
526 exca_reset(struct exca_softc *sc, device_t child)
527 {
528 	int cardtype;
529 	int win;
530 
531 	/* enable socket i/o */
532 	exca_setb(sc, EXCA_PWRCTL, EXCA_PWRCTL_OE);
533 
534 	exca_write(sc, EXCA_INTR, EXCA_INTR_ENABLE);
535 	/* hold reset for 30ms */
536 	DELAY(30*1000);
537 	/* clear the reset flag */
538 	exca_setb(sc, EXCA_INTR, EXCA_INTR_RESET);
539 	/* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
540 	DELAY(20*1000);
541 
542 	exca_wait_ready(sc);
543 
544 	/* disable all address windows */
545 	exca_write(sc, EXCA_ADDRWIN_ENABLE, 0);
546 
547 	CARD_GET_TYPE(child, &cardtype);
548 	exca_setb(sc, EXCA_INTR, (cardtype == PCCARD_IFTYPE_IO) ?
549 	    EXCA_INTR_CARDTYPE_IO : EXCA_INTR_CARDTYPE_MEM);
550 	DEVPRINTF(sc->dev, "card type is %s\n",
551 	    (cardtype == PCCARD_IFTYPE_IO) ? "io" : "mem");
552 
553 	/* reinstall all the memory and io mappings */
554 	for (win = 0; win < EXCA_MEM_WINS; ++win)
555 		if (sc->memalloc & (1 << win))
556 			exca_do_mem_map(sc, win);
557 	for (win = 0; win < EXCA_IO_WINS; ++win)
558 		if (sc->ioalloc & (1 << win))
559 			exca_do_io_map(sc, win);
560 }
561 
562 /*
563  * Initialize the exca_softc data structure for the first time.
564  */
565 void
566 exca_init(struct exca_softc *sc, device_t dev,
567     bus_space_tag_t bst, bus_space_handle_t bsh, uint32_t offset)
568 {
569 	sc->dev = dev;
570 	sc->memalloc = 0;
571 	sc->ioalloc = 0;
572 	sc->bst = bst;
573 	sc->bsh = bsh;
574 	sc->offset = offset;
575 	sc->flags = 0;
576 }
577 
578 /*
579  * Probe the expected slots.  We maybe should set the ID for each of these
580  * slots too while we're at it.  But maybe that belongs to a separate
581  * function.
582  *
583  * Callers must charantee that there are at least EXCA_NSLOTS (4) in
584  * the array that they pass the address of the first element in the
585  * "exca" parameter.
586  */
587 int
588 exca_probe_slots(device_t dev, struct exca_softc *exca)
589 {
590 	int rid;
591 	struct resource *res;
592 	int err;
593 	bus_space_tag_t iot;
594 	bus_space_handle_t ioh;
595 	int i;
596 
597 	err = ENXIO;
598 	rid = 0;
599 	res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, EXCA_IOSIZE,
600 	    RF_ACTIVE);
601 	if (res == NULL)
602 		return (ENXIO);
603 	iot = rman_get_bustag(res);
604 	ioh = rman_get_bushandle(res);
605 	for (i = 0; i < EXCA_NSLOTS; i++) {
606 		exca_init(&exca[i], dev, iot, ioh, i * EXCA_SOCKET_SIZE);
607 		if (exca_is_pcic(&exca[i])) {
608 			err = 0;
609 			exca[i].flags |= EXCA_SOCKET_PRESENT;
610 		}
611 	}
612 	bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
613 	return (err);
614 }
615 
616 int
617 exca_is_pcic(struct exca_softc *sc)
618 {
619 	/* XXX */
620 	return (0);
621 }
622 
623 static int exca_modevent(module_t mod, int cmd, void *arg)
624 {
625 	return 0;
626 }
627 DEV_MODULE(exca, exca_modevent, NULL);
628 MODULE_VERSION(exca, 1);
629