4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Ichiro FUKUHARA <ichiro@ichiro.org>.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
49 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * Copyright (c) 1997,1998 Mark Brinicombe.
59 * Copyright (c) 1997,1998 Causality Limited.
60 * All rights reserved.
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 * 2. Redistributions in binary form must reproduce the above copyright
68 * notice, this list of conditions and the following disclaimer in the
69 * documentation and/or other materials provided with the distribution.
70 * 3. All advertising materials mentioning features or use of this software
71 * must display the following acknowledgement:
72 * This product includes software developed by Mark Brinicombe
73 * for the NetBSD Project.
74 * 4. The name of the company nor the name of the author may be used to
75 * endorse or promote products derived from this software without specific
76 * prior written permission.
78 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
79 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
80 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
81 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
82 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
83 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
84 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * Machine dependant functions for kernel setup for Linksys NSLU2
93 * using RedBoot firmware.
96 #include <sys/cdefs.h>
97 __KERNEL_RCSID(0, "$NetBSD$");
100 #include "opt_kgdb.h"
101 #include "opt_pmap_debug.h"
103 #include <sys/param.h>
104 #include <sys/device.h>
105 #include <sys/systm.h>
106 #include <sys/kernel.h>
107 #include <sys/exec.h>
108 #include <sys/proc.h>
109 #include <sys/msgbuf.h>
110 #include <sys/reboot.h>
111 #include <sys/termios.h>
112 #include <sys/ksyms.h>
114 #include <uvm/uvm_extern.h>
116 #include <dev/cons.h>
118 #include <machine/db_machdep.h>
119 #include <ddb/db_sym.h>
120 #include <ddb/db_extern.h>
122 #include <machine/bootconfig.h>
123 #include <machine/bus.h>
124 #include <machine/cpu.h>
125 #include <machine/frame.h>
126 #include <arm/undefined.h>
128 #include <arm/arm32/machdep.h>
130 #include <arm/xscale/ixp425reg.h>
131 #include <arm/xscale/ixp425var.h>
132 #include <arm/xscale/ixp425_sipvar.h>
134 #include <evbarm/nslu2/nslu2reg.h>
138 #include <dev/ic/comreg.h>
139 #include <dev/ic/comvar.h>
144 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
145 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
146 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
149 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
150 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
152 #define KERNEL_VM_SIZE 0x0C000000
156 * Address to call from cpu_reset() to reset the machine.
157 * This is machine architecture dependant as it varies depending
158 * on where the ROM appears when you turn the MMU off.
161 u_int cpu_reset_address
= 0x00000000;
163 /* Define various stack sizes in pages */
164 #define IRQ_STACK_SIZE 1
165 #define ABT_STACK_SIZE 1
166 #define UND_STACK_SIZE 1
168 BootConfig bootconfig
; /* Boot config storage */
169 char *boot_args
= NULL
;
170 char *boot_file
= NULL
;
172 vm_offset_t physical_start
;
173 vm_offset_t physical_freestart
;
174 vm_offset_t physical_freeend
;
175 vm_offset_t physical_end
;
178 /* Physical and virtual addresses for some global pages */
182 pv_addr_t kernelstack
;
183 pv_addr_t minidataclean
;
185 vm_offset_t msgbufphys
;
187 extern u_int data_abort_handler_address
;
188 extern u_int prefetch_abort_handler_address
;
189 extern u_int undefined_handler_address
;
193 extern int pmap_debug_level
;
196 #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
198 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
199 #define KERNEL_PT_KERNEL_NUM 4
200 #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
201 /* L2 tables for mapping kernel VM */
202 #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
203 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
204 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
206 pv_addr_t kernel_pt_table
[NUM_KERNEL_PTS
];
211 u_int
cpu_get_control(void);
214 * Define the default console speed for the board. This is generally
215 * what the firmware provided with the board defaults to.
218 #define CONSPEED B115200
219 #endif /* ! CONSPEED */
226 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
229 int comcnspeed
= CONSPEED
;
230 int comcnmode
= CONMODE
;
231 int comcnunit
= CONUNIT
;
235 #error Must define KGDB_DEVNAME
237 const char kgdb_devname
[] = KGDB_DEVNAME
;
240 #error Must define KGDB_DEVADDR
242 unsigned long kgdb_devaddr
= KGDB_DEVADDR
;
245 #define KGDB_DEVRATE CONSPEED
247 int kgdb_devrate
= KGDB_DEVRATE
;
250 #define KGDB_DEVMODE CONMODE
252 int kgdb_devmode
= KGDB_DEVMODE
;
256 * void cpu_reboot(int howto, char *bootstr)
260 * Deal with any syncing, unmounting, dumping and shutdown hooks,
261 * then reset the CPU.
264 cpu_reboot(int howto
, char *bootstr
)
269 printf("boot: howto=%08x curproc=%p\n", howto
, curproc
);
273 * If we are still cold then hit the air brakes
274 * and crash to earth fast
278 pmf_system_shutdown(boothowto
);
279 printf("The operating system has halted.\n");
280 printf("Please press any key to reboot.\n\n");
285 /* Disable console buffering */
288 * If RB_NOSYNC was not specified sync the discs.
289 * Note: Unless cold is set to 1 here, syslogd will die during the
290 * unmount. It looks like syslogd is getting woken up only to find
291 * that it cannot page part of the binary in as the filesystem has
294 if (!(howto
& RB_NOSYNC
))
297 /* Say NO to interrupts */
300 /* Do a dump if requested. */
301 if ((howto
& (RB_DUMP
| RB_HALT
)) == RB_DUMP
)
304 /* Run any shutdown hooks */
307 pmf_system_shutdown(boothowto
);
309 /* Make sure IRQ's are disabled */
312 if ((howto
& (RB_HALT
| RB_POWERDOWN
)) == RB_HALT
) {
313 printf("The operating system has halted.\n");
314 printf("Please press any key to reboot.\n\n");
320 * Make really really sure that all interrupts are disabled,
322 (void) disable_interrupts(I32_bit
| F32_bit
);
324 if (howto
& RB_POWERDOWN
) {
327 printf("powering down...\n\r");
328 /* Delay to allow the UART's Tx FIFO to drain */
331 #define GPRD(r) *((volatile uint32_t *)(IXP425_GPIO_VBASE+(r)))
332 #define GPWR(r,v) *((volatile uint32_t *)(IXP425_GPIO_VBASE+(r))) = (v)
335 * Power-down pin requires a short pulse
337 reg
= GPRD(IXP425_GPIO_GPOUTR
);
338 reg
|= 1u << GPIO_POWER_OFF
;
339 GPWR(IXP425_GPIO_GPOUTR
, reg
);
343 reg
= GPRD(IXP425_GPIO_GPOUTR
);
344 reg
&= ~(1u << GPIO_POWER_OFF
);
345 GPWR(IXP425_GPIO_GPOUTR
, reg
);
348 printf("POWER OFF FAILED! TRYING TO REBOOT INSTEAD\n\r");
351 printf("rebooting...\n\r");
353 #define WDWR(r,v) *((volatile uint32_t *)(IXP425_OST_WDOG_VBASE+(r))) = (v)
354 /* Force a watchdog reset */
355 WDWR(IXP425_OST_WDOG_KEY
, OST_WDOG_KEY_MAJICK
);
356 WDWR(IXP425_OST_WDOG_ENAB
, OST_WDOG_ENAB_RST_ENA
);
357 WDWR(IXP425_OST_WDOG
, 0x1000);
358 WDWR(IXP425_OST_WDOG_ENAB
,
359 OST_WDOG_ENAB_RST_ENA
| OST_WDOG_ENAB_CNT_ENA
);
363 /* ...and if that didn't work, just croak. */
364 printf("RESET FAILED!\n");
369 /* Static device mappings. */
370 static const struct pmap_devmap nslu2_devmap
[] = {
371 /* Physical/Virtual address for I/O space */
376 VM_PROT_READ
|VM_PROT_WRITE
,
385 VM_PROT_READ
|VM_PROT_WRITE
,
389 /* IXP425 PCI Configuration */
394 VM_PROT_READ
|VM_PROT_WRITE
,
398 /* SDRAM Controller */
403 VM_PROT_READ
|VM_PROT_WRITE
,
407 /* PCI Memory Space */
409 IXP425_PCI_MEM_VBASE
,
410 IXP425_PCI_MEM_HWBASE
,
412 VM_PROT_READ
|VM_PROT_WRITE
,
421 VM_PROT_READ
|VM_PROT_WRITE
,
437 * Initial entry point on startup. This gets called before main() is
439 * It should be responsible for setting up everything that must be
440 * in place when main is called.
442 * Taking a copy of the boot configuration structure.
443 * Initialising the physical console so characters can be printed.
444 * Setting up page tables for the kernel
445 * Relocating the kernel to the bottom of physical memory
450 extern vaddr_t xscale_cache_clean_addr
;
452 extern vsize_t xscale_minidata_clean_size
;
456 u_int kerneldatasize
;
462 * Make sure the power-down GPIO pin is configured correctly, as
463 * cpu_reboot() may be called early on (e.g. from within ddb(9)).
465 /* Pin is active-high, so make sure it's driven low */
466 reg
= GPRD(IXP425_GPIO_GPOUTR
);
467 reg
&= ~(1u << GPIO_POWER_OFF
);
468 GPWR(IXP425_GPIO_GPOUTR
, reg
);
471 reg
= GPRD(IXP425_GPIO_GPOER
);
472 reg
&= ~(1u << GPIO_POWER_OFF
);
473 GPWR(IXP425_GPIO_GPOER
, reg
);
476 * Since we map v0xf0000000 == p0xc8000000, it's possible for
477 * us to initialize the console now.
481 #ifdef VERBOSE_INIT_ARM
482 /* Talk to the user */
483 printf("\nNetBSD/evbarm (Linksys NSLU2) booting ...\n");
487 * Heads up ... Setup the CPU / MMU / TLB functions
490 panic("cpu not recognized!");
492 /* XXX overwrite bootconfig to hardcoded values */
493 bootconfig
.dramblocks
= 1;
494 bootconfig
.dram
[0].address
= 0x10000000;
495 bootconfig
.dram
[0].pages
= ixp425_sdram_size() / PAGE_SIZE
;
497 kerneldatasize
= (u_int32_t
)&end
- (u_int32_t
)KERNEL_TEXT_BASE
;
499 #ifdef VERBOSE_INIT_ARM
500 printf("kernsize=0x%x\n", kerneldatasize
);
502 kerneldatasize
= ((kerneldatasize
- 1) & ~(PAGE_SIZE
* 4 - 1)) + PAGE_SIZE
* 8;
505 * Set up the variables that define the availablilty of
506 * physical memory. For now, we're going to set
507 * physical_freestart to 0x10200000 (where the kernel
508 * was loaded), and allocate the memory we need downwards.
509 * If we get too close to the L1 table that we set up, we
510 * will panic. We will update physical_freestart and
511 * physical_freeend later to reflect what pmap_bootstrap()
514 * XXX pmap_bootstrap() needs an enema.
516 physical_start
= bootconfig
.dram
[0].address
;
517 physical_end
= physical_start
+ (bootconfig
.dram
[0].pages
* PAGE_SIZE
);
519 physical_freestart
= physical_start
520 + (KERNEL_TEXT_BASE
- KERNEL_BASE
) + kerneldatasize
;
521 physical_freeend
= physical_end
;
523 physmem
= (physical_end
- physical_start
) / PAGE_SIZE
;
525 /* Tell the user about the memory */
526 #ifdef VERBOSE_INIT_ARM
527 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem
,
528 physical_start
, physical_end
- 1);
530 printf("Allocating page tables\n");
532 free_pages
= (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
534 freemempos
= 0x10000000;
536 #ifdef VERBOSE_INIT_ARM
537 printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
538 physical_start
, physical_end
);
541 /* Define a macro to simplify memory allocation */
542 #define valloc_pages(var, np) \
543 alloc_pages((var).pv_pa, (np)); \
544 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
547 #define alloc_pages(var, np) \
548 physical_freeend -= ((np) * PAGE_SIZE); \
549 if (physical_freeend < physical_freestart) \
550 panic("initarm: out of memory"); \
551 (var) = physical_freeend; \
552 free_pages -= (np); \
553 memset((char *)(var), 0, ((np) * PAGE_SIZE));
555 #define alloc_pages(var, np) \
556 (var) = freemempos; \
557 memset((char *)(var), 0, ((np) * PAGE_SIZE)); \
558 freemempos += (np) * PAGE_SIZE;
562 for (loop
= 0; loop
<= NUM_KERNEL_PTS
; ++loop
) {
563 /* Are we 16KB aligned for an L1 ? */
564 if (((physical_freeend
- L1_TABLE_SIZE
) & (L1_TABLE_SIZE
- 1)) == 0
565 && kernel_l1pt
.pv_pa
== 0) {
566 valloc_pages(kernel_l1pt
, L1_TABLE_SIZE
/ PAGE_SIZE
);
568 valloc_pages(kernel_pt_table
[loop1
],
569 L2_TABLE_SIZE
/ PAGE_SIZE
);
574 /* This should never be able to happen but better confirm that. */
575 if (!kernel_l1pt
.pv_pa
|| (kernel_l1pt
.pv_pa
& (L1_TABLE_SIZE
-1)) != 0)
576 panic("initarm: Failed to align the kernel page directory");
579 * Allocate a page for the system page.
580 * This page will just contain the system vectors and can be
581 * shared by all processes.
583 alloc_pages(systempage
.pv_pa
, 1);
585 /* Allocate stacks for all modes */
586 valloc_pages(irqstack
, IRQ_STACK_SIZE
);
587 valloc_pages(abtstack
, ABT_STACK_SIZE
);
588 valloc_pages(undstack
, UND_STACK_SIZE
);
589 valloc_pages(kernelstack
, UPAGES
);
591 /* Allocate enough pages for cleaning the Mini-Data cache. */
592 KASSERT(xscale_minidata_clean_size
<= PAGE_SIZE
);
593 valloc_pages(minidataclean
, 1);
595 #ifdef VERBOSE_INIT_ARM
596 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack
.pv_pa
,
598 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack
.pv_pa
,
600 printf("UND stack: p0x%08lx v0x%08lx\n", undstack
.pv_pa
,
602 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack
.pv_pa
,
607 * XXX Defer this to later so that we can reclaim the memory
608 * XXX used by the RedBoot page tables.
610 alloc_pages(msgbufphys
, round_page(MSGBUFSIZE
) / PAGE_SIZE
);
613 * Ok we have allocated physical pages for the primary kernel
617 #ifdef VERBOSE_INIT_ARM
618 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt
.pv_pa
);
622 * Now we start construction of the L1 page table
623 * We start by mapping the L2 page tables into the L1.
624 * This means that we can replace L1 mappings later on if necessary
626 l1pagetable
= kernel_l1pt
.pv_pa
;
628 /* Map the L2 pages tables in the L1 page table */
629 pmap_link_l2pt(l1pagetable
, ARM_VECTORS_HIGH
& ~(0x00400000 - 1),
630 &kernel_pt_table
[KERNEL_PT_SYS
]);
631 for (loop
= 0; loop
< KERNEL_PT_KERNEL_NUM
; loop
++)
632 pmap_link_l2pt(l1pagetable
, KERNEL_BASE
+ loop
* 0x00400000,
633 &kernel_pt_table
[KERNEL_PT_KERNEL
+ loop
]);
634 for (loop
= 0; loop
< KERNEL_PT_VMDATA_NUM
; loop
++)
635 pmap_link_l2pt(l1pagetable
, KERNEL_VM_BASE
+ loop
* 0x00400000,
636 &kernel_pt_table
[KERNEL_PT_VMDATA
+ loop
]);
638 /* update the top of the kernel VM */
640 KERNEL_VM_BASE
+ (KERNEL_PT_VMDATA_NUM
* 0x00400000);
642 pmap_link_l2pt(l1pagetable
, IXP425_IO_VBASE
,
643 &kernel_pt_table
[KERNEL_PT_IO
]);
645 #ifdef VERBOSE_INIT_ARM
646 printf("Mapping kernel\n");
649 /* Now we fill in the L2 pagetable for the kernel static code/data */
651 extern char etext
[], _end
[];
652 size_t textsize
= (uintptr_t) etext
- KERNEL_TEXT_BASE
;
653 size_t totalsize
= (uintptr_t) _end
- KERNEL_TEXT_BASE
;
656 textsize
= (textsize
+ PGOFSET
) & ~PGOFSET
;
657 totalsize
= (totalsize
+ PGOFSET
) & ~PGOFSET
;
659 logical
= 0x00200000; /* offset of kernel in RAM */
661 logical
+= pmap_map_chunk(l1pagetable
, KERNEL_BASE
+ logical
,
662 physical_start
+ logical
, textsize
,
663 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
664 logical
+= pmap_map_chunk(l1pagetable
, KERNEL_BASE
+ logical
,
665 physical_start
+ logical
, totalsize
- textsize
,
666 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
669 #ifdef VERBOSE_INIT_ARM
670 printf("Constructing L2 page tables\n");
673 /* Map the stack pages */
674 pmap_map_chunk(l1pagetable
, irqstack
.pv_va
, irqstack
.pv_pa
,
675 IRQ_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
676 pmap_map_chunk(l1pagetable
, abtstack
.pv_va
, abtstack
.pv_pa
,
677 ABT_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
678 pmap_map_chunk(l1pagetable
, undstack
.pv_va
, undstack
.pv_pa
,
679 UND_STACK_SIZE
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
680 pmap_map_chunk(l1pagetable
, kernelstack
.pv_va
, kernelstack
.pv_pa
,
681 UPAGES
* PAGE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
683 pmap_map_chunk(l1pagetable
, kernel_l1pt
.pv_va
, kernel_l1pt
.pv_pa
,
684 L1_TABLE_SIZE
, VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
686 for (loop
= 0; loop
< NUM_KERNEL_PTS
; ++loop
) {
687 pmap_map_chunk(l1pagetable
, kernel_pt_table
[loop
].pv_va
,
688 kernel_pt_table
[loop
].pv_pa
, L2_TABLE_SIZE
,
689 VM_PROT_READ
|VM_PROT_WRITE
, PTE_PAGETABLE
);
692 /* Map the Mini-Data cache clean area. */
693 xscale_setup_minidata(l1pagetable
, minidataclean
.pv_va
,
694 minidataclean
.pv_pa
);
696 /* Map the vector page. */
697 pmap_map_entry(l1pagetable
, ARM_VECTORS_HIGH
, systempage
.pv_pa
,
698 VM_PROT_READ
|VM_PROT_WRITE
, PTE_CACHE
);
701 * Map the IXP425 registers
703 pmap_devmap_bootstrap(l1pagetable
, nslu2_devmap
);
706 * Give the XScale global cache clean code an appropriately
707 * sized chunk of unmapped VA space starting at 0xff000000
708 * (our device mappings end before this address).
710 xscale_cache_clean_addr
= 0xff000000U
;
713 * Now we have the real page tables in place so we can switch to them.
714 * Once this is done we will be running with the REAL kernel page
719 * Update the physical_freestart/physical_freeend/free_pages
725 physical_freestart
= physical_start
+
726 (((((uintptr_t) _end
) + PGOFSET
) & ~PGOFSET
) -
728 physical_freeend
= physical_end
;
730 (physical_freeend
- physical_freestart
) / PAGE_SIZE
;
734 #ifdef VERBOSE_INIT_ARM
735 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
736 physical_freestart
, free_pages
, free_pages
);
737 printf("switching to new L1 page table @%#lx...", kernel_l1pt
.pv_pa
);
739 cpu_domains((DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2)) | DOMAIN_CLIENT
);
740 cpu_setttb(kernel_l1pt
.pv_pa
);
742 cpu_domains(DOMAIN_CLIENT
<< (PMAP_DOMAIN_KERNEL
*2));
745 * Moved from cpu_startup() as data_abort_handler() references
746 * this during uvm init
748 uvm_lwp_setuarea(&lwp0
, kernelstack
.pv_va
);
750 #ifdef VERBOSE_INIT_ARM
751 printf("bootstrap done.\n");
754 arm32_vector_init(ARM_VECTORS_HIGH
, ARM_VEC_ALL
);
757 * Pages were allocated during the secondary bootstrap for the
758 * stacks for different CPU modes.
759 * We must now set the r13 registers in the different CPU modes to
760 * point to these stacks.
761 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
762 * of the stack memory.
764 #ifdef VERBOSE_INIT_ARM
765 printf("init subsystems: stacks ");
768 set_stackptr(PSR_IRQ32_MODE
,
769 irqstack
.pv_va
+ IRQ_STACK_SIZE
* PAGE_SIZE
);
770 set_stackptr(PSR_ABT32_MODE
,
771 abtstack
.pv_va
+ ABT_STACK_SIZE
* PAGE_SIZE
);
772 set_stackptr(PSR_UND32_MODE
,
773 undstack
.pv_va
+ UND_STACK_SIZE
* PAGE_SIZE
);
776 * Well we should set a data abort handler.
777 * Once things get going this will change as we will need a proper
779 * Until then we will use a handler that just panics but tells us
781 * Initialisation of the vectors will just panic on a data abort.
782 * This just fills in a slightly better one.
784 #ifdef VERBOSE_INIT_ARM
787 data_abort_handler_address
= (u_int
)data_abort_handler
;
788 prefetch_abort_handler_address
= (u_int
)prefetch_abort_handler
;
789 undefined_handler_address
= (u_int
)undefinedinstruction_bounce
;
791 /* Initialise the undefined instruction handlers */
792 #ifdef VERBOSE_INIT_ARM
793 printf("undefined ");
797 /* Load memory into UVM. */
798 #ifdef VERBOSE_INIT_ARM
801 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
802 uvm_page_physload(atop(physical_freestart
), atop(physical_freeend
),
803 atop(physical_freestart
), atop(physical_freeend
),
804 VM_FREELIST_DEFAULT
);
806 /* Boot strap pmap telling it where the kernel page table is */
807 #ifdef VERBOSE_INIT_ARM
810 pmap_bootstrap(KERNEL_VM_BASE
, KERNEL_VM_BASE
+ KERNEL_VM_SIZE
);
812 /* Setup the IRQ system */
813 #ifdef VERBOSE_INIT_ARM
817 #ifdef VERBOSE_INIT_ARM
818 printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
822 boothowto
= BOOTHOWTO
;
827 if (boothowto
& RB_KDB
)
831 /* We return the new stack pointer address */
832 return(kernelstack
.pv_va
+ USPACE_SVC_STACK_TOP
);
841 static int consinit_called
;
842 static const bus_addr_t addrs
[2] = {
843 IXP425_UART0_HWBASE
, IXP425_UART1_HWBASE
846 if (consinit_called
!= 0)
851 pmap_devmap_register(nslu2_devmap
);
853 if (comcnattach(&ixp425_a4x_bs_tag
, addrs
[comcnunit
],
854 comcnspeed
, IXP425_UART_FREQ
, COM_TYPE_PXA2x0
, comcnmode
))
855 panic("can't init serial console (UART%d)", comcnunit
);