ofw.c revision 1.38 1 /* $NetBSD: ofw.c,v 1.38 2007/03/08 20:48:39 matt Exp $ */
2
3 /*
4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
23 *
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
34 */
35
36 /*
37 * Routines for interfacing between NetBSD and OFW.
38 *
39 * Parts of this could be moved to an MI file in time. -JJK
40 *
41 */
42
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: ofw.c,v 1.38 2007/03/08 20:48:39 matt Exp $");
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/reboot.h>
50 #include <sys/mbuf.h>
51
52 #include <uvm/uvm_extern.h>
53
54 #include <dev/cons.h>
55
56 #define _ARM32_BUS_DMA_PRIVATE
57 #include <machine/bus.h>
58 #include <machine/frame.h>
59 #include <machine/bootconfig.h>
60 #include <machine/cpu.h>
61 #include <machine/intr.h>
62 #include <machine/irqhandler.h>
63
64 #include <dev/ofw/openfirm.h>
65 #include <machine/ofw.h>
66
67 #include <netinet/in.h>
68
69 #if BOOT_FW_DHCP
70 #include <nfs/bootdata.h>
71 #endif
72
73 #ifdef SHARK
74 #include "machine/pio.h"
75 #include "machine/isa_machdep.h"
76 #endif
77
78 #include "pc.h"
79 #include "isadma.h"
80 #include "igsfb_ofbus.h"
81 #include "vga_ofbus.h"
82
83 #define IO_VIRT_BASE (OFW_VIRT_BASE + OFW_VIRT_SIZE)
84 #define IO_VIRT_SIZE 0x01000000
85
86 #define KERNEL_IMG_PTS 2
87 #define KERNEL_VMDATA_PTS (KERNEL_VM_SIZE >> (L1_S_SHIFT + 2))
88 #define KERNEL_OFW_PTS 4
89 #define KERNEL_IO_PTS 4
90
91 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
92 /*
93 * The range 0xf1000000 - 0xf6ffffff is available for kernel VM space
94 * OFW sits at 0xf7000000
95 */
96 #define KERNEL_VM_SIZE 0x06000000
97
98 /*
99 * Imported variables
100 */
101 extern BootConfig bootconfig; /* temporary, I hope */
102
103 #ifdef DIAGNOSTIC
104 /* NOTE: These variables will be removed, well some of them */
105 extern u_int spl_mask;
106 extern u_int current_mask;
107 #endif
108
109 extern int ofw_handleticks;
110
111
112 /*
113 * Imported routines
114 */
115 extern void dump_spl_masks __P((void));
116 extern void dumpsys __P((void));
117 extern void dotickgrovelling __P((vaddr_t));
118 #if defined(SHARK) && (NPC > 0)
119 extern void shark_screen_cleanup __P((int));
120 #endif
121
122 #define WriteWord(a, b) \
123 *((volatile unsigned int *)(a)) = (b)
124
125 #define ReadWord(a) \
126 (*((volatile unsigned int *)(a)))
127
128
129 /*
130 * Exported variables
131 */
132 /* These should all be in a meminfo structure. */
133 paddr_t physical_start;
134 paddr_t physical_freestart;
135 paddr_t physical_freeend;
136 paddr_t physical_end;
137 u_int free_pages;
138 int physmem;
139 pv_addr_t systempage;
140 #ifndef OFWGENCFG
141 pv_addr_t irqstack;
142 #endif
143 pv_addr_t undstack;
144 pv_addr_t abtstack;
145 pv_addr_t kernelstack;
146
147 paddr_t msgbufphys;
148
149 /* for storage allocation, used to be local to ofw_construct_proc0_addrspace */
150 static vaddr_t virt_freeptr;
151
152 int ofw_callbacks = 0; /* debugging counter */
153
154 #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
155 int console_ihandle = 0;
156 static void reset_screen(void);
157 #endif
158
159 /**************************************************************/
160
161
162 /*
163 * Declarations and definitions private to this module
164 *
165 */
166
167 struct mem_region {
168 paddr_t start;
169 psize_t size;
170 };
171
172 struct mem_translation {
173 vaddr_t virt;
174 vsize_t size;
175 paddr_t phys;
176 unsigned int mode;
177 };
178
179 struct isa_range {
180 paddr_t isa_phys_hi;
181 paddr_t isa_phys_lo;
182 paddr_t parent_phys_start;
183 psize_t isa_size;
184 };
185
186 struct vl_range {
187 paddr_t vl_phys_hi;
188 paddr_t vl_phys_lo;
189 paddr_t parent_phys_start;
190 psize_t vl_size;
191 };
192
193 struct vl_isa_range {
194 paddr_t isa_phys_hi;
195 paddr_t isa_phys_lo;
196 paddr_t parent_phys_hi;
197 paddr_t parent_phys_lo;
198 psize_t isa_size;
199 };
200
201 struct dma_range {
202 paddr_t start;
203 psize_t size;
204 };
205
206 struct ofw_cbargs {
207 char *name;
208 int nargs;
209 int nreturns;
210 int args_n_results[12];
211 };
212
213
214 /* Memory info */
215 static int nOFphysmem;
216 static struct mem_region *OFphysmem;
217 static int nOFphysavail;
218 static struct mem_region *OFphysavail;
219 static int nOFtranslations;
220 static struct mem_translation *OFtranslations;
221 static int nOFdmaranges;
222 static struct dma_range *OFdmaranges;
223
224 /* The OFW client services handle. */
225 /* Initialized by ofw_init(). */
226 static ofw_handle_t ofw_client_services_handle;
227
228
229 static void ofw_callbackhandler __P((void *));
230 static void ofw_construct_proc0_addrspace __P((pv_addr_t *));
231 static void ofw_getphysmeminfo __P((void));
232 static void ofw_getvirttranslations __P((void));
233 static void *ofw_malloc(vsize_t size);
234 static void ofw_claimpages __P((vaddr_t *, pv_addr_t *, vsize_t));
235 static void ofw_discardmappings __P ((vaddr_t, vaddr_t, vsize_t));
236 static int ofw_mem_ihandle __P((void));
237 static int ofw_mmu_ihandle __P((void));
238 static paddr_t ofw_claimphys __P((paddr_t, psize_t, paddr_t));
239 #if 0
240 static paddr_t ofw_releasephys __P((paddr_t, psize_t));
241 #endif
242 static vaddr_t ofw_claimvirt __P((vaddr_t, vsize_t, vaddr_t));
243 static void ofw_settranslation __P ((vaddr_t, paddr_t, vsize_t, int));
244 static void ofw_initallocator __P((void));
245 static void ofw_configisaonly __P((paddr_t *, paddr_t *));
246 static void ofw_configvl __P((int, paddr_t *, paddr_t *));
247 static vaddr_t ofw_valloc __P((vsize_t, vaddr_t));
248
249
250 /*
251 * DHCP hooks. For a first cut, we look to see if there is a DHCP
252 * packet that was saved by the firmware. If not, we proceed as before,
253 * getting hand-configured data from NVRAM. If there is one, we get the
254 * packet, and extract the data from it. For now, we hand that data up
255 * in the boot_args string as before.
256 */
257
258
259 /**************************************************************/
260
261
262 /*
263 *
264 * Support routines for xxx_machdep.c
265 *
266 * The intent is that all OFW-based configurations use the
267 * exported routines in this file to do their business. If
268 * they need to override some function they are free to do so.
269 *
270 * The exported routines are:
271 *
272 * openfirmware
273 * ofw_init
274 * ofw_boot
275 * ofw_getbootinfo
276 * ofw_configmem
277 * ofw_configisa
278 * ofw_configisadma
279 * ofw_gettranslation
280 * ofw_map
281 * ofw_getcleaninfo
282 */
283
284
285 int
286 openfirmware(args)
287 void *args;
288 {
289 int ofw_result;
290 u_int saved_irq_state;
291
292 /* OFW is not re-entrant, so we wrap a mutex around the call. */
293 saved_irq_state = disable_interrupts(I32_bit);
294 ofw_result = ofw_client_services_handle(args);
295 (void)restore_interrupts(saved_irq_state);
296
297 return(ofw_result);
298 }
299
300
301 void
302 ofw_init(ofw_handle)
303 ofw_handle_t ofw_handle;
304 {
305 ofw_client_services_handle = ofw_handle;
306
307 /* Everything we allocate in the remainder of this block is
308 * constrained to be in the "kernel-static" portion of the
309 * virtual address space (i.e., 0xF0000000 - 0xF1000000).
310 * This is because all such objects are expected to be in
311 * that range by NetBSD, or the objects will be re-mapped
312 * after the page-table-switch to other specific locations.
313 * In the latter case, it's simplest if our pre-switch handles
314 * on those objects are in regions that are already "well-
315 * known." (Otherwise, the cloning of the OFW-managed address-
316 * space becomes more awkward.) To minimize the number of L2
317 * page tables that we use, we are further restricting the
318 * remaining allocations in this block to the bottom quarter of
319 * the legal range. OFW will have loaded the kernel text+data+bss
320 * starting at the bottom of the range, and we will allocate
321 * objects from the top, moving downwards. The two sub-regions
322 * will collide if their total sizes hit 8MB. The current total
323 * is <1.5MB, but INSTALL kernels are > 4MB, so hence the 8MB
324 * limit. The variable virt-freeptr represents the next free va
325 * (moving downwards).
326 */
327 virt_freeptr = KERNEL_BASE + (0x00400000 * KERNEL_IMG_PTS);
328 }
329
330
331 void
332 ofw_boot(howto, bootstr)
333 int howto;
334 char *bootstr;
335 {
336
337 #ifdef DIAGNOSTIC
338 printf("boot: howto=%08x curlwp=%p\n", howto, curlwp);
339 printf("current_mask=%08x spl_mask=%08x\n", current_mask, spl_mask);
340
341 printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n",
342 irqmasks[IPL_BIO], irqmasks[IPL_NET], irqmasks[IPL_TTY],
343 irqmasks[IPL_VM]);
344 printf("ipl_audio=%08x ipl_clock=%08x ipl_none=%08x\n",
345 irqmasks[IPL_AUDIO], irqmasks[IPL_CLOCK], irqmasks[IPL_NONE]);
346
347 dump_spl_masks();
348 #endif
349
350 /*
351 * If we are still cold then hit the air brakes
352 * and crash to earth fast
353 */
354 if (cold) {
355 doshutdownhooks();
356 printf("Halted while still in the ICE age.\n");
357 printf("The operating system has halted.\n");
358 goto ofw_exit;
359 /*NOTREACHED*/
360 }
361
362 /*
363 * If RB_NOSYNC was not specified sync the discs.
364 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
365 * It looks like syslogd is getting woken up only to find that it cannot
366 * page part of the binary in as the filesystem has been unmounted.
367 */
368 if (!(howto & RB_NOSYNC))
369 bootsync();
370
371 /* Say NO to interrupts */
372 splhigh();
373
374 /* Do a dump if requested. */
375 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
376 dumpsys();
377
378 /* Run any shutdown hooks */
379 doshutdownhooks();
380
381 /* Make sure IRQ's are disabled */
382 IRQdisable;
383
384 if (howto & RB_HALT) {
385 printf("The operating system has halted.\n");
386 goto ofw_exit;
387 }
388
389 /* Tell the user we are booting */
390 printf("rebooting...\n");
391
392 /* Jump into the OFW boot routine. */
393 {
394 static char str[256];
395 char *ap = str, *ap1 = ap;
396
397 if (bootstr && *bootstr) {
398 if (strlen(bootstr) > sizeof str - 5)
399 printf("boot string too large, ignored\n");
400 else {
401 strcpy(str, bootstr);
402 ap1 = ap = str + strlen(str);
403 *ap++ = ' ';
404 }
405 }
406 *ap++ = '-';
407 if (howto & RB_SINGLE)
408 *ap++ = 's';
409 if (howto & RB_KDB)
410 *ap++ = 'd';
411 *ap++ = 0;
412 if (ap[-2] == '-')
413 *ap1 = 0;
414 #if defined(SHARK) && (NPC > 0)
415 shark_screen_cleanup(0);
416 #elif (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
417 reset_screen();
418 #endif
419 OF_boot(str);
420 /*NOTREACHED*/
421 }
422
423 ofw_exit:
424 printf("Calling OF_exit...\n");
425 #if defined(SHARK) && (NPC > 0)
426 shark_screen_cleanup(1);
427 #elif (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
428 reset_screen();
429 #endif
430 OF_exit();
431 /*NOTREACHED*/
432 }
433
434
435 #if BOOT_FW_DHCP
436
437 extern char *ip2dotted __P((struct in_addr));
438
439 /*
440 * Get DHCP data from OFW
441 */
442
443 void
444 get_fw_dhcp_data(bdp)
445 struct bootdata *bdp;
446 {
447 int chosen;
448 int dhcplen;
449
450 bzero((char *)bdp, sizeof(*bdp));
451 if ((chosen = OF_finddevice("/chosen")) == -1)
452 panic("no /chosen from OFW");
453 if ((dhcplen = OF_getproplen(chosen, "bootp-response")) > 0) {
454 u_char *cp;
455 int dhcp_type = 0;
456 char *ip;
457
458 /*
459 * OFW saved a DHCP (or BOOTP) packet for us.
460 */
461 if (dhcplen > sizeof(bdp->dhcp_packet))
462 panic("DHCP packet too large");
463 OF_getprop(chosen, "bootp-response", &bdp->dhcp_packet,
464 sizeof(bdp->dhcp_packet));
465 SANITY(bdp->dhcp_packet.op == BOOTREPLY, "bogus DHCP packet");
466 /*
467 * Collect the interesting data from DHCP into
468 * the bootdata structure.
469 */
470 bdp->ip_address = bdp->dhcp_packet.yiaddr;
471 ip = ip2dotted(bdp->ip_address);
472 if (bcmp(bdp->dhcp_packet.options, DHCP_OPTIONS_COOKIE, 4) == 0)
473 parse_dhcp_options(&bdp->dhcp_packet,
474 bdp->dhcp_packet.options + 4,
475 &bdp->dhcp_packet.options[dhcplen
476 - DHCP_FIXED_NON_UDP], bdp, ip);
477 if (bdp->root_ip.s_addr == 0)
478 bdp->root_ip = bdp->dhcp_packet.siaddr;
479 if (bdp->swap_ip.s_addr == 0)
480 bdp->swap_ip = bdp->dhcp_packet.siaddr;
481 }
482 /*
483 * If the DHCP packet did not contain all the necessary data,
484 * look in NVRAM for the missing parts.
485 */
486 {
487 int options;
488 int proplen;
489 #define BOOTJUNKV_SIZE 256
490 char bootjunkv[BOOTJUNKV_SIZE]; /* minimize stack usage */
491
492
493 if ((options = OF_finddevice("/options")) == -1)
494 panic("can't find /options");
495 if (bdp->ip_address.s_addr == 0 &&
496 (proplen = OF_getprop(options, "ipaddr",
497 bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
498 bootjunkv[proplen] = '\0';
499 if (dotted2ip(bootjunkv, &bdp->ip_address.s_addr) == 0)
500 bdp->ip_address.s_addr = 0;
501 }
502 if (bdp->ip_mask.s_addr == 0 &&
503 (proplen = OF_getprop(options, "netmask",
504 bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
505 bootjunkv[proplen] = '\0';
506 if (dotted2ip(bootjunkv, &bdp->ip_mask.s_addr) == 0)
507 bdp->ip_mask.s_addr = 0;
508 }
509 if (bdp->hostname[0] == '\0' &&
510 (proplen = OF_getprop(options, "hostname",
511 bdp->hostname, sizeof(bdp->hostname) - 1)) > 0) {
512 bdp->hostname[proplen] = '\0';
513 }
514 if (bdp->root[0] == '\0' &&
515 (proplen = OF_getprop(options, "rootfs",
516 bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
517 bootjunkv[proplen] = '\0';
518 parse_server_path(bootjunkv, &bdp->root_ip, bdp->root);
519 }
520 if (bdp->swap[0] == '\0' &&
521 (proplen = OF_getprop(options, "swapfs",
522 bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
523 bootjunkv[proplen] = '\0';
524 parse_server_path(bootjunkv, &bdp->swap_ip, bdp->swap);
525 }
526 }
527 }
528
529 #endif /* BOOT_FW_DHCP */
530
531 void
532 ofw_getbootinfo(bp_pp, ba_pp)
533 char **bp_pp;
534 char **ba_pp;
535 {
536 int chosen;
537 int bp_len;
538 int ba_len;
539 char *bootpathv;
540 char *bootargsv;
541
542 /* Read the bootpath and bootargs out of OFW. */
543 /* XXX is bootpath still interesting? --emg */
544 if ((chosen = OF_finddevice("/chosen")) == -1)
545 panic("no /chosen from OFW");
546 bp_len = OF_getproplen(chosen, "bootpath");
547 ba_len = OF_getproplen(chosen, "bootargs");
548 if (bp_len < 0 || ba_len < 0)
549 panic("can't get boot data from OFW");
550
551 bootpathv = (char *)ofw_malloc(bp_len);
552 bootargsv = (char *)ofw_malloc(ba_len);
553
554 if (bp_len)
555 OF_getprop(chosen, "bootpath", bootpathv, bp_len);
556 else
557 bootpathv[0] = '\0';
558
559 if (ba_len)
560 OF_getprop(chosen, "bootargs", bootargsv, ba_len);
561 else
562 bootargsv[0] = '\0';
563
564 *bp_pp = bootpathv;
565 *ba_pp = bootargsv;
566 #ifdef DIAGNOSTIC
567 printf("bootpath=<%s>, bootargs=<%s>\n", bootpathv, bootargsv);
568 #endif
569 }
570
571 paddr_t
572 ofw_getcleaninfo(void)
573 {
574 int cpu;
575 vaddr_t vclean;
576 paddr_t pclean;
577
578 if ((cpu = OF_finddevice("/cpu")) == -1)
579 panic("no /cpu from OFW");
580
581 if ((OF_getprop(cpu, "d-cache-flush-address", &vclean,
582 sizeof(vclean))) != sizeof(vclean)) {
583 #ifdef DEBUG
584 printf("no OFW d-cache-flush-address property\n");
585 #endif
586 return -1;
587 }
588
589 if ((pclean = ofw_gettranslation(
590 of_decode_int((unsigned char *)&vclean))) == -1)
591 panic("OFW failed to translate cache flush address");
592
593 return pclean;
594 }
595
596 void
597 ofw_configisa(pio, pmem)
598 paddr_t *pio;
599 paddr_t *pmem;
600 {
601 int vl;
602
603 if ((vl = OF_finddevice("/vlbus")) == -1) /* old style OFW dev info tree */
604 ofw_configisaonly(pio, pmem);
605 else /* old style OFW dev info tree */
606 ofw_configvl(vl, pio, pmem);
607 }
608
609 static void
610 ofw_configisaonly(pio, pmem)
611 paddr_t *pio;
612 paddr_t *pmem;
613 {
614 int isa;
615 int rangeidx;
616 int size;
617 paddr_t hi, start;
618 struct isa_range ranges[2];
619
620 if ((isa = OF_finddevice("/isa")) == -1)
621 panic("OFW has no /isa device node");
622
623 /* expect to find two isa ranges: IO/data and memory/data */
624 if ((size = OF_getprop(isa, "ranges", ranges, sizeof(ranges)))
625 != sizeof(ranges))
626 panic("unexpected size of OFW /isa ranges property: %d", size);
627
628 *pio = *pmem = -1;
629
630 for (rangeidx = 0; rangeidx < 2; ++rangeidx) {
631 hi = of_decode_int((unsigned char *)
632 &ranges[rangeidx].isa_phys_hi);
633 start = of_decode_int((unsigned char *)
634 &ranges[rangeidx].parent_phys_start);
635
636 if (hi & 1) { /* then I/O space */
637 *pio = start;
638 } else {
639 *pmem = start;
640 }
641 } /* END for */
642
643 if ((*pio == -1) || (*pmem == -1))
644 panic("bad OFW /isa ranges property");
645
646 }
647
648 static void
649 ofw_configvl(vl, pio, pmem)
650 int vl;
651 paddr_t *pio;
652 paddr_t *pmem;
653 {
654 int isa;
655 int ir, vr;
656 int size;
657 paddr_t hi, start;
658 struct vl_isa_range isa_ranges[2];
659 struct vl_range vl_ranges[2];
660
661 if ((isa = OF_finddevice("/vlbus/isa")) == -1)
662 panic("OFW has no /vlbus/isa device node");
663
664 /* expect to find two isa ranges: IO/data and memory/data */
665 if ((size = OF_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges)))
666 != sizeof(isa_ranges))
667 panic("unexpected size of OFW /vlbus/isa ranges property: %d",
668 size);
669
670 /* expect to find two vl ranges: IO/data and memory/data */
671 if ((size = OF_getprop(vl, "ranges", vl_ranges, sizeof(vl_ranges)))
672 != sizeof(vl_ranges))
673 panic("unexpected size of OFW /vlbus ranges property: %d", size);
674
675 *pio = -1;
676 *pmem = -1;
677
678 for (ir = 0; ir < 2; ++ir) {
679 for (vr = 0; vr < 2; ++vr) {
680 if ((isa_ranges[ir].parent_phys_hi
681 == vl_ranges[vr].vl_phys_hi) &&
682 (isa_ranges[ir].parent_phys_lo
683 == vl_ranges[vr].vl_phys_lo)) {
684 hi = of_decode_int((unsigned char *)
685 &isa_ranges[ir].isa_phys_hi);
686 start = of_decode_int((unsigned char *)
687 &vl_ranges[vr].parent_phys_start);
688
689 if (hi & 1) { /* then I/O space */
690 *pio = start;
691 } else {
692 *pmem = start;
693 }
694 } /* END if */
695 } /* END for */
696 } /* END for */
697
698 if ((*pio == -1) || (*pmem == -1))
699 panic("bad OFW /isa ranges property");
700 }
701
702 #if NISADMA > 0
703 struct arm32_dma_range *shark_isa_dma_ranges;
704 int shark_isa_dma_nranges;
705 #endif
706
707 void
708 ofw_configisadma(pdma)
709 paddr_t *pdma;
710 {
711 int root;
712 int rangeidx;
713 int size;
714 struct dma_range *dr;
715
716 if ((root = OF_finddevice("/")) == -1 ||
717 (size = OF_getproplen(root, "dma-ranges")) <= 0 ||
718 (OFdmaranges = (struct dma_range *)ofw_malloc(size)) == 0 ||
719 OF_getprop(root, "dma-ranges", OFdmaranges, size) != size)
720 panic("bad / dma-ranges property");
721
722 nOFdmaranges = size / sizeof(struct dma_range);
723
724 #if NISADMA > 0
725 /* Allocate storage for non-OFW representation of the range. */
726 shark_isa_dma_ranges = ofw_malloc(nOFdmaranges *
727 sizeof(*shark_isa_dma_ranges));
728 if (shark_isa_dma_ranges == NULL)
729 panic("unable to allocate shark_isa_dma_ranges");
730 shark_isa_dma_nranges = nOFdmaranges;
731 #endif
732
733 for (rangeidx = 0, dr = OFdmaranges; rangeidx < nOFdmaranges;
734 ++rangeidx, ++dr) {
735 dr->start = of_decode_int((unsigned char *)&dr->start);
736 dr->size = of_decode_int((unsigned char *)&dr->size);
737 #if NISADMA > 0
738 shark_isa_dma_ranges[rangeidx].dr_sysbase = dr->start;
739 shark_isa_dma_ranges[rangeidx].dr_busbase = dr->start;
740 shark_isa_dma_ranges[rangeidx].dr_len = dr->size;
741 #endif
742 }
743
744 #ifdef DEBUG
745 printf("DMA ranges size = %d\n", size);
746
747 for (rangeidx = 0; rangeidx < nOFdmaranges; ++rangeidx) {
748 printf("%08lx %08lx\n",
749 (u_long)OFdmaranges[rangeidx].start,
750 (u_long)OFdmaranges[rangeidx].size);
751 }
752 #endif
753 }
754
755 /*
756 * Memory configuration:
757 *
758 * We start off running in the environment provided by OFW.
759 * This has the MMU turned on, the kernel code and data
760 * mapped-in at KERNEL_BASE (0xF0000000), OFW's text and
761 * data mapped-in at OFW_VIRT_BASE (0xF7000000), and (possibly)
762 * page0 mapped-in at 0x0.
763 *
764 * The strategy is to set-up the address space for proc0 --
765 * including the allocation of space for new page tables -- while
766 * memory is still managed by OFW. We then effectively create a
767 * copy of the address space by dumping all of OFW's translations
768 * and poking them into the new page tables. We then notify OFW
769 * that we are assuming control of memory-management by installing
770 * our callback-handler, and switch to the NetBSD-managed page
771 * tables with the setttb() call.
772 *
773 * This scheme may cause some amount of memory to be wasted within
774 * OFW as dead page tables, but it shouldn't be more than about
775 * 20-30KB. (It's also possible that OFW will re-use the space.)
776 */
777 void
778 ofw_configmem(void)
779 {
780 pv_addr_t proc0_ttbbase;
781 int i;
782
783 /* Set-up proc0 address space. */
784 ofw_construct_proc0_addrspace(&proc0_ttbbase);
785
786 /*
787 * Get a dump of OFW's picture of physical memory.
788 * This is used below to initialize a load of variables used by pmap.
789 * We get it now rather than later because we are about to
790 * tell OFW to stop managing memory.
791 */
792 ofw_getphysmeminfo();
793
794 /* We are about to take control of memory-management from OFW.
795 * Establish callbacks for OFW to use for its future memory needs.
796 * This is required for us to keep using OFW services.
797 */
798
799 /* First initialize our callback memory allocator. */
800 ofw_initallocator();
801
802 OF_set_callback(ofw_callbackhandler);
803
804 /* Switch to the proc0 pagetables. */
805 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
806 setttb(proc0_ttbbase.pv_pa);
807 cpu_tlb_flushID();
808 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
809
810 /*
811 * Moved from cpu_startup() as data_abort_handler() references
812 * this during uvm init
813 */
814 {
815 extern struct user *proc0paddr;
816 proc0paddr = (struct user *)kernelstack.pv_va;
817 lwp0.l_addr = proc0paddr;
818 }
819
820 /* Aaaaaaaah, running in the proc0 address space! */
821 /* I feel good... */
822
823 /* Set-up the various globals which describe physical memory for pmap. */
824 {
825 struct mem_region *mp;
826 int totalcnt;
827 int availcnt;
828
829 /* physmem, physical_start, physical_end */
830 physmem = 0;
831 for (totalcnt = 0, mp = OFphysmem; totalcnt < nOFphysmem;
832 totalcnt++, mp++) {
833 #ifdef OLDPRINTFS
834 printf("physmem: %x, %x\n", mp->start, mp->size);
835 #endif
836 physmem += btoc(mp->size);
837 }
838 physical_start = OFphysmem[0].start;
839 mp--;
840 physical_end = mp->start + mp->size;
841
842 /* free_pages, physical_freestart, physical_freeend */
843 free_pages = 0;
844 for (availcnt = 0, mp = OFphysavail; availcnt < nOFphysavail;
845 availcnt++, mp++) {
846 #ifdef OLDPRINTFS
847 printf("physavail: %x, %x\n", mp->start, mp->size);
848 #endif
849 free_pages += btoc(mp->size);
850 }
851 physical_freestart = OFphysavail[0].start;
852 mp--;
853 physical_freeend = mp->start + mp->size;
854 #ifdef OLDPRINTFS
855 printf("pmap_bootstrap: physmem = %x, free_pages = %x\n",
856 physmem, free_pages);
857 #endif
858
859 /*
860 * This is a hack to work with the existing pmap code.
861 * That code depends on a RiscPC BootConfig structure
862 * containing, among other things, an array describing
863 * the regions of physical memory. So, for now, we need
864 * to stuff our OFW-derived physical memory info into a
865 * "fake" BootConfig structure.
866 *
867 * An added twist is that we initialize the BootConfig
868 * structure with our "available" physical memory regions
869 * rather than the "total" physical memory regions. Why?
870 * Because:
871 *
872 * (a) the VM code requires that the "free" pages it is
873 * initialized with have consecutive indices. This
874 * allows it to use more efficient data structures
875 * (presumably).
876 * (b) the current pmap routines which report the initial
877 * set of free page indices (pmap_next_page) and
878 * which map addresses to indices (pmap_page_index)
879 * assume that the free pages are consecutive across
880 * memory region boundaries.
881 *
882 * This means that memory which is "stolen" at startup time
883 * (say, for page descriptors) MUST come from either the
884 * bottom of the first region or the top of the last.
885 *
886 * This requirement doesn't mesh well with OFW (or at least
887 * our use of it). We can get around it for the time being
888 * by pretending that our "available" region array describes
889 * all of our physical memory. This may cause some important
890 * information to be excluded from a dump file, but so far
891 * I haven't come across any other negative effects.
892 *
893 * In the long-run we should fix the index
894 * generation/translation code in the pmap module.
895 */
896
897 if (DRAM_BLOCKS < (availcnt + 1))
898 panic("more ofw memory regions than bootconfig blocks");
899
900 for (i = 0, mp = OFphysavail; i < nOFphysavail; i++, mp++) {
901 bootconfig.dram[i].address = mp->start;
902 bootconfig.dram[i].pages = btoc(mp->size);
903 }
904 bootconfig.dramblocks = availcnt;
905 }
906
907 /* Load memory into UVM. */
908 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
909
910 /* XXX Please kill this code dead. */
911 for (i = 0; i < bootconfig.dramblocks; i++) {
912 paddr_t start = (paddr_t)bootconfig.dram[i].address;
913 paddr_t end = start + (bootconfig.dram[i].pages * PAGE_SIZE);
914 #if NISADMA > 0
915 paddr_t istart, isize;
916 #endif
917
918 if (start < physical_freestart)
919 start = physical_freestart;
920 if (end > physical_freeend)
921 end = physical_freeend;
922
923 #if 0
924 printf("%d: %lx -> %lx\n", loop, start, end - 1);
925 #endif
926
927 #if NISADMA > 0
928 if (arm32_dma_range_intersect(shark_isa_dma_ranges,
929 shark_isa_dma_nranges,
930 start, end - start,
931 &istart, &isize)) {
932 /*
933 * Place the pages that intersect with the
934 * ISA DMA range onto the ISA DMA free list.
935 */
936 #if 0
937 printf(" ISADMA 0x%lx -> 0x%lx\n", istart,
938 istart + isize - 1);
939 #endif
940 uvm_page_physload(atop(istart),
941 atop(istart + isize), atop(istart),
942 atop(istart + isize), VM_FREELIST_ISADMA);
943
944 /*
945 * Load the pieces that come before the
946 * intersection onto the default free list.
947 */
948 if (start < istart) {
949 #if 0
950 printf(" BEFORE 0x%lx -> 0x%lx\n",
951 start, istart - 1);
952 #endif
953 uvm_page_physload(atop(start),
954 atop(istart), atop(start),
955 atop(istart), VM_FREELIST_DEFAULT);
956 }
957
958 /*
959 * Load the pieces that come after the
960 * intersection onto the default free list.
961 */
962 if ((istart + isize) < end) {
963 #if 0
964 printf(" AFTER 0x%lx -> 0x%lx\n",
965 (istart + isize), end - 1);
966 #endif
967 uvm_page_physload(atop(istart + isize),
968 atop(end), atop(istart + isize),
969 atop(end), VM_FREELIST_DEFAULT);
970 }
971 } else {
972 uvm_page_physload(atop(start), atop(end),
973 atop(start), atop(end), VM_FREELIST_DEFAULT);
974 }
975 #else /* NISADMA > 0 */
976 uvm_page_physload(atop(start), atop(end),
977 atop(start), atop(end), VM_FREELIST_DEFAULT);
978 #endif /* NISADMA > 0 */
979 }
980
981 /* Initialize pmap module. */
982 pmap_bootstrap((pd_entry_t *)proc0_ttbbase.pv_va, KERNEL_VM_BASE,
983 KERNEL_VM_BASE + KERNEL_VM_SIZE);
984 }
985
986
987 /*
988 ************************************************************
989
990 Routines private to this module
991
992 ************************************************************
993 */
994
995 /* N.B. Not supposed to call printf in callback-handler! Could deadlock! */
996 static void
997 ofw_callbackhandler(v)
998 void *v;
999 {
1000 struct ofw_cbargs *args = v;
1001 char *name = args->name;
1002 int nargs = args->nargs;
1003 int nreturns = args->nreturns;
1004 int *args_n_results = args->args_n_results;
1005
1006 ofw_callbacks++;
1007
1008 #if defined(OFWGENCFG)
1009 /* Check this first, so that we don't waste IRQ time parsing. */
1010 if (strcmp(name, "tick") == 0) {
1011 vaddr_t frame;
1012
1013 /* Check format. */
1014 if (nargs != 1 || nreturns < 1) {
1015 args_n_results[nargs] = -1;
1016 args->nreturns = 1;
1017 return;
1018 }
1019 args_n_results[nargs] = 0; /* properly formatted request */
1020
1021 /*
1022 * Note that we are running in the IRQ frame, with interrupts
1023 * disabled.
1024 *
1025 * We need to do two things here:
1026 * - copy a few words out of the input frame into a global
1027 * area, for later use by our real tick-handling code
1028 * - patch a few words in the frame so that when OFW returns
1029 * from the interrupt it will resume with our handler
1030 * rather than the code that was actually interrupted.
1031 * Our handler will resume when it finishes with the code
1032 * that was actually interrupted.
1033 *
1034 * It's simplest to do this in assembler, since it requires
1035 * switching frames and grovelling about with registers.
1036 */
1037 frame = (vaddr_t)args_n_results[0];
1038 if (ofw_handleticks)
1039 dotickgrovelling(frame);
1040 args_n_results[nargs + 1] = frame;
1041 args->nreturns = 1;
1042 } else
1043 #endif
1044
1045 if (strcmp(name, "map") == 0) {
1046 vaddr_t va;
1047 paddr_t pa;
1048 vsize_t size;
1049 int mode;
1050 int ap_bits;
1051 int dom_bits;
1052 int cb_bits;
1053
1054 /* Check format. */
1055 if (nargs != 4 || nreturns < 2) {
1056 args_n_results[nargs] = -1;
1057 args->nreturns = 1;
1058 return;
1059 }
1060 args_n_results[nargs] = 0; /* properly formatted request */
1061
1062 pa = (paddr_t)args_n_results[0];
1063 va = (vaddr_t)args_n_results[1];
1064 size = (vsize_t)args_n_results[2];
1065 mode = args_n_results[3];
1066 ap_bits = (mode & 0x00000C00);
1067 dom_bits = (mode & 0x000001E0);
1068 cb_bits = (mode & 0x000000C0);
1069
1070 /* Sanity checks. */
1071 if ((va & PGOFSET) != 0 || va < OFW_VIRT_BASE ||
1072 (va + size) > (OFW_VIRT_BASE + OFW_VIRT_SIZE) ||
1073 (pa & PGOFSET) != 0 || (size & PGOFSET) != 0 ||
1074 size == 0 || (dom_bits >> 5) != 0) {
1075 args_n_results[nargs + 1] = -1;
1076 args->nreturns = 1;
1077 return;
1078 }
1079
1080 /* Write-back anything stuck in the cache. */
1081 cpu_idcache_wbinv_all();
1082
1083 /* Install new mappings. */
1084 {
1085 pt_entry_t *pte = vtopte(va);
1086 int npages = size >> PGSHIFT;
1087
1088 ap_bits >>= 10;
1089 for (; npages > 0; pte++, pa += PAGE_SIZE, npages--)
1090 *pte = (pa | L2_AP(ap_bits) | L2_TYPE_S |
1091 cb_bits);
1092 PTE_SYNC_RANGE(vtopte(va), size >> PGSHIFT);
1093 }
1094
1095 /* Clean out tlb. */
1096 tlb_flush();
1097
1098 args_n_results[nargs + 1] = 0;
1099 args->nreturns = 2;
1100 } else if (strcmp(name, "unmap") == 0) {
1101 vaddr_t va;
1102 vsize_t size;
1103
1104 /* Check format. */
1105 if (nargs != 2 || nreturns < 1) {
1106 args_n_results[nargs] = -1;
1107 args->nreturns = 1;
1108 return;
1109 }
1110 args_n_results[nargs] = 0; /* properly formatted request */
1111
1112 va = (vaddr_t)args_n_results[0];
1113 size = (vsize_t)args_n_results[1];
1114
1115 /* Sanity checks. */
1116 if ((va & PGOFSET) != 0 || va < OFW_VIRT_BASE ||
1117 (va + size) > (OFW_VIRT_BASE + OFW_VIRT_SIZE) ||
1118 (size & PGOFSET) != 0 || size == 0) {
1119 args_n_results[nargs + 1] = -1;
1120 args->nreturns = 1;
1121 return;
1122 }
1123
1124 /* Write-back anything stuck in the cache. */
1125 cpu_idcache_wbinv_all();
1126
1127 /* Zero the mappings. */
1128 {
1129 pt_entry_t *pte = vtopte(va);
1130 int npages = size >> PGSHIFT;
1131
1132 for (; npages > 0; pte++, npages--)
1133 *pte = 0;
1134 PTE_SYNC_RANGE(vtopte(va), size >> PGSHIFT);
1135 }
1136
1137 /* Clean out tlb. */
1138 tlb_flush();
1139
1140 args->nreturns = 1;
1141 } else if (strcmp(name, "translate") == 0) {
1142 vaddr_t va;
1143 paddr_t pa;
1144 int mode;
1145 pt_entry_t pte;
1146
1147 /* Check format. */
1148 if (nargs != 1 || nreturns < 4) {
1149 args_n_results[nargs] = -1;
1150 args->nreturns = 1;
1151 return;
1152 }
1153 args_n_results[nargs] = 0; /* properly formatted request */
1154
1155 va = (vaddr_t)args_n_results[0];
1156
1157 /* Sanity checks.
1158 * For now, I am only willing to translate va's in the
1159 * "ofw range." Eventually, I may be more generous. -JJK
1160 */
1161 if ((va & PGOFSET) != 0 || va < OFW_VIRT_BASE ||
1162 va >= (OFW_VIRT_BASE + OFW_VIRT_SIZE)) {
1163 args_n_results[nargs + 1] = -1;
1164 args->nreturns = 1;
1165 return;
1166 }
1167
1168 /* Lookup mapping. */
1169 pte = *vtopte(va);
1170 if (pte == 0) {
1171 /* No mapping. */
1172 args_n_results[nargs + 1] = -1;
1173 args->nreturns = 2;
1174 } else {
1175 /* Existing mapping. */
1176 pa = (pte & L2_S_FRAME) | (va & L2_S_OFFSET);
1177 mode = (pte & 0x0C00) | (0 << 5) | (pte & 0x000C); /* AP | DOM | CB */
1178
1179 args_n_results[nargs + 1] = 0;
1180 args_n_results[nargs + 2] = pa;
1181 args_n_results[nargs + 3] = mode;
1182 args->nreturns = 4;
1183 }
1184 } else if (strcmp(name, "claim-phys") == 0) {
1185 struct pglist alloclist;
1186 paddr_t low, high, align;
1187 psize_t size;
1188
1189 /*
1190 * XXX
1191 * XXX THIS IS A GROSS HACK AND NEEDS TO BE REWRITTEN. -- cgd
1192 * XXX
1193 */
1194
1195 /* Check format. */
1196 if (nargs != 4 || nreturns < 3) {
1197 args_n_results[nargs] = -1;
1198 args->nreturns = 1;
1199 return;
1200 }
1201 args_n_results[nargs] = 0; /* properly formatted request */
1202
1203 low = args_n_results[0];
1204 size = args_n_results[2];
1205 align = args_n_results[3];
1206 high = args_n_results[1] + size;
1207
1208 #if 0
1209 printf("claim-phys: low = 0x%x, size = 0x%x, align = 0x%x, high = 0x%x\n",
1210 low, size, align, high);
1211 align = size;
1212 printf("forcing align to be 0x%x\n", align);
1213 #endif
1214
1215 args_n_results[nargs + 1] =
1216 uvm_pglistalloc(size, low, high, align, 0, &alloclist, 1, 0);
1217 #if 0
1218 printf(" -> 0x%lx", args_n_results[nargs + 1]);
1219 #endif
1220 if (args_n_results[nargs + 1] != 0) {
1221 #if 0
1222 printf("(failed)\n");
1223 #endif
1224 args_n_results[nargs + 1] = -1;
1225 args->nreturns = 2;
1226 return;
1227 }
1228 args_n_results[nargs + 2] = VM_PAGE_TO_PHYS(alloclist.tqh_first);
1229 #if 0
1230 printf("(succeeded: pa = 0x%lx)\n", args_n_results[nargs + 2]);
1231 #endif
1232 args->nreturns = 3;
1233
1234 } else if (strcmp(name, "release-phys") == 0) {
1235 printf("unimplemented ofw callback - %s\n", name);
1236 args_n_results[nargs] = -1;
1237 args->nreturns = 1;
1238 } else if (strcmp(name, "claim-virt") == 0) {
1239 vaddr_t va;
1240 vsize_t size;
1241 vaddr_t align;
1242
1243 /* XXX - notyet */
1244 /* printf("unimplemented ofw callback - %s\n", name);*/
1245 args_n_results[nargs] = -1;
1246 args->nreturns = 1;
1247 return;
1248
1249 /* Check format. */
1250 if (nargs != 2 || nreturns < 3) {
1251 args_n_results[nargs] = -1;
1252 args->nreturns = 1;
1253 return;
1254 }
1255 args_n_results[nargs] = 0; /* properly formatted request */
1256
1257 /* Allocate size bytes with specified alignment. */
1258 size = (vsize_t)args_n_results[0];
1259 align = (vaddr_t)args_n_results[1];
1260 if (align % PAGE_SIZE != 0) {
1261 args_n_results[nargs + 1] = -1;
1262 args->nreturns = 2;
1263 return;
1264 }
1265
1266 if (va == 0) {
1267 /* Couldn't allocate. */
1268 args_n_results[nargs + 1] = -1;
1269 args->nreturns = 2;
1270 } else {
1271 /* Successful allocation. */
1272 args_n_results[nargs + 1] = 0;
1273 args_n_results[nargs + 2] = va;
1274 args->nreturns = 3;
1275 }
1276 } else if (strcmp(name, "release-virt") == 0) {
1277 vaddr_t va;
1278 vsize_t size;
1279
1280 /* XXX - notyet */
1281 printf("unimplemented ofw callback - %s\n", name);
1282 args_n_results[nargs] = -1;
1283 args->nreturns = 1;
1284 return;
1285
1286 /* Check format. */
1287 if (nargs != 2 || nreturns < 1) {
1288 args_n_results[nargs] = -1;
1289 args->nreturns = 1;
1290 return;
1291 }
1292 args_n_results[nargs] = 0; /* properly formatted request */
1293
1294 /* Release bytes. */
1295 va = (vaddr_t)args_n_results[0];
1296 size = (vsize_t)args_n_results[1];
1297
1298 args->nreturns = 1;
1299 } else {
1300 args_n_results[nargs] = -1;
1301 args->nreturns = 1;
1302 }
1303 }
1304
1305 static void
1306 ofw_construct_proc0_addrspace(pv_addr_t *proc0_ttbbase)
1307 {
1308 int i, oft;
1309 static pv_addr_t proc0_pagedir;
1310 static pv_addr_t proc0_pt_sys;
1311 static pv_addr_t proc0_pt_kernel[KERNEL_IMG_PTS];
1312 static pv_addr_t proc0_pt_vmdata[KERNEL_VMDATA_PTS];
1313 static pv_addr_t proc0_pt_ofw[KERNEL_OFW_PTS];
1314 static pv_addr_t proc0_pt_io[KERNEL_IO_PTS];
1315 static pv_addr_t msgbuf;
1316 vaddr_t L1pagetable;
1317 struct mem_translation *tp;
1318
1319 /* Set-up the system page. */
1320 KASSERT(vector_page == 0); /* XXX for now */
1321 systempage.pv_va = ofw_claimvirt(vector_page, PAGE_SIZE, 0);
1322 if (systempage.pv_va == -1) {
1323 /* Something was already mapped to vector_page's VA. */
1324 systempage.pv_va = vector_page;
1325 systempage.pv_pa = ofw_gettranslation(vector_page);
1326 if (systempage.pv_pa == -1)
1327 panic("bogus result from gettranslation(vector_page)");
1328 } else {
1329 /* We were just allocated the page-length range at VA 0. */
1330 if (systempage.pv_va != vector_page)
1331 panic("bogus result from claimvirt(vector_page, PAGE_SIZE, 0)");
1332
1333 /* Now allocate a physical page, and establish the mapping. */
1334 systempage.pv_pa = ofw_claimphys(0, PAGE_SIZE, PAGE_SIZE);
1335 if (systempage.pv_pa == -1)
1336 panic("bogus result from claimphys(0, PAGE_SIZE, PAGE_SIZE)");
1337 ofw_settranslation(systempage.pv_va, systempage.pv_pa,
1338 PAGE_SIZE, -1); /* XXX - mode? -JJK */
1339
1340 /* Zero the memory. */
1341 bzero((char *)systempage.pv_va, PAGE_SIZE);
1342 }
1343
1344 /* Allocate/initialize space for the proc0, NetBSD-managed */
1345 /* page tables that we will be switching to soon. */
1346 ofw_claimpages(&virt_freeptr, &proc0_pagedir, L1_TABLE_SIZE);
1347 ofw_claimpages(&virt_freeptr, &proc0_pt_sys, L2_TABLE_SIZE);
1348 for (i = 0; i < KERNEL_IMG_PTS; i++)
1349 ofw_claimpages(&virt_freeptr, &proc0_pt_kernel[i], L2_TABLE_SIZE);
1350 for (i = 0; i < KERNEL_VMDATA_PTS; i++)
1351 ofw_claimpages(&virt_freeptr, &proc0_pt_vmdata[i], L2_TABLE_SIZE);
1352 for (i = 0; i < KERNEL_OFW_PTS; i++)
1353 ofw_claimpages(&virt_freeptr, &proc0_pt_ofw[i], L2_TABLE_SIZE);
1354 for (i = 0; i < KERNEL_IO_PTS; i++)
1355 ofw_claimpages(&virt_freeptr, &proc0_pt_io[i], L2_TABLE_SIZE);
1356
1357 /* Allocate/initialize space for stacks. */
1358 #ifndef OFWGENCFG
1359 ofw_claimpages(&virt_freeptr, &irqstack, PAGE_SIZE);
1360 #endif
1361 ofw_claimpages(&virt_freeptr, &undstack, PAGE_SIZE);
1362 ofw_claimpages(&virt_freeptr, &abtstack, PAGE_SIZE);
1363 ofw_claimpages(&virt_freeptr, &kernelstack, UPAGES * PAGE_SIZE);
1364
1365 /* Allocate/initialize space for msgbuf area. */
1366 ofw_claimpages(&virt_freeptr, &msgbuf, MSGBUFSIZE);
1367 msgbufphys = msgbuf.pv_pa;
1368
1369 /* Construct the proc0 L1 pagetable. */
1370 L1pagetable = proc0_pagedir.pv_va;
1371
1372 pmap_link_l2pt(L1pagetable, 0x0, &proc0_pt_sys);
1373 for (i = 0; i < KERNEL_IMG_PTS; i++)
1374 pmap_link_l2pt(L1pagetable, KERNEL_BASE + i * 0x00400000,
1375 &proc0_pt_kernel[i]);
1376 for (i = 0; i < KERNEL_VMDATA_PTS; i++)
1377 pmap_link_l2pt(L1pagetable, KERNEL_VM_BASE + i * 0x00400000,
1378 &proc0_pt_vmdata[i]);
1379 for (i = 0; i < KERNEL_OFW_PTS; i++)
1380 pmap_link_l2pt(L1pagetable, OFW_VIRT_BASE + i * 0x00400000,
1381 &proc0_pt_ofw[i]);
1382 for (i = 0; i < KERNEL_IO_PTS; i++)
1383 pmap_link_l2pt(L1pagetable, IO_VIRT_BASE + i * 0x00400000,
1384 &proc0_pt_io[i]);
1385
1386 /*
1387 * OK, we're done allocating.
1388 * Get a dump of OFW's translations, and make the appropriate
1389 * entries in the L2 pagetables that we just allocated.
1390 */
1391
1392 ofw_getvirttranslations();
1393
1394 for (oft = 0, tp = OFtranslations; oft < nOFtranslations;
1395 oft++, tp++) {
1396
1397 vaddr_t va;
1398 paddr_t pa;
1399 int npages = tp->size / PAGE_SIZE;
1400
1401 /* Size must be an integral number of pages. */
1402 if (npages == 0 || tp->size % PAGE_SIZE != 0)
1403 panic("illegal ofw translation (size)");
1404
1405 /* Make an entry for each page in the appropriate table. */
1406 for (va = tp->virt, pa = tp->phys; npages > 0;
1407 va += PAGE_SIZE, pa += PAGE_SIZE, npages--) {
1408 /*
1409 * Map the top bits to the appropriate L2 pagetable.
1410 * The only allowable regions are page0, the
1411 * kernel-static area, and the ofw area.
1412 */
1413 switch (va >> (L1_S_SHIFT + 2)) {
1414 case 0:
1415 /* page0 */
1416 break;
1417
1418 #if KERNEL_IMG_PTS != 2
1419 #error "Update ofw translation range list"
1420 #endif
1421 case ( KERNEL_BASE >> (L1_S_SHIFT + 2)):
1422 case ((KERNEL_BASE + 0x00400000) >> (L1_S_SHIFT + 2)):
1423 /* kernel static area */
1424 break;
1425
1426 case ( OFW_VIRT_BASE >> (L1_S_SHIFT + 2)):
1427 case ((OFW_VIRT_BASE + 0x00400000) >> (L1_S_SHIFT + 2)):
1428 case ((OFW_VIRT_BASE + 0x00800000) >> (L1_S_SHIFT + 2)):
1429 case ((OFW_VIRT_BASE + 0x00C00000) >> (L1_S_SHIFT + 2)):
1430 /* ofw area */
1431 break;
1432
1433 case ( IO_VIRT_BASE >> (L1_S_SHIFT + 2)):
1434 case ((IO_VIRT_BASE + 0x00400000) >> (L1_S_SHIFT + 2)):
1435 case ((IO_VIRT_BASE + 0x00800000) >> (L1_S_SHIFT + 2)):
1436 case ((IO_VIRT_BASE + 0x00C00000) >> (L1_S_SHIFT + 2)):
1437 /* io area */
1438 break;
1439
1440 default:
1441 /* illegal */
1442 panic("illegal ofw translation (addr) %#lx",
1443 va);
1444 }
1445
1446 /* Make the entry. */
1447 pmap_map_entry(L1pagetable, va, pa,
1448 VM_PROT_READ|VM_PROT_WRITE,
1449 (tp->mode & 0xC) == 0xC ? PTE_CACHE
1450 : PTE_NOCACHE);
1451 }
1452 }
1453
1454 /*
1455 * We don't actually want some of the mappings that we just
1456 * set up to appear in proc0's address space. In particular,
1457 * we don't want aliases to physical addresses that the kernel
1458 * has-mapped/will-map elsewhere.
1459 */
1460 ofw_discardmappings(proc0_pt_kernel[KERNEL_IMG_PTS - 1].pv_va,
1461 msgbuf.pv_va, MSGBUFSIZE);
1462
1463 /* update the top of the kernel VM */
1464 pmap_curmaxkvaddr =
1465 KERNEL_VM_BASE + (KERNEL_VMDATA_PTS * 0x00400000);
1466
1467 /*
1468 * gross hack for the sake of not thrashing the TLB and making
1469 * cache flush more efficient: blast l1 ptes for sections.
1470 */
1471 for (oft = 0, tp = OFtranslations; oft < nOFtranslations; oft++, tp++) {
1472 vaddr_t va = tp->virt;
1473 paddr_t pa = tp->phys;
1474
1475 if (((va | pa) & L1_S_OFFSET) == 0) {
1476 int nsections = tp->size / L1_S_SIZE;
1477
1478 while (nsections--) {
1479 /* XXXJRT prot?? */
1480 pmap_map_section(L1pagetable, va, pa,
1481 VM_PROT_READ|VM_PROT_WRITE,
1482 (tp->mode & 0xC) == 0xC ? PTE_CACHE
1483 : PTE_NOCACHE);
1484 va += L1_S_SIZE;
1485 pa += L1_S_SIZE;
1486 }
1487 }
1488 }
1489
1490 /* OUT parameters are the new ttbbase and the pt which maps pts. */
1491 *proc0_ttbbase = proc0_pagedir;
1492 }
1493
1494
1495 static void
1496 ofw_getphysmeminfo()
1497 {
1498 int phandle;
1499 int mem_len;
1500 int avail_len;
1501 int i;
1502
1503 if ((phandle = OF_finddevice("/memory")) == -1 ||
1504 (mem_len = OF_getproplen(phandle, "reg")) <= 0 ||
1505 (OFphysmem = (struct mem_region *)ofw_malloc(mem_len)) == 0 ||
1506 OF_getprop(phandle, "reg", OFphysmem, mem_len) != mem_len ||
1507 (avail_len = OF_getproplen(phandle, "available")) <= 0 ||
1508 (OFphysavail = (struct mem_region *)ofw_malloc(avail_len)) == 0 ||
1509 OF_getprop(phandle, "available", OFphysavail, avail_len)
1510 != avail_len)
1511 panic("can't get physmeminfo from OFW");
1512
1513 nOFphysmem = mem_len / sizeof(struct mem_region);
1514 nOFphysavail = avail_len / sizeof(struct mem_region);
1515
1516 /*
1517 * Sort the blocks in each array into ascending address order.
1518 * Also, page-align all blocks.
1519 */
1520 for (i = 0; i < 2; i++) {
1521 struct mem_region *tmp = (i == 0) ? OFphysmem : OFphysavail;
1522 struct mem_region *mp;
1523 int cnt = (i == 0) ? nOFphysmem : nOFphysavail;
1524 int j;
1525
1526 #ifdef OLDPRINTFS
1527 printf("ofw_getphysmeminfo: %d blocks\n", cnt);
1528 #endif
1529
1530 /* XXX - Convert all the values to host order. -JJK */
1531 for (j = 0, mp = tmp; j < cnt; j++, mp++) {
1532 mp->start = of_decode_int((unsigned char *)&mp->start);
1533 mp->size = of_decode_int((unsigned char *)&mp->size);
1534 }
1535
1536 for (j = 0, mp = tmp; j < cnt; j++, mp++) {
1537 u_int s, sz;
1538 struct mem_region *mp1;
1539
1540 /* Page-align start of the block. */
1541 s = mp->start % PAGE_SIZE;
1542 if (s != 0) {
1543 s = (PAGE_SIZE - s);
1544
1545 if (mp->size >= s) {
1546 mp->start += s;
1547 mp->size -= s;
1548 }
1549 }
1550
1551 /* Page-align the size. */
1552 mp->size -= mp->size % PAGE_SIZE;
1553
1554 /* Handle empty block. */
1555 if (mp->size == 0) {
1556 memmove(mp, mp + 1, (cnt - (mp - tmp))
1557 * sizeof(struct mem_region));
1558 cnt--;
1559 mp--;
1560 continue;
1561 }
1562
1563 /* Bubble sort. */
1564 s = mp->start;
1565 sz = mp->size;
1566 for (mp1 = tmp; mp1 < mp; mp1++)
1567 if (s < mp1->start)
1568 break;
1569 if (mp1 < mp) {
1570 memmove(mp1 + 1, mp1, (char *)mp - (char *)mp1);
1571 mp1->start = s;
1572 mp1->size = sz;
1573 }
1574 }
1575
1576 #ifdef OLDPRINTFS
1577 for (mp = tmp; mp->size; mp++) {
1578 printf("%x, %x\n", mp->start, mp->size);
1579 }
1580 #endif
1581 }
1582 }
1583
1584
1585 static void
1586 ofw_getvirttranslations(void)
1587 {
1588 int mmu_phandle;
1589 int mmu_ihandle;
1590 int trans_len;
1591 int over, len;
1592 int i;
1593 struct mem_translation *tp;
1594
1595 mmu_ihandle = ofw_mmu_ihandle();
1596
1597 /* overallocate to avoid increases during allocation */
1598 over = 4 * sizeof(struct mem_translation);
1599 if ((mmu_phandle = OF_instance_to_package(mmu_ihandle)) == -1 ||
1600 (len = OF_getproplen(mmu_phandle, "translations")) <= 0 ||
1601 (OFtranslations = ofw_malloc(len + over)) == 0 ||
1602 (trans_len = OF_getprop(mmu_phandle, "translations",
1603 OFtranslations, len + over)) > (len + over))
1604 panic("can't get virttranslations from OFW");
1605
1606 /* XXX - Convert all the values to host order. -JJK */
1607 nOFtranslations = trans_len / sizeof(struct mem_translation);
1608 #ifdef OLDPRINTFS
1609 printf("ofw_getvirtmeminfo: %d blocks\n", nOFtranslations);
1610 #endif
1611 for (i = 0, tp = OFtranslations; i < nOFtranslations; i++, tp++) {
1612 tp->virt = of_decode_int((unsigned char *)&tp->virt);
1613 tp->size = of_decode_int((unsigned char *)&tp->size);
1614 tp->phys = of_decode_int((unsigned char *)&tp->phys);
1615 tp->mode = of_decode_int((unsigned char *)&tp->mode);
1616 }
1617 }
1618
1619 /*
1620 * ofw_valloc: allocate blocks of VM for IO and other special purposes
1621 */
1622 typedef struct _vfree {
1623 struct _vfree *pNext;
1624 vaddr_t start;
1625 vsize_t size;
1626 } VFREE, *PVFREE;
1627
1628 static VFREE vfinitial = { NULL, IO_VIRT_BASE, IO_VIRT_SIZE };
1629
1630 static PVFREE vflist = &vfinitial;
1631
1632 static vaddr_t
1633 ofw_valloc(size, align)
1634 vsize_t size;
1635 vaddr_t align;
1636 {
1637 PVFREE *ppvf;
1638 PVFREE pNew;
1639 vaddr_t new;
1640 vaddr_t lead;
1641
1642 for (ppvf = &vflist; *ppvf; ppvf = &((*ppvf)->pNext)) {
1643 if (align == 0) {
1644 new = (*ppvf)->start;
1645 lead = 0;
1646 } else {
1647 new = ((*ppvf)->start + (align - 1)) & ~(align - 1);
1648 lead = new - (*ppvf)->start;
1649 }
1650
1651 if (((*ppvf)->size - lead) >= size) {
1652 if (lead == 0) {
1653 /* using whole block */
1654 if (size == (*ppvf)->size) {
1655 /* splice out of list */
1656 (*ppvf) = (*ppvf)->pNext;
1657 } else { /* tail of block is free */
1658 (*ppvf)->start = new + size;
1659 (*ppvf)->size -= size;
1660 }
1661 } else {
1662 vsize_t tail = ((*ppvf)->start
1663 + (*ppvf)->size) - (new + size);
1664 /* free space at beginning */
1665 (*ppvf)->size = lead;
1666
1667 if (tail != 0) {
1668 /* free space at tail */
1669 pNew = ofw_malloc(sizeof(VFREE));
1670 pNew->pNext = (*ppvf)->pNext;
1671 (*ppvf)->pNext = pNew;
1672 pNew->start = new + size;
1673 pNew->size = tail;
1674 }
1675 }
1676 return new;
1677 } /* END if */
1678 } /* END for */
1679
1680 return -1;
1681 }
1682
1683 vaddr_t
1684 ofw_map(pa, size, cb_bits)
1685 paddr_t pa;
1686 vsize_t size;
1687 int cb_bits;
1688 {
1689 vaddr_t va;
1690
1691 if ((va = ofw_valloc(size, size)) == -1)
1692 panic("cannot alloc virtual memory for %#lx", pa);
1693
1694 ofw_claimvirt(va, size, 0); /* make sure OFW knows about the memory */
1695
1696 ofw_settranslation(va, pa, size, L2_AP(AP_KRW) | cb_bits);
1697
1698 return va;
1699 }
1700
1701 static int
1702 ofw_mem_ihandle(void)
1703 {
1704 static int mem_ihandle = 0;
1705 int chosen;
1706
1707 if (mem_ihandle != 0)
1708 return(mem_ihandle);
1709
1710 if ((chosen = OF_finddevice("/chosen")) == -1 ||
1711 OF_getprop(chosen, "memory", &mem_ihandle, sizeof(int)) < 0)
1712 panic("ofw_mem_ihandle");
1713
1714 mem_ihandle = of_decode_int((unsigned char *)&mem_ihandle);
1715
1716 return(mem_ihandle);
1717 }
1718
1719
1720 static int
1721 ofw_mmu_ihandle(void)
1722 {
1723 static int mmu_ihandle = 0;
1724 int chosen;
1725
1726 if (mmu_ihandle != 0)
1727 return(mmu_ihandle);
1728
1729 if ((chosen = OF_finddevice("/chosen")) == -1 ||
1730 OF_getprop(chosen, "mmu", &mmu_ihandle, sizeof(int)) < 0)
1731 panic("ofw_mmu_ihandle");
1732
1733 mmu_ihandle = of_decode_int((unsigned char *)&mmu_ihandle);
1734
1735 return(mmu_ihandle);
1736 }
1737
1738
1739 /* Return -1 on failure. */
1740 static paddr_t
1741 ofw_claimphys(pa, size, align)
1742 paddr_t pa;
1743 psize_t size;
1744 paddr_t align;
1745 {
1746 int mem_ihandle = ofw_mem_ihandle();
1747
1748 /* printf("ofw_claimphys (%x, %x, %x) --> ", pa, size, align);*/
1749 if (align == 0) {
1750 /* Allocate at specified base; alignment is ignored. */
1751 pa = OF_call_method_1("claim", mem_ihandle, 3, pa, size, align);
1752 } else {
1753 /* Allocate anywhere, with specified alignment. */
1754 pa = OF_call_method_1("claim", mem_ihandle, 2, size, align);
1755 }
1756
1757 /* printf("%x\n", pa);*/
1758 return(pa);
1759 }
1760
1761
1762 #if 0
1763 /* Return -1 on failure. */
1764 static paddr_t
1765 ofw_releasephys(pa, size)
1766 paddr_t pa;
1767 psize_t size;
1768 {
1769 int mem_ihandle = ofw_mem_ihandle();
1770
1771 /* printf("ofw_releasephys (%x, %x)\n", pa, size);*/
1772
1773 return (OF_call_method_1("release", mem_ihandle, 2, pa, size));
1774 }
1775 #endif
1776
1777 /* Return -1 on failure. */
1778 static vaddr_t
1779 ofw_claimvirt(va, size, align)
1780 vaddr_t va;
1781 vsize_t size;
1782 vaddr_t align;
1783 {
1784 int mmu_ihandle = ofw_mmu_ihandle();
1785
1786 /*printf("ofw_claimvirt (%x, %x, %x) --> ", va, size, align);*/
1787 if (align == 0) {
1788 /* Allocate at specified base; alignment is ignored. */
1789 va = OF_call_method_1("claim", mmu_ihandle, 3, va, size, align);
1790 } else {
1791 /* Allocate anywhere, with specified alignment. */
1792 va = OF_call_method_1("claim", mmu_ihandle, 2, size, align);
1793 }
1794
1795 /*printf("%x\n", va);*/
1796 return(va);
1797 }
1798
1799 /* Return -1 if no mapping. */
1800 paddr_t
1801 ofw_gettranslation(va)
1802 vaddr_t va;
1803 {
1804 int mmu_ihandle = ofw_mmu_ihandle();
1805 paddr_t pa;
1806 int mode;
1807 int exists;
1808
1809 #ifdef OFW_DEBUG
1810 printf("ofw_gettranslation (%x) --> ", (uint32_t)va);
1811 #endif
1812 exists = 0; /* gets set to true if translation exists */
1813 if (OF_call_method("translate", mmu_ihandle, 1, 3, va, &pa, &mode,
1814 &exists) != 0)
1815 return(-1);
1816
1817 #ifdef OFW_DEBUG
1818 printf("%d %x\n", exists, (uint32_t)pa);
1819 #endif
1820 return(exists ? pa : -1);
1821 }
1822
1823
1824 static void
1825 ofw_settranslation(va, pa, size, mode)
1826 vaddr_t va;
1827 paddr_t pa;
1828 vsize_t size;
1829 int mode;
1830 {
1831 int mmu_ihandle = ofw_mmu_ihandle();
1832
1833 #ifdef OFW_DEBUG
1834 printf("ofw_settranslation (%x, %x, %x, %x) --> void", (uint32_t)va,
1835 (uint32_t)pa, (uint32_t)size, (uint32_t)mode);
1836 #endif
1837 if (OF_call_method("map", mmu_ihandle, 4, 0, pa, va, size, mode) != 0)
1838 panic("ofw_settranslation failed");
1839 }
1840
1841 /*
1842 * Allocation routine used before the kernel takes over memory.
1843 * Use this for efficient storage for things that aren't rounded to
1844 * page size.
1845 *
1846 * The point here is not necessarily to be very efficient (even though
1847 * that's sort of nice), but to do proper dynamic allocation to avoid
1848 * size-limitation errors.
1849 *
1850 */
1851
1852 typedef struct _leftover {
1853 struct _leftover *pNext;
1854 vsize_t size;
1855 } LEFTOVER, *PLEFTOVER;
1856
1857 /* leftover bits of pages. first word is pointer to next.
1858 second word is size of leftover */
1859 static PLEFTOVER leftovers = NULL;
1860
1861 static void *
1862 ofw_malloc(size)
1863 vsize_t size;
1864 {
1865 PLEFTOVER *ppLeftover;
1866 PLEFTOVER pLeft;
1867 pv_addr_t new;
1868 vsize_t newSize, claim_size;
1869
1870 /* round and set minimum size */
1871 size = max(sizeof(LEFTOVER),
1872 ((size + (sizeof(LEFTOVER) - 1)) & ~(sizeof(LEFTOVER) - 1)));
1873
1874 for (ppLeftover = &leftovers; *ppLeftover;
1875 ppLeftover = &((*ppLeftover)->pNext))
1876 if ((*ppLeftover)->size >= size)
1877 break;
1878
1879 if (*ppLeftover) { /* have a leftover of the right size */
1880 /* remember the leftover */
1881 new.pv_va = (vaddr_t)*ppLeftover;
1882 if ((*ppLeftover)->size < (size + sizeof(LEFTOVER))) {
1883 /* splice out of chain */
1884 *ppLeftover = (*ppLeftover)->pNext;
1885 } else {
1886 /* remember the next pointer */
1887 pLeft = (*ppLeftover)->pNext;
1888 newSize = (*ppLeftover)->size - size; /* reduce size */
1889 /* move pointer */
1890 *ppLeftover = (PLEFTOVER)(((vaddr_t)*ppLeftover)
1891 + size);
1892 (*ppLeftover)->pNext = pLeft;
1893 (*ppLeftover)->size = newSize;
1894 }
1895 } else {
1896 claim_size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
1897 ofw_claimpages(&virt_freeptr, &new, claim_size);
1898 if ((size + sizeof(LEFTOVER)) <= claim_size) {
1899 pLeft = (PLEFTOVER)(new.pv_va + size);
1900 pLeft->pNext = leftovers;
1901 pLeft->size = claim_size - size;
1902 leftovers = pLeft;
1903 }
1904 }
1905
1906 return (void *)(new.pv_va);
1907 }
1908
1909 /*
1910 * Here is a really, really sleazy free. It's not used right now,
1911 * because it's not worth the extra complexity for just a few bytes.
1912 *
1913 */
1914 #if 0
1915 static void
1916 ofw_free(addr, size)
1917 vaddr_t addr;
1918 vsize_t size;
1919 {
1920 PLEFTOVER pLeftover = (PLEFTOVER)addr;
1921
1922 /* splice right into list without checks or compaction */
1923 pLeftover->pNext = leftovers;
1924 pLeftover->size = size;
1925 leftovers = pLeftover;
1926 }
1927 #endif
1928
1929 /*
1930 * Allocate and zero round(size)/PAGE_SIZE pages of memory.
1931 * We guarantee that the allocated memory will be
1932 * aligned to a boundary equal to the smallest power of
1933 * 2 greater than or equal to size.
1934 * free_pp is an IN/OUT parameter which points to the
1935 * last allocated virtual address in an allocate-downwards
1936 * stack. pv_p is an OUT parameter which contains the
1937 * virtual and physical base addresses of the allocated
1938 * memory.
1939 */
1940 static void
1941 ofw_claimpages(free_pp, pv_p, size)
1942 vaddr_t *free_pp;
1943 pv_addr_t *pv_p;
1944 vsize_t size;
1945 {
1946 /* round-up to page boundary */
1947 vsize_t alloc_size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
1948 vsize_t aligned_size;
1949 vaddr_t va;
1950 paddr_t pa;
1951
1952 if (alloc_size == 0)
1953 panic("ofw_claimpages zero");
1954
1955 for (aligned_size = 1; aligned_size < alloc_size; aligned_size <<= 1)
1956 ;
1957
1958 /* The only way to provide the alignment guarantees is to
1959 * allocate the virtual and physical ranges separately,
1960 * then do an explicit map call.
1961 */
1962 va = (*free_pp & ~(aligned_size - 1)) - aligned_size;
1963 if (ofw_claimvirt(va, alloc_size, 0) != va)
1964 panic("ofw_claimpages va alloc");
1965 pa = ofw_claimphys(0, alloc_size, aligned_size);
1966 if (pa == -1)
1967 panic("ofw_claimpages pa alloc");
1968 /* XXX - what mode? -JJK */
1969 ofw_settranslation(va, pa, alloc_size, -1);
1970
1971 /* The memory's mapped-in now, so we can zero it. */
1972 bzero((char *)va, alloc_size);
1973
1974 /* Set OUT parameters. */
1975 *free_pp = va;
1976 pv_p->pv_va = va;
1977 pv_p->pv_pa = pa;
1978 }
1979
1980
1981 static void
1982 ofw_discardmappings(L2pagetable, va, size)
1983 vaddr_t L2pagetable;
1984 vaddr_t va;
1985 vsize_t size;
1986 {
1987 /* round-up to page boundary */
1988 vsize_t alloc_size = (size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
1989 int npages = alloc_size / PAGE_SIZE;
1990
1991 if (npages == 0)
1992 panic("ofw_discardmappings zero");
1993
1994 /* Discard each mapping. */
1995 for (; npages > 0; va += PAGE_SIZE, npages--) {
1996 /* Sanity. The current entry should be non-null. */
1997 if (ReadWord(L2pagetable + ((va >> 10) & 0x00000FFC)) == 0)
1998 panic("ofw_discardmappings zero entry");
1999
2000 /* Clear the entry. */
2001 WriteWord(L2pagetable + ((va >> 10) & 0x00000FFC), 0);
2002 }
2003 }
2004
2005
2006 static void
2007 ofw_initallocator(void)
2008 {
2009
2010 }
2011
2012 #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
2013 static void
2014 reset_screen()
2015 {
2016
2017 if ((console_ihandle == 0) || (console_ihandle == -1))
2018 return;
2019
2020 OF_call_method("install", console_ihandle, 0, 0);
2021 }
2022 #endif /* (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0) */
2023