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