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