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