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