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