Home | History | Annotate | Line # | Download | only in oea
ofwoea_machdep.c revision 1.10
      1 /* $NetBSD: ofwoea_machdep.c,v 1.10 2008/02/05 18:10:47 garbled Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.10 2008/02/05 18:10:47 garbled Exp $");
     41 
     42 #include "opt_ppcarch.h"
     43 #include "opt_compat_netbsd.h"
     44 #include "opt_ddb.h"
     45 #include "opt_kgdb.h"
     46 #include "opt_ipkdb.h"
     47 
     48 #include <sys/param.h>
     49 #include <sys/buf.h>
     50 #include <sys/boot_flag.h>
     51 #include <sys/extent.h>
     52 #include <sys/kernel.h>
     53 #include <sys/ksyms.h>
     54 #include <uvm/uvm_extern.h>
     55 
     56 #include <dev/ofw/openfirm.h>
     57 #include <machine/pmap.h>
     58 #include <machine/powerpc.h>
     59 #include <machine/trap.h>
     60 #include <machine/vmparam.h>
     61 #include <machine/autoconf.h>
     62 #include <powerpc/bus.h>
     63 #include <powerpc/oea/bat.h>
     64 #include <powerpc/oea/cpufeat.h>
     65 #include <powerpc/ofw_bus.h>
     66 #include <powerpc/ofw_cons.h>
     67 #include <powerpc/spr.h>
     68 #include <arch/powerpc/pic/picvar.h>
     69 
     70 #include "opt_oea.h"
     71 
     72 #include "ksyms.h"
     73 
     74 #ifdef DDB
     75 #include <machine/db_machdep.h>
     76 #include <ddb/db_extern.h>
     77 #endif
     78 
     79 #ifdef KGDB
     80 #include <sys/kgdb.h>
     81 #endif
     82 
     83 #ifdef IPKDB
     84 #include <ipkdb/ipkdb.h>
     85 #endif
     86 
     87 #include "opt_ofwoea.h"
     88 
     89 #ifdef OFWOEA_DEBUG
     90 #define DPRINTF printf
     91 #else
     92 #define DPRINTF while (0) printf
     93 #endif
     94 
     95 typedef struct _rangemap {
     96 	u_int32_t addr;
     97 	u_int32_t size;
     98 	int type;
     99 } rangemap_t;
    100 
    101 struct ofw_translations {
    102 	vaddr_t va;
    103 	int len;
    104 #if defined (PMAC_G5)
    105 	register64_t pa;
    106 #else
    107 	register_t pa;
    108 #endif
    109 	int mode;
    110 }__attribute__((packed));
    111 
    112 struct pmap ofw_pmap;
    113 struct ofw_translations ofmap[32];
    114 char bootpath[256];
    115 char model_name[64];
    116 #if NKSYMS || defined(DDB) || defined(LKM)
    117 void *startsym, *endsym;
    118 #endif
    119 #ifdef TIMEBASE_FREQ
    120 u_int timebase_freq = TIMEBASE_FREQ;
    121 #else
    122 u_int timebase_freq = 0;
    123 #endif
    124 
    125 extern int ofmsr;
    126 extern int chosen;
    127 extern uint32_t ticks_per_sec;
    128 extern uint32_t ns_per_tick;
    129 extern uint32_t ticks_per_intr;
    130 extern unsigned long oeacpufeat;
    131 
    132 static int save_ofmap(struct ofw_translations *, int);
    133 static void restore_ofmap(struct ofw_translations *, int);
    134 static void set_timebase(void);
    135 
    136 void
    137 ofwoea_initppc(u_int startkernel, u_int endkernel, char *args)
    138 {
    139 	int ofmaplen, node;
    140 	register_t scratch;
    141 
    142 	/* initialze bats */
    143 	if ((oeacpufeat & OEACPU_NOBAT) == 0)
    144 		ofwoea_batinit();
    145 
    146 #if NKSYMS || defined(DDB) || defined(LKM)
    147 	/* get info of kernel symbol table from bootloader */
    148 	memcpy(&startsym, args + strlen(args) + 1, sizeof(startsym));
    149 	memcpy(&endsym, args + strlen(args) + 1 + sizeof(startsym),
    150 	    sizeof(endsym));
    151 	if (startsym == NULL || endsym == NULL)
    152 	    startsym = endsym = NULL;
    153 #endif
    154 
    155 	/* get model name and perform model-specific actions */
    156 	memset(model_name, 0, sizeof(model_name));
    157 	node = OF_finddevice("/");
    158 	if (node >= 0) {
    159 		OF_getprop(node, "model", model_name, sizeof(model_name));
    160 		model_init();
    161 	}
    162 
    163 	ofwoea_consinit();
    164 
    165 	oea_init(pic_ext_intr);
    166 
    167 	ofmaplen = save_ofmap(NULL, 0);
    168 	if (ofmaplen > 0)
    169 		save_ofmap(ofmap, ofmaplen);
    170 
    171 	ofmsr &= ~PSL_IP;
    172 
    173 	/* Parse the args string */
    174 	if (args) {
    175 		strcpy(bootpath, args);
    176 		args = bootpath;
    177 		while (*++args && *args != ' ');
    178 		if (*args) {
    179 			*args++ = 0;
    180 			while (*args)
    181 				BOOT_FLAG(*args++, boothowto);
    182 		}
    183 	}
    184 
    185 	uvm_setpagesize();
    186 
    187 #if defined (PPC_OEA64_BRIDGE) && defined (PPC_OEA)
    188 	if (oeacpufeat & OEACPU_64_BRIDGE)
    189 		pmap_setup64bridge();
    190 	else
    191 		pmap_setup32();
    192 #endif
    193 	pmap_bootstrap(startkernel, endkernel);
    194 
    195 #if defined(PPC_OEA64) || defined (PPC_OEA64_BRIDGE)
    196 #if defined (PMAC_G5)
    197 	/* Mapin 1st 256MB segment 1:1, also map in mem needed to access OFW*/
    198 	if (oeacpufeat & OEACPU_64_BRIDGE)
    199 		pmap_setup_segment0_map(0, 0xff800000, 0x3fc00000, 0x400000,
    200 		    0x0);
    201 #elif defined (MAMBO)
    202 	/* Mapin 1st 256MB segment 1:1, also map in mem needed to access OFW*/
    203 	if (oeacpufeat & OEACPU_64_BRIDGE)
    204 		pmap_setup_segment0_map(0, 0xf4000000, 0xf4000000, 0x1000, 0x0);
    205 #endif /* PMAC_G5 */
    206 #endif /* PPC_OEA64 || PPC_OEA64_BRIDGE */
    207 
    208 	/* Now enable translation (and machine checks/recoverable interrupts) */
    209 	__asm __volatile ("sync; mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    210 	    : "=r"(scratch)
    211 	    : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
    212 
    213 	restore_ofmap(ofmap, ofmaplen);
    214 
    215 #if NKSYMS || defined(DDB) || defined(LKM)
    216 	ksyms_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    217 #endif
    218 
    219 	/* CPU clock stuff */
    220 	set_timebase();
    221 }
    222 
    223 void
    224 set_timebase(void)
    225 {
    226 	int qhandle, phandle, msr, scratch;
    227 	char type[32];
    228 
    229 	if (timebase_freq != 0) {
    230 		ticks_per_sec = timebase_freq;
    231 		goto found;
    232 	}
    233 
    234 	for (qhandle = OF_peer(0); qhandle; qhandle = phandle) {
    235 		if (OF_getprop(qhandle, "device_type", type, sizeof type) > 0
    236 		    && strcmp(type, "cpu") == 0
    237 		    && OF_getprop(qhandle, "timebase-frequency",
    238 			&ticks_per_sec, sizeof ticks_per_sec) > 0) {
    239 			goto found;
    240 		}
    241 		if ((phandle = OF_child(qhandle)))
    242 			continue;
    243 		while (qhandle) {
    244 			if ((phandle = OF_peer(qhandle)))
    245 				break;
    246 			qhandle = OF_parent(qhandle);
    247 		}
    248 	}
    249 	panic("no cpu node");
    250 
    251 found:
    252 	__asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
    253 		: "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
    254 	ns_per_tick = 1000000000 / ticks_per_sec;
    255 	ticks_per_intr = ticks_per_sec / hz;
    256 	cpu_timebase = ticks_per_sec;
    257 	curcpu()->ci_lasttb = mftbl();
    258 	mtspr(SPR_DEC, ticks_per_intr);
    259 	mtmsr(msr);
    260 }
    261 
    262 static int
    263 save_ofmap(struct ofw_translations *map, int maxlen)
    264 {
    265 	int mmui, mmu, len;
    266 
    267 	OF_getprop(chosen, "mmu", &mmui, sizeof mmui);
    268 	mmu = OF_instance_to_package(mmui);
    269 
    270 	if (map) {
    271 		memset(map, 0, maxlen); /* to be safe */
    272 		len = OF_getprop(mmu, "translations", map, maxlen);
    273 	} else
    274 		len = OF_getproplen(mmu, "translations");
    275 
    276 	if (len < 0)
    277 		len = 0;
    278 	return len;
    279 }
    280 
    281 void
    282 restore_ofmap(struct ofw_translations *map, int len)
    283 {
    284 	int n = len / sizeof(struct ofw_translations);
    285 	int i;
    286 
    287 	pmap_pinit(&ofw_pmap);
    288 
    289 #if defined(PPC_OEA64_BRIDGE)
    290 	if (oeacpufeat & OEACPU_64_BRIDGE)
    291 		ofw_pmap.pm_sr[0x0] = KERNELN_SEGMENT(0);
    292 #endif
    293 	ofw_pmap.pm_sr[KERNEL_SR] = KERNEL_SEGMENT;
    294 
    295 #ifdef KERNEL2_SR
    296 	ofw_pmap.pm_sr[KERNEL2_SR] = KERNEL2_SEGMENT;
    297 #endif
    298 
    299 	for (i = 0; i < n; i++) {
    300 #if defined (PMAC_G5)
    301 		register64_t pa = map[i].pa;
    302 #else
    303 		register_t pa = map[i].pa;
    304 #endif
    305 		vaddr_t va = map[i].va;
    306 		size_t length = map[i].len;
    307 
    308 		if (va < 0xf0000000) /* XXX */
    309 			continue;
    310 
    311 		while (length > 0) {
    312 			pmap_enter(&ofw_pmap, va, (paddr_t)pa, VM_PROT_ALL,
    313 			    VM_PROT_ALL|PMAP_WIRED);
    314 			pa += PAGE_SIZE;
    315 			va += PAGE_SIZE;
    316 			length -= PAGE_SIZE;
    317 		}
    318 	}
    319 	pmap_update(&ofw_pmap);
    320 }
    321 
    322 
    323 
    324 /*
    325  * Scan the device tree for ranges, and batmap them.
    326  */
    327 
    328 static u_int16_t
    329 ranges_bitmap(int node, u_int16_t bitmap)
    330 {
    331 	int child, mlen, acells, scells, reclen, i, j;
    332 	u_int32_t addr, len, map[160];
    333 
    334 	for (child = OF_child(node); child; child = OF_peer(child)) {
    335 		mlen = OF_getprop(child, "ranges", map, sizeof(map));
    336 		if (mlen == -1)
    337 			goto noranges;
    338 
    339 		j = OF_getprop(child, "#address-cells", &acells,
    340 		    sizeof(acells));
    341 		if (j == -1)
    342 			goto noranges;
    343 
    344 		j = OF_getprop(child, "#size-cells", &scells,
    345 		    sizeof(scells));
    346 		if (j == -1)
    347 			goto noranges;
    348 
    349 		reclen = acells + 1 + scells;
    350 
    351 		for (i=0; i < (mlen/4)/reclen; i++) {
    352 			addr = map[reclen * i + acells];
    353 			len = map[reclen * i + reclen - 1];
    354 			for (j = 0; j < len / 0x10000000; j++)
    355 				bitmap |= 1 << ((addr+j*0x10000000) >>28);
    356 			bitmap |= 1 << (addr >> 28);
    357 		}
    358 noranges:
    359 		bitmap |= ranges_bitmap(child, bitmap);
    360 		continue;
    361 	}
    362 	return bitmap;
    363 }
    364 
    365 void
    366 ofwoea_batinit(void)
    367 {
    368 #if defined (PPC_OEA)
    369         u_int16_t bitmap;
    370 	int node, i;
    371 
    372 	node = OF_finddevice("/");
    373 	bitmap = ranges_bitmap(node, 0);
    374 	oea_batinit(0);
    375 
    376 #ifdef macppc
    377 	/* XXX this is a macppc-specific hack */
    378 	bitmap = 0x8f00;
    379 #endif
    380 	for (i=1; i < 0x10; i++) {
    381 		/* skip the three vital SR regions */
    382 		if (i == USER_SR || i == KERNEL_SR || i == KERNEL2_SR)
    383 			continue;
    384 		if (bitmap & (1 << i)) {
    385 			oea_iobat_add(0x10000000 * i, BAT_BL_256M);
    386 			DPRINTF("Batmapped 256M at 0x%x\n", 0x10000000 * i);
    387 		}
    388 	}
    389 #endif /* OEA */
    390 }
    391 
    392 
    393 /* we define these partially, as we will fill the rest in later */
    394 struct powerpc_bus_space genppc_isa_io_space_tag = {
    395 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
    396 	.pbs_base = 0x00000000,
    397 };
    398 
    399 struct powerpc_bus_space genppc_isa_mem_space_tag = {
    400 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
    401 	.pbs_base = 0x00000000,
    402 };
    403 
    404 /* This gives us a maximum of 6 PCI busses, assuming both io/mem on each.
    405  * Increase if necc.
    406  */
    407 static char ex_storage[EXSTORAGE_MAX][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
    408 	__attribute__((aligned(8)));
    409 
    410 
    411 static void
    412 find_ranges(int base, rangemap_t *regions, int *cur, int type)
    413 {
    414 	int node, i, len, reclen;
    415 	u_int32_t acells, scells, map[160];
    416 	char tmp[32];
    417 
    418 	node = base;
    419 	if (OF_getprop(node, "device_type", tmp, sizeof(tmp)) == -1)
    420 		goto rec;
    421 	if ((type == RANGE_TYPE_PCI || type == RANGE_TYPE_FIRSTPCI) &&
    422 	    strcmp("pci", tmp) != 0)
    423 		goto rec;
    424 	if (type == RANGE_TYPE_ISA && strcmp("isa", tmp) != 0)
    425 		goto rec;
    426 	len = OF_getprop(node, "ranges", map, sizeof(map));
    427 	if (len == -1)
    428 		goto rec;
    429 	if (OF_getprop(node, "#address-cells", &acells,
    430 	    sizeof(acells)) != sizeof(acells))
    431 		acells = 1;
    432 	if (OF_getprop(node, "#size-cells", &scells,
    433 	    sizeof(scells)) != sizeof(scells))
    434 		scells = 1;
    435 	if (type == RANGE_TYPE_ISA)
    436 		reclen = 6;
    437 	else
    438 		reclen = acells + scells + 1;
    439 	/*
    440 	 * There exist ISA buses with empty ranges properties.  This is
    441 	 * known to occur on the Pegasos II machine, and likely others.
    442 	 * According to them, that means that the isa bus is a fake bus, and
    443 	 * the real maps are the PCI maps of the preceeding bus.  To deal
    444 	 * with this, we will set cur to -1 and return.
    445 	 */
    446 	if (type == RANGE_TYPE_ISA && strcmp("isa", tmp) == 0 && len == 0) {
    447 		*cur = -1;
    448 		DPRINTF("Found empty range in isa bus\n");
    449 		return;
    450 	}
    451 
    452 	DPRINTF("found a map reclen=%d cur=%d len=%d\n", reclen, *cur, len);
    453 	switch (type) {
    454 		case RANGE_TYPE_PCI:
    455 		case RANGE_TYPE_FIRSTPCI:
    456 			for (i=0; i < len/(4*reclen); i++) {
    457 				DPRINTF("FOUND PCI RANGE\n");
    458 				regions[*cur].size =
    459 				    map[i*reclen + acells + scells];
    460 				/* skip ranges of size==0 */
    461 				if (regions[*cur].size == 0)
    462 					continue;
    463 				regions[*cur].type = map[i*reclen] >> 24;
    464 				regions[*cur].addr = map[i*reclen + acells];
    465 				(*cur)++;
    466 			}
    467 			break;
    468 		case RANGE_TYPE_ISA:
    469 			for (i=0; i < len/(4*reclen); i++) {
    470 				if (map[i*reclen] == 1)
    471 					regions[*cur].type = RANGE_IO;
    472 				else
    473 					regions[*cur].type = RANGE_MEM;
    474 				DPRINTF("FOUND ISA RANGE TYPE=%d\n",
    475 					regions[*cur].type);
    476 				regions[*cur].size =
    477 				    map[i*reclen + acells + scells];
    478 				(*cur)++;
    479 			}
    480 			break;
    481 	}
    482 	DPRINTF("returning with CUR=%d\n", *cur);
    483 	return;
    484 rec:
    485 	for (node = OF_child(base); node; node = OF_peer(node)) {
    486 		DPRINTF("RECURSE 1 STEP\n");
    487 		find_ranges(node, regions, cur, type);
    488 		if (*cur == -1)
    489 			return;
    490 	}
    491 }
    492 
    493 static int
    494 find_lowest_range(rangemap_t *ranges, int nrof, int type)
    495 {
    496 	int i, low = 0;
    497 	u_int32_t addr = 0xffffffff;
    498 
    499 	for (i=0; i < nrof; i++) {
    500 		if (ranges[i].type == type && ranges[i].addr != 0 &&
    501 		    ranges[i].addr < addr) {
    502 			low = i;
    503 			addr = ranges[i].addr;
    504 		}
    505 	}
    506 	if (addr == 0xffffffff)
    507 		return -1;
    508 	return low;
    509 }
    510 
    511 /*
    512  * Find a region of memory, and create a bus_space_tag for it.
    513  * Notes:
    514  * For ISA node is ignored.
    515  * node is the starting node.  if -1, we start at / and map everything.
    516  */
    517 
    518 int
    519 ofwoea_map_space(int rangetype, int iomem, int node,
    520     struct powerpc_bus_space *tag, const char *name)
    521 {
    522 	int i, cur, range, nrofholes, error;
    523 	static int exmap=0;
    524 	u_int32_t addr;
    525 	rangemap_t region, holes[32], list[32];
    526 
    527 	memset(list, 0, sizeof(list));
    528 	cur = 0;
    529 	if (rangetype == RANGE_TYPE_ISA || node == -1)
    530 		node = OF_finddevice("/");
    531 	if (rangetype == RANGE_TYPE_ISA) {
    532 		u_int32_t size = 0;
    533 		rangemap_t regions[32];
    534 
    535 		DPRINTF("LOOKING FOR FIRSTPCI\n");
    536 		find_ranges(node, list, &cur, RANGE_TYPE_FIRSTPCI);
    537 		range = 0;
    538 		DPRINTF("LOOKING FOR ISA\n");
    539 		find_ranges(node, regions, &range, RANGE_TYPE_ISA);
    540 		if (range == 0 || cur == 0)
    541 			return -1; /* no isa stuff found */
    542 		/*
    543 		 * This may be confusing to some.  The ISA ranges property
    544 		 * is supposed to be a set of IO ranges for the ISA bus, but
    545 		 * generally, it's just a set of pci devfunc lists that tell
    546 		 * you to go look at the parent PCI device for the actual
    547 		 * ranges.
    548 		 */
    549 		if (range == -1) {
    550 			/* we found a rangeless isa bus */
    551 		}
    552 		DPRINTF("found isa stuff\n");
    553 		for (i=0; i < range; i++)
    554 			if (regions[i].type == iomem)
    555 				size = regions[i].size;
    556 		if (iomem == RANGE_IO) {
    557 			/* the first io range is the one */
    558 			for (i=0; i < cur; i++)
    559 				if (list[i].type == RANGE_IO && size) {
    560 					DPRINTF("found IO\n");
    561 					tag->pbs_offset = list[i].addr;
    562 					tag->pbs_limit = size;
    563 					error = bus_space_init(tag, name, NULL, 0);
    564 					return error;
    565 				}
    566 		} else {
    567 			for (i=0; i < cur; i++)
    568 				if (list[i].type == RANGE_MEM &&
    569 				    list[i].size == size) {
    570 					DPRINTF("found mem\n");
    571 					tag->pbs_offset = list[i].addr;
    572 					tag->pbs_limit = size;
    573 					error = bus_space_init(tag, name, NULL, 0);
    574 					return error;
    575 				}
    576 		}
    577 		return -1; /* NO ISA FOUND */
    578 	}
    579 	find_ranges(node, list, &cur, rangetype);
    580 
    581 	DPRINTF("cur == %d\n", cur);
    582 	/* now list should contain a list of memory regions */
    583 	for (i=0; i < cur; i++)
    584 		DPRINTF("addr=0x%x size=0x%x type=%d\n", list[i].addr,
    585 		    list[i].size, list[i].type);
    586 
    587 	addr=0;
    588 	range = find_lowest_range(list, cur, iomem);
    589 	i = 0;
    590 	nrofholes = 0;
    591 	while (range != -1) {
    592 		DPRINTF("range==%d\n", range);
    593 		DPRINTF("i==%d\n", i);
    594 		if (i == 0) {
    595 			memcpy(&region, &list[range], sizeof(rangemap_t));
    596 			list[range].addr = 0;
    597 			i++;
    598 			range = find_lowest_range(list, cur, iomem);
    599 			continue;
    600 		}
    601 		if (region.addr + region.size < list[range].addr) {
    602 			/* allocate a hole */
    603 			holes[nrofholes].addr = region.size + region.addr;
    604 			holes[nrofholes].size = list[range].addr -
    605 			    holes[nrofholes].addr - 1;
    606 			nrofholes++;
    607 		}
    608 		region.size = list[range].size + list[range].addr -
    609 		    region.addr;
    610 		list[range].addr = 0;
    611 		range = find_lowest_range(list, cur, iomem);
    612 	}
    613 	DPRINTF("RANGE iomem=%d FOUND\n", iomem);
    614 	DPRINTF("addr=0x%x size=0x%x type=%d\n", region.addr,
    615 		    region.size, region.type);
    616 	DPRINTF("HOLES FOUND\n");
    617 	for (i=0; i < nrofholes; i++)
    618 		DPRINTF("addr=0x%x size=0x%x type=%d\n", holes[i].addr,
    619 		    holes[i].size, holes[i].type);
    620 	/* AT THIS POINT WE MAP IT */
    621 
    622 	if (rangetype == RANGE_TYPE_PCI) {
    623 		if (exmap == EXSTORAGE_MAX)
    624 			panic("Not enough ex_storage space. "
    625 			    "Increase EXSTORAGE_MAX");
    626 
    627 		/* XXX doing this in here might be wrong */
    628 		if (iomem == 1) {
    629 			/* we map an IO region */
    630 			tag->pbs_offset = region.addr;
    631 			tag->pbs_base = 0;
    632 			tag->pbs_limit = region.size;
    633 		} else {
    634 			/* ... or a memory region */
    635 			tag->pbs_offset = 0;
    636 			tag->pbs_base = region.addr;
    637 			tag->pbs_limit = region.size + region.addr;
    638 		}
    639 
    640 		error = bus_space_init(tag, name, ex_storage[exmap],
    641 		    sizeof(ex_storage[exmap]));
    642 		exmap++;
    643 		if (error)
    644 			panic("ofwoea_bus_space_init: can't init tag %s", name);
    645 		for (i=0; i < nrofholes; i++) {
    646 			error =
    647 			    extent_alloc_region(tag->pbs_extent,
    648 				holes[i].addr, holes[i].size, EX_NOWAIT);
    649 			if (error)
    650 				panic("ofwoea_bus_space_init: can't block out"
    651 				    " reserved space 0x%x-0x%x: error=%d",
    652 				    holes[i].addr, holes[i].addr+holes[i].size,
    653 				    error);
    654 		}
    655 		return error;
    656 	}
    657 	return -1;
    658 }
    659 
    660 void
    661 ofwoea_bus_space_init(void)
    662 {
    663 	int error;
    664 
    665 	error = ofwoea_map_space(RANGE_TYPE_ISA, RANGE_IO, -1,
    666 	    &genppc_isa_io_space_tag, "isa-ioport");
    667 	if (error > 0)
    668 		panic("Could not map ISA IO");
    669 
    670 	error = ofwoea_map_space(RANGE_TYPE_ISA, RANGE_MEM, -1,
    671 	    &genppc_isa_mem_space_tag, "isa-iomem");
    672 	if (error > 0)
    673 		panic("Could not map ISA MEM");
    674 }
    675