Home | History | Annotate | Line # | Download | only in eisa
eisa_machdep.c revision 1.1
      1  1.1  thorpej /* $NetBSD: eisa_machdep.c,v 1.1 2000/07/29 23:18:47 thorpej 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.1  thorpej __KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.1 2000/07/29 23:18:47 thorpej 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.1  thorpej 	bus_addr_t ecum_addr;
     92  1.1  thorpej 	bus_size_t ecum_size;
     93  1.1  thorpej 	int	ecum_isram;
     94  1.1  thorpej 	int	ecum_decode;
     95  1.1  thorpej 	int	ecum_unitsize;
     96  1.1  thorpej };
     97  1.1  thorpej 
     98  1.1  thorpej struct ecu_irq {
     99  1.1  thorpej 	SIMPLEQ_ENTRY(ecu_irq) ecui_list;
    100  1.1  thorpej 	int	ecui_irq;
    101  1.1  thorpej 	int	ecui_ist;
    102  1.1  thorpej 	int	ecui_shared;
    103  1.1  thorpej };
    104  1.1  thorpej 
    105  1.1  thorpej struct ecu_dma {
    106  1.1  thorpej 	SIMPLEQ_ENTRY(ecu_dma) ecud_list;
    107  1.1  thorpej 	int	ecud_drq;
    108  1.1  thorpej 	int	ecud_shared;
    109  1.1  thorpej 	int	ecud_size;
    110  1.1  thorpej #define	ECUD_SIZE_8BIT		0
    111  1.1  thorpej #define	ECUD_SIZE_16BIT		1
    112  1.1  thorpej #define	ECUD_SIZE_32BIT		2
    113  1.1  thorpej #define	ECUD_SIZE_RESERVED	3
    114  1.1  thorpej 	int	ecud_timing;
    115  1.1  thorpej #define	ECUD_TIMING_ISA		0
    116  1.1  thorpej #define	ECUD_TIMING_TYPEA	1
    117  1.1  thorpej #define	ECUD_TIMING_TYPEB	2
    118  1.1  thorpej #define	ECUD_TIMING_TYPEC	3
    119  1.1  thorpej };
    120  1.1  thorpej 
    121  1.1  thorpej struct ecu_io {
    122  1.1  thorpej 	SIMPLEQ_ENTRY(ecu_io) ecuio_list;
    123  1.1  thorpej 	bus_addr_t ecuio_addr;
    124  1.1  thorpej 	bus_size_t ecuio_size;
    125  1.1  thorpej 	int	ecuio_shared;
    126  1.1  thorpej };
    127  1.1  thorpej 
    128  1.1  thorpej struct ecu_func {
    129  1.1  thorpej 	SIMPLEQ_ENTRY(ecu_func) ecuf_list;
    130  1.1  thorpej 	int ecuf_funcno;
    131  1.1  thorpej 	u_int32_t ecuf_id;
    132  1.1  thorpej 	u_int16_t ecuf_slot_info;
    133  1.1  thorpej 	u_int16_t ecuf_cfg_ext;
    134  1.1  thorpej 	u_int8_t ecuf_selections[ECUF_SELECTIONS_SIZE];
    135  1.1  thorpej 	u_int8_t ecuf_func_info;
    136  1.1  thorpej 	u_int8_t ecuf_type_string[ECUF_TYPE_STRING_SIZE];
    137  1.1  thorpej 	u_int8_t ecuf_init[ECUF_INIT_ENTRY_SIZE];
    138  1.1  thorpej 	SIMPLEQ_HEAD(, ecu_mem) ecuf_mem;
    139  1.1  thorpej 	SIMPLEQ_HEAD(, ecu_irq) ecuf_irq;
    140  1.1  thorpej 	SIMPLEQ_HEAD(, ecu_dma) ecuf_dma;
    141  1.1  thorpej 	SIMPLEQ_HEAD(, ecu_io) ecuf_io;
    142  1.1  thorpej };
    143  1.1  thorpej 
    144  1.1  thorpej struct ecu_data {
    145  1.1  thorpej 	SIMPLEQ_ENTRY(ecu_data) ecud_list;
    146  1.1  thorpej 	int ecud_slot;
    147  1.1  thorpej 	u_int8_t ecud_eisaid[EISA_IDSTRINGLEN];
    148  1.1  thorpej 	u_int32_t ecud_offset;
    149  1.1  thorpej 
    150  1.1  thorpej 	/* General slot info. */
    151  1.1  thorpej 	u_int8_t ecud_slot_info;
    152  1.1  thorpej 	u_int16_t ecud_ecu_major_rev;
    153  1.1  thorpej 	u_int16_t ecud_ecu_minor_rev;
    154  1.1  thorpej 	u_int16_t ecud_cksum;
    155  1.1  thorpej 	u_int16_t ecud_ndevfuncs;
    156  1.1  thorpej 	u_int8_t ecud_funcinfo;
    157  1.1  thorpej 	u_int32_t ecud_comp_id;
    158  1.1  thorpej 
    159  1.1  thorpej 	/* The functions */
    160  1.1  thorpej 	SIMPLEQ_HEAD(, ecu_func) ecud_funcs;
    161  1.1  thorpej };
    162  1.1  thorpej 
    163  1.1  thorpej SIMPLEQ_HEAD(, ecu_data) ecu_data_list =
    164  1.1  thorpej     SIMPLEQ_HEAD_INITIALIZER(ecu_data_list);
    165  1.1  thorpej 
    166  1.1  thorpej static void
    167  1.1  thorpej ecuf_init(struct ecu_func *ecuf)
    168  1.1  thorpej {
    169  1.1  thorpej 
    170  1.1  thorpej 	memset(ecuf, 0, sizeof(*ecuf));
    171  1.1  thorpej 	SIMPLEQ_INIT(&ecuf->ecuf_mem);
    172  1.1  thorpej 	SIMPLEQ_INIT(&ecuf->ecuf_irq);
    173  1.1  thorpej 	SIMPLEQ_INIT(&ecuf->ecuf_dma);
    174  1.1  thorpej 	SIMPLEQ_INIT(&ecuf->ecuf_io);
    175  1.1  thorpej }
    176  1.1  thorpej 
    177  1.1  thorpej static void
    178  1.1  thorpej eisa_parse_mem(struct ecu_func *ecuf, u_int8_t *dp)
    179  1.1  thorpej {
    180  1.1  thorpej 	struct ecu_mem *ecum;
    181  1.1  thorpej 	int i;
    182  1.1  thorpej 
    183  1.1  thorpej 	for (i = 0; i < ECUF_MEM_ENTRY_CNT; i++) {
    184  1.1  thorpej 		ecum = malloc(sizeof(*ecum), M_DEVBUF, M_WAITOK);
    185  1.1  thorpej 
    186  1.1  thorpej 		ecum->ecum_isram = dp[0] & 0x1;
    187  1.1  thorpej 		ecum->ecum_unitsize = dp[1] & 0x3;
    188  1.1  thorpej 		ecum->ecum_decode = (dp[1] >> 2) & 0x3;
    189  1.1  thorpej 		ecum->ecum_addr = (dp[2] | (dp[3] << 8) | (dp[4] << 16)) << 8;
    190  1.1  thorpej 		ecum->ecum_size = (dp[5] | (dp[6] << 8)) << 10;
    191  1.1  thorpej 		if (ecum->ecum_size == 0)
    192  1.1  thorpej 			ecum->ecum_size = (1 << 26);
    193  1.1  thorpej 		SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_mem, ecum, ecum_list);
    194  1.1  thorpej 
    195  1.1  thorpej #if 0
    196  1.1  thorpej 		printf("MEM 0x%lx 0x%lx %d %d %d\n",
    197  1.1  thorpej 		    ecum->ecum_addr, ecum->ecum_size,
    198  1.1  thorpej 		    ecum->ecum_isram, ecum->ecum_unitsize,
    199  1.1  thorpej 		    ecum->ecum_decode);
    200  1.1  thorpej #endif
    201  1.1  thorpej 
    202  1.1  thorpej 		if ((dp[0] & 0x80) == 0)
    203  1.1  thorpej 			break;
    204  1.1  thorpej 		dp += ECUF_MEM_ENTRY_SIZE;
    205  1.1  thorpej 	}
    206  1.1  thorpej }
    207  1.1  thorpej 
    208  1.1  thorpej static void
    209  1.1  thorpej eisa_parse_irq(struct ecu_func *ecuf, u_int8_t *dp)
    210  1.1  thorpej {
    211  1.1  thorpej 	struct ecu_irq *ecui;
    212  1.1  thorpej 	int i;
    213  1.1  thorpej 
    214  1.1  thorpej 	for (i = 0; i < ECUF_IRQ_ENTRY_CNT; i++) {
    215  1.1  thorpej 		ecui = malloc(sizeof(*ecui), M_DEVBUF, M_WAITOK);
    216  1.1  thorpej 
    217  1.1  thorpej 		ecui->ecui_irq = dp[0] & 0xf;
    218  1.1  thorpej 		ecui->ecui_ist = (dp[0] & 0x20) ? IST_LEVEL : IST_EDGE;
    219  1.1  thorpej 		ecui->ecui_shared = (dp[0] & 0x40) ? 1 : 0;
    220  1.1  thorpej 		SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_irq, ecui, ecui_list);
    221  1.1  thorpej 
    222  1.1  thorpej #if 0
    223  1.1  thorpej 		printf("IRQ %d %s%s\n", ecui->ecui_irq,
    224  1.1  thorpej 		    ecui->ecui_ist == IST_LEVEL ? "level" : "edge",
    225  1.1  thorpej 		    ecui->ecui_shared ? " shared" : "");
    226  1.1  thorpej #endif
    227  1.1  thorpej 
    228  1.1  thorpej 		if ((dp[0] & 0x80) == 0)
    229  1.1  thorpej 			break;
    230  1.1  thorpej 		dp += ECUF_IRQ_ENTRY_SIZE;
    231  1.1  thorpej 	}
    232  1.1  thorpej }
    233  1.1  thorpej 
    234  1.1  thorpej static void
    235  1.1  thorpej eisa_parse_dma(struct ecu_func *ecuf, u_int8_t *dp)
    236  1.1  thorpej {
    237  1.1  thorpej 	struct ecu_dma *ecud;
    238  1.1  thorpej 	int i;
    239  1.1  thorpej 
    240  1.1  thorpej 	for (i = 0; i < ECUF_DMA_ENTRY_CNT; i++) {
    241  1.1  thorpej 		ecud = malloc(sizeof(*ecud), M_DEVBUF, M_WAITOK);
    242  1.1  thorpej 
    243  1.1  thorpej 		ecud->ecud_drq = dp[0] & 0x7;
    244  1.1  thorpej 		ecud->ecud_shared = dp[0] & 0x40;
    245  1.1  thorpej 		ecud->ecud_size = (dp[1] >> 2) & 0x3;
    246  1.1  thorpej 		ecud->ecud_timing = (dp[1] >> 4) & 0x3;
    247  1.1  thorpej 		SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_dma, ecud, ecud_list);
    248  1.1  thorpej 
    249  1.1  thorpej #if 0
    250  1.1  thorpej 		printf("DRQ %d%s %d %d\n", ecud->ecud_drq,
    251  1.1  thorpej 		    ecud->ecud_shared ? " shared" : "",
    252  1.1  thorpej 		    ecud->ecud_size, ecud->ecud_timing);
    253  1.1  thorpej #endif
    254  1.1  thorpej 
    255  1.1  thorpej 		if ((dp[0] & 0x80) == 0)
    256  1.1  thorpej 			break;
    257  1.1  thorpej 		dp += ECUF_DMA_ENTRY_SIZE;
    258  1.1  thorpej 	}
    259  1.1  thorpej }
    260  1.1  thorpej 
    261  1.1  thorpej static void
    262  1.1  thorpej eisa_parse_io(struct ecu_func *ecuf, u_int8_t *dp)
    263  1.1  thorpej {
    264  1.1  thorpej 	struct ecu_io *ecuio;
    265  1.1  thorpej 	int i;
    266  1.1  thorpej 
    267  1.1  thorpej 	for (i = 0; i < ECUF_IO_ENTRY_CNT; i++) {
    268  1.1  thorpej 		ecuio = malloc(sizeof(*ecuio), M_DEVBUF, M_WAITOK);
    269  1.1  thorpej 
    270  1.1  thorpej 		ecuio->ecuio_addr = dp[1] | (dp[2] << 8);
    271  1.1  thorpej 		ecuio->ecuio_size = (dp[0] & 0x1f) + 1;
    272  1.1  thorpej 		ecuio->ecuio_shared = (dp[0] & 0x40) ? 1 : 0;
    273  1.1  thorpej 
    274  1.1  thorpej #if 0
    275  1.1  thorpej 		printf("IO 0x%lx 0x%lx%s\n", ecuio->ecuio_addr,
    276  1.1  thorpej 		    ecuio->ecuio_size,
    277  1.1  thorpej 		    ecuio->ecuio_shared ? " shared" : "");
    278  1.1  thorpej #endif
    279  1.1  thorpej 
    280  1.1  thorpej 		if ((dp[0] & 0x80) == 0)
    281  1.1  thorpej 			break;
    282  1.1  thorpej 		dp += ECUF_IO_ENTRY_SIZE;
    283  1.1  thorpej 	}
    284  1.1  thorpej }
    285  1.1  thorpej 
    286  1.1  thorpej static void
    287  1.1  thorpej eisa_read_config_bytes(paddr_t addr, void *buf, size_t count)
    288  1.1  thorpej {
    289  1.1  thorpej 	const u_int8_t *src = (const u_int8_t *)ALPHA_PHYS_TO_K0SEG(addr);
    290  1.1  thorpej 	u_int8_t *dst = buf;
    291  1.1  thorpej 
    292  1.1  thorpej 	for (; count != 0; count--) {
    293  1.1  thorpej 		*dst++ = *src;
    294  1.1  thorpej 		src += eisa_config_stride;
    295  1.1  thorpej 	}
    296  1.1  thorpej }
    297  1.1  thorpej 
    298  1.1  thorpej static void
    299  1.1  thorpej eisa_read_config_word(paddr_t addr, u_int32_t *valp)
    300  1.1  thorpej {
    301  1.1  thorpej 	const u_int8_t *src = (const u_int8_t *)ALPHA_PHYS_TO_K0SEG(addr);
    302  1.1  thorpej 	u_int32_t val = 0;
    303  1.1  thorpej 	int i;
    304  1.1  thorpej 
    305  1.1  thorpej 	for (i = 0; i < sizeof(val); i++) {
    306  1.1  thorpej 		val |= (u_int)(*src << (i * 8));
    307  1.1  thorpej 		src += eisa_config_stride;
    308  1.1  thorpej 	}
    309  1.1  thorpej 
    310  1.1  thorpej 	*valp = val;
    311  1.1  thorpej }
    312  1.1  thorpej 
    313  1.1  thorpej static size_t
    314  1.1  thorpej eisa_uncompress(void *cbufp, void *ucbufp, size_t count)
    315  1.1  thorpej {
    316  1.1  thorpej 	const u_int8_t *cbuf = cbufp;
    317  1.1  thorpej 	u_int8_t *ucbuf = ucbufp;
    318  1.1  thorpej 	u_int zeros = 0;
    319  1.1  thorpej 
    320  1.1  thorpej 	while (count--) {
    321  1.1  thorpej 		if (zeros) {
    322  1.1  thorpej 			zeros--;
    323  1.1  thorpej 			*ucbuf++ = '\0';
    324  1.1  thorpej 		} else if (*cbuf == '\0') {
    325  1.1  thorpej 			*ucbuf++ = *cbuf++;
    326  1.1  thorpej 			zeros = *cbuf++ - 1;
    327  1.1  thorpej 		} else
    328  1.1  thorpej 			*ucbuf++ = *cbuf++;
    329  1.1  thorpej 	}
    330  1.1  thorpej 
    331  1.1  thorpej 	return ((size_t)cbuf - (size_t)cbufp);
    332  1.1  thorpej }
    333  1.1  thorpej 
    334  1.1  thorpej void
    335  1.1  thorpej eisa_init()
    336  1.1  thorpej {
    337  1.1  thorpej 	struct ecu_data *ecud;
    338  1.1  thorpej 	paddr_t cfgaddr;
    339  1.1  thorpej 	u_int32_t offset;
    340  1.1  thorpej 	u_int8_t eisaid[EISA_IDSTRINGLEN];
    341  1.1  thorpej 	u_int8_t *cdata, *data;
    342  1.1  thorpej 	u_int8_t *cdp, *dp;
    343  1.1  thorpej 	struct ecu_func *ecuf;
    344  1.1  thorpej 	int i, func;
    345  1.1  thorpej 
    346  1.1  thorpej 	/*
    347  1.1  thorpej 	 * Locate EISA configuration space.
    348  1.1  thorpej 	 */
    349  1.1  thorpej 	if (hwrpb->rpb_condat_off == 0UL ||
    350  1.1  thorpej 	    (hwrpb->rpb_condat_off >> 63) != 0) {
    351  1.1  thorpej 		printf(": WARNING: no EISA configuration space");
    352  1.1  thorpej 		return;
    353  1.1  thorpej 	}
    354  1.1  thorpej 
    355  1.1  thorpej 	if (eisa_config_header_addr) {
    356  1.1  thorpej 		printf("\n");
    357  1.1  thorpej 		panic("eisa_init: EISA config space already initialized");
    358  1.1  thorpej 	}
    359  1.1  thorpej 
    360  1.1  thorpej 	eisa_config_header_addr = hwrpb->rpb_condat_off;
    361  1.1  thorpej #if 0
    362  1.1  thorpej 	printf("\nEISA config header at 0x%lx\n", eisa_config_header_addr);
    363  1.1  thorpej #endif
    364  1.1  thorpej 	if (eisa_config_stride == 0)
    365  1.1  thorpej 		eisa_config_stride = 1;
    366  1.1  thorpej 
    367  1.1  thorpej 	/*
    368  1.1  thorpej 	 * Read the slot headers, and allocate config structures for
    369  1.1  thorpej 	 * valid slots.
    370  1.1  thorpej 	 */
    371  1.1  thorpej 	for (cfgaddr = eisa_config_header_addr, i = 0; i < 16 /* XXX */; i++) {
    372  1.1  thorpej 		eisa_read_config_bytes(cfgaddr, eisaid, sizeof(eisaid));
    373  1.1  thorpej 		eisaid[EISA_IDSTRINGLEN - 1] = '\0';	/* sanity */
    374  1.1  thorpej 		cfgaddr += sizeof(eisaid) * eisa_config_stride;
    375  1.1  thorpej 		eisa_read_config_word(cfgaddr, &offset);
    376  1.1  thorpej 		cfgaddr += sizeof(offset) * eisa_config_stride;
    377  1.1  thorpej 
    378  1.1  thorpej 		if (offset != 0) {
    379  1.1  thorpej #if 0
    380  1.1  thorpej 			printf("SLOT %d: offset 0x%08x eisaid %s\n",
    381  1.1  thorpej 			    i, offset, eisaid);
    382  1.1  thorpej #endif
    383  1.1  thorpej 			ecud = malloc(sizeof(*ecud), M_DEVBUF, M_WAITOK);
    384  1.1  thorpej 			memset(ecud, 0, sizeof(*ecud));
    385  1.1  thorpej 
    386  1.1  thorpej 			SIMPLEQ_INIT(&ecud->ecud_funcs);
    387  1.1  thorpej 
    388  1.1  thorpej 			ecud->ecud_slot = i;
    389  1.1  thorpej 			memcpy(ecud->ecud_eisaid, eisaid, sizeof(eisaid));
    390  1.1  thorpej 			ecud->ecud_offset = offset;
    391  1.1  thorpej 			SIMPLEQ_INSERT_TAIL(&ecu_data_list, ecud, ecud_list);
    392  1.1  thorpej 		}
    393  1.1  thorpej 	}
    394  1.1  thorpej 
    395  1.1  thorpej 	/*
    396  1.1  thorpej 	 * Now traverse the valid slots and read the info.
    397  1.1  thorpej 	 */
    398  1.1  thorpej 
    399  1.1  thorpej 	cdata = malloc(512, M_TEMP, M_WAITOK);
    400  1.1  thorpej 	data = malloc(512, M_TEMP, M_WAITOK);
    401  1.1  thorpej 
    402  1.1  thorpej 	for (ecud = SIMPLEQ_FIRST(&ecu_data_list); ecud != NULL;
    403  1.1  thorpej 	     ecud = SIMPLEQ_NEXT(ecud, ecud_list)) {
    404  1.1  thorpej 		cfgaddr = eisa_config_addr + ecud->ecud_offset;
    405  1.1  thorpej 		eisa_read_config_bytes(cfgaddr, &cdata[0], 1);
    406  1.1  thorpej 		cfgaddr += eisa_config_stride;
    407  1.1  thorpej 
    408  1.1  thorpej 		for (i = 1; ; cfgaddr += eisa_config_stride, i++) {
    409  1.1  thorpej 			eisa_read_config_bytes(cfgaddr, &cdata[i], 1);
    410  1.1  thorpej 			if (cdata[i - 1] == 0 && cdata[i] == 0)
    411  1.1  thorpej 				break;
    412  1.1  thorpej 		}
    413  1.1  thorpej 		i++;	/* index -> length */
    414  1.1  thorpej 
    415  1.1  thorpej #if 0
    416  1.1  thorpej 		printf("SLOT %d compressed data length %d:",
    417  1.1  thorpej 		    ecud->ecud_slot, i);
    418  1.1  thorpej 		{
    419  1.1  thorpej 			int j;
    420  1.1  thorpej 
    421  1.1  thorpej 			for (j = 0; j < i; j++) {
    422  1.1  thorpej 				if ((j % 16) == 0)
    423  1.1  thorpej 					printf("\n");
    424  1.1  thorpej 				printf("0x%02x ", cdata[j]);
    425  1.1  thorpej 			}
    426  1.1  thorpej 			printf("\n");
    427  1.1  thorpej 		}
    428  1.1  thorpej #endif
    429  1.1  thorpej 
    430  1.1  thorpej 		cdp = cdata;
    431  1.1  thorpej 		dp = data;
    432  1.1  thorpej 
    433  1.1  thorpej 		/* Uncompress the slot header. */
    434  1.1  thorpej 		cdp += eisa_uncompress(cdp, dp, EISA_SLOT_HEADER_SIZE);
    435  1.1  thorpej #if 0
    436  1.1  thorpej 		printf("SLOT %d uncompressed header data:",
    437  1.1  thorpej 		    ecud->ecud_slot);
    438  1.1  thorpej 		{
    439  1.1  thorpej 			int j;
    440  1.1  thorpej 
    441  1.1  thorpej 			for (j = 0; j < EISA_SLOT_HEADER_SIZE; j++) {
    442  1.1  thorpej 				if ((j % 16) == 0)
    443  1.1  thorpej 					printf("\n");
    444  1.1  thorpej 				printf("0x%02x ", dp[j]);
    445  1.1  thorpej 			}
    446  1.1  thorpej 			printf("\n");
    447  1.1  thorpej 		}
    448  1.1  thorpej #endif
    449  1.1  thorpej 
    450  1.1  thorpej 		dp = &data[EISA_SLOT_INFO_OFFSET];
    451  1.1  thorpej 		ecud->ecud_slot_info = *dp++;
    452  1.1  thorpej 		ecud->ecud_ecu_major_rev = *dp++;
    453  1.1  thorpej 		ecud->ecud_ecu_minor_rev = *dp++;
    454  1.1  thorpej 		memcpy(&ecud->ecud_cksum, dp, sizeof(ecud->ecud_cksum));
    455  1.1  thorpej 		dp += sizeof(ecud->ecud_cksum);
    456  1.1  thorpej 		ecud->ecud_ndevfuncs = *dp++;
    457  1.1  thorpej 		ecud->ecud_funcinfo = *dp++;
    458  1.1  thorpej 		memcpy(&ecud->ecud_comp_id, dp, sizeof(ecud->ecud_comp_id));
    459  1.1  thorpej 		dp += sizeof(ecud->ecud_comp_id);
    460  1.1  thorpej 
    461  1.1  thorpej #if 0
    462  1.1  thorpej 		printf("SLOT %d: ndevfuncs %d\n", ecud->ecud_slot,
    463  1.1  thorpej 		    ecud->ecud_ndevfuncs);
    464  1.1  thorpej #endif
    465  1.1  thorpej 
    466  1.1  thorpej 		for (func = 0; func < ecud->ecud_ndevfuncs; func++) {
    467  1.1  thorpej 			dp = data;
    468  1.1  thorpej 			cdp += eisa_uncompress(cdp, dp, EISA_CONFIG_BLOCK_SIZE);
    469  1.1  thorpej #if 0
    470  1.1  thorpej 			printf("SLOT %d:%d uncompressed data:",
    471  1.1  thorpej 			    ecud->ecud_slot, func);
    472  1.1  thorpej 			{
    473  1.1  thorpej 				int j;
    474  1.1  thorpej 
    475  1.1  thorpej 				for (j = 0; i < EISA_CONFIG_BLOCK_SIZE; j++) {
    476  1.1  thorpej 					if ((j % 16) == 0)
    477  1.1  thorpej 						printf("\n");
    478  1.1  thorpej 					printf("0x%02x ", dp[j]);
    479  1.1  thorpej 				}
    480  1.1  thorpej 				printf("\n");
    481  1.1  thorpej 			}
    482  1.1  thorpej #endif
    483  1.1  thorpej 
    484  1.1  thorpej 			/* Skip disabled functions. */
    485  1.1  thorpej 			if (dp[EISA_FUNC_INFO_OFFSET] & ECUF_DISABLED) {
    486  1.1  thorpej 				printf("SLOT %d:%d disabled\n",
    487  1.1  thorpej 				    ecud->ecud_slot, func);
    488  1.1  thorpej 				continue;
    489  1.1  thorpej 			}
    490  1.1  thorpej 
    491  1.1  thorpej 			ecuf = malloc(sizeof(*ecuf), M_DEVBUF, M_WAITOK);
    492  1.1  thorpej 			ecuf_init(ecuf);
    493  1.1  thorpej 			ecuf->ecuf_funcno = func;
    494  1.1  thorpej 			SIMPLEQ_INSERT_TAIL(&ecud->ecud_funcs, ecuf,
    495  1.1  thorpej 			    ecuf_list);
    496  1.1  thorpej 
    497  1.1  thorpej 			memcpy(&ecuf->ecuf_id, dp, sizeof(ecuf->ecuf_id));
    498  1.1  thorpej 			dp += sizeof(ecuf->ecuf_id);
    499  1.1  thorpej 
    500  1.1  thorpej 			memcpy(&ecuf->ecuf_slot_info, dp,
    501  1.1  thorpej 			    sizeof(ecuf->ecuf_slot_info));
    502  1.1  thorpej 			dp += sizeof(ecuf->ecuf_slot_info);
    503  1.1  thorpej 
    504  1.1  thorpej 			memcpy(&ecuf->ecuf_cfg_ext, dp,
    505  1.1  thorpej 			    sizeof(ecuf->ecuf_cfg_ext));
    506  1.1  thorpej 			dp += sizeof(ecuf->ecuf_cfg_ext);
    507  1.1  thorpej 
    508  1.1  thorpej 			memcpy(&ecuf->ecuf_selections, dp,
    509  1.1  thorpej 			    sizeof(ecuf->ecuf_selections));
    510  1.1  thorpej 			dp += sizeof(ecuf->ecuf_selections);
    511  1.1  thorpej 
    512  1.1  thorpej 			memcpy(&ecuf->ecuf_func_info, dp,
    513  1.1  thorpej 			    sizeof(ecuf->ecuf_func_info));
    514  1.1  thorpej 			dp += sizeof(ecuf->ecuf_func_info);
    515  1.1  thorpej 
    516  1.1  thorpej 			if (ecuf->ecuf_func_info & ECUF_TYPE_STRING)
    517  1.1  thorpej 				memcpy(ecuf->ecuf_type_string, dp,
    518  1.1  thorpej 				    sizeof(ecuf->ecuf_type_string));
    519  1.1  thorpej 			dp += sizeof(ecuf->ecuf_type_string);
    520  1.1  thorpej 
    521  1.1  thorpej 			if (ecuf->ecuf_func_info & ECUF_MEM_ENTRY)
    522  1.1  thorpej 				eisa_parse_mem(ecuf, dp);
    523  1.1  thorpej 			dp += ECUF_MEM_ENTRY_SIZE * ECUF_MEM_ENTRY_CNT;
    524  1.1  thorpej 
    525  1.1  thorpej 			if (ecuf->ecuf_func_info & ECUF_IRQ_ENTRY)
    526  1.1  thorpej 				eisa_parse_irq(ecuf, dp);
    527  1.1  thorpej 			dp += ECUF_IRQ_ENTRY_SIZE * ECUF_IRQ_ENTRY_CNT;
    528  1.1  thorpej 
    529  1.1  thorpej 			if (ecuf->ecuf_func_info & ECUF_DMA_ENTRY)
    530  1.1  thorpej 				eisa_parse_dma(ecuf, dp);
    531  1.1  thorpej 			dp += ECUF_DMA_ENTRY_SIZE * ECUF_DMA_ENTRY_CNT;
    532  1.1  thorpej 
    533  1.1  thorpej 			if (ecuf->ecuf_func_info & ECUF_IO_ENTRY)
    534  1.1  thorpej 				eisa_parse_io(ecuf, dp);
    535  1.1  thorpej 			dp += ECUF_IO_ENTRY_SIZE * ECUF_IO_ENTRY_CNT;
    536  1.1  thorpej 
    537  1.1  thorpej 			if (ecuf->ecuf_func_info & ECUF_INIT_ENTRY)
    538  1.1  thorpej 				memcpy(ecuf->ecuf_init, dp,
    539  1.1  thorpej 				    sizeof(ecuf->ecuf_init));
    540  1.1  thorpej 			dp += sizeof(ecuf->ecuf_init);
    541  1.1  thorpej 		}
    542  1.1  thorpej 	}
    543  1.1  thorpej 
    544  1.1  thorpej 	free(cdata, M_TEMP);
    545  1.1  thorpej 	free(data, M_TEMP);
    546  1.1  thorpej }
    547