Home | History | Annotate | Line # | Download | only in pnpbus
pnpbus.c revision 1.13.2.1
      1 /*	$NetBSD: pnpbus.c,v 1.13.2.1 2021/03/20 19:33:37 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tim Rightnour
      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 __KERNEL_RCSID(0, "$NetBSD: pnpbus.c,v 1.13.2.1 2021/03/20 19:33:37 thorpej Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 #include <sys/extent.h>
     39 #include <sys/kmem.h>
     40 
     41 #include <sys/bus.h>
     42 #include <machine/pio.h>
     43 #include <machine/intr.h>
     44 #include <machine/platform.h>
     45 #include <machine/residual.h>
     46 #include <machine/pnp.h>
     47 #include <machine/isa_machdep.h>
     48 #include <machine/chpidpnp.h>
     49 
     50 #include <dev/isa/isareg.h>
     51 
     52 #include <prep/pnpbus/pnpbusvar.h>
     53 
     54 #include "isadma.h"
     55 
     56 static int	pnpbus_match(device_t, cfdata_t, void *);
     57 static void	pnpbus_attach(device_t, device_t, void *);
     58 static int	pnpbus_print(void *, const char *);
     59 static int	pnpbus_search(device_t, cfdata_t, const int *, void *);
     60 
     61 CFATTACH_DECL_NEW(pnpbus, sizeof(struct pnpbus_softc),
     62     pnpbus_match, pnpbus_attach, NULL, NULL);
     63 
     64 struct pnpbus_softc *pnpbus_softc;
     65 extern struct cfdriver pnpbus_cd;
     66 
     67 static int
     68 pnpbus_match(device_t parent, cfdata_t cf, void *aux)
     69 {
     70 	struct pnpbus_attach_args *paa = aux;
     71 
     72 	if (paa->paa_name != NULL && strcmp(paa->paa_name, "pnpbus") == 0)
     73 		return 1;
     74 	return 0;
     75 }
     76 
     77 static void
     78 pnpbus_attach(device_t parent, device_t self, void *aux)
     79 {
     80 	struct pnpbus_softc *sc = device_private(self);
     81 	struct pnpbus_attach_args *paa = aux;
     82 
     83 	aprint_normal("\n");
     84 
     85 	pnpbus_softc = sc;
     86 	sc->sc_dev = self;
     87 	sc->sc_ic = paa->paa_ic;
     88 	sc->sc_iot = paa->paa_iot;
     89 	sc->sc_memt = paa->paa_memt;
     90 	sc->sc_dmat = paa->paa_dmat;
     91 
     92 #if NISADMA > 0
     93 	isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
     94 #endif
     95 
     96 	config_search(self, aux,
     97 	    CFARG_SUBMATCH, pnpbus_search,
     98 	    CFARG_IATTR, "pnpbus",
     99 	    CFARG_EOL);
    100 }
    101 
    102 static int
    103 pnp_newirq(void *v, struct pnpresources *r, int size)
    104 {
    105 	struct _S4_Pack *p = v;
    106 	struct pnpbus_irq *irq;
    107 
    108 	irq = kmem_alloc(sizeof(struct pnpbus_irq), KM_SLEEP);
    109 
    110 	irq->mask = le16dec(&p->IRQMask[0]);
    111 
    112 	if (size > 2)
    113 		irq->flags = p->IRQInfo;
    114 	else
    115 		irq->flags = 0x1;
    116 
    117 	SIMPLEQ_INSERT_TAIL(&r->irq, irq, next);
    118 	r->numirq++;
    119 
    120 	return 0;
    121 }
    122 
    123 static int
    124 pnp_newdma(void *v, struct pnpresources *r, int size)
    125 {
    126 	struct _S5_Pack *p = v;
    127 	struct pnpbus_dma *dma;
    128 
    129 	dma = kmem_alloc(sizeof(struct pnpbus_dma), KM_SLEEP);
    130 
    131 	dma->mask = le16dec(&p->DMAMask);
    132 	if (size > 2)
    133 		dma->flags = p->DMAInfo;
    134 	else
    135 		dma->flags = 0x01;
    136 
    137 	SIMPLEQ_INSERT_TAIL(&r->dma, dma, next);
    138 	r->numdma++;
    139 
    140 	return 0;
    141 }
    142 
    143 static int
    144 pnp_newioport(void *v, struct pnpresources *r, int size)
    145 {
    146 	struct _S8_Pack *p = v;
    147 	struct pnpbus_io *io;
    148 	uint16_t mask;
    149 
    150 	io = kmem_alloc(sizeof(struct pnpbus_io), KM_SLEEP);
    151 	mask = p->IOInfo & ISAAddr16bit ? 0xffff : 0x03ff;
    152 	io->minbase = (p->RangeMin[0] | (p->RangeMin[1] << 8)) & mask;
    153 	io->maxbase = (p->RangeMax[0] | (p->RangeMax[1] << 8)) & mask;
    154 	io->align = p->IOAlign;
    155 	io->len = p->IONum;
    156 	io->flags = p->IOInfo;
    157 
    158 	SIMPLEQ_INSERT_TAIL(&r->io, io, next);
    159 	r->numio++;
    160 
    161 	return 0;
    162 }
    163 
    164 static int
    165 pnp_newfixedioport(void *v, struct pnpresources *r, int size)
    166 {
    167 	struct _S9_Pack *p = v;
    168 	struct pnpbus_io *io;
    169 
    170 	io = kmem_alloc(sizeof(struct pnpbus_io), KM_SLEEP);
    171 	io->minbase = (p->Range[0] | (p->Range[1] << 8)) & 0x3ff;
    172 	io->len = p->IONum;
    173 	io->maxbase = -1;
    174 	io->flags = 0;
    175 	io->align = 1;
    176 
    177 	SIMPLEQ_INSERT_TAIL(&r->io, io, next);
    178 	r->numio++;
    179 
    180 	return 0;
    181 }
    182 
    183 static int
    184 pnp_newiomem(void *v, struct pnpresources *r, int size)
    185 {
    186 	struct pnpbus_mem *mem;
    187 	struct _L1_Pack *pack = v;
    188 
    189 	if (pack->Count0 >= 0x9) {
    190 		mem = kmem_alloc(sizeof(struct pnpbus_mem), KM_SLEEP);
    191 		mem->minbase = (pack->Data[2] << 16) | (pack->Data[1] << 8);
    192 		mem->maxbase = (pack->Data[4] << 16) | (pack->Data[3] << 8);
    193 		mem->align = (pack->Data[6] << 8) | pack->Data[5];
    194 		mem->len = (pack->Data[8] << 16) | (pack->Data[7] << 8);
    195 		mem->flags = pack->Data[0];
    196 		SIMPLEQ_INSERT_TAIL(&r->iomem, mem, next);
    197 		r->numiomem++;
    198 		return 0;
    199 	}
    200 	return -1;
    201 }
    202 
    203 static int
    204 pnp_newaddr(void *v, struct pnpresources *r, int size)
    205 {
    206 	struct pnpbus_io *io;
    207 	struct pnpbus_mem *mem;
    208 	struct _L4_Pack *pack = v;
    209 	struct _L4_PPCPack *p =  &pack->L4_Data.L4_PPCPack;
    210 
    211 	if (p->PPCData[0] == 1) {/* type IO */
    212 		io = kmem_alloc(sizeof(struct pnpbus_io), KM_SLEEP);
    213 		io->minbase = (uint16_t)le64dec(&p->PPCData[4]);
    214 		io->maxbase = -1;
    215 		io->align = p->PPCData[1];
    216 		io->len = (uint16_t)le64dec(&p->PPCData[12]);
    217 		io->flags = 0;
    218 		SIMPLEQ_INSERT_TAIL(&r->io, io, next);
    219 		r->numio++;
    220 
    221 		return 0;
    222 	} else if (p->PPCData[0] == 2) {
    223 		mem = kmem_alloc(sizeof(struct pnpbus_mem), KM_SLEEP);
    224 		mem->minbase = (uint32_t)le64dec(&p->PPCData[4]);
    225 		mem->maxbase = -1;
    226 		mem->align = p->PPCData[1];
    227 		mem->len = (uint32_t)le64dec(&p->PPCData[12]);
    228 		mem->flags = 0;
    229 		SIMPLEQ_INSERT_TAIL(&r->mem, mem, next);
    230 		r->nummem++;
    231 
    232 		return 0;
    233 	} else
    234 		return -1;
    235 }
    236 
    237 static int
    238 pnp_newcompatid(void *v, struct pnpresources *r, int size)
    239 {
    240 	struct _S3_Pack *p = v;
    241 	struct pnpbus_compatid *id;
    242 	uint32_t cid;
    243 
    244 	id = kmem_alloc(sizeof(*id), KM_SLEEP);
    245 	cid = le32dec(p->CompatId);
    246 	pnp_devid_to_string(cid, id->idstr);
    247 	id->next = r->compatids;
    248 	r->compatids = id;
    249 
    250 	return 0;
    251 }
    252 
    253 /*
    254  * Call if match succeeds.  This way we don't allocate lots of ram
    255  * for structures we never use if the device isn't attached.
    256  */
    257 
    258 int
    259 pnpbus_scan(struct pnpbus_dev_attach_args *pna, PPC_DEVICE *dev)
    260 {
    261 	struct pnpresources *r = &pna->pna_res;
    262 	uint32_t l;
    263 	uint8_t *p, *q;
    264 	void *v;
    265 	int tag, size, item;
    266 
    267 	l = be32toh(dev->AllocatedOffset);
    268 	p = res->DevicePnPHeap + l;
    269 
    270 	if (p == NULL)
    271 		return -1;
    272 
    273 	for (; p[0] != END_TAG; p += size) {
    274 		tag = *p;
    275 		v = p;
    276 		if (tag_type(p[0]) == PNP_SMALL) {
    277 			size = tag_small_count(tag) + 1;
    278 			item = tag_small_item_name(tag);
    279 			switch (item) {
    280 			case IRQFormat:
    281 				pnp_newirq(v, r, size);
    282 				break;
    283 			case DMAFormat:
    284 				pnp_newdma(v, r, size);
    285 				break;
    286 			case IOPort:
    287 				pnp_newioport(v, r, size);
    288 				break;
    289 			case FixedIOPort:
    290 				pnp_newfixedioport(v, r, size);
    291 				break;
    292 			}
    293 		} else {
    294 			struct _L4_Pack *pack = v;
    295 			struct _L4_PPCPack *pa = &pack->L4_Data.L4_PPCPack;
    296 
    297 			q = p;
    298 			size = (q[1] | (q[2] << 8)) + 3 /* tag + length */;
    299 			item = tag_large_item_name(tag);
    300 			if (item == LargeVendorItem &&
    301 			    pa->Type == LV_GenericAddress)
    302 				pnp_newaddr(v, r, size);
    303 			else if (item == MemoryRange)
    304 				pnp_newiomem(v, r, size);
    305 		}
    306 	}
    307 
    308 	/* scan for compatid's */
    309 
    310 	l = be32toh(dev->CompatibleOffset);
    311 	p = res->DevicePnPHeap + l;
    312 
    313 	if (p == NULL)
    314 		return -1;
    315 
    316 	for (; p[0] != END_TAG; p += size) {
    317 		tag = *p;
    318 		v = p;
    319 		if (tag_type(p[0]) == PNP_SMALL) {
    320 			size = tag_small_count(tag) + 1;
    321 			item = tag_small_item_name(tag);
    322 			switch (item) {
    323 			case CompatibleDevice:
    324 				pnp_newcompatid(v, r, size);
    325 				break;
    326 			}
    327 		} else {
    328 			q = p;
    329 			size = (q[1] | (q[2] << 8)) + 3 /* tag + length */;
    330 		}
    331 	}
    332 	return 0;
    333 }
    334 
    335 /*
    336  * Setup the basic pna structure.
    337  */
    338 
    339 static void
    340 pnp_getpna(struct pnpbus_dev_attach_args *pna, struct pnpbus_attach_args *paa,
    341 	PPC_DEVICE *dev)
    342 {
    343 	DEVICE_ID *id = &dev->DeviceId;
    344 	struct pnpresources *r = &pna->pna_res;
    345 	ChipIDPack *pack;
    346 	uint32_t l;
    347 	uint8_t *p;
    348 	void *v;
    349 	int tag, size, item;
    350 
    351 	l = be32toh(dev->AllocatedOffset);
    352 	p = res->DevicePnPHeap + l;
    353 
    354 	pna->pna_iot = paa->paa_iot;
    355 	pna->pna_memt = paa->paa_memt;
    356 	pna->pna_ic = paa->paa_ic;
    357 	pna->pna_dmat = paa->paa_dmat;
    358 	pnp_devid_to_string(id->DevId, pna->pna_devid);
    359 	pna->basetype = id->BaseType;
    360 	pna->subtype = id->SubType;
    361 	pna->interface = id->Interface;
    362 	pna->pna_ppc_dev = dev;
    363 	memset(r, 0, sizeof(*r));
    364 	SIMPLEQ_INIT(&r->mem);
    365 	SIMPLEQ_INIT(&r->io);
    366 	SIMPLEQ_INIT(&r->irq);
    367 	SIMPLEQ_INIT(&r->dma);
    368 	SIMPLEQ_INIT(&r->iomem);
    369 	if (p == NULL)
    370 		return;
    371 	/* otherwise, we start looking for chipid's */
    372 	for (; p[0] != END_TAG; p += size) {
    373 		tag = *p;
    374 		v = p;
    375 		if (tag_type(p[0]) == PNP_SMALL) {
    376 			size = tag_small_count(tag) + 1;
    377 			item = tag_small_item_name(tag);
    378 			if (item != SmallVendorItem || p[1] != 1)
    379 				continue;
    380 			pack = v;
    381 			pna->chipid = le16dec(&pack->Name[0]);
    382 			pna->chipmfg0 = pack->VendorID0;
    383 			pna->chipmfg1 = pack->VendorID1;
    384 			break;
    385 		} else {
    386 			/* Large */
    387 			size = (p[1] | (p[2] << 8)) + 3 /* tag + length */;
    388 		}
    389 	}
    390 }
    391 
    392 static int
    393 pnpbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    394 {
    395 	struct pnpbus_dev_attach_args pna;
    396 	struct pnpbus_attach_args *paa = aux;
    397 	PPC_DEVICE *ppc_dev;
    398 	int i;
    399 	uint32_t ndev;
    400 
    401 	ndev = be32toh(res->ActualNumDevices);
    402 	ppc_dev = res->Devices;
    403 
    404 	for (i = 0; i < ((ndev > MAX_DEVICES) ? MAX_DEVICES : ndev); i++) {
    405 		pnp_getpna(&pna, paa, &ppc_dev[i]);
    406 		if (config_match(parent, cf, &pna) > 0)
    407 			config_attach(parent, cf, &pna, pnpbus_print);
    408 	}
    409 
    410 	return 0;
    411 }
    412 
    413 static void
    414 pnpbus_printres(struct pnpresources *r)
    415 {
    416 	struct pnpbus_io *io;
    417 	struct pnpbus_mem *mem;
    418 	struct pnpbus_irq *irq;
    419 	struct pnpbus_dma *dma;
    420 	int p = 0;
    421 
    422 	if (!SIMPLEQ_EMPTY(&r->mem)) {
    423 		aprint_normal("mem");
    424 		SIMPLEQ_FOREACH(mem, &r->mem, next) {
    425 			aprint_normal(" 0x%x", mem->minbase);
    426 			if (mem->len > 1)
    427 				aprint_normal("-0x%x",
    428 				    mem->minbase + mem->len - 1);
    429 		}
    430 		p++;
    431 	}
    432 	if (!SIMPLEQ_EMPTY(&r->io)) {
    433 		if (p++)
    434 			aprint_normal(", ");
    435 		aprint_normal("port");
    436 		SIMPLEQ_FOREACH(io, &r->io, next) {
    437 			aprint_normal(" 0x%x", io->minbase);
    438 			if (io->len > 1)
    439 				aprint_normal("-0x%x",
    440 				    io->minbase + io->len - 1);
    441 		}
    442 	}
    443 	if (!SIMPLEQ_EMPTY(&r->iomem)) {
    444 		if (p++)
    445 			aprint_normal(", ");
    446 		aprint_normal("iomem");
    447 		SIMPLEQ_FOREACH(mem, &r->iomem, next) {
    448 			aprint_normal(" 0x%x", mem->minbase);
    449 			if (mem->len > 1)
    450 				aprint_normal("-0x%x",
    451 				    mem->minbase + mem->len - 1);
    452 		}
    453 		p++;
    454 	}
    455 	if (!SIMPLEQ_EMPTY(&r->irq)) {
    456 		if (p++)
    457 			aprint_normal(", ");
    458 		aprint_normal("irq");
    459 		SIMPLEQ_FOREACH(irq, &r->irq, next) {
    460 			aprint_normal(" %d", ffs(irq->mask) - 1);
    461 		}
    462 	}
    463 	if (!SIMPLEQ_EMPTY(&r->dma)) {
    464 		if (p++)
    465 			aprint_normal(", ");
    466 		aprint_normal("DMA");
    467 		SIMPLEQ_FOREACH(dma, &r->dma, next) {
    468 			aprint_normal(" %d", ffs(dma->mask) - 1);
    469 		}
    470 	}
    471 }
    472 
    473 void
    474 pnpbus_print_devres(struct pnpbus_dev_attach_args *pna)
    475 {
    476 	aprint_normal(": ");
    477 	pnpbus_printres(&pna->pna_res);
    478 }
    479 
    480 static int
    481 pnpbus_print(void *args, const char *name)
    482 {
    483 	struct pnpbus_dev_attach_args *pna = args;
    484 
    485 	pnpbus_print_devres(pna);
    486 	return (UNCONF);
    487 }
    488 
    489 /*
    490  * Set up an interrupt handler to start being called.
    491  */
    492 void *
    493 pnpbus_intr_establish(int idx, int level, int tover, int (*ih_fun)(void *),
    494     void *ih_arg, struct pnpresources *r)
    495 {
    496 	struct pnpbus_irq *irq;
    497 	int irqnum, type;
    498 
    499 	if (idx >= r->numirq)
    500 		return 0;
    501 
    502 	irq = SIMPLEQ_FIRST(&r->irq);
    503 	while (idx--)
    504 		irq = SIMPLEQ_NEXT(irq, next);
    505 
    506 	irqnum = ffs(irq->mask) - 1;
    507 	type = (irq->flags & 0x0c) ? IST_LEVEL : IST_EDGE;
    508 	if (tover != IST_PNP)
    509 		type = tover;
    510 
    511 	return (void *)intr_establish(irqnum, type, level, ih_fun, ih_arg);
    512 }
    513 
    514 /*
    515  * Deregister an interrupt handler.
    516  */
    517 void
    518 pnpbus_intr_disestablish(void *arg)
    519 {
    520 
    521 	intr_disestablish(arg);
    522 }
    523 
    524 int
    525 pnpbus_getirqnum(struct pnpresources *r, int idx, int *irqp, int *istp)
    526 {
    527 	struct pnpbus_irq *irq;
    528 
    529 	if (idx >= r->numirq)
    530 		return EINVAL;
    531 
    532 	irq = SIMPLEQ_FIRST(&r->irq);
    533 	while (idx--)
    534 		irq = SIMPLEQ_NEXT(irq, next);
    535 
    536 	if (irqp != NULL)
    537 		*irqp = ffs(irq->mask) - 1;
    538 	if (istp != NULL)
    539 		*istp = (irq->flags &0x0c) ? IST_LEVEL : IST_EDGE;
    540 	return 0;
    541 }
    542 
    543 int
    544 pnpbus_getdmachan(struct pnpresources *r, int idx, int *chanp)
    545 {
    546 	struct pnpbus_dma *dma;
    547 
    548 	if (idx >= r->numdma)
    549 		return EINVAL;
    550 
    551 	dma = SIMPLEQ_FIRST(&r->dma);
    552 	while (idx--)
    553 		dma = SIMPLEQ_NEXT(dma, next);
    554 
    555 	if (chanp != NULL)
    556 		*chanp = ffs(dma->mask) - 1;
    557 	return 0;
    558 }
    559 
    560 int
    561 pnpbus_getioport(struct pnpresources *r, int idx, int *basep, int *sizep)
    562 {
    563 	struct pnpbus_io *io;
    564 
    565 	if (idx >= r->numio)
    566 		return EINVAL;
    567 
    568 	io = SIMPLEQ_FIRST(&r->io);
    569 	while (idx--)
    570 		io = SIMPLEQ_NEXT(io, next);
    571 
    572 	if (basep)
    573 		*basep = io->minbase;
    574 	if (sizep)
    575 		*sizep = io->len;
    576 	return 0;
    577 }
    578 
    579 int
    580 pnpbus_io_map(struct pnpresources *r, int idx, bus_space_tag_t *tagp,
    581     bus_space_handle_t *hdlp)
    582 {
    583 	struct pnpbus_io *io;
    584 
    585 	if (idx >= r->numio)
    586 		return EINVAL;
    587 
    588 	io = SIMPLEQ_FIRST(&r->io);
    589 	while (idx--)
    590 		io = SIMPLEQ_NEXT(io, next);
    591 
    592 	*tagp = &genppc_isa_io_space_tag;
    593 	return (bus_space_map(&genppc_isa_io_space_tag, io->minbase, io->len,
    594 	    0, hdlp));
    595 }
    596 
    597 void
    598 pnpbus_io_unmap(struct pnpresources *r, int idx, bus_space_tag_t tag,
    599     bus_space_handle_t hdl)
    600 {
    601 	struct pnpbus_io *io;
    602 
    603 	if (idx >= r->numio)
    604 		return;
    605 
    606 	io = SIMPLEQ_FIRST(&r->io);
    607 	while (idx--)
    608 		io = SIMPLEQ_NEXT(io, next);
    609 
    610 	bus_space_unmap(tag, hdl, io->len);
    611 }
    612 
    613 int
    614 pnpbus_getiomem(struct pnpresources *r, int idx, int *basep, int *sizep)
    615 {
    616 	struct pnpbus_mem *mem;
    617 
    618 	if (idx >= r->numiomem)
    619 		return EINVAL;
    620 
    621 	mem = SIMPLEQ_FIRST(&r->iomem);
    622 	while (idx--)
    623 		mem = SIMPLEQ_NEXT(mem, next);
    624 
    625 	if (basep)
    626 		*basep = mem->minbase;
    627 	if (sizep)
    628 		*sizep = mem->len;
    629 	return 0;
    630 }
    631 
    632 int
    633 pnpbus_iomem_map(struct pnpresources *r, int idx, bus_space_tag_t *tagp,
    634     bus_space_handle_t *hdlp)
    635 {
    636 	struct pnpbus_mem *mem;
    637 
    638 	if (idx >= r->numiomem)
    639 		return EINVAL;
    640 
    641 	mem = SIMPLEQ_FIRST(&r->iomem);
    642 	while (idx--)
    643 		mem = SIMPLEQ_NEXT(mem, next);
    644 
    645 	*tagp = &genppc_isa_mem_space_tag;
    646 	return (bus_space_map(&genppc_isa_mem_space_tag, mem->minbase, mem->len,
    647 	    0, hdlp));
    648 }
    649 
    650 void
    651 pnpbus_iomem_unmap(struct pnpresources *r, int idx, bus_space_tag_t tag,
    652     bus_space_handle_t hdl)
    653 {
    654 	struct pnpbus_mem *mem;
    655 
    656 	if (idx >= r->numiomem)
    657 		return;
    658 
    659 	mem = SIMPLEQ_FIRST(&r->mem);
    660 	while (idx--)
    661 		mem = SIMPLEQ_NEXT(mem, next);
    662 
    663 	bus_space_unmap(tag, hdl, mem->len);
    664 }
    665