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
101 #include <sys/cdefs.h>
102 __KERNEL_RCSID(0, "$NetBSD$");
104 #include "opt_machdep.h"
106 #include "opt_kgdb.h"
111 #include <sys/param.h>
112 #include <sys/device.h>
113 #include <sys/systm.h>
114 #include <sys/kernel.h>
115 #include <sys/exec.h>
116 #include <sys/proc.h>
117 #include <sys/msgbuf.h>
118 #include <sys/reboot.h>
119 #include <sys/termios.h>
120 #include <sys/ksyms.h>
122 #include <uvm/uvm_extern.h>
124 #include <sys/conf.h>
125 #include <dev/cons.h>
128 #include <machine/db_machdep.h>
129 #include <ddb/db_sym.h>
130 #include <ddb/db_extern.h>
132 #include <sys/kgdb.h>
135 #include <machine/bootconfig.h>
136 #include <machine/bus.h>
137 #include <machine/cpu.h>
138 #include <machine/frame.h>
139 #include <arm/undefined.h>
141 #include <arm/arm32/machdep.h>
143 #include <arm/omap/omap_reg.h>
144 #include <arm/omap/omap_tipb.h>
145 #include <arm/omap/omap_com.h>
148 * The range 0xc1000000 - 0xccffffff is available for kernel VM space.
150 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
151 #define KERNEL_VM_SIZE 0x0C000000
155 * Address to call from cpu_reset() to reset the machine.
156 * This is machine architecture dependant as it varies depending
157 * on where the ROM appears when you turn the MMU off.
160 u_int cpu_reset_address
= 0;
162 /* Define various stack sizes in pages */
163 #define IRQ_STACK_SIZE 1
164 #define ABT_STACK_SIZE 1
165 #define UND_STACK_SIZE 1
167 BootConfig bootconfig
; /* Boot config storage */
168 char *boot_args
= NULL
;
169 char *boot_file
= NULL
;
171 /* Physical address of the beginning of SDRAM. */
172 paddr_t physical_start
;
173 /* Physical address of the first byte after the end of SDRAM. */
174 paddr_t physical_end
;
175 /* Number of pages of memory. */
177 /* Same things, but for the free (unused by the kernel) memory. */
178 static paddr_t physical_freestart
, physical_freeend
;
179 static u_int free_pages
;
181 /* Physical and virtual addresses for some global pages */
185 pv_addr_t kernelstack
; /* stack for SVC mode */
187 /* Physical address of the message buffer. */
190 extern u_int data_abort_handler_address
;
191 extern u_int prefetch_abort_handler_address
;
192 extern u_int undefined_handler_address
;
193 extern char KERNEL_BASE_phys
[];
194 extern char etext
[], __data_start
[], _edata
[], __bss_start
[], __bss_end__
[];
197 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
198 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
199 #define KERNEL_PT_KERNEL_NUM 4
200 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
201 /* Page tables for mapping kernel VM */
202 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
203 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
205 pv_addr_t kernel_pt_table
[NUM_KERNEL_PTS
];
208 * Macros to translate between physical and virtual for a subset of the
209 * kernel address space. *Not* for general use.
211 #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
212 #define KERN_VTOPHYS(va) \
213 ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
214 #define KERN_PHYSTOV(pa) \
215 ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
221 static void kgdb_port_init(void);
223 static void setup_real_page_tables(void);
224 static void init_clocks(void);
226 bs_protos(bs_notimpl
);
230 #include <dev/ic/comreg.h>
231 #include <dev/ic/comvar.h>
235 * void cpu_reboot(int howto, char *bootstr)
239 * Deal with any syncing, unmounting, dumping and shutdown hooks,
240 * then reset the CPU.
243 cpu_reboot(int howto
, char *bootstr
)
247 printf("boot: howto=%08x curproc=%p\n", howto
, curproc
);
251 * If we are still cold then hit the air brakes
252 * and crash to earth fast
256 pmf_system_shutdown(boothowto
);
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 the
271 * unmount. It looks like syslogd is getting woken up only to find
272 * that it cannot page part of the binary in as the filesystem has
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
)
285 /* Run any shutdown hooks */
288 pmf_system_shutdown(boothowto
);
290 /* Make sure IRQ's are disabled */
293 if (howto
& RB_HALT
) {
294 printf("The operating system has halted.\n");
295 printf("Please press any key to reboot.\n\n");
299 printf("rebooting...\n");
305 * Static device mappings. These peripheral registers are mapped at
306 * fixed virtual addresses very early in initarm() so that we can use
307 * them while booting the kernel, and stay at the same address
308 * throughout whole kernel's life time.
310 * We use this table twice; once with bootstrap page table, and once
311 * with kernel's page table which we build up in initarm().
313 * Since we map these registers into the bootstrap page table using
314 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
315 * registers segment-aligned and segment-rounded in order to avoid
316 * using the 2nd page tables.
319 #define _A(a) ((a) & ~L1_S_OFFSET)
320 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
322 static const struct pmap_devmap devmap
[] = {
324 /* Map the Texas Instruments Peripheral Bus VA==PA */
325 .pd_va
= _A(OMAP_TIPB_PBASE
),
326 .pd_pa
= _A(OMAP_TIPB_PBASE
),
327 .pd_size
= _S(OMAP_TIPB_SIZE
),
328 .pd_prot
= VM_PROT_READ
|VM_PROT_WRITE
,
329 .pd_cache
= PTE_NOCACHE
340 * Initial entry point on startup. This gets called before main() is
342 * It should be responsible for setting up everything that must be
343 * in place when main is called.
345 * Taking a copy of the boot configuration structure.
346 * Initialising the physical console so characters can be printed.
347 * Setting up page tables for the kernel
348 * Relocating the kernel to the bottom of physical memory
354 * When we enter here, we are using a temporary first level
355 * translation table with section entries in it to cover the TIPB
356 * peripherals and SDRAM. The temporary first level translation table
357 * is at the end of SDRAM.
360 /* Heads up ... Setup the CPU / MMU / TLB functions. */
362 panic("cpu not recognized!");
366 /* The console is going to try to map things. Give pmap a devmap. */
367 pmap_devmap_register(devmap
);
373 #ifdef VERBOSE_INIT_ARM
374 /* Talk to the user */
375 printf("\nNetBSD/evbarm (OSK5912) booting ...\n");
379 char mi_bootargs
[] = BOOT_ARGS
;
380 parse_mi_bootargs(mi_bootargs
);
383 #ifdef VERBOSE_INIT_ARM
384 printf("initarm: Configuring system ...\n");
388 * Set up the variables that define the availability of physical
391 physical_start
= KERNEL_BASE_PHYS
;
392 physical_end
= physical_start
+ MEMSIZE_BYTES
;
393 physmem
= MEMSIZE_BYTES
/ PAGE_SIZE
;
395 /* Fake bootconfig structure for the benefit of pmap.c. */
396 bootconfig
.dramblocks
= 1;
397 bootconfig
.dram
[0].address
= physical_start
;
398 bootconfig
.dram
[0].pages
= physmem
;
401 * Our kernel is at the beginning of memory, so set our free space to
402 * all the memory after the kernel.
404 physical_freestart
= KERN_VTOPHYS(round_page((vaddr_t
) _end
));
405 physical_freeend
= physical_end
;
406 free_pages
= (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
409 * This is going to do all the hard work of setting up the first and
410 * and second level page tables. Pages of memory will be allocated
411 * and mapped for other structures that are required for system
412 * operation. When it returns, physical_freestart and free_pages will
413 * have been updated to reflect the allocations that were made. In
414 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack,
415 * abtstack, undstack, kernelstack, msgbufphys will be set to point to
416 * the memory that was allocated for them.
418 setup_real_page_tables();
421 * Moved from cpu_startup() as data_abort_handler() references
422 * this during uvm init.
424 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
426 #ifdef VERBOSE_INIT_ARM
427 printf("bootstrap done.\n");
430 arm32_vector_init(ARM_VECTORS_LOW
, ARM_VEC_ALL
);
433 * Pages were allocated during the secondary bootstrap for the
434 * stacks for different CPU modes.
435 * We must now set the r13 registers in the different CPU modes to
436 * point to these stacks.
437 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
438 * of the stack memory.
440 #ifdef VERBOSE_INIT_ARM
441 printf("init subsystems: stacks ");
444 set_stackptr(PSR_IRQ32_MODE
, irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
445 set_stackptr(PSR_ABT32_MODE
, abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
446 set_stackptr(PSR_UND32_MODE
, undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
449 * Well we should set a data abort handler.
450 * Once things get going this will change as we will need a proper
452 * Until then we will use a handler that just panics but tells us
454 * Initialisation of the vectors will just panic on a data abort.
455 * This just fills in a slightly better one.
457 #ifdef VERBOSE_INIT_ARM
460 data_abort_handler_address
= (u_int
)data_abort_handler
;
461 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
462 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
464 /* Initialise the undefined instruction handlers */
465 #ifdef VERBOSE_INIT_ARM
466 printf("undefined ");
470 /* Load memory into UVM. */
471 #ifdef VERBOSE_INIT_ARM
474 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
475 uvm_page_physload(atop(physical_freestart
), atop(physical_freeend
),
476 atop(physical_freestart
), atop(physical_freeend
),
477 VM_FREELIST_DEFAULT
);
479 /* Boot strap pmap telling it where the kernel page table is */
480 #ifdef VERBOSE_INIT_ARM
483 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
485 #ifdef VERBOSE_INIT_ARM
490 if (boothowto
& RB_KDB
) {
499 /* Firmware doesn't load symbols. */
500 ddb_init(0, NULL
, NULL
);
502 if (boothowto
& RB_KDB
)
506 /* We return the new stack pointer address */
507 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
513 #define OMAP_MPU_BASE 0xFFFECE00
514 #define ARM_CKCTL 0x00
515 #define ARM_TIMXO (1 << 12)
516 #define ARM_IDLECT1 0x04
517 #define IDLTIM_ARM (1 << 9)
518 #define ARM_IDLECT2 0x08
519 #define EN_TIMCK (1 << 7)
521 #define OMAP_ULPD_BASE 0xFFFE0800
522 #define CAM_CLK_CTRL 0x007C
523 #define SYSTEM_CLK_EN (1 << 2)
525 #define SOFT_REQ_REG 0x34
526 #define SOFT_UART3_DPLL_REQ 11
527 #define SOFT_UART2_DPLL_REQ 10
528 #define SOFT_UART1_DPLL_REQ 9
530 #define SOFT_DISABLE_REQ_REG 0x68
531 #define DIS_UART3_DPLL_REQ 9
532 #define DIS_UART2_DPLL_REQ 8
533 #define DIS_UART1_DPLL_REQ 7
535 /* For now, just hack up the clocking as needed to get things working. */
536 *(volatile uint32_t *)(OMAP_MPU_BASE
+ ARM_IDLECT2
) |= EN_TIMCK
;
537 *(volatile uint32_t *)(OMAP_MPU_BASE
+ ARM_IDLECT1
) &= ~IDLTIM_ARM
;
538 *(volatile uint32_t *)(OMAP_MPU_BASE
+ ARM_CKCTL
) &= ~ARM_TIMXO
;
542 * Note: The SYSTEM_CLK_EN bit of the CAM_CLK_CTRL register must be set
543 * to 1, for GPIO interrupt generation to work.
545 *(volatile uint32_t *)(OMAP_ULPD_BASE
+ CAM_CLK_CTRL
) |= SYSTEM_CLK_EN
;
548 * Issue the software request for the UART clocks. The bootloader probably
549 * already did UART1 but might not have done UART3.
552 *(volatile uint16_t *)(OMAP_ULPD_BASE
+ SOFT_REQ_REG
) |=
553 (1 << SOFT_UART1_DPLL_REQ
) | (1 << SOFT_UART3_DPLL_REQ
);
554 *(volatile uint16_t *)(OMAP_ULPD_BASE
+ SOFT_DISABLE_REQ_REG
) &=
555 ~((1 << DIS_UART1_DPLL_REQ
) | (1 << DIS_UART3_DPLL_REQ
));
560 #error Specify the address of the console UART with the CONSADDR option.
563 #define CONSPEED 115200
566 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
569 static const vaddr_t consaddr
= CONSADDR
;
570 static const int conspeed
= CONSPEED
;
571 static const int conmode
= CONMODE
;
576 static int consinit_called
= 0;
578 if (consinit_called
!= 0)
583 bus_space_handle_t bh
;
584 if (bus_space_map(&omap_a4x_bs_tag
, consaddr
, OMAP_COM_SIZE
, 0, &bh
))
585 panic("Serial console can not be mapped.");
588 * The TRM says the mode should be disabled while dll and dlh are
589 * being changed so we disable before attaching, then enable.
591 bus_space_write_1(&omap_a4x_bs_tag
, bh
,
592 OMAP_COM_MDR1
, OMAP_COM_MDR1_MODE_DISABLE
);
594 if (comcnattach(&omap_a4x_bs_tag
, consaddr
, conspeed
,
595 OMAP_COM_FREQ
, COM_TYPE_NORMAL
, conmode
))
596 panic("Serial console can not be initialized.");
598 bus_space_write_1(&omap_a4x_bs_tag
, bh
,
599 OMAP_COM_MDR1
, OMAP_COM_MDR1_MODE_UART_16X
);
601 bus_space_unmap(&omap_a4x_bs_tag
, bh
, OMAP_COM_SIZE
);
606 #error Specify the address of the kgdb UART with the KGDB_DEVADDR option.
609 #define KGDB_DEVRATE 115200
613 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
615 static const vaddr_t comkgdbaddr
= KGDB_DEVADDR
;
616 static const int comkgdbspeed
= KGDB_DEVRATE
;
617 static const int comkgdbmode
= KGDB_DEVMODE
;
620 static kgdb_port_init(void)
622 static int kgdbsinit_called
= 0;
624 if (kgdbsinit_called
!= 0)
627 kgdbsinit_called
= 1;
629 bus_space_handle_t bh
;
630 if (bus_space_map(&omap_a4x_bs_tag
, comkgdbaddr
, OMAP_COM_SIZE
, 0, &bh
))
631 panic("kgdb port can not be mapped.");
634 * The TRM says the mode should be disabled while dll and dlh are
635 * being changed so we disable before attaching, then enable.
637 bus_space_write_1(&omap_a4x_bs_tag
, bh
,
638 OMAP_COM_MDR1
, OMAP_COM_MDR1_MODE_DISABLE
);
640 if (com_kgdb_attach(&omap_a4x_bs_tag
, comkgdbaddr
, comkgdbspeed
,
641 OMAP_COM_FREQ
, COM_TYPE_NORMAL
, comkgdbmode
))
642 panic("KGDB uart can not be initialized.");
644 bus_space_write_1(&omap_a4x_bs_tag
, bh
,
645 OMAP_COM_MDR1
, OMAP_COM_MDR1_MODE_UART_16X
);
647 bus_space_unmap(&omap_a4x_bs_tag
, bh
, OMAP_COM_SIZE
);
652 setup_real_page_tables(void)
655 * We need to allocate some fixed page tables to get the kernel going.
657 * We are going to allocate our bootstrap pages from the beginning of
658 * the free space that we just calculated. We allocate one page
659 * directory and a number of page tables and store the physical
660 * addresses in the kernel_pt_table array.
662 * The kernel page directory must be on a 16K boundary. The page
663 * tables must be on 4K boundaries. What we do is allocate the
664 * page directory on the first 16K boundary that we encounter, and
665 * the page tables on 4K boundaries otherwise. Since we allocate
666 * at least 3 L2 page tables, we are guaranteed to encounter at
667 * least one 16K aligned region.
670 #ifdef VERBOSE_INIT_ARM
671 printf("Allocating page tables\n");
675 * Define a macro to simplify memory allocation. As we allocate the
676 * memory, make sure that we don't walk over our temporary first level
679 #define valloc_pages(var, np) \
680 (var).pv_pa = physical_freestart; \
681 physical_freestart += ((np) * PAGE_SIZE); \
682 if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \
683 panic("initarm: out of memory"); \
684 free_pages -= (np); \
685 (var).pv_va = KERN_PHYSTOV((var).pv_pa); \
686 memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
691 kernel_l1pt
.pv_pa
= 0;
692 kernel_l1pt
.pv_va
= 0;
693 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
694 /* Are we 16KB aligned for an L1 ? */
695 if ((physical_freestart
& (L1_TABLE_SIZE
- 1)) == 0
696 && kernel_l1pt
.pv_pa
== 0) {
697 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
699 valloc_pages(kernel_pt_table
[pt_index
],
700 L2_TABLE_SIZE
/ PAGE_SIZE
);
705 /* This should never be able to happen but better confirm that. */
706 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
707 panic("initarm: Failed to align the kernel page directory");
710 * Allocate a page for the system page mapped to V0x00000000
711 * This page will just contain the system vectors and can be
712 * shared by all processes.
714 valloc_pages(systempage
, 1);
715 systempage
.pv_va
= 0x00000000;
717 /* Allocate stacks for all modes */
718 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
719 valloc_pages(abtstack
, ABT_STACK_SIZE
);
720 valloc_pages(undstack
, UND_STACK_SIZE
);
721 valloc_pages(kernelstack
, UPAGES
);
723 /* Allocate the message buffer. */
725 int msgbuf_pgs
= round_page(MSGBUFSIZE
) / PAGE_SIZE
;
726 valloc_pages(msgbuf
, msgbuf_pgs
);
727 msgbufphys
= msgbuf
.pv_pa
;
730 * Ok we have allocated physical pages for the primary kernel
734 #ifdef VERBOSE_INIT_ARM
735 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt
.pv_pa
);
739 * Now we start construction of the L1 page table
740 * We start by mapping the L2 page tables into the L1.
741 * This means that we can replace L1 mappings later on if necessary
743 vaddr_t l1_va
= kernel_l1pt
.pv_va
;
744 paddr_t l1_pa
= kernel_l1pt
.pv_pa
;
746 /* Map the L2 pages tables in the L1 page table */
747 pmap_link_l2pt(l1_va
, 0x00000000, &kernel_pt_table
[KERNEL_PT_SYS
]);
748 for (loop
= 0; loop
< KERNEL_PT_KERNEL_NUM
; loop
++)
749 pmap_link_l2pt(l1_va
, KERNEL_BASE
+ loop
* 0x00400000,
750 &kernel_pt_table
[KERNEL_PT_KERNEL
+ loop
]);
751 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; loop
++)
752 pmap_link_l2pt(l1_va
, KERNEL_VM_BASE
+ loop
* 0x00400000,
753 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
755 /* update the top of the kernel VM */
757 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
759 #ifdef VERBOSE_INIT_ARM
760 printf("Mapping kernel\n");
763 /* Now we fill in the L2 pagetable for the kernel static code/data */
764 size_t textsize
= round_page((uintptr_t) etext
- KERNEL_BASE
);
765 size_t totalsize
= round_page((uintptr_t) _end
- KERNEL_BASE
);
766 u_int offset
= 0; /* offset of kernel in RAM */
768 /* Map text section read-only. */
769 offset
+= pmap_map_chunk(l1_va
, KERNEL_BASE
+ offset
,
770 physical_start
+ offset
, textsize
,
771 VM_PROT_READ
, PTE_CACHE
);
772 /* Map data and bss sections read-write. */
773 offset
+= pmap_map_chunk(l1_va
, KERNEL_BASE
+ offset
,
774 physical_start
+ offset
, totalsize
- textsize
,
775 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
777 #ifdef VERBOSE_INIT_ARM
778 printf("Constructing L2 page tables\n");
781 /* Map the stack pages */
782 pmap_map_chunk(l1_va
, irqstack
.pv_va
, irqstack
.pv_pa
,
783 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
784 pmap_map_chunk(l1_va
, abtstack
.pv_va
, abtstack
.pv_pa
,
785 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
786 pmap_map_chunk(l1_va
, undstack
.pv_va
, undstack
.pv_pa
,
787 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
788 pmap_map_chunk(l1_va
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
789 UPAGES
* PAGE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_CACHE
);
791 pmap_map_chunk(l1_va
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
792 L1_TABLE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_PAGETABLE
);
794 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
795 pmap_map_chunk(l1_va
, kernel_pt_table
[loop
].pv_va
,
796 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
797 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
800 /* Map the vector page. */
801 pmap_map_entry(l1_va
, ARM_VECTORS_LOW
, systempage
.pv_pa
,
802 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
805 * Map integrated peripherals at same address in first level page
806 * table so that we can continue to use console.
808 pmap_devmap_bootstrap(l1_va
, devmap
);
811 #ifdef VERBOSE_INIT_ARM
812 /* Tell the user about where all the bits and pieces live. */
813 printf("%22s Physical Virtual Num\n", " ");
814 printf("%22s Starting Ending Starting Ending Pages\n", " ");
816 static const char mem_fmt
[] =
817 "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
818 static const char mem_fmt_nov
[] =
819 "%20s: 0x%08lx 0x%08lx %d\n";
821 printf(mem_fmt
, "SDRAM", physical_start
, physical_end
-1,
822 KERN_PHYSTOV(physical_start
), KERN_PHYSTOV(physical_end
-1),
824 printf(mem_fmt
, "text section",
825 KERN_VTOPHYS(KERNEL_BASE
), KERN_VTOPHYS(etext
-1),
826 (vaddr_t
)KERNEL_BASE
, (vaddr_t
)etext
-1,
827 (int)(textsize
/ PAGE_SIZE
));
828 printf(mem_fmt
, "data section",
829 KERN_VTOPHYS(__data_start
), KERN_VTOPHYS(_edata
),
830 (vaddr_t
)__data_start
, (vaddr_t
)_edata
,
831 (int)((round_page((vaddr_t
)_edata
)
832 - trunc_page((vaddr_t
)__data_start
)) / PAGE_SIZE
));
833 printf(mem_fmt
, "bss section",
834 KERN_VTOPHYS(__bss_start
), KERN_VTOPHYS(__bss_end__
),
835 (vaddr_t
)__bss_start
, (vaddr_t
)__bss_end__
,
836 (int)((round_page((vaddr_t
)__bss_end__
)
837 - trunc_page((vaddr_t
)__bss_start
)) / PAGE_SIZE
));
838 printf(mem_fmt
, "L1 page directory",
839 kernel_l1pt
.pv_pa
, kernel_l1pt
.pv_pa
+ L1_TABLE_SIZE
- 1,
840 kernel_l1pt
.pv_va
, kernel_l1pt
.pv_va
+ L1_TABLE_SIZE
- 1,
841 L1_TABLE_SIZE
/ PAGE_SIZE
);
842 printf(mem_fmt
, "Exception Vectors",
843 systempage
.pv_pa
, systempage
.pv_pa
+ PAGE_SIZE
- 1,
844 (vaddr_t
)ARM_VECTORS_LOW
, (vaddr_t
)ARM_VECTORS_LOW
+ PAGE_SIZE
- 1,
846 printf(mem_fmt
, "IRQ stack",
847 irqstack
.pv_pa
, irqstack
.pv_pa
+ (IRQ_STACK_SIZE
* PAGE_SIZE
) - 1,
848 irqstack
.pv_va
, irqstack
.pv_va
+ (IRQ_STACK_SIZE
* PAGE_SIZE
) - 1,
850 printf(mem_fmt
, "ABT stack",
851 abtstack
.pv_pa
, abtstack
.pv_pa
+ (ABT_STACK_SIZE
* PAGE_SIZE
) - 1,
852 abtstack
.pv_va
, abtstack
.pv_va
+ (ABT_STACK_SIZE
* PAGE_SIZE
) - 1,
854 printf(mem_fmt
, "UND stack",
855 undstack
.pv_pa
, undstack
.pv_pa
+ (UND_STACK_SIZE
* PAGE_SIZE
) - 1,
856 undstack
.pv_va
, undstack
.pv_va
+ (UND_STACK_SIZE
* PAGE_SIZE
) - 1,
858 printf(mem_fmt
, "SVC stack",
859 kernelstack
.pv_pa
, kernelstack
.pv_pa
+ (UPAGES
* PAGE_SIZE
) - 1,
860 kernelstack
.pv_va
, kernelstack
.pv_va
+ (UPAGES
* PAGE_SIZE
) - 1,
862 printf(mem_fmt_nov
, "Message Buffer",
863 msgbufphys
, msgbufphys
+ msgbuf_pgs
* PAGE_SIZE
- 1, msgbuf_pgs
);
864 printf(mem_fmt
, "Free Memory", physical_freestart
, physical_freeend
-1,
865 KERN_PHYSTOV(physical_freestart
), KERN_PHYSTOV(physical_freeend
-1),
870 * Now we have the real page tables in place so we can switch to them.
871 * Once this is done we will be running with the REAL kernel page
876 #ifdef VERBOSE_INIT_ARM
877 printf("switching to new L1 page table @%#lx...", l1_pa
);
880 cpu_domains((DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2)) | DOMAIN_CLIENT
);
883 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));