ofwoea_machdep.c revision 1.26.6.1 1 /* $NetBSD: ofwoea_machdep.c,v 1.26.6.1 2012/02/18 07:32:57 mrg 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.26.6.1 2012/02/18 07:32:57 mrg 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 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
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 0);
423 #else
424 uint16_t bitmap;
425 int node, i;
426
427 node = OF_finddevice("/");
428
429 bitmap = ranges_bitmap(node, 0);
430 oea_batinit(0);
431
432 for (i=1; i < 0x10; i++) {
433 /* skip the three vital SR regions */
434 if (i == USER_SR || i == KERNEL_SR || i == KERNEL2_SR)
435 continue;
436 if (bitmap & (1 << i)) {
437 oea_iobat_add(0x10000000 * i, BAT_BL_256M);
438 DPRINTF("Batmapped 256M at 0x%x\n", 0x10000000 * i);
439 }
440 }
441 #endif
442 #endif /* OEA */
443 }
444
445
446 /* we define these partially, as we will fill the rest in later */
447 struct powerpc_bus_space genppc_isa_io_space_tag = {
448 .pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
449 .pbs_base = 0x00000000,
450 };
451
452 struct powerpc_bus_space genppc_isa_mem_space_tag = {
453 .pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
454 .pbs_base = 0x00000000,
455 };
456
457 /* This gives us a maximum of 6 PCI busses, assuming both io/mem on each.
458 * Increase if necc.
459 */
460 static char ex_storage[EXSTORAGE_MAX][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
461 __attribute__((aligned(8)));
462
463
464 static void
465 find_ranges(int base, rangemap_t *regions, int *cur, int type)
466 {
467 int node, i, len, reclen;
468 u_int32_t acells, scells, map[160];
469 char tmp[32];
470
471 node = base;
472 if (OF_getprop(node, "device_type", tmp, sizeof(tmp)) == -1)
473 goto rec;
474 if ((type == RANGE_TYPE_PCI || type == RANGE_TYPE_FIRSTPCI) &&
475 strcmp("pci", tmp) != 0)
476 goto rec;
477 if (type == RANGE_TYPE_ISA && strcmp("isa", tmp) != 0)
478 goto rec;
479 len = OF_getprop(node, "ranges", map, sizeof(map));
480 if (len == -1)
481 goto rec;
482 if (OF_getprop(node, "#address-cells", &acells,
483 sizeof(acells)) != sizeof(acells))
484 acells = 1;
485 if (OF_getprop(node, "#size-cells", &scells,
486 sizeof(scells)) != sizeof(scells))
487 scells = 1;
488 #ifdef ofppc
489 if (modeldata.ranges_offset == 0)
490 scells -= 1;
491 #endif
492 if (type == RANGE_TYPE_ISA)
493 reclen = 6;
494 else
495 reclen = acells + scells + 1;
496 /*
497 * There exist ISA buses with empty ranges properties. This is
498 * known to occur on the Pegasos II machine, and likely others.
499 * According to them, that means that the isa bus is a fake bus, and
500 * the real maps are the PCI maps of the preceeding bus. To deal
501 * with this, we will set cur to -1 and return.
502 */
503 if (type == RANGE_TYPE_ISA && strcmp("isa", tmp) == 0 && len == 0) {
504 *cur = -1;
505 DPRINTF("Found empty range in isa bus\n");
506 return;
507 }
508
509 DPRINTF("found a map reclen=%d cur=%d len=%d\n", reclen, *cur, len);
510 switch (type) {
511 case RANGE_TYPE_PCI:
512 case RANGE_TYPE_FIRSTPCI:
513 for (i=0; i < len/(4*reclen); i++) {
514 DPRINTF("FOUND PCI RANGE\n");
515 regions[*cur].size =
516 map[i*reclen + acells + scells];
517 /* skip ranges of size==0 */
518 if (regions[*cur].size == 0)
519 continue;
520 regions[*cur].type = map[i*reclen] >> 24;
521 regions[*cur].addr = map[i*reclen + acells];
522 (*cur)++;
523 }
524 break;
525 case RANGE_TYPE_ISA:
526 for (i=0; i < len/(4*reclen); i++) {
527 if (map[i*reclen] == 1)
528 regions[*cur].type = RANGE_IO;
529 else
530 regions[*cur].type = RANGE_MEM;
531 DPRINTF("FOUND ISA RANGE TYPE=%d\n",
532 regions[*cur].type);
533 regions[*cur].size =
534 map[i*reclen + acells + scells];
535 (*cur)++;
536 }
537 break;
538 }
539 DPRINTF("returning with CUR=%d\n", *cur);
540 return;
541 rec:
542 for (node = OF_child(base); node; node = OF_peer(node)) {
543 DPRINTF("RECURSE 1 STEP\n");
544 find_ranges(node, regions, cur, type);
545 if (*cur == -1)
546 return;
547 }
548 }
549
550 static int
551 find_lowest_range(rangemap_t *ranges, int nrof, int type)
552 {
553 int i, low = 0;
554 u_int32_t addr = 0xffffffff;
555
556 for (i=0; i < nrof; i++) {
557 if (ranges[i].type == type && ranges[i].addr != 0 &&
558 ranges[i].addr < addr) {
559 low = i;
560 addr = ranges[i].addr;
561 }
562 }
563 if (addr == 0xffffffff)
564 return -1;
565 return low;
566 }
567
568 /*
569 * Find a region of memory, and create a bus_space_tag for it.
570 * Notes:
571 * For ISA node is ignored.
572 * node is the starting node. if -1, we start at / and map everything.
573 */
574
575 int
576 ofwoea_map_space(int rangetype, int iomem, int node,
577 struct powerpc_bus_space *tag, const char *name)
578 {
579 int i, cur, range, nrofholes, error;
580 static int exmap=0;
581 u_int32_t addr;
582 rangemap_t region, holes[32], list[32];
583
584 memset(list, 0, sizeof(list));
585 cur = 0;
586 if (rangetype == RANGE_TYPE_ISA || node == -1)
587 node = OF_finddevice("/");
588 if (rangetype == RANGE_TYPE_ISA) {
589 u_int32_t size = 0;
590 rangemap_t regions[32];
591
592 DPRINTF("LOOKING FOR FIRSTPCI\n");
593 find_ranges(node, list, &cur, RANGE_TYPE_FIRSTPCI);
594 range = 0;
595 DPRINTF("LOOKING FOR ISA\n");
596 find_ranges(node, regions, &range, RANGE_TYPE_ISA);
597 if (range == 0 || cur == 0)
598 return -1; /* no isa stuff found */
599 /*
600 * This may be confusing to some. The ISA ranges property
601 * is supposed to be a set of IO ranges for the ISA bus, but
602 * generally, it's just a set of pci devfunc lists that tell
603 * you to go look at the parent PCI device for the actual
604 * ranges.
605 */
606 if (range == -1) {
607 /* we found a rangeless isa bus */
608 if (iomem == RANGE_IO)
609 size = 0x10000;
610 else
611 size = 0x1000000;
612 }
613 DPRINTF("found isa stuff\n");
614 for (i=0; i < range; i++)
615 if (regions[i].type == iomem)
616 size = regions[i].size;
617 if (iomem == RANGE_IO) {
618 /* the first io range is the one */
619 for (i=0; i < cur; i++)
620 if (list[i].type == RANGE_IO && size) {
621 DPRINTF("found IO\n");
622 tag->pbs_offset = list[i].addr;
623 tag->pbs_limit = size;
624 error = bus_space_init(tag, name,
625 ex_storage[exmap],
626 sizeof(ex_storage[exmap]));
627 exmap++;
628 return error;
629 }
630 } else {
631 for (i=0; i < cur; i++)
632 if (list[i].type == RANGE_MEM &&
633 list[i].size == size) {
634 DPRINTF("found mem\n");
635 tag->pbs_offset = list[i].addr;
636 tag->pbs_limit = size;
637 error = bus_space_init(tag, name,
638 ex_storage[exmap],
639 sizeof(ex_storage[exmap]));
640 exmap++;
641 return error;
642 }
643 }
644 return -1; /* NO ISA FOUND */
645 }
646 find_ranges(node, list, &cur, rangetype);
647
648 DPRINTF("cur == %d\n", cur);
649 /* now list should contain a list of memory regions */
650 for (i=0; i < cur; i++)
651 DPRINTF("addr=0x%x size=0x%x type=%d\n", list[i].addr,
652 list[i].size, list[i].type);
653
654 addr=0;
655 range = find_lowest_range(list, cur, iomem);
656 i = 0;
657 nrofholes = 0;
658 while (range != -1) {
659 DPRINTF("range==%d\n", range);
660 DPRINTF("i==%d\n", i);
661 if (i == 0) {
662 memcpy(®ion, &list[range], sizeof(rangemap_t));
663 list[range].addr = 0;
664 i++;
665 range = find_lowest_range(list, cur, iomem);
666 continue;
667 }
668 if (region.addr + region.size < list[range].addr) {
669 /* allocate a hole */
670 holes[nrofholes].type = iomem;
671 holes[nrofholes].addr = region.size + region.addr;
672 holes[nrofholes].size = list[range].addr -
673 holes[nrofholes].addr - 1;
674 nrofholes++;
675 }
676 region.size = list[range].size + list[range].addr -
677 region.addr;
678 list[range].addr = 0;
679 range = find_lowest_range(list, cur, iomem);
680 }
681 DPRINTF("RANGE iomem=%d FOUND\n", iomem);
682 DPRINTF("addr=0x%x size=0x%x type=%d\n", region.addr,
683 region.size, region.type);
684 DPRINTF("HOLES FOUND\n");
685 for (i=0; i < nrofholes; i++)
686 DPRINTF("addr=0x%x size=0x%x type=%d\n", holes[i].addr,
687 holes[i].size, holes[i].type);
688 /* AT THIS POINT WE MAP IT */
689
690 if (rangetype == RANGE_TYPE_PCI) {
691 if (exmap == EXSTORAGE_MAX)
692 panic("Not enough ex_storage space. "
693 "Increase EXSTORAGE_MAX");
694
695 /* XXX doing this in here might be wrong */
696 if (iomem == 1) {
697 /* we map an IO region */
698 tag->pbs_offset = region.addr;
699 tag->pbs_base = 0;
700 tag->pbs_limit = region.size;
701 } else {
702 /* ... or a memory region */
703 tag->pbs_offset = 0;
704 tag->pbs_base = region.addr;
705 tag->pbs_limit = region.size + region.addr;
706 }
707
708 error = bus_space_init(tag, name, ex_storage[exmap],
709 sizeof(ex_storage[exmap]));
710 exmap++;
711 if (error)
712 panic("ofwoea_bus_space_init: can't init tag %s", name);
713 for (i=0; i < nrofholes; i++) {
714 if (holes[i].type == RANGE_IO) {
715 error = extent_alloc_region(tag->pbs_extent,
716 holes[i].addr - tag->pbs_offset,
717 holes[i].size, EX_NOWAIT);
718 } else {
719 error = extent_alloc_region(tag->pbs_extent,
720 holes[i].addr, holes[i].size, EX_NOWAIT);
721 }
722 if (error)
723 panic("ofwoea_bus_space_init: can't block out"
724 " reserved space 0x%x-0x%x: error=%d",
725 holes[i].addr, holes[i].addr+holes[i].size,
726 error);
727 }
728 return error;
729 }
730 return -1;
731 }
732
733 void
734 ofwoea_bus_space_init(void)
735 {
736 int error;
737
738 error = ofwoea_map_space(RANGE_TYPE_ISA, RANGE_IO, -1,
739 &genppc_isa_io_space_tag, "isa-ioport");
740 if (error > 0)
741 panic("Could not map ISA IO");
742
743 error = ofwoea_map_space(RANGE_TYPE_ISA, RANGE_MEM, -1,
744 &genppc_isa_mem_space_tag, "isa-iomem");
745 if (error > 0)
746 panic("Could not map ISA MEM");
747 }
748