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