Home | History | Annotate | Line # | Download | only in eisa
eisa_machdep.c revision 1.6
      1 /* $NetBSD: eisa_machdep.c,v 1.6 2007/07/22 02:14:39 tsutsui Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 
     41 __KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.6 2007/07/22 02:14:39 tsutsui Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/device.h>
     46 #include <sys/malloc.h>
     47 #include <sys/queue.h>
     48 
     49 #include <machine/intr.h>
     50 #include <machine/rpb.h>
     51 
     52 #include <dev/eisa/eisareg.h>
     53 #include <dev/eisa/eisavar.h>
     54 
     55 #define	EISA_SLOT_HEADER_SIZE	31
     56 #define	EISA_SLOT_INFO_OFFSET	20
     57 
     58 #define	EISA_FUNC_INFO_OFFSET	34
     59 #define	EISA_CONFIG_BLOCK_SIZE	320
     60 
     61 #define	ECUF_TYPE_STRING	0x01
     62 #define	ECUF_MEM_ENTRY		0x02
     63 #define	ECUF_IRQ_ENTRY		0x04
     64 #define	ECUF_DMA_ENTRY		0x08
     65 #define	ECUF_IO_ENTRY		0x10
     66 #define	ECUF_INIT_ENTRY		0x20
     67 #define	ECUF_DISABLED		0x80
     68 
     69 #define	ECUF_SELECTIONS_SIZE	26
     70 #define	ECUF_TYPE_STRING_SIZE	80
     71 #define	ECUF_MEM_ENTRY_SIZE	7
     72 #define	ECUF_IRQ_ENTRY_SIZE	2
     73 #define	ECUF_DMA_ENTRY_SIZE	2
     74 #define	ECUF_IO_ENTRY_SIZE	3
     75 #define	ECUF_INIT_ENTRY_SIZE	60
     76 
     77 #define	ECUF_MEM_ENTRY_CNT	9
     78 #define	ECUF_IRQ_ENTRY_CNT	7
     79 #define	ECUF_DMA_ENTRY_CNT	4
     80 #define	ECUF_IO_ENTRY_CNT	20
     81 
     82 #define	CBUFSIZE		512
     83 
     84 /*
     85  * EISA configuration space, as set up by the ECU, may be sparse.
     86  */
     87 bus_size_t eisa_config_stride;
     88 paddr_t eisa_config_addr;		/* defaults to 0 */
     89 paddr_t eisa_config_header_addr;
     90 
     91 struct ecu_mem {
     92 	SIMPLEQ_ENTRY(ecu_mem) ecum_list;
     93 	struct eisa_cfg_mem ecum_mem;
     94 };
     95 
     96 struct ecu_irq {
     97 	SIMPLEQ_ENTRY(ecu_irq) ecui_list;
     98 	struct eisa_cfg_irq ecui_irq;
     99 };
    100 
    101 struct ecu_dma {
    102 	SIMPLEQ_ENTRY(ecu_dma) ecud_list;
    103 	struct eisa_cfg_dma ecud_dma;
    104 };
    105 
    106 struct ecu_io {
    107 	SIMPLEQ_ENTRY(ecu_io) ecuio_list;
    108 	struct eisa_cfg_io ecuio_io;
    109 };
    110 
    111 struct ecu_func {
    112 	SIMPLEQ_ENTRY(ecu_func) ecuf_list;
    113 	int ecuf_funcno;
    114 	u_int32_t ecuf_id;
    115 	u_int16_t ecuf_slot_info;
    116 	u_int16_t ecuf_cfg_ext;
    117 	u_int8_t ecuf_selections[ECUF_SELECTIONS_SIZE];
    118 	u_int8_t ecuf_func_info;
    119 	u_int8_t ecuf_type_string[ECUF_TYPE_STRING_SIZE];
    120 	u_int8_t ecuf_init[ECUF_INIT_ENTRY_SIZE];
    121 	SIMPLEQ_HEAD(, ecu_mem) ecuf_mem;
    122 	SIMPLEQ_HEAD(, ecu_irq) ecuf_irq;
    123 	SIMPLEQ_HEAD(, ecu_dma) ecuf_dma;
    124 	SIMPLEQ_HEAD(, ecu_io) ecuf_io;
    125 };
    126 
    127 struct ecu_data {
    128 	SIMPLEQ_ENTRY(ecu_data) ecud_list;
    129 	int ecud_slot;
    130 	u_int8_t ecud_eisaid[EISA_IDSTRINGLEN];
    131 	u_int32_t ecud_offset;
    132 
    133 	/* General slot info. */
    134 	u_int8_t ecud_slot_info;
    135 	u_int16_t ecud_ecu_major_rev;
    136 	u_int16_t ecud_ecu_minor_rev;
    137 	u_int16_t ecud_cksum;
    138 	u_int16_t ecud_ndevfuncs;
    139 	u_int8_t ecud_funcinfo;
    140 	u_int32_t ecud_comp_id;
    141 
    142 	/* The functions */
    143 	SIMPLEQ_HEAD(, ecu_func) ecud_funcs;
    144 };
    145 
    146 SIMPLEQ_HEAD(, ecu_data) ecu_data_list =
    147     SIMPLEQ_HEAD_INITIALIZER(ecu_data_list);
    148 
    149 static void
    150 ecuf_init(struct ecu_func *ecuf)
    151 {
    152 
    153 	memset(ecuf, 0, sizeof(*ecuf));
    154 	SIMPLEQ_INIT(&ecuf->ecuf_mem);
    155 	SIMPLEQ_INIT(&ecuf->ecuf_irq);
    156 	SIMPLEQ_INIT(&ecuf->ecuf_dma);
    157 	SIMPLEQ_INIT(&ecuf->ecuf_io);
    158 }
    159 
    160 static void
    161 eisa_parse_mem(struct ecu_func *ecuf, u_int8_t *dp)
    162 {
    163 	struct ecu_mem *ecum;
    164 	int i;
    165 
    166 	for (i = 0; i < ECUF_MEM_ENTRY_CNT; i++) {
    167 		ecum = malloc(sizeof(*ecum), M_DEVBUF, M_ZERO|M_WAITOK);
    168 		if (ecum == NULL)
    169 			panic("%s: can't allocate memory for ecum", __func__);
    170 
    171 		ecum->ecum_mem.ecm_isram = dp[0] & 0x1;
    172 		ecum->ecum_mem.ecm_unitsize = dp[1] & 0x3;
    173 		ecum->ecum_mem.ecm_decode = (dp[1] >> 2) & 0x3;
    174 		ecum->ecum_mem.ecm_addr =
    175 		    (dp[2] | (dp[3] << 8) | (dp[4] << 16)) << 8;
    176 		ecum->ecum_mem.ecm_size = (dp[5] | (dp[6] << 8)) << 10;
    177 		if (ecum->ecum_mem.ecm_size == 0)
    178 			ecum->ecum_mem.ecm_size = (1 << 26);
    179 		SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_mem, ecum, ecum_list);
    180 
    181 #ifdef EISA_DEBUG
    182 		printf("MEM 0x%lx 0x%lx %d %d %d\n",
    183 		    ecum->ecum_mem.ecm_addr, ecum->ecum_mem.ecm_size,
    184 		    ecum->ecum_mem.ecm_isram, ecum->ecum_mem.ecm_unitsize,
    185 		    ecum->ecum_mem.ecm_decode);
    186 #endif
    187 
    188 		if ((dp[0] & 0x80) == 0)
    189 			break;
    190 		dp += ECUF_MEM_ENTRY_SIZE;
    191 	}
    192 }
    193 
    194 static void
    195 eisa_parse_irq(struct ecu_func *ecuf, u_int8_t *dp)
    196 {
    197 	struct ecu_irq *ecui;
    198 	int i;
    199 
    200 	for (i = 0; i < ECUF_IRQ_ENTRY_CNT; i++) {
    201 		ecui = malloc(sizeof(*ecui), M_DEVBUF, M_ZERO|M_WAITOK);
    202 		if (ecui == NULL)
    203 			panic("%s: can't allocate memory for ecui", __func__);
    204 
    205 		ecui->ecui_irq.eci_irq = dp[0] & 0xf;
    206 		ecui->ecui_irq.eci_ist = (dp[0] & 0x20) ? IST_LEVEL : IST_EDGE;
    207 		ecui->ecui_irq.eci_shared = (dp[0] & 0x40) ? 1 : 0;
    208 		SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_irq, ecui, ecui_list);
    209 
    210 #ifdef EISA_DEBUG
    211 		printf("IRQ %d %s%s\n", ecui->ecui_irq.eci_irq,
    212 		    ecui->ecui_irq.eci_ist == IST_LEVEL ? "level" : "edge",
    213 		    ecui->ecui_irq.eci_shared ? " shared" : "");
    214 #endif
    215 
    216 		if ((dp[0] & 0x80) == 0)
    217 			break;
    218 		dp += ECUF_IRQ_ENTRY_SIZE;
    219 	}
    220 }
    221 
    222 static void
    223 eisa_parse_dma(struct ecu_func *ecuf, u_int8_t *dp)
    224 {
    225 	struct ecu_dma *ecud;
    226 	int i;
    227 
    228 	for (i = 0; i < ECUF_DMA_ENTRY_CNT; i++) {
    229 		ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
    230 		if (ecud == NULL)
    231 			panic("%s: can't allocate memory for ecud", __func__);
    232 
    233 		ecud->ecud_dma.ecd_drq = dp[0] & 0x7;
    234 		ecud->ecud_dma.ecd_shared = dp[0] & 0x40;
    235 		ecud->ecud_dma.ecd_size = (dp[1] >> 2) & 0x3;
    236 		ecud->ecud_dma.ecd_timing = (dp[1] >> 4) & 0x3;
    237 		SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_dma, ecud, ecud_list);
    238 
    239 #ifdef EISA_DEBUG
    240 		printf("DRQ %d%s %d %d\n", ecud->ecud_dma.ecd_drq,
    241 		    ecud->ecud_dma.ecd_shared ? " shared" : "",
    242 		    ecud->ecud_dma.ecd_size, ecud->ecud_dma.ecd_timing);
    243 #endif
    244 
    245 		if ((dp[0] & 0x80) == 0)
    246 			break;
    247 		dp += ECUF_DMA_ENTRY_SIZE;
    248 	}
    249 }
    250 
    251 static void
    252 eisa_parse_io(struct ecu_func *ecuf, u_int8_t *dp)
    253 {
    254 	struct ecu_io *ecuio;
    255 	int i;
    256 
    257 	for (i = 0; i < ECUF_IO_ENTRY_CNT; i++) {
    258 		ecuio = malloc(sizeof(*ecuio), M_DEVBUF, M_ZERO|M_WAITOK);
    259 		if (ecuio == NULL)
    260 			panic("%s: can't allocate memory for ecuio", __func__);
    261 
    262 		ecuio->ecuio_io.ecio_addr = dp[1] | (dp[2] << 8);
    263 		ecuio->ecuio_io.ecio_size = (dp[0] & 0x1f) + 1;
    264 		ecuio->ecuio_io.ecio_shared = (dp[0] & 0x40) ? 1 : 0;
    265 
    266 #ifdef EISA_DEBUG
    267 		printf("IO 0x%lx 0x%lx%s\n", ecuio->ecuio_io.ecio_addr,
    268 		    ecuio->ecuio_io.ecio_size,
    269 		    ecuio->ecuio_io.ecio_shared ? " shared" : "");
    270 #endif
    271 
    272 		if ((dp[0] & 0x80) == 0)
    273 			break;
    274 		dp += ECUF_IO_ENTRY_SIZE;
    275 	}
    276 }
    277 
    278 static void
    279 eisa_read_config_bytes(paddr_t addr, void *buf, size_t count)
    280 {
    281 	const u_int8_t *src = (const u_int8_t *)ALPHA_PHYS_TO_K0SEG(addr);
    282 	u_int8_t *dst = buf;
    283 
    284 	for (; count != 0; count--) {
    285 		*dst++ = *src;
    286 		src += eisa_config_stride;
    287 	}
    288 }
    289 
    290 static void
    291 eisa_read_config_word(paddr_t addr, u_int32_t *valp)
    292 {
    293 	const u_int8_t *src = (const u_int8_t *)ALPHA_PHYS_TO_K0SEG(addr);
    294 	u_int32_t val = 0;
    295 	int i;
    296 
    297 	for (i = 0; i < sizeof(val); i++) {
    298 		val |= (uint32_t)*src << (i * 8);
    299 		src += eisa_config_stride;
    300 	}
    301 
    302 	*valp = val;
    303 }
    304 
    305 static size_t
    306 eisa_uncompress(void *cbufp, void *ucbufp, size_t count)
    307 {
    308 	const u_int8_t *cbuf = cbufp;
    309 	u_int8_t *ucbuf = ucbufp;
    310 	u_int zeros = 0;
    311 
    312 	while (count--) {
    313 		if (zeros) {
    314 			zeros--;
    315 			*ucbuf++ = '\0';
    316 		} else if (*cbuf == '\0') {
    317 			*ucbuf++ = *cbuf++;
    318 			zeros = *cbuf++ - 1;
    319 		} else
    320 			*ucbuf++ = *cbuf++;
    321 	}
    322 
    323 	return ((size_t)cbuf - (size_t)cbufp);
    324 }
    325 
    326 void
    327 eisa_init(eisa_chipset_tag_t ec)
    328 {
    329 	struct ecu_data *ecud;
    330 	paddr_t cfgaddr;
    331 	u_int32_t offset;
    332 	u_int8_t eisaid[EISA_IDSTRINGLEN];
    333 	u_int8_t *cdata, *data;
    334 	u_int8_t *cdp, *dp;
    335 	struct ecu_func *ecuf;
    336 	int i, func;
    337 
    338 	/*
    339 	 * Locate EISA configuration space.
    340 	 */
    341 	if (hwrpb->rpb_condat_off == 0UL ||
    342 	    (hwrpb->rpb_condat_off >> 63) != 0) {
    343 		printf(": WARNING: no EISA configuration space");
    344 		return;
    345 	}
    346 
    347 	if (eisa_config_header_addr) {
    348 		printf("\n");
    349 		panic("eisa_init: EISA config space already initialized");
    350 	}
    351 
    352 	eisa_config_header_addr = hwrpb->rpb_condat_off;
    353 	if (eisa_config_stride == 0)
    354 		eisa_config_stride = 1;
    355 
    356 #ifdef EISA_DEBUG
    357 	printf("\nEISA config header at 0x%lx\n", eisa_config_header_addr);
    358 	printf("EISA config at 0x%lx\n", eisa_config_addr);
    359 	printf("EISA config stride: %ld\n", eisa_config_stride);
    360 #endif
    361 
    362 	/*
    363 	 * Read the slot headers, and allocate config structures for
    364 	 * valid slots.
    365 	 */
    366 	for (cfgaddr = eisa_config_header_addr, i = 0;
    367 	    i < eisa_maxslots(ec); i++) {
    368 		eisa_read_config_bytes(cfgaddr, eisaid, sizeof(eisaid));
    369 		eisaid[EISA_IDSTRINGLEN - 1] = '\0';	/* sanity */
    370 		cfgaddr += sizeof(eisaid) * eisa_config_stride;
    371 		eisa_read_config_word(cfgaddr, &offset);
    372 		cfgaddr += sizeof(offset) * eisa_config_stride;
    373 
    374 		if (offset != 0 && offset != 0xffffffff) {
    375 #ifdef EISA_DEBUG
    376 			printf("SLOT %d: offset 0x%08x eisaid %s\n",
    377 			    i, offset, eisaid);
    378 #endif
    379 			ecud = malloc(sizeof(*ecud), M_DEVBUF, M_ZERO|M_WAITOK);
    380 			if (ecud == NULL)
    381 				panic("%s: can't allocate memory for ecud",
    382 				    __func__);
    383 
    384 			SIMPLEQ_INIT(&ecud->ecud_funcs);
    385 
    386 			ecud->ecud_slot = i;
    387 			memcpy(ecud->ecud_eisaid, eisaid, sizeof(eisaid));
    388 			ecud->ecud_offset = offset;
    389 			SIMPLEQ_INSERT_TAIL(&ecu_data_list, ecud, ecud_list);
    390 		}
    391 	}
    392 
    393 	/*
    394 	 * Now traverse the valid slots and read the info.
    395 	 */
    396 
    397 	cdata = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
    398 	if (cdata == NULL)
    399 		panic("%s: can't allocate memory for cdata", __func__);
    400 	data = malloc(CBUFSIZE, M_TEMP, M_ZERO|M_WAITOK);
    401 	if (data == NULL)
    402 		panic("%s: can't allocate memory for data", __func__);
    403 
    404 	SIMPLEQ_FOREACH(ecud, &ecu_data_list, ecud_list) {
    405 		cfgaddr = eisa_config_addr + ecud->ecud_offset;
    406 #ifdef EISA_DEBUG
    407 		printf("Checking SLOT %d\n", ecud->ecud_slot);
    408 		printf("Reading config bytes at 0x%lx to cdata[0]\n", cfgaddr);
    409 #endif
    410 		eisa_read_config_bytes(cfgaddr, &cdata[0], 1);
    411 		cfgaddr += eisa_config_stride;
    412 
    413 		for (i = 1; i < CBUFSIZE; cfgaddr += eisa_config_stride, i++) {
    414 #ifdef EISA_DEBUG
    415 			printf("Reading config bytes at 0x%lx to cdata[%d]\n",
    416 			    cfgaddr, i);
    417 #endif
    418 			eisa_read_config_bytes(cfgaddr, &cdata[i], 1);
    419 			if (cdata[i - 1] == 0 && cdata[i] == 0)
    420 				break;
    421 		}
    422 		if (i == CBUFSIZE) {
    423 			/* assume this compressed data invalid */
    424 #ifdef EISA_DEBUG
    425 			printf("SLOT %d has invalid config\n", ecud->ecud_slot);
    426 #endif
    427 			continue;
    428 		}
    429 
    430 		i++;	/* index -> length */
    431 
    432 #ifdef EISA_DEBUG
    433 		printf("SLOT %d compressed data length %d:",
    434 		    ecud->ecud_slot, i);
    435 		{
    436 			int j;
    437 
    438 			for (j = 0; j < i; j++) {
    439 				if ((j % 16) == 0)
    440 					printf("\n");
    441 				printf("0x%02x ", cdata[j]);
    442 			}
    443 			printf("\n");
    444 		}
    445 #endif
    446 
    447 		cdp = cdata;
    448 		dp = data;
    449 
    450 		/* Uncompress the slot header. */
    451 		cdp += eisa_uncompress(cdp, dp, EISA_SLOT_HEADER_SIZE);
    452 #ifdef EISA_DEBUG
    453 		printf("SLOT %d uncompressed header data:",
    454 		    ecud->ecud_slot);
    455 		{
    456 			int j;
    457 
    458 			for (j = 0; j < EISA_SLOT_HEADER_SIZE; j++) {
    459 				if ((j % 16) == 0)
    460 					printf("\n");
    461 				printf("0x%02x ", dp[j]);
    462 			}
    463 			printf("\n");
    464 		}
    465 #endif
    466 
    467 		dp = &data[EISA_SLOT_INFO_OFFSET];
    468 		ecud->ecud_slot_info = *dp++;
    469 		ecud->ecud_ecu_major_rev = *dp++;
    470 		ecud->ecud_ecu_minor_rev = *dp++;
    471 		memcpy(&ecud->ecud_cksum, dp, sizeof(ecud->ecud_cksum));
    472 		dp += sizeof(ecud->ecud_cksum);
    473 		ecud->ecud_ndevfuncs = *dp++;
    474 		ecud->ecud_funcinfo = *dp++;
    475 		memcpy(&ecud->ecud_comp_id, dp, sizeof(ecud->ecud_comp_id));
    476 		dp += sizeof(ecud->ecud_comp_id);
    477 
    478 #ifdef EISA_DEBUG
    479 		printf("SLOT %d: ndevfuncs %d\n", ecud->ecud_slot,
    480 		    ecud->ecud_ndevfuncs);
    481 #endif
    482 
    483 		for (func = 0; func < ecud->ecud_ndevfuncs; func++) {
    484 			dp = data;
    485 			cdp += eisa_uncompress(cdp, dp, EISA_CONFIG_BLOCK_SIZE);
    486 #ifdef EISA_DEBUG
    487 			printf("SLOT %d:%d uncompressed data:",
    488 			    ecud->ecud_slot, func);
    489 			{
    490 				int j;
    491 
    492 				for (j = 0; i < EISA_CONFIG_BLOCK_SIZE; j++) {
    493 					if ((j % 16) == 0)
    494 						printf("\n");
    495 					printf("0x%02x ", dp[j]);
    496 				}
    497 				printf("\n");
    498 			}
    499 #endif
    500 
    501 			/* Skip disabled functions. */
    502 			if (dp[EISA_FUNC_INFO_OFFSET] & ECUF_DISABLED) {
    503 #ifdef EISA_DEBUG
    504 				printf("SLOT %d:%d disabled\n",
    505 				    ecud->ecud_slot, func);
    506 #endif
    507 				continue;
    508 			}
    509 
    510 			ecuf = malloc(sizeof(*ecuf), M_DEVBUF, M_WAITOK);
    511 			if (ecuf == NULL)
    512 				panic("%s: can't allocate memory for ecuf",
    513 				    __func__);
    514 			ecuf_init(ecuf);
    515 			ecuf->ecuf_funcno = func;
    516 			SIMPLEQ_INSERT_TAIL(&ecud->ecud_funcs, ecuf,
    517 			    ecuf_list);
    518 
    519 			memcpy(&ecuf->ecuf_id, dp, sizeof(ecuf->ecuf_id));
    520 			dp += sizeof(ecuf->ecuf_id);
    521 
    522 			memcpy(&ecuf->ecuf_slot_info, dp,
    523 			    sizeof(ecuf->ecuf_slot_info));
    524 			dp += sizeof(ecuf->ecuf_slot_info);
    525 
    526 			memcpy(&ecuf->ecuf_cfg_ext, dp,
    527 			    sizeof(ecuf->ecuf_cfg_ext));
    528 			dp += sizeof(ecuf->ecuf_cfg_ext);
    529 
    530 			memcpy(&ecuf->ecuf_selections, dp,
    531 			    sizeof(ecuf->ecuf_selections));
    532 			dp += sizeof(ecuf->ecuf_selections);
    533 
    534 			memcpy(&ecuf->ecuf_func_info, dp,
    535 			    sizeof(ecuf->ecuf_func_info));
    536 			dp += sizeof(ecuf->ecuf_func_info);
    537 
    538 			if (ecuf->ecuf_func_info & ECUF_TYPE_STRING)
    539 				memcpy(ecuf->ecuf_type_string, dp,
    540 				    sizeof(ecuf->ecuf_type_string));
    541 			dp += sizeof(ecuf->ecuf_type_string);
    542 
    543 			if (ecuf->ecuf_func_info & ECUF_MEM_ENTRY)
    544 				eisa_parse_mem(ecuf, dp);
    545 			dp += ECUF_MEM_ENTRY_SIZE * ECUF_MEM_ENTRY_CNT;
    546 
    547 			if (ecuf->ecuf_func_info & ECUF_IRQ_ENTRY)
    548 				eisa_parse_irq(ecuf, dp);
    549 			dp += ECUF_IRQ_ENTRY_SIZE * ECUF_IRQ_ENTRY_CNT;
    550 
    551 			if (ecuf->ecuf_func_info & ECUF_DMA_ENTRY)
    552 				eisa_parse_dma(ecuf, dp);
    553 			dp += ECUF_DMA_ENTRY_SIZE * ECUF_DMA_ENTRY_CNT;
    554 
    555 			if (ecuf->ecuf_func_info & ECUF_IO_ENTRY)
    556 				eisa_parse_io(ecuf, dp);
    557 			dp += ECUF_IO_ENTRY_SIZE * ECUF_IO_ENTRY_CNT;
    558 
    559 			if (ecuf->ecuf_func_info & ECUF_INIT_ENTRY)
    560 				memcpy(ecuf->ecuf_init, dp,
    561 				    sizeof(ecuf->ecuf_init));
    562 			dp += sizeof(ecuf->ecuf_init);
    563 		}
    564 	}
    565 
    566 	free(cdata, M_TEMP);
    567 	free(data, M_TEMP);
    568 }
    569 
    570 static struct ecu_data *
    571 eisa_lookup_data(int slot)
    572 {
    573 	struct ecu_data *ecud;
    574 
    575 	SIMPLEQ_FOREACH(ecud, &ecu_data_list, ecud_list) {
    576 		if (ecud->ecud_slot == slot)
    577 			return (ecud);
    578 	}
    579 	return (NULL);
    580 }
    581 
    582 static struct ecu_func *
    583 eisa_lookup_func(int slot, int func)
    584 {
    585 	struct ecu_data *ecud;
    586 	struct ecu_func *ecuf;
    587 
    588 	ecud = eisa_lookup_data(slot);
    589 	if (ecud == NULL)
    590 		return (NULL);
    591 
    592 	SIMPLEQ_FOREACH(ecuf, &ecud->ecud_funcs, ecuf_list) {
    593 		if (ecuf->ecuf_funcno == func)
    594 			return (ecuf);
    595 	}
    596 	return (NULL);
    597 }
    598 
    599 int
    600 eisa_conf_read_mem(eisa_chipset_tag_t ec, int slot, int func, int entry,
    601     struct eisa_cfg_mem *dp)
    602 {
    603 	struct ecu_func *ecuf;
    604 	struct ecu_mem *ecum;
    605 
    606 	ecuf = eisa_lookup_func(slot, func);
    607 	if (ecuf == NULL)
    608 		return (ENOENT);
    609 
    610 	SIMPLEQ_FOREACH(ecum, &ecuf->ecuf_mem, ecum_list) {
    611 		if (entry-- == 0)
    612 			break;
    613 	}
    614 	if (ecum == NULL)
    615 		return (ENOENT);
    616 
    617 	*dp = ecum->ecum_mem;
    618 	return (0);
    619 }
    620 
    621 int
    622 eisa_conf_read_irq(eisa_chipset_tag_t ec, int slot, int func, int entry,
    623     struct eisa_cfg_irq *dp)
    624 {
    625 	struct ecu_func *ecuf;
    626 	struct ecu_irq *ecui;
    627 
    628 	ecuf = eisa_lookup_func(slot, func);
    629 	if (ecuf == NULL)
    630 		return (ENOENT);
    631 
    632 	SIMPLEQ_FOREACH(ecui, &ecuf->ecuf_irq, ecui_list) {
    633 		if (entry-- == 0)
    634 			break;
    635 	}
    636 	if (ecui == NULL)
    637 		return (ENOENT);
    638 
    639 	*dp = ecui->ecui_irq;
    640 	return (0);
    641 }
    642 
    643 int
    644 eisa_conf_read_dma(eisa_chipset_tag_t ec, int slot, int func, int entry,
    645     struct eisa_cfg_dma *dp)
    646 {
    647 	struct ecu_func *ecuf;
    648 	struct ecu_dma *ecud;
    649 
    650 	ecuf = eisa_lookup_func(slot, func);
    651 	if (ecuf == NULL)
    652 		return (ENOENT);
    653 
    654 	SIMPLEQ_FOREACH(ecud, &ecuf->ecuf_dma, ecud_list) {
    655 		if (entry-- == 0)
    656 			break;
    657 	}
    658 	if (ecud == NULL)
    659 		return (ENOENT);
    660 
    661 	*dp = ecud->ecud_dma;
    662 	return (0);
    663 }
    664 
    665 int
    666 eisa_conf_read_io(eisa_chipset_tag_t ec, int slot, int func, int entry,
    667     struct eisa_cfg_io *dp)
    668 {
    669 	struct ecu_func *ecuf;
    670 	struct ecu_io *ecuio;
    671 
    672 	ecuf = eisa_lookup_func(slot, func);
    673 	if (ecuf == NULL)
    674 		return (ENOENT);
    675 
    676 	SIMPLEQ_FOREACH(ecuio, &ecuf->ecuf_io, ecuio_list) {
    677 		if (entry-- == 0)
    678 			break;
    679 	}
    680 	if (ecuio == NULL)
    681 		return (ENOENT);
    682 
    683 	*dp = ecuio->ecuio_io;
    684 	return (0);
    685 }
    686