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