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