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