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