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