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/beagle/beagle.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))
257 static void kgdb_port_init(void);
260 static void setup_real_page_tables(void);
261 static void init_clocks(void);
263 bs_protos(bs_notimpl
);
267 #include <dev/ic/comreg.h>
268 #include <dev/ic/comvar.h>
272 * void cpu_reboot(int howto, char *bootstr)
276 * Deal with any syncing, unmounting, dumping and shutdown hooks,
277 * then reset the CPU.
280 cpu_reboot(int howto
, char *bootstr
)
284 printf("boot: howto=%08x curproc=%p\n", howto
, curproc
);
288 * If we are still cold then hit the air brakes
289 * and crash to earth fast
293 pmf_system_shutdown(boothowto
);
294 printf("The operating system has halted.\n");
295 printf("Please press any key to reboot.\n\n");
297 printf("rebooting...\n");
305 /* Disable console buffering */
309 * If RB_NOSYNC was not specified sync the discs.
310 * Note: Unless cold is set to 1 here, syslogd will die during the
311 * unmount. It looks like syslogd is getting woken up only to find
312 * that it cannot page part of the binary in as the filesystem has
315 if (!(howto
& RB_NOSYNC
))
318 /* Say NO to interrupts */
321 /* Do a dump if requested. */
322 if ((howto
& (RB_DUMP
| RB_HALT
)) == RB_DUMP
)
325 /* Run any shutdown hooks */
328 pmf_system_shutdown(boothowto
);
330 /* Make sure IRQ's are disabled */
333 if (howto
& RB_HALT
) {
334 printf("The operating system has halted.\n");
335 printf("Please press any key to reboot.\n\n");
339 printf("rebooting...\n");
348 * Static device mappings. These peripheral registers are mapped at
349 * fixed virtual addresses very early in initarm() so that we can use
350 * them while booting the kernel, and stay at the same address
351 * throughout whole kernel's life time.
353 * We use this table twice; once with bootstrap page table, and once
354 * with kernel's page table which we build up in initarm().
356 * Since we map these registers into the bootstrap page table using
357 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
358 * registers segment-aligned and segment-rounded in order to avoid
359 * using the 2nd page tables.
362 #define _A(a) ((a) & ~L1_S_OFFSET)
363 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
365 static const struct pmap_devmap devmap
[] = {
368 * Map the first 1MB of L4 Core area
369 * this gets us the ICU, I2C, USB, GPT[10-11], MMC, McSPI
370 * UART[12], clock manager, sDMA, ...
372 .pd_va
= _A(OMAP3530_L4_CORE_VBASE
),
373 .pd_pa
= _A(OMAP3530_L4_CORE_BASE
),
374 .pd_size
= _S(1 << 20),
375 .pd_prot
= VM_PROT_READ
|VM_PROT_WRITE
,
376 .pd_cache
= PTE_NOCACHE
380 * Map the all 1MB of the L4 Core area
381 * this gets us the console UART3, GPT[2-9], WDT1,
384 .pd_va
= _A(OMAP3530_L4_PERIPHERAL_VBASE
),
385 .pd_pa
= _A(OMAP3530_L4_PERIPHERAL_BASE
),
386 .pd_size
= _S(1 << 20),
387 .pd_prot
= VM_PROT_READ
|VM_PROT_WRITE
,
388 .pd_cache
= PTE_NOCACHE
392 * Map all 256KB of the L4 Wakeup area
393 * this gets us GPIO1, WDT2, GPT1, 32K and power/reset regs
395 .pd_va
= _A(OMAP3530_L4_WAKEUP_VBASE
),
396 .pd_pa
= _A(OMAP3530_L4_WAKEUP_BASE
),
397 .pd_size
= _S(1 << 18),
398 .pd_prot
= VM_PROT_READ
|VM_PROT_WRITE
,
399 .pd_cache
= PTE_NOCACHE
408 static void beagle_db_trap(int where
)
411 static int oldwatchdogstate
;
414 oldwatchdogstate
= omapwdt32k_enable(0);
416 omapwdt32k_enable(oldwatchdogstate
);
422 void beagle_putchar(char c
);
424 beagle_putchar(char c
)
426 unsigned char *com0addr
= (char *)CONSADDR_VA
;
429 while ((com0addr
[5 * 4] & 0x20) == 0)
435 while ((com0addr
[5 * 4] & 0x20) == 0)
443 * Initial entry point on startup. This gets called before main() is
445 * It should be responsible for setting up everything that must be
446 * in place when main is called.
448 * Taking a copy of the boot configuration structure.
449 * Initialising the physical console so characters can be printed.
450 * Setting up page tables for the kernel
451 * Relocating the kernel to the bottom of physical memory
460 * When we enter here, we are using a temporary first level
461 * translation table with section entries in it to cover the OBIO
462 * peripherals and SDRAM. The temporary first level translation table
463 * is at the end of SDRAM.
466 /* Heads up ... Setup the CPU / MMU / TLB functions. */
468 panic("cpu not recognized!");
472 /* The console is going to try to map things. Give pmap a devmap. */
473 pmap_devmap_register(devmap
);
482 #ifdef VERBOSE_INIT_ARM
483 /* Talk to the user */
484 printf("\nNetBSD/evbarm (beagle) booting ...\n");
488 char mi_bootargs
[] = BOOT_ARGS
;
489 parse_mi_bootargs(mi_bootargs
);
492 #ifdef VERBOSE_INIT_ARM
493 printf("initarm: Configuring system ...\n");
497 * Set up the variables that define the availability of physical
500 physical_start
= KERNEL_BASE_PHYS
;
501 #define MEMSIZE_BYTES (MEMSIZE * 1024 * 1024)
502 physical_end
= (physical_start
& ~(0x400000-1)) + MEMSIZE_BYTES
;
503 physmem
= (physical_end
- physical_start
) / PAGE_SIZE
;
505 /* Fake bootconfig structure for the benefit of pmap.c. */
506 bootconfig
.dramblocks
= 1;
507 bootconfig
.dram
[0].address
= physical_start
;
508 bootconfig
.dram
[0].pages
= physmem
;
511 * Our kernel is at the beginning of memory, so set our free space to
512 * all the memory after the kernel.
514 physical_freestart
= KERN_VTOPHYS(round_page((vaddr_t
) _end
));
515 physical_freeend
= physical_end
;
516 free_pages
= (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
519 * This is going to do all the hard work of setting up the first and
520 * and second level page tables. Pages of memory will be allocated
521 * and mapped for other structures that are required for system
522 * operation. When it returns, physical_freestart and free_pages will
523 * have been updated to reflect the allocations that were made. In
524 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack,
525 * abtstack, undstack, kernelstack, msgbufphys will be set to point to
526 * the memory that was allocated for them.
528 setup_real_page_tables();
531 * Moved from cpu_startup() as data_abort_handler() references
532 * this during uvm init.
534 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
536 #ifdef VERBOSE_INIT_ARM
537 printf("bootstrap done.\n");
540 arm32_vector_init(ARM_VECTORS_HIGH
, ARM_VEC_ALL
);
543 * Pages were allocated during the secondary bootstrap for the
544 * stacks for different CPU modes.
545 * We must now set the r13 registers in the different CPU modes to
546 * point to these stacks.
547 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
548 * of the stack memory.
550 #ifdef VERBOSE_INIT_ARM
551 printf("init subsystems: stacks ");
554 set_stackptr(PSR_FIQ32_MODE
, fiqstack
.pv_va
+ FIQ_STACK_SIZE
* PAGE_SIZE
);
555 set_stackptr(PSR_IRQ32_MODE
, irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
556 set_stackptr(PSR_ABT32_MODE
, abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
557 set_stackptr(PSR_UND32_MODE
, undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
560 * Well we should set a data abort handler.
561 * Once things get going this will change as we will need a proper
563 * Until then we will use a handler that just panics but tells us
565 * Initialisation of the vectors will just panic on a data abort.
566 * This just fills in a slightly better one.
568 #ifdef VERBOSE_INIT_ARM
571 data_abort_handler_address
= (u_int
)data_abort_handler
;
572 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
573 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
575 /* Initialise the undefined instruction handlers */
576 #ifdef VERBOSE_INIT_ARM
577 printf("undefined ");
581 /* Load memory into UVM. */
582 #ifdef VERBOSE_INIT_ARM
585 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
586 uvm_page_physload(atop(physical_freestart
), atop(physical_freeend
),
587 atop(physical_freestart
), atop(physical_freeend
),
588 VM_FREELIST_DEFAULT
);
590 /* Boot strap pmap telling it where the kernel page table is */
591 #ifdef VERBOSE_INIT_ARM
594 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
596 #ifdef VERBOSE_INIT_ARM
601 /* Initialise ipkdb */
603 if (boothowto
& RB_KDB
)
608 if (boothowto
& RB_KDB
) {
615 db_trap_callback
= beagle_db_trap
;
618 /* Firmware doesn't load symbols. */
619 ddb_init(0, NULL
, NULL
);
621 if (boothowto
& RB_KDB
)
624 printf("initarm done.\n");
626 /* We return the new stack pointer address */
627 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
630 void arm11_pmc_ccnt_init(void);
636 static volatile uint32_t * const clksel_reg
= (volatile uint32_t *) (OMAP3530_L4_WAKEUP_VBASE
+ OMAP2_CM_BASE
+ OMAP2_CM_CLKSEL_MPU
- OMAP3530_L4_WAKEUP_BASE
);
641 if (v
!= OMAP3530_CM_CLKSEL_MPU_FULLSPEED
) {
642 printf("Changed CPU speed from half (%d) ", v
);
643 *clksel_reg
= OMAP3530_CM_CLKSEL_MPU_FULLSPEED
;
644 printf("to full speed.\n");
648 arm11_pmc_ccnt_init();
652 #error Specify the address of the console UART with the CONSADDR option.
655 #define CONSPEED 115200
658 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
661 static const bus_addr_t consaddr
= CONSADDR
;
662 static const int conspeed
= CONSPEED
;
663 static const int conmode
= CONMODE
;
668 bus_space_handle_t bh
;
669 static int consinit_called
= 0;
671 if (consinit_called
!= 0)
678 if (bus_space_map(&omap_a4x_bs_tag
, consaddr
, OMAP_COM_SIZE
, 0, &bh
))
679 panic("Serial console can not be mapped.");
681 if (comcnattach(&omap_a4x_bs_tag
, consaddr
, conspeed
,
682 OMAP_COM_FREQ
, COM_TYPE_NORMAL
, conmode
))
683 panic("Serial console can not be initialized.");
685 bus_space_unmap(&omap_a4x_bs_tag
, bh
, OMAP_COM_SIZE
);
693 #error Specify the address of the kgdb UART with the KGDB_DEVADDR option.
696 #define KGDB_DEVRATE 115200
700 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
702 static const vaddr_t comkgdbaddr
= KGDB_DEVADDR
;
703 static const int comkgdbspeed
= KGDB_DEVRATE
;
704 static const int comkgdbmode
= KGDB_DEVMODE
;
707 static kgdb_port_init(void)
709 static int kgdbsinit_called
= 0;
711 if (kgdbsinit_called
!= 0)
714 kgdbsinit_called
= 1;
716 bus_space_handle_t bh
;
717 if (bus_space_map(&omap_a4x_bs_tag
, comkgdbaddr
, OMAP_COM_SIZE
, 0, &bh
))
718 panic("kgdb port can not be mapped.");
720 if (com_kgdb_attach(&omap_a4x_bs_tag
, comkgdbaddr
, comkgdbspeed
,
721 OMAP_COM_FREQ
, COM_TYPE_NORMAL
, comkgdbmode
))
722 panic("KGDB uart can not be initialized.");
724 bus_space_unmap(&omap_a4x_bs_tag
, bh
, OMAP_COM_SIZE
);
729 setup_real_page_tables(void)
732 * We need to allocate some fixed page tables to get the kernel going.
734 * We are going to allocate our bootstrap pages from the beginning of
735 * the free space that we just calculated. We allocate one page
736 * directory and a number of page tables and store the physical
737 * addresses in the kernel_pt_table array.
739 * The kernel page directory must be on a 16K boundary. The page
740 * tables must be on 4K boundaries. What we do is allocate the
741 * page directory on the first 16K boundary that we encounter, and
742 * the page tables on 4K boundaries otherwise. Since we allocate
743 * at least 3 L2 page tables, we are guaranteed to encounter at
744 * least one 16K aligned region.
747 #ifdef VERBOSE_INIT_ARM
748 printf("Allocating page tables\n");
752 * Define a macro to simplify memory allocation. As we allocate the
753 * memory, make sure that we don't walk over our temporary first level
756 #define valloc_pages(var, np) \
757 (var).pv_pa = physical_freestart; \
758 physical_freestart += ((np) * PAGE_SIZE); \
759 if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \
760 panic("initarm: out of memory"); \
761 free_pages -= (np); \
762 (var).pv_va = KERN_PHYSTOV((var).pv_pa); \
763 memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
768 kernel_l1pt
.pv_pa
= 0;
769 kernel_l1pt
.pv_va
= 0;
770 printf("%s: physical_freestart %#lx\n", __func__
, physical_freestart
);
771 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
772 /* Are we 16KB aligned for an L1 ? */
773 if ((physical_freestart
& (L1_TABLE_SIZE
- 1)) == 0
774 && kernel_l1pt
.pv_pa
== 0) {
775 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
777 valloc_pages(kernel_pt_table
[pt_index
],
778 L2_TABLE_SIZE
/ PAGE_SIZE
);
783 printf("%s: kernel_l1pt: %#lx:%#lx\n", __func__
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
);
784 printf("%s: kernel_pt_table:\n", __func__
);
785 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
786 printf("\t%#lx:%#lx\n", kernel_pt_table
[pt_index
].pv_va
, kernel_pt_table
[pt_index
].pv_pa
);
790 /* This should never be able to happen but better confirm that. */
791 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
792 panic("initarm: Failed to align the kernel page directory");
795 * Allocate a page for the system page mapped to V0x00000000
796 * This page will just contain the system vectors and can be
797 * shared by all processes.
799 valloc_pages(systempage
, 1);
800 systempage
.pv_va
= ARM_VECTORS_HIGH
;
802 /* Allocate stacks for all modes */
803 valloc_pages(fiqstack
, FIQ_STACK_SIZE
);
804 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
805 valloc_pages(abtstack
, ABT_STACK_SIZE
);
806 valloc_pages(undstack
, UND_STACK_SIZE
);
807 valloc_pages(kernelstack
, UPAGES
);
809 /* Allocate the message buffer. */
811 int msgbuf_pgs
= round_page(MSGBUFSIZE
) / PAGE_SIZE
;
812 valloc_pages(msgbuf
, msgbuf_pgs
);
813 msgbufphys
= msgbuf
.pv_pa
;
816 * Ok we have allocated physical pages for the primary kernel
820 #ifdef VERBOSE_INIT_ARM
821 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt
.pv_pa
);
825 * Now we start construction of the L1 page table
826 * We start by mapping the L2 page tables into the L1.
827 * This means that we can replace L1 mappings later on if necessary
829 vaddr_t l1_va
= kernel_l1pt
.pv_va
;
830 paddr_t l1_pa
= kernel_l1pt
.pv_pa
;
832 /* Map the L2 pages tables in the L1 page table */
833 pmap_link_l2pt(l1_va
, ARM_VECTORS_HIGH
& ~(0x00400000 - 1),
834 &kernel_pt_table
[KERNEL_PT_SYS
]);
835 for (loop
= 0; loop
< KERNEL_PT_KERNEL_NUM
; loop
++)
836 pmap_link_l2pt(l1_va
, KERNEL_BASE
+ loop
* 0x00400000,
837 &kernel_pt_table
[KERNEL_PT_KERNEL
+ loop
]);
838 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; loop
++)
839 pmap_link_l2pt(l1_va
, KERNEL_VM_BASE
+ loop
* 0x00400000,
840 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
842 /* update the top of the kernel VM */
844 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
846 #ifdef VERBOSE_INIT_ARM
847 printf("Mapping kernel\n");
850 /* Now we fill in the L2 pagetable for the kernel static code/data */
851 #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
852 size_t textsize
= round_L_page(etext
- KERNEL_BASE_phys
);
853 size_t totalsize
= round_L_page(_end
- KERNEL_BASE_phys
);
854 /* offset of kernel in RAM */
857 /* Map text section read-only. */
858 offset
+= pmap_map_chunk(l1_va
, physical_start
+ offset
,
859 physical_start
+ offset
, textsize
,
860 VM_PROT_READ
|VM_PROT_EXECUTE
, PTE_CACHE
);
861 /* Map data and bss sections read-write. */
862 offset
+= pmap_map_chunk(l1_va
, physical_start
+ offset
,
863 physical_start
+ offset
, totalsize
- textsize
,
864 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
866 #ifdef VERBOSE_INIT_ARM
867 printf("Constructing L2 page tables\n");
870 /* Map the stack pages */
871 pmap_map_chunk(l1_va
, fiqstack
.pv_va
, fiqstack
.pv_pa
,
872 FIQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
873 pmap_map_chunk(l1_va
, irqstack
.pv_va
, irqstack
.pv_pa
,
874 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
875 pmap_map_chunk(l1_va
, abtstack
.pv_va
, abtstack
.pv_pa
,
876 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
877 pmap_map_chunk(l1_va
, undstack
.pv_va
, undstack
.pv_pa
,
878 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
879 pmap_map_chunk(l1_va
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
880 UPAGES
* PAGE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_CACHE
);
882 pmap_map_chunk(l1_va
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
883 L1_TABLE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_PAGETABLE
);
885 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
886 pmap_map_chunk(l1_va
, kernel_pt_table
[loop
].pv_va
,
887 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
888 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
891 /* Map the vector page. */
892 pmap_map_entry(l1_va
, ARM_VECTORS_HIGH
, systempage
.pv_pa
,
893 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
896 * Map integrated peripherals at same address in first level page
897 * table so that we can continue to use console.
899 pmap_devmap_bootstrap(l1_va
, devmap
);
902 #ifdef VERBOSE_INIT_ARM
903 /* Tell the user about where all the bits and pieces live. */
904 printf("%22s Physical Virtual Num\n", " ");
905 printf("%22s Starting Ending Starting Ending Pages\n", " ");
907 static const char mem_fmt
[] =
908 "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
909 static const char mem_fmt_nov
[] =
910 "%20s: 0x%08lx 0x%08lx %d\n";
912 printf(mem_fmt
, "SDRAM", physical_start
, physical_end
-1,
913 KERN_PHYSTOV(physical_start
), KERN_PHYSTOV(physical_end
-1),
915 printf(mem_fmt
, "text section",
916 KERN_VTOPHYS(physical_start
), KERN_VTOPHYS(etext
-1),
917 (vaddr_t
)KERNEL_BASE_phys
, (vaddr_t
)etext
-1,
918 (int)(textsize
/ PAGE_SIZE
));
919 printf(mem_fmt
, "data section",
920 KERN_VTOPHYS(__data_start
), KERN_VTOPHYS(_edata
),
921 (vaddr_t
)__data_start
, (vaddr_t
)_edata
,
922 (int)((round_page((vaddr_t
)_edata
)
923 - trunc_page((vaddr_t
)__data_start
)) / PAGE_SIZE
));
924 printf(mem_fmt
, "bss section",
925 KERN_VTOPHYS(__bss_start
), KERN_VTOPHYS(__bss_end__
),
926 (vaddr_t
)__bss_start
, (vaddr_t
)__bss_end__
,
927 (int)((round_page((vaddr_t
)__bss_end__
)
928 - trunc_page((vaddr_t
)__bss_start
)) / PAGE_SIZE
));
929 printf(mem_fmt
, "L1 page directory",
930 kernel_l1pt
.pv_pa
, kernel_l1pt
.pv_pa
+ L1_TABLE_SIZE
- 1,
931 kernel_l1pt
.pv_va
, kernel_l1pt
.pv_va
+ L1_TABLE_SIZE
- 1,
932 L1_TABLE_SIZE
/ PAGE_SIZE
);
933 printf(mem_fmt
, "Exception Vectors",
934 systempage
.pv_pa
, systempage
.pv_pa
+ PAGE_SIZE
- 1,
935 (vaddr_t
)ARM_VECTORS_HIGH
, (vaddr_t
)ARM_VECTORS_HIGH
+ PAGE_SIZE
- 1,
937 printf(mem_fmt
, "FIQ stack",
938 fiqstack
.pv_pa
, fiqstack
.pv_pa
+ (FIQ_STACK_SIZE
* PAGE_SIZE
) - 1,
939 fiqstack
.pv_va
, fiqstack
.pv_va
+ (FIQ_STACK_SIZE
* PAGE_SIZE
) - 1,
941 printf(mem_fmt
, "IRQ stack",
942 irqstack
.pv_pa
, irqstack
.pv_pa
+ (IRQ_STACK_SIZE
* PAGE_SIZE
) - 1,
943 irqstack
.pv_va
, irqstack
.pv_va
+ (IRQ_STACK_SIZE
* PAGE_SIZE
) - 1,
945 printf(mem_fmt
, "ABT stack",
946 abtstack
.pv_pa
, abtstack
.pv_pa
+ (ABT_STACK_SIZE
* PAGE_SIZE
) - 1,
947 abtstack
.pv_va
, abtstack
.pv_va
+ (ABT_STACK_SIZE
* PAGE_SIZE
) - 1,
949 printf(mem_fmt
, "UND stack",
950 undstack
.pv_pa
, undstack
.pv_pa
+ (UND_STACK_SIZE
* PAGE_SIZE
) - 1,
951 undstack
.pv_va
, undstack
.pv_va
+ (UND_STACK_SIZE
* PAGE_SIZE
) - 1,
953 printf(mem_fmt
, "SVC stack",
954 kernelstack
.pv_pa
, kernelstack
.pv_pa
+ (UPAGES
* PAGE_SIZE
) - 1,
955 kernelstack
.pv_va
, kernelstack
.pv_va
+ (UPAGES
* PAGE_SIZE
) - 1,
957 printf(mem_fmt_nov
, "Message Buffer",
958 msgbufphys
, msgbufphys
+ msgbuf_pgs
* PAGE_SIZE
- 1, msgbuf_pgs
);
959 printf(mem_fmt
, "Free Memory", physical_freestart
, physical_freeend
-1,
960 KERN_PHYSTOV(physical_freestart
), KERN_PHYSTOV(physical_freeend
-1),
965 * Now we have the real page tables in place so we can switch to them.
966 * Once this is done we will be running with the REAL kernel page
971 #ifdef VERBOSE_INIT_ARM
972 printf("switching to new L1 page table @%#lx...", l1_pa
);
975 cpu_domains((DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2)) | DOMAIN_CLIENT
);
978 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));
980 #ifdef VERBOSE_INIT_ARM