gumstix_machdep.c revision 1.32 1 /* $NetBSD: gumstix_machdep.c,v 1.32 2010/08/30 05:37:30 kiyohara Exp $ */
2 /*
3 * Copyright (C) 2005, 2006, 2007 WIDE Project and SOUM Corporation.
4 * All rights reserved.
5 *
6 * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
7 * Corporation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the name of SOUM Corporation
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33 /*
34 * Copyright (c) 2002, 2003, 2004, 2005 Genetec Corporation.
35 * All rights reserved.
36 *
37 * Written by Hiroyuki Bessho for Genetec Corporation.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. The name of Genetec Corporation may not be used to endorse or
48 * promote products derived from this software without specific prior
49 * written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
53 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
55 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
56 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
57 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
59 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
61 * POSSIBILITY OF SUCH DAMAGE.
62 *
63 * Machine dependant functions for kernel setup for Genetec G4250EBX
64 * evaluation board.
65 *
66 * Based on iq80310_machhdep.c
67 */
68 /*
69 * Copyright (c) 2001 Wasabi Systems, Inc.
70 * All rights reserved.
71 *
72 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
73 *
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
76 * are met:
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 * 3. All advertising materials mentioning features or use of this software
83 * must display the following acknowledgement:
84 * This product includes software developed for the NetBSD Project by
85 * Wasabi Systems, Inc.
86 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
87 * or promote products derived from this software without specific prior
88 * written permission.
89 *
90 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
92 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
93 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
94 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
95 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
96 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
97 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
98 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
99 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
100 * POSSIBILITY OF SUCH DAMAGE.
101 */
102
103 /*
104 * Copyright (c) 1997,1998 Mark Brinicombe.
105 * Copyright (c) 1997,1998 Causality Limited.
106 * All rights reserved.
107 *
108 * Redistribution and use in source and binary forms, with or without
109 * modification, are permitted provided that the following conditions
110 * are met:
111 * 1. Redistributions of source code must retain the above copyright
112 * notice, this list of conditions and the following disclaimer.
113 * 2. Redistributions in binary form must reproduce the above copyright
114 * notice, this list of conditions and the following disclaimer in the
115 * documentation and/or other materials provided with the distribution.
116 * 3. All advertising materials mentioning features or use of this software
117 * must display the following acknowledgement:
118 * This product includes software developed by Mark Brinicombe
119 * for the NetBSD Project.
120 * 4. The name of the company nor the name of the author may be used to
121 * endorse or promote products derived from this software without specific
122 * prior written permission.
123 *
124 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
125 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
126 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
127 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
128 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
129 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
130 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
131 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
132 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
133 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
134 * SUCH DAMAGE.
135 *
136 * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
137 * boards using RedBoot firmware.
138 */
139
140 #include "opt_evbarm_boardtype.h"
141 #include "opt_cputypes.h"
142 #include "opt_gumstix.h"
143 #ifdef OVERO
144 #include "opt_omap.h"
145 #include "prcm.h"
146 #endif
147 #include "opt_ddb.h"
148 #include "opt_kgdb.h"
149 #include "opt_pmap_debug.h"
150 #include "opt_md.h"
151 #include "opt_modular.h"
152 #include "opt_com.h"
153 #include "md.h"
154
155 #include <sys/param.h>
156 #include <sys/conf.h>
157 #include <sys/device.h>
158 #include <sys/exec.h>
159 #include <sys/kernel.h>
160 #include <sys/ksyms.h>
161 #include <sys/msgbuf.h>
162 #include <sys/proc.h>
163 #include <sys/reboot.h>
164 #include <sys/systm.h>
165 #include <sys/termios.h>
166
167 #include <machine/autoconf.h>
168 #include <machine/bootconfig.h>
169 #include <machine/bus.h>
170 #include <machine/cpu.h>
171 #include <machine/db_machdep.h>
172 #include <machine/frame.h>
173
174 #include <arm/arm32/machdep.h>
175 #include <arm/omap/omap2_gpmcreg.h>
176 #if NPRCM > 0
177 #include <arm/omap/omap2_prcm.h>
178 #endif
179 #include <arm/omap/omap2_reg.h>
180 #include <arm/omap/omap_var.h>
181 #include <arm/omap/omap_com.h>
182 #include <arm/undefined.h>
183 #include <arm/xscale/pxa2x0reg.h>
184 #include <arm/xscale/pxa2x0var.h>
185 #include <arm/xscale/pxa2x0_gpio.h>
186 #include <evbarm/gumstix/gumstixreg.h>
187 #include <evbarm/gumstix/gumstixvar.h>
188
189 #include <uvm/uvm_extern.h>
190
191 #include <dev/cons.h>
192 #include <dev/md.h>
193
194 #include <ddb/db_sym.h>
195 #include <ddb/db_extern.h>
196 #ifdef KGDB
197 #include <sys/kgdb.h>
198 #endif
199
200 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
201 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
202 #ifndef KERNEL_VM_BASE
203 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
204 #endif
205
206 /*
207 * The range 0xc1000000 - 0xccffffff is available for kernel VM space
208 * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
209 */
210 #define KERNEL_VM_SIZE 0x0C000000
211
212
213 /*
214 * Address to call from cpu_reset() to reset the machine.
215 * This is machine architecture dependant as it varies depending
216 * on where the ROM appears when you turn the MMU off.
217 */
218
219 u_int cpu_reset_address = 0;
220
221 /* Define various stack sizes in pages */
222 #define IRQ_STACK_SIZE 1
223 #define ABT_STACK_SIZE 1
224 #define UND_STACK_SIZE 1
225
226 BootConfig bootconfig; /* Boot config storage */
227 static char bootargs[MAX_BOOT_STRING];
228 char *boot_args = NULL;
229
230 uint32_t system_serial_high;
231 uint32_t system_serial_low;
232
233 vm_offset_t physical_start;
234 vm_offset_t physical_freestart;
235 vm_offset_t physical_freeend;
236 vm_offset_t physical_end;
237 u_int free_pages;
238
239 /*int debug_flags;*/
240 #ifndef PMAP_STATIC_L1S
241 int max_processes = 64; /* Default number */
242 #endif /* !PMAP_STATIC_L1S */
243
244 /* Physical and virtual addresses for some global pages */
245 pv_addr_t irqstack;
246 pv_addr_t undstack;
247 pv_addr_t abtstack;
248 pv_addr_t kernelstack;
249 pv_addr_t minidataclean;
250
251 vm_offset_t msgbufphys;
252
253 extern u_int data_abort_handler_address;
254 extern u_int prefetch_abort_handler_address;
255 extern u_int undefined_handler_address;
256
257 #ifdef PMAP_DEBUG
258 extern int pmap_debug_level;
259 #endif
260
261 #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
262 #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
263 #define KERNEL_PT_KERNEL_NUM ((KERNEL_VM_BASE - KERNEL_BASE) >> 22)
264 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
265 /* Page tables for mapping kernel VM */
266 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
267 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
268
269 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
270
271 /* Prototypes */
272 #if defined(GUMSTIX)
273 static void read_system_serial(void);
274 #endif
275 static void process_kernel_args(int, char *[]);
276 static void process_kernel_args_liner(char *);
277 #ifdef KGDB
278 static void kgdb_port_init(void);
279 #endif
280 static void gumstix_device_register(device_t, void *);
281
282 bs_protos(bs_notimpl);
283
284 #include "com.h"
285 #if NCOM > 0
286 #include <dev/ic/comreg.h>
287 #include <dev/ic/comvar.h>
288 #endif
289
290 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
291 #include "lcd.h"
292 #endif
293
294 #ifndef CONSPEED
295 #define CONSPEED B115200 /* It's a setting of the default of u-boot */
296 #endif
297 #ifndef CONMODE
298 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
299 #endif
300
301 int comcnspeed = CONSPEED;
302 int comcnmode = CONMODE;
303
304 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
305 static char console[16];
306 #endif
307
308 extern void gxio_config_pin(void);
309 extern void gxio_config_expansion(char *);
310
311 /*
312 * void cpu_reboot(int howto, char *bootstr)
313 *
314 * Deal with any syncing, unmounting, dumping and shutdown hooks,
315 * then reset the CPU.
316 */
317 void
318 cpu_reboot(int howto, char *bootstr)
319 {
320
321 #ifdef DIAGNOSTIC
322 /* info */
323 printf("boot: howto=%08x curproc=%p\n", howto, curproc);
324 #endif
325
326 /*
327 * If we are still cold then hit the air brakes
328 * and crash to earth fast
329 */
330 if (cold) {
331 doshutdownhooks();
332 pmf_system_shutdown(boothowto);
333 printf("The operating system has halted.\n");
334 printf("Please press any key to reboot.\n\n");
335 cngetc();
336 printf("rebooting...\n");
337 #if defined(OMAP_3530) && NPRCM > 0
338 prcm_cold_reset();
339 #endif
340 cpu_reset();
341 /*NOTREACHED*/
342 }
343
344 /*
345 * If RB_NOSYNC was not specified sync the discs.
346 * Note: Unless cold is set to 1 here, syslogd will die during the
347 * unmount. It looks like syslogd is getting woken up only to find
348 * that it cannot page part of the binary in as the filesystem has
349 * been unmounted.
350 */
351 if (!(howto & RB_NOSYNC))
352 bootsync();
353
354 /* Say NO to interrupts */
355 splhigh();
356
357 /* Do a dump if requested. */
358 if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
359 dumpsys();
360
361 /* Run any shutdown hooks */
362 doshutdownhooks();
363
364 pmf_system_shutdown(boothowto);
365
366 /* Make sure IRQ's are disabled */
367 IRQdisable;
368
369 if (howto & RB_HALT) {
370 printf("The operating system has halted.\n");
371 printf("Please press any key to reboot.\n\n");
372 cngetc();
373 }
374
375 printf("rebooting...\n");
376 #if defined(OMAP_3530) && NPRCM > 0
377 prcm_cold_reset();
378 #endif
379 cpu_reset();
380 /*NOTREACHED*/
381 }
382
383 static inline pd_entry_t *
384 read_ttb(void)
385 {
386 long ttb;
387
388 __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
389
390 return (pd_entry_t *)(ttb & ~((1<<14)-1));
391 }
392
393 /*
394 * Static device mappings. These peripheral registers are mapped at
395 * fixed virtual addresses very early in initarm() so that we can use
396 * them while booting the kernel, and stay at the same address
397 * throughout whole kernel's life time.
398 *
399 * We use this table twice; once with bootstrap page table, and once
400 * with kernel's page table which we build up in initarm().
401 *
402 * Since we map these registers into the bootstrap page table using
403 * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
404 * registers segment-aligned and segment-rounded in order to avoid
405 * using the 2nd page tables.
406 */
407
408 #define _A(a) ((a) & ~L1_S_OFFSET)
409 #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
410
411 static const struct pmap_devmap gumstix_devmap[] = {
412 #if defined(GUMSTIX)
413 {
414 GUMSTIX_GPIO_VBASE,
415 _A(PXA2X0_GPIO_BASE),
416 _S(PXA250_GPIO_SIZE),
417 VM_PROT_READ | VM_PROT_WRITE,
418 PTE_NOCACHE,
419 },
420 {
421 GUMSTIX_CLKMAN_VBASE,
422 _A(PXA2X0_CLKMAN_BASE),
423 _S(PXA2X0_CLKMAN_SIZE),
424 VM_PROT_READ | VM_PROT_WRITE,
425 PTE_NOCACHE,
426 },
427 {
428 GUMSTIX_INTCTL_VBASE,
429 _A(PXA2X0_INTCTL_BASE),
430 _S(PXA2X0_INTCTL_SIZE),
431 VM_PROT_READ | VM_PROT_WRITE,
432 PTE_NOCACHE,
433 },
434 {
435 GUMSTIX_FFUART_VBASE,
436 _A(PXA2X0_FFUART_BASE),
437 _S(4 * COM_NPORTS),
438 VM_PROT_READ | VM_PROT_WRITE,
439 PTE_NOCACHE,
440 },
441 {
442 GUMSTIX_STUART_VBASE,
443 _A(PXA2X0_STUART_BASE),
444 _S(4 * COM_NPORTS),
445 VM_PROT_READ | VM_PROT_WRITE,
446 PTE_NOCACHE,
447 },
448 {
449 GUMSTIX_BTUART_VBASE,
450 _A(PXA2X0_BTUART_BASE),
451 _S(4 * COM_NPORTS),
452 VM_PROT_READ | VM_PROT_WRITE,
453 PTE_NOCACHE,
454 },
455 {
456 GUMSTIX_HWUART_VBASE,
457 _A(PXA2X0_HWUART_BASE),
458 _S(4 * COM_NPORTS),
459 VM_PROT_READ | VM_PROT_WRITE,
460 PTE_NOCACHE,
461 },
462 {
463 GUMSTIX_LCDC_VBASE,
464 _A(PXA2X0_LCDC_BASE),
465 _S(4 * COM_NPORTS),
466 VM_PROT_READ | VM_PROT_WRITE,
467 PTE_NOCACHE,
468 },
469 #elif defined(OVERO)
470 {
471 OVERO_L4_PERIPHERAL_VBASE,
472 _A(OMAP3530_L4_PERIPHERAL_BASE),
473 _S(OMAP3530_L4_PERIPHERAL_SIZE),
474 VM_PROT_READ | VM_PROT_WRITE,
475 PTE_NOCACHE
476 },
477 {
478 OVERO_GPMC_VBASE,
479 _A(GPMC_BASE),
480 _S(GPMC_SIZE),
481 VM_PROT_READ | VM_PROT_WRITE,
482 PTE_NOCACHE
483 },
484 #endif
485 { 0, 0, 0, 0, 0 }
486 };
487
488 #undef _A
489 #undef _S
490
491
492 /*
493 * u_int initarm(...)
494 *
495 * Initial entry point on startup. This gets called before main() is
496 * entered.
497 * It should be responsible for setting up everything that must be
498 * in place when main is called.
499 * This includes
500 * Taking a copy of the boot configuration structure.
501 * Initialising the physical console so characters can be printed.
502 * Setting up page tables for the kernel
503 * Relocating the kernel to the bottom of physical memory
504 */
505 u_int
506 initarm(void *arg)
507 {
508 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
509 #ifdef DIAGNOSTIC
510 extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
511 #endif
512 extern vaddr_t xscale_cache_clean_addr;
513 #endif
514 extern uint32_t *u_boot_args[];
515 extern uint32_t ram_size;
516 enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
517 int loop;
518 int loop1;
519 u_int l1pagetable;
520 paddr_t memstart;
521 psize_t memsize;
522
523 /*
524 * U-Boot doesn't use the virtual memory.
525 *
526 * Gumstix (basix, connex, verdex, verdex-pro):
527 * Physical Address Range Description
528 * ----------------------- ----------------------------------
529 * 0x00000000 - 0x00ffffff flash Memory (16MB or 4MB)
530 * 0x40000000 - 0x480fffff Processor Registers
531 * 0xa0000000 - 0xa3ffffff SDRAM Bank 0 (64MB or 128MB)
532 *
533 * Overo:
534 * Physical Address Range Description
535 * ----------------------- ----------------------------------
536 */
537
538 /*
539 * Heads up ... Setup the CPU / MMU / TLB functions
540 */
541 if (set_cpufuncs())
542 panic("cpu not recognized!");
543
544 /* map some peripheral registers at static I/O area */
545 pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
546
547 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
548 /* start 32.768kHz OSC */
549 ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
550
551 /* Get ready for splfoo() */
552 pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
553
554 /* setup GPIO for {FF,ST,HW}UART. */
555 pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
556
557 pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
558 #elif defined(CPU_CORTEXA8)
559 {
560 void cortexa8_pmc_ccnt_init(void);
561
562 cortexa8_pmc_ccnt_init();
563 }
564 #endif
565
566 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
567
568 /* configure GPIOs. */
569 gxio_config_pin();
570
571
572 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
573 consinit();
574 #endif
575 #ifdef KGDB
576 kgdb_port_init();
577 #endif
578
579 /*
580 * Examine the boot args string for options we need to know about
581 * now.
582 */
583 #if defined(GUMSTIX)
584 #define SDRAM_START 0xa0000000UL
585 #elif defined(OVERO)
586 #define SDRAM_START 0x80000000UL
587 #endif
588 if (((uint32_t)u_boot_args[r0] & 0xf0000000) != SDRAM_START)
589 /* Maybe r0 is 'argc'. We are booted by command 'go'. */
590 process_kernel_args((int)u_boot_args[r0],
591 (char **)u_boot_args[r1]);
592 else
593 /*
594 * Maybe r3 is 'boot args string' of 'bootm'. This string is
595 * linely.
596 */
597 process_kernel_args_liner((char *)u_boot_args[r3]);
598 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
599 consinit();
600 #endif
601
602 /* Talk to the user */
603 #define BDSTR(s) _BDSTR(s)
604 #define _BDSTR(s) #s
605 printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
606
607 /* Read system serial */
608 #if defined(GUMSTIX)
609 read_system_serial();
610 #endif
611
612 memstart = SDRAM_START;
613 memsize = ram_size;
614
615 #ifdef VERBOSE_INIT_ARM
616 printf("initarm: Configuring system ...\n");
617 #endif
618
619 /* Fake bootconfig structure for the benefit of pmap.c */
620 /* XXX must make the memory description h/w independent */
621 bootconfig.dramblocks = 1;
622 bootconfig.dram[0].address = memstart;
623 bootconfig.dram[0].pages = memsize / PAGE_SIZE;
624
625 /*
626 * Set up the variables that define the availablilty of
627 * physical memory. For now, we're going to set
628 * physical_freestart to 0xa0200000 (where the kernel
629 * was loaded), and allocate the memory we need downwards.
630 * If we get too close to the L1 table that we set up, we
631 * will panic. We will update physical_freestart and
632 * physical_freeend later to reflect what pmap_bootstrap()
633 * wants to see.
634 *
635 * XXX pmap_bootstrap() needs an enema.
636 */
637 physical_start = bootconfig.dram[0].address;
638 physical_end = physical_start + memsize;
639
640 #if defined(GUMSTIX)
641 physical_freestart = 0xa0009000UL;
642 physical_freeend = 0xa0200000UL;
643 #elif defined(OVERO)
644 physical_freestart = 0x80009000UL;
645 physical_freeend = 0x80200000UL;
646 #endif
647
648 physmem = (physical_end - physical_start) / PAGE_SIZE;
649
650 #ifdef VERBOSE_INIT_ARM
651 /* Tell the user about the memory */
652 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
653 physical_start, physical_end - 1);
654 #endif
655
656 /*
657 * Okay, the kernel starts 2MB in from the bottom of physical
658 * memory. We are going to allocate our bootstrap pages downwards
659 * from there.
660 *
661 * We need to allocate some fixed page tables to get the kernel
662 * going. We allocate one page directory and a number of page
663 * tables and store the physical addresses in the kernel_pt_table
664 * array.
665 *
666 * The kernel page directory must be on a 16K boundary. The page
667 * tables must be on 4K bounaries. What we do is allocate the
668 * page directory on the first 16K boundary that we encounter, and
669 * the page tables on 4K boundaries otherwise. Since we allocate
670 * at least 3 L2 page tables, we are guaranteed to encounter at
671 * least one 16K aligned region.
672 */
673
674 #ifdef VERBOSE_INIT_ARM
675 printf("Allocating page tables\n");
676 #endif
677
678 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
679
680 #ifdef VERBOSE_INIT_ARM
681 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
682 physical_freestart, free_pages, free_pages);
683 #endif
684
685 /* Define a macro to simplify memory allocation */
686 #define valloc_pages(var, np) \
687 alloc_pages((var).pv_pa, (np)); \
688 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
689
690 #define alloc_pages(var, np) \
691 physical_freeend -= ((np) * PAGE_SIZE); \
692 if (physical_freeend < physical_freestart) \
693 panic("initarm: out of memory"); \
694 (var) = physical_freeend; \
695 free_pages -= (np); \
696 memset((char *)(var), 0, ((np) * PAGE_SIZE));
697
698 loop1 = 0;
699 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
700 /* Are we 16KB aligned for an L1 ? */
701 if ((physical_freeend & (L1_TABLE_SIZE - 1)) == 0 &&
702 kernel_l1pt.pv_pa == 0) {
703 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
704 } else {
705 valloc_pages(kernel_pt_table[loop1],
706 L2_TABLE_SIZE / PAGE_SIZE);
707 ++loop1;
708 }
709 }
710
711 /* This should never be able to happen but better confirm that. */
712 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
713 panic("initarm: Failed to align the kernel page directory");
714
715 /*
716 * Allocate a page for the system page mapped to V0x00000000
717 * This page will just contain the system vectors and can be
718 * shared by all processes.
719 */
720 alloc_pages(systempage.pv_pa, 1);
721 #if defined(CPU_CORTEXA8)
722 systempage.pv_va = ARM_VECTORS_HIGH;
723 #endif
724
725 /* Allocate stacks for all modes */
726 valloc_pages(irqstack, IRQ_STACK_SIZE);
727 valloc_pages(abtstack, ABT_STACK_SIZE);
728 valloc_pages(undstack, UND_STACK_SIZE);
729 valloc_pages(kernelstack, UPAGES);
730
731 /* Allocate enough pages for cleaning the Mini-Data cache. */
732 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
733 KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
734 #endif
735 valloc_pages(minidataclean, 1);
736
737 #ifdef VERBOSE_INIT_ARM
738 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
739 irqstack.pv_va);
740 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
741 abtstack.pv_va);
742 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
743 undstack.pv_va);
744 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
745 kernelstack.pv_va);
746 #endif
747
748 /*
749 * XXX Defer this to later so that we can reclaim the memory
750 * XXX used by the RedBoot page tables.
751 */
752 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
753
754 /*
755 * Ok we have allocated physical pages for the primary kernel
756 * page tables
757 */
758
759 #ifdef VERBOSE_INIT_ARM
760 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
761 #endif
762
763 /*
764 * Now we start construction of the L1 page table
765 * We start by mapping the L2 page tables into the L1.
766 * This means that we can replace L1 mappings later on if necessary
767 */
768 l1pagetable = kernel_l1pt.pv_va;
769
770 /* Map the L2 pages tables in the L1 page table */
771 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
772 pmap_link_l2pt(l1pagetable, 0x00000000,
773 &kernel_pt_table[KERNEL_PT_SYS]);
774 #elif defined(CPU_CORTEXA8)
775 pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
776 &kernel_pt_table[KERNEL_PT_SYS]);
777 #endif
778 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
779 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
780 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
781 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
782 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
783 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
784
785 /* update the top of the kernel VM */
786 pmap_curmaxkvaddr =
787 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
788
789 #ifdef VERBOSE_INIT_ARM
790 printf("Mapping kernel\n");
791 #endif
792
793 /* Now we fill in the L2 pagetable for the kernel static code/data */
794 {
795 extern char etext[], _end[];
796 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
797 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
798 u_int logical;
799
800 textsize = (textsize + PGOFSET) & ~PGOFSET;
801 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
802
803 logical = 0x00200000; /* offset of kernel in RAM */
804
805 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
806 physical_start + logical, textsize,
807 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
808 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
809 physical_start + logical, totalsize - textsize,
810 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
811 }
812
813 #ifdef VERBOSE_INIT_ARM
814 printf("Constructing L2 page tables\n");
815 #endif
816
817 /* Map the stack pages */
818 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
819 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
820 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
821 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
822 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
823 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
824 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
825 UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
826
827 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
828 L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
829
830 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
831 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
832 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
833 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
834 }
835
836 /* Map the Mini-Data cache clean area. */
837 #if defined(GUMSTIX)
838 xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
839 minidataclean.pv_pa);
840 #endif
841
842 /* Map the vector page. */
843 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
844 #if 1
845 /* MULTI-ICE requires that page 0 is NC/NB so that it can download the
846 * cache-clean code there. */
847 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
848 VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
849 #else
850 pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
851 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
852 #endif
853 #elif defined(CPU_CORTEXA8)
854 pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
855 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
856 #endif
857
858 /*
859 * map integrated peripherals at same address in l1pagetable
860 * so that we can continue to use console.
861 */
862 pmap_devmap_bootstrap(l1pagetable, gumstix_devmap);
863
864 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
865 /*
866 * Give the XScale global cache clean code an appropriately
867 * sized chunk of unmapped VA space starting at 0xff000000
868 * (our device mappings end before this address).
869 */
870 xscale_cache_clean_addr = 0xff000000U;
871 #endif
872
873 /*
874 * Now we have the real page tables in place so we can switch to them.
875 * Once this is done we will be running with the REAL kernel page
876 * tables.
877 */
878
879 /*
880 * Update the physical_freestart/physical_freeend/free_pages
881 * variables.
882 */
883 {
884 extern char _end[];
885
886 physical_freestart = physical_start +
887 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
888 KERNEL_BASE);
889 physical_freeend = physical_end;
890 free_pages =
891 (physical_freeend - physical_freestart) / PAGE_SIZE;
892 }
893
894 /* Switch tables */
895 #ifdef VERBOSE_INIT_ARM
896 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
897 physical_freestart, free_pages, free_pages);
898 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
899 #endif
900
901 cpu_setttb(kernel_l1pt.pv_pa);
902 cpu_tlb_flushID();
903 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
904
905 /*
906 * Moved from cpu_startup() as data_abort_handler() references
907 * this during uvm init
908 */
909 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
910
911 #ifdef VERBOSE_INIT_ARM
912 printf("bootstrap done.\n");
913 #endif
914
915 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
916 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
917 #elif defined(CPU_CORTEXA8)
918 arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
919 #endif
920
921 /*
922 * Pages were allocated during the secondary bootstrap for the
923 * stacks for different CPU modes.
924 * We must now set the r13 registers in the different CPU modes to
925 * point to these stacks.
926 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
927 * of the stack memory.
928 */
929 #ifdef VERBOSE_INIT_ARM
930 printf("init subsystems: stacks ");
931 #endif
932
933 set_stackptr(PSR_IRQ32_MODE,
934 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
935 set_stackptr(PSR_ABT32_MODE,
936 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
937 set_stackptr(PSR_UND32_MODE,
938 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
939
940 /*
941 * Well we should set a data abort handler.
942 * Once things get going this will change as we will need a proper
943 * handler.
944 * Until then we will use a handler that just panics but tells us
945 * why.
946 * Initialisation of the vectors will just panic on a data abort.
947 * This just fills in a slighly better one.
948 */
949 #ifdef VERBOSE_INIT_ARM
950 printf("vectors ");
951 #endif
952 data_abort_handler_address = (u_int)data_abort_handler;
953 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
954 undefined_handler_address = (u_int)undefinedinstruction_bounce;
955
956 /* Initialise the undefined instruction handlers */
957 #ifdef VERBOSE_INIT_ARM
958 printf("undefined ");
959 #endif
960 undefined_init();
961
962 /* Load memory into UVM. */
963 #ifdef VERBOSE_INIT_ARM
964 printf("page ");
965 #endif
966 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
967 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
968 atop(physical_freestart), atop(physical_freeend),
969 VM_FREELIST_DEFAULT);
970
971 /* Boot strap pmap telling it where the kernel page table is */
972 #ifdef VERBOSE_INIT_ARM
973 printf("pmap ");
974 #endif
975 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
976
977 #ifdef __HAVE_MEMORY_DISK__
978 md_root_setconf(memory_disk, sizeof memory_disk);
979 #endif
980
981 #ifdef BOOTHOWTO
982 boothowto |= BOOTHOWTO;
983 #endif
984
985 #ifdef KGDB
986 if (boothowto & RB_KDB) {
987 kgdb_debug_init = 1;
988 kgdb_connect(1);
989 }
990 #endif
991
992 #if NKSYMS || defined(DDB) || defined(MODULAR)
993 /* Firmware doesn't load symbols. */
994 ddb_init(0, NULL, NULL);
995 #endif
996
997 #ifdef DDB
998 db_machine_init();
999 if (boothowto & RB_KDB)
1000 Debugger();
1001 #endif
1002
1003 /* We have our own device_register() */
1004 evbarm_device_register = gumstix_device_register;
1005
1006 /* We return the new stack pointer address */
1007 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
1008 }
1009
1010 #if defined(GUMSTIX)
1011 static void
1012 read_system_serial(void)
1013 {
1014 #define GUMSTIX_SYSTEM_SERIAL_ADDR 0
1015 #define GUMSTIX_SYSTEM_SERIAL_SIZE 8
1016 #define FLASH_OFFSET_INTEL_PROTECTION 0x81
1017 #define FLASH_OFFSET_USER_PROTECTION 0x85
1018 #define FLASH_CMD_READ_ID 0x90
1019 #define FLASH_CMD_RESET 0xff
1020 int i;
1021 char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
1022 char x;
1023
1024 src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
1025 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
1026 memcpy(system_serial,
1027 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
1028 *(volatile uint16_t *)0 = FLASH_CMD_RESET;
1029
1030 for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
1031 x &= system_serial[i];
1032 if (x == 0xff) {
1033 src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
1034 *(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
1035 memcpy(system_serial,
1036 src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
1037 *(volatile uint16_t *)0 = FLASH_CMD_RESET;
1038
1039 /*
1040 * XXXX: Don't need ???
1041 * gumstix_serial_hash(system_serial);
1042 */
1043 }
1044 system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
1045 system_serial[2] << 8 | system_serial[3];
1046 system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
1047 system_serial[6] << 8 | system_serial[7];
1048
1049 printf("system serial: 0x");
1050 for (i = 0; i < sizeof (system_serial); i++)
1051 printf("%02x", system_serial[i]);
1052 printf("\n");
1053 }
1054 #endif
1055
1056 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
1057 static const char busheader_name[] = "busheader=";
1058 #endif
1059 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
1060 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
1061 static const char expansion_name[] = "expansion=";
1062 #endif
1063 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
1064 static const char console_name[] = "console=";
1065 #endif
1066 static void
1067 process_kernel_args(int argc, char *argv[])
1068 {
1069 int gxio_configured = 0, i, j;
1070
1071 boothowto = 0;
1072
1073 for (i = 1, j = 0; i < argc; i++) {
1074 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
1075 if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
1076 /* Configure for GPIOs of busheader side */
1077 gxio_config_expansion(argv[i] + strlen(busheader_name));
1078 gxio_configured = 1;
1079 continue;
1080 }
1081 #endif
1082 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
1083 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
1084 if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) {
1085 /* Configure expansion */
1086 gxio_config_expansion(argv[i] + strlen(expansion_name));
1087 gxio_configured = 1;
1088 continue;
1089 }
1090 #endif
1091 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
1092 if (!strncmp(argv[i], console_name, strlen(console_name))) {
1093 strncpy(console, argv[i] + strlen(console_name),
1094 sizeof(console));
1095 consinit();
1096 }
1097 #endif
1098 if (j == MAX_BOOT_STRING) {
1099 *(bootargs + j) = '\0';
1100 continue;
1101 }
1102 if (j != 0)
1103 *(bootargs + j++) = ' ';
1104 strncpy(bootargs + j, argv[i], MAX_BOOT_STRING - j);
1105 j += strlen(argv[i]);
1106 }
1107 boot_args = bootargs;
1108
1109 parse_mi_bootargs(boot_args);
1110
1111 if (!gxio_configured)
1112 gxio_config_expansion(NULL);
1113 }
1114
1115 static void
1116 process_kernel_args_liner(char *args)
1117 {
1118 int i = 0;
1119 char *p = NULL;
1120
1121 boothowto = 0;
1122
1123 strncpy(bootargs, args, sizeof(bootargs));
1124 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
1125 defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
1126 {
1127 char *q;
1128
1129 if ((p = strstr(bootargs, expansion_name)))
1130 q = p + strlen(expansion_name);
1131 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
1132 else if ((p = strstr(bootargs, busheader_name)))
1133 q = p + strlen(busheader_name);
1134 #endif
1135 if (p) {
1136 char expansion[256], c;
1137
1138 i = 0;
1139 do {
1140 c = *(q + i);
1141 if (c == ' ')
1142 c = '\0';
1143 expansion[i++] = c;
1144 } while (c != '\0' && i < sizeof(expansion));
1145 gxio_config_expansion(expansion);
1146 strcpy(p, q + i);
1147 }
1148 }
1149 #endif
1150 if (p == NULL)
1151 gxio_config_expansion(NULL);
1152 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
1153 p = strstr(bootargs, console_name);
1154 if (p != NULL) {
1155 char c;
1156
1157 i = 0;
1158 do {
1159 c = *(p + strlen(console_name) + i);
1160 if (c == ' ')
1161 c = '\0';
1162 console[i++] = c;
1163 } while (c != '\0' && i < sizeof(console));
1164 consinit();
1165 strcpy(p, p + strlen(console_name) + i);
1166 }
1167 #endif
1168 boot_args = bootargs;
1169
1170 parse_mi_bootargs(boot_args);
1171 }
1172
1173 #ifdef KGDB
1174 #ifndef KGDB_DEVNAME
1175 #define KGDB_DEVNAME "ffuart"
1176 #endif
1177 const char kgdb_devname[] = KGDB_DEVNAME;
1178
1179 #ifndef KGDB_DEVRATE
1180 #define KGDB_DEVRATE CONSPEED
1181 #endif
1182 int kgdb_devrate = KGDB_DEVRATE;
1183
1184 #if (NCOM > 0)
1185 #ifndef KGDB_DEVMODE
1186 #define KGDB_DEVMODE CONMODE
1187 #endif
1188 int comkgdbmode = KGDB_DEVMODE;
1189 #endif /* NCOM */
1190
1191 #endif /* KGDB */
1192
1193
1194 void
1195 consinit(void)
1196 {
1197 static int consinit_called = 0;
1198
1199 if (consinit_called != 0)
1200 return;
1201
1202 consinit_called = 1;
1203
1204 #if NCOM > 0
1205
1206 #if defined(GUMSTIX)
1207
1208 #ifdef FFUARTCONSOLE
1209 #ifdef KGDB
1210 if (strcmp(kgdb_devname, "ffuart") == 0){
1211 /* port is reserved for kgdb */
1212 } else
1213 #endif
1214 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1215 if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0)
1216 #endif
1217 {
1218 int rv;
1219
1220 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
1221 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1222 if (rv == 0) {
1223 pxa2x0_clkman_config(CKEN_FFUART, 1);
1224 return;
1225 }
1226 }
1227 #endif /* FFUARTCONSOLE */
1228
1229 #ifdef STUARTCONSOLE
1230 #ifdef KGDB
1231 if (strcmp(kgdb_devname, "stuart") == 0) {
1232 /* port is reserved for kgdb */
1233 } else
1234 #endif
1235 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1236 if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
1237 #endif
1238 {
1239 int rv;
1240
1241 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
1242 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1243 if (rv == 0) {
1244 pxa2x0_clkman_config(CKEN_STUART, 1);
1245 return;
1246 }
1247 }
1248 #endif /* STUARTCONSOLE */
1249
1250 #ifdef BTUARTCONSOLE
1251 #ifdef KGDB
1252 if (strcmp(kgdb_devname, "btuart") == 0) {
1253 /* port is reserved for kgdb */
1254 } else
1255 #endif
1256 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1257 if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
1258 #endif
1259 {
1260 int rv;
1261
1262 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
1263 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1264 if (rv == 0) {
1265 pxa2x0_clkman_config(CKEN_BTUART, 1);
1266 return;
1267 }
1268 }
1269 #endif /* BTUARTCONSOLE */
1270
1271 #ifdef HWUARTCONSOLE
1272 #ifdef KGDB
1273 if (strcmp(kgdb_devname, "hwuart") == 0) {
1274 /* port is reserved for kgdb */
1275 } else
1276 #endif
1277 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1278 if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
1279 #endif
1280 {
1281 rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
1282 comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
1283 if (rv == 0) {
1284 pxa2x0_clkman_config(CKEN_HWUART, 1);
1285 return;
1286 }
1287 }
1288 #endif /* HWUARTCONSOLE */
1289
1290 #elif defined(OVERO)
1291
1292 if (comcnattach(&omap_a4x_bs_tag, 0x49020000, comcnspeed,
1293 OMAP_COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
1294 return;
1295
1296 #endif /* GUMSTIX or OVERO */
1297
1298 #endif /* NCOM */
1299
1300 #if NLCD > 0
1301 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
1302 if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
1303 #endif
1304 {
1305 gxlcd_cnattach();
1306 }
1307 #endif
1308 }
1309
1310 #ifdef KGDB
1311 static void
1312 kgdb_port_init(void)
1313 {
1314 #if (NCOM > 0) && defined(COM_PXA2X0)
1315 paddr_t paddr = 0;
1316 int cken = 0;
1317
1318 if (0 == strcmp(kgdb_devname, "ffuart")) {
1319 paddr = PXA2X0_FFUART_BASE;
1320 cken = CKEN_FFUART;
1321 } else if (0 == strcmp(kgdb_devname, "stuart")) {
1322 paddr = PXA2X0_STUART_BASE;
1323 cken = CKEN_STUART;
1324 } else if (0 == strcmp(kgdb_devname, "btuart")) {
1325 paddr = PXA2X0_BTUART_BASE;
1326 cken = CKEN_BTUART;
1327 } else if (0 == strcmp(kgdb_devname, "hwuart")) {
1328 paddr = PXA2X0_HWUART_BASE;
1329 cken = CKEN_HWUART;
1330 }
1331
1332 if (paddr &&
1333 0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
1334 kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
1335
1336 pxa2x0_clkman_config(cken, 1);
1337 }
1338
1339 #endif
1340 }
1341 #endif
1342
1343 static void
1344 gumstix_device_register(device_t dev, void *aux)
1345 {
1346
1347 if (device_is_a(dev, "ohci")) {
1348 if (prop_dictionary_set_bool(device_properties(dev),
1349 "Ganged-power-mask-on-port1", 1) == false) {
1350 printf("WARNING: unable to set power-mask for port1"
1351 " property for %s\n", dev->dv_xname);
1352 }
1353 if (prop_dictionary_set_bool(device_properties(dev),
1354 "Ganged-power-mask-on-port2", 1) == false) {
1355 printf("WARNING: unable to set power-mask for port2"
1356 " property for %s\n", dev->dv_xname);
1357 }
1358 if (prop_dictionary_set_bool(device_properties(dev),
1359 "Ganged-power-mask-on-port3", 1) == false) {
1360 printf("WARNING: unable to set power-mask for port3"
1361 " property for %s\n", dev->dv_xname);
1362 }
1363 }
1364 }
1365