nslu2_machdep.c revision 1.3.6.2 1 1.3.6.2 yamt /* $NetBSD: nslu2_machdep.c,v 1.3.6.2 2006/06/21 14:50:54 yamt Exp $ */
2 1.3.6.2 yamt
3 1.3.6.2 yamt /*-
4 1.3.6.2 yamt * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.3.6.2 yamt * All rights reserved.
6 1.3.6.2 yamt *
7 1.3.6.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.3.6.2 yamt * by Steve C. Woodford.
9 1.3.6.2 yamt *
10 1.3.6.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.3.6.2 yamt * modification, are permitted provided that the following conditions
12 1.3.6.2 yamt * are met:
13 1.3.6.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.3.6.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.3.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.6.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.3.6.2 yamt * documentation and/or other materials provided with the distribution.
18 1.3.6.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.3.6.2 yamt * must display the following acknowledgement:
20 1.3.6.2 yamt * This product includes software developed by the NetBSD
21 1.3.6.2 yamt * Foundation, Inc. and its contributors.
22 1.3.6.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.6.2 yamt * contributors may be used to endorse or promote products derived
24 1.3.6.2 yamt * from this software without specific prior written permission.
25 1.3.6.2 yamt *
26 1.3.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.6.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.6.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.6.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.6.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.6.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.6.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.6.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.6.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.6.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.6.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.3.6.2 yamt */
38 1.3.6.2 yamt /*
39 1.3.6.2 yamt * Copyright (c) 2003
40 1.3.6.2 yamt * Ichiro FUKUHARA <ichiro (at) ichiro.org>.
41 1.3.6.2 yamt * All rights reserved.
42 1.3.6.2 yamt *
43 1.3.6.2 yamt * Redistribution and use in source and binary forms, with or without
44 1.3.6.2 yamt * modification, are permitted provided that the following conditions
45 1.3.6.2 yamt * are met:
46 1.3.6.2 yamt * 1. Redistributions of source code must retain the above copyright
47 1.3.6.2 yamt * notice, this list of conditions and the following disclaimer.
48 1.3.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
49 1.3.6.2 yamt * notice, this list of conditions and the following disclaimer in the
50 1.3.6.2 yamt * documentation and/or other materials provided with the distribution.
51 1.3.6.2 yamt * 3. All advertising materials mentioning features or use of this software
52 1.3.6.2 yamt * must display the following acknowledgement:
53 1.3.6.2 yamt * This product includes software developed by Ichiro FUKUHARA.
54 1.3.6.2 yamt * 4. The name of the company nor the name of the author may be used to
55 1.3.6.2 yamt * endorse or promote products derived from this software without specific
56 1.3.6.2 yamt * prior written permission.
57 1.3.6.2 yamt *
58 1.3.6.2 yamt * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
59 1.3.6.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.3.6.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.3.6.2 yamt * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
62 1.3.6.2 yamt * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.3.6.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.3.6.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.3.6.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.3.6.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.3.6.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.3.6.2 yamt * SUCH DAMAGE.
69 1.3.6.2 yamt */
70 1.3.6.2 yamt /*
71 1.3.6.2 yamt * Copyright (c) 1997,1998 Mark Brinicombe.
72 1.3.6.2 yamt * Copyright (c) 1997,1998 Causality Limited.
73 1.3.6.2 yamt * All rights reserved.
74 1.3.6.2 yamt *
75 1.3.6.2 yamt * Redistribution and use in source and binary forms, with or without
76 1.3.6.2 yamt * modification, are permitted provided that the following conditions
77 1.3.6.2 yamt * are met:
78 1.3.6.2 yamt * 1. Redistributions of source code must retain the above copyright
79 1.3.6.2 yamt * notice, this list of conditions and the following disclaimer.
80 1.3.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
81 1.3.6.2 yamt * notice, this list of conditions and the following disclaimer in the
82 1.3.6.2 yamt * documentation and/or other materials provided with the distribution.
83 1.3.6.2 yamt * 3. All advertising materials mentioning features or use of this software
84 1.3.6.2 yamt * must display the following acknowledgement:
85 1.3.6.2 yamt * This product includes software developed by Mark Brinicombe
86 1.3.6.2 yamt * for the NetBSD Project.
87 1.3.6.2 yamt * 4. The name of the company nor the name of the author may be used to
88 1.3.6.2 yamt * endorse or promote products derived from this software without specific
89 1.3.6.2 yamt * prior written permission.
90 1.3.6.2 yamt *
91 1.3.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
92 1.3.6.2 yamt * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
93 1.3.6.2 yamt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
94 1.3.6.2 yamt * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
95 1.3.6.2 yamt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
96 1.3.6.2 yamt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
97 1.3.6.2 yamt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 1.3.6.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 1.3.6.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 1.3.6.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 1.3.6.2 yamt * SUCH DAMAGE.
102 1.3.6.2 yamt */
103 1.3.6.2 yamt
104 1.3.6.2 yamt /*
105 1.3.6.2 yamt * Machine dependant functions for kernel setup for Linksys NSLU2
106 1.3.6.2 yamt * using RedBoot firmware.
107 1.3.6.2 yamt */
108 1.3.6.2 yamt
109 1.3.6.2 yamt #include <sys/cdefs.h>
110 1.3.6.2 yamt __KERNEL_RCSID(0, "$NetBSD: nslu2_machdep.c,v 1.3.6.2 2006/06/21 14:50:54 yamt Exp $");
111 1.3.6.2 yamt
112 1.3.6.2 yamt #include "opt_ddb.h"
113 1.3.6.2 yamt #include "opt_kgdb.h"
114 1.3.6.2 yamt #include "opt_pmap_debug.h"
115 1.3.6.2 yamt
116 1.3.6.2 yamt #include <sys/param.h>
117 1.3.6.2 yamt #include <sys/device.h>
118 1.3.6.2 yamt #include <sys/systm.h>
119 1.3.6.2 yamt #include <sys/kernel.h>
120 1.3.6.2 yamt #include <sys/exec.h>
121 1.3.6.2 yamt #include <sys/proc.h>
122 1.3.6.2 yamt #include <sys/msgbuf.h>
123 1.3.6.2 yamt #include <sys/reboot.h>
124 1.3.6.2 yamt #include <sys/termios.h>
125 1.3.6.2 yamt #include <sys/ksyms.h>
126 1.3.6.2 yamt
127 1.3.6.2 yamt #include <uvm/uvm_extern.h>
128 1.3.6.2 yamt
129 1.3.6.2 yamt #include <dev/cons.h>
130 1.3.6.2 yamt
131 1.3.6.2 yamt #include <machine/db_machdep.h>
132 1.3.6.2 yamt #include <ddb/db_sym.h>
133 1.3.6.2 yamt #include <ddb/db_extern.h>
134 1.3.6.2 yamt
135 1.3.6.2 yamt #include <machine/bootconfig.h>
136 1.3.6.2 yamt #include <machine/bus.h>
137 1.3.6.2 yamt #include <machine/cpu.h>
138 1.3.6.2 yamt #include <machine/frame.h>
139 1.3.6.2 yamt #include <arm/undefined.h>
140 1.3.6.2 yamt
141 1.3.6.2 yamt #include <arm/arm32/machdep.h>
142 1.3.6.2 yamt
143 1.3.6.2 yamt #include <arm/xscale/ixp425reg.h>
144 1.3.6.2 yamt #include <arm/xscale/ixp425var.h>
145 1.3.6.2 yamt #include <arm/xscale/ixp425_sipvar.h>
146 1.3.6.2 yamt
147 1.3.6.2 yamt #include <evbarm/nslu2/nslu2reg.h>
148 1.3.6.2 yamt
149 1.3.6.2 yamt #include "com.h"
150 1.3.6.2 yamt #if NCOM > 0
151 1.3.6.2 yamt #include <dev/ic/comreg.h>
152 1.3.6.2 yamt #include <dev/ic/comvar.h>
153 1.3.6.2 yamt #endif
154 1.3.6.2 yamt
155 1.3.6.2 yamt #include "opt_ipkdb.h"
156 1.3.6.2 yamt #include "ksyms.h"
157 1.3.6.2 yamt
158 1.3.6.2 yamt /* Kernel text starts 2MB in from the bottom of the kernel address space. */
159 1.3.6.2 yamt #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
160 1.3.6.2 yamt #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
161 1.3.6.2 yamt
162 1.3.6.2 yamt /*
163 1.3.6.2 yamt * The range 0xc1000000 - 0xccffffff is available for kernel VM space
164 1.3.6.2 yamt * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
165 1.3.6.2 yamt */
166 1.3.6.2 yamt #define KERNEL_VM_SIZE 0x0C000000
167 1.3.6.2 yamt
168 1.3.6.2 yamt
169 1.3.6.2 yamt /*
170 1.3.6.2 yamt * Address to call from cpu_reset() to reset the machine.
171 1.3.6.2 yamt * This is machine architecture dependant as it varies depending
172 1.3.6.2 yamt * on where the ROM appears when you turn the MMU off.
173 1.3.6.2 yamt */
174 1.3.6.2 yamt
175 1.3.6.2 yamt u_int cpu_reset_address = 0x00000000;
176 1.3.6.2 yamt
177 1.3.6.2 yamt /* Define various stack sizes in pages */
178 1.3.6.2 yamt #define IRQ_STACK_SIZE 1
179 1.3.6.2 yamt #define ABT_STACK_SIZE 1
180 1.3.6.2 yamt #ifdef IPKDB
181 1.3.6.2 yamt #define UND_STACK_SIZE 2
182 1.3.6.2 yamt #else
183 1.3.6.2 yamt #define UND_STACK_SIZE 1
184 1.3.6.2 yamt #endif
185 1.3.6.2 yamt
186 1.3.6.2 yamt BootConfig bootconfig; /* Boot config storage */
187 1.3.6.2 yamt char *boot_args = NULL;
188 1.3.6.2 yamt char *boot_file = NULL;
189 1.3.6.2 yamt
190 1.3.6.2 yamt vm_offset_t physical_start;
191 1.3.6.2 yamt vm_offset_t physical_freestart;
192 1.3.6.2 yamt vm_offset_t physical_freeend;
193 1.3.6.2 yamt vm_offset_t physical_end;
194 1.3.6.2 yamt u_int free_pages;
195 1.3.6.2 yamt vm_offset_t pagetables_start;
196 1.3.6.2 yamt int physmem = 0;
197 1.3.6.2 yamt
198 1.3.6.2 yamt /* Physical and virtual addresses for some global pages */
199 1.3.6.2 yamt pv_addr_t systempage;
200 1.3.6.2 yamt pv_addr_t irqstack;
201 1.3.6.2 yamt pv_addr_t undstack;
202 1.3.6.2 yamt pv_addr_t abtstack;
203 1.3.6.2 yamt pv_addr_t kernelstack;
204 1.3.6.2 yamt pv_addr_t minidataclean;
205 1.3.6.2 yamt
206 1.3.6.2 yamt vm_offset_t msgbufphys;
207 1.3.6.2 yamt
208 1.3.6.2 yamt extern u_int data_abort_handler_address;
209 1.3.6.2 yamt extern u_int prefetch_abort_handler_address;
210 1.3.6.2 yamt extern u_int undefined_handler_address;
211 1.3.6.2 yamt extern int end;
212 1.3.6.2 yamt
213 1.3.6.2 yamt #ifdef PMAP_DEBUG
214 1.3.6.2 yamt extern int pmap_debug_level;
215 1.3.6.2 yamt #endif
216 1.3.6.2 yamt
217 1.3.6.2 yamt #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
218 1.3.6.2 yamt
219 1.3.6.2 yamt #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
220 1.3.6.2 yamt #define KERNEL_PT_KERNEL_NUM 4
221 1.3.6.2 yamt #define KERNEL_PT_IO (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
222 1.3.6.2 yamt /* L2 tables for mapping kernel VM */
223 1.3.6.2 yamt #define KERNEL_PT_VMDATA (KERNEL_PT_IO + 1)
224 1.3.6.2 yamt #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
225 1.3.6.2 yamt #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
226 1.3.6.2 yamt
227 1.3.6.2 yamt pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
228 1.3.6.2 yamt
229 1.3.6.2 yamt struct user *proc0paddr;
230 1.3.6.2 yamt
231 1.3.6.2 yamt /* Prototypes */
232 1.3.6.2 yamt
233 1.3.6.2 yamt void consinit(void);
234 1.3.6.2 yamt u_int cpu_get_control __P((void));
235 1.3.6.2 yamt
236 1.3.6.2 yamt /*
237 1.3.6.2 yamt * Define the default console speed for the board. This is generally
238 1.3.6.2 yamt * what the firmware provided with the board defaults to.
239 1.3.6.2 yamt */
240 1.3.6.2 yamt #ifndef CONSPEED
241 1.3.6.2 yamt #define CONSPEED B115200
242 1.3.6.2 yamt #endif /* ! CONSPEED */
243 1.3.6.2 yamt
244 1.3.6.2 yamt #ifndef CONUNIT
245 1.3.6.2 yamt #define CONUNIT 0
246 1.3.6.2 yamt #endif
247 1.3.6.2 yamt
248 1.3.6.2 yamt #ifndef CONMODE
249 1.3.6.2 yamt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
250 1.3.6.2 yamt #endif
251 1.3.6.2 yamt
252 1.3.6.2 yamt int comcnspeed = CONSPEED;
253 1.3.6.2 yamt int comcnmode = CONMODE;
254 1.3.6.2 yamt int comcnunit = CONUNIT;
255 1.3.6.2 yamt
256 1.3.6.2 yamt #if KGDB
257 1.3.6.2 yamt #ifndef KGDB_DEVNAME
258 1.3.6.2 yamt #error Must define KGDB_DEVNAME
259 1.3.6.2 yamt #endif
260 1.3.6.2 yamt const char kgdb_devname[] = KGDB_DEVNAME;
261 1.3.6.2 yamt
262 1.3.6.2 yamt #ifndef KGDB_DEVADDR
263 1.3.6.2 yamt #error Must define KGDB_DEVADDR
264 1.3.6.2 yamt #endif
265 1.3.6.2 yamt unsigned long kgdb_devaddr = KGDB_DEVADDR;
266 1.3.6.2 yamt
267 1.3.6.2 yamt #ifndef KGDB_DEVRATE
268 1.3.6.2 yamt #define KGDB_DEVRATE CONSPEED
269 1.3.6.2 yamt #endif
270 1.3.6.2 yamt int kgdb_devrate = KGDB_DEVRATE;
271 1.3.6.2 yamt
272 1.3.6.2 yamt #ifndef KGDB_DEVMODE
273 1.3.6.2 yamt #define KGDB_DEVMODE CONMODE
274 1.3.6.2 yamt #endif
275 1.3.6.2 yamt int kgdb_devmode = KGDB_DEVMODE;
276 1.3.6.2 yamt #endif /* KGDB */
277 1.3.6.2 yamt
278 1.3.6.2 yamt /*
279 1.3.6.2 yamt * void cpu_reboot(int howto, char *bootstr)
280 1.3.6.2 yamt *
281 1.3.6.2 yamt * Reboots the system
282 1.3.6.2 yamt *
283 1.3.6.2 yamt * Deal with any syncing, unmounting, dumping and shutdown hooks,
284 1.3.6.2 yamt * then reset the CPU.
285 1.3.6.2 yamt */
286 1.3.6.2 yamt void
287 1.3.6.2 yamt cpu_reboot(int howto, char *bootstr)
288 1.3.6.2 yamt {
289 1.3.6.2 yamt
290 1.3.6.2 yamt #ifdef DIAGNOSTIC
291 1.3.6.2 yamt /* info */
292 1.3.6.2 yamt printf("boot: howto=%08x curproc=%p\n", howto, curproc);
293 1.3.6.2 yamt #endif
294 1.3.6.2 yamt
295 1.3.6.2 yamt /*
296 1.3.6.2 yamt * If we are still cold then hit the air brakes
297 1.3.6.2 yamt * and crash to earth fast
298 1.3.6.2 yamt */
299 1.3.6.2 yamt if (cold) {
300 1.3.6.2 yamt doshutdownhooks();
301 1.3.6.2 yamt printf("The operating system has halted.\n");
302 1.3.6.2 yamt printf("Please press any key to reboot.\n\n");
303 1.3.6.2 yamt cngetc();
304 1.3.6.2 yamt goto reset;
305 1.3.6.2 yamt }
306 1.3.6.2 yamt
307 1.3.6.2 yamt /* Disable console buffering */
308 1.3.6.2 yamt
309 1.3.6.2 yamt /*
310 1.3.6.2 yamt * If RB_NOSYNC was not specified sync the discs.
311 1.3.6.2 yamt * Note: Unless cold is set to 1 here, syslogd will die during the
312 1.3.6.2 yamt * unmount. It looks like syslogd is getting woken up only to find
313 1.3.6.2 yamt * that it cannot page part of the binary in as the filesystem has
314 1.3.6.2 yamt * been unmounted.
315 1.3.6.2 yamt */
316 1.3.6.2 yamt if (!(howto & RB_NOSYNC))
317 1.3.6.2 yamt bootsync();
318 1.3.6.2 yamt
319 1.3.6.2 yamt /* Say NO to interrupts */
320 1.3.6.2 yamt splhigh();
321 1.3.6.2 yamt
322 1.3.6.2 yamt /* Do a dump if requested. */
323 1.3.6.2 yamt if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
324 1.3.6.2 yamt dumpsys();
325 1.3.6.2 yamt
326 1.3.6.2 yamt /* Run any shutdown hooks */
327 1.3.6.2 yamt doshutdownhooks();
328 1.3.6.2 yamt
329 1.3.6.2 yamt /* Make sure IRQ's are disabled */
330 1.3.6.2 yamt IRQdisable;
331 1.3.6.2 yamt
332 1.3.6.2 yamt if ((howto & (RB_HALT | RB_POWERDOWN)) == RB_HALT) {
333 1.3.6.2 yamt printf("The operating system has halted.\n");
334 1.3.6.2 yamt printf("Please press any key to reboot.\n\n");
335 1.3.6.2 yamt cngetc();
336 1.3.6.2 yamt }
337 1.3.6.2 yamt
338 1.3.6.2 yamt reset:
339 1.3.6.2 yamt /*
340 1.3.6.2 yamt * Make really really sure that all interrupts are disabled,
341 1.3.6.2 yamt */
342 1.3.6.2 yamt (void) disable_interrupts(I32_bit | F32_bit);
343 1.3.6.2 yamt
344 1.3.6.2 yamt if (howto & RB_POWERDOWN) {
345 1.3.6.2 yamt uint32_t reg;
346 1.3.6.2 yamt
347 1.3.6.2 yamt printf("powering down...\n\r");
348 1.3.6.2 yamt /* Delay to allow the UART's Tx FIFO to drain */
349 1.3.6.2 yamt delay(50000);
350 1.3.6.2 yamt
351 1.3.6.2 yamt #define GPRD(r) *((volatile uint32_t *)(IXP425_GPIO_VBASE+(r)))
352 1.3.6.2 yamt #define GPWR(r,v) *((volatile uint32_t *)(IXP425_GPIO_VBASE+(r))) = (v)
353 1.3.6.2 yamt
354 1.3.6.2 yamt /*
355 1.3.6.2 yamt * Power-down pin requires a short pulse
356 1.3.6.2 yamt */
357 1.3.6.2 yamt reg = GPRD(IXP425_GPIO_GPOUTR);
358 1.3.6.2 yamt reg |= 1u << GPIO_POWER_OFF;
359 1.3.6.2 yamt GPWR(IXP425_GPIO_GPOUTR, reg);
360 1.3.6.2 yamt
361 1.3.6.2 yamt delay(1000);
362 1.3.6.2 yamt
363 1.3.6.2 yamt reg = GPRD(IXP425_GPIO_GPOUTR);
364 1.3.6.2 yamt reg &= ~(1u << GPIO_POWER_OFF);
365 1.3.6.2 yamt GPWR(IXP425_GPIO_GPOUTR, reg);
366 1.3.6.2 yamt
367 1.3.6.2 yamt delay(500000);
368 1.3.6.2 yamt printf("POWER OFF FAILED! TRYING TO REBOOT INSTEAD\n\r");
369 1.3.6.2 yamt }
370 1.3.6.2 yamt
371 1.3.6.2 yamt printf("rebooting...\n\r");
372 1.3.6.2 yamt
373 1.3.6.2 yamt #define WDWR(r,v) *((volatile uint32_t *)(IXP425_TIMER_VBASE+(r))) = (v)
374 1.3.6.2 yamt /* Force a watchdog reset */
375 1.3.6.2 yamt WDWR(IXP425_OST_WDOG_KEY, OST_WDOG_KEY_MAJICK);
376 1.3.6.2 yamt WDWR(IXP425_OST_WDOG_ENAB, OST_WDOG_ENAB_RST_ENA);
377 1.3.6.2 yamt WDWR(IXP425_OST_WDOG, 0x1000);
378 1.3.6.2 yamt WDWR(IXP425_OST_WDOG_ENAB,
379 1.3.6.2 yamt OST_WDOG_ENAB_RST_ENA | OST_WDOG_ENAB_CNT_ENA);
380 1.3.6.2 yamt
381 1.3.6.2 yamt delay(500000);
382 1.3.6.2 yamt
383 1.3.6.2 yamt /* ...and if that didn't work, just croak. */
384 1.3.6.2 yamt printf("RESET FAILED!\n");
385 1.3.6.2 yamt
386 1.3.6.2 yamt for (;;);
387 1.3.6.2 yamt }
388 1.3.6.2 yamt
389 1.3.6.2 yamt /* Static device mappings. */
390 1.3.6.2 yamt static const struct pmap_devmap nslu2_devmap[] = {
391 1.3.6.2 yamt /* Physical/Virtual address for I/O space */
392 1.3.6.2 yamt {
393 1.3.6.2 yamt IXP425_IO_VBASE,
394 1.3.6.2 yamt IXP425_IO_HWBASE,
395 1.3.6.2 yamt IXP425_IO_SIZE,
396 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
397 1.3.6.2 yamt PTE_NOCACHE,
398 1.3.6.2 yamt },
399 1.3.6.2 yamt
400 1.3.6.2 yamt /* Expansion Bus */
401 1.3.6.2 yamt {
402 1.3.6.2 yamt IXP425_EXP_VBASE,
403 1.3.6.2 yamt IXP425_EXP_HWBASE,
404 1.3.6.2 yamt IXP425_EXP_SIZE,
405 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
406 1.3.6.2 yamt PTE_NOCACHE,
407 1.3.6.2 yamt },
408 1.3.6.2 yamt
409 1.3.6.2 yamt /* IXP425 PCI Configuration */
410 1.3.6.2 yamt {
411 1.3.6.2 yamt IXP425_PCI_VBASE,
412 1.3.6.2 yamt IXP425_PCI_HWBASE,
413 1.3.6.2 yamt IXP425_PCI_SIZE,
414 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
415 1.3.6.2 yamt PTE_NOCACHE,
416 1.3.6.2 yamt },
417 1.3.6.2 yamt
418 1.3.6.2 yamt /* SDRAM Controller */
419 1.3.6.2 yamt {
420 1.3.6.2 yamt IXP425_MCU_VBASE,
421 1.3.6.2 yamt IXP425_MCU_HWBASE,
422 1.3.6.2 yamt IXP425_MCU_SIZE,
423 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
424 1.3.6.2 yamt PTE_NOCACHE,
425 1.3.6.2 yamt },
426 1.3.6.2 yamt
427 1.3.6.2 yamt /* PCI Memory Space */
428 1.3.6.2 yamt {
429 1.3.6.2 yamt IXP425_PCI_MEM_VBASE,
430 1.3.6.2 yamt IXP425_PCI_MEM_HWBASE,
431 1.3.6.2 yamt IXP425_PCI_MEM_SIZE,
432 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
433 1.3.6.2 yamt PTE_NOCACHE,
434 1.3.6.2 yamt },
435 1.3.6.2 yamt
436 1.3.6.2 yamt /* Flash memory */
437 1.3.6.2 yamt {
438 1.3.6.2 yamt NSLU2_FLASH_VBASE,
439 1.3.6.2 yamt NSLU2_FLASH_HWBASE,
440 1.3.6.2 yamt NSLU2_FLASH_SIZE,
441 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE,
442 1.3.6.2 yamt PTE_NOCACHE,
443 1.3.6.2 yamt },
444 1.3.6.2 yamt
445 1.3.6.2 yamt {
446 1.3.6.2 yamt 0,
447 1.3.6.2 yamt 0,
448 1.3.6.2 yamt 0,
449 1.3.6.2 yamt 0,
450 1.3.6.2 yamt 0,
451 1.3.6.2 yamt }
452 1.3.6.2 yamt };
453 1.3.6.2 yamt
454 1.3.6.2 yamt /*
455 1.3.6.2 yamt * u_int initarm(...)
456 1.3.6.2 yamt *
457 1.3.6.2 yamt * Initial entry point on startup. This gets called before main() is
458 1.3.6.2 yamt * entered.
459 1.3.6.2 yamt * It should be responsible for setting up everything that must be
460 1.3.6.2 yamt * in place when main is called.
461 1.3.6.2 yamt * This includes
462 1.3.6.2 yamt * Taking a copy of the boot configuration structure.
463 1.3.6.2 yamt * Initialising the physical console so characters can be printed.
464 1.3.6.2 yamt * Setting up page tables for the kernel
465 1.3.6.2 yamt * Relocating the kernel to the bottom of physical memory
466 1.3.6.2 yamt */
467 1.3.6.2 yamt u_int
468 1.3.6.2 yamt initarm(void *arg)
469 1.3.6.2 yamt {
470 1.3.6.2 yamt extern vaddr_t xscale_cache_clean_addr;
471 1.3.6.2 yamt #ifdef DIAGNOSTIC
472 1.3.6.2 yamt extern vsize_t xscale_minidata_clean_size;
473 1.3.6.2 yamt #endif
474 1.3.6.2 yamt int loop;
475 1.3.6.2 yamt int loop1;
476 1.3.6.2 yamt u_int kerneldatasize;
477 1.3.6.2 yamt u_int l1pagetable;
478 1.3.6.2 yamt u_int freemempos;
479 1.3.6.2 yamt pv_addr_t kernel_l1pt;
480 1.3.6.2 yamt uint32_t reg;
481 1.3.6.2 yamt
482 1.3.6.2 yamt /*
483 1.3.6.2 yamt * Make sure the power-down GPIO pin is configured correctly, as
484 1.3.6.2 yamt * cpu_reboot() may be called early on (e.g. from within ddb(9)).
485 1.3.6.2 yamt */
486 1.3.6.2 yamt /* Pin is active-high, so make sure it's driven low */
487 1.3.6.2 yamt reg = GPRD(IXP425_GPIO_GPOUTR);
488 1.3.6.2 yamt reg &= ~(1u << GPIO_POWER_OFF);
489 1.3.6.2 yamt GPWR(IXP425_GPIO_GPOUTR, reg);
490 1.3.6.2 yamt
491 1.3.6.2 yamt /* Set as output */
492 1.3.6.2 yamt reg = GPRD(IXP425_GPIO_GPOER);
493 1.3.6.2 yamt reg &= ~(1u << GPIO_POWER_OFF);
494 1.3.6.2 yamt GPWR(IXP425_GPIO_GPOER, reg);
495 1.3.6.2 yamt
496 1.3.6.2 yamt /*
497 1.3.6.2 yamt * Since we map v0xf0000000 == p0xc8000000, it's possible for
498 1.3.6.2 yamt * us to initialize the console now.
499 1.3.6.2 yamt */
500 1.3.6.2 yamt consinit();
501 1.3.6.2 yamt
502 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
503 1.3.6.2 yamt /* Talk to the user */
504 1.3.6.2 yamt printf("\nNetBSD/evbarm (Linksys NSLU2) booting ...\n");
505 1.3.6.2 yamt #endif
506 1.3.6.2 yamt
507 1.3.6.2 yamt /*
508 1.3.6.2 yamt * Heads up ... Setup the CPU / MMU / TLB functions
509 1.3.6.2 yamt */
510 1.3.6.2 yamt if (set_cpufuncs())
511 1.3.6.2 yamt panic("cpu not recognized!");
512 1.3.6.2 yamt
513 1.3.6.2 yamt /* XXX overwrite bootconfig to hardcoded values */
514 1.3.6.2 yamt bootconfig.dramblocks = 1;
515 1.3.6.2 yamt bootconfig.dram[0].address = 0x10000000;
516 1.3.6.2 yamt bootconfig.dram[0].pages = ixp425_sdram_size() / PAGE_SIZE;
517 1.3.6.2 yamt
518 1.3.6.2 yamt kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
519 1.3.6.2 yamt
520 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
521 1.3.6.2 yamt printf("kernsize=0x%x\n", kerneldatasize);
522 1.3.6.2 yamt #endif
523 1.3.6.2 yamt kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
524 1.3.6.2 yamt
525 1.3.6.2 yamt /*
526 1.3.6.2 yamt * Set up the variables that define the availablilty of
527 1.3.6.2 yamt * physical memory. For now, we're going to set
528 1.3.6.2 yamt * physical_freestart to 0x10200000 (where the kernel
529 1.3.6.2 yamt * was loaded), and allocate the memory we need downwards.
530 1.3.6.2 yamt * If we get too close to the L1 table that we set up, we
531 1.3.6.2 yamt * will panic. We will update physical_freestart and
532 1.3.6.2 yamt * physical_freeend later to reflect what pmap_bootstrap()
533 1.3.6.2 yamt * wants to see.
534 1.3.6.2 yamt *
535 1.3.6.2 yamt * XXX pmap_bootstrap() needs an enema.
536 1.3.6.2 yamt */
537 1.3.6.2 yamt physical_start = bootconfig.dram[0].address;
538 1.3.6.2 yamt physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
539 1.3.6.2 yamt
540 1.3.6.2 yamt physical_freestart = physical_start
541 1.3.6.2 yamt + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
542 1.3.6.2 yamt physical_freeend = physical_end;
543 1.3.6.2 yamt
544 1.3.6.2 yamt physmem = (physical_end - physical_start) / PAGE_SIZE;
545 1.3.6.2 yamt
546 1.3.6.2 yamt /* Tell the user about the memory */
547 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
548 1.3.6.2 yamt printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
549 1.3.6.2 yamt physical_start, physical_end - 1);
550 1.3.6.2 yamt
551 1.3.6.2 yamt printf("Allocating page tables\n");
552 1.3.6.2 yamt #endif
553 1.3.6.2 yamt free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
554 1.3.6.2 yamt
555 1.3.6.2 yamt freemempos = 0x10000000;
556 1.3.6.2 yamt
557 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
558 1.3.6.2 yamt printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
559 1.3.6.2 yamt physical_start, physical_end);
560 1.3.6.2 yamt #endif
561 1.3.6.2 yamt
562 1.3.6.2 yamt /* Define a macro to simplify memory allocation */
563 1.3.6.2 yamt #define valloc_pages(var, np) \
564 1.3.6.2 yamt alloc_pages((var).pv_pa, (np)); \
565 1.3.6.2 yamt (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
566 1.3.6.2 yamt
567 1.3.6.2 yamt #if 0
568 1.3.6.2 yamt #define alloc_pages(var, np) \
569 1.3.6.2 yamt physical_freeend -= ((np) * PAGE_SIZE); \
570 1.3.6.2 yamt if (physical_freeend < physical_freestart) \
571 1.3.6.2 yamt panic("initarm: out of memory"); \
572 1.3.6.2 yamt (var) = physical_freeend; \
573 1.3.6.2 yamt free_pages -= (np); \
574 1.3.6.2 yamt memset((char *)(var), 0, ((np) * PAGE_SIZE));
575 1.3.6.2 yamt #else
576 1.3.6.2 yamt #define alloc_pages(var, np) \
577 1.3.6.2 yamt (var) = freemempos; \
578 1.3.6.2 yamt memset((char *)(var), 0, ((np) * PAGE_SIZE)); \
579 1.3.6.2 yamt freemempos += (np) * PAGE_SIZE;
580 1.3.6.2 yamt #endif
581 1.3.6.2 yamt
582 1.3.6.2 yamt loop1 = 0;
583 1.3.6.2 yamt kernel_l1pt.pv_pa = 0;
584 1.3.6.2 yamt kernel_l1pt.pv_va = 0;
585 1.3.6.2 yamt for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
586 1.3.6.2 yamt /* Are we 16KB aligned for an L1 ? */
587 1.3.6.2 yamt if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
588 1.3.6.2 yamt && kernel_l1pt.pv_pa == 0) {
589 1.3.6.2 yamt valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
590 1.3.6.2 yamt } else {
591 1.3.6.2 yamt valloc_pages(kernel_pt_table[loop1],
592 1.3.6.2 yamt L2_TABLE_SIZE / PAGE_SIZE);
593 1.3.6.2 yamt ++loop1;
594 1.3.6.2 yamt }
595 1.3.6.2 yamt }
596 1.3.6.2 yamt
597 1.3.6.2 yamt /* This should never be able to happen but better confirm that. */
598 1.3.6.2 yamt if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
599 1.3.6.2 yamt panic("initarm: Failed to align the kernel page directory");
600 1.3.6.2 yamt
601 1.3.6.2 yamt /*
602 1.3.6.2 yamt * Allocate a page for the system page.
603 1.3.6.2 yamt * This page will just contain the system vectors and can be
604 1.3.6.2 yamt * shared by all processes.
605 1.3.6.2 yamt */
606 1.3.6.2 yamt alloc_pages(systempage.pv_pa, 1);
607 1.3.6.2 yamt
608 1.3.6.2 yamt /* Allocate stacks for all modes */
609 1.3.6.2 yamt valloc_pages(irqstack, IRQ_STACK_SIZE);
610 1.3.6.2 yamt valloc_pages(abtstack, ABT_STACK_SIZE);
611 1.3.6.2 yamt valloc_pages(undstack, UND_STACK_SIZE);
612 1.3.6.2 yamt valloc_pages(kernelstack, UPAGES);
613 1.3.6.2 yamt
614 1.3.6.2 yamt /* Allocate enough pages for cleaning the Mini-Data cache. */
615 1.3.6.2 yamt KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
616 1.3.6.2 yamt valloc_pages(minidataclean, 1);
617 1.3.6.2 yamt
618 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
619 1.3.6.2 yamt printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
620 1.3.6.2 yamt irqstack.pv_va);
621 1.3.6.2 yamt printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
622 1.3.6.2 yamt abtstack.pv_va);
623 1.3.6.2 yamt printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
624 1.3.6.2 yamt undstack.pv_va);
625 1.3.6.2 yamt printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
626 1.3.6.2 yamt kernelstack.pv_va);
627 1.3.6.2 yamt #endif
628 1.3.6.2 yamt
629 1.3.6.2 yamt /*
630 1.3.6.2 yamt * XXX Defer this to later so that we can reclaim the memory
631 1.3.6.2 yamt * XXX used by the RedBoot page tables.
632 1.3.6.2 yamt */
633 1.3.6.2 yamt alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
634 1.3.6.2 yamt
635 1.3.6.2 yamt /*
636 1.3.6.2 yamt * Ok we have allocated physical pages for the primary kernel
637 1.3.6.2 yamt * page tables
638 1.3.6.2 yamt */
639 1.3.6.2 yamt
640 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
641 1.3.6.2 yamt printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
642 1.3.6.2 yamt #endif
643 1.3.6.2 yamt
644 1.3.6.2 yamt /*
645 1.3.6.2 yamt * Now we start construction of the L1 page table
646 1.3.6.2 yamt * We start by mapping the L2 page tables into the L1.
647 1.3.6.2 yamt * This means that we can replace L1 mappings later on if necessary
648 1.3.6.2 yamt */
649 1.3.6.2 yamt l1pagetable = kernel_l1pt.pv_pa;
650 1.3.6.2 yamt
651 1.3.6.2 yamt /* Map the L2 pages tables in the L1 page table */
652 1.3.6.2 yamt pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
653 1.3.6.2 yamt &kernel_pt_table[KERNEL_PT_SYS]);
654 1.3.6.2 yamt for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
655 1.3.6.2 yamt pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
656 1.3.6.2 yamt &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
657 1.3.6.2 yamt for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
658 1.3.6.2 yamt pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
659 1.3.6.2 yamt &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
660 1.3.6.2 yamt
661 1.3.6.2 yamt /* update the top of the kernel VM */
662 1.3.6.2 yamt pmap_curmaxkvaddr =
663 1.3.6.2 yamt KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
664 1.3.6.2 yamt
665 1.3.6.2 yamt pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
666 1.3.6.2 yamt &kernel_pt_table[KERNEL_PT_IO]);
667 1.3.6.2 yamt
668 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
669 1.3.6.2 yamt printf("Mapping kernel\n");
670 1.3.6.2 yamt #endif
671 1.3.6.2 yamt
672 1.3.6.2 yamt /* Now we fill in the L2 pagetable for the kernel static code/data */
673 1.3.6.2 yamt {
674 1.3.6.2 yamt extern char etext[], _end[];
675 1.3.6.2 yamt size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
676 1.3.6.2 yamt size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
677 1.3.6.2 yamt u_int logical;
678 1.3.6.2 yamt
679 1.3.6.2 yamt textsize = (textsize + PGOFSET) & ~PGOFSET;
680 1.3.6.2 yamt totalsize = (totalsize + PGOFSET) & ~PGOFSET;
681 1.3.6.2 yamt
682 1.3.6.2 yamt logical = 0x00200000; /* offset of kernel in RAM */
683 1.3.6.2 yamt
684 1.3.6.2 yamt logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
685 1.3.6.2 yamt physical_start + logical, textsize,
686 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
687 1.3.6.2 yamt logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
688 1.3.6.2 yamt physical_start + logical, totalsize - textsize,
689 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
690 1.3.6.2 yamt }
691 1.3.6.2 yamt
692 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
693 1.3.6.2 yamt printf("Constructing L2 page tables\n");
694 1.3.6.2 yamt #endif
695 1.3.6.2 yamt
696 1.3.6.2 yamt /* Map the stack pages */
697 1.3.6.2 yamt pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
698 1.3.6.2 yamt IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
699 1.3.6.2 yamt pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
700 1.3.6.2 yamt ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
701 1.3.6.2 yamt pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
702 1.3.6.2 yamt UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
703 1.3.6.2 yamt pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
704 1.3.6.2 yamt UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
705 1.3.6.2 yamt
706 1.3.6.2 yamt pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
707 1.3.6.2 yamt L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
708 1.3.6.2 yamt
709 1.3.6.2 yamt for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
710 1.3.6.2 yamt pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
711 1.3.6.2 yamt kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
712 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
713 1.3.6.2 yamt }
714 1.3.6.2 yamt
715 1.3.6.2 yamt /* Map the Mini-Data cache clean area. */
716 1.3.6.2 yamt xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
717 1.3.6.2 yamt minidataclean.pv_pa);
718 1.3.6.2 yamt
719 1.3.6.2 yamt /* Map the vector page. */
720 1.3.6.2 yamt pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
721 1.3.6.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
722 1.3.6.2 yamt
723 1.3.6.2 yamt /*
724 1.3.6.2 yamt * Map the IXP425 registers
725 1.3.6.2 yamt */
726 1.3.6.2 yamt pmap_devmap_bootstrap(l1pagetable, nslu2_devmap);
727 1.3.6.2 yamt
728 1.3.6.2 yamt /*
729 1.3.6.2 yamt * Give the XScale global cache clean code an appropriately
730 1.3.6.2 yamt * sized chunk of unmapped VA space starting at 0xff000000
731 1.3.6.2 yamt * (our device mappings end before this address).
732 1.3.6.2 yamt */
733 1.3.6.2 yamt xscale_cache_clean_addr = 0xff000000U;
734 1.3.6.2 yamt
735 1.3.6.2 yamt /*
736 1.3.6.2 yamt * Now we have the real page tables in place so we can switch to them.
737 1.3.6.2 yamt * Once this is done we will be running with the REAL kernel page
738 1.3.6.2 yamt * tables.
739 1.3.6.2 yamt */
740 1.3.6.2 yamt
741 1.3.6.2 yamt /*
742 1.3.6.2 yamt * Update the physical_freestart/physical_freeend/free_pages
743 1.3.6.2 yamt * variables.
744 1.3.6.2 yamt */
745 1.3.6.2 yamt {
746 1.3.6.2 yamt extern char _end[];
747 1.3.6.2 yamt
748 1.3.6.2 yamt physical_freestart = physical_start +
749 1.3.6.2 yamt (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
750 1.3.6.2 yamt KERNEL_BASE);
751 1.3.6.2 yamt physical_freeend = physical_end;
752 1.3.6.2 yamt free_pages =
753 1.3.6.2 yamt (physical_freeend - physical_freestart) / PAGE_SIZE;
754 1.3.6.2 yamt }
755 1.3.6.2 yamt
756 1.3.6.2 yamt /* Switch tables */
757 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
758 1.3.6.2 yamt printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
759 1.3.6.2 yamt physical_freestart, free_pages, free_pages);
760 1.3.6.2 yamt printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
761 1.3.6.2 yamt #endif
762 1.3.6.2 yamt cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
763 1.3.6.2 yamt setttb(kernel_l1pt.pv_pa);
764 1.3.6.2 yamt cpu_tlb_flushID();
765 1.3.6.2 yamt cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
766 1.3.6.2 yamt
767 1.3.6.2 yamt /*
768 1.3.6.2 yamt * Moved from cpu_startup() as data_abort_handler() references
769 1.3.6.2 yamt * this during uvm init
770 1.3.6.2 yamt */
771 1.3.6.2 yamt proc0paddr = (struct user *)kernelstack.pv_va;
772 1.3.6.2 yamt lwp0.l_addr = proc0paddr;
773 1.3.6.2 yamt
774 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
775 1.3.6.2 yamt printf("bootstrap done.\n");
776 1.3.6.2 yamt #endif
777 1.3.6.2 yamt
778 1.3.6.2 yamt arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
779 1.3.6.2 yamt
780 1.3.6.2 yamt /*
781 1.3.6.2 yamt * Pages were allocated during the secondary bootstrap for the
782 1.3.6.2 yamt * stacks for different CPU modes.
783 1.3.6.2 yamt * We must now set the r13 registers in the different CPU modes to
784 1.3.6.2 yamt * point to these stacks.
785 1.3.6.2 yamt * Since the ARM stacks use STMFD etc. we must set r13 to the top end
786 1.3.6.2 yamt * of the stack memory.
787 1.3.6.2 yamt */
788 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
789 1.3.6.2 yamt printf("init subsystems: stacks ");
790 1.3.6.2 yamt #endif
791 1.3.6.2 yamt
792 1.3.6.2 yamt set_stackptr(PSR_IRQ32_MODE,
793 1.3.6.2 yamt irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
794 1.3.6.2 yamt set_stackptr(PSR_ABT32_MODE,
795 1.3.6.2 yamt abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
796 1.3.6.2 yamt set_stackptr(PSR_UND32_MODE,
797 1.3.6.2 yamt undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
798 1.3.6.2 yamt
799 1.3.6.2 yamt /*
800 1.3.6.2 yamt * Well we should set a data abort handler.
801 1.3.6.2 yamt * Once things get going this will change as we will need a proper
802 1.3.6.2 yamt * handler.
803 1.3.6.2 yamt * Until then we will use a handler that just panics but tells us
804 1.3.6.2 yamt * why.
805 1.3.6.2 yamt * Initialisation of the vectors will just panic on a data abort.
806 1.3.6.2 yamt * This just fills in a slightly better one.
807 1.3.6.2 yamt */
808 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
809 1.3.6.2 yamt printf("vectors ");
810 1.3.6.2 yamt #endif
811 1.3.6.2 yamt data_abort_handler_address = (u_int)data_abort_handler;
812 1.3.6.2 yamt prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
813 1.3.6.2 yamt undefined_handler_address = (u_int)undefinedinstruction_bounce;
814 1.3.6.2 yamt
815 1.3.6.2 yamt /* Initialise the undefined instruction handlers */
816 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
817 1.3.6.2 yamt printf("undefined ");
818 1.3.6.2 yamt #endif
819 1.3.6.2 yamt undefined_init();
820 1.3.6.2 yamt
821 1.3.6.2 yamt /* Load memory into UVM. */
822 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
823 1.3.6.2 yamt printf("page ");
824 1.3.6.2 yamt #endif
825 1.3.6.2 yamt uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
826 1.3.6.2 yamt uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
827 1.3.6.2 yamt atop(physical_freestart), atop(physical_freeend),
828 1.3.6.2 yamt VM_FREELIST_DEFAULT);
829 1.3.6.2 yamt
830 1.3.6.2 yamt /* Boot strap pmap telling it where the kernel page table is */
831 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
832 1.3.6.2 yamt printf("pmap ");
833 1.3.6.2 yamt #endif
834 1.3.6.2 yamt pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
835 1.3.6.2 yamt KERNEL_VM_BASE + KERNEL_VM_SIZE);
836 1.3.6.2 yamt
837 1.3.6.2 yamt /* Setup the IRQ system */
838 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
839 1.3.6.2 yamt printf("irq ");
840 1.3.6.2 yamt #endif
841 1.3.6.2 yamt ixp425_intr_init();
842 1.3.6.2 yamt #ifdef VERBOSE_INIT_ARM
843 1.3.6.2 yamt printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
844 1.3.6.2 yamt #endif
845 1.3.6.2 yamt
846 1.3.6.2 yamt #ifdef BOOTHOWTO
847 1.3.6.2 yamt boothowto = BOOTHOWTO;
848 1.3.6.2 yamt #endif
849 1.3.6.2 yamt
850 1.3.6.2 yamt #ifdef IPKDB
851 1.3.6.2 yamt /* Initialise ipkdb */
852 1.3.6.2 yamt ipkdb_init();
853 1.3.6.2 yamt if (boothowto & RB_KDB)
854 1.3.6.2 yamt ipkdb_connect(0);
855 1.3.6.2 yamt #endif
856 1.3.6.2 yamt
857 1.3.6.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
858 1.3.6.2 yamt /* Firmware doesn't load symbols. */
859 1.3.6.2 yamt ksyms_init(0, NULL, NULL);
860 1.3.6.2 yamt #endif
861 1.3.6.2 yamt
862 1.3.6.2 yamt #ifdef DDB
863 1.3.6.2 yamt db_machine_init();
864 1.3.6.2 yamt if (boothowto & RB_KDB)
865 1.3.6.2 yamt Debugger();
866 1.3.6.2 yamt #endif
867 1.3.6.2 yamt
868 1.3.6.2 yamt /* We return the new stack pointer address */
869 1.3.6.2 yamt return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
870 1.3.6.2 yamt }
871 1.3.6.2 yamt
872 1.3.6.2 yamt /*
873 1.3.6.2 yamt * consinit
874 1.3.6.2 yamt */
875 1.3.6.2 yamt void
876 1.3.6.2 yamt consinit(void)
877 1.3.6.2 yamt {
878 1.3.6.2 yamt static int consinit_called;
879 1.3.6.2 yamt static const bus_addr_t addrs[2] = {
880 1.3.6.2 yamt IXP425_UART0_HWBASE, IXP425_UART1_HWBASE
881 1.3.6.2 yamt };
882 1.3.6.2 yamt
883 1.3.6.2 yamt if (consinit_called != 0)
884 1.3.6.2 yamt return;
885 1.3.6.2 yamt
886 1.3.6.2 yamt consinit_called = 1;
887 1.3.6.2 yamt
888 1.3.6.2 yamt pmap_devmap_register(nslu2_devmap);
889 1.3.6.2 yamt
890 1.3.6.2 yamt if (comcnattach(&ixp425_a4x_bs_tag, addrs[comcnunit],
891 1.3.6.2 yamt comcnspeed, IXP425_UART_FREQ, COM_TYPE_PXA2x0, comcnmode))
892 1.3.6.2 yamt panic("can't init serial console (UART%d)", comcnunit);
893 1.3.6.2 yamt }
894