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