viper_machdep.c revision 1.7 1 1.7 kiyohara /* $NetBSD: viper_machdep.c,v 1.7 2007/08/21 11:39:12 kiyohara Exp $ */
2 1.1 pooka
3 1.1 pooka /*
4 1.1 pooka * Startup routines for the Arcom Viper. Below you can trace the
5 1.1 pooka * impressive lineage ;)
6 1.1 pooka *
7 1.1 pooka * Modified for the Viper by Antti Kantee <pooka (at) netbsd.org>
8 1.1 pooka */
9 1.1 pooka
10 1.1 pooka /*
11 1.1 pooka * Copyright (c) 2002, 2003, 2005 Genetec Corporation. All rights reserved.
12 1.1 pooka * Written by Hiroyuki Bessho for Genetec Corporation.
13 1.1 pooka *
14 1.1 pooka * Redistribution and use in source and binary forms, with or without
15 1.1 pooka * modification, are permitted provided that the following conditions
16 1.1 pooka * are met:
17 1.1 pooka * 1. Redistributions of source code must retain the above copyright
18 1.1 pooka * notice, this list of conditions and the following disclaimer.
19 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 pooka * notice, this list of conditions and the following disclaimer in the
21 1.1 pooka * documentation and/or other materials provided with the distribution.
22 1.1 pooka * 3. The name of Genetec Corporation may not be used to endorse or
23 1.1 pooka * promote products derived from this software without specific prior
24 1.1 pooka * written permission.
25 1.1 pooka *
26 1.1 pooka * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
27 1.1 pooka * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
30 1.1 pooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pooka * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pooka *
38 1.1 pooka * Machine dependant functions for kernel setup for
39 1.1 pooka * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
40 1.1 pooka * Based on iq80310_machhdep.c
41 1.1 pooka */
42 1.1 pooka /*
43 1.1 pooka * Copyright (c) 2001 Wasabi Systems, Inc.
44 1.1 pooka * All rights reserved.
45 1.1 pooka *
46 1.1 pooka * Written by Jason R. Thorpe for Wasabi Systems, Inc.
47 1.1 pooka *
48 1.1 pooka * Redistribution and use in source and binary forms, with or without
49 1.1 pooka * modification, are permitted provided that the following conditions
50 1.1 pooka * are met:
51 1.1 pooka * 1. Redistributions of source code must retain the above copyright
52 1.1 pooka * notice, this list of conditions and the following disclaimer.
53 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 pooka * notice, this list of conditions and the following disclaimer in the
55 1.1 pooka * documentation and/or other materials provided with the distribution.
56 1.1 pooka * 3. All advertising materials mentioning features or use of this software
57 1.1 pooka * must display the following acknowledgement:
58 1.1 pooka * This product includes software developed for the NetBSD Project by
59 1.1 pooka * Wasabi Systems, Inc.
60 1.1 pooka * 4. The name of Wasabi Systems, Inc. may not be used to endorse
61 1.1 pooka * or promote products derived from this software without specific prior
62 1.1 pooka * written permission.
63 1.1 pooka *
64 1.1 pooka * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
65 1.1 pooka * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
66 1.1 pooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
67 1.1 pooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
68 1.1 pooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
69 1.1 pooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
70 1.1 pooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
71 1.1 pooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
72 1.1 pooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
73 1.1 pooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
74 1.1 pooka * POSSIBILITY OF SUCH DAMAGE.
75 1.1 pooka */
76 1.1 pooka
77 1.1 pooka /*
78 1.1 pooka * Copyright (c) 1997,1998 Mark Brinicombe.
79 1.1 pooka * Copyright (c) 1997,1998 Causality Limited.
80 1.1 pooka * All rights reserved.
81 1.1 pooka *
82 1.1 pooka * Redistribution and use in source and binary forms, with or without
83 1.1 pooka * modification, are permitted provided that the following conditions
84 1.1 pooka * are met:
85 1.1 pooka * 1. Redistributions of source code must retain the above copyright
86 1.1 pooka * notice, this list of conditions and the following disclaimer.
87 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
88 1.1 pooka * notice, this list of conditions and the following disclaimer in the
89 1.1 pooka * documentation and/or other materials provided with the distribution.
90 1.1 pooka * 3. All advertising materials mentioning features or use of this software
91 1.1 pooka * must display the following acknowledgement:
92 1.1 pooka * This product includes software developed by Mark Brinicombe
93 1.1 pooka * for the NetBSD Project.
94 1.1 pooka * 4. The name of the company nor the name of the author may be used to
95 1.1 pooka * endorse or promote products derived from this software without specific
96 1.1 pooka * prior written permission.
97 1.1 pooka *
98 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
99 1.1 pooka * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
100 1.1 pooka * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
101 1.1 pooka * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
102 1.1 pooka * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
103 1.1 pooka * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
104 1.1 pooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 1.1 pooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 1.1 pooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 1.1 pooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 1.1 pooka * SUCH DAMAGE.
109 1.1 pooka *
110 1.1 pooka * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
111 1.1 pooka * boards using RedBoot firmware.
112 1.1 pooka */
113 1.1 pooka
114 1.1 pooka #include <sys/cdefs.h>
115 1.7 kiyohara __KERNEL_RCSID(0, "$NetBSD: viper_machdep.c,v 1.7 2007/08/21 11:39:12 kiyohara Exp $");
116 1.1 pooka
117 1.1 pooka #include "opt_ddb.h"
118 1.1 pooka #include "opt_kgdb.h"
119 1.1 pooka #include "opt_ipkdb.h"
120 1.1 pooka #include "opt_pmap_debug.h"
121 1.1 pooka #include "opt_md.h"
122 1.1 pooka #include "opt_com.h"
123 1.1 pooka #include "md.h"
124 1.1 pooka #include "lcd.h"
125 1.1 pooka
126 1.1 pooka #include <sys/param.h>
127 1.1 pooka #include <sys/device.h>
128 1.1 pooka #include <sys/systm.h>
129 1.1 pooka #include <sys/kernel.h>
130 1.1 pooka #include <sys/exec.h>
131 1.1 pooka #include <sys/proc.h>
132 1.1 pooka #include <sys/msgbuf.h>
133 1.1 pooka #include <sys/reboot.h>
134 1.1 pooka #include <sys/termios.h>
135 1.1 pooka #include <sys/ksyms.h>
136 1.1 pooka
137 1.1 pooka #include <uvm/uvm_extern.h>
138 1.1 pooka
139 1.1 pooka #include <sys/conf.h>
140 1.1 pooka #include <dev/cons.h>
141 1.1 pooka #include <dev/md.h>
142 1.1 pooka #include <dev/ic/smc91cxxreg.h>
143 1.1 pooka
144 1.1 pooka #include <machine/db_machdep.h>
145 1.1 pooka #include <ddb/db_sym.h>
146 1.1 pooka #include <ddb/db_extern.h>
147 1.1 pooka #ifdef KGDB
148 1.1 pooka #include <sys/kgdb.h>
149 1.1 pooka #endif
150 1.1 pooka
151 1.1 pooka #include <machine/bootconfig.h>
152 1.1 pooka #include <machine/bus.h>
153 1.1 pooka #include <machine/cpu.h>
154 1.1 pooka #include <machine/frame.h>
155 1.1 pooka #include <arm/undefined.h>
156 1.1 pooka
157 1.1 pooka #include <arm/arm32/machdep.h>
158 1.1 pooka
159 1.1 pooka #include <arm/xscale/pxa2x0reg.h>
160 1.1 pooka #include <arm/xscale/pxa2x0var.h>
161 1.1 pooka #include <arm/xscale/pxa2x0_gpio.h>
162 1.1 pooka #include <arm/sa11x0/sa1111_reg.h>
163 1.1 pooka #include <evbarm/viper/viper_reg.h>
164 1.1 pooka
165 1.1 pooka /* Kernel text starts 2MB in from the bottom of the kernel address space. */
166 1.1 pooka #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
167 1.1 pooka #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
168 1.1 pooka
169 1.1 pooka /*
170 1.1 pooka * The range 0xc1000000 - 0xccffffff is available for kernel VM space
171 1.1 pooka * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
172 1.1 pooka */
173 1.1 pooka #define KERNEL_VM_SIZE 0x0C000000
174 1.1 pooka
175 1.1 pooka
176 1.1 pooka /*
177 1.1 pooka * Address to call from cpu_reset() to reset the machine.
178 1.1 pooka * This is machine architecture dependant as it varies depending
179 1.1 pooka * on where the ROM appears when you turn the MMU off.
180 1.1 pooka */
181 1.1 pooka
182 1.1 pooka u_int cpu_reset_address = 0;
183 1.1 pooka
184 1.1 pooka /* Define various stack sizes in pages */
185 1.1 pooka #define IRQ_STACK_SIZE 1
186 1.1 pooka #define ABT_STACK_SIZE 1
187 1.1 pooka #ifdef IPKDB
188 1.1 pooka #define UND_STACK_SIZE 2
189 1.1 pooka #else
190 1.1 pooka #define UND_STACK_SIZE 1
191 1.1 pooka #endif
192 1.1 pooka
193 1.1 pooka BootConfig bootconfig; /* Boot config storage */
194 1.1 pooka char *boot_args = NULL;
195 1.1 pooka char *boot_file = NULL;
196 1.1 pooka
197 1.1 pooka vm_offset_t physical_start;
198 1.1 pooka vm_offset_t physical_freestart;
199 1.1 pooka vm_offset_t physical_freeend;
200 1.1 pooka vm_offset_t physical_end;
201 1.1 pooka u_int free_pages;
202 1.1 pooka vm_offset_t pagetables_start;
203 1.1 pooka int physmem = 0;
204 1.1 pooka
205 1.1 pooka /*int debug_flags;*/
206 1.1 pooka #ifndef PMAP_STATIC_L1S
207 1.1 pooka int max_processes = 64; /* Default number */
208 1.1 pooka #endif /* !PMAP_STATIC_L1S */
209 1.1 pooka
210 1.1 pooka /* Physical and virtual addresses for some global pages */
211 1.1 pooka pv_addr_t systempage;
212 1.1 pooka pv_addr_t irqstack;
213 1.1 pooka pv_addr_t undstack;
214 1.1 pooka pv_addr_t abtstack;
215 1.1 pooka pv_addr_t kernelstack;
216 1.1 pooka pv_addr_t minidataclean;
217 1.1 pooka
218 1.1 pooka vm_offset_t msgbufphys;
219 1.1 pooka
220 1.1 pooka extern u_int data_abort_handler_address;
221 1.1 pooka extern u_int prefetch_abort_handler_address;
222 1.1 pooka extern u_int undefined_handler_address;
223 1.1 pooka
224 1.1 pooka #ifdef PMAP_DEBUG
225 1.1 pooka extern int pmap_debug_level;
226 1.1 pooka #endif
227 1.1 pooka
228 1.1 pooka #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
229 1.1 pooka #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
230 1.1 pooka #define KERNEL_PT_KERNEL_NUM 4
231 1.1 pooka #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
232 1.1 pooka /* Page tables for mapping kernel VM */
233 1.1 pooka #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
234 1.1 pooka #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
235 1.1 pooka
236 1.1 pooka pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
237 1.1 pooka
238 1.1 pooka struct user *proc0paddr;
239 1.1 pooka
240 1.1 pooka /* Prototypes */
241 1.1 pooka
242 1.1 pooka #if 0
243 1.1 pooka void process_kernel_args(char *);
244 1.1 pooka #endif
245 1.1 pooka
246 1.1 pooka void consinit(void);
247 1.1 pooka void kgdb_port_init(void);
248 1.1 pooka void change_clock(uint32_t v);
249 1.1 pooka
250 1.1 pooka bs_protos(bs_notimpl);
251 1.1 pooka
252 1.1 pooka #include "com.h"
253 1.1 pooka #if NCOM > 0
254 1.1 pooka #include <dev/ic/comreg.h>
255 1.1 pooka #include <dev/ic/comvar.h>
256 1.1 pooka #endif
257 1.1 pooka
258 1.1 pooka #ifndef CONSPEED
259 1.1 pooka #define CONSPEED B115200 /* What RedBoot uses */
260 1.1 pooka #endif
261 1.1 pooka #ifndef CONMODE
262 1.1 pooka #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
263 1.1 pooka #endif
264 1.1 pooka
265 1.1 pooka int comcnspeed = CONSPEED;
266 1.1 pooka int comcnmode = CONMODE;
267 1.1 pooka
268 1.7 kiyohara static struct pxa2x0_gpioconf boarddep_gpioconf[] = {
269 1.7 kiyohara { 44, GPIO_ALT_FN_1_IN }, /* BTCST */
270 1.7 kiyohara { 45, GPIO_ALT_FN_2_OUT }, /* BTRST */
271 1.7 kiyohara
272 1.7 kiyohara { -1 }
273 1.7 kiyohara };
274 1.7 kiyohara static struct pxa2x0_gpioconf *viper_gpioconf[] = {
275 1.7 kiyohara pxa25x_com_btuart_gpioconf,
276 1.7 kiyohara pxa25x_com_ffuart_gpioconf,
277 1.7 kiyohara pxa25x_com_stuart_gpioconf,
278 1.7 kiyohara boarddep_gpioconf,
279 1.7 kiyohara NULL
280 1.7 kiyohara };
281 1.7 kiyohara
282 1.1 pooka /*
283 1.1 pooka * void cpu_reboot(int howto, char *bootstr)
284 1.1 pooka *
285 1.1 pooka * Reboots the system
286 1.1 pooka *
287 1.1 pooka * Deal with any syncing, unmounting, dumping and shutdown hooks,
288 1.1 pooka * then reset the CPU.
289 1.1 pooka */
290 1.1 pooka void
291 1.1 pooka cpu_reboot(int howto, char *bootstr)
292 1.1 pooka {
293 1.1 pooka #ifdef DIAGNOSTIC
294 1.1 pooka /* info */
295 1.1 pooka printf("boot: howto=%08x curproc=%p\n", howto, curproc);
296 1.1 pooka #endif
297 1.1 pooka
298 1.1 pooka /*
299 1.1 pooka * If we are still cold then hit the air brakes
300 1.1 pooka * and crash to earth fast
301 1.1 pooka */
302 1.1 pooka if (cold) {
303 1.1 pooka doshutdownhooks();
304 1.1 pooka printf("The operating system has halted.\n");
305 1.1 pooka printf("Please press any key to reboot.\n\n");
306 1.1 pooka cngetc();
307 1.1 pooka printf("rebooting...\n");
308 1.1 pooka cpu_reset();
309 1.1 pooka /*NOTREACHED*/
310 1.1 pooka }
311 1.1 pooka
312 1.1 pooka /* Disable console buffering */
313 1.1 pooka /* cnpollc(1);*/
314 1.1 pooka
315 1.1 pooka /*
316 1.1 pooka * If RB_NOSYNC was not specified sync the discs.
317 1.1 pooka * Note: Unless cold is set to 1 here, syslogd will die during the
318 1.1 pooka * unmount. It looks like syslogd is getting woken up only to find
319 1.1 pooka * that it cannot page part of the binary in as the filesystem has
320 1.1 pooka * been unmounted.
321 1.1 pooka */
322 1.1 pooka if (!(howto & RB_NOSYNC))
323 1.1 pooka bootsync();
324 1.1 pooka
325 1.1 pooka /* Say NO to interrupts */
326 1.1 pooka splhigh();
327 1.1 pooka
328 1.1 pooka /* Do a dump if requested. */
329 1.1 pooka if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
330 1.1 pooka dumpsys();
331 1.1 pooka
332 1.1 pooka /* Run any shutdown hooks */
333 1.1 pooka doshutdownhooks();
334 1.1 pooka
335 1.1 pooka /* Make sure IRQ's are disabled */
336 1.1 pooka IRQdisable;
337 1.1 pooka
338 1.1 pooka if (howto & RB_HALT) {
339 1.1 pooka printf("The operating system has halted.\n");
340 1.1 pooka printf("Please press any key to reboot.\n\n");
341 1.1 pooka cngetc();
342 1.1 pooka }
343 1.1 pooka
344 1.1 pooka printf("rebooting...\n");
345 1.1 pooka cpu_reset();
346 1.1 pooka /*NOTREACHED*/
347 1.1 pooka }
348 1.1 pooka
349 1.1 pooka /*
350 1.1 pooka * Static device mappings. These peripheral registers are mapped at
351 1.1 pooka * fixed virtual addresses very early in viper_start() so that we
352 1.1 pooka * can use them while booting the kernel, and stay at the same address
353 1.1 pooka * throughout whole kernel's life time.
354 1.1 pooka *
355 1.1 pooka * We use this table twice; once with bootstrap page table, and once
356 1.1 pooka * with kernel's page table which we build up in initarm().
357 1.1 pooka */
358 1.1 pooka
359 1.1 pooka static const struct pmap_devmap viper_devmap[] = {
360 1.1 pooka {
361 1.1 pooka VIPER_GPIO_VBASE,
362 1.1 pooka PXA2X0_GPIO_BASE,
363 1.1 pooka L1_S_SIZE,
364 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
365 1.1 pooka },
366 1.1 pooka {
367 1.1 pooka VIPER_CLKMAN_VBASE,
368 1.1 pooka PXA2X0_CLKMAN_BASE,
369 1.1 pooka L1_S_SIZE,
370 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
371 1.1 pooka },
372 1.1 pooka {
373 1.1 pooka VIPER_INTCTL_VBASE,
374 1.1 pooka PXA2X0_INTCTL_BASE,
375 1.1 pooka L1_S_SIZE,
376 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
377 1.1 pooka },
378 1.1 pooka {
379 1.1 pooka VIPER_FFUART_VBASE,
380 1.1 pooka PXA2X0_FFUART_BASE,
381 1.1 pooka L1_S_SIZE,
382 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
383 1.1 pooka },
384 1.1 pooka {
385 1.1 pooka VIPER_BTUART_VBASE,
386 1.1 pooka PXA2X0_BTUART_BASE,
387 1.1 pooka L1_S_SIZE,
388 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
389 1.1 pooka },
390 1.1 pooka
391 1.1 pooka {0, 0, 0, 0,}
392 1.1 pooka };
393 1.1 pooka
394 1.1 pooka #ifndef MEMSTART
395 1.1 pooka #define MEMSTART 0xa0000000
396 1.1 pooka #endif
397 1.1 pooka #ifndef MEMSIZE
398 1.1 pooka #define MEMSIZE 0x4000000
399 1.1 pooka #endif
400 1.1 pooka
401 1.1 pooka /*
402 1.1 pooka * u_int initarm(...)
403 1.1 pooka *
404 1.1 pooka * Initial entry point on startup. This gets called before main() is
405 1.1 pooka * entered.
406 1.1 pooka * It should be responsible for setting up everything that must be
407 1.1 pooka * in place when main is called.
408 1.1 pooka * This includes
409 1.1 pooka * Taking a copy of the boot configuration structure.
410 1.1 pooka * Initialising the physical console so characters can be printed.
411 1.1 pooka * Setting up page tables for the kernel
412 1.1 pooka * Relocating the kernel to the bottom of physical memory
413 1.1 pooka */
414 1.1 pooka u_int
415 1.1 pooka initarm(void *arg)
416 1.1 pooka {
417 1.1 pooka extern vaddr_t xscale_cache_clean_addr;
418 1.1 pooka int loop;
419 1.1 pooka int loop1;
420 1.1 pooka u_int l1pagetable;
421 1.1 pooka pv_addr_t kernel_l1pt;
422 1.1 pooka #ifdef DIAGNOSTIC
423 1.1 pooka extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
424 1.1 pooka #endif
425 1.1 pooka
426 1.1 pooka /* Register devmap for devices we mapped in start */
427 1.1 pooka pmap_devmap_register(viper_devmap);
428 1.1 pooka
429 1.3 lukem /* start 32.768 kHz OSC */
430 1.1 pooka ioreg_write(VIPER_CLKMAN_VBASE + 0x08, 2);
431 1.1 pooka /* Get ready for splfoo() */
432 1.1 pooka pxa2x0_intr_bootstrap(VIPER_INTCTL_VBASE);
433 1.1 pooka
434 1.1 pooka /*
435 1.1 pooka * Heads up ... Setup the CPU / MMU / TLB functions
436 1.1 pooka */
437 1.1 pooka if (set_cpufuncs())
438 1.1 pooka panic("cpu not recognized!");
439 1.1 pooka
440 1.1 pooka #if 0
441 1.1 pooka /* Calibrate the delay loop. */
442 1.1 pooka #endif
443 1.1 pooka
444 1.1 pooka /* setup GPIO for BTUART, in case bootloader doesn't take care of it */
445 1.1 pooka pxa2x0_gpio_bootstrap(VIPER_GPIO_VBASE);
446 1.7 kiyohara pxa2x0_gpio_config(viper_gpioconf);
447 1.1 pooka
448 1.1 pooka /* turn on clock to UART block.
449 1.1 pooka XXX: this should not be done here. */
450 1.1 pooka ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, CKEN_FFUART|CKEN_BTUART |
451 1.1 pooka ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN));
452 1.1 pooka
453 1.1 pooka consinit();
454 1.1 pooka #ifdef KGDB
455 1.1 pooka kgdb_port_init();
456 1.1 pooka #endif
457 1.1 pooka /* Talk to the user */
458 1.1 pooka printf("\nNetBSD/evbarm (viper) booting ...\n");
459 1.1 pooka
460 1.1 pooka #if 0
461 1.1 pooka /*
462 1.1 pooka * Examine the boot args string for options we need to know about
463 1.1 pooka * now.
464 1.1 pooka */
465 1.1 pooka process_kernel_args((char *)nwbootinfo.bt_args);
466 1.1 pooka #endif
467 1.1 pooka
468 1.1 pooka printf("initarm: Configuring system ...\n");
469 1.1 pooka
470 1.1 pooka /* Fake bootconfig structure for the benefit of pmap.c */
471 1.6 wiz /* XXX must make the memory description h/w independent */
472 1.1 pooka bootconfig.dramblocks = 1;
473 1.1 pooka bootconfig.dram[0].address = MEMSTART;
474 1.1 pooka bootconfig.dram[0].pages = MEMSIZE / PAGE_SIZE;
475 1.1 pooka
476 1.1 pooka /*
477 1.1 pooka * Set up the variables that define the availablilty of
478 1.1 pooka * physical memory. For now, we're going to set
479 1.1 pooka * physical_freestart to 0xa0200000 (where the kernel
480 1.1 pooka * was loaded), and allocate the memory we need downwards.
481 1.1 pooka * If we get too close to the page tables that RedBoot
482 1.1 pooka * set up, we will panic. We will update physical_freestart
483 1.1 pooka * and physical_freeend later to reflect what pmap_bootstrap()
484 1.1 pooka * wants to see.
485 1.1 pooka *
486 1.1 pooka * XXX pmap_bootstrap() needs an enema.
487 1.1 pooka * (now that would be truly hardcore XXX)
488 1.1 pooka */
489 1.1 pooka physical_start = bootconfig.dram[0].address;
490 1.1 pooka physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
491 1.1 pooka
492 1.1 pooka physical_freestart = 0xa0009000UL;
493 1.1 pooka physical_freeend = 0xa0200000UL;
494 1.1 pooka
495 1.1 pooka physmem = (physical_end - physical_start) / PAGE_SIZE;
496 1.1 pooka
497 1.1 pooka #ifdef VERBOSE_INIT_ARM
498 1.1 pooka /* Tell the user about the memory */
499 1.1 pooka printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
500 1.1 pooka physical_start, physical_end - 1);
501 1.1 pooka #endif
502 1.1 pooka
503 1.1 pooka /*
504 1.1 pooka * Okay, the kernel starts 2MB in from the bottom of physical
505 1.1 pooka * memory. We are going to allocate our bootstrap pages downwards
506 1.1 pooka * from there.
507 1.1 pooka *
508 1.1 pooka * We need to allocate some fixed page tables to get the kernel
509 1.1 pooka * going. We allocate one page directory and a number of page
510 1.1 pooka * tables and store the physical addresses in the kernel_pt_table
511 1.1 pooka * array.
512 1.1 pooka *
513 1.1 pooka * The kernel page directory must be on a 16K boundary. The page
514 1.1 pooka * tables must be on 4K boundaries. What we do is allocate the
515 1.1 pooka * page directory on the first 16K boundary that we encounter, and
516 1.1 pooka * the page tables on 4K boundaries otherwise. Since we allocate
517 1.1 pooka * at least 3 L2 page tables, we are guaranteed to encounter at
518 1.1 pooka * least one 16K aligned region.
519 1.1 pooka */
520 1.1 pooka
521 1.1 pooka #ifdef VERBOSE_INIT_ARM
522 1.1 pooka printf("Allocating page tables\n");
523 1.1 pooka #endif
524 1.1 pooka
525 1.1 pooka free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
526 1.1 pooka
527 1.1 pooka #ifdef VERBOSE_INIT_ARM
528 1.1 pooka printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
529 1.1 pooka physical_freestart, free_pages, free_pages);
530 1.1 pooka #endif
531 1.1 pooka
532 1.1 pooka /* Define a macro to simplify memory allocation */
533 1.1 pooka #define valloc_pages(var, np) \
534 1.1 pooka alloc_pages((var).pv_pa, (np)); \
535 1.1 pooka (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
536 1.1 pooka
537 1.1 pooka #define alloc_pages(var, np) \
538 1.1 pooka physical_freeend -= ((np) * PAGE_SIZE); \
539 1.1 pooka if (physical_freeend < physical_freestart) \
540 1.1 pooka panic("initarm: out of memory"); \
541 1.1 pooka (var) = physical_freeend; \
542 1.1 pooka free_pages -= (np); \
543 1.1 pooka memset((char *)(var), 0, ((np) * PAGE_SIZE));
544 1.1 pooka
545 1.1 pooka loop1 = 0;
546 1.1 pooka kernel_l1pt.pv_pa = 0;
547 1.4 mrg kernel_l1pt.pv_va = 0;
548 1.1 pooka for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
549 1.1 pooka /* Are we 16KB aligned for an L1 ? */
550 1.1 pooka if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
551 1.1 pooka && kernel_l1pt.pv_pa == 0) {
552 1.1 pooka valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
553 1.1 pooka } else {
554 1.1 pooka valloc_pages(kernel_pt_table[loop1],
555 1.1 pooka L2_TABLE_SIZE / PAGE_SIZE);
556 1.1 pooka ++loop1;
557 1.1 pooka }
558 1.1 pooka }
559 1.1 pooka
560 1.1 pooka /* This should never be able to happen but better confirm that. */
561 1.1 pooka if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
562 1.1 pooka panic("initarm: Failed to align the kernel page directory");
563 1.1 pooka
564 1.1 pooka /*
565 1.1 pooka * Allocate a page for the system page mapped to V0x00000000
566 1.1 pooka * This page will just contain the system vectors and can be
567 1.1 pooka * shared by all processes.
568 1.1 pooka */
569 1.1 pooka alloc_pages(systempage.pv_pa, 1);
570 1.1 pooka
571 1.1 pooka /* Allocate stacks for all modes */
572 1.1 pooka valloc_pages(irqstack, IRQ_STACK_SIZE);
573 1.1 pooka valloc_pages(abtstack, ABT_STACK_SIZE);
574 1.1 pooka valloc_pages(undstack, UND_STACK_SIZE);
575 1.1 pooka valloc_pages(kernelstack, UPAGES);
576 1.1 pooka
577 1.1 pooka /* Allocate enough pages for cleaning the Mini-Data cache. */
578 1.1 pooka KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
579 1.1 pooka valloc_pages(minidataclean, 1);
580 1.1 pooka
581 1.1 pooka #ifdef VERBOSE_INIT_ARM
582 1.1 pooka printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
583 1.1 pooka irqstack.pv_va);
584 1.1 pooka printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
585 1.1 pooka abtstack.pv_va);
586 1.1 pooka printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
587 1.1 pooka undstack.pv_va);
588 1.1 pooka printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
589 1.1 pooka kernelstack.pv_va);
590 1.1 pooka #endif
591 1.1 pooka
592 1.1 pooka /*
593 1.1 pooka * XXX Defer this to later so that we can reclaim the memory
594 1.1 pooka * XXX used by the RedBoot page tables.
595 1.1 pooka */
596 1.1 pooka alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
597 1.1 pooka
598 1.1 pooka /*
599 1.1 pooka * Ok we have allocated physical pages for the primary kernel
600 1.1 pooka * page tables
601 1.1 pooka */
602 1.1 pooka
603 1.1 pooka #ifdef VERBOSE_INIT_ARM
604 1.1 pooka printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
605 1.1 pooka #endif
606 1.1 pooka
607 1.1 pooka /*
608 1.1 pooka * Now we start construction of the L1 page table
609 1.1 pooka * We start by mapping the L2 page tables into the L1.
610 1.1 pooka * This means that we can replace L1 mappings later on if necessary
611 1.1 pooka */
612 1.1 pooka l1pagetable = kernel_l1pt.pv_pa;
613 1.1 pooka
614 1.1 pooka /* Map the L2 pages tables in the L1 page table */
615 1.1 pooka pmap_link_l2pt(l1pagetable, 0x00000000,
616 1.1 pooka &kernel_pt_table[KERNEL_PT_SYS]);
617 1.1 pooka for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
618 1.1 pooka pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
619 1.1 pooka &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
620 1.1 pooka for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
621 1.1 pooka pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
622 1.1 pooka &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
623 1.1 pooka
624 1.1 pooka /* update the top of the kernel VM */
625 1.1 pooka pmap_curmaxkvaddr =
626 1.1 pooka KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
627 1.1 pooka
628 1.1 pooka #ifdef VERBOSE_INIT_ARM
629 1.1 pooka printf("Mapping kernel\n");
630 1.1 pooka #endif
631 1.1 pooka
632 1.1 pooka /* Now we fill in the L2 pagetable for the kernel static code/data */
633 1.1 pooka {
634 1.1 pooka extern char etext[], _end[];
635 1.1 pooka size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
636 1.1 pooka size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
637 1.1 pooka u_int logical;
638 1.1 pooka
639 1.1 pooka textsize = (textsize + PGOFSET) & ~PGOFSET;
640 1.1 pooka totalsize = (totalsize + PGOFSET) & ~PGOFSET;
641 1.1 pooka
642 1.1 pooka logical = 0x00200000; /* offset of kernel in RAM */
643 1.1 pooka
644 1.1 pooka logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
645 1.1 pooka physical_start + logical, textsize,
646 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
647 1.1 pooka logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
648 1.1 pooka physical_start + logical, totalsize - textsize,
649 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
650 1.1 pooka }
651 1.1 pooka
652 1.1 pooka #ifdef VERBOSE_INIT_ARM
653 1.1 pooka printf("Constructing L2 page tables\n");
654 1.1 pooka #endif
655 1.1 pooka
656 1.1 pooka /* Map the stack pages */
657 1.1 pooka pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
658 1.1 pooka IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
659 1.1 pooka pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
660 1.1 pooka ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
661 1.1 pooka pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
662 1.1 pooka UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
663 1.1 pooka pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
664 1.1 pooka UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
665 1.1 pooka
666 1.1 pooka pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
667 1.1 pooka L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
668 1.1 pooka
669 1.1 pooka for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
670 1.1 pooka pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
671 1.1 pooka kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
672 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
673 1.1 pooka }
674 1.1 pooka
675 1.1 pooka /* Map the Mini-Data cache clean area. */
676 1.1 pooka xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
677 1.1 pooka minidataclean.pv_pa);
678 1.1 pooka
679 1.1 pooka /* Map the vector page. */
680 1.1 pooka #if 1
681 1.1 pooka /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
682 1.1 pooka * cache-clean code there. */
683 1.1 pooka pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
684 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
685 1.1 pooka #else
686 1.1 pooka pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
687 1.1 pooka VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
688 1.1 pooka #endif
689 1.1 pooka
690 1.1 pooka /*
691 1.1 pooka * map integrated peripherals at same address in l1pagetable
692 1.1 pooka * so that we can continue to use console.
693 1.1 pooka */
694 1.1 pooka pmap_devmap_bootstrap(l1pagetable, viper_devmap);
695 1.1 pooka
696 1.1 pooka /*
697 1.1 pooka * Give the XScale global cache clean code an appropriately
698 1.1 pooka * sized chunk of unmapped VA space starting at 0xff000000
699 1.1 pooka * (our device mappings end before this address).
700 1.1 pooka */
701 1.1 pooka xscale_cache_clean_addr = 0xff000000U;
702 1.1 pooka
703 1.1 pooka /*
704 1.1 pooka * Now we have the real page tables in place so we can switch to them.
705 1.1 pooka * Once this is done we will be running with the REAL kernel page
706 1.1 pooka * tables.
707 1.1 pooka */
708 1.1 pooka
709 1.1 pooka /*
710 1.1 pooka * Update the physical_freestart/physical_freeend/free_pages
711 1.1 pooka * variables.
712 1.1 pooka */
713 1.1 pooka {
714 1.1 pooka extern char _end[];
715 1.1 pooka
716 1.1 pooka physical_freestart = physical_start +
717 1.1 pooka (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
718 1.1 pooka KERNEL_BASE);
719 1.1 pooka physical_freeend = physical_end;
720 1.1 pooka free_pages =
721 1.1 pooka (physical_freeend - physical_freestart) / PAGE_SIZE;
722 1.1 pooka }
723 1.1 pooka
724 1.1 pooka /* Switch tables */
725 1.1 pooka #ifdef VERBOSE_INIT_ARM
726 1.1 pooka printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
727 1.1 pooka physical_freestart, free_pages, free_pages);
728 1.1 pooka printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
729 1.1 pooka #endif
730 1.1 pooka
731 1.1 pooka cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
732 1.1 pooka setttb(kernel_l1pt.pv_pa);
733 1.1 pooka cpu_tlb_flushID();
734 1.1 pooka cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
735 1.1 pooka
736 1.1 pooka /*
737 1.1 pooka * Moved from cpu_startup() as data_abort_handler() references
738 1.1 pooka * this during uvm init
739 1.1 pooka */
740 1.1 pooka proc0paddr = (struct user *)kernelstack.pv_va;
741 1.1 pooka lwp0.l_addr = proc0paddr;
742 1.1 pooka
743 1.1 pooka #ifdef VERBOSE_INIT_ARM
744 1.1 pooka printf("bootstrap done.\n");
745 1.1 pooka #endif
746 1.1 pooka
747 1.1 pooka arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
748 1.1 pooka
749 1.1 pooka /*
750 1.1 pooka * Pages were allocated during the secondary bootstrap for the
751 1.1 pooka * stacks for different CPU modes.
752 1.1 pooka * We must now set the r13 registers in the different CPU modes to
753 1.1 pooka * point to these stacks.
754 1.1 pooka * Since the ARM stacks use STMFD etc. we must set r13 to the top end
755 1.1 pooka * of the stack memory.
756 1.1 pooka */
757 1.1 pooka printf("init subsystems: stacks ");
758 1.1 pooka
759 1.1 pooka set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
760 1.1 pooka set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
761 1.1 pooka set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
762 1.1 pooka
763 1.1 pooka /*
764 1.1 pooka * Well we should set a data abort handler.
765 1.1 pooka * Once things get going this will change as we will need a proper
766 1.1 pooka * handler.
767 1.1 pooka * Until then we will use a handler that just panics but tells us
768 1.1 pooka * why.
769 1.1 pooka * Initialisation of the vectors will just panic on a data abort.
770 1.1 pooka * This just fills in a slightly better one.
771 1.1 pooka */
772 1.1 pooka printf("vectors ");
773 1.1 pooka data_abort_handler_address = (u_int)data_abort_handler;
774 1.1 pooka prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
775 1.1 pooka undefined_handler_address = (u_int)undefinedinstruction_bounce;
776 1.1 pooka
777 1.1 pooka /* Initialise the undefined instruction handlers */
778 1.1 pooka printf("undefined ");
779 1.1 pooka undefined_init();
780 1.1 pooka
781 1.1 pooka /* Load memory into UVM. */
782 1.1 pooka printf("page ");
783 1.1 pooka uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
784 1.1 pooka uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
785 1.1 pooka atop(physical_freestart), atop(physical_freeend),
786 1.1 pooka VM_FREELIST_DEFAULT);
787 1.1 pooka
788 1.1 pooka /* Boot strap pmap telling it where the kernel page table is */
789 1.1 pooka printf("pmap ");
790 1.1 pooka pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
791 1.1 pooka KERNEL_VM_BASE + KERNEL_VM_SIZE);
792 1.1 pooka
793 1.1 pooka #ifdef __HAVE_MEMORY_DISK__
794 1.1 pooka md_root_setconf(memory_disk, sizeof memory_disk);
795 1.1 pooka #endif
796 1.1 pooka
797 1.1 pooka #ifdef IPKDB
798 1.1 pooka /* Initialise ipkdb */
799 1.1 pooka ipkdb_init();
800 1.1 pooka if (boothowto & RB_KDB)
801 1.1 pooka ipkdb_connect(0);
802 1.1 pooka #endif
803 1.1 pooka
804 1.1 pooka #ifdef KGDB
805 1.1 pooka if (boothowto & RB_KDB) {
806 1.1 pooka kgdb_debug_init = 1;
807 1.1 pooka kgdb_connect(1);
808 1.1 pooka }
809 1.1 pooka #endif
810 1.1 pooka
811 1.1 pooka #ifdef DDB
812 1.1 pooka db_machine_init();
813 1.1 pooka
814 1.1 pooka /* Firmware doesn't load symbols. */
815 1.1 pooka ddb_init(0, NULL, NULL);
816 1.1 pooka
817 1.1 pooka if (boothowto & RB_KDB)
818 1.1 pooka Debugger();
819 1.1 pooka #endif
820 1.1 pooka
821 1.1 pooka /* We return the new stack pointer address */
822 1.1 pooka return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
823 1.1 pooka }
824 1.1 pooka
825 1.1 pooka #if 0
826 1.1 pooka void
827 1.1 pooka process_kernel_args(char *args)
828 1.1 pooka {
829 1.1 pooka
830 1.1 pooka boothowto = 0;
831 1.1 pooka
832 1.1 pooka /* Make a local copy of the bootargs */
833 1.1 pooka strncpy(bootargs, args, MAX_BOOT_STRING);
834 1.1 pooka
835 1.1 pooka args = bootargs;
836 1.1 pooka boot_file = bootargs;
837 1.1 pooka
838 1.1 pooka /* Skip the kernel image filename */
839 1.1 pooka while (*args != ' ' && *args != 0)
840 1.1 pooka ++args;
841 1.1 pooka
842 1.1 pooka if (*args != 0)
843 1.1 pooka *args++ = 0;
844 1.1 pooka
845 1.1 pooka while (*args == ' ')
846 1.1 pooka ++args;
847 1.1 pooka
848 1.1 pooka boot_args = args;
849 1.1 pooka
850 1.1 pooka printf("bootfile: %s\n", boot_file);
851 1.1 pooka printf("bootargs: %s\n", boot_args);
852 1.1 pooka
853 1.1 pooka parse_mi_bootargs(boot_args);
854 1.1 pooka }
855 1.1 pooka #endif
856 1.1 pooka
857 1.1 pooka #ifdef KGDB
858 1.1 pooka #ifndef KGDB_DEVNAME
859 1.1 pooka #define KGDB_DEVNAME "ffuart"
860 1.1 pooka #endif
861 1.1 pooka const char kgdb_devname[] = KGDB_DEVNAME;
862 1.1 pooka
863 1.1 pooka #if (NCOM > 0)
864 1.1 pooka #ifndef KGDB_DEVMODE
865 1.1 pooka #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
866 1.1 pooka #endif
867 1.1 pooka int comkgdbmode = KGDB_DEVMODE;
868 1.1 pooka #endif /* NCOM */
869 1.1 pooka
870 1.1 pooka #endif /* KGDB */
871 1.1 pooka
872 1.1 pooka
873 1.1 pooka void
874 1.1 pooka consinit(void)
875 1.1 pooka {
876 1.1 pooka static int consinit_called = 0;
877 1.1 pooka uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN);
878 1.1 pooka #if 0
879 1.1 pooka char *console = CONSDEVNAME;
880 1.1 pooka #endif
881 1.1 pooka
882 1.1 pooka if (consinit_called != 0)
883 1.1 pooka return;
884 1.1 pooka consinit_called = 1;
885 1.1 pooka
886 1.1 pooka #if NCOM > 0
887 1.1 pooka
888 1.1 pooka #ifdef FFUARTCONSOLE
889 1.1 pooka #ifdef KGDB
890 1.1 pooka if (0 == strcmp(kgdb_devname, "ffuart")) {
891 1.1 pooka /* port is reserved for kgdb */
892 1.1 pooka } else
893 1.1 pooka #endif
894 1.1 pooka if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
895 1.1 pooka comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
896 1.1 pooka
897 1.1 pooka #if 0
898 1.1 pooka /* XXX: can't call pxa2x0_clkman_config yet */
899 1.1 pooka pxa2x0_clkman_config(CKEN_FFUART, 1);
900 1.1 pooka #else
901 1.1 pooka ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN,
902 1.1 pooka ckenreg|CKEN_FFUART);
903 1.1 pooka #endif
904 1.1 pooka
905 1.1 pooka return;
906 1.1 pooka }
907 1.1 pooka
908 1.1 pooka #endif /* FFUARTCONSOLE */
909 1.1 pooka
910 1.1 pooka #ifdef BTUARTCONSOLE
911 1.1 pooka #ifdef KGDB
912 1.1 pooka if (0 == strcmp(kgdb_devname, "btuart")) {
913 1.1 pooka /* port is reserved for kgdb */
914 1.1 pooka } else
915 1.1 pooka #endif
916 1.1 pooka if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
917 1.1 pooka comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
918 1.1 pooka ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN,
919 1.1 pooka ckenreg|CKEN_BTUART);
920 1.1 pooka return;
921 1.1 pooka }
922 1.1 pooka #endif /* BTUARTCONSOLE */
923 1.1 pooka
924 1.1 pooka /* no console, guess we're flying blind */
925 1.1 pooka
926 1.1 pooka #endif /* NCOM */
927 1.1 pooka
928 1.1 pooka }
929 1.1 pooka
930 1.1 pooka #ifdef KGDB
931 1.1 pooka void
932 1.1 pooka kgdb_port_init(void)
933 1.1 pooka {
934 1.1 pooka #if (NCOM > 0) && defined(COM_PXA2X0)
935 1.1 pooka paddr_t paddr = 0;
936 1.1 pooka uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN);
937 1.1 pooka
938 1.1 pooka if (0 == strcmp(kgdb_devname, "ffuart")) {
939 1.1 pooka paddr = PXA2X0_FFUART_BASE;
940 1.1 pooka ckenreg |= CKEN_FFUART;
941 1.1 pooka }
942 1.1 pooka else if (0 == strcmp(kgdb_devname, "btuart")) {
943 1.1 pooka paddr = PXA2X0_BTUART_BASE;
944 1.1 pooka ckenreg |= CKEN_BTUART;
945 1.1 pooka }
946 1.1 pooka
947 1.1 pooka if (paddr &&
948 1.1 pooka 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
949 1.1 pooka kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
950 1.1 pooka
951 1.1 pooka ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, ckenreg);
952 1.1 pooka }
953 1.1 pooka #endif
954 1.1 pooka }
955 1.1 pooka #endif
956