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