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