4 * Startup routines for the Arcom Viper. Below you can trace the
5 * impressive lineage ;)
7 * Modified for the Viper by Antti Kantee <pooka@netbsd.org>
11 * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
12 * Written by Hiroyuki Bessho for Genetec Corporation.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. The name of Genetec Corporation may not be used to endorse or
23 * promote products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
38 * Machine dependant functions for kernel setup for
39 * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
40 * Based on iq80310_machhdep.c
43 * Copyright (c) 2001 Wasabi Systems, Inc.
44 * All rights reserved.
46 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed for the NetBSD Project by
59 * Wasabi Systems, Inc.
60 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
61 * or promote products derived from this software without specific prior
64 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
66 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
67 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
68 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
69 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
70 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
71 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
72 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
73 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
74 * POSSIBILITY OF SUCH DAMAGE.
78 * Copyright (c) 1997,1998 Mark Brinicombe.
79 * Copyright (c) 1997,1998 Causality Limited.
80 * All rights reserved.
82 * Redistribution and use in source and binary forms, with or without
83 * modification, are permitted provided that the following conditions
85 * 1. Redistributions of source code must retain the above copyright
86 * notice, this list of conditions and the following disclaimer.
87 * 2. Redistributions in binary form must reproduce the above copyright
88 * notice, this list of conditions and the following disclaimer in the
89 * documentation and/or other materials provided with the distribution.
90 * 3. All advertising materials mentioning features or use of this software
91 * must display the following acknowledgement:
92 * This product includes software developed by Mark Brinicombe
93 * for the NetBSD Project.
94 * 4. The name of the company nor the name of the author may be used to
95 * endorse or promote products derived from this software without specific
96 * prior written permission.
98 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
99 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
100 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
101 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
102 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
103 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
104 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
110 * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
111 * boards using RedBoot firmware.
114 #include <sys/cdefs.h>
115 __KERNEL_RCSID(0, "$NetBSD$");
118 #include "opt_kgdb.h"
119 #include "opt_pmap_debug.h"
125 #include <sys/param.h>
126 #include <sys/device.h>
127 #include <sys/systm.h>
128 #include <sys/kernel.h>
129 #include <sys/exec.h>
130 #include <sys/proc.h>
131 #include <sys/msgbuf.h>
132 #include <sys/reboot.h>
133 #include <sys/termios.h>
134 #include <sys/ksyms.h>
136 #include <uvm/uvm_extern.h>
138 #include <sys/conf.h>
139 #include <dev/cons.h>
141 #include <dev/ic/smc91cxxreg.h>
143 #include <machine/db_machdep.h>
144 #include <ddb/db_sym.h>
145 #include <ddb/db_extern.h>
147 #include <sys/kgdb.h>
150 #include <machine/bootconfig.h>
151 #include <machine/bus.h>
152 #include <machine/cpu.h>
153 #include <machine/frame.h>
154 #include <arm/undefined.h>
156 #include <arm/arm32/machdep.h>
158 #include <arm/xscale/pxa2x0reg.h>
159 #include <arm/xscale/pxa2x0var.h>
160 #include <arm/xscale/pxa2x0_gpio.h>
161 #include <arm/sa11x0/sa1111_reg.h>
162 #include <evbarm/viper/viper_reg.h>
164 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
165 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
166 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
169 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
170 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
172 #define KERNEL_VM_SIZE 0x0C000000
176 * Address to call from cpu_reset() to reset the machine.
177 * This is machine architecture dependant as it varies depending
178 * on where the ROM appears when you turn the MMU off.
181 u_int cpu_reset_address
= 0;
183 /* Define various stack sizes in pages */
184 #define IRQ_STACK_SIZE 1
185 #define ABT_STACK_SIZE 1
186 #define UND_STACK_SIZE 1
188 BootConfig bootconfig
; /* Boot config storage */
189 char *boot_args
= NULL
;
190 char *boot_file
= NULL
;
192 vm_offset_t physical_start
;
193 vm_offset_t physical_freestart
;
194 vm_offset_t physical_freeend
;
195 vm_offset_t physical_end
;
199 #ifndef PMAP_STATIC_L1S
200 int max_processes
= 64; /* Default number */
201 #endif /* !PMAP_STATIC_L1S */
203 /* Physical and virtual addresses for some global pages */
207 pv_addr_t kernelstack
;
208 pv_addr_t minidataclean
;
210 vm_offset_t msgbufphys
;
212 extern u_int data_abort_handler_address
;
213 extern u_int prefetch_abort_handler_address
;
214 extern u_int undefined_handler_address
;
217 extern int pmap_debug_level
;
220 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
221 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
222 #define KERNEL_PT_KERNEL_NUM 4
223 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
224 /* Page tables for mapping kernel VM */
225 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
226 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
228 pv_addr_t kernel_pt_table
[NUM_KERNEL_PTS
];
233 void process_kernel_args(char *);
237 void kgdb_port_init(void);
238 void change_clock(uint32_t v
);
240 bs_protos(bs_notimpl
);
244 #include <dev/ic/comreg.h>
245 #include <dev/ic/comvar.h>
249 #define CONSPEED B115200 /* What RedBoot uses */
252 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
255 int comcnspeed
= CONSPEED
;
256 int comcnmode
= CONMODE
;
258 static struct pxa2x0_gpioconf boarddep_gpioconf
[] = {
259 { 44, GPIO_ALT_FN_1_IN
}, /* BTCST */
260 { 45, GPIO_ALT_FN_2_OUT
}, /* BTRST */
264 static struct pxa2x0_gpioconf
*viper_gpioconf
[] = {
265 pxa25x_com_btuart_gpioconf
,
266 pxa25x_com_ffuart_gpioconf
,
267 pxa25x_com_stuart_gpioconf
,
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");
303 /* Disable console buffering */
307 * If RB_NOSYNC was not specified sync the discs.
308 * Note: Unless cold is set to 1 here, syslogd will die during the
309 * unmount. It looks like syslogd is getting woken up only to find
310 * that it cannot page part of the binary in as the filesystem has
313 if (!(howto
& RB_NOSYNC
))
316 /* Say NO to interrupts */
319 /* Do a dump if requested. */
320 if ((howto
& (RB_DUMP
| RB_HALT
)) == RB_DUMP
)
323 /* Run any shutdown hooks */
326 pmf_system_shutdown(boothowto
);
328 /* Make sure IRQ's are disabled */
331 if (howto
& RB_HALT
) {
332 printf("The operating system has halted.\n");
333 printf("Please press any key to reboot.\n\n");
337 printf("rebooting...\n");
343 * Static device mappings. These peripheral registers are mapped at
344 * fixed virtual addresses very early in viper_start() so that we
345 * can use them while booting the kernel, and stay at the same address
346 * throughout whole kernel's life time.
348 * We use this table twice; once with bootstrap page table, and once
349 * with kernel's page table which we build up in initarm().
352 static const struct pmap_devmap viper_devmap
[] = {
357 VM_PROT_READ
|VM_PROT_WRITE
, PTE_NOCACHE
,
363 VM_PROT_READ
|VM_PROT_WRITE
, PTE_NOCACHE
,
369 VM_PROT_READ
|VM_PROT_WRITE
, PTE_NOCACHE
,
375 VM_PROT_READ
|VM_PROT_WRITE
, PTE_NOCACHE
,
381 VM_PROT_READ
|VM_PROT_WRITE
, PTE_NOCACHE
,
388 #define MEMSTART 0xa0000000
391 #define MEMSIZE 0x4000000
397 * Initial entry point on startup. This gets called before main() is
399 * It should be responsible for setting up everything that must be
400 * in place when main is called.
402 * Taking a copy of the boot configuration structure.
403 * Initialising the physical console so characters can be printed.
404 * Setting up page tables for the kernel
405 * Relocating the kernel to the bottom of physical memory
410 extern vaddr_t xscale_cache_clean_addr
;
415 extern vsize_t xscale_minidata_clean_size
; /* used in KASSERT */
418 /* Register devmap for devices we mapped in start */
419 pmap_devmap_register(viper_devmap
);
421 /* start 32.768 kHz OSC */
422 ioreg_write(VIPER_CLKMAN_VBASE
+ 0x08, 2);
423 /* Get ready for splfoo() */
424 pxa2x0_intr_bootstrap(VIPER_INTCTL_VBASE
);
427 * Heads up ... Setup the CPU / MMU / TLB functions
430 panic("cpu not recognized!");
433 /* Calibrate the delay loop. */
436 /* setup GPIO for BTUART, in case bootloader doesn't take care of it */
437 pxa2x0_gpio_bootstrap(VIPER_GPIO_VBASE
);
438 pxa2x0_gpio_config(viper_gpioconf
);
440 /* turn on clock to UART block.
441 XXX: this should not be done here. */
442 ioreg_write(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
, CKEN_FFUART
|CKEN_BTUART
|
443 ioreg_read(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
));
449 /* Talk to the user */
450 printf("\nNetBSD/evbarm (viper) booting ...\n");
454 * Examine the boot args string for options we need to know about
457 process_kernel_args((char *)nwbootinfo
.bt_args
);
460 printf("initarm: Configuring system ...\n");
462 /* Fake bootconfig structure for the benefit of pmap.c */
463 /* XXX must make the memory description h/w independent */
464 bootconfig
.dramblocks
= 1;
465 bootconfig
.dram
[0].address
= MEMSTART
;
466 bootconfig
.dram
[0].pages
= MEMSIZE
/ PAGE_SIZE
;
469 * Set up the variables that define the availablilty of
470 * physical memory. For now, we're going to set
471 * physical_freestart to 0xa0200000 (where the kernel
472 * was loaded), and allocate the memory we need downwards.
473 * If we get too close to the page tables that RedBoot
474 * set up, we will panic. We will update physical_freestart
475 * and physical_freeend later to reflect what pmap_bootstrap()
478 * XXX pmap_bootstrap() needs an enema.
479 * (now that would be truly hardcore XXX)
481 physical_start
= bootconfig
.dram
[0].address
;
482 physical_end
= physical_start
+ (bootconfig
.dram
[0].pages
* PAGE_SIZE
);
484 physical_freestart
= 0xa0009000UL
;
485 physical_freeend
= 0xa0200000UL
;
487 physmem
= (physical_end
- physical_start
) / PAGE_SIZE
;
489 #ifdef VERBOSE_INIT_ARM
490 /* Tell the user about the memory */
491 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem
,
492 physical_start
, physical_end
- 1);
496 * Okay, the kernel starts 2MB in from the bottom of physical
497 * memory. We are going to allocate our bootstrap pages downwards
500 * We need to allocate some fixed page tables to get the kernel
501 * going. We allocate one page directory and a number of page
502 * tables and store the physical addresses in the kernel_pt_table
505 * The kernel page directory must be on a 16K boundary. The page
506 * tables must be on 4K boundaries. What we do is allocate the
507 * page directory on the first 16K boundary that we encounter, and
508 * the page tables on 4K boundaries otherwise. Since we allocate
509 * at least 3 L2 page tables, we are guaranteed to encounter at
510 * least one 16K aligned region.
513 #ifdef VERBOSE_INIT_ARM
514 printf("Allocating page tables\n");
517 free_pages
= (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
519 #ifdef VERBOSE_INIT_ARM
520 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
521 physical_freestart
, free_pages
, free_pages
);
524 /* Define a macro to simplify memory allocation */
525 #define valloc_pages(var, np) \
526 alloc_pages((var).pv_pa, (np)); \
527 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
529 #define alloc_pages(var, np) \
530 physical_freeend -= ((np) * PAGE_SIZE); \
531 if (physical_freeend < physical_freestart) \
532 panic("initarm: out of memory"); \
533 (var) = physical_freeend; \
534 free_pages -= (np); \
535 memset((char *)(var), 0, ((np) * PAGE_SIZE));
538 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
539 /* Are we 16KB aligned for an L1 ? */
540 if (((physical_freeend
- L1_TABLE_SIZE
) & (L1_TABLE_SIZE
- 1)) == 0
541 && kernel_l1pt
.pv_pa
== 0) {
542 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
544 valloc_pages(kernel_pt_table
[loop1
],
545 L2_TABLE_SIZE
/ PAGE_SIZE
);
550 /* This should never be able to happen but better confirm that. */
551 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
552 panic("initarm: Failed to align the kernel page directory");
555 * Allocate a page for the system page mapped to V0x00000000
556 * This page will just contain the system vectors and can be
557 * shared by all processes.
559 alloc_pages(systempage
.pv_pa
, 1);
561 /* Allocate stacks for all modes */
562 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
563 valloc_pages(abtstack
, ABT_STACK_SIZE
);
564 valloc_pages(undstack
, UND_STACK_SIZE
);
565 valloc_pages(kernelstack
, UPAGES
);
567 /* Allocate enough pages for cleaning the Mini-Data cache. */
568 KASSERT(xscale_minidata_clean_size
<= PAGE_SIZE
);
569 valloc_pages(minidataclean
, 1);
571 #ifdef VERBOSE_INIT_ARM
572 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack
.pv_pa
,
574 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack
.pv_pa
,
576 printf("UND stack: p0x%08lx v0x%08lx\n", undstack
.pv_pa
,
578 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack
.pv_pa
,
583 * XXX Defer this to later so that we can reclaim the memory
584 * XXX used by the RedBoot page tables.
586 alloc_pages(msgbufphys
, round_page(MSGBUFSIZE
) / PAGE_SIZE
);
589 * Ok we have allocated physical pages for the primary kernel
593 #ifdef VERBOSE_INIT_ARM
594 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt
.pv_pa
);
598 * Now we start construction of the L1 page table
599 * We start by mapping the L2 page tables into the L1.
600 * This means that we can replace L1 mappings later on if necessary
602 l1pagetable
= kernel_l1pt
.pv_pa
;
604 /* Map the L2 pages tables in the L1 page table */
605 pmap_link_l2pt(l1pagetable
, 0x00000000,
606 &kernel_pt_table
[KERNEL_PT_SYS
]);
607 for (loop
= 0; loop
< KERNEL_PT_KERNEL_NUM
; loop
++)
608 pmap_link_l2pt(l1pagetable
, KERNEL_BASE
+ loop
* 0x00400000,
609 &kernel_pt_table
[KERNEL_PT_KERNEL
+ loop
]);
610 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; loop
++)
611 pmap_link_l2pt(l1pagetable
, KERNEL_VM_BASE
+ loop
* 0x00400000,
612 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
614 /* update the top of the kernel VM */
616 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
618 #ifdef VERBOSE_INIT_ARM
619 printf("Mapping kernel\n");
622 /* Now we fill in the L2 pagetable for the kernel static code/data */
624 extern char etext
[], _end
[];
625 size_t textsize
= (uintptr_t) etext
- KERNEL_TEXT_BASE
;
626 size_t totalsize
= (uintptr_t) _end
- KERNEL_TEXT_BASE
;
629 textsize
= (textsize
+ PGOFSET
) & ~PGOFSET
;
630 totalsize
= (totalsize
+ PGOFSET
) & ~PGOFSET
;
632 logical
= 0x00200000; /* offset of kernel in RAM */
634 logical
+= pmap_map_chunk(l1pagetable
, KERNEL_BASE
+ logical
,
635 physical_start
+ logical
, textsize
,
636 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
637 logical
+= pmap_map_chunk(l1pagetable
, KERNEL_BASE
+ logical
,
638 physical_start
+ logical
, totalsize
- textsize
,
639 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
642 #ifdef VERBOSE_INIT_ARM
643 printf("Constructing L2 page tables\n");
646 /* Map the stack pages */
647 pmap_map_chunk(l1pagetable
, irqstack
.pv_va
, irqstack
.pv_pa
,
648 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
649 pmap_map_chunk(l1pagetable
, abtstack
.pv_va
, abtstack
.pv_pa
,
650 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
651 pmap_map_chunk(l1pagetable
, undstack
.pv_va
, undstack
.pv_pa
,
652 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
653 pmap_map_chunk(l1pagetable
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
654 UPAGES
* PAGE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_CACHE
);
656 pmap_map_chunk(l1pagetable
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
657 L1_TABLE_SIZE
, VM_PROT_READ
| VM_PROT_WRITE
, PTE_PAGETABLE
);
659 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
660 pmap_map_chunk(l1pagetable
, kernel_pt_table
[loop
].pv_va
,
661 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
662 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
665 /* Map the Mini-Data cache clean area. */
666 xscale_setup_minidata(l1pagetable
, minidataclean
.pv_va
,
667 minidataclean
.pv_pa
);
669 /* Map the vector page. */
671 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
672 * cache-clean code there. */
673 pmap_map_entry(l1pagetable
, vector_page
, systempage
.pv_pa
,
674 VM_PROT_READ
|VM_PROT_WRITE
, PTE_NOCACHE
);
676 pmap_map_entry(l1pagetable
, vector_page
, systempage
.pv_pa
,
677 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
681 * map integrated peripherals at same address in l1pagetable
682 * so that we can continue to use console.
684 pmap_devmap_bootstrap(l1pagetable
, viper_devmap
);
687 * Give the XScale global cache clean code an appropriately
688 * sized chunk of unmapped VA space starting at 0xff000000
689 * (our device mappings end before this address).
691 xscale_cache_clean_addr
= 0xff000000U
;
694 * Now we have the real page tables in place so we can switch to them.
695 * Once this is done we will be running with the REAL kernel page
700 * Update the physical_freestart/physical_freeend/free_pages
706 physical_freestart
= physical_start
+
707 (((((uintptr_t) _end
) + PGOFSET
) & ~PGOFSET
) -
709 physical_freeend
= physical_end
;
711 (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
715 #ifdef VERBOSE_INIT_ARM
716 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
717 physical_freestart
, free_pages
, free_pages
);
718 printf("switching to new L1 page table @%#lx...", kernel_l1pt
.pv_pa
);
721 cpu_domains((DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2)) | DOMAIN_CLIENT
);
722 cpu_setttb(kernel_l1pt
.pv_pa
);
724 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));
727 * Moved from cpu_startup() as data_abort_handler() references
728 * this during uvm init
730 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
732 #ifdef VERBOSE_INIT_ARM
733 printf("bootstrap done.\n");
736 arm32_vector_init(ARM_VECTORS_LOW
, ARM_VEC_ALL
);
739 * Pages were allocated during the secondary bootstrap for the
740 * stacks for different CPU modes.
741 * We must now set the r13 registers in the different CPU modes to
742 * point to these stacks.
743 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
744 * of the stack memory.
746 printf("init subsystems: stacks ");
748 set_stackptr(PSR_IRQ32_MODE
, irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
749 set_stackptr(PSR_ABT32_MODE
, abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
750 set_stackptr(PSR_UND32_MODE
, undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
753 * Well we should set a data abort handler.
754 * Once things get going this will change as we will need a proper
756 * Until then we will use a handler that just panics but tells us
758 * Initialisation of the vectors will just panic on a data abort.
759 * This just fills in a slightly better one.
762 data_abort_handler_address
= (u_int
)data_abort_handler
;
763 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
764 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
766 /* Initialise the undefined instruction handlers */
767 printf("undefined ");
770 /* Load memory into UVM. */
772 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
773 uvm_page_physload(atop(physical_freestart
), atop(physical_freeend
),
774 atop(physical_freestart
), atop(physical_freeend
),
775 VM_FREELIST_DEFAULT
);
777 /* Boot strap pmap telling it where the kernel page table is */
779 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
781 #ifdef __HAVE_MEMORY_DISK__
782 md_root_setconf(memory_disk
, sizeof memory_disk
);
786 if (boothowto
& RB_KDB
) {
795 /* Firmware doesn't load symbols. */
796 ddb_init(0, NULL
, NULL
);
798 if (boothowto
& RB_KDB
)
802 /* We return the new stack pointer address */
803 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
808 process_kernel_args(char *args
)
813 /* Make a local copy of the bootargs */
814 strncpy(bootargs
, args
, MAX_BOOT_STRING
);
817 boot_file
= bootargs
;
819 /* Skip the kernel image filename */
820 while (*args
!= ' ' && *args
!= 0)
831 printf("bootfile: %s\n", boot_file
);
832 printf("bootargs: %s\n", boot_args
);
834 parse_mi_bootargs(boot_args
);
840 #define KGDB_DEVNAME "ffuart"
842 const char kgdb_devname
[] = KGDB_DEVNAME
;
846 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
848 int comkgdbmode
= KGDB_DEVMODE
;
857 static int consinit_called
= 0;
858 uint32_t ckenreg
= ioreg_read(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
);
860 char *console
= CONSDEVNAME
;
863 if (consinit_called
!= 0)
871 if (0 == strcmp(kgdb_devname
, "ffuart")) {
872 /* port is reserved for kgdb */
875 if (0 == comcnattach(&pxa2x0_a4x_bs_tag
, PXA2X0_FFUART_BASE
,
876 comcnspeed
, PXA2X0_COM_FREQ
, COM_TYPE_PXA2x0
, comcnmode
)) {
879 /* XXX: can't call pxa2x0_clkman_config yet */
880 pxa2x0_clkman_config(CKEN_FFUART
, 1);
882 ioreg_write(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
,
883 ckenreg
|CKEN_FFUART
);
889 #endif /* FFUARTCONSOLE */
893 if (0 == strcmp(kgdb_devname
, "btuart")) {
894 /* port is reserved for kgdb */
897 if (0 == comcnattach(&pxa2x0_a4x_bs_tag
, PXA2X0_BTUART_BASE
,
898 comcnspeed
, PXA2X0_COM_FREQ
, COM_TYPE_PXA2x0
, comcnmode
)) {
899 ioreg_write(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
,
900 ckenreg
|CKEN_BTUART
);
903 #endif /* BTUARTCONSOLE */
905 /* no console, guess we're flying blind */
915 #if (NCOM > 0) && defined(COM_PXA2X0)
917 uint32_t ckenreg
= ioreg_read(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
);
919 if (0 == strcmp(kgdb_devname
, "ffuart")) {
920 paddr
= PXA2X0_FFUART_BASE
;
921 ckenreg
|= CKEN_FFUART
;
923 else if (0 == strcmp(kgdb_devname
, "btuart")) {
924 paddr
= PXA2X0_BTUART_BASE
;
925 ckenreg
|= CKEN_BTUART
;
929 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag
, paddr
,
930 kgdb_rate
, PXA2X0_COM_FREQ
, COM_TYPE_PXA2x0
, comkgdbmode
)) {
932 ioreg_write(VIPER_CLKMAN_VBASE
+CLKMAN_CKEN
, ckenreg
);