4 * Copyright (c) 2000-2002 Reinoud Zandijk.
5 * Copyright (c) 1994-1998 Mark Brinicombe.
6 * Copyright (c) 1994 Brini.
9 * This code is derived from software written for Brini by Mark Brinicombe
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Brini.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * RiscBSD kernel project
42 * Machine dependant functions for kernel setup
44 * This file still needs a lot of work
47 * Updated for yet another new bootloader 28/12/02
51 #include "opt_modular.h"
52 #include "opt_pmap_debug.h"
53 #include "vidcvideo.h"
56 #include <sys/param.h>
58 __KERNEL_RCSID(0, "$NetBSD$");
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
62 #include <sys/reboot.h>
64 #include <sys/msgbuf.h>
66 #include <sys/exec_aout.h>
67 #include <sys/ksyms.h>
71 #include <machine/db_machdep.h>
72 #include <ddb/db_sym.h>
73 #include <ddb/db_extern.h>
77 #include <machine/signal.h>
78 #include <machine/frame.h>
79 #include <machine/bootconfig.h>
80 #include <machine/cpu.h>
81 #include <machine/io.h>
82 #include <machine/intr.h>
83 #include <arm/cpuconf.h>
84 #include <arm/arm32/katelib.h>
85 #include <arm/arm32/machdep.h>
86 #include <arm/undefined.h>
87 #include <machine/rtc.h>
88 #include <machine/bus.h>
90 #include <arm/iomd/vidc.h>
91 #include <arm/iomd/iomdreg.h>
92 #include <arm/iomd/iomdvar.h>
94 #include <arm/iomd/vidcvideo.h>
96 #include <sys/device.h>
97 #include <dev/ic/pckbcvar.h>
99 #include <dev/i2c/i2cvar.h>
100 #include <dev/i2c/pcf8583var.h>
101 #include <arm/iomd/iomdiicvar.h>
103 /* static i2c_tag_t acorn32_i2c_tag;*/
107 /* Kernel text starts at the base of the kernel address space. */
108 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00000000)
109 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
112 * The range 0xf1000000 - 0xf5ffffff is available for kernel VM space
113 * Fixed mappings exist from 0xf6000000 - 0xffffffff
115 #define KERNEL_VM_SIZE 0x05000000
118 * Address to call from cpu_reset() to reset the machine.
119 * This is machine architecture dependant as it varies depending
120 * on where the ROM appears when you turn the MMU off.
122 u_int cpu_reset_address
= 0x0; /* XXX 0x3800000 too for rev0 RiscPC 600 */
124 #define VERBOSE_INIT_ARM
127 /* Define various stack sizes in pages */
128 #define IRQ_STACK_SIZE 1
129 #define ABT_STACK_SIZE 1
130 #define UND_STACK_SIZE 1
133 struct bootconfig bootconfig
; /* Boot config storage */
134 videomemory_t videomemory
; /* Video memory descriptor */
136 char *boot_args
= NULL
; /* holds the pre-processed boot arguments */
137 extern char *booted_kernel
; /* used for ioctl to retrieve booted kernel */
139 extern int *vidc_base
;
140 extern u_int32_t iomd_base
;
141 extern struct bus_space iomd_bs_tag
;
143 paddr_t physical_start
;
144 paddr_t physical_freestart
;
145 paddr_t physical_freeend
;
146 paddr_t physical_end
;
147 paddr_t dma_range_begin
;
148 paddr_t dma_range_end
;
151 paddr_t memoryblock_end
;
153 #ifndef PMAP_STATIC_L1S
154 int max_processes
= 64; /* Default number */
155 #endif /* !PMAP_STATIC_L1S */
157 u_int videodram_size
= 0; /* Amount of DRAM to reserve for video */
159 /* Physical and virtual addresses for some global pages */
160 pv_addr_t systempage
;
164 pv_addr_t kernelstack
;
168 extern u_int data_abort_handler_address
;
169 extern u_int prefetch_abort_handler_address
;
170 extern u_int undefined_handler_address
;
173 extern int pmap_debug_level
;
174 #endif /* PMAP_DEBUG */
176 #define KERNEL_PT_VMEM 0 /* Page table for mapping video memory */
177 #define KERNEL_PT_SYS 1 /* Page table for mapping proc0 zero page */
178 #define KERNEL_PT_KERNEL 2 /* Page table for mapping kernel */
179 #define KERNEL_PT_VMDATA 3 /* Page tables for mapping kernel VM */
180 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
181 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
183 pv_addr_t kernel_pt_table
[NUM_KERNEL_PTS
];
187 #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2)
188 static vaddr_t sa110_cc_base
;
189 #endif /* CPU_SA110 */
192 void physcon_display_base(u_int
);
193 extern void consinit(void);
195 void data_abort_handler(trapframe_t
*);
196 void prefetch_abort_handler(trapframe_t
*);
197 void undefinedinstruction_bounce(trapframe_t
*frame
);
199 static void canonicalise_bootconfig(struct bootconfig
*, struct bootconfig
*);
200 static void process_kernel_args(void);
202 extern void dump_spl_masks(void);
204 void rpc_sa110_cc_setup(void);
206 void parse_rpc_bootargs(char *args
);
208 extern void dumpsys(void);
211 # define console_flush() /* empty */
214 #define panic2(a) do { \
215 memset((void *) (videomemory.vidm_vbase), 0x55, 50*1024); \
218 } while (/* CONSTCOND */ 0)
221 * void cpu_reboot(int howto, char *bootstr)
225 * Deal with any syncing, unmounting, dumping and shutdown hooks,
226 * then reset the CPU.
229 /* NOTE: These variables will be removed, well some of them */
231 extern u_int current_mask
;
234 cpu_reboot(int howto
, char *bootstr
)
238 printf("boot: howto=%08x curlwp=%p\n", howto
, curlwp
);
240 printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n",
241 irqmasks
[IPL_BIO
], irqmasks
[IPL_NET
], irqmasks
[IPL_TTY
],
243 printf("ipl_audio=%08x ipl_clock=%08x ipl_none=%08x\n",
244 irqmasks
[IPL_AUDIO
], irqmasks
[IPL_CLOCK
], irqmasks
[IPL_NONE
]);
246 /* dump_spl_masks(); */
247 #endif /* DIAGNOSTIC */
250 * If we are still cold then hit the air brakes
251 * and crash to earth fast
255 pmf_system_shutdown(boothowto
);
256 printf("Halted while still in the ICE age.\n");
257 printf("The operating system has halted.\n");
258 printf("Please press any key to reboot.\n\n");
260 printf("rebooting...\n");
265 /* Disable console buffering */
269 * If RB_NOSYNC was not specified sync the discs.
270 * Note: Unless cold is set to 1 here, syslogd will die during
271 * the unmount. It looks like syslogd is getting woken up
272 * only to find that it cannot page part of the binary in as
273 * the filesystem has been unmounted.
275 if (!(howto
& RB_NOSYNC
))
278 /* Say NO to interrupts */
281 /* Do a dump if requested. */
282 if ((howto
& (RB_DUMP
| RB_HALT
)) == RB_DUMP
)
286 * Auto reboot overload protection
288 * This code stops the kernel entering an endless loop of reboot
289 * - panic cycles. This will have the effect of stopping further
290 * reboots after it has rebooted 8 times after panics. A clean
291 * halt or reboot will reset the counter.
294 /* Run any shutdown hooks */
297 pmf_system_shutdown(boothowto
);
299 /* Make sure IRQ's are disabled */
302 if (howto
& RB_HALT
) {
303 printf("The operating system has halted.\n");
304 printf("Please press any key to reboot.\n\n");
308 printf("rebooting...\n");
315 * u_int initarm(BootConfig *bootconf)
317 * Initial entry point on startup. This gets called before main() is
319 * It should be responsible for setting up everything that must be
320 * in place when main is called.
322 * Taking a copy of the boot configuration structure.
323 * Initialising the physical console so characters can be printed.
324 * Setting up page tables for the kernel
325 * Relocating the kernel to the bottom of physical memory
329 * this part is completely rewritten for the new bootloader ... It features
330 * a flat memory map with a mapping comparable to the EBSA arm32 machine
331 * to boost the portability and likeness of the code
335 * Mapping table for core kernel memory. This memory is mapped at init
336 * time with section mappings.
338 * XXX One big assumption in the current architecture seems that the kernel is
339 * XXX supposed to be mapped into bootconfig.dram[0].
342 #define ONE_MB 0x100000
351 /* Map 1Mb section for VIDC20 */
352 { VIDC_BASE
, VIDC_HW_BASE
,
353 ONE_MB
, VM_PROT_READ
|VM_PROT_WRITE
,
356 /* Map 1Mb section from IOMD */
357 { IOMD_BASE
, IOMD_HW_BASE
,
358 ONE_MB
, VM_PROT_READ
|VM_PROT_WRITE
,
361 /* Map 1Mb of COMBO (and module space) */
362 { IO_BASE
, IO_HW_BASE
,
363 ONE_MB
, VM_PROT_READ
|VM_PROT_WRITE
,
370 canonicalise_bootconfig(struct bootconfig
*bootconf
, struct bootconfig
*raw_bootconf
)
372 /* check for bootconfig v2+ structure */
373 if (raw_bootconf
->magic
== BOOTCONFIG_MAGIC
) {
374 /* v2+ cleaned up structure found */
375 *bootconf
= *raw_bootconf
;
378 panic2(("Internal error: no valid bootconfig block found"));
384 initarm(void *cookie
)
386 struct bootconfig
*raw_bootconf
= cookie
;
390 u_int kerneldatasize
;
392 struct exec
*kernexec
= (struct exec
*)KERNEL_TEXT_BASE
;
395 * Heads up ... Setup the CPU / MMU / TLB functions
399 /* canonicalise the boot configuration structure to alow versioning */
400 canonicalise_bootconfig(&bootconfig
, raw_bootconf
);
401 booted_kernel
= bootconfig
.kernelname
;
403 /* if the wscons interface is used, switch off VERBOSE booting :( */
405 # undef VERBOSE_INIT_ARM
410 * Initialise the video memory descriptor
412 * Note: all references to the video memory virtual/physical address
413 * should go via this structure.
416 /* Hardwire it on the place the bootloader tells us */
417 videomemory
.vidm_vbase
= bootconfig
.display_start
;
418 videomemory
.vidm_pbase
= bootconfig
.display_phys
;
419 videomemory
.vidm_size
= bootconfig
.display_size
;
420 if (bootconfig
.vram
[0].pages
)
421 videomemory
.vidm_type
= VIDEOMEM_TYPE_VRAM
;
423 videomemory
.vidm_type
= VIDEOMEM_TYPE_DRAM
;
424 vidc_base
= (int *) VIDC_HW_BASE
;
425 iomd_base
= IOMD_HW_BASE
;
428 * Initialise the physical console
429 * This is done in main() but for the moment we do it here so that
430 * we can use printf in initarm() before main() has been called.
431 * only for `vidcconsole!' ... not wscons
438 * Initialise the diagnostic serial console
439 * This allows a means of generating output during initarm().
440 * Once all the memory map changes are complete we can call consinit()
441 * and not have to worry about things moving.
443 /* fcomcnattach(DC21285_ARMCSR_BASE, comcnspeed, comcnmode); */
444 /* XXX snif .... i am still not able to this */
447 * We have the following memory map (derived from EBSA)
449 * virtual address == physical address apart from the areas:
450 * 0x00000000 -> 0x000fffff which is mapped to
451 * top 1MB of physical memory
452 * 0xf0000000 -> 0xf0ffffff wich is mapped to
453 * physical address 0x01000000 -> 0x01ffffff (DRAM0a, dram[0])
455 * This means that the kernel is mapped suitably for continuing
456 * execution, all I/O is mapped 1:1 virtual to physical and
457 * physical memory is accessible.
459 * The initarm() has the responsibility for creating the kernel
461 * It must also set up various memory pointers that are used
465 /* START OF REAL NEW STUFF */
467 /* Check to make sure the page size is correct */
468 if (PAGE_SIZE
!= bootconfig
.pagesize
)
469 panic2(("Page size is %d bytes instead of %d !! (huh?)\n",
470 bootconfig
.pagesize
, PAGE_SIZE
));
472 /* process arguments */
473 process_kernel_args();
477 * Now set up the page tables for the kernel ... this part is copied
478 * in a (modified?) way from the EBSA machine port....
481 #ifdef VERBOSE_INIT_ARM
482 printf("Allocating page tables\n");
485 * Set up the variables that define the availablilty of physical
488 physical_start
= 0xffffffff;
490 for (loop
= 0, physmem
= 0; loop
< bootconfig
.dramblocks
; ++loop
) {
491 if (bootconfig
.dram
[loop
].address
< physical_start
)
492 physical_start
= bootconfig
.dram
[loop
].address
;
493 memoryblock_end
= bootconfig
.dram
[loop
].address
+
494 bootconfig
.dram
[loop
].pages
* PAGE_SIZE
;
495 if (memoryblock_end
> physical_end
)
496 physical_end
= memoryblock_end
;
497 physmem
+= bootconfig
.dram
[loop
].pages
;
499 /* constants for now, but might be changed/configured */
500 dma_range_begin
= (paddr_t
) physical_start
;
501 dma_range_end
= (paddr_t
) MIN(physical_end
, 512*1024*1024);
502 /* XXX HACK HACK XXX */
503 /* dma_range_end = 0x18000000; */
505 if (physical_start
!= bootconfig
.dram
[0].address
) {
509 * must be a kinetic, as it's the only thing to shuffle memory
512 /* hack hack - throw away the slow dram */
513 for (loop
= 0; loop
< bootconfig
.dramblocks
; ++loop
) {
514 if (bootconfig
.dram
[loop
].address
<
515 bootconfig
.dram
[0].address
) {
516 /* non kinetic ram */
517 bootconfig
.dram
[loop
].address
= 0;
518 physmem
-= bootconfig
.dram
[loop
].pages
;
519 bootconfig
.drampages
-=
520 bootconfig
.dram
[loop
].pages
;
521 bootconfig
.dram
[loop
].pages
= 0;
525 physical_start
= bootconfig
.dram
[0].address
;
526 bootconfig
.dramblocks
-= oldblocks
;
529 physical_freestart
= physical_start
;
530 free_pages
= bootconfig
.drampages
;
531 physical_freeend
= physical_end
;
535 * AHUM !! set this variable ... it was set up in the old 1st
538 kerneldatasize
= bootconfig
.kernsize
+ bootconfig
.MDFsize
;
540 /* Update the address of the first free page of physical memory */
541 /* XXX Assumption that the kernel and stuff is at the LOWEST physical memory address? XXX */
542 physical_freestart
+=
543 bootconfig
.kernsize
+ bootconfig
.MDFsize
+ bootconfig
.scratchsize
;
544 free_pages
-= (physical_freestart
- physical_start
) / PAGE_SIZE
;
546 /* Define a macro to simplify memory allocation */
547 #define valloc_pages(var, np) \
548 alloc_pages((var).pv_pa, (np)); \
549 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
551 #define alloc_pages(var, np) \
552 (var) = physical_freestart; \
553 physical_freestart += ((np) * PAGE_SIZE); \
554 free_pages -= (np); \
555 memset((char *)(var), 0, ((np) * PAGE_SIZE));
558 kernel_l1pt
.pv_pa
= 0;
559 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
560 /* Are we 16KB aligned for an L1 ? */
561 if ((physical_freestart
& (L1_TABLE_SIZE
- 1)) == 0
562 && kernel_l1pt
.pv_pa
== 0) {
563 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
565 valloc_pages(kernel_pt_table
[loop1
],
566 L2_TABLE_SIZE
/ PAGE_SIZE
);
573 /* This should never be able to happen but better confirm that. */
574 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
575 panic2(("initarm: Failed to align the kernel page "
580 * Allocate a page for the system page mapped to V0x00000000
581 * This page will just contain the system vectors and can be
582 * shared by all processes.
584 alloc_pages(systempage
.pv_pa
, 1);
586 /* Allocate stacks for all modes */
587 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
588 valloc_pages(abtstack
, ABT_STACK_SIZE
);
589 valloc_pages(undstack
, UND_STACK_SIZE
);
590 valloc_pages(kernelstack
, UPAGES
);
592 #ifdef VERBOSE_INIT_ARM
593 printf("Setting up stacks :\n");
594 printf("IRQ stack: p0x%08lx v0x%08lx\n",
595 irqstack
.pv_pa
, irqstack
.pv_va
);
596 printf("ABT stack: p0x%08lx v0x%08lx\n",
597 abtstack
.pv_pa
, abtstack
.pv_va
);
598 printf("UND stack: p0x%08lx v0x%08lx\n",
599 undstack
.pv_pa
, undstack
.pv_va
);
600 printf("SVC stack: p0x%08lx v0x%08lx\n",
601 kernelstack
.pv_pa
, kernelstack
.pv_va
);
605 alloc_pages(msgbufphys
, round_page(MSGBUFSIZE
) / PAGE_SIZE
);
609 * XXX totally stuffed hack to work round problems introduced
610 * in recent versions of the pmap code. Due to the calls used there
611 * we cannot allocate virtual memory during bootstrap.
613 sa110_cc_base
= (KERNEL_BASE
+ (physical_freestart
- physical_start
)
614 + (CPU_SA110_CACHE_CLEAN_SIZE
- 1))
615 & ~(CPU_SA110_CACHE_CLEAN_SIZE
- 1);
616 #endif /* CPU_SA110 */
619 * Ok we have allocated physical pages for the primary kernel
623 #ifdef VERBOSE_INIT_ARM
624 printf("Creating L1 page table\n");
628 * Now we start construction of the L1 page table
629 * We start by mapping the L2 page tables into the L1.
630 * This means that we can replace L1 mappings later on if necessary
632 l1pagetable
= kernel_l1pt
.pv_pa
;
634 /* Map the L2 pages tables in the L1 page table */
635 pmap_link_l2pt(l1pagetable
, 0x00000000,
636 &kernel_pt_table
[KERNEL_PT_SYS
]);
637 pmap_link_l2pt(l1pagetable
, KERNEL_BASE
,
638 &kernel_pt_table
[KERNEL_PT_KERNEL
]);
639 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; ++loop
)
640 pmap_link_l2pt(l1pagetable
, KERNEL_VM_BASE
+ loop
* 0x00400000,
641 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
642 pmap_link_l2pt(l1pagetable
, VMEM_VBASE
,
643 &kernel_pt_table
[KERNEL_PT_VMEM
]);
645 /* update the top of the kernel VM */
647 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
649 #ifdef VERBOSE_INIT_ARM
650 printf("Mapping kernel\n");
653 /* Now we fill in the L2 pagetable for the kernel code/data */
654 /* XXX Kernel doesn't have to be on physical_start (!) use bootconfig XXX */
656 * The defines are a workaround for a recent problem that occurred
657 * with ARM 610 processors and some ARM 710 processors
658 * Other ARM 710 and StrongARM processors don't have a problem.
660 if (N_GETMAGIC(kernexec
[0]) == ZMAGIC
) {
661 #if defined(CPU_ARM6) || defined(CPU_ARM7)
662 logical
= pmap_map_chunk(l1pagetable
, KERNEL_TEXT_BASE
,
663 physical_start
, kernexec
->a_text
,
664 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
665 #else /* CPU_ARM6 || CPU_ARM7 */
666 logical
= pmap_map_chunk(l1pagetable
, KERNEL_TEXT_BASE
,
667 physical_start
, kernexec
->a_text
,
668 VM_PROT_READ
, PTE_CACHE
);
669 #endif /* CPU_ARM6 || CPU_ARM7 */
670 logical
+= pmap_map_chunk(l1pagetable
,
671 KERNEL_TEXT_BASE
+ logical
, physical_start
+ logical
,
672 kerneldatasize
- kernexec
->a_text
,
673 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
674 } else { /* !ZMAGIC */
676 * Most likely an ELF kernel ...
677 * XXX no distinction yet between read only and
678 * read/write area's ...
680 pmap_map_chunk(l1pagetable
, KERNEL_TEXT_BASE
,
681 physical_start
, kerneldatasize
,
682 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
686 #ifdef VERBOSE_INIT_ARM
687 printf("Constructing L2 page tables\n");
690 /* Map the stack pages */
691 pmap_map_chunk(l1pagetable
, irqstack
.pv_va
, irqstack
.pv_pa
,
692 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
693 pmap_map_chunk(l1pagetable
, abtstack
.pv_va
, abtstack
.pv_pa
,
694 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
695 pmap_map_chunk(l1pagetable
, undstack
.pv_va
, undstack
.pv_pa
,
696 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
697 pmap_map_chunk(l1pagetable
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
698 UPAGES
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
700 pmap_map_chunk(l1pagetable
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
701 L1_TABLE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
703 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
704 pmap_map_chunk(l1pagetable
, kernel_pt_table
[loop
].pv_va
,
705 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
706 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
709 /* Now we fill in the L2 pagetable for the VRAM */
711 * Current architectures mean that the VRAM is always in 1
712 * continuous bank. This means that we can just map the 2 meg
713 * that the VRAM would occupy. In theory we don't need a page
714 * table for VRAM, we could section map it but we would need
715 * the page tables if DRAM was in use.
716 * XXX please map two adjacent virtual areas to ONE physical
719 pmap_map_chunk(l1pagetable
, VMEM_VBASE
, videomemory
.vidm_pbase
,
720 videomemory
.vidm_size
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
721 pmap_map_chunk(l1pagetable
, VMEM_VBASE
+ videomemory
.vidm_size
,
722 videomemory
.vidm_pbase
, videomemory
.vidm_size
,
723 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
725 /* Map the vector page. */
726 pmap_map_entry(l1pagetable
, vector_page
, systempage
.pv_pa
,
727 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
729 /* Map the core memory needed before autoconfig */
731 while (l1_sec_table
[loop
].size
) {
734 #ifdef VERBOSE_INIT_ARM
735 printf("%08lx -> %08lx @ %08lx\n", l1_sec_table
[loop
].pa
,
736 l1_sec_table
[loop
].pa
+ l1_sec_table
[loop
].size
- 1,
737 l1_sec_table
[loop
].va
);
739 for (sz
= 0; sz
< l1_sec_table
[loop
].size
; sz
+= L1_S_SIZE
)
740 pmap_map_section(l1pagetable
,
741 l1_sec_table
[loop
].va
+ sz
,
742 l1_sec_table
[loop
].pa
+ sz
,
743 l1_sec_table
[loop
].prot
,
744 l1_sec_table
[loop
].cache
);
749 * Now we have the real page tables in place so we can switch
750 * to them. Once this is done we will be running with the
751 * REAL kernel page tables.
754 #ifdef VERBOSE_INIT_ARM
755 printf("switching domains\n");
757 /* be a client to all domains */
758 cpu_domains(0x55555555);
761 #ifdef VERBOSE_INIT_ARM
762 printf("switching to new L1 page table\n");
764 cpu_setttb(kernel_l1pt
.pv_pa
);
767 * We must now clean the cache again....
768 * Cleaning may be done by reading new data to displace any
769 * dirty data in the cache. This will have happened in cpu_setttb()
770 * but since we are boot strapping the addresses used for the read
771 * may have just been remapped and thus the cache could be out
772 * of sync. A re-clean after the switch will cure this.
773 * After booting there are no gross reloations of the kernel thus
774 * this problem will not occur after initarm().
776 cpu_idcache_wbinv_all();
778 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));
781 * Moved from cpu_startup() as data_abort_handler() references
782 * this during uvm init
784 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
787 * if there is support for a serial console ...we should now
793 * Reflect videomemory relocation in the videomemory structure
796 if (bootconfig
.vram
[0].pages
== 0) {
797 videomemory
.vidm_vbase
= VMEM_VBASE
;
799 videomemory
.vidm_vbase
= VMEM_VBASE
;
800 bootconfig
.display_start
= VMEM_VBASE
;
802 vidc_base
= (int *) VIDC_BASE
;
803 iomd_base
= IOMD_BASE
;
805 #ifdef VERBOSE_INIT_ARM
806 printf("running on the new L1 page table!\n");
810 arm32_vector_init(ARM_VECTORS_LOW
, ARM_VEC_ALL
);
812 #ifdef VERBOSE_INIT_ARM
817 * Pages were allocated during the secondary bootstrap for the
818 * stacks for different CPU modes.
819 * We must now set the r13 registers in the different CPU modes to
820 * point to these stacks.
821 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
822 * of the stack memory.
824 #ifdef VERBOSE_INIT_ARM
825 printf("init subsystems: stacks ");
829 set_stackptr(PSR_IRQ32_MODE
,
830 irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
831 set_stackptr(PSR_ABT32_MODE
,
832 abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
833 set_stackptr(PSR_UND32_MODE
,
834 undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
836 if (pmap_debug_level
>= 0)
837 printf("kstack V%08lx P%08lx\n", kernelstack
.pv_va
,
839 #endif /* PMAP_DEBUG */
842 * Well we should set a data abort handler.
843 * Once things get going this will change as we will need a proper
844 * handler. Until then we will use a handler that just panics but
846 * Initialisation of the vectors will just panic on a data abort.
847 * This just fills in a slightly better one.
849 #ifdef VERBOSE_INIT_ARM
852 data_abort_handler_address
= (u_int
)data_abort_handler
;
853 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
854 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
860 * We now have the kernel in physical memory from the bottom upwards.
861 * Kernel page tables are physically above this.
862 * The kernel is mapped to 0xf0000000
863 * The kernel data PTs will handle the mapping of
864 * 0xf1000000-0xf5ffffff (80 Mb)
865 * 2Meg of VRAM is mapped to 0xf7000000
866 * The page tables are mapped to 0xefc00000
867 * The IOMD is mapped to 0xf6000000
868 * The VIDC is mapped to 0xf6100000
869 * The IOMD/VIDC could be pushed up higher but i havent got
870 * sufficient documentation to do so; the addresses are not
871 * parametized yet and hard to read... better fix this before;
872 * its pretty unforgiving.
875 /* Initialise the undefined instruction handlers */
876 #ifdef VERBOSE_INIT_ARM
877 printf("undefined ");
882 /* Load memory into UVM. */
883 #ifdef VERBOSE_INIT_ARM
886 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
887 for (loop
= 0; loop
< bootconfig
.dramblocks
; loop
++) {
888 paddr_t start
= (paddr_t
)bootconfig
.dram
[loop
].address
;
889 paddr_t end
= start
+ (bootconfig
.dram
[loop
].pages
* PAGE_SIZE
);
891 if (start
< physical_freestart
)
892 start
= physical_freestart
;
893 if (end
> physical_freeend
)
894 end
= physical_freeend
;
896 /* XXX Consider DMA range intersection checking. */
898 uvm_page_physload(atop(start
), atop(end
),
899 atop(start
), atop(end
), VM_FREELIST_DEFAULT
);
902 /* Boot strap pmap telling it where the kernel page table is */
903 #ifdef VERBOSE_INIT_ARM
906 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
909 /* Setup the IRQ system */
910 #ifdef VERBOSE_INIT_ARM
915 #ifdef VERBOSE_INIT_ARM
920 consinit(); /* necessary ? */
923 /* Talk to the user */
924 printf("NetBSD/evbarm booting ... \n");
926 /* Tell the user if his boot loader is too old */
927 if ((bootconfig
.magic
< BOOTCONFIG_MAGIC
) ||
928 (bootconfig
.version
!= BOOTCONFIG_VERSION
)) {
929 printf("\nDETECTED AN OLD BOOTLOADER. PLEASE UPGRADE IT\n\n");
933 printf("Kernel loaded from file %s\n", bootconfig
.kernelname
);
934 printf("Kernel arg string (@%p) %s\n",
935 bootconfig
.args
, bootconfig
.args
);
936 printf("\nBoot configuration structure reports the following "
939 printf(" DRAM block 0a at %08x size %08x "
940 "DRAM block 0b at %08x size %08x\n\r",
941 bootconfig
.dram
[0].address
,
942 bootconfig
.dram
[0].pages
* bootconfig
.pagesize
,
943 bootconfig
.dram
[1].address
,
944 bootconfig
.dram
[1].pages
* bootconfig
.pagesize
);
945 printf(" DRAM block 1a at %08x size %08x "
946 "DRAM block 1b at %08x size %08x\n\r",
947 bootconfig
.dram
[2].address
,
948 bootconfig
.dram
[2].pages
* bootconfig
.pagesize
,
949 bootconfig
.dram
[3].address
,
950 bootconfig
.dram
[3].pages
* bootconfig
.pagesize
);
951 printf(" VRAM block 0 at %08x size %08x\n\r",
952 bootconfig
.vram
[0].address
,
953 bootconfig
.vram
[0].pages
* bootconfig
.pagesize
);
955 #if NKSYMS || defined(DDB) || defined(MODULAR)
956 ksyms_addsyms_elf(bootconfig
.ksym_end
- bootconfig
.ksym_start
,
957 (void *) bootconfig
.ksym_start
, (void *) bootconfig
.ksym_end
);
963 if (boothowto
& RB_KDB
)
967 /* We return the new stack pointer address */
968 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
973 process_kernel_args(void)
977 /* Ok now we will check the arguments for interesting parameters. */
978 args
= bootconfig
.args
;
981 /* Only arguments itself are passed from the new bootloader */
986 parse_mi_bootargs(boot_args
);
987 parse_rpc_bootargs(boot_args
);
992 parse_rpc_bootargs(char *args
)
996 if (get_bootconf_option(args
, "videodram", BOOTOPT_TYPE_INT
,
998 videodram_size
= integer
;
999 /* Round to 4K page */
1000 videodram_size
*= 1024;
1001 videodram_size
= round_page(videodram_size
);
1002 if (videodram_size
> 1024*1024)
1003 videodram_size
= 1024*1024;
1006 /* End of machdep.c */