Home | History | Annotate | Line # | Download | only in pnpbios
pnpbios.c revision 1.2
      1  1.2   thorpej /* $NetBSD: pnpbios.c,v 1.2 1999/11/14 02:15:51 thorpej Exp $ */
      2  1.1  drochner /*
      3  1.1  drochner  * Copyright (c) 1999
      4  1.1  drochner  * 	Matthias Drochner.  All rights reserved.
      5  1.1  drochner  *
      6  1.1  drochner  * Redistribution and use in source and binary forms, with or without
      7  1.1  drochner  * modification, are permitted provided that the following conditions
      8  1.1  drochner  * are met:
      9  1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     10  1.1  drochner  *    notice, this list of conditions, and the following disclaimer.
     11  1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  drochner  *    documentation and/or other materials provided with the distribution.
     14  1.1  drochner  *
     15  1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  drochner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  drochner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  drochner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  drochner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  drochner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  drochner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  drochner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  drochner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  drochner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  drochner  * SUCH DAMAGE.
     26  1.1  drochner  */
     27  1.1  drochner 
     28  1.1  drochner #include <sys/param.h>
     29  1.1  drochner #include <sys/systm.h>
     30  1.1  drochner #include <sys/device.h>
     31  1.1  drochner #include <sys/malloc.h>
     32  1.1  drochner #include <dev/isa/isareg.h>
     33  1.1  drochner #include <machine/isa_machdep.h>
     34  1.1  drochner #include <machine/segments.h>
     35  1.1  drochner #include <vm/vm.h>
     36  1.1  drochner #include <vm/vm_kern.h>
     37  1.1  drochner 
     38  1.1  drochner #include <arch/i386/pnpbios/pnpbiosvar.h>
     39  1.1  drochner 
     40  1.1  drochner #include "opt_pnpbiosverbose.h"
     41  1.2   thorpej #include "locators.h"
     42  1.1  drochner 
     43  1.1  drochner struct pnpbios_softc {
     44  1.1  drochner 	struct device sc_dev;
     45  1.1  drochner 	isa_chipset_tag_t sc_ic;
     46  1.1  drochner };
     47  1.1  drochner 
     48  1.1  drochner static caddr_t pnpbios_find __P((void));
     49  1.1  drochner static int pnpbios_match __P((struct device *, struct cfdata *, void *));
     50  1.1  drochner static void pnpbios_attach __P((struct device *, struct device *, void *));
     51  1.1  drochner static void pnpbios_printres __P((struct pnpresources *));
     52  1.1  drochner static int pnpbios_print __P((void *, const char *));
     53  1.1  drochner static int pnpbios_getnumnodes __P((int *, size_t *));
     54  1.1  drochner static int pnpbios_getnode __P((int, int *, unsigned char *, size_t));
     55  1.1  drochner static void eisaid_to_string __P((unsigned char *, char *));
     56  1.2   thorpej static void pnpbios_attachnode __P((struct pnpbios_softc *, int,
     57  1.1  drochner 				    unsigned char *, size_t));
     58  1.1  drochner static int pnp_scan __P((unsigned char **, size_t, struct pnpresources *, int));
     59  1.1  drochner 
     60  1.2   thorpej static int pnpbios_submatch __P((struct device *, struct cfdata *, void *));
     61  1.2   thorpej 
     62  1.1  drochner extern int pnpbioscall __P((int));
     63  1.1  drochner 
     64  1.1  drochner struct cfattach pnpbios_ca = {
     65  1.1  drochner 	sizeof(struct pnpbios_softc), pnpbios_match, pnpbios_attach
     66  1.1  drochner };
     67  1.1  drochner 
     68  1.1  drochner /*
     69  1.1  drochner  * Private stack and return value buffer. Spec (1.0a, ch. 4.3) says that
     70  1.1  drochner  * 1024 bytes must be available to the BIOS function.
     71  1.1  drochner  */
     72  1.1  drochner #define PNPBIOS_BUFSIZE 4096
     73  1.1  drochner 
     74  1.1  drochner int pnpbios_enabled = 1;
     75  1.1  drochner size_t pnpbios_entry;
     76  1.1  drochner caddr_t pnpbios_scratchbuf;
     77  1.1  drochner 
     78  1.2   thorpej /*
     79  1.2   thorpej  * There can be only one of these, and the i386 ISA code needs to
     80  1.2   thorpej  * reference this.
     81  1.2   thorpej  */
     82  1.2   thorpej struct pnpbios_softc *pnpbios_softc;
     83  1.2   thorpej 
     84  1.1  drochner #define PNPBIOS_SIGNATURE ('$' | ('P' << 8) | ('n' << 16) | ('P' << 24))
     85  1.1  drochner 
     86  1.1  drochner static caddr_t
     87  1.1  drochner pnpbios_find()
     88  1.1  drochner {
     89  1.1  drochner 	caddr_t p, c;
     90  1.1  drochner 	unsigned char cksum;
     91  1.1  drochner 	size_t structlen;
     92  1.1  drochner 
     93  1.1  drochner 	for (p = (caddr_t)ISA_HOLE_VADDR(0xf0000);
     94  1.1  drochner 	     p <= (caddr_t)ISA_HOLE_VADDR(0xffff0);
     95  1.1  drochner 	     p += 16) {
     96  1.1  drochner 		if (*(int *)p != PNPBIOS_SIGNATURE)
     97  1.1  drochner 			continue;
     98  1.1  drochner 		structlen = *(unsigned char *)(p + 5);
     99  1.1  drochner 		if ((structlen < 0x21) ||
    100  1.1  drochner 		    ((p + structlen - 1) > (caddr_t)ISA_HOLE_VADDR(0xfffff)))
    101  1.1  drochner 			continue;
    102  1.1  drochner 
    103  1.1  drochner 		cksum = 0;
    104  1.1  drochner 		for (c = p; c < p + structlen; c++)
    105  1.1  drochner 			cksum += *(unsigned char *)c;
    106  1.1  drochner 		if (cksum != 0)
    107  1.1  drochner 			continue;
    108  1.1  drochner 
    109  1.1  drochner 		if (*(char *)(p + 4) != 0x10) {
    110  1.1  drochner 			printf("unknown version %x\n", *(char *)(p + 4));
    111  1.1  drochner 			continue;
    112  1.1  drochner 		}
    113  1.1  drochner 
    114  1.1  drochner 		return (p);
    115  1.1  drochner 	}
    116  1.1  drochner 
    117  1.1  drochner 	return (0);
    118  1.1  drochner }
    119  1.1  drochner 
    120  1.1  drochner int
    121  1.1  drochner pnpbios_probe()
    122  1.1  drochner {
    123  1.1  drochner 
    124  1.1  drochner 	return (pnpbios_find() != 0);
    125  1.1  drochner }
    126  1.1  drochner 
    127  1.1  drochner static int
    128  1.1  drochner pnpbios_match(parent, match, aux)
    129  1.1  drochner 	struct device *parent;
    130  1.1  drochner 	struct cfdata *match;
    131  1.1  drochner 	void *aux;
    132  1.1  drochner {
    133  1.1  drochner 	struct pnpbios_attach_args *paa = aux;
    134  1.1  drochner 
    135  1.1  drochner 	/* These are not the droids you're looking for. */
    136  1.1  drochner 	if (strcmp(paa->paa_busname, "pnpbios") != 0)
    137  1.1  drochner 		return (0);
    138  1.1  drochner 
    139  1.1  drochner 	/* There can be only one! */
    140  1.2   thorpej 	if (pnpbios_softc != NULL)
    141  1.1  drochner 		return (0);
    142  1.1  drochner 
    143  1.1  drochner 	return (pnpbios_enabled);
    144  1.1  drochner }
    145  1.1  drochner 
    146  1.1  drochner static caddr_t mapit __P((u_long, u_long, int));
    147  1.1  drochner 
    148  1.1  drochner static caddr_t
    149  1.1  drochner mapit(addr, len, prot)
    150  1.1  drochner 	u_long addr, len;
    151  1.1  drochner 	int prot;
    152  1.1  drochner {
    153  1.1  drochner 	u_long startpa, pa, endpa;
    154  1.1  drochner 	vaddr_t startva, va;
    155  1.1  drochner 
    156  1.1  drochner 	pa = startpa = i386_trunc_page(addr);
    157  1.1  drochner 	endpa = i386_round_page(addr + len);
    158  1.1  drochner 
    159  1.1  drochner 	va = startva = uvm_km_valloc(kernel_map, endpa - startpa);
    160  1.1  drochner 	if (!startva)
    161  1.1  drochner 		return (0);
    162  1.1  drochner 	for (; pa < endpa; pa += NBPG, va += NBPG)
    163  1.1  drochner 		pmap_kenter_pa(va, pa, prot);
    164  1.1  drochner 
    165  1.1  drochner 	return ((caddr_t)(startva + (addr - startpa)));
    166  1.1  drochner }
    167  1.1  drochner 
    168  1.1  drochner static void
    169  1.1  drochner pnpbios_attach(parent, self, aux)
    170  1.1  drochner 	struct device *parent, *self;
    171  1.1  drochner 	void *aux;
    172  1.1  drochner {
    173  1.1  drochner 	struct pnpbios_softc *sc = (struct pnpbios_softc *)self;
    174  1.1  drochner 	struct pnpbios_attach_args *paa = aux;
    175  1.1  drochner 	caddr_t p;
    176  1.1  drochner 	unsigned int codepbase, datapbase;
    177  1.1  drochner 	caddr_t codeva, datava;
    178  1.1  drochner 	extern char pnpbiostramp[], epnpbiostramp[];
    179  1.1  drochner 	int res, num, i, size, idx;
    180  1.1  drochner 	unsigned char *buf;
    181  1.1  drochner 
    182  1.2   thorpej 	pnpbios_softc = sc;
    183  1.1  drochner 	sc->sc_ic = paa->paa_ic;
    184  1.1  drochner 
    185  1.1  drochner 	isa_dmainit(sc->sc_ic, I386_BUS_SPACE_IO, &isa_bus_dma_tag, self);
    186  1.1  drochner 
    187  1.1  drochner 	p = pnpbios_find();
    188  1.1  drochner 	if (!p)
    189  1.1  drochner 		panic("pnpbios_attach: disappeared");
    190  1.1  drochner 
    191  1.1  drochner 	codepbase = *(unsigned int *)(p + 0x13);
    192  1.1  drochner 	datapbase = *(unsigned int *)(p + 0x1d);
    193  1.1  drochner 	pnpbios_entry = *(unsigned short *)(p + 0x11);
    194  1.1  drochner 
    195  1.1  drochner #ifdef PNPBIOSVERBOSE
    196  1.1  drochner 	printf(": code %x, data %x, entry %x\n%s",
    197  1.1  drochner 		codepbase, datapbase, pnpbios_entry, self->dv_xname);
    198  1.1  drochner #endif
    199  1.1  drochner 
    200  1.1  drochner 	codeva = mapit(codepbase, 0x10000,
    201  1.1  drochner 		VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
    202  1.1  drochner 	datava = mapit(datapbase, 0x10000,
    203  1.1  drochner 		VM_PROT_READ | VM_PROT_WRITE);
    204  1.1  drochner 	if (codeva == 0 || datava == 0) {
    205  1.1  drochner 		printf("no vm for mapping\n");
    206  1.1  drochner 		return;
    207  1.1  drochner 	}
    208  1.1  drochner 	pnpbios_scratchbuf = malloc(PNPBIOS_BUFSIZE, M_DEVBUF, M_NOWAIT);
    209  1.1  drochner 
    210  1.1  drochner 	setsegment(&gdt[GPNPBIOSCODE_SEL].sd, codeva, 0xffff,
    211  1.1  drochner 		   SDT_MEMERA, SEL_KPL, 0, 0);
    212  1.1  drochner 	setsegment(&gdt[GPNPBIOSDATA_SEL].sd, datava, 0xffff,
    213  1.1  drochner 		   SDT_MEMRWA, SEL_KPL, 0, 0);
    214  1.1  drochner 	setsegment(&gdt[GPNPBIOSSCRATCH_SEL].sd,
    215  1.1  drochner 		   pnpbios_scratchbuf, PNPBIOS_BUFSIZE - 1,
    216  1.1  drochner 		   SDT_MEMRWA, SEL_KPL, 0, 0);
    217  1.1  drochner 	setsegment(&gdt[GPNPBIOSTRAMP_SEL].sd,
    218  1.1  drochner 		   pnpbiostramp, epnpbiostramp - pnpbiostramp - 1,
    219  1.1  drochner 		   SDT_MEMERA, SEL_KPL, 1, 0);
    220  1.1  drochner 
    221  1.1  drochner 	res = pnpbios_getnumnodes(&num, &size);
    222  1.1  drochner 	if (res) {
    223  1.1  drochner 		printf("pnpbios_getnumnodes: error %d\n", res);
    224  1.1  drochner 		return;
    225  1.1  drochner 	}
    226  1.1  drochner 
    227  1.1  drochner 	printf(": %d nodes, max len %d\n", num, size);
    228  1.1  drochner 	buf = malloc(size, M_DEVBUF, M_NOWAIT);
    229  1.1  drochner 
    230  1.1  drochner 	idx = 0;
    231  1.1  drochner 	for (i = 0; i < num; i++) {
    232  1.1  drochner 		res = pnpbios_getnode(1, &idx, buf, size);
    233  1.1  drochner 		if (res) {
    234  1.1  drochner 			printf("pnpbios_getnode: error %d\n", res);
    235  1.1  drochner 			continue;
    236  1.1  drochner 		}
    237  1.2   thorpej 		pnpbios_attachnode(sc, idx, buf, buf[0] + (buf[1] << 8));
    238  1.1  drochner 	}
    239  1.1  drochner 	if (idx != 0xff)
    240  1.1  drochner 		printf("last idx=%x\n", idx);
    241  1.1  drochner 
    242  1.1  drochner 	free(buf, M_DEVBUF);
    243  1.1  drochner }
    244  1.1  drochner 
    245  1.1  drochner static int
    246  1.1  drochner pnpbios_getnumnodes(nump, sizep)
    247  1.1  drochner 	int *nump;
    248  1.1  drochner 	size_t *sizep;
    249  1.1  drochner {
    250  1.1  drochner 	int res;
    251  1.1  drochner 	short *help = (short *)(pnpbios_scratchbuf + PNPBIOS_BUFSIZE);
    252  1.1  drochner 
    253  1.1  drochner 	*--help = GSEL(GPNPBIOSDATA_SEL, SEL_KPL);
    254  1.1  drochner 	*--help = GSEL(GPNPBIOSSCRATCH_SEL, SEL_KPL);
    255  1.1  drochner 	*--help = 2; /* buffer offset for node size */
    256  1.1  drochner 	*--help = GSEL(GPNPBIOSSCRATCH_SEL, SEL_KPL);
    257  1.1  drochner 	*--help = 0; /* buffer offset for numnodes */
    258  1.1  drochner 	*--help = 0; /* GET_NUM_NODES */
    259  1.1  drochner 
    260  1.1  drochner 	res = pnpbioscall(((caddr_t)help) - pnpbios_scratchbuf);
    261  1.1  drochner 	if (res)
    262  1.1  drochner 		return (res);
    263  1.1  drochner 
    264  1.1  drochner 	*nump = *(short *)(pnpbios_scratchbuf + 0);
    265  1.1  drochner 	*sizep = *(short *)(pnpbios_scratchbuf + 2);
    266  1.1  drochner 	return (0);
    267  1.1  drochner }
    268  1.1  drochner 
    269  1.1  drochner static int
    270  1.1  drochner pnpbios_getnode(flags, idxp, buf, len)
    271  1.1  drochner 	int flags;
    272  1.1  drochner 	int *idxp;
    273  1.1  drochner 	unsigned char *buf;
    274  1.1  drochner 	size_t len;
    275  1.1  drochner {
    276  1.1  drochner 	int res;
    277  1.1  drochner 	short *help = (short *)(pnpbios_scratchbuf + PNPBIOS_BUFSIZE);
    278  1.1  drochner 
    279  1.1  drochner 	*--help = GSEL(GPNPBIOSDATA_SEL, SEL_KPL);
    280  1.1  drochner 	*--help = flags;
    281  1.1  drochner 	*--help = GSEL(GPNPBIOSSCRATCH_SEL, SEL_KPL);
    282  1.1  drochner 	*--help = 2; /* buffer offset for node data */
    283  1.1  drochner 	*--help = GSEL(GPNPBIOSSCRATCH_SEL, SEL_KPL);
    284  1.1  drochner 	*--help = 0; /* buffer offset for index in/out */
    285  1.1  drochner 	*--help = 1; /* GET_DEVICE_NODE */
    286  1.1  drochner 
    287  1.1  drochner 	*(short *)(pnpbios_scratchbuf + 0) = *idxp;
    288  1.1  drochner 
    289  1.1  drochner 	res = pnpbioscall(((caddr_t)help) - pnpbios_scratchbuf);
    290  1.1  drochner 	if (res)
    291  1.1  drochner 		return (res);
    292  1.1  drochner 
    293  1.1  drochner 	*idxp = *(short *)(pnpbios_scratchbuf + 0);
    294  1.1  drochner 	bcopy(pnpbios_scratchbuf + 2, buf, len);
    295  1.1  drochner 	return (0);
    296  1.1  drochner }
    297  1.1  drochner 
    298  1.1  drochner static void
    299  1.1  drochner eisaid_to_string(id, s)
    300  1.1  drochner 	unsigned char *id;
    301  1.1  drochner 	char *s;
    302  1.1  drochner {
    303  1.1  drochner 	static char hex[] = "0123456789ABCDEF";
    304  1.1  drochner 
    305  1.1  drochner 	*s++ = 'A' + (id[0] >> 2) - 1;
    306  1.1  drochner 	*s++ = 'A' + ((id[0] & 3) << 3) + (id[1] >> 5) - 1;
    307  1.1  drochner 	*s++ = 'A' + (id[1] & 0x1f) - 1;
    308  1.1  drochner 	*s++ = hex[id[2] >> 4];
    309  1.1  drochner 	*s++ = hex[id[2] & 0x0f];
    310  1.1  drochner 	*s++ = hex[id[3] >> 4];
    311  1.1  drochner 	*s++ = hex[id[3] & 0x0f];
    312  1.1  drochner 	*s = '\0';
    313  1.1  drochner }
    314  1.1  drochner 
    315  1.1  drochner static void
    316  1.1  drochner pnpbios_printres(r)
    317  1.1  drochner 	struct pnpresources *r;
    318  1.1  drochner {
    319  1.1  drochner 	struct pnp_mem *mem;
    320  1.1  drochner 	struct pnp_io *io;
    321  1.1  drochner 	struct pnp_irq *irq;
    322  1.1  drochner 	struct pnp_dma *dma;
    323  1.1  drochner 	int p = 0;
    324  1.1  drochner 
    325  1.1  drochner 	mem = SIMPLEQ_FIRST(&r->mem);
    326  1.1  drochner 	if (mem) {
    327  1.1  drochner 		printf("mem");
    328  1.1  drochner 		do {
    329  1.1  drochner 			printf(" %x", mem->minbase);
    330  1.1  drochner 			if (mem->len > 1)
    331  1.1  drochner 				printf("-%x", mem->minbase + mem->len - 1);
    332  1.1  drochner 		} while ((mem = SIMPLEQ_NEXT(mem, next)));
    333  1.1  drochner 		p++;
    334  1.1  drochner 	}
    335  1.1  drochner 	io = SIMPLEQ_FIRST(&r->io);
    336  1.1  drochner 	if (io) {
    337  1.1  drochner 		if (p++)
    338  1.1  drochner 			printf(", ");
    339  1.1  drochner 		printf("io");
    340  1.1  drochner 		do {
    341  1.1  drochner 			printf(" %x", io->minbase);
    342  1.1  drochner 			if (io->len > 1)
    343  1.1  drochner 				printf("-%x", io->minbase + io->len - 1);
    344  1.1  drochner 		} while ((io = SIMPLEQ_NEXT(io, next)));
    345  1.1  drochner 	}
    346  1.1  drochner 	irq = SIMPLEQ_FIRST(&r->irq);
    347  1.1  drochner 	if (irq) {
    348  1.1  drochner 		if (p++)
    349  1.1  drochner 			printf(", ");
    350  1.1  drochner 		printf("irq");
    351  1.1  drochner 		do {
    352  1.1  drochner 			printf(" %d", ffs(irq->mask) - 1);
    353  1.1  drochner 		} while ((irq = SIMPLEQ_NEXT(irq, next)));
    354  1.1  drochner 	}
    355  1.1  drochner 	dma = SIMPLEQ_FIRST(&r->dma);
    356  1.1  drochner 	if (dma) {
    357  1.1  drochner 		if (p)
    358  1.1  drochner 			printf(", ");
    359  1.1  drochner 		printf("dma");
    360  1.1  drochner 		do {
    361  1.1  drochner 			printf(" %d", ffs(dma->mask) - 1);
    362  1.1  drochner 		} while ((dma = SIMPLEQ_NEXT(dma, next)));
    363  1.1  drochner 	}
    364  1.1  drochner }
    365  1.1  drochner 
    366  1.1  drochner static int
    367  1.1  drochner pnpbios_print(aux, pnp)
    368  1.1  drochner 	void *aux;
    369  1.1  drochner 	const char *pnp;
    370  1.1  drochner {
    371  1.1  drochner 	struct pnpbiosdev_attach_args *aa = aux;
    372  1.1  drochner 
    373  1.1  drochner 	if (pnp)
    374  1.1  drochner 		return (QUIET);
    375  1.1  drochner 
    376  1.2   thorpej 	printf(" index %d (%s", aa->idx, aa->primid);
    377  1.1  drochner 	if (aa->resc->longname)
    378  1.1  drochner 		printf(", %s", aa->resc->longname);
    379  1.1  drochner 	if (aa->idstr != aa->primid)
    380  1.1  drochner 		printf(", attached as %s", aa->idstr);
    381  1.2   thorpej 	printf(")");
    382  1.2   thorpej 
    383  1.2   thorpej 	return (0);
    384  1.2   thorpej }
    385  1.2   thorpej 
    386  1.2   thorpej void
    387  1.2   thorpej pnpbios_print_devres(dev, aa)
    388  1.2   thorpej 	struct device *dev;
    389  1.2   thorpej 	struct pnpbiosdev_attach_args *aa;
    390  1.2   thorpej {
    391  1.2   thorpej 
    392  1.2   thorpej 	printf("%s: ", dev->dv_xname);
    393  1.1  drochner 	pnpbios_printres(aa->resc);
    394  1.2   thorpej 	printf("\n");
    395  1.2   thorpej }
    396  1.1  drochner 
    397  1.2   thorpej static int
    398  1.2   thorpej pnpbios_submatch(parent, match, aux)
    399  1.2   thorpej 	struct device *parent;
    400  1.2   thorpej 	struct cfdata *match;
    401  1.2   thorpej 	void *aux;
    402  1.2   thorpej {
    403  1.2   thorpej 	struct pnpbiosdev_attach_args *aa = aux;
    404  1.2   thorpej 
    405  1.2   thorpej 	if (match->cf_loc[PNPBIOSCF_INDEX] != PNPBIOSCF_INDEX_DEFAULT &&
    406  1.2   thorpej 	    match->cf_loc[PNPBIOSCF_INDEX] != aa->idx)
    407  1.2   thorpej 		return (0);
    408  1.2   thorpej 
    409  1.2   thorpej 	return ((*match->cf_attach->ca_match)(parent, match, aux));
    410  1.1  drochner }
    411  1.1  drochner 
    412  1.1  drochner static void
    413  1.2   thorpej pnpbios_attachnode(sc, idx, buf, len)
    414  1.1  drochner 	struct pnpbios_softc *sc;
    415  1.2   thorpej 	int idx;
    416  1.1  drochner 	unsigned char *buf;
    417  1.1  drochner 	size_t len;
    418  1.1  drochner {
    419  1.1  drochner 	char idstr[8];
    420  1.1  drochner 	unsigned char *p;
    421  1.1  drochner 	int res;
    422  1.1  drochner 	struct pnpresources r, s;
    423  1.1  drochner 	int i;
    424  1.1  drochner 	struct pnpbiosdev_attach_args aa;
    425  1.1  drochner 	struct pnp_compatid *compatid;
    426  1.1  drochner 
    427  1.1  drochner 	eisaid_to_string(buf + 3, idstr);
    428  1.1  drochner 	p = buf + 12;
    429  1.1  drochner 
    430  1.1  drochner 	res = pnp_scan(&p, len - 12, &r, 0);
    431  1.1  drochner 	if (res < 0) {
    432  1.1  drochner 		printf("error in config data\n");
    433  1.1  drochner 		goto dump;
    434  1.1  drochner 	}
    435  1.1  drochner 
    436  1.1  drochner 	/*
    437  1.1  drochner 	 * the following is consistency check only for now
    438  1.1  drochner 	 */
    439  1.1  drochner 	res = pnp_scan(&p, len - (p - buf), &s, 0);
    440  1.1  drochner 	if (res < 0) {
    441  1.1  drochner 		printf("error in possible configuration\n");
    442  1.1  drochner 		goto dump;
    443  1.1  drochner 	}
    444  1.1  drochner 
    445  1.1  drochner 	res = pnp_scan(&p, len - (p - buf), &s, 0);
    446  1.1  drochner 	if (res < 0) {
    447  1.1  drochner 		printf("error in compatible ID\n");
    448  1.1  drochner 		goto dump;
    449  1.1  drochner 	}
    450  1.1  drochner 
    451  1.1  drochner 	if (p != buf + len) {
    452  1.1  drochner 		printf("length mismatch\n");
    453  1.1  drochner 		goto dump;
    454  1.1  drochner 	}
    455  1.1  drochner 
    456  1.1  drochner 	aa.pbt = 0; /* XXX placeholder */
    457  1.2   thorpej 	aa.idx = idx;
    458  1.1  drochner 	aa.resc = &r;
    459  1.1  drochner 	aa.ic = sc->sc_ic;
    460  1.1  drochner 	aa.primid = idstr;
    461  1.1  drochner 
    462  1.1  drochner 	/* first try the specific device ID */
    463  1.1  drochner 	aa.idstr = idstr;
    464  1.2   thorpej 	if (config_found_sm((struct device *)sc, &aa, pnpbios_print,
    465  1.2   thorpej 	    pnpbios_submatch))
    466  1.1  drochner 		return;
    467  1.1  drochner 
    468  1.1  drochner 	/* if no driver was found, try compatible IDs */
    469  1.1  drochner 	compatid = s.compatids;
    470  1.1  drochner 	while (compatid) {
    471  1.1  drochner 		aa.idstr = compatid->idstr;
    472  1.2   thorpej 		if (config_found_sm((struct device *)sc, &aa, pnpbios_print,
    473  1.2   thorpej 		    pnpbios_submatch))
    474  1.1  drochner 			return;
    475  1.1  drochner 		compatid = compatid->next;
    476  1.1  drochner 	}
    477  1.1  drochner 
    478  1.1  drochner #ifdef PNPBIOSVERBOSE
    479  1.1  drochner 	printf("%s", idstr);
    480  1.1  drochner 	if (r.longname)
    481  1.1  drochner 		printf(", %s", r.longname);
    482  1.1  drochner 	compatid = s.compatids;
    483  1.1  drochner 	while (compatid) {
    484  1.1  drochner 		printf(", %s", compatid->idstr);
    485  1.1  drochner 		compatid = compatid->next;
    486  1.1  drochner 	}
    487  1.1  drochner 	printf(" (");
    488  1.1  drochner 	pnpbios_printres(&r);
    489  1.2   thorpej 	printf(") at %s index %d ignored\n", sc->sc_dev.dv_xname, idx);
    490  1.1  drochner #endif
    491  1.1  drochner 
    492  1.1  drochner 	return;
    493  1.1  drochner 
    494  1.1  drochner 	/* XXX should free ressource lists */
    495  1.1  drochner 
    496  1.1  drochner dump:
    497  1.1  drochner 	for (i = 0; i < len; i++)
    498  1.1  drochner 		printf(" %02x", buf[i]);
    499  1.1  drochner 	printf("\n");
    500  1.1  drochner }
    501  1.1  drochner 
    502  1.1  drochner static int pnp_compatid __P((struct pnpresources *, unsigned char *, size_t));
    503  1.1  drochner static int pnp_newirq __P((struct pnpresources *, unsigned char *, size_t));
    504  1.1  drochner static int pnp_newdma __P((struct pnpresources *, unsigned char *, size_t));
    505  1.1  drochner static int pnp_newioport __P((struct pnpresources *, unsigned char *, size_t));
    506  1.1  drochner 
    507  1.1  drochner /*
    508  1.1  drochner  * small ressource types (beginning with 1)
    509  1.1  drochner  */
    510  1.1  drochner static struct{
    511  1.1  drochner 	int (*handler) __P((struct pnpresources *, unsigned char *, size_t));
    512  1.1  drochner 	int minlen, maxlen;
    513  1.1  drochner } smallrescs[] = {
    514  1.1  drochner 	{0, 2, 2}, /* PnP version number */
    515  1.1  drochner 	{0, 5, 6}, /* logical device id */
    516  1.1  drochner 	{pnp_compatid, 4, 4}, /* compatible device id */
    517  1.1  drochner 	{pnp_newirq, 2, 3}, /* irq  descriptor */
    518  1.1  drochner 	{pnp_newdma, 2, 2}, /* dma  descriptor */
    519  1.1  drochner 	{0, 0, 1}, /* start dep */
    520  1.1  drochner 	{0, 0, 0}, /* end dep */
    521  1.1  drochner 	{pnp_newioport, 7, 7}, /* io descriptor */
    522  1.1  drochner 	{0, 3, 3}, /* fixed io descriptor */
    523  1.1  drochner 	{0, -1, -1}, /* reserved */
    524  1.1  drochner 	{0, -1, -1},
    525  1.1  drochner 	{0, -1, -1},
    526  1.1  drochner 	{0, -1, -1},
    527  1.1  drochner 	{0, 1, 7}, /* vendor defined */
    528  1.1  drochner 	{0, 1, 1} /* end */
    529  1.1  drochner };
    530  1.1  drochner 
    531  1.1  drochner #define NEXTBYTE(p) (*(p)++)
    532  1.1  drochner 
    533  1.1  drochner static int
    534  1.1  drochner pnp_scan(bufp, maxlen, r, in_depends)
    535  1.1  drochner 	unsigned char **bufp;
    536  1.1  drochner 	size_t maxlen;
    537  1.1  drochner 	struct pnpresources *r;
    538  1.1  drochner 	int in_depends;
    539  1.1  drochner {
    540  1.1  drochner 	unsigned char *p = *bufp;
    541  1.1  drochner 	int tag, type, len;
    542  1.1  drochner 	char *idstr;
    543  1.1  drochner 	int i;
    544  1.1  drochner 	struct pnp_mem *mem;
    545  1.1  drochner 
    546  1.1  drochner 	bzero(r, sizeof(*r));
    547  1.1  drochner 	SIMPLEQ_INIT(&r->mem);
    548  1.1  drochner 	SIMPLEQ_INIT(&r->io);
    549  1.1  drochner 	SIMPLEQ_INIT(&r->irq);
    550  1.1  drochner 	SIMPLEQ_INIT(&r->dma);
    551  1.1  drochner 
    552  1.1  drochner 	for (;;) {
    553  1.1  drochner 		if (p >= *bufp + maxlen) {
    554  1.1  drochner 			printf("pnp_scanresources: end of buffer\n");
    555  1.1  drochner 			return (-1);
    556  1.1  drochner 		}
    557  1.1  drochner 		tag = NEXTBYTE(p);
    558  1.1  drochner 
    559  1.1  drochner 		if (tag & 0x80) { /* long tag */
    560  1.1  drochner 			type = tag & 0x7f;
    561  1.1  drochner 			len = NEXTBYTE(p);
    562  1.1  drochner 			len |= NEXTBYTE(p) << 8;
    563  1.1  drochner 
    564  1.1  drochner 			switch (type) {
    565  1.1  drochner 			case 0x01: /* memory descriptor */
    566  1.1  drochner 				if (len != 9) {
    567  1.1  drochner 					printf("pnp_scan: bad mem desc\n");
    568  1.1  drochner 					return (-1);
    569  1.1  drochner 				}
    570  1.1  drochner 
    571  1.1  drochner 				mem = malloc(sizeof(struct pnp_mem),
    572  1.1  drochner 					     M_DEVBUF, M_WAITOK);
    573  1.1  drochner 				mem->flags = NEXTBYTE(p);
    574  1.1  drochner 				mem->minbase = NEXTBYTE(p) << 8;
    575  1.1  drochner 				mem->minbase |= NEXTBYTE(p) << 16;
    576  1.1  drochner 				mem->maxbase = NEXTBYTE(p) << 8;
    577  1.1  drochner 				mem->maxbase |= NEXTBYTE(p) << 16;
    578  1.1  drochner 				mem->align = NEXTBYTE(p);
    579  1.1  drochner 				mem->align |= NEXTBYTE(p) << 8;
    580  1.1  drochner 				if (mem->align == 0)
    581  1.1  drochner 					mem->align = 0x10000;
    582  1.1  drochner 				mem->len = NEXTBYTE(p) << 8;
    583  1.1  drochner 				mem->len |= NEXTBYTE(p) << 16;
    584  1.1  drochner 				SIMPLEQ_INSERT_TAIL(&r->mem, mem, next);
    585  1.1  drochner 				r->nummem++;
    586  1.1  drochner #ifdef PNPBIOSDEBUG
    587  1.1  drochner 				if (mem->len == 0)
    588  1.1  drochner 					printf("ZERO mem descriptor\n");
    589  1.1  drochner #endif
    590  1.1  drochner 				break;
    591  1.1  drochner 			case 0x02:
    592  1.1  drochner 				if (in_depends)
    593  1.1  drochner 					printf("ID in dep?\n");
    594  1.1  drochner 				idstr = malloc(len + 1, M_DEVBUF, M_NOWAIT);
    595  1.1  drochner 				for (i = 0; i < len; i++)
    596  1.1  drochner 					idstr[i] = NEXTBYTE(p);
    597  1.1  drochner 				idstr[len] = '\0';
    598  1.1  drochner 				r->longname = idstr;
    599  1.1  drochner 				break;
    600  1.1  drochner 			case 0x06: /* 32bit fixed memory descriptor */
    601  1.1  drochner 				if (len != 9) {
    602  1.1  drochner 					printf("pnp_scan: bad mem32 desc\n");
    603  1.1  drochner 					return (-1);
    604  1.1  drochner 				}
    605  1.1  drochner 
    606  1.1  drochner 				mem = malloc(sizeof(struct pnp_mem),
    607  1.1  drochner 					     M_DEVBUF, M_WAITOK);
    608  1.1  drochner 				mem->flags = NEXTBYTE(p);
    609  1.1  drochner 				mem->minbase = NEXTBYTE(p);
    610  1.1  drochner 				mem->minbase |= NEXTBYTE(p) << 8;
    611  1.1  drochner 				mem->minbase |= NEXTBYTE(p) << 16;
    612  1.1  drochner 				mem->minbase |= NEXTBYTE(p) << 24;
    613  1.1  drochner 				mem->maxbase = mem->minbase;
    614  1.1  drochner 				mem->align = 0;
    615  1.1  drochner 				mem->len = NEXTBYTE(p);
    616  1.1  drochner 				mem->len |= NEXTBYTE(p) << 8;
    617  1.1  drochner 				mem->len |= NEXTBYTE(p) << 16;
    618  1.1  drochner 				mem->len |= NEXTBYTE(p) << 24;
    619  1.1  drochner 				SIMPLEQ_INSERT_TAIL(&r->mem, mem, next);
    620  1.1  drochner 				r->nummem++;
    621  1.1  drochner #ifdef PNPBIOSDEBUG
    622  1.1  drochner 				if (mem->len == 0)
    623  1.1  drochner 					printf("ZERO mem descriptor\n");
    624  1.1  drochner #endif
    625  1.1  drochner 				break;
    626  1.1  drochner 			default:
    627  1.1  drochner 				printf("ignoring long tag %x\n", type);
    628  1.1  drochner 				while (len--)
    629  1.1  drochner 					(void) NEXTBYTE(p);
    630  1.1  drochner 			}
    631  1.1  drochner 		} else {
    632  1.1  drochner 			unsigned char tmpbuf[7];
    633  1.1  drochner 			int i;
    634  1.1  drochner 
    635  1.1  drochner 			type = (tag >> 3) & 0x0f;
    636  1.1  drochner 			len = tag & 0x07;
    637  1.1  drochner 
    638  1.1  drochner 			if (type == 0 ||
    639  1.1  drochner 			    len < smallrescs[type - 1].minlen ||
    640  1.1  drochner 			    len > smallrescs[type - 1].maxlen) {
    641  1.1  drochner 				printf("pnp_scan: bad small resource\n");
    642  1.1  drochner 				return (-1);
    643  1.1  drochner 			}
    644  1.1  drochner 			for (i = 0; i < len; i++)
    645  1.1  drochner 				tmpbuf[i] = NEXTBYTE(p);
    646  1.1  drochner 
    647  1.1  drochner 			if (type == 0x0f) { /* end mark */
    648  1.1  drochner 				if (in_depends) {
    649  1.1  drochner 					printf("end in dep?\n");
    650  1.1  drochner 					return (-1);
    651  1.1  drochner 				}
    652  1.1  drochner 				break;
    653  1.1  drochner 			}
    654  1.1  drochner 			if (type == 0x06) { /* start dep */
    655  1.1  drochner 				struct pnpresources *new, *last;
    656  1.1  drochner 				int res;
    657  1.1  drochner 
    658  1.1  drochner 				if (r->dependant_link) {
    659  1.1  drochner 					printf("second dep?\n");
    660  1.1  drochner 					return (-1);
    661  1.1  drochner 				}
    662  1.1  drochner 
    663  1.1  drochner 				if (in_depends) {
    664  1.1  drochner 					*bufp = p;
    665  1.1  drochner 					return (1);
    666  1.1  drochner 				}
    667  1.1  drochner 
    668  1.1  drochner 				last = r;
    669  1.1  drochner 				do {
    670  1.1  drochner 					new = malloc(sizeof(*new),
    671  1.1  drochner 						     M_DEVBUF, M_NOWAIT);
    672  1.1  drochner 
    673  1.1  drochner 					res = pnp_scan(&p, maxlen - (p - *bufp),
    674  1.1  drochner 						       new, 1);
    675  1.1  drochner 					if (res < 0) {
    676  1.1  drochner 				printf("error in dependant function\n");
    677  1.1  drochner 						free(new, M_DEVBUF);
    678  1.1  drochner 						return (-1);
    679  1.1  drochner 					}
    680  1.1  drochner 
    681  1.1  drochner 					last->dependant_link = new;
    682  1.1  drochner 					last = new;
    683  1.1  drochner 				} while (res > 0);
    684  1.1  drochner 				continue;
    685  1.1  drochner 			}
    686  1.1  drochner 			if (type == 0x07) { /* end dep */
    687  1.1  drochner 				if (!in_depends) {
    688  1.1  drochner 					printf("end dep?\n");
    689  1.1  drochner 					return (-1);
    690  1.1  drochner 				}
    691  1.1  drochner 				break;
    692  1.1  drochner 			}
    693  1.1  drochner 
    694  1.1  drochner 			if (!smallrescs[type - 1].handler)
    695  1.1  drochner 				printf("ignoring short tag %x\n", type);
    696  1.1  drochner 			else
    697  1.1  drochner 				if ((*smallrescs[type - 1].handler)(r, tmpbuf,
    698  1.1  drochner 								    len))
    699  1.1  drochner 					return (-1);
    700  1.1  drochner 		}
    701  1.1  drochner 	}
    702  1.1  drochner 	*bufp = p;
    703  1.1  drochner 	return (0);
    704  1.1  drochner }
    705  1.1  drochner 
    706  1.1  drochner static int
    707  1.1  drochner pnp_newirq(r, buf, len)
    708  1.1  drochner 	struct pnpresources *r;
    709  1.1  drochner 	unsigned char *buf;
    710  1.1  drochner 	size_t len;
    711  1.1  drochner {
    712  1.1  drochner 	struct pnp_irq *irq;
    713  1.1  drochner 
    714  1.1  drochner 	irq = malloc(sizeof(struct pnp_irq), M_DEVBUF, M_NOWAIT);
    715  1.1  drochner 	irq->mask = buf[0] | (buf[1] << 8);
    716  1.1  drochner 	if (len > 2)
    717  1.1  drochner 		irq->flags = buf[2];
    718  1.1  drochner 	else
    719  1.1  drochner 		irq->flags = 0x01;
    720  1.1  drochner 	SIMPLEQ_INSERT_TAIL(&r->irq, irq, next);
    721  1.1  drochner 	r->numirq++;
    722  1.1  drochner 	return (0);
    723  1.1  drochner }
    724  1.1  drochner 
    725  1.1  drochner static int
    726  1.1  drochner pnp_newdma(r, buf, len)
    727  1.1  drochner 	struct pnpresources *r;
    728  1.1  drochner 	unsigned char *buf;
    729  1.1  drochner 	size_t len;
    730  1.1  drochner {
    731  1.1  drochner 	struct pnp_dma *dma;
    732  1.1  drochner 
    733  1.1  drochner 	dma = malloc(sizeof(struct pnp_dma), M_DEVBUF, M_NOWAIT);
    734  1.1  drochner 	dma->mask = buf[0];
    735  1.1  drochner 	dma->flags = buf[1];
    736  1.1  drochner 	SIMPLEQ_INSERT_TAIL(&r->dma, dma, next);
    737  1.1  drochner 	r->numdma++;
    738  1.1  drochner 	return (0);
    739  1.1  drochner }
    740  1.1  drochner 
    741  1.1  drochner static int
    742  1.1  drochner pnp_newioport(r, buf, len)
    743  1.1  drochner 	struct pnpresources *r;
    744  1.1  drochner 	unsigned char *buf;
    745  1.1  drochner 	size_t len;
    746  1.1  drochner {
    747  1.1  drochner 	struct pnp_io *io;
    748  1.1  drochner 
    749  1.1  drochner 	io = malloc(sizeof(struct pnp_io), M_DEVBUF, M_NOWAIT);
    750  1.1  drochner 	io->flags = buf[0];
    751  1.1  drochner 	io->minbase = buf[1] | (buf[2] << 8);
    752  1.1  drochner 	io->maxbase = buf[3] | (buf[4] << 8);
    753  1.1  drochner 	io->align = buf[5];
    754  1.1  drochner 	io->len = buf[6];
    755  1.1  drochner 	SIMPLEQ_INSERT_TAIL(&r->io, io, next);
    756  1.1  drochner 	r->numio++;
    757  1.1  drochner 	return (0);
    758  1.1  drochner }
    759  1.1  drochner 
    760  1.1  drochner static int
    761  1.1  drochner pnp_compatid(r, buf, len)
    762  1.1  drochner 	struct pnpresources *r;
    763  1.1  drochner 	unsigned char *buf;
    764  1.1  drochner 	size_t len;
    765  1.1  drochner {
    766  1.1  drochner 	struct pnp_compatid *id;
    767  1.1  drochner 
    768  1.1  drochner 	id = malloc(sizeof(*id), M_DEVBUF, M_NOWAIT);
    769  1.1  drochner 	eisaid_to_string(buf, id->idstr);
    770  1.1  drochner 	id->next = r->compatids;
    771  1.1  drochner 	r->compatids = id;
    772  1.1  drochner 	return (0);
    773  1.1  drochner }
    774  1.1  drochner 
    775  1.1  drochner int
    776  1.1  drochner pnpbios_io_map(pbt, resc, idx, tagp, hdlp)
    777  1.1  drochner 	pnpbios_tag_t pbt;
    778  1.1  drochner 	struct pnpresources *resc;
    779  1.1  drochner 	int idx;
    780  1.1  drochner 	bus_space_tag_t *tagp;
    781  1.1  drochner 	bus_space_handle_t *hdlp;
    782  1.1  drochner {
    783  1.1  drochner 	struct pnp_io *io;
    784  1.1  drochner 
    785  1.1  drochner 	if (idx >= resc->numio)
    786  1.1  drochner 		return (EINVAL);
    787  1.1  drochner 
    788  1.1  drochner 	io = SIMPLEQ_FIRST(&resc->io);
    789  1.1  drochner 	while (idx--)
    790  1.1  drochner 		io = SIMPLEQ_NEXT(io, next);
    791  1.1  drochner 
    792  1.1  drochner 	*tagp = I386_BUS_SPACE_IO;
    793  1.1  drochner 	return (i386_memio_map(I386_BUS_SPACE_IO, io->minbase, io->len,
    794  1.1  drochner 			       0, hdlp));
    795  1.1  drochner }
    796  1.1  drochner 
    797  1.1  drochner int
    798  1.1  drochner pnpbios_getiobase(pbt, resc, idx, tagp, basep)
    799  1.1  drochner 	pnpbios_tag_t pbt;
    800  1.1  drochner 	struct pnpresources *resc;
    801  1.1  drochner 	int idx;
    802  1.1  drochner 	bus_space_tag_t *tagp;
    803  1.1  drochner 	int *basep;
    804  1.1  drochner {
    805  1.1  drochner 	struct pnp_io *io;
    806  1.1  drochner 
    807  1.1  drochner 	if (idx >= resc->numio)
    808  1.1  drochner 		return (EINVAL);
    809  1.1  drochner 
    810  1.1  drochner 	io = SIMPLEQ_FIRST(&resc->io);
    811  1.1  drochner 	while (idx--)
    812  1.1  drochner 		io = SIMPLEQ_NEXT(io, next);
    813  1.1  drochner 
    814  1.1  drochner 	if (tagp)
    815  1.1  drochner 		*tagp = I386_BUS_SPACE_IO;
    816  1.1  drochner 	if (basep)
    817  1.1  drochner 		*basep = io->minbase;
    818  1.1  drochner 	return (0);
    819  1.1  drochner }
    820  1.1  drochner 
    821  1.1  drochner void *
    822  1.1  drochner pnpbios_intr_establish(pbt, resc, idx, level, fcn, arg)
    823  1.1  drochner 	pnpbios_tag_t pbt;
    824  1.1  drochner 	struct pnpresources *resc;
    825  1.1  drochner 	int idx, level;
    826  1.1  drochner 	int (*fcn) __P((void *));
    827  1.1  drochner 	void *arg;
    828  1.1  drochner {
    829  1.1  drochner 	struct pnp_irq *irq;
    830  1.1  drochner 	int irqnum, type;
    831  1.1  drochner 
    832  1.1  drochner 	if (idx >= resc->numirq)
    833  1.1  drochner 		return (0);
    834  1.1  drochner 
    835  1.1  drochner 	irq = SIMPLEQ_FIRST(&resc->irq);
    836  1.1  drochner 	while (idx--)
    837  1.1  drochner 		irq = SIMPLEQ_NEXT(irq, next);
    838  1.1  drochner 
    839  1.1  drochner 	irqnum = ffs(irq->mask) - 1;
    840  1.1  drochner 	type = (irq->flags & 0x0c) ? IST_LEVEL : IST_EDGE;
    841  1.1  drochner 
    842  1.1  drochner 	return (isa_intr_establish(0, irqnum, type, level, fcn, arg));
    843  1.1  drochner }
    844  1.1  drochner 
    845  1.1  drochner int
    846  1.1  drochner pnpbios_getirqnum(pbt, resc, idx, irqp)
    847  1.1  drochner 	pnpbios_tag_t pbt;
    848  1.1  drochner 	struct pnpresources *resc;
    849  1.1  drochner 	int idx;
    850  1.1  drochner 	int *irqp;
    851  1.1  drochner {
    852  1.1  drochner 	struct pnp_irq *irq;
    853  1.1  drochner 
    854  1.1  drochner 	if (idx >= resc->numirq)
    855  1.1  drochner 		return (EINVAL);
    856  1.1  drochner 
    857  1.1  drochner 	irq = SIMPLEQ_FIRST(&resc->irq);
    858  1.1  drochner 	while (idx--)
    859  1.1  drochner 		irq = SIMPLEQ_NEXT(irq, next);
    860  1.1  drochner 
    861  1.1  drochner 	*irqp = ffs(irq->mask) - 1;
    862  1.1  drochner 	return (0);
    863  1.1  drochner }
    864  1.1  drochner 
    865  1.1  drochner int
    866  1.1  drochner pnpbios_getdmachan(pbt, resc, idx, chanp)
    867  1.1  drochner 	pnpbios_tag_t pbt;
    868  1.1  drochner 	struct pnpresources *resc;
    869  1.1  drochner 	int idx;
    870  1.1  drochner 	int *chanp;
    871  1.1  drochner {
    872  1.1  drochner 	struct pnp_dma *dma;
    873  1.1  drochner 
    874  1.1  drochner 	if (idx >= resc->numdma)
    875  1.1  drochner 		return (EINVAL);
    876  1.1  drochner 
    877  1.1  drochner 	dma = SIMPLEQ_FIRST(&resc->dma);
    878  1.1  drochner 	while (idx--)
    879  1.1  drochner 		dma = SIMPLEQ_NEXT(dma, next);
    880  1.1  drochner 
    881  1.1  drochner 	*chanp = ffs(dma->mask) - 1;
    882  1.1  drochner 	return (0);
    883  1.1  drochner }
    884