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