netwalker_machdep.c revision 1.1.2.2 1 1.1.2.2 uebayasi /* $NetBSD: netwalker_machdep.c,v 1.1.2.2 2010/11/15 14:38:23 uebayasi Exp $ */
2 1.1.2.2 uebayasi
3 1.1.2.2 uebayasi /*
4 1.1.2.2 uebayasi * Copyright (c) 2002, 2003, 2005, 2010 Genetec Corporation.
5 1.1.2.2 uebayasi * All rights reserved.
6 1.1.2.2 uebayasi * Written by Hiroyuki Bessho for Genetec Corporation.
7 1.1.2.2 uebayasi *
8 1.1.2.2 uebayasi * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 uebayasi * modification, are permitted provided that the following conditions
10 1.1.2.2 uebayasi * are met:
11 1.1.2.2 uebayasi * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 uebayasi * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 uebayasi * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 uebayasi * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 uebayasi * documentation and/or other materials provided with the distribution.
16 1.1.2.2 uebayasi *
17 1.1.2.2 uebayasi * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
18 1.1.2.2 uebayasi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 1.1.2.2 uebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1.1.2.2 uebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
21 1.1.2.2 uebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 1.1.2.2 uebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.1.2.2 uebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1.2.2 uebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.1.2.2 uebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.1.2.2 uebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1.2.2 uebayasi * POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 uebayasi *
29 1.1.2.2 uebayasi * Machine dependant functions for kernel setup for Sharp Netwalker.
30 1.1.2.2 uebayasi * Based on iq80310_machhdep.c
31 1.1.2.2 uebayasi */
32 1.1.2.2 uebayasi /*
33 1.1.2.2 uebayasi * Copyright (c) 2001 Wasabi Systems, Inc.
34 1.1.2.2 uebayasi * All rights reserved.
35 1.1.2.2 uebayasi *
36 1.1.2.2 uebayasi * Written by Jason R. Thorpe for Wasabi Systems, Inc.
37 1.1.2.2 uebayasi *
38 1.1.2.2 uebayasi * Redistribution and use in source and binary forms, with or without
39 1.1.2.2 uebayasi * modification, are permitted provided that the following conditions
40 1.1.2.2 uebayasi * are met:
41 1.1.2.2 uebayasi * 1. Redistributions of source code must retain the above copyright
42 1.1.2.2 uebayasi * notice, this list of conditions and the following disclaimer.
43 1.1.2.2 uebayasi * 2. Redistributions in binary form must reproduce the above copyright
44 1.1.2.2 uebayasi * notice, this list of conditions and the following disclaimer in the
45 1.1.2.2 uebayasi * documentation and/or other materials provided with the distribution.
46 1.1.2.2 uebayasi * 3. All advertising materials mentioning features or use of this software
47 1.1.2.2 uebayasi * must display the following acknowledgement:
48 1.1.2.2 uebayasi * This product includes software developed for the NetBSD Project by
49 1.1.2.2 uebayasi * Wasabi Systems, Inc.
50 1.1.2.2 uebayasi * 4. The name of Wasabi Systems, Inc. may not be used to endorse
51 1.1.2.2 uebayasi * or promote products derived from this software without specific prior
52 1.1.2.2 uebayasi * written permission.
53 1.1.2.2 uebayasi *
54 1.1.2.2 uebayasi * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
55 1.1.2.2 uebayasi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 1.1.2.2 uebayasi * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 1.1.2.2 uebayasi * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
58 1.1.2.2 uebayasi * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 1.1.2.2 uebayasi * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 1.1.2.2 uebayasi * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 1.1.2.2 uebayasi * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 1.1.2.2 uebayasi * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 1.1.2.2 uebayasi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 1.1.2.2 uebayasi * POSSIBILITY OF SUCH DAMAGE.
65 1.1.2.2 uebayasi */
66 1.1.2.2 uebayasi
67 1.1.2.2 uebayasi /*
68 1.1.2.2 uebayasi * Copyright (c) 1997,1998 Mark Brinicombe.
69 1.1.2.2 uebayasi * Copyright (c) 1997,1998 Causality Limited.
70 1.1.2.2 uebayasi * All rights reserved.
71 1.1.2.2 uebayasi *
72 1.1.2.2 uebayasi * Redistribution and use in source and binary forms, with or without
73 1.1.2.2 uebayasi * modification, are permitted provided that the following conditions
74 1.1.2.2 uebayasi * are met:
75 1.1.2.2 uebayasi * 1. Redistributions of source code must retain the above copyright
76 1.1.2.2 uebayasi * notice, this list of conditions and the following disclaimer.
77 1.1.2.2 uebayasi * 2. Redistributions in binary form must reproduce the above copyright
78 1.1.2.2 uebayasi * notice, this list of conditions and the following disclaimer in the
79 1.1.2.2 uebayasi * documentation and/or other materials provided with the distribution.
80 1.1.2.2 uebayasi * 3. All advertising materials mentioning features or use of this software
81 1.1.2.2 uebayasi * must display the following acknowledgement:
82 1.1.2.2 uebayasi * This product includes software developed by Mark Brinicombe
83 1.1.2.2 uebayasi * for the NetBSD Project.
84 1.1.2.2 uebayasi * 4. The name of the company nor the name of the author may be used to
85 1.1.2.2 uebayasi * endorse or promote products derived from this software without specific
86 1.1.2.2 uebayasi * prior written permission.
87 1.1.2.2 uebayasi *
88 1.1.2.2 uebayasi * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
89 1.1.2.2 uebayasi * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
90 1.1.2.2 uebayasi * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
91 1.1.2.2 uebayasi * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
92 1.1.2.2 uebayasi * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
93 1.1.2.2 uebayasi * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
94 1.1.2.2 uebayasi * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
95 1.1.2.2 uebayasi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96 1.1.2.2 uebayasi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
97 1.1.2.2 uebayasi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
98 1.1.2.2 uebayasi * SUCH DAMAGE.
99 1.1.2.2 uebayasi *
100 1.1.2.2 uebayasi * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
101 1.1.2.2 uebayasi * boards using RedBoot firmware.
102 1.1.2.2 uebayasi */
103 1.1.2.2 uebayasi
104 1.1.2.2 uebayasi #include <sys/cdefs.h>
105 1.1.2.2 uebayasi __KERNEL_RCSID(0, "$NetBSD: netwalker_machdep.c,v 1.1.2.2 2010/11/15 14:38:23 uebayasi Exp $");
106 1.1.2.2 uebayasi
107 1.1.2.2 uebayasi #include "opt_ddb.h"
108 1.1.2.2 uebayasi #include "opt_kgdb.h"
109 1.1.2.2 uebayasi #include "opt_ipkdb.h"
110 1.1.2.2 uebayasi #include "opt_pmap_debug.h"
111 1.1.2.2 uebayasi #include "opt_md.h"
112 1.1.2.2 uebayasi #include "opt_com.h"
113 1.1.2.2 uebayasi #include "md.h"
114 1.1.2.2 uebayasi #include "imxuart.h"
115 1.1.2.2 uebayasi #include "opt_imxuart.h"
116 1.1.2.2 uebayasi #include "opt_imx.h"
117 1.1.2.2 uebayasi
118 1.1.2.2 uebayasi #include <sys/param.h>
119 1.1.2.2 uebayasi #include <sys/device.h>
120 1.1.2.2 uebayasi #include <sys/systm.h>
121 1.1.2.2 uebayasi #include <sys/kernel.h>
122 1.1.2.2 uebayasi #include <sys/exec.h>
123 1.1.2.2 uebayasi #include <sys/proc.h>
124 1.1.2.2 uebayasi #include <sys/msgbuf.h>
125 1.1.2.2 uebayasi #include <sys/reboot.h>
126 1.1.2.2 uebayasi #include <sys/termios.h>
127 1.1.2.2 uebayasi #include <sys/ksyms.h>
128 1.1.2.2 uebayasi
129 1.1.2.2 uebayasi #include <uvm/uvm_extern.h>
130 1.1.2.2 uebayasi
131 1.1.2.2 uebayasi #include <sys/conf.h>
132 1.1.2.2 uebayasi #include <dev/cons.h>
133 1.1.2.2 uebayasi #include <dev/md.h>
134 1.1.2.2 uebayasi
135 1.1.2.2 uebayasi #include <machine/db_machdep.h>
136 1.1.2.2 uebayasi #include <ddb/db_sym.h>
137 1.1.2.2 uebayasi #include <ddb/db_extern.h>
138 1.1.2.2 uebayasi #ifdef KGDB
139 1.1.2.2 uebayasi #include <sys/kgdb.h>
140 1.1.2.2 uebayasi #endif
141 1.1.2.2 uebayasi
142 1.1.2.2 uebayasi #include <machine/bootconfig.h>
143 1.1.2.2 uebayasi #include <machine/bus.h>
144 1.1.2.2 uebayasi #include <machine/cpu.h>
145 1.1.2.2 uebayasi #include <machine/frame.h>
146 1.1.2.2 uebayasi #include <arm/undefined.h>
147 1.1.2.2 uebayasi
148 1.1.2.2 uebayasi #include <arm/arm32/pte.h>
149 1.1.2.2 uebayasi #include <arm/arm32/machdep.h>
150 1.1.2.2 uebayasi
151 1.1.2.2 uebayasi #include <arm/imx/imx51reg.h>
152 1.1.2.2 uebayasi #include <arm/imx/imx51var.h>
153 1.1.2.2 uebayasi #include <arm/imx/imxgpioreg.h>
154 1.1.2.2 uebayasi #include <arm/imx/imxwdogreg.h>
155 1.1.2.2 uebayasi #include <arm/imx/imxuartreg.h>
156 1.1.2.2 uebayasi #include <arm/imx/imxuartvar.h>
157 1.1.2.2 uebayasi #include <arm/imx/imx51_iomuxreg.h>
158 1.1.2.2 uebayasi #include <evbarm/netwalker/netwalker_reg.h>
159 1.1.2.2 uebayasi
160 1.1.2.2 uebayasi /* Kernel text starts 1MB in from the bottom of the kernel address space. */
161 1.1.2.2 uebayasi #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00100000)
162 1.1.2.2 uebayasi #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
163 1.1.2.2 uebayasi
164 1.1.2.2 uebayasi /*
165 1.1.2.2 uebayasi * The range 0xc1000000 - 0xccffffff is available for kernel VM space
166 1.1.2.2 uebayasi * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
167 1.1.2.2 uebayasi */
168 1.1.2.2 uebayasi #define KERNEL_VM_SIZE 0x0C000000
169 1.1.2.2 uebayasi
170 1.1.2.2 uebayasi
171 1.1.2.2 uebayasi /*
172 1.1.2.2 uebayasi * Address to call from cpu_reset() to reset the machine.
173 1.1.2.2 uebayasi * This is machine architecture dependant as it varies depending
174 1.1.2.2 uebayasi * on where the ROM appears when you turn the MMU off.
175 1.1.2.2 uebayasi */
176 1.1.2.2 uebayasi
177 1.1.2.2 uebayasi u_int cpu_reset_address = 0;
178 1.1.2.2 uebayasi
179 1.1.2.2 uebayasi /* Define various stack sizes in pages */
180 1.1.2.2 uebayasi #define FIQ_STACK_SIZE 1
181 1.1.2.2 uebayasi #define IRQ_STACK_SIZE 1
182 1.1.2.2 uebayasi #define ABT_STACK_SIZE 1
183 1.1.2.2 uebayasi #ifdef IPKDB
184 1.1.2.2 uebayasi #define UND_STACK_SIZE 2
185 1.1.2.2 uebayasi #else
186 1.1.2.2 uebayasi #define UND_STACK_SIZE 1
187 1.1.2.2 uebayasi #endif
188 1.1.2.2 uebayasi
189 1.1.2.2 uebayasi BootConfig bootconfig; /* Boot config storage */
190 1.1.2.2 uebayasi char *boot_args = NULL;
191 1.1.2.2 uebayasi char *boot_file = NULL;
192 1.1.2.2 uebayasi
193 1.1.2.2 uebayasi vm_offset_t physical_start;
194 1.1.2.2 uebayasi vm_offset_t physical_freestart;
195 1.1.2.2 uebayasi vm_offset_t physical_freeend;
196 1.1.2.2 uebayasi vm_offset_t physical_end;
197 1.1.2.2 uebayasi u_int free_pages;
198 1.1.2.2 uebayasi vm_offset_t pagetables_start;
199 1.1.2.2 uebayasi
200 1.1.2.2 uebayasi /*int debug_flags;*/
201 1.1.2.2 uebayasi #ifndef PMAP_STATIC_L1S
202 1.1.2.2 uebayasi int max_processes = 64; /* Default number */
203 1.1.2.2 uebayasi #endif /* !PMAP_STATIC_L1S */
204 1.1.2.2 uebayasi
205 1.1.2.2 uebayasi /* Physical and virtual addresses for some global pages */
206 1.1.2.2 uebayasi pv_addr_t fiqstack;
207 1.1.2.2 uebayasi pv_addr_t irqstack;
208 1.1.2.2 uebayasi pv_addr_t undstack;
209 1.1.2.2 uebayasi pv_addr_t abtstack;
210 1.1.2.2 uebayasi pv_addr_t kernelstack;
211 1.1.2.2 uebayasi
212 1.1.2.2 uebayasi vm_offset_t msgbufphys;
213 1.1.2.2 uebayasi
214 1.1.2.2 uebayasi extern u_int data_abort_handler_address;
215 1.1.2.2 uebayasi extern u_int prefetch_abort_handler_address;
216 1.1.2.2 uebayasi extern u_int undefined_handler_address;
217 1.1.2.2 uebayasi extern char KERNEL_BASE_phys[];
218 1.1.2.2 uebayasi extern char KERNEL_BASE_virt[];
219 1.1.2.2 uebayasi extern char etext[], __data_start[], _edata[], __bss_start[], __bss_end__[];
220 1.1.2.2 uebayasi extern char _end[];
221 1.1.2.2 uebayasi extern int cpu_do_powersave;
222 1.1.2.2 uebayasi
223 1.1.2.2 uebayasi #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
224 1.1.2.2 uebayasi #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
225 1.1.2.2 uebayasi #define KERNEL_PT_KERNEL_NUM 4
226 1.1.2.2 uebayasi #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
227 1.1.2.2 uebayasi /* Page tables for mapping kernel VM */
228 1.1.2.2 uebayasi #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
229 1.1.2.2 uebayasi #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
230 1.1.2.2 uebayasi
231 1.1.2.2 uebayasi pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
232 1.1.2.2 uebayasi
233 1.1.2.2 uebayasi /*
234 1.1.2.2 uebayasi * Macros to translate between physical and virtual for a subset of the
235 1.1.2.2 uebayasi * kernel address space. *Not* for general use.
236 1.1.2.2 uebayasi */
237 1.1.2.2 uebayasi #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
238 1.1.2.2 uebayasi #define KERNEL_BASE_VIRT ((vaddr_t)&KERNEL_BASE_virt)
239 1.1.2.2 uebayasi #define KERN_VTOPHYS(va) \
240 1.1.2.2 uebayasi ((paddr_t)((vaddr_t)va - KERNEL_BASE_VIRT + KERNEL_BASE_PHYS))
241 1.1.2.2 uebayasi #define KERN_PHYSTOV(pa) \
242 1.1.2.2 uebayasi ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE_VIRT))
243 1.1.2.2 uebayasi
244 1.1.2.2 uebayasi
245 1.1.2.2 uebayasi /* Prototypes */
246 1.1.2.2 uebayasi
247 1.1.2.2 uebayasi void consinit(void);
248 1.1.2.2 uebayasi #if 0
249 1.1.2.2 uebayasi void process_kernel_args(char *);
250 1.1.2.2 uebayasi #endif
251 1.1.2.2 uebayasi
252 1.1.2.2 uebayasi #ifdef KGDB
253 1.1.2.2 uebayasi void kgdb_port_init(void);
254 1.1.2.2 uebayasi #endif
255 1.1.2.2 uebayasi void change_clock(uint32_t v);
256 1.1.2.2 uebayasi
257 1.1.2.2 uebayasi static void init_clocks(void);
258 1.1.2.2 uebayasi static void setup_ioports(void);
259 1.1.2.2 uebayasi #ifdef DEBUG_IOPORTS
260 1.1.2.2 uebayasi void dump_registers(void);
261 1.1.2.2 uebayasi #endif
262 1.1.2.2 uebayasi
263 1.1.2.2 uebayasi bs_protos(bs_notimpl);
264 1.1.2.2 uebayasi
265 1.1.2.2 uebayasi #ifndef CONSPEED
266 1.1.2.2 uebayasi #define CONSPEED B115200 /* What RedBoot uses */
267 1.1.2.2 uebayasi #endif
268 1.1.2.2 uebayasi #ifndef CONMODE
269 1.1.2.2 uebayasi #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
270 1.1.2.2 uebayasi #endif
271 1.1.2.2 uebayasi
272 1.1.2.2 uebayasi int comcnspeed = CONSPEED;
273 1.1.2.2 uebayasi int comcnmode = CONMODE;
274 1.1.2.2 uebayasi
275 1.1.2.2 uebayasi /*
276 1.1.2.2 uebayasi * void cpu_reboot(int howto, char *bootstr)
277 1.1.2.2 uebayasi *
278 1.1.2.2 uebayasi * Reboots the system
279 1.1.2.2 uebayasi *
280 1.1.2.2 uebayasi * Deal with any syncing, unmounting, dumping and shutdown hooks,
281 1.1.2.2 uebayasi * then reset the CPU.
282 1.1.2.2 uebayasi */
283 1.1.2.2 uebayasi void
284 1.1.2.2 uebayasi cpu_reboot(int howto, char *bootstr)
285 1.1.2.2 uebayasi {
286 1.1.2.2 uebayasi #ifdef DIAGNOSTIC
287 1.1.2.2 uebayasi /* info */
288 1.1.2.2 uebayasi printf("boot: howto=%08x curproc=%p\n", howto, curproc);
289 1.1.2.2 uebayasi #endif
290 1.1.2.2 uebayasi
291 1.1.2.2 uebayasi /*
292 1.1.2.2 uebayasi * If we are still cold then hit the air brakes
293 1.1.2.2 uebayasi * and crash to earth fast
294 1.1.2.2 uebayasi */
295 1.1.2.2 uebayasi if (cold) {
296 1.1.2.2 uebayasi doshutdownhooks();
297 1.1.2.2 uebayasi pmf_system_shutdown(boothowto);
298 1.1.2.2 uebayasi printf("The operating system has halted.\n");
299 1.1.2.2 uebayasi printf("Please press any key to reboot.\n\n");
300 1.1.2.2 uebayasi cngetc();
301 1.1.2.2 uebayasi printf("rebooting...\n");
302 1.1.2.2 uebayasi cpu_reset();
303 1.1.2.2 uebayasi /*NOTREACHED*/
304 1.1.2.2 uebayasi }
305 1.1.2.2 uebayasi
306 1.1.2.2 uebayasi /* Disable console buffering */
307 1.1.2.2 uebayasi /* cnpollc(1);*/
308 1.1.2.2 uebayasi
309 1.1.2.2 uebayasi /*
310 1.1.2.2 uebayasi * If RB_NOSYNC was not specified sync the discs.
311 1.1.2.2 uebayasi * Note: Unless cold is set to 1 here, syslogd will die during the
312 1.1.2.2 uebayasi * unmount. It looks like syslogd is getting woken up only to find
313 1.1.2.2 uebayasi * that it cannot page part of the binary in as the filesystem has
314 1.1.2.2 uebayasi * been unmounted.
315 1.1.2.2 uebayasi */
316 1.1.2.2 uebayasi if (!(howto & RB_NOSYNC))
317 1.1.2.2 uebayasi bootsync();
318 1.1.2.2 uebayasi
319 1.1.2.2 uebayasi /* Say NO to interrupts */
320 1.1.2.2 uebayasi splhigh();
321 1.1.2.2 uebayasi
322 1.1.2.2 uebayasi /* Do a dump if requested. */
323 1.1.2.2 uebayasi if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
324 1.1.2.2 uebayasi dumpsys();
325 1.1.2.2 uebayasi
326 1.1.2.2 uebayasi /* Run any shutdown hooks */
327 1.1.2.2 uebayasi doshutdownhooks();
328 1.1.2.2 uebayasi
329 1.1.2.2 uebayasi pmf_system_shutdown(boothowto);
330 1.1.2.2 uebayasi
331 1.1.2.2 uebayasi /* Make sure IRQ's are disabled */
332 1.1.2.2 uebayasi IRQdisable;
333 1.1.2.2 uebayasi
334 1.1.2.2 uebayasi if (howto & RB_HALT) {
335 1.1.2.2 uebayasi printf("The operating system has halted.\n");
336 1.1.2.2 uebayasi printf("Please press any key to reboot.\n\n");
337 1.1.2.2 uebayasi cngetc();
338 1.1.2.2 uebayasi }
339 1.1.2.2 uebayasi
340 1.1.2.2 uebayasi printf("rebooting...\n");
341 1.1.2.2 uebayasi cpu_reset();
342 1.1.2.2 uebayasi /*NOTREACHED*/
343 1.1.2.2 uebayasi }
344 1.1.2.2 uebayasi
345 1.1.2.2 uebayasi /*
346 1.1.2.2 uebayasi * Static device mappings. These peripheral registers are mapped at
347 1.1.2.2 uebayasi * fixed virtual addresses very early in netwalker_start() so that we
348 1.1.2.2 uebayasi * can use them while booting the kernel, and stay at the same address
349 1.1.2.2 uebayasi * throughout whole kernel's life time.
350 1.1.2.2 uebayasi *
351 1.1.2.2 uebayasi * We use this table twice; once with bootstrap page table, and once
352 1.1.2.2 uebayasi * with kernel's page table which we build up in initarm().
353 1.1.2.2 uebayasi */
354 1.1.2.2 uebayasi
355 1.1.2.2 uebayasi #define _A(a) ((a) & ~L1_S_OFFSET)
356 1.1.2.2 uebayasi #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
357 1.1.2.2 uebayasi
358 1.1.2.2 uebayasi static const struct pmap_devmap netwalker_devmap[] = {
359 1.1.2.2 uebayasi {
360 1.1.2.2 uebayasi /* for UART1, IOMUXC */
361 1.1.2.2 uebayasi NETWALKER_IO_VBASE0,
362 1.1.2.2 uebayasi _A(NETWALKER_IO_PBASE0),
363 1.1.2.2 uebayasi L1_S_SIZE * 4,
364 1.1.2.2 uebayasi VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE
365 1.1.2.2 uebayasi },
366 1.1.2.2 uebayasi {0, 0, 0, 0, 0 }
367 1.1.2.2 uebayasi };
368 1.1.2.2 uebayasi
369 1.1.2.2 uebayasi #ifndef MEMSTART
370 1.1.2.2 uebayasi #define MEMSTART 0x90000000
371 1.1.2.2 uebayasi #endif
372 1.1.2.2 uebayasi #ifndef MEMSIZE
373 1.1.2.2 uebayasi #define MEMSIZE 512
374 1.1.2.2 uebayasi #endif
375 1.1.2.2 uebayasi
376 1.1.2.2 uebayasi /*
377 1.1.2.2 uebayasi * u_int initarm(...)
378 1.1.2.2 uebayasi *
379 1.1.2.2 uebayasi * Initial entry point on startup. This gets called before main() is
380 1.1.2.2 uebayasi * entered.
381 1.1.2.2 uebayasi * It should be responsible for setting up everything that must be
382 1.1.2.2 uebayasi * in place when main is called.
383 1.1.2.2 uebayasi * This includes
384 1.1.2.2 uebayasi * Taking a copy of the boot configuration structure.
385 1.1.2.2 uebayasi * Initialising the physical console so characters can be printed.
386 1.1.2.2 uebayasi * Setting up page tables for the kernel
387 1.1.2.2 uebayasi * Relocating the kernel to the bottom of physical memory
388 1.1.2.2 uebayasi */
389 1.1.2.2 uebayasi u_int
390 1.1.2.2 uebayasi initarm(void *arg)
391 1.1.2.2 uebayasi {
392 1.1.2.2 uebayasi int loop;
393 1.1.2.2 uebayasi int loop1;
394 1.1.2.2 uebayasi vaddr_t l1pagetable;
395 1.1.2.2 uebayasi
396 1.1.2.2 uebayasi #ifdef RBFLAGS
397 1.1.2.2 uebayasi boothowto |= RBFLAGS;
398 1.1.2.2 uebayasi #endif
399 1.1.2.2 uebayasi
400 1.1.2.2 uebayasi disable_interrupts(I32_bit|F32_bit);
401 1.1.2.2 uebayasi /* XXX move to netwalker_start.S */
402 1.1.2.2 uebayasi
403 1.1.2.2 uebayasi /* Register devmap for devices we mapped in start */
404 1.1.2.2 uebayasi pmap_devmap_register(netwalker_devmap);
405 1.1.2.2 uebayasi
406 1.1.2.2 uebayasi setup_ioports();
407 1.1.2.2 uebayasi
408 1.1.2.2 uebayasi consinit();
409 1.1.2.2 uebayasi
410 1.1.2.2 uebayasi #ifdef DEBUG_IOPORTS
411 1.1.2.2 uebayasi dump_registers();
412 1.1.2.2 uebayasi #endif
413 1.1.2.2 uebayasi
414 1.1.2.2 uebayasi /*
415 1.1.2.2 uebayasi * Heads up ... Setup the CPU / MMU / TLB functions
416 1.1.2.2 uebayasi */
417 1.1.2.2 uebayasi if (set_cpufuncs())
418 1.1.2.2 uebayasi panic("cpu not recognized!");
419 1.1.2.2 uebayasi
420 1.1.2.2 uebayasi #ifdef NO_POWERSAVE
421 1.1.2.2 uebayasi cpu_do_powersave=0;
422 1.1.2.2 uebayasi #endif
423 1.1.2.2 uebayasi
424 1.1.2.2 uebayasi init_clocks();
425 1.1.2.2 uebayasi
426 1.1.2.2 uebayasi #ifdef KGDB
427 1.1.2.2 uebayasi kgdb_port_init();
428 1.1.2.2 uebayasi #endif
429 1.1.2.2 uebayasi
430 1.1.2.2 uebayasi /* Talk to the user */
431 1.1.2.2 uebayasi printf("\nNetBSD/evbarm (netwalker) booting ...\n");
432 1.1.2.2 uebayasi
433 1.1.2.2 uebayasi /*
434 1.1.2.2 uebayasi * Ok we have the following memory map
435 1.1.2.2 uebayasi *
436 1.1.2.2 uebayasi * Physical Address Range Description
437 1.1.2.2 uebayasi * ----------------------- ----------------------------------
438 1.1.2.2 uebayasi *
439 1.1.2.2 uebayasi * 0x90000000 - 0x97FFFFFF DDR SDRAM (128MByte)
440 1.1.2.2 uebayasi *
441 1.1.2.2 uebayasi * The initarm() has the responsibility for creating the kernel
442 1.1.2.2 uebayasi * page tables.
443 1.1.2.2 uebayasi * It must also set up various memory pointers that are used
444 1.1.2.2 uebayasi * by pmap etc.
445 1.1.2.2 uebayasi */
446 1.1.2.2 uebayasi
447 1.1.2.2 uebayasi #if 0
448 1.1.2.2 uebayasi /*
449 1.1.2.2 uebayasi * Examine the boot args string for options we need to know about
450 1.1.2.2 uebayasi * now.
451 1.1.2.2 uebayasi */
452 1.1.2.2 uebayasi process_kernel_args((char *)nwbootinfo.bt_args);
453 1.1.2.2 uebayasi #endif
454 1.1.2.2 uebayasi
455 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
456 1.1.2.2 uebayasi printf("initarm: Configuring system ...\n");
457 1.1.2.2 uebayasi #endif
458 1.1.2.2 uebayasi /* Fake bootconfig structure for the benefit of pmap.c */
459 1.1.2.2 uebayasi /* XXX must make the memory description h/w independent */
460 1.1.2.2 uebayasi bootconfig.dramblocks = 1;
461 1.1.2.2 uebayasi bootconfig.dram[0].address = MEMSTART;
462 1.1.2.2 uebayasi bootconfig.dram[0].pages = (MEMSIZE * 1024 * 1024)/ PAGE_SIZE;
463 1.1.2.2 uebayasi
464 1.1.2.2 uebayasi /*
465 1.1.2.2 uebayasi * Set up the variables that define the availablilty of
466 1.1.2.2 uebayasi * physical memory. For now, we're going to set
467 1.1.2.2 uebayasi * physical_freestart to 0x80100000 (where the kernel
468 1.1.2.2 uebayasi * was loaded), and allocate the memory we need downwards.
469 1.1.2.2 uebayasi * If we get too close to the bottom of SDRAM, we
470 1.1.2.2 uebayasi * will panic. We will update physical_freestart and
471 1.1.2.2 uebayasi * physical_freeend later to reflect what pmap_bootstrap()
472 1.1.2.2 uebayasi * wants to see.
473 1.1.2.2 uebayasi *
474 1.1.2.2 uebayasi * XXX pmap_bootstrap() needs an enema.
475 1.1.2.2 uebayasi */
476 1.1.2.2 uebayasi physical_start = bootconfig.dram[0].address;
477 1.1.2.2 uebayasi physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
478 1.1.2.2 uebayasi
479 1.1.2.2 uebayasi physical_freestart = 0x90000000UL; /* top of loadaddres */
480 1.1.2.2 uebayasi physical_freeend = 0x90100000UL; /* base of kernel */
481 1.1.2.2 uebayasi
482 1.1.2.2 uebayasi physmem = (physical_end - physical_start) / PAGE_SIZE;
483 1.1.2.2 uebayasi
484 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
485 1.1.2.2 uebayasi /* Tell the user about the memory */
486 1.1.2.2 uebayasi printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
487 1.1.2.2 uebayasi physical_start, physical_end - 1);
488 1.1.2.2 uebayasi #endif
489 1.1.2.2 uebayasi
490 1.1.2.2 uebayasi /*
491 1.1.2.2 uebayasi * Okay, the kernel starts 1MB in from the bottom of physical
492 1.1.2.2 uebayasi * memory. We are going to allocate our bootstrap pages downwards
493 1.1.2.2 uebayasi * from there.
494 1.1.2.2 uebayasi *
495 1.1.2.2 uebayasi * We need to allocate some fixed page tables to get the kernel
496 1.1.2.2 uebayasi * going. We allocate one page directory and a number of page
497 1.1.2.2 uebayasi * tables and store the physical addresses in the kernel_pt_table
498 1.1.2.2 uebayasi * array.
499 1.1.2.2 uebayasi *
500 1.1.2.2 uebayasi * The kernel page directory must be on a 16K boundary. The page
501 1.1.2.2 uebayasi * tables must be on 4K boundaries. What we do is allocate the
502 1.1.2.2 uebayasi * page directory on the first 16K boundary that we encounter, and
503 1.1.2.2 uebayasi * the page tables on 4K boundaries otherwise. Since we allocate
504 1.1.2.2 uebayasi * at least 3 L2 page tables, we are guaranteed to encounter at
505 1.1.2.2 uebayasi * least one 16K aligned region.
506 1.1.2.2 uebayasi */
507 1.1.2.2 uebayasi
508 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
509 1.1.2.2 uebayasi printf("Allocating page tables\n");
510 1.1.2.2 uebayasi #endif
511 1.1.2.2 uebayasi
512 1.1.2.2 uebayasi free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
513 1.1.2.2 uebayasi
514 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
515 1.1.2.2 uebayasi printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
516 1.1.2.2 uebayasi physical_freestart, free_pages, free_pages);
517 1.1.2.2 uebayasi #endif
518 1.1.2.2 uebayasi
519 1.1.2.2 uebayasi /* Define a macro to simplify memory allocation */
520 1.1.2.2 uebayasi #define valloc_pages(var, np) \
521 1.1.2.2 uebayasi alloc_pages((var).pv_pa, (np)); \
522 1.1.2.2 uebayasi (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
523 1.1.2.2 uebayasi
524 1.1.2.2 uebayasi #define alloc_pages(var, np) \
525 1.1.2.2 uebayasi physical_freeend -= ((np) * PAGE_SIZE); \
526 1.1.2.2 uebayasi if (physical_freeend < physical_freestart) \
527 1.1.2.2 uebayasi panic("initarm: out of memory"); \
528 1.1.2.2 uebayasi (var) = physical_freeend; \
529 1.1.2.2 uebayasi free_pages -= (np); \
530 1.1.2.2 uebayasi memset((char *)(var), 0, ((np) * PAGE_SIZE));
531 1.1.2.2 uebayasi
532 1.1.2.2 uebayasi loop1 = 0;
533 1.1.2.2 uebayasi for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
534 1.1.2.2 uebayasi /* Are we 16KB aligned for an L1 ? */
535 1.1.2.2 uebayasi if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
536 1.1.2.2 uebayasi && kernel_l1pt.pv_pa == 0) {
537 1.1.2.2 uebayasi valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
538 1.1.2.2 uebayasi } else {
539 1.1.2.2 uebayasi valloc_pages(kernel_pt_table[loop1],
540 1.1.2.2 uebayasi L2_TABLE_SIZE / PAGE_SIZE);
541 1.1.2.2 uebayasi ++loop1;
542 1.1.2.2 uebayasi }
543 1.1.2.2 uebayasi }
544 1.1.2.2 uebayasi
545 1.1.2.2 uebayasi /* This should never be able to happen but better confirm that. */
546 1.1.2.2 uebayasi if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
547 1.1.2.2 uebayasi panic("initarm: Failed to align the kernel page directory");
548 1.1.2.2 uebayasi
549 1.1.2.2 uebayasi /*
550 1.1.2.2 uebayasi * Allocate a page for the system page mapped to V0x00000000
551 1.1.2.2 uebayasi * This page will just contain the system vectors and can be
552 1.1.2.2 uebayasi * shared by all processes.
553 1.1.2.2 uebayasi */
554 1.1.2.2 uebayasi valloc_pages(systempage, 1);
555 1.1.2.2 uebayasi systempage.pv_va = ARM_VECTORS_HIGH;
556 1.1.2.2 uebayasi
557 1.1.2.2 uebayasi /* Allocate stacks for all modes */
558 1.1.2.2 uebayasi valloc_pages(fiqstack, FIQ_STACK_SIZE);
559 1.1.2.2 uebayasi valloc_pages(irqstack, IRQ_STACK_SIZE);
560 1.1.2.2 uebayasi valloc_pages(abtstack, ABT_STACK_SIZE);
561 1.1.2.2 uebayasi valloc_pages(undstack, UND_STACK_SIZE);
562 1.1.2.2 uebayasi valloc_pages(kernelstack, UPAGES);
563 1.1.2.2 uebayasi
564 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
565 1.1.2.2 uebayasi printf("FIQ stack: p0x%08lx v0x%08lx\n", fiqstack.pv_pa,
566 1.1.2.2 uebayasi fiqstack.pv_va);
567 1.1.2.2 uebayasi printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
568 1.1.2.2 uebayasi irqstack.pv_va);
569 1.1.2.2 uebayasi printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
570 1.1.2.2 uebayasi abtstack.pv_va);
571 1.1.2.2 uebayasi printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
572 1.1.2.2 uebayasi undstack.pv_va);
573 1.1.2.2 uebayasi printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
574 1.1.2.2 uebayasi kernelstack.pv_va);
575 1.1.2.2 uebayasi #endif
576 1.1.2.2 uebayasi
577 1.1.2.2 uebayasi alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
578 1.1.2.2 uebayasi
579 1.1.2.2 uebayasi /*
580 1.1.2.2 uebayasi * Ok we have allocated physical pages for the primary kernel
581 1.1.2.2 uebayasi * page tables
582 1.1.2.2 uebayasi */
583 1.1.2.2 uebayasi
584 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
585 1.1.2.2 uebayasi printf("Creating L1 page table at p0x%08lx v0x%08lx\n",
586 1.1.2.2 uebayasi kernel_l1pt.pv_pa, kernel_l1pt.pv_va);
587 1.1.2.2 uebayasi #endif
588 1.1.2.2 uebayasi
589 1.1.2.2 uebayasi /*
590 1.1.2.2 uebayasi * Now we start construction of the L1 page table
591 1.1.2.2 uebayasi * We start by mapping the L2 page tables into the L1.
592 1.1.2.2 uebayasi * This means that we can replace L1 mappings later on if necessary
593 1.1.2.2 uebayasi */
594 1.1.2.2 uebayasi l1pagetable = kernel_l1pt.pv_pa;
595 1.1.2.2 uebayasi
596 1.1.2.2 uebayasi /* Map the L2 pages tables in the L1 page table */
597 1.1.2.2 uebayasi pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
598 1.1.2.2 uebayasi &kernel_pt_table[KERNEL_PT_SYS]);
599 1.1.2.2 uebayasi for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
600 1.1.2.2 uebayasi pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
601 1.1.2.2 uebayasi &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
602 1.1.2.2 uebayasi for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
603 1.1.2.2 uebayasi pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
604 1.1.2.2 uebayasi &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
605 1.1.2.2 uebayasi
606 1.1.2.2 uebayasi /* update the top of the kernel VM */
607 1.1.2.2 uebayasi pmap_curmaxkvaddr =
608 1.1.2.2 uebayasi KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
609 1.1.2.2 uebayasi
610 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
611 1.1.2.2 uebayasi printf("Mapping kernel\n");
612 1.1.2.2 uebayasi #endif
613 1.1.2.2 uebayasi
614 1.1.2.2 uebayasi /* Now we fill in the L2 pagetable for the kernel static code/data */
615 1.1.2.2 uebayasi #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
616 1.1.2.2 uebayasi {
617 1.1.2.2 uebayasi size_t textsize = round_L_page((size_t)etext - KERNEL_TEXT_BASE);
618 1.1.2.2 uebayasi size_t totalsize = round_L_page((size_t)_end - KERNEL_TEXT_BASE);
619 1.1.2.2 uebayasi u_int logical;
620 1.1.2.2 uebayasi
621 1.1.2.2 uebayasi
622 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
623 1.1.2.2 uebayasi printf("%s: etext %lx, _end %lx\n",
624 1.1.2.2 uebayasi __func__, (uintptr_t)etext, (uintptr_t)_end);
625 1.1.2.2 uebayasi printf("%s: textsize %#lx, totalsize %#lx\n",
626 1.1.2.2 uebayasi __func__, textsize, totalsize);
627 1.1.2.2 uebayasi #endif
628 1.1.2.2 uebayasi logical = 0x00100000; /* offset of kernel in RAM */
629 1.1.2.2 uebayasi
630 1.1.2.2 uebayasi /* Map text section read-only. */
631 1.1.2.2 uebayasi logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
632 1.1.2.2 uebayasi physical_start + logical, textsize,
633 1.1.2.2 uebayasi VM_PROT_READ|VM_PROT_EXECUTE, PTE_CACHE);
634 1.1.2.2 uebayasi
635 1.1.2.2 uebayasi /* Map data and bss sections read-write. */
636 1.1.2.2 uebayasi logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
637 1.1.2.2 uebayasi physical_start + logical, totalsize - textsize,
638 1.1.2.2 uebayasi VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
639 1.1.2.2 uebayasi }
640 1.1.2.2 uebayasi
641 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
642 1.1.2.2 uebayasi printf("Constructing L2 page tables\n");
643 1.1.2.2 uebayasi #endif
644 1.1.2.2 uebayasi
645 1.1.2.2 uebayasi /* Map the stack pages */
646 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, fiqstack.pv_va, fiqstack.pv_pa,
647 1.1.2.2 uebayasi FIQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
648 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
649 1.1.2.2 uebayasi IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
650 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
651 1.1.2.2 uebayasi ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
652 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
653 1.1.2.2 uebayasi UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
654 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
655 1.1.2.2 uebayasi UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
656 1.1.2.2 uebayasi
657 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
658 1.1.2.2 uebayasi L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
659 1.1.2.2 uebayasi
660 1.1.2.2 uebayasi for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
661 1.1.2.2 uebayasi pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
662 1.1.2.2 uebayasi kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
663 1.1.2.2 uebayasi VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
664 1.1.2.2 uebayasi }
665 1.1.2.2 uebayasi
666 1.1.2.2 uebayasi /* Map the vector page. */
667 1.1.2.2 uebayasi #if 0
668 1.1.2.2 uebayasi /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
669 1.1.2.2 uebayasi * cache-clean code there. */
670 1.1.2.2 uebayasi pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
671 1.1.2.2 uebayasi VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
672 1.1.2.2 uebayasi #else
673 1.1.2.2 uebayasi pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
674 1.1.2.2 uebayasi VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
675 1.1.2.2 uebayasi #endif
676 1.1.2.2 uebayasi
677 1.1.2.2 uebayasi /*
678 1.1.2.2 uebayasi * map integrated peripherals at same address in l1pagetable
679 1.1.2.2 uebayasi * so that we can continue to use console.
680 1.1.2.2 uebayasi */
681 1.1.2.2 uebayasi pmap_devmap_bootstrap(l1pagetable, netwalker_devmap);
682 1.1.2.2 uebayasi
683 1.1.2.2 uebayasi /*
684 1.1.2.2 uebayasi * Now we have the real page tables in place so we can switch to them.
685 1.1.2.2 uebayasi * Once this is done we will be running with the REAL kernel page
686 1.1.2.2 uebayasi * tables.
687 1.1.2.2 uebayasi */
688 1.1.2.2 uebayasi
689 1.1.2.2 uebayasi /*
690 1.1.2.2 uebayasi * Update the physical_freestart/physical_freeend/free_pages
691 1.1.2.2 uebayasi * variables.
692 1.1.2.2 uebayasi */
693 1.1.2.2 uebayasi physical_freestart = physical_start +
694 1.1.2.2 uebayasi (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) - KERNEL_BASE);
695 1.1.2.2 uebayasi physical_freeend = physical_end;
696 1.1.2.2 uebayasi free_pages =
697 1.1.2.2 uebayasi (physical_freeend - physical_freestart) / PAGE_SIZE;
698 1.1.2.2 uebayasi
699 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
700 1.1.2.2 uebayasi /* Tell the user about where all the bits and pieces live. */
701 1.1.2.2 uebayasi printf("%22s Physical Virtual Num\n", " ");
702 1.1.2.2 uebayasi printf("%22s Starting Ending Starting Ending Pages\n", " ");
703 1.1.2.2 uebayasi
704 1.1.2.2 uebayasi static const char mem_fmt[] =
705 1.1.2.2 uebayasi "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
706 1.1.2.2 uebayasi static const char mem_fmt_nov[] =
707 1.1.2.2 uebayasi "%20s: 0x%08lx 0x%08lx %d\n";
708 1.1.2.2 uebayasi
709 1.1.2.2 uebayasi printf(mem_fmt, "SDRAM", physical_start, physical_end-1,
710 1.1.2.2 uebayasi KERN_PHYSTOV(physical_start), KERN_PHYSTOV(physical_end-1),
711 1.1.2.2 uebayasi physmem);
712 1.1.2.2 uebayasi printf(mem_fmt, "text section",
713 1.1.2.2 uebayasi (paddr_t)KERNEL_BASE_phys, KERN_VTOPHYS(etext-1),
714 1.1.2.2 uebayasi (vaddr_t)KERNEL_BASE_virt, (vaddr_t)etext-1,
715 1.1.2.2 uebayasi (int)(round_L_page((size_t)etext - KERNEL_TEXT_BASE) / PAGE_SIZE));
716 1.1.2.2 uebayasi printf(mem_fmt, "data section",
717 1.1.2.2 uebayasi KERN_VTOPHYS(__data_start), KERN_VTOPHYS(_edata),
718 1.1.2.2 uebayasi (vaddr_t)__data_start, (vaddr_t)_edata,
719 1.1.2.2 uebayasi (int)((round_page((vaddr_t)_edata)
720 1.1.2.2 uebayasi - trunc_page((vaddr_t)__data_start)) / PAGE_SIZE));
721 1.1.2.2 uebayasi printf(mem_fmt, "bss section",
722 1.1.2.2 uebayasi KERN_VTOPHYS(__bss_start), KERN_VTOPHYS(__bss_end__),
723 1.1.2.2 uebayasi (vaddr_t)__bss_start, (vaddr_t)__bss_end__,
724 1.1.2.2 uebayasi (int)((round_page((vaddr_t)__bss_end__)
725 1.1.2.2 uebayasi - trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE));
726 1.1.2.2 uebayasi printf(mem_fmt, "L1 page directory",
727 1.1.2.2 uebayasi kernel_l1pt.pv_pa, kernel_l1pt.pv_pa + L1_TABLE_SIZE - 1,
728 1.1.2.2 uebayasi kernel_l1pt.pv_va, kernel_l1pt.pv_va + L1_TABLE_SIZE - 1,
729 1.1.2.2 uebayasi L1_TABLE_SIZE / PAGE_SIZE);
730 1.1.2.2 uebayasi printf(mem_fmt, "Exception Vectors",
731 1.1.2.2 uebayasi systempage.pv_pa, systempage.pv_pa + PAGE_SIZE - 1,
732 1.1.2.2 uebayasi systempage.pv_va, systempage.pv_va + PAGE_SIZE - 1,
733 1.1.2.2 uebayasi 1);
734 1.1.2.2 uebayasi printf(mem_fmt, "FIQ stack",
735 1.1.2.2 uebayasi fiqstack.pv_pa, fiqstack.pv_pa + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
736 1.1.2.2 uebayasi fiqstack.pv_va, fiqstack.pv_va + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
737 1.1.2.2 uebayasi FIQ_STACK_SIZE);
738 1.1.2.2 uebayasi printf(mem_fmt, "IRQ stack",
739 1.1.2.2 uebayasi irqstack.pv_pa, irqstack.pv_pa + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
740 1.1.2.2 uebayasi irqstack.pv_va, irqstack.pv_va + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
741 1.1.2.2 uebayasi IRQ_STACK_SIZE);
742 1.1.2.2 uebayasi printf(mem_fmt, "ABT stack",
743 1.1.2.2 uebayasi abtstack.pv_pa, abtstack.pv_pa + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
744 1.1.2.2 uebayasi abtstack.pv_va, abtstack.pv_va + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
745 1.1.2.2 uebayasi ABT_STACK_SIZE);
746 1.1.2.2 uebayasi printf(mem_fmt, "UND stack",
747 1.1.2.2 uebayasi undstack.pv_pa, undstack.pv_pa + (UND_STACK_SIZE * PAGE_SIZE) - 1,
748 1.1.2.2 uebayasi undstack.pv_va, undstack.pv_va + (UND_STACK_SIZE * PAGE_SIZE) - 1,
749 1.1.2.2 uebayasi UND_STACK_SIZE);
750 1.1.2.2 uebayasi printf(mem_fmt, "SVC stack",
751 1.1.2.2 uebayasi kernelstack.pv_pa, kernelstack.pv_pa + (UPAGES * PAGE_SIZE) - 1,
752 1.1.2.2 uebayasi kernelstack.pv_va, kernelstack.pv_va + (UPAGES * PAGE_SIZE) - 1,
753 1.1.2.2 uebayasi UPAGES);
754 1.1.2.2 uebayasi printf(mem_fmt_nov, "Message Buffer",
755 1.1.2.2 uebayasi msgbufphys, msgbufphys + round_page(MSGBUFSIZE) - 1, round_page(MSGBUFSIZE) / PAGE_SIZE);
756 1.1.2.2 uebayasi printf(mem_fmt, "Free Memory", physical_freestart, physical_freeend-1,
757 1.1.2.2 uebayasi KERN_PHYSTOV(physical_freestart), KERN_PHYSTOV(physical_freeend-1),
758 1.1.2.2 uebayasi free_pages);
759 1.1.2.2 uebayasi #endif
760 1.1.2.2 uebayasi
761 1.1.2.2 uebayasi /* Switch tables */
762 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
763 1.1.2.2 uebayasi printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
764 1.1.2.2 uebayasi physical_freestart, free_pages, free_pages);
765 1.1.2.2 uebayasi printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
766 1.1.2.2 uebayasi #endif
767 1.1.2.2 uebayasi
768 1.1.2.2 uebayasi cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
769 1.1.2.2 uebayasi cpu_setttb(kernel_l1pt.pv_pa);
770 1.1.2.2 uebayasi cpu_tlb_flushID();
771 1.1.2.2 uebayasi cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
772 1.1.2.2 uebayasi
773 1.1.2.2 uebayasi /*
774 1.1.2.2 uebayasi * Moved from cpu_startup() as data_abort_handler() references
775 1.1.2.2 uebayasi * this during uvm init
776 1.1.2.2 uebayasi */
777 1.1.2.2 uebayasi uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
778 1.1.2.2 uebayasi
779 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
780 1.1.2.2 uebayasi printf("bootstrap done.\n");
781 1.1.2.2 uebayasi #endif
782 1.1.2.2 uebayasi
783 1.1.2.2 uebayasi arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
784 1.1.2.2 uebayasi
785 1.1.2.2 uebayasi /*
786 1.1.2.2 uebayasi * Pages were allocated during the secondary bootstrap for the
787 1.1.2.2 uebayasi * stacks for different CPU modes.
788 1.1.2.2 uebayasi * We must now set the r13 registers in the different CPU modes to
789 1.1.2.2 uebayasi * point to these stacks.
790 1.1.2.2 uebayasi * Since the ARM stacks use STMFD etc. we must set r13 to the top end
791 1.1.2.2 uebayasi * of the stack memory.
792 1.1.2.2 uebayasi */
793 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
794 1.1.2.2 uebayasi printf("init subsystems: stacks ");
795 1.1.2.2 uebayasi #endif
796 1.1.2.2 uebayasi set_stackptr(PSR_FIQ32_MODE, fiqstack.pv_va + FIQ_STACK_SIZE * PAGE_SIZE);
797 1.1.2.2 uebayasi set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
798 1.1.2.2 uebayasi set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
799 1.1.2.2 uebayasi set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
800 1.1.2.2 uebayasi
801 1.1.2.2 uebayasi /*
802 1.1.2.2 uebayasi * Well we should set a data abort handler.
803 1.1.2.2 uebayasi * Once things get going this will change as we will need a proper
804 1.1.2.2 uebayasi * handler.
805 1.1.2.2 uebayasi * Until then we will use a handler that just panics but tells us
806 1.1.2.2 uebayasi * why.
807 1.1.2.2 uebayasi * Initialisation of the vectors will just panic on a data abort.
808 1.1.2.2 uebayasi * This just fills in a slightly better one.
809 1.1.2.2 uebayasi */
810 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
811 1.1.2.2 uebayasi printf("vectors ");
812 1.1.2.2 uebayasi #endif
813 1.1.2.2 uebayasi data_abort_handler_address = (u_int)data_abort_handler;
814 1.1.2.2 uebayasi prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
815 1.1.2.2 uebayasi undefined_handler_address = (u_int)undefinedinstruction_bounce;
816 1.1.2.2 uebayasi
817 1.1.2.2 uebayasi /* Initialise the undefined instruction handlers */
818 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
819 1.1.2.2 uebayasi printf("undefined ");
820 1.1.2.2 uebayasi #endif
821 1.1.2.2 uebayasi undefined_init();
822 1.1.2.2 uebayasi
823 1.1.2.2 uebayasi /* Load memory into UVM. */
824 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
825 1.1.2.2 uebayasi printf("page ");
826 1.1.2.2 uebayasi #endif
827 1.1.2.2 uebayasi uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
828 1.1.2.2 uebayasi uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
829 1.1.2.2 uebayasi atop(physical_freestart), atop(physical_freeend),
830 1.1.2.2 uebayasi VM_FREELIST_DEFAULT);
831 1.1.2.2 uebayasi
832 1.1.2.2 uebayasi /* Boot strap pmap telling it where the kernel page table is */
833 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
834 1.1.2.2 uebayasi printf("pmap ");
835 1.1.2.2 uebayasi #endif
836 1.1.2.2 uebayasi pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
837 1.1.2.2 uebayasi
838 1.1.2.2 uebayasi #ifdef __HAVE_MEMORY_DISK__
839 1.1.2.2 uebayasi md_root_setconf(memory_disk, sizeof memory_disk);
840 1.1.2.2 uebayasi #endif
841 1.1.2.2 uebayasi
842 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
843 1.1.2.2 uebayasi printf("done.\n");
844 1.1.2.2 uebayasi #endif
845 1.1.2.2 uebayasi
846 1.1.2.2 uebayasi /* disable power down counter in watch dog,
847 1.1.2.2 uebayasi This must be done within 16 seconds of start-up. */
848 1.1.2.2 uebayasi ioreg16_write(NETWALKER_WDOG_VBASE + IMX_WDOG_WMCR, 0);
849 1.1.2.2 uebayasi
850 1.1.2.2 uebayasi #ifdef IPKDB
851 1.1.2.2 uebayasi /* Initialise ipkdb */
852 1.1.2.2 uebayasi ipkdb_init();
853 1.1.2.2 uebayasi if (boothowto & RB_KDB)
854 1.1.2.2 uebayasi ipkdb_connect(0);
855 1.1.2.2 uebayasi #endif
856 1.1.2.2 uebayasi
857 1.1.2.2 uebayasi #ifdef KGDB
858 1.1.2.2 uebayasi if (boothowto & RB_KDB) {
859 1.1.2.2 uebayasi kgdb_debug_init = 1;
860 1.1.2.2 uebayasi kgdb_connect(1);
861 1.1.2.2 uebayasi }
862 1.1.2.2 uebayasi #endif
863 1.1.2.2 uebayasi
864 1.1.2.2 uebayasi #ifdef DDB
865 1.1.2.2 uebayasi #ifdef VERBOSE_INIT_ARM
866 1.1.2.2 uebayasi printf("ddb ");
867 1.1.2.2 uebayasi #endif
868 1.1.2.2 uebayasi db_machine_init();
869 1.1.2.2 uebayasi
870 1.1.2.2 uebayasi /* Firmware doesn't load symbols. */
871 1.1.2.2 uebayasi ddb_init(0, NULL, NULL);
872 1.1.2.2 uebayasi
873 1.1.2.2 uebayasi if (boothowto & RB_KDB)
874 1.1.2.2 uebayasi Debugger();
875 1.1.2.2 uebayasi #endif
876 1.1.2.2 uebayasi
877 1.1.2.2 uebayasi
878 1.1.2.2 uebayasi
879 1.1.2.2 uebayasi printf("initarm done.\n");
880 1.1.2.2 uebayasi
881 1.1.2.2 uebayasi /* We return the new stack pointer address */
882 1.1.2.2 uebayasi return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
883 1.1.2.2 uebayasi }
884 1.1.2.2 uebayasi
885 1.1.2.2 uebayasi #if 0
886 1.1.2.2 uebayasi void
887 1.1.2.2 uebayasi process_kernel_args(char *args)
888 1.1.2.2 uebayasi {
889 1.1.2.2 uebayasi
890 1.1.2.2 uebayasi boothowto = 0;
891 1.1.2.2 uebayasi
892 1.1.2.2 uebayasi /* Make a local copy of the bootargs */
893 1.1.2.2 uebayasi strncpy(bootargs, args, MAX_BOOT_STRING);
894 1.1.2.2 uebayasi
895 1.1.2.2 uebayasi args = bootargs;
896 1.1.2.2 uebayasi boot_file = bootargs;
897 1.1.2.2 uebayasi
898 1.1.2.2 uebayasi /* Skip the kernel image filename */
899 1.1.2.2 uebayasi while (*args != ' ' && *args != 0)
900 1.1.2.2 uebayasi ++args;
901 1.1.2.2 uebayasi
902 1.1.2.2 uebayasi if (*args != 0)
903 1.1.2.2 uebayasi *args++ = 0;
904 1.1.2.2 uebayasi
905 1.1.2.2 uebayasi while (*args == ' ')
906 1.1.2.2 uebayasi ++args;
907 1.1.2.2 uebayasi
908 1.1.2.2 uebayasi boot_args = args;
909 1.1.2.2 uebayasi
910 1.1.2.2 uebayasi printf("bootfile: %s\n", boot_file);
911 1.1.2.2 uebayasi printf("bootargs: %s\n", boot_args);
912 1.1.2.2 uebayasi
913 1.1.2.2 uebayasi parse_mi_bootargs(boot_args);
914 1.1.2.2 uebayasi }
915 1.1.2.2 uebayasi #endif
916 1.1.2.2 uebayasi
917 1.1.2.2 uebayasi static void
918 1.1.2.2 uebayasi init_clocks(void)
919 1.1.2.2 uebayasi {
920 1.1.2.2 uebayasi extern void cortexa8_pmc_ccnt_init(void);
921 1.1.2.2 uebayasi
922 1.1.2.2 uebayasi cortexa8_pmc_ccnt_init();
923 1.1.2.2 uebayasi }
924 1.1.2.2 uebayasi
925 1.1.2.2 uebayasi struct iomux_setup {
926 1.1.2.2 uebayasi size_t pad_ctl_reg;
927 1.1.2.2 uebayasi uint32_t pad_ctl_val;
928 1.1.2.2 uebayasi size_t mux_ctl_reg;
929 1.1.2.2 uebayasi uint32_t mux_ctl_val;
930 1.1.2.2 uebayasi };
931 1.1.2.2 uebayasi
932 1.1.2.2 uebayasi #define IOMUX_DATA(padname, mux, pad) \
933 1.1.2.2 uebayasi IOMUX_DATA2(__CONCAT(IOMUXC_SW_MUX_CTL_PAD_,padname), mux, \
934 1.1.2.2 uebayasi __CONCAT(IOMUXC_SW_PAD_CTL_PAD_,padname), pad)
935 1.1.2.2 uebayasi
936 1.1.2.2 uebayasi
937 1.1.2.2 uebayasi #define IOMUX_DATA2(muxreg, muxval, padreg, padval) \
938 1.1.2.2 uebayasi { \
939 1.1.2.2 uebayasi .pad_ctl_reg = (padreg), \
940 1.1.2.2 uebayasi .pad_ctl_val = (padval), \
941 1.1.2.2 uebayasi .mux_ctl_reg = (muxreg), \
942 1.1.2.2 uebayasi .mux_ctl_val = (muxval) \
943 1.1.2.2 uebayasi }
944 1.1.2.2 uebayasi
945 1.1.2.2 uebayasi
946 1.1.2.2 uebayasi const struct iomux_setup iomux_setup_data[] = {
947 1.1.2.2 uebayasi
948 1.1.2.2 uebayasi /* left buttons */
949 1.1.2.2 uebayasi IOMUX_DATA(EIM_EB2, IOMUX_CONFIG_ALT1,
950 1.1.2.2 uebayasi PAD_CTL_HYS_ENABLE),
951 1.1.2.2 uebayasi /* right buttons */
952 1.1.2.2 uebayasi IOMUX_DATA(EIM_EB3, IOMUX_CONFIG_ALT1,
953 1.1.2.2 uebayasi PAD_CTL_HYS_ENABLE),
954 1.1.2.2 uebayasi
955 1.1.2.2 uebayasi
956 1.1.2.2 uebayasi #if 0
957 1.1.2.2 uebayasi /* UART1 */
958 1.1.2.2 uebayasi IOMUX_DATA(UART1_RXD, IOMUX_CONFIG_ALT0,
959 1.1.2.2 uebayasi (PAD_CTL_HYS_ENABLE | PAD_CTL_PKE_ENABLE |
960 1.1.2.2 uebayasi PAD_CTL_PUE_PULL | PAD_CTL_DSE_HIGH |
961 1.1.2.2 uebayasi PAD_CTL_SRE_FAST)),
962 1.1.2.2 uebayasi IOMUX_DATA(UART1_TXD, IOMUX_CONFIG_ALT0,
963 1.1.2.2 uebayasi (PAD_CTL_HYS_ENABLE | PAD_CTL_PKE_ENABLE |
964 1.1.2.2 uebayasi PAD_CTL_PUE_PULL | PAD_CTL_DSE_HIGH |
965 1.1.2.2 uebayasi PAD_CTL_SRE_FAST)),
966 1.1.2.2 uebayasi IOMUX_DATA(UART1_RTS, IOMUX_CONFIG_ALT0,
967 1.1.2.2 uebayasi (PAD_CTL_HYS_ENABLE | PAD_CTL_PKE_ENABLE |
968 1.1.2.2 uebayasi PAD_CTL_PUE_PULL | PAD_CTL_DSE_HIGH)),
969 1.1.2.2 uebayasi IOMUX_DATA(UART1_CTS, IOMUX_CONFIG_ALT0,
970 1.1.2.2 uebayasi (PAD_CTL_HYS_ENABLE | PAD_CTL_PKE_ENABLE |
971 1.1.2.2 uebayasi PAD_CTL_PUE_PULL | PAD_CTL_DSE_HIGH)),
972 1.1.2.2 uebayasi #else
973 1.1.2.2 uebayasi /* UART1 */
974 1.1.2.2 uebayasi #if 1
975 1.1.2.2 uebayasi IOMUX_DATA(UART1_RXD, IOMUX_CONFIG_ALT0,
976 1.1.2.2 uebayasi PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
977 1.1.2.2 uebayasi #else
978 1.1.2.2 uebayasi IOMUX_DATA(UART1_RXD, IOMUX_CONFIG_ALT3, /* gpio4[28] */
979 1.1.2.2 uebayasi PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
980 1.1.2.2 uebayasi #endif
981 1.1.2.2 uebayasi IOMUX_DATA(UART1_TXD, IOMUX_CONFIG_ALT0,
982 1.1.2.2 uebayasi PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
983 1.1.2.2 uebayasi IOMUX_DATA(UART1_RTS, IOMUX_CONFIG_ALT0,
984 1.1.2.2 uebayasi PAD_CTL_DSE_HIGH),
985 1.1.2.2 uebayasi IOMUX_DATA(UART1_CTS, IOMUX_CONFIG_ALT0,
986 1.1.2.2 uebayasi PAD_CTL_DSE_HIGH),
987 1.1.2.2 uebayasi #endif
988 1.1.2.2 uebayasi
989 1.1.2.2 uebayasi };
990 1.1.2.2 uebayasi
991 1.1.2.2 uebayasi static void
992 1.1.2.2 uebayasi setup_ioports(void)
993 1.1.2.2 uebayasi {
994 1.1.2.2 uebayasi int i;
995 1.1.2.2 uebayasi const struct iomux_setup *p;
996 1.1.2.2 uebayasi
997 1.1.2.2 uebayasi #if 0 /* These are all done already by Netwalker's bootloader. */
998 1.1.2.2 uebayasi /* set IO multiplexor for UART1 */
999 1.1.2.2 uebayasi uint32_t reg;
1000 1.1.2.2 uebayasi uint32_t addr;
1001 1.1.2.2 uebayasi
1002 1.1.2.2 uebayasi /* input */
1003 1.1.2.2 uebayasi addr = NETWALKER_IOMUXC_VBASE + MUX_IN_UART1_IPP_UART_RXD_MUX;
1004 1.1.2.2 uebayasi reg = INPUT_DAISY_0;
1005 1.1.2.2 uebayasi ioreg_write(addr, reg);
1006 1.1.2.2 uebayasi addr = NETWALKER_IOMUXC_VBASE + MUX_IN_UART1_IPP_UART_RTS_B;
1007 1.1.2.2 uebayasi reg = INPUT_DAISY_0;
1008 1.1.2.2 uebayasi ioreg_write(addr, reg);
1009 1.1.2.2 uebayasi #endif
1010 1.1.2.2 uebayasi
1011 1.1.2.2 uebayasi for (i=0; i < __arraycount(iomux_setup_data); ++i) {
1012 1.1.2.2 uebayasi p = iomux_setup_data + i;
1013 1.1.2.2 uebayasi
1014 1.1.2.2 uebayasi ioreg_write(NETWALKER_IOMUXC_VBASE +
1015 1.1.2.2 uebayasi p->pad_ctl_reg,
1016 1.1.2.2 uebayasi p->pad_ctl_val);
1017 1.1.2.2 uebayasi ioreg_write(NETWALKER_IOMUXC_VBASE +
1018 1.1.2.2 uebayasi p->mux_ctl_reg,
1019 1.1.2.2 uebayasi p->mux_ctl_val);
1020 1.1.2.2 uebayasi }
1021 1.1.2.2 uebayasi
1022 1.1.2.2 uebayasi
1023 1.1.2.2 uebayasi #if 0 /* already done by bootloader */
1024 1.1.2.2 uebayasi /* GPIO2[22,23]: input (left/right button)
1025 1.1.2.2 uebayasi GPIO2[21]: input (power button) */
1026 1.1.2.2 uebayasi ioreg_write(NETWALKER_GPIO_VBASE(2) + GPIO_DIR,
1027 1.1.2.2 uebayasi ~__BITS(21,23) &
1028 1.1.2.2 uebayasi ioreg_read(NETWALKER_GPIO_VBASE(2) + GPIO_DIR));
1029 1.1.2.2 uebayasi #endif
1030 1.1.2.2 uebayasi
1031 1.1.2.2 uebayasi #if 0 /* already done by bootloader */
1032 1.1.2.2 uebayasi /* GPIO4[12]: input (cover switch) */
1033 1.1.2.2 uebayasi ioreg_write(NETWALKER_GPIO_VBASE(4) + GPIO_DIR,
1034 1.1.2.2 uebayasi ~__BIT(12) &
1035 1.1.2.2 uebayasi ioreg_read(NETWALKER_GPIO_VBASE(4) + GPIO_DIR));
1036 1.1.2.2 uebayasi #endif
1037 1.1.2.2 uebayasi }
1038 1.1.2.2 uebayasi
1039 1.1.2.2 uebayasi
1040 1.1.2.2 uebayasi #ifdef CONSDEVNAME
1041 1.1.2.2 uebayasi const char consdevname[] = CONSDEVNAME;
1042 1.1.2.2 uebayasi
1043 1.1.2.2 uebayasi #ifndef CONMODE
1044 1.1.2.2 uebayasi #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
1045 1.1.2.2 uebayasi #endif
1046 1.1.2.2 uebayasi #ifndef CONSPEED
1047 1.1.2.2 uebayasi #define CONSPEED 115200
1048 1.1.2.2 uebayasi #endif
1049 1.1.2.2 uebayasi
1050 1.1.2.2 uebayasi int consmode = CONMODE;
1051 1.1.2.2 uebayasi int consrate = CONSPEED;
1052 1.1.2.2 uebayasi
1053 1.1.2.2 uebayasi #endif /* CONSDEVNAME */
1054 1.1.2.2 uebayasi
1055 1.1.2.2 uebayasi #ifndef IMXUART_FREQ
1056 1.1.2.2 uebayasi #define IMXUART_FREQ 66355200
1057 1.1.2.2 uebayasi #endif
1058 1.1.2.2 uebayasi
1059 1.1.2.2 uebayasi void
1060 1.1.2.2 uebayasi consinit(void)
1061 1.1.2.2 uebayasi {
1062 1.1.2.2 uebayasi static int consinit_called = 0;
1063 1.1.2.2 uebayasi
1064 1.1.2.2 uebayasi if (consinit_called)
1065 1.1.2.2 uebayasi return;
1066 1.1.2.2 uebayasi
1067 1.1.2.2 uebayasi consinit_called = 1;
1068 1.1.2.2 uebayasi
1069 1.1.2.2 uebayasi #ifdef CONSDEVNAME
1070 1.1.2.2 uebayasi
1071 1.1.2.2 uebayasi #if NIMXUART > 0
1072 1.1.2.2 uebayasi imxuart_set_frequency(IMXUART_FREQ, 2);
1073 1.1.2.2 uebayasi #endif
1074 1.1.2.2 uebayasi
1075 1.1.2.2 uebayasi #if (NIMXUART > 0) && defined(IMXUARTCONSOLE)
1076 1.1.2.2 uebayasi if (strcmp(consdevname, "imxuart") == 0) {
1077 1.1.2.2 uebayasi paddr_t consaddr;
1078 1.1.2.2 uebayasi #ifdef CONADDR
1079 1.1.2.2 uebayasi consaddr = CONADDR;
1080 1.1.2.2 uebayasi #else
1081 1.1.2.2 uebayasi consaddr = IMX51_UART1_BASE;
1082 1.1.2.2 uebayasi #endif
1083 1.1.2.2 uebayasi imxuart_cons_attach(&imx_bs_tag, consaddr, consrate, consmode);
1084 1.1.2.2 uebayasi return;
1085 1.1.2.2 uebayasi }
1086 1.1.2.2 uebayasi #endif
1087 1.1.2.2 uebayasi
1088 1.1.2.2 uebayasi #endif
1089 1.1.2.2 uebayasi
1090 1.1.2.2 uebayasi #if (NWSDISPLAY > 0) && defined(IMXLCDCONSOLE)
1091 1.1.2.2 uebayasi {
1092 1.1.2.2 uebayasi extern void netwalker_cnattach(void);
1093 1.1.2.2 uebayasi netwalker_cnattach();
1094 1.1.2.2 uebayasi }
1095 1.1.2.2 uebayasi #endif
1096 1.1.2.2 uebayasi }
1097 1.1.2.2 uebayasi
1098 1.1.2.2 uebayasi #ifdef KGDB
1099 1.1.2.2 uebayasi #ifndef KGDB_DEVNAME
1100 1.1.2.2 uebayasi #define KGDB_DEVNAME "imxuart"
1101 1.1.2.2 uebayasi #endif
1102 1.1.2.2 uebayasi #ifndef KGDB_DEVMODE
1103 1.1.2.2 uebayasi #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
1104 1.1.2.2 uebayasi #endif
1105 1.1.2.2 uebayasi
1106 1.1.2.2 uebayasi const char kgdb_devname[20] = KGDB_DEVNAME;
1107 1.1.2.2 uebayasi int kgdb_mode = KGDB_DEVMODE;
1108 1.1.2.2 uebayasi int kgdb_addr = KGDB_DEVADDR;
1109 1.1.2.2 uebayasi extern int kgdb_rate; /* defined in kgdb_stub.c */
1110 1.1.2.2 uebayasi
1111 1.1.2.2 uebayasi void
1112 1.1.2.2 uebayasi kgdb_port_init(void)
1113 1.1.2.2 uebayasi {
1114 1.1.2.2 uebayasi #if (NIMXUART > 0)
1115 1.1.2.2 uebayasi if (strcmp(kgdb_devname, "imxuart") == 0) {
1116 1.1.2.2 uebayasi imxuart_kgdb_attach(&imx_bs_tag, kgdb_addr,
1117 1.1.2.2 uebayasi kgdb_rate, kgdb_mode);
1118 1.1.2.2 uebayasi return;
1119 1.1.2.2 uebayasi }
1120 1.1.2.2 uebayasi
1121 1.1.2.2 uebayasi #endif
1122 1.1.2.2 uebayasi }
1123 1.1.2.2 uebayasi #endif
1124 1.1.2.2 uebayasi
1125 1.1.2.2 uebayasi
1126 1.1.2.2 uebayasi #ifdef DEBUG_IOPORTS
1127 1.1.2.2 uebayasi static void dump_sub(paddr_t addr, size_t size)
1128 1.1.2.2 uebayasi {
1129 1.1.2.2 uebayasi paddr_t end = addr + size;
1130 1.1.2.2 uebayasi
1131 1.1.2.2 uebayasi for (; addr < end; addr += 4) {
1132 1.1.2.2 uebayasi if (addr % 16 == 0)
1133 1.1.2.2 uebayasi printf("%08x: ", (u_int)addr);
1134 1.1.2.2 uebayasi printf("%08x ", ioreg_read(addr));
1135 1.1.2.2 uebayasi
1136 1.1.2.2 uebayasi if (addr % 16 == 12)
1137 1.1.2.2 uebayasi printf("\n");
1138 1.1.2.2 uebayasi }
1139 1.1.2.2 uebayasi printf("\n");
1140 1.1.2.2 uebayasi }
1141 1.1.2.2 uebayasi
1142 1.1.2.2 uebayasi void
1143 1.1.2.2 uebayasi dump_registers(void)
1144 1.1.2.2 uebayasi {
1145 1.1.2.2 uebayasi paddr_t pa;
1146 1.1.2.2 uebayasi int i;
1147 1.1.2.2 uebayasi
1148 1.1.2.2 uebayasi dump_sub(IOMUXC_BASE, IOMUXC_USBOH3_IPP_IND_UH3_STP_SELECT_INPUT + 4);
1149 1.1.2.2 uebayasi
1150 1.1.2.2 uebayasi for (i = 1; i <= 4; ++i) {
1151 1.1.2.2 uebayasi dump_sub(GPIO_BASE(i), GPIO_SIZE);
1152 1.1.2.2 uebayasi }
1153 1.1.2.2 uebayasi
1154 1.1.2.2 uebayasi printf("\nwatchdog: ");
1155 1.1.2.2 uebayasi for (pa = WDOG1_BASE; pa <= WDOG1_BASE + IMX_WDOG_WMCR;
1156 1.1.2.2 uebayasi pa += 2) {
1157 1.1.2.2 uebayasi printf("%04x ", *(volatile uint16_t *)pa);
1158 1.1.2.2 uebayasi }
1159 1.1.2.2 uebayasi printf("\n");
1160 1.1.2.2 uebayasi
1161 1.1.2.2 uebayasi #if 0
1162 1.1.2.2 uebayasi /* disable power down counter in watch dog,
1163 1.1.2.2 uebayasi This must be done within 16 seconds of start-up. */
1164 1.1.2.2 uebayasi ioreg16_write(NETWALKER_WDOG_VBASE + IMX_WDOG_WMCR, 0);
1165 1.1.2.2 uebayasi
1166 1.1.2.2 uebayasi /* read left/right buttons */
1167 1.1.2.2 uebayasi for (;;) {
1168 1.1.2.2 uebayasi uint32_t reg;
1169 1.1.2.2 uebayasi
1170 1.1.2.2 uebayasi reg = ioreg_read(GPIO_BASE(2) + GPIO_DR);
1171 1.1.2.2 uebayasi printf("\r%08x", reg);
1172 1.1.2.2 uebayasi reg = ioreg_read(GPIO_BASE(4) + GPIO_DR);
1173 1.1.2.2 uebayasi printf(" %08x", reg);
1174 1.1.2.2 uebayasi
1175 1.1.2.2 uebayasi #if 0
1176 1.1.2.2 uebayasi ioreg16_write(WDOG1_BASE + IMX_WDOG_WSR, WSR_MAGIC1);
1177 1.1.2.2 uebayasi ioreg16_write(WDOG1_BASE + IMX_WDOG_WSR, WSR_MAGIC2);
1178 1.1.2.2 uebayasi #endif
1179 1.1.2.2 uebayasi
1180 1.1.2.2 uebayasi }
1181 1.1.2.2 uebayasi #endif
1182 1.1.2.2 uebayasi
1183 1.1.2.2 uebayasi }
1184 1.1.2.2 uebayasi #endif
1185