Home | History | Annotate | Line # | Download | only in gumstix
gumstix_machdep.c revision 1.50.8.1
      1 /*	$NetBSD: gumstix_machdep.c,v 1.50.8.1 2017/03/13 07:41:26 skrll Exp $ */
      2 /*
      3  * Copyright (C) 2005, 2006, 2007  WIDE Project and SOUM Corporation.
      4  * All rights reserved.
      5  *
      6  * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
      7  * Corporation.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. Neither the name of the project nor the name of SOUM Corporation
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
     22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 /*
     34  * Copyright (c) 2002, 2003, 2004, 2005  Genetec Corporation.
     35  * All rights reserved.
     36  *
     37  * Written by Hiroyuki Bessho for Genetec Corporation.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. The name of Genetec Corporation may not be used to endorse or
     48  *    promote products derived from this software without specific prior
     49  *    written permission.
     50  *
     51  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     53  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     54  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     55  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     56  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     57  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     58  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     59  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     60  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     61  * POSSIBILITY OF SUCH DAMAGE.
     62  *
     63  * Machine dependent functions for kernel setup for Genetec G4250EBX
     64  * evaluation board.
     65  *
     66  * Based on iq80310_machhdep.c
     67  */
     68 /*
     69  * Copyright (c) 2001 Wasabi Systems, Inc.
     70  * All rights reserved.
     71  *
     72  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     73  *
     74  * Redistribution and use in source and binary forms, with or without
     75  * modification, are permitted provided that the following conditions
     76  * are met:
     77  * 1. Redistributions of source code must retain the above copyright
     78  *    notice, this list of conditions and the following disclaimer.
     79  * 2. Redistributions in binary form must reproduce the above copyright
     80  *    notice, this list of conditions and the following disclaimer in the
     81  *    documentation and/or other materials provided with the distribution.
     82  * 3. All advertising materials mentioning features or use of this software
     83  *    must display the following acknowledgement:
     84  *	This product includes software developed for the NetBSD Project by
     85  *	Wasabi Systems, Inc.
     86  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     87  *    or promote products derived from this software without specific prior
     88  *    written permission.
     89  *
     90  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     91  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     92  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     93  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     94  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     95  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     96  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     97  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     98  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     99  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    100  * POSSIBILITY OF SUCH DAMAGE.
    101  */
    102 
    103 /*
    104  * Copyright (c) 1997,1998 Mark Brinicombe.
    105  * Copyright (c) 1997,1998 Causality Limited.
    106  * All rights reserved.
    107  *
    108  * Redistribution and use in source and binary forms, with or without
    109  * modification, are permitted provided that the following conditions
    110  * are met:
    111  * 1. Redistributions of source code must retain the above copyright
    112  *    notice, this list of conditions and the following disclaimer.
    113  * 2. Redistributions in binary form must reproduce the above copyright
    114  *    notice, this list of conditions and the following disclaimer in the
    115  *    documentation and/or other materials provided with the distribution.
    116  * 3. All advertising materials mentioning features or use of this software
    117  *    must display the following acknowledgement:
    118  *	This product includes software developed by Mark Brinicombe
    119  *	for the NetBSD Project.
    120  * 4. The name of the company nor the name of the author may be used to
    121  *    endorse or promote products derived from this software without specific
    122  *    prior written permission.
    123  *
    124  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    125  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    126  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    127  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    128  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    129  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    130  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    131  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    132  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    133  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    134  * SUCH DAMAGE.
    135  *
    136  * Machine dependent functions for kernel setup for Intel IQ80310 evaluation
    137  * boards using RedBoot firmware.
    138  */
    139 
    140 #include "opt_evbarm_boardtype.h"
    141 #include "opt_cputypes.h"
    142 #include "opt_gumstix.h"
    143 #ifdef OVERO
    144 #include "opt_omap.h"
    145 #include "prcm.h"
    146 #endif
    147 #include "opt_kgdb.h"
    148 #include "opt_pmap_debug.h"
    149 #include "opt_com.h"
    150 
    151 #include <sys/param.h>
    152 #include <sys/conf.h>
    153 #include <sys/device.h>
    154 #include <sys/exec.h>
    155 #include <sys/kernel.h>
    156 #include <sys/proc.h>
    157 #include <sys/reboot.h>
    158 #include <sys/systm.h>
    159 #include <sys/termios.h>
    160 #include <sys/bus.h>
    161 #include <sys/cpu.h>
    162 
    163 #include <uvm/uvm_extern.h>
    164 
    165 #include <machine/autoconf.h>
    166 #include <machine/bootconfig.h>
    167 #include <arm/locore.h>
    168 
    169 #include <arm/arm32/machdep.h>
    170 #ifdef OVERO
    171 #include <arm/omap/omap2_gpmcreg.h>
    172 #include <arm/omap/omap2_prcm.h>
    173 #include <arm/omap/omap2_reg.h>
    174 #include <arm/omap/omap_var.h>
    175 #include <arm/omap/omap_com.h>
    176 #endif
    177 #include <arm/xscale/pxa2x0reg.h>
    178 #include <arm/xscale/pxa2x0var.h>
    179 #include <arm/xscale/pxa2x0_gpio.h>
    180 #include <evbarm/gumstix/gumstixreg.h>
    181 #include <evbarm/gumstix/gumstixvar.h>
    182 
    183 #include <dev/cons.h>
    184 
    185 #ifdef KGDB
    186 #include <sys/kgdb.h>
    187 #endif
    188 
    189 /*
    190  * The range 0xc1000000 - 0xfd000000 is available for kernel VM space
    191  * Core-logic registers and I/O mappings occupy
    192  *
    193  *    0xfd000000 - 0xfd800000	on gumstix
    194  *    0xc0000000 - 0xc0400000	on overo, duovero and pepper
    195  */
    196 #ifndef KERNEL_VM_BASE
    197 #define	KERNEL_VM_BASE		0xc8000000
    198 #endif
    199 #define KERNEL_VM_SIZE		0x35000000
    200 
    201 BootConfig bootconfig;		/* Boot config storage */
    202 static char bootargs[MAX_BOOT_STRING];
    203 const size_t bootargs_len = sizeof(bootargs) - 1;	/* without nul */
    204 char *boot_args = NULL;
    205 
    206 uint32_t system_serial_high;
    207 uint32_t system_serial_low;
    208 
    209 /* Prototypes */
    210 #if defined(GUMSTIX)
    211 static void	read_system_serial(void);
    212 #elif defined(OVERO)
    213 static void	overo_reset(void);
    214 static void	find_cpu_clock(void);
    215 #endif
    216 static void	process_kernel_args(int, char *[]);
    217 static void	process_kernel_args_liner(char *);
    218 #ifdef KGDB
    219 static void	kgdb_port_init(void);
    220 #endif
    221 static void	gumstix_device_register(device_t, void *);
    222 
    223 bs_protos(bs_notimpl);
    224 
    225 #include "com.h"
    226 #if NCOM > 0
    227 #include <dev/ic/comreg.h>
    228 #include <dev/ic/comvar.h>
    229 #endif
    230 
    231 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    232 #include "lcd.h"
    233 #endif
    234 
    235 #ifndef CONSPEED
    236 #define CONSPEED B115200	/* It's a setting of the default of u-boot */
    237 #endif
    238 #ifndef CONMODE
    239 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    240 #endif
    241 
    242 int comcnspeed = CONSPEED;
    243 int comcnmode = CONMODE;
    244 
    245 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    246 static char console[16];
    247 #endif
    248 
    249 extern void gxio_config_pin(void);
    250 extern void gxio_config_expansion(char *);
    251 
    252 
    253 static inline pd_entry_t *
    254 read_ttb(void)
    255 {
    256 	long ttb;
    257 
    258 	__asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));
    259 
    260 	return (pd_entry_t *)(ttb & ~((1<<14)-1));
    261 }
    262 
    263 /*
    264  * Static device mappings. These peripheral registers are mapped at
    265  * fixed virtual addresses very early in initarm() so that we can use
    266  * them while booting the kernel, and stay at the same address
    267  * throughout whole kernel's life time.
    268  *
    269  * We use this table twice; once with bootstrap page table, and once
    270  * with kernel's page table which we build up in initarm().
    271  *
    272  * Since we map these registers into the bootstrap page table using
    273  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    274  * registers segment-aligned and segment-rounded in order to avoid
    275  * using the 2nd page tables.
    276  */
    277 
    278 #define	_A(a)	((a) & ~L1_S_OFFSET)
    279 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    280 
    281 static const struct pmap_devmap gumstix_devmap[] = {
    282 #if defined(GUMSTIX)
    283 	{
    284 		GUMSTIX_GPIO_VBASE,
    285 		_A(PXA2X0_GPIO_BASE),
    286 		_S(PXA250_GPIO_SIZE),
    287 		VM_PROT_READ | VM_PROT_WRITE,
    288 		PTE_NOCACHE,
    289 	},
    290 	{
    291 		GUMSTIX_CLKMAN_VBASE,
    292 		_A(PXA2X0_CLKMAN_BASE),
    293 		_S(PXA2X0_CLKMAN_SIZE),
    294 		VM_PROT_READ | VM_PROT_WRITE,
    295 		PTE_NOCACHE,
    296 	},
    297 	{
    298 		GUMSTIX_INTCTL_VBASE,
    299 		_A(PXA2X0_INTCTL_BASE),
    300 		_S(PXA2X0_INTCTL_SIZE),
    301 		VM_PROT_READ | VM_PROT_WRITE,
    302 		PTE_NOCACHE,
    303 	},
    304 	{
    305 		GUMSTIX_FFUART_VBASE,
    306 		_A(PXA2X0_FFUART_BASE),
    307 		_S(4 * COM_NPORTS),
    308 		VM_PROT_READ | VM_PROT_WRITE,
    309 		PTE_NOCACHE,
    310 	},
    311 	{
    312 		GUMSTIX_STUART_VBASE,
    313 		_A(PXA2X0_STUART_BASE),
    314 		_S(4 * COM_NPORTS),
    315 		VM_PROT_READ | VM_PROT_WRITE,
    316 		PTE_NOCACHE,
    317 	},
    318 	{
    319 		GUMSTIX_BTUART_VBASE,
    320 		_A(PXA2X0_BTUART_BASE),
    321 		_S(4 * COM_NPORTS),
    322 		VM_PROT_READ | VM_PROT_WRITE,
    323 		PTE_NOCACHE,
    324 	},
    325 	{
    326 		GUMSTIX_HWUART_VBASE,
    327 		_A(PXA2X0_HWUART_BASE),
    328 		_S(4 * COM_NPORTS),
    329 		VM_PROT_READ | VM_PROT_WRITE,
    330 		PTE_NOCACHE,
    331 	},
    332 	{
    333 		GUMSTIX_LCDC_VBASE,
    334 		_A(PXA2X0_LCDC_BASE),
    335 		_S(4 * COM_NPORTS),
    336 		VM_PROT_READ | VM_PROT_WRITE,
    337 		PTE_NOCACHE,
    338 	},
    339 #elif defined(OVERO)
    340 	{
    341 		OVERO_L4_PERIPHERAL_VBASE,
    342 		_A(OMAP3530_L4_PERIPHERAL_BASE),
    343 		_S(OMAP3530_L4_PERIPHERAL_SIZE),
    344 		VM_PROT_READ | VM_PROT_WRITE,
    345 		PTE_NOCACHE
    346 	},
    347 	{
    348 		OVERO_GPMC_VBASE,
    349 		_A(GPMC_BASE),
    350 		_S(GPMC_SIZE),
    351 		VM_PROT_READ | VM_PROT_WRITE,
    352 		PTE_NOCACHE
    353 	},
    354 #endif
    355 	{ 0, 0, 0, 0, 0 }
    356 };
    357 
    358 #undef	_A
    359 #undef	_S
    360 
    361 
    362 /*
    363  * u_int initarm(...)
    364  *
    365  * Initial entry point on startup. This gets called before main() is
    366  * entered.
    367  * It should be responsible for setting up everything that must be
    368  * in place when main is called.
    369  * This includes
    370  *   Taking a copy of the boot configuration structure.
    371  *   Initialising the physical console so characters can be printed.
    372  *   Setting up page tables for the kernel
    373  *   Relocating the kernel to the bottom of physical memory
    374  */
    375 u_int
    376 initarm(void *arg)
    377 {
    378 	extern char KERNEL_BASE_phys[];
    379 	extern uint32_t *u_boot_args[];
    380 	extern uint32_t ram_size;
    381 	enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
    382 
    383 	/*
    384 	 * We mapped PA == VA in gumstix_start.S.
    385 	 * Also mapped SDRAM to KERNEL_BASE first 64Mbyte only with cachable.
    386 	 *
    387 	 * Gumstix (basix, connex, verdex, verdex-pro):
    388 	 * Physical Address Range     Description
    389 	 * -----------------------    ----------------------------------
    390 	 * 0x00000000 - 0x00ffffff    flash Memory   (16MB or 4MB)
    391 	 * 0x40000000 - 0x480fffff    Processor Registers
    392 	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB or 128MB)
    393 	 * 0xc0000000 - 0xc3ffffff    KERNEL_BASE
    394 	 *
    395 	 * Overo:
    396 	 * Physical Address Range     Description
    397 	 * -----------------------    ----------------------------------
    398 	 * 0x80000000 - 0x8fffffff    SDRAM Bank 0 (256MB or 512MB)
    399 	 * 0x80000000 - 0x83ffffff    KERNEL_BASE
    400 	 */
    401 
    402 #if defined(GUMSTIX)
    403 	extern vaddr_t xscale_cache_clean_addr;
    404 	xscale_cache_clean_addr = 0xff000000U;
    405 
    406 	cpu_reset_address = NULL;
    407 #elif defined(OVERO)
    408 	cpu_reset_address = overo_reset;
    409 
    410 	find_cpu_clock();	// find our CPU speed.
    411 #endif
    412 
    413 	/*
    414 	 * Heads up ... Setup the CPU / MMU / TLB functions
    415 	 */
    416 	if (set_cpufuncs())
    417 		panic("cpu not recognized!");
    418 
    419 	/* map some peripheral registers at static I/O area */
    420 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
    421 
    422 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    423 	/* start 32.768kHz OSC */
    424 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
    425 
    426 	/* Get ready for splfoo() */
    427 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
    428 
    429 	/* setup GPIO for {FF,ST,HW}UART. */
    430 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
    431 
    432 	pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
    433 #elif defined(CPU_CORTEX)
    434 	cortex_pmc_ccnt_init();
    435 #endif
    436 
    437 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    438 
    439 	/* configure GPIOs. */
    440 	gxio_config_pin();
    441 
    442 
    443 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
    444 	consinit();
    445 #endif
    446 #ifdef KGDB
    447 	kgdb_port_init();
    448 #endif
    449 
    450 	/*
    451 	 * Examine the boot args string for options we need to know about
    452 	 * now.
    453 	 */
    454 #if defined(GUMSTIX)
    455 #define SDRAM_START	0xa0000000UL
    456 #elif defined(OVERO)
    457 #define SDRAM_START	0x80000000UL
    458 #endif
    459 	if (((uint32_t)u_boot_args[r0] & 0xf0000000) != SDRAM_START)
    460 		/* Maybe r0 is 'argc'.  We are booted by command 'go'. */
    461 		process_kernel_args((int)u_boot_args[r0],
    462 		    (char **)u_boot_args[r1]);
    463 	else
    464 		/*
    465 		 * Maybe r3 is 'boot args string' of 'bootm'.  This string is
    466 		 * linely.
    467 		 */
    468 		process_kernel_args_liner((char *)u_boot_args[r3]);
    469 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    470 	consinit();
    471 #endif
    472 
    473 	/* Talk to the user */
    474 #define BDSTR(s)	_BDSTR(s)
    475 #define _BDSTR(s)	#s
    476 	printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
    477 
    478 	/* Read system serial */
    479 #if defined(GUMSTIX)
    480 	read_system_serial();
    481 #endif
    482 
    483 #ifdef VERBOSE_INIT_ARM
    484 	printf("initarm: Configuring system ...\n");
    485 #endif
    486 
    487 	/* Fake bootconfig structure for the benefit of pmap.c */
    488 	/* XXX must make the memory description h/w independent */
    489 	bootconfig.dramblocks = 1;
    490 	bootconfig.dram[0].address = SDRAM_START;
    491 	bootconfig.dram[0].pages = ram_size / PAGE_SIZE;
    492 
    493 	KASSERT(ram_size <= KERNEL_VM_BASE - KERNEL_BASE);
    494 
    495 	arm32_bootmem_init(bootconfig.dram[0].address, ram_size,
    496 	    (uintptr_t) KERNEL_BASE_phys);
    497 	arm32_kernel_vm_init(KERNEL_VM_BASE,
    498 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    499 	    ARM_VECTORS_LOW,
    500 #elif defined(CPU_CORTEXA8)
    501 	    ARM_VECTORS_HIGH,
    502 #endif
    503 	    0, gumstix_devmap, true);
    504 
    505 	evbarm_device_register = gumstix_device_register;
    506 
    507 	return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
    508 }
    509 
    510 #if defined(GUMSTIX)
    511 static void
    512 read_system_serial(void)
    513 {
    514 #define GUMSTIX_SYSTEM_SERIAL_ADDR	0
    515 #define GUMSTIX_SYSTEM_SERIAL_SIZE	8
    516 #define FLASH_OFFSET_INTEL_PROTECTION	0x81
    517 #define FLASH_OFFSET_USER_PROTECTION	0x85
    518 #define FLASH_CMD_READ_ID		0x90
    519 #define FLASH_CMD_RESET			0xff
    520 	int i;
    521 	char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
    522 	char x;
    523 
    524 	src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
    525 	*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    526 	memcpy(system_serial,
    527 	    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    528 	*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    529 
    530 	for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
    531 		x &= system_serial[i];
    532 	if (x == 0xff) {
    533 		src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
    534 		*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    535 		memcpy(system_serial,
    536 		    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    537 		*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    538 
    539 		/*
    540 		 * XXXX: Don't need ???
    541 		 * gumstix_serial_hash(system_serial);
    542 		 */
    543 	}
    544 	system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
    545 	    system_serial[2] << 8 | system_serial[3];
    546 	system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
    547 	    system_serial[6] << 8 | system_serial[7];
    548 
    549 	printf("system serial: 0x");
    550 	for (i = 0; i < sizeof (system_serial); i++)
    551 		printf("%02x", system_serial[i]);
    552 	printf("\n");
    553 }
    554 
    555 #elif defined(OVERO)
    556 
    557 static void
    558 overo_reset(void)
    559 {
    560 
    561 #if NPRCM > 0
    562 	prcm_cold_reset();
    563 #endif
    564 }
    565 
    566 static void
    567 find_cpu_clock(void)
    568 {
    569 	const vaddr_t prm_base = OMAP2_PRM_BASE;
    570 	const vaddr_t cm_base = OMAP2_CM_BASE;
    571 	const uint32_t prm_clksel =
    572 	    *(volatile uint32_t *)(prm_base + PLL_MOD + OMAP3_PRM_CLKSEL);
    573 	static const uint32_t prm_clksel_freqs[] = OMAP3_PRM_CLKSEL_FREQS;
    574 	const uint32_t sys_clk =
    575 	    prm_clksel_freqs[__SHIFTOUT(prm_clksel, OMAP3_PRM_CLKSEL_CLKIN)];
    576 	const uint32_t dpll1 =
    577 	    *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL1_PLL_MPU);
    578 	const uint32_t dpll2 =
    579 	    *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL2_PLL_MPU);
    580 	const uint32_t m =
    581 	    __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_MULT);
    582 	const uint32_t n = __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_DIV);
    583 	const uint32_t m2 =
    584 	    __SHIFTOUT(dpll2, OMAP3_CM_CLKSEL2_PLL_MPU_DPLL_CLKOUT_DIV);
    585 
    586 	/*
    587 	 * MPU_CLK supplies ARM_FCLK which is twice the CPU frequency.
    588 	 */
    589 	curcpu()->ci_data.cpu_cc_freq =
    590 	    ((sys_clk * m) / ((n + 1) * m2 * 2)) * OMAP3_PRM_CLKSEL_MULT;
    591 	omap_sys_clk = sys_clk * OMAP3_PRM_CLKSEL_MULT;
    592 }
    593 #endif
    594 
    595 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
    596 static const char busheader_name[] = "busheader=";
    597 #endif
    598 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
    599     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
    600 static const char expansion_name[] = "expansion=";
    601 #endif
    602 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    603 static const char console_name[] = "console=";
    604 #endif
    605 static void
    606 process_kernel_args(int argc, char *argv[])
    607 {
    608 	int gxio_configured = 0, i, j;
    609 
    610 	boothowto = 0;
    611 
    612 	for (i = 1, j = 0; i < argc; i++) {
    613 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
    614 		if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
    615 			/* Configure for GPIOs of busheader side */
    616 			gxio_config_expansion(argv[i] + strlen(busheader_name));
    617 			gxio_configured = 1;
    618 			continue;
    619 		}
    620 #endif
    621 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
    622     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
    623 		if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) {
    624 			/* Configure expansion */
    625 			gxio_config_expansion(argv[i] + strlen(expansion_name));
    626 			gxio_configured = 1;
    627 			continue;
    628 		}
    629 #endif
    630 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    631 		if (!strncmp(argv[i], console_name, strlen(console_name))) {
    632 			strncpy(console, argv[i] + strlen(console_name),
    633 			    sizeof(console));
    634 			consinit();
    635 		}
    636 #endif
    637 		if (j == bootargs_len) {
    638 			*(bootargs + j) = '\0';
    639 			continue;
    640 		}
    641 		if (j != 0)
    642 			*(bootargs + j++) = ' ';
    643 		strncpy(bootargs + j, argv[i], bootargs_len - j);
    644 		bootargs[bootargs_len] = '\0';
    645 		j += strlen(argv[i]);
    646 	}
    647 	boot_args = bootargs;
    648 
    649 	parse_mi_bootargs(boot_args);
    650 
    651 	if (!gxio_configured)
    652 		gxio_config_expansion(NULL);
    653 }
    654 
    655 static void
    656 process_kernel_args_liner(char *args)
    657 {
    658 	int i = 0;
    659 	char *p = NULL;
    660 
    661 	boothowto = 0;
    662 
    663 	strncpy(bootargs, args, sizeof(bootargs));
    664 #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
    665     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
    666 	{
    667 		char *q;
    668 
    669 		if ((p = strstr(bootargs, expansion_name)))
    670 			q = p + strlen(expansion_name);
    671 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
    672 		else if ((p = strstr(bootargs, busheader_name)))
    673 			q = p + strlen(busheader_name);
    674 #endif
    675 		if (p) {
    676 			char expansion[256], c;
    677 
    678 			i = 0;
    679 			do {
    680 				c = *(q + i);
    681 				if (c == ' ')
    682 					c = '\0';
    683 				expansion[i++] = c;
    684 			} while (c != '\0' && i < sizeof(expansion));
    685 			gxio_config_expansion(expansion);
    686 			strcpy(p, q + i);
    687 		}
    688 	}
    689 #endif
    690 	if (p == NULL)
    691 		gxio_config_expansion(NULL);
    692 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    693 	p = strstr(bootargs, console_name);
    694 	if (p != NULL) {
    695 		char c;
    696 
    697 		i = 0;
    698 		do {
    699 			c = *(p + strlen(console_name) + i);
    700 			if (c == ' ')
    701 				c = '\0';
    702 			console[i++] = c;
    703 		} while (c != '\0' && i < sizeof(console));
    704 		consinit();
    705 		strcpy(p, p + strlen(console_name) + i);
    706 	}
    707 #endif
    708 	boot_args = bootargs;
    709 
    710 	parse_mi_bootargs(boot_args);
    711 }
    712 
    713 #ifdef KGDB
    714 #ifndef KGDB_DEVNAME
    715 #define KGDB_DEVNAME	"ffuart"
    716 #endif
    717 const char kgdb_devname[] = KGDB_DEVNAME;
    718 
    719 #ifndef KGDB_DEVRATE
    720 #define KGDB_DEVRATE	CONSPEED
    721 #endif
    722 int kgdb_devrate = KGDB_DEVRATE;
    723 
    724 #if (NCOM > 0)
    725 #ifndef KGDB_DEVMODE
    726 #define KGDB_DEVMODE	CONMODE
    727 #endif
    728 int comkgdbmode = KGDB_DEVMODE;
    729 #endif /* NCOM */
    730 
    731 #endif /* KGDB */
    732 
    733 
    734 void
    735 consinit(void)
    736 {
    737 	static int consinit_called = 0;
    738 
    739 	if (consinit_called != 0)
    740 		return;
    741 
    742 	consinit_called = 1;
    743 
    744 #if NCOM > 0
    745 
    746 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    747 	/* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */
    748 	if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') {
    749 		int i;
    750 
    751 		comcnspeed = 0;
    752 		for (i = 6; i < strlen(console) && isdigit(console[i]); i++)
    753 			comcnspeed = comcnspeed * 10 + (console[i] - '0');
    754 	}
    755 #endif
    756 
    757 #if defined(GUMSTIX)
    758 
    759 #ifdef FFUARTCONSOLE
    760 #ifdef KGDB
    761 	if (strcmp(kgdb_devname, "ffuart") == 0){
    762 		/* port is reserved for kgdb */
    763 	} else
    764 #endif
    765 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
    766 	if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 ||
    767 	    strncmp(console, "ttyS0,", 6) == 0)
    768 #endif
    769 	{
    770 		int rv;
    771 
    772 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
    773 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
    774 		if (rv == 0) {
    775 			pxa2x0_clkman_config(CKEN_FFUART, 1);
    776 			return;
    777 		}
    778 	}
    779 #endif /* FFUARTCONSOLE */
    780 
    781 #ifdef STUARTCONSOLE
    782 #ifdef KGDB
    783 	if (strcmp(kgdb_devname, "stuart") == 0) {
    784 		/* port is reserved for kgdb */
    785 	} else
    786 #endif
    787 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
    788 	if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
    789 #endif
    790 	{
    791 		int rv;
    792 
    793 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
    794 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
    795 		if (rv == 0) {
    796 			pxa2x0_clkman_config(CKEN_STUART, 1);
    797 			return;
    798 		}
    799 	}
    800 #endif /* STUARTCONSOLE */
    801 
    802 #ifdef BTUARTCONSOLE
    803 #ifdef KGDB
    804 	if (strcmp(kgdb_devname, "btuart") == 0) {
    805 		/* port is reserved for kgdb */
    806 	} else
    807 #endif
    808 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
    809 	if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
    810 #endif
    811 	{
    812 		int rv;
    813 
    814 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
    815 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
    816 		if (rv == 0) {
    817 			pxa2x0_clkman_config(CKEN_BTUART, 1);
    818 			return;
    819 		}
    820 	}
    821 #endif /* BTUARTCONSOLE */
    822 
    823 #ifdef HWUARTCONSOLE
    824 #ifdef KGDB
    825 	if (strcmp(kgdb_devname, "hwuart") == 0) {
    826 		/* port is reserved for kgdb */
    827 	} else
    828 #endif
    829 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
    830 	if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
    831 #endif
    832 	{
    833 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
    834 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
    835 		if (rv == 0) {
    836 			pxa2x0_clkman_config(CKEN_HWUART, 1);
    837 			return;
    838 		}
    839 	}
    840 #endif /* HWUARTCONSOLE */
    841 
    842 #elif defined(OVERO)
    843 
    844 	if (comcnattach(&omap_a4x_bs_tag, 0x49020000, comcnspeed,
    845 	    OMAP_COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
    846 		return;
    847 
    848 #endif /* GUMSTIX or OVERO */
    849 
    850 #endif /* NCOM */
    851 
    852 #if NLCD > 0
    853 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
    854 	if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
    855 #endif
    856 	{
    857 		gxlcd_cnattach();
    858 	}
    859 #endif
    860 }
    861 
    862 #ifdef KGDB
    863 static void
    864 kgdb_port_init(void)
    865 {
    866 #if (NCOM > 0) && defined(COM_PXA2X0)
    867 	paddr_t paddr = 0;
    868 	int cken = 0;
    869 
    870 	if (0 == strcmp(kgdb_devname, "ffuart")) {
    871 		paddr = PXA2X0_FFUART_BASE;
    872 		cken = CKEN_FFUART;
    873 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
    874 		paddr = PXA2X0_STUART_BASE;
    875 		cken = CKEN_STUART;
    876 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
    877 		paddr = PXA2X0_BTUART_BASE;
    878 		cken = CKEN_BTUART;
    879 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
    880 		paddr = PXA2X0_HWUART_BASE;
    881 		cken = CKEN_HWUART;
    882 	}
    883 
    884 	if (paddr &&
    885 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
    886 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
    887 
    888 		pxa2x0_clkman_config(cken, 1);
    889 	}
    890 
    891 #endif
    892 }
    893 #endif
    894 
    895 static void
    896 gumstix_device_register(device_t dev, void *aux)
    897 {
    898 	prop_dictionary_t dict = device_properties(dev);
    899 
    900 	if (device_is_a(dev, "ehci")) {
    901 		prop_dictionary_set_uint16(dict, "nports", 2);
    902 		prop_dictionary_set_bool(dict, "phy-reset", true);
    903 		prop_dictionary_set_cstring(dict, "port0-mode", "none");
    904 		prop_dictionary_set_int16(dict, "port0-gpio", -1);
    905 		prop_dictionary_set_cstring(dict, "port1-mode", "phy");
    906 		prop_dictionary_set_int16(dict, "port1-gpio", 183);
    907 		prop_dictionary_set_bool(dict, "port1-gpioval", true);
    908 		prop_dictionary_set_uint16(dict, "dpll5-m", 443);
    909 		prop_dictionary_set_uint16(dict, "dpll5-n", 11);
    910 		prop_dictionary_set_uint16(dict, "dpll5-m2", 4);
    911 	}
    912 	if (device_is_a(dev, "ohci")) {
    913 		if (prop_dictionary_set_bool(dict,
    914 		    "Ganged-power-mask-on-port1", 1) == false) {
    915 			printf("WARNING: unable to set power-mask for port1"
    916 			    " property for %s\n", device_xname(dev));
    917 		}
    918 		if (prop_dictionary_set_bool(dict,
    919 		    "Ganged-power-mask-on-port2", 1) == false) {
    920 			printf("WARNING: unable to set power-mask for port2"
    921 			    " property for %s\n", device_xname(dev));
    922 		}
    923 		if (prop_dictionary_set_bool(dict,
    924 		    "Ganged-power-mask-on-port3", 1) == false) {
    925 			printf("WARNING: unable to set power-mask for port3"
    926 			    " property for %s\n", device_xname(dev));
    927 		}
    928 	}
    929 }
    930