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