4 * Machine dependent functions for kernel setup for TI OSK5912 board.
5 * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c
7 * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
8 * Written by Hiroyuki Bessho for Genetec Corporation.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 * 3. The name of Genetec Corporation may not be used to endorse or
19 * promote products derived from this software without specific prior
22 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 2001 Wasabi Systems, Inc.
35 * All rights reserved.
37 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed for the NetBSD Project by
50 * Wasabi Systems, Inc.
51 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
52 * or promote products derived from this software without specific prior
55 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
59 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
65 * POSSIBILITY OF SUCH DAMAGE.
67 * Copyright (c) 1997,1998 Mark Brinicombe.
68 * Copyright (c) 1997,1998 Causality Limited.
69 * All rights reserved.
71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions
74 * 1. Redistributions of source code must retain the above copyright
75 * notice, this list of conditions and the following disclaimer.
76 * 2. Redistributions in binary form must reproduce the above copyright
77 * notice, this list of conditions and the following disclaimer in the
78 * documentation and/or other materials provided with the distribution.
79 * 3. All advertising materials mentioning features or use of this software
80 * must display the following acknowledgement:
81 * This product includes software developed by Mark Brinicombe
82 * for the NetBSD Project.
83 * 4. The name of the company nor the name of the author may be used to
84 * endorse or promote products derived from this software without specific
85 * prior written permission.
87 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
88 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
89 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
91 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
92 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
93 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 * Copyright (c) 2007 Microsoft
100 * All rights reserved.
102 * Redistribution and use in source and binary forms, with or without
103 * modification, are permitted provided that the following conditions
105 * 1. Redistributions of source code must retain the above copyright
106 * notice, this list of conditions and the following disclaimer.
107 * 2. Redistributions in binary form must reproduce the above copyright
108 * notice, this list of conditions and the following disclaimer in the
109 * documentation and/or other materials provided with the distribution.
110 * 3. All advertising materials mentioning features or use of this software
111 * must display the following acknowledgement:
112 * This product includes software developed by Microsoft
114 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
115 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
116 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
117 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
118 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
119 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
121 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
122 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
123 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
127 #include <sys/cdefs.h>
128 __KERNEL_RCSID(0, "$NetBSD$");
130 #include "opt_machdep.h"
132 #include "opt_kgdb.h"
133 #include "opt_ipkdb.h"
136 #include "opt_omap.h"
139 #include <sys/param.h>
140 #include <sys/device.h>
141 #include <sys/systm.h>
142 #include <sys/kernel.h>
143 #include <sys/exec.h>
144 #include <sys/proc.h>
145 #include <sys/msgbuf.h>
146 #include <sys/reboot.h>
147 #include <sys/termios.h>
148 #include <sys/ksyms.h>
150 #include <uvm/uvm_extern.h>
152 #include <sys/conf.h>
153 #include <dev/cons.h>
156 #include <machine/db_machdep.h>
157 #include <ddb/db_sym.h>
158 #include <ddb/db_extern.h>
160 #include <sys/kgdb.h>
163 #include <machine/bootconfig.h>
164 #include <machine/bus.h>
165 #include <machine/cpu.h>
166 #include <machine/frame.h>
167 #include <arm/armreg.h>
168 #include <arm/undefined.h>
170 #include <arm/arm32/machdep.h>
172 #include <arm/omap/omap_com.h>
173 #include <arm/omap/omap_var.h>
174 #include <arm/omap/omap_wdtvar.h>
176 #include <evbarm/tisdp24xx/sdp24xx.h>
178 #include "omapwdt32k.h"
181 * Address to call from cpu_reset() to reset the machine.
182 * This is machine architecture dependant as it varies depending
183 * on where the ROM appears when you turn the MMU off.
186 u_int cpu_reset_address
= 0;
188 /* Define various stack sizes in pages */
189 #define IRQ_STACK_SIZE 1
190 #define FIQ_STACK_SIZE 1
191 #define ABT_STACK_SIZE 1
193 #define UND_STACK_SIZE 2
195 #define UND_STACK_SIZE 1
198 BootConfig bootconfig
; /* Boot config storage */
199 char *boot_args
= NULL
;
200 char *boot_file
= NULL
;
202 /* Physical address of the beginning of SDRAM. */
203 paddr_t physical_start
;
204 /* Physical address of the first byte after the end of SDRAM. */
205 paddr_t physical_end
;
207 /* Same things, but for the free (unused by the kernel) memory. */
208 static paddr_t physical_freestart
, physical_freeend
;
209 static u_int free_pages
;
211 /* Physical and virtual addresses for some global pages */
216 pv_addr_t kernelstack
; /* stack for SVC mode */
218 /* Physical address of the message buffer. */
221 extern u_int data_abort_handler_address
;
222 extern u_int prefetch_abort_handler_address
;
223 extern u_int undefined_handler_address
;
224 extern char KERNEL_BASE_phys
[];
225 extern char etext
[], __data_start
[], _edata
[], __bss_start
[], __bss_end__
[];
228 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
229 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
230 #define KERNEL_PT_KERNEL_NUM 4
231 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
232 /* Page tables for mapping kernel VM */
233 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
234 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
236 pv_addr_t kernel_pt_table
[NUM_KERNEL_PTS
];
239 * Macros to translate between physical and virtual for a subset of the
240 * kernel address space. *Not* for general use.
242 #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
244 #define KERN_VTOPHYS(va) \
245 ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
246 #define KERN_PHYSTOV(pa) \
247 ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
249 #define KERN_VTOPHYS(va) ((paddr_t)(va))
250 #define KERN_PHYSTOV(pa) ((vaddr_t)(pa))
255 void omap2430_intr_init(bus_space_tag_t
);
258 static void kgdb_port_init(void);
261 static void setup_real_page_tables(void);
262 static void init_clocks(void);
264 bs_protos(bs_notimpl
);
268 #include <dev/ic/comreg.h>
269 #include <dev/ic/comvar.h>
273 * void cpu_reboot(int howto, char *bootstr)
277 * Deal with any syncing, unmounting, dumping and shutdown hooks,
278 * then reset the CPU.
281 cpu_reboot(int howto
, char *bootstr
)
285 printf("boot: howto=%08x curproc=%p\n", howto
, curproc
);
289 * If we are still cold then hit the air brakes
290 * and crash to earth fast
294 pmf_system_shutdown(boothowto
);
295 printf("The operating system has halted.\n");
296 printf("Please press any key to reboot.\n\n");
298 printf("rebooting...\n");
306 /* Disable console buffering */
310 * If RB_NOSYNC was not specified sync the discs.
311 * Note: Unless cold is set to 1 here, syslogd will die during the
312 * unmount. It looks like syslogd is getting woken up only to find
313 * that it cannot page part of the binary in as the filesystem has
316 if (!(howto
& RB_NOSYNC
))
319 /* Say NO to interrupts */
322 /* Do a dump if requested. */
323 if ((howto
& (RB_DUMP
| RB_HALT
)) == RB_DUMP
)
326 /* Run any shutdown hooks */
329 pmf_system_shutdown(boothowto
);
331 /* Make sure IRQ's are disabled */
334 if (howto
& RB_HALT
) {
335 printf("The operating system has halted.\n");
336 printf("Please press any key to reboot.\n\n");
340 printf("rebooting...\n");
349 * Static device mappings. These peripheral registers are mapped at
350 * fixed virtual addresses very early in initarm() so that we can use
351 * them while booting the kernel, and stay at the same address
352 * throughout whole kernel's life time.
354 * We use this table twice; once with bootstrap page table, and once
355 * with kernel's page table which we build up in initarm().
357 * Since we map these registers into the bootstrap page table using
358 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
359 * registers segment-aligned and segment-rounded in order to avoid
360 * using the 2nd page tables.
363 #define _A(a) ((a) & ~L1_S_OFFSET)
364 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
366 static const struct pmap_devmap devmap
[] = {
369 * Map the first 1MB of L4 Core area
370 * this gets us the console UART, GP timers, interrupt
371 * controller and GPIO5.
373 .pd_va
= _A(OMAP2430_L4_CORE_VBASE
),
374 .pd_pa
= _A(OMAP2430_L4_CORE_BASE
),
375 .pd_size
= _S(1 << 20),
376 .pd_prot
= VM_PROT_READ
|VM_PROT_WRITE
,
377 .pd_cache
= PTE_NOCACHE
381 * Map the first 1MB of L4 Wakeup area
382 * this gets us GPIO[1-4] and Clock Management regs
384 .pd_va
= _A(OMAP2430_L4_WAKEUP_VBASE
),
385 .pd_pa
= _A(OMAP2430_L4_WAKEUP_BASE
),
386 .pd_size
= _S(1 << 20),
387 .pd_prot
= VM_PROT_READ
|VM_PROT_WRITE
,
388 .pd_cache
= PTE_NOCACHE
397 static void sdp_db_trap(int where
)
400 static int oldwatchdogstate
;
403 oldwatchdogstate
= omapwdt32k_enable(0);
405 omapwdt32k_enable(oldwatchdogstate
);
411 void sdp_putchar(char c
);
415 unsigned char *com0addr
= (char *)CONSADDR_VA
;
418 while ((com0addr
[5 * 4] & 0x20) == 0)
424 while ((com0addr
[5 * 4] & 0x20) == 0)
432 * Initial entry point on startup. This gets called before main() is
434 * It should be responsible for setting up everything that must be
435 * in place when main is called.
437 * Taking a copy of the boot configuration structure.
438 * Initialising the physical console so characters can be printed.
439 * Setting up page tables for the kernel
440 * Relocating the kernel to the bottom of physical memory
449 * When we enter here, we are using a temporary first level
450 * translation table with section entries in it to cover the OBIO
451 * peripherals and SDRAM. The temporary first level translation table
452 * is at the end of SDRAM.
455 /* Heads up ... Setup the CPU / MMU / TLB functions. */
457 panic("cpu not recognized!");
461 /* The console is going to try to map things. Give pmap a devmap. */
462 pmap_devmap_register(devmap
);
471 #ifdef VERBOSE_INIT_ARM
472 /* Talk to the user */
473 printf("\nNetBSD/evbarm (SDP24xx) booting ...\n");
477 char mi_bootargs
[] = BOOT_ARGS
;
478 parse_mi_bootargs(mi_bootargs
);
481 #ifdef VERBOSE_INIT_ARM
482 printf("initarm: Configuring system ...\n");
486 * Set up the variables that define the availability of physical
489 physical_start
= KERNEL_BASE_PHYS
;
490 #define MEMSIZE_BYTES (MEMSIZE * 1024 * 1024)
491 physical_end
= (physical_start
& ~(0x400000-1)) + MEMSIZE_BYTES
;
492 physmem
= (physical_end
- physical_start
) / PAGE_SIZE
;
494 /* Fake bootconfig structure for the benefit of pmap.c. */
495 bootconfig
.dramblocks
= 1;
496 bootconfig
.dram
[0].address
= physical_start
;
497 bootconfig
.dram
[0].pages
= physmem
;
500 * Our kernel is at the beginning of memory, so set our free space to
501 * all the memory after the kernel.
503 physical_freestart
= KERN_VTOPHYS(round_page((vaddr_t
) _end
));
504 physical_freeend
= physical_end
;
505 free_pages
= (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
508 * This is going to do all the hard work of setting up the first and
509 * and second level page tables. Pages of memory will be allocated
510 * and mapped for other structures that are required for system
511 * operation. When it returns, physical_freestart and free_pages will
512 * have been updated to reflect the allocations that were made. In
513 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack,
514 * abtstack, undstack, kernelstack, msgbufphys will be set to point to
515 * the memory that was allocated for them.
517 setup_real_page_tables();
520 * Moved from cpu_startup() as data_abort_handler() references
521 * this during uvm init.
523 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
525 #ifdef VERBOSE_INIT_ARM
526 printf("bootstrap done.\n");
529 arm32_vector_init(ARM_VECTORS_HIGH
, ARM_VEC_ALL
);
532 * Pages were allocated during the secondary bootstrap for the
533 * stacks for different CPU modes.
534 * We must now set the r13 registers in the different CPU modes to
535 * point to these stacks.
536 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
537 * of the stack memory.
539 #ifdef VERBOSE_INIT_ARM
540 printf("init subsystems: stacks ");
543 set_stackptr(PSR_FIQ32_MODE
, fiqstack
.pv_va
+ FIQ_STACK_SIZE
* PAGE_SIZE
);
544 set_stackptr(PSR_IRQ32_MODE
, irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
545 set_stackptr(PSR_ABT32_MODE
, abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
546 set_stackptr(PSR_UND32_MODE
, undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
549 * Well we should set a data abort handler.
550 * Once things get going this will change as we will need a proper
552 * Until then we will use a handler that just panics but tells us
554 * Initialisation of the vectors will just panic on a data abort.
555 * This just fills in a slightly better one.
557 #ifdef VERBOSE_INIT_ARM
560 data_abort_handler_address
= (u_int
)data_abort_handler
;
561 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
562 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
564 /* Initialise the undefined instruction handlers */
565 #ifdef VERBOSE_INIT_ARM
566 printf("undefined ");
570 /* Load memory into UVM. */
571 #ifdef VERBOSE_INIT_ARM
574 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
575 uvm_page_physload(atop(physical_freestart
), atop(physical_freeend
),
576 atop(physical_freestart
), atop(physical_freeend
),
577 VM_FREELIST_DEFAULT
);
579 /* Boot strap pmap telling it where the kernel page table is */
580 #ifdef VERBOSE_INIT_ARM
583 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
585 #ifdef VERBOSE_INIT_ARM
590 /* Initialise ipkdb */
592 if (boothowto
& RB_KDB
)
597 if (boothowto
& RB_KDB
) {
604 db_trap_callback
= sdp_db_trap
;
607 /* Firmware doesn't load symbols. */
608 ddb_init(0, NULL
, NULL
);
610 if (boothowto
& RB_KDB
)
613 printf("initarm done.\n");
615 /* We return the new stack pointer address */
616 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
619 void arm11_pmc_ccnt_init(void);
625 static volatile uint32_t * const clksel_reg
= (volatile uint32_t *) (OMAP2430_L4_WAKEUP_VBASE
+ OMAP2_CM_BASE
+ OMAP2_CM_CLKSEL_MPU
- OMAP2430_L4_WAKEUP_BASE
);
630 if (v
!= OMAP2430_CM_CLKSEL_MPU_FULLSPEED
) {
631 printf("Changed CPU speed from half (%d) ", v
);
632 *clksel_reg
= OMAP2430_CM_CLKSEL_MPU_FULLSPEED
;
633 printf("to full speed.\n");
637 arm11_pmc_ccnt_init();
641 #error Specify the address of the console UART with the CONSADDR option.
644 #define CONSPEED 115200
647 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
650 static const bus_addr_t consaddr
= CONSADDR
;
651 static const int conspeed
= CONSPEED
;
652 static const int conmode
= CONMODE
;
657 bus_space_handle_t bh
;
658 static int consinit_called
= 0;
660 if (consinit_called
!= 0)
667 if (bus_space_map(&omap_a4x_bs_tag
, consaddr
, OMAP_COM_SIZE
, 0, &bh
))
668 panic("Serial console can not be mapped.");
670 if (comcnattach(&omap_a4x_bs_tag
, consaddr
, conspeed
,
671 OMAP_COM_FREQ
, COM_TYPE_NORMAL
, conmode
))
672 panic("Serial console can not be initialized.");
674 bus_space_unmap(&omap_a4x_bs_tag
, bh
, OMAP_COM_SIZE
);
682 #error Specify the address of the kgdb UART with the KGDB_DEVADDR option.
685 #define KGDB_DEVRATE 115200
689 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
691 static const vaddr_t comkgdbaddr
= KGDB_DEVADDR
;
692 static const int comkgdbspeed
= KGDB_DEVRATE
;
693 static const int comkgdbmode
= KGDB_DEVMODE
;
696 static kgdb_port_init(void)
698 static int kgdbsinit_called
= 0;
700 if (kgdbsinit_called
!= 0)
703 kgdbsinit_called
= 1;
705 bus_space_handle_t bh
;
706 if (bus_space_map(&omap_a4x_bs_tag
, comkgdbaddr
, OMAP_COM_SIZE
, 0, &bh
))
707 panic("kgdb port can not be mapped.");
709 if (com_kgdb_attach(&omap_a4x_bs_tag
, comkgdbaddr
, comkgdbspeed
,
710 OMAP_COM_FREQ
, COM_TYPE_NORMAL
, comkgdbmode
))
711 panic("KGDB uart can not be initialized.");
713 bus_space_unmap(&omap_a4x_bs_tag
, bh
, OMAP_COM_SIZE
);
718 setup_real_page_tables(void)
721 * We need to allocate some fixed page tables to get the kernel going.
723 * We are going to allocate our bootstrap pages from the beginning of
724 * the free space that we just calculated. We allocate one page
725 * directory and a number of page tables and store the physical
726 * addresses in the kernel_pt_table array.
728 * The kernel page directory must be on a 16K boundary. The page
729 * tables must be on 4K boundaries. What we do is allocate the
730 * page directory on the first 16K boundary that we encounter, and
731 * the page tables on 4K boundaries otherwise. Since we allocate
732 * at least 3 L2 page tables, we are guaranteed to encounter at
733 * least one 16K aligned region.
736 #ifdef VERBOSE_INIT_ARM
737 printf("Allocating page tables\n");
741 * Define a macro to simplify memory allocation. As we allocate the
742 * memory, make sure that we don't walk over our temporary first level
745 #define valloc_pages(var, np) \
746 (var).pv_pa = physical_freestart; \
747 physical_freestart += ((np) * PAGE_SIZE); \
748 if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \
749 panic("initarm: out of memory"); \
750 free_pages -= (np); \
751 (var).pv_va = KERN_PHYSTOV((var).pv_pa); \
752 memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
757 kernel_l1pt
.pv_pa
= 0;
758 kernel_l1pt
.pv_va
= 0;
759 printf("%s: physical_freestart %#lx\n", __func__
, physical_freestart
);
760 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
761 /* Are we 16KB aligned for an L1 ? */
762 if ((physical_freestart
& (L1_TABLE_SIZE
- 1)) == 0
763 && kernel_l1pt
.pv_pa
== 0) {
764 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
766 valloc_pages(kernel_pt_table
[pt_index
],
767 L2_TABLE_SIZE
/ PAGE_SIZE
);
772 printf("%s: kernel_l1pt: %#lx:%#lx\n", __func__
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
);
773 printf("%s: kernel_pt_table:\n", __func__
);
774 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
775 printf("\t%#lx:%#lx\n", kernel_pt_table
[pt_index
].pv_va
, kernel_pt_table
[pt_index
].pv_pa
);
779 /* This should never be able to happen but better confirm that. */
780 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
781 panic("initarm: Failed to align the kernel page directory");
784 * Allocate a page for the system page mapped to V0x00000000
785 * This page will just contain the system vectors and can be
786 * shared by all processes.
788 valloc_pages(systempage
, 1);
789 systempage
.pv_va
= ARM_VECTORS_HIGH
;
791 /* Allocate stacks for all modes */
792 valloc_pages(fiqstack
, FIQ_STACK_SIZE
);
793 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
794 valloc_pages(abtstack
, ABT_STACK_SIZE
);
795 valloc_pages(undstack
, UND_STACK_SIZE
);
796 valloc_pages(kernelstack
, UPAGES
);
798 /* Allocate the message buffer. */
800 int msgbuf_pgs
= round_page(MSGBUFSIZE
) / PAGE_SIZE
;
801 valloc_pages(msgbuf
, msgbuf_pgs
);
802 msgbufphys
= msgbuf
.pv_pa
;
805 * Ok we have allocated physical pages for the primary kernel
809 #ifdef VERBOSE_INIT_ARM
810 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt
.pv_pa
);
814 * Now we start construction of the L1 page table
815 * We start by mapping the L2 page tables into the L1.
816 * This means that we can replace L1 mappings later on if necessary
818 vaddr_t l1_va
= kernel_l1pt
.pv_va
;
819 paddr_t l1_pa
= kernel_l1pt
.pv_pa
;
821 /* Map the L2 pages tables in the L1 page table */
822 pmap_link_l2pt(l1_va
, ARM_VECTORS_HIGH
& ~(0x00400000 - 1),
823 &kernel_pt_table
[KERNEL_PT_SYS
]);
824 for (loop
= 0; loop
< KERNEL_PT_KERNEL_NUM
; loop
++)
825 pmap_link_l2pt(l1_va
, KERNEL_BASE
+ loop
* 0x00400000,
826 &kernel_pt_table
[KERNEL_PT_KERNEL
+ loop
]);
827 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; loop
++)
828 pmap_link_l2pt(l1_va
, KERNEL_VM_BASE
+ loop
* 0x00400000,
829 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
831 /* update the top of the kernel VM */
833 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
835 #ifdef VERBOSE_INIT_ARM
836 printf("Mapping kernel\n");
839 /* Now we fill in the L2 pagetable for the kernel static code/data */
840 #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
841 size_t textsize
= round_L_page(etext
- KERNEL_BASE_phys
);
842 size_t totalsize
= round_L_page(_end
- KERNEL_BASE_phys
);
843 /* offset of kernel in RAM */
846 /* Map text section read-only. */
847 offset
+= pmap_map_chunk(l1_va
, physical_start
+ offset
,
848 physical_start
+ offset
, textsize
,
849 VM_PROT_READ
|VM_PROT_EXECUTE
, PTE_CACHE
);
850 /* Map data and bss sections read-write. */
851 offset
+= pmap_map_chunk(l1_va
, physical_start
+ offset
,
852 physical_start
+ offset
, totalsize
- textsize
,
853 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
855 #ifdef VERBOSE_INIT_ARM
856 printf("Constructing L2 page tables\n");
859 /* Map the stack pages */
860 pmap_map_chunk(l1_va
, fiqstack
.pv_va
, fiqstack
.pv_pa
,
861 FIQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
862 pmap_map_chunk(l1_va
, irqstack
.pv_va
, irqstack
.pv_pa
,
863 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
864 pmap_map_chunk(l1_va
, abtstack
.pv_va
, abtstack
.pv_pa
,
865 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
866 pmap_map_chunk(l1_va
, undstack
.pv_va
, undstack
.pv_pa
,
867 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
868 pmap_map_chunk(l1_va
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
869 UPAGES
* PAGE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_CACHE
);
871 pmap_map_chunk(l1_va
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
872 L1_TABLE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_PAGETABLE
);
874 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
875 pmap_map_chunk(l1_va
, kernel_pt_table
[loop
].pv_va
,
876 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
877 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
880 /* Map the vector page. */
881 pmap_map_entry(l1_va
, ARM_VECTORS_HIGH
, systempage
.pv_pa
,
882 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
885 * Map integrated peripherals at same address in first level page
886 * table so that we can continue to use console.
888 pmap_devmap_bootstrap(l1_va
, devmap
);
891 #ifdef VERBOSE_INIT_ARM
892 /* Tell the user about where all the bits and pieces live. */
893 printf("%22s Physical Virtual Num\n", " ");
894 printf("%22s Starting Ending Starting Ending Pages\n", " ");
896 static const char mem_fmt
[] =
897 "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
898 static const char mem_fmt_nov
[] =
899 "%20s: 0x%08lx 0x%08lx %d\n";
901 printf(mem_fmt
, "SDRAM", physical_start
, physical_end
-1,
902 KERN_PHYSTOV(physical_start
), KERN_PHYSTOV(physical_end
-1),
904 printf(mem_fmt
, "text section",
905 KERN_VTOPHYS(physical_start
), KERN_VTOPHYS(etext
-1),
906 (vaddr_t
)KERNEL_BASE_phys
, (vaddr_t
)etext
-1,
907 (int)(textsize
/ PAGE_SIZE
));
908 printf(mem_fmt
, "data section",
909 KERN_VTOPHYS(__data_start
), KERN_VTOPHYS(_edata
),
910 (vaddr_t
)__data_start
, (vaddr_t
)_edata
,
911 (int)((round_page((vaddr_t
)_edata
)
912 - trunc_page((vaddr_t
)__data_start
)) / PAGE_SIZE
));
913 printf(mem_fmt
, "bss section",
914 KERN_VTOPHYS(__bss_start
), KERN_VTOPHYS(__bss_end__
),
915 (vaddr_t
)__bss_start
, (vaddr_t
)__bss_end__
,
916 (int)((round_page((vaddr_t
)__bss_end__
)
917 - trunc_page((vaddr_t
)__bss_start
)) / PAGE_SIZE
));
918 printf(mem_fmt
, "L1 page directory",
919 kernel_l1pt
.pv_pa
, kernel_l1pt
.pv_pa
+ L1_TABLE_SIZE
- 1,
920 kernel_l1pt
.pv_va
, kernel_l1pt
.pv_va
+ L1_TABLE_SIZE
- 1,
921 L1_TABLE_SIZE
/ PAGE_SIZE
);
922 printf(mem_fmt
, "Exception Vectors",
923 systempage
.pv_pa
, systempage
.pv_pa
+ PAGE_SIZE
- 1,
924 (vaddr_t
)ARM_VECTORS_HIGH
, (vaddr_t
)ARM_VECTORS_HIGH
+ PAGE_SIZE
- 1,
926 printf(mem_fmt
, "FIQ stack",
927 fiqstack
.pv_pa
, fiqstack
.pv_pa
+ (FIQ_STACK_SIZE
* PAGE_SIZE
) - 1,
928 fiqstack
.pv_va
, fiqstack
.pv_va
+ (FIQ_STACK_SIZE
* PAGE_SIZE
) - 1,
930 printf(mem_fmt
, "IRQ stack",
931 irqstack
.pv_pa
, irqstack
.pv_pa
+ (IRQ_STACK_SIZE
* PAGE_SIZE
) - 1,
932 irqstack
.pv_va
, irqstack
.pv_va
+ (IRQ_STACK_SIZE
* PAGE_SIZE
) - 1,
934 printf(mem_fmt
, "ABT stack",
935 abtstack
.pv_pa
, abtstack
.pv_pa
+ (ABT_STACK_SIZE
* PAGE_SIZE
) - 1,
936 abtstack
.pv_va
, abtstack
.pv_va
+ (ABT_STACK_SIZE
* PAGE_SIZE
) - 1,
938 printf(mem_fmt
, "UND stack",
939 undstack
.pv_pa
, undstack
.pv_pa
+ (UND_STACK_SIZE
* PAGE_SIZE
) - 1,
940 undstack
.pv_va
, undstack
.pv_va
+ (UND_STACK_SIZE
* PAGE_SIZE
) - 1,
942 printf(mem_fmt
, "SVC stack",
943 kernelstack
.pv_pa
, kernelstack
.pv_pa
+ (UPAGES
* PAGE_SIZE
) - 1,
944 kernelstack
.pv_va
, kernelstack
.pv_va
+ (UPAGES
* PAGE_SIZE
) - 1,
946 printf(mem_fmt_nov
, "Message Buffer",
947 msgbufphys
, msgbufphys
+ msgbuf_pgs
* PAGE_SIZE
- 1, msgbuf_pgs
);
948 printf(mem_fmt
, "Free Memory", physical_freestart
, physical_freeend
-1,
949 KERN_PHYSTOV(physical_freestart
), KERN_PHYSTOV(physical_freeend
-1),
954 * Now we have the real page tables in place so we can switch to them.
955 * Once this is done we will be running with the REAL kernel page
960 #ifdef VERBOSE_INIT_ARM
961 printf("switching to new L1 page table @%#lx...", l1_pa
);
964 cpu_domains((DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2)) | DOMAIN_CLIENT
);
967 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));
969 #ifdef VERBOSE_INIT_ARM