ofwoea_machdep.c revision 1.63 1 /* $NetBSD: ofwoea_machdep.c,v 1.63 2023/09/23 21:26:16 andvar 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.63 2023/09/23 21:26:16 andvar 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 #if NWSDISPLAY > 0
274 rascons_finalize();
275 #endif
276
277 #if NKSYMS || defined(DDB) || defined(MODULAR)
278 ksyms_addsyms_elf((int)((uintptr_t)endsym - (uintptr_t)startsym), startsym, endsym);
279 #endif
280
281 /* Kick off the clock. */
282 init_decrementer();
283
284 #ifdef DDB
285 if (boothowto & RB_KDB)
286 Debugger();
287 #endif
288 }
289
290 static void
291 get_timebase_frequency(void)
292 {
293 int qhandle, phandle, node;
294 char type[32];
295
296 if (timebase_freq != 0) {
297 ticks_per_sec = timebase_freq;
298 return;
299 }
300
301 node = OF_finddevice("/cpus/@0");
302 if (node != -1 &&
303 OF_getprop(node, "timebase-frequency", &ticks_per_sec,
304 sizeof ticks_per_sec) > 0) {
305 return;
306 }
307
308 node = OF_finddevice("/");
309 for (qhandle = node; qhandle; qhandle = phandle) {
310 if (OF_getprop(qhandle, "device_type", type, sizeof type) > 0
311 && strcmp(type, "cpu") == 0
312 && OF_getprop(qhandle, "timebase-frequency",
313 &ticks_per_sec, sizeof ticks_per_sec) > 0) {
314 return;
315 }
316 if ((phandle = OF_child(qhandle)))
317 continue;
318 while (qhandle) {
319 if ((phandle = OF_peer(qhandle)))
320 break;
321 qhandle = OF_parent(qhandle);
322 }
323 }
324 panic("no cpu node");
325 }
326
327 static void
328 init_decrementer(void)
329 {
330 int scratch, msr;
331
332 KASSERT(ticks_per_sec != 0);
333
334 __asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
335 : "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
336 ns_per_tick = 1000000000 / ticks_per_sec;
337 ticks_per_intr = ticks_per_sec / hz;
338 cpu_timebase = ticks_per_sec;
339
340 #ifdef PPC_OEA601
341 if ((mfpvr() >> 16) == MPC601)
342 curcpu()->ci_lasttb = rtc_nanosecs();
343 else
344 #endif
345 curcpu()->ci_lasttb = mftbl();
346
347 mtspr(SPR_DEC, ticks_per_intr);
348 mtmsr(msr);
349 }
350
351 void
352 restore_ofmap(void)
353 {
354 vaddr_t va, size;
355 paddr_t pa;
356 int i;
357
358 pmap_pinit(&ofw_pmap);
359
360 #ifndef _LP64
361 ofw_pmap.pm_sr[0] = KERNELN_SEGMENT(0)|SR_PRKEY;
362 ofw_pmap.pm_sr[KERNEL_SR] = KERNEL_SEGMENT|SR_SUKEY|SR_PRKEY;
363
364 #ifdef KERNEL2_SR
365 ofw_pmap.pm_sr[KERNEL2_SR] = KERNEL2_SEGMENT|SR_SUKEY|SR_PRKEY;
366 #endif
367 #endif
368
369 for (i = 0; i < __arraycount(ofw_translations); i++) {
370 va = ofw_translations[i].virt;
371 size = ofw_translations[i].size;
372 pa = ofw_translations[i].phys;
373 /* XXX mode */
374
375 if (size == 0) {
376 /* No more, all done! */
377 break;
378 }
379
380 if (va < 0xf0000000) /* XXX */
381 continue;
382
383 /*
384 * XXX macallan@
385 * My beige G3 throws a DSI trap if we try to map the last page
386 * of the 32bit address space. On old world macs the firmware
387 * ROM occupies 4MB at 0xffc00000, triggering it when we
388 * restore OF translations. This just works around a bug
389 * elsewhere in pmap and should go away once fixed there.
390 */
391 if (pa == 0xffc00000 && size == 0x400000)
392 size = 0x3ff000;
393
394 while (size > 0) {
395 pmap_enter(&ofw_pmap, va, pa, VM_PROT_ALL,
396 VM_PROT_ALL|PMAP_WIRED);
397 pa += PAGE_SIZE;
398 va += PAGE_SIZE;
399 size -= PAGE_SIZE;
400 }
401 }
402 pmap_update(&ofw_pmap);
403 }
404
405 /* we define these partially, as we will fill the rest in later */
406 struct powerpc_bus_space genppc_isa_io_space_tag = {
407 .pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
408 .pbs_base = 0x00000000,
409 };
410
411 struct powerpc_bus_space genppc_isa_mem_space_tag = {
412 .pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
413 .pbs_base = 0x00000000,
414 };
415
416 /* This gives us a maximum of 6 PCI busses, assuming both io/mem on each.
417 * Increase if necc.
418 */
419 static char ex_storage[EXSTORAGE_MAX][EXTENT_FIXED_STORAGE_SIZE(EXTMAP_RANGES)]
420 __attribute__((aligned(8)));
421
422
423 static void
424 find_ranges(int base, rangemap_t *regions, int *cur, int type)
425 {
426 int node, i, len, reclen;
427 u_int32_t parent_acells, acells, scells, map[160];
428 char tmp[32];
429
430 node = base;
431 if (OF_getprop(node, "device_type", tmp, sizeof(tmp)) == -1)
432 goto rec;
433 if ((type == RANGE_TYPE_PCI || type == RANGE_TYPE_FIRSTPCI) &&
434 strcmp("pci", tmp) != 0)
435 goto rec;
436 if (type == RANGE_TYPE_ISA && strcmp("isa", tmp) != 0)
437 goto rec;
438 if (type == RANGE_TYPE_MACIO && strcmp("memory-controller", tmp) == 0) {
439 len = OF_getprop(node, "reg", map, sizeof(map));
440 acells = 1;
441 scells = 1;
442 } else {
443 len = OF_getprop(node, "ranges", map, sizeof(map));
444 }
445 if (len == -1)
446 goto rec;
447 if (OF_getprop(OF_parent(node), "#address-cells", &parent_acells,
448 sizeof(parent_acells)) != sizeof(parent_acells))
449 parent_acells = 1;
450 if (OF_getprop(node, "#address-cells", &acells,
451 sizeof(acells)) != sizeof(acells))
452 acells = 3;
453 if (OF_getprop(node, "#size-cells", &scells,
454 sizeof(scells)) != sizeof(scells))
455 scells = 2;
456 #ifdef ofppc
457 if (modeldata.ranges_offset == 0)
458 scells -= 1;
459 #endif
460 if (type == RANGE_TYPE_ISA)
461 reclen = 6;
462 else
463 reclen = parent_acells + acells + scells;
464 /*
465 * There exist ISA buses with empty ranges properties. This is
466 * known to occur on the Pegasos II machine, and likely others.
467 * According to them, that means that the isa bus is a fake bus, and
468 * the real maps are the PCI maps of the preceding bus. To deal
469 * with this, we will set cur to -1 and return.
470 */
471 if (type == RANGE_TYPE_ISA && strcmp("isa", tmp) == 0 && len == 0) {
472 *cur = -1;
473 DPRINTF("Found empty range in isa bus\n");
474 return;
475 }
476
477 DPRINTF("found a map reclen=%d cur=%d len=%d\n", reclen, *cur, len);
478 switch (type) {
479 case RANGE_TYPE_PCI:
480 case RANGE_TYPE_FIRSTPCI:
481 for (i=0; i < len/(4*reclen); i++) {
482 DPRINTF("FOUND PCI RANGE\n");
483 regions[*cur].size =
484 map[i*reclen + parent_acells + acells + scells - 1];
485 /* skip ranges of size==0 */
486 if (regions[*cur].size == 0)
487 continue;
488 regions[*cur].type = (map[i*reclen] >> 24) & 0x3;
489 regions[*cur].addr = map[i*reclen + parent_acells + acells - 1];
490 (*cur)++;
491 }
492 break;
493 case RANGE_TYPE_ISA:
494 for (i=0; i < len/(4*reclen); i++) {
495 if (map[i*reclen] == 1)
496 regions[*cur].type = RANGE_IO;
497 else
498 regions[*cur].type = RANGE_MEM;
499 DPRINTF("FOUND ISA RANGE TYPE=%d\n",
500 regions[*cur].type);
501 regions[*cur].size =
502 map[i*reclen + acells + scells];
503 (*cur)++;
504 }
505 break;
506 case RANGE_TYPE_MACIO:
507 regions[*cur].type = RANGE_MEM;
508 if (len == 8) {
509 regions[*cur].size = map[1];
510 regions[*cur].addr = map[0];
511 } else {
512 regions[*cur].size = map[2];
513 regions[*cur].addr = map[1];
514 }
515 (*cur)++;
516 break;
517 }
518 DPRINTF("returning with CUR=%d\n", *cur);
519 return;
520 rec:
521 for (node = OF_child(base); node; node = OF_peer(node)) {
522 DPRINTF("RECURSE 1 STEP\n");
523 find_ranges(node, regions, cur, type);
524 if (*cur == -1)
525 return;
526 }
527 }
528
529 static int
530 find_lowest_range(rangemap_t *ranges, int nrof, int type)
531 {
532 int i, low = 0;
533 u_int32_t addr = 0xffffffff;
534
535 for (i=0; i < nrof; i++) {
536 if (ranges[i].type == type && ranges[i].addr != 0 &&
537 ranges[i].addr < addr) {
538 low = i;
539 addr = ranges[i].addr;
540 }
541 }
542 if (addr == 0xffffffff)
543 return -1;
544 return low;
545 }
546
547 /*
548 * Find a region of memory, and create a bus_space_tag for it.
549 * Notes:
550 * For ISA node is ignored.
551 * node is the starting node. if -1, we start at / and map everything.
552 */
553
554 int
555 ofwoea_map_space(int rangetype, int iomem, int node,
556 struct powerpc_bus_space *tag, const char *name)
557 {
558 int i, cur, range, nrofholes, error;
559 static int exmap=0;
560 rangemap_t region, holes[32], list[32];
561
562 memset(list, 0, sizeof(list));
563 memset(®ion, 0, sizeof(region));
564 cur = 0;
565 if (rangetype == RANGE_TYPE_ISA || node == -1)
566 node = OF_finddevice("/");
567 if (rangetype == RANGE_TYPE_ISA) {
568 u_int32_t size = 0;
569 rangemap_t regions[32];
570
571 DPRINTF("LOOKING FOR FIRSTPCI\n");
572 find_ranges(node, list, &cur, RANGE_TYPE_FIRSTPCI);
573 range = 0;
574 DPRINTF("LOOKING FOR ISA\n");
575 find_ranges(node, regions, &range, RANGE_TYPE_ISA);
576 if (range == 0 || cur == 0)
577 return -1; /* no isa stuff found */
578 /*
579 * This may be confusing to some. The ISA ranges property
580 * is supposed to be a set of IO ranges for the ISA bus, but
581 * generally, it's just a set of pci devfunc lists that tell
582 * you to go look at the parent PCI device for the actual
583 * ranges.
584 */
585 if (range == -1) {
586 /* we found a rangeless isa bus */
587 if (iomem == RANGE_IO)
588 size = 0x10000;
589 else
590 size = 0x1000000;
591 }
592 DPRINTF("found isa stuff\n");
593 for (i=0; i < range; i++)
594 if (regions[i].type == iomem)
595 size = regions[i].size;
596 if (iomem == RANGE_IO) {
597 /* the first io range is the one */
598 for (i=0; i < cur; i++)
599 if (list[i].type == RANGE_IO && size) {
600 DPRINTF("found IO\n");
601 tag->pbs_offset = list[i].addr;
602 tag->pbs_limit = size;
603 error = bus_space_init(tag, name,
604 ex_storage[exmap],
605 sizeof(ex_storage[exmap]));
606 exmap++;
607 return error;
608 }
609 } else {
610 for (i=0; i < cur; i++)
611 if (list[i].type == RANGE_MEM &&
612 list[i].size == size) {
613 DPRINTF("found mem\n");
614 tag->pbs_offset = list[i].addr;
615 tag->pbs_limit = size;
616 error = bus_space_init(tag, name,
617 ex_storage[exmap],
618 sizeof(ex_storage[exmap]));
619 exmap++;
620 return error;
621 }
622 }
623 return -1; /* NO ISA FOUND */
624 }
625 find_ranges(node, list, &cur, rangetype);
626
627 DPRINTF("cur == %d\n", cur);
628 /* now list should contain a list of memory regions */
629 for (i=0; i < cur; i++)
630 DPRINTF("addr=0x%x size=0x%x type=%d\n", list[i].addr,
631 list[i].size, list[i].type);
632
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) || (rangetype == RANGE_TYPE_MACIO)) {
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