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