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