xref: /freebsd/sys/dev/exca/exca.c (revision 70fe064ad7cab6c0444b91622f60ec6a462f308a)
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 
64 #include <sys/bus.h>
65 #include <machine/bus.h>
66 #include <sys/rman.h>
67 #include <machine/resource.h>
68 
69 #include <dev/pccard/pccardreg.h>
70 #include <dev/pccard/pccardvar.h>
71 
72 #include <dev/exca/excareg.h>
73 #include <dev/exca/excavar.h>
74 
75 #define EXCA_DEBUG
76 #ifdef EXCA_DEBUG
77 #define DEVPRINTF(dev, fmt, args...)	device_printf((dev), (fmt), ## args)
78 #define DPRINTF(fmt, args...)		printf(fmt, ## args)
79 #else
80 #define DEVPRINTF(dev, fmt, args...)
81 #define DPRINTF(fmt, args...)
82 #endif
83 
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 
201 	sc->mem[win].cardaddr = 0;
202 	sc->mem[win].memt = rman_get_bustag(res);
203 	sc->mem[win].memh = rman_get_bushandle(res);
204 	sc->mem[win].addr = rman_get_start(res);
205 	sc->mem[win].size = rman_get_end(res) - sc->mem[win].addr + 1;
206 	sc->mem[win].realsize = sc->mem[win].size + EXCA_MEM_PAGESIZE - 1;
207 	sc->mem[win].realsize = sc->mem[win].realsize -
208 	    (sc->mem[win].realsize % EXCA_MEM_PAGESIZE);
209 	sc->mem[win].offset = (long)(sc->mem[win].addr);
210 	sc->mem[win].kind = kind;
211 	DPRINTF("exca_mem_map window %d bus %x+%x+%lx card addr %x\n",
212 	    win, sc->mem[win].addr, sc->mem[win].size,
213 	    sc->mem[win].offset, sc->mem[win].cardaddr);
214 	exca_do_mem_map(sc, win);
215 
216 	return (0);
217 }
218 
219 /*
220  * Private helper function.  This turns off a given memory map that is in
221  * use.  We do this by just clearing the enable bit in the pcic.  If we needed
222  * to make memory unmapping/mapping pairs faster, we would have to store
223  * more state information about the pcic and then use that to intelligently
224  * to the map/unmap.  However, since we don't do that sort of thing often
225  * (generally just at configure time), it isn't a case worth optimizing.
226  */
227 static void
228 exca_mem_unmap(struct exca_softc *sc, int window)
229 {
230 	if (window < 0 || window >= EXCA_MEM_WINS)
231 		panic("exca_mem_unmap: window out of range");
232 
233 	exca_clrb(sc, EXCA_ADDRWIN_ENABLE, mem_map_index[window].memenable);
234 	sc->memalloc &= ~(1 << window);
235 }
236 
237 /*
238  * Find the map that we're using to hold the resoruce.  This works well
239  * so long as the client drivers don't do silly things like map the same
240  * area mutliple times, or map both common and attribute memory at the
241  * same time.  This latter restriction is a bug.  We likely should just
242  * store a pointer to the res in the mem[x] data structure.
243  */
244 static int
245 exca_mem_findmap(struct exca_softc *sc, struct resource *res)
246 {
247 	int win;
248 
249 	for (win = 0; win < EXCA_MEM_WINS; win++) {
250 		if (sc->mem[win].memt == rman_get_bustag(res) &&
251 		    sc->mem[win].addr == rman_get_start(res) &&
252 		    sc->mem[win].size == rman_get_size(res))
253 			return (win);
254 	}
255 	return (-1);
256 }
257 
258 /*
259  * Set the memory flag.  This means that we are setting if the memory
260  * is coming from attribute memory or from common memory on the card.
261  * CIS entries are generally in attribute memory (although they can
262  * reside in common memory).  Generally, this is the only use for attribute
263  * memory.  However, some cards require their drivers to dance in both
264  * common and/or attribute memory and this interface (and setting the
265  * offset interface) exist for such cards.
266  */
267 int
268 exca_mem_set_flags(struct exca_softc *sc, struct resource *res, uint32_t flags)
269 {
270 	int win;
271 
272 	win = exca_mem_findmap(sc, res);
273 	if (win < 0) {
274 		device_printf(sc->dev,
275 		    "set_res_flags: specified resource not active\n");
276 		return (ENOENT);
277 	}
278 
279 	sc->mem[win].kind = flags;
280 	exca_do_mem_map(sc, win);
281 	return (0);
282 }
283 
284 /*
285  * Given a resource, go ahead and unmap it if we can find it in the
286  * resrouce list that's used.
287  */
288 int
289 exca_mem_unmap_res(struct exca_softc *sc, struct resource *res)
290 {
291 	int win;
292 
293 	win = exca_mem_findmap(sc, res);
294 	if (win < 0)
295 		return (ENOENT);
296 	exca_mem_unmap(sc, win);
297 	return (0);
298 }
299 
300 /*
301  * Set the offset of the memory.  We use this for reading the CIS and
302  * frobbing the pccard's pccard registers (POR, etc).  Some drivers
303  * need to access this functionality as well, since they have receive
304  * buffers defined in the attribute memory.  Thankfully, these cards
305  * are few and fare between.  Some cards also have common memory that
306  * is large and only map a small portion of it at a time (but these cards
307  * are rare, the more common case being to have just a small amount
308  * of common memory that the driver needs to bcopy data from in order to
309  * get at it.
310  */
311 int
312 exca_mem_set_offset(struct exca_softc *sc, struct resource *res,
313     uint32_t cardaddr, uint32_t *deltap)
314 {
315 	int win;
316 	uint32_t delta;
317 
318 	win = exca_mem_findmap(sc, res);
319 	if (win < 0) {
320 		device_printf(sc->dev,
321 		    "set_memory_offset: specified resource not active\n");
322 		return (ENOENT);
323 	}
324 	sc->mem[win].cardaddr = cardaddr;
325 	delta = cardaddr % EXCA_MEM_PAGESIZE;
326 	if (deltap)
327 		*deltap = delta;
328 	cardaddr -= delta;
329 	sc->mem[win].realsize = sc->mem[win].size + delta +
330 	    EXCA_MEM_PAGESIZE - 1;
331 	sc->mem[win].realsize = sc->mem[win].realsize -
332 	    (sc->mem[win].realsize % EXCA_MEM_PAGESIZE);
333 	sc->mem[win].offset = cardaddr - sc->mem[win].addr;
334 	exca_do_mem_map(sc, win);
335 	return (0);
336 }
337 
338 
339 /* I/O */
340 
341 #define	EXCA_IOINFO(NUM) {						\
342 	EXCA_IOADDR ## NUM ## _START_LSB,				\
343 	EXCA_IOADDR ## NUM ## _START_MSB,				\
344 	EXCA_IOADDR ## NUM ## _STOP_LSB,				\
345 	EXCA_IOADDR ## NUM ## _STOP_MSB,				\
346 	EXCA_ADDRWIN_ENABLE_IO ## NUM ##,				\
347 	EXCA_IOCTL_IO ## NUM ## _WAITSTATE				\
348 	| EXCA_IOCTL_IO ## NUM ## _ZEROWAIT				\
349 	| EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_MASK			\
350 	| EXCA_IOCTL_IO ## NUM ## _DATASIZE_MASK,			\
351 	{								\
352 		EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_CARD,		\
353 		EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_DATASIZE		\
354 		| EXCA_IOCTL_IO ## NUM ## _DATASIZE_8BIT,		\
355 		EXCA_IOCTL_IO ## NUM ## _IOCS16SRC_DATASIZE		\
356 		| EXCA_IOCTL_IO ## NUM ## _DATASIZE_16BIT,		\
357 	}								\
358 }
359 
360 static struct io_map_index_st {
361 	int	start_lsb;
362 	int	start_msb;
363 	int	stop_lsb;
364 	int	stop_msb;
365 	int	ioenable;
366 	int	ioctlmask;
367 	int	ioctlbits[3]; /* indexed by PCCARD_WIDTH_* */
368 } io_map_index[] = {
369 	EXCA_IOINFO(0),
370 	EXCA_IOINFO(1),
371 };
372 #undef	EXCA_IOINFO
373 
374 static void
375 exca_do_io_map(struct exca_softc *sc, int win)
376 {
377 	struct io_map_index_st *map;
378 
379 	struct pccard_io_handle *io;
380 
381 	map = &io_map_index[win];
382 	io = &sc->io[win];
383 	exca_write(sc, map->start_lsb, io->addr & 0xff);
384 	exca_write(sc, map->start_msb, (io->addr >> 8) & 0xff);
385 
386 	exca_write(sc, map->stop_lsb, (io->addr + io->size - 1) & 0xff);
387 	exca_write(sc, map->stop_msb, ((io->addr + io->size - 1) >> 8) & 0xff);
388 
389 	exca_clrb(sc, EXCA_IOCTL, map->ioctlmask);
390 	exca_setb(sc, EXCA_IOCTL, map->ioctlbits[io->width]);
391 
392 	exca_setb(sc, EXCA_ADDRWIN_ENABLE, map->ioenable);
393 #ifdef EXCA_DEBUG
394 	{
395 		int r1, r2, r3, r4;
396 		r1 = exca_read(sc, map->start_msb);
397 		r2 = exca_read(sc, map->start_lsb);
398 		r3 = exca_read(sc, map->stop_msb);
399 		r4 = exca_read(sc, map->stop_lsb);
400 		DPRINTF("exca_do_io_map window %d: %02x%02x %02x%02x "
401 		    "(%08x+%08x)\n", win, r1, r2, r3, r4,
402 		    io->addr, io->size);
403 	}
404 #endif
405 }
406 
407 int
408 exca_io_map(struct exca_softc *sc, int width, struct resource *r)
409 {
410 	int win;
411 #ifdef EXCA_DEBUG
412 	static char *width_names[] = { "auto", "io8", "io16"};
413 #endif
414 	for (win=0; win < EXCA_IO_WINS; win++) {
415 		if ((sc->ioalloc & (1 << win)) == 0) {
416 			sc->ioalloc |= (1 << win);
417 			break;
418 		}
419 	}
420 	if (win >= EXCA_IO_WINS)
421 		return (1);
422 
423 	sc->io[win].iot = rman_get_bustag(r);
424 	sc->io[win].ioh = rman_get_bushandle(r);
425 	sc->io[win].addr = rman_get_start(r);
426 	sc->io[win].size = rman_get_end(r) - sc->io[win].addr + 1;
427 	sc->io[win].flags = 0;
428 	sc->io[win].width = width;
429 	DPRINTF("exca_io_map window %d %s port %x+%x\n",
430 	    win, width_names[width], sc->io[win].addr,
431 	    sc->io[win].size);
432 	exca_do_io_map(sc, win);
433 
434 	return (0);
435 }
436 
437 static void
438 exca_io_unmap(struct exca_softc *sc, int window)
439 {
440 	if (window >= EXCA_IO_WINS)
441 		panic("exca_io_unmap: window out of range");
442 
443 	exca_clrb(sc, EXCA_ADDRWIN_ENABLE, io_map_index[window].ioenable);
444 
445 	sc->ioalloc &= ~(1 << window);
446 
447 	sc->io[window].iot = 0;
448 	sc->io[window].ioh = 0;
449 	sc->io[window].addr = 0;
450 	sc->io[window].size = 0;
451 	sc->io[window].flags = 0;
452 	sc->io[window].width = 0;
453 }
454 
455 static int
456 exca_io_findmap(struct exca_softc *sc, struct resource *res)
457 {
458 	int win;
459 
460 	for (win = 0; win < EXCA_IO_WINS; win++) {
461 		if (sc->io[win].iot == rman_get_bustag(res) &&
462 		    sc->io[win].addr == rman_get_start(res) &&
463 		    sc->io[win].size == rman_get_size(res))
464 			return (win);
465 	}
466 	return (-1);
467 }
468 
469 
470 int
471 exca_io_unmap_res(struct exca_softc *sc, struct resource *res)
472 {
473 	int win;
474 
475 	win = exca_io_findmap(sc, res);
476 	if (win < 0)
477 		return (ENOENT);
478 	exca_io_unmap(sc, win);
479 	return (0);
480 }
481 
482 /* Misc */
483 
484 /*
485  * If interrupts are enabled, then we should be able to just wait for
486  * an interrupt routine to wake us up.  Busy waiting shouldn't be
487  * necessary.  Sadly, not all legacy ISA cards support an interrupt
488  * for the busy state transitions, at least according to their datasheets,
489  * so we busy wait a while here..
490  */
491 static void
492 exca_wait_ready(struct exca_softc *sc)
493 {
494 	int i;
495 	DEVPRINTF(sc->dev, "exca_wait_ready: status 0x%02x\n",
496 	    exca_read(sc, EXCA_IF_STATUS));
497 	for (i = 0; i < 10000; i++) {
498 		if (exca_read(sc, EXCA_IF_STATUS) & EXCA_IF_STATUS_READY)
499 			return;
500 		DELAY(500);
501 	}
502 	device_printf(sc->dev, "ready never happened, status = %02x\n",
503 	    exca_read(sc, EXCA_IF_STATUS));
504 }
505 
506 /*
507  * Reset the card.  Ideally, we'd do a lot of this via interrupts.
508  * However, many PC Cards will deassert the ready signal.  This means
509  * that they are asserting an interrupt.  This makes it hard to
510  * do anything but a busy wait here.  One could argue that these
511  * such cards are broken, or that the bridge that allows this sort
512  * of interrupt through isn't quite what you'd want (and may be a standards
513  * violation).  However, such arguing would leave a huge class of pc cards
514  * and bridges out of reach for
515  */
516 void
517 exca_reset(struct exca_softc *sc, device_t child)
518 {
519 	int cardtype;
520 	int win;
521 
522 	/* enable socket i/o */
523 	exca_setb(sc, EXCA_PWRCTL, EXCA_PWRCTL_OE);
524 
525 	exca_write(sc, EXCA_INTR, EXCA_INTR_ENABLE);
526 	/* hold reset for 30ms */
527 	DELAY(30*1000);
528 	/* clear the reset flag */
529 	exca_setb(sc, EXCA_INTR, EXCA_INTR_RESET);
530 	/* wait 20ms as per pc card standard (r2.01) section 4.3.6 */
531 	DELAY(20*1000);
532 
533 	exca_wait_ready(sc);
534 
535 	/* disable all address windows */
536 	exca_write(sc, EXCA_ADDRWIN_ENABLE, 0);
537 
538 	CARD_GET_TYPE(child, &cardtype);
539 	exca_setb(sc, EXCA_INTR, (cardtype == PCCARD_IFTYPE_IO) ?
540 	    EXCA_INTR_CARDTYPE_IO : EXCA_INTR_CARDTYPE_MEM);
541 	DEVPRINTF(sc->dev, "card type is %s\n",
542 	    (cardtype == PCCARD_IFTYPE_IO) ? "io" : "mem");
543 
544 	/* reinstall all the memory and io mappings */
545 	for (win = 0; win < EXCA_MEM_WINS; ++win)
546 		if (sc->memalloc & (1 << win))
547 			exca_do_mem_map(sc, win);
548 	for (win = 0; win < EXCA_IO_WINS; ++win)
549 		if (sc->ioalloc & (1 << win))
550 			exca_do_io_map(sc, win);
551 }
552 
553 /*
554  * Initialize the exca_softc data structure for the first time.
555  */
556 void
557 exca_init(struct exca_softc *sc, device_t dev, exca_write_t *wrfn,
558     exca_read_t *rdfn, bus_space_tag_t bst, bus_space_handle_t bsh,
559     uint32_t offset)
560 {
561 	sc->dev = dev;
562 	sc->write_exca = wrfn;
563 	sc->read_exca = rdfn;
564 	sc->memalloc = 0;
565 	sc->ioalloc = 0;
566 	sc->bst = bst;
567 	sc->bsh = bsh;
568 	sc->offset = offset;
569 	sc->flags = 0;
570 }
571 
572 /*
573  * Probe the expected slots.  We maybe should set the ID for each of these
574  * slots too while we're at it.  But maybe that belongs to a separate
575  * function.
576  *
577  * Callers must charantee that there are at least EXCA_NSLOTS (4) in
578  * the array that they pass the address of the first element in the
579  * "exca" parameter.
580  */
581 int
582 exca_probe_slots(device_t dev, struct exca_softc *exca, exca_write_t writefnp,
583     exca_read_t readfnp)
584 {
585 	int rid;
586 	struct resource *res;
587 	int err;
588 	bus_space_tag_t iot;
589 	bus_space_handle_t ioh;
590 	int i;
591 
592 	err = ENXIO;
593 	rid = 0;
594 	res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, EXCA_IOSIZE,
595 	    RF_ACTIVE);
596 	if (res == NULL)
597 		return (ENXIO);
598 	iot = rman_get_bustag(res);
599 	ioh = rman_get_bushandle(res);
600 	for (i = 0; i < EXCA_NSLOTS; i++) {
601 		exca_init(&exca[i], dev, writefnp, readfnp, iot, ioh,
602 		    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